/
db_http.c
157 lines (121 loc) · 3.7 KB
/
db_http.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/*
* Copyright (C) 2009 Voice Sistem SRL
* Copyright (C) 2009 Andrei Dragus
*
* This file is part of opensips, a free SIP server.
*
* opensips is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* opensips is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*
* History:
* ---------
* 2009-08-12 first version (andreidragus)
*/
#include "../../sr_module.h"
#include "../../db/db.h"
#include "http_dbase.h"
static int http_mod_init(void);
int db_http_bind_api( const str* mod, db_func_t *dbb);
int cap_raw_query = 0;
int cap_id = 0;
int cap_replace = 0;
int cap_insert_update = 0;
int use_ssl = 0 ;
unsigned int db_http_timeout = 30000; /* Default is 30 seconds */
/*
* MySQL database module interface
*/
static cmd_export_t cmds[] = {
{"db_bind_api", (cmd_function)db_http_bind_api, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0}
};
/*
* Exported parameters
*/
static param_export_t params[] = {
{"SSL", INT_PARAM ,&use_ssl},
{"cap_raw_query", INT_PARAM ,&cap_raw_query},
{"cap_replace", INT_PARAM , &cap_replace},
{"cap_last_inserted_id", INT_PARAM , &cap_id},
{"cap_insert_update", INT_PARAM , &cap_insert_update},
{"field_delimiter", STR_PARAM | USE_FUNC_PARAM ,set_col_delim},
{"row_delimiter", STR_PARAM | USE_FUNC_PARAM ,set_line_delim},
{"quote_delimiter", STR_PARAM | USE_FUNC_PARAM ,set_quote_delim},
{"value_delimiter", STR_PARAM | USE_FUNC_PARAM ,set_value_delim},
{"timeout", INT_PARAM,&db_http_timeout},
{0, 0, 0}
};
struct module_exports exports = {
"db_http",
MOD_TYPE_SQLDB, /* class of this module */
MODULE_VERSION,
DEFAULT_DLFLAGS, /* dlopen flags */
0, /* load function */
NULL, /* OpenSIPS module dependencies */
cmds,
0,
params, /* module parameters */
0, /* exported statistics */
0, /* exported MI functions */
0, /* exported pseudo-variables */
0, /* exported transformations */
0, /* extra processes */
http_mod_init, /* module initialization function */
0, /* response function*/
0, /* destroy function */
0 /* per-child init function */
};
static int http_mod_init(void)
{
return 0;
}
int db_http_bind_api( const str* mod, db_func_t *dbb)
{
if(dbb==NULL)
return -1;
memset(dbb, 0, sizeof(db_func_t));
dbb->cap = DB_CAP_QUERY | DB_CAP_INSERT | DB_CAP_DELETE |
DB_CAP_UPDATE ;
if( cap_id)
{
dbb->cap |= DB_CAP_LAST_INSERTED_ID;
dbb->last_inserted_id = db_last_inserted_id;
}
if( cap_raw_query)
{
dbb->cap |= DB_CAP_RAW_QUERY;
dbb->raw_query = db_http_raw_query;
}
if( cap_replace)
{
dbb->cap |= DB_CAP_REPLACE;
dbb->replace = db_http_replace;
}
if( cap_insert_update)
{
dbb->cap |= DB_CAP_INSERT_UPDATE;
dbb->insert_update = db_insert_update;
}
dbb->use_table = db_http_use_table;
dbb->init = db_http_init;
dbb->close = db_http_close;
dbb->query = db_http_query;
dbb->fetch_result = NULL;
dbb->free_result = db_http_free_result;
dbb->insert = db_http_insert;
dbb->delete = db_http_delete;
dbb->update = db_http_update;
return 0;
}