From 3f83e91fb22caed086aae60afbf365b8de9cb835 Mon Sep 17 00:00:00 2001 From: Roberto De Ioris Date: Fri, 18 Jan 2013 09:57:19 +0100 Subject: [PATCH] added uwsgi_buffer_insert() --- core/buffer.c | 11 ++++++++++- core/uwsgi.c | 2 +- uwsgi.h | 2 ++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/core/buffer.c b/core/buffer.c index 4b68e536..f8bd8cb8 100644 --- a/core/buffer.c +++ b/core/buffer.c @@ -48,9 +48,18 @@ int uwsgi_buffer_ensure(struct uwsgi_buffer *ub, size_t len) { return 0; } +int uwsgi_buffer_insert(struct uwsgi_buffer *ub, size_t pos, char *buf, size_t len) { + size_t to_move = (ub->pos-pos); + if (uwsgi_buffer_ensure(ub, len)) return -1; + memmove(ub->buf+pos+len, ub->buf+pos, to_move); + memcpy(ub->buf+pos, buf, len); + ub->pos += len; + return 0; +} + int uwsgi_buffer_decapitate(struct uwsgi_buffer *ub, size_t len) { if (len > ub->pos) return -1; - ub->buf = memmove(ub->buf, ub->buf + len, ub->pos-len); + memmove(ub->buf, ub->buf + len, ub->pos-len); ub->pos = ub->pos-len; return 0; } diff --git a/core/uwsgi.c b/core/uwsgi.c index 7a5a0f04..f4c6c1d1 100644 --- a/core/uwsgi.c +++ b/core/uwsgi.c @@ -2,7 +2,7 @@ *** uWSGI *** - Copyright (C) 2009-2012 Unbit S.a.s. + Copyright (C) 2009-2013 Unbit S.a.s. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/uwsgi.h b/uwsgi.h index 714f48e6..9f146862 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -3574,6 +3574,8 @@ int uwsgi_buffer_append_ipv4(struct uwsgi_buffer *, void *); int uwsgi_buffer_append_keyipv4(struct uwsgi_buffer *, char *, uint16_t, void *); int uwsgi_buffer_decapitate(struct uwsgi_buffer *, size_t); int uwsgi_buffer_append_base64(struct uwsgi_buffer *, char *, size_t); +int uwsgi_buffer_insert(struct uwsgi_buffer *, size_t, char *, size_t); + ssize_t uwsgi_buffer_write_simple(struct wsgi_request *, struct uwsgi_buffer *); void uwsgi_httpize_var(char *, size_t);