OSDN Git Service

update libMiMic
[mimic/MiMicSDK.git] / lib / src / net / httpd / mod / NyLPC_cModUrl.c
index cfe76bd..6e6936d 100644 (file)
@@ -19,8 +19,8 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.\r
  *\r
  * For further information please contact.\r
- *     http://nyatla.jp/\r
- *     <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>\r
+ *  http://nyatla.jp/\r
+ *  <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>\r
  *\r
  *********************************************************************************/\r
 #include "NyLPC_cModUrl.h"\r
 \r
 typedef struct TcHeaderParser\r
 {\r
-       NyLPC_TcHttpBasicHeaderParser_t super;\r
-       char* url_buf;\r
-       NyLPC_TInt16 length_of_buf;\r
-       NyLPC_TInt16 length_of_url;\r
-       NyLPC_TInt16 reason;\r
-       NyLPC_TUInt8 skip;\r
-       NyLPC_TUInt8 mode;\r
+    NyLPC_TcHttpBasicHeaderParser_t super;\r
+    char* url_buf;\r
+    NyLPC_TInt16 length_of_buf;\r
+    NyLPC_TInt16 length_of_url;\r
+    NyLPC_TInt16 reason;\r
+    NyLPC_TUInt8 skip;\r
+    NyLPC_TUInt8 mode;\r
 }TcHeaderParser_t;\r
 \r
 \r
 \r
 static NyLPC_TBool NyLPC_cModUrl_urlHandler(NyLPC_TcHttpBasicHeaderParser_t* i_inst,NyLPC_TChar i_c,struct NyLPC_THttpBasicHeader* o_out)\r
 {\r
-       TcHeaderParser_t* inst=(TcHeaderParser_t*)i_inst;\r
-       if(inst->skip){\r
-               //SKIPが有効な場合\r
-               if(inst->length_of_url<0){\r
-                       inst->length_of_url++;\r
-                       if(inst->length_of_url==0){\r
-                               inst->skip=NyLPC_TUInt8_FALSE;\r
-                       }\r
-               }\r
-               return NyLPC_TBool_TRUE;\r
-       }\r
-       if((inst->mode & NyLPC_cModUrl_ParseMode_PATH_ONLY)==NyLPC_cModUrl_ParseMode_PATH_ONLY){\r
-               if(strchr("?#",i_c)){\r
-                       inst->url_buf[inst->length_of_url]='\0';\r
-                       inst->skip=NyLPC_TUInt8_TRUE;\r
-                       return NyLPC_TBool_TRUE;//Terminate\r
-               }\r
-       }\r
-       inst->url_buf[inst->length_of_url]=i_c;\r
-       if(i_c=='\0'){\r
-               return NyLPC_TBool_TRUE;//Terminate\r
-       }\r
-       inst->length_of_url++;\r
-       if(inst->length_of_url==inst->length_of_buf){\r
-               inst->reason=414;\r
-               return NyLPC_TBool_FALSE;//長すぎる。\r
-       }\r
-\r
-       return NyLPC_TBool_TRUE;\r
+    TcHeaderParser_t* inst=(TcHeaderParser_t*)i_inst;\r
+    if(inst->skip){\r
+        //SKIPが有効な場合\r
+        if(inst->length_of_url<0){\r
+            inst->length_of_url++;\r
+            if(inst->length_of_url==0){\r
+                inst->skip=NyLPC_TUInt8_FALSE;\r
+            }\r
+        }\r
+        return NyLPC_TBool_TRUE;\r
+    }\r
+    if((inst->mode & NyLPC_cModUrl_ParseMode_PATH_ONLY)==NyLPC_cModUrl_ParseMode_PATH_ONLY){\r
+        if(strchr("?#",i_c)){\r
+            inst->url_buf[inst->length_of_url]='\0';\r
+            inst->skip=NyLPC_TUInt8_TRUE;\r
+            return NyLPC_TBool_TRUE;//Terminate\r
+        }\r
+    }\r
+    inst->url_buf[inst->length_of_url]=i_c;\r
+    if(i_c=='\0'){\r
+        return NyLPC_TBool_TRUE;//Terminate\r
+    }\r
+    inst->length_of_url++;\r
+    if(inst->length_of_url==inst->length_of_buf){\r
+        inst->reason=414;\r
+        return NyLPC_TBool_FALSE;//長すぎる。\r
+    }\r
+\r
+    return NyLPC_TBool_TRUE;\r
 }\r
 /**\r
  * デフォルトハンドラ\r
  */\r
 static const struct NyLPC_TcHttpBasicHeaderParser_Handler _handler=\r
 {\r
-       NULL,\r
-       NyLPC_cModUrl_urlHandler\r
+    NULL,\r
+    NyLPC_cModUrl_urlHandler\r
 };\r
 \r
 \r
 \r
 void NyLPC_cModUrl_initialize(NyLPC_TcModUrl_t* i_inst)\r
 {\r
-       NyLPC_cHttpBodyParser_initialize(&i_inst->_body_parser);\r
+    NyLPC_cHttpBodyParser_initialize(&i_inst->_body_parser);\r
 }\r
 void NyLPC_cModUrl_finalize(NyLPC_TcModUrl_t* i_inst)\r
 {\r
-       NyLPC_cHttpBodyParser_finalize(&i_inst->_body_parser);\r
+    NyLPC_cHttpBodyParser_finalize(&i_inst->_body_parser);\r
 }\r
 \r
 const struct NyLPC_THttpBasicHeader* NyLPC_cModUrl_getHeader(const NyLPC_TcModUrl_t* i_inst)\r
 {\r
-       return &(i_inst->_header);\r
+    return &(i_inst->_header);\r
 }\r
 \r
 /**\r
@@ -104,68 +104,68 @@ const struct NyLPC_THttpBasicHeader* NyLPC_cModUrl_getHeader(const NyLPC_TcModUr
  */\r
 NyLPC_THttpMethodType NyLPC_cModUrl_getMethod(const NyLPC_TcModUrl_t* i_inst)\r
 {\r
-       return i_inst->_header.startline.req.method;\r
+    return i_inst->_header.startline.req.method;\r
 }\r
 \r
 \r
 \r
 NyLPC_TBool NyLPC_cModUrl_execute2(NyLPC_TcModUrl_t* i_inst,NyLPC_TcHttpdConnection_t* i_connection,char* o_url_buf,NyLPC_TInt16 i_length_buf,NyLPC_TInt16 i_pass_prefix_len,NyLPC_cModUrl_ParseMode i_mode)\r
 {\r
-       TcHeaderParser_t parser;\r
-       NyLPC_Assert(i_length_buf>0);\r
-       NyLPC_Assert(i_pass_prefix_len>=0);\r
-       //コネクションのステータスチェック\r
-       if(!NyLPC_cHttpdConnection_getReqStatus(i_connection)==NyLPC_cHttpdConnection_ReqStatus_REQPARSE)\r
-       {\r
-               NyLPC_OnErrorGoto(Error1);\r
-       }\r
-       //リクエストParse済へ遷移\r
-       NyLPC_cHttpdConnection_setReqStatusParsed(i_connection);\r
-\r
-       NyLPC_cHttpBasicHeaderParser_initialize(&parser.super,&_handler);\r
-       parser.length_of_buf=i_length_buf;\r
-       parser.length_of_url=-i_pass_prefix_len;//無視するPrefix長\r
-       parser.skip=(parser.length_of_url<0)?NyLPC_TUInt8_TRUE:NyLPC_TUInt8_FALSE;//スキップの初期値の設定\r
-       parser.url_buf=o_url_buf;\r
-       parser.url_buf[0]='\0';//URL長<=prefix長に備えてNULLターミネイト\r
-       parser.reason=400;\r
-       parser.mode=i_mode;\r
-       //プリフェッチしたデータを流す\r
-       NyLPC_cHttpBasicHeaderParser_parseInit(&parser.super,&(i_inst->_header));\r
-       NyLPC_cHttpdConnection_pushPrefetchInfo(i_connection,&parser.super,&(i_inst->_header));\r
-       //後続をストリームから取り込む\r
-       if(!NyLPC_cHttpBasicHeaderParser_parseStream(&parser.super,NyLPC_cHttpdConnection_refStream(i_connection),&(i_inst->_header))){\r
-               NyLPC_OnErrorGoto(Error2);\r
-       }\r
-       if(!NyLPC_cHttpBasicHeaderParser_parseFinish(&parser.super,&(i_inst->_header))){\r
-               NyLPC_OnErrorGoto(Error2);\r
-       }\r
-       //@todo http/1.1 && POSTの場合はcontinueを送る。\r
-       if(i_inst->_header.startline.req.version==NyLPC_THttpVersion_11){\r
-               if(i_inst->_header.startline.req.method==NyLPC_THttpMethodType_POST)\r
-               {\r
-                       NyLPC_cHttpdConnection_send100Continue(i_connection);\r
-               }\r
-       }\r
-       //Request::ConnectionがClose設定,又はHTTP1.1では無い場合,CLOSE\r
-       if(i_inst->_header.connection==NyLPC_THttpMessgeHeader_Connection_CLOSE || i_inst->_header.startline.req.version!=NyLPC_THttpVersion_11)\r
-       {\r
-               NyLPC_cHttpdConnection_setConnectionMode(i_connection,NyLPC_TcHttpdConnection_CONNECTION_MODE_CLOSE);\r
-       }\r
-\r
-       NyLPC_cHttpBasicHeaderParser_finalize(&parser);\r
-       //BodyParserの初期化\r
-       if(NyLPC_cHttpBodyParser_getState(&i_inst->_body_parser)!=NyLPC_TcHttpBasicBodyParser_ST_NULL){\r
-               NyLPC_cHttpBodyParser_parseFinish(&i_inst->_body_parser);\r
-       }\r
-       NyLPC_cHttpBodyParser_parseInit(&i_inst->_body_parser,&i_inst->_header);\r
-       return NyLPC_TBool_TRUE;\r
+    TcHeaderParser_t parser;\r
+    NyLPC_Assert(i_length_buf>0);\r
+    NyLPC_Assert(i_pass_prefix_len>=0);\r
+    //コネクションのステータスチェック\r
+    if(!NyLPC_cHttpdConnection_getReqStatus(i_connection)==NyLPC_cHttpdConnection_ReqStatus_REQPARSE)\r
+    {\r
+        NyLPC_OnErrorGoto(Error1);\r
+    }\r
+    //リクエストParse済へ遷移\r
+    NyLPC_cHttpdConnection_setReqStatusParsed(i_connection);\r
+\r
+    NyLPC_cHttpBasicHeaderParser_initialize(&parser.super,&_handler);\r
+    parser.length_of_buf=i_length_buf;\r
+    parser.length_of_url=-i_pass_prefix_len;//無視するPrefix長\r
+    parser.skip=(parser.length_of_url<0)?NyLPC_TUInt8_TRUE:NyLPC_TUInt8_FALSE;//スキップの初期値の設定\r
+    parser.url_buf=o_url_buf;\r
+    parser.url_buf[0]='\0';//URL長<=prefix長に備えてNULLターミネイト\r
+    parser.reason=400;\r
+    parser.mode=i_mode;\r
+    //プリフェッチしたデータを流す\r
+    NyLPC_cHttpBasicHeaderParser_parseInit(&parser.super,&(i_inst->_header));\r
+    NyLPC_cHttpdConnection_pushPrefetchInfo(i_connection,&parser.super,&(i_inst->_header));\r
+    //後続をストリームから取り込む\r
+    if(!NyLPC_cHttpBasicHeaderParser_parseStream(&parser.super,NyLPC_cHttpdConnection_refStream(i_connection),&(i_inst->_header))){\r
+        NyLPC_OnErrorGoto(Error2);\r
+    }\r
+    if(!NyLPC_cHttpBasicHeaderParser_parseFinish(&parser.super,&(i_inst->_header))){\r
+        NyLPC_OnErrorGoto(Error2);\r
+    }\r
+    //@todo http/1.1 && POSTの場合はcontinueを送る。\r
+    if(i_inst->_header.startline.req.version==NyLPC_THttpVersion_11){\r
+        if(i_inst->_header.startline.req.method==NyLPC_THttpMethodType_POST)\r
+        {\r
+            NyLPC_cHttpdConnection_send100Continue(i_connection);\r
+        }\r
+    }\r
+    //Request::ConnectionがClose設定,又はHTTP1.1では無い場合,CLOSE\r
+    if(i_inst->_header.connection==NyLPC_THttpMessgeHeader_Connection_CLOSE || i_inst->_header.startline.req.version!=NyLPC_THttpVersion_11)\r
+    {\r
+        NyLPC_cHttpdConnection_setConnectionMode(i_connection,NyLPC_TcHttpdConnection_CONNECTION_MODE_CLOSE);\r
+    }\r
+\r
+    NyLPC_cHttpBasicHeaderParser_finalize(&parser);\r
+    //BodyParserの初期化\r
+    if(NyLPC_cHttpBodyParser_getState(&i_inst->_body_parser)!=NyLPC_TcHttpBasicBodyParser_ST_NULL){\r
+        NyLPC_cHttpBodyParser_parseFinish(&i_inst->_body_parser);\r
+    }\r
+    NyLPC_cHttpBodyParser_parseInit(&i_inst->_body_parser,&i_inst->_header);\r
+    return NyLPC_TBool_TRUE;\r
 Error2:\r
-       //400Error\r
-       NyLPC_cHttpdUtils_sendErrorResponse(i_connection,parser.reason);\r
-       NyLPC_cHttpBasicHeaderParser_finalize(&parser);\r
+    //400Error\r
+    NyLPC_cHttpdUtils_sendErrorResponse(i_connection,parser.reason);\r
+    NyLPC_cHttpBasicHeaderParser_finalize(&parser);\r
 Error1:\r
-       return NyLPC_TBool_FALSE;\r
+    return NyLPC_TBool_FALSE;\r
 }\r
 \r
 \r
@@ -174,15 +174,15 @@ Error1:
 \r
 NyLPC_TInt16 NyLPC_cModUrl_readBody(NyLPC_TcModUrl_t* i_inst,NyLPC_TcHttpdConnection_t* i_connection,void* i_buf,NyLPC_TInt16 i_buf_size)\r
 {\r
-       NyLPC_TInt16 l;\r
-       //リクエストは解析済であること\r
-       if(!NyLPC_cHttpdConnection_getReqStatus(i_connection)==NyLPC_cHttpdConnection_ReqStatus_END)\r
-       {\r
-               return -1;\r
-       }\r
-       if(!NyLPC_cHttpBodyParser_parseStream(&i_inst->_body_parser,NyLPC_cHttpdConnection_refStream(i_connection),i_buf,i_buf_size,&l)){\r
-               return -1;\r
-       }\r
-       return l;\r
+    NyLPC_TInt16 l;\r
+    //リクエストは解析済であること\r
+    if(!NyLPC_cHttpdConnection_getReqStatus(i_connection)==NyLPC_cHttpdConnection_ReqStatus_END)\r
+    {\r
+        return -1;\r
+    }\r
+    if(!NyLPC_cHttpBodyParser_parseStream(&i_inst->_body_parser,NyLPC_cHttpdConnection_refStream(i_connection),i_buf,i_buf_size,&l)){\r
+        return -1;\r
+    }\r
+    return l;\r
 }\r
 \r