Multiple Account Callback in Python

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

I am experiencing weird things.
I need to have multiple account (75), each with its own callback.
The problem is when ever a callback happens, it is always from the last
account initialized.
here is the SIP log:


Record-Route: <sip:67.231.8.93;lr;ftag=172.21.1.115338+1+f3490002+618751a1>
Call-ID: 888307DC at 172.21.1.115338
From: <sip:13474064370@xxxxxxxxxxxxxxxxxxxx
>;tag=172.21.1.115338+1+f3490002+618751a1
To: <sip:13477566641 at bandwidth.nextamh.syniverse.com
>;tag=z9hG4bKe37a.308f9c25.0
CSeq: 373023929 MESSAGE
Content-Length:  0


--end msg--

2011-09-10 05:58:22 DEBUG: receive message from
sip:+13477566607 at 184.72.120.210:5060
2011-09-10 05:58:22 DEBUG: ('from_uri: ', '<
sip:13474064370 at synsms.bandwidth.com>')
2011-09-10 05:58:22 DEBUG: ('contact: ', ' ')
2011-09-10 05:58:22 DEBUG: ('account.info().uri: ', '+13477566607')
2011-09-10 05:58:22 DEBUG: ('mime_type: ', 'text/plain')
2011-09-10 05:58:22 DEBUG: ('body: ', 'Duuu')


if you see the TO from the log and then from the account.info().uri
(contact)

the problem is the latest initialized account gets all the callback
1: if I send sms to account 1 and then account 2
2: if account 1 answer it goes to the callback of account2

and BuddyCallback never gets called either ..

here is the message class handling the thingy, and its called with
Message(lib)


class Message(object):
    @staticmethod
    def init(lib):
        Message.accounts = {}
        Message.buddies = {}
        Message.lib = lib

    @staticmethod
    def getaccount(longcode=0):
        logging.info("getting account")
        account = Message.accounts.get(longcode)
        if not account:
            logging.info("no account yet, creating one with longcode = %s "
% str(longcode) )
            acc_cfg = pj.AccountConfig()
            acc_cfg.id = "sip:%s@%s" % (str(longcode), SIPBOXADDR)
            id_domain = "sip:%s@%s" % (str(longcode), '
bandwidth.nextamh.syniverse.com')
            acc_cfg.force_contact = id_domain
            acc_cfg.allow_contact_rewrite = True
            account = Message.lib.create_account(acc_cfg, cb =
MyAccountCallback())
            Message.accounts[longcode] = account
            logging.debug("account created with: %s " % str(acc_cfg))
        return account

    @staticmethod
    def createSIPmessage(msisdn, text, sender):
        logging.debug("creating message with: %s  %s %s" % (msisdn, text,
sender))
        longcode = Mapping.getlongcode(sender)
        acc = Message.getaccount(longcode)
        sipaddress = "sip:+%s@%s" % (msisdn.strip(), BANDWIDTHIP)
        try:
            logging.debug("adding a buddy %s" % str(sipaddress))
            buddy = Message.buddies.get(longcode)
            if not buddy:
                logging.debug("Creating new buddy")
                cb = MyBuddyCallback()
                buddy = acc.add_buddy(sipaddress, cb)

            logging.debug("Sending message to %s" % str(buddy.info()))
            logging.debug("uri: %s" % str(buddy.info().uri))
            logging.debug("contact:  %s" % str(buddy.info().contact))
            logging.debug("online_status: %s" % str(buddy.info
().online_status))
            logging.debug("online_next: %s" % str(buddy.info().online_text))
            logging.debug("activity: %s" % str(buddy.info().activity))
            logging.debug("subscribed: %s" % str(buddy.info().subscribed))
            logging.debug("sub_state: %s" % str(buddy.info().sub_state))
            logging.debug("sub_term_reason: %s " % str(buddy.info
().sub_term_reason))
            lck = lib.auto_lock()
            send = buddy.send_pager(text)
            Message.buddies[longcode] = buddy
            del lck
            return send



thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pjsip.org/pipermail/pjsip_lists.pjsip.org/attachments/20110910/8c9ee1dd/attachment.html>


[Index of Archives]     [Asterisk Users]     [Asterisk App Development]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [Linux API]
  Powered by Linux