1 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,159 +0,0 @@ |
1 |
-/* |
|
2 |
- * $Id$ |
|
3 |
- * |
|
4 |
- * UNIXODBC module |
|
5 |
- * |
|
6 |
- * Copyright (C) 2005-2006 Marco Lorrai |
|
7 |
- * Copyright (C) 2008 1&1 Internet AG |
|
8 |
- * |
|
9 |
- * This file is part of Kamailio, a free SIP server. |
|
10 |
- * |
|
11 |
- * Kamailio is free software; you can redistribute it and/or modify |
|
12 |
- * it under the terms of the GNU General Public License as published by |
|
13 |
- * the Free Software Foundation; either version 2 of the License, or |
|
14 |
- * (at your option) any later version |
|
15 |
- * |
|
16 |
- * Kamailio is distributed in the hope that it will be useful, |
|
17 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
19 |
- * GNU General Public License for more details. |
|
20 |
- * |
|
21 |
- * You should have received a copy of the GNU General Public License |
|
22 |
- * along with this program; if not, write to the Free Software |
|
23 |
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
24 |
- * |
|
25 |
- * |
|
26 |
- * History: |
|
27 |
- * -------- |
|
28 |
- * 2005-12-01 initial commit (chgen) |
|
29 |
- */ |
|
30 |
- |
|
31 |
- |
|
32 |
-#include "../../dprint.h" |
|
33 |
-#include "../../lib/kcore/strcommon.h" |
|
34 |
-#include "../../lib/srdb1/db_ut.h" |
|
35 |
-#include "db_unixodbc.h" |
|
36 |
-#include "val.h" |
|
37 |
-#include "con.h" |
|
38 |
- |
|
39 |
-/* |
|
40 |
- * Used when converting the query to a result |
|
41 |
- */ |
|
42 |
-int db_unixodbc_str2val(const db_type_t _t, db_val_t* _v, const char* _s, const int _l, |
|
43 |
- const unsigned int _cpy) |
|
44 |
-{ |
|
45 |
- /* db_unixodbc uses the NULL string for NULL SQL values */ |
|
46 |
- if (_v && _s && !strcmp(_s, "NULL")) { |
|
47 |
- LM_DBG("converting NULL value"); |
|
48 |
- static str dummy_string = {"", 0}; |
|
49 |
- memset(_v, 0, sizeof(db_val_t)); |
|
50 |
- /* Initialize the string pointers to a dummy empty |
|
51 |
- * string so that we do not crash when the NULL flag |
|
52 |
- * is set but the module does not check it properly |
|
53 |
- */ |
|
54 |
- VAL_STRING(_v) = dummy_string.s; |
|
55 |
- VAL_STR(_v) = dummy_string; |
|
56 |
- VAL_BLOB(_v) = dummy_string; |
|
57 |
- VAL_TYPE(_v) = _t; |
|
58 |
- VAL_NULL(_v) = 1; |
|
59 |
- return 0; |
|
60 |
- } else { |
|
61 |
- return db_str2val(_t, _v, _s, _l, _cpy); |
|
62 |
- } |
|
63 |
-} |
|
64 |
- |
|
65 |
-/* |
|
66 |
- * Used when converting a result from the query |
|
67 |
- */ |
|
68 |
-int db_unixodbc_val2str(const db1_con_t* _c, const db_val_t* _v, char* _s, int* _len) |
|
69 |
-{ |
|
70 |
- int l, tmp; |
|
71 |
- char* old_s; |
|
72 |
- |
|
73 |
- /* db_unixodbc uses a custom escape function */ |
|
74 |
- tmp = db_val2str(_c, _v, _s, _len); |
|
75 |
- if (tmp < 1) |
|
76 |
- return tmp; |
|
77 |
- |
|
78 |
- switch(VAL_TYPE(_v)) |
|
79 |
- { |
|
80 |
- case DB1_STRING: |
|
81 |
- l = strlen(VAL_STRING(_v)); |
|
82 |
- if (*_len < (l * 2 + 3)) |
|
83 |
- { |
|
84 |
- LM_ERR("destination buffer too short\n"); |
|
85 |
- return -6; |
|
86 |
- } |
|
87 |
- else |
|
88 |
- { |
|
89 |
- old_s = _s; |
|
90 |
- *_s++ = '\''; |
|
91 |
- if(use_escape_common) |
|
92 |
- { |
|
93 |
- _s += escape_common(_s, (char*)VAL_STRING(_v), l); |
|
94 |
- } else { |
|
95 |
- memcpy(_s, VAL_STRING(_v), l); |
|
96 |
- _s += l; |
|
97 |
- } |
|
98 |
- *_s++ = '\''; |
|
99 |
- *_s = '\0'; /* FIXME */ |
|
100 |
- *_len = _s - old_s; |
|
101 |
- return 0; |
|
102 |
- } |
|
103 |
- break; |
|
104 |
- |
|
105 |
- case DB1_STR: |
|
106 |
- l = VAL_STR(_v).len; |
|
107 |
- if (*_len < (l * 2 + 3)) |
|
108 |
- { |
|
109 |
- LM_ERR("destination buffer too short\n"); |
|
110 |
- return -7; |
|
111 |
- } |
|
112 |
- else |
|
113 |
- { |
|
114 |
- old_s = _s; |
|
115 |
- *_s++ = '\''; |
|
116 |
- if(use_escape_common) |
|
117 |
- { |
|
118 |
- _s += escape_common(_s, VAL_STR(_v).s, l); |
|
119 |
- } else { |
|
120 |
- memcpy(_s, VAL_STR(_v).s, l); |
|
121 |
- _s += l; |
|
122 |
- } |
|
123 |
- *_s++ = '\''; |
|
124 |
- *_s = '\0'; /* FIXME */ |
|
125 |
- *_len = _s - old_s; |
|
126 |
- return 0; |
|
127 |
- } |
|
128 |
- break; |
|
129 |
- |
|
130 |
- case DB1_BLOB: |
|
131 |
- l = VAL_BLOB(_v).len; |
|
132 |
- if (*_len < (l * 2 + 3)) |
|
133 |
- { |
|
134 |
- LM_ERR("destination buffer too short\n"); |
|
135 |
- return -9; |
|
136 |
- } |
|
137 |
- else |
|
138 |
- { |
|
139 |
- old_s = _s; |
|
140 |
- *_s++ = '\''; |
|
141 |
- if(use_escape_common) |
|
142 |
- { |
|
143 |
- _s += escape_common(_s, VAL_BLOB(_v).s, l); |
|
144 |
- } else { |
|
145 |
- memcpy(_s, VAL_BLOB(_v).s, l); |
|
146 |
- _s += l; |
|
147 |
- } |
|
148 |
- *_s++ = '\''; |
|
149 |
- *_s = '\0'; /* FIXME */ |
|
150 |
- *_len = _s - old_s; |
|
151 |
- return 0; |
|
152 |
- } |
|
153 |
- break; |
|
154 |
- |
|
155 |
- default: |
|
156 |
- LM_DBG("unknown data type\n"); |
|
157 |
- return -10; |
|
158 |
- } |
|
159 |
-} |
This patch does two things:
* It links the module with the shared library libkcore which contains
strcommon files that were originally present in kamailio core and
are missing from the sip-router core.
* it fixes the path to strcommon.h to point to the header in the shared
library.
This patch makes the module compatible with the changes done in the
database library of kamailio/ser when it was converted to shared library
libsrdb1. These changes are mostly needed to avoid conflicts with the
symbols defined in the newer version of the library libsrdb2.
List of changes:
* Rename db_con_t to db1_con_t
* Rename db_res_t to db1_res_t
* Rename db field type names from DB_* to DB1_*
* Updated header paths to files in ../../lib/srdb1
* Link with libsrdb1
... | ... |
@@ -31,7 +31,7 @@ |
31 | 31 |
|
32 | 32 |
#include "../../dprint.h" |
33 | 33 |
#include "../../strcommon.h" |
34 |
-#include "../../db/db_ut.h" |
|
34 |
+#include "../../lib/srdb1/db_ut.h" |
|
35 | 35 |
#include "db_unixodbc.h" |
36 | 36 |
#include "val.h" |
37 | 37 |
#include "con.h" |
... | ... |
@@ -65,7 +65,7 @@ int db_unixodbc_str2val(const db_type_t _t, db_val_t* _v, const char* _s, const |
65 | 65 |
/* |
66 | 66 |
* Used when converting a result from the query |
67 | 67 |
*/ |
68 |
-int db_unixodbc_val2str(const db_con_t* _c, const db_val_t* _v, char* _s, int* _len) |
|
68 |
+int db_unixodbc_val2str(const db1_con_t* _c, const db_val_t* _v, char* _s, int* _len) |
|
69 | 69 |
{ |
70 | 70 |
int l, tmp; |
71 | 71 |
char* old_s; |
... | ... |
@@ -77,7 +77,7 @@ int db_unixodbc_val2str(const db_con_t* _c, const db_val_t* _v, char* _s, int* _ |
77 | 77 |
|
78 | 78 |
switch(VAL_TYPE(_v)) |
79 | 79 |
{ |
80 |
- case DB_STRING: |
|
80 |
+ case DB1_STRING: |
|
81 | 81 |
l = strlen(VAL_STRING(_v)); |
82 | 82 |
if (*_len < (l * 2 + 3)) |
83 | 83 |
{ |
... | ... |
@@ -102,7 +102,7 @@ int db_unixodbc_val2str(const db_con_t* _c, const db_val_t* _v, char* _s, int* _ |
102 | 102 |
} |
103 | 103 |
break; |
104 | 104 |
|
105 |
- case DB_STR: |
|
105 |
+ case DB1_STR: |
|
106 | 106 |
l = VAL_STR(_v).len; |
107 | 107 |
if (*_len < (l * 2 + 3)) |
108 | 108 |
{ |
... | ... |
@@ -127,7 +127,7 @@ int db_unixodbc_val2str(const db_con_t* _c, const db_val_t* _v, char* _s, int* _ |
127 | 127 |
} |
128 | 128 |
break; |
129 | 129 |
|
130 |
- case DB_BLOB: |
|
130 |
+ case DB1_BLOB: |
|
131 | 131 |
l = VAL_BLOB(_v).len; |
132 | 132 |
if (*_len < (l * 2 + 3)) |
133 | 133 |
{ |
git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@5519 689a6050-402a-0410-94f2-e92a70836424
... | ... |
@@ -36,15 +36,41 @@ |
36 | 36 |
#include "val.h" |
37 | 37 |
#include "con.h" |
38 | 38 |
|
39 |
+/* |
|
40 |
+ * Used when converting the query to a result |
|
41 |
+ */ |
|
42 |
+int db_unixodbc_str2val(const db_type_t _t, db_val_t* _v, const char* _s, const int _l, |
|
43 |
+ const unsigned int _cpy) |
|
44 |
+{ |
|
45 |
+ /* db_unixodbc uses the NULL string for NULL SQL values */ |
|
46 |
+ if (_v && _s && !strcmp(_s, "NULL")) { |
|
47 |
+ LM_DBG("converting NULL value"); |
|
48 |
+ static str dummy_string = {"", 0}; |
|
49 |
+ memset(_v, 0, sizeof(db_val_t)); |
|
50 |
+ /* Initialize the string pointers to a dummy empty |
|
51 |
+ * string so that we do not crash when the NULL flag |
|
52 |
+ * is set but the module does not check it properly |
|
53 |
+ */ |
|
54 |
+ VAL_STRING(_v) = dummy_string.s; |
|
55 |
+ VAL_STR(_v) = dummy_string; |
|
56 |
+ VAL_BLOB(_v) = dummy_string; |
|
57 |
+ VAL_TYPE(_v) = _t; |
|
58 |
+ VAL_NULL(_v) = 1; |
|
59 |
+ return 0; |
|
60 |
+ } else { |
|
61 |
+ return db_str2val(_t, _v, _s, _l, _cpy); |
|
62 |
+ } |
|
63 |
+} |
|
39 | 64 |
|
40 | 65 |
/* |
41 |
- * Used when converting result from a query |
|
66 |
+ * Used when converting a result from the query |
|
42 | 67 |
*/ |
43 | 68 |
int db_unixodbc_val2str(const db_con_t* _c, const db_val_t* _v, char* _s, int* _len) |
44 | 69 |
{ |
45 | 70 |
int l, tmp; |
46 | 71 |
char* old_s; |
47 | 72 |
|
73 |
+ /* db_unixodbc uses a custom escape function */ |
|
48 | 74 |
tmp = db_val2str(_c, _v, _s, _len); |
49 | 75 |
if (tmp < 1) |
50 | 76 |
return tmp; |
git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@5359 689a6050-402a-0410-94f2-e92a70836424
... | ... |
@@ -37,85 +37,20 @@ |
37 | 37 |
#include "con.h" |
38 | 38 |
|
39 | 39 |
|
40 |
-#include <string.h> |
|
41 |
-#include <stdio.h> |
|
42 |
- |
|
43 |
- |
|
44 | 40 |
/* |
45 | 41 |
* Used when converting result from a query |
46 | 42 |
*/ |
47 | 43 |
int db_unixodbc_val2str(const db_con_t* _c, const db_val_t* _v, char* _s, int* _len) |
48 | 44 |
{ |
49 |
- int l; |
|
45 |
+ int l, tmp; |
|
50 | 46 |
char* old_s; |
51 | 47 |
|
52 |
- if (!_c || !_v || !_s || !_len || !*_len) |
|
53 |
- { |
|
54 |
- LM_ERR("invalid parameter value\n"); |
|
55 |
- return -1; |
|
56 |
- } |
|
57 |
- |
|
58 |
- if (VAL_NULL(_v)) |
|
59 |
- { |
|
60 |
- if (*_len < sizeof("NULL")) |
|
61 |
- { |
|
62 |
- LM_ERR("buffer too small\n"); |
|
63 |
- return -1; |
|
64 |
- } |
|
65 |
- *_len = snprintf(_s, *_len, "NULL"); |
|
66 |
- return 0; |
|
67 |
- } |
|
48 |
+ tmp = db_val2str(_c, _v, _s, _len); |
|
49 |
+ if (tmp < 1) |
|
50 |
+ return tmp; |
|
68 | 51 |
|
69 | 52 |
switch(VAL_TYPE(_v)) |
70 | 53 |
{ |
71 |
- case DB_INT: |
|
72 |
- if (db_int2str(VAL_INT(_v), _s, _len) < 0) |
|
73 |
- { |
|
74 |
- LM_ERR("converting string to int failed\n"); |
|
75 |
- return -2; |
|
76 |
- } |
|
77 |
- else |
|
78 |
- { |
|
79 |
- return 0; |
|
80 |
- } |
|
81 |
- break; |
|
82 |
- |
|
83 |
- case DB_BIGINT: |
|
84 |
- if (db_longlong2str(VAL_BIGINT(_v), _s, _len) < 0) |
|
85 |
- { |
|
86 |
- LM_ERR("converting string to big int failed\n"); |
|
87 |
- return -3; |
|
88 |
- } |
|
89 |
- else |
|
90 |
- { |
|
91 |
- return 0; |
|
92 |
- } |
|
93 |
- break; |
|
94 |
- |
|
95 |
- case DB_BITMAP: |
|
96 |
- if (db_int2str(VAL_BITMAP(_v), _s, _len) < 0) |
|
97 |
- { |
|
98 |
- LM_ERR("converting string to int failed\n"); |
|
99 |
- return -4; |
|
100 |
- } |
|
101 |
- else |
|
102 |
- { |
|
103 |
- return 0; |
|
104 |
- } |
|
105 |
- break; |
|
106 |
- |
|
107 |
- case DB_DOUBLE: |
|
108 |
- if (db_double2str(VAL_DOUBLE(_v), _s, _len) < 0) |
|
109 |
- { |
|
110 |
- LM_ERR("converting string to double failed\n"); |
|
111 |
- return -5; |
|
112 |
- } |
|
113 |
- else |
|
114 |
- { |
|
115 |
- return 0; |
|
116 |
- } |
|
117 |
- break; |
|
118 |
- |
|
119 | 54 |
case DB_STRING: |
120 | 55 |
l = strlen(VAL_STRING(_v)); |
121 | 56 |
if (*_len < (l * 2 + 3)) |
... | ... |
@@ -166,18 +101,6 @@ int db_unixodbc_val2str(const db_con_t* _c, const db_val_t* _v, char* _s, int* _ |
166 | 101 |
} |
167 | 102 |
break; |
168 | 103 |
|
169 |
- case DB_DATETIME: |
|
170 |
- if (db_time2str(VAL_TIME(_v), _s, _len) < 0) |
|
171 |
- { |
|
172 |
- LM_ERR("converting string to time_t failed\n"); |
|
173 |
- return -8; |
|
174 |
- } |
|
175 |
- else |
|
176 |
- { |
|
177 |
- return 0; |
|
178 |
- } |
|
179 |
- break; |
|
180 |
- |
|
181 | 104 |
case DB_BLOB: |
182 | 105 |
l = VAL_BLOB(_v).len; |
183 | 106 |
if (*_len < (l * 2 + 3)) |
git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@5322 689a6050-402a-0410-94f2-e92a70836424
... | ... |
@@ -41,130 +41,6 @@ |
41 | 41 |
#include <stdio.h> |
42 | 42 |
|
43 | 43 |
|
44 |
-/* |
|
45 |
- * Convert str to db value, does not copy strings |
|
46 |
- */ |
|
47 |
-int db_unixodbc_str2val(const db_type_t _t, db_val_t* _v, const char* _s, const int _l) |
|
48 |
-{ |
|
49 |
- static str dummy_string = {"", 0}; |
|
50 |
- |
|
51 |
- if (!_v) |
|
52 |
- { |
|
53 |
- LM_ERR("invalid parameter value\n"); |
|
54 |
- return -1; |
|
55 |
- } |
|
56 |
- |
|
57 |
- if (!_s || !strcmp(_s, "NULL")) |
|
58 |
- { |
|
59 |
- memset(_v, 0, sizeof(db_val_t)); |
|
60 |
-/* Initialize the string pointers to a dummy empty |
|
61 |
- * string so that we do not crash when the NULL flag |
|
62 |
- * is set but the module does not check it properly |
|
63 |
- */ |
|
64 |
- VAL_STRING(_v) = dummy_string.s; |
|
65 |
- VAL_STR(_v) = dummy_string; |
|
66 |
- VAL_BLOB(_v) = dummy_string; |
|
67 |
- VAL_TYPE(_v) = _t; |
|
68 |
- VAL_NULL(_v) = 1; |
|
69 |
- return 0; |
|
70 |
- } |
|
71 |
- VAL_NULL(_v) = 0; |
|
72 |
- |
|
73 |
- switch(_t) |
|
74 |
- { |
|
75 |
- case DB_INT: |
|
76 |
- LM_DBG("converting INT [%s]\n", _s); |
|
77 |
- if (db_str2int(_s, &VAL_INT(_v)) < 0) |
|
78 |
- { |
|
79 |
- LM_ERR("converting integer value from string failed\n"); |
|
80 |
- return -2; |
|
81 |
- } |
|
82 |
- else |
|
83 |
- { |
|
84 |
- VAL_TYPE(_v) = DB_INT; |
|
85 |
- return 0; |
|
86 |
- } |
|
87 |
- break; |
|
88 |
- |
|
89 |
- case DB_BIGINT: |
|
90 |
- LM_DBG("converting BIGINT [%s]\n", _s); |
|
91 |
- if (db_str2longlong(_s, &VAL_BIGINT(_v)) < 0) |
|
92 |
- { |
|
93 |
- LM_ERR("converting big integer value from string failed\n"); |
|
94 |
- return -3; |
|
95 |
- } |
|
96 |
- else |
|
97 |
- { |
|
98 |
- VAL_TYPE(_v) = DB_BIGINT; |
|
99 |
- return 0; |
|
100 |
- } |
|
101 |
- break; |
|
102 |
- |
|
103 |
- case DB_BITMAP: |
|
104 |
- LM_DBG("converting BITMAP [%s]\n", _s); |
|
105 |
- if (db_str2int(_s, &VAL_INT(_v)) < 0) |
|
106 |
- { |
|
107 |
- LM_ERR("converting bitmap value from string failed\n"); |
|
108 |
- return -4; |
|
109 |
- } |
|
110 |
- else |
|
111 |
- { |
|
112 |
- VAL_TYPE(_v) = DB_BITMAP; |
|
113 |
- return 0; |
|
114 |
- } |
|
115 |
- break; |
|
116 |
- |
|
117 |
- case DB_DOUBLE: |
|
118 |
- LM_DBG("converting DOUBLE [%s]\n", _s); |
|
119 |
- if (db_str2double(_s, &VAL_DOUBLE(_v)) < 0) |
|
120 |
- { |
|
121 |
- LM_ERR("converting double value from string failed\n"); |
|
122 |
- return -5; |
|
123 |
- } |
|
124 |
- else |
|
125 |
- { |
|
126 |
- VAL_TYPE(_v) = DB_DOUBLE; |
|
127 |
- return 0; |
|
128 |
- } |
|
129 |
- break; |
|
130 |
- |
|
131 |
- case DB_STRING: |
|
132 |
- LM_DBG("converting STRING [%s]\n", _s); |
|
133 |
- VAL_STRING(_v) = _s; |
|
134 |
- VAL_TYPE(_v) = DB_STRING; |
|
135 |
- return 0; |
|
136 |
- |
|
137 |
- case DB_STR: |
|
138 |
- LM_DBG("converting STR [%.*s]\n", _l, _s); |
|
139 |
- VAL_STR(_v).s = (char*)_s; |
|
140 |
- VAL_STR(_v).len = _l; |
|
141 |
- VAL_TYPE(_v) = DB_STR; |
|
142 |
- return 0; |
|
143 |
- |
|
144 |
- case DB_DATETIME: |
|
145 |
- LM_DBG("converting DATETIME [%s]\n", _s); |
|
146 |
- if (db_str2time(_s, &VAL_TIME(_v)) < 0) |
|
147 |
- { |
|
148 |
- LM_ERR("converting datetime value from string failed\n"); |
|
149 |
- return -6; |
|
150 |
- } |
|
151 |
- else |
|
152 |
- { |
|
153 |
- VAL_TYPE(_v) = DB_DATETIME; |
|
154 |
- return 0; |
|
155 |
- } |
|
156 |
- break; |
|
157 |
- |
|
158 |
- case DB_BLOB: |
|
159 |
- LM_DBG("converting BLOB [%.*s]\n", _l, _s); |
|
160 |
- VAL_BLOB(_v).s = (char*)_s; |
|
161 |
- VAL_BLOB(_v).len = _l; |
|
162 |
- VAL_TYPE(_v) = DB_BLOB; |
|
163 |
- return 0; |
|
164 |
- } |
|
165 |
- return -7; |
|
166 |
-} |
|
167 |
- |
|
168 | 44 |
/* |
169 | 45 |
* Used when converting result from a query |
170 | 46 |
*/ |
git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@4965 689a6050-402a-0410-94f2-e92a70836424
git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@4928 689a6050-402a-0410-94f2-e92a70836424
... | ... |
@@ -86,12 +86,26 @@ int db_unixodbc_str2val(const db_type_t _t, db_val_t* _v, const char* _s, const |
86 | 86 |
} |
87 | 87 |
break; |
88 | 88 |
|
89 |
+ case DB_BIGINT: |
|
90 |
+ LM_DBG("converting BIGINT [%s]\n", _s); |
|
91 |
+ if (db_str2longlong(_s, &VAL_BIGINT(_v)) < 0) |
|
92 |
+ { |
|
93 |
+ LM_ERR("converting big integer value from string failed\n"); |
|
94 |
+ return -3; |
|
95 |
+ } |
|
96 |
+ else |
|
97 |
+ { |
|
98 |
+ VAL_TYPE(_v) = DB_BIGINT; |
|
99 |
+ return 0; |
|
100 |
+ } |
|
101 |
+ break; |
|
102 |
+ |
|
89 | 103 |
case DB_BITMAP: |
90 | 104 |
LM_DBG("converting BITMAP [%s]\n", _s); |
91 | 105 |
if (db_str2int(_s, &VAL_INT(_v)) < 0) |
92 | 106 |
{ |
93 | 107 |
LM_ERR("converting bitmap value from string failed\n"); |
94 |
- return -3; |
|
108 |
+ return -4; |
|
95 | 109 |
} |
96 | 110 |
else |
97 | 111 |
{ |
... | ... |
@@ -105,7 +119,7 @@ int db_unixodbc_str2val(const db_type_t _t, db_val_t* _v, const char* _s, const |
105 | 119 |
if (db_str2double(_s, &VAL_DOUBLE(_v)) < 0) |
106 | 120 |
{ |
107 | 121 |
LM_ERR("converting double value from string failed\n"); |
108 |
- return -4; |
|
122 |
+ return -5; |
|
109 | 123 |
} |
110 | 124 |
else |
111 | 125 |
{ |
... | ... |
@@ -132,7 +146,7 @@ int db_unixodbc_str2val(const db_type_t _t, db_val_t* _v, const char* _s, const |
132 | 146 |
if (db_str2time(_s, &VAL_TIME(_v)) < 0) |
133 | 147 |
{ |
134 | 148 |
LM_ERR("converting datetime value from string failed\n"); |
135 |
- return -5; |
|
149 |
+ return -6; |
|
136 | 150 |
} |
137 | 151 |
else |
138 | 152 |
{ |
... | ... |
@@ -148,7 +162,7 @@ int db_unixodbc_str2val(const db_type_t _t, db_val_t* _v, const char* _s, const |
148 | 162 |
VAL_TYPE(_v) = DB_BLOB; |
149 | 163 |
return 0; |
150 | 164 |
} |
151 |
- return -6; |
|
165 |
+ return -7; |
|
152 | 166 |
} |
153 | 167 |
|
154 | 168 |
/* |
... | ... |
@@ -190,11 +204,23 @@ int db_unixodbc_val2str(const db_con_t* _c, const db_val_t* _v, char* _s, int* _ |
190 | 204 |
} |
191 | 205 |
break; |
192 | 206 |
|
207 |
+ case DB_BIGINT: |
|
208 |
+ if (db_longlong2str(VAL_BIGINT(_v), _s, _len) < 0) |
|
209 |
+ { |
|
210 |
+ LM_ERR("converting string to big int failed\n"); |
|
211 |
+ return -3; |
|
212 |
+ } |
|
213 |
+ else |
|
214 |
+ { |
|
215 |
+ return 0; |
|
216 |
+ } |
|
217 |
+ break; |
|
218 |
+ |
|
193 | 219 |
case DB_BITMAP: |
194 | 220 |
if (db_int2str(VAL_BITMAP(_v), _s, _len) < 0) |
195 | 221 |
{ |
196 | 222 |
LM_ERR("converting string to int failed\n"); |
197 |
- return -3; |
|
223 |
+ return -4; |
|
198 | 224 |
} |
199 | 225 |
else |
200 | 226 |
{ |
... | ... |
@@ -206,7 +232,7 @@ int db_unixodbc_val2str(const db_con_t* _c, const db_val_t* _v, char* _s, int* _ |
206 | 232 |
if (db_double2str(VAL_DOUBLE(_v), _s, _len) < 0) |
207 | 233 |
{ |
208 | 234 |
LM_ERR("converting string to double failed\n"); |
209 |
- return -4; |
|
235 |
+ return -5; |
|
210 | 236 |
} |
211 | 237 |
else |
212 | 238 |
{ |
... | ... |
@@ -219,7 +245,7 @@ int db_unixodbc_val2str(const db_con_t* _c, const db_val_t* _v, char* _s, int* _ |
219 | 245 |
if (*_len < (l * 2 + 3)) |
220 | 246 |
{ |
221 | 247 |
LM_ERR("destination buffer too short\n"); |
222 |
- return -5; |
|
248 |
+ return -6; |
|
223 | 249 |
} |
224 | 250 |
else |
225 | 251 |
{ |
... | ... |
@@ -244,7 +270,7 @@ int db_unixodbc_val2str(const db_con_t* _c, const db_val_t* _v, char* _s, int* _ |
244 | 270 |
if (*_len < (l * 2 + 3)) |
245 | 271 |
{ |
246 | 272 |
LM_ERR("destination buffer too short\n"); |
247 |
- return -6; |
|
273 |
+ return -7; |
|
248 | 274 |
} |
249 | 275 |
else |
250 | 276 |
{ |
... | ... |
@@ -268,7 +294,7 @@ int db_unixodbc_val2str(const db_con_t* _c, const db_val_t* _v, char* _s, int* _ |
268 | 294 |
if (db_time2str(VAL_TIME(_v), _s, _len) < 0) |
269 | 295 |
{ |
270 | 296 |
LM_ERR("converting string to time_t failed\n"); |
271 |
- return -7; |
|
297 |
+ return -8; |
|
272 | 298 |
} |
273 | 299 |
else |
274 | 300 |
{ |
... | ... |
@@ -281,7 +307,7 @@ int db_unixodbc_val2str(const db_con_t* _c, const db_val_t* _v, char* _s, int* _ |
281 | 307 |
if (*_len < (l * 2 + 3)) |
282 | 308 |
{ |
283 | 309 |
LM_ERR("destination buffer too short\n"); |
284 |
- return -8; |
|
310 |
+ return -9; |
|
285 | 311 |
} |
286 | 312 |
else |
287 | 313 |
{ |
... | ... |
@@ -303,7 +329,7 @@ int db_unixodbc_val2str(const db_con_t* _c, const db_val_t* _v, char* _s, int* _ |
303 | 329 |
|
304 | 330 |
default: |
305 | 331 |
LM_DBG("unknown data type\n"); |
306 |
- return -9; |
|
332 |
+ return -10; |
|
307 | 333 |
} |
308 | 334 |
/*return -8; --not reached*/ |
309 | 335 |
} |
git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@4518 689a6050-402a-0410-94f2-e92a70836424
... | ... |
@@ -6,14 +6,14 @@ |
6 | 6 |
* Copyright (C) 2005-2006 Marco Lorrai |
7 | 7 |
* Copyright (C) 2008 1&1 Internet AG |
8 | 8 |
* |
9 |
- * This file is part of openser, a free SIP server. |
|
9 |
+ * This file is part of Kamailio, a free SIP server. |
|
10 | 10 |
* |
11 |
- * openser is free software; you can redistribute it and/or modify |
|
11 |
+ * Kamailio is free software; you can redistribute it and/or modify |
|
12 | 12 |
* it under the terms of the GNU General Public License as published by |
13 | 13 |
* the Free Software Foundation; either version 2 of the License, or |
14 | 14 |
* (at your option) any later version |
15 | 15 |
* |
16 |
- * openser is distributed in the hope that it will be useful, |
|
16 |
+ * Kamailio is distributed in the hope that it will be useful, |
|
17 | 17 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
18 | 18 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
19 | 19 |
* GNU General Public License for more details. |
git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@3666 689a6050-402a-0410-94f2-e92a70836424
git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@3638 689a6050-402a-0410-94f2-e92a70836424
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,309 @@ |
1 |
+/* |
|
2 |
+ * $Id$ |
|
3 |
+ * |
|
4 |
+ * UNIXODBC module |
|
5 |
+ * |
|
6 |
+ * Copyright (C) 2005-2006 Marco Lorrai |
|
7 |
+ * Copyright (C) 2008 1&1 Internet AG |
|
8 |
+ * |
|
9 |
+ * This file is part of openser, a free SIP server. |
|
10 |
+ * |
|
11 |
+ * openser is free software; you can redistribute it and/or modify |
|
12 |
+ * it under the terms of the GNU General Public License as published by |
|
13 |
+ * the Free Software Foundation; either version 2 of the License, or |
|
14 |
+ * (at your option) any later version |
|
15 |
+ * |
|
16 |
+ * openser is distributed in the hope that it will be useful, |
|
17 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
19 |
+ * GNU General Public License for more details. |
|
20 |
+ * |
|
21 |
+ * You should have received a copy of the GNU General Public License |
|
22 |
+ * along with this program; if not, write to the Free Software |
|
23 |
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
24 |
+ * |
|
25 |
+ * |
|
26 |
+ * History: |
|
27 |
+ * -------- |
|
28 |
+ * 2005-12-01 initial commit (chgen) |
|
29 |
+ */ |
|
30 |
+ |
|
31 |
+ |
|
32 |
+#include "../../dprint.h" |
|
33 |
+#include "../../strcommon.h" |
|
34 |
+#include "../../db/db_ut.h" |
|
35 |
+#include "db_mod.h" |
|
36 |
+#include "val.h" |
|
37 |
+#include "my_con.h" |
|
38 |
+ |
|
39 |
+ |
|
40 |
+#include <string.h> |
|
41 |
+#include <stdio.h> |
|
42 |
+ |
|
43 |
+ |
|
44 |
+/* |
|
45 |
+ * Convert str to db value, does not copy strings |
|
46 |
+ */ |
|
47 |
+int db_unixodbc_str2val(const db_type_t _t, db_val_t* _v, const char* _s, const int _l) |
|
48 |
+{ |
|
49 |
+ static str dummy_string = {"", 0}; |
|
50 |
+ |
|
51 |
+ if (!_v) |
|
52 |
+ { |
|
53 |
+ LM_ERR("invalid parameter value\n"); |
|
54 |
+ return -1; |
|
55 |
+ } |
|
56 |
+ |
|
57 |
+ if (!_s || !strcmp(_s, "NULL")) |
|
58 |
+ { |
|
59 |
+ memset(_v, 0, sizeof(db_val_t)); |
|
60 |
+/* Initialize the string pointers to a dummy empty |
|
61 |
+ * string so that we do not crash when the NULL flag |
|
62 |
+ * is set but the module does not check it properly |
|
63 |
+ */ |
|
64 |
+ VAL_STRING(_v) = dummy_string.s; |
|
65 |
+ VAL_STR(_v) = dummy_string; |
|
66 |
+ VAL_BLOB(_v) = dummy_string; |
|
67 |
+ VAL_TYPE(_v) = _t; |
|
68 |
+ VAL_NULL(_v) = 1; |
|
69 |
+ return 0; |
|
70 |
+ } |
|
71 |
+ VAL_NULL(_v) = 0; |
|
72 |
+ |
|
73 |
+ switch(_t) |
|
74 |
+ { |
|
75 |
+ case DB_INT: |
|
76 |
+ LM_DBG("converting INT [%s]\n", _s); |
|
77 |
+ if (db_str2int(_s, &VAL_INT(_v)) < 0) |
|
78 |
+ { |
|
79 |
+ LM_ERR("converting integer value from string failed\n"); |
|
80 |
+ return -2; |
|
81 |
+ } |
|
82 |
+ else |
|
83 |
+ { |
|
84 |
+ VAL_TYPE(_v) = DB_INT; |
|
85 |
+ return 0; |
|
86 |
+ } |
|
87 |
+ break; |
|
88 |
+ |
|
89 |
+ case DB_BITMAP: |
|
90 |
+ LM_DBG("converting BITMAP [%s]\n", _s); |
|
91 |
+ if (db_str2int(_s, &VAL_INT(_v)) < 0) |
|
92 |
+ { |
|
93 |
+ LM_ERR("converting bitmap value from string failed\n"); |
|
94 |
+ return -3; |
|
95 |
+ } |
|
96 |
+ else |
|
97 |
+ { |
|
98 |
+ VAL_TYPE(_v) = DB_BITMAP; |
|
99 |
+ return 0; |
|
100 |
+ } |
|
101 |
+ break; |
|
102 |
+ |
|
103 |
+ case DB_DOUBLE: |
|
104 |
+ LM_DBG("converting DOUBLE [%s]\n", _s); |
|
105 |
+ if (db_str2double(_s, &VAL_DOUBLE(_v)) < 0) |
|
106 |
+ { |
|
107 |
+ LM_ERR("converting double value from string failed\n"); |
|
108 |
+ return -4; |
|
109 |
+ } |
|
110 |
+ else |
|
111 |
+ { |
|
112 |
+ VAL_TYPE(_v) = DB_DOUBLE; |
|
113 |
+ return 0; |
|
114 |
+ } |
|
115 |
+ break; |
|
116 |
+ |
|
117 |
+ case DB_STRING: |
|
118 |
+ LM_DBG("converting STRING [%s]\n", _s); |
|
119 |
+ VAL_STRING(_v) = _s; |
|
120 |
+ VAL_TYPE(_v) = DB_STRING; |
|
121 |
+ return 0; |
|
122 |
+ |
|
123 |
+ case DB_STR: |
|
124 |
+ LM_DBG("converting STR [%.*s]\n", _l, _s); |
|
125 |
+ VAL_STR(_v).s = (char*)_s; |
|
126 |
+ VAL_STR(_v).len = _l; |
|
127 |
+ VAL_TYPE(_v) = DB_STR; |
|
128 |
+ return 0; |
|
129 |
+ |
|
130 |
+ case DB_DATETIME: |
|
131 |
+ LM_DBG("converting DATETIME [%s]\n", _s); |
|
132 |
+ if (db_str2time(_s, &VAL_TIME(_v)) < 0) |
|
133 |
+ { |
|
134 |
+ LM_ERR("converting datetime value from string failed\n"); |
|
135 |
+ return -5; |
|
136 |
+ } |
|
137 |
+ else |
|
138 |
+ { |
|
139 |
+ VAL_TYPE(_v) = DB_DATETIME; |
|
140 |
+ return 0; |
|
141 |
+ } |
|
142 |
+ break; |
|
143 |
+ |
|
144 |
+ case DB_BLOB: |
|
145 |
+ LM_DBG("converting BLOB [%.*s]\n", _l, _s); |
|
146 |
+ VAL_BLOB(_v).s = (char*)_s; |
|
147 |
+ VAL_BLOB(_v).len = _l; |
|
148 |
+ VAL_TYPE(_v) = DB_BLOB; |
|
149 |
+ return 0; |
|
150 |
+ } |
|
151 |
+ return -6; |
|
152 |
+} |
|
153 |
+ |
|
154 |
+/* |
|
155 |
+ * Used when converting result from a query |
|
156 |
+ */ |
|
157 |
+int db_unixodbc_val2str(const db_con_t* _c, const db_val_t* _v, char* _s, int* _len) |
|
158 |
+{ |
|
159 |
+ int l; |
|
160 |
+ char* old_s; |
|
161 |
+ |
|
162 |
+ if (!_c || !_v || !_s || !_len || !*_len) |
|
163 |
+ { |
|
164 |
+ LM_ERR("invalid parameter value\n"); |
|
165 |
+ return -1; |
|
166 |
+ } |
|
167 |
+ |
|
168 |
+ if (VAL_NULL(_v)) |
|
169 |
+ { |
|
170 |
+ if (*_len < sizeof("NULL")) |
|
171 |
+ { |
|
172 |
+ LM_ERR("buffer too small\n"); |
|
173 |
+ return -1; |
|
174 |
+ } |
|
175 |
+ *_len = snprintf(_s, *_len, "NULL"); |
|
176 |
+ return 0; |
|
177 |
+ } |
|
178 |
+ |
|
179 |
+ switch(VAL_TYPE(_v)) |
|
180 |
+ { |
|
181 |
+ case DB_INT: |
|
182 |
+ if (db_int2str(VAL_INT(_v), _s, _len) < 0) |
|
183 |
+ { |
|
184 |
+ LM_ERR("converting string to int failed\n"); |
|
185 |
+ return -2; |
|
186 |
+ } |
|
187 |
+ else |
|
188 |
+ { |
|
189 |
+ return 0; |
|
190 |
+ } |
|
191 |
+ break; |
|
192 |
+ |
|
193 |
+ case DB_BITMAP: |
|
194 |
+ if (db_int2str(VAL_BITMAP(_v), _s, _len) < 0) |
|
195 |
+ { |
|
196 |
+ LM_ERR("converting string to int failed\n"); |
|
197 |
+ return -3; |
|
198 |
+ } |
|
199 |
+ else |
|
200 |
+ { |
|
201 |
+ return 0; |
|
202 |
+ } |
|
203 |
+ break; |
|
204 |
+ |
|
205 |
+ case DB_DOUBLE: |
|
206 |
+ if (db_double2str(VAL_DOUBLE(_v), _s, _len) < 0) |
|
207 |
+ { |
|
208 |
+ LM_ERR("converting string to double failed\n"); |
|
209 |
+ return -4; |
|
210 |
+ } |
|
211 |
+ else |
|
212 |
+ { |
|
213 |
+ return 0; |
|
214 |
+ } |
|
215 |
+ break; |
|
216 |
+ |
|
217 |
+ case DB_STRING: |
|
218 |
+ l = strlen(VAL_STRING(_v)); |
|
219 |
+ if (*_len < (l * 2 + 3)) |
|
220 |
+ { |
|
221 |
+ LM_ERR("destination buffer too short\n"); |
|
222 |
+ return -5; |
|
223 |
+ } |
|
224 |
+ else |
|
225 |
+ { |
|
226 |
+ old_s = _s; |
|
227 |
+ *_s++ = '\''; |
|
228 |
+ if(use_escape_common) |
|
229 |
+ { |
|
230 |
+ _s += escape_common(_s, (char*)VAL_STRING(_v), l); |
|
231 |
+ } else { |
|
232 |
+ memcpy(_s, VAL_STRING(_v), l); |
|
233 |
+ _s += l; |
|
234 |
+ } |
|
235 |
+ *_s++ = '\''; |
|