summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortriatmoko2011-06-29 19:07:28 +0200
committertriatmoko2011-06-29 19:07:28 +0200
commit23d68579615be27e7e199a6d9283489f91cd5c39 (patch)
treefe66637c1419c88efb6e44caa42d6a47e53db76c
parentmake function for SIP to GSM RZ, but still missing some script. (diff)
downloadgsm-selftest-23d68579615be27e7e199a6d9283489f91cd5c39.tar.gz
gsm-selftest-23d68579615be27e7e199a6d9283489f91cd5c39.tar.xz
gsm-selftest-23d68579615be27e7e199a6d9283489f91cd5c39.zip
remove old sip handler
-rw-r--r--Handler/IncomingCall2.py194
-rw-r--r--Handler/SIPCall3.py274
2 files changed, 0 insertions, 468 deletions
diff --git a/Handler/IncomingCall2.py b/Handler/IncomingCall2.py
deleted file mode 100644
index 48a28fc..0000000
--- a/Handler/IncomingCall2.py
+++ /dev/null
@@ -1,194 +0,0 @@
-import sys
-import pjsua as pj
-import os
-import re
-import time
-import MySQLdb
-import subprocess
-from time import sleep
-from datetime import datetime
-import string
-
-LOG_LEVEL=2
-current_call = None
-Stop="False"
-SIPID=sys.argv[1]
-
-
-lifeline = re.compile(r"(\d) received")
-report = ("No response","Partial Response","Alive")
-status=""
-
-A=1,2,3
-for host in A:
- ip = "132.230.4.8"
- pingaling = os.popen("ping -q -c2 "+ip,"r")
- #print "Testing ",ip,
- #sys.stdout.flush()
- while 1:
- line = pingaling.readline()
- if not line: break
- igot = re.findall(lifeline,line)
- if igot:
- #print report[int(igot[0])]
- status= report[int(igot[0])]
-
-
-try:
- mydb = MySQLdb.connect('localhost', 'root', 'randompasswordSQL','GSMTesting');
- db=mydb.cursor()
- print " _ _ _ _ _ _ _ _ _ _ _"
- print "_ _ _ _ _ _ _ _ _ _ _ _"
- print "Database connection establish"
-
-except MySQLdb.Error, e:
- print "Error %d: %s" % (e.args[0],e.args[1])
- sys.exit(1)
-
-# Logging callback
-def log_cb(level, str, len):
- print str, "I am here"
-
-
-# Callback to receive events from account
-class MyAccountCallback(pj.AccountCallback):
-
- def __init__(self, account=None):
- pj.AccountCallback.__init__(self, account)
-
- # Notification on incoming call
- def on_incoming_call(self, call):
- global current_call
- global Stop
- if current_call:
- call.answer(486, "Busy")
- return
-
- current_call = call
-
- call_cb = MyCallCallback(current_call)
- current_call.set_callback(call_cb)
-
- current_call.answer(180)
- current_call.answer(200)
- sleep(5)
- current_call.hangup()
- Stop="True"
-
-
-# Callback to receive events from Call
-class MyCallCallback():
-
- def __init__(self, call=None):
- pj.CallCallback.__init__(self, call)
-
- # Notification when call state has changed
- def on_state(self):
- global current_call
- global Stop
- print "(" + self.call.info().last_reason + ")",
- print "From ", self.call.info().remote_uri
- print "is", self.call.info().state_text,
-
-
- if self.call.info().state == pj.CallState.DISCONNECTED:
- current_call = None
- print 'Current call is', current_call
-
- # Notification when call's media state hValueError:as changed.
- def on_media_state(self):
- if self.call.info().media_state == pj.MediaState.ACTIVE:
- # Connect the call to sound device
- call_slot = self.call.info().conf_slot
- pj.Lib.instance().conf_connect(call_slot, 0)
- pj.Lib.instance().conf_connect(0, call_slot)
-
- print "Media is now active"
- print "Call Establish"
- else:
- print "Media is inactive"
-
-##class make_call(URI):
-
-lib = pj.Lib()
-
-if status <> "":
-
- if status == "Alive":
- print "ready to Regsiter"
- 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()
-
- db.execute ("SELECT Username, Password, Server, Status FROM SIPAccountInformation where IDSIP=%s",(SIPID))
- Rows = db.fetchall()
-
- for Row in Rows:
- Server=Row[2]
- Username=Row[0]
- Password=Row[1]
-
- try:
-
- acc_cfg = pj.AccountConfig(str(Server), str(Username), str(Password))
- acc = lib.create_account(acc_cfg, cb=MyAccountCallback())
-
- if acc.info().reg_status < 700:
- Regis_status= "OK"
- my_sip_uri = "sip:" + transport.info().host + ":" + str(transport.info().port)
- db.execute("Select max(TaskID) from SIPReady")
- row = db.fetchone()
-
- test=str(row)
- test = test[1:]
- location = int(string.find(test,'L'))
- test= test[0:location]
-
-
-
- db.execute ("Update SIPReady Set Status='R' where TaskID=%s",(test))
-
- while Stop <> "True":
- print "My SIP URI is", my_sip_uri
-
- sleep(10)
-
-
- transport = None
- acc.delete()
- acc = None
- lib.destroy()
- lib = None
-
-
- else:
- Regis_status= "Bad"
- print "error when register"
- lib.destroy()
- lib = None
-
-
- # Shutdown the library
-
-
- except ValueError:
- print "Something missing"
-
- except ValueError:
- print "Exception: " + str(e)
- lib.destroy()
- lib = None
-
-
- if status == "Partial Response":
- print "Bad Connection"
-
- if status == "No response Response":
- print "Server not respon"
-else:
- print "stop the register"
diff --git a/Handler/SIPCall3.py b/Handler/SIPCall3.py
deleted file mode 100644
index 3a3fe15..0000000
--- a/Handler/SIPCall3.py
+++ /dev/null
@@ -1,274 +0,0 @@
-import sys
-import pjsua as pj
-import os
-import re
-import time
-import MySQLdb
-import subprocess
-from time import sleep
-from datetime import datetime
-
-LOG_LEVEL=2
-current_call = None
-number=""
-Stop = "False"
-
-## -- Identify Server -- ##
-lifeline = re.compile(r"(\d) received")
-report = ("No response","Partial Response","Alive")
-StatusPing=""
-
-#make class connect to db
-try:
- mydb = MySQLdb.connect('localhost', 'root', 'randompasswordSQL','GSMTesting');
- db=mydb.cursor()
- print " _ _ _ _ _ _ _ _ _ _ _"
- print "_ _ _ _ _ _ _ _ _ _ _ _"
- print "Database connection establish"
-
-except MySQLdb.Error, e:
- print "Error %d: %s" % (e.args[0],e.args[1])
- sys.exit(1)
-
-#make it to be class
-
-A=1,2,3
-for host in A:
- ip = "132.230.4.8"
- pingaling = os.popen("ping -q -c2 "+ip,"r")
-
- while 1:
- line = pingaling.readline()
- if not line: break
- igot = re.findall(lifeline,line)
- if igot:
-
- StatusPing= report[int(igot[0])]
-
-
-###--- Ping -- Thread
-
-# Logging callback
-def log_cb(level, str, len):
- print str, "testingggggggg"
-
-
-# Callback to receive events from account
-class MyAccountCallback(pj.AccountCallback):
-
- def __init__(self, account=None):
- pj.AccountCallback.__init__(self, account)
-
- # Notification on incoming call##
-
-
-
-# Callback to receive events from Call
-class MyCallCallback(pj.CallCallback):
-
- def __init__(self, call=None):
- pj.CallCallback.__init__(self, call)
-
- # Notification when call state has changed
- def on_state(self):
- global current_call
- global Stop
- global Succes
- if self.call.info().state_text <> "DISCONNCTD":
- if self.call.info().state_text == "CONNECTING":
- print "CONNECTING CALL"
- #print "isine opo:", self.call.info().state_text
- print "CALL CONFIRMED and ESTABLISH", self.call.info().state_text
- sleep(5)
- current_call.hangup()
- Success = "True"
- else:
- sleep(1)
- #print ""
-
- if self.call.info().last_reason <> "":
-
- if self.call.info().last_reason == "Busy Here":
-
- print "Destination Number is Busy or offline"
- print ""
- Success = "True"
-
-
- #print self.call.info().state_text
-
- if self.call.info().state == pj.CallState.DISCONNECTED:
- current_call = None
- print 'Current call Disconnected'
- Stop="True"
- Success = "True"
-
-# Function to make call should become class
-
-class make_call(URI):
-def make_call(uri):
- try:
- print "Making call to", uri
- cb=MyCallCallback()
- return acc.make_call(number, cb)
- except pj.Error, e:
- print "iki opo to yo Exception: " + str(e)
- return None
-
-
-lib = pj.Lib()
-lib.init()
-lib.start()
-
-if StatusPing <> "":
-
- if StatusPing == "Alive":
- print ""
- print "Checking Order from DB, hell yeah"
- try:
- while True:
- db.execute ("SELECT IDOrder, IDTester, SIPDesti, GSMDesti, GSM2Desti, Landline, GSMO2, Status FROM SIPTestOrder")
- rows = db.fetchall()
-
-
- for row in rows:
- status=row[7]
- if status == "no":
- IDOrder=row[0]
- SIPTester=row[1]
- SIPDest=row[2]
- GSMDest1=row[3]
- GSMDest2=row[4]
- Landln=row[5]
- GSMO2=row[6]
- print "yes, I have something to do. I need to call", SIPDest, GSMDest1, GSMDest2, Landln, GSMO2
-
- db.execute ("SELECT Username, Password, Server, Status FROM SIPAccountInformation where IDSIP=%s",(SIPTester))
- Rows = db.fetchall()
-
- for Row in Rows:
- Server=Row[2]
- Username=Row[0]
- Password=Row[1]
-
- try:
- print "I send my purpose to the server", Server, Username, Password
- lib.set_null_snd_dev()#
- sleep(1)
- transport = lib.create_transport(pj.TransportType.UDP, pj.TransportConfig(0))
- acc_cfg = pj.AccountConfig(Server, Username, Password)
- acc = lib.create_account(acc_cfg, cb=MyAccountCallback())
-
- if acc.info().reg_status < 700:
- Regis_status= "OK"
- print "heeeyyy She Accept me"
-
-
-
-
- if SIPDest <> "":
- IDTask=IDOrder
- SIPID=SIPDest
- Status = "N"
- db.execute ("insert into SIPReady (TaskID,SIPID,Status) value ('"+str(IDTask)+"','"+str(SIPID)+"','"+str(Status)+"')")
- command="--command=python IncomingCall2.py " +SIPDest #pindahin kebawah
- subprocess.Popen(args=["gnome-terminal", command])
- db.execute ("SELECT Number FROM SIPAccountInformation where IDSIP=%s",(SIPDest))
- Num = db.fetchall()
-
- for no in Num:
- number="sip:"+no[0]+"@132.230.4.8"
- stop="False"
-
- while stop <> "True":
- print "Waiting SIP Destination Ready to handle Incoming Call"
- db.execute ("SELECT Status FROM SIPReady where TaskID=%s",(IDOrder))
- Num = db.fetchall()
-
- for no in Num:
- if no[0] == "R":
-
- try:
- current_call = acc.make_call(number, MyCallCallback())
- sleep(5)
- number=""
- if Success == "True":
- report = "Succed"
- db.execute ("insert into StatusConnection (TaskID,Caller,Receiver,Status) value ('"+str(IDTask)+"','"+str(SIPTester)+"','"+str(SIPDest)+"','"+str(report)+"')")
- else:
- report = "Failed"
- db.execute ("insert into StatusConnection (TaskID,Caller,Receiver,Status) value ('"+str(IDTask)+"','"+str(SIPTester)+"','"+str(SIPDest)+"','"+str(report)+"')")
- stop = "True"
- break#stop == "True"
-
- #
-
- except pj.Error, e:
- print "invalid SIP nummber", e
-
- sleep(2)
- if GSMDest1 <> "":
-
- try:
- #call GSM, if error accour about invalid number
- state="N"
- time=""
- db.execute ("insert into GSMReady (doID,recU,state) value ('"+str(IDOrder)+"','"+str(GSMDest1)+"','"+str(state)+"')")#still problemo
- stop = "False"
- while stop <> "True":
- db.execute ("SELECT state FROM GSMReady where doID=%s",(IDOrder))
- Num = db.fetchall()
-
- for rOw in Num:
- if rOw[0]=="R":
- number=GSMDest1
- db.execute ("SELECT Number FROM SIPAccountInformation where IDSIP=%s",(GSMDest1))
- Num = db.fetchall()
-
- for nO in Num:
- number="sip:"+nO[0]+"@132.230.4.8"
- print "GSM Number", number
- current_call = acc.make_call(number, MyCallCallback())
- sleep(10)
- stop = "True"
- break
- sleep(3)
-
- number=""
-
-
- except ValueError:
- print "Invalid GSM1 Number", e
-
- db.execute ("Update SIPTestOrder Set Status='ok' where IDOrder=%s",(IDOrder))
- acc.delete()
- acc = None
- else:
- Regis_status= "Bad"
-
-
-
- except ValueError:
- print "Register Error, Unknown Reason"
-
-
- else:
- sleep(2)
- print""
-
- print "The guy says Nothing to do. I'm going to sleep for 10 Seconds. Tschuss!!!"
- sleep(2)
- print ""
- print " hey, you miss me? I'm Back. Ready to check the Task in 2 seconds"
- sleep(2)
-
- except pj.Error, e:
- print "hallo Exception: " + str(e)
- lib.destroy()
- lib = None
-
- if StatusPing == "Partial Response":
- print "Bad Connection"
-
- if StatusPing == "No response Response":
- print "Server not respon"