From 059d687249f0f95e0b30785c418e1aa47555615a Mon Sep 17 00:00:00 2001 From: Benny Prijono Date: Sun, 1 Aug 2010 09:48:51 +0000 Subject: Implemented core multipart support and support in the invite session (re #1070) - incoming multipart message will be handled automatically - for testing, enable HAVE_MULTIPART_TEST in pjsua_app.c git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@3243 74dad513-b988-da41-8d7b-12977e46ad98 --- tests/pjsua/inc_sip.py | 19 ++++++--- tests/pjsua/mod_sendto.py | 2 +- .../scripts-sendto/251_multipart_ok_simple.py | 38 +++++++++++++++++ .../scripts-sendto/252_multipart_ok_clutter.py | 47 ++++++++++++++++++++++ .../scripts-sendto/260_multipart_err_no_sdp.py | 38 +++++++++++++++++ 5 files changed, 137 insertions(+), 7 deletions(-) create mode 100644 tests/pjsua/scripts-sendto/251_multipart_ok_simple.py create mode 100644 tests/pjsua/scripts-sendto/252_multipart_ok_clutter.py create mode 100644 tests/pjsua/scripts-sendto/260_multipart_err_no_sdp.py (limited to 'tests/pjsua') diff --git a/tests/pjsua/inc_sip.py b/tests/pjsua/inc_sip.py index d64ae87f..c27c72f3 100644 --- a/tests/pjsua/inc_sip.py +++ b/tests/pjsua/inc_sip.py @@ -107,7 +107,7 @@ class Dialog: msg = msg.replace("$BRANCH", branch) return msg - def create_req(self, method, sdp, branch="", extra_headers=""): + def create_req(self, method, sdp, branch="", extra_headers="", body=""): if branch=="": self.cseq = self.cseq + 1 msg = req_templ @@ -119,10 +119,14 @@ class Dialog: if sdp!="": msg = msg.replace("$CONTENT_LENGTH", str(len(sdp))) msg = msg + "Content-Type: application/sdp\r\n" + msg = msg + "\r\n" + msg = msg + sdp + elif body!="": + msg = msg.replace("$CONTENT_LENGTH", str(len(body))) + msg = msg + "\r\n" + msg = msg + body else: msg = msg.replace("$CONTENT_LENGTH", "0") - msg = msg + "\r\n" - msg = msg + sdp return self.update_fields(msg) def create_response(self, request, code, reason, to_tag=""): @@ -138,9 +142,9 @@ class Dialog: response = response + line + "\r\n" return response - def create_invite(self, sdp, extra_headers=""): + def create_invite(self, sdp, extra_headers="", body=""): self.inv_branch = str(random.random()) - return self.create_req("INVITE", sdp, branch=self.inv_branch, extra_headers=extra_headers) + return self.create_req("INVITE", sdp, branch=self.inv_branch, extra_headers=extra_headers, body=body) def create_ack(self, sdp="", extra_headers=""): return self.create_req("ACK", sdp, extra_headers=extra_headers, branch=self.inv_branch) @@ -252,10 +256,12 @@ class SendtoCfg: resp_include = [] # List of RE patterns that must NOT exist in response resp_exclude = [] + # Full (non-SDP) body + body = "" # Constructor def __init__(self, name, pjsua_args, sdp, resp_code, resp_inc=[], resp_exc=[], use_tcp=False, - extra_headers="", complete_msg="", + extra_headers="", body="", complete_msg="", enable_buffer = False): self.complete_msg = complete_msg self.sdp = sdp @@ -264,6 +270,7 @@ class SendtoCfg: self.resp_exclude = resp_exc self.use_tcp = use_tcp self.extra_headers = extra_headers + self.body = body self.inst_param = cfg.InstanceParam("pjsua", pjsua_args) self.inst_param.enable_buffer = enable_buffer diff --git a/tests/pjsua/mod_sendto.py b/tests/pjsua/mod_sendto.py index a2f45212..50dc0fe8 100644 --- a/tests/pjsua/mod_sendto.py +++ b/tests/pjsua/mod_sendto.py @@ -21,7 +21,7 @@ def test_func(t): if len(cfg.complete_msg) != 0: req = dlg.update_fields(cfg.complete_msg) else: - req = dlg.create_invite(cfg.sdp, cfg.extra_headers) + req = dlg.create_invite(cfg.sdp, cfg.extra_headers, cfg.body) resp = dlg.send_request_wait(req, 10) if resp=="": raise TestError("Timed-out waiting for response") diff --git a/tests/pjsua/scripts-sendto/251_multipart_ok_simple.py b/tests/pjsua/scripts-sendto/251_multipart_ok_simple.py new file mode 100644 index 00000000..42163199 --- /dev/null +++ b/tests/pjsua/scripts-sendto/251_multipart_ok_simple.py @@ -0,0 +1,38 @@ +# $Id$ +import inc_sip as sip +import inc_sdp as sdp + +body = \ +""" +--12345 +Content-Type: application/sdp + +v=0 +o=- 0 0 IN IP4 127.0.0.1 +s=pjmedia +c=IN IP4 127.0.0.1 +t=0 0 +m=audio 4000 RTP/AVP 0 101 +a=rtpmap:0 PCMU/8000 +a=sendrecv +a=rtpmap:101 telephone-event/8000 +a=fmtp:101 0-15 + +--12345 +Content-Type: text/plain + +Hi there this is definitely not SDP + +--12345-- +""" + +args = "--null-audio --auto-answer 200 --max-calls 1" +extra_headers = "Content-Type: multipart/mixed; boundary=12345" +include = ["v=0", "m=audio"] +exclude = [] + +sendto_cfg = sip.SendtoCfg( "Valid multipart/mixed body containing SDP", + pjsua_args=args, sdp="", resp_code=200, + extra_headers=extra_headers, body=body, + resp_inc=include, resp_exc=exclude) + diff --git a/tests/pjsua/scripts-sendto/252_multipart_ok_clutter.py b/tests/pjsua/scripts-sendto/252_multipart_ok_clutter.py new file mode 100644 index 00000000..65038488 --- /dev/null +++ b/tests/pjsua/scripts-sendto/252_multipart_ok_clutter.py @@ -0,0 +1,47 @@ +# $Id$ +import inc_sip as sip +import inc_sdp as sdp + +body = \ +""" +This is the preamble. It is to be ignored, though it +is a handy place for composition agents to include an +explanatory note to non-MIME conformant readers. + +--123:45 +Content-Type: text/plain + +The first part is definitely not SDP + +--123:45 + +This is implicitly typed plain US-ASCII text. +It does NOT end with a linebreak. +--123:45 +Content-Type: application/sdp + +v=0 +o=- 0 0 IN IP4 127.0.0.1 +s=pjmedia +c=IN IP4 127.0.0.1 +t=0 0 +m=audio 4000 RTP/AVP 0 101 +a=rtpmap:0 PCMU/8000 +a=sendrecv +a=rtpmap:101 telephone-event/8000 +a=fmtp:101 0-15 + +--123:45-- +This is the epilogue. It is also to be ignored. +""" + +args = "--null-audio --auto-answer 200 --max-calls 1" +extra_headers = "Content-Type: multipart/mixed; boundary=\"123:45\"" +include = ["v=0", "m=audio"] +exclude = [] + +sendto_cfg = sip.SendtoCfg( "Valid but cluttered multipart/mixed body containing SDP", + pjsua_args=args, sdp="", resp_code=200, + extra_headers=extra_headers, body=body, + resp_inc=include, resp_exc=exclude) + diff --git a/tests/pjsua/scripts-sendto/260_multipart_err_no_sdp.py b/tests/pjsua/scripts-sendto/260_multipart_err_no_sdp.py new file mode 100644 index 00000000..7827ec11 --- /dev/null +++ b/tests/pjsua/scripts-sendto/260_multipart_err_no_sdp.py @@ -0,0 +1,38 @@ +# $Id$ +import inc_sip as sip +import inc_sdp as sdp + +body = \ +""" +--12345 +Content-Type: application/notsdp + +v=0 +o=- 0 0 IN IP4 127.0.0.1 +s=pjmedia +c=IN IP4 127.0.0.1 +t=0 0 +m=audio 4000 RTP/AVP 0 101 +a=rtpmap:0 PCMU/8000 +a=sendrecv +a=rtpmap:101 telephone-event/8000 +a=fmtp:101 0-15 + +--12345 +Content-Type: text/plain + +Hi there this is definitely not SDP + +--12345-- +""" + +args = "--null-audio --auto-answer 200 --max-calls 1" +extra_headers = "Content-Type: multipart/mixed; boundary=12345" +include = [] +exclude = [] + +sendto_cfg = sip.SendtoCfg( "Multipart/mixed body without SDP", + pjsua_args=args, sdp="", resp_code=400, + extra_headers=extra_headers, body=body, + resp_inc=include, resp_exc=exclude) + -- cgit v1.2.3