Browse code

modules_k/*: moved k modules in directory modules/

Daniel-Constantin Mierla authored on 20/01/2013 11:57:52
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,225 +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
- *  2006-01-10  UID (username) and PWD (password) attributes added to 
30
- *              connection string (bogdan)
31
- *  2006-05-05  extract_error passes back last error state on return (sgupta)
32
- */
33
-
34
-#include "con.h"
35
-#include "../../mem/mem.h"
36
-#include "../../dprint.h"
37
-#include "../../ut.h"
38
-#include <time.h>
39
-
40
-#define DSN_ATTR  "DSN="
41
-#define DSN_ATTR_LEN  (sizeof(DSN_ATTR)-1)
42
-#define UID_ATTR  "UID="
43
-#define UID_ATTR_LEN  (sizeof(UID_ATTR)-1)
44
-#define PWD_ATTR  "PWD="
45
-#define PWD_ATTR_LEN  (sizeof(PWD_ATTR)-1)
46
-
47
-
48
-char *db_unixodbc_build_conn_str(const struct db_id* id, char *buf)
49
-{
50
-	int len, ld, lu, lp;
51
-	char *p;
52
-
53
-	if (!buf) return 0;
54
-
55
-	ld = id->database?strlen(id->database):0;
56
-	lu = id->username?strlen(id->username):0;
57
-	lp = id->password?strlen(id->password):0;
58
-
59
-	len = (ld?(DSN_ATTR_LEN + ld + 1):0)
60
-		+ (lu?(UID_ATTR_LEN + lu + 1):0)
61
-		+ PWD_ATTR_LEN + lp + 1;
62
-
63
-	if ( len>=MAX_CONN_STR_LEN ){
64
-		LM_ERR("connection string too long! Increase MAX_CONN_STR_LEN"
65
-				" and recompile\n");
66
-		return 0;
67
-	}
68
-
69
-	p = buf;
70
-	if (ld) {
71
-		memcpy( p , DSN_ATTR, DSN_ATTR_LEN);
72
-		p += DSN_ATTR_LEN;
73
-		memcpy( p, id->database, ld);
74
-		p += ld;
75
-	}
76
-	if (lu) {
77
-		*(p++) = ';';
78
-		memcpy( p , UID_ATTR, UID_ATTR_LEN);
79
-		p += UID_ATTR_LEN;
80
-		memcpy( p, id->username, lu);
81
-		p += lu;
82
-	}
83
-	if (lp) {
84
-		*(p++) = ';';
85
-		memcpy( p , PWD_ATTR, PWD_ATTR_LEN);
86
-		p += PWD_ATTR_LEN;
87
-		memcpy( p, id->password, lp);
88
-		p += lp;
89
-	}
90
-	*(p++) = ';';
91
-	*p = 0 ; /* make it null terminated */
92
-
93
-	return buf;
94
-}
95
-
96
-
97
-/*
98
- * Create a new connection structure,
99
- * open the UNIXODBC connection and set reference count to 1
100
- */
101
-struct my_con* db_unixodbc_new_connection(struct db_id* id)
102
-{
103
-	SQLCHAR outstr[1024];
104
-	SQLSMALLINT outstrlen;
105
-	int ret;
106
-	struct my_con* ptr;
107
-	char conn_str[MAX_CONN_STR_LEN];
108
-
109
-	if (!id)
110
-	{
111
-		LM_ERR("invalid parameter value\n");
112
-		return 0;
113
-	}
114
-
115
-	ptr = (struct my_con*)pkg_malloc(sizeof(struct my_con));
116
-	if (!ptr)
117
-	{
118
-		LM_ERR("no more memory left\n");
119
-		return 0;
120
-	}
121
-
122
-	memset(ptr, 0, sizeof(struct my_con));
123
-	ptr->ref = 1;
124
-	// allocate environment handle
125
-	ret = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &(ptr->env));
126
-	if ((ret != SQL_SUCCESS) && (ret != SQL_SUCCESS_WITH_INFO))
127
-	{
128
-		LM_ERR("could not alloc a SQL handle\n");
129
-		if (ptr) pkg_free(ptr);
130
-		return 0;
131
-	}
132
-	// set the environment
133
-	ret = SQLSetEnvAttr(ptr->env, SQL_ATTR_ODBC_VERSION, (void *) SQL_OV_ODBC3, 0);
134
-	if ((ret != SQL_SUCCESS) && (ret != SQL_SUCCESS_WITH_INFO))
135
-	{
136
-		LM_ERR("could not set the environment\n");
137
-		goto err1;
138
-	}
139
-	// allocate connection handle
140
-	ret = SQLAllocHandle(SQL_HANDLE_DBC, ptr->env, &(ptr->dbc));
141
-	if ((ret != SQL_SUCCESS) && (ret != SQL_SUCCESS_WITH_INFO))
142
-	{
143
-		LM_ERR("could not alloc a connection handle %d\n", ret);
144
-		goto err1;
145
-	}
146
-
147
-	if (!db_unixodbc_build_conn_str(id, conn_str)) {
148
-		LM_ERR("failed to build connection string\n");
149
-		goto err2;
150
-	}
151
-
152
-	LM_DBG("opening connection: unixodbc://xxxx:xxxx@%s/%s\n", ZSW(id->host),
153
-		ZSW(id->database));
154
-
155
-	ret = SQLDriverConnect(ptr->dbc, NULL, (SQLCHAR*)conn_str, SQL_NTS,
156
-		outstr, sizeof(outstr), &outstrlen,
157
-		SQL_DRIVER_COMPLETE);
158
-	if (SQL_SUCCEEDED(ret))
159
-	{
160
-		LM_DBG("connection succeeded with reply <%s>\n", outstr);
161
-		if (ret == SQL_SUCCESS_WITH_INFO)
162
-		{
163
-			LM_DBG("driver reported the following diagnostics\n");
164
-			db_unixodbc_extract_error("SQLDriverConnect", ptr->dbc, SQL_HANDLE_DBC, NULL);
165
-		}
166
-	}
167
-	else
168
-	{
169
-		LM_ERR("failed to connect\n");
170
-		db_unixodbc_extract_error("SQLDriverConnect", ptr->dbc, SQL_HANDLE_DBC, NULL);
171
-		goto err2;
172
-	}
173
-
174
-	ptr->stmt_handle = NULL;
175
-
176
-	ptr->timestamp = time(0);
177
-	ptr->id = id;
178
-	return ptr;
179
-
180
-err1:
181
-	SQLFreeHandle(SQL_HANDLE_ENV, &(ptr->env));
182
-	if (ptr) pkg_free(ptr);
183
-	return 0;
184
-
185
-err2:
186
-	SQLFreeHandle(SQL_HANDLE_ENV, &(ptr->env));
187
-	SQLFreeHandle(SQL_HANDLE_DBC, &(ptr->dbc));
188
-	if (ptr) pkg_free(ptr);
189
-	return 0;
190
-}
191
-
192
-/*
193
- * Close the connection and release memory
194
- */
195
-void db_unixodbc_free_connection(struct my_con* con)
196
-{
197
-	if (!con) return;
198
-	SQLFreeHandle(SQL_HANDLE_ENV, con->env);
199
-	SQLDisconnect(con->dbc);
200
-	SQLFreeHandle(SQL_HANDLE_DBC, con->dbc);
201
-	pkg_free(con);
202
-}
203
-
204
-
205
-void db_unixodbc_extract_error(const char *fn, const SQLHANDLE handle, const SQLSMALLINT type, char* stret)
206
-{
207
-	SQLINTEGER   i = 0;
208
-	SQLINTEGER   native;
209
-	SQLCHAR  state[ 7 ];
210
-	SQLCHAR  text[256];
211
-	SQLSMALLINT  len;
212
-	SQLRETURN	ret;
213
-
214
-	do
215
-	{
216
-		ret = SQLGetDiagRec(type, handle, ++i, state, &native, text,
217
-			sizeof(text), &len );
218
-		if (SQL_SUCCEEDED(ret)) {
219
-			LM_ERR("unixodbc:%s=%s:%ld:%ld:%s\n", fn, state, (long)i, 
220
-					(long)native, text);
221
-			if(stret) strcpy( stret, (char*)state );
222
-		}
223
-	}
224
-	while( ret == SQL_SUCCESS );
225
-}
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
... ...
@@ -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.
Browse code

- rename db_mod.* files - rename my_con.* files in db_unixodbc - fix includes in modules

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

Henning Westerholt authored on 08/02/2008 11:39:46
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,225 @@
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
+ *  2006-01-10  UID (username) and PWD (password) attributes added to 
30
+ *              connection string (bogdan)
31
+ *  2006-05-05  extract_error passes back last error state on return (sgupta)
32
+ */
33
+
34
+#include "con.h"
35
+#include "../../mem/mem.h"
36
+#include "../../dprint.h"
37
+#include "../../ut.h"
38
+#include <time.h>
39
+
40
+#define DSN_ATTR  "DSN="
41
+#define DSN_ATTR_LEN  (sizeof(DSN_ATTR)-1)
42
+#define UID_ATTR  "UID="
43
+#define UID_ATTR_LEN  (sizeof(UID_ATTR)-1)
44
+#define PWD_ATTR  "PWD="
45
+#define PWD_ATTR_LEN  (sizeof(PWD_ATTR)-1)
46
+
47
+
48
+char *db_unixodbc_build_conn_str(const struct db_id* id, char *buf)
49
+{
50
+	int len, ld, lu, lp;
51
+	char *p;
52
+
53
+	if (!buf) return 0;
54
+
55
+	ld = id->database?strlen(id->database):0;
56
+	lu = id->username?strlen(id->username):0;
57
+	lp = id->password?strlen(id->password):0;
58
+
59
+	len = (ld?(DSN_ATTR_LEN + ld + 1):0)
60
+		+ (lu?(UID_ATTR_LEN + lu + 1):0)
61
+		+ PWD_ATTR_LEN + lp + 1;
62
+
63
+	if ( len>=MAX_CONN_STR_LEN ){
64
+		LM_ERR("connection string too long! Increase MAX_CONN_STR_LEN"
65
+				" and recompile\n");
66
+		return 0;
67
+	}
68
+
69
+	p = buf;
70
+	if (ld) {
71
+		memcpy( p , DSN_ATTR, DSN_ATTR_LEN);
72
+		p += DSN_ATTR_LEN;
73
+		memcpy( p, id->database, ld);
74
+		p += ld;
75
+	}
76
+	if (lu) {
77
+		*(p++) = ';';
78
+		memcpy( p , UID_ATTR, UID_ATTR_LEN);
79
+		p += UID_ATTR_LEN;
80
+		memcpy( p, id->username, lu);
81
+		p += lu;
82
+	}
83
+	if (lp) {
84
+		*(p++) = ';';
85
+		memcpy( p , PWD_ATTR, PWD_ATTR_LEN);
86
+		p += PWD_ATTR_LEN;
87
+		memcpy( p, id->password, lp);
88
+		p += lp;
89
+	}
90
+	*(p++) = ';';
91
+	*p = 0 ; /* make it null terminated */
92
+
93
+	return buf;
94
+}
95
+
96
+
97
+/*
98
+ * Create a new connection structure,
99
+ * open the UNIXODBC connection and set reference count to 1
100
+ */
101
+struct my_con* db_unixodbc_new_connection(struct db_id* id)
102
+{
103
+	SQLCHAR outstr[1024];
104
+	SQLSMALLINT outstrlen;
105
+	int ret;
106
+	struct my_con* ptr;
107
+	char conn_str[MAX_CONN_STR_LEN];
108
+
109
+	if (!id)
110
+	{
111
+		LM_ERR("invalid parameter value\n");
112
+		return 0;
113
+	}
114
+
115
+	ptr = (struct my_con*)pkg_malloc(sizeof(struct my_con));
116
+	if (!ptr)
117
+	{
118
+		LM_ERR("no more memory left\n");
119
+		return 0;
120
+	}
121
+
122
+	memset(ptr, 0, sizeof(struct my_con));
123
+	ptr->ref = 1;
124
+	// allocate environment handle
125
+	ret = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &(ptr->env));
126
+	if ((ret != SQL_SUCCESS) && (ret != SQL_SUCCESS_WITH_INFO))
127
+	{
128
+		LM_ERR("could not alloc a SQL handle\n");
129
+		if (ptr) pkg_free(ptr);
130
+		return 0;
131
+	}
132
+	// set the environment
133
+	ret = SQLSetEnvAttr(ptr->env, SQL_ATTR_ODBC_VERSION, (void *) SQL_OV_ODBC3, 0);
134
+	if ((ret != SQL_SUCCESS) && (ret != SQL_SUCCESS_WITH_INFO))
135
+	{
136
+		LM_ERR("could not set the environment\n");
137
+		goto err1;
138
+	}
139
+	// allocate connection handle
140
+	ret = SQLAllocHandle(SQL_HANDLE_DBC, ptr->env, &(ptr->dbc));
141
+	if ((ret != SQL_SUCCESS) && (ret != SQL_SUCCESS_WITH_INFO))
142
+	{
143
+		LM_ERR("could not alloc a connection handle %d\n", ret);
144
+		goto err1;
145
+	}
146
+
147
+	if (!db_unixodbc_build_conn_str(id, conn_str)) {
148
+		LM_ERR("failed to build connection string\n");
149
+		goto err2;
150
+	}
151
+
152
+	LM_DBG("opening connection: unixodbc://xxxx:xxxx@%s/%s\n", ZSW(id->host),
153
+		ZSW(id->database));
154
+
155
+	ret = SQLDriverConnect(ptr->dbc, NULL, (SQLCHAR*)conn_str, SQL_NTS,
156
+		outstr, sizeof(outstr), &outstrlen,
157
+		SQL_DRIVER_COMPLETE);
158
+	if (SQL_SUCCEEDED(ret))
159
+	{
160
+		LM_DBG("connection succeeded with reply <%s>\n", outstr);
161
+		if (ret == SQL_SUCCESS_WITH_INFO)
162
+		{
163
+			LM_DBG("driver reported the following diagnostics\n");
164
+			db_unixodbc_extract_error("SQLDriverConnect", ptr->dbc, SQL_HANDLE_DBC, NULL);
165
+		}
166
+	}
167
+	else
168
+	{
169
+		LM_ERR("failed to connect\n");
170
+		db_unixodbc_extract_error("SQLDriverConnect", ptr->dbc, SQL_HANDLE_DBC, NULL);
171
+		goto err2;
172
+	}
173
+
174
+	ptr->stmt_handle = NULL;
175
+
176
+	ptr->timestamp = time(0);
177
+	ptr->id = id;
178
+	return ptr;
179
+
180
+err1:
181
+	SQLFreeHandle(SQL_HANDLE_ENV, &(ptr->env));
182
+	if (ptr) pkg_free(ptr);
183
+	return 0;
184
+
185
+err2:
186
+	SQLFreeHandle(SQL_HANDLE_ENV, &(ptr->env));
187
+	SQLFreeHandle(SQL_HANDLE_DBC, &(ptr->dbc));
188
+	if (ptr) pkg_free(ptr);
189
+	return 0;
190
+}
191
+
192
+/*
193
+ * Close the connection and release memory
194
+ */
195
+void db_unixodbc_free_connection(struct my_con* con)
196
+{
197
+	if (!con) return;
198
+	SQLFreeHandle(SQL_HANDLE_ENV, con->env);
199
+	SQLDisconnect(con->dbc);
200
+	SQLFreeHandle(SQL_HANDLE_DBC, con->dbc);
201
+	pkg_free(con);
202
+}
203
+
204
+
205
+void db_unixodbc_extract_error(const char *fn, const SQLHANDLE handle, const SQLSMALLINT type, char* stret)
206
+{
207
+	SQLINTEGER   i = 0;
208
+	SQLINTEGER   native;
209
+	SQLCHAR  state[ 7 ];
210
+	SQLCHAR  text[256];
211
+	SQLSMALLINT  len;
212
+	SQLRETURN	ret;
213
+
214
+	do
215
+	{
216
+		ret = SQLGetDiagRec(type, handle, ++i, state, &native, text,
217
+			sizeof(text), &len );
218
+		if (SQL_SUCCEEDED(ret)) {
219
+			LM_ERR("unixodbc:%s=%s:%ld:%ld:%s\n", fn, state, (long)i, 
220
+					(long)native, text);
221
+			if(stret) strcpy( stret, (char*)state );
222
+		}
223
+	}
224
+	while( ret == SQL_SUCCESS );
225
+}