本文整理汇总了Python中sippy.UA.UA类的典型用法代码示例。如果您正苦于以下问题:Python UA类的具体用法?Python UA怎么用?Python UA使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UA类的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, global_config, body, done_cb, portrange):
uaO = UA(global_config, event_cb = self.recvEvent, nh_address = ('127.0.0.1', 5060), \
conn_cbs = (self.connected,), disc_cbs = (self.disconnected,), fail_cbs = (self.disconnected,), \
dead_cbs = (self.alldone,))
uaO.godead_timeout = 10
uaO.compact_sip = self.compact_sip
event = CCEventTry((SipCallId(), SipCiscoGUID(), self.cli, self.cld, body, \
None, 'Alice Smith'))
uaO.recvEvent(event)
self.done_cb = done_cb
self.portrange = portrange
开发者ID:hongbinz,项目名称:voiptests,代码行数:12,代码来源:a_test1.py
示例2: recvRequest
def recvRequest(self, req, sip_t):
if req.getMethod() in ('NOTIFY', 'PING'):
# Whynot?
return (req.genResponse(200, 'OK'), None, None)
if req.getMethod() == 'INVITE':
if self.rserv != None:
return (req.genResponse(486, 'Busy Here'), None, None)
# New dialog
uaA = UA(self.global_config, self.recvEvent, disc_cbs = (self.sess_term,))
uaA.recvRequest(req, sip_t)
return
return (req.genResponse(501, 'Not Implemented'), None, None)
开发者ID:sippy,项目名称:b2bua,代码行数:12,代码来源:IoTUAS.py
示例3: answer
def answer(self, global_config, body, req, sip_t):
in_body = req.getBody()
in_body.parse()
if not checkhostport(in_body, self.portrange, self.atype):
self.nerrs += 1
raise ValueError('Bob(%s): hostport validation has failed' % str(self.__class__))
# New dialog
uaA = UA(global_config, self.recvEvent, disc_cbs = (self.disconnected,), \
fail_cbs = (self.disconnected,), dead_cbs = (self.alldone,))
uaA.godead_timeout = 10
uaA.compact_sip = self.compact_sip
Timeout(self.ring, self.ring_ival, 1, uaA)
self.body = body
return uaA.recvRequest(req, sip_t)
开发者ID:hongbinz,项目名称:voiptests,代码行数:14,代码来源:b_test1.py
示例4: placeOriginate
def placeOriginate(self, oroute):
cId, cGUID, cli, cld, body, auth, caller_name = self.eTry.getData()
cld = oroute.cld
self.huntstop_scodes = oroute.params.get('huntstop_scodes', ())
if 'static_tr_out' in self.global_config:
cld = re_replace(self.global_config['static_tr_out'], cld)
if oroute.hostport == 'sip-ua':
host = self.source[0]
nh_address, same_af = self.source, True
else:
host = oroute.hostonly
nh_address, same_af = oroute.getNHAddr(self.source)
if not oroute.forward_on_fail and self.global_config['acct_enable']:
self.acctO = RadiusAccounting(self.global_config, 'originate', \
send_start = self.global_config['start_acct_enable'], lperiod = \
self.global_config.getdefault('alive_acct_int', None))
self.acctO.ms_precision = self.global_config.getdefault('precise_acct', False)
self.acctO.setParams(oroute.params.get('bill-to', self.username), oroute.params.get('bill-cli', oroute.cli), \
oroute.params.get('bill-cld', cld), self.cGUID, self.cId, host)
else:
self.acctO = None
self.acctA.credit_time = oroute.credit_time
conn_handlers = [self.oConn]
disc_handlers = []
if not oroute.forward_on_fail and self.global_config['acct_enable']:
disc_handlers.append(self.acctO.disc)
self.uaO = UA(self.global_config, self.recvEvent, oroute.user, oroute.passw, nh_address, oroute.credit_time, tuple(conn_handlers), \
tuple(disc_handlers), tuple(disc_handlers), dead_cbs = (self.oDead,), expire_time = oroute.expires, \
no_progress_time = oroute.no_progress_expires, extra_headers = oroute.extra_headers)
self.uaO.local_ua = self.global_config['_uaname']
if self.source != oroute.params.get('outbound_proxy', None):
self.uaO.outbound_proxy = oroute.params.get('outbound_proxy', None)
if self.rtp_proxy_session != None and oroute.params.get('rtpp', True):
self.uaO.on_local_sdp_change = self.rtp_proxy_session.on_caller_sdp_change
self.uaO.on_remote_sdp_change = self.rtp_proxy_session.on_callee_sdp_change
self.rtp_proxy_session.caller.raddress = nh_address
if body != None:
body = body.getCopy()
self.proxied = True
self.uaO.kaInterval = self.global_config['keepalive_orig']
if 'group_timeout' in oroute.params:
timeout, skipto = oroute.params['group_timeout']
Timeout(self.group_expires, timeout, 1, skipto)
if self.global_config.getdefault('hide_call_id', False):
cId = SipCallId(md5(str(cId).encode()).hexdigest() + ('-b2b_%d' % oroute.rnum))
else:
cId += '-b2b_%d' % oroute.rnum
event = CCEventTry((cId, cGUID, oroute.cli, cld, body, auth, \
oroute.params.get('caller_name', self.caller_name)))
if self.eTry.max_forwards != None:
event.max_forwards = self.eTry.max_forwards - 1
if event.max_forwards <= 0:
self.uaA.recvEvent(CCEventFail((483, 'Too Many Hops')))
self.state = CCStateDead
return
event.reason = self.eTry.reason
self.uaO.recvEvent(event)
开发者ID:sippy,项目名称:b2bua,代码行数:57,代码来源:b2bua_radius.py
示例5: __init__
def __init__(self, global_config, body, done_cb, portrange, atype = 'IP4', \
cli = None):
self.atype = atype
if cli != None:
self.cli = cli
if atype == 'IP4':
nh_address = self.nh_address4
else:
nh_address = self.nh_address6
uaO = UA(global_config, event_cb = self.recvEvent, nh_address = nh_address, \
conn_cbs = (self.connected,), disc_cbs = (self.disconnected,), fail_cbs = (self.disconnected,), \
dead_cbs = (self.alldone,))
uaO.godead_timeout = 10
uaO.compact_sip = self.compact_sip
event = CCEventTry((SipCallId(), SipCiscoGUID(), self.cli, self.cld, body, \
None, 'Alice Smith'))
self.done_cb = done_cb
self.portrange = portrange
self.run(uaO, event)
开发者ID:jevonearth,项目名称:voiptests,代码行数:19,代码来源:a_test1.py
示例6: recvEvent
def recvEvent(self, event, ua):
if ua == self.uaA:
if self.uaO == None:
if not isinstance(event, CCEventTry):
# Some weird event received
self.uaA.recvEvent(CCEventDisconnect())
return
self.uaO = UA(self.global_config, event_cb = self.recvEvent, nh_address = (self.global_config['nh_addr'], self.global_config['sip_port_default']))
self.uaO.recvEvent(event)
else:
self.uaA.recvEvent(event)
开发者ID:gtkiller,项目名称:b2bua,代码行数:11,代码来源:b2bua_simple.py
示例7: sess_term
def sess_term(self, ua, rtime, origin, result = 0):
print('disconnected', origin)
if origin == 'IoTUAC':
return
self.rgen.suspend()
self.ua = UA(self.global_config, event_cb = self.recvEvent, \
nh_address = tuple(self.global_config['nh_addr']), disc_cbs = (self.sess_term,))
self.ua.username = self.authname
self.ua.password = self.authpass
self.body.content.o_header = SdpOrigin()
event = CCEventTry((SipCallId(), SipCiscoGUID(), self.cli, self.cld, self.body, \
None, 'PEL 150-2'))
self.ua.recvEvent(event)
开发者ID:sippy,项目名称:b2bua,代码行数:13,代码来源:IoTUAC.py
示例8: __init__
def __init__(self, remote_ip, source, global_config, pass_headers):
self.id = CallController.id
CallController.id += 1
self.global_config = global_config
self.uaA = UA(self.global_config, event_cb = self.recvEvent, conn_cbs = (self.aConn,), disc_cbs = (self.aDisc,), \
fail_cbs = (self.aDisc,), dead_cbs = (self.aDead,))
self.uaA.kaInterval = self.global_config['keepalive_ans']
self.state = CCStateIdle
self.uaO = None
self.routes = []
self.remote_ip = remote_ip
self.source = source
self.pass_headers = pass_headers
开发者ID:DarthRa,项目名称:pulsar,代码行数:13,代码来源:b2bua_radius.py
示例9: sess_started
def sess_started(self):
print('started')
self.ua = UA(self.global_config, event_cb = self.recvEvent, \
nh_address = tuple(self.global_config['nh_addr']), disc_cbs = (self.sess_term,))
self.ua.username = self.authname
self.ua.password = self.authpass
rtp_laddr = local4remote(self.global_config['nh_addr'][0])
rserv_opts = Udp_server_opts((rtp_laddr, 0), self.rtp_received)
rserv_opts.nworkers = 1
self.rserv = Udp_server({}, rserv_opts)
sect = self.body.content.sections[0]
sect.c_header.addr = self.rserv.uopts.laddress[0]
sect.m_header.port = self.rserv.uopts.laddress[1]
self.body.content.o_header = SdpOrigin()
event = CCEventTry((SipCallId(), SipCiscoGUID(), self.cli, self.cld, self.body, \
None, 'PEL 150-2'))
self.rgen = RTPGen()
self.ua.recvEvent(event)
return (self.rgen.enqueue)
开发者ID:sippy,项目名称:b2bua,代码行数:19,代码来源:IoTUAC.py
示例10: placeOriginate
def placeOriginate(self, args, conn_cbs):
cId, cGUID, cli, cld, body, auth, caller_name = self.eTry.getData()
rnum, host, cld, credit_time, expires, no_progress_expires, forward_on_fail, user, passw, cli, \
parameters = args
self.huntstop_scodes = parameters.get('huntstop_scodes', ())
if self.global_config.has_key('static_tr_out'):
cld = re_replace(self.global_config['static_tr_out'], cld)
if host == 'sip-ua':
host = self.source[0]
port = self.source[1]
else:
host = host.split(':', 1)
if len(host) > 1:
port = int(host[1])
else:
port = SipConf.default_port
host = host[0]
disc_cbs = []
if not forward_on_fail and self.global_config['acct_enable']:
self.acctO = RadiusAccounting(self.global_config, 'originate', send_start = self.global_config['start_acct_enable'])
self.acctO.setParams(parameters.get('bill-to', self.username), parameters.get('bill-cli', cli), \
parameters.get('bill-cld', cld), self.cGUID, self.cId, host, credit_time)
print 'adding acct stop cb'
disc_cbs.append(self.acctO.disc)
else:
self.acctO = None
self.acctA.credit_time = credit_time
ua = UA(self.global_config, self.recvEvent, user, passw, (host, port), credit_time, \
(conn_cbs,), tuple(disc_cbs), tuple(disc_cbs), dead_cbs = (self.oDead,), \
expire_time = expires, no_progress_time = no_progress_expires, \
extra_headers = parameters.get('extra_headers', None))
if self.rtp_proxy_session and parameters.get('rtpp', True):
ua.on_local_sdp_change = self.rtp_proxy_session.on_caller_sdp_change
ua.on_remote_sdp_change = self.rtp_proxy_session.on_callee_sdp_change
body = body.getCopy()
body.content += 'a=nortpproxy:yes\r\n'
self.proxied = True
ua.kaInterval = self.global_config['ka_orig']
if parameters.has_key('group_timeout'):
timeout, skipto = parameters['group_timeout']
Timeout(self.group_expires, timeout, 1, skipto)
ua.recvEvent(CCEventTry((cId + '-b2b_%d' % rnum, cGUID, cli, cld, body, auth, \
parameters.get('caller_name', self.caller_name))))
return ua
开发者ID:gtkiller,项目名称:b2bua,代码行数:44,代码来源:b2bua_radius.py
示例11: placeAnswer
def placeAnswer(self, args):
cId, cGUID, cli, cld, body, auth, caller_name = self.eTry.getData() #TODO: move to a subroutine
rnum, host, cld, credit_time, expires, no_progress_expires, forward_on_fail, user, passw, cli, \
parameters = args
self.huntstop_scodes = parameters.get('huntstop_scodes', ())
if self.global_config.has_key('static_tr_out'):
cld = re_replace(self.global_config['static_tr_out'], cld)
if host == 'sip-ua':
host = self.source[0]
port = self.source[1]
else:
host = host.split(':', 1)
if len(host) > 1:
port = int(host[1])
else:
port = SipConf.default_port
host = host[0]
if not forward_on_fail and self.global_config['acct_enable']:
self.acctA = RadiusAccounting(self.global_config, 'answer', send_start = self.global_config['start_acct_enable'])
self.acctA.setParams(parameters.get('bill-to', self.username), parameters.get('bill-cli', cli), \
parameters.get('bill-cld', cld), self.cGUID, self.cId, host, credit_time)
print 'adding acct stop cb'
else:
self.acctA = FakeAccounting()
ua = UA(self.global_config, self.recvEvent, user, passw, (host, port), credit_time, \
(self.aConnA,), (self.aDisc,), (self.aDisc,), dead_cbs = (self.aDead,), \
expire_time = expires, no_progress_time = no_progress_expires, \
extra_headers = parameters.get('extra_headers', None))
if self.rtp_proxy_session and parameters.get('rtpp', True):
print 'placeAnswer() registering on sdp change callbacks'
ua.on_local_sdp_change = self.rtp_proxy_session.on_callee_sdp_change
ua.on_remote_sdp_change = self.rtp_proxy_session.on_caller_sdp_change
body = body.getCopy()
body.content += 'a=nortpproxy:yes\r\n'
self.proxied = True
ua.kaInterval = self.global_config['ka_ans'] #TODO: is this okay for uaA?
if parameters.has_key('group_timeout'):
timeout, skipto = parameters['group_timeout']
Timeout(self.group_expires, timeout, 1, skipto)
ua.recvEvent(CCEventTry((cId + '-b2b_%d' % rnum, cGUID, cli, cld, body, auth, \
parameters.get('caller_name', self.caller_name))))
return ua
开发者ID:gtkiller,项目名称:b2bua,代码行数:42,代码来源:b2bua_radius.py
示例12: CallController
class CallController(object):
global_config = None
uaA = None
uaO = None
nh_addr = None
def __init__(self, global_config):
self.global_config = global_config
self.uaA = UA(self.global_config, self.recvEvent)
self.uaO = None
def recvEvent(self, event, ua):
if ua == self.uaA:
if self.uaO == None:
if not isinstance(event, CCEventTry):
# Some weird event received
self.uaA.recvEvent(CCEventDisconnect())
return
self.uaO = UA(self.global_config, event_cb = self.recvEvent, nh_address = (self.global_config['nh_addr'], self.global_config['sip_port_default']))
self.uaO.recvEvent(event)
else:
self.uaA.recvEvent(event)
开发者ID:gtkiller,项目名称:b2bua,代码行数:22,代码来源:b2bua_simple.py
示例13: CallController
class CallController(object):
id = 1
uaA = None
uaO = None
state = None
cId = None
cld = None
eTry = None
routes = None
remote_ip = None
source = None
acctA = None
acctO = None
global_config = None
rtp_proxy_session = None
huntstop_scodes = None
pass_headers = None
auth_proc = None
proxied = False
challenge = None
def __init__(self, remote_ip, source, global_config, pass_headers):
self.id = CallController.id
CallController.id += 1
self.global_config = global_config
self.uaA = UA(self.global_config, event_cb = self.recvEvent, conn_cbs = (self.aConn,), disc_cbs = (self.aDisc,), \
fail_cbs = (self.aDisc,), dead_cbs = (self.aDead,))
self.uaA.kaInterval = self.global_config['keepalive_ans']
self.state = CCStateIdle
self.uaO = None
self.routes = []
self.remote_ip = remote_ip
self.source = source
self.pass_headers = pass_headers
def recvEvent(self, event, ua):
if ua == self.uaA:
if self.state == CCStateIdle:
if not isinstance(event, CCEventTry):
# Some weird event received
self.uaA.recvEvent(CCEventDisconnect(rtime = event.rtime))
return
self.cId, cGUID, self.cli, self.cld, body, auth, self.caller_name = event.getData()
self.cGUID = cGUID.hexForm()
if self.cld == None:
self.uaA.recvEvent(CCEventFail((500, 'Internal Server Error (1)'), rtime = event.rtime))
self.state = CCStateDead
return
if body == None:
self.uaA.recvEvent(CCEventFail((500, 'Body-less INVITE is not supported'), rtime = event.rtime))
self.state = CCStateDead
return
if self.global_config.has_key('_allowed_pts'):
try:
body.parse()
except:
self.uaA.recvEvent(CCEventFail((400, 'Malformed SDP Body'), rtime = event.rtime))
self.state = CCStateDead
return
allowed_pts = self.global_config['_allowed_pts']
mbody = body.content.sections[0].m_header
if mbody.transport.lower() == 'rtp/avp':
mbody.formats = [x for x in mbody.formats if x in allowed_pts]
if len(mbody.formats) == 0:
self.uaA.recvEvent(CCEventFail((488, 'Not Acceptable Here')))
self.state = CCStateDead
return
if self.cld.startswith('nat-'):
self.cld = self.cld[4:]
body.content += 'a=nated:yes\r\n'
event.data = (self.cId, cGUID, self.cli, self.cld, body, auth, self.caller_name)
if self.global_config.has_key('static_tr_in'):
self.cld = re_replace(self.global_config['static_tr_in'], self.cld)
event.data = (self.cId, cGUID, self.cli, self.cld, body, auth, self.caller_name)
if self.global_config.has_key('_rtp_proxy_clients'):
self.rtp_proxy_session = Rtp_proxy_session(self.global_config, call_id = self.cId, \
notify_socket = global_config['b2bua_socket'], \
notify_tag = quote('r %s' % str(self.id)))
self.rtp_proxy_session.callee_raddress = (self.remote_ip, 5060)
self.eTry = event
self.state = CCStateWaitRoute
if not self.global_config['auth_enable']:
self.username = self.remote_ip
self.rDone(((), 0))
elif auth == None or auth.username == None or len(auth.username) == 0:
self.username = self.remote_ip
self.auth_proc = self.global_config['_radius_client'].do_auth(self.remote_ip, self.cli, self.cld, self.cGUID, \
self.cId, self.remote_ip, self.rDone)
else:
self.username = auth.username
self.auth_proc = self.global_config['_radius_client'].do_auth(auth.username, self.cli, self.cld, self.cGUID,
self.cId, self.remote_ip, self.rDone, auth.realm, auth.nonce, auth.uri, auth.response)
return
if self.state not in (CCStateARComplete, CCStateConnected, CCStateDisconnecting) or self.uaO == None:
return
self.uaO.recvEvent(event)
else:
if (isinstance(event, CCEventFail) or isinstance(event, CCEventDisconnect)) and self.state == CCStateARComplete and \
(isinstance(self.uaA.state, UasStateTrying) or isinstance(self.uaA.state, UasStateRinging)) and len(self.routes) > 0:
if isinstance(event, CCEventFail):
#.........这里部分代码省略.........
开发者ID:DarthRa,项目名称:pulsar,代码行数:101,代码来源:b2bua_radius.py
示例14: placeOriginate
def placeOriginate(self, args):
cId, cGUID, cli, cld, body, auth, caller_name = self.eTry.getData()
rnum, host, cld, credit_time, expires, no_progress_expires, forward_on_fail, user, passw, cli, \
parameters = args
self.huntstop_scodes = parameters.get('huntstop_scodes', ())
if self.global_config.has_key('static_tr_out'):
cld = re_replace(self.global_config['static_tr_out'], cld)
if host == 'sip-ua':
host = self.source[0]
port = self.source[1]
else:
if host.startswith('['):
# IPv6
host = host.split(']', 1)
port = host[1].split(':', 1)
host = host[0] + ']'
if len(port) > 1:
port = int(port[1])
else:
port = SipConf.default_port
else:
# IPv4
host = host.split(':', 1)
if len(host) > 1:
port = int(host[1])
else:
port = SipConf.default_port
host = host[0]
if not forward_on_fail and self.global_config['acct_enable']:
self.acctO = RadiusAccounting(self.global_config, 'originate', \
send_start = self.global_config['start_acct_enable'], lperiod = \
self.global_config.getdefault('alive_acct_int', None))
self.acctO.ms_precision = self.global_config.getdefault('precise_acct', False)
self.acctO.setParams(parameters.get('bill-to', self.username), parameters.get('bill-cli', cli), \
parameters.get('bill-cld', cld), self.cGUID, self.cId, host)
else:
self.acctO = None
self.acctA.credit_time = credit_time
conn_handlers = [self.oConn]
disc_handlers = []
if not forward_on_fail and self.global_config['acct_enable']:
disc_handlers.append(self.acctO.disc)
self.uaO = UA(self.global_config, self.recvEvent, user, passw, (host, port), credit_time, tuple(conn_handlers), \
tuple(disc_handlers), tuple(disc_handlers), dead_cbs = (self.oDead,), expire_time = expires, \
no_progress_time = no_progress_expires, extra_headers = parameters.get('extra_headers', None))
if self.rtp_proxy_session != None and parameters.get('rtpp', True):
self.uaO.on_local_sdp_change = self.rtp_proxy_session.on_caller_sdp_change
self.uaO.on_remote_sdp_change = self.rtp_proxy_session.on_callee_sdp_change
self.rtp_proxy_session.caller_raddress = (host, port)
body = body.getCopy()
body.content += 'a=nortpproxy:yes\r\n'
self.proxied = True
self.uaO.kaInterval = self.global_config['keepalive_orig']
if parameters.has_key('group_timeout'):
timeout, skipto = parameters['group_timeout']
Timeout(self.group_expires, timeout, 1, skipto)
if self.global_config.getdefault('hide_call_id', False):
cId = SipCallId(md5(str(cId)).hexdigest() + ('-b2b_%d' % rnum))
else:
cId += '-b2b_%d' % rnum
event = CCEventTry((cId, cGUID, cli, cld, body, auth, \
parameters.get('caller_name', self.caller_name)))
event.reason = self.eTry.reason
self.uaO.recvEvent(event)
开发者ID:DarthRa,项目名称:pulsar,代码行数:64,代码来源:b2bua_radius.py
示例15: register_clients
def register_clients(ud):
# For each record in UserData list create a registrar UA
for (InternalUserId, ExtDisplayName, ExtName, ExtLogin, ExtPassword, ExtDomain, ExtPort) in ud.Data:
Ua = UA(
global_config,
event_cb = recvEvent,
username = ExtLogin,
password = ExtPassword,
conn_cbs = (recvConnect,),
disc_cbs = (recvDisconnect,),
fail_cbs = (recvDisconnect,),
dead_cbs = (recvDead,),
nh_address = (global_config['proxy_address'], global_config['proxy_port'])
)
if ExtPort == None:
Ua.rTarget = SipURL(url = "sip:" + ExtName + "@" + ExtDomain)
Ua.rUri = SipTo(body = "<sip:" + ExtName + "@" + ExtDomain + ">")
Ua.lUri = SipFrom(body = ExtDisplayName + " <sip:" + ExtName + "@" + ExtDomain + ">")
else:
Ua.rTarget = SipURL(url = "sip:" + ExtName + "@" + ExtDomain + ":" + ExtPort)
Ua.rUri = SipTo(body = "<sip:" + ExtName + "@" + ExtDomain + ":" + ExtPort + ">")
Ua.lUri = SipFrom(body = ExtDisplayName + " <sip:" + ExtName + "@" + ExtDomain + ":" + ExtPort + ">")
Ua.lUri.parse()
Ua.lUri.genTag()
Ua.lContact = SipContact(body = "<sip:" + InternalUserId + "@" + global_config['proxy_address'] + ">")
Ua.routes = ()
Ua.lCSeq = 1
Ua.rCSeq = 1
Ua.cId = SipCallId()
req = Ua.genRequest("REGISTER")
Ua.changeState((UacStateTrying,))
global_config['_sip_tm'].regConsumer(Ua, str(Ua.cId))
Ua.tr = global_config['_sip_tm'].newTransaction(req, Ua.recvResponse)
开发者ID:lemenkov,项目名称:registrar_agent,代码行数:34,代码来源:registrar_agent.py
示例16: CallController
class CallController(object):
id = 1
uaA = None
uaO = None
state = None
cId = None
cld = None
eTry = None
routes = None
remote_ip = None
source = None
acctA = None
acctO = None
global_config = None
rtp_proxy_session = None
huntstop_scodes = None
pass_headers = None
auth_proc = None
proxied = False
challenge = None
def __init__(self, remote_ip, source, global_config, pass_headers):
self.id = CallController.id
CallController.id += 1
self.global_config = global_config
self.uaA = UA(self.global_config, event_cb = self.recvEvent, conn_cbs = (self.aConn,), disc_cbs = (self.aDisc,), \
fail_cbs = (self.aDisc,), dead_cbs = (self.aDead,))
self.uaA.kaInterval = self.global_config['keepalive_ans']
self.uaA.local_ua = self.global_config['_uaname']
self.state = CCStateIdle
self.uaO = None
self.routes = []
self.remote_ip = remote_ip
self.source = source
self.pass_headers = pass_headers
def recvEvent(self, event, ua):
if ua == self.uaA:
if self.state == CCStateIdle:
if not isinstance(event, CCEventTry):
# Some weird event received
self.uaA.recvEvent(CCEventDisconnect(rtime = event.rtime))
return
self.cId, cGUID, self.cli, self.cld, body, auth, self.caller_name = event.getData()
self.cGUID = cGUID.hexForm()
if self.cld == None:
self.uaA.recvEvent(CCEventFail((500, 'Internal Server Error (1)'), rtime = event.rtime))
self.state = CCStateDead
return
if body != None and '_allowed_pts' in self.global_config:
try:
body.parse()
except:
self.uaA.recvEvent(CCEventFail((400, 'Malformed SDP Body'), rtime = event.rtime))
self.state = CCStateDead
return
allowed_pts = self.global_config['_allowed_pts']
mbody = body.content.sections[0].m_header
if mbody.transport.lower() == 'rtp/avp':
old_len = len(mbody.formats)
mbody.formats = [x for x in mbody.formats if x in allowed_pts]
if len(mbody.formats) == 0:
self.uaA.recvEvent(CCEventFail((488, 'Not Acceptable Here')))
self.state = CCStateDead
return
if old_len > len(mbody.formats):
body.content.sections[0].optimize_a()
if self.cld.startswith('nat-'):
self.cld = self.cld[4:]
if body != None:
body.content += 'a=nated:yes\r\n'
event.data = (self.cId, cGUID, self.cli, self.cld, body, auth, self.caller_name)
if 'static_tr_in' in self.global_config:
self.cld = re_replace(self.global_config['static_tr_in'], self.cld)
event.data = (self.cId, cGUID, self.cli, self.cld, body, auth, self.caller_name)
if '_rtp_proxy_clients' in self.global_config:
self.rtp_proxy_session = Rtp_proxy_session(self.global_config, call_id = self.cId, \
notify_socket = self.global_config['b2bua_socket'], \
notify_tag = quote('r %s' % str(self.id)))
self.rtp_proxy_session.callee.raddress = (self.remote_ip, 5060)
self.rtp_proxy_session.insert_nortpp = True
self.eTry = event
self.state = CCStateWaitRoute
if not self.global_config['auth_enable']:
self.username = self.remote_ip
self.rDone(((), 0))
elif auth == None or auth.username == None or len(auth.username) == 0:
self.username = self.remote_ip
self.auth_proc = self.global_config['_radius_client'].do_auth(self.remote_ip, self.cli, self.cld, self.cGUID, \
self.cId, self.remote_ip, self.rDone)
else:
self.username = auth.username
self.auth_proc = self.global_config['_radius_client'].do_auth(auth.username, self.cli, self.cld, self.cGUID,
self.cId, self.remote_ip, self.rDone, auth.realm, auth.nonce, auth.uri, auth.response)
return
if self.state not in (CCStateARComplete, CCStateConnected, CCStateDisconnecting) or self.uaO == None:
return
self.uaO.recvEvent(event)
else:
if (isinstance(event, CCEventFail) or isinstance(event, CCEventDisconnect)) and self.state == CCStateARComplete and \
#.........这里部分代码省略.........
开发者ID:sippy,项目名称:b2bua,代码行数:101,代码来源:b2bua_radius.py
示例17: __init__
def __init__(self, global_config):
self.global_config = global_config
self.uaA = UA(self.global_config, self.recvEvent)
self.uaO = None
开发者ID:gtkiller,项目名称:b2bua,代码行数:4,代码来源:b2bua_simple.py
示例18: CallController
class CallController(object):
id = 1
uaA = None
uaO = None
state = None
cId = None
cld = None
eTry = None
routes = None
remote_ip = None
source = None
acctA = None
acctO = None
global_config = None
rtp_proxy_session = None
huntstop_scodes = None
pass_headers = None
auth_proc = None
proxied = False
challenge = None
def __init__(self, remote_ip, source, global_config, pass_headers, username = None):
self.id = CallController.id
CallController.id += 1
self.global_config = global_config
if remote_ip:
self.uaA = UA(self.global_config, event_cb = self.recvEvent, conn_cbs = (self.aConn,), disc_cbs = (self.aDisc,), \
fail_cbs = (self.aDisc,), dead_cbs = (self.aDead,))
self.uaA.kaInterval = self.global_config['ka_ans']
self.state = CCStateIdle
self.uaO = None
self.routes = []
self.remote_ip = remote_ip
self.source = source
self.pass_headers = pass_headers
self.username = username
def recvEvent(self, event, ua):
who = 'uaA' if ua == self.uaA else 'uaO'
print who, 'received event', event, 'in state', self.state.sname
if self.uaA:
print 'self.uaA.state:', self.uaA.state
if self.uaO:
print 'self.uaO.state:', self.uaO.state
if ua == self.uaA:
if self.state == CCStateIdle:
if not isinstance(event, CCEventTry):
# Some weird event received
self.uaA.recvEvent(CCEventDisconnect(rtime = event.rtime))
return
self.cId, cGUID, self.cli, self.cld, body, auth, self.caller_name = event.getData()
print 'auth:', auth
self.cGUID = cGUID.hexForm()
if not self.cld:
self.uaA.recvEvent(CCEventFail((500, 'Internal Server Error (1)'), rtime = event.rtime))
self.state = CCStateDead
return
if not body:
self.uaA.recvEvent(CCEventFail((500, 'Body-less INVITE is not supported'), rtime = event.rtime))
self.state = CCStateDead
return
if self.global_config.has_key('allowed_pts'):
try:
body.parse()
except:
self.uaA.recvEvent(CCEventFail((400, 'Malformed SDP Body'), rtime = event.rtime))
self.state = CCStateDead
return
allowed_pts = self.global_config['allowed_pts']
mbody = body.content.sections[0].m_header
if mbody.transport.lower() == 'rtp/avp':
mbody.formats = [x for x in mbody.formats if x in allowed_pts]
if not mbody.formats:
self.uaA.recvEvent(CCEventFail((488, 'Not Acceptable Here')))
self.state = CCStateDead
return
if self.cld.startswith('nat-'):
self.cld = self.cld[4:]
body.content += 'a=nated:yes\r\n'
event = CCEventTry((self.cId, cGUID, self.cli, self.cld, body, auth, self.caller_name), \
rtime = event.rtime, origin = event.origin)
if self.global_config.has_key('static_tr_in'):
self.cld = re_replace(self.global_config['static_tr_in'], self.cld)
event = CCEventTry((self.cId, cGUID, self.cli, self.cld, body, auth, self.caller_name), \
rtime = event.rtime, origin = event.origin)
if self.global_config.has_key('rtp_proxy_clients'):
self.rtp_proxy_session = Rtp_proxy_session(self.global_config, call_id = self.cId, \
notify_socket = global_config['b2bua_socket'], \
notify_tag = quote('r %s' % str(self.id)))
self.eTry = event
self.state = CCStateWaitRoute
if not self.global_config['auth_enable']:
self.username = self.remote_ip
self.rDone(((), 0))
elif not auth or not auth.username:
print 'setting username to remote ip ', self.remote_ip
self.username = self.remote_ip
self.auth_proc = self.global_config['radius_client'].do_auth(self.remote_ip, self.cli, self.cld, self.cGUID, \
self.cId, self.remote_ip, self.rDone)
else:
#.........这里部分代码省略.........
开发者ID:gtkiller,项目名称:b2bua,代码行数:101,代码来源:b2bua_radius.py
示例19: IoTUAC
class IoTUAC(object):
global_config = None
ua = None
cli = 'pel150_uac'
cld = 'pel150_uas'
authname = None
authpass = None
body = None
rgen = None
rserv = None
def __init__(self, global_config):
self.global_config = global_config
SipTransactionManager.nworkers_udp = 1
global_config['_sip_tm'] = SipTransactionManager(global_config)
self.body = MsgBody(body_txt)
self.body.parse()
def sess_started(self):
print('started')
self.ua = UA(self.global_config, event_cb = self.recvEvent, \
nh_address = tuple(self.global_config['nh_addr']), disc_cbs = (self.sess_term,))
self.ua.username = self.authname
self.ua.password = self.authpass
rtp_laddr = local4remote(self.global_config['nh_addr'][0])
rserv_opts = Udp_server_opts((rtp_laddr, 0), self.rtp_received)
rserv_opts.nworkers = 1
self.rserv = Udp_server({}, rserv_opts)
sect = self.body.content.sections[0]
sect.c_header.addr = self.rserv.uopts.laddress[0]
sect.m_header.port = self.rserv.uopts.laddress[1]
self.body.content.o_header = SdpOrigin()
event = CCEventTry((SipCallId(), SipCiscoGUID(), self.cli, self.cld, self.body, \
None, 'PEL 150-2'))
self.rgen = RTPGen()
self.ua.recvEvent(event)
return (self.rgen.enqueue)
def sess_term(self, ua, rtime, origin, result = 0):
print('disconnected', origin)
if origin == 'IoTUAC':
return
self.rgen.suspend()
self.ua = UA(self.global_config, event_cb = self.recvEvent, \
nh_address = tuple(self.global_config['nh_addr']), disc_cbs = (self.sess_term,))
self.ua.username = self.authname
self.ua.password = self.authpass
self.body.content.o_header = SdpOrigin()
event = CCEventTry((SipCallId(), SipCiscoGUID(), self.cli, self.cld, self.body, \
None, 'PEL 150-2'))
self.ua.recvEvent(event)
def sess_ended(self):
print('ended')
event = CCEventDisconnect(origin = 'IoTUAC')
self.ua.recvEvent(event)
self.rgen.stop()
self.rserv.shutdown()
self.rgen = None
def rtp_received(self, data, address, udp_server, rtime):
pass
def recvEvent(self, event, ua):
print('recvEvent', event, ua)
if isinstance(event, CCEventRing) or isinstance(event, CCEventConnect) or \
isinstance(event, CCEventPreConnect):
code, reason, sdp_body = event.getData()
if sdp_body == None:
return
sdp_body.parse()
sect = sdp_body.content.sections[0]
rtp_target = (sect.c_header.addr, sect.m_header.port)
self.rgen.start(self.rserv, rtp_target)
开发者ID:sippy,项目名称:b2bua,代码行数:74,代码来源:IoTUAC.py
注:本文中的sippy.UA.UA类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论