#include #include #include #include #include #include #include bool XMPPQueryMUC(XMPPComponent *jabber, char *muc, MUCInfo *out) { XMLElement *iq_query, *query; char *uuid, *from; if (!jabber || !muc) { return false; } pthread_mutex_lock(&jabber->write_lock); iq_query = XMLCreateTag("iq"); query = XMLCreateTag("query"); XMLAddAttr(iq_query, "from",(from = StrConcat(2,"parsee@",jabber->host))); XMLAddAttr(iq_query, "to", muc); XMLAddAttr(iq_query, "id", (uuid = StrRandom(8))); XMLAddAttr(iq_query, "type", "get"); XMLAddAttr(query, "xmlns", "http://jabber.org/protocol/disco#info"); XMLAddChild(iq_query, query); Free(from); { XMLElement *identity; XMLEncode(jabber->stream, iq_query); StreamFlush(jabber->stream); XMLFreeElement(iq_query); /* Except an IQ reply. 10 seconds of timeout is pretty * generous, if you ask me. */ iq_query = ParseeAwaitStanza(uuid, 10 SECONDS); Free(uuid); if (!iq_query || !StrEquals(iq_query->name, "iq")) { XMLFreeElement(iq_query); pthread_mutex_unlock(&jabber->write_lock); return false; } query = XMLookForUnique(iq_query, "query"); identity = XMLookForUnique(query, "identity"); if (!identity || !StrEquals(HashMapGet(identity->attrs, "category"), "conference")) { XMLFreeElement(iq_query); pthread_mutex_unlock(&jabber->write_lock); return false; } /* We found a MUC! */ if (out) { out->exists = true; out->jabber = jabber; out->iq_reply = iq_query; } else { XMLFreeElement(iq_query); } } pthread_mutex_unlock(&jabber->write_lock); return true; } void XMPPFreeMUCInfo(MUCInfo info) { if (!info.exists) { return; } XMLFreeElement(info.iq_reply); info.exists = false; } char * XMPPGetMUCName(MUCInfo info) { XMLElement *query, *identity; char *name; if (!info.exists) { return NULL; } query = XMLookForUnique(info.iq_reply, "query"); identity = XMLookForUnique(query, "identity"); name = StrDuplicate(HashMapGet(identity->attrs, "name")); return name; }