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

Commit

Permalink
Support IPv6 Zone ID as per RFC 6874
Browse files Browse the repository at this point in the history
IPv6 scoped address contains Zone ID, which is appended to IPv6
address after '%' separator.  RFC 6874 says that Zone ID after '%'
must consist of 1*(unreserved or pct-encoded).  This commit adds this
IPv6 Zone ID support.
  • Loading branch information
tatsuhiro-t committed Jun 18, 2015
1 parent 39ff097 commit 354c3a6
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
25 changes: 25 additions & 0 deletions http_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,8 @@ enum http_host_state
, s_http_host
, s_http_host_v6
, s_http_host_v6_end
, s_http_host_v6_zone_start
, s_http_host_v6_zone
, s_http_host_port_start
, s_http_host_port
};
Expand Down Expand Up @@ -2212,7 +2214,23 @@ http_parse_host_char(enum http_host_state s, const char ch) {
if (IS_HEX(ch) || ch == ':' || ch == '.') {
return s_http_host_v6;
}
if (ch == '%') {
return s_http_host_v6_zone_start;
}
break;

case s_http_host_v6_zone:
if (ch == ']') {
return s_http_host_v6_end;
}

/* FALLTHROUGH */
case s_http_host_v6_zone_start:
/* RFC 6874 Zone ID consists of 1*( unreserved / pct-encoded) */
if (IS_ALPHANUM(ch) || ch == '%' || ch == '.' || ch == '-' || ch == '_' ||
ch == '~') {
return s_http_host_v6_zone;
}
break;

case s_http_host_port:
Expand Down Expand Up @@ -2263,6 +2281,11 @@ http_parse_host(const char * buf, struct http_parser_url *u, int found_at) {
u->field_data[UF_HOST].len++;
break;

case s_http_host_v6_zone_start:
case s_http_host_v6_zone:
u->field_data[UF_HOST].len++;
break;

case s_http_host_port:
if (s != s_http_host_port) {
u->field_data[UF_PORT].off = p - buf;
Expand Down Expand Up @@ -2292,6 +2315,8 @@ http_parse_host(const char * buf, struct http_parser_url *u, int found_at) {
case s_http_host_start:
case s_http_host_v6_start:
case s_http_host_v6:
case s_http_host_v6_zone_start:
case s_http_host_v6_zone:
case s_http_host_port_start:
case s_http_userinfo:
case s_http_userinfo_start:
Expand Down
48 changes: 48 additions & 0 deletions test.c
Original file line number Diff line number Diff line change
Expand Up @@ -2918,6 +2918,54 @@ const struct url_test url_tests[] =
,.rv=1 /* s_dead */
}

, {.name="ipv6 address with Zone ID"
,.url="http://[fe80::a%25eth0]/"
,.is_connect=0
,.u=
{.field_set= (1<<UF_SCHEMA) | (1<<UF_HOST) | (1<<UF_PATH)
,.port=0
,.field_data=
{{ 0, 4 } /* UF_SCHEMA */
,{ 8, 14 } /* UF_HOST */
,{ 0, 0 } /* UF_PORT */
,{ 23, 1 } /* UF_PATH */
,{ 0, 0 } /* UF_QUERY */
,{ 0, 0 } /* UF_FRAGMENT */
,{ 0, 0 } /* UF_USERINFO */
}
}
,.rv=0
}

, {.name="ipv6 address with Zone ID, but '%' is not percent-encoded"
,.url="http://[fe80::a%eth0]/"
,.is_connect=0
,.u=
{.field_set= (1<<UF_SCHEMA) | (1<<UF_HOST) | (1<<UF_PATH)
,.port=0
,.field_data=
{{ 0, 4 } /* UF_SCHEMA */
,{ 8, 12 } /* UF_HOST */
,{ 0, 0 } /* UF_PORT */
,{ 21, 1 } /* UF_PATH */
,{ 0, 0 } /* UF_QUERY */
,{ 0, 0 } /* UF_FRAGMENT */
,{ 0, 0 } /* UF_USERINFO */
}
}
,.rv=0
}

, {.name="ipv6 address ending with '%'"
,.url="http://[fe80::a%]/"
,.rv=1 /* s_dead */
}

, {.name="ipv6 address with Zone ID including bad character"
,.url="http://[fe80::a%$HOME]/"
,.rv=1 /* s_dead */
}

#if HTTP_PARSER_STRICT

, {.name="tab in URL"
Expand Down

0 comments on commit 354c3a6

Please sign in to comment.