mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-13 15:15:10 +00:00
This is still unstable(and I still need to design/document the exposed API)! Do(n't) go and use it!
119 lines
2.8 KiB
C
119 lines
2.8 KiB
C
|
|
#include <Cytoplasm/HashMap.h>
|
|
#include <Cytoplasm/Memory.h>
|
|
#include <Cytoplasm/Json.h>
|
|
#include <Cytoplasm/Util.h>
|
|
#include <Cytoplasm/Str.h>
|
|
#include <Cytoplasm/Log.h>
|
|
|
|
#include <XMPPFormTool.h>
|
|
#include <XMPPCommand.h>
|
|
#include <Matrix.h>
|
|
#include <Parsee.h>
|
|
#include <XMPP.h>
|
|
#include <XML.h>
|
|
#include <AS.h>
|
|
|
|
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;
|
|
}
|