Browse code

- fixed presence exported function 'update_db_subs' -removed dependency to presence module database connection to make it usable when presence module works in library mode.(reported by Reinhold Buchinger) - updated rls module to the change

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

Anca Vamanu authored on 10/10/2007 16:07:33
Showing 6 changed files
... ...
@@ -121,8 +121,8 @@ static cmd_export_t cmds[]=
121 121
 	{"handle_publish",		handle_publish,	     0,	   0,         0, REQUEST_ROUTE},
122 122
 	{"handle_publish",		handle_publish,	     1,fixup_presence,0, REQUEST_ROUTE},
123 123
 	{"handle_subscribe",	handle_subscribe,	 0,	   0,         0, REQUEST_ROUTE},
124
-	{"bind_presence",(cmd_function)bind_presence,1,    0,            0, 0         },
125
-	{0,						0,				     0,	   0,            0, 0	       }	 
124
+	{"bind_presence",(cmd_function)bind_presence,1,    0,         0,    0         },
125
+	{0,						0,				     0,	   0,         0,    0	      }	 
126 126
 };
127 127
 
128 128
 static param_export_t params[]={
... ...
@@ -1283,12 +1283,19 @@ void timer_db_update(unsigned int ticks,void *param)
1283 1283
 
1284 1284
 	if(ticks== 0 && param == NULL)
1285 1285
 		no_lock= 1;
1286
-	
1287
-	update_db_subs(active_watchers_table, subs_htable, 
1286
+
1287
+	if(pa_dbf.use_table(pa_db, active_watchers_table)< 0)
1288
+	{
1289
+		LM_ERR("sql use table failed\n");
1290
+		return;
1291
+	}
1292
+
1293
+	update_db_subs(pa_db, pa_dbf, subs_htable, 
1288 1294
 			shtable_size, no_lock, handle_expired_subs);
1295
+
1289 1296
 }
1290 1297
 
1291
-void update_db_subs(char* db_table, shtable_t hash_table,
1298
+void update_db_subs(db_con_t *db,db_func_t dbf, shtable_t hash_table,
1292 1299
 	int htable_size, int no_lock, handle_expired_func_t handle_expired_func)
1293 1300
 {	
1294 1301
 	db_key_t query_cols[22], update_cols[7], result_cols[6];
... ...
@@ -1442,16 +1449,11 @@ void update_db_subs(char* db_table, shtable_t hash_table,
1442 1442
 
1443 1443
 	result_cols[0]= "expires";
1444 1444
 
1445
-	if(pa_db== NULL)
1445
+	if(db== NULL)
1446 1446
 	{
1447 1447
 		LM_ERR("null database connection\n");
1448 1448
 		return;
1449 1449
 	}
1450
-	if(pa_dbf.use_table(pa_db, db_table)< 0)
1451
-	{
1452
-		LM_ERR("in use table\n");
1453
-		return ;
1454
-	}
1455 1450
 	for(i=0; i<htable_size; i++) 
1456 1451
 	{
1457 1452
 		if(!no_lock)
... ...
@@ -1506,7 +1508,7 @@ void update_db_subs(char* db_table, shtable_t hash_table,
1506 1506
 					update_vals[u_status_col].val.int_val= s->status;
1507 1507
 					update_vals[u_reason_col].val.str_val= s->reason;
1508 1508
 
1509
-					if(pa_dbf.update(pa_db, query_cols, 0, query_vals, update_cols, 
1509
+					if(dbf.update(db, query_cols, 0, query_vals, update_cols, 
1510 1510
 								update_vals, n_query_update, n_update_cols)< 0)
1511 1511
 					{
1512 1512
 						LM_ERR("updating in database\n");
... ...
@@ -1541,7 +1543,7 @@ void update_db_subs(char* db_table, shtable_t hash_table,
1541 1541
 					query_vals[reason_col].val.str_val= s->reason;
1542 1542
 					query_vals[socket_info_col].val.str_val= s->sockinfo_str;
1543 1543
 				
1544
-					if(pa_dbf.insert(pa_db,query_cols,query_vals,n_query_cols )<0)
1544
+					if(dbf.insert(db,query_cols,query_vals,n_query_cols )<0)
1545 1545
 					{
1546 1546
 						LM_ERR("unsuccessful sql insert\n");
1547 1547
 						if(!no_lock)
... ...
@@ -1562,7 +1564,7 @@ void update_db_subs(char* db_table, shtable_t hash_table,
1562 1562
 
1563 1563
 	update_vals[0].val.int_val= (int)time(NULL)- 10;
1564 1564
 	update_ops[0]= OP_LT;
1565
-	if(pa_dbf.delete(pa_db, update_cols, update_ops, update_vals, 1) < 0)
1565
+	if(dbf.delete(db, update_cols, update_ops, update_vals, 1) < 0)
1566 1566
 	{
1567 1567
 		LM_ERR("deleting expired information from database\n");
1568 1568
 	}
... ...
@@ -31,6 +31,7 @@
31 31
 
32 32
 //#include "presence.h"
33 33
 #include "../../str.h"
34
+#include "../../db/db.h"
34 35
 
35 36
 struct pres_ev;
36 37
 
... ...
@@ -91,10 +92,11 @@ typedef int (*refresh_watcher_t)(str*, str* , str* ,int , str* );
91 91
 int restore_db_subs(void);
92 92
 
93 93
 typedef int (*handle_expired_func_t)(subs_t* );
94
-void update_db_subs(char* db_table, shtable_t hash_table,int htable_size,
95
-		int no_lock, handle_expired_func_t handle_expired_subs);
96 94
 
97
-typedef void (*update_db_subs_t)(char* ,shtable_t ,int ,int ,
95
+void update_db_subs(db_con_t *db,db_func_t dbf, shtable_t hash_table,
96
+	int htable_size, int no_lock, handle_expired_func_t handle_expired_func);
97
+
98
+typedef void (*update_db_subs_t)(db_con_t * ,db_func_t ,shtable_t ,int ,int ,
98 99
 		handle_expired_func_t);
99 100
 
100 101
 int extract_sdialog_info(subs_t* subs,struct sip_msg* msg, int max_expire,
... ...
@@ -193,7 +193,8 @@ modparam("rls", "clean_period", 100)
193 193
 		<title><varname>waitn_time</varname> (int)</title>
194 194
 		<para>
195 195
 	 The timer period at which the server should attempt to send
196
-	 Notifies with the updated state of the subscribed list.
196
+	 Notifies with the updated presence state of the subscribed list
197
+	 or watcher information.
197 198
 		</para>
198 199
 		<para>
199 200
 		<emphasis>Default value is <quote>50</quote>.
... ...
@@ -552,6 +552,8 @@ void timer_send_notify(unsigned int ticks,void *param)
552 552
 			rlmi_doc= NULL;
553 553
 			pkg_free(rl_uri);
554 554
 			rl_uri= NULL;
555
+			pkg_free(dialog);
556
+			dialog= NULL;
555 557
 		}
556 558
 
557 559
 		if(prev_did== NULL || strcmp(prev_did, curr_did)) /*if first or different*/
... ...
@@ -733,6 +735,8 @@ void timer_send_notify(unsigned int ticks,void *param)
733 733
 		}
734 734
 		pkg_free(rl_uri);
735 735
 		rl_uri= NULL;
736
+		pkg_free(dialog);
737
+		dialog= NULL;
736 738
 	}
737 739
 
738 740
 	/* update the rlpres table */
... ...
@@ -767,7 +771,8 @@ done:
767 767
 		
768 768
 	if(buf)
769 769
 		pkg_free(buf);
770
-
770
+	if(dialog)
771
+		pkg_free(dialog);
771 772
 	return;
772 773
 }
773 774
 
... ...
@@ -498,7 +498,12 @@ void rlsubs_table_update(unsigned int ticks,void *param)
498 498
 	if(ticks== 0 && param == NULL)
499 499
 		no_lock= 1;
500 500
 	
501
-	pres_update_db_subs(rlsubs_table, rls_table, hash_size, 
501
+	if(rls_dbf.use_table(rls_db, rlsubs_table)< 0)
502
+	{
503
+		LM_ERR("sql use table failed\n");
504
+		return;
505
+	}
506
+	pres_update_db_subs(rls_db, rls_dbf, rls_table, hash_size, 
502 507
 			no_lock, handle_expired_record);
503 508
 
504 509
 }