http-parser.c

Small C library to parse HTTP requests
Log | Files | Refs | README | LICENSE

commit f5f019b2424dc7255df6a61412cd962c678dc1dd
parent a7d424d186f02de4d25d948ff0992356e8aa2252
Author: finwo <finwo@pm.me>
Date:   Fri, 17 Apr 2020 14:05:11 +0200

Renamed _print_ functions to _sprint_

Diffstat:
MMakefile | 2--
Msrc/http-parser.c | 16++++++++--------
Msrc/http-parser.h | 8++++----
Mtest.c | 8++++----
4 files changed, 16 insertions(+), 18 deletions(-)

diff --git a/Makefile b/Makefile @@ -1,5 +1,3 @@ - - http-parser-test: test.c src/http-parser.c $(CC) -o $@ $^ diff --git a/src/http-parser.c b/src/http-parser.c @@ -278,15 +278,15 @@ static int http_parser_message_read_chunked(struct http_parser_message *message) return 2; } -char * http_parser_print_pair_response(struct http_parser_pair *pair) { - return http_parser_print_response(pair->response); +char * http_parser_sprint_pair_response(struct http_parser_pair *pair) { + return http_parser_sprint_response(pair->response); } -char * http_parser_print_pair_quest(struct http_parser_pair *pair) { - return http_parser_print_response(pair->response); +char * http_parser_sprint_pair_quest(struct http_parser_pair *pair) { + return http_parser_sprint_response(pair->response); } -char * http_parser_print_response(struct http_parser_message *response) { +char * http_parser_sprint_response(struct http_parser_message *response) { char *result = calloc(1,256); struct http_parser_header *header; int index, length; @@ -334,10 +334,10 @@ char * http_parser_print_response(struct http_parser_message *response) { *(result + length) = '\0'; memcpy( result + index + 2, response->body, response->bodysize ); - return result;; + return result; } -char * http_parser_print_request(struct http_parser_message *request) { +char * http_parser_sprint_request(struct http_parser_message *request) { char *result = calloc(1,8192); struct http_parser_header *header; int index, length; @@ -410,7 +410,7 @@ char * http_parser_print_request(struct http_parser_message *request) { *(result+length+5) = '\0'; } - return result;; + return result; } /** diff --git a/src/http-parser.h b/src/http-parser.h @@ -69,10 +69,10 @@ void http_parser_pair_response_data(struct http_parser_pair *pair, char *data, i void http_parser_pair_free(struct http_parser_pair *pair); void http_parser_message_free(struct http_parser_message *subject); -char * http_parser_print_pair_response(struct http_parser_pair *pair); -char * http_parser_print_pair_request(struct http_parser_pair *pair); -char * http_parser_print_response(struct http_parser_message *response); -char * http_parser_print_request(struct http_parser_message *request); +char * http_parser_sprint_pair_response(struct http_parser_pair *pair); +char * http_parser_sprint_pair_request(struct http_parser_pair *pair); +char * http_parser_sprint_response(struct http_parser_message *response); +char * http_parser_sprint_request(struct http_parser_message *request); #ifdef __cplusplus } // extern "C" diff --git a/test.c b/test.c @@ -117,7 +117,7 @@ int main() { ASSERT("request->version is 1.1", strcmp(request->version, "1.1") == 0); ASSERT("request->method is GET", strcmp(request->method, "GET") == 0); ASSERT("request->path is /foobar", strcmp(request->path, "/foobar") == 0); - ASSERT("request->toString matches", strcmp(getMessage, http_parser_print_request(request))); + ASSERT("request->toString matches", strcmp(getMessage, http_parser_sprint_request(request))); http_parser_message_free(request); request = http_parser_request_init(); @@ -128,7 +128,7 @@ int main() { ASSERT("request->method is POST", strcmp(request->method, "POST") == 0); ASSERT("request->path is /foobar", strcmp(request->path, "/foobar") == 0); ASSERT("request->body is \"Helo World\\r\\n\"", strcmp(request->body, "Hello World\r\n") == 0); - ASSERT("request->toString matches", strcmp(postMessage, http_parser_print_request(request))); + ASSERT("request->toString matches", strcmp(postMessage, http_parser_sprint_request(request))); http_parser_message_free(request); request = http_parser_request_init(); @@ -151,7 +151,7 @@ int main() { ASSERT("response->status = 200", response->status == 200); ASSERT("response->statusmessage = \"OK\"", strcmp(response->statusMessage, "OK") == 0); ASSERT("response->body = \"Hello World\\r\\n\"", strcmp(response->body, "Hello World\r\n") == 0); - ASSERT("response->toString matches", strcmp(responseMessage, http_parser_print_response(response))); + ASSERT("response->toString matches", strcmp(responseMessage, http_parser_sprint_response(response))); http_parser_message_free(response); response = http_parser_response_init(); @@ -170,7 +170,7 @@ int main() { ASSERT("response->status = 404", response->status == 404); ASSERT("response->statusmessage = \"Not Found\"", strcmp(response->statusMessage, "Not Found") == 0); ASSERT("response->body = \"Not Found\\r\\n\"", strcmp(response->body, "Not Found\r\n") == 0); - ASSERT("response->toString matches", strcmp(responseNotFoundMessage, http_parser_print_response(response))); + ASSERT("response->toString matches", strcmp(responseNotFoundMessage, http_parser_sprint_response(response))); return err; }