1
# $Id: mod_recvfrom.py 3259 2010-08-09 07:31:34Z nanang $
5
import inc_const as const
10
cfg_file = imp.load_source("cfg_file", ARGS[1])
12
# Default server port (should we randomize?)
16
pjsua = test.process[0]
17
dlg = sip.Dialog("127.0.0.1", pjsua.inst_param.sip_port,
19
tcp=cfg_file.recvfrom_cfg.tcp)
24
for t in cfg_file.recvfrom_cfg.transaction:
25
# Print transaction title
28
# Run command and expect patterns
30
if c[0] and c[0] != "":
32
if len(c)>1 and c[1] and c[1] != "":
36
# Absorbs retransmissions
39
call_id = last_call_id
40
while cseq <= last_cseq and method == last_method and call_id == last_call_id:
41
request, src_addr = dlg.wait_msg_from(30)
42
if request==None or request=="":
43
raise TestError("Timeout waiting for request")
44
method = request.split(" ", 1)[0]
45
cseq_hval = sip.get_header(request, "CSeq")
46
cseq_hval = cseq_hval.split(" ")[0]
48
call_id = sip.get_header(request, "Call-ID")
52
request, src_addr = dlg.wait_msg_from(30)
53
if request==None or request=="":
54
raise TestError("Timeout waiting for request")
56
# Check for include patterns
58
if re.search(pat, request, re.M | re.I)==None:
60
tname = " in " + t.title + " transaction"
63
raise TestError("Pattern " + pat + " not found" + tname)
64
# Check for exclude patterns
66
if re.search(pat, request, re.M | re.I)!=None:
68
tname = " in " + t.title + " transaction"
71
raise TestError("Excluded pattern " + pat + " found" + tname)
74
response = dlg.create_response(request, t.resp_code, "Status reason")
75
# Add headers to response
77
response = response + h + "\r\n"
78
# Add message body if required
80
response = response + t.body
82
dlg.send_msg(response, src_addr)
84
# Expect something to happen in pjsua
86
pjsua.expect(t.expect)
90
# Replace "$PORT" with server port in pjsua args
91
cfg_file.recvfrom_cfg.inst_param.arg = cfg_file.recvfrom_cfg.inst_param.arg.replace("$PORT", str(srv_port))
93
# Here where it all comes together
94
test = TestParam(cfg_file.recvfrom_cfg.name,
95
[cfg_file.recvfrom_cfg.inst_param],