Mercurial > libervia-pubsub
comparison src/mam.py @ 398:845ed0f71dd6
mam: don't crash on missing <first> element in RSM on archive request
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 11 Mar 2019 20:50:54 +0100 |
parents | 66fbf026ed49 |
children | 2521c53bc359 |
comparison
equal
deleted
inserted
replaced
397:a4980d03b3a3 | 398:845ed0f71dd6 |
---|---|
86 ext_data['rsm'] = mam_request.rsm | 86 ext_data['rsm'] = mam_request.rsm |
87 | 87 |
88 if mam_request.orderBy: | 88 if mam_request.orderBy: |
89 ext_data['order_by'] = mam_request.orderBy | 89 ext_data['order_by'] = mam_request.orderBy |
90 | 90 |
91 d = self.backend.getItemsData(mam_request.node, mam_request.sender, mam_request.recipient, None, None, ext_data) | 91 d = self.backend.getItemsData(mam_request.node, mam_request.sender, |
92 mam_request.recipient, None, None, ext_data) | |
92 | 93 |
93 def make_message(elt): | 94 def make_message(elt): |
94 # XXX: http://xmpp.org/extensions/xep-0297.html#sect-idp629952 (rule 3) | 95 # XXX: http://xmpp.org/extensions/xep-0297.html#sect-idp629952 (rule 3) |
95 message = domish.Element((const.NS_CLIENT, "message")) | 96 message = domish.Element((const.NS_CLIENT, "message")) |
96 event = message.addElement((pubsub.NS_PUBSUB_EVENT, "event")) | 97 event = message.addElement((pubsub.NS_PUBSUB_EVENT, "event")) |
105 attributes = {} | 106 attributes = {} |
106 for item_data in items_data: | 107 for item_data in items_data: |
107 if item_data.item.name == 'set' and item_data.item.uri == rsm.NS_RSM: | 108 if item_data.item.name == 'set' and item_data.item.uri == rsm.NS_RSM: |
108 assert rsm_elt is None | 109 assert rsm_elt is None |
109 rsm_elt = item_data.item | 110 rsm_elt = item_data.item |
110 # XXX: we check if it is the last page using initial request data | 111 if rsm_elt.first: |
111 # and RSM element data. In this case, we must have the "complete" | 112 # XXX: we check if it is the last page using initial request data |
112 # attribute set to "true". | 113 # and RSM element data. In this case, we must have the |
113 page_max = (int(rsm_elt.first['index']) + 1) * mam_request.rsm.max | 114 # "complete" |
114 count = int(unicode(rsm_elt.count)) | 115 # attribute set to "true". |
115 if page_max >= count: | 116 page_max = (int(rsm_elt.first['index']) + 1) * mam_request.rsm.max |
116 # the maximum items which can be displayed is equal to or above | 117 count = int(unicode(rsm_elt.count)) |
117 # the total number of items, which means we are complete | 118 if page_max >= count: |
118 attributes['complete'] = "true" | 119 # the maximum items which can be displayed is equal to or |
120 # above the total number of items, which means we are complete | |
121 attributes['complete'] = "true" | |
122 else: | |
123 log.warnign(u"no <first> element in RSM request: {xml}".format( | |
124 xml = rsm_elt.toXml())) | |
119 elif item_data.item.name == 'item': | 125 elif item_data.item.name == 'item': |
120 msg_data.append([item_data.item['id'], make_message(item_data.item), item_data.created]) | 126 msg_data.append([item_data.item['id'], make_message(item_data.item), |
127 item_data.created]) | |
121 else: | 128 else: |
122 log.msg("WARNING: unknown element: {}".format(item_data.item.name)) | 129 log.msg("WARNING: unknown element: {}".format(item_data.item.name)) |
123 if pep: | 130 if pep: |
124 # we need to send privileged message | 131 # we need to send privileged message |
125 # so me manage the sending ourself, and return | 132 # so me manage the sending ourself, and return |