Kannel: Open Source WAP and SMS gateway  $Revision: 5037 $
dbpool.h
Go to the documentation of this file.
1 /* ====================================================================
2  * The Kannel Software License, Version 1.0
3  *
4  * Copyright (c) 2001-2016 Kannel Group
5  * Copyright (c) 1998-2001 WapIT Ltd.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Kannel Group (http://www.kannel.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "Kannel" and "Kannel Group" must not be used to
28  * endorse or promote products derived from this software without
29  * prior written permission. For written permission, please
30  * contact org@kannel.org.
31  *
32  * 5. Products derived from this software may not be called "Kannel",
33  * nor may "Kannel" appear in their name, without prior written
34  * permission of the Kannel Group.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE KANNEL GROUP OR ITS CONTRIBUTORS
40  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
41  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
42  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
43  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
44  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
45  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
46  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
47  * ====================================================================
48  *
49  * This software consists of voluntary contributions made by many
50  * individuals on behalf of the Kannel Group. For more information on
51  * the Kannel Group, please see <http://www.kannel.org/>.
52  *
53  * Portions of this software are based upon software originally written at
54  * WapIT Ltd., Helsinki, Finland for the Kannel project.
55  */
56 
57 /*
58  * dbpool.h - database pool functions
59  *
60  * Stipe Tolj <stolj@wapme-group.de>
61  * Alexander Malysh <a.malysh@centrium.de>
62  */
63 
64 #ifndef GWDBPOOL_H
65 #define GWDBPOOL_H
66 
67 #if defined(HAVE_MYSQL) || defined(HAVE_SDB) || \
68  defined(HAVE_ORACLE) || defined(HAVE_SQLITE) || \
69  defined(HAVE_PGSQL) || defined(HAVE_SQLITE3) || \
70  defined(HAVE_MSSQL) || defined(HAVE_REDIS) || \
71  defined(HAVE_CASS)
72 #define HAVE_DBPOOL 1
73 #endif
74 
75 /* supported databases for connection pools */
76 enum db_type {
79 };
80 
81 
82 /*
83  * The DBPool type. It is opaque: do not touch it except via the functions
84  * defined in this header.
85  */
86 typedef struct DBPool DBPool;
87 
88 /*
89  * The DBPoolConn type. It stores the abtracted pointer to a database
90  * specific connection and the pool pointer itself to allow easy
91  * re-storage into the pool (also disallowing to insert the conn into an
92  * other pool).
93  */
94  typedef struct {
95  void *conn; /* the pointer holding the database specific connection */
96  DBPool *pool; /* pointer of the pool where this connection belongs to */
97 } DBPoolConn;
98 
99 typedef struct {
101  long port;
105 } MySQLConf;
106 
107 /*
108  * TODO Think how to get rid of it and have generic Conf struct
109  */
110 typedef struct {
115 } MSSQLConf;
116 
117 typedef struct {
121 } OracleConf;
122 
123 typedef struct {
125 } SDBConf;
126 
127 typedef struct {
130 } SQLiteConf;
131 
132 typedef struct {
135 } SQLite3Conf;
136 
137 typedef struct {
139  long port;
143  Octstr *options; /* yet not used */
144  Octstr *tty; /* yet not used */
145 } PgSQLConf;
146 
147 typedef struct {
149  long port;
151  long database;
153 } RedisConf;
154 
155 typedef struct {
157  long port;
162 } CassConf;
163 
164 typedef union {
174 } DBConf;
175 
176 /*
177  * Create a database pool with #connections of connections. The pool
178  * is stored within a queue list.
179  * Returns a pointer to the pool object on success or NULL if the
180  * creation fails.
181  */
182 DBPool *dbpool_create(enum db_type db_type, DBConf *conf, unsigned int connections);
183 
184 /*
185  * Destroys the database pool. Includes also shutdowning all existing
186  * connections within the pool queue.
187  */
188 void dbpool_destroy(DBPool *p);
189 
190 /*
191  * Increase the connection size of the pool by #conn connections.
192  * Beware that you can't increase a pool size to more then the initial
193  * dbpool_create() call defined and opened the maximum pool connections.
194  * Returns how many connections have been additionally created and
195  * inserted to the pool.
196  */
197 unsigned int dbpool_increase(DBPool *p, unsigned int conn);
198 
199 /*
200  * Decrease the connection size of the pool by #conn connections.
201  * A pool size can only by reduced up to 0. So if the caller specifies
202  * to close more connections then there are in the pool, all connections
203  * are closed.
204  * Returns how many connections have been shutdown and deleted from the
205  * pool queue.
206  */
207 unsigned int dbpool_decrease(DBPool *p, unsigned int conn);
208 
209 /*
210  * Return the number of connections that are currently queued in the pool.
211  */
212 long dbpool_conn_count(DBPool *p);
213 
214 /*
215  * Gets and active connection from the pool and returns it.
216  * The caller can use it then for queuery operations and has to put it
217  * back into the pool via dbpool_conn_produce(conn).
218  * If no connection is in pool and DBPool is not in destroying phase then
219  * will block until connection is available otherwise returns NULL.
220  */
222 
223 /*
224  * Returns a used connection to the pool again.
225  * The connection is returned to it's domestic pool for further extraction
226  * using dbpool_conn_consume().
227  */
228 void dbpool_conn_produce(DBPoolConn *conn);
229 
230 int dbpool_conn_select(DBPoolConn *conn, const Octstr *sql, List *binds, List **result);
231 int dbpool_conn_update(DBPoolConn *conn, const Octstr *sql, List *binds);
232 
233 /*
234  * Perfoms a check of all connections within the pool and tries to
235  * re-establish the same ammount of connections if there are broken
236  * connections within the pool.
237  * (This operation can only be performed if the database allows such
238  * operations by its API.)
239  * Returns how many connections within the pool have been checked and
240  * are still considered active.
241  */
242 unsigned int dbpool_check(DBPool *p);
243 
244 
245 #endif
MSSQLConf * mssql
Definition: dbpool.h:165
Octstr * password
Definition: dbpool.h:119
db_type
Definition: dbpool.h:76
unsigned int dbpool_check(DBPool *p)
long dbpool_conn_count(DBPool *p)
SQLite3Conf * sqlite3
Definition: dbpool.h:170
DBPool * dbpool_create(enum db_type db_type, DBConf *conf, unsigned int connections)
Octstr * file
Definition: dbpool.h:133
RedisConf * redis
Definition: dbpool.h:172
Octstr * database
Definition: dbpool.h:160
Octstr * options
Definition: dbpool.h:143
Octstr * server
Definition: dbpool.h:113
Octstr * url
Definition: dbpool.h:124
Octstr * database
Definition: dbpool.h:114
SDBConf * sdb
Definition: dbpool.h:167
unsigned int dbpool_decrease(DBPool *p, unsigned int conn)
unsigned int dbpool_increase(DBPool *p, unsigned int conn)
Octstr * username
Definition: dbpool.h:140
int lock_timeout
Definition: dbpool.h:134
Octstr * password
Definition: dbpool.h:150
void dbpool_conn_produce(DBPoolConn *conn)
Octstr * username
Definition: dbpool.h:118
PgSQLConf * pgsql
Definition: dbpool.h:171
Octstr * password
Definition: dbpool.h:112
CassConf * cass
Definition: dbpool.h:173
Octstr * password
Definition: dbpool.h:103
Octstr * username
Definition: dbpool.h:111
long port
Definition: dbpool.h:157
Octstr * password
Definition: dbpool.h:141
Octstr * host
Definition: dbpool.h:100
long database
Definition: dbpool.h:151
Definition: dbpool.h:164
Octstr * tnsname
Definition: dbpool.h:120
void dbpool_destroy(DBPool *p)
int dbpool_conn_update(DBPoolConn *conn, const Octstr *sql, List *binds)
Octstr * host
Definition: dbpool.h:156
Octstr * database
Definition: dbpool.h:142
Definition: octstr.c:118
MySQLConf * mysql
Definition: dbpool.h:166
long port
Definition: dbpool.h:149
Octstr * tty
Definition: dbpool.h:144
long idle_timeout
Definition: dbpool.h:161
Octstr * username
Definition: dbpool.h:102
Octstr * database
Definition: dbpool.h:104
int dbpool_conn_select(DBPoolConn *conn, const Octstr *sql, List *binds, List **result)
long port
Definition: dbpool.h:139
long port
Definition: dbpool.h:101
DBPoolConn * dbpool_conn_consume(DBPool *p)
void * conn
Definition: dbpool.h:95
Octstr * host
Definition: dbpool.h:148
Octstr * file
Definition: dbpool.h:128
Octstr * password
Definition: dbpool.h:159
int lock_timeout
Definition: dbpool.h:129
Octstr * host
Definition: dbpool.h:138
Octstr * username
Definition: dbpool.h:158
Definition: list.c:102
SQLiteConf * sqlite
Definition: dbpool.h:169
DBPool * pool
Definition: dbpool.h:96
OracleConf * oracle
Definition: dbpool.h:168
long idle_timeout
Definition: dbpool.h:152
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.