From 545e490d1b044e8453c54a62b64e4da0d12bee65 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Sat, 20 Apr 2002 14:37:39 +0000 Subject: [PATCH] Added support for indexing/searching by custom attributes. See the CUSTOM_ATTRS macro in lib/custom.h for an explanation. --- lib/Makefile | 2 +- lib/config.h | 7 +++++-- lib/custom.c | 32 ++++++++++++++++++++++++++++++++ lib/custom.h | 43 ++++++++++++++++++++++++++++++++++++------- lib/index.h | 5 ++++- 5 files changed, 78 insertions(+), 11 deletions(-) create mode 100644 lib/custom.c diff --git a/lib/Makefile b/lib/Makefile index 2c93e1cf..6c8ec220 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -8,7 +8,7 @@ SHLIB_OBJS=alloc.o alloc_str.o ctmatch.o db.o fastbuf.o fb-file.o fb-mem.o lists prime.o random.o realloc.o regex.o timer.o url.o wildmatch.o \ wordsplit.o str_ctype.o str_upper.o bucket.o conf.o object.o sorter.o \ finger.o proctitle.o ipaccess.o profile.o bitsig.o randomkey.o \ - hash-string.o hash-istring.o + hash-string.o hash-istring.o custom.o obj/lib/libsh.a: $(addprefix obj/lib/,$(SHLIB_OBJS)) diff --git a/lib/config.h b/lib/config.h index 66cc25a0..0cee3ffe 100644 --- a/lib/config.h +++ b/lib/config.h @@ -7,10 +7,9 @@ #ifndef _SHERLOCK_CONFIG_H #define _SHERLOCK_CONFIG_H -/* Custom configuration */ +/* Configuration switches */ #include "lib/autoconf.h" -#include "lib/custom.h" /* Version */ @@ -42,6 +41,10 @@ typedef unsigned int sh_time_t; /* Timestamp */ typedef u32 oid_t; /* Object ID */ +/* Custom stuff */ + +#include "lib/custom.h" + /* Data types and functions for accessing file positions */ #ifdef SHERLOCK_CONFIG_LARGE_DB diff --git a/lib/custom.c b/lib/custom.c new file mode 100644 index 00000000..cba8412a --- /dev/null +++ b/lib/custom.c @@ -0,0 +1,32 @@ +/* + * Sherlock: Custom Parts of Configuration + * + * (c) 2001--2002 Martin Mares + */ + +#include "lib/lib.h" +#include "lib/index.h" + +#include + +#if 0 /* Example */ + +void +custom_get_lm(struct card_attr *ca, byte *attr) +{ + if (attr) + ca->lm = atol(attr); + else + ca->lm = 0; +} + +byte * +custom_parse_lm(u32 *dest, byte *value, uns intval) +{ + if (value) + return "LM is an integer, not a string"; + *dest = intval; + return NULL; +} + +#endif diff --git a/lib/custom.h b/lib/custom.h index 2244dd84..f4a57115 100644 --- a/lib/custom.h +++ b/lib/custom.h @@ -1,19 +1,13 @@ /* * Sherlock: Custom Parts of Configuration * - * (c) 2001 Martin Mares + * (c) 2001--2002 Martin Mares */ /* Name of this customization (version suffix) */ #define SHER_SUFFIX "" -/* Features */ - -#define SHERLOCK_CONFIG_LARGE_DB /* Support for DB files >4GB */ -#define SHERLOCK_CONFIG_LFS /* Large files on 32-bit systems */ -#define SHERLOCK_CONFIG_LFS_LIBC /* LFS supported directly by libc */ - /* Word types */ enum word_type { @@ -84,3 +78,38 @@ enum string_type { #define STRING_TYPES_URL ((1 << ST_URL) | (1 << ST_REF) | (1 << ST_BACKREF)) /* These must be indexed in lowercase form */ #define STRING_TYPES_CASE_INSENSITIVE ((1 << ST_HOST) | (1 << ST_DOMAIN)) + +/* + * Definitions of custom attributes: + * + * INT_ATTR(type, id, oattr, keyword, get_func, parse_func) + * + * type data type used to hold the value + * id C identifier of the attribute + * oattr object attribute we get the value from + * keywd search server keyword for the attribute + * void get_func(struct card_attr *ca, byte *attr) + * parse object attribute (may be NULL) + * byte *parse_func(u32 *dest, byte *value, uns intval) + * parse value in query (returns error message or NULL) + * for KEYWD = "string", it gets value="string", intval=0 + * for KEYWD = num, it gets value=NULL, intval=num. + * + * A good place for definitions of the functions is lib/custom.c. + * + * Please order the attributes by decreasing size to get optimum padding. + */ + +#if 0 /* Example */ + +#define CUSTOM_ATTRS INT_ATTR(u32, lm, 'L', LM, custom_get_lm, custom_parse_lm) + +struct card_attr; +void custom_get_lm(struct card_attr *ca, byte *attr); +byte *custom_parse_lm(u32 *dest, byte *value, uns intval); + +#else + +#define CUSTOM_ATTRS + +#endif diff --git a/lib/index.h b/lib/index.h index 0bd9a635..dc8dab1a 100644 --- a/lib/index.h +++ b/lib/index.h @@ -15,9 +15,12 @@ struct card_attr { u32 card; /* Reference to card description (either oid or filepos) */ u32 site_id; +#define INT_ATTR(t,i,o,k,g,p) t i; + CUSTOM_ATTRS /* Include all custom attributes */ +#undef INT_ATTR byte weight; byte flags; - byte rfu[2]; + // byte rfu[2]; /* If no custom attributes are defined */ }; enum card_flag { -- 2.39.2