diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2014-07-23 12:57:31 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2014-07-23 12:57:31 +0100 |
commit | 379055dbbb4af997b4d3ffb161d447872d7ca357 (patch) | |
tree | 3774553d470f93e12ddeb454aad9b3b607cf8918 /src/libserver/proxy.c | |
parent | 602ae7a0b7e215ba2677131b8fdc70abc156b3ca (diff) | |
download | rspamd-379055dbbb4af997b4d3ffb161d447872d7ca357.tar.gz rspamd-379055dbbb4af997b4d3ffb161d447872d7ca357.zip |
Unify style without sorting headers.
Diffstat (limited to 'src/libserver/proxy.c')
-rw-r--r-- | src/libserver/proxy.c | 108 |
1 files changed, 79 insertions, 29 deletions
diff --git a/src/libserver/proxy.c b/src/libserver/proxy.c index 67c7665b8..a4076954b 100644 --- a/src/libserver/proxy.c +++ b/src/libserver/proxy.c @@ -28,7 +28,7 @@ static void rspamd_proxy_backend_handler (gint fd, gshort what, gpointer data); static void rspamd_proxy_client_handler (gint fd, gshort what, gpointer data); -static inline GQuark +static inline GQuark proxy_error_quark (void) { return g_quark_from_static_string ("proxy-error"); @@ -50,9 +50,9 @@ rspamd_proxy_close (rspamd_proxy_t *proxy) static void rspamd_proxy_client_handler (gint fd, gshort what, gpointer data) { - rspamd_proxy_t *proxy = data; - gint r; - GError *err = NULL; + rspamd_proxy_t *proxy = data; + gint r; + GError *err = NULL; if (what == EV_READ) { /* Got data from client */ @@ -63,14 +63,20 @@ rspamd_proxy_client_handler (gint fd, gshort what, gpointer data) proxy->read_len = r; proxy->buf_offset = 0; event_del (&proxy->backend_ev); - event_set (&proxy->backend_ev, proxy->bfd, EV_WRITE, rspamd_proxy_backend_handler, proxy); + event_set (&proxy->backend_ev, + proxy->bfd, + EV_WRITE, + rspamd_proxy_backend_handler, + proxy); event_add (&proxy->backend_ev, proxy->tv); } else { /* Error case or zero reply */ if (r < 0) { /* Error case */ - g_set_error (&err, proxy_error_quark(), r, "Client read error: %s", strerror (errno)); + g_set_error (&err, + proxy_error_quark (), r, "Client read error: %s", + strerror (errno)); rspamd_proxy_close (proxy); proxy->err_cb (err, proxy->user_data); } @@ -83,17 +89,27 @@ rspamd_proxy_client_handler (gint fd, gshort what, gpointer data) } else if (what == EV_WRITE) { /* Can write to client */ - r = write (proxy->cfd, proxy->buf + proxy->buf_offset, proxy->read_len - proxy->buf_offset); + r = write (proxy->cfd, + proxy->buf + proxy->buf_offset, + proxy->read_len - proxy->buf_offset); if (r > 0) { /* We wrote something */ - proxy->buf_offset +=r; + proxy->buf_offset += r; if (proxy->buf_offset == proxy->read_len) { /* We wrote everything */ event_del (&proxy->client_ev); - event_set (&proxy->client_ev, proxy->cfd, EV_READ, rspamd_proxy_client_handler, proxy); + event_set (&proxy->client_ev, + proxy->cfd, + EV_READ, + rspamd_proxy_client_handler, + proxy); event_add (&proxy->client_ev, proxy->tv); event_del (&proxy->backend_ev); - event_set (&proxy->backend_ev, proxy->bfd, EV_READ, rspamd_proxy_backend_handler, proxy); + event_set (&proxy->backend_ev, + proxy->bfd, + EV_READ, + rspamd_proxy_backend_handler, + proxy); event_add (&proxy->backend_ev, proxy->tv); } else { @@ -105,7 +121,9 @@ rspamd_proxy_client_handler (gint fd, gshort what, gpointer data) /* Error case or zero reply */ if (r < 0) { /* Error case */ - g_set_error (&err, proxy_error_quark(), r, "Client write error: %s", strerror (errno)); + g_set_error (&err, + proxy_error_quark (), r, "Client write error: %s", + strerror (errno)); rspamd_proxy_close (proxy); proxy->err_cb (err, proxy->user_data); } @@ -118,7 +136,7 @@ rspamd_proxy_client_handler (gint fd, gshort what, gpointer data) } else { /* Got timeout */ - g_set_error (&err, proxy_error_quark(), ETIMEDOUT, "Client timeout"); + g_set_error (&err, proxy_error_quark (), ETIMEDOUT, "Client timeout"); rspamd_proxy_close (proxy); proxy->err_cb (err, proxy->user_data); } @@ -127,9 +145,9 @@ rspamd_proxy_client_handler (gint fd, gshort what, gpointer data) static void rspamd_proxy_backend_handler (gint fd, gshort what, gpointer data) { - rspamd_proxy_t *proxy = data; - gint r; - GError *err = NULL; + rspamd_proxy_t *proxy = data; + gint r; + GError *err = NULL; if (what == EV_READ) { /* Got data from backend */ @@ -140,14 +158,20 @@ rspamd_proxy_backend_handler (gint fd, gshort what, gpointer data) proxy->read_len = r; proxy->buf_offset = 0; event_del (&proxy->client_ev); - event_set (&proxy->client_ev, proxy->bfd, EV_WRITE, rspamd_proxy_client_handler, proxy); + event_set (&proxy->client_ev, + proxy->bfd, + EV_WRITE, + rspamd_proxy_client_handler, + proxy); event_add (&proxy->client_ev, proxy->tv); } else { /* Error case or zero reply */ if (r < 0) { /* Error case */ - g_set_error (&err, proxy_error_quark(), r, "Backend read error: %s", strerror (errno)); + g_set_error (&err, + proxy_error_quark (), r, "Backend read error: %s", + strerror (errno)); rspamd_proxy_close (proxy); proxy->err_cb (err, proxy->user_data); } @@ -160,17 +184,27 @@ rspamd_proxy_backend_handler (gint fd, gshort what, gpointer data) } else if (what == EV_WRITE) { /* Can write to backend */ - r = write (proxy->bfd, proxy->buf + proxy->buf_offset, proxy->read_len - proxy->buf_offset); + r = write (proxy->bfd, + proxy->buf + proxy->buf_offset, + proxy->read_len - proxy->buf_offset); if (r > 0) { /* We wrote something */ - proxy->buf_offset +=r; + proxy->buf_offset += r; if (proxy->buf_offset == proxy->read_len) { /* We wrote everything */ event_del (&proxy->backend_ev); - event_set (&proxy->backend_ev, proxy->bfd, EV_READ, rspamd_proxy_backend_handler, proxy); + event_set (&proxy->backend_ev, + proxy->bfd, + EV_READ, + rspamd_proxy_backend_handler, + proxy); event_add (&proxy->backend_ev, proxy->tv); event_del (&proxy->client_ev); - event_set (&proxy->client_ev, proxy->cfd, EV_READ, rspamd_proxy_client_handler, proxy); + event_set (&proxy->client_ev, + proxy->cfd, + EV_READ, + rspamd_proxy_client_handler, + proxy); event_add (&proxy->client_ev, proxy->tv); } else { @@ -182,7 +216,9 @@ rspamd_proxy_backend_handler (gint fd, gshort what, gpointer data) /* Error case or zero reply */ if (r < 0) { /* Error case */ - g_set_error (&err, proxy_error_quark(), r, "Backend write error: %s", strerror (errno)); + g_set_error (&err, + proxy_error_quark (), r, "Backend write error: %s", + strerror (errno)); rspamd_proxy_close (proxy); proxy->err_cb (err, proxy->user_data); } @@ -195,7 +231,7 @@ rspamd_proxy_backend_handler (gint fd, gshort what, gpointer data) } else { /* Got timeout */ - g_set_error (&err, proxy_error_quark(), ETIMEDOUT, "Client timeout"); + g_set_error (&err, proxy_error_quark (), ETIMEDOUT, "Client timeout"); rspamd_proxy_close (proxy); proxy->err_cb (err, proxy->user_data); } @@ -210,11 +246,17 @@ rspamd_proxy_backend_handler (gint fd, gshort what, gpointer data) * @param ud user data for callback * @return new proxy object */ -rspamd_proxy_t* -rspamd_create_proxy (gint cfd, gint bfd, rspamd_mempool_t *pool, struct event_base *base, - gsize bufsize, struct timeval *tv, dispatcher_err_callback_t err_cb, gpointer ud) +rspamd_proxy_t * +rspamd_create_proxy (gint cfd, + gint bfd, + rspamd_mempool_t *pool, + struct event_base *base, + gsize bufsize, + struct timeval *tv, + dispatcher_err_callback_t err_cb, + gpointer ud) { - rspamd_proxy_t *new; + rspamd_proxy_t *new; new = rspamd_mempool_alloc0 (pool, sizeof (rspamd_proxy_t)); @@ -229,11 +271,19 @@ rspamd_create_proxy (gint cfd, gint bfd, rspamd_mempool_t *pool, struct event_ba new->tv = tv; /* Set client's and backend's interfaces to read events */ - event_set (&new->client_ev, new->cfd, EV_READ, rspamd_proxy_client_handler, new); + event_set (&new->client_ev, + new->cfd, + EV_READ, + rspamd_proxy_client_handler, + new); event_base_set (new->base, &new->client_ev); event_add (&new->client_ev, new->tv); - event_set (&new->backend_ev, new->bfd, EV_READ, rspamd_proxy_backend_handler, new); + event_set (&new->backend_ev, + new->bfd, + EV_READ, + rspamd_proxy_backend_handler, + new); event_base_set (new->base, &new->backend_ev); event_add (&new->backend_ev, new->tv); |