Browse code

- fixed refreshWatchers MI command exported from presence module

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

Anca Vamanu authored on 29/08/2007 15:38:09
Showing 13 changed files
... ...
@@ -237,7 +237,7 @@ void free_pres_event(pres_ev_t* ev)
237 237
 
238 238
 }
239 239
 
240
-evlist_t* init_evlist()
240
+evlist_t* init_evlist(void)
241 241
 {
242 242
 	evlist_t*  list= NULL;
243 243
 
... ...
@@ -361,7 +361,7 @@ int get_event_list(str** ev_list)
361 361
 	return 0;
362 362
 }
363 363
 
364
-void destroy_evlist()
364
+void destroy_evlist(void)
365 365
 {
366 366
     pres_ev_t* e1, *e2;
367 367
     if (EvList) 
... ...
@@ -107,7 +107,7 @@ typedef struct evlist
107 107
 	pres_ev_t* events;
108 108
 }evlist_t;	
109 109
 
110
-evlist_t* init_evlist();
110
+evlist_t* init_evlist(void);
111 111
 
112 112
 int add_event(pres_ev_t* event);
113 113
 
... ...
@@ -121,7 +121,7 @@ int get_event_list(str** ev_list);
121 121
 
122 122
 typedef int (*get_event_list_t) (str** ev_list);
123 123
 
124
-void destroy_evlist();
124
+void destroy_evlist(void);
125 125
 
126 126
 extern evlist_t* EvList;
127 127
 
... ...
@@ -36,7 +36,7 @@
36 36
 #include "hash.h"
37 37
 #include "notify.h"
38 38
 
39
-shtable_t new_shtable()
39
+shtable_t new_shtable(void)
40 40
 {
41 41
 	shtable_t htable= NULL;
42 42
 	int i, j;
... ...
@@ -83,7 +83,7 @@ error:
83 83
 
84 84
 }
85 85
 
86
-void destroy_shtable()
86
+void destroy_shtable(void)
87 87
 {
88 88
 	int i;
89 89
 
... ...
@@ -302,7 +302,7 @@ int update_shtable(subs_t* subs, int type)
302 302
 	return 0;
303 303
 }
304 304
 
305
-phtable_t* new_phtable()
305
+phtable_t* new_phtable(void)
306 306
 {
307 307
 	phtable_t* htable= NULL;
308 308
 	int i, j;
... ...
@@ -350,7 +350,7 @@ error:
350 350
 
351 351
 }
352 352
 
353
-void destroy_phtable()
353
+void destroy_phtable(void)
354 354
 {
355 355
 	int i;
356 356
 	pres_entry_t* p, *prev_p;
... ...
@@ -57,9 +57,10 @@ typedef struct subs_entry
57 57
 
58 58
 typedef subs_entry_t* shtable_t;
59 59
 
60
-shtable_t new_shtable();
60
+shtable_t new_shtable(void);
61 61
 
62
-subs_t* search_shtable();
62
+subs_t* search_shtable(str callid,str to_tag,str from_tag,
63
+		unsigned int hash_code);
63 64
 
64 65
 int insert_shtable(subs_t* subs);
65 66
 
... ...
@@ -71,7 +72,7 @@ subs_t* mem_copy_subs(subs_t* s, int mem_type);
71 71
 
72 72
 void free_subs_list(subs_t* s_array, int mem_type);
73 73
 
74
-void destroy_shtable();
74
+void destroy_shtable(void);
75 75
 
76 76
 /* presentity hash table */
77 77
 typedef struct pres_entry
... ...
@@ -88,7 +89,7 @@ typedef struct pres_htable
88 88
 	gen_lock_t lock;
89 89
 }phtable_t;
90 90
 
91
-phtable_t* new_phtable();
91
+phtable_t* new_phtable(void);
92 92
 
93 93
 pres_entry_t* search_phtable(str* pres_uri, int event, unsigned int hash_code);
94 94
 
... ...
@@ -96,7 +97,7 @@ int insert_phtable(str* pres_uri, int event);
96 96
 
97 97
 int delete_phtable(str* pres_uri, int event);
98 98
 
99
-void destroy_phtable();
99
+void destroy_phtable(void);
100 100
 
101 101
 #endif
102 102
 
... ...
@@ -100,6 +100,7 @@ int stored_pres_info(struct sip_msg* msg, char* pres_uri, char* s);
100 100
 static int fixup_presence(void** param, int param_no);
101 101
 struct mi_root* mi_refreshWatchers(struct mi_root* cmd, void* param);
102 102
 int get_pw_dialogs(subs_t* subs, unsigned int hash_code, subs_t** subs_array);
103
+int mi_child_init(void);
103 104
 
104 105
 int counter =0;
105 106
 int pid = 0;
... ...
@@ -141,7 +142,7 @@ static param_export_t params[]={
141 141
 };
142 142
 
143 143
 static mi_export_t mi_cmds[] = {
144
-	{ "refreshWatchers", mi_refreshWatchers,    0,  0,  0},
144
+	{ "refreshWatchers", mi_refreshWatchers,    0,  0,  mi_child_init},
145 145
 	{  0,                0,                     0,  0,  0}
146 146
 };
147 147
 
... ...
@@ -365,30 +366,69 @@ static int child_init(int rank)
365 365
 				rank);
366 366
 		return -1;
367 367
 	}
368
-	else
368
+		
369
+	if (pa_dbf.use_table(pa_db, presentity_table) < 0)  
369 370
 	{
370
-		if (pa_dbf.use_table(pa_db, presentity_table) < 0)  
371
-		{
372
-			LOG(L_ERR, "PRESENCE: child %d: Error in use_table presentity_table\n", rank);
373
-			return -1;
374
-		}
375
-		if (pa_dbf.use_table(pa_db, active_watchers_table) < 0)  
376
-		{
377
-			LOG(L_ERR, "PRESENCE: child %d: Error in use_table active_watchers_table\n",
378
-					rank);
379
-			return -1;
380
-		}
381
-		if (pa_dbf.use_table(pa_db, watchers_table) < 0)  
382
-		{
383
-			LOG(L_ERR, "PRESENCE: child %d: Error in use_table watchers_table\n", rank);
384
-			return -1;
385
-		}
371
+		LOG(L_ERR, "PRESENCE: child %d: Error in use_table presentity_table\n", rank);
372
+		return -1;
373
+	}
374
+	if (pa_dbf.use_table(pa_db, active_watchers_table) < 0)  
375
+	{
376
+		LOG(L_ERR, "PRESENCE: child %d: Error in use_table active_watchers_table\n",
377
+				rank);
378
+		return -1;
379
+	}
380
+	if (pa_dbf.use_table(pa_db, watchers_table) < 0)  
381
+	{
382
+		LOG(L_ERR, "PRESENCE: child %d: Error in use_table watchers_table\n", rank);
383
+		return -1;
384
+	}
385
+
386
+	DBG("PRESENCE: child %d: Database connection opened successfully\n", rank);
387
+	
388
+	return 0;
389
+}
386 390
 
387
-		DBG("PRESENCE: child %d: Database connection opened successfully\n", rank);
391
+int mi_child_init(void)
392
+{
393
+	if(use_db== 0)
394
+		return 0;
395
+
396
+	if (pa_dbf.init==0)
397
+	{
398
+		LOG(L_CRIT,"PRESENCE:mi_child_init:ERROR database not bound\n");
399
+		return -1;
400
+	}
401
+	pa_db = pa_dbf.init(db_url.s);
402
+	if (!pa_db)
403
+	{
404
+		LOG(L_ERR,"PRESENCE:mi_child_init:Error while connecting database\n");
405
+		return -1;
406
+	}
407
+	
408
+	if (pa_dbf.use_table(pa_db, presentity_table) < 0)  
409
+	{
410
+		LOG(L_ERR, "PRESENCE:mi_child_init: Error in use_table"
411
+				" presentity_table\n");
412
+		return -1;
413
+	}
414
+	if (pa_dbf.use_table(pa_db, active_watchers_table) < 0)  
415
+	{
416
+		LOG(L_ERR, "PRESENCE:mi_child_init: Error in use_table"
417
+				" active_watchers_table\n");
418
+		return -1;
388 419
 	}
420
+	if (pa_dbf.use_table(pa_db, watchers_table) < 0)  
421
+	{
422
+		LOG(L_ERR, "PRESENCE:mi_child_init: Error in use_table watchers_table\n");
423
+		return -1;
424
+	}
425
+
426
+	DBG("PRESENCE:mi_child_init: Database connection opened successfully\n");
389 427
 	return 0;
390 428
 }
391 429
 
430
+
392 431
 /*
393 432
  * destroy function
394 433
  */
... ...
@@ -444,7 +484,8 @@ struct mi_root* mi_refreshWatchers(struct mi_root* cmd, void* param)
444 444
 	str pres_uri, event;
445 445
 	struct sip_uri uri;
446 446
 	pres_ev_t* ev;
447
-	str* rules_doc;
447
+	str* rules_doc= NULL;
448
+	int result;
448 449
 
449 450
 	DBG("PRESENCE:mi_refreshWatchers: start\n");
450 451
 	
... ...
@@ -491,14 +532,14 @@ struct mi_root* mi_refreshWatchers(struct mi_root* cmd, void* param)
491 491
 		LOG(L_ERR, "PRESENCE:mi_refreshWatchers: ERROR wrong event parameter\n");
492 492
 		return 0;
493 493
 	}
494
-
495
-	if(ev->get_rules_doc(&uri.user,&uri.host,&rules_doc)< 0 || rules_doc==0
496
-			|| rules_doc->s== NULL)
494
+	
495
+	result= ev->get_rules_doc(&uri.user,&uri.host,&rules_doc);
496
+	if(result< 0 || rules_doc==NULL || rules_doc->s== NULL)
497 497
 	{
498 498
 		LOG(L_ERR, "PRESENCE:mi_refreshWatchers:ERROR getting rules doc\n");
499 499
 		goto error;
500 500
 	}
501
-
501
+	
502 502
 	if(update_watchers(pres_uri, ev, rules_doc)< 0)
503 503
 	{
504 504
 		LOG(L_ERR, "PRESENCE:mi_refreshWatchers:ERROR updating watchers\n");
... ...
@@ -561,12 +602,12 @@ int update_watchers(str pres_uri, pres_ev_t* ev, str* rules_doc)
561 561
 	query_vals[n_query_cols].val.str_val= ev->name;
562 562
 	n_query_cols++;
563 563
 
564
-	result_cols[status_col= n_result_cols++]= "status";
564
+	result_cols[status_col= n_result_cols++]= "subs_status";
565 565
 	result_cols[reason_col= n_result_cols++]= "reason";
566 566
 	result_cols[w_user_col= n_result_cols++]= "w_user";
567 567
 	result_cols[w_domain_col= n_result_cols++]= "w_domain";
568 568
 	
569
-	update_cols[u_status_col= n_update_cols]= "status";
569
+	update_cols[u_status_col= n_update_cols]= "subs_status";
570 570
 	update_vals[u_status_col].nul= 0;
571 571
 	update_vals[u_status_col].type= DB_INT;
572 572
 	n_update_cols++;
... ...
@@ -615,7 +656,7 @@ int update_watchers(str pres_uri, pres_ev_t* ev, str* rules_doc)
615 615
 
616 616
 		subs.from_user= w_user;
617 617
 		subs.from_domain= w_domain;
618
-
618
+		memset(&subs.reason, 0, sizeof(str));
619 619
 		if(ev->get_auth_status(&subs)< 0)
620 620
 		{
621 621
 			LOG(L_ERR, "PRESENCE:update_watchers: ERROR while getting status"
... ...
@@ -638,7 +679,7 @@ int update_watchers(str pres_uri, pres_ev_t* ev, str* rules_doc)
638 638
 			}
639 639
 
640 640
 			if(pa_dbf.update(pa_db, query_cols, 0, query_vals, update_cols,
641
-						update_vals, n_query_cols, 2)< 0)
641
+						update_vals, n_query_cols, n_update_cols)< 0)
642 642
 			{
643 643
 				LOG(L_ERR, "PRESENCE:update_watchers: ERROR in sql update\n");
644 644
 				lock_release(&subs_htable[hash_code].lock);
... ...
@@ -647,7 +688,7 @@ int update_watchers(str pres_uri, pres_ev_t* ev, str* rules_doc)
647 647
 			/* save in the list all affected dialogs */
648 648
 			if(get_pw_dialogs(&subs, hash_code, &subs_array)< 0)
649 649
 			{
650
-				LOG(L_ERR, "PRESENCE:update_watchers: ERROR ERROR extracting"
650
+				LOG(L_ERR, "PRESENCE:update_watchers: ERROR extracting dialogs"
651 651
 						"from [watcher]=%.*s@%.*s to [presentity]=%.*s\n",
652 652
 						w_user.len, w_user.s, w_domain.len, w_domain.s, 
653 653
 						pres_uri.len, pres_uri.s);
... ...
@@ -687,7 +728,8 @@ error:
687 687
 int get_pw_dialogs(subs_t* subs, unsigned int hash_code, subs_t** subs_array)
688 688
 {
689 689
 	subs_t* s, *cs;
690
-	
690
+	int i= 0;
691
+
691 692
 	s= subs_htable[hash_code].entries->next;
692 693
 	
693 694
 	while(s)
... ...
@@ -699,6 +741,7 @@ int get_pw_dialogs(subs_t* subs, unsigned int hash_code, subs_t** subs_array)
699 699
 			strncmp(s->from_user.s, subs->from_user.s, s->from_user.len)== 0 &&
700 700
 			strncmp(s->from_domain.s,subs->from_domain.s,s->from_domain.len)==0)
701 701
 		{
702
+			i++;
702 703
 			s->status= subs->status;
703 704
 			s->reason= subs->reason;
704 705
 			s->db_flag= UPDATEDB_FLAG;
... ...
@@ -710,12 +753,14 @@ int get_pw_dialogs(subs_t* subs, unsigned int hash_code, subs_t** subs_array)
710 710
 						" stucture\n");
711 711
 				return -1;
712 712
 			}
713
+			cs->expires-= (int)time(NULL);
713 714
 			cs->next= (*subs_array);
714 715
 			(*subs_array)= cs;
715 716
 
716 717
 		}
717 718
 		s= s->next;
718 719
 	}
719
-	return 0;
720
+	DBG("PRESENCE:get_pw_dialogs:found %d matching dialogs\n", i);
720 721
 
722
+	return 0;
721 723
 }
... ...
@@ -541,7 +541,7 @@ error:
541 541
 
542 542
 }
543 543
 
544
-int pres_htable_restore()
544
+int pres_htable_restore(void)
545 545
 {
546 546
 	/* query all records from presentity table and insert records 
547 547
 	 * in presentity table */
... ...
@@ -66,7 +66,7 @@ void free_presentity(presentity_t* p);
66 66
 
67 67
 char* generate_ETag(int publ_count);
68 68
 
69
-int pres_htable_restore();
69
+int pres_htable_restore(void);
70 70
 
71 71
 #endif
72 72
 
... ...
@@ -1579,7 +1579,7 @@ void timer_db_update(unsigned int ticks,void *param)
1579 1579
 
1580 1580
 }
1581 1581
 
1582
-int restore_db_subs()
1582
+int restore_db_subs(void)
1583 1583
 {
1584 1584
 	db_key_t result_cols[22]; 
1585 1585
 	db_res_t *res= NULL;
... ...
@@ -80,7 +80,7 @@ int delete_db_subs(str pres_uri, str ev_stored_name, str to_tag);
80 80
 
81 81
 void timer_db_update(unsigned int ticks,void *param);
82 82
 
83
-int restore_db_subs();
83
+int restore_db_subs(void);
84 84
 
85 85
 int update_subs_db(subs_t* subs, int type);
86 86
 
... ...
@@ -44,7 +44,7 @@
44 44
 static str pu_415_rpl  = str_init("Unsupported media type");
45 45
 extern add_event_t pres_add_event;
46 46
 
47
-int xml_add_events()
47
+int xml_add_events(void)
48 48
 {
49 49
 	pres_ev_t event;
50 50
 	
... ...
@@ -29,7 +29,7 @@
29 29
 #ifndef _XML_ADD_EV_H_
30 30
 #define _XML_ADD_EV_H_
31 31
 
32
-int xml_add_events();
32
+int xml_add_events(void);
33 33
 int	xml_publ_handl(struct sip_msg* msg);
34 34
 
35 35
 #endif
... ...
@@ -57,9 +57,11 @@ static int mod_init(void);
57 57
 static int child_init(int);
58 58
 static void destroy(void);
59 59
 int pxml_add_xcap_server( modparam_t type, void* val);
60
-int shm_copy_xcap_list();
60
+int shm_copy_xcap_list(void);
61 61
 void free_xs_list(xcap_serv_t* xs_list, int mem_type);
62 62
 int xcap_doc_updated(int doc_type, str xid, char* doc);
63
+int mi_child_init(void);
64
+struct mi_root* dum(struct mi_root* cmd, void* param);
63 65
 
64 66
 /** module variables ***/
65 67
 add_event_t pres_add_event;
... ...
@@ -92,14 +94,20 @@ static param_export_t params[]={
92 92
 	{ "xcap_server",     STR_PARAM|USE_FUNC_PARAM,(void*)pxml_add_xcap_server},
93 93
 	{  0,						0,										    0}
94 94
 };
95
-	/** module exports */
95
+
96
+static mi_export_t mi_cmds[] = {
97
+	{ "dum",             dum,            0,  0,  mi_child_init},
98
+	{  0,                0,            0,  0,        0      }
99
+};
100
+
101
+/** module exports */
96 102
 struct module_exports exports= {
97 103
 	"presence_xml",				/* module name */
98 104
 	 DEFAULT_DLFLAGS,           /* dlopen flags */
99 105
 	 0,  						/* exported functions */
100 106
 	 params,					/* exported parameters */
101 107
 	 0,							/* exported statistics */
102
-	 0,							/* exported MI functions */
108
+	 mi_cmds,							/* exported MI functions */
103 109
 	 0,							/* exported pseudo-variables */
104 110
 	 0,							/* extra processes */
105 111
 	 mod_init,					/* module initialization function */
... ...
@@ -232,6 +240,33 @@ static int mod_init(void)
232 232
 	return 0;
233 233
 }
234 234
 
235
+int mi_child_init(void)
236
+{
237
+	DBG("presence_xml: mi_child_init\n");
238
+	
239
+	if (pxml_dbf.init==0)
240
+	{
241
+		LOG(L_CRIT, "PRESENCE_XML:mi_child_init:ERROR database not bound\n");
242
+		return -1;
243
+	}
244
+	pxml_db = pxml_dbf.init(db_url.s);
245
+	if (pxml_db== NULL)
246
+	{
247
+		LOG(L_ERR,"PRESENCE_XML:mi_child_init:ERROR while connecting database\n");
248
+		return -1;
249
+	}
250
+		
251
+	if (pxml_dbf.use_table(pxml_db, xcap_table) < 0)  
252
+	{
253
+		LOG(L_ERR, "PRESENCE_XML:mi_child_init: ERROR in use_table\n");
254
+		return -1;
255
+	}
256
+	
257
+	DBG("PRESENCE_XML:mi_child_init:Database connection opened successfully\n");
258
+
259
+	return 0;
260
+}	
261
+
235 262
 static int child_init(int rank)
236 263
 {
237 264
 	DBG("presence_xml: init_child [%d]  pid [%d]\n", rank, getpid());
... ...
@@ -242,22 +277,21 @@ static int child_init(int rank)
242 242
 		return -1;
243 243
 	}
244 244
 	pxml_db = pxml_dbf.init(db_url.s);
245
-	if (!pxml_db)
245
+	if (pxml_db== NULL)
246 246
 	{
247
-		LOG(L_ERR,"PRESENCE_XML: child %d: Error while connecting database\n",
247
+		LOG(L_ERR,"PRESENCE_XML: child %d: ERROR while connecting database\n",
248 248
 				rank);
249 249
 		return -1;
250 250
 	}
251
-	else
252
-	{
253
-		if (pxml_dbf.use_table(pxml_db, xcap_table) < 0)  
254
-		{
255
-			LOG(L_ERR, "PRESENCE_XML: child %d: Error in use_table\n", rank);
256
-			return -1;
257
-		}
258 251
 		
259
-		DBG("PRESENCE_XML: child %d: Database connection opened successfully\n", rank);
252
+	if (pxml_dbf.use_table(pxml_db, xcap_table) < 0)  
253
+	{
254
+		LOG(L_ERR, "PRESENCE_XML: child %d: ERROR in use_table\n", rank);
255
+		return -1;
260 256
 	}
257
+	
258
+	DBG("PRESENCE_XML:child %d: Database connection opened successfully\n",
259
+			rank);
261 260
 
262 261
 	return 0;
263 262
 }	
... ...
@@ -300,7 +334,7 @@ error:
300 300
 	return -1;
301 301
 }
302 302
 
303
-int shm_copy_xcap_list()
303
+int shm_copy_xcap_list(void)
304 304
 {
305 305
 	xcap_serv_t* xs, *shm_xs, *prev_xs;
306 306
 	int size;
... ...
@@ -433,3 +467,7 @@ int xcap_doc_updated(int doc_type, str xid, char* doc)
433 433
 	return 0;
434 434
 
435 435
 }
436
+struct mi_root* dum(struct mi_root* cmd, void* param)
437
+{
438
+	return 0;
439
+}
... ...
@@ -378,7 +378,7 @@ int get_rules_doc(str* user, str* domain, int type, str** rules_doc)
378 378
 		*rules_doc= NULL;
379 379
 		return 0;
380 380
 	}
381
-
381
+	DBG("PRESENCE_XML:get_rules_doc..\n");
382 382
 	/* first search in database */
383 383
 	query_cols[n_query_cols] = "username";
384 384
 	query_vals[n_query_cols].type = DB_STR;
... ...
@@ -402,7 +402,8 @@ int get_rules_doc(str* user, str* domain, int type, str** rules_doc)
402 402
 
403 403
 	if (pxml_dbf.use_table(pxml_db, xcap_table) < 0) 
404 404
 	{
405
-		LOG(L_ERR, "PRESENCE_XML:get_rules_doc: Error in use_table\n");
405
+		LOG(L_ERR, "PRESENCE_XML:get_rules_doc: Error in use_table-"
406
+				"[table]= %s\n", xcap_table);
406 407
 		return -1;
407 408
 	}
408 409