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
00028
00029
00034
00035 #include <fakedbfs/types.h>
00036
00037 #include <fakedbfs/fdbfsconfig.h>
00038 #ifndef _SQLITE3_H_
00039 #include <sqlite3.h>
00040 #endif
00041 #include <fakedbfs/conf.h>
00042 #ifndef HAVE_DBSPECDATA_H
00043 #include <fakedbfs/dbspecdata.h>
00044 #endif
00045 #ifndef HAVE_QUERY_H
00046 #include <fakedbfs/query.h>
00047 #endif
00048 #if defined(DMALLOC) && !defined(NODMALLOC)
00049 #include "dmalloc.h"
00050 #endif
00051
00052 #ifdef HAVE_FICL_H
00053 #include <ficl.h>
00054 #endif
00055
00056 #define ERR(act, fmt, ...) fdbfs_ferr(f, act, fmt, __VA_ARGS__)
00057 #define SERR(act, fmt) fdbfs_ferr(f, act, fmt)
00058 #define CERR(act, fmt, ...) fdbfs_cferr(f, act, fmt, __VA_ARGS__)
00059 #define SCERR(act, fmt) fdbfs_cferr(f, act, fmt)
00060 #define _unused __attribute__((__unused__))
00061
00062 #define MAJOR_API_VERSION 2
00063 #define MINOR_API_VERSION 0
00064
00065 #define FAKEDBFSVER "2.0.0"
00066 #define VERNAME "Doctor Wu"
00067 #define FAKEDBFSMAJOR 2
00068 #define FAKEDBFSMINOR 0
00069 #define FAKEDBFSMICRO 0
00070
00071
00072 #ifndef lint
00073 #define RCSID(str) static const char _cvsid[] __unused = str;
00074 #else
00075 #define RCSID(str) ;
00076 #endif
00077
00078 #define DELIMCHAR "|"
00079 #define FDBFSDIR ".fdbfs"
00080 #define FDBFSPLUGENV "FDBFSPLUGPATH"
00081
00082 #ifdef lint
00083
00084 #endif
00085
00086 #if !defined(ISLEX) && defined(FREEDEBUG) && !defined(DMALLOC)
00087 #undef free
00088 #define free(x) printf("fr %p (%s:%d)\n", x, __FILE__, __LINE__); free(x)
00089 #endif
00090
00091
00092
00093 #define FIELDS_FLAG_MMAPED 0x1
00094 #define FIELDS_FLAG_LASTDEF 0x2
00095
00096
00097
00098
00099 struct PluginInfo {
00100 const char *extensions;
00101
00102
00103
00104
00105
00106
00107
00108 const char *pluginname;
00109 const char *version;
00110 const char *author;
00111 const char *website;
00112 const int majapi;
00113
00114
00115
00116 const int minapi;
00117
00118
00119 };
00120
00121
00122
00123
00124
00125
00126 #define DEBUGFUNC_STDERR ((void(*)(char*, enum ErrorAction))0)
00127 #define AFFPROTO (answer_t * , answer_t * , const char * , const char * , \
00128 const char * , enum DataType, struct EnumHead * , struct EnumSubElem * )
00129 #define ASKFUNC_STD ((answer_t*(*)AFFPROTO)0)
00130
00131 union _ansdata {
00132 char *string;
00133 int integer;
00134 long long linteger;
00135 FLOATTYPE fp;
00136 void *vd;
00137 };
00138
00139 struct _answer {
00140 enum DataType dt;
00141 ansdata_t ad;
00142 size_t len;
00143 };
00144
00145 struct _actcat {
00146 char *name;
00147 char *alias;
00148 struct CatalogueHead *def;
00149 actcat_t *next;
00150 };
00151
00152 struct reg_functype {
00153 fdbfs_t *f;
00154 short negated;
00155 };
00156
00157 struct _fdbfs {
00158 char *dbname;
00159 sqlite3 *db;
00160 error_t error;
00161 config_t conf;
00162 query_t *curq;
00163 struct Plugin *plugins;
00164 void (*debugfunc)(char*, enum ErrorAction);
00165 answer_t *(*askfieldfunc) AFFPROTO;
00166 Heads heads;
00167 actcat_t *catsh;
00168 ficlSystem *fsys;
00169 ficlstate_t fst;
00170 confnode_t *rconf;
00171 struct reg_functype reg_norm;
00172 struct reg_functype reg_negated;
00173 };
00174
00175
00176 struct _file_id {
00177 #if defined(UNIX)
00178 int filenum;
00179 int devnum;
00180 #endif
00181 char *filename;
00182 };
00183
00184 struct _crawl {
00185 crawlframe_t *topframe;
00186 crawlframe_t *curframe;
00187 fdbfs_t *f;
00188 int maxlevels;
00189 int mlbefdep;
00190 };
00191
00192 struct DirState {
00193 #if defined(UNIX) && defined(HAVE_DIR_H)
00194 DIR *dir;
00195 #endif
00196 };
00197
00198 struct _crawlframe {
00199 crawlframe_t **stack;
00200 crawlframe_t **sp;
00201 crawlframe_t **stop;
00202 int maxelements;
00203 int cindex;
00204 file_id_t oid;
00205 struct DirState ds;
00206 int level;
00207 crawlframe_t *parent;
00208 crawl_t *fajah;
00209 };
00210
00211 struct _dspdata {
00212 fdbfs_t *f;
00213 char *yytext;
00214 int error;
00215 struct CatalogueHead *cat;
00216 fields_t *fhead;
00217 fields_t *lastf;
00218 fields_t *cf;
00219 };
00220
00221 #define CRAWL_ERROR 0x0
00222 #define CRAWL_FILE 0x1
00223 #define CRAWL_DIR 0x2
00224 #define CRAWL_FINISHED 0x3
00225
00226
00227 #define CRAWL_DIE_ON_ERROR 0x1
00228
00229
00230
00231
00232 #ifdef NO_CALLOC
00233 void* allocz(size_t size);
00234 #else
00235 #define allocz(x) calloc(1, x)
00236 #endif
00237
00245 void fdbfs_set_aff(fdbfs_t *f, answer_t *(*aff)AFFPROTO);
00246
00257 fdbfs_t *fdbfs_new(const char *dbfile, char **error, void (*debugf)(char*, enum ErrorAction), int useplugins);
00258
00266 int fdbfs_destroy(fdbfs_t *f);
00267
00275 int fdbfs_read_specs_from_db(fdbfs_t *f);
00276
00277
00278
00285 char* fdbfs_normalise(const char *s);
00286
00293 size_t fdbfs_number_size(unsigned int n);
00294
00301 size_t fdbfs_signed_size(int n);
00302
00303 answer_t* fdbfs_askfunc_std AFFPROTO;
00304
00312 char* fdbfs_strdupq(const char *s);
00313
00320 char* fdbfs_fstrdup(const char *str);
00321
00331 int fdbfs_create_catalogue(fdbfs_t *f, const char *name, const char *alias, const char *cname);
00332
00339 int fdbfs_cat_type_exists(fdbfs_t *f, const char *ct);
00340
00348 actcat_t* fdbfs_find_catalogue(fdbfs_t *f, const char *name);
00349
00350
00351
00352 crawl_t* fdbfs_crawler_new(fdbfs_t *f, int mlevels, int mlbd);
00353 void fdbfs_crawler_destroy(crawl_t *cr);
00354 int fdbfs_crawl_dir(crawl_t *cr, const char *dir);
00355
00356
00357