mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-13 21:35:10 +00:00
[MOD/WIP] Externalise and add errors to commands
Still need forms...
This commit is contained in:
parent
408888ef67
commit
a880769c48
9 changed files with 311 additions and 89 deletions
77
src/XMPPCommands/Status.c
Normal file
77
src/XMPPCommands/Status.c
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
#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 <Parsee.h>
|
||||
#include <XMPP.h>
|
||||
|
||||
void
|
||||
StatusCallback(XMPPCommandManager *m, char *from, HashMap *form, XMLElement *out)
|
||||
{
|
||||
ParseeData *data = XMPPGetManagerCookie(m);
|
||||
char *trimmed = ParseeTrimJID(from);
|
||||
size_t alloc = MemoryAllocated();
|
||||
size_t kb = alloc >> 10;
|
||||
size_t mb = kb >> 10;
|
||||
size_t gb = mb >> 10;
|
||||
size_t min = gb ? gb : (mb ? mb : (kb ? kb : alloc));
|
||||
char *unit = gb ? "GB" : (mb ? "MB" : (kb ? "KB" : "B"));
|
||||
XMLElement *x;
|
||||
XMLElement *title, *txt;
|
||||
|
||||
if (!ParseeIsAdmin(data, trimmed))
|
||||
{
|
||||
XMLElement *note = XMLCreateTag("note");
|
||||
XMLAddAttr(note, "type", "error");
|
||||
|
||||
txt = XMLCreateText("User is not authorised to execute command.");
|
||||
XMLAddChild(note, txt);
|
||||
XMLAddChild(out, note);
|
||||
|
||||
Free(trimmed);
|
||||
return;
|
||||
}
|
||||
Free(trimmed);
|
||||
x = XMLCreateTag("x");
|
||||
title = XMLCreateTag("title");
|
||||
|
||||
{
|
||||
XMLElement *title_text = XMLCreateText("Parsee statistics");
|
||||
XMLAddChild(title, title_text);
|
||||
}
|
||||
XMLAddChild(x, title);
|
||||
|
||||
XMLAddAttr(x, "xmlns", "jabber:x:data");
|
||||
XMLAddAttr(x, "type", "result");
|
||||
{
|
||||
XMLElement *reported, *item, *field, *value;
|
||||
reported = XMLCreateTag("reported");
|
||||
XMLAddChild(x, reported);
|
||||
|
||||
/* Report */
|
||||
Report("mem-alloc", "Heap allocated with Cytoplasm");
|
||||
Report("xml-congest", "Unprocessed stanzas(congestion)");
|
||||
|
||||
/* Set */
|
||||
BeginItem();
|
||||
{
|
||||
char *min_str = StrInt(min);
|
||||
char *congest = StrInt(ParseeCongestion());
|
||||
char *alloc = StrConcat(3, min_str, " ", unit);
|
||||
|
||||
SetField("mem-alloc", alloc);
|
||||
SetField("xml-congest", congest);
|
||||
|
||||
Free(congest);
|
||||
Free(min_str);
|
||||
Free(alloc);
|
||||
}
|
||||
EndItem();
|
||||
}
|
||||
XMLAddChild(out, x);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue