123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522 |
- /*
- * Copyright (C) 2010-2015 Mamadou Diop.
- *
- * This file is part of Open Source Doubango Framework.
- *
- * DOUBANGO is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * DOUBANGO is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with DOUBANGO.
- *
- */
- /**@file thttp_parser_header.c
- * @brief HTTP headers parser.
- */
- #include "tinyhttp/parsers/thttp_parser_header.h"
- //#include "tinyhttp/headers/thttp_header_Allow.h"
- //#include "tinyhttp/headers/thttp_header_Allow_Events.h"
- #include "tinyhttp/headers/thttp_header_Authorization.h"
- //#include "tinyhttp/headers/thttp_header_Call_ID.h"
- //#include "tinyhttp/headers/thttp_header_Contact.h"
- //#include "tinyhttp/headers/thttp_header_CSeq.h"
- #include "tinyhttp/headers/thttp_header_Dummy.h"
- #include "tinyhttp/headers/thttp_header_ETag.h"
- //#include "tinyhttp/headers/thttp_header_Expires.h"
- //#include "tinyhttp/headers/thttp_header_From.h"
- //#include "tinyhttp/headers/thttp_header_Max_Forwards.h"
- //#include "tinyhttp/headers/thttp_header_Min_Expires.h"
- //#include "tinyhttp/headers/thttp_header_Path.h"
- //#include "tinyhttp/headers/thttp_header_P_Access_Network_Info.h"
- //#include "tinyhttp/headers/thttp_header_P_Preferred_Identity.h"
- //#include "tinyhttp/headers/thttp_header_Privacy.h"
- //#include "tinyhttp/headers/thttp_header_Proxy_Authenticate.h"
- //#include "tinyhttp/headers/thttp_header_Proxy_Authorization.h"
- //#include "tinyhttp/headers/thttp_header_Record_Route.h"
- //#include "tinyhttp/headers/thttp_header_Require.h"
- //#include "tinyhttp/headers/thttp_header_Route.h"
- #include "tinyhttp/headers/thttp_header_Sec_WebSocket_Accept.h"
- #include "tinyhttp/headers/thttp_header_Sec_WebSocket_Key.h"
- #include "tinyhttp/headers/thttp_header_Sec_WebSocket_Protocol.h"
- #include "tinyhttp/headers/thttp_header_Sec_WebSocket_Version.h"
- //#include "tinyhttp/headers/thttp_header_Service_Route.h"
- //#include "tinyhttp/headers/thttp_header_Supported.h"
- #include "tinyhttp/headers/thttp_header_Transfer_Encoding.h"
- //#include "tinyhttp/headers/thttp_header_User_Agent.h"
- //#include "tinyhttp/headers/thttp_header_Via.h"
- #include "tinyhttp/headers/thttp_header_WWW_Authenticate.h"
- #include "tsk_debug.h"
- #undef ADD_HEADERS
- #undef ADD_HEADER
- #define ADD_HEADERS(headers)\
- if(headers)\
- {\
- tsk_list_item_t *item;\
- tsk_list_foreach(item, headers)\
- {\
- thttp_header_t *hdr = tsk_object_ref(item->data);\
- tsk_list_push_back_data(message->headers, ((void**) &hdr));\
- }\
- \
- TSK_OBJECT_SAFE_FREE(headers);\
- }
- #define ADD_HEADER(header)\
- if(header)\
- {\
- tsk_list_push_back_data(message->headers, ((void**) &header));\
- }
- /***********************************
- * Ragel state machine.
- */
- %%{
- machine thttp_machine_parser_headers;
- # /*== Accept: ==*/
- action parse_header_Accept
- {
- thttp_header_Dummy_t *header = thttp_header_Dummy_parse(state->tag_start, (state->tag_end-state->tag_start));
- ADD_HEADER(header);
- //TSK_DEBUG_WARN("parse_header_Accept NOT IMPLEMENTED. Will be added as Dummy header.");
- }
- # /*== Accept_Charset: ==*/
- action parse_header_Accept_Charset
- {
- thttp_header_Dummy_t *header = thttp_header_Dummy_parse(state->tag_start, (state->tag_end-state->tag_start));
- ADD_HEADER(header);
- //TSK_DEBUG_WARN("parse_header_Accept_Charset NOT IMPLEMENTED. Will be added as Dummy header.");
- }
- # /*== Accept_Encoding: ==*/
- action parse_header_Accept_Encoding
- {
- thttp_header_Dummy_t *header = thttp_header_Dummy_parse(state->tag_start, (state->tag_end-state->tag_start));
- ADD_HEADER(header);
- //TSK_DEBUG_WARN("parse_header_Accept_Encoding NOT IMPLEMENTED. Will be added as Dummy header.");
- }
-
- # /*== Accept_Language: ==*/
- action parse_header_Accept_Language
- {
- thttp_header_Dummy_t *header = thttp_header_Dummy_parse(state->tag_start, (state->tag_end-state->tag_start));
- ADD_HEADER(header);
- //TSK_DEBUG_WARN("parse_header_Accept_Language NOT IMPLEMENTED. Will be added as Dummy header.");
- }
-
- # /*== Allow: ==*/
- action parse_header_Allow
- {
- thttp_header_Dummy_t *header = thttp_header_Dummy_parse(state->tag_start, (state->tag_end-state->tag_start));
- ADD_HEADER(header);
- //TSK_DEBUG_WARN("parse_header_Allow NOT IMPLEMENTED. Will be added as Dummy header.");
- }
-
- # /*== Authorization: ==*/
- action parse_header_Authorization
- {
- thttp_header_Authorization_t *header = thttp_header_Authorization_parse(state->tag_start, (state->tag_end-state->tag_start));
- ADD_HEADER(header);
- }
-
- # /*== Cache_Control: ==*/
- action parse_header_Cache_Control
- {
- thttp_header_Dummy_t *header = thttp_header_Dummy_parse(state->tag_start, (state->tag_end-state->tag_start));
- ADD_HEADER(header);
- //TSK_DEBUG_WARN("parse_header_Cache_Control NOT IMPLEMENTED. Will be added as Dummy header.");
- }
-
- # /*== Connection: ==*/
- action parse_header_Connection
- {
- thttp_header_Dummy_t *header = thttp_header_Dummy_parse(state->tag_start, (state->tag_end-state->tag_start));
- ADD_HEADER(header);
- //TSK_DEBUG_WARN("parse_header_Connection NOT IMPLEMENTED. Will be added as Dummy header.");
- }
-
- # /*== Content_Encoding: ==*/
- action parse_header_Content_Encoding
- {
- thttp_header_Dummy_t *header = thttp_header_Dummy_parse(state->tag_start, (state->tag_end-state->tag_start));
- ADD_HEADER(header);
- //TSK_DEBUG_WARN("parse_header_Content_Encoding NOT IMPLEMENTED. Will be added as Dummy header.");
- }
-
- # /*== Content_Language: ==*/
- action parse_header_Content_Language
- {
- thttp_header_Dummy_t *header = thttp_header_Dummy_parse(state->tag_start, (state->tag_end-state->tag_start));
- ADD_HEADER(header);
- //TSK_DEBUG_WARN("parse_header_Content_Language NOT IMPLEMENTED. Will be added as Dummy header.");
- }
- # /*== Content_Length: ==*/
- action parse_header_Content_Length
- {
- if(!message->Content_Length){
- message->Content_Length = thttp_header_Content_Length_parse(state->tag_start, (state->tag_end-state->tag_start));
- }
- else{
- thttp_header_Dummy_t *header = thttp_header_Dummy_parse(state->tag_start, (state->tag_end-state->tag_start));
- ADD_HEADER(header);
- //TSK_DEBUG_WARN("The message already have 'Content-Length' header.");
- }
- }
- # /*== Content_Location: ==*/
- action parse_header_Content_Location
- {
- thttp_header_Dummy_t *header = thttp_header_Dummy_parse(state->tag_start, (state->tag_end-state->tag_start));
- ADD_HEADER(header);
- //TSK_DEBUG_WARN("parse_header_Content_Location NOT IMPLEMENTED. Will be added as Dummy header.");
- }
-
- # /*== Content_MD5: ==*/
- action parse_header_Content_MD5
- {
- thttp_header_Dummy_t *header = thttp_header_Dummy_parse(state->tag_start, (state->tag_end-state->tag_start));
- ADD_HEADER(header);
- //TSK_DEBUG_WARN("parse_header_Content_MD5 NOT IMPLEMENTED. Will be added as Dummy header.");
- }
-
- # /*== Content_Range: ==*/
- action parse_header_Content_Range
- {
- thttp_header_Dummy_t *header = thttp_header_Dummy_parse(state->tag_start, (state->tag_end-state->tag_start));
- ADD_HEADER(header);
- //TSK_DEBUG_WARN("parse_header_Content_Range NOT IMPLEMENTED. Will be added as Dummy header.");
- }
-
- # /*== Content_Type: ==*/
- action parse_header_Content_Type
- {
- if(!message->Content_Type){
- message->Content_Type = thttp_header_Content_Type_parse(state->tag_start, (state->tag_end-state->tag_start));
- }
- else{
- thttp_header_Dummy_t *header = thttp_header_Dummy_parse(state->tag_start, (state->tag_end-state->tag_start));
- ADD_HEADER(header);
- //TSK_DEBUG_WARN("The message already have 'Content-Type' header.");
- }
- }
- # /*== Date: ==*/
- action parse_header_Date
- {
- thttp_header_Dummy_t *header = thttp_header_Dummy_parse(state->tag_start, (state->tag_end-state->tag_start));
- ADD_HEADER(header);
- //TSK_DEBUG_WARN("parse_header_Date NOT IMPLEMENTED. Will be added as Dummy header.");
- }
- # /*== ETag: ==*/
- action parse_header_ETag
- {
- thttp_header_ETag_t *header = thttp_header_ETag_parse(state->tag_start, (state->tag_end-state->tag_start));
- ADD_HEADER(header);
- //TSK_DEBUG_WARN("parse_header_Expires NOT IMPLEMENTED. Will be added as Dummy header.");
- }
- # /*== Expect: ==*/
- action parse_header_Expect
- {
- thttp_header_Dummy_t *header = thttp_header_Dummy_parse(state->tag_start, (state->tag_end-state->tag_start));
- ADD_HEADER(header);
- //TSK_DEBUG_WARN("parse_header_Expect NOT IMPLEMENTED. Will be added as Dummy header.");
- }
-
- # /*== Expires: ==*/
- action parse_header_Expires
- {
- thttp_header_Dummy_t *header = thttp_header_Dummy_parse(state->tag_start, (state->tag_end-state->tag_start));
- ADD_HEADER(header);
- //TSK_DEBUG_WARN("parse_header_Expires NOT IMPLEMENTED. Will be added as Dummy header.");
- }
-
- # /*== From: ==*/
- action parse_header_From
- {
- thttp_header_Dummy_t *header = thttp_header_Dummy_parse(state->tag_start, (state->tag_end-state->tag_start));
- ADD_HEADER(header);
- //TSK_DEBUG_WARN("parse_header_From NOT IMPLEMENTED. Will be added as Dummy header.");
- }
-
- # /*== Host: ==*/
- action parse_header_Host
- {
- thttp_header_Dummy_t *header = thttp_header_Dummy_parse(state->tag_start, (state->tag_end-state->tag_start));
- ADD_HEADER(header);
- //TSK_DEBUG_WARN("parse_header_Host NOT IMPLEMENTED. Will be added as Dummy header.");
- }
- # /*== If_Match: ==*/
- action parse_header_If_Match
- {
- thttp_header_Dummy_t *header = thttp_header_Dummy_parse(state->tag_start, (state->tag_end-state->tag_start));
- ADD_HEADER(header);
- //TSK_DEBUG_WARN("parse_header_If_Match NOT IMPLEMENTED. Will be added as Dummy header.");
- }
-
- # /*== If_Modified_Since: ==*/
- action parse_header_If_Modified_Since
- {
- thttp_header_Dummy_t *header = thttp_header_Dummy_parse(state->tag_start, (state->tag_end-state->tag_start));
- ADD_HEADER(header);
- //TSK_DEBUG_WARN("parse_header_If_Modified_Since NOT IMPLEMENTED. Will be added as Dummy header.");
- }
-
- # /*== If_None_Match: ==*/
- action parse_header_If_None_Match
- {
- thttp_header_Dummy_t *header = thttp_header_Dummy_parse(state->tag_start, (state->tag_end-state->tag_start));
- ADD_HEADER(header);
- //TSK_DEBUG_WARN("parse_header_If_None_Match NOT IMPLEMENTED. Will be added as Dummy header.");
- }
-
- # /*== If_Range: ==*/
- action parse_header_If_Range
- {
- thttp_header_Dummy_t *header = thttp_header_Dummy_parse(state->tag_start, (state->tag_end-state->tag_start));
- ADD_HEADER(header);
- //TSK_DEBUG_WARN("parse_header_If_Range NOT IMPLEMENTED. Will be added as Dummy header.");
- }
- # /*== If_Unmodified_Since: ==*/
- action parse_header_If_Unmodified_Since
- {
- thttp_header_Dummy_t *header = thttp_header_Dummy_parse(state->tag_start, (state->tag_end-state->tag_start));
- ADD_HEADER(header);
- //TSK_DEBUG_WARN("parse_header_If_Unmodified_Since NOT IMPLEMENTED. Will be added as Dummy header.");
- }
-
- # /*== Last_Modified: ==*/
- action parse_header_Last_Modified
- {
- thttp_header_Dummy_t *header = thttp_header_Dummy_parse(state->tag_start, (state->tag_end-state->tag_start));
- ADD_HEADER(header);
- //TSK_DEBUG_WARN("parse_header_Last_Modified NOT IMPLEMENTED. Will be added as Dummy header.");
- }
- # /*== Max_Forwards: ==*/
- action parse_header_Max_Forwards
- {
- thttp_header_Dummy_t *header = thttp_header_Dummy_parse(state->tag_start, (state->tag_end-state->tag_start));
- ADD_HEADER(header);
- //TSK_DEBUG_WARN("parse_header_Max_Forwards NOT IMPLEMENTED. Will be added as Dummy header.");
- }
-
- # /*== Pragma: ==*/
- action parse_header_Pragma
- {
- thttp_header_Dummy_t *header = thttp_header_Dummy_parse(state->tag_start, (state->tag_end-state->tag_start));
- ADD_HEADER(header);
- //TSK_DEBUG_WARN("parse_header_Pragma NOT IMPLEMENTED. Will be added as Dummy header.");
- }
-
- # /*== Proxy_Authenticate: ==*/
- action parse_header_Proxy_Authenticate
- {
- thttp_header_Proxy_Authenticate_t *header = thttp_header_Proxy_Authenticate_parse(state->tag_start, (state->tag_end-state->tag_start));
- ADD_HEADER(header);
- }
- # /*== Proxy_Authorization: ==*/
- action parse_header_Proxy_Authorization
- {
- thttp_header_Proxy_Authorization_t *header = thttp_header_Proxy_Authorization_parse(state->tag_start, (state->tag_end-state->tag_start));
- ADD_HEADER(header);
- }
-
- # /*== Range: ==*/
- action parse_header_Range
- {
- thttp_header_Dummy_t *header = thttp_header_Dummy_parse(state->tag_start, (state->tag_end-state->tag_start));
- ADD_HEADER(header);
- //TSK_DEBUG_WARN("parse_header_Range NOT IMPLEMENTED. Will be added as Dummy header.");
- }
- # /*== Referer: ==*/
- action parse_header_Referer
- {
- thttp_header_Dummy_t *header = thttp_header_Dummy_parse(state->tag_start, (state->tag_end-state->tag_start));
- ADD_HEADER(header);
- //TSK_DEBUG_WARN("parse_header_Referer NOT IMPLEMENTED. Will be added as Dummy header.");
- }
-
- # /* == Sec-WebSocket-Accept == */
- action parse_header_Sec_WebSocket_Accept
- {
- thttp_header_Sec_WebSocket_Accept_t* header = thttp_header_Sec_WebSocket_Accept_parse(state->tag_start, (state->tag_end-state->tag_start));
- ADD_HEADER(header);
- }
- # /* == Sec-WebSocket-Key == */
- action parse_header_Sec_WebSocket_Key
- {
- thttp_header_Sec_WebSocket_Key_t* header = thttp_header_Sec_WebSocket_Key_parse(state->tag_start, (state->tag_end-state->tag_start));
- ADD_HEADER(header);
- }
- # /* == Sec-WebSocket-Protocol == */
- action parse_header_Sec_WebSocket_Protocol
- {
- thttp_header_Sec_WebSocket_Protocol_t* header = thttp_header_Sec_WebSocket_Protocol_parse(state->tag_start, (state->tag_end-state->tag_start));
- ADD_HEADER(header);
- }
- # /* == Sec-WebSocket-Version == */
- action parse_header_Sec_WebSocket_Version
- {
- thttp_header_Sec_WebSocket_Version_t* header = thttp_header_Sec_WebSocket_Version_parse(state->tag_start, (state->tag_end-state->tag_start));
- ADD_HEADER(header);
- }
- # /*== TE: ==*/
- action parse_header_TE
- {
- thttp_header_Dummy_t *header = thttp_header_Dummy_parse(state->tag_start, (state->tag_end-state->tag_start));
- ADD_HEADER(header);
- //TSK_DEBUG_WARN("parse_header_TE NOT IMPLEMENTED. Will be added as Dummy header.");
- }
-
- # /*== Trailer: ==*/
- action parse_header_Trailer
- {
- thttp_header_Dummy_t *header = thttp_header_Dummy_parse(state->tag_start, (state->tag_end-state->tag_start));
- ADD_HEADER(header);
- //TSK_DEBUG_WARN("parse_header_Trailer NOT IMPLEMENTED. Will be added as Dummy header.");
- }
- # /*== Transfer_Encoding: ==*/
- action parse_header_Transfer_Encoding
- {
- thttp_header_Transfer_Encoding_t *header = thttp_header_Transfer_Encoding_parse(state->tag_start, (state->tag_end-state->tag_start));
- ADD_HEADER(header);
- //TSK_DEBUG_WARN("parse_header_Trailer NOT IMPLEMENTED. Will be added as Dummy header.");
- }
- # /*== Upgrade: ==*/
- action parse_header_Upgrade
- {
- thttp_header_Dummy_t *header = thttp_header_Dummy_parse(state->tag_start, (state->tag_end-state->tag_start));
- ADD_HEADER(header);
- //TSK_DEBUG_WARN("parse_header_Upgrade NOT IMPLEMENTED. Will be added as Dummy header.");
- }
-
- # /*== User_Agent: ==*/
- action parse_header_User_Agent
- {
- thttp_header_Dummy_t *header = thttp_header_Dummy_parse(state->tag_start, (state->tag_end-state->tag_start));
- ADD_HEADER(header);
- //TSK_DEBUG_WARN("parse_header_User_Agent NOT IMPLEMENTED. Will be added as Dummy header.");
- }
-
- # /*== Via: ==*/
- action parse_header_Via
- {
- thttp_header_Dummy_t *header = thttp_header_Dummy_parse(state->tag_start, (state->tag_end-state->tag_start));
- ADD_HEADER(header);
- //TSK_DEBUG_WARN("parse_header_Via NOT IMPLEMENTED. Will be added as Dummy header.");
- }
-
- # /*== Warning: ==*/
- action parse_header_Warning
- {
- thttp_header_Dummy_t *header = thttp_header_Dummy_parse(state->tag_start, (state->tag_end-state->tag_start));
- ADD_HEADER(header);
- //TSK_DEBUG_WARN("parse_header_Warning NOT IMPLEMENTED. Will be added as Dummy header.");
- }
- # /*== WWW-Authenticate: ==*/
- action parse_header_WWW_Authenticate
- {
- thttp_header_WWW_Authenticate_t *header = thttp_header_WWW_Authenticate_parse(state->tag_start, (state->tag_end-state->tag_start));
- ADD_HEADER(header);
- }
-
- # /*== extension_header: ==*/
- action parse_header_extension_header
- {
- thttp_header_Dummy_t *header = thttp_header_Dummy_parse(state->tag_start, (state->tag_end-state->tag_start));
- ADD_HEADER(header);
- //TSK_DEBUG_WARN("parse_header_extension_header NOT IMPLEMENTED. Will be added as Dummy header.");
- }
- # Includes
- include thttp_machine_utils "./ragel/thttp_machine_utils.rl";
- include thttp_machine_header "./ragel/thttp_machine_header.rl";
- # Entry point
- main := HEADER;
- }%%
- int thttp_header_parse(tsk_ragel_state_t *state, thttp_message_t *message)
- {
- int cs = 0;
- const char *p = state->tag_start;
- const char *pe = state->tag_end;
- const char *eof = pe;
- TSK_RAGEL_DISABLE_WARNINGS_BEGIN()
- %%write data;
- (void)(eof);
- (void)(thttp_machine_parser_headers_first_final);
- (void)(thttp_machine_parser_headers_error);
- (void)(thttp_machine_parser_headers_en_main);
- %%write init;
- %%write exec;
- TSK_RAGEL_DISABLE_WARNINGS_END()
- return ( cs >= %%{ write first_final; }%% ) ? 0 : -1;
- }
|