[ADD] No-fly, forms

This commit is contained in:
LDA 2024-07-14 11:42:30 +02:00
commit df394172ec
11 changed files with 338 additions and 52 deletions

View file

@ -10,7 +10,7 @@
typedef struct XMPPCommandManager XMPPCommandManager;
typedef struct XMPPCommand XMPPCommand;
typedef struct XMPPOption XMPPOption;
typedef void (*XMPPCmdCallback)(XMPPCommandManager *, char *, HashMap *, XMLElement *);
typedef void (*XMPPCmdCallback)(XMPPCommandManager *, char *, XMLElement *, XMLElement *);
/** Creates a simple XMPP command manager, which routes commands
* with a single-stage form system, with a {cookie}
@ -32,7 +32,7 @@ extern XMLElement * XMPPFormifyCommand(XMPPCommand *cmd);
extern char * XMPPGetCommandNode(XMPPCommand *cmd);
extern char * XMPPGetCommandDesc(XMPPCommand *cmd);
extern bool XMPPCommandRequiresForm(XMPPCommand *cmd);
extern void XMPPExecuteCommand(XMPPCommandManager *m, XMPPCommand *cmd, char *from, XMLElement *to, HashMap *arg_table);
extern void XMPPExecuteCommand(XMPPCommandManager *m, XMPPCommand *cmd, char *from, XMLElement *to, XMLElement *form);
/** Create a basic option.
* -----------------------------------------------------
@ -47,11 +47,17 @@ extern XMPPOption * XMPPCreateFixed(char *id, char *text);
extern void XMPPAddListOption(XMPPOption *list, char *option);
extern void XMPPSetDescription(XMPPOption *opt, char *descri);
extern bool XMPPIsOptionRequired(XMPPOption *opt);
extern char * XMPPOptionVar(XMPPOption *opt);
extern XMLElement * XMPPOptionToXML(XMPPOption *opt);
extern void XMPPShoveOptions(XMPPCommand *cmd, XMLElement *form);
extern void XMPPFreeOption(XMPPOption *opt);
extern void XMPPFreeCommand(XMPPCommand *cmd);
extern bool XMPPVerifyForm(XMPPCommand *cmd, XMLElement *form);
/** Registers a {cmd} to the {m}anager, with no extra metadata or callback.
* It also makes {cmd} belong to {m}anager, and therefore does not belong to
* its creator anymore.
@ -87,9 +93,22 @@ extern bool XMPPManageCommand(XMPPCommandManager *m, XMLElement *stanza, ParseeD
#define XMPPCOMMANDS \
XMPP_COMMAND(StatusCallback, "stats", "Get Parsee statistics", {}) \
XMPP_COMMAND(AdminsCallback, "admin", "Get Parsee admin list", {}) \
XMPP_COMMAND(NoflyCallback, "nofly", "Get Parsee nofly list", {})
XMPP_COMMAND(AddAdminCallback, "add-admin", "Adds glob as admin", { \
XMPPOption *glob = XMPPCreateText(true, "glob", ""); \
XMPPSetDescription(glob, "Glob pattern to set as admin"); \
XMPPAddOption(cmd, glob); \
}) \
XMPP_COMMAND(AddNoflyCallback, "add-nofly", "Adds user to nofly", { \
XMPPOption *entity = XMPPCreateText(true, "entity", ""); \
XMPPOption *reason = XMPPCreateText(false, "reason", "Not behaving"); \
XMPPSetDescription(entity, "Entity(glob) to no-fly"); \
XMPPAddOption(cmd, entity); \
XMPPSetDescription(reason, "Reason for the no-fly"); \
XMPPAddOption(cmd, reason); \
}) \
XMPP_COMMAND(NoflyCallback, "nofly", "Get Parsee nofly list", {})
#define XMPP_COMMAND(f,n,t,s) extern void f(XMPPCommandManager *, char *, HashMap *, XMLElement *);
#define XMPP_COMMAND(f,n,t,s) extern void f(XMPPCommandManager *, char *, XMLElement *, XMLElement *);
XMPPCOMMANDS
#undef XMPP_COMMAND
#endif

View file

@ -35,4 +35,36 @@
} \
while(0)
#define GetFieldValue(to, id, form) do \
{ \
XMLElement *field_content = XMLookForTKV(form, "field", "var", id); \
XMLElement *value = XMLookForUnique(field_content, "value"); \
XMLElement *val_data = value ? ArrayGet(value->children, 0) : NULL; \
if (val_data && val_data->data) \
{ \
to = val_data->data; \
} \
} \
while(0)
#define SetNote(type, text) do \
{ \
XMLElement *note_xml = XMLCreateTag("note"); \
XMLElement *note_msg = XMLCreateText(text); \
XMLAddAttr(note_xml, "type", type); \
XMLAddChild(note_xml, note_msg); \
XMLAddChild(out, note_xml); \
} \
while(0)
#define SetTitle(form, text) do \
{ \
XMLElement *title_xml, *title_txt; \
title_xml = XMLCreateTag("title"); \
title_txt = XMLCreateText(text); \
XMLAddChild(title_xml, title_txt); \
XMLAddChild(form, title_xml); \
} \
while(0)
#endif