text: /*
   * This file is part of remdiff.
   * Copyright © Richard Kettlewell
   *
   * This program is free software: you can redistribute it and/or modify
   * it under the terms of the GNU General Public License as published by
   * the Free Software Foundation, either version 3 of the License, or
   * (at your option) any later version.
   *
   * This program is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU General Public License for more details.
   *
   * You should have received a copy of the GNU General Public License
   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
   */
  #ifndef SFTP_INTERNAL_H
  #define SFTP_INTERNAL_H
  
  #include <config.h>
  #include <stdint.h>
  #include <mutex>
  
  static inline uint32_t tobe32(uint32_t n) {
  #ifndef WORDS_BIGENDIAN
    n = __builtin_bswap32(n);
  #endif
    return n;
  }
  
  static inline uint64_t tobe64(uint64_t n) {
  #ifndef WORDS_BIGENDIAN
    n = __builtin_bswap64(n);
  #endif
    return n;
  }
  
  static inline uint32_t frombe32(uint32_t n) {
  #ifndef WORDS_BIGENDIAN
    n = __builtin_bswap32(n);
  #endif
    return n;
  }
  
  static inline uint64_t frombe64(uint64_t n) {
  #ifndef WORDS_BIGENDIAN
    n = __builtin_bswap64(n);
  #endif
    return n;
  }
  
  #define SSH_FXP_INIT 1
  #define SSH_FXP_VERSION 2
  #define SSH_FXP_OPEN 3
  #define SSH_FXP_CLOSE 4
  #define SSH_FXP_READ 5
  #define SSH_FXP_WRITE 6
  #define SSH_FXP_LSTAT 7
  #define SSH_FXP_FSTAT 8
  #define SSH_FXP_SETSTAT 9
  #define SSH_FXP_FSETSTAT 10
  #define SSH_FXP_OPENDIR 11
  #define SSH_FXP_READDIR 12
  #define SSH_FXP_REMOVE 13
  #define SSH_FXP_MKDIR 14
  #define SSH_FXP_RMDIR 15
  #define SSH_FXP_REALPATH 16
  #define SSH_FXP_STAT 17
  #define SSH_FXP_RENAME 18
  #define SSH_FXP_READLINK 19
  #define SSH_FXP_SYMLINK 20
  #define SSH_FXP_LINK 21
  #define SSH_FXP_BLOCK 22
  #define SSH_FXP_UNBLOCK 23
  #define SSH_FXP_STATUS 101
  #define SSH_FXP_HANDLE 102
  #define SSH_FXP_DATA 103
  #define SSH_FXP_NAME 104
  #define SSH_FXP_ATTRS 105
  #define SSH_FXP_EXTENDED 200
  #define SSH_FXP_EXTENDED_REPLY 201
  #define SSH_ACL_CAP_ALLOW 0x00000001
  #define SSH_ACL_CAP_DENY 0x00000002
  #define SSH_ACL_CAP_AUDIT 0x00000004
  #define SSH_ACL_CAP_ALARM 0x00000008
  #define SSH_ACL_CAP_INHERIT_ACCESS 0x00000010
  #define SSH_ACL_CAP_INHERIT_AUDIT_ALARM 0x00000020
  #define SSH_FILEXFER_ATTR_SIZE 0x00000001
  #define SSH_FILEXFER_ATTR_UIDGID 0x00000002
  #define SSH_FILEXFER_ATTR_PERMISSIONS 0x00000004
  #define SSH_FILEXFER_ATTR_ACCESSTIME 0x00000008
  #define SSH_FILEXFER_ACMODTIME 0x00000008
  #define SSH_FILEXFER_ATTR_CREATETIME 0x00000010
  #define SSH_FILEXFER_ATTR_MODIFYTIME 0x00000020
  #define SSH_FILEXFER_ATTR_ACL 0x00000040
  #define SSH_FILEXFER_ATTR_OWNERGROUP 0x00000080
  #define SSH_FILEXFER_ATTR_SUBSECOND_TIMES 0x00000100
  #define SSH_FILEXFER_ATTR_BITS 0x00000200
  #define SSH_FILEXFER_ATTR_ALLOCATION_SIZE 0x00000400
  #define SSH_FILEXFER_ATTR_TEXT_HINT 0x00000800
  #define SSH_FILEXFER_ATTR_MIME_TYPE 0x00001000
  #define SSH_FILEXFER_ATTR_LINK_COUNT 0x00002000
  #define SSH_FILEXFER_ATTR_UNTRANSLATED_NAME 0x00004000
  #define SSH_FILEXFER_ATTR_CTIME 0x00008000
  #define SSH_FILEXFER_ATTR_EXTENDED 0x80000000
  #define SSH_FILEXFER_TYPE_REGULAR 1
  #define SSH_FILEXFER_TYPE_DIRECTORY 2
  #define SSH_FILEXFER_TYPE_SYMLINK 3
  #define SSH_FILEXFER_TYPE_SPECIAL 4
  #define SSH_FILEXFER_TYPE_UNKNOWN 5
  #define SSH_FILEXFER_TYPE_SOCKET 6
  #define SSH_FILEXFER_TYPE_CHAR_DEVICE 7
  #define SSH_FILEXFER_TYPE_BLOCK_DEVICE 8
  #define SSH_FILEXFER_TYPE_FIFO 9
  #define SFX_ACL_CONTROL_INCLUDED 0x00000001
  #define SFX_ACL_CONTROL_PRESENT 0x00000002
  #define SFX_ACL_CONTROL_INHERITED 0x00000004
  #define SFX_ACL_AUDIT_ALARM_INCLUDED 0x00000010
  #define ACE4_ACCESS_ALLOWED_ACE_TYPE 0x00000000
  #define ACE4_ACCESS_DENIED_ACE_TYPE 0x00000001
  #define ACE4_SYSTEM_AUDIT_ACE_TYPE 0x00000002
  #define ACE4_SYSTEM_ALARM_ACE_TYPE 0x00000003
  #define ACE4_FILE_INHERIT_ACE 0x00000001
  #define ACE4_DIRECTORY_INHERIT_ACE 0x00000002
  #define ACE4_NO_PROPAGATE_INHERIT_ACE 0x00000004
  #define ACE4_INHERIT_ONLY_ACE 0x00000008
  #define ACE4_SUCCESSFUL_ACCESS_ACE_FLAG 0x00000010
  #define ACE4_FAILED_ACCESS_ACE_FLAG 0x00000020
  #define ACE4_IDENTIFIER_GROUP 0x00000040
  #define ACE4_READ_DATA 0x00000001
  #define ACE4_LIST_DIRECTORY 0x00000001
  #define ACE4_WRITE_DATA 0x00000002
  #define ACE4_ADD_FILE 0x00000002
  #define ACE4_APPEND_DATA 0x00000004
  #define ACE4_ADD_SUBDIRECTORY 0x00000004
  #define ACE4_READ_NAMED_ATTRS 0x00000008
  #define ACE4_WRITE_NAMED_ATTRS 0x00000010
  #define ACE4_EXECUTE 0x00000020
  #define ACE4_DELETE_CHILD 0x00000040
  #define ACE4_READ_ATTRIBUTES 0x00000080
  #define ACE4_WRITE_ATTRIBUTES 0x00000100
  #define ACE4_DELETE 0x00010000
  #define ACE4_READ_ACL 0x00020000
  #define ACE4_WRITE_ACL 0x00040000
  #define ACE4_WRITE_OWNER 0x00080000
  #define ACE4_SYNCHRONIZE 0x00100000
  #define SSH_FILEXFER_ATTR_FLAGS_READONLY 0x00000001
  #define SSH_FILEXFER_ATTR_FLAGS_SYSTEM 0x00000002
  #define SSH_FILEXFER_ATTR_FLAGS_HIDDEN 0x00000004
  #define SSH_FILEXFER_ATTR_FLAGS_CASE_INSENSITIVE 0x00000008
  #define SSH_FILEXFER_ATTR_FLAGS_ARCHIVE 0x00000010
  #define SSH_FILEXFER_ATTR_FLAGS_ENCRYPTED 0x00000020
  #define SSH_FILEXFER_ATTR_FLAGS_COMPRESSED 0x00000040
  #define SSH_FILEXFER_ATTR_FLAGS_SPARSE 0x00000080
  #define SSH_FILEXFER_ATTR_FLAGS_APPEND_ONLY 0x00000100
  #define SSH_FILEXFER_ATTR_FLAGS_IMMUTABLE 0x00000200
  #define SSH_FILEXFER_ATTR_FLAGS_SYNC 0x00000400
  #define SSH_FILEXFER_ATTR_FLAGS_TRANSLATION_ERR 0x00000800
  #define SSH_FILEXFER_ATTR_KNOWN_TEXT 0x00
  #define SSH_FILEXFER_ATTR_GUESSED_TEXT 0x01
  #define SSH_FILEXFER_ATTR_KNOWN_BINARY 0x02
  #define SSH_FILEXFER_ATTR_GUESSED_BINARY 0x03
  #define SSH_FXF_ACCESS_DISPOSITION 0x00000007
  #define SSH_FXF_CREATE_NEW 0x00000000
  #define SSH_FXF_CREATE_TRUNCATE 0x00000001
  #define SSH_FXF_OPEN_EXISTING 0x00000002
  #define SSH_FXF_OPEN_OR_CREATE 0x00000003
  #define SSH_FXF_TRUNCATE_EXISTING 0x00000004
  #define SSH_FXF_APPEND_DATA 0x00000008
  #define SSH_FXF_APPEND_DATA_ATOMIC 0x00000010
  #define SSH_FXF_TEXT_MODE 0x00000020
  #define SSH_FXF_BLOCK_READ 0x00000040
  #define SSH_FXF_BLOCK_WRITE 0x00000080
  #define SSH_FXF_BLOCK_DELETE 0x00000100
  #define SSH_FXF_BLOCK_ADVISORY 0x00000200
  #define SSH_FXF_NOFOLLOW 0x00000400
  #define SSH_FXF_DELETE_ON_CLOSE 0x00000800
  #define SSH_FXF_ACCESS_AUDIT_ALARM_INFO 0x00001000
  #define SSH_FXF_ACCESS_BACKUP 0x00002000
  #define SSH_FXF_BACKUP_STREAM 0x00004000
  #define SSH_FXF_OVERRIDE_OWNER 0x00008000
  #define SSH_FXF_RENAME_OVERWRITE 0x00000001
  #define SSH_FXF_RENAME_ATOMIC 0x00000002
  #define SSH_FXF_RENAME_NATIVE 0x00000004
  #define SSH_FXP_REALPATH_NO_CHECK 0x00000001
  #define SSH_FXP_REALPATH_STAT_IF 0x00000002
  #define SSH_FXP_REALPATH_STAT_ALWAYS 0x00000003
  
  #endif
  