diff options
author | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2009-02-06 20:04:54 +0300 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2009-02-06 20:04:54 +0300 |
commit | acec2b42286f734eacb7bab14d7d20e1110f4545 (patch) | |
tree | 9d2c91f31111495e986523a6baac3874688e16f0 /src/util.c | |
parent | 7f8de787946b883cc791bf6c0bcb514496caf074 (diff) | |
download | rspamd-acec2b42286f734eacb7bab14d7d20e1110f4545.tar.gz rspamd-acec2b42286f734eacb7bab14d7d20e1110f4545.zip |
* Try to fix reading a line from user (using pools)
Diffstat (limited to 'src/util.c')
-rw-r--r-- | src/util.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/util.c b/src/util.c index 9444592cf..0cda8a8c8 100644 --- a/src/util.c +++ b/src/util.c @@ -894,5 +894,50 @@ resolve_stat_filename (memory_pool_t *pool, char *pattern, char *rcpt, char *fro } /* + * These functions are from libevent where they are static and not exported anywhere + * XXX: think how to avoid this + */ + +char * +buffer_readline (memory_pool_t *pool, struct evbuffer *buf) +{ + u_char *data = EVBUFFER_DATA (buf); + size_t len = EVBUFFER_LENGTH (buf); + char *line, fch, sch; + unsigned int i; + + for (i = 0; i < len; i++) { + if (data[i] == '\r' || data[i] == '\n') { + break; + } + } + + if (i == len) { + return (NULL); + } + + line = memory_pool_alloc (pool, i + 1); + + memcpy (line, data, i); + line[i] = '\0'; + + /* + * Some protocols terminate a line with '\r\n', so check for + * that, too. + */ + if ( i < len - 1 ) { + fch = data[i], sch = data[i+1]; + + /* Drain one more character if needed */ + if ( (sch == '\r' || sch == '\n') && sch != fch ) + i += 1; + } + + evbuffer_drain (buf, i + 1); + + return (line); +} + +/* * vi:ts=4 */ |