Browse code

modules_k/pua, modules_k/rls: Several debug, PostgreSQL, and DB only fixes to PUA and RLS

- A number of small tweaks and fixes

pd authored on 20/11/2011 21:55:28
Showing 3 changed files
... ...
@@ -1044,7 +1044,10 @@ static void db_update(unsigned int ticks,void *param)
1044 1044
 					if((p->watcher_uri))
1045 1045
 						q_vals[watcher_col].val.str_val = *(p->watcher_uri);
1046 1046
 					else
1047
-						memset(& q_vals[watcher_col].val.str_val ,0, sizeof(str));
1047
+					{
1048
+						q_vals[watcher_col].val.str_val.s = "";
1049
+						q_vals[watcher_col].val.str_val.len = 0;
1050
+					}
1048 1051
 
1049 1052
 					if(p->tuple_id.s == NULL)
1050 1053
 					{
... ...
@@ -65,51 +65,6 @@ static int puadb_debug=0;
65 65
 
66 66
 /******************************************************************************/
67 67
 
68
-void pua_trace( char *func_name, char *text, ua_pres_t *pres )
69
-{
70
-  str *w=pres->watcher_uri;
71
-
72
-  if (!puadb_debug) return;	
73
-
74
-    /*LM_ERR( "%s %s pres_uri=%.*s watcher_uri=%.*s\n", */
75
-    LM_ERR( "%s %s pres_uri=%.*s pres_id=%.*s flag=%d event=%d watcher_uri=%.*s\n", 
76
-           func_name, text, pres->pres_uri->len, pres->pres_uri->s,
77
-           pres->id.len, pres->id.s, pres->flag, pres->event,
78
-           w?w->len:0, w?w->s:"" );
79
-} 
80
-
81
-/******************************************************************************/
82
-
83
-void pua_trace_int( char *func_name, char *text, int val, ua_pres_t *pres )
84
-{
85
-  str *w=pres->watcher_uri;
86
-
87
-  if (!puadb_debug) return;
88
-
89
-    /*LM_ERR( "%s %s %d pres_uri=%.*s watcher_uri=%.*s\n", */
90
-    LM_ERR( "%s %s %d pres_uri=%.*s pres_id=%.*s flag=%d event=%d watcher_uri=%.*s\n", 
91
-           func_name, text, val, pres->pres_uri->len, pres->pres_uri->s,
92
-          pres->id.len, pres->id.s, pres->flag, pres->event,
93
-            w?w->len:0, w?w->s:"" );
94
-} 
95
-
96
-/******************************************************************************/
97
-
98
-void pua_trace_string( char *func_name, char *text, const char *val, ua_pres_t *pres )
99
-{
100
-  str *w=pres->watcher_uri;
101
-
102
-  if (!puadb_debug) return;
103
-
104
-    /*LM_ERR( "%s %s %s pres_uri=%.*s watcher_uri=%.*s\n", */
105
-    LM_ERR( "%s %s %s pres_uri=%.*s pres_id=%.*s flag=%d event=%d watcher_uri=%.*s\n", 
106
-           func_name, text, "val", pres->pres_uri->len, pres->pres_uri->s,
107
-           pres->id.len, pres->id.s, pres->flag, pres->event,
108
-            w?w->len:0, w?w->s:"" );
109
-} 
110
-
111
-/******************************************************************************/
112
-
113 68
 void free_results_puadb( db1_res_t *res )
114 69
 
115 70
 {
... ...
@@ -420,7 +375,7 @@ int matches_in_puadb(ua_pres_t *pres)
420 375
   nr_rows = RES_ROW_N(res);
421 376
 
422 377
   pua_dbf.free_result(pua_db, res);
423
-  pua_trace_int( "matches_in_puadb", "DONE rval=", nr_rows, pres );
378
+  LM_DBG("Found %d rows\n", nr_rows);
424 379
   return(nr_rows);
425 380
 }
426 381
 
... ...
@@ -539,14 +494,14 @@ ua_pres_t* search_puadb(ua_pres_t *pres, ua_pres_t *result, db1_res_t **dbres)
539 494
   if (nr_rows == 0)
540 495
   {
541 496
     /* no match */ 
542
-    pua_trace( "search_puadb", "NO MATCH", pres );
497
+    LM_DBG("No rows found\n");
543 498
     pua_dbf.free_result(pua_db, res);
544 499
     return(NULL);
545 500
   }
546 501
 
547 502
   if (nr_rows != 1)
548 503
   {
549
-    pua_trace_int( "search_puadb", "TOO MANY MATCHES=", nr_rows, pres );   
504
+    LM_ERR("Too many rows found (%d)\n", nr_rows);
550 505
     pua_dbf.free_result(pua_db, res);
551 506
     return(NULL);
552 507
   }
... ...
@@ -561,8 +516,6 @@ ua_pres_t* search_puadb(ua_pres_t *pres, ua_pres_t *result, db1_res_t **dbres)
561 516
   /*pua_dbf.free_result(pua_db, res);*/
562 517
   *dbres = res;
563 518
 
564
-  pua_trace( "search_puadb", "DONE", pres );  
565
-
566 519
   return(result);
567 520
 }
568 521
 
... ...
@@ -665,14 +618,14 @@ ua_pres_t* get_dialog_puadb(ua_pres_t *pres, ua_pres_t *result, db1_res_t **dbre
665 618
   if (nr_rows == 0)
666 619
   {
667 620
     /* no match */ 
668
-    pua_trace( "get_dialog_puadb", "NO MATCH", pres );  
621
+    LM_DBG("No rows found\n");
669 622
     pua_dbf.free_result(pua_db, res);
670 623
     return(NULL);
671 624
   }
672 625
 
673 626
   if (nr_rows != 1)
674 627
   {
675
-    pua_trace_int( "get_dialog_puadb", "TOO MANY RESULTS=", nr_rows, pres );  
628
+    LM_ERR("Too many rows found (%d)\n", nr_rows);
676 629
     return(NULL);
677 630
   }
678 631
 
... ...
@@ -686,7 +639,6 @@ ua_pres_t* get_dialog_puadb(ua_pres_t *pres, ua_pres_t *result, db1_res_t **dbre
686 639
   /*pua_dbf.free_result(pua_db, res);*/
687 640
   *dbres = res;
688 641
 
689
-  pua_trace( "get_dialog_puadb", "DONE", pres );  
690 642
   return(result);
691 643
 }
692 644
 
... ...
@@ -783,18 +735,16 @@ int is_dialog_puadb(ua_pres_t *pres)
783 735
   if (nr_rows == 0)
784 736
   {
785 737
     /* no match */ 
786
-    pua_trace( "is_dialog_puadb", "NO MATCH", pres );  
738
+    LM_ERR("No rows found.\n");
787 739
     return(-1);
788 740
   }
789 741
 
790 742
   if (nr_rows != 1)
791 743
   {
792
-    pua_trace_int( "is_dialog_puadb", "TOO MANY RESULTS=", nr_rows, pres );
744
+    LM_ERR("Too many rows found (%d)\n", nr_rows);
793 745
     return(-1);
794 746
   }
795 747
 
796
-
797
-  pua_trace( "is_dialog_puadb", "MATCH", pres );
798 748
   return(0);
799 749
 }
800 750
 
... ...
@@ -895,15 +845,15 @@ int get_record_id_puadb(ua_pres_t *pres, str **rec_id )
895 845
 
896 846
   if (nr_rows == 0)
897 847
   {
898
-    /* no match */ 
899
-    pua_trace( "get_record_id_puadb", "NO MATCH", pres );
848
+    /* no match */
849
+    LM_DBG("No rows found.\n");
900 850
     pua_dbf.free_result(pua_db, res);
901 851
     return(0);
902 852
   }
903 853
 
904 854
   if (nr_rows != 1)
905 855
   {
906
-    pua_trace_int( "get_record_id_puadb", "TOO MANY MATCHES=", nr_rows, pres );
856
+    LM_ERR("Too many rows found (%d)\n", nr_rows);
907 857
     pua_dbf.free_result(pua_db, res);
908 858
     return(-1);
909 859
   }
... ...
@@ -940,7 +890,7 @@ int get_record_id_puadb(ua_pres_t *pres, str **rec_id )
940 890
   *rec_id= id;
941 891
   pua_dbf.free_result(pua_db, res);
942 892
 
943
-  pua_trace_string( "get_record_id_puadb", "FOUND id=", VAL_STRING(values+1), pres );
893
+  LM_DBG("Found id=%.*s\n", id->len, id->s);
944 894
   return(0);
945 895
 }
946 896
 
... ...
@@ -1022,11 +972,11 @@ int delete_temporary_dialog_puadb(ua_pres_t *pres )
1022 972
 
1023 973
   if ( rval < 0 ) 
1024 974
   {
1025
-    pua_trace( "delete_temporary_dialog_puad", "NOT FOUND", pres );
975
+    LM_DBG("No temporary dialog found and deleted\n");
1026 976
   }
1027 977
   else
1028 978
   {
1029
-    pua_trace( "delete_temporary_dialog_puad", "DONE", pres );
979
+    LM_DBG("Temporary dialog found and deleted\n");
1030 980
   }
1031 981
 
1032 982
   return(rval);
... ...
@@ -1133,11 +1083,11 @@ int delete_puadb(ua_pres_t *pres )
1133 1083
 
1134 1084
   if ( rval < 0 ) 
1135 1085
   {
1136
-    pua_trace( "delete_puad", "NOT FOUND", pres );
1086
+    LM_DBG("No dialog found and deleted\n");
1137 1087
   }
1138 1088
   else
1139 1089
   {
1140
-    pua_trace( "delete_puad", "DONE", pres );
1090
+    LM_DBG("Dialog found and deleted\n");
1141 1091
   }
1142 1092
 
1143 1093
   return(rval);
... ...
@@ -1228,11 +1178,10 @@ int update_contact_puadb(ua_pres_t *pres, str *contact)
1228 1178
   if(pua_dbf.update(pua_db, q_cols, q_ops, q_vals,
1229 1179
                     db_cols,db_vals,n_query_cols,n_update_cols) < 0)
1230 1180
   {
1231
-    pua_trace( "update_contact_puad", "FAILED", pres );
1181
+    LM_ERR("DB update failed\n");
1232 1182
     return(-1);
1233 1183
   }
1234 1184
   
1235
-  pua_trace( "update_contact_puad", "DONE", pres );
1236 1185
   return(0);
1237 1186
 }
1238 1187
 
... ...
@@ -1274,10 +1223,6 @@ int update_version_puadb(ua_pres_t *pres, int version )
1274 1223
     q_ops[watcher_col] = OP_EQ;
1275 1224
     n_query_cols++;
1276 1225
   }
1277
-  else
1278
-  {
1279
-    LM_ERR( "update_version_puadb has NULL watcher_uri\n" );
1280
-  }
1281 1226
 
1282 1227
   q_cols[callid_col= n_query_cols] = &str_call_id_col;	
1283 1228
   q_vals[callid_col].type = DB1_STR;
... ...
@@ -1307,6 +1252,7 @@ int update_version_puadb(ua_pres_t *pres, int version )
1307 1252
   /* we overwrite contact even if not changed */
1308 1253
   db_cols[n_update_cols] = &str_version_col;
1309 1254
   db_vals[n_update_cols].type = DB1_INT;
1255
+  db_vals[n_update_cols].nul = 0;
1310 1256
   db_vals[n_update_cols].val.int_val = version;
1311 1257
   n_update_cols++;
1312 1258
  
... ...
@@ -1321,11 +1267,10 @@ int update_version_puadb(ua_pres_t *pres, int version )
1321 1267
                     db_cols,db_vals,n_query_cols,n_update_cols) < 0)
1322 1268
   
1323 1269
   {
1324
-    pua_trace( "update_version_puad", "FAILED", pres );
1270
+    LM_ERR("DB update failed\n");
1325 1271
     return(-1);
1326 1272
   }
1327 1273
   
1328
-  pua_trace( "update_version_puad", "DONE", pres );
1329 1274
   return(0);
1330 1275
 }
1331 1276
 
... ...
@@ -1475,13 +1420,8 @@ void update_puadb(ua_pres_t* pres, time_t desired_expires,
1475 1420
   if(pua_dbf.update(pua_db, q_cols, q_ops, q_vals,
1476 1421
                     db_cols,db_vals,n_query_cols,n_update_cols) < 0)
1477 1422
   {
1478
-    pua_trace( "update_puad", "FAILED", pres );
1423
+    LM_ERR("DB update failed\n");
1479 1424
   }
1480
-  else
1481
-  {
1482
-    pua_trace( "update_puad", "DONE", pres );
1483
-  }	
1484
-
1485 1425
 }
1486 1426
 
1487 1427
 /******************************************************************************/
... ...
@@ -1561,16 +1501,23 @@ void insert_puadb(ua_pres_t* pres)
1561 1501
   n_cols++;
1562 1502
 
1563 1503
   /* subscribe */
1504
+  db_cols[n_cols] = &str_watcher_uri_col;
1505
+  db_vals[n_cols].type = DB1_STR;
1506
+  db_vals[n_cols].nul = 0; 
1507
+ 
1564 1508
   if (pres->watcher_uri)
1565 1509
   {
1566
-    db_cols[n_cols] = &str_watcher_uri_col;
1567
-    db_vals[n_cols].type = DB1_STR;
1568
-    db_vals[n_cols].nul = 0; 
1569 1510
     db_vals[n_cols].val.str_val.s = pres->watcher_uri->s;
1570 1511
     db_vals[n_cols].val.str_val.len = pres->watcher_uri->len;
1571
-    n_cols++;
1512
+  }
1513
+  else
1514
+  {
1515
+    db_vals[n_cols].val.str_val.s = "";
1516
+    db_vals[n_cols].val.str_val.len = 0;
1572 1517
   }
1573 1518
 
1519
+  n_cols++;
1520
+ 
1574 1521
   db_cols[n_cols] = &str_call_id_col;
1575 1522
   db_vals[n_cols].type = DB1_STR;
1576 1523
   db_vals[n_cols].nul = 0; 
... ...
@@ -1653,13 +1600,8 @@ void insert_puadb(ua_pres_t* pres)
1653 1600
 
1654 1601
   if(pua_dbf.insert(pua_db, db_cols, db_vals, n_cols) < 0)  
1655 1602
   {
1656
-    pua_trace( "insert_puad", "FAILED", pres );
1603
+    LM_ERR("DB insert failed\n");
1657 1604
   }
1658
-  else
1659
-  {
1660
-    pua_trace( "insert_puad", "DONE", pres );  
1661
-  }
1662
-  
1663 1605
 }
1664 1606
 
1665 1607
 /******************************************************************************/
... ...
@@ -675,6 +675,7 @@ int update_subs_rlsdb( subs_t *subs )
675 675
 	if ( r_remote_cseq >= subs->remote_cseq)
676 676
 	{
677 677
 		LM_DBG("stored cseq= %d\n", r_remote_cseq);
678
+		rls2_dbf.free_result(rls2_db, result);
678 679
 		return(401); /*stale cseq code */
679 680
 	}
680 681