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

Commit

Permalink
src: support BIND/REBIND/UNBIND (WebDAV, RFC5842)
Browse files Browse the repository at this point in the history
Support BIND/REBIND/UNBIND methods, see sections 4, 5, 6 of
RFC5842.

PR-URL: #242
Reviewed-By: Fedor Indutny <fedor@indutny.com>
  • Loading branch information
Hywan authored and indutny committed Jul 16, 2015
1 parent 7d75dd7 commit 8b1d652
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
14 changes: 12 additions & 2 deletions http_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,7 @@ size_t http_parser_execute (http_parser *parser,
parser->method = (enum http_method) 0;
parser->index = 1;
switch (ch) {
case 'B': parser->method = HTTP_BIND; break;
case 'C': parser->method = HTTP_CONNECT; /* or COPY, CHECKOUT */ break;
case 'D': parser->method = HTTP_DELETE; break;
case 'G': parser->method = HTTP_GET; break;
Expand All @@ -970,10 +971,10 @@ size_t http_parser_execute (http_parser *parser,
case 'P': parser->method = HTTP_POST;
/* or PROPFIND|PROPPATCH|PUT|PATCH|PURGE */
break;
case 'R': parser->method = HTTP_REPORT; break;
case 'R': parser->method = HTTP_REPORT; /* or REBIND */ break;
case 'S': parser->method = HTTP_SUBSCRIBE; /* or SEARCH */ break;
case 'T': parser->method = HTTP_TRACE; break;
case 'U': parser->method = HTTP_UNLOCK; /* or UNSUBSCRIBE */ break;
case 'U': parser->method = HTTP_UNLOCK; /* or UNSUBSCRIBE, UNBIND */ break;
default:
SET_ERRNO(HPE_INVALID_METHOD);
goto error;
Expand Down Expand Up @@ -1029,6 +1030,13 @@ size_t http_parser_execute (http_parser *parser,
SET_ERRNO(HPE_INVALID_METHOD);
goto error;
}
} else if (parser->method == HTTP_REPORT) {
if (parser->index == 2 && ch == 'B') {
parser->method = HTTP_REBIND;
} else {
SET_ERRNO(HPE_INVALID_METHOD);
goto error;
}
} else if (parser->index == 1 && parser->method == HTTP_POST) {
if (ch == 'R') {
parser->method = HTTP_PROPFIND; /* or HTTP_PROPPATCH */
Expand All @@ -1051,6 +1059,8 @@ size_t http_parser_execute (http_parser *parser,
} else if (parser->method == HTTP_UNLOCK) {
if (ch == 'S') {
parser->method = HTTP_UNSUBSCRIBE;
} else if(ch == 'B') {
parser->method = HTTP_UNBIND;
} else {
SET_ERRNO(HPE_INVALID_METHOD);
goto error;
Expand Down
27 changes: 15 additions & 12 deletions http_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ typedef int (*http_cb) (http_parser*);
XX(5, CONNECT, CONNECT) \
XX(6, OPTIONS, OPTIONS) \
XX(7, TRACE, TRACE) \
/* webdav */ \
/* WebDAV */ \
XX(8, COPY, COPY) \
XX(9, LOCK, LOCK) \
XX(10, MKCOL, MKCOL) \
Expand All @@ -104,21 +104,24 @@ typedef int (*http_cb) (http_parser*);
XX(13, PROPPATCH, PROPPATCH) \
XX(14, SEARCH, SEARCH) \
XX(15, UNLOCK, UNLOCK) \
XX(16, BIND, BIND) \
XX(17, REBIND, REBIND) \
XX(18, UNBIND, UNBIND) \
/* subversion */ \
XX(16, REPORT, REPORT) \
XX(17, MKACTIVITY, MKACTIVITY) \
XX(18, CHECKOUT, CHECKOUT) \
XX(19, MERGE, MERGE) \
XX(19, REPORT, REPORT) \
XX(20, MKACTIVITY, MKACTIVITY) \
XX(21, CHECKOUT, CHECKOUT) \
XX(22, MERGE, MERGE) \
/* upnp */ \
XX(20, MSEARCH, M-SEARCH) \
XX(21, NOTIFY, NOTIFY) \
XX(22, SUBSCRIBE, SUBSCRIBE) \
XX(23, UNSUBSCRIBE, UNSUBSCRIBE) \
XX(23, MSEARCH, M-SEARCH) \
XX(24, NOTIFY, NOTIFY) \
XX(25, SUBSCRIBE, SUBSCRIBE) \
XX(26, UNSUBSCRIBE, UNSUBSCRIBE) \
/* RFC-5789 */ \
XX(24, PATCH, PATCH) \
XX(25, PURGE, PURGE) \
XX(27, PATCH, PATCH) \
XX(28, PURGE, PURGE) \
/* CalDAV */ \
XX(26, MKCALENDAR, MKCALENDAR) \
XX(29, MKCALENDAR, MKCALENDAR) \

enum http_method
{
Expand Down
3 changes: 3 additions & 0 deletions test.c
Original file line number Diff line number Diff line change
Expand Up @@ -3744,6 +3744,9 @@ main (void)
"PROPFIND",
"PROPPATCH",
"UNLOCK",
"BIND",
"REBIND",
"UNBIND",
"REPORT",
"MKACTIVITY",
"CHECKOUT",
Expand Down

0 comments on commit 8b1d652

Please sign in to comment.