kore

An easy to use, scalable and secure web application framework for writing web APIs in C.
Commits | Files | Refs | README | LICENSE | git clone https://git.kore.io/kore.git

commit b0700162c4627501de91a3046990f4913bf04d57
parent 9b3ff7db5342b87380729be71dd8c421f0d2cbb3
Author: Joris Vink <joris@coders.se>
Date:   Mon,  4 Aug 2014 21:03:26 +0200

Make http_post_data_bytes() and http_post_data_text() available

Diffstat:
includes/http.h | 2++
src/http.c | 73+++++++++++++++++++++++++++++++++++--------------------------------------
2 files changed, 37 insertions(+), 38 deletions(-)

diff --git a/includes/http.h b/includes/http.h @@ -197,7 +197,9 @@ time_t http_date_to_time(char *); void http_request_free(struct http_request *); void http_request_sleep(struct http_request *); void http_request_wakeup(struct http_request *); +char *http_post_data_text(struct http_request *); void http_process_request(struct http_request *, int); +u_int8_t *http_post_data_bytes(struct http_request *, u_int32_t *); void http_response(struct http_request *, int, void *, u_int32_t); int http_request_header_get(struct http_request *, const char *, char **); diff --git a/src/http.c b/src/http.c @@ -33,11 +33,8 @@ static char *http_status_text(int); static int http_post_data_recv(struct netbuf *); -static char *http_post_data_text(struct http_request *); static void http_error_response(struct connection *, struct spdy_stream *, int); -static u_int8_t *http_post_data_bytes(struct http_request *, - u_int32_t *); static void http_argument_add(struct http_request *, const char *, void *, u_int32_t, int); static void http_file_add(struct http_request *, const char *, @@ -892,6 +889,41 @@ http_generic_404(struct http_request *req) return (KORE_RESULT_OK); } +char * +http_post_data_text(struct http_request *req) +{ + u_int32_t len; + u_int8_t *data; + char *text; + + if (req->post_data == NULL) + return (NULL); + + data = kore_buf_release(req->post_data, &len); + req->post_data = NULL; + len++; + + text = kore_malloc(len); + kore_strlcpy(text, (char *)data, len); + kore_mem_free(data); + + return (text); +} + +u_int8_t * +http_post_data_bytes(struct http_request *req, u_int32_t *len) +{ + u_int8_t *data; + + if (req->post_data == NULL) + return (NULL); + + data = kore_buf_release(req->post_data, len); + req->post_data = NULL; + + return (data); +} + static void http_argument_add(struct http_request *req, const char *name, void *value, u_int32_t len, int type) @@ -963,41 +995,6 @@ http_post_data_recv(struct netbuf *nb) return (KORE_RESULT_OK); } -static char * -http_post_data_text(struct http_request *req) -{ - u_int32_t len; - u_int8_t *data; - char *text; - - if (req->post_data == NULL) - return (NULL); - - data = kore_buf_release(req->post_data, &len); - req->post_data = NULL; - len++; - - text = kore_malloc(len); - kore_strlcpy(text, (char *)data, len); - kore_mem_free(data); - - return (text); -} - -static u_int8_t * -http_post_data_bytes(struct http_request *req, u_int32_t *len) -{ - u_int8_t *data; - - if (req->post_data == NULL) - return (NULL); - - data = kore_buf_release(req->post_data, len); - req->post_data = NULL; - - return (data); -} - static void http_error_response(struct connection *c, struct spdy_stream *s, int status) {