Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of libMiMic by
Diff: core/http/NyLPC_cHttpBasicHeaderParser.c
- Revision:
- 48:00d211aac2ec
- Parent:
- 41:2389bd6b6f74
- Child:
- 57:bc4330dfa62f
--- a/core/http/NyLPC_cHttpBasicHeaderParser.c Sun Jul 28 01:07:37 2013 +0000
+++ b/core/http/NyLPC_cHttpBasicHeaderParser.c Wed Aug 07 13:53:02 2013 +0000
@@ -26,23 +26,47 @@
#include "NyLPC_cHttpBasicHeaderParser_protected.h"
#include <stdlib.h>
+static const struct NyLPC_TTextIdTbl method_id_table[]=
+{
+ //HTTP STANDARD
+ {"GET",NyLPC_THttpMethodType_GET},
+ {"POST",NyLPC_THttpMethodType_POST},
+ {"HEAD",NyLPC_THttpMethodType_HEAD},
+ //SSDP
+ {"M-SEARCH",NyLPC_THttpMethodType_M_SEARCH},
+ {"NOTIFY",NyLPC_THttpMethodType_NOTIFY},
+ {NULL,NyLPC_THttpMethodType_NULL}
+};
+/*--------------------------------------------------------------------------------
+ *
+ * NyLPC_THttpMethodType
+ *
+ --------------------------------------------------------------------------------*/
const char* NyLPC_THttpMethodType_toString(NyLPC_THttpMethodType i_method)
{
- static const char* method_prefix[3]={"GET","POST","HEAD"};
- switch(i_method)
- {
- case NyLPC_THttpMethodType_GET:
- return method_prefix[0];
- case NyLPC_THttpMethodType_POST:
- return method_prefix[1];
- case NyLPC_THttpMethodType_HEAD:
- return method_prefix[2];
- default:
+ const char* ret=NyLPC_TTextIdTbl_getTextById(i_method,method_id_table);
+ if(ret==NULL){
NyLPC_Abort();
}
- return NULL;
+ return ret;
}
+static NyLPC_TBool parseRequestMethodStr(NyLPC_TcStr_t* i_str,NyLPC_THttpMethodType* o_out)
+{
+ //解析処理
+ *o_out=NyLPC_TTextIdTbl_getMatchIdIgnoreCase(NyLPC_cStr_str(i_str),method_id_table);
+ if(*o_out==NyLPC_THttpMethodType_NULL){
+ NyLPC_OnErrorGoto(ERROR);
+ }
+ return NyLPC_TBool_TRUE;
+ERROR:
+ return NyLPC_TBool_FALSE;
+}
+/*--------------------------------------------------------------------------------
+ *
+ * NyLPC_THttpBasicHeader
+ *
+ --------------------------------------------------------------------------------*/
NyLPC_TBool NyLPC_THttpBasicHeader_isPersistent(const struct NyLPC_THttpBasicHeader* i_struct)
{
@@ -93,30 +117,12 @@
static NyLPC_TBool testHeader(struct NyLPC_THttpBasicHeader* i_header,NyLPC_TUInt16* o_error);
-/*----------------------------------------
- デフォルトハンドラ
-----------------------------------------*/
-
-static NyLPC_TBool default_message_handler(NyLPC_TcHttpBasicHeaderParser_t* i_inst,const NyLPC_TChar* i_name,NyLPC_TChar i_c,struct NyLPC_THttpBasicHeader* o_out)
-{
- (void)i_inst;
- (void)i_name;
- (void)i_c;
- return NyLPC_TBool_TRUE;
-}
-static NyLPC_TBool default_urlHandler(NyLPC_TcHttpBasicHeaderParser_t* i_inst,NyLPC_TChar i_c,struct NyLPC_THttpBasicHeader* o_out)
-{
- (void)i_inst;
- (void)i_c;
- return NyLPC_TBool_TRUE;
-}
/**
* デフォルトハンドラ
*/
static const struct NyLPC_TcHttpBasicHeaderParser_Handler _default_handler=
{
- default_message_handler,
- default_urlHandler
+ NULL,NULL
};
@@ -233,7 +239,7 @@
* FALSE-失敗/TRUE-成功
* 関数が成功した場合、NyLPC_cHttpBasicHeaderParser_parseFinishでパーサを閉じることが出来ます。
*/
-NyLPC_TBool NyLPC_cHttpBasicHeaderParser_parseStream(NyLPC_TcHttpBasicHeaderParser_t* i_inst,NyLPC_TcHttpStream_t* i_stream,struct NyLPC_THttpBasicHeader* o_out)
+NyLPC_TBool NyLPC_cHttpBasicHeaderParser_parseStream(NyLPC_TcHttpBasicHeaderParser_t* i_inst,NyLPC_TiHttpPtrStream_t* i_stream,struct NyLPC_THttpBasicHeader* o_out)
{
const char* rp_base;
NyLPC_TInt32 rsize;
@@ -574,17 +580,21 @@
return NyLPC_TcHttpBasicHeaderParser_ST_MSGPARAM;//変化なし
case HTTP_LF:
//メッセージフィールドの終端を通知
- if(!i_inst->_handler->messageHandler(i_inst,NULL,0,o_out)){
- i_inst->_rcode=500;
- NyLPC_OnErrorGoto(Error);
+ if(i_inst->_handler->messageHandler!=NULL){
+ if(!i_inst->_handler->messageHandler(i_inst,NULL,0,o_out)){
+ i_inst->_rcode=500;
+ NyLPC_OnErrorGoto(Error);
+ }
}
NyLPC_cStr_clear(ws);
return NyLPC_TcHttpBasicHeaderParser_ST_MSGHEAD;
default:
//メッセージフィールドの追記
- if(!i_inst->_handler->messageHandler(i_inst,NULL,i_c,o_out)){
- i_inst->_rcode=500;
- NyLPC_OnErrorGoto(Error);
+ if(i_inst->_handler->messageHandler!=NULL){
+ if(!i_inst->_handler->messageHandler(i_inst,NULL,i_c,o_out)){
+ i_inst->_rcode=500;
+ NyLPC_OnErrorGoto(Error);
+ }
}
break;
}
@@ -623,9 +633,11 @@
}
}
//メッセージフィールドの名前を通知
- if(!i_inst->_handler->messageHandler(i_inst,(NyLPC_TChar*)&(i_inst->_wsb),0,o_out)){
- i_inst->_rcode=500;
- NyLPC_OnErrorGoto(Error);
+ if(i_inst->_handler->messageHandler!=NULL){
+ if(!i_inst->_handler->messageHandler(i_inst,NyLPC_cStr_str(&(i_inst->_wsb)),0,o_out)){
+ i_inst->_rcode=500;
+ NyLPC_OnErrorGoto(Error);
+ }
}
//カスタムヘッダ解析へ。
return NyLPC_TcHttpBasicHeaderParser_ST_MSGPARAM;
@@ -700,16 +712,20 @@
if(i_c==HTTP_SP){
NyLPC_cStr_clear(&(i_inst->_wsb));
//URLハンドラへ通知
- if(!i_inst->_handler->urlHandler(i_inst,0,o_out)){
- i_inst->_rcode=500;
- NyLPC_OnErrorGoto(Error);
+ if(i_inst->_handler->urlHandler!=NULL){
+ if(!i_inst->_handler->urlHandler(i_inst,0,o_out)){
+ i_inst->_rcode=500;
+ NyLPC_OnErrorGoto(Error);
+ }
}
return NyLPC_TcHttpBasicHeaderParser_ST_RL_VERSION;
}
//URLパーサへ通知
- if(!i_inst->_handler->urlHandler(i_inst,i_c,o_out)){
- i_inst->_rcode=500;
- NyLPC_OnErrorGoto(Error);
+ if(i_inst->_handler->urlHandler!=NULL){
+ if(!i_inst->_handler->urlHandler(i_inst,i_c,o_out)){
+ i_inst->_rcode=500;
+ NyLPC_OnErrorGoto(Error);
+ }
}
return NyLPC_TcHttpBasicHeaderParser_ST_RL_URL;//変化なし
Error:
@@ -750,26 +766,7 @@
return NyLPC_TcHttpBasicHeaderParser_ST_ERROR;
}
-static NyLPC_TBool parseRequestMethodStr(NyLPC_TcStr_t* i_str,NyLPC_THttpMethodType* o_out)
-{
- static const char* METHOD[]={
- "GET","POST","HEAD",NULL};
- static const NyLPC_THttpMethodType MT[]={
- NyLPC_THttpMethodType_GET,NyLPC_THttpMethodType_POST,NyLPC_THttpMethodType_HEAD,0x00};
- int i;
- //解析処理
- for(i=0;METHOD[i]!=0x00;i++){
- NyLPC_cStr_toUpper(i_str);//大文字化
- if(NyLPC_cStr_isEqual(i_str,METHOD[i])){
- *o_out=MT[i];
- return NyLPC_TBool_TRUE;
- }
- }
- NyLPC_OnErrorGoto(ERROR);
-ERROR:
- return NyLPC_TBool_FALSE;
-}
