From 4472f7bbc3f50c13ee36df2806781c4b09f43c0b Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Mon, 12 Mar 2012 02:23:34 +0100 Subject: [PATCH] http: use HTTP_METHOD_MAP macro --- src/node_http_parser.cc | 91 ++++++----------------------------------- 1 file changed, 13 insertions(+), 78 deletions(-) diff --git a/src/node_http_parser.cc b/src/node_http_parser.cc index 72525d23d7..f6559ee8b4 100644 --- a/src/node_http_parser.cc +++ b/src/node_http_parser.cc @@ -54,33 +54,6 @@ static Persistent on_headers_complete_sym; static Persistent on_body_sym; static Persistent on_message_complete_sym; -static Persistent delete_sym; -static Persistent get_sym; -static Persistent head_sym; -static Persistent post_sym; -static Persistent purge_sym; -static Persistent put_sym; -static Persistent connect_sym; -static Persistent options_sym; -static Persistent trace_sym; -static Persistent patch_sym; -static Persistent copy_sym; -static Persistent lock_sym; -static Persistent mkcol_sym; -static Persistent move_sym; -static Persistent propfind_sym; -static Persistent proppatch_sym; -static Persistent unlock_sym; -static Persistent report_sym; -static Persistent mkactivity_sym; -static Persistent checkout_sym; -static Persistent merge_sym; -static Persistent msearch_sym; -static Persistent notify_sym; -static Persistent subscribe_sym; -static Persistent unsubscribe_sym; -static Persistent unknown_method_sym; - static Persistent method_sym; static Persistent status_code_sym; static Persistent http_version_sym; @@ -91,6 +64,12 @@ static Persistent upgrade_sym; static Persistent headers_sym; static Persistent url_sym; +static Persistent unknown_method_sym; + +#define X(num, name, string) static Persistent name##_sym; +HTTP_METHOD_MAP(X) +#undef X + static struct http_parser_settings settings; @@ -121,33 +100,11 @@ static size_t current_buffer_len; static inline Persistent method_to_str(unsigned short m) { switch (m) { - case HTTP_DELETE: return delete_sym; - case HTTP_GET: return get_sym; - case HTTP_HEAD: return head_sym; - case HTTP_POST: return post_sym; - case HTTP_PURGE: return purge_sym; - case HTTP_PUT: return put_sym; - case HTTP_CONNECT: return connect_sym; - case HTTP_OPTIONS: return options_sym; - case HTTP_TRACE: return trace_sym; - case HTTP_PATCH: return patch_sym; - case HTTP_COPY: return copy_sym; - case HTTP_LOCK: return lock_sym; - case HTTP_MKCOL: return mkcol_sym; - case HTTP_MOVE: return move_sym; - case HTTP_PROPFIND: return propfind_sym; - case HTTP_PROPPATCH: return proppatch_sym; - case HTTP_UNLOCK: return unlock_sym; - case HTTP_REPORT: return report_sym; - case HTTP_MKACTIVITY: return mkactivity_sym; - case HTTP_CHECKOUT: return checkout_sym; - case HTTP_MERGE: return merge_sym; - case HTTP_MSEARCH: return msearch_sym; - case HTTP_NOTIFY: return notify_sym; - case HTTP_SUBSCRIBE: return subscribe_sym; - case HTTP_UNSUBSCRIBE:return unsubscribe_sym; - default: return unknown_method_sym; +#define X(num, name, string) case HTTP_##name: return name##_sym; + HTTP_METHOD_MAP(X) +#undef X } + return unknown_method_sym; } @@ -609,31 +566,9 @@ void InitHttpParser(Handle target) { on_body_sym = NODE_PSYMBOL("onBody"); on_message_complete_sym = NODE_PSYMBOL("onMessageComplete"); - delete_sym = NODE_PSYMBOL("DELETE"); - get_sym = NODE_PSYMBOL("GET"); - head_sym = NODE_PSYMBOL("HEAD"); - post_sym = NODE_PSYMBOL("POST"); - purge_sym = NODE_PSYMBOL("PURGE"); - put_sym = NODE_PSYMBOL("PUT"); - connect_sym = NODE_PSYMBOL("CONNECT"); - options_sym = NODE_PSYMBOL("OPTIONS"); - trace_sym = NODE_PSYMBOL("TRACE"); - patch_sym = NODE_PSYMBOL("PATCH"); - copy_sym = NODE_PSYMBOL("COPY"); - lock_sym = NODE_PSYMBOL("LOCK"); - mkcol_sym = NODE_PSYMBOL("MKCOL"); - move_sym = NODE_PSYMBOL("MOVE"); - propfind_sym = NODE_PSYMBOL("PROPFIND"); - proppatch_sym = NODE_PSYMBOL("PROPPATCH"); - unlock_sym = NODE_PSYMBOL("UNLOCK"); - report_sym = NODE_PSYMBOL("REPORT"); - mkactivity_sym = NODE_PSYMBOL("MKACTIVITY"); - checkout_sym = NODE_PSYMBOL("CHECKOUT"); - merge_sym = NODE_PSYMBOL("MERGE"); - msearch_sym = NODE_PSYMBOL("M-SEARCH"); - notify_sym = NODE_PSYMBOL("NOTIFY"); - subscribe_sym = NODE_PSYMBOL("SUBSCRIBE"); - unsubscribe_sym = NODE_PSYMBOL("UNSUBSCRIBE");; +#define X(num, name, string) name##_sym = NODE_PSYMBOL(#string); + HTTP_METHOD_MAP(X) +#undef X unknown_method_sym = NODE_PSYMBOL("UNKNOWN_METHOD"); method_sym = NODE_PSYMBOL("method");