00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef _EGG_MOD_FILESYS_FILEDB3_H
00028 #define _EGG_MOD_FILESYS_FILEDB3_H
00029
00030
00031 typedef struct {
00032 char version;
00033 time_t timestamp;
00034 } filedb_top;
00035
00036
00037 typedef struct {
00038 time_t uploaded;
00039 unsigned int size;
00040 unsigned short int stat;
00041 unsigned short int gots;
00042 unsigned short int filename_len;
00043 unsigned short int desc_len;
00044 unsigned short int sharelink_len;
00045 unsigned short int chan_len;
00046 unsigned short int uploader_len;
00047 unsigned short int flags_req_len;
00048 unsigned short int buffer_len;
00049 } filedb_header;
00050
00051
00052
00053
00054 typedef struct {
00055 time_t uploaded;
00056 unsigned int size;
00057 unsigned short int stat;
00058 unsigned short int gots;
00059 unsigned short int _type;
00060
00061
00062
00063
00064
00065 long pos;
00066 unsigned short int dyn_len;
00067 unsigned short int buf_len;
00068
00069 char *filename;
00070 char *desc;
00071 char *sharelink;
00072
00073 char *chan;
00074 char *uploader;
00075 char *flags_req;
00076 } filedb_entry;
00077
00078
00079
00080
00081
00082
00083 #define my_free(ptr) \
00084 if (ptr) { \
00085 nfree(ptr); \
00086 ptr = NULL; \
00087 }
00088
00089
00090
00091
00092
00093 #define malloc_strcpy(target, entry) \
00094 do { \
00095 if (entry) { \
00096 (target) = nrealloc((target), strlen(entry) + 1); \
00097 strcpy((target), (entry)); \
00098 } else \
00099 my_free(target); \
00100 } while (0)
00101
00102 #define malloc_strcpy_nocheck(target, entry) \
00103 do { \
00104 (target) = nrealloc((target), strlen(entry) + 1); \
00105 strcpy((target), (entry)); \
00106 } while (0)
00107
00108
00109 #define filedb_tot_dynspace(fdh) ((fdh).filename_len + (fdh).desc_len + \
00110 (fdh).chan_len + (fdh).uploader_len + (fdh).flags_req_len + \
00111 (fdh).sharelink_len)
00112
00113 #define filedb_zero_dynspace(fdh) { \
00114 (fdh).filename_len = 0; \
00115 (fdh).desc_len = 0; \
00116 (fdh).chan_len = 0; \
00117 (fdh).uploader_len = 0; \
00118 (fdh).flags_req_len = 0; \
00119 (fdh).sharelink_len = 0; \
00120 }
00121
00122
00123 #define malloc_fdbe() _malloc_fdbe(__FILE__, __LINE__)
00124 #define filedb_getfile(fdb, pos, get) _filedb_getfile(fdb, pos, get, __FILE__, __LINE__)
00125 #define filedb_matchfile(fdb, pos, match) _filedb_matchfile(fdb, pos, match, __FILE__, __LINE__)
00126 #define filedb_updatefile(fdb, pos, fdbe, update) _filedb_updatefile(fdb, pos, fdbe, update, __FILE__, __LINE__)
00127 #define filedb_addfile(fdb, fdbe) _filedb_addfile(fdb, fdbe, __FILE__, __LINE__)
00128 #define filedb_movefile(fdb, pos, fdbe) _filedb_movefile(fdb, pos, fdbe, __FILE__, __LINE__)
00129
00130
00131
00132
00133
00134
00135 #define FILEDB_VERSION1 0x0001
00136 #define FILEDB_VERSION2 0x0002
00137 #define FILEDB_VERSION3 0x0003
00138 #define FILEDB_NEWEST_VER FILEDB_VERSION3
00139
00140 #define POS_NEW 0
00141
00142
00143 #define FILE_UNUSED 0x0001
00144 #define FILE_DIR 0x0002
00145 #define FILE_SHARE 0x0004
00146 #define FILE_HIDDEN 0x0008
00147 #define FILE_ISLINK 0x0010
00148
00149 #define FILEDB_ESTDYN 50
00150
00151 enum {
00152 GET_HEADER,
00153 GET_FILENAME,
00154 GET_FULL,
00155
00156 UPDATE_HEADER,
00157 UPDATE_SIZE,
00158 UPDATE_ALL,
00159
00160 TYPE_NEW,
00161 TYPE_EXIST
00162 };
00163
00164
00165
00166
00167
00168
00169 static void free_fdbe(filedb_entry **);
00170 static filedb_entry *_malloc_fdbe(char *, int);
00171 static int filedb_readtop(FILE *, filedb_top *);
00172 static int filedb_writetop(FILE *, filedb_top *);
00173 static int filedb_delfile(FILE *, long);
00174 static filedb_entry *filedb_findempty(FILE *, int);
00175 static int _filedb_updatefile(FILE *, long, filedb_entry *, int, char *, int);
00176 static int _filedb_movefile(FILE *, long, filedb_entry *, char *, int);
00177 static int _filedb_addfile(FILE *, filedb_entry *, char *, int);
00178 static filedb_entry *_filedb_getfile(FILE *, long, int, char *, int);
00179 static filedb_entry *_filedb_matchfile(FILE *, long, char *, char *, int);
00180 static filedb_entry *filedb_getentry(char *, char *);
00181
00182 #endif