Prechádzať zdrojové kódy

sca: fix sca_call_info_update() [to|from] optional parameters

* use str values
* need to build struct to_body and free memory afterwards
Victor Seva 9 rokov pred
rodič
commit
e638326f62

+ 20 - 2
modules/sca/sca.c

@@ -425,12 +425,30 @@ static int sca_call_info_update_1_f(sip_msg_t* msg, char* p1) {
 	return sca_call_info_update(msg, p1, NULL, NULL);
 }
 static int sca_call_info_update_2_f(sip_msg_t* msg, char* p1, char* p2) {
-	return sca_call_info_update(msg, p1, p2, NULL);
+	str uri_to = STR_NULL;
+	if(get_str_fparam(&uri_to, msg, (gparam_p)p2)!=0)
+	{
+		LM_ERR("unable to get value from param pvar_to\n");
+		return -1;
+	}
+	return sca_call_info_update(msg, p1, &uri_to, NULL);
 }
 static int sca_call_info_update_3_f(sip_msg_t* msg,
 	char* p1, char* p2, char * p3)
 {
-	return sca_call_info_update(msg, p1, p2, p3);
+	str uri_to = STR_NULL;
+	str uri_from = STR_NULL;
+	if(get_str_fparam(&uri_to, msg, (gparam_p)p2)!=0)
+	{
+		LM_ERR("unable to get value from param pvar_to\n");
+		return -1;
+	}
+	if(get_str_fparam(&uri_from, msg, (gparam_p)p3)!=0)
+	{
+		LM_ERR("unable to get value from param pvar_from\n");
+		return -1;
+	}
+	return sca_call_info_update(msg, p1, &uri_to, &uri_from);
 }
 
 int fixup_ciu(void **param, int param_no)

+ 45 - 19
modules/sca/sca_call_info.c

@@ -1816,7 +1816,7 @@ struct sca_call_info_dispatch call_info_dispatch[] = {
 #define SCA_CALL_INFO_UPDATE_FLAG_FROM_ALLOC	(1 << 0)
 #define SCA_CALL_INFO_UPDATE_FLAG_TO_ALLOC	(1 << 1)
 
-int sca_call_info_update(sip_msg_t *msg, char *p1, char *p2, char *p3)
+int sca_call_info_update(sip_msg_t *msg, char *p1, str *uri_to, str *uri_from)
 {
 	sca_call_info call_info;
 	hdr_field_t *call_info_hdr;
@@ -1827,6 +1827,7 @@ int sca_call_info_update(sip_msg_t *msg, char *p1, char *p2, char *p3)
 	str to_aor = STR_NULL;
 	str contact_uri = STR_NULL;
 	int aor_flags = SCA_CALL_INFO_UPDATE_FLAG_DEFAULT;
+	int to_body_flags = SCA_CALL_INFO_UPDATE_FLAG_DEFAULT;
 	int n_dispatch;
 	int i;
 	int method;
@@ -1892,25 +1893,33 @@ int sca_call_info_update(sip_msg_t *msg, char *p1, char *p2, char *p3)
 		}
 	}
 
-	if (p3 != NULL) {
-		if (sca_get_pv_from_header(msg, &from, (pv_spec_t *) p3) < 0) {
-			LM_ERR("Bad From pvar\n");
+	if (uri_from != NULL) {
+		if(sca_build_to_body_from_uri(msg, &from, uri_from)<0){
+			LM_ERR("Bad From uri from param\n");
 			return (-1);
 		}
+		LM_DBG("from[%.*s] param\n", STR_FMT(uri_from));
+		to_body_flags |= SCA_CALL_INFO_UPDATE_FLAG_FROM_ALLOC;
+		from_aor.s = uri_from->s;
+		from_aor.len = uri_from->len;
 	}
 	else if (sca_get_msg_from_header(msg, &from) < 0) {
 		LM_ERR("Bad From header\n");
 		return (-1);
 	}
-	if (p2 != NULL) {
-		if (sca_get_pv_to_header(msg, &to, (pv_spec_t *) p2) < 0) {
-			LM_ERR("Bad To pvar\n");
-			return (-1);
+	if (uri_to != NULL) {
+		if(sca_build_to_body_from_uri(msg, &to, uri_to)<0){
+			LM_ERR("Bad From uri to param\n");
+			goto done;
 		}
+		LM_DBG("to[%.*s] param\n", STR_FMT(uri_to));
+		to_body_flags |= SCA_CALL_INFO_UPDATE_FLAG_TO_ALLOC;
+		to_aor.s = uri_to->s;
+		to_aor.len = uri_to->len;
 	}
 	else if (sca_get_msg_to_header(msg, &to) < 0) {
 		LM_ERR("Bad To header\n");
-		return (-1);
+		goto done;
 	}
 
 	memset(&c_uri, 0, sizeof(sip_uri_t));
@@ -1920,22 +1929,24 @@ int sca_call_info_update(sip_msg_t *msg, char *p1, char *p2, char *p3)
 		if (parse_uri(contact_uri.s, contact_uri.len, &c_uri) < 0) {
 			LM_ERR("Failed to parse Contact URI %.*s\n",
 					STR_FMT(&contact_uri));
-			return (-1);
+			rc = -1;
+			goto done;
 		}
 	} else if (rc < 0) {
 		LM_ERR("Bad Contact\n");
-		return (-1);
+		goto done;
 	}
 	// reset rc to -1 so we don't end up returning 0 to the script
 	rc = -1;
 
 	// reconcile mismatched Contact users and To/From URIs
 	if (msg->first_line.type == SIP_REQUEST) {
-		if (sca_create_canonical_aor(msg, &from_aor) < 0) {
-			return (-1);
+		if (uri_from==NULL) {
+			if (sca_create_canonical_aor(msg, &from_aor) < 0) {
+				goto done;
+			}
+			aor_flags |= SCA_CALL_INFO_UPDATE_FLAG_FROM_ALLOC;
 		}
-		aor_flags |= SCA_CALL_INFO_UPDATE_FLAG_FROM_ALLOC;
-
 		if (sca_uri_extract_aor(&to->uri, &to_aor) < 0) {
 			LM_ERR("Failed to extract AoR from To URI %.*s\n",
 					STR_FMT(&to->uri));
@@ -1947,12 +1958,17 @@ int sca_call_info_update(sip_msg_t *msg, char *p1, char *p2, char *p3)
 					STR_FMT(&from->uri));
 			goto done;
 		}
-		if (sca_create_canonical_aor(msg, &to_aor) < 0) {
-			return (-1);
+		if (uri_to==NULL) {
+			if (sca_create_canonical_aor(msg, &to_aor) < 0) {
+				goto done;
+			}
+			aor_flags |= SCA_CALL_INFO_UPDATE_FLAG_TO_ALLOC;
 		}
-		aor_flags |= SCA_CALL_INFO_UPDATE_FLAG_TO_ALLOC;
 	}
 
+	LM_DBG("to_aor[%.*s] from_aor[%.*s]\n",
+		STR_FMT(&to_aor), STR_FMT(&from_aor));
+
 	// early check to see if we're dealing with any SCA endpoints
 	if (sca_uri_is_shared_appearance(sca, &from_aor)) {
 		if ((update_mask & SCA_CALL_INFO_SHARED_CALLER)) {
@@ -1985,7 +2001,7 @@ int sca_call_info_update(sip_msg_t *msg, char *p1, char *p2, char *p3)
 
 	if (sca_call_info_header_remove(msg) < 0) {
 		LM_ERR("Failed to remove Call-Info header\n");
-		return (-1);
+		goto done;
 	}
 
 	if (call_info.ua_shared == SCA_CALL_INFO_SHARED_NONE) {
@@ -2016,6 +2032,16 @@ int sca_call_info_update(sip_msg_t *msg, char *p1, char *p2, char *p3)
 			pkg_free(to_aor.s);
 		}
 	}
+	if ((to_body_flags & SCA_CALL_INFO_UPDATE_FLAG_FROM_ALLOC)) {
+		if (from != NULL) {
+			free_to(from);
+		}
+	}
+	if ((to_body_flags & SCA_CALL_INFO_UPDATE_FLAG_TO_ALLOC)) {
+		if (to != NULL) {
+			free_to(to);
+		}
+	}
 
 	return (rc);
 }

+ 1 - 1
modules/sca/sca_call_info.h

@@ -59,7 +59,7 @@ typedef struct _sca_call_info sca_call_info;
 
 extern const str SCA_CALL_INFO_HEADER_STR;
 
-int sca_call_info_update(sip_msg_t *, char *, char *, char *);
+int sca_call_info_update(sip_msg_t *, char *, str*, str*);
 void sca_call_info_sl_reply_cb(void *);
 void sca_call_info_ack_cb(struct cell *, int, struct tmcb_params *);
 

+ 16 - 48
modules/sca/sca_util.c

@@ -178,60 +178,28 @@ int sca_get_msg_to_header(sip_msg_t *msg, struct to_body **to)
 	return (0);
 }
 
-int sca_get_pv_from_header(sip_msg_t *msg, struct to_body **from, pv_spec_t *sp)
+/*
+ * caller needs to call free_to for *body
+ */
+int sca_build_to_body_from_uri(sip_msg_t *msg, struct to_body **body, str *uri)
 {
-	struct to_body parsed_from;
-	pv_value_t pv_val;
-
 	assert(msg != NULL);
-	assert(from != NULL);
-	assert(sp != NULL);
+	assert(body != NULL);
+	assert(uri != NULL);
 
-	if (pv_get_spec_value(msg, sp, &pv_val) < 0) {
-		LM_ERR("can't get value from to_pvar\n");
-		return (-1);
+	*body = pkg_malloc(sizeof(struct to_body));
+	if(*body == NULL) {
+		LM_ERR("cannot allocate pkg memory\n");
+		return(-1);
 	}
-	if (pv_val.flags & PV_VAL_STR) {
-		parse_to(pv_val.rs.s, pv_val.rs.s + pv_val.rs.len + 1, &parsed_from);
-		if (parsed_from.error != PARSE_OK) {
-			LM_ERR("Bad From value from from_pvar\n");
-			return (-1);
-		}
-		*from = &parsed_from;
-		return (0);
-	}
-	else {
-		LM_ERR("value from from_pvar is not a string\n");
-	}
-	return (-1);
-}
 
-int sca_get_pv_to_header(sip_msg_t *msg, struct to_body **to, pv_spec_t *sp)
-{
-	struct to_body parsed_to;
-	pv_value_t pv_val;
-
-	assert(msg != NULL);
-	assert(to != NULL);
-	assert(sp != NULL);
-
-	if (pv_get_spec_value(msg, sp, &pv_val) < 0) {
-		LM_ERR("can't get value from to_pvar\n");
-		return (-1);
-	}
-	if (pv_val.flags & PV_VAL_STR) {
-		parse_to(pv_val.rs.s, pv_val.rs.s + pv_val.rs.len + 1, &parsed_to);
-		if (parsed_to.error != PARSE_OK) {
-			LM_ERR("Bad To value from to_pvar\n");
-			return (-1);
-		}
-		*to = &parsed_to;
-		return (0);
-	}
-	else {
-		LM_ERR("value from to_pvar is not a string\n");
+	parse_to(uri->s, uri->s + uri->len + 1, *body);
+	if ((*body)->error != PARSE_OK) {
+		LM_ERR("Bad uri value[%.*s]\n", STR_FMT(uri));
+		free_to(*body);
+		return(-1);
 	}
-	return (-1);
+	return (0);
 }
 
 /*

+ 1 - 2
modules/sca/sca_util.h

@@ -46,8 +46,7 @@ int sca_get_msg_from_header(sip_msg_t *, struct to_body **);
 // convenient To header parsing and extraction
 int sca_get_msg_to_header(sip_msg_t *, struct to_body **);
 
-int sca_get_pv_from_header(sip_msg_t *, struct to_body **, pv_spec_t *);
-int sca_get_pv_to_header(sip_msg_t *, struct to_body **, pv_spec_t *);
+int sca_build_to_body_from_uri(sip_msg_t *, struct to_body **, str *);
 
 // count number of characters requiring escape as defined by escape_common
 int sca_uri_display_escapes_count(str *);