/home/dcp1990/prog/fakedbfs/include/fakedbfs/fakedbfs.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2005-2006, Dan Ponte
00003  *
00004  * fakedbfs.h - main header
00005  * 
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions
00008  * are met:
00009  * 1. Redistributions of source code must retain the above copyright
00010  *    notice, this list of conditions and the following disclaimer.
00011  * 2. Redistributions in binary form must reproduce the above copyright
00012  *    notice, this list of conditions and the following disclaimer in the
00013  *    documentation and/or other materials provided with the distribution.
00014  * 4. Neither the name of the author nor the names of his contributors
00015  *    may be used to endorse or promote products derived from this software
00016  *    without specific prior written permission.
00017  *
00018  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
00019  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
00022  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00023  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00024  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00025  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00026  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00027  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00028  * SUCH DAMAGE.
00029  */
00034 /* $Amigan: fakedbfs/include/fakedbfs/fakedbfs.h,v 1.77 2006/04/19 19:58:22 dcp1990 Exp $ */
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" /* major changes with major incompat changes, minor with minor incompat, micro with additions, bugfixes, and security fixes */
00066 #define VERNAME "Doctor Wu" /* this changes for each release */
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 /* LINTLIBRARY */
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     /* set if we need to do an mmap (only for stuff that supports this! */
00094 #define FIELDS_FLAG_LASTDEF     0x2     /* used in the indexer to keep track of what it can and cannot free */
00095 
00096 
00097 
00098 
00099 struct PluginInfo {
00100         const char *extensions; /* a list of file extensions, not including dots, that
00101                                 this plugin handles. Each extension is separated
00102                                 by a slash character. (since it cannot occur in a filename)
00103                                 Note that this isn't required, but if a file's extension is in
00104                                 the list, the plugin will be given priority,
00105                                 thereby speeding up searches (check_file() is
00106                                 always called, however).
00107                           */
00108         const char *pluginname; /* the name of the plugin; self-explanatory */
00109         const char *version; /* the version of the plugin */
00110         const char *author; /* author (usually name and email address) */
00111         const char *website; /* website of plugin */
00112         const int majapi; /* major API version; this changes when incompatible changes
00113                         are made to the API. This should always be set to the
00114                         define MAJOR_API_VERSION.
00115                     */
00116         const int minapi; /* minor API version; this changes for backwards-compatible
00117                         changes. This should be set to MINOR_API_VERSION.
00118                     */
00119 };      /*
00120         note that this structure will stay fairly consistent, at least for the
00121         first elements listed here. Another words: plugin_inf.majapi should
00122         always refer to the same object, even across major API changes.
00123         */
00124 
00125 
00126 #define DEBUGFUNC_STDERR ((void(*)(char*, enum ErrorAction))0)
00127 #define AFFPROTO (answer_t * /* buffer */, answer_t * /* default */, const char * /*fieldname*/, const char * /* unformatted name */, \
00128                         const char * /* filename */, enum DataType, struct EnumHead * /* if oenum */, struct EnumSubElem * /* if sub */)
00129 #define ASKFUNC_STD ((answer_t*(*)AFFPROTO)0)
00130 
00131 union _ansdata {
00132         char *string; /* this and vd will be free()d if they aren't NULL, no exceptions. Hence, make them dynamic. */
00133         int integer; /* applies to enums and subenums as well */
00134         long long linteger; /* long integer */
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; /* current query; must be reset on each exec/step */
00163         struct Plugin *plugins;
00164         void (*debugfunc)(char*, enum ErrorAction);
00165         answer_t *(*askfieldfunc) AFFPROTO; /* returns status: 0 means no change, 1 means change, -1 means error */
00166         Heads heads;
00167         actcat_t *catsh;
00168         ficlSystem *fsys;
00169         ficlstate_t fst;
00170         confnode_t *rconf;
00171         struct reg_functype reg_norm; /* hack! oh well. */
00172         struct reg_functype reg_negated;
00173 };
00174 
00175 /* crawler stuff */
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; /* max levels before we just start doing a depth traversal rather than a breadth */
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; /* this is stack of POINTERS to crawlframes, not of crawlframes themselves! */
00200         crawlframe_t **sp; /* *sp is the object, sp is what we deal with */
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 /* error; curframe null? */
00222 #define CRAWL_FILE      0x1 /* found a file; act upon it */
00223 #define CRAWL_DIR       0x2 /* found a directory; rerun crawl_go() to find the next entry */
00224 #define CRAWL_FINISHED  0x3 /* we've hit the bottom; give up */
00225 
00226 /* flags */
00227 #define CRAWL_DIE_ON_ERROR      0x1
00228 
00229 
00230 /* end crawler */
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 /* misc string functions */
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 /* crawl stuff -- will move to own file when we can*/
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); /* simply adds dir to the base frame */
00355 
00356 
00357 

Generated on Wed Apr 19 16:26:23 2006 for fakedbfs by  doxygen 1.4.6