Esempio n. 1
0
 def _NH_SIPEngineGotMessage(self, notification):
     # THIS DOESN'T WORK! Don't need it though for now
     # Receives and processes messages from SIP
     content_type = notification.data.content_type
     if content_type not in ('text/plain', 'text/html'):
         return
     from_header = FromHeader.new(notification.data.from_header)
     from_header.parameters = {}
     from_header.uri.parameters = {}
     identity = str(from_header.uri)
     if from_header.display_name:
         identity = '"%s" <%s>' % (from_header.display_name, identity)
     body = notification.data.body
     self.output.put("Got MESSAGE from '%s', Content-Type: %s\n%s\n" %
                     (identity, content_type, body))
Esempio n. 2
0
 def _NH_SIPSubscriptionGotNotify(self, notification):
     if notification.data.content_type == PIDFDocument.content_type:
         self.output.put('\nReceived NOTIFY:')
         try:
             pidf = PIDF.parse(notification.data.body)
         except ParserError, e:
             self.output.put('Got illegal PIDF document: %s\n%s' %
                             (str(e), notification.data.body))
         else:
             from_header = FromHeader.new(notification.data.from_header)
             extension = str(from_header.uri.user)
             status = self._display_pidf(pidf).lower()
             self.statusdict[extension] = status
             if (notification.sender.route_header):
                 route = Route(
                     notification.sender.route_header.uri.host,
                     notification.sender.route_header.uri.port,
                     notification.sender.route_header.uri.parameters.get(
                         'transport', 'udp'))
                 datajson = {
                     "data": json.dumps(self.statusdict)
                 }  # This is no longer used as the presences are pulled from the DB
                 newjson = json.dumps({
                     "to": "all",
                     "type": "statusupdate",
                     'data': extension
                 })
                 if (
                         datajson != self.lastmessage
                 ):  # makes sure stuff doesn't happen multiple times from multiple same notifies
                     if (self.commandsystemenabled):
                         self._send_message(
                             self.account.uri, newjson, route
                         )  # sends a statusupdate sip command if the system is enabled
                     self.db.updatePresence(extension, status)
                     self.lastmessage = datajson