aboutsummaryrefslogtreecommitdiffstats
path: root/src/client
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2014-07-23 12:45:28 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2014-07-23 12:45:28 +0100
commite0483657ff6cf1adc828ccce457814d61fe90a0d (patch)
tree5183e4163f40b81b3e7d5f51488d360883782154 /src/client
parent7962087e808fb824aa3af6d41d02abc92916ba1e (diff)
downloadrspamd-e0483657ff6cf1adc828ccce457814d61fe90a0d.tar.gz
rspamd-e0483657ff6cf1adc828ccce457814d61fe90a0d.zip
Unify code style.
Diffstat (limited to 'src/client')
-rw-r--r--src/client/rspamc.c241
-rw-r--r--src/client/rspamdclient.c44
-rw-r--r--src/client/rspamdclient.h36
3 files changed, 188 insertions, 133 deletions
diff --git a/src/client/rspamc.c b/src/client/rspamc.c
index e526850c4..61961ecba 100644
--- a/src/client/rspamc.c
+++ b/src/client/rspamc.c
@@ -23,61 +23,82 @@
*/
#include "config.h"
-#include "util.h"
#include "http.h"
#include "rspamdclient.h"
+#include "util.h"
#include "utlist.h"
#define DEFAULT_PORT 11333
#define DEFAULT_CONTROL_PORT 11334
-static gchar *connect_str = "localhost";
-static gchar *password = NULL;
-static gchar *ip = NULL;
-static gchar *from = NULL;
-static gchar *deliver_to = NULL;
-static gchar *rcpt = NULL;
-static gchar *user = NULL;
-static gchar *helo = NULL;
-static gchar *hostname = NULL;
-static gchar *classifier = "bayes";
-static gchar *local_addr = NULL;
-static gint weight = 0;
-static gint flag = 0;
-static gint max_requests = 1024;
-static gdouble timeout = 5.0;
-static gboolean pass_all;
-static gboolean tty = FALSE;
-static gboolean verbose = FALSE;
-static gboolean print_commands = FALSE;
-static gboolean json = FALSE;
-static gboolean headers = FALSE;
-static gboolean raw = FALSE;
+static gchar *connect_str = "localhost";
+static gchar *password = NULL;
+static gchar *ip = NULL;
+static gchar *from = NULL;
+static gchar *deliver_to = NULL;
+static gchar *rcpt = NULL;
+static gchar *user = NULL;
+static gchar *helo = NULL;
+static gchar *hostname = NULL;
+static gchar *classifier = "bayes";
+static gchar *local_addr = NULL;
+static gint weight = 0;
+static gint flag = 0;
+static gint max_requests = 1024;
+static gdouble timeout = 5.0;
+static gboolean pass_all;
+static gboolean tty = FALSE;
+static gboolean verbose = FALSE;
+static gboolean print_commands = FALSE;
+static gboolean json = FALSE;
+static gboolean headers = FALSE;
+static gboolean raw = FALSE;
static GOptionEntry entries[] =
{
- { "connect", 'h', 0, G_OPTION_ARG_STRING, &connect_str, "Specify host and port", NULL },
- { "password", 'P', 0, G_OPTION_ARG_STRING, &password, "Specify control password", NULL },
- { "classifier", 'c', 0, G_OPTION_ARG_STRING, &classifier, "Classifier to learn spam or ham", NULL },
- { "weight", 'w', 0, G_OPTION_ARG_INT, &weight, "Weight for fuzzy operations", NULL },
- { "flag", 'f', 0, G_OPTION_ARG_INT, &flag, "Flag for fuzzy operations", NULL },
- { "pass-all", 'p', 0, G_OPTION_ARG_NONE, &pass_all, "Pass all filters", NULL },
- { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "More verbose output", NULL },
- { "ip", 'i', 0, G_OPTION_ARG_STRING, &ip, "Emulate that message was received from specified ip address", NULL },
- { "user", 'u', 0, G_OPTION_ARG_STRING, &user, "Emulate that message was from specified user", NULL },
- { "deliver", 'd', 0, G_OPTION_ARG_STRING, &deliver_to, "Emulate that message is delivered to specified user", NULL },
- { "from", 'F', 0, G_OPTION_ARG_STRING, &from, "Emulate that message is from specified user", NULL },
- { "rcpt", 'r', 0, G_OPTION_ARG_STRING, &rcpt, "Emulate that message is for specified user", NULL },
- { "helo", 0, 0, G_OPTION_ARG_STRING, &helo, "Imitate SMTP HELO passing from MTA", NULL },
- { "hostname", 0, 0, G_OPTION_ARG_STRING, &hostname, "Imitate hostname passing from MTA", NULL },
- { "timeout", 't', 0, G_OPTION_ARG_DOUBLE, &timeout, "Time in seconds to wait for a reply", NULL },
- { "bind", 'b', 0, G_OPTION_ARG_STRING, &local_addr, "Bind to specified ip address", NULL },
- { "commands", 0, 0, G_OPTION_ARG_NONE, &print_commands, "List available commands", NULL },
- { "json", 'j', 0, G_OPTION_ARG_NONE, &json, "Output json reply", NULL },
- { "headers", 0, 0, G_OPTION_ARG_NONE, &headers, "Output HTTP headers", NULL },
- { "raw", 0, 0, G_OPTION_ARG_NONE, &raw, "Output raw reply from rspamd", NULL },
- { "max-requests", 'n', 0, G_OPTION_ARG_INT, &max_requests, "Maximum count of parallel requests to rspamd", NULL },
- { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL }
+ { "connect", 'h', 0, G_OPTION_ARG_STRING, &connect_str,
+ "Specify host and port", NULL },
+ { "password", 'P', 0, G_OPTION_ARG_STRING, &password,
+ "Specify control password", NULL },
+ { "classifier", 'c', 0, G_OPTION_ARG_STRING, &classifier,
+ "Classifier to learn spam or ham", NULL },
+ { "weight", 'w', 0, G_OPTION_ARG_INT, &weight,
+ "Weight for fuzzy operations", NULL },
+ { "flag", 'f', 0, G_OPTION_ARG_INT, &flag, "Flag for fuzzy operations",
+ NULL },
+ { "pass-all", 'p', 0, G_OPTION_ARG_NONE, &pass_all, "Pass all filters",
+ NULL },
+ { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "More verbose output",
+ NULL },
+ { "ip", 'i', 0, G_OPTION_ARG_STRING, &ip,
+ "Emulate that message was received from specified ip address",
+ NULL },
+ { "user", 'u', 0, G_OPTION_ARG_STRING, &user,
+ "Emulate that message was from specified user", NULL },
+ { "deliver", 'd', 0, G_OPTION_ARG_STRING, &deliver_to,
+ "Emulate that message is delivered to specified user", NULL },
+ { "from", 'F', 0, G_OPTION_ARG_STRING, &from,
+ "Emulate that message is from specified user", NULL },
+ { "rcpt", 'r', 0, G_OPTION_ARG_STRING, &rcpt,
+ "Emulate that message is for specified user", NULL },
+ { "helo", 0, 0, G_OPTION_ARG_STRING, &helo,
+ "Imitate SMTP HELO passing from MTA", NULL },
+ { "hostname", 0, 0, G_OPTION_ARG_STRING, &hostname,
+ "Imitate hostname passing from MTA", NULL },
+ { "timeout", 't', 0, G_OPTION_ARG_DOUBLE, &timeout,
+ "Time in seconds to wait for a reply", NULL },
+ { "bind", 'b', 0, G_OPTION_ARG_STRING, &local_addr,
+ "Bind to specified ip address", NULL },
+ { "commands", 0, 0, G_OPTION_ARG_NONE, &print_commands,
+ "List available commands", NULL },
+ { "json", 'j', 0, G_OPTION_ARG_NONE, &json, "Output json reply", NULL },
+ { "headers", 0, 0, G_OPTION_ARG_NONE, &headers, "Output HTTP headers",
+ NULL },
+ { "raw", 0, 0, G_OPTION_ARG_NONE, &raw, "Output raw reply from rspamd",
+ NULL },
+ { "max-requests", 'n', 0, G_OPTION_ARG_INT, &max_requests,
+ "Maximum count of parallel requests to rspamd", NULL },
+ { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL }
};
static void rspamc_symbols_output (ucl_object_t *obj);
@@ -143,7 +164,8 @@ struct rspamc_command {
.cmd = RSPAMC_COMMAND_FUZZY_ADD,
.name = "fuzzy_add",
.path = "fuzzyadd",
- .description = "add message to fuzzy storage (check -f and -w options for this command)",
+ .description =
+ "add message to fuzzy storage (check -f and -w options for this command)",
.is_controller = TRUE,
.is_privileged = TRUE,
.need_input = TRUE,
@@ -153,7 +175,8 @@ struct rspamc_command {
.cmd = RSPAMC_COMMAND_FUZZY_DEL,
.name = "fuzzy_del",
.path = "fuzzydel",
- .description = "delete message from fuzzy storage (check -f option for this command)",
+ .description =
+ "delete message from fuzzy storage (check -f option for this command)",
.is_controller = TRUE,
.is_privileged = TRUE,
.need_input = TRUE,
@@ -232,12 +255,13 @@ struct rspamc_callback_data {
static void
read_cmd_line (gint *argc, gchar ***argv)
{
- GError *error = NULL;
- GOptionContext *context;
+ GError *error = NULL;
+ GOptionContext *context;
/* Prepare parser */
context = g_option_context_new ("- run rspamc client");
- g_option_context_set_summary (context, "Summary:\n Rspamd client version " RVERSION "\n Release id: " RID);
+ g_option_context_set_summary (context,
+ "Summary:\n Rspamd client version " RVERSION "\n Release id: " RID);
g_option_context_add_main_entries (context, entries, NULL);
/* Parse options */
@@ -298,7 +322,7 @@ check_rspamc_command (const gchar *cmd)
ct = RSPAMC_COMMAND_ADD_ACTION;
}
- for (i = 0; i < G_N_ELEMENTS (rspamc_commands); i ++) {
+ for (i = 0; i < G_N_ELEMENTS (rspamc_commands); i++) {
if (rspamc_commands[i].cmd == ct) {
return &rspamc_commands[i];
}
@@ -310,17 +334,21 @@ check_rspamc_command (const gchar *cmd)
static void
print_commands_list (void)
{
- guint i;
+ guint i;
rspamd_fprintf (stdout, "Rspamc commands summary:\n");
- for (i = 0; i < G_N_ELEMENTS (rspamc_commands); i ++) {
- rspamd_fprintf (stdout, " %10s (%7s%1s)\t%s\n", rspamc_commands[i].name,
- rspamc_commands[i].is_controller ? "control" : "normal",
- rspamc_commands[i].is_privileged ? "*" : "",
- rspamc_commands[i].description);
- }
- rspamd_fprintf (stdout, "\n* is for privileged commands that may need password (see -P option)\n");
- rspamd_fprintf (stdout, "control commands use port 11334 while normal use 11333 by default (see -h option)\n");
+ for (i = 0; i < G_N_ELEMENTS (rspamc_commands); i++) {
+ rspamd_fprintf (stdout,
+ " %10s (%7s%1s)\t%s\n",
+ rspamc_commands[i].name,
+ rspamc_commands[i].is_controller ? "control" : "normal",
+ rspamc_commands[i].is_privileged ? "*" : "",
+ rspamc_commands[i].description);
+ }
+ rspamd_fprintf (stdout,
+ "\n* is for privileged commands that may need password (see -P option)\n");
+ rspamd_fprintf (stdout,
+ "control commands use port 11334 while normal use 11333 by default (see -h option)\n");
}
@@ -410,24 +438,28 @@ rspamc_metric_output (const ucl_object_t *obj)
while ((cur = ucl_iterate_object (obj, &it, true)) != NULL) {
if (g_ascii_strcasecmp (ucl_object_key (cur), "is_spam") == 0) {
rspamd_fprintf (stdout, "Spam: %s\n", ucl_object_toboolean (cur) ?
- "true" : "false");
+ "true" : "false");
}
else if (g_ascii_strcasecmp (ucl_object_key (cur), "score") == 0) {
score = ucl_object_todouble (cur);
- got_scores ++;
+ got_scores++;
}
- else if (g_ascii_strcasecmp (ucl_object_key (cur), "required_score") == 0) {
+ else if (g_ascii_strcasecmp (ucl_object_key (cur),
+ "required_score") == 0) {
required_score = ucl_object_todouble (cur);
- got_scores ++;
+ got_scores++;
}
else if (g_ascii_strcasecmp (ucl_object_key (cur), "action") == 0) {
- rspamd_fprintf (stdout, "Action: %s\n", ucl_object_tostring(cur));
+ rspamd_fprintf (stdout, "Action: %s\n", ucl_object_tostring (cur));
}
else if (cur->type == UCL_OBJECT) {
rspamc_symbol_output (cur);
}
if (got_scores == 2) {
- rspamd_fprintf (stdout, "Score: %.2f / %.2f\n", score, required_score);
+ rspamd_fprintf (stdout,
+ "Score: %.2f / %.2f\n",
+ score,
+ required_score);
got_scores = 0;
}
}
@@ -442,10 +474,12 @@ rspamc_symbols_output (ucl_object_t *obj)
while ((cur = ucl_iterate_object (obj, &it, true)) != NULL) {
if (g_ascii_strcasecmp (ucl_object_key (cur), "message-id") == 0) {
- rspamd_fprintf (stdout, "Message-ID: %s\n", ucl_object_tostring (cur));
+ rspamd_fprintf (stdout, "Message-ID: %s\n", ucl_object_tostring (
+ cur));
}
else if (g_ascii_strcasecmp (ucl_object_key (cur), "queue-id") == 0) {
- rspamd_fprintf (stdout, "Queue-ID: %s\n", ucl_object_tostring (cur));
+ rspamd_fprintf (stdout, "Queue-ID: %s\n",
+ ucl_object_tostring (cur));
}
else if (g_ascii_strcasecmp (ucl_object_key (cur), "urls") == 0) {
emitted = ucl_object_emit (cur, UCL_EMIT_JSON_COMPACT);
@@ -458,7 +492,8 @@ rspamc_symbols_output (ucl_object_t *obj)
free (emitted);
}
else if (g_ascii_strcasecmp (ucl_object_key (cur), "error") == 0) {
- rspamd_fprintf (stdout, "Scan error: %s\n", ucl_object_tostring (cur));
+ rspamd_fprintf (stdout, "Scan error: %s\n", ucl_object_tostring (
+ cur));
}
else if (cur->type == UCL_OBJECT) {
/* Parse metric */
@@ -475,7 +510,8 @@ rspamc_uptime_output (ucl_object_t *obj)
elt = ucl_object_find_key (obj, "version");
if (elt != NULL) {
- rspamd_fprintf (stdout, "Rspamd version: %s\n", ucl_object_tostring (elt));
+ rspamd_fprintf (stdout, "Rspamd version: %s\n", ucl_object_tostring (
+ elt));
}
elt = ucl_object_find_key (obj, "uptime");
@@ -487,13 +523,13 @@ rspamc_uptime_output (ucl_object_t *obj)
hours = seconds / 3600 - days * 24;
minutes = seconds / 60 - hours * 60 - days * 1440;
rspamd_printf ("%L day%s %L hour%s %L minute%s\n", days,
- days > 1 ? "s" : "", hours, hours > 1 ? "s" : "",
- minutes, minutes > 1 ? "s" : "");
+ days > 1 ? "s" : "", hours, hours > 1 ? "s" : "",
+ minutes, minutes > 1 ? "s" : "");
}
/* If uptime is less than 1 minute print only seconds */
else if (seconds / 60 == 0) {
rspamd_printf ("%L second%s\n", (gint)seconds,
- (gint)seconds > 1 ? "s" : "");
+ (gint)seconds > 1 ? "s" : "");
}
/* Else print the minutes and seconds. */
else {
@@ -501,9 +537,9 @@ rspamc_uptime_output (ucl_object_t *obj)
minutes = seconds / 60 - hours * 60;
seconds -= hours * 3600 + minutes * 60;
rspamd_printf ("%L hour%s %L minute%s %L second%s\n", hours,
- hours > 1 ? "s" : "", minutes,
- minutes > 1 ? "s" : "",
- seconds, seconds > 1 ? "s" : "");
+ hours > 1 ? "s" : "", minutes,
+ minutes > 1 ? "s" : "",
+ seconds, seconds > 1 ? "s" : "");
}
}
}
@@ -532,7 +568,7 @@ rspamc_counters_output (ucl_object_t *obj)
}
rspamd_snprintf (fmt_buf, sizeof (fmt_buf),
- "| %%3s | %%%ds | %%6s | %%9s | %%9s |\n", max_len);
+ "| %%3s | %%%ds | %%6s | %%9s | %%9s |\n", max_len);
memset (dash_buf, '-', 40 + max_len);
dash_buf[40 + max_len] = '\0';
@@ -546,7 +582,7 @@ rspamc_counters_output (ucl_object_t *obj)
printf ("\033[0m");
}
rspamd_snprintf (fmt_buf, sizeof (fmt_buf),
- "| %%3d | %%%ds | %%6.1f | %%9d | %%9.3f |\n", max_len);
+ "| %%3d | %%%ds | %%6.1f | %%9d | %%9.3f |\n", max_len);
iter = NULL;
i = 0;
@@ -563,7 +599,7 @@ rspamc_counters_output (ucl_object_t *obj)
(gint)ucl_object_toint (freq),
ucl_object_todouble (tim));
}
- i ++;
+ i++;
}
printf (" %s \n", dash_buf);
}
@@ -573,7 +609,8 @@ rspamc_output_headers (struct rspamd_http_message *msg)
{
struct rspamd_http_header *h;
- LL_FOREACH (msg->headers, h) {
+ LL_FOREACH (msg->headers, h)
+ {
rspamd_fprintf (stdout, "%v: %v\n", h->name, h->value);
}
rspamd_fprintf (stdout, "\n");
@@ -581,9 +618,9 @@ rspamc_output_headers (struct rspamd_http_message *msg)
static void
rspamc_client_cb (struct rspamd_client_connection *conn,
- struct rspamd_http_message *msg,
- const gchar *name, ucl_object_t *result,
- gpointer ud, GError *err)
+ struct rspamd_http_message *msg,
+ const gchar *name, ucl_object_t *result,
+ gpointer ud, GError *err)
{
gchar *out;
struct rspamc_callback_data *cbdata = (struct rspamc_callback_data *)ud;
@@ -628,13 +665,13 @@ rspamc_client_cb (struct rspamd_client_connection *conn,
static void
rspamc_process_input (struct event_base *ev_base, struct rspamc_command *cmd,
- FILE *in, const gchar *name, GHashTable *attrs)
+ FILE *in, const gchar *name, GHashTable *attrs)
{
struct rspamd_client_connection *conn;
gchar **connectv;
guint16 port;
GError *err = NULL;
- struct rspamc_callback_data *cbdata;
+ struct rspamc_callback_data *cbdata;
connectv = g_strsplit_set (connect_str, ":", -1);
@@ -663,11 +700,16 @@ rspamc_process_input (struct event_base *ev_base, struct rspamc_command *cmd,
cbdata->filename = name;
if (cmd->need_input) {
rspamd_client_command (conn, cmd->path, attrs, in, rspamc_client_cb,
- cbdata, &err);
+ cbdata, &err);
}
else {
- rspamd_client_command (conn, cmd->path, attrs, NULL, rspamc_client_cb,
- cbdata, &err);
+ rspamd_client_command (conn,
+ cmd->path,
+ attrs,
+ NULL,
+ rspamc_client_cb,
+ cbdata,
+ &err);
}
}
}
@@ -675,11 +717,11 @@ rspamc_process_input (struct event_base *ev_base, struct rspamc_command *cmd,
gint
main (gint argc, gchar **argv, gchar **env)
{
- gint i, start_argc, cur_req = 0;
- GHashTable *kwattrs;
- struct rspamc_command *cmd;
- FILE *in = NULL;
- struct event_base *ev_base;
+ gint i, start_argc, cur_req = 0;
+ GHashTable *kwattrs;
+ struct rspamc_command *cmd;
+ FILE *in = NULL;
+ struct event_base *ev_base;
kwattrs = g_hash_table_new (rspamd_str_hash, rspamd_str_equal);
@@ -719,18 +761,19 @@ main (gint argc, gchar **argv, gchar **env)
else {
if ((cmd = check_rspamc_command (argv[1])) != NULL) {
/* In case of command read arguments starting from 2 */
- if (cmd->cmd == RSPAMC_COMMAND_ADD_SYMBOL || cmd->cmd == RSPAMC_COMMAND_ADD_ACTION) {
+ if (cmd->cmd == RSPAMC_COMMAND_ADD_SYMBOL || cmd->cmd ==
+ RSPAMC_COMMAND_ADD_ACTION) {
if (argc < 4 || argc > 5) {
fprintf (stderr, "invalid arguments\n");
exit (EXIT_FAILURE);
}
if (argc == 5) {
g_hash_table_insert (kwattrs, "metric", argv[2]);
- g_hash_table_insert (kwattrs, "name", argv[3]);
- g_hash_table_insert (kwattrs, "value", argv[4]);
+ g_hash_table_insert (kwattrs, "name", argv[3]);
+ g_hash_table_insert (kwattrs, "value", argv[4]);
}
else {
- g_hash_table_insert (kwattrs, "name", argv[2]);
+ g_hash_table_insert (kwattrs, "name", argv[2]);
g_hash_table_insert (kwattrs, "value", argv[3]);
}
start_argc = argc;
@@ -752,14 +795,14 @@ main (gint argc, gchar **argv, gchar **env)
rspamc_process_input (ev_base, cmd, in, "stdin", kwattrs);
}
else {
- for (i = start_argc; i < argc; i ++) {
+ for (i = start_argc; i < argc; i++) {
in = fopen (argv[i], "r");
if (in == NULL) {
fprintf (stderr, "cannot open file %s\n", argv[i]);
exit (EXIT_FAILURE);
}
rspamc_process_input (ev_base, cmd, in, argv[i], kwattrs);
- cur_req ++;
+ cur_req++;
fclose (in);
if (cur_req >= max_requests) {
cur_req = 0;
diff --git a/src/client/rspamdclient.c b/src/client/rspamdclient.c
index 55f1a6e37..7034b42fb 100644
--- a/src/client/rspamdclient.c
+++ b/src/client/rspamdclient.c
@@ -21,9 +21,9 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include "http.h"
#include "rspamdclient.h"
#include "util.h"
-#include "http.h"
#ifdef HAVE_FETCH_H
#include <fetch.h>
@@ -62,8 +62,8 @@ rspamd_client_error_quark (void)
static gint
rspamd_client_body_handler (struct rspamd_http_connection *conn,
- struct rspamd_http_message *msg,
- const gchar *chunk, gsize len)
+ struct rspamd_http_message *msg,
+ const gchar *chunk, gsize len)
{
/* Do nothing here */
return 0;
@@ -72,7 +72,8 @@ rspamd_client_body_handler (struct rspamd_http_connection *conn,
static void
rspamd_client_error_handler (struct rspamd_http_connection *conn, GError *err)
{
- struct rspamd_client_request *req = (struct rspamd_client_request *)conn->ud;
+ struct rspamd_client_request *req =
+ (struct rspamd_client_request *)conn->ud;
struct rspamd_client_connection *c;
c = req->conn;
@@ -81,9 +82,10 @@ rspamd_client_error_handler (struct rspamd_http_connection *conn, GError *err)
static gint
rspamd_client_finish_handler (struct rspamd_http_connection *conn,
- struct rspamd_http_message *msg)
+ struct rspamd_http_message *msg)
{
- struct rspamd_client_request *req = (struct rspamd_client_request *)conn->ud;
+ struct rspamd_client_request *req =
+ (struct rspamd_client_request *)conn->ud;
struct rspamd_client_connection *c;
struct ucl_parser *parser;
GError *err;
@@ -93,13 +95,18 @@ rspamd_client_finish_handler (struct rspamd_http_connection *conn,
if (!c->req_sent) {
c->req_sent = TRUE;
rspamd_http_connection_reset (c->http_conn);
- rspamd_http_connection_read_message (c->http_conn, c->req, c->fd, &c->timeout, c->ev_base);
+ rspamd_http_connection_read_message (c->http_conn,
+ c->req,
+ c->fd,
+ &c->timeout,
+ c->ev_base);
return 0;
}
else {
if (msg->body == NULL || msg->body->len == 0 || msg->code != 200) {
err = g_error_new (RCLIENT_ERROR, msg->code, "HTTP error: %d, %s",
- msg->code, msg->status ? msg->status->str : "unknown error");
+ msg->code,
+ msg->status ? msg->status->str : "unknown error");
req->cb (c, msg, c->server_name->str, NULL, req->ud, err);
g_error_free (err);
return -1;
@@ -115,7 +122,8 @@ rspamd_client_finish_handler (struct rspamd_http_connection *conn,
return -1;
}
- req->cb (c, msg, c->server_name->str, ucl_parser_get_object (parser), req->ud, NULL);
+ req->cb (c, msg, c->server_name->str, ucl_parser_get_object (
+ parser), req->ud, NULL);
ucl_parser_free (parser);
}
@@ -124,7 +132,7 @@ rspamd_client_finish_handler (struct rspamd_http_connection *conn,
struct rspamd_client_connection *
rspamd_client_init (struct event_base *ev_base, const gchar *name,
- guint16 port, gdouble timeout)
+ guint16 port, gdouble timeout)
{
struct rspamd_client_connection *conn;
gint fd;
@@ -139,7 +147,10 @@ rspamd_client_init (struct event_base *ev_base, const gchar *name,
conn->fd = fd;
conn->req_sent = FALSE;
conn->http_conn = rspamd_http_connection_new (rspamd_client_body_handler,
- rspamd_client_error_handler, rspamd_client_finish_handler, 0, RSPAMD_HTTP_CLIENT);
+ rspamd_client_error_handler,
+ rspamd_client_finish_handler,
+ 0,
+ RSPAMD_HTTP_CLIENT);
conn->server_name = g_string_new (name);
if (port != 0) {
rspamd_printf_gstring (conn->server_name, ":%d", (int)port);
@@ -152,9 +163,9 @@ rspamd_client_init (struct event_base *ev_base, const gchar *name,
gboolean
rspamd_client_command (struct rspamd_client_connection *conn,
- const gchar *command, GHashTable *attrs,
- FILE *in, rspamd_client_callback cb,
- gpointer ud, GError **err)
+ const gchar *command, GHashTable *attrs,
+ FILE *in, rspamd_client_callback cb,
+ gpointer ud, GError **err)
{
struct rspamd_client_request *req;
gchar *p, *hn, *hv;
@@ -186,7 +197,8 @@ rspamd_client_command (struct rspamd_client_connection *conn,
}
}
if (ferror (in) != 0) {
- g_set_error (err, RCLIENT_ERROR, ferror (in), "input IO error: %s", strerror (ferror (in)));
+ g_set_error (err, RCLIENT_ERROR, ferror (
+ in), "input IO error: %s", strerror (ferror (in)));
g_slice_free1 (sizeof (struct rspamd_client_request), req);
return FALSE;
}
@@ -207,7 +219,7 @@ rspamd_client_command (struct rspamd_client_connection *conn,
conn->req = req;
rspamd_http_connection_write_message (conn->http_conn, req->msg, NULL,
- "text/plain", req, conn->fd, &conn->timeout, conn->ev_base);
+ "text/plain", req, conn->fd, &conn->timeout, conn->ev_base);
return TRUE;
}
diff --git a/src/client/rspamdclient.h b/src/client/rspamdclient.h
index 85b57c376..6a41c35c1 100644
--- a/src/client/rspamdclient.h
+++ b/src/client/rspamdclient.h
@@ -39,12 +39,12 @@ struct rspamd_http_message;
* @param err error pointer
*/
typedef void (*rspamd_client_callback) (
- struct rspamd_client_connection *conn,
- struct rspamd_http_message *msg,
- const gchar *name,
- ucl_object_t *result,
- gpointer ud,
- GError *err);
+ struct rspamd_client_connection *conn,
+ struct rspamd_http_message *msg,
+ const gchar *name,
+ ucl_object_t *result,
+ gpointer ud,
+ GError *err);
/**
* Start rspamd worker or controller command
@@ -54,11 +54,11 @@ typedef void (*rspamd_client_callback) (
* @param timeout timeout in seconds
* @return
*/
-struct rspamd_client_connection* rspamd_client_init (
- struct event_base *ev_base,
- const gchar *name,
- guint16 port,
- gdouble timeout);
+struct rspamd_client_connection * rspamd_client_init (
+ struct event_base *ev_base,
+ const gchar *name,
+ guint16 port,
+ gdouble timeout);
/**
*
@@ -71,13 +71,13 @@ struct rspamd_client_connection* rspamd_client_init (
* @return
*/
gboolean rspamd_client_command (
- struct rspamd_client_connection *conn,
- const gchar *command,
- GHashTable *attrs,
- FILE *in,
- rspamd_client_callback cb,
- gpointer ud,
- GError **err);
+ struct rspamd_client_connection *conn,
+ const gchar *command,
+ GHashTable *attrs,
+ FILE *in,
+ rspamd_client_callback cb,
+ gpointer ud,
+ GError **err);
/**
* Destroy a connection to rspamd