kore

Kore is a web application platform for writing scalable, concurrent web based processes in C or Python.
Commits | Files | Refs | README | LICENSE | git clone https://git.kore.io/kore.git

commit 2dfd22a79a7d8c04a43970b3f69c4d291d39b43a
parent 3b43df553658505881a0461070bba785cc522408
Author: Joris Vink <joris@coders.se>
Date:   Thu,  2 Jun 2016 07:08:19 +0200

Change kore_buf_stringify() a bit.

Takes a size_t pointer as its second argument now, if not
NULL this will be populated with the length of the string
that is being returned.

Diffstat:
includes/kore.h | 2+-
src/buf.c | 6+++++-
src/cli.c | 4++--
src/http.c | 8++++----
4 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/includes/kore.h b/includes/kore.h @@ -603,7 +603,7 @@ void kore_buf_append(struct kore_buf *, const void *, u_int32_t); u_int8_t *kore_buf_release(struct kore_buf *, u_int32_t *); void kore_buf_reset(struct kore_buf *); -char *kore_buf_stringify(struct kore_buf *); +char *kore_buf_stringify(struct kore_buf *, size_t *); void kore_buf_appendf(struct kore_buf *, const char *, ...); void kore_buf_appendv(struct kore_buf *, const char *, va_list); void kore_buf_appendb(struct kore_buf *, struct kore_buf *); diff --git a/src/buf.c b/src/buf.c @@ -94,12 +94,16 @@ kore_buf_appendf(struct kore_buf *buf, const char *fmt, ...) } char * -kore_buf_stringify(struct kore_buf *buf) +kore_buf_stringify(struct kore_buf *buf, size_t *len) { char c; + if (len != NULL) + *len = buf->offset; + c = '\0'; kore_buf_append(buf, &c, sizeof(c)); + return ((char *)buf->data); } diff --git a/src/cli.c b/src/cli.c @@ -1206,7 +1206,7 @@ cli_build_cflags(struct buildopt *bopt) obopt->cflags->offset); } - string = kore_buf_stringify(bopt->cflags); + string = kore_buf_stringify(bopt->cflags, NULL); printf("CFLAGS=%s\n", string); cflags_count = kore_split_string(string, " ", cflags, CFLAGS_MAX); } @@ -1235,7 +1235,7 @@ cli_build_ldflags(struct buildopt *bopt) obopt->ldflags->offset); } - string = kore_buf_stringify(bopt->ldflags); + string = kore_buf_stringify(bopt->ldflags, NULL); printf("LDFLAGS=%s\n", string); ldflags_count = kore_split_string(string, " ", ldflags, LD_FLAGS_MAX); } diff --git a/src/http.c b/src/http.c @@ -915,7 +915,7 @@ http_populate_post(struct http_request *req) if (req->http_body != NULL) { body = NULL; req->http_body->offset = req->content_length; - string = kore_buf_stringify(req->http_body); + string = kore_buf_stringify(req->http_body, NULL); } else { body = kore_buf_create(128); for (;;) { @@ -926,7 +926,7 @@ http_populate_post(struct http_request *req) break; kore_buf_append(body, data, ret); } - string = kore_buf_stringify(body); + string = kore_buf_stringify(body, NULL); } v = kore_split_string(string, "&", args, HTTP_MAX_QUERY_ARGS); @@ -1171,7 +1171,7 @@ multipart_parse_headers(struct http_request *req, struct kore_buf *in, char *headers[5], *args[5], *opt[5]; char *d, *val, *name, *fname, *string; - string = kore_buf_stringify(hbuf); + string = kore_buf_stringify(hbuf, NULL); h = kore_split_string(string, "\r\n", headers, 5); for (i = 0; i < h; i++) { c = kore_split_string(headers[i], ":", args, 5); @@ -1252,7 +1252,7 @@ multipart_add_field(struct http_request *req, struct kore_buf *in, } data->offset -= 2; - string = kore_buf_stringify(data); + string = kore_buf_stringify(data, NULL); http_argument_add(req, name, string); kore_buf_free(data); }