DICT *dict_open3(const char *dict_type, const char *dict_name, int open_flags, int dict_flags) { const char *myname = "dict_open"; DICT_OPEN_INFO *dp; DICT *dict; if (*dict_type == 0 || *dict_name == 0) msg_fatal("open dictionary: expecting \"type:name\" form instead of \"%s:%s\"", dict_type, dict_name); if (dict_open_hash == 0) dict_open_init(); if ((dp = (DICT_OPEN_INFO *) htable_find(dict_open_hash, dict_type)) == 0) return (dict_surrogate(dict_type, dict_name, open_flags, dict_flags, "unsupported dictionary type: %s", dict_type)); if ((dict = dp->open(dict_name, open_flags, dict_flags)) == 0) return (dict_surrogate(dict_type, dict_name, open_flags, dict_flags, "cannot open %s:%s: %m", dict_type, dict_name)); if (msg_verbose) msg_info("%s: %s:%s", myname, dict_type, dict_name); /* XXX the choice between wait-for-lock or no-wait is hard-coded. */ if (dict_flags & DICT_FLAG_OPEN_LOCK) { if (dict_flags & DICT_FLAG_LOCK) msg_panic("%s: attempt to open %s:%s with both \"open\" lock and \"access\" lock", myname, dict_type, dict_name); if (dict->lock(dict, MYFLOCK_OP_EXCLUSIVE | MYFLOCK_OP_NOWAIT) < 0) msg_fatal("%s:%s: unable to get exclusive lock: %m", dict_type, dict_name); } return (dict); }
ARGV *dict_mapnames() { HTABLE_INFO **ht_info; HTABLE_INFO **ht; DICT_OPEN_INFO *dp; ARGV *mapnames; #ifndef NO_DYNAMIC_MAPS DLINFO *dlp; #endif if (dict_open_hash == 0) dict_open_init(); mapnames = argv_alloc(dict_open_hash->used + 1); for (ht_info = ht = htable_list(dict_open_hash); *ht; ht++) { dp = (DICT_OPEN_INFO *) ht[0]->value; argv_add(mapnames, dp->type, ARGV_END); } #ifndef NO_DYNAMIC_MAPS if (!dict_dlinfo) msg_fatal("dlinfo==NULL"); for (dlp=dict_dlinfo; dlp->pattern; dlp++) { argv_add(mapnames, dlp->pattern, ARGV_END); } #endif qsort((void *) mapnames->argv, mapnames->argc, sizeof(mapnames->argv[0]), dict_sort_alpha_cpp); myfree((char *) ht_info); argv_terminate(mapnames); return mapnames; }
void dict_open_register(const char *type, DICT *(*open) (const char *, int, int)) { const char *myname = "dict_open_register"; DICT_OPEN_INFO *dp; if (dict_open_hash == 0) dict_open_init(); if (htable_find(dict_open_hash, type)) msg_panic("%s: dictionary type exists: %s", myname, type); dp = (DICT_OPEN_INFO *) mymalloc(sizeof(*dp)); dp->type = mystrdup(type); dp->open = open; htable_enter(dict_open_hash, dp->type, (char *) dp); }
void dict_open_register(const char *type, DICT_OPEN_FN open) { const char *myname = "dict_open_register"; DICT_OPEN_INFO *dp; HTABLE_INFO *ht; if (dict_open_hash == 0) dict_open_init(); if (htable_find(dict_open_hash, type)) msg_panic("%s: dictionary type exists: %s", myname, type); dp = (DICT_OPEN_INFO *) mymalloc(sizeof(*dp)); dp->open = open; ht = htable_enter(dict_open_hash, type, (char *) dp); dp->type = ht->key; }
DICT *dict_open3(const char *dict_type, const char *dict_name, int open_flags, int dict_flags) { const char *myname = "dict_open"; DICT_OPEN_INFO *dp; DICT_OPEN_FN open_fn; DICT *dict; if (*dict_type == 0 || *dict_name == 0) msg_fatal("open dictionary: expecting \"type:name\" form instead of \"%s:%s\"", dict_type, dict_name); if (dict_open_hash == 0) dict_open_init(); if ((dp = (DICT_OPEN_INFO *) htable_find(dict_open_hash, dict_type)) == 0) { if (dict_open_extend_hook != 0 && (open_fn = dict_open_extend_hook(dict_type)) != 0) { dict_open_register(dict_type, open_fn); dp = (DICT_OPEN_INFO *) htable_find(dict_open_hash, dict_type); } if (dp == 0) return (dict_surrogate(dict_type, dict_name, open_flags, dict_flags, "unsupported dictionary type: %s", dict_type)); } if ((dict = dp->open(dict_name, open_flags, dict_flags)) == 0) return (dict_surrogate(dict_type, dict_name, open_flags, dict_flags, "cannot open %s:%s: %m", dict_type, dict_name)); if (msg_verbose) msg_info("%s: %s:%s", myname, dict_type, dict_name); /* XXX The choice between wait-for-lock or no-wait is hard-coded. */ if (dict->flags & DICT_FLAG_OPEN_LOCK) { if (dict->flags & DICT_FLAG_LOCK) msg_panic("%s: attempt to open %s:%s with both \"open\" lock and \"access\" lock", myname, dict_type, dict_name); /* Multi-writer safe map: downgrade persistent lock to temporary. */ if (dict->flags & DICT_FLAG_MULTI_WRITER) { dict->flags &= ~DICT_FLAG_OPEN_LOCK; dict->flags |= DICT_FLAG_LOCK; } /* Multi-writer unsafe map: acquire exclusive lock or bust. */ else if (dict->lock(dict, MYFLOCK_OP_EXCLUSIVE | MYFLOCK_OP_NOWAIT) < 0) msg_fatal("%s:%s: unable to get exclusive lock: %m", dict_type, dict_name); } return (dict); }
DICT *dict_open3(const char *dict_type, const char *dict_name, int open_flags, int dict_flags) { const char *myname = "dict_open"; DICT_OPEN_INFO *dp; DICT *dict; if (*dict_type == 0 || *dict_name == 0) msg_fatal("open dictionary: expecting \"type:name\" form instead of \"%s:%s\"", dict_type, dict_name); if (dict_open_hash == 0) dict_open_init(); if ((dp = (DICT_OPEN_INFO *) htable_find(dict_open_hash, dict_type)) == 0) { #ifdef NO_DYNAMIC_MAPS msg_fatal("%s: unsupported dictionary type: %s", myname, dict_type); #else struct stat st; LIB_FN fn[2]; DICT *(*open) (const char *, int, int); DLINFO *dl=dict_open_dlfind(dict_type); if (!dl) msg_fatal("%s: unsupported dictionary type: %s: Is the postfix-%s package installed?", myname, dict_type, dict_type); if (stat(dl->soname,&st) < 0) { msg_fatal("%s: unsupported dictionary type: %s (%s not found. Is the postfix-%s package installed?)", myname, dict_type, dl->soname, dict_type); } fn[0].name = dl->openfunc; fn[0].ptr = (void**)&open; fn[1].name = NULL; load_library_symbols(dl->soname, fn, NULL); dict_open_register(dict_type, open); dp = (DICT_OPEN_INFO *) htable_find(dict_open_hash, dict_type); #endif } if (msg_verbose>1) { msg_info("%s: calling %s open routine",myname,dict_type); } if ((dict = dp->open(dict_name, open_flags, dict_flags)) == 0) msg_fatal("opening %s:%s %m", dict_type, dict_name); if (msg_verbose) msg_info("%s: %s:%s", myname, dict_type, dict_name); return (dict); }
ARGV *dict_mapnames() { HTABLE_INFO **ht_info; HTABLE_INFO **ht; DICT_OPEN_INFO *dp; ARGV *mapnames; if (dict_open_hash == 0) dict_open_init(); mapnames = argv_alloc(dict_open_hash->used + 1); for (ht_info = ht = htable_list(dict_open_hash); *ht; ht++) { dp = (DICT_OPEN_INFO *) ht[0]->value; argv_add(mapnames, dp->type, ARGV_END); } qsort((void *) mapnames->argv, mapnames->argc, sizeof(mapnames->argv[0]), dict_sort_alpha_cpp); myfree((char *) ht_info); argv_terminate(mapnames); return mapnames; }
void tls_scache_init() { dict_open_init(); }