Browse code

- followed the suggestions of Adrian Georgescu to use the same names in equivalent columns from watchers and active_watchers database tables

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

Anca Vamanu authored on 16/10/2007 11:38:54
Showing 5 changed files
... ...
@@ -242,7 +242,7 @@ int get_wi_subs_db(subs_t* subs, watcher_t** watchers)
242 242
 	int status_col, expires_col, from_user_col, from_domain_col;
243 243
 	str from_user, from_domain;
244 244
 
245
-	query_cols[n_query_cols] = "pres_uri";
245
+	query_cols[n_query_cols] = "presentity_uri";
246 246
 	query_ops[n_query_cols] = OP_EQ;
247 247
 	query_vals[n_query_cols].type = DB_STR;
248 248
 	query_vals[n_query_cols].nul = 0;
... ...
@@ -258,8 +258,8 @@ int get_wi_subs_db(subs_t* subs, watcher_t** watchers)
258 258
 
259 259
 	result_cols[status_col=n_result_cols++] = "status" ;
260 260
 	result_cols[expires_col=n_result_cols++] = "expires";
261
-	result_cols[from_user_col=n_result_cols++] = "from_user";
262
-	result_cols[from_domain_col=n_result_cols++] = "from_domain";
261
+	result_cols[from_user_col=n_result_cols++] = "watcher_username";
262
+	result_cols[from_domain_col=n_result_cols++] = "watcher_domain";
263 263
 	
264 264
 	if (pa_dbf.use_table(pa_db, active_watchers_table) < 0) 
265 265
 	{
... ...
@@ -890,7 +890,7 @@ int get_subs_db(str* pres_uri, pres_ev_t* event, str* sender,
890 890
 	}
891 891
 
892 892
 	LM_DBG("querying database table = active_watchers\n");
893
-	query_cols[n_query_cols] = "pres_uri";
893
+	query_cols[n_query_cols] = "presentity_uri";
894 894
 	query_ops[n_query_cols] = OP_EQ;
895 895
 	query_vals[n_query_cols].type = DB_STR;
896 896
 	query_vals[n_query_cols].nul = 0;
... ...
@@ -924,8 +924,8 @@ int get_subs_db(str* pres_uri, pres_ev_t* event, str* sender,
924 924
 
925 925
 	result_cols[to_user_col=n_result_cols++]      =   "to_user" ;
926 926
 	result_cols[to_domain_col=n_result_cols++]    =   "to_domain";
927
-	result_cols[from_user_col=n_result_cols++]    =   "from_user" ;
928
-	result_cols[from_domain_col=n_result_cols++]  =   "from_domain" ;
927
+	result_cols[from_user_col=n_result_cols++]    =   "watcher_username" ;
928
+	result_cols[from_domain_col=n_result_cols++]  =   "watcher_domain" ;
929 929
 	result_cols[event_id_col=n_result_cols++]     =   "event_id";
930 930
 	result_cols[from_tag_col=n_result_cols++]     =   "from_tag";
931 931
 	result_cols[to_tag_col=n_result_cols++]       =   "to_tag";	
... ...
@@ -60,9 +60,9 @@
60 60
 
61 61
 MODULE_VERSION
62 62
 
63
-#define S_TABLE_VERSION  2
63
+#define S_TABLE_VERSION  3
64 64
 #define P_TABLE_VERSION  2
65
-#define ACTWATCH_TABLE_VERSION 8
65
+#define ACTWATCH_TABLE_VERSION 9
66 66
 
67 67
 char *log_buf = NULL;
68 68
 static int clean_period=100;
... ...
@@ -593,7 +593,7 @@ int update_watchers_status(str pres_uri, pres_ev_t* ev, str* rules_doc)
593 593
 	db_val_t *row_vals ;
594 594
 	int i;
595 595
 	str w_user, w_domain, reason;
596
-	int status;
596
+	unsigned int status;
597 597
 	int status_col, w_user_col, w_domain_col, reason_col;
598 598
 	int u_status_col, u_reason_col, q_wuser_col, q_wdomain_col;
599 599
 	subs_t* subs_array= NULL,* s;
... ...
@@ -615,7 +615,7 @@ int update_watchers_status(str pres_uri, pres_ev_t* ev, str* rules_doc)
615 615
 	subs.auth_rules_doc= rules_doc;
616 616
 
617 617
 	/* update in watchers_table */
618
-	query_cols[n_query_cols]= "p_uri";
618
+	query_cols[n_query_cols]= "presentity_uri";
619 619
 	query_vals[n_query_cols].nul= 0;
620 620
 	query_vals[n_query_cols].type= DB_STR;
621 621
 	query_vals[n_query_cols].val.str_val= pres_uri;
... ...
@@ -627,12 +627,12 @@ int update_watchers_status(str pres_uri, pres_ev_t* ev, str* rules_doc)
627 627
 	query_vals[n_query_cols].val.str_val= ev->name;
628 628
 	n_query_cols++;
629 629
 
630
-	result_cols[status_col= n_result_cols++]= "subs_status";
630
+	result_cols[status_col= n_result_cols++]= "status";
631 631
 	result_cols[reason_col= n_result_cols++]= "reason";
632
-	result_cols[w_user_col= n_result_cols++]= "w_user";
633
-	result_cols[w_domain_col= n_result_cols++]= "w_domain";
632
+	result_cols[w_user_col= n_result_cols++]= "watcher_username";
633
+	result_cols[w_domain_col= n_result_cols++]= "watcher_domain";
634 634
 	
635
-	update_cols[u_status_col= n_update_cols]= "subs_status";
635
+	update_cols[u_status_col= n_update_cols]= "status";
636 636
 	update_vals[u_status_col].nul= 0;
637 637
 	update_vals[u_status_col].type= DB_INT;
638 638
 	n_update_cols++;
... ...
@@ -663,12 +663,12 @@ int update_watchers_status(str pres_uri, pres_ev_t* ev, str* rules_doc)
663 663
 		goto done;
664 664
 	}
665 665
 
666
-	query_cols[q_wuser_col=n_query_cols]= "w_user";
666
+	query_cols[q_wuser_col=n_query_cols]= "watcher_username";
667 667
 	query_vals[n_query_cols].nul= 0;
668 668
 	query_vals[n_query_cols].type= DB_STR;
669 669
 	n_query_cols++;
670 670
 
671
-	query_cols[q_wdomain_col=n_query_cols]= "w_domain";
671
+	query_cols[q_wdomain_col=n_query_cols]= "watcher_domain";
672 672
 	query_vals[n_query_cols].nul= 0;
673 673
 	query_vals[n_query_cols].type= DB_STR;
674 674
 	n_query_cols++;
... ...
@@ -451,7 +451,8 @@ int handle_publish(struct sip_msg* msg, char* sender_uri, char* str2)
451 451
 	/* now we have all the necessary values */
452 452
 	/* fill in the filds of the structure */
453 453
 
454
-	presentity= new_presentity(&pres_domain, &pres_user, lexpire, event, &etag, sender);
454
+	presentity= new_presentity(&pres_domain, &pres_user, lexpire, event,
455
+			&etag, sender);
455 456
 	if(presentity== NULL)
456 457
 	{
457 458
 		LM_ERR("creating presentity structure\n");
... ...
@@ -141,7 +141,7 @@ int delete_db_subs(str pres_uri, str ev_stored_name, str to_tag)
141 141
 	db_val_t query_vals[5];
142 142
 	int n_query_cols= 0;
143 143
 
144
-	query_cols[n_query_cols] = "pres_uri";
144
+	query_cols[n_query_cols] = "presentity_uri";
145 145
 	query_vals[n_query_cols].type = DB_STR;
146 146
 	query_vals[n_query_cols].nul = 0;
147 147
 	query_vals[n_query_cols].val.str_val = pres_uri;
... ...
@@ -182,19 +182,19 @@ int update_subs_db(subs_t* subs, int type)
182 182
 	int n_update_cols= 0;
183 183
 	int n_query_cols = 0;
184 184
 
185
-	query_cols[n_query_cols] = "pres_uri";
185
+	query_cols[n_query_cols] = "presentity_uri";
186 186
 	query_vals[n_query_cols].type = DB_STR;
187 187
 	query_vals[n_query_cols].nul = 0;
188 188
 	query_vals[n_query_cols].val.str_val = subs->pres_uri;
189 189
 	n_query_cols++;
190 190
 	
191
-	query_cols[n_query_cols] = "from_user";
191
+	query_cols[n_query_cols] = "watcher_username";
192 192
 	query_vals[n_query_cols].type = DB_STR;
193 193
 	query_vals[n_query_cols].nul = 0;
194 194
 	query_vals[n_query_cols].val.str_val = subs->from_user;
195 195
 	n_query_cols++;
196 196
 	
197
-	query_cols[n_query_cols] = "from_domain";
197
+	query_cols[n_query_cols] = "watcher_domain";
198 198
 	query_vals[n_query_cols].type = DB_STR;
199 199
 	query_vals[n_query_cols].nul = 0;
200 200
 	query_vals[n_query_cols].val.str_val = subs->from_domain;
... ...
@@ -458,7 +458,7 @@ void msg_watchers_clean(unsigned int ticks,void *param)
458 458
 	db_vals[0].nul = 0;
459 459
 	db_vals[0].val.int_val = (int)time(NULL)- 24*3600 ;
460 460
 
461
-	db_keys[1] = "subs_status";
461
+	db_keys[1] = "status";
462 462
 	db_ops [1] = OP_EQ;
463 463
 	db_vals[1].type = DB_INT;
464 464
 	db_vals[1].nul = 0;
... ...
@@ -640,7 +640,11 @@ int handle_subscribe(struct sip_msg* msg, char* str1, char* str2)
640 640
 					LM_ERR("in event specific function is_watcher_allowed\n");
641 641
 					goto error;
642 642
 				}
643
-				
643
+				if(get_status_str(subs.status)== NULL)
644
+				{
645
+					LM_ERR("wrong status= %d\n", subs.status);
646
+					goto error;
647
+				}
644 648
 				if(insert_db_subs_auth(&subs)< 0)
645 649
 				{
646 650
 					LM_ERR("while inserting record in watchers table\n");
... ...
@@ -1097,13 +1101,13 @@ int get_database_info(struct sip_msg* msg, subs_t* subs, int* error_ret)
1097 1097
 	query_vals[n_query_cols].val.str_val = subs->to_domain;
1098 1098
 	n_query_cols++;
1099 1099
 
1100
-	query_cols[n_query_cols] = "from_user";
1100
+	query_cols[n_query_cols] = "watcher_username";
1101 1101
 	query_vals[n_query_cols].type = DB_STR;
1102 1102
 	query_vals[n_query_cols].nul = 0;
1103 1103
 	query_vals[n_query_cols].val.str_val = subs->from_user;
1104 1104
 	n_query_cols++;
1105 1105
 	
1106
-	query_cols[n_query_cols] = "from_domain";
1106
+	query_cols[n_query_cols] = "watcher_domain";
1107 1107
 	query_vals[n_query_cols].type = DB_STR;
1108 1108
 	query_vals[n_query_cols].nul = 0;
1109 1109
 	query_vals[n_query_cols].val.str_val = subs->from_domain;
... ...
@@ -1146,7 +1150,7 @@ int get_database_info(struct sip_msg* msg, subs_t* subs, int* error_ret)
1146 1146
 	query_vals[n_query_cols].val.str_val = subs->from_tag;
1147 1147
 	n_query_cols++;
1148 1148
 
1149
-	result_cols[pres_uri_col=n_result_cols++] = "pres_uri";
1149
+	result_cols[pres_uri_col=n_result_cols++] = "presentity_uri";
1150 1150
 	result_cols[remote_cseq_col=n_result_cols++] = "remote_cseq";
1151 1151
 	result_cols[local_cseq_col=n_result_cols++] = "local_cseq";
1152 1152
 	result_cols[status_col=n_result_cols++] = "status";
... ...
@@ -1314,7 +1318,7 @@ void update_db_subs(db_con_t *db,db_func_t dbf, shtable_t hash_table,
1314 1314
 	int n_query_cols= 0, n_update_cols= 0;
1315 1315
 	int n_query_update;
1316 1316
 
1317
-	query_cols[pres_uri_col= n_query_cols] ="pres_uri";
1317
+	query_cols[pres_uri_col= n_query_cols] ="presentity_uri";
1318 1318
 	query_vals[pres_uri_col].type = DB_STR;
1319 1319
 	query_vals[pres_uri_col].nul = 0;
1320 1320
 	n_query_cols++;
... ...
@@ -1346,12 +1350,12 @@ void update_db_subs(db_con_t *db,db_func_t dbf, shtable_t hash_table,
1346 1346
 	query_vals[to_domain_col].nul = 0;
1347 1347
 	n_query_cols++;
1348 1348
 	
1349
-	query_cols[from_user_col= n_query_cols] ="from_user";
1349
+	query_cols[from_user_col= n_query_cols] ="watcher_username";
1350 1350
 	query_vals[from_user_col].type = DB_STR;
1351 1351
 	query_vals[from_user_col].nul = 0;
1352 1352
 	n_query_cols++;
1353 1353
 
1354
-	query_cols[from_domain_col= n_query_cols] ="from_domain";
1354
+	query_cols[from_domain_col= n_query_cols] ="watcher_domain";
1355 1355
 	query_vals[from_domain_col].type = DB_STR;
1356 1356
 	query_vals[from_domain_col].nul = 0;
1357 1357
 	n_query_cols++;
... ...
@@ -1590,14 +1594,14 @@ int restore_db_subs(void)
1590 1590
 	unsigned int expires;
1591 1591
 	unsigned int hash_code;
1592 1592
 
1593
-	result_cols[pres_uri_col=n_result_cols++]	="pres_uri";		
1593
+	result_cols[pres_uri_col=n_result_cols++]	="presentity_uri";		
1594 1594
 	result_cols[expires_col=n_result_cols++]="expires";
1595 1595
 	result_cols[event_col=n_result_cols++]	="event";
1596 1596
 	result_cols[event_id_col=n_result_cols++]="event_id";
1597 1597
 	result_cols[to_user_col=n_result_cols++]	="to_user";
1598 1598
 	result_cols[to_domain_col=n_result_cols++]	="to_domain";
1599
-	result_cols[from_user_col=n_result_cols++]	="from_user";
1600
-	result_cols[from_domain_col=n_result_cols++]="from_domain";
1599
+	result_cols[from_user_col=n_result_cols++]	="watcher_username";
1600
+	result_cols[from_domain_col=n_result_cols++]="watcher_domain";
1601 1601
 	result_cols[callid_col=n_result_cols++] ="callid";
1602 1602
 	result_cols[totag_col=n_result_cols++]	="to_tag";
1603 1603
 	result_cols[fromtag_col=n_result_cols++]="from_tag";
... ...
@@ -1844,19 +1848,19 @@ int get_db_subs_auth(subs_t* subs, int* found)
1844 1844
 	db_row_t *row ;	
1845 1845
 	db_val_t *row_vals ;
1846 1846
 
1847
-	db_keys[n_query_cols] ="p_uri";
1847
+	db_keys[n_query_cols] ="presentity_uri";
1848 1848
 	db_vals[n_query_cols].type = DB_STR;
1849 1849
 	db_vals[n_query_cols].nul = 0;
1850 1850
 	db_vals[n_query_cols].val.str_val= subs->pres_uri;
1851 1851
 	n_query_cols++;
1852 1852
 
1853
-	db_keys[n_query_cols] ="w_user";
1853
+	db_keys[n_query_cols] ="watcher_username";
1854 1854
 	db_vals[n_query_cols].type = DB_STR;
1855 1855
 	db_vals[n_query_cols].nul = 0;
1856 1856
 	db_vals[n_query_cols].val.str_val = subs->from_user;
1857 1857
 	n_query_cols++;
1858 1858
 
1859
-	db_keys[n_query_cols] ="w_domain";
1859
+	db_keys[n_query_cols] ="watcher_domain";
1860 1860
 	db_vals[n_query_cols].type = DB_STR;
1861 1861
 	db_vals[n_query_cols].nul = 0;
1862 1862
 	db_vals[n_query_cols].val.str_val = subs->from_domain;
... ...
@@ -1868,7 +1872,7 @@ int get_db_subs_auth(subs_t* subs, int* found)
1868 1868
 	db_vals[n_query_cols].val.str_val = subs->event->name;
1869 1869
 	n_query_cols++;
1870 1870
 
1871
-	result_cols[0] = "subs_status";
1871
+	result_cols[0] = "status";
1872 1872
 	result_cols[1] = "reason";
1873 1873
 
1874 1874
 	if(pa_dbf.use_table(pa_db, watchers_table)< 0)
... ...
@@ -1930,19 +1934,19 @@ int insert_db_subs_auth(subs_t* subs)
1930 1930
 	db_val_t db_vals[10];
1931 1931
 	int n_query_cols= 0; 
1932 1932
 
1933
-	db_keys[n_query_cols] ="p_uri";
1933
+	db_keys[n_query_cols] ="presentity_uri";
1934 1934
 	db_vals[n_query_cols].type = DB_STR;
1935 1935
 	db_vals[n_query_cols].nul = 0;
1936 1936
 	db_vals[n_query_cols].val.str_val= subs->pres_uri;
1937 1937
 	n_query_cols++;
1938 1938
 
1939
-	db_keys[n_query_cols] ="w_user";
1939
+	db_keys[n_query_cols] ="watcher_username";
1940 1940
 	db_vals[n_query_cols].type = DB_STR;
1941 1941
 	db_vals[n_query_cols].nul = 0;
1942 1942
 	db_vals[n_query_cols].val.str_val = subs->from_user;
1943 1943
 	n_query_cols++;
1944 1944
 
1945
-	db_keys[n_query_cols] ="w_domain";
1945
+	db_keys[n_query_cols] ="watcher_domain";
1946 1946
 	db_vals[n_query_cols].type = DB_STR;
1947 1947
 	db_vals[n_query_cols].nul = 0;
1948 1948
 	db_vals[n_query_cols].val.str_val = subs->from_domain;
... ...
@@ -1954,7 +1958,7 @@ int insert_db_subs_auth(subs_t* subs)
1954 1954
 	db_vals[n_query_cols].val.str_val = subs->event->name;
1955 1955
 	n_query_cols++;
1956 1956
 
1957
-	db_keys[n_query_cols] ="subs_status";
1957
+	db_keys[n_query_cols] ="status";
1958 1958
 	db_vals[n_query_cols].type = DB_INT;
1959 1959
 	db_vals[n_query_cols].nul = 0;
1960 1960
 	db_vals[n_query_cols].val.int_val = subs->status;
... ...
@@ -1989,69 +1993,3 @@ int insert_db_subs_auth(subs_t* subs)
1989 1989
 
1990 1990
 	return 0;
1991 1991
 }
1992
-
1993
-int update_db_subs_auth(subs_t* subs)	
1994
-{	
1995
-	db_key_t db_keys[10], update_keys[3];
1996
-	db_val_t db_vals[10], update_vals[3];
1997
-	int n_query_cols= 0; 
1998
-
1999
-	db_keys[n_query_cols] ="p_uri";
2000
-	db_vals[n_query_cols].type = DB_STR;
2001
-	db_vals[n_query_cols].nul = 0;
2002
-	db_vals[n_query_cols].val.str_val= subs->pres_uri;
2003
-	n_query_cols++;
2004
-
2005
-	db_keys[n_query_cols] ="w_user";
2006
-	db_vals[n_query_cols].type = DB_STR;
2007
-	db_vals[n_query_cols].nul = 0;
2008
-	db_vals[n_query_cols].val.str_val = subs->from_user;
2009
-	n_query_cols++;
2010
-
2011
-	db_keys[n_query_cols] ="w_domain";
2012
-	db_vals[n_query_cols].type = DB_STR;
2013
-	db_vals[n_query_cols].nul = 0;
2014
-	db_vals[n_query_cols].val.str_val = subs->from_domain;
2015
-	n_query_cols++;
2016
-	
2017
-	db_keys[n_query_cols] ="event";
2018
-	db_vals[n_query_cols].type = DB_STR;
2019
-	db_vals[n_query_cols].nul = 0;
2020
-	db_vals[n_query_cols].val.str_val = subs->event->name;
2021
-	n_query_cols++;
2022
-
2023
-	/* update if different */
2024
-	int n_update_cols= 0;
2025
-
2026
-	update_keys[0]="subs_status";
2027
-	update_vals[0].type = DB_INT;
2028
-	update_vals[0].nul = 0;
2029
-	update_vals[0].val.int_val= subs->status;
2030
-	n_update_cols++;
2031
-
2032
-	if(subs->reason.s && subs->reason.len)
2033
-	{
2034
-		update_keys[1]="reason";
2035
-		update_vals[1].type = DB_STR;
2036
-		update_vals[1].nul = 0;
2037
-		update_vals[1].val.str_val= subs->reason;
2038
-		n_update_cols++;
2039
-	}	
2040
-
2041
-	if (pa_dbf.use_table(pa_db, watchers_table) < 0) 
2042
-	{
2043
-		LM_ERR("in use_table\n");
2044
-		return -1;
2045
-	}
2046
-
2047
-				
2048
-	if(pa_dbf.update(pa_db, db_keys, 0, db_vals, 
2049
-		update_keys, update_vals, n_query_cols, n_update_cols)< 0)
2050
-	{
2051
-		LM_ERR("updating database table\n");
2052
-		return -1;
2053
-	}
2054
-	return 0;	
2055
-	
2056
-}
2057
-
... ...
@@ -61,7 +61,7 @@ struct subscription
61 61
 	str local_contact;
62 62
 	str record_route;
63 63
 	unsigned int expires;
64
-	int status;
64
+	unsigned int status;
65 65
 	str reason;
66 66
 	int version;
67 67
 	int send_on_cback;