Mercurial > libervia-backend
comparison sat/core/xmpp.py @ 3197:f4a28767ec35
core (xmpp): check that entity_jid is actually a jid in SatRosterProtocol.isJidInRoster
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 01 Mar 2020 18:29:46 +0100 |
parents | adf1aeaa0d37 |
children | fee8e33e2b3f |
comparison
equal
deleted
inserted
replaced
3196:adf1aeaa0d37 | 3197:f4a28767ec35 |
---|---|
1008 | 1008 |
1009 def __init__(self, host): | 1009 def __init__(self, host): |
1010 xmppim.MessageProtocol.__init__(self) | 1010 xmppim.MessageProtocol.__init__(self) |
1011 self.host = host | 1011 self.host = host |
1012 | 1012 |
1013 @property | |
1014 def client(self): | |
1015 return self.parent | |
1016 | |
1013 def parseMessage(self, message_elt): | 1017 def parseMessage(self, message_elt): |
1014 """Parse a message XML and return message_data | 1018 """Parse a message XML and return message_data |
1015 | 1019 |
1016 @param message_elt(domish.Element): raw <message> xml | 1020 @param message_elt(domish.Element): raw <message> xml |
1017 @param client(SatXMPPClient, None): client to map message id to uid | 1021 @param client(SatXMPPClient, None): client to map message id to uid |
1139 attachment["name"] = name | 1143 attachment["name"] = name |
1140 if C.MESS_KEY_ATTACHMENTS_MEDIA_TYPE not in attachment: | 1144 if C.MESS_KEY_ATTACHMENTS_MEDIA_TYPE not in attachment: |
1141 media_type = mimetypes.guess_type(attachment['name'], strict=False)[0] | 1145 media_type = mimetypes.guess_type(attachment['name'], strict=False)[0] |
1142 if media_type: | 1146 if media_type: |
1143 attachment[C.MESS_KEY_ATTACHMENTS_MEDIA_TYPE] = media_type | 1147 attachment[C.MESS_KEY_ATTACHMENTS_MEDIA_TYPE] = media_type |
1148 | |
1144 return data | 1149 return data |
1145 | 1150 |
1146 def skipEmptyMessage(self, data): | 1151 def skipEmptyMessage(self, data): |
1147 if not data["message"] and not data["extra"] and not data["subject"]: | 1152 if not data["message"] and not data["extra"] and not data["subject"]: |
1148 raise failure.Failure(exceptions.CancelError("Cancelled empty message")) | 1153 raise failure.Failure(exceptions.CancelError("Cancelled empty message")) |
1429 """Return all jids of the roster""" | 1434 """Return all jids of the roster""" |
1430 return list(self._jids.keys()) | 1435 return list(self._jids.keys()) |
1431 | 1436 |
1432 def isJidInRoster(self, entity_jid): | 1437 def isJidInRoster(self, entity_jid): |
1433 """Return True if jid is in roster""" | 1438 """Return True if jid is in roster""" |
1439 if not isinstance(entity_jid, jid.JID): | |
1440 raise exceptions.InternalError( | |
1441 f"a JID is expected, not {type(entity_jid)}: {entity_jid!r}") | |
1434 return entity_jid in self._jids | 1442 return entity_jid in self._jids |
1435 | 1443 |
1436 def isPresenceAuthorised(self, entity_jid): | 1444 def isPresenceAuthorised(self, entity_jid): |
1437 """Return True if entity is authorised to see our presence""" | 1445 """Return True if entity is authorised to see our presence""" |
1438 try: | 1446 try: |