Browse code

db_mysql: data converting log improvement - errors should be logged as such

Henning Westerholt authored on 06/03/2018 07:41:01
Showing 1 changed files
... ...
@@ -123,7 +123,7 @@ int db_mysql_val2str(const db1_con_t* _c, const db_val_t* _v, char* _s, int* _le
123 123
 		break;
124 124
 
125 125
 	default:
126
-		LM_DBG("unknown data type\n");
126
+		LM_ERR("unknown data type\n");
127 127
 		return -10;
128 128
 	}
129 129
 }
Browse code

db_mysql: coherent indentation and whitespacing

Daniel-Constantin Mierla authored on 09/11/2017 06:03:02
Showing 1 changed files
... ...
@@ -1,4 +1,4 @@
1
-/* 
1
+/*
2 2
  * Copyright (C) 2001-2003 FhG Fokus
3 3
  * Copyright (C) 2008 1&1 Internet AG
4 4
  *
... ...
@@ -14,8 +14,8 @@
14 14
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 15
  * GNU General Public License for more details.
16 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 
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 19
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
20 20
  */
21 21
 
... ...
@@ -81,7 +81,8 @@ int db_mysql_val2str(const db1_con_t* _c, const db_val_t* _v, char* _s, int* _le
81 81
 		} else {
82 82
 			old_s = _s;
83 83
 			*_s++ = '\'';
84
-			_s += mysql_real_escape_string(CON_CONNECTION(_c), _s, VAL_STRING(_v), l);
84
+			_s += mysql_real_escape_string(CON_CONNECTION(_c), _s,
85
+					VAL_STRING(_v), l);
85 86
 			*_s++ = '\'';
86 87
 			*_s = '\0'; /* FIXME */
87 88
 			*_len = _s - old_s;
... ...
@@ -96,7 +97,8 @@ int db_mysql_val2str(const db1_con_t* _c, const db_val_t* _v, char* _s, int* _le
96 97
 		} else {
97 98
 			old_s = _s;
98 99
 			*_s++ = '\'';
99
-			_s += mysql_real_escape_string(CON_CONNECTION(_c), _s, VAL_STR(_v).s, VAL_STR(_v).len);
100
+			_s += mysql_real_escape_string(CON_CONNECTION(_c), _s,
101
+					VAL_STR(_v).s, VAL_STR(_v).len);
100 102
 			*_s++ = '\'';
101 103
 			*_s = '\0';
102 104
 			*_len = _s - old_s;
... ...
@@ -117,7 +119,7 @@ int db_mysql_val2str(const db1_con_t* _c, const db_val_t* _v, char* _s, int* _le
117 119
 			*_s = '\0';
118 120
 			*_len = _s - old_s;
119 121
 			return 0;
120
-		}			
122
+		}
121 123
 		break;
122 124
 
123 125
 	default:
Browse code

db_mysql: Let the database convert the timestamp

Add option to use FROM_UNUXTIME(time_t) instead of using the
time2str routines. This makes MySQL apply the database timezone
instead of using the localtime of the system inserting the data.

This is useful for the sipcapture module where the system time
might be in CET but the database is using UTC. In these cases
the micro_ts and the date columns were offseted by the timezone
difference.

Holger Hans Peter Freyther authored on 29/01/2017 09:51:06
Showing 1 changed files
... ...
@@ -29,6 +29,7 @@
29 29
 #include "../../lib/srdb1/db_ut.h"
30 30
 #include "km_val.h"
31 31
 #include "km_my_con.h"
32
+#include "db_mysql.h"
32 33
 
33 34
 
34 35
 /*!
... ...
@@ -46,6 +47,27 @@ int db_mysql_val2str(const db1_con_t* _c, const db_val_t* _v, char* _s, int* _le
46 47
 	int l, tmp;
47 48
 	char* old_s;
48 49
 
50
+	switch(VAL_TYPE(_v)) {
51
+	case DB1_DATETIME:
52
+		if (my_server_timezone) {
53
+			/* Let MySQL handle timestamp to internal time representation */
54
+			if (!_s || !_len || !*_len) {
55
+				LM_ERR("Invalid parameter value\n");
56
+				return -1;
57
+			}
58
+			l = snprintf(_s, *_len, "FROM_UNIXTIME(%d)", VAL_INT(_v));
59
+			if (l < 0 || l >= *_len) {
60
+				LM_ERR("Error in snprintf\n");
61
+				return -1;
62
+			}
63
+			*_len  = l;
64
+			return 0;
65
+		}
66
+		break;
67
+	default:
68
+		break;
69
+	};
70
+
49 71
 	tmp = db_val2str(_c, _v, _s, _len);
50 72
 	if (tmp < 1)
51 73
 		return tmp;
Browse code

core, lib, modules: updated include paths for header files

Daniel-Constantin Mierla authored on 07/12/2016 11:07:22
Showing 1 changed files
... ...
@@ -25,7 +25,7 @@
25 25
  *  Module: \ref db_mysql
26 26
  */
27 27
 
28
-#include "../../dprint.h"
28
+#include "../../core/dprint.h"
29 29
 #include "../../lib/srdb1/db_ut.h"
30 30
 #include "km_val.h"
31 31
 #include "km_my_con.h"
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
new file mode 100644
... ...
@@ -0,0 +1,105 @@
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
+}