From e8089ba3448724a08acb13fd17475f62cd3ef2c0 Mon Sep 17 00:00:00 2001 From: defanor Date: Thu, 2 Apr 2020 03:50:20 +0300 Subject: Check JIDs in IQ replies --- src/rexmpp.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/rexmpp.c b/src/rexmpp.c index 050f86b..391364f 100644 --- a/src/rexmpp.c +++ b/src/rexmpp.c @@ -1337,7 +1337,16 @@ void rexmpp_process_element (rexmpp_t *s) { int found = 0; while (req != NULL && found == 0) { char *req_id = xmlGetProp(req->request, "id"); - if (strcmp(id, req_id) == 0) { + char *req_to = xmlGetProp(req->request, "to"); + char *rep_from = xmlGetProp(elem, "from"); + int id_matches = (strcmp(id, req_id) == 0); + int jid_matches = 0; + if (req_to == NULL && rep_from == NULL) { + jid_matches = 1; + } else if (req_to != NULL && rep_from != NULL) { + jid_matches = (strcmp(req_to, rep_from) == 0); + } + if (id_matches && jid_matches) { found = 1; if (req->cb != NULL) { char *iq_type = xmlGetProp(elem, "type"); @@ -1367,6 +1376,12 @@ void rexmpp_process_element (rexmpp_t *s) { xmlFreeNode(req->request); free(req); } + if (req_to != NULL) { + free(req_to); + } + if (rep_from != NULL) { + free(rep_from); + } free(req_id); req = req->next; } -- cgit v1.2.3