Преглед на файлове

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 преди 10 години
родител
ревизия
035d2cb706

+ 5 - 3
modules/ims_registrar_scscf/save.c

@@ -298,8 +298,10 @@ static inline ucontact_info_t* pack_ci(struct sip_msg* _m, contact_t* _c, unsign
                 }
             }
         }
-
-        ci.last_modified = act_time;
+	
+	if(_c->params) {
+	    ci.params = _c->params;
+	}
 
         /* set flags */
         ci.flags = _f;
@@ -566,7 +568,7 @@ static inline int update_contacts_helper(struct sip_msg* msg, impurecord_t* impu
                                 "sos: [%d],"
                                 "expires [%ld]\n", chi->uri.len, chi->uri.s, qvalue, sos, expires - time(NULL));
 
-                        LM_DBG("packing contact information\n");
+			LM_DBG("packing contact information\n");
                         if ((ci = pack_ci(msg, chi, expires, 0)) == 0) {
                             LM_ERR("Failed to extract contact info\n");
                             goto error;

+ 49 - 4
modules/ims_usrloc_scscf/ucontact.c

@@ -80,6 +80,8 @@ extern struct contact_list* contact_list;
  */
 ucontact_t* new_ucontact(str* _dom, str* _aor, str* _contact, ucontact_info_t* _ci) {
     ucontact_t *c;
+    param_t *prev, *curr, *param;
+    int first = 1;
 
     c = (ucontact_t*) shm_malloc(sizeof (ucontact_t));
     if (!c) {
@@ -99,7 +101,29 @@ ucontact_t* new_ucontact(str* _dom, str* _aor, str* _contact, ucontact_info_t* _
     }
     c->cbs->first = 0;
     c->cbs->reg_types = 0;
-
+    
+    /*Copy parameter list into shm**/
+    param = _ci->params;
+    while(param) {
+	/*Copy first param in curr*/
+	curr = shm_malloc(sizeof (param_t));
+	curr->len = param->len;
+	curr->type = param->type;
+	curr->next = 0;
+	if (shm_str_dup(&curr->body, &param->body) < 0) goto error;
+	if (shm_str_dup(&curr->name, &param->name) < 0) goto error;
+	
+	if(first) {
+	    c->params = curr;
+	    first = 0;
+	} else {
+	    prev->next = curr;
+	}
+	prev = curr;
+	param = param->next;
+	
+    }
+    
     if (shm_str_dup(&c->c, _contact) < 0) goto error;
     if (shm_str_dup(&c->callid, _ci->callid) < 0) goto error;
     if (shm_str_dup(&c->user_agent, _ci->user_agent) < 0) goto error;
@@ -146,7 +170,8 @@ error:
 void free_ucontact(ucontact_t* _c) {
     struct ul_callback *cbp, *cbp_tmp;
     struct contact_dialog_data *dialog_data, *tmp_dialog_data; 
-
+    param_t * tmp, *tmp1;
+    
     if (!_c) return;
     LM_DBG("Freeing ucontact [%.*s]\n", _c->aor.len, _c->aor.s);    
     if (_c->path.s) shm_free(_c->path.s);
@@ -154,6 +179,16 @@ void free_ucontact(ucontact_t* _c) {
     if (_c->user_agent.s) shm_free(_c->user_agent.s);
     if (_c->callid.s) shm_free(_c->callid.s);
     if (_c->c.s) shm_free(_c->c.s);
+    
+    tmp = _c->params;
+    while(tmp){
+	tmp1 = tmp->next;
+	if (tmp->body.s) shm_free(tmp->body.s);
+	if (tmp->name.s) shm_free(tmp->name.s);
+	if(tmp) shm_free(tmp);
+	tmp = tmp1;
+    }
+    
     if (_c->domain.s) shm_free(_c->domain.s);
     if (_c->aor.s) shm_free(_c->aor.s);
 
@@ -186,11 +221,21 @@ void free_ucontact(ucontact_t* _c) {
 void print_ucontact(FILE* _f, ucontact_t* _c) {
     time_t t = time(0);
     char* st = "";
-
+    param_t * tmp;
+    
     fprintf(_f, "~~~Contact(%p)~~~\n", _c);
     fprintf(_f, "domain    : '%.*s'\n", _c->domain.len, ZSW(_c->domain.s));
     fprintf(_f, "aor       : '%.*s'\n", _c->aor.len, ZSW(_c->aor.s));
     fprintf(_f, "Contact   : '%.*s'\n", _c->c.len, ZSW(_c->c.s));
+    
+    fprintf(_f, "Params   :\n");
+    tmp = _c->params;
+    while (tmp) {
+	fprintf(_f, "Param Name: '%.*s' Param Body '%.*s'\n", tmp->name.len, ZSW(tmp->name.s), tmp->body.len, ZSW(tmp->body.s));
+	tmp = tmp->next;
+    }
+    
+    
     fprintf(_f, "Expires   : ");
     if (_c->expires == 0) {
         fprintf(_f, "Permanent\n");
@@ -270,7 +315,7 @@ int mem_update_ucontact(ucontact_t* _c, ucontact_info_t* _ci) {
         _c->path.s = 0;
         _c->path.len = 0;
     }
-
+    
     LM_DBG("Setting contact expires to %d which is in %d seconds time\n", (unsigned int) _ci->expires, (unsigned int) (_ci->expires - time(NULL)));
     _c->sock = _ci->sock;
     _c->expires = _ci->expires;

+ 2 - 0
modules/ims_usrloc_scscf/usrloc.h

@@ -301,6 +301,7 @@ typedef struct ucontact {
     str domain; /*!< Pointer to domain name (NULL terminated) */
     str aor; /*!< Pointer to the AOR string in record structure*/
     str c; /*!< Contact address */
+    param_t *params; /*!< Params header details> */
     str received; /*!< IP+port+protocol we received the REGISTER from */
     str path; /*!< Path header */
     time_t expires; /*!< Expires parameter */
@@ -336,6 +337,7 @@ typedef struct ucontact_info {
     time_t expires; /*!< Contact expires */
     qvalue_t q; /*!< Q-value */
     str* callid; /*!< call-ID */
+    param_t *params;
     int cseq; /*!< CSEQ number */
     unsigned int flags; /*!< message flags */
     unsigned int cflags; /*!< contact flags */

+ 72 - 28
modules/ims_usrloc_scscf/usrloc_db.c

@@ -5,6 +5,7 @@
 #include "udomain.h"
 #include "math.h"
 #include "subscribe.h"
+#include "../../lib/ims/useful_defs.h"
 
 str id_col = str_init(ID_COL); /*!< Name of column containing ID (gen. auto_increment field */
 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 */
 str ecf2_col = str_init(ECF2_COL); /*!< Name of column containing ecf2 */
 str ims_sub_data_col = str_init(IMS_SUB_COL); /*!< Name of column containing ims_subscription data */
 str contact_col = str_init(CONTACT_COL); /*!< Name of column containing contact addresses */
+str params_col = str_init(PARAMS_COL); /*!< Name of column containing contact addresses */
 str expires_col = str_init(EXPIRES_COL); /*!< Name of column containing expires values */
 str q_col = str_init(Q_COL); /*!< Name of column containing q values */
 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) {
 	return 0;
 }
 
+static int MAX_PARAMS_SIZE = 1000;
+static str param_name_and_nody = {"%.*s=%.*s;", 1};
+static str param_name_no_body = {"%.*s;", 1};
+
 int db_insert_ucontact(impurecord_t* _r, ucontact_t* _c) {
-	db_key_t key[6];
-	db_val_t val[6];
+	
+	str param_buf, param_pad;
+	param_t * tmp;
+	char param_bufc[MAX_PARAMS_SIZE], param_padc[MAX_PARAMS_SIZE];
+	param_buf.s = param_bufc;
+	param_buf.len = 0;
+	param_pad.s = param_padc;
+	param_pad.len = 0;
+	
+	db_key_t key[7];
+	db_val_t val[7];
 	
 	LM_DBG("DB: inserting ucontact [%.*s]\n", _c->c.len, _c->c.s);
+	
+	tmp = _c->params;
+	while (tmp) {
+	    if(tmp->body.len > 0) {
+		sprintf(param_pad.s, param_name_and_nody.s, tmp->name.len, tmp->name.s, tmp->body.len, tmp->body.s);
+	    } else {
+		sprintf(param_pad.s, param_name_no_body.s, tmp->name.len, tmp->name.s);
+	    }
+	    param_pad.len = strlen(param_pad.s);
+	    STR_APPEND(param_buf, param_pad);
+	    tmp = tmp->next;
+	}
+	LM_DBG("Converted params to string to insert into db: [%.*s]\n", param_buf.len, param_buf.s);
+	
 
 	key[0] = &contact_col;
-	key[1] = &path_col;
-	key[2] = &user_agent_col;
-	key[3] = &received_col;
-	key[4] = &expires_col;
-	key[5] = &callid_col;
+	key[1] = &params_col;
+	key[2] = &path_col;
+	key[3] = &user_agent_col;
+	key[4] = &received_col;
+	key[5] = &expires_col;
+	key[6] = &callid_col;
 
 	val[0].type = DB1_STR;
 	val[0].nul = 0;
@@ -276,29 +306,33 @@ int db_insert_ucontact(impurecord_t* _r, ucontact_t* _c) {
 
 	val[1].type = DB1_STR;
 	val[1].nul = 0;
-	val[1].val.str_val = _c->path;
-
+	val[1].val.str_val = param_buf;
+	
 	val[2].type = DB1_STR;
 	val[2].nul = 0;
-	val[2].val.str_val = _c->user_agent;
+	val[2].val.str_val = _c->path;
 
 	val[3].type = DB1_STR;
 	val[3].nul = 0;
-	val[3].val.str_val = _c->received;
+	val[3].val.str_val = _c->user_agent;
 
-	val[4].type = DB1_DATETIME;
+	val[4].type = DB1_STR;
 	val[4].nul = 0;
-	val[4].val.time_val = _c->expires;
+	val[4].val.str_val = _c->received;
 
-	val[5].type = DB1_STR;
+	val[5].type = DB1_DATETIME;
 	val[5].nul = 0;
-	val[5].val.str_val = _c->callid;
+	val[5].val.time_val = _c->expires;
+
+	val[6].type = DB1_STR;
+	val[6].nul = 0;
+	val[6].val.str_val = _c->callid;
 
 	if (ul_dbf.use_table(ul_dbh, &contact_table) != 0) {
 		LM_ERR("Unable to use table [%.*s]\n", contact_table.len, contact_table.s);
 		return -1;
 	}
-	if (ul_dbf.insert_update(ul_dbh, key, val, 6) != 0) {
+	if (ul_dbf.insert_update(ul_dbh, key, val, 7) != 0) {
 		LM_ERR("Failed to insert/update contact record for [%.*s]\n", _c->c.len, _c->c.s);
 		return -1;
 	}
@@ -473,35 +507,45 @@ int inline int_to_str_len(int i) {
 }
 
 static inline int dbrow2contact(db_val_t* val, ucontact_info_t* ci) {
-	static str path, user_agent, callid;
+	static str params, path, user_agent, callid;
 
+	
+	//TODO FIX PARAMS
+//	/* params */
+//	if (!VAL_NULL(val + 1)) {
+//		params.s = (char*)VAL_STRING(val + 1);
+//		params.len = strlen(params.s);
+//	}
+//	ci->params = &params;
+//	LM_DBG("Loading contact params: [%.*s]", ci->params->len, ci->params->s);
+	
 	/* path */
-	if (!VAL_NULL(val + 1)) {
-		path.s = (char*)VAL_STRING(val + 1);
+	if (!VAL_NULL(val + 2)) {
+		path.s = (char*)VAL_STRING(val + 2);
 		path.len = strlen(path.s);
 	}
 	ci->path = &path;
 
 	/* user-agent */
-	if (!VAL_NULL(val + 2)) {
-		user_agent.s = (char*)VAL_STRING(val + 2);
+	if (!VAL_NULL(val + 3)) {
+		user_agent.s = (char*)VAL_STRING(val + 3);
 		user_agent.len = strlen(user_agent.s);
 	}
 	ci->user_agent = &user_agent;
 
 	/* received */
-	if (!VAL_NULL(val + 3)) {
-		ci->received.s = (char*)VAL_STRING(val + 3);
+	if (!VAL_NULL(val + 4)) {
+		ci->received.s = (char*)VAL_STRING(val + 4);
 		ci->received.len = strlen(ci->received.s);
 	}
 
 	/* expires */
-	if (!VAL_NULL(val + 4)) {
-		ci->expires = VAL_TIME(val + 4);
+	if (!VAL_NULL(val + 5)) {
+		ci->expires = VAL_TIME(val + 5);
 	}
 	/* callid */
-	if (!VAL_NULL(val + 5)) {
-		callid.s = (char*) VAL_STRING(val + 5);
+	if (!VAL_NULL(val + 6)) {
+		callid.s = (char*) VAL_STRING(val + 6);
 		callid.len = strlen(callid.s);
 	}
 	ci->callid = &callid;
@@ -634,7 +678,7 @@ int preload_udomain(db1_con_t* _c, udomain_t* _d) {
      */
 
     char *p_contact =
-	    "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=";
+	    "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=";
 
     char *p_subscriber =
 	    "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,"

+ 1 - 0
modules/ims_usrloc_scscf/usrloc_db.h

@@ -11,6 +11,7 @@ extern db_func_t ul_dbf;
 #define USER_COL       "username"
 #define DOMAIN_COL     "domain"
 #define CONTACT_COL    "contact"
+#define PARAMS_COL    "params"
 #define EXPIRES_COL    "expires"
 #define Q_COL          "q"
 #define CALLID_COL     "callid"