Esempio n. 1
0
 def register(self,extern,host,port=5060,password=None,renew=True,tmp=True):
     if not password:
         password=extern
     sip='sip:%s@%s:%s'%(extern,host,port)
     domain="%s:%s"%(host,port)
     if self.created.has_key(sip):
         self.created[sip].set_registration(renew)
         return self.created[sip]
     if (tmp and not self.tmpacc) or not tmp:
         acc=self.lib.create_account(pj.AccountConfig(domain=domain,username=extern,password=password),set_default=False)
         acc_cb=DefaultAccountCB(acc,sipclient=self)
         acc.set_callback(acc_cb)
         if not acc_cb.wait():
             return None
         if tmp:
             self.tmpacc=acc
         else:
             self.created[sip]=acc
         return acc
     if tmp and self.tmpacc:
         #self.tmpacc.set_registration(False)
         acc_id=self.tmpacc._id
         self.lib.modify_account(acc_id,pj.AccountConfig(domain=domain,username=extern,password=password))
         #if not self.tmpacc._cb.wait():
         #    return None
         #self.tmpacc.set_registration(renew)
         return self.tmpacc
Esempio n. 2
0
    def __create_account(self, acct_cfg):
        """Create a PJSuaAccount from configuration"""
        account_cb = None
        name = acct_cfg['name']
        username = acct_cfg.get('username', name)
        domain = acct_cfg.get('domain', '127.0.0.1')
        password = acct_cfg.get('password', '')

        # If account is not to register to a server then create the config
        # without specifying a domain and set the ID using the domain ourself.
        if not self.config.get('register', True):
            pj_acct_cfg = pj.AccountConfig()
            pj_acct_cfg.id = "%s <sip:%s@%s>" % (name, username, domain)
        else:
            account_cb = RegDetector(self)
            pj_acct_cfg = pj.AccountConfig(domain, username, password, name)

        if acct_cfg.get('mwi-subscribe'):
            pj_acct_cfg.mwi_enabled = 1
        if acct_cfg.get('transport'):
            acct_transport = acct_cfg.get('transport')
            if acct_transport in self.pj_transports:
                transport_id = self.pj_transports[acct_transport]._id
                pj_acct_cfg.transport_id = transport_id

        LOGGER.info("Creating PJSUA account %s@%s" % (username, domain))
        account = PJsuaAccount(
            self.lib.create_account(pj_acct_cfg, False, account_cb), self.lib)
        account.add_buddies(acct_cfg.get('buddies', []))
        return account
Esempio n. 3
0
    def initAccounts(self):
        for cc_code, acc in self.accounts.items():
            #sipscc = pj.AccountConfig(str(acc['domain']), str(acc['username']), str(acc['password']),
            #                          str(acc['domain']))
            sipscc = pj.AccountConfig()
            sipscc.id = str(acc['domain']) + "<sip:" + str(
                acc['username']) + "@" + str(acc['domain']) + ">"
            sipscc.domain = str(acc['domain'])
            sipscc.auth_cred = [
                pj.AuthCred("*", str(acc['username']), str(acc['password']))
            ]
            sipscc.reg_uri = "sip:" + str(acc['domain'])
            if acc.has_key('proxy'):
                sipscc.proxy = [str(acc['proxy'][0])]
            if acc.has_key('srtp'):
                sipscc.use_srtp = str(acc['srtp'])
            if acc.has_key('srtp_sig'):
                sipscc.srtp_secure_signaling = str(acc['srtp_sig'])
            if acc.has_key('auth_algo'):
                sipscc.auth_initial_algorithm = str(acc['auth_algo'])

            if acc['transport'] == 'UDP':
                transport_type = pj.TransportType.UDP
                transport = pj.Lib.instance().create_transport(transport_type)
                sipscc.transport_id = transport._id

                acc['transport_object'] = transport
            else:
                transport_type = pj.TransportType.TCP
                #TCP transport is already created in initLib function of SipPhone class

            acc['acc_config'] = sipscc
Esempio n. 4
0
    def _create_endpoint(self, account_id: str, registration_uri: str, username: str, password: str):
        class MyAccountCallback(pjsua.AccountCallback):
            sem = None

            def __init__(self, account=None):
                pjsua.AccountCallback.__init__(self, account)

            def wait(self):
                self.sem = threading.Semaphore(0)
                self.sem.acquire()

            def on_reg_state(self):
                if self.sem:
                    if self.account.info().reg_status >= 200:
                        self.sem.release()

        acc_cfg = pjsua.AccountConfig()
        acc_cfg.id = account_id
        acc_cfg.reg_uri = registration_uri
        acc_cfg.auth_cred = [pjsua.AuthCred("*", username, password)]
        acc_cb = MyAccountCallback()
        acc = self.lib.create_account(acc_cfg, cb=acc_cb)
        print("\n")
        print('Registering %s' % registration_uri)
        acc_cb.wait()
        reg_status = acc.info().reg_status
        reg_reason = acc.info().reg_reason
        if reg_status != 200:
            print('Registration failed (%s) status= %s (%s)' % (registration_uri, reg_status, reg_reason))
            exit(1)
        print('Registration completed (%s) status= %s (%s)' % (registration_uri, reg_status, reg_reason))
        return acc
Esempio n. 5
0
    def reg_user(self, user):
        """ Registers a L{User} instance in this batch to the SIP server.
        At the beginning of the simulation, users stay unregistered for some amount of time
        and this function is called when the register event is triggered.

        Along with registration, a C{PJSUA.Account} instance is attached to the user and a
        L{UserAccountCallback} instance is set to the C{Account}.

        @type   user:   User
        @param  user:   the user instance to be registered
        """
        try:
            uname = user.id + self.BASE_ID
            trans = self.lib.create_transport(pj.TransportType.UDP,
                                              pj.TransportConfig(uname))
            conf = pj.AccountConfig(self.SIP_SERVER_IP, str(uname),
                                    self.PASSWORD)
            conf.reg_timeout = user.registration_period
            conf.ka_interval = 0
            conf.transport_id = trans._id
            acc = self.lib.create_account(conf)
            user.account = acc
            acc_cb = UserAccountCallback(user)
            acc.set_callback(acc_cb)
        except Exception, e:
            print "Exception while registering user:", str(e)
Esempio n. 6
0
 def register(self, config, default=False):
     for k, v in config.iteritems():
         config[k] = str(v)
     ddi = config['ddi']
     logging.info("Creating transport for %s" % (config['uri']))
     transport = self.lib.create_transport(pj.TransportType.UDP)
     logging.info(
         "Listening on %s:%d for %s" %
         (transport.info().host, transport.info().port, config['uri']))
     logging.info("Attempting registration for %s" % config['uri'])
     account_cfg = pj.AccountConfig(domain=config['domain'],
                                    username=config['username'],
                                    password=config['password'],
                                    proxy=config['proxy'])
     account_cfg.id = config['uri']
     account = self.lib.create_account(acc_config=account_cfg,
                                       set_default=default)
     account.set_transport(transport)
     account_cb = AccountHandler(account)
     account.set_callback(account_cb)
     account_cb.wait()
     logging.info("%s registered, status: %s (%s)" %
                  (config['uri'], account.info().reg_status,
                   account.info().reg_reason))
     return (ddi, account, account_cb, account_cfg)
Esempio n. 7
0
File: pjUA.py Progetto: pakru/pj-UA
    def __init__(self,
                 domain,
                 username,
                 passwd,
                 sipProxy,
                 displayName,
                 uaIP,
                 regExpiresTimeout=200,
                 req100rel=False,
                 autoAnswer=True):
        global lib
        logging.info('Creating of pjsip subcriber UA: ' + username + '@' +
                     domain)
        self.uaCurrentCallInfo = pj.CallInfo
        self.uaCurrentCall = pj.Call
        self.uaAccountInfo = pj.AccountInfo
        self.uaAutoAnswerBehavior = autoAnswer
        self.failureFlag = False
        self.expectedState = None

        self.AccConfig = pj.AccountConfig(domain=domain,
                                          username=username,
                                          password=passwd,
                                          display=displayName,
                                          proxy='sip:' + sipProxy)
        self.AccConfig.reg_timeout = regExpiresTimeout
        self.AccConfig.require_100rel = req100rel

        #print('Creating account...')
        self.acc = lib.create_account(self.AccConfig)

        #print('Creating callback account...')
        self.acc_cb = MyAccountCallback(account=self.acc, accInstance=self)

        #print('Setting callback account')
        self.acc.set_callback(self.acc_cb)

        #print('Registering for registration...')
        self.acc_cb.wait()

        #print('\n')
        #print('Registration status=', self.acc.info().reg_status, "(" + self.acc.info().reg_reason + ")")
        print(
            str(self.uaAccountInfo.uri) + ': Registration status=',
            self.uaAccountInfo.reg_status,
            "(" + self.uaAccountInfo.reg_reason + ")")
        logging.info(
            str(self.uaAccountInfo.uri) + ': Registration status=' +
            str(self.uaAccountInfo.reg_status) + "(" +
            str(self.uaAccountInfo.reg_reason) + ")")

        self.soundsPath = sys.path[-1] + '/pjSIP_py/pjsounds/'
        #print('Sounds path: ' + self.soundsPath)
        self.playerID = lib.create_player(filename=self.soundsPath +
                                          'demo-instruct-low.wav',
                                          loop=True)
        self.playerSlot = lib.player_get_slot(self.playerID)
Esempio n. 8
0
    def run(self, domain, user, password):
        try:
            mediaconfig = pj.MediaConfig()
            mediaconfig.quality = 10
            self.lib.init(log_cfg=pj.LogConfig(level=4, callback=self.log_cb),
                          media_cfg=mediaconfig)
            transport = self.lib.create_transport(pj.TransportType.UDP,
                                                  pj.TransportConfig())
            self.lib.start()

            # Put your sIP client credentials here
            acc = self.lib.create_account(
                pj.AccountConfig(domain=domain,
                                 username=user,
                                 password=password))

            acc_cb = MyAccountCallback(app=self, account=acc)
            acc.set_callback(acc_cb)
            acc_cb.wait()

            print "\n"
            print "Registration complete, status=", acc.info().reg_status, \
                "(" + acc.info().reg_reason + ")"

            if len(sys.argv) > 1:
                lck = self.lib.auto_lock()

            my_sip_uri = "sip:" + transport.info().host + \
                         ":" + str(transport.info().port)

            # Menu loop
            while True:
                print "My SIP URI is", my_sip_uri
                print "Menu: h=hangup call, q=quit"

                input = sys.stdin.readline().rstrip("\r\n")

                if input == "h":
                    if not self.current_call:
                        print "There is no call"
                        continue
                    self.current_call.hangup()
                    self.reset_all()

                elif input == "q":
                    break

            # shutdown the library
            transport = None

            self.lib.destroy()
            self.lib = None

        except pj.Error, e:
            print "Exception: " + str(e)
            self.lib.destroy()
            lib = None
Esempio n. 9
0
def register_account(lib, proxy, username, password):
    """Register on proxy with given username and password"""
    acc = lib.create_account(pj.AccountConfig(proxy, username, password))
    acc.reg_timeout = REGISTER_TIMEOUT

    acc_cb = AccountCallback(acc)
    acc.set_callback(acc_cb)
    acc_cb.wait()
    return acc, acc_cb
Esempio n. 10
0
    def register(self, login, server, password, realm="*"):
        config = pj.AccountConfig()
        config.id = "sip:" + login + "@" + server
        config.reg_uri = "sip:" + server + ";transport=tcp"

        config.auth_cred = [pj.AuthCred(realm, login, password)]

        account_callback = NoopAccountCallback()
        self.account = self.pjsip.create_account(config, cb=account_callback)
        account_callback.wait()
Esempio n. 11
0
    def register(self,
                 server,
                 port,
                 username,
                 password,
                 default_account=False,
                 proxy=None,
                 protocol='UDP',
                 bind_address='127.0.0.1',
                 bind_port=0):
        """ Register an account at i.e. Asterisk PBX, and set network transport options.
            Returns: Account registered, account callback handler.
        """
        if protocol == 'UDP': protocol = pj.TransportType.UDP
        elif protocol == 'TCP': protocol = pj.TransportType.TCP
        elif protocol == 'TLS': protocol = pj.TransportType.TLS
        else: logger.info(f"Error: Invalid protocol type.")

        logger.info("Creating transport and generating SIP URI.")
        transport = self.lib.create_transport(
            protocol,
            pj.TransportConfig(
                0
            )  # TransportConfig(host=bind_address, port=bind_port) # TODO: Add bind_address and bind_port here.
        )

        public_sip_uri = f"sip:{username}@{str(transport.info().host)}:{str(transport.info().port)}"
        logger.info(
            f"Listening on {transport.info().host}:{transport.info().port} for {public_sip_uri}."
        )
        logger.info(
            f"Attempting registration for {public_sip_uri} at {server}:{port}."
        )

        account_cfg = pj.AccountConfig(domain=server + ":" + port,
                                       username=username,
                                       password=password)

        account_cfg.id = public_sip_uri

        account = self.lib.create_account(acc_config=account_cfg,
                                          set_default=default_account)
        account.set_transport(transport)

        account_handler = AccountHandler(lib=self.lib, account=account)
        account.set_callback(account_handler)

        logger.info(f"Waiting for registration...")
        account_handler.wait()
        logger.info(
            f"Successfully registered {public_sip_uri}, status: {account.info().reg_status} ({account.info().reg_reason})."
        )

        return account
Esempio n. 12
0
def info():
    sIp = raw_input("Enter the server's IP address : ")
    usr = raw_input("Enter user ID/Display name :  ")
    pas = raw_input("Enter your password : "******"sip:" + usr
    a_conf.reg_uri = 'sip:' + sIp + ':5060'
    return a_conf
Esempio n. 13
0
 def modifyacc(self,old_uri,new_uri):
     if not old_uri in self.created.iterkeys():
         return None
     acc_id=self.created[old_uri]._id
     
     uri=pj.SIPUri(new_uri)
     domain=uri.host
     if uri.port==0:
         domain="%s:5060"%domain
     else:
         domain="%s:%s"%(domain,uri.port)
     extern=uri.user
     password=uri.user
     self.lib.modify_account(acc_id,pj.AccountConfig(domain=domain,username=extern,password=password))
Esempio n. 14
0
 def register_all(self):
     trans = {}
     accs = []
     for user in self.users:
         uname = user.id + self.BASE_ID
         trans[user.id] = self.lib.create_transport(
             pj.TransportType.UDP, pj.TransportConfig(uname))
         uname = user.id + self.BASE_ID
         conf = pj.AccountConfig(self.SIP_SERVER_IP, str(uname),
                                 self.PASSWORD)
         conf.reg_timeout = 1000000
         conf.ka_interval = 0
         conf.transport_id = trans[user.id]._id
         accs.append(self.lib.create_account(conf))
     return trans, accs
Esempio n. 15
0
def sip_registration(lib, conf_params):
    global acc, common_objects
    lib.init(log_cfg=pj.LogConfig(level=1, callback=log_cb))

    transport = lib.create_transport(pj.TransportType.UDP,
                                     pj.TransportConfig(0))
    lib.start()

    acc = lib.create_account(
        pj.AccountConfig(conf_params['elx_host'], conf_params['sip_user'],
                         conf_params['sip_pass']))

    acc_cb = MyAccountCallback(acc)
    acc.set_callback(acc_cb)
    acc_cb.wait()
Esempio n. 16
0
def create_AccountConfig():
    logger.debug("create_AccountConfig")
    # Doc: http://www.pjsip.org/python/pjsua.htm#AccountConfig
    server = conf.get(SIPPHONE_SECTION, "server")
    username = conf.get(SIPPHONE_SECTION, "username")
    password = conf.get(SIPPHONE_SECTION, "password")
    realm = conf.get(SIPPHONE_SECTION, "realm")

    AccountConfig = pj.AccountConfig()
    AccountConfig.id = "sip:" + username + "@" + server
    AccountConfig.reg_uri = "sip:" + server
    AccountConfig.auth_cred = [pj.AuthCred(realm, username, password)]
    AccountConfig.allow_contact_rewrite = conf.get_bool(
        SIPPHONE_SECTION, 'account.allow_contact_rewrite', 0)
    AccountConfig.reg_timeout = conf.get_int(SIPPHONE_SECTION,
                                             'account.reg_timeout', 10)

    return AccountConfig
Esempio n. 17
0
 def create_account_config(self, transport_type, domain, username,
                           password):
     # make sure that reg_uri has the correct format for TCP
     if 'TCP' == transport_type:
         reg_uri = 'sip:'
         if username:
             reg_uri += username + '@' + domain
         else:
             reg_uri += domain
         reg_uri += ';transport=tcp'
     else:
         reg_uri = ''
     account_config = pj.AccountConfig(domain=domain,
                                       username=username,
                                       password=password,
                                       display='',
                                       registrar=reg_uri)
     return account_config
Esempio n. 18
0
    def reg_attack(self):
        trans = {}
        for user in self.users:
            uname = user.id + self.BASE_ID
            trans[user.id] = self.lib.create_transport(
                pj.TransportType.UDP, pj.TransportConfig(uname))
        while True:
            for user in self.users:
                try:
                    uname = user.id + self.BASE_ID
                    conf = pj.AccountConfig(self.SIP_SERVER_IP, str(uname),
                                            self.PASSWORD)
                    conf.transport_id = trans[user.id]._id
                    acc = self.lib.create_account(conf)
                    acc.delete()
                except Exception, e:
                    print "Exception while registering user:", str(e)

            time.sleep(3)
Esempio n. 19
0
    def setUp(self):
        self.assertTrue(self.AH_Agent.isConnected(),
                        "AH_Agent connection failure")

        if self.lib == None:
            self.lib = pjsua.Lib()

        self.lib.init(log_cfg=pjsua.LogConfig(
            level=0, filename='PJSUA.log', callback=None, console_level=0))
        self.lib.set_null_snd_dev()
        self.lib.create_transport(pjsua.TransportType.UDP,
                                  pjsua.TransportConfig(5060))
        self.lib.start()
        self.acc = self.lib.create_account(
            pjsua.AccountConfig(config.PBX_Host, "test1", "12345"))
        self.assertTrue(self.acc.is_valid(), "invalid account")
        acc_cb = MyAccountCallback(self.acc)
        self.acc.set_callback(acc_cb)
        acc_cb.wait()

        self.assertTrue(acc_cb.account.info().reg_status >= 200,
                        "Could not register")
Esempio n. 20
0
    def __create_account(self, acct_cfg):
        """Create a PJSuaAccount from configuration"""
        name = acct_cfg['name']
        username = acct_cfg.get('username', name)
        domain = acct_cfg.get('domain', '127.0.0.1')
        password = acct_cfg.get('password', '')

        pj_acct_cfg = pj.AccountConfig(domain, username, password, name)
        if acct_cfg.get('mwi-subscribe'):
            pj_acct_cfg.mwi_enabled = 1
        if acct_cfg.get('transport'):
            acct_transport = acct_cfg.get('transport')
            if acct_transport in self.pj_transports:
                transport_id = self.pj_transports[acct_transport]._id
                pj_acct_cfg.transport_id = transport_id

        LOGGER.info("Creating PJSUA account %s@%s" % (username, domain))
        account = PJsuaAccount(
            self.lib.create_account(pj_acct_cfg, False, RegDetector(self)),
            self.lib)
        account.add_buddies(acct_cfg.get('buddies', []))
        return account
Esempio n. 21
0
 def _create_and_register_account_with_pbx(self):
     """
     Create and register an account for the phone instance with the PBX
     """
     logger.debug(
         "[{}] Creating account with domain = {}, username = {} and password = {}"
         .format(self.pbx_account_name, self.pbx_ip, self.pbx_account_name,
                 self.pbx_password))
     account = pj.AccountConfig(self.pbx_ip, self.pbx_account_name,
                                self.pbx_password)
     self.account = self.lib.create_account(
         account,
         cb=IncomingCallCallback(
             account,
             self,
             action_on_incoming_call=self.action_on_incoming_call,
             audio_playback_file=self.answer_audio,
             loop=self.loop))
     logger.log(
         5, "[{}] Registration info - {}".format(self.pbx_account_name,
                                                 vars(self.account.info())))
     logger.info("[{}] Account created".format(self.pbx_account_name))
Esempio n. 22
0
    lib.init(log_cfg=pj.LogConfig(level=LOG_LEVEL, callback=log_callback))

    # Configuring one Transport Object
    tran_conf = pj.TransportConfig()
    tran_conf.bound_addr = "192.168.100.50"  # IP address of PJSIP client
    transport = lib.create_transport(pj.TransportType.UDP,
                                     pj.TransportConfig(0))
    print "\nListening on", transport.info().host, "\n"

    # Start library
    lib.start()

    # Configuring Account class to register with Registrar server
    acc_conf = pj.AccountConfig(domain='192.168.100.50',
                                username='******',
                                password='******',
                                display='2050',
                                registrar='sip:192.168.100.1',
                                proxy='sip:192.168.100.1')
    acc_conf.id = "sip:2050"
    acc_conf.reg_uri = "sip:192.168.100.1"

    # Creating account
    acc = lib.create_account(acc_conf)
    cb = MyAccountCallback(acc)
    acc.set_callback(cb)

    if len(sys.argv) > 1:
        lck = lib.auto_lock()
        curr_call = make_call(sys.argv[1])
        print 'Current call is', curr_call
        del lck
        self.sem.acquire()

    def on_reg_state(self):
        if self.sem:
            if self.account.info().reg_status >= 200:
                self.sem.release()


lib = pj.Lib()

try:
    lib.init(log_cfg=pj.LogConfig(level=4, callback=log_cb))
    lib.create_transport(pj.TransportType.UDP, pj.TransportConfig(5080))
    lib.start()

    acc = lib.create_account(pj.AccountConfig("pjsip.org", "bennylp", "***"))

    acc_cb = MyAccountCallback(acc)
    acc.set_callback(acc_cb)
    acc_cb.wait()

    print("\n")
    print("Registration complete, status=", acc.info().reg_status, \
          "(" + acc.info().reg_reason + ")")
    print("\nPress ENTER to quit")
    sys.stdin.readline()

    lib.destroy()
    lib = None

except pj.Error as e:
Esempio n. 24
0
    if channel_count != -1:
        media_cfg.channel_count = channel_count

    media_cfg.no_vad = no_vad

    lib.init(ua_cfg, loging_cfg, media_cfg)

    lib.set_snd_dev(audio_dev_in, audio_dev_out)

    my_transport_cfg = pj.TransportConfig()
    my_transport_cfg.port = rtp_port
    transport = lib.create_transport(pj.TransportType.UDP, my_transport_cfg)

    lib.start()

    my_account_cfg = pj.AccountConfig(sip_registrar, user, password)
    acc = lib.create_account(my_account_cfg)

    acc_cb = MyAccountCallback(acc)
    acc.set_callback(acc_cb)
    acc_cb.wait()

    log("Registration complete, status=" + str(acc.info().reg_status) + "(" +
        str(acc.info().reg_reason) + ")")

    os.system("/usr/bin/mm_generate_voice_mail_theme_list &")

    if interactive:

        while True:
            print "\n\nMenu:\n  m=make call\n  h=hangup call\n  a=answer call\n  v=voice-mail\n  q=quit\n\n"
Esempio n. 25
0
    def __init__(self):
        super( Example,self ).__init__()
         
        self.initUI()
        lib = pj.Lib()

        current_call = None

        my_ua_cfg = pj.UAConfig()
        my_ua_cfg.nameserver = ['8.8.8.8', '8.8.4.4']
        my_ua_cfg.user_agent = "hanxiaotian_bupt"
        # http://www.pjsip.org/python/pjsua.htm#MediaConfig
        my_media_cfg = pj.MediaConfig()
        my_media_cfg.enable_ice = True
    
        #
        # Procedure: Initialize > Create Transpot > Start > Handle calls > Shutdown
        #

        # https://trac.pjsip.org/repos/wiki/Python_SIP/Settings#StartupandShutdown
        # Initialize the Library
        lib.init(ua_cfg=my_ua_cfg, media_cfg=my_media_cfg, log_cfg = pj.LogConfig(level=3, callback=log_cb))
    
        # Create One or More Transports
        transport = lib.create_transport(pj.TransportType.TCP, pj.TransportConfig())
        #transport = lib.create_transport(pj.TransportType.UDP, pj.TransportConfig(0))
        #transport = lib.create_transport(pj.TransportType.TLS, pj.TransportConfig(port=5060)) # SSL
        lib.set_null_snd_dev()

        # Starting the Library
        lib.start()
        lib.handle_events()

        #
        # Registration
        #
        acc_cfg = pj.AccountConfig()
        succeed = 0
        while (succeed == 0):
            print "---------------------------------------------------------------------"
            acc_cfg.id = "sip:[email protected]"
            # 
            acc_cfg.reg_uri  = "sip:10.103.241.142;transport=tcp"
            #
            acc_cfg.proxy = [] 
       
            server = "10.103.241.142"
            acc_cfg.proxy = [ "sip:10.103.241.142;transport=tcp;lr" ]
            #
            realm = "han"
            #
            username = "******"
            #
            passwd = "101"
            print "---------------------------------------------------------------------"
    
            acc_cfg.auth_cred = [pj.AuthCred(realm, username ,passwd)]
            
            self.acc_cb = MyAccountCallback()
            self.acc = lib.create_account(acc_cfg, cb=self.acc_cb)
            self.acc_cb.wait()
    
            # Conditions are not correct, because when "IP address change detected for account", all other accounts is Forbidden
            if ((str(self.acc.info().reg_status) == "200") or (str(self.acc.info().reg_status) == "403")):
                succeed = 1
            else:
                print ""
                print "Registration failed, status=", self.acc.info().reg_status, \
                  "(" + self.acc.info().reg_reason + ")"
                print ""
                print "Please try again !"
Esempio n. 26
0
    call_slot = None


lib = pj.Lib()

try:
    mediaconfig = pj.MediaConfig()
    mediaconfig.quality = 10
    lib.init(log_cfg=pj.LogConfig(
        level=4, callback=log_cb), media_cfg=mediaconfig)
    transport = lib.create_transport(
        pj.TransportType.UDP, pj.TransportConfig())
    lib.start()

    # Put your sIP client credentials here
    acc = lib.create_account(pj.AccountConfig(
        "10.208.209.59", "1000", "1000"))

    acc_cb = MyAccountCallback(acc)
    acc.set_callback(acc_cb)
    acc_cb.wait()

    print "\n"
    print "Registration complete, status=", acc.info().reg_status, \
          "(" + acc.info().reg_reason + ")"

    if len(sys.argv) > 1:
        lck = lib.auto_lock()

    my_sip_uri = "sip:" + transport.info().host + \
                 ":" + str(transport.info().port)
Esempio n. 27
0
        print "Details of encountered exception in making call: " + str(e)
        return None


#Main : Program starts here
#Library instance is created for lib class
lib = pj.Lib()

try:
    lib.init(log_cfg=pj.LogConfig(level=Log_Value, callback=log_callback))
    transport = lib.create_transport(pj.TransportType.UDP,
                                     pj.TransportConfig(0))
    lib.start()

    account_C = lib.create_account(
        pj.AccountConfig("192.168.137.1", "2020", "password"))
    acc_cb = CallbckforAccount(account_C)
    account_C.set_callback(acc_cb)
    print "\n"
    print "Status of the completed Registration =", account_C.info(
    ).reg_status, "(" + account_C.info().reg_reason + ")"

    if len(sys.argv) > 1:
        lck = lib.auto_lock()
        on_call = connect_call(sys.argv[1])
        print 'Current call is', on_call
        del lck

    uri_sip_curr = "Current SIP URI:" + transport.info().host + ":" + str(
        transport.info().port)
Esempio n. 28
0
transport = lib.create_transport(pj.TransportType.UDP,trans_conf)



# Instatiation of library class lib.start() lib.set_null_snd_dev()


# Giving information to create header of REGISTER SIP message


pq4=raw_input("Enter IP address of the Server: ") pq=raw_input("Enter Username: "******"Enter Password: "******"Do you want to display name as the username Y/N ??") if pq2=="y" or pq2=="Y":
  pq3=pq else:
pq3=raw_input("Enter Display Name: ")

config_acc= pj.AccountConfig(domain = pq4, username = pq, password =pq1, display = pq3) # registrngar = 'sip:'+p4+':5060', proxy = 'sip:'+pq4+':5060')


config_acc.id ="sip:"+pq config_acc.reg_uri ='sip:'+pq4+':5060'
acc_callback = My_Acnt_Clbck(acc_conf)

acc = lib.create_account(acc_conf,cb=acc_callback)



# creating instance of Acnt_Clbck class acc.set_callback(acc_callback)


print('\n')
print "Registrngation Complete-----------" print('Status= ',acc.info().reg_status, \
Esempio n. 29
0
            },
            doc_ids=[1])

    # If there's no username or password
    elif len(password) < 1 or len(username) < 1:
        tick.update(
            {
                'Error':
                "URI Verification Status: " + str(uri_check) +
                "\nInvalid URI, please check your SIP username/password."
            },
            doc_ids=[1])

    # SIP register
    acc_cfg = pj.AccountConfig(domain=domain,
                               username=username,
                               password=password)

    # Create account with user
    acc = lib.create_account(acc_config=acc_cfg)
    account_info = acc.info()

    # print account_info
    # print "reg_active: " + str(account_info.reg_active)
    # print 'online_text: ' + str(account_info.online_text)
    # print 'online_status: ' + str(account_info.online_status)
    # print 'reg_expires: ' + str(account_info.reg_expires)
    # print 'reg_status: ' + str(account_info.reg_status)

    if not (account_info.reg_status == 100):
        tick.update(
Esempio n. 30
0
    # Create library instance
    lib = pj.Lib()

    # Init library with default config
    lib.init(log_cfg=pj.LogConfig(level=3, callback=log_cb))

    transportConfig = pj.TransportConfig()
    transportConfig.port = 5080

    # Create UDP transport which listens to any available port
    transport = lib.create_transport(pj.TransportType.UDP, transportConfig)

    # Start the library
    lib.start()

    acc_cfg = pj.AccountConfig()
    acc_cfg.id = "%s" % sipId
    acc_cfg.reg_uri = "%s" % sipRegUrl
    acc_cfg.proxy = ["%s" % sipProxy]
    acc_cfg.auth_cred = [pj.AuthCred("*", "%s" % sipUser, "%s" % sipPassword)]

    acc_ck = CallbackAccount()
    acc = lib.create_account(acc_cfg, cb=acc_ck)

    # Wait for ENTER before quitting
    print "Press <ENTER> to quit"
    input = sys.stdin.readline().rstrip("\r\n")

    # We're done, shutdown the library
    lib.destroy()
    lib = None