RSS

(root)/fsp/fsplib : /fsplib.h (revision 61)

Line Revision Contents
1 15 #ifndef _FSPLIB_H
2 #define _FSPLIB_H 1
3 #include <time.h>
4 22 #include <dirent.h>
5 #include <sys/stat.h>
6 39 #include <stddef.h>
7
8 15 /* The FSP v2 protocol support library - public interface */
9 2
10 6 /*
11 This file is part of fsplib - FSP protocol stack implemented in C
12 language. See http://fsp.sourceforge.net for more information.
13
14 32 Copyright (c) 2003-2005 by Radim HSN Kolar (hsn@sendmail.cz)
15 6
16 You may copy or modify this file in any manner you wish, provided
17 that this notice is always included, and that you hold the author
18 harmless for any loss or damage resulting from the installation or
19 use of this software.
20
21 10                      This is a free software.  Be creative.
22                     Let me know of any bugs and suggestions.
23 6 */
24
25 2 /* definition of FSP protocol v2 commands */
26
27 10 #define FSP_CC_VERSION      0x10    /* return server's version string.      */
28 #define FSP_CC_INFO         0x11    /* return server's extended info block  */
29 2 #define FSP_CC_ERR          0x40    /* error response from server.          */
30 #define FSP_CC_GET_DIR      0x41    /* get a directory listing.             */
31 #define FSP_CC_GET_FILE     0x42    /* get a file.                          */
32 #define FSP_CC_UP_LOAD      0x43    /* open a file for writing.             */
33 #define FSP_CC_INSTALL      0x44    /* close a file opened for writing.     */
34 #define FSP_CC_DEL_FILE     0x45    /* delete a file.                       */
35 #define FSP_CC_DEL_DIR      0x46    /* delete a directory.                  */
36 #define FSP_CC_GET_PRO      0x47    /* get directory protection.            */
37 #define FSP_CC_SET_PRO      0x48    /* set directory protection.            */
38 #define FSP_CC_MAKE_DIR     0x49    /* create a directory.                  */
39 #define FSP_CC_BYE          0x4A    /* finish a session.                    */
40 10 #define FSP_CC_GRAB_FILE    0x4B    /* atomic get+delete a file.            */
41 #define FSP_CC_GRAB_DONE    0x4C    /* atomic get+delete a file done.       */
42 2 #define FSP_CC_STAT         0x4D    /* get information about file.          */
43 #define FSP_CC_RENAME       0x4E    /* rename file or directory.            */
44 #define FSP_CC_CH_PASSWD    0x4F    /* change password                      */
45 #define FSP_CC_LIMIT        0x80    /* # > 0x7f for future cntrl blk ext.   */
46 10 #define FSP_CC_TEST         0x81    /* reserved for testing                 */
47 2
48 6 /* FSP v2 packet size */
49 2 #define FSP_HSIZE 12                           /* 12 bytes for v2 header */
50 10 #define FSP_SPACE 1024                         /* maximum payload.       */
51 #define FSP_MAXPACKET   FSP_HSIZE+FSP_SPACE    /* maximum packet size.   */
52 6
53 /* byte offsets of fields in the FSP v2 header */
54 10 #define FSP_OFFSET_CMD          0
55 #define FSP_OFFSET_SUM          1
56 #define FSP_OFFSET_KEY          2
57 #define FSP_OFFSET_SEQ          4
58 #define FSP_OFFSET_LEN          6
59 #define FSP_OFFSET_POS          8
60
61 /* types of directory entry */ 
62 #define FSP_RDTYPE_END      0x00
63 #define FSP_RDTYPE_FILE     0x01
64 #define FSP_RDTYPE_DIR      0x02
65 15 #define FSP_RDTYPE_LINK     0x03
66 10 #define FSP_RDTYPE_SKIP     0x2A
67 6
68 13 /* definition of directory bitfield for directory information */
69 /* directory information is just going to be a bitfield encoding
70  * of which protection bits are set/unset
71  */
72
73 #define FSP_PRO_BYTES   1       /* currently only 8 bits or less of info  */
74 #define FSP_DIR_OWNER   0x01    /* does caller own directory              */
75 #define FSP_DIR_DEL     0x02    /* can files be deleted from this dir     */
76 #define FSP_DIR_ADD     0x04    /* can files be added to this dir         */
77 #define FSP_DIR_MKDIR   0x08    /* can new subdirectories be created      */
78 #define FSP_DIR_GET     0x10    /* are files readable by non-owners?      */
79 #define FSP_DIR_README  0x20    /* does this dir contain an readme file?  */
80 #define FSP_DIR_LIST    0x40    /* public can list directory              */
81 #define FSP_DIR_RENAME  0x80    /* can files be renamed in this dir       */
82  
83 6 /* decoded FSP packet */
84 typedef struct FSP_PKT {
85                         unsigned char       cmd; /* message code.             */
86 2                         unsigned char       sum; /* message checksum.         */
87                         unsigned short      key; /* message key.              */
88                         unsigned short      seq; /* message sequence number.  */
89                         unsigned short      len; /* number of bytes in buf 1. */
90 10                         unsigned int        pos; /* location in the file.     */                        unsigned short     xlen; /* number of bytes in buf 2  */
91 6
92 10                         unsigned char   buf[FSP_SPACE];   /* packet payload */
93 6               } FSP_PKT;
94
95 /* FSP host:port */
96 typedef struct FSP_SESSION {
97 15                         void *   lock;            /* key locking         */
98 12                         unsigned int   timeout;   /* send timeout 1/1000s*/
99 13                         unsigned int   maxdelay;  /* maximum recv. delay */
100 10                         unsigned short seq;       /* sequence number     */
101                         unsigned int dupes;       /* total pkt. dupes    */
102                         unsigned int resends;     /* total pkt. sends    */
103                         unsigned int trips;       /* total pkt trips     */
104                         unsigned long rtts;       /* cumul. rtt          */
105                         unsigned int last_rtt;    /* last rtt            */
106                         unsigned int last_delay;  /* last delay time     */
107 15                         unsigned int last_dupes;  /* last dupes          */
108                         unsigned int last_resends;/* last resends        */
109                         int fd;                   /* i/o descriptor      */
110 10                         char *password;           /* host acccess password */
111                 } FSP_SESSION;
112 13
113 10 /* fsp directory handle */
114 typedef struct FSP_DIR {
115                         char   *dirname;          /* directory name */
116                         short   inuse;            /* in use counter */
117                         int     dirpos;           /* current directory pos. */
118                         unsigned short blocksize; /* size of directory block */
119                         unsigned char  *data;     /* raw directory data */
120                         unsigned int   datasize;  /* size of raw dir. data */
121 } FSP_DIR;
122
123 /* fsp directory entry */
124 typedef struct FSP_RDENTRY  {
125                        char name[255 + 1];        /* entry name */
126                        unsigned short namlen;     /* length     */
127                        unsigned char type;        /* field type */
128                        unsigned short reclen;     /* directory record length */
129                        unsigned int  size;
130                        unsigned int  lastmod;
131 } FSP_RDENTRY;
132
133 /* fsp file handle */
134 typedef struct FSP_FILE {
135                       FSP_PKT in,out;            /* io packets */
136                       FSP_SESSION *s;            /* master session */
137                       char *name;                /* filename for upload */
138                       unsigned char writing;     /* opened for writing */
139                       unsigned char eof;         /* EOF reached? */
140                       unsigned char err;         /* i/o error? */
141                       int bufpos;                /* position in buffer */
142                       unsigned int pos;          /* position of next packet */
143 } FSP_FILE;
144
145 39
146 typedef union dirent_workaround {
147       struct dirent dirent;
148       char fill[offsetof (struct dirent, d_name) + MAXNAMLEN + 1];
149 } dirent_workaround;
150  
151 10 /* function prototypes */
152
153 /* session management */
154 FSP_SESSION * fsp_open_session(const char *host,unsigned short port, const char *password);
155 void fsp_close_session(FSP_SESSION *s);
156
157 /* packet encoding/decoding */
158 6 size_t fsp_pkt_write(const FSP_PKT *p,void *space);
159 int fsp_pkt_read(FSP_PKT *p,const void *space,size_t recv_len);
160 10
161 /* send/receive round-trip */
162 int fsp_transaction(FSP_SESSION *s,FSP_PKT *p,FSP_PKT *rpkt);
163
164 /* directory listing commands */
165 FSP_DIR * fsp_opendir(FSP_SESSION *s,const char *dirname);
166 int fsp_readdir_r(FSP_DIR *dir,struct dirent *entry, struct dirent **result);
167 long fsp_telldir(FSP_DIR *dirp);
168 void fsp_seekdir(FSP_DIR *dirp, long loc);
169 void fsp_rewinddir(FSP_DIR *dirp);
170 struct dirent * fsp_readdir(FSP_DIR *dirp);
171 int fsp_readdir_native(FSP_DIR *dir,FSP_RDENTRY *entry, FSP_RDENTRY **result);
172 int fsp_closedir(FSP_DIR *dirp);
173 /* high level  file i/o */
174 FSP_FILE * fsp_fopen(FSP_SESSION *session, const char *path,const char *modeflags);
175 size_t fsp_fread(void *ptr,size_t size,size_t nmemb,FSP_FILE *file);
176 size_t fsp_fwrite(const void * source, size_t size, size_t count, FSP_FILE * file);
177 int fsp_fclose(FSP_FILE *file);
178 int fsp_fpurge(FSP_FILE *file);
179 int fsp_fflush(FSP_FILE *file);
180 int fsp_fseek(FSP_FILE *stream, long offset, int whence);
181 long fsp_ftell(FSP_FILE *f);
182 void fsp_rewind(FSP_FILE *f);
183 /* misc. functions */
184 int fsp_stat(FSP_SESSION *s,const char *path,struct stat *sb);
185 int fsp_mkdir(FSP_SESSION *s,const char *directory);
186 int fsp_rmdir(FSP_SESSION *s,const char *directory);
187 int fsp_unlink(FSP_SESSION *s,const char *directory);
188 13 int fsp_rename(FSP_SESSION *s,const char *from, const char *to);
189 int fsp_access(FSP_SESSION *s,const char *path, int mode);
190 /* fsp protocol specific functions */
191 int fsp_getpro(FSP_SESSION *s,const char *directory,unsigned char *result);
192 int fsp_install(FSP_SESSION *s,const char *fname,time_t timestamp);
193 int fsp_canupload(FSP_SESSION *s,const char *fname);
194 15 #endif

Loggerhead is a web-based interface for Bazaar branches