summaryrefslogtreecommitdiffstats
path: root/For Weekly Test/20-07-2011/landlineReceiver.py
diff options
context:
space:
mode:
Diffstat (limited to 'For Weekly Test/20-07-2011/landlineReceiver.py')
-rw-r--r--For Weekly Test/20-07-2011/landlineReceiver.py161
1 files changed, 161 insertions, 0 deletions
diff --git a/For Weekly Test/20-07-2011/landlineReceiver.py b/For Weekly Test/20-07-2011/landlineReceiver.py
new file mode 100644
index 0000000..0890f36
--- /dev/null
+++ b/For Weekly Test/20-07-2011/landlineReceiver.py
@@ -0,0 +1,161 @@
+import sys
+import pjsua as pj
+import string
+import classServer
+
+from time import sleep
+from datetime import datetime
+
+stop = False
+
+LOG_LEVEL=2
+current_call = None
+status = None
+global accept
+accept = None
+
+
+# Logging
+def log_cb(level, str, len):
+ print str, "SIP Handler Receiver Log"
+
+
+
+class MyAccountCallback(pj.AccountCallback):
+
+ global status
+
+ def __init__(self, account=None):
+ pj.AccountCallback.__init__(self, account)
+
+ def on_incoming_call(self, call):
+ global current_call
+ global number
+
+ if current_call:
+ call.answer(486, "Busy")
+ return
+
+ number = call.info().remote_uri
+
+ current_call = call
+
+ call_cb = MyCallCallback(current_call)
+ current_call.set_callback(call_cb)
+
+ current_call.answer(180)
+ print "accept call"
+
+ if current_call <> None:
+ accept = True
+
+ if accept == True:
+ #sleep(0.5)
+ print "here"
+ current_call.answer(200)
+ sleep(1)
+ #current_call.hangup()
+ #status = 200
+ server.sendData('200')
+
+class MyCallCallback(pj.CallCallback):
+
+ def __init__(self, call=None):
+ pj.CallCallback.__init__(self, call)
+
+
+ def on_state(self):
+ global current_call
+ global success
+
+ if self.call.info().state == pj.CallState.CONNECTING:
+ print self.call.info().state_text
+ status = 200
+ #server.sendData('200')
+
+ if self.call.info().state == pj.CallState.DISCONNECTED:
+ current_call = None
+
+ print '701 The called party has hung up'
+
+
+lib = pj.Lib()
+
+try:
+
+
+ lib.init(log_cfg = pj.LogConfig(level=LOG_LEVEL, callback=log_cb))
+ transport = lib.create_transport(pj.TransportType.UDP, pj.TransportConfig(0))
+
+ print "\nListening on", transport.info().host,
+ print "port", transport.info().port, "\n"
+
+
+ lib.start()
+ lib.set_null_snd_dev()
+
+
+
+ try:
+ acc_cfg = pj.AccountConfig("sipgate.de","1289459","MMW9AX")
+ acc = lib.create_account(acc_cfg, cb=MyAccountCallback())
+
+ if acc.info().reg_status < 700:
+
+ my_sip_uri = "sip:" + transport.info().host + ":" + str(transport.info().port)
+ server = classServer.ServerHandler(50106)
+ tried = server.openSocket()
+ print tried
+ server.sendData('ready')
+ server.closeConnection()
+ tried = server.openSocket()
+ while stop <> True:
+
+ data = server.receiveData()
+
+ if data == "487":
+ print "BYE BYE"
+ sleep(5)
+ stop = True
+ break
+
+ if current_call == None:
+ accept = None
+ continue
+ else:
+ accept = True
+ #print "Incoming call from :"
+ #current_call.answer(200)
+
+
+
+
+ transport = None
+ acc.delete()
+ acc = None
+ lib.destroy()
+ lib = None
+ server.closeConnection()
+
+ else:
+ print "Bad Register"
+
+ lib.destroy()
+ lib = None
+ acc = None
+ server.closeConnection()
+
+
+ except pj.Error, e:
+ print "401 Unauthorized " +str(e)
+ lib.destroy()
+ lib = None
+ server.closeConnection()
+
+
+except pj.Error, e:
+ print "Exception: " + str(e)
+ lib.destroy()
+ lib = None
+ server.closeConnection()
+ del server