updates.
[silc.git] / lib / silcsftp / sftp_util.h
1 /*
2
3   sftp_util.h 
4
5   Author: Pekka Riikonen <priikone@silcnet.org>
6
7   Copyright (C) 2001 Pekka Riikonen
8
9   This program is free software; you can redistribute it and/or modify
10   it under the terms of the GNU General Public License as published by
11   the Free Software Foundation; version 2 of the License.
12
13   This program is distributed in the hope that it will be useful,
14   but WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   GNU General Public License for more details.
17
18 */
19
20 #ifndef SFTP_UTIL_H
21 #define SFTP_UTIL_H
22
23 typedef uint32 SilcSFTPPacket;
24
25 /* SFTP packet types */
26 #define SILC_SFTP_INIT               1
27 #define SILC_SFTP_VERSION            2
28 #define SILC_SFTP_OPEN               3
29 #define SILC_SFTP_CLOSE              4
30 #define SILC_SFTP_READ               5
31 #define SILC_SFTP_WRITE              6
32 #define SILC_SFTP_LSTAT              7
33 #define SILC_SFTP_FSTAT              8
34 #define SILC_SFTP_SETSTAT            9
35 #define SILC_SFTP_FSETSTAT           10
36 #define SILC_SFTP_OPENDIR            11
37 #define SILC_SFTP_READDIR            12
38 #define SILC_SFTP_REMOVE             13
39 #define SILC_SFTP_MKDIR              14
40 #define SILC_SFTP_RMDIR              15
41 #define SILC_SFTP_REALPATH           16
42 #define SILC_SFTP_STAT               17
43 #define SILC_SFTP_RENAME             18
44 #define SILC_SFTP_READLINK           19
45 #define SILC_SFTP_SYMLINK            20
46 #define SILC_SFTP_STATUS             101
47 #define SILC_SFTP_HANDLE             102
48 #define SILC_SFTP_DATA               103
49 #define SILC_SFTP_NAME               104
50 #define SILC_SFTP_ATTRS              105
51 #define SILC_SFTP_EXTENDED           200
52 #define SILC_SFTP_EXTENDED_REPLY     201
53
54 /* SFTP attributes flags */
55 #define SILC_SFTP_ATTR_SIZE          0x00000001
56 #define SILC_SFTP_ATTR_UIDGID        0x00000002
57 #define SILC_SFTP_ATTR_PERMISSIONS   0x00000004
58 #define SILC_SFTP_ATTR_ACMODTIME     0x00000008
59 #define SILC_SFTP_ATTR_EXTENDED      0x80000000
60
61 /* Encodes a SFTP packet of type `packet' of length `len'. The variable
62    argument list is encoded as data payload to the buffer. Returns the
63    encoded packet or NULL on error. The caller must free the returned
64    buffer. */
65 SilcBuffer silc_sftp_packet_encode(SilcSFTPPacket packet, uint32 len, ...);
66
67 /* Same as silc_sftp_packet_encode but takes the variable argument list
68    pointer as argument. */
69 SilcBuffer silc_sftp_packet_encode_vp(SilcSFTPPacket packet, uint32 len, 
70                                       va_list vp);
71
72 /* Decodes the SFTP packet data `data' and return the SFTP packet type.
73    The payload of the packet is returned to the `payload' pointer. Returns
74    NULL if error occurred during decoding. */
75 SilcSFTPPacket silc_sftp_packet_decode(SilcBuffer packet,
76                                        unsigned char **payload,
77                                        uint32 *payload_len);
78
79 /* Encodes the SFTP attributes to a buffer and returns the allocated buffer.
80    The caller must free the buffer. */
81 SilcBuffer silc_sftp_attr_encode(SilcSFTPAttributes attr);
82
83 /* Decodes SilcSFTPAttributes from the buffer `buffer'. Returns the allocated
84    attributes that the caller must free or NULL on error. */
85 SilcSFTPAttributes silc_sftp_attr_decode(SilcBuffer buffer);
86
87 /* Frees the attributes context and its internals. */
88 void silc_sftp_attr_free(SilcSFTPAttributes attr);
89
90 /* Adds an entry to the `name' context. */
91 void silc_sftp_name_add(SilcSFTPName name, const char *short_name,
92                         const char *long_name, SilcSFTPAttributes attrs);
93
94 /* Encodes the SilcSFTPName to a buffer and returns the allocated buffer. 
95    The caller must free the buffer. */
96 SilcBuffer silc_sftp_name_encode(SilcSFTPName name);
97
98 /* Decodes a SilcSFTPName structure from the `buffer' that must include
99    `count' many name, longname and attribute values. Returns the allocated
100    structure or NULL on error. */
101 SilcSFTPName silc_sftp_name_decode(uint32 count, SilcBuffer buffer);
102
103 /* Frees the name context and its internals. */
104 void silc_sftp_name_free(SilcSFTPName name);
105
106 /* Maps errno to SFTP status message. */
107 SilcSFTPStatus silc_sftp_map_errno(int err);
108
109 #endif /* SFTP_UTIL_H */