Browse code

-corrected a bug in opening database connexion

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

Anca Vamanu authored on 27/04/2007 11:53:03
Showing 6 changed files
1 1
deleted file mode 100644
2 2
Binary files a/modules_k/presence_xml/doc/.presence_xml_user.sgml.swp and /dev/null differ
... ...
@@ -15,7 +15,7 @@
15 15
 	<title>Overview</title>
16 16
 	<para> 
17 17
 	The module does specific handling for notify-subscribe events using xml bodies.
18
-	It is used with the general event handling module, presence. It constructs and add
18
+	It is used with the general event handling module, presence. It constructs and adds
19 19
 	3 events to it: presence, presence.winfo, dialog;sla. 
20 20
 	</para>
21 21
 	<para>
... ...
@@ -871,14 +871,14 @@ str* build_off_nbody(str p_user, str p_domain, str* etag)
871 871
 
872 872
 	result_cols[body_col=n_result_cols++] = "body" ;
873 873
 
874
-	if (pa_dbf.use_table(pa_db, presentity_table) < 0) 
874
+	if (pxml_dbf.use_table(pxml_db, presentity_table) < 0) 
875 875
 	{
876 876
 		LOG(L_ERR, "PRESENCE: build_off_nbody: Error in use_table\n");
877 877
 		goto error;
878 878
 	}
879 879
 
880 880
 	DBG("PRESENCE: build_off_nbody: querying presentity\n");
881
-	if (pa_dbf.query (pa_db, query_cols, query_ops, query_vals,
881
+	if (pxml_dbf.query (pxml_db, query_cols, query_ops, query_vals,
882 882
 		 result_cols, n_query_cols, n_result_cols, 0,  &result) < 0) 
883 883
 	{
884 884
 		LOG(L_ERR, "PRESENCE: build_off_nbody: Error while querying"
... ...
@@ -989,7 +989,7 @@ str* build_off_nbody(str p_user, str p_domain, str* etag)
989 989
 	DBG("PRESENCE: build_off_nbody:new_body:\n%.*s\n",body->len, body->s);
990 990
 
991 991
 	if(result !=NULL)
992
-		pa_dbf.free_result(pa_db, result);
992
+		pxml_dbf.free_result(pxml_db, result);
993 993
 
994 994
     /*free the document */
995 995
     xmlFreeDoc(doc);
... ...
@@ -1018,7 +1018,7 @@ error:
1018 1018
 	if(new_doc)
1019 1019
 		xmlFreeDoc(new_doc);
1020 1020
 	if(result)
1021
-		pa_dbf.free_result(pa_db, result);
1021
+		pxml_dbf.free_result(pxml_db, result);
1022 1022
 	if(body)
1023 1023
 	{
1024 1024
 		if(body->s)
... ...
@@ -63,8 +63,8 @@ int force_active= 0;
63 63
 struct sl_binds slb;
64 64
 
65 65
 /* database connection */
66
-db_con_t *pa_db = NULL;
67
-db_func_t pa_dbf;
66
+db_con_t *pxml_db = NULL;
67
+db_func_t pxml_dbf;
68 68
 
69 69
 
70 70
 static cmd_export_t cmds[]=
... ...
@@ -113,21 +113,21 @@ static int mod_init(void)
113 113
 			db_url.s);
114 114
 	
115 115
 	/* binding to mysql module  */
116
-	if (bind_dbmod(db_url.s, &pa_dbf))
116
+	if (bind_dbmod(db_url.s, &pxml_dbf))
117 117
 	{
118 118
 		DBG("presence_xml:mod_init: ERROR: Database module not found\n");
119 119
 		return -1;
120 120
 	}
121 121
 	
122 122
 
123
-	if (!DB_CAPABILITY(pa_dbf, DB_CAP_ALL)) {
123
+	if (!DB_CAPABILITY(pxml_dbf, DB_CAP_ALL)) {
124 124
 		LOG(L_ERR,"presence_xml:mod_init: ERROR Database module does not implement "
125 125
 		    "all functions needed by the module\n");
126 126
 		return -1;
127 127
 	}
128 128
 
129
-	pa_db = pa_dbf.init(db_url.s);
130
-	if (!pa_db)
129
+	pxml_db = pxml_dbf.init(db_url.s);
130
+	if (!pxml_db)
131 131
 	{
132 132
 		LOG(L_ERR,"presence_xml:mod_init: Error while connecting database\n");
133 133
 		return -1;
... ...
@@ -135,7 +135,7 @@ static int mod_init(void)
135 135
 
136 136
 	_s.s = xcap_table;
137 137
 	_s.len = strlen(xcap_table);
138
-	 ver =  table_version(&pa_dbf, pa_db, &_s);
138
+	 ver =  table_version(&pxml_dbf, pxml_db, &_s);
139 139
 	if(ver!=S_TABLE_VERSION)
140 140
 	{
141 141
 		LOG(L_ERR,"presence_xml:mod_init: Wrong version v%d for table <%s>,"
... ...
@@ -172,6 +172,9 @@ static int mod_init(void)
172 172
 		LOG(L_ERR, "presence_xml:mod_init: ERROR while adding xml events\n");
173 173
 		return -1;		
174 174
 	}	
175
+	if(pxml_db)
176
+		pxml_dbf.close(pxml_db);
177
+	pxml_db = NULL;
175 178
 
176 179
 	return 0;
177 180
 }
... ...
@@ -179,12 +182,38 @@ static int mod_init(void)
179 182
 static int child_init(int rank)
180 183
 {
181 184
 	DBG("presence_xml: init_child [%d]  pid [%d]\n", rank, getpid());
185
+	
186
+	if (pxml_dbf.init==0)
187
+	{
188
+		LOG(L_CRIT, "BUG: PRESENCE_XML: child_init: database not bound\n");
189
+		return -1;
190
+	}
191
+	pxml_db = pxml_dbf.init(db_url.s);
192
+	if (!pxml_db)
193
+	{
194
+		LOG(L_ERR,"PRESENCE_XML: child %d: Error while connecting database\n",
195
+				rank);
196
+		return -1;
197
+	}
198
+	else
199
+	{
200
+		if (pxml_dbf.use_table(pxml_db, xcap_table) < 0)  
201
+		{
202
+			LOG(L_ERR, "PRESENCE_XML: child %d: Error in use_table\n", rank);
203
+			return -1;
204
+		}
205
+		
206
+		DBG("PRESENCE_XML: child %d: Database connection opened successfully\n", rank);
207
+	}
208
+
182 209
 	return 0;
183 210
 }	
184 211
 
185 212
 static void destroy(void)
186 213
 {	
187 214
 	DBG("presence_xml: destroying module ...\n");
215
+	if(pxml_db && pxml_dbf.close)
216
+		pxml_dbf.close(pxml_db);
188 217
 
189 218
 	return ;
190 219
 }
... ...
@@ -33,8 +33,8 @@
33 33
 
34 34
 extern char *xcap_table;  
35 35
 extern add_event_t pres_add_event;
36
-extern db_con_t *pa_db = NULL;
37
-extern db_func_t pa_dbf;
36
+extern db_con_t *pxml_db = NULL;
37
+extern db_func_t pxml_dbf;
38 38
 extern int force_active;
39 39
 /* SL bind */
40 40
 extern struct sl_binds slb;
... ...
@@ -29,12 +29,14 @@
29 29
 #include "../../str.h"
30 30
 #include "../../dprint.h"
31 31
 #include "../presence/utils_func.h"
32
+#include "presence_xml.h"
32 33
 #include "xcap_auth.h"
33 34
 #include "pidf.h"
34
-#include "presence_xml.h"
35 35
 
36 36
 extern char* xcap_table;
37 37
 extern int force_active;
38
+extern db_func_t pxml_dbf;
39
+extern db_con_t *pxml_db;
38 40
 
39 41
 int is_watcher_allowed( subs_t* subs, xmlDocPtr xcap_tree );
40 42
 
... ...
@@ -331,13 +333,13 @@ xmlDocPtr get_xcap_tree(str user, str domain)
331 333
 
332 334
 	result_cols[0] = "xcap";
333 335
 
334
-	if (pa_dbf.use_table(pa_db, xcap_table) < 0) 
336
+	if (pxml_dbf.use_table(pxml_db, xcap_table) < 0) 
335 337
 	{
336 338
 		LOG(L_ERR, "PRESENCE_XML:get_xcap_tree: Error in use_table\n");
337 339
 		return NULL;
338 340
 	}
339 341
 
340
-	if( pa_dbf.query(pa_db, query_cols, 0 , query_vals, result_cols, 
342
+	if( pxml_dbf.query(pxml_db, query_cols, 0 , query_vals, result_cols, 
341 343
 				n_query_cols, 1, 0, &result)<0)
342 344
 	{
343 345
 		LOG(L_ERR, "PRESENCE_XML:get_xcap_tree:Error while querying table xcap for"
... ...
@@ -385,13 +387,13 @@ xmlDocPtr get_xcap_tree(str user, str domain)
385 387
 	}
386 388
 
387 389
 	if(result!=NULL)
388
-		pa_dbf.free_result(pa_db, result);
390
+		pxml_dbf.free_result(pxml_db, result);
389 391
 
390 392
 	return xcap_tree;
391 393
 
392 394
 error:
393 395
 	if(result!=NULL)
394
-		pa_dbf.free_result(pa_db, result);
396
+		pxml_dbf.free_result(pxml_db, result);
395 397
 	return NULL;
396 398
 }
397 399