Allow SIP messages in mod_sendto.py to insert fields (ticket #707)

git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@2440 74dad513-b988-da41-8d7b-12977e46ad98
diff --git a/tests/pjsua/inc_sip.py b/tests/pjsua/inc_sip.py
index 6d5ef05..0c05756 100644
--- a/tests/pjsua/inc_sip.py
+++ b/tests/pjsua/inc_sip.py
@@ -91,11 +91,7 @@
 		if self.trace_enabled:
 			print str(time.strftime("%H:%M:%S ")) + txt
 
-	def create_req(self, method, sdp, branch="", extra_headers=""):
-		if branch=="":
-			self.cseq = self.cseq + 1
-		msg = req_templ
-		msg = msg.replace("$METHOD", method)
+	def update_fields(self, msg):
 		if self.tcp:
 			transport_param = ";transport=tcp"
 		else:
@@ -103,14 +99,23 @@
 		msg = msg.replace("$TARGET_URI", "sip:"+self.dst_addr+":"+str(self.dst_port) + transport_param)
 		msg = msg.replace("$LOCAL_IP", self.local_ip)
 		msg = msg.replace("$LOCAL_PORT", str(self.local_port))
-		if branch=="":
-			branch=str(random.random())
-		msg = msg.replace("$BRANCH", branch)
 		msg = msg.replace("$FROM_TAG", self.local_tag)
 		msg = msg.replace("$TO_TAG", self.rem_tag)
 		msg = msg.replace("$CALL_ID", self.call_id)
 		msg = msg.replace("$CSEQ", str(self.cseq))
+		branch=str(random.random())
+		msg = msg.replace("$BRANCH", branch)
+		return msg
+
+	def create_req(self, method, sdp, branch="", extra_headers=""):
+		if branch=="":
+			self.cseq = self.cseq + 1
+		msg = req_templ
+		msg = msg.replace("$METHOD", method)
 		msg = msg.replace("$SIP_HEADERS", extra_headers)
+		if branch=="":
+			branch=str(random.random())
+		msg = msg.replace("$BRANCH", branch)
 		if sdp!="":
 			msg = msg.replace("$CONTENT_LENGTH", str(len(sdp)))
 			msg = msg + "Content-Type: application/sdp\r\n"
@@ -118,7 +123,7 @@
 			msg = msg.replace("$CONTENT_LENGTH", "0")
 		msg = msg + "\r\n"
 		msg = msg + sdp
-		return msg
+		return self.update_fields(msg)
 
 	def create_response(self, request, code, reason, to_tag=""):
 		response = "SIP/2.0 " + str(code) + " " + reason + "\r\n"
diff --git a/tests/pjsua/mod_sendto.py b/tests/pjsua/mod_sendto.py
index 4cc12a4..a2f4521 100644
--- a/tests/pjsua/mod_sendto.py
+++ b/tests/pjsua/mod_sendto.py
@@ -19,7 +19,7 @@
 	cfg = cfg_file.sendto_cfg
 	
 	if len(cfg.complete_msg) != 0:
-		req = cfg.complete_msg
+		req = dlg.update_fields(cfg.complete_msg)
 	else:
 		req = dlg.create_invite(cfg.sdp, cfg.extra_headers)
 	resp = dlg.send_request_wait(req, 10)