--- exim-4.50/src/functions.h.lookup1 2005-02-17 14:49:11.000000000 +0000 +++ exim-4.50/src/functions.h 2005-02-27 15:54:13.000000000 +0000 @@ -233,10 +233,10 @@ extern void route_tidyup(void); extern uschar *search_find(void *, uschar *, uschar *, int, uschar *, int, int, int *); -extern int search_findtype(uschar *, int); -extern int search_findtype_partial(uschar *, int *, uschar **, int *, +extern struct lookup_info *search_findtype(uschar *, int); +extern struct lookup_info *search_findtype_partial(uschar *, int *, uschar **, int *, int *); -extern void *search_open(uschar *, int, int, uid_t *, gid_t *); +extern void *search_open(uschar *, struct lookup_info *, int, uid_t *, gid_t *); extern void search_tidyup(void); extern void set_process_info(char *, ...); extern void sha1_end(sha1 *, const uschar *, int, uschar *); --- exim-4.50/src/search.c.lookup1 2005-02-17 14:49:11.000000000 +0000 +++ exim-4.50/src/search.c 2005-02-27 15:56:59.000000000 +0000 @@ -63,7 +63,7 @@ Returns: +ve => valid lookup name; v -ve => invalid name; message in search_error_message. */ -int +struct lookup_info * search_findtype(uschar *name, int len) { int bot = 0; @@ -83,18 +83,18 @@ while (top > bot) if (c == 0 && Ustrlen(lookup_list[mid].name) == len) { - if (lookup_list[mid].find != NULL) return mid; + if (lookup_list[mid].find != NULL) return &lookup_list[mid]; search_error_message = string_sprintf("lookup type \"%.*s\" is not " "available (not in the binary - check buildtime LOOKUP configuration)", len, name); - return -1; + return NULL; } if (c > 0) bot = mid + 1; else top = mid; } search_error_message = string_sprintf("unknown lookup type \"%.*s\"",len,name); -return -1; +return NULL; } @@ -122,11 +122,12 @@ Returns: +ve => valid lookup name; v -ve => invalid name; message in search_error_message. */ -int +struct lookup_info * search_findtype_partial(uschar *name, int *ptypeptr, uschar **ptypeaff, int *afflen, int *starflags) { -int len, stype; +int len; +struct lookup_info *stype; int pv = -1; uschar *ss = name; @@ -165,7 +166,7 @@ if (Ustrncmp(name, "partial", 7) == 0) BAD_TYPE: search_error_message = string_sprintf("format error in lookup type \"%s\"", name); - return -1; + return NULL; } } @@ -191,7 +192,7 @@ if (pv >= 0 && mac_islookup(stype, looku { search_error_message = string_sprintf("\"partial\" is not permitted " "for lookup type \"%s\"", ss); - return -1; + return NULL; } /* All is well; pass back the partial type and return the lookup type. */ @@ -229,8 +230,8 @@ if (t->left != NULL) tidyup_subtree(t->l if (t->right != NULL) tidyup_subtree(t->right); if (c != NULL && c->handle != NULL && - lookup_list[c->search_type].close != NULL) - lookup_list[c->search_type].close(c->handle); + c->search_type->close != NULL) + c->search_type->close(c->handle); } @@ -321,14 +322,13 @@ Returns: an identifying handle f */ void * -search_open(uschar *filename, int search_type, int modemask, uid_t *owners, +search_open(uschar *filename, struct lookup_info *lk, int modemask, uid_t *owners, gid_t *owngroups) { void *handle; tree_node *t; search_cache *c; -lookup_info *lk = lookup_list + search_type; -uschar keybuffer[256]; +uschar keybuffer[256+(2*sizeof(void *))]; int old_pool = store_pool; /* Change to the search store pool and remember our reset point */ @@ -340,11 +340,11 @@ DEBUG(D_lookup) debug_printf("search_ope (filename == NULL)? US"NULL" : filename); /* See if we already have this open for this type of search, and if so, -pass back the tree block as the handle. The key for the tree node is the search -type plus '0' concatenated with the file name. There may be entries in the tree -with closed files if a lot of files have been opened. */ +pass back the tree block as the handle. The key for the tree node is the +address of the search_info concatenated with the file name. There may be +entries in the tree with closed files if a lot of files have been opened. */ -sprintf(CS keybuffer, "%c%.254s", search_type + '0', +sprintf(CS keybuffer, "%p%.255s", lk, (filename == NULL)? US"" : filename); if ((t = tree_search(search_tree, keybuffer)) != NULL) @@ -380,7 +380,7 @@ if (lk->type == lookup_absfile && open_f ((search_cache *)(open_bot->data.ptr))->down = NULL; else open_top = NULL; - ((lookup_list + c->search_type)->close)(c->handle); + (c->search_type->close)(c->handle); c->handle = NULL; open_filecount--; } @@ -424,7 +424,7 @@ if (t == NULL) else c = t->data.ptr; c->handle = handle; -c->search_type = search_type; +c->search_type = lk; c->up = c->down = NULL; store_pool = old_pool; @@ -461,7 +461,7 @@ internal_search_find(void *handle, uscha tree_node *t = (tree_node *)handle; search_cache *c = (search_cache *)(t->data.ptr); uschar *data = NULL; -int search_type = t->name[0] - '0'; +struct lookup_info *search_type = c->search_type; int old_pool = store_pool; /* Lookups that return DEFER may not always set an error message. So that @@ -472,7 +472,7 @@ search_find_defer = FALSE; DEBUG(D_lookup) debug_printf("internal_search_find: file=\"%s\"\n " "type=%s key=\"%s\"\n", filename, - lookup_list[search_type].name, keystring); + search_type->name, keystring); /* Insurance. If the keystring is empty, just fail. */ @@ -503,7 +503,7 @@ if ((t = tree_search(c->item_cache, keys like FAIL, except that search_find_defer is set so the caller can distinguish if necessary. */ - if (lookup_list[search_type].find(c->handle, filename, keystring, keylength, + if (search_type->find(c->handle, filename, keystring, keylength, &data, &search_error_message, &do_cache) == DEFER) { search_find_defer = TRUE; @@ -598,6 +598,7 @@ search_find(void *handle, uschar *filena uschar *affix, int affixlen, int starflags, int *expand_setup) { tree_node *t = (tree_node *)handle; +search_cache *c = (search_cache *)(t->data.ptr); BOOL set_null_wild = FALSE; uschar *yield; @@ -614,9 +615,8 @@ DEBUG(D_lookup) that opens real files. */ if (open_top != (tree_node *)handle && - lookup_list[t->name[0]-'0'].type == lookup_absfile) + c->search_type->type == lookup_absfile) { - search_cache *c = (search_cache *)(t->data.ptr); tree_node *up = c->up; tree_node *down = c->down; --- exim-4.50/src/expand.c.lookup1 2005-02-17 14:49:11.000000000 +0000 +++ exim-4.50/src/expand.c 2005-02-27 15:54:13.000000000 +0000 @@ -2848,7 +2848,8 @@ while (*s != 0) case EITEM_LOOKUP: { - int stype, partial, affixlen, starflags; + struct lookup_info *stype; + int partial, affixlen, starflags; int expand_setup = 0; int nameptr = 0; uschar *key, *filename, *affix; @@ -2900,7 +2901,7 @@ while (*s != 0) stype = search_findtype_partial(name, &partial, &affix, &affixlen, &starflags); - if (stype < 0) + if (!stype) { expand_string_message = search_error_message; goto EXPAND_FAILED; @@ -4101,20 +4102,20 @@ while (*s != 0) else { - int n; + struct lookup_info *stype; uschar *opt = Ustrchr(arg, '_'); if (opt != NULL) *opt++ = 0; - n = search_findtype(arg, Ustrlen(arg)); - if (n < 0) + stype = search_findtype(arg, Ustrlen(arg)); + if (!stype) { expand_string_message = search_error_message; goto EXPAND_FAILED; } - if (lookup_list[n].quote != NULL) - sub = (lookup_list[n].quote)(sub, opt); + if (stype->quote != NULL) + sub = (stype->quote)(sub, opt); else if (opt != NULL) sub = NULL; if (sub == NULL) --- exim-4.50/src/match.c.lookup1 2005-02-17 14:49:11.000000000 +0000 +++ exim-4.50/src/match.c 2005-02-27 15:54:13.000000000 +0000 @@ -96,7 +96,8 @@ static int check_string(void *arg, uschar *pattern, uschar **valueptr, uschar **error) { check_string_block *cb = (check_string_block *)arg; -int search_type, partial, affixlen, starflags; +struct lookup_info *search_type; +int partial, affixlen, starflags; int expand_setup = cb->expand_setup; uschar *affix; uschar *s = cb->subject; @@ -258,7 +259,7 @@ the part of the string preceding the sem search_type = search_findtype_partial(pattern, &partial, &affix, &affixlen, &starflags); *semicolon = ';'; -if (search_type < 0) log_write(0, LOG_MAIN|LOG_PANIC_DIE, "%s", +if (!search_type) log_write(0, LOG_MAIN|LOG_PANIC_DIE, "%s", search_error_message); /* Partial matching is not appropriate for certain lookups (e.g. when looking --- exim-4.50/src/macros.h.lookup1 2005-02-17 14:49:11.000000000 +0000 +++ exim-4.50/src/macros.h 2005-02-27 15:54:13.000000000 +0000 @@ -90,7 +90,7 @@ don't make the file descriptors two-way. /* A macro to simplify testing bits in lookup types */ -#define mac_islookup(a,b) ((lookup_list[a].type & (b)) != 0) +#define mac_islookup(a,b) (((a)->type & (b)) != 0) /* Debugging control */ --- exim-4.50/src/structs.h.lookup1 2005-02-17 14:49:11.000000000 +0000 +++ exim-4.50/src/structs.h 2005-02-27 15:54:13.000000000 +0000 @@ -639,7 +639,7 @@ to close. */ typedef struct search_cache { void *handle; /* lookup handle, or NULL if closed */ - int search_type; /* search type */ + struct lookup_info *search_type;/* search type */ tree_node *up; /* LRU up pointer */ tree_node *down; /* LRU down pointer */ tree_node *item_cache; /* tree of cached results */ --- exim-4.50/src/verify.c.lookup1 2005-02-17 14:49:11.000000000 +0000 +++ exim-4.50/src/verify.c 2005-02-27 15:54:13.000000000 +0000 @@ -1854,7 +1854,7 @@ if (Ustrncmp(ss, "net", 3) == 0 && (semi if (*t++ == '-') { int insize; - int search_type; + struct lookup_info *search_type; int incoming[4]; void *handle; uschar *filename, *key, *result; @@ -1868,7 +1868,7 @@ if (Ustrncmp(ss, "net", 3) == 0 && (semi search_type = search_findtype(t, semicolon - t); - if (search_type < 0) log_write(0, LOG_MAIN|LOG_PANIC_DIE, "%s", + if (!search_type) log_write(0, LOG_MAIN|LOG_PANIC_DIE, "%s", search_error_message); /* Adjust parameters for the type of lookup. For a query-style @@ -1960,19 +1960,20 @@ on spec. */ if ((semicolon = Ustrchr(ss, ';')) != NULL) { uschar *affix; - int partial, affixlen, starflags, id; + int partial, affixlen, starflags; + struct lookup_info *stype; *semicolon = 0; - id = search_findtype_partial(ss, &partial, &affix, &affixlen, &starflags); + stype = search_findtype_partial(ss, &partial, &affix, &affixlen, &starflags); *semicolon=';'; - if (id < 0) /* Unknown lookup type */ + if (!stype) /* Unknown lookup type */ { log_write(0, LOG_MAIN|LOG_PANIC, "%s in host list item \"%s\"", search_error_message, ss); return DEFER; } - isquery = mac_islookup(id, lookup_querystyle); + isquery = mac_islookup(stype, lookup_querystyle); } if (isquery)