Browse code

modules/ims_registrar_scscf ims_usrloc_s: store contact params on registration ims_registrar_scscf: pass params if they exist when saving contact ims_usrloc_scscf: store params in usrloc and persist to db

Richard Good authored on 13/11/2014 07:53:12
Showing 5 changed files
... ...
@@ -298,8 +298,10 @@ static inline ucontact_info_t* pack_ci(struct sip_msg* _m, contact_t* _c, unsign
298 298
                 }
299 299
             }
300 300
         }
301
-
302
-        ci.last_modified = act_time;
301
+	
302
+	if(_c->params) {
303
+	    ci.params = _c->params;
304
+	}
303 305
 
304 306
         /* set flags */
305 307
         ci.flags = _f;
... ...
@@ -566,7 +568,7 @@ static inline int update_contacts_helper(struct sip_msg* msg, impurecord_t* impu
566 568
                                 "sos: [%d],"
567 569
                                 "expires [%ld]\n", chi->uri.len, chi->uri.s, qvalue, sos, expires - time(NULL));
568 570
 
569
-                        LM_DBG("packing contact information\n");
571
+			LM_DBG("packing contact information\n");
570 572
                         if ((ci = pack_ci(msg, chi, expires, 0)) == 0) {
571 573
                             LM_ERR("Failed to extract contact info\n");
572 574
                             goto error;
... ...
@@ -80,6 +80,8 @@ extern struct contact_list* contact_list;
80 80
  */
81 81
 ucontact_t* new_ucontact(str* _dom, str* _aor, str* _contact, ucontact_info_t* _ci) {
82 82
     ucontact_t *c;
83
+    param_t *prev, *curr, *param;
84
+    int first = 1;
83 85
 
84 86
     c = (ucontact_t*) shm_malloc(sizeof (ucontact_t));
85 87
     if (!c) {
... ...
@@ -99,7 +101,29 @@ ucontact_t* new_ucontact(str* _dom, str* _aor, str* _contact, ucontact_info_t* _
99 101
     }
100 102
     c->cbs->first = 0;
101 103
     c->cbs->reg_types = 0;
102
-
104
+    
105
+    /*Copy parameter list into shm**/
106
+    param = _ci->params;
107
+    while(param) {
108
+	/*Copy first param in curr*/
109
+	curr = shm_malloc(sizeof (param_t));
110
+	curr->len = param->len;
111
+	curr->type = param->type;
112
+	curr->next = 0;
113
+	if (shm_str_dup(&curr->body, &param->body) < 0) goto error;
114
+	if (shm_str_dup(&curr->name, &param->name) < 0) goto error;
115
+	
116
+	if(first) {
117
+	    c->params = curr;
118
+	    first = 0;
119
+	} else {
120
+	    prev->next = curr;
121
+	}
122
+	prev = curr;
123
+	param = param->next;
124
+	
125
+    }
126
+    
103 127
     if (shm_str_dup(&c->c, _contact) < 0) goto error;
104 128
     if (shm_str_dup(&c->callid, _ci->callid) < 0) goto error;
105 129
     if (shm_str_dup(&c->user_agent, _ci->user_agent) < 0) goto error;
... ...
@@ -146,7 +170,8 @@ error:
146 170
 void free_ucontact(ucontact_t* _c) {
147 171
     struct ul_callback *cbp, *cbp_tmp;
148 172
     struct contact_dialog_data *dialog_data, *tmp_dialog_data; 
149
-
173
+    param_t * tmp, *tmp1;
174
+    
150 175
     if (!_c) return;
151 176
     LM_DBG("Freeing ucontact [%.*s]\n", _c->aor.len, _c->aor.s);    
152 177
     if (_c->path.s) shm_free(_c->path.s);
... ...
@@ -154,6 +179,16 @@ void free_ucontact(ucontact_t* _c) {
154 179
     if (_c->user_agent.s) shm_free(_c->user_agent.s);
155 180
     if (_c->callid.s) shm_free(_c->callid.s);
156 181
     if (_c->c.s) shm_free(_c->c.s);
182
+    
183
+    tmp = _c->params;
184
+    while(tmp){
185
+	tmp1 = tmp->next;
186
+	if (tmp->body.s) shm_free(tmp->body.s);
187
+	if (tmp->name.s) shm_free(tmp->name.s);
188
+	if(tmp) shm_free(tmp);
189
+	tmp = tmp1;
190
+    }
191
+    
157 192
     if (_c->domain.s) shm_free(_c->domain.s);
158 193
     if (_c->aor.s) shm_free(_c->aor.s);
159 194
 
... ...
@@ -186,11 +221,21 @@ void free_ucontact(ucontact_t* _c) {
186 221
 void print_ucontact(FILE* _f, ucontact_t* _c) {
187 222
     time_t t = time(0);
188 223
     char* st = "";
189
-
224
+    param_t * tmp;
225
+    
190 226
     fprintf(_f, "~~~Contact(%p)~~~\n", _c);
191 227
     fprintf(_f, "domain    : '%.*s'\n", _c->domain.len, ZSW(_c->domain.s));
192 228
     fprintf(_f, "aor       : '%.*s'\n", _c->aor.len, ZSW(_c->aor.s));
193 229
     fprintf(_f, "Contact   : '%.*s'\n", _c->c.len, ZSW(_c->c.s));
230
+    
231
+    fprintf(_f, "Params   :\n");
232
+    tmp = _c->params;
233
+    while (tmp) {
234
+	fprintf(_f, "Param Name: '%.*s' Param Body '%.*s'\n", tmp->name.len, ZSW(tmp->name.s), tmp->body.len, ZSW(tmp->body.s));
235
+	tmp = tmp->next;
236
+    }
237
+    
238
+    
194 239
     fprintf(_f, "Expires   : ");
195 240
     if (_c->expires == 0) {
196 241
         fprintf(_f, "Permanent\n");
... ...
@@ -270,7 +315,7 @@ int mem_update_ucontact(ucontact_t* _c, ucontact_info_t* _ci) {
270 315
         _c->path.s = 0;
271 316
         _c->path.len = 0;
272 317
     }
273
-
318
+    
274 319
     LM_DBG("Setting contact expires to %d which is in %d seconds time\n", (unsigned int) _ci->expires, (unsigned int) (_ci->expires - time(NULL)));
275 320
     _c->sock = _ci->sock;
276 321
     _c->expires = _ci->expires;
... ...
@@ -301,6 +301,7 @@ typedef struct ucontact {
301 301
     str domain; /*!< Pointer to domain name (NULL terminated) */
302 302
     str aor; /*!< Pointer to the AOR string in record structure*/
303 303
     str c; /*!< Contact address */
304
+    param_t *params; /*!< Params header details> */
304 305
     str received; /*!< IP+port+protocol we received the REGISTER from */
305 306
     str path; /*!< Path header */
306 307
     time_t expires; /*!< Expires parameter */
... ...
@@ -336,6 +337,7 @@ typedef struct ucontact_info {
336 337
     time_t expires; /*!< Contact expires */
337 338
     qvalue_t q; /*!< Q-value */
338 339
     str* callid; /*!< call-ID */
340
+    param_t *params;
339 341
     int cseq; /*!< CSEQ number */
340 342
     unsigned int flags; /*!< message flags */
341 343
     unsigned int cflags; /*!< contact flags */
... ...
@@ -5,6 +5,7 @@
5 5
 #include "udomain.h"
6 6
 #include "math.h"
7 7
 #include "subscribe.h"
8
+#include "../../lib/ims/useful_defs.h"
8 9
 
9 10
 str id_col = str_init(ID_COL); /*!< Name of column containing ID (gen. auto_increment field */
10 11
 str impu_id_col = str_init(IMPU_ID_COL); /*!< Name of column containing impu ID in mapping table */
... ...
@@ -18,6 +19,7 @@ str ecf1_col = str_init(ECF1_COL); /*!< Name of column containing ecf1 */
18 19
 str ecf2_col = str_init(ECF2_COL); /*!< Name of column containing ecf2 */
19 20
 str ims_sub_data_col = str_init(IMS_SUB_COL); /*!< Name of column containing ims_subscription data */
20 21
 str contact_col = str_init(CONTACT_COL); /*!< Name of column containing contact addresses */
22
+str params_col = str_init(PARAMS_COL); /*!< Name of column containing contact addresses */
21 23
 str expires_col = str_init(EXPIRES_COL); /*!< Name of column containing expires values */
22 24
 str q_col = str_init(Q_COL); /*!< Name of column containing q values */
23 25
 str callid_col = str_init(CALLID_COL); /*!< Name of column containing callid string */
... ...
@@ -257,18 +259,46 @@ int db_delete_impurecord(udomain_t* _d, struct impurecord* _r) {
257 259
 	return 0;
258 260
 }
259 261
 
262
+static int MAX_PARAMS_SIZE = 1000;
263
+static str param_name_and_nody = {"%.*s=%.*s;", 1};
264
+static str param_name_no_body = {"%.*s;", 1};
265
+
260 266
 int db_insert_ucontact(impurecord_t* _r, ucontact_t* _c) {
261
-	db_key_t key[6];
262
-	db_val_t val[6];
267
+	
268
+	str param_buf, param_pad;
269
+	param_t * tmp;
270
+	char param_bufc[MAX_PARAMS_SIZE], param_padc[MAX_PARAMS_SIZE];
271
+	param_buf.s = param_bufc;
272
+	param_buf.len = 0;
273
+	param_pad.s = param_padc;
274
+	param_pad.len = 0;
275
+	
276
+	db_key_t key[7];
277
+	db_val_t val[7];
263 278
 	
264 279
 	LM_DBG("DB: inserting ucontact [%.*s]\n", _c->c.len, _c->c.s);
280
+	
281
+	tmp = _c->params;
282
+	while (tmp) {
283
+	    if(tmp->body.len > 0) {
284
+		sprintf(param_pad.s, param_name_and_nody.s, tmp->name.len, tmp->name.s, tmp->body.len, tmp->body.s);
285
+	    } else {
286
+		sprintf(param_pad.s, param_name_no_body.s, tmp->name.len, tmp->name.s);
287
+	    }
288
+	    param_pad.len = strlen(param_pad.s);
289
+	    STR_APPEND(param_buf, param_pad);
290
+	    tmp = tmp->next;
291
+	}
292
+	LM_DBG("Converted params to string to insert into db: [%.*s]\n", param_buf.len, param_buf.s);
293
+	
265 294
 
266 295
 	key[0] = &contact_col;
267
-	key[1] = &path_col;
268
-	key[2] = &user_agent_col;
269
-	key[3] = &received_col;
270
-	key[4] = &expires_col;
271
-	key[5] = &callid_col;
296
+	key[1] = &params_col;
297
+	key[2] = &path_col;
298
+	key[3] = &user_agent_col;
299
+	key[4] = &received_col;
300
+	key[5] = &expires_col;
301
+	key[6] = &callid_col;
272 302
 
273 303
 	val[0].type = DB1_STR;
274 304
 	val[0].nul = 0;
... ...
@@ -276,29 +306,33 @@ int db_insert_ucontact(impurecord_t* _r, ucontact_t* _c) {
276 306
 
277 307
 	val[1].type = DB1_STR;
278 308
 	val[1].nul = 0;
279
-	val[1].val.str_val = _c->path;
280
-
309
+	val[1].val.str_val = param_buf;
310
+	
281 311
 	val[2].type = DB1_STR;
282 312
 	val[2].nul = 0;
283
-	val[2].val.str_val = _c->user_agent;
313
+	val[2].val.str_val = _c->path;
284 314
 
285 315
 	val[3].type = DB1_STR;
286 316
 	val[3].nul = 0;
287
-	val[3].val.str_val = _c->received;
317
+	val[3].val.str_val = _c->user_agent;
288 318
 
289
-	val[4].type = DB1_DATETIME;
319
+	val[4].type = DB1_STR;
290 320
 	val[4].nul = 0;
291
-	val[4].val.time_val = _c->expires;
321
+	val[4].val.str_val = _c->received;
292 322
 
293
-	val[5].type = DB1_STR;
323
+	val[5].type = DB1_DATETIME;
294 324
 	val[5].nul = 0;
295
-	val[5].val.str_val = _c->callid;
325
+	val[5].val.time_val = _c->expires;
326
+
327
+	val[6].type = DB1_STR;
328
+	val[6].nul = 0;
329
+	val[6].val.str_val = _c->callid;
296 330
 
297 331
 	if (ul_dbf.use_table(ul_dbh, &contact_table) != 0) {
298 332
 		LM_ERR("Unable to use table [%.*s]\n", contact_table.len, contact_table.s);
299 333
 		return -1;
300 334
 	}
301
-	if (ul_dbf.insert_update(ul_dbh, key, val, 6) != 0) {
335
+	if (ul_dbf.insert_update(ul_dbh, key, val, 7) != 0) {
302 336
 		LM_ERR("Failed to insert/update contact record for [%.*s]\n", _c->c.len, _c->c.s);
303 337
 		return -1;
304 338
 	}
... ...
@@ -473,35 +507,45 @@ int inline int_to_str_len(int i) {
473 507
 }
474 508
 
475 509
 static inline int dbrow2contact(db_val_t* val, ucontact_info_t* ci) {
476
-	static str path, user_agent, callid;
510
+	static str params, path, user_agent, callid;
477 511
 
512
+	
513
+	//TODO FIX PARAMS
514
+//	/* params */
515
+//	if (!VAL_NULL(val + 1)) {
516
+//		params.s = (char*)VAL_STRING(val + 1);
517
+//		params.len = strlen(params.s);
518
+//	}
519
+//	ci->params = &params;
520
+//	LM_DBG("Loading contact params: [%.*s]", ci->params->len, ci->params->s);
521
+	
478 522
 	/* path */
479
-	if (!VAL_NULL(val + 1)) {
480
-		path.s = (char*)VAL_STRING(val + 1);
523
+	if (!VAL_NULL(val + 2)) {
524
+		path.s = (char*)VAL_STRING(val + 2);
481 525
 		path.len = strlen(path.s);
482 526
 	}
483 527
 	ci->path = &path;
484 528
 
485 529
 	/* user-agent */
486
-	if (!VAL_NULL(val + 2)) {
487
-		user_agent.s = (char*)VAL_STRING(val + 2);
530
+	if (!VAL_NULL(val + 3)) {
531
+		user_agent.s = (char*)VAL_STRING(val + 3);
488 532
 		user_agent.len = strlen(user_agent.s);
489 533
 	}
490 534
 	ci->user_agent = &user_agent;
491 535
 
492 536
 	/* received */
493
-	if (!VAL_NULL(val + 3)) {
494
-		ci->received.s = (char*)VAL_STRING(val + 3);
537
+	if (!VAL_NULL(val + 4)) {
538
+		ci->received.s = (char*)VAL_STRING(val + 4);
495 539
 		ci->received.len = strlen(ci->received.s);
496 540
 	}
497 541
 
498 542
 	/* expires */
499
-	if (!VAL_NULL(val + 4)) {
500
-		ci->expires = VAL_TIME(val + 4);
543
+	if (!VAL_NULL(val + 5)) {
544
+		ci->expires = VAL_TIME(val + 5);
501 545
 	}
502 546
 	/* callid */
503
-	if (!VAL_NULL(val + 5)) {
504
-		callid.s = (char*) VAL_STRING(val + 5);
547
+	if (!VAL_NULL(val + 6)) {
548
+		callid.s = (char*) VAL_STRING(val + 6);
505 549
 		callid.len = strlen(callid.s);
506 550
 	}
507 551
 	ci->callid = &callid;
... ...
@@ -634,7 +678,7 @@ int preload_udomain(db1_con_t* _c, udomain_t* _d) {
634 678
      */
635 679
 
636 680
     char *p_contact =
637
-	    "SELECT c.contact,c.path,c.user_agent,c.received,c.expires,c.callid FROM impu_contact m LEFT JOIN contact c ON c.id=m.contact_id WHERE m.impu_id=";
681
+	    "SELECT c.contact,c.params,c.path,c.user_agent,c.received,c.expires,c.callid FROM impu_contact m LEFT JOIN contact c ON c.id=m.contact_id WHERE m.impu_id=";
638 682
 
639 683
     char *p_subscriber =
640 684
 	    "SELECT s.presentity_uri,s.watcher_uri,s.watcher_contact,s.event,s.expires,s.version,s.local_cseq,s.call_id,s.from_tag,"
... ...
@@ -11,6 +11,7 @@ extern db_func_t ul_dbf;
11 11
 #define USER_COL       "username"
12 12
 #define DOMAIN_COL     "domain"
13 13
 #define CONTACT_COL    "contact"
14
+#define PARAMS_COL    "params"
14 15
 #define EXPIRES_COL    "expires"
15 16
 #define Q_COL          "q"
16 17
 #define CALLID_COL     "callid"