diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2014-01-20 15:44:51 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2014-01-20 15:44:51 +0000 |
commit | 4b21810277a55f7c247f6bead1fadf87a2ad5e45 (patch) | |
tree | 3881e3c79bc4d07bf9747961feb39a142e391dfa /src/client/rspamdclient.c | |
parent | 43a44c7faf94133305a7afd627b3d009a60aa371 (diff) | |
download | rspamd-4b21810277a55f7c247f6bead1fadf87a2ad5e45.tar.gz rspamd-4b21810277a55f7c247f6bead1fadf87a2ad5e45.zip |
New rspamc client.
Diffstat (limited to 'src/client/rspamdclient.c')
-rw-r--r-- | src/client/rspamdclient.c | 45 |
1 files changed, 26 insertions, 19 deletions
diff --git a/src/client/rspamdclient.c b/src/client/rspamdclient.c index c612901e1..7cb913f6f 100644 --- a/src/client/rspamdclient.c +++ b/src/client/rspamdclient.c @@ -36,7 +36,7 @@ struct rspamd_client_connection { struct event_base *ev_base; struct timeval timeout; struct rspamd_http_connection *http_conn; - gboolean connected; + gboolean req_sent; struct rspamd_client_request *req; }; @@ -70,7 +70,7 @@ rspamd_client_error_handler (struct rspamd_http_connection *conn, GError *err) struct rspamd_client_connection *c; c = req->conn; - req->cb (c->server_name->str, NULL, req->ud, err); + req->cb (c, c->server_name->str, NULL, req->ud, err); } static void @@ -83,25 +83,33 @@ rspamd_client_finish_handler (struct rspamd_http_connection *conn, GError *err; c = req->conn; - if (msg->body == NULL || msg->body->len == 0 || msg->code != 200) { - err = g_error_new (RCLIENT_ERROR, msg->code, "HTTP error occurred: %d", msg->code); - req->cb (c->server_name->str, NULL, req->ud, err); - g_error_free (err); - return; + + 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); } + else { + if (msg->body == NULL || msg->body->len == 0 || msg->code != 200) { + err = g_error_new (RCLIENT_ERROR, msg->code, "HTTP error occurred: %d", msg->code); + req->cb (c, c->server_name->str, NULL, req->ud, err); + g_error_free (err); + return; + } - parser = ucl_parser_new (0); - if (!ucl_parser_add_chunk (parser, msg->body->str, msg->body->len)) { - err = g_error_new (RCLIENT_ERROR, msg->code, "Cannot parse UCL: %s", - ucl_parser_get_error (parser)); + parser = ucl_parser_new (0); + if (!ucl_parser_add_chunk (parser, msg->body->str, msg->body->len)) { + err = g_error_new (RCLIENT_ERROR, msg->code, "Cannot parse UCL: %s", + ucl_parser_get_error (parser)); + ucl_parser_free (parser); + req->cb (c, c->server_name->str, NULL, req->ud, err); + g_error_free (err); + return; + } + + req->cb (c, c->server_name->str, ucl_parser_get_object (parser), req->ud, NULL); ucl_parser_free (parser); - req->cb (c->server_name->str, NULL, req->ud, err); - g_error_free (err); - return; } - - req->cb (c->server_name->str, ucl_parser_get_object (parser), req->ud, NULL); - ucl_parser_free (parser); } struct rspamd_client_connection * @@ -119,7 +127,7 @@ rspamd_client_init (struct event_base *ev_base, const gchar *name, conn = g_slice_alloc (sizeof (struct rspamd_client_connection)); conn->ev_base = ev_base; conn->fd = fd; - conn->connected = FALSE; + 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); conn->server_name = g_string_new (name); @@ -197,7 +205,6 @@ rspamd_client_destroy (struct rspamd_client_connection *conn) if (conn != NULL) { rspamd_http_connection_free (conn->http_conn); if (conn->req != NULL) { - rspamd_http_message_free (conn->req->msg); g_slice_free1 (sizeof (struct rspamd_client_request), conn->req); } close (conn->fd); |