xref: /netbsd-src/external/ibm-public/postfix/dist/src/global/mail_dict.c (revision 4ac76180e904e771b9d522c7e57296d371f06499)
1 /*	$NetBSD: mail_dict.c,v 1.2 2017/02/14 01:16:45 christos Exp $	*/
2 
3 /*++
4 /* NAME
5 /*	mail_dict 3
6 /* SUMMARY
7 /*	register application-specific dictionaries
8 /* SYNOPSIS
9 /*	#include <mail_dict.h>
10 /*
11 /*	void	mail_dict_init()
12 /* DESCRIPTION
13 /*	This module registers dictionary types that depend on higher-level
14 /*	Postfix-specific interfaces and protocols.
15 /*
16 /*	This also initializes the support for run-time loading of
17 /*	lookup tables, if applicable.
18 /*
19 /*	The latter requires basic parameter initialization
20 /*	by either mail_conf_read() or mail_params_init().
21 /* LICENSE
22 /* .ad
23 /* .fi
24 /*	The Secure Mailer license must be distributed with this software.
25 /* AUTHOR(S)
26 /*	Wietse Venema
27 /*	IBM T.J. Watson Research
28 /*	P.O. Box 704
29 /*	Yorktown Heights, NY 10598, USA
30 /*--*/
31 
32 /* System library. */
33 
34 #include <sys_defs.h>
35 
36 /* Utility library. */
37 
38 #include <dict.h>
39 #include <msg.h>
40 #include <mymalloc.h>
41 #include <stringops.h>
42 #include <dynamicmaps.h>
43 
44 /* Global library. */
45 
46 #include <dict_proxy.h>
47 #include <dict_ldap.h>
48 #include <dict_mysql.h>
49 #include <dict_pgsql.h>
50 #include <dict_sqlite.h>
51 #include <dict_memcache.h>
52 #include <mail_dict.h>
53 #include <mail_params.h>
54 #include <mail_dict.h>
55 
56 typedef struct {
57     char   *type;
58     struct DICT *(*open) (const char *, int, int);
59 } DICT_OPEN_INFO;
60 
61 static const DICT_OPEN_INFO dict_open_info[] = {
62     DICT_TYPE_PROXY, dict_proxy_open,
63 #ifndef USE_DYNAMIC_MAPS
64 #ifdef HAS_LDAP
65     DICT_TYPE_LDAP, dict_ldap_open,
66 #endif
67 #ifdef HAS_MYSQL
68     DICT_TYPE_MYSQL, dict_mysql_open,
69 #endif
70 #ifdef HAS_PGSQL
71     DICT_TYPE_PGSQL, dict_pgsql_open,
72 #endif
73 #ifdef HAS_SQLITE
74     DICT_TYPE_SQLITE, dict_sqlite_open,
75 #endif
76 #endif					/* !USE_DYNAMIC_MAPS */
77     DICT_TYPE_MEMCACHE, dict_memcache_open,
78     0,
79 };
80 
81 /* mail_dict_init - dictionaries that depend on Postfix-specific interfaces */
82 
83 void    mail_dict_init(void)
84 {
85     const DICT_OPEN_INFO *dp;
86 
87 #ifdef USE_DYNAMIC_MAPS
88     char   *path;
89 
90     path = concatenate(var_meta_dir, "/", "dynamicmaps.cf",
91 #ifdef SHLIB_VERSION
92 		       ".", SHLIB_VERSION,
93 #endif
94 		       (char *) 0);
95     dymap_init(path, var_shlib_dir);
96     myfree(path);
97 #endif
98 
99     for (dp = dict_open_info; dp->type; dp++)
100 	dict_open_register(dp->type, dp->open);
101 }
102 
103 #ifdef TEST
104 
105  /*
106   * Proof-of-concept test program.
107   */
108 
109 #include <mail_proto.h>
110 #include <mail_params.h>
111 
112 int     main(int argc, char **argv)
113 {
114     var_queue_dir = DEF_QUEUE_DIR;
115     var_proxymap_service = DEF_PROXYMAP_SERVICE;
116     var_proxywrite_service = DEF_PROXYWRITE_SERVICE;
117     var_ipc_timeout = 3600;
118     mail_dict_init();
119     dict_test(argc, argv);
120     return (0);
121 }
122 
123 #endif
124