Stefan Sayer writes:

> > yes, using pua_publish mi function provided by pua_mi module.
> care to share some sample code?

sure, see below.  it is specific to my environment, but the idea should
be clear.  improvement ideas are welcome.

-- juha

----------------------------------------------------------------------

    def sendPublish(self):

        if self.PS_MGMT_URI == '':
            return

        c = xmlrpclib.ServerProxy(self.PS_MGMT_URI)
        
        def parseMySQLuser(MySQLuser):
            (mysql, user, rest) = MySQLuser.split(':')
            user = user.lstrip('/')
            (passwd, rest) = rest.split('@')
            (host, db) = rest.split('/')
            return (user, host, passwd, db)

        (user, host, passwd, db) = parseMySQLuser(self.mysql_user)

        username = self.dialog.user
        domain = self.dialog.domain
        mailbox = username + "@" + domain
        uri = "sip:" + mailbox

        msgs = self.loadMsgs()
        if self.msgs == None:
            self.sendBye()
            return

        unseen = len(filter(new, msgs))
        seen = len(filter(saved, msgs))

        if unseen > 0:
            body = "Messages-Waiting: yes\n\nVoice-Message: %d/%d (0/0)\n\n" % 
(unseen, seen)
        else:
            body = "Messages-Waiting: no\n\nVoice-Message: %d/%d (0/0)\n\n" % 
(unseen, seen)

        try:
            db = MySQLdb.connect(host=host, user=user, passwd=passwd, db=db)
        except MySQLdb.Error, e:
            error(APPLICATION + ": cannot open database: " +\
                  str(e.args[0]) + ":" + e.args[1])
            return

        cursor = db.cursor()

        try:

            cursor.execute("SELECT etag FROM presentity WHERE username=%s AND 
domain=%s ORDER BY received_time DESC",
                           (username, domain))
            if cursor.rowcount == 0:
                etag = "."
            else:
                etag = cursor.fetchone()[0]
            debug(APPLICATION + ": ETag of mailbox <%s> is <%s>" %
                  (mailbox, etag))

            result = None

            try:
                result = c.pua_publish(uri, EXPIRES, EVENT_PACKAGE,
                                       CONTENT_TYPE, etag, EXTRA_HEADERS, body)
            except xmlrpclib.Fault, v:
                error(APPLICATION + ": xmlrpc server error %d: %s" %
                      (v.faultCode, v.faultString))
                try:
                    result = c.pua_publish(uri, EXPIRES, EVENT_PACKAGE,
                                           CONTENT_TYPE, ".", EXTRA_HEADERS,
                                           body)
                except xmlrpclib.Fault, v:
                    error(APPLICATION + ": xmlrpc server error %d: %s" %
                          (v.faultCode, v.faultString))
                except:
                    error(APPLICATION + ": system error error: type " +\
                          str(sys.exc_info()[0]))
            except:
                error(APPLICATION + ": system error error: type " + 
str(sys.exc_info()[0]))

            debug(APPLICATION + ": publish result for mailbox <%s>" % result)

        except MySQLdb.Error, e:
            error(APPLICATION + ": MySQL error %d: %s" %
                  (e.args[0], e.args[1]))

        cursor.close()
        db.close()
        return
_______________________________________________
Sems mailing list
[email protected]
http://lists.iptel.org/mailman/listinfo/sems

Reply via email to