1 /*	$NetBSD: sdlz_helper.h,v 1.3 2014/12/10 04:37:55 christos Exp $	*/
2 
3 /*
4  * Copyright (C) 2002 Stichting NLnet, Netherlands, stichting@nlnet.nl.
5  *
6  * Permission to use, copy, modify, and distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the
8  * above copyright notice and this permission notice appear in all
9  * copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND STICHTING NLNET
12  * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
13  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
14  * STICHTING NLNET BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
15  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
16  * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
17  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE
18  * USE OR PERFORMANCE OF THIS SOFTWARE.
19  *
20  * The development of Dynamically Loadable Zones (DLZ) for Bind 9 was
21  * conceived and contributed by Rob Butler.
22  *
23  * Permission to use, copy, modify, and distribute this software for any
24  * purpose with or without fee is hereby granted, provided that the
25  * above copyright notice and this permission notice appear in all
26  * copies.
27  *
28  * THE SOFTWARE IS PROVIDED "AS IS" AND ROB BUTLER
29  * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
30  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
31  * ROB BUTLER BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
32  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
33  * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
34  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE
35  * USE OR PERFORMANCE OF THIS SOFTWARE.
36  */
37 
38 #ifndef SDLZHELPER_H
39 #define SDLZHELPER_H
40 
41 /*
42  * Types
43  */
44 #define SDLZH_REQUIRE_CLIENT	0x01
45 #define SDLZH_REQUIRE_QUERY	0x02
46 #define SDLZH_REQUIRE_RECORD	0x04
47 #define SDLZH_REQUIRE_ZONE	0x08
48 
49 typedef struct query_segment query_segment_t;
50 typedef ISC_LIST(query_segment_t) query_list_t;
51 typedef struct dbinstance dbinstance_t;
52 typedef ISC_LIST(dbinstance_t) db_list_t;
53 typedef struct driverinstance driverinstance_t;
54 
55 /*%
56  * a query segment is all the text between our special tokens
57  * special tokens are %zone%, %record%, %client%
58  */
59 struct query_segment {
60 	void				*sql;
61 	unsigned int			strlen;
62 	isc_boolean_t			direct;
63 	ISC_LINK(query_segment_t)	link;
64 };
65 
66 /*%
67  * a database instance contains everything we need for running
68  * a query against the database.  Using it each separate thread
69  * can dynamically construct a query and execute it against the
70  * database.  The "instance_lock" and locking code in the driver's
71  * make sure no two threads try to use the same DBI at a time.
72  */
73 struct dbinstance {
74 	void			*dbconn;
75 	query_list_t		*allnodes_q;
76 	query_list_t		*allowxfr_q;
77 	query_list_t		*authority_q;
78 	query_list_t		*findzone_q;
79 	query_list_t		*lookup_q;
80 	query_list_t		*countzone_q;
81 	char			*query_buf;
82 	char			*zone;
83 	char			*record;
84 	char			*client;
85 	isc_mem_t		*mctx;
86 	isc_mutex_t		instance_lock;
87 	ISC_LINK(dbinstance_t)	link;
88 };
89 
90 /*
91  * Method declarations
92  */
93 
94 /* see the code in sdlz_helper.c for more information on these methods */
95 
96 char *
97 sdlzh_build_querystring(isc_mem_t *mctx, query_list_t *querylist);
98 
99 isc_result_t
100 sdlzh_build_sqldbinstance(isc_mem_t *mctx, const char *allnodes_str,
101 			  const char *allowxfr_str, const char *authority_str,
102 			  const char *findzone_str, const char *lookup_str,
103 			  const char *countzone_str, dbinstance_t **dbi);
104 
105 void
106 sdlzh_destroy_sqldbinstance(dbinstance_t *dbi);
107 
108 char *
109 sdlzh_get_parameter_value(isc_mem_t *mctx, const char *input, const char* key);
110 
111 /* Compatability with existing DLZ drivers */
112 
113 #define	build_querystring	sdlzh_build_querystring
114 #define	build_sqldbinstance	sdlzh_build_sqldbinstance
115 #define	destroy_sqldbinstance	sdlzh_destroy_sqldbinstance
116 
117 #define	getParameterValue(x,y)  sdlzh_get_parameter_value(ns_g_mctx, (x), (y))
118 
119 #endif /* SDLZHELPER_H */
120