#include #include #include #include #include #include #include #include #include #include #include #include #include void MUCSetKey(XMPPCommandManager *m, char *from, XMLElement *form, XMLElement *out, char *node) { ParseeData *data = XMPPGetManagerCookie(m); char *affiliation, *role; char *chat_id; char *muc; char *key = NULL, *val = NULL; ParseeLookupAffiliation(from, &affiliation, &role); Free(role); if (!StrEquals(affiliation, "owner")) { SetNote("error", "Setting MUC properties requires the 'owner' affiliation."); Free(affiliation); return; } GetFieldValue(key, "key", form); GetFieldValue(val, "val", form); if (!key || !val) { SetNote("error", "No keys or no value given."); goto end; } muc = ParseeTrimJID(from); chat_id = ParseeGetFromMUCID(data, muc); ParseeSetChatSetting(data, chat_id, key, val); SetNote("info", "Set key-value pair!"); end: Free(affiliation); Free(chat_id); Free(muc); (void) form; (void) node; } void MUCGetKeys(XMPPCommandManager *m, char *from, XMLElement *form, XMLElement *out, char *node) { ParseeData *data = XMPPGetManagerCookie(m); char *affiliation = NULL, *role = NULL; char *chat_id = NULL; char *muc = NULL; XMLElement *x; XMLElement *title; XMLElement *reported, *item, *field, *value, *txt; HashMap *settings = NULL; ParseeLookupAffiliation(from, &affiliation, &role); Free(role); if (!StrEquals(affiliation, "owner")) { SetNote("error", "Getting MUC roperties requires the 'owner' affiliation."); goto end; } muc = ParseeTrimJID(from); chat_id = ParseeGetFromMUCID(data, muc); settings = ParseeGetChatSettings(data, chat_id); x = XMLCreateTag("x"); title = XMLCreateTag("title"); SetTitle(x, "MUC/room settings"); XMLAddChild(x, title); XMLAddAttr(x, "xmlns", "jabber:x:data"); XMLAddAttr(x, "type", "result"); { char *key, *val; reported = XMLCreateTag("reported"); XMLAddChild(x, reported); /* Report */ Report("key", "Setting's key"); Report("val", "Setting's value"); /* Set */ while (HashMapIterate(settings, &key, (void **) &val)) { BeginItem(); SetField("key", key); SetField("val", val); EndItem(); } } XMLAddChild(out, x); end: ParseeFreeChatSettings(settings); Free(affiliation); Free(chat_id); Free(muc); (void) form; (void) node; }