aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua/lua_xmlrpc.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2014-07-23 12:57:31 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2014-07-23 12:57:31 +0100
commit379055dbbb4af997b4d3ffb161d447872d7ca357 (patch)
tree3774553d470f93e12ddeb454aad9b3b607cf8918 /src/lua/lua_xmlrpc.c
parent602ae7a0b7e215ba2677131b8fdc70abc156b3ca (diff)
downloadrspamd-379055dbbb4af997b4d3ffb161d447872d7ca357.tar.gz
rspamd-379055dbbb4af997b4d3ffb161d447872d7ca357.zip
Unify style without sorting headers.
Diffstat (limited to 'src/lua/lua_xmlrpc.c')
-rw-r--r--src/lua/lua_xmlrpc.c171
1 files changed, 111 insertions, 60 deletions
diff --git a/src/lua/lua_xmlrpc.c b/src/lua/lua_xmlrpc.c
index 4608d2328..762711c30 100644
--- a/src/lua/lua_xmlrpc.c
+++ b/src/lua/lua_xmlrpc.c
@@ -27,7 +27,7 @@
LUA_FUNCTION_DEF (xmlrpc, parse_reply);
LUA_FUNCTION_DEF (xmlrpc, make_request);
-static const struct luaL_reg xmlrpclib_m[] = {
+static const struct luaL_reg xmlrpclib_m[] = {
LUA_INTERFACE_DEF (xmlrpc, parse_reply),
LUA_INTERFACE_DEF (xmlrpc, make_request),
{"__tostring", lua_class_tostring},
@@ -42,13 +42,24 @@ struct lua_xmlrpc_ud {
lua_State *L;
};
-static void xmlrpc_start_element (GMarkupParseContext *context, const gchar *name, const gchar **attribute_names,
- const gchar **attribute_values, gpointer user_data, GError **error);
-static void xmlrpc_end_element (GMarkupParseContext *context, const gchar *element_name, gpointer user_data,
- GError **error);
-static void xmlrpc_error (GMarkupParseContext *context, GError *error, gpointer user_data);
-static void xmlrpc_text (GMarkupParseContext *context, const gchar *text, gsize text_len, gpointer user_data,
- GError **error);
+static void xmlrpc_start_element (GMarkupParseContext *context,
+ const gchar *name,
+ const gchar **attribute_names,
+ const gchar **attribute_values,
+ gpointer user_data,
+ GError **error);
+static void xmlrpc_end_element (GMarkupParseContext *context,
+ const gchar *element_name,
+ gpointer user_data,
+ GError **error);
+static void xmlrpc_error (GMarkupParseContext *context,
+ GError *error,
+ gpointer user_data);
+static void xmlrpc_text (GMarkupParseContext *context,
+ const gchar *text,
+ gsize text_len,
+ gpointer user_data,
+ GError **error);
static GMarkupParser xmlrpc_parser = {
.start_element = xmlrpc_start_element,
@@ -65,11 +76,15 @@ xmlrpc_error_quark (void)
}
static void
-xmlrpc_start_element (GMarkupParseContext *context, const gchar *name, const gchar **attribute_names,
- const gchar **attribute_values, gpointer user_data, GError **error)
+xmlrpc_start_element (GMarkupParseContext *context,
+ const gchar *name,
+ const gchar **attribute_names,
+ const gchar **attribute_values,
+ gpointer user_data,
+ GError **error)
{
- struct lua_xmlrpc_ud *ud = user_data;
- int last_state;
+ struct lua_xmlrpc_ud *ud = user_data;
+ int last_state;
last_state = ud->parser_state;
@@ -123,7 +138,7 @@ xmlrpc_start_element (GMarkupParseContext *context, const gchar *name, const gch
ud->parser_state = 5;
/* Create new param of table type */
lua_newtable (ud->L);
- ud->depth ++;
+ ud->depth++;
}
else if (g_ascii_strcasecmp (name, "string") == 0) {
ud->parser_state = 11;
@@ -193,7 +208,7 @@ xmlrpc_start_element (GMarkupParseContext *context, const gchar *name, const gch
ud->parser_state = 5;
/* Create new param of table type */
lua_newtable (ud->L);
- ud->depth ++;
+ ud->depth++;
}
else {
/* Error state */
@@ -203,16 +218,20 @@ xmlrpc_start_element (GMarkupParseContext *context, const gchar *name, const gch
}
if (ud->parser_state == 99) {
- g_set_error (error, xmlrpc_error_quark(), 1, "xmlrpc parse error on state: %d, while parsing start tag: %s",
- last_state, name);
+ g_set_error (error,
+ xmlrpc_error_quark (), 1, "xmlrpc parse error on state: %d, while parsing start tag: %s",
+ last_state, name);
}
}
static void
-xmlrpc_end_element (GMarkupParseContext *context, const gchar *name, gpointer user_data, GError **error)
+xmlrpc_end_element (GMarkupParseContext *context,
+ const gchar *name,
+ gpointer user_data,
+ GError **error)
{
- struct lua_xmlrpc_ud *ud = user_data;
- int last_state;
+ struct lua_xmlrpc_ud *ud = user_data;
+ int last_state;
last_state = ud->parser_state;
@@ -272,7 +291,7 @@ xmlrpc_end_element (GMarkupParseContext *context, const gchar *name, gpointer us
/* Got tag struct */
if (g_ascii_strcasecmp (name, "struct") == 0) {
ud->parser_state = 4;
- ud->depth --;
+ ud->depth--;
}
else {
/* Error state */
@@ -340,25 +359,30 @@ xmlrpc_end_element (GMarkupParseContext *context, const gchar *name, gpointer us
}
if (ud->parser_state == 99) {
- g_set_error (error, xmlrpc_error_quark(), 1, "xmlrpc parse error on state: %d, while parsing end tag: %s",
- last_state, name);
+ g_set_error (error,
+ xmlrpc_error_quark (), 1, "xmlrpc parse error on state: %d, while parsing end tag: %s",
+ last_state, name);
}
}
static void
-xmlrpc_text (GMarkupParseContext *context, const gchar *text, gsize text_len, gpointer user_data, GError **error)
+xmlrpc_text (GMarkupParseContext *context,
+ const gchar *text,
+ gsize text_len,
+ gpointer user_data,
+ GError **error)
{
- struct lua_xmlrpc_ud *ud = user_data;
- gint num;
- gdouble dnum;
+ struct lua_xmlrpc_ud *ud = user_data;
+ gint num;
+ gdouble dnum;
/* Strip line */
while (text_len > 0 && g_ascii_isspace (*text)) {
- text ++;
- text_len --;
+ text++;
+ text_len--;
}
while (text_len > 0 && g_ascii_isspace (text[text_len - 1])) {
- text_len --;
+ text_len--;
}
if (text_len > 0) {
@@ -390,7 +414,7 @@ xmlrpc_text (GMarkupParseContext *context, const gchar *text, gsize text_len, gp
static void
xmlrpc_error (GMarkupParseContext *context, GError *error, gpointer user_data)
{
- struct lua_xmlrpc_ud *ud = user_data;
+ struct lua_xmlrpc_ud *ud = user_data;
msg_err ("xmlrpc parser error: %s", error->message, ud->parser_state);
}
@@ -398,12 +422,12 @@ xmlrpc_error (GMarkupParseContext *context, GError *error, gpointer user_data)
static gint
lua_xmlrpc_parse_reply (lua_State *L)
{
- const gchar *data;
- GMarkupParseContext *ctx;
- GError *err = NULL;
- struct lua_xmlrpc_ud ud;
- gsize s;
- gboolean res;
+ const gchar *data;
+ GMarkupParseContext *ctx;
+ GError *err = NULL;
+ struct lua_xmlrpc_ud ud;
+ gsize s;
+ gboolean res;
data = luaL_checklstring (L, 1, &s);
@@ -418,7 +442,7 @@ lua_xmlrpc_parse_reply (lua_State *L)
res = g_markup_parse_context_parse (ctx, data, s, &err);
g_markup_parse_context_free (ctx);
- if (! res) {
+ if (!res) {
lua_pushnil (L);
}
}
@@ -431,10 +455,14 @@ lua_xmlrpc_parse_reply (lua_State *L)
}
static gint
-lua_xmlrpc_parse_table (lua_State *L, gint pos, gchar *databuf, gint pr, gsize size)
+lua_xmlrpc_parse_table (lua_State *L,
+ gint pos,
+ gchar *databuf,
+ gint pr,
+ gsize size)
{
- gint r = pr, num;
- double dnum;
+ gint r = pr, num;
+ double dnum;
r += rspamd_snprintf (databuf + r, size - r, "<struct>");
lua_pushnil (L); /* first key */
@@ -442,10 +470,12 @@ lua_xmlrpc_parse_table (lua_State *L, gint pos, gchar *databuf, gint pr, gsize s
/* uses 'key' (at index -2) and 'value' (at index -1) */
if (lua_type (L, -2) != LUA_TSTRING) {
/* Ignore non sting keys */
- lua_pop(L, 1);
+ lua_pop (L, 1);
continue;
}
- r += rspamd_snprintf (databuf + r, size - r, "<member><name>%s</name><value>",
+ r += rspamd_snprintf (databuf + r,
+ size - r,
+ "<member><name>%s</name><value>",
lua_tostring (L, -2));
switch (lua_type (L, -1)) {
case LUA_TNUMBER:
@@ -454,16 +484,22 @@ lua_xmlrpc_parse_table (lua_State *L, gint pos, gchar *databuf, gint pr, gsize s
/* Try to avoid conversion errors */
if (dnum != (double)num) {
- r += rspamd_snprintf (databuf + r, sizeof (databuf) - r, "<double>%f</double>",
+ r += rspamd_snprintf (databuf + r,
+ sizeof (databuf) - r,
+ "<double>%f</double>",
dnum);
}
else {
- r += rspamd_snprintf (databuf + r, sizeof (databuf) - r, "<int>%d</int>",
+ r += rspamd_snprintf (databuf + r,
+ sizeof (databuf) - r,
+ "<int>%d</int>",
num);
}
break;
case LUA_TBOOLEAN:
- r += rspamd_snprintf (databuf + r, size - r, "<boolean>%d</boolean>",
+ r += rspamd_snprintf (databuf + r,
+ size - r,
+ "<boolean>%d</boolean>",
lua_toboolean (L, -1) ? 1 : 0);
break;
case LUA_TSTRING:
@@ -477,7 +513,7 @@ lua_xmlrpc_parse_table (lua_State *L, gint pos, gchar *databuf, gint pr, gsize s
}
r += rspamd_snprintf (databuf + r, size - r, "</value></member>");
/* removes 'value'; keeps 'key' for next iteration */
- lua_pop(L, 1);
+ lua_pop (L, 1);
}
r += rspamd_snprintf (databuf + r, size - r, "</struct>");
@@ -491,10 +527,10 @@ lua_xmlrpc_parse_table (lua_State *L, gint pos, gchar *databuf, gint pr, gsize s
static gint
lua_xmlrpc_make_request (lua_State *L)
{
- gchar databuf[BUFSIZ * 2];
- const gchar *func;
- gint r, top, i, num;
- double dnum;
+ gchar databuf[BUFSIZ * 2];
+ const gchar *func;
+ gint r, top, i, num;
+ double dnum;
func = luaL_checkstring (L, 1);
@@ -507,7 +543,9 @@ lua_xmlrpc_make_request (lua_State *L)
top = lua_gettop (L);
/* Get additional options */
for (i = 2; i <= top; i++) {
- r += rspamd_snprintf (databuf + r, sizeof (databuf) - r, "<param><value>");
+ r += rspamd_snprintf (databuf + r,
+ sizeof (databuf) - r,
+ "<param><value>");
switch (lua_type (L, i)) {
case LUA_TNUMBER:
num = lua_tointeger (L, i);
@@ -515,30 +553,43 @@ lua_xmlrpc_make_request (lua_State *L)
/* Try to avoid conversion errors */
if (dnum != (double)num) {
- r += rspamd_snprintf (databuf + r, sizeof (databuf) - r, "<double>%f</double>",
- dnum);
+ r += rspamd_snprintf (databuf + r,
+ sizeof (databuf) - r,
+ "<double>%f</double>",
+ dnum);
}
else {
- r += rspamd_snprintf (databuf + r, sizeof (databuf) - r, "<int>%d</int>",
- num);
+ r += rspamd_snprintf (databuf + r,
+ sizeof (databuf) - r,
+ "<int>%d</int>",
+ num);
}
break;
case LUA_TBOOLEAN:
- r += rspamd_snprintf (databuf + r, sizeof (databuf) - r, "<boolean>%d</boolean>",
+ r += rspamd_snprintf (databuf + r,
+ sizeof (databuf) - r,
+ "<boolean>%d</boolean>",
lua_toboolean (L, i) ? 1 : 0);
break;
case LUA_TSTRING:
- r += rspamd_snprintf (databuf + r, sizeof (databuf) - r, "<string>%s</string>",
+ r += rspamd_snprintf (databuf + r,
+ sizeof (databuf) - r,
+ "<string>%s</string>",
lua_tostring (L, i));
break;
case LUA_TTABLE:
- r += lua_xmlrpc_parse_table (L, i, databuf, r, sizeof (databuf));
+ r +=
+ lua_xmlrpc_parse_table (L, i, databuf, r, sizeof (databuf));
break;
}
- r += rspamd_snprintf (databuf + r, sizeof (databuf) - r, "</value></param>");
+ r += rspamd_snprintf (databuf + r,
+ sizeof (databuf) - r,
+ "</value></param>");
}
- r += rspamd_snprintf (databuf + r, sizeof (databuf) - r, "</params></methodCall>");
+ r += rspamd_snprintf (databuf + r,
+ sizeof (databuf) - r,
+ "</params></methodCall>");
lua_pushlstring (L, databuf, r);
}
else {