Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Coding style improvment

  • Loading branch information...
commit bb29f437411d8aa6403bc4e1d913320b783e6417 1 parent e42aa93
Bertrand Paquet authored
Showing with 22 additions and 15 deletions.
  1. +11 −10 http_parser.c
  2. +11 −5 test.c
View
21 http_parser.c
@@ -354,8 +354,12 @@ enum http_host_state
#define IS_NUM(c) ((c) >= '0' && (c) <= '9')
#define IS_ALPHANUM(c) (IS_ALPHA(c) || IS_NUM(c))
#define IS_HEX(c) (IS_NUM(c) || (LOWER(c) >= 'a' && LOWER(c) <= 'f'))
-#define IS_MARK(c) ((c) == '-' || (c) == '_' || (c) == '.' || (c) == '!' || (c) == '~' || (c) == '*' || (c) == '\'' || (c) == '(' || (c) == ')')
-#define IS_USERINFO_CHAR(c) (IS_ALPHANUM(c) || IS_MARK(c) || (c) == '%' || (c) == ';' || (c) == ':' || (c) == '&' || (c) == '=' || (c) == '+' || (c) == '$' || (c) == ',')
+#define IS_MARK(c) ((c) == '-' || (c) == '_' || (c) == '.' || \
+ (c) == '!' || (c) == '~' || (c) == '*' || (c) == '\'' || (c) == '(' || \
+ (c) == ')')
+#define IS_USERINFO_CHAR(c) (IS_ALPHANUM(c) || IS_MARK(c) || (c) == '%' || \
+ (c) == ';' || (c) == ':' || (c) == '&' || (c) == '=' || (c) == '+' || \
+ (c) == '$' || (c) == ',')
#if HTTP_PARSER_STRICT
#define TOKEN(c) (tokens[(unsigned char)c])
@@ -412,7 +416,7 @@ int http_message_needs_eof(http_parser *parser);
* URL and non-URL states by looking for these.
*/
static enum state
-parse_url_char(enum state s, const char ch, int * found_at)
+parse_url_char(enum state s, const char ch, int *found_at)
{
if (ch == ' ' || ch == '\r' || ch == '\n') {
return s_dead;
@@ -970,7 +974,7 @@ size_t http_parser_execute (http_parser *parser,
parser->state = s_req_host_start;
}
- parser->state = parse_url_char((enum state)parser->state, ch, 0);
+ parser->state = parse_url_char((enum state)parser->state, ch, NULL);
if (parser->state == s_dead) {
SET_ERRNO(HPE_INVALID_URL);
goto error;
@@ -992,7 +996,7 @@ size_t http_parser_execute (http_parser *parser,
SET_ERRNO(HPE_INVALID_URL);
goto error;
default:
- parser->state = parse_url_char((enum state)parser->state, ch, 0);
+ parser->state = parse_url_char((enum state)parser->state, ch, NULL);
if (parser->state == s_dead) {
SET_ERRNO(HPE_INVALID_URL);
goto error;
@@ -1024,7 +1028,7 @@ size_t http_parser_execute (http_parser *parser,
CALLBACK_DATA(url);
break;
default:
- parser->state = parse_url_char((enum state)parser->state, ch, 0);
+ parser->state = parse_url_char((enum state)parser->state, ch, NULL);
if (parser->state == s_dead) {
SET_ERRNO(HPE_INVALID_URL);
goto error;
@@ -1927,7 +1931,6 @@ http_parse_host_char(enum http_host_state s, const char ch) {
break;
case s_http_host:
-
if (IS_HOST_CHAR(ch)) {
return s_http_host;
}
@@ -1967,8 +1970,6 @@ http_parse_host_char(enum http_host_state s, const char ch) {
return s_http_host_dead;
}
-#include <stdio.h>
-
static int
http_parse_host(const char * buf, struct http_parser_url *u, int found_at) {
enum http_host_state s;
@@ -2109,7 +2110,7 @@ http_parser_parse_url(const char *buf, size_t buflen, int is_connect,
old_uf = uf;
}
- // host must be present if there is a schema
+ /* host must be present if there is a schema */
if ((u->field_set & ((1 << UF_SCHEMA) | (1 << UF_HOST))) != 0) {
if (http_parse_host(buf, u, found_at) != 0) {
return 1;
View
16 test.c
@@ -2109,7 +2109,9 @@ const struct url_test url_tests[] =
}
, {.name="extra ? in query string"
- ,.url="http://a.tbcdn.cn/p/fp/2010c/??fp-header-min.css,fp-base-min.css,fp-channel-min.css,fp-product-min.css,fp-mall-min.css,fp-category-min.css,fp-sub-min.css,fp-gdp4p-min.css,fp-css3-min.css,fp-misc-min.css?t=20101022.css"
+ ,.url="http://a.tbcdn.cn/p/fp/2010c/??fp-header-min.css,fp-base-min.css,"
+ "fp-channel-min.css,fp-product-min.css,fp-mall-min.css,fp-category-min.css,"
+ "fp-sub-min.css,fp-gdp4p-min.css,fp-css3-min.css,fp-misc-min.css?t=20101022.css"
,.is_connect=0
,.u=
{.field_set=(1<<UF_SCHEMA) | (1<<UF_HOST) | (1<<UF_PATH) | (1<<UF_QUERY)
@@ -2167,10 +2169,12 @@ const struct url_test url_tests[] =
}
, {.name="complex URL fragment"
- ,.url="http://www.webmasterworld.com/r.cgi?f=21&d=8405&url=http://www.example.com/index.html?foo=bar&hello=world#midpage"
+ ,.url="http://www.webmasterworld.com/r.cgi?f=21&d=8405&url="
+ "http://www.example.com/index.html?foo=bar&hello=world#midpage"
,.is_connect=0
,.u=
- {.field_set= (1<<UF_SCHEMA) | (1<<UF_HOST) | (1<<UF_PATH) | (1<<UF_QUERY) | (1<<UF_FRAGMENT)
+ {.field_set= (1<<UF_SCHEMA) | (1<<UF_HOST) | (1<<UF_PATH) | (1<<UF_QUERY) |\
+ (1<<UF_FRAGMENT)
,.port=0
,.field_data=
{{ 0, 4 } /* UF_SCHEMA */
@@ -2189,7 +2193,8 @@ const struct url_test url_tests[] =
,.url="http://host.com:8080/p/a/t/h?query=string#hash"
,.is_connect=0
,.u=
- {.field_set= (1<<UF_SCHEMA) | (1<<UF_HOST) | (1<<UF_PORT) | (1<<UF_PATH) | (1<<UF_QUERY) | (1<<UF_FRAGMENT)
+ {.field_set= (1<<UF_SCHEMA) | (1<<UF_HOST) | (1<<UF_PORT) | (1<<UF_PATH) |\
+ (1<<UF_QUERY) | (1<<UF_FRAGMENT)
,.port=8080
,.field_data=
{{ 0, 4 } /* UF_SCHEMA */
@@ -2208,7 +2213,8 @@ const struct url_test url_tests[] =
,.url="http://a:b@host.com:8080/p/a/t/h?query=string#hash"
,.is_connect=0
,.u=
- {.field_set= (1<<UF_SCHEMA) | (1<<UF_HOST) | (1<<UF_PORT) | (1<<UF_PATH) | (1<<UF_QUERY) | (1<<UF_FRAGMENT) | (1<<UF_USERINFO)
+ {.field_set= (1<<UF_SCHEMA) | (1<<UF_HOST) | (1<<UF_PORT) | (1<<UF_PATH) |\
+ (1<<UF_QUERY) | (1<<UF_FRAGMENT) | (1<<UF_USERINFO)
,.port=8080
,.field_data=
{{ 0, 4 } /* UF_SCHEMA */
Please sign in to comment.
Something went wrong with that request. Please try again.