Browse code

topos: MESSAGE may be without Contact header

Daniel-Constantin Mierla authored on 18/03/2016 15:43:14
Showing 4 changed files
... ...
@@ -228,6 +228,11 @@ int tps_prepare_msg(sip_msg_t *msg)
228 228
 		LM_DBG("no second via in this message \n");
229 229
 	}
230 230
 
231
+	if(parse_headers(msg, HDR_CSEQ_F, 0)!=0 || msg->cseq==NULL) {
232
+		LM_ERR("cannot parse cseq header\n");
233
+		return -1;
234
+	}
235
+
231 236
 	if(parse_from_header(msg)<0) {
232 237
 		LM_ERR("cannot parse FROM header\n");
233 238
 		return 3;
... ...
@@ -292,7 +297,7 @@ int tps_msg_received(void *data)
292 297
 		}
293 298
 	} else {
294 299
 		/* reply */
295
-		if(msg->first_line.u.reply.statuscode==100) {
300
+		if(msg.first_line.u.reply.statuscode==100) {
296 301
 			/* nothing to do - it should be absorbed */
297 302
 			return 0;
298 303
 		}
... ...
@@ -409,6 +409,7 @@ int tps_pack_request(sip_msg_t *msg, tps_data_t *ptsd)
409 409
 			ptsd->as_contact.len, ZSW(ptsd->as_contact.s), ptsd->as_contact.len,
410 410
 			ptsd->bs_contact.len, ZSW(ptsd->bs_contact.s), ptsd->bs_contact.len);
411 411
 	ptsd->x_rr = ptsd->a_rr;
412
+	ptsd->s_method_id = get_cseq(msg)->method_id;
412 413
 	return 0;
413 414
 }
414 415
 
... ...
@@ -275,8 +275,20 @@ int tps_storage_link_msg(sip_msg_t *msg, tps_data_t *td, int dir)
275 275
 		td->b_tag = td->a_tag;
276 276
 	}
277 277
 
278
+	td->x_via = td->x_via2;
279
+	if(parse_headers(msg, HDR_CSEQ_F, 0)!=0 || msg->cseq==NULL) {
280
+		LM_ERR("cannot parse cseq header\n");
281
+		return -1; /* should it be 0 ?!?! */
282
+	}
283
+	td->s_method = get_cseq(msg)->method;
284
+	td->s_cseq = get_cseq(msg)->number;
285
+
278 286
 	/* extract the contact address */
279 287
 	if(parse_headers(msg, HDR_CONTACT_F, 0)<0 || msg->contact==NULL) {
288
+		if(td->s_method_id == METHOD_MESSAGE) {
289
+			/* no contact required for MESSAGE - done */
290
+			return 0;
291
+		}
280 292
 		LM_ERR("bad sip message or missing Contact hdr\n");
281 293
 		goto error;
282 294
 	}
... ...
@@ -291,13 +303,7 @@ int tps_storage_link_msg(sip_msg_t *msg, tps_data_t *td, int dir)
291 303
 	} else {
292 304
 		td->b_contact = ((contact_body_t*)msg->contact->parsed)->contacts->uri;
293 305
 	}
294
-	td->x_via = td->x_via2;
295
-	if(parse_headers(msg, HDR_CSEQ_F, 0)!=0 || msg->cseq==NULL) {
296
-		LM_ERR("cannot parse cseq header\n");
297
-		return -1; /* should it be 0 ?!?! */
298
-	}
299
-	td->s_method = get_cseq(msg)->method;
300
-	td->s_cseq = get_cseq(msg)->number;
306
+
301 307
 	return 0;
302 308
 
303 309
 error:
... ...
@@ -65,6 +65,7 @@ typedef struct tps_data {
65 65
 	str s_cseq;
66 66
 	int32_t iflags;
67 67
 	int32_t direction;
68
+	uint32_t s_method_id;
68 69
 } tps_data_t;
69 70
 
70 71
 int tps_storage_dialog_find(sip_msg_t *msg, tps_data_t *td);