Browse code

core, lib, modules: restructured source code tree

- new folder src/ to hold the source code for main project applications
- main.c is in src/
- all core files are subfolder are in src/core/
- modules are in src/modules/
- libs are in src/lib/
- application Makefiles are in src/
- application binary is built in src/ (src/kamailio)

Daniel-Constantin Mierla authored on 07/12/2016 11:03:51
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,105 +0,0 @@
1
-/* 
2
- * Copyright (C) 2001-2003 FhG Fokus
3
- * Copyright (C) 2008 1&1 Internet AG
4
- *
5
- * This file is part of Kamailio, a free SIP server.
6
- *
7
- * Kamailio is free software; you can redistribute it and/or modify
8
- * it under the terms of the GNU General Public License as published by
9
- * the Free Software Foundation; either version 2 of the License, or
10
- * (at your option) any later version
11
- *
12
- * Kamailio is distributed in the hope that it will be useful,
13
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
- * GNU General Public License for more details.
16
- *
17
- * You should have received a copy of the GNU General Public License 
18
- * along with this program; if not, write to the Free Software 
19
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
20
- */
21
-
22
-/*! \file
23
- *  \brief DB_MYSQL :: Data conversions
24
- *  \ingroup db_mysql
25
- *  Module: \ref db_mysql
26
- */
27
-
28
-#include "../../dprint.h"
29
-#include "../../lib/srdb1/db_ut.h"
30
-#include "km_val.h"
31
-#include "km_my_con.h"
32
-
33
-
34
-/*!
35
- * \brief Converting a value to a string
36
- *
37
- * Converting a value to a string, used when converting result from a query
38
- * \param _c database connection
39
- * \param _v source value
40
- * \param _s target string
41
- * \param _len target string length
42
- * \return 0 on success, negative on error
43
- */
44
-int db_mysql_val2str(const db1_con_t* _c, const db_val_t* _v, char* _s, int* _len)
45
-{
46
-	int l, tmp;
47
-	char* old_s;
48
-
49
-	tmp = db_val2str(_c, _v, _s, _len);
50
-	if (tmp < 1)
51
-		return tmp;
52
-
53
-	switch(VAL_TYPE(_v)) {
54
-	case DB1_STRING:
55
-		l = strlen(VAL_STRING(_v));
56
-		if (*_len < (l * 2 + 3)) {
57
-			LM_ERR("destination buffer too short\n");
58
-			return -6;
59
-		} else {
60
-			old_s = _s;
61
-			*_s++ = '\'';
62
-			_s += mysql_real_escape_string(CON_CONNECTION(_c), _s, VAL_STRING(_v), l);
63
-			*_s++ = '\'';
64
-			*_s = '\0'; /* FIXME */
65
-			*_len = _s - old_s;
66
-			return 0;
67
-		}
68
-		break;
69
-
70
-	case DB1_STR:
71
-		if (*_len < (VAL_STR(_v).len * 2 + 3)) {
72
-			LM_ERR("destination buffer too short\n");
73
-			return -7;
74
-		} else {
75
-			old_s = _s;
76
-			*_s++ = '\'';
77
-			_s += mysql_real_escape_string(CON_CONNECTION(_c), _s, VAL_STR(_v).s, VAL_STR(_v).len);
78
-			*_s++ = '\'';
79
-			*_s = '\0';
80
-			*_len = _s - old_s;
81
-			return 0;
82
-		}
83
-		break;
84
-
85
-	case DB1_BLOB:
86
-		l = VAL_BLOB(_v).len;
87
-		if (*_len < (l * 2 + 3)) {
88
-			LM_ERR("destination buffer too short\n");
89
-			return -9;
90
-		} else {
91
-			old_s = _s;
92
-			*_s++ = '\'';
93
-			_s += mysql_real_escape_string(CON_CONNECTION(_c), _s, VAL_STR(_v).s, l);
94
-			*_s++ = '\'';
95
-			*_s = '\0';
96
-			*_len = _s - old_s;
97
-			return 0;
98
-		}			
99
-		break;
100
-
101
-	default:
102
-		LM_DBG("unknown data type\n");
103
-		return -10;
104
-	}
105
-}
Browse code

db_mysql: Remove SVN ID's, remove history sections

Olle E. Johansson authored on 11/03/2015 15:26:21
Showing 1 changed files
... ...
@@ -1,6 +1,4 @@
1 1
 /* 
2
- * $Id$ 
3
- *
4 2
  * Copyright (C) 2001-2003 FhG Fokus
5 3
  * Copyright (C) 2008 1&1 Internet AG
6 4
  *
Browse code

all: updated FSF address in GPL text

Anthony Messina authored on 04/07/2014 09:36:37 • Daniel-Constantin Mierla committed on 04/07/2014 09:37:36
Showing 1 changed files
... ...
@@ -18,7 +18,7 @@
18 18
  *
19 19
  * You should have received a copy of the GNU General Public License 
20 20
  * along with this program; if not, write to the Free Software 
21
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22 22
  */
23 23
 
24 24
 /*! \file
Browse code

DB_* renamed to DB1_* in files originating from kamailio/db_mysql.

Jan Janak authored on 16/02/2009 22:17:48
Showing 1 changed files
... ...
@@ -53,7 +53,7 @@ int db_mysql_val2str(const db1_con_t* _c, const db_val_t* _v, char* _s, int* _le
53 53
 		return tmp;
54 54
 
55 55
 	switch(VAL_TYPE(_v)) {
56
-	case DB_STRING:
56
+	case DB1_STRING:
57 57
 		l = strlen(VAL_STRING(_v));
58 58
 		if (*_len < (l * 2 + 3)) {
59 59
 			LM_ERR("destination buffer too short\n");
... ...
@@ -69,7 +69,7 @@ int db_mysql_val2str(const db1_con_t* _c, const db_val_t* _v, char* _s, int* _le
69 69
 		}
70 70
 		break;
71 71
 
72
-	case DB_STR:
72
+	case DB1_STR:
73 73
 		if (*_len < (VAL_STR(_v).len * 2 + 3)) {
74 74
 			LM_ERR("destination buffer too short\n");
75 75
 			return -7;
... ...
@@ -84,7 +84,7 @@ int db_mysql_val2str(const db1_con_t* _c, const db_val_t* _v, char* _s, int* _le
84 84
 		}
85 85
 		break;
86 86
 
87
-	case DB_BLOB:
87
+	case DB1_BLOB:
88 88
 		l = VAL_BLOB(_v).len;
89 89
 		if (*_len < (l * 2 + 3)) {
90 90
 			LM_ERR("destination buffer too short\n");
Browse code

db_con renamed to db1_con in files originating from kamailio/db_mysql.

The structure db_con has been renamed in lib/srdb1 to db1_con, thus we
need to change the name of the structure in all files originating from
kamailio/modules/db_mysql (and using lib/srdb1).

Jan Janak authored on 16/02/2009 22:09:32
Showing 1 changed files
... ...
@@ -43,7 +43,7 @@
43 43
  * \param _len target string length
44 44
  * \return 0 on success, negative on error
45 45
  */
46
-int db_mysql_val2str(const db_con_t* _c, const db_val_t* _v, char* _s, int* _len)
46
+int db_mysql_val2str(const db1_con_t* _c, const db_val_t* _v, char* _s, int* _len)
47 47
 {
48 48
 	int l, tmp;
49 49
 	char* old_s;
Browse code

Integration of both modules, first step.

* Defines protecting header files from double inclusion fixed to match
filenames.
* Linked the module also with srdb1
* Fixed path to header files in lib/srdb1.
* Filenames of local included header files prefixed with km_ to match
their real filenames

Jan Janak authored on 16/02/2009 21:58:33
Showing 1 changed files
... ...
@@ -28,9 +28,9 @@
28 28
  */
29 29
 
30 30
 #include "../../dprint.h"
31
-#include "../../db/db_ut.h"
32
-#include "val.h"
33
-#include "my_con.h"
31
+#include "../../lib/srdb1/db_ut.h"
32
+#include "km_val.h"
33
+#include "km_my_con.h"
34 34
 
35 35
 
36 36
 /*!
Browse code

- change behaviour of db_str2val, this now copy strings - this change was necessary because in some circumstances the memory that is returned from the database driver is used by some other means too fast, causes crashed or wrong results later on, this bug is timing related - this means for mysql and unixodbc that the performance will be decreased a bit, postgres already copied the string, so here nothing change - add a new function to DB core API, db_val2str that, usable to convert numerical values to a string, and common things like NULL values conversion, parameter checks - convert mysql, postgres and unixodbc module to use this new function - convert postgres function to use the core db_str2val function, the copying is now done at a different place, cleanup the code somewhat - remove unnecessary assignment if a NULL value is encountered in postgres - TODO: fix NULL handling and double copying that is done now for unixodbc

git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@5359 689a6050-402a-0410-94f2-e92a70836424

Henning Westerholt authored on 15/12/2008 15:07:12
Showing 1 changed files
... ...
@@ -32,9 +32,6 @@
32 32
 #include "val.h"
33 33
 #include "my_con.h"
34 34
 
35
-#include <string.h>
36
-#include <stdio.h>
37
-
38 35
 
39 36
 /*!
40 37
  * \brief Converting a value to a string
... ...
@@ -48,60 +45,14 @@
48 45
  */
49 46
 int db_mysql_val2str(const db_con_t* _c, const db_val_t* _v, char* _s, int* _len)
50 47
 {
51
-	int l;
48
+	int l, tmp;
52 49
 	char* old_s;
53 50
 
54
-	if (!_c || !_v || !_s || !_len || !*_len) {
55
-		LM_ERR("invalid parameter value\n");
56
-		return -1;
57
-	}
51
+	tmp = db_val2str(_c, _v, _s, _len);
52
+	if (tmp < 1)
53
+		return tmp;
58 54
 
59
-	if (VAL_NULL(_v)) {
60
-		if (*_len < sizeof("NULL")) {
61
-			LM_ERR("buffer too small\n");
62
-			return -1;
63
-		}
64
-		*_len = snprintf(_s, *_len, "NULL");
65
-		return 0;
66
-	}
67
-	
68 55
 	switch(VAL_TYPE(_v)) {
69
-	case DB_INT:
70
-		if (db_int2str(VAL_INT(_v), _s, _len) < 0) {
71
-			LM_ERR("error while converting string to int\n");
72
-			return -2;
73
-		} else {
74
-			return 0;
75
-		}
76
-		break;
77
-
78
-	case DB_BIGINT:
79
-		if (db_longlong2str(VAL_BIGINT(_v), _s, _len) < 0) {
80
-			LM_ERR("error while converting string to big int\n");
81
-			return -3;
82
-		} else {
83
-			return 0;
84
-		}
85
-		break;
86
-
87
-	case DB_BITMAP:
88
-		if (db_int2str(VAL_BITMAP(_v), _s, _len) < 0) {
89
-			LM_ERR("error while converting string to int\n");
90
-			return -4;
91
-		} else {
92
-			return 0;
93
-		}
94
-		break;
95
-
96
-	case DB_DOUBLE:
97
-		if (db_double2str(VAL_DOUBLE(_v), _s, _len) < 0) {
98
-			LM_ERR("error while converting string to double\n");
99
-			return -5;
100
-		} else {
101
-			return 0;
102
-		}
103
-		break;
104
-
105 56
 	case DB_STRING:
106 57
 		l = strlen(VAL_STRING(_v));
107 58
 		if (*_len < (l * 2 + 3)) {
... ...
@@ -133,15 +84,6 @@ int db_mysql_val2str(const db_con_t* _c, const db_val_t* _v, char* _s, int* _len
133 84
 		}
134 85
 		break;
135 86
 
136
-	case DB_DATETIME:
137
-		if (db_time2str(VAL_TIME(_v), _s, _len) < 0) {
138
-			LM_ERR("error while converting string to time_t\n");
139
-			return -8;
140
-		} else {
141
-			return 0;
142
-		}
143
-		break;
144
-
145 87
 	case DB_BLOB:
146 88
 		l = VAL_BLOB(_v).len;
147 89
 		if (*_len < (l * 2 + 3)) {
Browse code

- move db_mysql and db_unixodbc str2val implementation to the DB core, remove the duplicated implementation in the modules (preparation for query copy problem) - introduced a small regression for the unixodbc in the NULL value handling that needs to be fixed

git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@5322 689a6050-402a-0410-94f2-e92a70836424

Henning Westerholt authored on 10/12/2008 18:41:09
Showing 1 changed files
... ...
@@ -36,120 +36,6 @@
36 36
 #include <stdio.h>
37 37
 
38 38
 
39
-/*!
40
- * \brief Convert a str to a db value, does not copy strings
41
- *
42
- * Convert a str to a db value, does not copy strings.
43
- * \param _t destination value type
44
- * \param _v destination value
45
- * \param _s source string
46
- * \param _l string length
47
- * \return 0 on success, negative on error
48
- */
49
-int db_mysql_str2val(const db_type_t _t, db_val_t* _v, const char* _s, const int _l)
50
-{
51
-	static str dummy_string = {"", 0};
52
-	
53
-	if (!_v) {
54
-		LM_ERR("invalid parameter value\n");
55
-		return -1;
56
-	}
57
-	/* A NULL string is a NULL value in mysql, otherwise its an empty value */
58
-	if (!_s) {
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
-	case DB_INT:
75
-		LM_DBG("converting INT [%s]\n", _s);
76
-		if (db_str2int(_s, &VAL_INT(_v)) < 0) {
77
-			LM_ERR("error while converting integer value from string\n");
78
-			return -2;
79
-		} else {
80
-			VAL_TYPE(_v) = DB_INT;
81
-			return 0;
82
-		}
83
-		break;
84
-
85
-	case DB_BIGINT:
86
-		LM_DBG("converting BIGINT [%s]\n", _s);
87
-		if (db_str2longlong(_s, &VAL_BIGINT(_v)) < 0) {
88
-			LM_ERR("error while converting big integer value from string\n");
89
-			return -3;
90
-		} else {
91
-			VAL_TYPE(_v) = DB_BIGINT;
92
-			return 0;
93
-		}
94
-		break;
95
-
96
-	case DB_BITMAP:
97
-		LM_DBG("converting BITMAP [%s]\n", _s);
98
-		if (db_str2int(_s, &VAL_INT(_v)) < 0) {
99
-			LM_ERR("error while converting bitmap value from string\n");
100
-			return -4;
101
-		} else {
102
-			VAL_TYPE(_v) = DB_BITMAP;
103
-			return 0;
104
-		}
105
-		break;
106
-	
107
-	case DB_DOUBLE:
108
-		LM_DBG("converting DOUBLE [%s]\n", _s);
109
-		if (db_str2double(_s, &VAL_DOUBLE(_v)) < 0) {
110
-			LM_ERR("error while converting double value from string\n");
111
-			return -5;
112
-		} else {
113
-			VAL_TYPE(_v) = DB_DOUBLE;
114
-			return 0;
115
-		}
116
-		break;
117
-
118
-	case DB_STRING:
119
-		LM_DBG("converting STRING [%s]\n", _s);
120
-		VAL_STRING(_v) = _s;
121
-		VAL_TYPE(_v) = DB_STRING;
122
-		return 0;
123
-
124
-	case DB_STR:
125
-		LM_DBG("converting STR [%.*s]\n", _l, _s);
126
-		VAL_STR(_v).s = (char*)_s;
127
-		VAL_STR(_v).len = _l;
128
-		VAL_TYPE(_v) = DB_STR;
129
-		return 0;
130
-
131
-	case DB_DATETIME:
132
-		LM_DBG("converting DATETIME [%s]\n", _s);
133
-		if (db_str2time(_s, &VAL_TIME(_v)) < 0) {
134
-			LM_ERR("error while converting datetime value from string\n");
135
-			return -6;
136
-		} else {
137
-			VAL_TYPE(_v) = DB_DATETIME;
138
-			return 0;
139
-		}
140
-		break;
141
-
142
-	case DB_BLOB:
143
-		LM_DBG("converting BLOB [%.*s]\n", _l, _s);
144
-		VAL_BLOB(_v).s = (char*)_s;
145
-		VAL_BLOB(_v).len = _l;
146
-		VAL_TYPE(_v) = DB_BLOB;
147
-		return 0;
148
-	}
149
-	return -7;
150
-}
151
-
152
-
153 39
 /*!
154 40
  * \brief Converting a value to a string
155 41
  *
Browse code

- add a comment about the NULL value behaviour of libmysql - add some doxygen documentation

git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@5197 689a6050-402a-0410-94f2-e92a70836424

Henning Westerholt authored on 13/11/2008 16:14:34
Showing 1 changed files
... ...
@@ -22,7 +22,7 @@
22 22
  */
23 23
 
24 24
 /*! \file
25
- *  \brief DB_MYSQL :: Data conversion
25
+ *  \brief DB_MYSQL :: Data conversions
26 26
  *  \ingroup db_mysql
27 27
  *  Module: \ref db_mysql
28 28
  */
... ...
@@ -36,8 +36,15 @@
36 36
 #include <stdio.h>
37 37
 
38 38
 
39
-/*! \brief
40
- * Convert str to db value, does not copy strings
39
+/*!
40
+ * \brief Convert a str to a db value, does not copy strings
41
+ *
42
+ * Convert a str to a db value, does not copy strings.
43
+ * \param _t destination value type
44
+ * \param _v destination value
45
+ * \param _s source string
46
+ * \param _l string length
47
+ * \return 0 on success, negative on error
41 48
  */
42 49
 int db_mysql_str2val(const db_type_t _t, db_val_t* _v, const char* _s, const int _l)
43 50
 {
... ...
@@ -47,7 +54,7 @@ int db_mysql_str2val(const db_type_t _t, db_val_t* _v, const char* _s, const int
47 54
 		LM_ERR("invalid parameter value\n");
48 55
 		return -1;
49 56
 	}
50
-
57
+	/* A NULL string is a NULL value in mysql, otherwise its an empty value */
51 58
 	if (!_s) {
52 59
 		memset(_v, 0, sizeof(db_val_t));
53 60
 			/* Initialize the string pointers to a dummy empty
... ...
@@ -143,8 +150,15 @@ int db_mysql_str2val(const db_type_t _t, db_val_t* _v, const char* _s, const int
143 150
 }
144 151
 
145 152
 
146
-/*! \brief
147
- * Used when converting result from a query
153
+/*!
154
+ * \brief Converting a value to a string
155
+ *
156
+ * Converting a value to a string, used when converting result from a query
157
+ * \param _c database connection
158
+ * \param _v source value
159
+ * \param _s target string
160
+ * \param _len target string length
161
+ * \return 0 on success, negative on error
148 162
  */
149 163
 int db_mysql_val2str(const db_con_t* _c, const db_val_t* _v, char* _s, int* _len)
150 164
 {
Browse code

- remove not reached return statement at the end of val2str functions

git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@4965 689a6050-402a-0410-94f2-e92a70836424

Henning Westerholt authored on 19/09/2008 11:56:49
Showing 1 changed files
... ...
@@ -262,5 +262,4 @@ int db_mysql_val2str(const db_con_t* _c, const db_val_t* _v, char* _s, int* _len
262 262
 		LM_DBG("unknown data type\n");
263 263
 		return -10;
264 264
 	}
265
-	/*return -8; --not reached*/
266 265
 }
Browse code

- initial support for BIGINT database in DB core and SQL based database modules, closes patch #2101659 - some tests for mysql were done, but more testing, especially for the postgres and unixodbc would be appreciated - Todo: fix other DB modules, at the moment some warnings are printed during compilation because of the unhandled BIGINT state

git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@4928 689a6050-402a-0410-94f2-e92a70836424

Henning Westerholt authored on 16/09/2008 16:44:10
Showing 1 changed files
... ...
@@ -75,11 +75,22 @@ int db_mysql_str2val(const db_type_t _t, db_val_t* _v, const char* _s, const int
75 75
 		}
76 76
 		break;
77 77
 
78
+	case DB_BIGINT:
79
+		LM_DBG("converting BIGINT [%s]\n", _s);
80
+		if (db_str2longlong(_s, &VAL_BIGINT(_v)) < 0) {
81
+			LM_ERR("error while converting big integer value from string\n");
82
+			return -3;
83
+		} else {
84
+			VAL_TYPE(_v) = DB_BIGINT;
85
+			return 0;
86
+		}
87
+		break;
88
+
78 89
 	case DB_BITMAP:
79 90
 		LM_DBG("converting BITMAP [%s]\n", _s);
80 91
 		if (db_str2int(_s, &VAL_INT(_v)) < 0) {
81 92
 			LM_ERR("error while converting bitmap value from string\n");
82
-			return -3;
93
+			return -4;
83 94
 		} else {
84 95
 			VAL_TYPE(_v) = DB_BITMAP;
85 96
 			return 0;
... ...
@@ -90,7 +101,7 @@ int db_mysql_str2val(const db_type_t _t, db_val_t* _v, const char* _s, const int
90 101
 		LM_DBG("converting DOUBLE [%s]\n", _s);
91 102
 		if (db_str2double(_s, &VAL_DOUBLE(_v)) < 0) {
92 103
 			LM_ERR("error while converting double value from string\n");
93
-			return -4;
104
+			return -5;
94 105
 		} else {
95 106
 			VAL_TYPE(_v) = DB_DOUBLE;
96 107
 			return 0;
... ...
@@ -114,7 +125,7 @@ int db_mysql_str2val(const db_type_t _t, db_val_t* _v, const char* _s, const int
114 125
 		LM_DBG("converting DATETIME [%s]\n", _s);
115 126
 		if (db_str2time(_s, &VAL_TIME(_v)) < 0) {
116 127
 			LM_ERR("error while converting datetime value from string\n");
117
-			return -5;
128
+			return -6;
118 129
 		} else {
119 130
 			VAL_TYPE(_v) = DB_DATETIME;
120 131
 			return 0;
... ...
@@ -128,7 +139,7 @@ int db_mysql_str2val(const db_type_t _t, db_val_t* _v, const char* _s, const int
128 139
 		VAL_TYPE(_v) = DB_BLOB;
129 140
 		return 0;
130 141
 	}
131
-	return -6;
142
+	return -7;
132 143
 }
133 144
 
134 145
 
... ...
@@ -164,10 +175,19 @@ int db_mysql_val2str(const db_con_t* _c, const db_val_t* _v, char* _s, int* _len
164 175
 		}
165 176
 		break;
166 177
 
178
+	case DB_BIGINT:
179
+		if (db_longlong2str(VAL_BIGINT(_v), _s, _len) < 0) {
180
+			LM_ERR("error while converting string to big int\n");
181
+			return -3;
182
+		} else {
183
+			return 0;
184
+		}
185
+		break;
186
+
167 187
 	case DB_BITMAP:
168 188
 		if (db_int2str(VAL_BITMAP(_v), _s, _len) < 0) {
169 189
 			LM_ERR("error while converting string to int\n");
170
-			return -3;
190
+			return -4;
171 191
 		} else {
172 192
 			return 0;
173 193
 		}
... ...
@@ -176,7 +196,7 @@ int db_mysql_val2str(const db_con_t* _c, const db_val_t* _v, char* _s, int* _len
176 196
 	case DB_DOUBLE:
177 197
 		if (db_double2str(VAL_DOUBLE(_v), _s, _len) < 0) {
178 198
 			LM_ERR("error while converting string to double\n");
179
-			return -4;
199
+			return -5;
180 200
 		} else {
181 201
 			return 0;
182 202
 		}
... ...
@@ -186,7 +206,7 @@ int db_mysql_val2str(const db_con_t* _c, const db_val_t* _v, char* _s, int* _len
186 206
 		l = strlen(VAL_STRING(_v));
187 207
 		if (*_len < (l * 2 + 3)) {
188 208
 			LM_ERR("destination buffer too short\n");
189
-			return -5;
209
+			return -6;
190 210
 		} else {
191 211
 			old_s = _s;
192 212
 			*_s++ = '\'';
... ...
@@ -201,7 +221,7 @@ int db_mysql_val2str(const db_con_t* _c, const db_val_t* _v, char* _s, int* _len
201 221
 	case DB_STR:
202 222
 		if (*_len < (VAL_STR(_v).len * 2 + 3)) {
203 223
 			LM_ERR("destination buffer too short\n");
204
-			return -6;
224
+			return -7;
205 225
 		} else {
206 226
 			old_s = _s;
207 227
 			*_s++ = '\'';
... ...
@@ -216,7 +236,7 @@ int db_mysql_val2str(const db_con_t* _c, const db_val_t* _v, char* _s, int* _len
216 236
 	case DB_DATETIME:
217 237
 		if (db_time2str(VAL_TIME(_v), _s, _len) < 0) {
218 238
 			LM_ERR("error while converting string to time_t\n");
219
-			return -7;
239
+			return -8;
220 240
 		} else {
221 241
 			return 0;
222 242
 		}
... ...
@@ -226,7 +246,7 @@ int db_mysql_val2str(const db_con_t* _c, const db_val_t* _v, char* _s, int* _len
226 246
 		l = VAL_BLOB(_v).len;
227 247
 		if (*_len < (l * 2 + 3)) {
228 248
 			LM_ERR("destination buffer too short\n");
229
-			return -8;
249
+			return -9;
230 250
 		} else {
231 251
 			old_s = _s;
232 252
 			*_s++ = '\'';
... ...
@@ -240,7 +260,7 @@ int db_mysql_val2str(const db_con_t* _c, const db_val_t* _v, char* _s, int* _len
240 260
 
241 261
 	default:
242 262
 		LM_DBG("unknown data type\n");
243
-		return -9;
263
+		return -10;
244 264
 	}
245 265
 	/*return -8; --not reached*/
246 266
 }
Browse code

- change name in copyright headers

git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@4518 689a6050-402a-0410-94f2-e92a70836424

Henning Westerholt authored on 28/07/2008 15:39:28
Showing 1 changed files
... ...
@@ -4,14 +4,14 @@
4 4
  * Copyright (C) 2001-2003 FhG Fokus
5 5
  * Copyright (C) 2008 1&1 Internet AG
6 6
  *
7
- * This file is part of openser, a free SIP server.
7
+ * This file is part of Kamailio, a free SIP server.
8 8
  *
9
- * openser is free software; you can redistribute it and/or modify
9
+ * Kamailio is free software; you can redistribute it and/or modify
10 10
  * it under the terms of the GNU General Public License as published by
11 11
  * the Free Software Foundation; either version 2 of the License, or
12 12
  * (at your option) any later version
13 13
  *
14
- * openser is distributed in the hope that it will be useful,
14
+ * Kamailio is distributed in the hope that it will be useful,
15 15
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 16
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 17
  * GNU General Public License for more details.
Browse code

- small doxygen updates (group, syntax), small docs update - patch provided from Olle E. Johansson, closes #2025079

git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@4505 689a6050-402a-0410-94f2-e92a70836424

Henning Westerholt authored on 24/07/2008 15:20:11
Showing 1 changed files
... ...
@@ -21,6 +21,11 @@
21 21
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22 22
  */
23 23
 
24
+/*! \file
25
+ *  \brief DB_MYSQL :: Data conversion
26
+ *  \ingroup db_mysql
27
+ *  Module: \ref db_mysql
28
+ */
24 29
 
25 30
 #include "../../dprint.h"
26 31
 #include "../../db/db_ut.h"
... ...
@@ -31,7 +36,7 @@
31 36
 #include <stdio.h>
32 37
 
33 38
 
34
-/*
39
+/*! \brief
35 40
  * Convert str to db value, does not copy strings
36 41
  */
37 42
 int db_mysql_str2val(const db_type_t _t, db_val_t* _v, const char* _s, const int _l)
... ...
@@ -127,7 +132,7 @@ int db_mysql_str2val(const db_type_t _t, db_val_t* _v, const char* _s, const int
127 132
 }
128 133
 
129 134
 
130
-/*
135
+/*! \brief
131 136
  * Used when converting result from a query
132 137
  */
133 138
 int db_mysql_val2str(const db_con_t* _c, const db_val_t* _v, char* _s, int* _len)
Browse code

- small optimization in db_mysql

git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@3761 689a6050-402a-0410-94f2-e92a70836424

Henning Westerholt authored on 26/02/2008 14:41:46
Showing 1 changed files
... ...
@@ -194,14 +194,13 @@ int db_mysql_val2str(const db_con_t* _c, const db_val_t* _v, char* _s, int* _len
194 194
 		break;
195 195
 
196 196
 	case DB_STR:
197
-		l = VAL_STR(_v).len;
198
-		if (*_len < (l * 2 + 3)) {
197
+		if (*_len < (VAL_STR(_v).len * 2 + 3)) {
199 198
 			LM_ERR("destination buffer too short\n");
200 199
 			return -6;
201 200
 		} else {
202 201
 			old_s = _s;
203 202
 			*_s++ = '\'';
204
-			_s += mysql_real_escape_string(CON_CONNECTION(_c), _s, VAL_STR(_v).s, l);
203
+			_s += mysql_real_escape_string(CON_CONNECTION(_c), _s, VAL_STR(_v).s, VAL_STR(_v).len);
205 204
 			*_s++ = '\'';
206 205
 			*_s = '\0';
207 206
 			*_len = _s - old_s;
Browse code

- rename database modules to use the 'db_' prefix

git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@3638 689a6050-402a-0410-94f2-e92a70836424

Henning Westerholt authored on 06/02/2008 13:10:03
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,242 @@
1
+/* 
2
+ * $Id$ 
3
+ *
4
+ * Copyright (C) 2001-2003 FhG Fokus
5
+ * Copyright (C) 2008 1&1 Internet AG
6
+ *
7
+ * This file is part of openser, a free SIP server.
8
+ *
9
+ * openser is free software; you can redistribute it and/or modify
10
+ * it under the terms of the GNU General Public License as published by
11
+ * the Free Software Foundation; either version 2 of the License, or
12
+ * (at your option) any later version
13
+ *
14
+ * openser is distributed in the hope that it will be useful,
15
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
+ * GNU General Public License for more details.
18
+ *
19
+ * You should have received a copy of the GNU General Public License 
20
+ * along with this program; if not, write to the Free Software 
21
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22
+ */
23
+
24
+
25
+#include "../../dprint.h"
26
+#include "../../db/db_ut.h"
27
+#include "val.h"
28
+#include "my_con.h"
29
+
30
+#include <string.h>
31
+#include <stdio.h>
32
+
33
+
34
+/*
35
+ * Convert str to db value, does not copy strings
36
+ */
37
+int db_mysql_str2val(const db_type_t _t, db_val_t* _v, const char* _s, const int _l)
38
+{
39
+	static str dummy_string = {"", 0};
40
+	
41
+	if (!_v) {
42
+		LM_ERR("invalid parameter value\n");
43
+		return -1;
44
+	}
45
+
46
+	if (!_s) {
47
+		memset(_v, 0, sizeof(db_val_t));
48
+			/* Initialize the string pointers to a dummy empty
49
+			 * string so that we do not crash when the NULL flag
50
+			 * is set but the module does not check it properly
51
+			 */
52
+		VAL_STRING(_v) = dummy_string.s;
53
+		VAL_STR(_v) = dummy_string;
54
+		VAL_BLOB(_v) = dummy_string;
55
+		VAL_TYPE(_v) = _t;
56
+		VAL_NULL(_v) = 1;
57
+		return 0;
58
+	}
59
+	VAL_NULL(_v) = 0;
60
+
61
+	switch(_t) {
62
+	case DB_INT:
63
+		LM_DBG("converting INT [%s]\n", _s);
64
+		if (db_str2int(_s, &VAL_INT(_v)) < 0) {
65
+			LM_ERR("error while converting integer value from string\n");
66
+			return -2;
67
+		} else {
68
+			VAL_TYPE(_v) = DB_INT;
69
+			return 0;
70
+		}
71
+		break;
72
+
73
+	case DB_BITMAP:
74
+		LM_DBG("converting BITMAP [%s]\n", _s);
75
+		if (db_str2int(_s, &VAL_INT(_v)) < 0) {
76
+			LM_ERR("error while converting bitmap value from string\n");
77
+			return -3;
78
+		} else {
79
+			VAL_TYPE(_v) = DB_BITMAP;
80
+			return 0;
81
+		}
82
+		break;
83
+	
84
+	case DB_DOUBLE:
85
+		LM_DBG("converting DOUBLE [%s]\n", _s);
86
+		if (db_str2double(_s, &VAL_DOUBLE(_v)) < 0) {
87
+			LM_ERR("error while converting double value from string\n");
88
+			return -4;
89
+		} else {
90
+			VAL_TYPE(_v) = DB_DOUBLE;
91
+			return 0;
92
+		}
93
+		break;
94
+
95
+	case DB_STRING:
96
+		LM_DBG("converting STRING [%s]\n", _s);
97
+		VAL_STRING(_v) = _s;
98
+		VAL_TYPE(_v) = DB_STRING;
99
+		return 0;
100
+
101
+	case DB_STR:
102
+		LM_DBG("converting STR [%.*s]\n", _l, _s);
103
+		VAL_STR(_v).s = (char*)_s;
104
+		VAL_STR(_v).len = _l;
105
+		VAL_TYPE(_v) = DB_STR;
106
+		return 0;
107
+
108
+	case DB_DATETIME:
109
+		LM_DBG("converting DATETIME [%s]\n", _s);
110
+		if (db_str2time(_s, &VAL_TIME(_v)) < 0) {
111
+			LM_ERR("error while converting datetime value from string\n");
112
+			return -5;
113
+		} else {
114
+			VAL_TYPE(_v) = DB_DATETIME;
115
+			return 0;
116
+		}
117
+		break;
118
+
119
+	case DB_BLOB:
120
+		LM_DBG("converting BLOB [%.*s]\n", _l, _s);
121
+		VAL_BLOB(_v).s = (char*)_s;
122
+		VAL_BLOB(_v).len = _l;
123
+		VAL_TYPE(_v) = DB_BLOB;
124
+		return 0;
125
+	}
126
+	return -6;
127
+}
128
+
129
+
130
+/*
131
+ * Used when converting result from a query
132
+ */
133
+int db_mysql_val2str(const db_con_t* _c, const db_val_t* _v, char* _s, int* _len)
134
+{
135
+	int l;
136
+	char* old_s;
137
+
138
+	if (!_c || !_v || !_s || !_len || !*_len) {
139
+		LM_ERR("invalid parameter value\n");
140
+		return -1;
141
+	}
142
+
143
+	if (VAL_NULL(_v)) {
144
+		if (*_len < sizeof("NULL")) {
145
+			LM_ERR("buffer too small\n");
146
+			return -1;
147
+		}
148
+		*_len = snprintf(_s, *_len, "NULL");
149
+		return 0;
150
+	}
151
+	
152
+	switch(VAL_TYPE(_v)) {
153
+	case DB_INT:
154
+		if (db_int2str(VAL_INT(_v), _s, _len) < 0) {
155
+			LM_ERR("error while converting string to int\n");
156
+			return -2;
157
+		} else {
158
+			return 0;
159
+		}
160
+		break;
161
+
162
+	case DB_BITMAP:
163
+		if (db_int2str(VAL_BITMAP(_v), _s, _len) < 0) {
164
+			LM_ERR("error while converting string to int\n");
165
+			return -3;
166
+		} else {
167
+			return 0;
168
+		}
169
+		break;
170
+
171
+	case DB_DOUBLE:
172
+		if (db_double2str(VAL_DOUBLE(_v), _s, _len) < 0) {
173
+			LM_ERR("error while converting string to double\n");
174
+			return -4;
175
+		} else {
176
+			return 0;
177
+		}
178
+		break;
179
+
180
+	case DB_STRING:
181
+		l = strlen(VAL_STRING(_v));
182
+		if (*_len < (l * 2 + 3)) {
183
+			LM_ERR("destination buffer too short\n");
184
+			return -5;
185
+		} else {
186
+			old_s = _s;
187
+			*_s++ = '\'';
188
+			_s += mysql_real_escape_string(CON_CONNECTION(_c), _s, VAL_STRING(_v), l);
189
+			*_s++ = '\'';
190
+			*_s = '\0'; /* FIXME */
191
+			*_len = _s - old_s;
192
+			return 0;
193
+		}
194
+		break;
195
+
196
+	case DB_STR:
197
+		l = VAL_STR(_v).len;
198
+		if (*_len < (l * 2 + 3)) {
199
+			LM_ERR("destination buffer too short\n");
200
+			return -6;
201
+		} else {
202
+			old_s = _s;
203
+			*_s++ = '\'';
204
+			_s += mysql_real_escape_string(CON_CONNECTION(_c), _s, VAL_STR(_v).s, l);
205
+			*_s++ = '\'';
206
+			*_s = '\0';
207
+			*_len = _s - old_s;
208
+			return 0;
209
+		}
210
+		break;
211
+
212
+	case DB_DATETIME:
213
+		if (db_time2str(VAL_TIME(_v), _s, _len) < 0) {
214
+			LM_ERR("error while converting string to time_t\n");
215
+			return -7;
216
+		} else {
217
+			return 0;
218
+		}
219
+		break;
220
+
221
+	case DB_BLOB:
222
+		l = VAL_BLOB(_v).len;
223
+		if (*_len < (l * 2 + 3)) {
224
+			LM_ERR("destination buffer too short\n");
225
+			return -8;
226
+		} else {
227
+			old_s = _s;
228
+			*_s++ = '\'';
229
+			_s += mysql_real_escape_string(CON_CONNECTION(_c), _s, VAL_STR(_v).s, l);
230
+			*_s++ = '\'';
231
+			*_s = '\0';
232
+			*_len = _s - old_s;
233
+			return 0;
234
+		}			
235
+		break;
236
+
237
+	default:
238
+		LM_DBG("unknown data type\n");
239
+		return -9;
240
+	}
241
+	/*return -8; --not reached*/
242
+}