Skip to content
This repository has been archived by the owner on Nov 6, 2022. It is now read-only.

Commit

Permalink
src: introduce http_parser_url_init
Browse files Browse the repository at this point in the history
The struct must be zero-initialized, but this wasn't explicitly stated
anywhere in headers. Introduce `http_parser_url_init` API method that
will do it.

Fixes: #209
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
PR-URL: #225
  • Loading branch information
indutny authored and jasnell committed Oct 27, 2015
1 parent 483eca7 commit 777ba4e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion contrib/url_parser.c
Expand Up @@ -35,6 +35,7 @@ int main(int argc, char ** argv) {
connect = strcmp("connect", argv[1]) == 0 ? 1 : 0; connect = strcmp("connect", argv[1]) == 0 ? 1 : 0;
printf("Parsing %s, connect %d\n", argv[2], connect); printf("Parsing %s, connect %d\n", argv[2], connect);


http_parser_url_init(&u);
result = http_parser_parse_url(argv[2], len, connect, &u); result = http_parser_parse_url(argv[2], len, connect, &u);
if (result != 0) { if (result != 0) {
printf("Parse error : %d\n", result); printf("Parse error : %d\n", result);
Expand All @@ -43,4 +44,4 @@ int main(int argc, char ** argv) {
printf("Parse ok, result : \n"); printf("Parse ok, result : \n");
dump_url(argv[2], &u); dump_url(argv[2], &u);
return 0; return 0;
} }
5 changes: 5 additions & 0 deletions http_parser.c
Expand Up @@ -2350,6 +2350,11 @@ http_parse_host(const char * buf, struct http_parser_url *u, int found_at) {
return 0; return 0;
} }


void
http_parser_url_init(struct http_parser_url *u) {
memset(u, 0, sizeof(*u));
}

int int
http_parser_parse_url(const char *buf, size_t buflen, int is_connect, http_parser_parse_url(const char *buf, size_t buflen, int is_connect,
struct http_parser_url *u) struct http_parser_url *u)
Expand Down
3 changes: 3 additions & 0 deletions http_parser.h
Expand Up @@ -333,6 +333,9 @@ const char *http_errno_name(enum http_errno err);
/* Return a string description of the given error */ /* Return a string description of the given error */
const char *http_errno_description(enum http_errno err); const char *http_errno_description(enum http_errno err);


/* Initialize all http_parser_url members to 0 */
void http_parser_url_init(struct http_parser_url *u);

/* Parse a URL; return nonzero on failure */ /* Parse a URL; return nonzero on failure */
int http_parser_parse_url(const char *buf, size_t buflen, int http_parser_parse_url(const char *buf, size_t buflen,
int is_connect, int is_connect,
Expand Down

0 comments on commit 777ba4e

Please sign in to comment.