... | ... |
@@ -35,7 +35,9 @@ |
35 | 35 |
|
36 | 36 |
#include "../../sr_module.h" |
37 | 37 |
#include "dbase.h" |
38 |
+#include "db_mod.h" |
|
38 | 39 |
|
40 |
+int ping_interval = 5 * 60; /* Default is 5 minutes */ |
|
39 | 41 |
|
40 | 42 |
MODULE_VERSION |
41 | 43 |
|
... | ... |
@@ -57,13 +59,22 @@ static cmd_export_t cmds[] = { |
57 | 59 |
}; |
58 | 60 |
|
59 | 61 |
|
62 |
+/* |
|
63 |
+ * Exported parameters |
|
64 |
+ */ |
|
65 |
+static param_export_t params[] = { |
|
66 |
+ {"ping_interval", INT_PARAM }, |
|
67 |
+ {0, 0, 0} |
|
68 |
+}; |
|
69 |
+ |
|
70 |
+ |
|
60 | 71 |
struct module_exports exports = { |
61 | 72 |
"mysql", |
62 | 73 |
cmds, |
63 |
- 0, /* module paramers */ |
|
64 |
- 0, /* module initialization function */ |
|
65 |
- 0, /* response function*/ |
|
66 |
- 0, /* destroy function */ |
|
67 |
- 0, /* oncancel function */ |
|
68 |
- 0 /* per-child init function */ |
|
74 |
+ params, /* module paramers */ |
|
75 |
+ 0, /* module initialization function */ |
|
76 |
+ 0, /* response function*/ |
|
77 |
+ 0, /* destroy function */ |
|
78 |
+ 0, /* oncancel function */ |
|
79 |
+ 0 /* per-child init function */ |
|
69 | 80 |
}; |
70 | 81 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,41 @@ |
1 |
+/* |
|
2 |
+ * $Id$ |
|
3 |
+ * |
|
4 |
+ * MySQL module interface |
|
5 |
+ * |
|
6 |
+ * Copyright (C) 2001-2003 Fhg Fokus |
|
7 |
+ * |
|
8 |
+ * This file is part of ser, a free SIP server. |
|
9 |
+ * |
|
10 |
+ * ser is free software; you can redistribute it and/or modify |
|
11 |
+ * it under the terms of the GNU General Public License as published by |
|
12 |
+ * the Free Software Foundation; either version 2 of the License, or |
|
13 |
+ * (at your option) any later version |
|
14 |
+ * |
|
15 |
+ * For a license to use the ser software under conditions |
|
16 |
+ * other than those described here, or to purchase support for this |
|
17 |
+ * software, please contact iptel.org by e-mail at the following addresses: |
|
18 |
+ * info@iptel.org |
|
19 |
+ * |
|
20 |
+ * ser is distributed in the hope that it will be useful, |
|
21 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
22 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
23 |
+ * GNU General Public License for more details. |
|
24 |
+ * |
|
25 |
+ * You should have received a copy of the GNU General Public License |
|
26 |
+ * along with this program; if not, write to the Free Software |
|
27 |
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
28 |
+ */ |
|
29 |
+/* |
|
30 |
+ * History: |
|
31 |
+ * -------- |
|
32 |
+ * 2003-03-11 updated to the new module exports interface (andrei) |
|
33 |
+ * 2003-03-16 flags export parameter added (janakj) |
|
34 |
+ */ |
|
35 |
+ |
|
36 |
+#ifndef DB_MOD_H |
|
37 |
+#define DB_MOD_H |
|
38 |
+ |
|
39 |
+extern int ping_interval; |
|
40 |
+ |
|
41 |
+#endif /* DB_MOD_H */ |
... | ... |
@@ -30,6 +30,7 @@ |
30 | 30 |
#include <stdio.h> |
31 | 31 |
#include <string.h> |
32 | 32 |
#include <stdlib.h> |
33 |
+#include <time.h> |
|
33 | 34 |
#include <mysql/mysql.h> |
34 | 35 |
#include "../../mem/mem.h" |
35 | 36 |
#include "../../dprint.h" |
... | ... |
@@ -38,6 +39,7 @@ |
38 | 39 |
#include "my_con.h" |
39 | 40 |
#include "my_pool.h" |
40 | 41 |
#include "res.h" |
42 |
+#include "db_mod.h" |
|
41 | 43 |
#include "dbase.h" |
42 | 44 |
|
43 | 45 |
|
... | ... |
@@ -51,11 +53,22 @@ static char sql_buf[SQL_BUF_LEN]; |
51 | 53 |
*/ |
52 | 54 |
static int submit_query(db_con_t* _h, const char* _s) |
53 | 55 |
{ |
56 |
+ time_t t; |
|
57 |
+ |
|
54 | 58 |
if ((!_h) || (!_s)) { |
55 | 59 |
LOG(L_ERR, "submit_query(): Invalid parameter value\n"); |
56 | 60 |
return -1; |
57 | 61 |
} |
58 | 62 |
|
63 |
+ t = time(0); |
|
64 |
+ if ((t - CON_TIMESTAMP(_h)) > ping_interval) { |
|
65 |
+ if (mysql_ping(CON_CONNECTION(_h))) { |
|
66 |
+ LOG(L_ERR, "submit_query(): mysql_ping failed\n"); |
|
67 |
+ } else { |
|
68 |
+ CON_TIMESTAMP(_h) = t; |
|
69 |
+ } |
|
70 |
+ } |
|
71 |
+ |
|
59 | 72 |
/* screws up the terminal when the query contains a BLOB :-( (by bogdan) |
60 | 73 |
* DBG("submit_query(): %s\n", _s); |
61 | 74 |
*/ |
... | ... |
@@ -27,6 +27,7 @@ |
27 | 27 |
*/ |
28 | 28 |
|
29 | 29 |
#include <string.h> |
30 |
+#include <time.h> |
|
30 | 31 |
#include "my_con.h" |
31 | 32 |
#include "../../mem/mem.h" |
32 | 33 |
#include "../../dprint.h" |
... | ... |
@@ -69,6 +70,8 @@ struct my_con* new_connection(struct my_id* id) |
69 | 70 |
goto err; |
70 | 71 |
} |
71 | 72 |
|
73 |
+ ptr->timestamp = time(0); |
|
74 |
+ |
|
72 | 75 |
ptr->id = id; |
73 | 76 |
return ptr; |
74 | 77 |
|
... | ... |
@@ -29,15 +29,17 @@ |
29 | 29 |
#ifndef MY_CON_H |
30 | 30 |
#define MY_CON_H |
31 | 31 |
|
32 |
+#include <time.h> |
|
32 | 33 |
#include <mysql/mysql.h> |
33 | 34 |
#include "my_id.h" |
34 | 35 |
|
35 | 36 |
struct my_con { |
36 |
- struct my_id* id; /* Connection identifier */ |
|
37 |
+ struct my_id* id; /* Connection identifier */ |
|
37 | 38 |
int ref; /* Reference count */ |
38 | 39 |
MYSQL_RES* res; /* Actual result */ |
39 | 40 |
MYSQL* con; /* Connection representation */ |
40 | 41 |
MYSQL_ROW row; /* Actual row in the result */ |
42 |
+ time_t timestamp; /* Timestamp of last query */ |
|
41 | 43 |
struct my_con* next; /* Next connection in the pool */ |
42 | 44 |
}; |
43 | 45 |
|
... | ... |
@@ -48,6 +50,7 @@ struct my_con { |
48 | 50 |
#define CON_RESULT(db_con) (((struct my_con*)((db_con)->tail))->res) |
49 | 51 |
#define CON_CONNECTION(db_con) (((struct my_con*)((db_con)->tail))->con) |
50 | 52 |
#define CON_ROW(db_con) (((struct my_con*)((db_con)->tail))->row) |
53 |
+#define CON_TIMESTAMP(db_con) (((struct my_con*)((db_con)->tail))->timestamp) |
|
51 | 54 |
|
52 | 55 |
|
53 | 56 |
/* |