Browse code

usrloc: generate callid at startup and increase cseq for records added via mi

- should fix FS#448, reported by Savolainen Dmitri

(cherry picked from commit 66c497fdf4ac1c3b889a7c3b50c3e5fed770cf0b)

Daniel-Constantin Mierla authored on 04/07/2014 11:46:35
Showing 1 changed files
... ...
@@ -48,9 +48,9 @@
48 48
 #include "usrloc.h"
49 49
 
50 50
 /*! CSEQ nr used */
51
-#define MI_UL_CSEQ 1
51
+static int MI_UL_CSEQ = 0;
52 52
 /*! call-id used for ul_add and ul_rm_contact */
53
-static str mi_ul_cid = str_init("dfjrewr12386fd6-343@kamailio.mi");
53
+static str mi_ul_cid = {0,0}; /* str_init("dfjrewr12386fd6-343@kamailio.mi");*/
54 54
 /*! user agent used for ul_add */
55 55
 static str mi_ul_ua  = str_init("SIP Router MI Server");
56 56
 /*! path used for ul_add and ul_rm_contact */
... ...
@@ -58,8 +58,27 @@ static str mi_ul_path = str_init("dummypath");
58 58
 
59 59
 extern sruid_t _ul_sruid;
60 60
 
61
+static char mi_ul_cid_buf[32];
62
+
61 63
 /************************ helper functions ****************************/
62 64
 
65
+static void set_mi_ul_cid(void)
66
+{
67
+	int i;
68
+    char charset[] = "0123456789"
69
+                     "abcdefghijklmnopqrstuvwxyz"
70
+                     "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
71
+
72
+	if(mi_ul_cid.s!=NULL) return;
73
+
74
+	for(i=0; i<19; i++) {
75
+        mi_ul_cid_buf[i] = charset[rand()%(sizeof(charset) - 1)];
76
+    }
77
+    memcpy(mi_ul_cid_buf+i, "@kamailio.mi", sizeof("@kamailio.mi"));
78
+    mi_ul_cid.s = mi_ul_cid_buf;
79
+	mi_ul_cid.len = strlen(mi_ul_cid.s);
80
+}
81
+
63 82
 /*!
64 83
  * \brief Search a domain in the global domain list
65 84
  * \param table domain (table) name
... ...
@@ -360,6 +379,7 @@ struct mi_root* mi_usrloc_rm_contact(struct mi_root *cmd, void *param)
360 379
 	}
361 380
 
362 381
 	contact = &node->next->next->value;
382
+	set_mi_ul_cid();
363 383
 	ret = get_ucontact( rec, contact, &mi_ul_cid, &mi_ul_path, MI_UL_CSEQ+1, &con);
364 384
 	if (ret < 0) {
365 385
 		unlock_udomain( dom, aor);
... ...
@@ -566,6 +586,7 @@ struct mi_root* mi_usrloc_add(struct mi_root *cmd, void *param)
566 586
 
567 587
 	lock_udomain( dom, aor);
568 588
 
589
+	set_mi_ul_cid();
569 590
 	n = get_urecord( dom, aor, &r);
570 591
 	if ( n==1) {
571 592
 		if (insert_urecord( dom, aor, &r) < 0)
... ...
@@ -580,7 +601,7 @@ struct mi_root* mi_usrloc_add(struct mi_root *cmd, void *param)
580 601
 
581 602
 	ci.callid = &mi_ul_cid;
582 603
 	ci.user_agent = &mi_ul_ua;
583
-	ci.cseq = MI_UL_CSEQ;
604
+	ci.cseq = ++MI_UL_CSEQ;
584 605
 	/* 0 expires means permanent contact */
585 606
 	if (ci.expires!=0)
586 607
 		ci.expires += act_time;