mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-13 23:05:10 +00:00
[ADD/MOD] Cleanup cmd, change Matrix user format
This commit is contained in:
parent
9e5e741989
commit
91d373addb
13 changed files with 217 additions and 77 deletions
|
|
@ -8,6 +8,10 @@ struct XMPPCommand {
|
|||
XMPPCmdCallback callback;
|
||||
char *node, *name;
|
||||
|
||||
char *form_instruction;
|
||||
char *form_title;
|
||||
|
||||
/* TODO: On-the-fly generation of options */
|
||||
Array *options;
|
||||
};
|
||||
|
||||
|
|
@ -25,12 +29,34 @@ XMPPBasicCmd(char *node, char *name, XMPPCmdCallback callback_funct)
|
|||
cmd->callback = callback_funct;
|
||||
cmd->node = StrDuplicate(node);
|
||||
cmd->name = StrDuplicate(name);
|
||||
cmd->form_instruction = NULL;
|
||||
cmd->form_title = NULL;
|
||||
|
||||
/* No options -> no form required */
|
||||
cmd->options = NULL;
|
||||
|
||||
return cmd;
|
||||
}
|
||||
void
|
||||
XMPPSetFormTitle(XMPPCommand *cmd, char *title)
|
||||
{
|
||||
if (!cmd)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Free(cmd->form_title);
|
||||
cmd->form_title = StrDuplicate(title);
|
||||
}
|
||||
void
|
||||
XMPPSetFormInstruction(XMPPCommand *cmd, char *instruction)
|
||||
{
|
||||
if (!cmd)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Free(cmd->form_instruction);
|
||||
cmd->form_instruction = StrDuplicate(instruction);
|
||||
}
|
||||
void
|
||||
XMPPFreeCommand(XMPPCommand *cmd)
|
||||
{
|
||||
|
|
@ -47,6 +73,8 @@ XMPPFreeCommand(XMPPCommand *cmd)
|
|||
}
|
||||
ArrayFree(cmd->options);
|
||||
|
||||
XMPPSetFormInstruction(cmd, NULL);
|
||||
XMPPSetFormTitle(cmd, NULL);
|
||||
Free(cmd->node);
|
||||
Free(cmd->name);
|
||||
Free(cmd);
|
||||
|
|
@ -80,6 +108,25 @@ XMPPFormifyCommand(XMPPCommand *cmd)
|
|||
x = XMLCreateTag("x");
|
||||
XMLAddAttr(x, "xmlns", "jabber:x:data");
|
||||
XMLAddAttr(x, "type", "form");
|
||||
|
||||
if (cmd->form_title)
|
||||
{
|
||||
XMLElement *instr_xml, *instr_txt;
|
||||
|
||||
instr_xml = XMLCreateTag("title");
|
||||
instr_txt = XMLCreateText(cmd->form_title);
|
||||
XMLAddChild(instr_xml, instr_txt);
|
||||
XMLAddChild(x, instr_xml);
|
||||
}
|
||||
if (cmd->form_instruction)
|
||||
{
|
||||
XMLElement *instr_xml, *instr_txt;
|
||||
|
||||
instr_xml = XMLCreateTag("instructions");
|
||||
instr_txt = XMLCreateText(cmd->form_instruction);
|
||||
XMLAddChild(instr_xml, instr_txt);
|
||||
XMLAddChild(x, instr_xml);
|
||||
}
|
||||
/* TODO: Other fields */
|
||||
|
||||
for (i = 0; i < ArraySize(cmd->options); i++)
|
||||
|
|
@ -117,23 +164,6 @@ XMPPExecuteCommand(XMPPCommandManager *m, XMPPCommand *cmd, char *from, XMLEleme
|
|||
cmd->callback(m, from, form, to);
|
||||
}
|
||||
|
||||
void
|
||||
XMPPShoveOptions(XMPPCommand *cmd, XMLElement *form)
|
||||
{
|
||||
size_t i;
|
||||
if (!cmd || !form)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < ArraySize(cmd->options); i++)
|
||||
{
|
||||
XMPPOption *opt = ArrayGet(cmd->options, i);
|
||||
XMLElement *xml = XMPPOptionToXML(opt);
|
||||
|
||||
XMLAddChild(form, xml);
|
||||
}
|
||||
}
|
||||
bool
|
||||
XMPPVerifyForm(XMPPCommand *cmd, XMLElement *form)
|
||||
{
|
||||
|
|
@ -157,7 +187,7 @@ XMPPVerifyForm(XMPPCommand *cmd, XMLElement *form)
|
|||
/* Required field not found; die. */
|
||||
return false;
|
||||
}
|
||||
/* TODO */
|
||||
/* TODO: Verify type, array membership, uniqueness, etc... */
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue