From: nyatla Date: Fri, 5 Apr 2013 08:12:52 +0000 (+0000) Subject: shortURLモジュールの削除 X-Git-Tag: SVN-final~164 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=af6d52e888b7c387a9118195fa27c37b540f6dd2;p=mimic%2FMiMicSDK.git shortURLモジュールの削除 URLモジュールの追加 git-svn-id: http://svn.osdn.jp/svnroot/mimic/trunk@207 47198e57-cb75-475f-84c4-a814cd6f29e0 --- diff --git a/lib/src/driver/flash/LPC17xx_IAP.c b/lib/src/driver/flash/LPC17xx_IAP.c index 53d11d2..93e51ba 100644 --- a/lib/src/driver/flash/LPC17xx_IAP.c +++ b/lib/src/driver/flash/LPC17xx_IAP.c @@ -7,6 +7,11 @@ #include "LPC17xx_IAP.h" +/** + * IPAに通知するCPUクロック。 + * ここで指定したクロック以上で動作させないでください。 + */ +#define IPA_CPU_FREQ_IN_HZ ( ( unsigned long ) 100000000 ) #define LPC17xx_FLASH_SECTOR_ADDR_16 ((void*)0x00010000) //Define data structure or pointers to pass IAP command table and result table to the IAP @@ -85,7 +90,7 @@ unsigned long LPC17xx_IAP_prepare(unsigned long i_start,unsigned long i_end) /** * IAPのcopy ram to flashコマンドを実行。 */ -unsigned long LPC17xx_IAP_copyRam2Flash(const void* i_flash_addr,const void* i_src_addr,unsigned long i_size,unsigned long i_clock_in_khz) +unsigned long LPC17xx_IAP_copyRam2Flash(const void* i_flash_addr,const void* i_src_addr,unsigned long i_size) { unsigned long b[8]; unsigned long c[5]; @@ -94,7 +99,7 @@ unsigned long LPC17xx_IAP_copyRam2Flash(const void* i_flash_addr,const void* i_s c[1]=(unsigned long)i_flash_addr; c[2]=(unsigned long)i_src_addr; c[3]=i_size; - c[4]=i_clock_in_khz; + c[4]=IPA_CPU_FREQ_IN_HZ/1000; memcpy(b,(void*)0x10000000,32); LPCXpresso_iap_entry(c,r); memcpy((void*)0x10000000,b,32); @@ -103,7 +108,7 @@ unsigned long LPC17xx_IAP_copyRam2Flash(const void* i_flash_addr,const void* i_s /** * IAPのeraseコマンドを実行 */ -unsigned long LPC17xx_IAP_erase(unsigned long i_start,unsigned long i_end,unsigned long i_clock_in_khz) +unsigned long LPC17xx_IAP_erase(unsigned long i_start,unsigned long i_end) { unsigned long b[8]; unsigned long c[5]; @@ -111,7 +116,7 @@ unsigned long LPC17xx_IAP_erase(unsigned long i_start,unsigned long i_end,unsign c[0]=52; c[1]=i_start; c[2]=i_end; - c[3]=i_clock_in_khz; + c[3]=IPA_CPU_FREQ_IN_HZ/1000; memcpy(b,(void*)0x10000000,32); LPCXpresso_iap_entry(c,r); memcpy((void*)0x10000000,b,32); diff --git a/lib/src/driver/flash/LPC17xx_IAP.h b/lib/src/driver/flash/LPC17xx_IAP.h index 3d69b14..a89d20a 100644 --- a/lib/src/driver/flash/LPC17xx_IAP.h +++ b/lib/src/driver/flash/LPC17xx_IAP.h @@ -16,8 +16,8 @@ int LPC17xx_IAP_sector2Addr(unsigned int i_sector,void** o_addr); unsigned long LPC17xx_IAP_getSectorSize(unsigned int i_sector); unsigned long LPC17xx_IAP_prepare(unsigned long i_start,unsigned long i_end); -unsigned long LPC17xx_IAP_copyRam2Flash(const void* i_flash_addr,const void* i_src_addr,unsigned long i_size,unsigned long i_clock_in_khz); -unsigned long LPC17xx_IAP_erase(unsigned long i_start,unsigned long i_end,unsigned long i_clock_in_khz); +unsigned long LPC17xx_IAP_copyRam2Flash(const void* i_flash_addr,const void* i_src_addr,unsigned long i_size); +unsigned long LPC17xx_IAP_erase(unsigned long i_start,unsigned long i_end); #ifdef __cplusplus } diff --git a/lib/src/flash/NyLPC_cMiMicConfiglation.c b/lib/src/flash/NyLPC_cMiMicConfiglation.c index 5ae9a26..b7f5b68 100644 --- a/lib/src/flash/NyLPC_cMiMicConfiglation.c +++ b/lib/src/flash/NyLPC_cMiMicConfiglation.c @@ -39,15 +39,13 @@ const static NyLPC_TUInt32 FAST_BOOT_DATA=0xfffffffe; */ NyLPC_TBool NyLPC_cMiMicConfiglation_updateConfigulation(const struct NyLPC_TMimicConfigulation* i_congfiglation) { - NyLPC_TcOnchipFlashWriter_t s; const NyLPC_TUInt32* volatile fast_boot=&(factory_default.fast_boot); - NyLPC_cOnchipFlashWriter_initialize(&s); //イレース - if(!NyLPC_cOnchipFlashWriter_elase(&s,MIMIC_CONFIGLATION_FLASH_SECTOR,MIMIC_CONFIGLATION_FLASH_SECTOR)){ + if(!NyLPC_cOnchipFlashWriter_elase(MIMIC_CONFIGLATION_FLASH_SECTOR,MIMIC_CONFIGLATION_FLASH_SECTOR)){ NyLPC_OnErrorGoto(Error); } //コンフィギュレーションを書き込む。 - if(!NyLPC_cOnchipFlashWriter_writeSector(&s,MIMIC_CONFIGLATION_FLASH_SECTOR,0x00000000,i_congfiglation,sizeof(struct NyLPC_TMimicConfigulation))){ + if(!NyLPC_cOnchipFlashWriter_writeSector(MIMIC_CONFIGLATION_FLASH_SECTOR,0x00000000,i_congfiglation,sizeof(struct NyLPC_TMimicConfigulation))){ NyLPC_OnErrorGoto(Error); } //プログラム済フラッシュの一部を書き換えてユーザコンフィギュレーションをONにする。 @@ -55,15 +53,13 @@ NyLPC_TBool NyLPC_cMiMicConfiglation_updateConfigulation(const struct NyLPC_TMim //フラグ値のアドレスが4バイトアライメントにあるFlashメモリか確認する。 if(((NyLPC_TUInt32)fast_boot)%4==0 && (!NyLPC_cOnchipFlashWriter_isOnchipFlash(fast_boot))){ //書き込み - NyLPC_cOnchipFlashWriter_write(&s,fast_boot,&FAST_BOOT_DATA,4); + NyLPC_cOnchipFlashWriter_write(fast_boot,&FAST_BOOT_DATA,4); }else{ NyLPC_OnErrorGoto(Error); } } - NyLPC_cOnchipFlashWriter_finalize(&s); return NyLPC_TBool_TRUE; Error: - NyLPC_cOnchipFlashWriter_finalize(&s); return NyLPC_TBool_FALSE; } /** diff --git a/lib/src/flash/NyLPC_cOnchipFlashWriter.c b/lib/src/flash/NyLPC_cOnchipFlashWriter.c index a2b5c11..eb173c3 100644 --- a/lib/src/flash/NyLPC_cOnchipFlashWriter.c +++ b/lib/src/flash/NyLPC_cOnchipFlashWriter.c @@ -1,10 +1,7 @@ #include "../driver/flash/LPC17xx_IAP.h" #include "NyLPC_cOnchipFlashWriter.h" -void NyLPC_cOnchipFlashWriter_initialize(NyLPC_TcOnchipFlashWriter_t* i_inst) -{ - (void)i_inst; -} + /** * 指定したアドレスが、オンチップフラッシュかどうか */ @@ -14,21 +11,16 @@ NyLPC_TBool NyLPC_cOnchipFlashWriter_isOnchipFlash(const void* i_addr) return LPC17xx_IAP_addr2Sector(i_addr,&snum)==LPC17xx_IAP_CMD_SUCCESS; } -/** - * アドレスi_destに、i_srcの内容を書き込みます。 - * 書き込みは、FlashROMがイレース済なものとして実行します。書込み範囲以外のデータは、変更されません。 - * 既に書込み済みのデータがある場合(0xFFFFFFFF以外)は、期待した結果が得られないので、注意してください。 - * この関数は、IAPインタフェイス経由で256バイト単位でデータを書き込みます。 - * IAPは0x1000000から32バイトをワークエリアとして使用します。 - * 関数はワークエリアの待避と復帰を行いますが、安全の為、使用前にRTOSを一旦停止させてください。 - */ -NyLPC_TBool NyLPC_cOnchipFlashWriter_write(NyLPC_TcOnchipFlashWriter_t* i_inst,const void* i_dest,const void* i_src,NyLPC_TUInt32 i_size) +NyLPC_TUInt8 _work[256]; + + +NyLPC_TBool NyLPC_cOnchipFlashWriter_write(const void* i_dest,const void* i_src,NyLPC_TUInt32 i_size) { NyLPC_TUInt32 size; - const void* src; + const char* src; NyLPC_TUInt32 snum; - const void* fblock_addr; - const void* dest_addr; + const char* fblock_addr; + const char* dest_addr; NyLPC_TUInt32 wsize; NyLPC_TUInt16 s_padding; NyLPC_TUInt16 free_size; @@ -39,8 +31,8 @@ NyLPC_TBool NyLPC_cOnchipFlashWriter_write(NyLPC_TcOnchipFlashWriter_t* i_inst,c NyLPC_OnErrorGoto(Error); } size=i_size; - src=i_src; - dest_addr=i_dest; + src=(const char*)i_src; + dest_addr=(const char*)i_dest; for(;size>0;){ //開始位置の端数を調べる s_padding=((NyLPC_TUInt32)dest_addr)%256; @@ -52,13 +44,13 @@ NyLPC_TBool NyLPC_cOnchipFlashWriter_write(NyLPC_TcOnchipFlashWriter_t* i_inst,c wsize=free_size>size?size:free_size; //Flashから一時RAMへ前方パディングを読む if(s_padding>0){ - memcpy(i_inst->_work,fblock_addr,s_padding); + memcpy(_work,fblock_addr,s_padding); } //書き込むデータを一時RAMへ書き込む - memcpy(i_inst->_work+s_padding,src,wsize); + memcpy(_work+s_padding,src,wsize); //後半 if(256-(wsize+s_padding)>0){ - memcpy(i_inst->_work+s_padding+wsize,fblock_addr+(wsize+s_padding),256-(wsize+s_padding)); + memcpy(_work+s_padding+wsize,fblock_addr+(wsize+s_padding),256-(wsize+s_padding)); } //Flashへ書込み @@ -72,7 +64,7 @@ NyLPC_TBool NyLPC_cOnchipFlashWriter_write(NyLPC_TcOnchipFlashWriter_t* i_inst,c NyLPC_OnErrorGoto(Error); } //IAPのwriteコマンド - if(LPC17xx_IAP_CMD_SUCCESS!=LPC17xx_IAP_copyRam2Flash(fblock_addr,i_inst->_work,256,configCPU_CLOCK_HZ/1000)){ + if(LPC17xx_IAP_CMD_SUCCESS!=LPC17xx_IAP_copyRam2Flash(fblock_addr,_work,256)){ NyLPC_OnErrorGoto(Error); } dest_addr+=wsize; @@ -87,26 +79,25 @@ Error: /** * セクタ+オフセット形式で、データを書き込みます。 */ -NyLPC_TBool NyLPC_cOnchipFlashWriter_writeSector(NyLPC_TcOnchipFlashWriter_t* i_inst,NyLPC_TUInt16 i_sector,NyLPC_TUInt32 i_offset,const void* i_src,NyLPC_TUInt32 i_size) +NyLPC_TBool NyLPC_cOnchipFlashWriter_writeSector(NyLPC_TUInt16 i_sector,NyLPC_TUInt32 i_offset,const void* i_src,NyLPC_TUInt32 i_size) { void* addr; if(!LPC17xx_IAP_sector2Addr(i_sector,&addr)){ return NyLPC_TBool_FALSE; } addr=(void*)((NyLPC_TUInt32)addr+i_offset); - return NyLPC_cOnchipFlashWriter_write(i_inst,addr,i_src,i_size); + return NyLPC_cOnchipFlashWriter_write(addr,i_src,i_size); } /** * FlashRomのセクタ番号Nにイレースを実行します。 */ -NyLPC_TBool NyLPC_cOnchipFlashWriter_elase(NyLPC_TcOnchipFlashWriter_t* i_inst,NyLPC_TUInt16 i_sector_s,NyLPC_TUInt16 i_sector_e) +NyLPC_TBool NyLPC_cOnchipFlashWriter_elase(NyLPC_TUInt16 i_sector_s,NyLPC_TUInt16 i_sector_e) { - (void)i_inst; if(LPC17xx_IAP_CMD_SUCCESS!=LPC17xx_IAP_prepare(i_sector_s,i_sector_e)){ return NyLPC_TBool_FALSE; } - if(LPC17xx_IAP_CMD_SUCCESS!=LPC17xx_IAP_erase(i_sector_s,i_sector_e,configCPU_CLOCK_HZ/1000)){ + if(LPC17xx_IAP_CMD_SUCCESS!=LPC17xx_IAP_erase(i_sector_s,i_sector_e)){ return NyLPC_TBool_FALSE; } return NyLPC_TBool_TRUE; diff --git a/lib/src/flash/NyLPC_cOnchipFlashWriter.h b/lib/src/flash/NyLPC_cOnchipFlashWriter.h index 25e567f..d0d5fb2 100644 --- a/lib/src/flash/NyLPC_cOnchipFlashWriter.h +++ b/lib/src/flash/NyLPC_cOnchipFlashWriter.h @@ -7,20 +7,23 @@ extern "C" { #endif /* __cplusplus */ -typedef struct NyLPC_TcOnchipFlashWriter NyLPC_TcOnchipFlashWriter_t; -struct NyLPC_TcOnchipFlashWriter -{ - NyLPC_TUInt8 _work[256]; -}; -void NyLPC_cOnchipFlashWriter_initialize(NyLPC_TcOnchipFlashWriter_t* i_inst); - -#define NyLPC_cOnchipFlashWriter_finalize(i) - -NyLPC_TBool NyLPC_cOnchipFlashWriter_write(NyLPC_TcOnchipFlashWriter_t* i_inst,const void* i_dest,const void* i_src,NyLPC_TUInt32 i_size); -NyLPC_TBool NyLPC_cOnchipFlashWriter_writeSector(NyLPC_TcOnchipFlashWriter_t* i_inst,NyLPC_TUInt16 i_sector,NyLPC_TUInt32 i_offset,const void* i_src,NyLPC_TUInt32 i_size); -NyLPC_TBool NyLPC_cOnchipFlashWriter_elase(NyLPC_TcOnchipFlashWriter_t* i_inst,NyLPC_TUInt16 i_sector_s,NyLPC_TUInt16 i_sector_e); +/** + * アドレスi_destに、i_srcの内容を書き込みます。 + * 書き込みは、FlashROMがイレース済なものとして実行します。書込み範囲以外のデータは、変更されません。 + * 既に書込み済みのデータがある場合(0xFFFFFFFF以外)は、期待した結果が得られないので、注意してください。 + * この関数は、IAPインタフェイス経由で256バイト単位でデータを書き込みます。 + * IAPは0x1000000から32バイトをワークエリアとして使用します。 + * 関数はワークエリアの待避と復帰を行いますが、安全の為、使用前にRTOSを一旦停止させてください。 + * この関数はリエントラントではありません。 + */ +NyLPC_TBool NyLPC_cOnchipFlashWriter_write(const void* i_dest,const void* i_src,NyLPC_TUInt32 i_size); +/** + * この関数はリエントラントではありません。 + */ +NyLPC_TBool NyLPC_cOnchipFlashWriter_writeSector(NyLPC_TUInt16 i_sector,NyLPC_TUInt32 i_offset,const void* i_src,NyLPC_TUInt32 i_size); +NyLPC_TBool NyLPC_cOnchipFlashWriter_elase(NyLPC_TUInt16 i_sector_s,NyLPC_TUInt16 i_sector_e); NyLPC_TBool NyLPC_cOnchipFlashWriter_isOnchipFlash(const void* i_addr); diff --git a/lib/src/http/NyLPC_cHttpShortRequestHeaderParser.c b/lib/src/http/NyLPC_cHttpShortRequestHeaderParser.c deleted file mode 100644 index 889921b..0000000 --- a/lib/src/http/NyLPC_cHttpShortRequestHeaderParser.c +++ /dev/null @@ -1,81 +0,0 @@ -/********************************************************************************* - * PROJECT: MiMic - * -------------------------------------------------------------------------------- - * - * This file is part of MiMic - * Copyright (C)2011 Ryo Iizuka - * - * MiMic is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published - * by the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program 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 Lesser General Public License - * along with this program. If not, see . - * - * For further information please contact. - * http://nyatla.jp/ - * or - * - *********************************************************************************/ -#include "NyLPC_cHttpShortRequestHeaderParser.h" - -static NyLPC_TBool 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 urlHandler(NyLPC_TcHttpBasicHeaderParser_t* i_inst,NyLPC_TChar i_c,struct NyLPC_THttpBasicHeader* o_out) -{ - //32文字までのURL解析 - NyLPC_TcHttpShortRequestHeaderParser_t* inst=(NyLPC_TcHttpShortRequestHeaderParser_t*)i_inst; - struct NyLPC_THttpShortRequestHeader* out=(struct NyLPC_THttpShortRequestHeader*)o_out; - out->url[inst->url_len]=i_c; - inst->url_len++; - if(inst->url_len>=32){ - out->url[inst->url_len-1]='\0'; - return NyLPC_TBool_FALSE; - } - return NyLPC_TBool_TRUE; -} -/** - * デフォルトハンドラ - */ -static const struct NyLPC_TcHttpBasicHeaderParser_Handler _handler= -{ - message_handler, - urlHandler -}; - - - - -void NyLPC_cHttpShortRequestHeaderParser_initialize(NyLPC_TcHttpShortRequestHeaderParser_t* i_inst) -{ - NyLPC_cHttpBasicHeaderParser_initialize(&(i_inst->super),&_handler); -} - -void NyLPC_cHttpShortRequestHeaderParser_parseInit(NyLPC_TcHttpShortRequestHeaderParser_t* i_inst,struct NyLPC_THttpShortRequestHeader* o_out) -{ - i_inst->url_len=0; - NyLPC_cHttpBasicHeaderParser_parseInit(&((i_inst)->super),&((o_out)->super)); -} - -NyLPC_TBool NyLPC_cHttpShortRequestHeaderParser_parse(NyLPC_TcHttpShortRequestHeaderParser_t* i_inst,NyLPC_TcHttpStream_t* i_stream,struct NyLPC_THttpShortRequestHeader* o_out) -{ - NyLPC_cHttpShortRequestHeaderParser_parseInit(i_inst,o_out); - if(!NyLPC_cHttpBasicHeaderParser_parseStream(&(i_inst->super),i_stream,&(o_out->super))) - { - return NyLPC_TBool_FALSE; - } - return NyLPC_cHttpBasicHeaderParser_parseFinish(&(i_inst->super),&(o_out->super)); -} - - diff --git a/lib/src/http/NyLPC_cHttpShortRequestHeaderParser.h b/lib/src/http/NyLPC_cHttpShortRequestHeaderParser.h deleted file mode 100644 index 93f9dc9..0000000 --- a/lib/src/http/NyLPC_cHttpShortRequestHeaderParser.h +++ /dev/null @@ -1,85 +0,0 @@ -/********************************************************************************* - * PROJECT: MiMic - * -------------------------------------------------------------------------------- - * - * This file is part of MiMic - * Copyright (C)2011 Ryo Iizuka - * - * MiMic is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published - * by the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program 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 Lesser General Public License - * along with this program. If not, see . - * - * For further information please contact. - * http://nyatla.jp/ - * or - * - *********************************************************************************/ -#ifndef NYLPC_CHTTPSHORTHTTPHEADERPARSER_H_ -#define NYLPC_CHTTPSHORTHTTPHEADERPARSER_H_ -#include "NyLPC_cHttpBasicHeaderParser.h" - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/** - * URLが最大31文字までの、短いHttpリクエストを処理します。 - * このクラスは、NyLPC_TBasicHttpHeader_tにキャストできます。 - */ -typedef struct NyLPC_TcHttpShortReqestHeaderParser NyLPC_TcHttpShortRequestHeaderParser_t; - - -struct NyLPC_THttpShortRequestHeader -{ - struct NyLPC_THttpBasicHeader super; - NyLPC_TChar url[32]; -}; - -struct NyLPC_TcHttpShortReqestHeaderParser{ - NyLPC_TcHttpBasicHeaderParser_t super; - NyLPC_TUInt16 url_len; -}; - -void NyLPC_cHttpShortRequestHeaderParser_initialize(NyLPC_TcHttpShortRequestHeaderParser_t* i_inst); - -#define NyLPC_cHttpShortRequestHeaderParser_finalize(i_inst) NyLPC_cHttpBasicHeaderParser_finalize(i_inst); - -/** - * parseInit,parseStream,parseFinishを一括で実行します。 - */ -NyLPC_TBool NyLPC_cHttpShortRequestHeaderParser_parse(NyLPC_TcHttpShortRequestHeaderParser_t* i_inst,NyLPC_TcHttpStream_t* i_stream,struct NyLPC_THttpShortRequestHeader* o_out); - - -/** override - */ -void NyLPC_cHttpShortRequestHeaderParser_parseInit(NyLPC_TcHttpShortRequestHeaderParser_t* i_inst,struct NyLPC_THttpShortRequestHeader* o_out); - - -/** override - */ -#define NyLPC_cHttpShortRequestHeaderParser_parseFinish(i_inst,o_out) NyLPC_cHttpBasicHeaderParser_parseFinish(&((i_inst)->super),&((o_out)->super)) - -/** override - */ -#define NyLPC_cHttpShortRequestHeaderParser_parseChar(i_inst,i_c,i_size,o_out) NyLPC_cHttpBasicHeaderParser_parseChar(&((i_inst)->super),i_c,i_size,&((o_out)->super)); - -/** override - */ -#define NyLPC_cHttpShortRequestHeaderParser_parseStream(i_inst,i_stream,o_out) NyLPC_cHttpBasicHeaderParser_parseStream(&((i_inst)->super),i_stream,&((o_out)->super)) - - - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* NYLPC_CHTTPSHORTHTTPHEADERPARSER_H_ */ diff --git a/lib/src/include/NyLPC_http.h b/lib/src/include/NyLPC_http.h index e2539d6..0563a23 100644 --- a/lib/src/include/NyLPC_http.h +++ b/lib/src/include/NyLPC_http.h @@ -33,10 +33,9 @@ #include "../http/NyLPC_cHttpdConfig.h" #include "../http/NyLPC_cHttpHeaderWriter.h" #include "../http/NyLPC_cHttpBodyWriter.h" -#include "../http/NyLPC_cHttpShortRequestHeaderParser.h" #include "../http/NyLPC_cHttpBasicHeaderParser.h" #include "../http/NyLPC_cHttpStream.h" - +#include "../http/NyLPC_cHttpNullRequestHeaderParser.h" #ifdef __cplusplus extern "C" { diff --git a/lib/src/net/NyLPC_cNet.h b/lib/src/net/NyLPC_cNet.h index 9e07908..85d2bb9 100644 --- a/lib/src/net/NyLPC_cNet.h +++ b/lib/src/net/NyLPC_cNet.h @@ -25,6 +25,8 @@ struct NyLPC_TcNet * ネットワークを初期化する。 */ void NyLPC_cNet_initialize(NyLPC_TcNet_t* i_inst); + +#define NyLPC_cNet_finalize(inst) /** * 関数は、ネットワークアダプタの値を元にNyLPC_cMiMicEnv_PlatformName変数の値を更新します。 * @param i_ref_config diff --git a/lib/src/net/httpd/NyLPC_cHttpRequestPrefixParser.c b/lib/src/net/httpd/NyLPC_cHttpRequestPrefixParser.c index 343e3fa..168b850 100644 --- a/lib/src/net/httpd/NyLPC_cHttpRequestPrefixParser.c +++ b/lib/src/net/httpd/NyLPC_cHttpRequestPrefixParser.c @@ -24,8 +24,6 @@ * *********************************************************************************/ #include "NyLPC_cHttpRequestPrefixParser.h" -#include "../http/NyLPC_cHttpBasicHeaderParser_protected.h" - diff --git a/lib/src/net/httpd/NyLPC_cHttpd.h b/lib/src/net/httpd/NyLPC_cHttpd.h index 261cee5..fc423c9 100644 --- a/lib/src/net/httpd/NyLPC_cHttpd.h +++ b/lib/src/net/httpd/NyLPC_cHttpd.h @@ -26,7 +26,7 @@ typedef void (*NyLPC_TcHttpd_onRequest)(NyLPC_TcHttpdConnection_t* i_inst); struct NyLPC_TcHttpd { struct{ - NyLPC_TcHttpd_onRequest _handler; + NyLPC_TcHttpd_onRequest onRequest; }function; NyLPC_TcMutex_t _mutex; NyLPC_TcTcpListener_t _listener; diff --git a/lib/src/net/httpd/NyLPC_cHttpdConnection.c b/lib/src/net/httpd/NyLPC_cHttpdConnection.c index 7d73346..7a1846d 100644 --- a/lib/src/net/httpd/NyLPC_cHttpdConnection.c +++ b/lib/src/net/httpd/NyLPC_cHttpdConnection.c @@ -1,5 +1,5 @@ #include "NyLPC_cHttpdConnection_protected.h" -#include "../http/NyLPC_cHttpNullRequestHeaderParser.h" +#include "NyLPC_http.h" #include "./mod/NyLPC_cHttpModUtils_protected.h" #include "./NyLPC_cHttpd_protected.h" diff --git a/lib/src/net/httpd/NyLPC_cHttpdConnection_protected.h b/lib/src/net/httpd/NyLPC_cHttpdConnection_protected.h index 4a6a705..ae97219 100644 --- a/lib/src/net/httpd/NyLPC_cHttpdConnection_protected.h +++ b/lib/src/net/httpd/NyLPC_cHttpdConnection_protected.h @@ -7,9 +7,10 @@ #ifndef NYLPC_CHTTPDCONNECTION_PROTECTED_H_ #define NYLPC_CHTTPDCONNECTION_PROTECTED_H_ -#include "../../uip/NyLPC_cTcpListener.h" +#include "NyLPC_uipService.h" #include "NyLPC_cHttpdConnection.h" #include "NyLPC_stdlib.h" +#include "./mod/NyLPC_cHttpModUtils_protected.h" /** * コネクションモード */ diff --git a/lib/src/net/httpd/NyLPC_cHttpdThread.c b/lib/src/net/httpd/NyLPC_cHttpdThread.c index 1a920c3..f0303f3 100644 --- a/lib/src/net/httpd/NyLPC_cHttpdThread.c +++ b/lib/src/net/httpd/NyLPC_cHttpdThread.c @@ -59,7 +59,7 @@ static int server(void* p) NyLPC_cHttpdConnection_setConnectionMode(inst,NyLPC_TcHttpdConnection_CONNECTION_MODE_CLOSE); {//handler - (inst->_parent_httpd->function._handler)(inst); + (inst->_parent_httpd->function.onRequest)(inst); } //コネクションが増えすぎたら持続性接続を停止するためにCLOSEDにする。 if(NyLPC_cHttpd_getNumOfConnection(inst->_parent_httpd)>LIMIT_OF_PERSISTENT_CONNECTION){ diff --git a/lib/src/net/httpd/mod/NyLPC_cHttpModUtils.c b/lib/src/net/httpd/mod/NyLPC_cHttpModUtils.c index b1083bb..94d2554 100644 --- a/lib/src/net/httpd/mod/NyLPC_cHttpModUtils.c +++ b/lib/src/net/httpd/mod/NyLPC_cHttpModUtils.c @@ -4,7 +4,7 @@ * Created on: 2013/03/05 * Author: nyatla */ -#include "NyLPC_cHttpmodUtils_protected.h" +#include "NyLPC_cHttpModUtils_protected.h" const char* NyLPC_cHttpdModUtils_getMethodPrefix(NyLPC_THttpMethodType i_method) { diff --git a/lib/src/net/httpd/mod/NyLPC_cModMiMicSetting.c b/lib/src/net/httpd/mod/NyLPC_cModMiMicSetting.c index daf78ae..b580e8f 100644 --- a/lib/src/net/httpd/mod/NyLPC_cModMiMicSetting.c +++ b/lib/src/net/httpd/mod/NyLPC_cModMiMicSetting.c @@ -25,9 +25,9 @@ *********************************************************************************/ #include "NyLPC_cModMiMicSetting.h" #include "NyLPC_stdlib.h" -#include "NyLPC_cHttpmodUtils_protected.h" +#include "NyLPC_cHttpModUtils_protected.h" #include "NyLPC_http.h" -#include "NyLPC_mimicvm.h" +#include "NyLPC_mimicVm.h" #include "NyLPC_flash.h" #include "../NyLPC_cHttpdConnection_protected.h" #include "../../NyLPC_cNet.h" diff --git a/lib/src/net/httpd/mod/NyLPC_cModRemoteMcu.c b/lib/src/net/httpd/mod/NyLPC_cModRemoteMcu.c index 2be6710..69d1774 100644 --- a/lib/src/net/httpd/mod/NyLPC_cModRemoteMcu.c +++ b/lib/src/net/httpd/mod/NyLPC_cModRemoteMcu.c @@ -26,7 +26,7 @@ #include "NyLPC_cModRemoteMcu.h" #include "NyLPC_stdlib.h" #include "NyLPC_http.h" -#include "NyLPC_mimicvm.h" +#include "NyLPC_mimicVm.h" #include "../NyLPC_cHttpdConnection_protected.h" #include "NyLPC_cHttpmodUtils_protected.h" #include "NyLPC_net.h" diff --git a/lib/src/net/httpd/mod/NyLPC_cModRomFiles.c b/lib/src/net/httpd/mod/NyLPC_cModRomFiles.c index 344d88b..7e42ed8 100644 --- a/lib/src/net/httpd/mod/NyLPC_cModRomFiles.c +++ b/lib/src/net/httpd/mod/NyLPC_cModRomFiles.c @@ -182,7 +182,7 @@ NyLPC_TUInt16 NyLPC_cModRomFiles_getUrlSuffix(NyLPC_TcModRomFiles_t* i_inst,NyLP if(!NyLPC_cHttpBasicHeaderParser_parseFinish(&parser,&(header->super))){ NyLPC_OnErrorGoto(Error2); } - NyLPC_cHttpShortRequestHeaderParser_finalize(&parser); + NyLPC_cHttpBasicHeaderParser_finalize(&parser); return 200; Error2: //BadRequest diff --git a/lib/src/net/httpd/mod/NyLPC_cModShortUrl.c b/lib/src/net/httpd/mod/NyLPC_cModShortUrl.c deleted file mode 100644 index 7ecb6dc..0000000 --- a/lib/src/net/httpd/mod/NyLPC_cModShortUrl.c +++ /dev/null @@ -1,102 +0,0 @@ -/********************************************************************************* - * PROJECT: MiMic - * -------------------------------------------------------------------------------- - * - * This file is part of MiMic - * Copyright (C)2011 Ryo Iizuka - * - * MiMic is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published - * by the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program 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 Lesser General Public License - * along with this program. If not, see . - * - * For further information please contact. - * http://nyatla.jp/ - * or - * - *********************************************************************************/ -#include "NyLPC_cModShortUrl.h" -#include "NyLPC_stdlib.h" -#include "NyLPC_http.h" -#include "NyLPC_cHttpModUtils_protected.h" -#include "../NyLPC_cHttpdConnection_protected.h" - -void NyLPC_cModShortUrl_initialize(NyLPC_TcModShortUrl_t* i_inst) -{ - -} -void NyLPC_cModShortUrl_finalize(NyLPC_TcModShortUrl_t* i_inst) -{ - -} - -const struct NyLPC_THttpBasicHeader* NyLPC_cModShortUrl_getHeader(const NyLPC_TcModShortUrl_t* i_inst) -{ - return &(i_inst->_header.super); -} -const NyLPC_TChar* NyLPC_cModShortUrl_getPath(const NyLPC_TcModShortUrl_t* i_inst) -{ - return i_inst->_header.url; -} - -NyLPC_TBool NyLPC_cModShortUrl_isEqualPath(const NyLPC_TcModShortUrl_t* i_inst,const NyLPC_TChar* i_path) -{ - return strcmp(i_inst->_header.url,i_path)==0; -} -/** - * Methodタイプを返します。 - */ -NyLPC_THttpMethodType NyLPC_cModShortUrl_getMethod(const NyLPC_TcModShortUrl_t* i_inst) -{ - return i_inst->_header.super.startline.req.method; -} - - - - -NyLPC_TBool NyLPC_cModShortUrl_execute(NyLPC_TcModShortUrl_t* i_inst,NyLPC_TcHttpdConnection_t* i_connection) -{ - NyLPC_TcHttpShortRequestHeaderParser_t parser; - if(!NyLPC_cHttpdConnection_getReqStatus(i_connection)==NyLPC_cHttpdConnection_ReqStatus_REQPARSE) - { - NyLPC_OnErrorGoto(Error1); - } - //リクエストParse済へ遷移 - NyLPC_cHttpdConnection_setReqStatusParsed(i_connection); - - NyLPC_cHttpShortRequestHeaderParser_initialize(&parser); - //プリフェッチしたデータを流す - NyLPC_cHttpShortRequestHeaderParser_parseInit(&parser,&(i_inst->_header)); - NyLPC_cHttpdConnection_pushPrefetchInfo(i_connection,&parser.super,&(i_inst->_header.super)); - //後続をストリームから取り込む - if(!NyLPC_cHttpShortRequestHeaderParser_parseStream(&parser,NyLPC_cHttpdConnection_refStream(i_connection),&(i_inst->_header))){ - NyLPC_OnErrorGoto(Error2); - } - if(!NyLPC_cHttpShortRequestHeaderParser_parseFinish(&parser,&(i_inst->_header))){ - NyLPC_OnErrorGoto(Error2); - } - //Connection Modeの設定 1.1 && !closeの場合はCONTINUE - if(i_inst->_header.super.connection!=NyLPC_THttpMessgeHeader_Connection_CLOSE && i_inst->_header.super.startline.req.version==NyLPC_THttpVersion_11) - { - NyLPC_cHttpdConnection_setConnectionMode(i_connection,NyLPC_TcHttpdConnection_CONNECTION_MODE_CONTINUE); - } - NyLPC_cHttpShortRequestHeaderParser_finalize(&parser); - return NyLPC_TBool_TRUE; -Error2: - //400Error - NyLPC_cHttpdConnection_sendResponseHeader2(i_connection,400,"text/html",0,NULL); - NyLPC_cHttpShortRequestHeaderParser_finalize(&parser); -Error1: - return NyLPC_TBool_FALSE; -} - - - diff --git a/lib/src/net/httpd/mod/NyLPC_cModUrl.c b/lib/src/net/httpd/mod/NyLPC_cModUrl.c new file mode 100644 index 0000000..b9cb4ba --- /dev/null +++ b/lib/src/net/httpd/mod/NyLPC_cModUrl.c @@ -0,0 +1,136 @@ +/********************************************************************************* + * PROJECT: MiMic + * -------------------------------------------------------------------------------- + * + * This file is part of MiMic + * Copyright (C)2011 Ryo Iizuka + * + * MiMic is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 Lesser General Public License + * along with this program. If not, see . + * + * For further information please contact. + * http://nyatla.jp/ + * or + * + *********************************************************************************/ +#include "NyLPC_cModUrl.h" +#include "NyLPC_stdlib.h" +#include "NyLPC_http.h" +#include "NyLPC_cHttpModUtils_protected.h" +#include "../NyLPC_cHttpdConnection_protected.h" + +typedef struct TcHeaderParser +{ + NyLPC_TcHttpBasicHeaderParser_t super; + char* url_buf; + NyLPC_TUInt16 length_of_buf; + NyLPC_TUInt16 length_of_url; +}TcHeaderParser_t; + +static NyLPC_TBool NyLPC_cModUrl_messageHandler(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 NyLPC_cModUrl_urlHandler(NyLPC_TcHttpBasicHeaderParser_t* i_inst,NyLPC_TChar i_c,struct NyLPC_THttpBasicHeader* o_out) +{ + TcHeaderParser_t* inst=(TcHeaderParser_t*)i_inst; + inst->url_buf[inst->length_of_url]=i_c; + inst->length_of_url++; + if(i_c=='\0'){ + return NyLPC_TBool_TRUE;//Terminate + } + if(inst->length_of_url==inst->length_of_buf){ + return NyLPC_TBool_FALSE;//長すぎる。 + } + return NyLPC_TBool_TRUE; +} +/** + * デフォルトハンドラ + */ +static const struct NyLPC_TcHttpBasicHeaderParser_Handler _handler= +{ + NyLPC_cModUrl_messageHandler, + NyLPC_cModUrl_urlHandler +}; + + + +void NyLPC_cModUrl_initialize(NyLPC_TcModUrl_t* i_inst) +{ + +} +void NyLPC_cModUrl_finalize(NyLPC_TcModUrl_t* i_inst) +{ + +} + +const struct NyLPC_THttpBasicHeader* NyLPC_cModUrl_getHeader(const NyLPC_TcModUrl_t* i_inst) +{ + return &(i_inst->_header); +} + +/** + * Methodタイプを返します。 + */ +NyLPC_THttpMethodType NyLPC_cModUrl_getMethod(const NyLPC_TcModUrl_t* i_inst) +{ + return i_inst->_header.startline.req.method; +} + + + + +NyLPC_TBool NyLPC_cModUrl_execute(NyLPC_TcModUrl_t* i_inst,NyLPC_TcHttpdConnection_t* i_connection,char* o_url_buf,int i_length_buf) +{ + TcHeaderParser_t parser; + if(!NyLPC_cHttpdConnection_getReqStatus(i_connection)==NyLPC_cHttpdConnection_ReqStatus_REQPARSE) + { + NyLPC_OnErrorGoto(Error1); + } + //リクエストParse済へ遷移 + NyLPC_cHttpdConnection_setReqStatusParsed(i_connection); + + NyLPC_cHttpBasicHeaderParser_initialize(&parser.super,&_handler); + parser.length_of_buf=i_length_buf; + parser.length_of_url=0; + parser.url_buf=o_url_buf; + //プリフェッチしたデータを流す + NyLPC_cHttpBasicHeaderParser_parseInit(&parser.super,&(i_inst->_header)); + NyLPC_cHttpdConnection_pushPrefetchInfo(i_connection,&parser.super,&(i_inst->_header)); + //後続をストリームから取り込む + if(!NyLPC_cHttpBasicHeaderParser_parseStream(&parser.super,NyLPC_cHttpdConnection_refStream(i_connection),&(i_inst->_header))){ + NyLPC_OnErrorGoto(Error2); + } + if(!NyLPC_cHttpBasicHeaderParser_parseFinish(&parser.super,&(i_inst->_header))){ + NyLPC_OnErrorGoto(Error2); + } + //Connection Modeの設定 1.1 && !closeの場合はCONTINUE + if(i_inst->_header.connection!=NyLPC_THttpMessgeHeader_Connection_CLOSE && i_inst->_header.startline.req.version==NyLPC_THttpVersion_11) + { + NyLPC_cHttpdConnection_setConnectionMode(i_connection,NyLPC_TcHttpdConnection_CONNECTION_MODE_CONTINUE); + } + NyLPC_cHttpBasicHeaderParser_finalize(&parser); + return NyLPC_TBool_TRUE; +Error2: + //400Error + NyLPC_cHttpdConnection_sendResponseHeader2(i_connection,400,"text/html",0,NULL); + NyLPC_cHttpBasicHeaderParser_finalize(&parser); +Error1: + return NyLPC_TBool_FALSE; +} + + + diff --git a/lib/src/net/httpd/mod/NyLPC_cModShortUrl.h b/lib/src/net/httpd/mod/NyLPC_cModUrl.h similarity index 53% rename from lib/src/net/httpd/mod/NyLPC_cModShortUrl.h rename to lib/src/net/httpd/mod/NyLPC_cModUrl.h index 31dc5a7..099b128 100644 --- a/lib/src/net/httpd/mod/NyLPC_cModShortUrl.h +++ b/lib/src/net/httpd/mod/NyLPC_cModUrl.h @@ -23,8 +23,9 @@ * or * *********************************************************************************/ -#ifndef NYLPC_CMODSHORTURL_H_ -#define NYLPC_CMODSHORTURL_H_ +#ifndef NYLPC_CMODURL_H_ +#define NYLPC_CMODURL_H_ + #include "NyLPC_http.h" #include "../NyLPC_cHttpdConnection.h" #ifdef __cplusplus @@ -32,44 +33,36 @@ extern "C" { #endif /* __cplusplus */ /** - * URLが最大31文字までの、短いHttpリクエストを処理して、リクエスト内容を取得します。 + * URLを */ -typedef struct NyLPC_TcModShortUrl NyLPC_TcModShortUrl_t; +typedef struct NyLPC_TcModUrl NyLPC_TcModUrl_t; -struct NyLPC_TcModShortUrl +struct NyLPC_TcModUrl { - struct NyLPC_THttpShortRequestHeader _header; + struct NyLPC_THttpBasicHeader _header; }; /** * コンストラクタ。 */ -void NyLPC_cModShortUrl_initialize(NyLPC_TcModShortUrl_t* i_inst); -void NyLPC_cModShortUrl_finalize(NyLPC_TcModShortUrl_t* i_inst); +void NyLPC_cModUrl_initialize(NyLPC_TcModUrl_t* i_inst); +void NyLPC_cModUrl_finalize(NyLPC_TcModUrl_t* i_inst); /** - * ShortURLのパースを実行して、コネクションの返却準備をします。 + * 。 */ -NyLPC_TBool NyLPC_cModShortUrl_execute(NyLPC_TcModShortUrl_t* i_inst,NyLPC_TcHttpdConnection_t* i_connection); +NyLPC_TBool NyLPC_cModUrl_execute(NyLPC_TcModUrl_t* i_inst,NyLPC_TcHttpdConnection_t* i_connection,char* o_url_buf,int i_length_buf); /** * basicヘッダオブジェクトを返します。 */ -const struct NyLPC_THttpBasicHeader* NyLPC_cModShortUrl_getHeader(const NyLPC_TcModShortUrl_t* i_inst); -/** - * URLを返します。URL長は最大32文字です。 - */ -const NyLPC_TChar* NyLPC_cModShortUrl_getPath(const NyLPC_TcModShortUrl_t* i_inst); -/** - * URLが一致しているかを返します。 - */ -NyLPC_TBool NyLPC_cModShortUrl_isEqualPath(const NyLPC_TcModShortUrl_t* i_inst,const NyLPC_TChar* i_path); +const struct NyLPC_THttpBasicHeader* NyLPC_cModUrl_getHeader(const NyLPC_TcModUrl_t* i_inst); /** * Methodタイプを返します。 */ -NyLPC_THttpMethodType NyLPC_cModShortUrl_getMethod(const NyLPC_TcModShortUrl_t* i_inst); +NyLPC_THttpMethodType NyLPC_cModUrl_getMethod(const NyLPC_TcModUrl_t* i_inst); @@ -80,4 +73,7 @@ NyLPC_THttpMethodType NyLPC_cModShortUrl_getMethod(const NyLPC_TcModShortUrl_t* } #endif /* __cplusplus */ -#endif /* NYLPC_CHTTPSHORTHTTPHEADERPARSER_H_ */ + + + +#endif /* NYLPC_CMODURL_H_ */ diff --git a/lib/src/uip/NyLPC_cIPv4Payload.c b/lib/src/uip/NyLPC_cIPv4Payload.c index 0ff614a..ef32926 100644 --- a/lib/src/uip/NyLPC_cIPv4Payload.c +++ b/lib/src/uip/NyLPC_cIPv4Payload.c @@ -257,7 +257,7 @@ void NyLPC_cIPv4Payload_closeTcpTxPacket( i_inst->payload.tcp->tcpchksum=~(NyLPC_TIPv4Header_makeTcpChecksum(i_inst->header)); i_inst->header->ipchksum = ~(NyLPC_TIPv4Header_makeIpChecksum(i_inst->header)); } - +/* なんだっけっこれ? //1の補数v1にv2を加算する。 static NyLPC_TUInt16 add16c(NyLPC_TUInt16 i_v1,NyLPC_TUInt16 i_v2) { @@ -272,6 +272,7 @@ static NyLPC_TUInt16 sub16c(NyLPC_TUInt16 i_v1,NyLPC_TUInt16 i_v2) t=i_v1-i_v2; return (theader=i_inst->header; o_inst->payload=i_inst->payload; } -static void* logA; -static void* logB; + /** * ACK番号を更新する。 * @param i_ackno @@ -295,8 +295,7 @@ void NyLPC_cIPv4Payload_updateAckNo( NyLPC_TUInt32 i_ackno) { NyLPC_Assert(i_inst->header!=NULL); - logA=i_inst->header; - logB=i_inst->payload.tcp; + /* union{ NyLPC_TUInt32 l;