This is Webservice SDK for mbed. LPCXpresso1769/LPC1768/FRDM-K64F/LPC4088
Dependents: MbedFileServer_1768MiniDK2 RedWireBridge IssueDebug_gcc MiMicRemoteMCU-for-Mbed ... more
NyLPC_cHttpBasicHeaderParser.h
00001 /********************************************************************************* 00002 * PROJECT: MiMic 00003 * -------------------------------------------------------------------------------- 00004 * 00005 * This file is part of MiMic 00006 * Copyright (C)2011 Ryo Iizuka 00007 * 00008 * MiMic is free software: you can redistribute it and/or modify 00009 * it under the terms of the GNU Lesser General Public License as published 00010 * by the Free Software Foundation, either version 3 of the License, or 00011 * (at your option) any later version. 00012 * 00013 * This program is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public License 00019 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00020 * 00021 * For further information please contact. 00022 * http://nyatla.jp/ 00023 * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp> 00024 * 00025 *********************************************************************************/ 00026 00027 #ifndef NyLPC_TcHttpBasicHeaderParser_H 00028 #define NyLPC_TcHttpBasicHeaderParser_H 00029 #include "NyLPC_stdlib.h" 00030 #include "NyLPC_cHttpStream.h" 00031 00032 #ifdef __cplusplus 00033 extern "C" { 00034 #endif /* __cplusplus */ 00035 00036 /** 00037 * HeaderParserのステータス定義値。 00038 */ 00039 typedef NyLPC_TUInt8 NyLPC_TcHttpBasicHeaderParser_ST; 00040 #define NyLPC_TcHttpBasicHeaderParser_ST_START ((NyLPC_TcHttpBasicHeaderParser_ST)0x01)//HTTPステータスラインか、リクエストライン 00041 #define NyLPC_TcHttpBasicHeaderParser_ST_RL_URL ((NyLPC_TcHttpBasicHeaderParser_ST)0x12)//URL 00042 #define NyLPC_TcHttpBasicHeaderParser_ST_RL_VERSION ((NyLPC_TcHttpBasicHeaderParser_ST)0x13)//VERSION 00043 #define NyLPC_TcHttpBasicHeaderParser_ST_SL_STATUSCODE ((NyLPC_TcHttpBasicHeaderParser_ST)0x21)//ステータスコード 00044 #define NyLPC_TcHttpBasicHeaderParser_ST_SL_REASON ((NyLPC_TcHttpBasicHeaderParser_ST)0x22)//Reason-Phrase 00045 #define NyLPC_TcHttpBasicHeaderParser_ST_MSGHEAD ((NyLPC_TcHttpBasicHeaderParser_ST)0x31)//MESSAGE 00046 #define NyLPC_TcHttpBasicHeaderParser_ST_MSGPARAM ((NyLPC_TcHttpBasicHeaderParser_ST)0x32)//MESSAGEパラメータ部 00047 #define NyLPC_TcHttpBasicHeaderParser_ST_MSG_CONTENTLENGTH ((NyLPC_TcHttpBasicHeaderParser_ST)0x33)//MESSAGEContentLength 00048 #define NyLPC_TcHttpBasicHeaderParser_ST_MSG_CONNECTION ((NyLPC_TcHttpBasicHeaderParser_ST)0x34)//MESSAGEConnection 00049 #define NyLPC_TcHttpBasicHeaderParser_ST_MSG_TRANSFERENCODING ((NyLPC_TcHttpBasicHeaderParser_ST)0x35)//TransferEncoding 00050 #define NyLPC_TcHttpBasicHeaderParser_ST_MSG_RANGE ((NyLPC_TcHttpBasicHeaderParser_ST)0x36)//Range 00051 #define NyLPC_TcHttpBasicHeaderParser_ST_EOH ((NyLPC_TcHttpBasicHeaderParser_ST)0x7F)//終わり 00052 #define NyLPC_TcHttpBasicHeaderParser_ST_ERROR ((NyLPC_TcHttpBasicHeaderParser_ST)0x80)//終わり 00053 /* 00054 プライベート関数 00055 */ 00056 #define NyLPC_TcHttpBasicHeaderParser_ST_isError(i_v) ((i_v)==NyLPC_TcHttpBasicHeaderParser_ST_ERROR) 00057 00058 00059 00060 /** 00061 * このクラスは、Httpヘッダのパーサを定義します。 00062 */ 00063 typedef struct NyLPC_TcHttpBasicHeaderParser NyLPC_TcHttpBasicHeaderParser_t; 00064 00065 00066 /** 00067 * HTTPメソッドの定義値。 00068 */ 00069 typedef NyLPC_TUInt8 NyLPC_THttpMethodType; 00070 //HTTP STANDARD 00071 #define NyLPC_THttpMethodType_NULL ((NyLPC_THttpMethodType)0x00) 00072 #define NyLPC_THttpMethodType_GET ((NyLPC_THttpMethodType)0x01) 00073 #define NyLPC_THttpMethodType_POST ((NyLPC_THttpMethodType)0x02) 00074 #define NyLPC_THttpMethodType_HEAD ((NyLPC_THttpMethodType)0x03) 00075 //SSDP 00076 #define NyLPC_THttpMethodType_M_SEARCH ((NyLPC_THttpMethodType)0x11) 00077 #define NyLPC_THttpMethodType_NOTIFY ((NyLPC_THttpMethodType)0x12) 00078 00079 const char* NyLPC_THttpMethodType_toString(NyLPC_THttpMethodType i_method); 00080 00081 /** 00082 * HTTPバージョンの定義値 00083 */ 00084 typedef NyLPC_TUInt8 NyLPC_THttpVersion; 00085 #define NyLPC_THttpVersion_09 ((NyLPC_THttpVersion)0x01) 00086 #define NyLPC_THttpVersion_10 ((NyLPC_THttpVersion)0x02) 00087 #define NyLPC_THttpVersion_11 ((NyLPC_THttpVersion)0x03) 00088 #define NyLPC_THttpVersion_UNKNOWN ((NyLPC_THttpVersion)0x04) 00089 00090 00091 typedef NyLPC_TUInt8 NyLPC_THttpHeaderType; 00092 #define NyLPC_THttpHeaderType_REQUEST ((NyLPC_THttpHeaderType)0x01) 00093 #define NyLPC_THttpHeaderType_RESPONSE ((NyLPC_THttpHeaderType)0x02) 00094 00095 00096 typedef NyLPC_TUInt8 NyLPC_THttpMessgeHeader_Connection; 00097 #define NyLPC_THttpMessgeHeader_Connection_NONE ((NyLPC_THttpMessgeHeader_Connection)0x01) 00098 #define NyLPC_THttpMessgeHeader_Connection_CLOSE ((NyLPC_THttpMessgeHeader_Connection)0x02) 00099 #define NyLPC_THttpMessgeHeader_Connection_KEEPALIVE ((NyLPC_THttpMessgeHeader_Connection)0x03) 00100 #define NyLPC_THttpMessgeHeader_Connection_UPGRADE ((NyLPC_THttpMessgeHeader_Connection)0x04) 00101 #define NyLPC_THttpMessgeHeader_Connection_UNKNOWN ((NyLPC_THttpMessgeHeader_Connection)0x10) 00102 00103 typedef NyLPC_TUInt8 NyLPC_THttpMessgeHeader_TransferEncoding; 00104 #define NyLPC_THttpMessgeHeader_TransferEncoding_NONE ((NyLPC_THttpMessgeHeader_TransferEncoding)0x01) //TEはない 00105 #define NyLPC_THttpMessgeHeader_TransferEncoding_CHUNKED ((NyLPC_THttpMessgeHeader_TransferEncoding)0x02) 00106 #define NyLPC_THttpMessgeHeader_TransferEncoding_UNKNOWN ((NyLPC_THttpMessgeHeader_TransferEncoding)0x10) 00107 00108 #define NyLPC_THttpContentLength_INVALID_LENGTH 0xFFFFFFFF 00109 00110 00111 00112 00113 00114 /** 00115 * この構造体は、NyLPC_cHttpBasicHeaderParserの結果を格納します。 00116 */ 00117 struct NyLPC_THttpBasicHeader 00118 { 00119 NyLPC_THttpMessgeHeader_TransferEncoding transfer_encoding; 00120 NyLPC_THttpMessgeHeader_Connection connection; 00121 NyLPC_THttpHeaderType type; 00122 NyLPC_TUInt8 _padding; 00123 union{ 00124 struct{ 00125 NyLPC_THttpVersion version; 00126 NyLPC_THttpMethodType method; 00127 }req; 00128 struct{ 00129 NyLPC_THttpVersion version; 00130 NyLPC_TUInt32 status; 00131 }res; 00132 }startline; 00133 NyLPC_TUInt32 content_length; 00134 }; 00135 00136 /** 00137 * このヘッダが持続性接続を求めているか判定します。 00138 */ 00139 NyLPC_TBool NyLPC_THttpBasicHeader_isPersistent(const struct NyLPC_THttpBasicHeader* i_struct); 00140 00141 00142 00143 00144 00145 00146 /** 00147 * コンフィギュレーション値。 00148 * ショートパラメータ解析バッファのサイズ 00149 */ 00150 #define NyLPC_cHttpBasicHeaderParser_SIZE_OF_WBS 32 00151 00152 00153 00154 00155 /** 00156 * 独自のメッセージフィールドを受け取るイベントハンドラです。 00157 * メッセージハンドラはNyLPC_cHttpBasicHeaderParserから3種類のメッセージを受け取ります。 00158 * ハンドラは、NyLPC_TcHttpBasicHeaderParserが処理しないメッセージヘッダをパース中に、次の順番で呼び出されます。 00159 * <ol> 00160 * <li>開始メッセージ - i_nameに有効な文字列を指定して、そのフィールド値が入力される事を伝えます。i_cはnullです。 00161 * <li>フィールドメッセージ - i_nameにNULL,i_cに\0以外の文字を指定して、フィールド値が入力されている事を指示します。 00162 * <li>フィールドエンド - i_nameにNULL,i_cに0を指定して、フィールドが完了した事を指示します。 00163 * </ol> 00164 */ 00165 typedef NyLPC_TBool (*NyLPC_cHttpBasicHeaderParser_messageHandler) (NyLPC_TcHttpBasicHeaderParser_t* i_inst,const NyLPC_TChar* i_name,NyLPC_TChar i_c,struct NyLPC_THttpBasicHeader* o_out); 00166 /** 00167 * リクエストのURL文字列を受け取るイベントハンドラです。 00168 * メッセージハンドラはNyLPC_cHttpBasicHeaderParserから3種類のメッセージを受け取ります。 00169 * ハンドラは、NyLPC_TcHttpBasicHeaderParserが処理しないメッセージヘッダをパース中に、次の順番で呼び出されます。 00170 * <ol> 00171 * <li>URLメッセージ - i_cに\0以外の文字を指定して、URL値が入力されている事を指示します。 00172 * <li>URLエンド - i_cに0を指定して、URLが完了した事を指示します。 00173 * </ol> 00174 */ 00175 typedef NyLPC_TBool (*NyLPC_cHttpBasicHeaderParser_urlHandler) (NyLPC_TcHttpBasicHeaderParser_t* i_inst,NyLPC_TChar i_c,struct NyLPC_THttpBasicHeader* o_out); 00176 00177 00178 00179 /** 00180 * HTTPヘッダパーサハンドラの集合です。 00181 * ハンドラにNULL指定の場合TRUEを返したと見なします。 00182 */ 00183 struct NyLPC_TcHttpBasicHeaderParser_Handler 00184 { 00185 NyLPC_cHttpBasicHeaderParser_messageHandler messageHandler; 00186 NyLPC_cHttpBasicHeaderParser_urlHandler urlHandler; 00187 }; 00188 00189 00190 00191 /** 00192 * クラス構造体 00193 */ 00194 struct NyLPC_TcHttpBasicHeaderParser 00195 { 00196 /**継承クラスで実装すべきインタフェイス*/ 00197 const struct NyLPC_TcHttpBasicHeaderParser_Handler* _handler; 00198 NyLPC_TUInt16 _rcode;//_stがERRORの時にエラーコードを格納する。 00199 /** パースの実行状態*/ 00200 NyLPC_TcHttpBasicHeaderParser_ST _st; 00201 /**ワーク文字列*/ 00202 NyLPC_TcStr_t _wsb; 00203 /**ワーク文字列のバッファ*/ 00204 char _wsb_buf[NyLPC_cHttpBasicHeaderParser_SIZE_OF_WBS]; 00205 }; 00206 00207 00208 void NyLPC_cHttpBasicHeaderParser_initialize(NyLPC_TcHttpBasicHeaderParser_t* i_inst,const struct NyLPC_TcHttpBasicHeaderParser_Handler* i_handler); 00209 #define NyLPC_cHttpBasicHeaderParser_finalize(i_inst) 00210 00211 /** 00212 * パーサの開始処理をします。 00213 * 関数は、parseInit->parseChar[n回]->(parseStream)->parseFinishの順でコールします。 00214 * parseChar、又はparseStreamでエラーが発生した場合は、後続の関数を呼び出すことは出来ません。 00215 * parseCharでEOHに達した場合、parseCharまたはparseStreamを続けて呼ぶことは出来ません。 00216 * parseFinishはparseCharまたはparseStreamでEOHに達した場合のみ呼び出すことが出来ます。 00217 */ 00218 void NyLPC_cHttpBasicHeaderParser_parseInit(NyLPC_TcHttpBasicHeaderParser_t* i_inst,struct NyLPC_THttpBasicHeader* o_out); 00219 00220 /** 00221 * パーサの処理を閉じます。 00222 * @return 00223 * パース処理が正常に終了したかの真偽値 00224 */ 00225 NyLPC_TBool NyLPC_cHttpBasicHeaderParser_parseFinish(NyLPC_TcHttpBasicHeaderParser_t* i_inst,struct NyLPC_THttpBasicHeader* o_out); 00226 00227 /** 00228 * 文字列をパースします。 00229 * コール前にNyLPC_cHttpBasicHeaderParser_parseInitでパーサを開始してください。 00230 * @return 00231 * パースした文字数。エラーの場合-1です。 00232 * 0以上の場合、getParseStatusでパーサの状態を確認してください。 00233 */ 00234 NyLPC_TInt32 NyLPC_cHttpBasicHeaderParser_parseChar(NyLPC_TcHttpBasicHeaderParser_t* i_inst,const NyLPC_TChar* i_c,NyLPC_TInt32 i_size,struct NyLPC_THttpBasicHeader* o_out); 00235 00236 00237 /** 00238 * ストリームから読み出して、EOHに達するまでパースします。 00239 * コール前にNyLPC_cHttpBasicHeaderParser_parseInitでパーサを開始してください。 00240 * @return 00241 * 処理が正常に終了したかを返します。 00242 * TRUEの場合、ステータスはEOHに達しています。(parseFinishをコールできます。) 00243 */ 00244 NyLPC_TBool NyLPC_cHttpBasicHeaderParser_parseStream(NyLPC_TcHttpBasicHeaderParser_t* i_inst,NyLPC_TiHttpPtrStream_t* i_stream,struct NyLPC_THttpBasicHeader* o_out); 00245 00246 00247 /** 00248 * parse関数がエラーの場合に、 00249 * 候補のエラーのステータスコードを返す。 00250 */ 00251 #define NyLPC_cHttpBasicHeaderParser_getStatusCode(inst) ((inst)->_rcode) 00252 00253 #ifdef __cplusplus 00254 } 00255 #endif /* __cplusplus */ 00256 00257 #endif
Generated on Tue Jul 12 2022 15:46:15 by 1.7.2