return TRUE;
}
+static struct rspamd_buffer_buf *
+allocate_buffer (rspamd_mempool_t *pool, gsize size)
+{
+ struct rspamd_buffer_buf *b;
+
+ b = rspamd_mempool_alloc_tmp (pool, sizeof (*b));
+ b->begin = rspamd_mempool_alloc_tmp (pool, size);
+ b->size = size;
+ b->len = 0;
+
+ return b;
+}
+
static void
read_buffers (gint fd, rspamd_io_dispatcher_t * d, gboolean skip_read)
{
ssize_t r;
GError *err = NULL;
- rspamd_fstring_t res;
- gchar *c, *b;
- gchar *end;
+ rspamd_ftok_t res;
+ guchar *c, *b;
+ guchar *end;
size_t len;
enum io_policy saved_policy;
d->in_buf =
rspamd_mempool_alloc_tmp (d->pool, sizeof (rspamd_buffer_t));
if (d->policy == BUFFER_LINE || d->policy == BUFFER_ANY) {
- d->in_buf->data = rspamd_fstralloc_tmp (d->pool, d->default_buf_size);
+ d->in_buf->data = allocate_buffer (d->pool, d->default_buf_size);
}
else {
- d->in_buf->data = rspamd_fstralloc_tmp (d->pool, d->nchars + 1);
+ d->in_buf->data = allocate_buffer (d->pool, d->nchars + 1);
}
d->in_buf->pos = d->in_buf->data->begin;
}
enum io_policy policy,
size_t nchars)
{
- rspamd_fstring_t *tmp;
+ struct rspamd_buffer_buf *tmp;
gint t;
if (d->policy != policy || nchars != d->nchars) {
/* Resize input buffer if needed */
if (policy == BUFFER_CHARACTER && nchars != 0) {
if (d->in_buf && d->in_buf->data->size < nchars) {
- tmp = rspamd_fstralloc_tmp (d->pool, d->nchars + 1);
+ tmp = allocate_buffer (d->pool, d->nchars + 1);
memcpy (tmp->begin, d->in_buf->data->begin,
d->in_buf->data->len);
t = d->in_buf->pos - d->in_buf->data->begin;
}
else if (policy == BUFFER_LINE || policy == BUFFER_ANY) {
if (d->in_buf && d->nchars < d->default_buf_size) {
- tmp = rspamd_fstralloc_tmp (d->pool, d->default_buf_size);
+ tmp = allocate_buffer (d->pool, d->default_buf_size);
memcpy (tmp->begin, d->in_buf->data->begin,
d->in_buf->data->len);
t = d->in_buf->pos - d->in_buf->data->begin;
return TRUE;
}
-gboolean
-rspamd_dispatcher_write_string (rspamd_io_dispatcher_t *d,
- GString *str,
- gboolean delayed,
- gboolean free_on_write)
-{
- struct rspamd_out_buffer_s *newbuf;
-
- newbuf = g_slice_alloc (sizeof (struct rspamd_out_buffer_s));
- newbuf->data = str;
- newbuf->allocated = free_on_write;
-
- APPEND_OUT_BUFFER (d, newbuf);
-
- if (!delayed) {
- debug_ip ("plan write event");
- return write_buffers (d->fd, d, FALSE);
- }
- /* Otherwise plan write event */
- event_del (d->ev);
- event_set (d->ev, d->fd, EV_WRITE, dispatcher_cb, (void *)d);
- event_base_set (d->ev_base, d->ev);
- event_add (d->ev, d->tv);
-
- return TRUE;
-}
-
gboolean
rspamd_dispatcher_sendfile (rspamd_io_dispatcher_t *d, gint fd, size_t len)
{
}
#undef debug_ip
-
-/*
- * vi:ts=4
- */
#include "mem_pool.h"
#include "fstring.h"
-typedef gboolean (*dispatcher_read_callback_t)(rspamd_fstring_t *in, void *user_data);
+typedef gboolean (*dispatcher_read_callback_t)(rspamd_ftok_t *in, void *user_data);
typedef gboolean (*dispatcher_write_callback_t)(void *user_data);
typedef void (*dispatcher_err_callback_t)(GError *err, void *user_data);
/**
* Buffer structure
*/
+struct rspamd_buffer_buf {
+ gsize size;
+ gsize len;
+ guchar *begin;
+};
+
typedef struct rspamd_buffer_s {
- rspamd_fstring_t *data; /**< buffer logic */
- gchar *pos; /**< current position */
+ struct rspamd_buffer_buf *data;
+ guchar *pos; /**< current position */
} rspamd_buffer_t;
struct rspamd_out_buffer_s {
size_t len, gboolean delayed,
gboolean allocated) G_GNUC_WARN_UNUSED_RESULT;
-/**
- * Write a GString to dispatcher
- * @param d dipatcher object
- * @param str string to write
- * @param delayed delay write
- * @param free_on_write free string after writing to a socket
- * @return TRUE if write has been queued successfully
- */
-gboolean rspamd_dispatcher_write_string (rspamd_io_dispatcher_t *d,
- GString *str,
- gboolean delayed,
- gboolean free_on_write) G_GNUC_WARN_UNUSED_RESULT;
-
/**
* Send specified descriptor to dispatcher
* @param d pointer to dispatcher's object
/* Dispatcher callbacks */
static gboolean
-lua_io_read_cb (rspamd_fstring_t * in, void *arg)
+lua_io_read_cb (rspamd_ftok_t * in, void *arg)
{
struct lua_dispatcher_cbdata *cbdata = arg;
gboolean res;
lua_newuserdata (cbdata->L, sizeof (struct rspamd_io_dispatcher_s *));
rspamd_lua_setclass (cbdata->L, "rspamd{io_dispatcher}", -1);
*pdispatcher = cbdata->d;
- lua_pushlstring (cbdata->L, in->str, in->len);
+ lua_pushlstring (cbdata->L, in->begin, in->len);
if (lua_pcall (cbdata->L, 2, 1, 0) != 0) {
msg_info ("call to session finalizer failed: %s",