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
NyLPC_cHttpRequestPrefixParser.c
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 #include "NyLPC_cHttpRequestPrefixParser.h" 00027 00028 00029 00030 00031 struct THttpHeaderPrefix{ 00032 struct NyLPC_THttpBasicHeader super; 00033 /** URL蓄積用のオブジェクト*/ 00034 NyLPC_TcStr_t surl; 00035 /** コールバック関数の成功/失敗を判定するフラグ*/ 00036 NyLPC_TBool status; 00037 }; 00038 00039 00040 00041 const NyLPC_TChar* NyLPC_cHttpRequestPrefixParser_getUrlPrefix(const NyLPC_TcHttpRequestPrefixParser_t* i_inst) 00042 { 00043 return i_inst->_url; 00044 } 00045 /** 00046 * URLハンドラ。 00047 * 規定文字数のPathを入力されるか、Pathが終了するまで文字列を蓄積する。 00048 */ 00049 static NyLPC_TBool urlHandler(NyLPC_TcHttpBasicHeaderParser_t* i_inst,NyLPC_TChar i_c,struct NyLPC_THttpBasicHeader* o_out) 00050 { 00051 struct THttpHeaderPrefix* s=(struct THttpHeaderPrefix*)o_out; 00052 00053 //終端なら終わらせる。 00054 if(i_c=='\0'){ 00055 s->status=NyLPC_TBool_TRUE; 00056 return NyLPC_TBool_FALSE; 00057 } 00058 //容量がいっぱい->解析を終わらせる。 00059 if(NyLPC_cStr_capacity(&(s->surl))<1) 00060 { 00061 s->status=NyLPC_TBool_TRUE; 00062 return NyLPC_TBool_FALSE; 00063 } 00064 NyLPC_cStr_put(&(s->surl),i_c); 00065 return NyLPC_TBool_TRUE; 00066 } 00067 /** 00068 * デフォルトハンドラ 00069 */ 00070 static const struct NyLPC_TcHttpBasicHeaderParser_Handler _handler= 00071 { 00072 NULL, 00073 urlHandler 00074 }; 00075 void NyLPC_cHttpRequestPrefixParser_initialize(NyLPC_TcHttpRequestPrefixParser_t* i_inst) 00076 { 00077 return; 00078 } 00079 00080 NyLPC_TBool NyLPC_cHttpRequestPrefixParser_parse(NyLPC_TcHttpRequestPrefixParser_t* i_inst,NyLPC_TiHttpPtrStream_t* i_stream) 00081 { 00082 struct THttpHeaderPrefix hout; 00083 NyLPC_TcHttpBasicHeaderParser_t parser; 00084 NyLPC_cStr_initialize(&hout.surl,i_inst->_url,NyLPC_TcHttpRequestPrefixParser_MAX_URL_LEN); 00085 hout.status=NyLPC_TBool_FALSE; 00086 NyLPC_cHttpBasicHeaderParser_initialize(&parser,&_handler); 00087 NyLPC_cHttpBasicHeaderParser_parseInit(&parser,&hout.super); 00088 NyLPC_cHttpBasicHeaderParser_parseStream(&parser,i_stream,&hout.super);//どの道エラー 00089 NyLPC_cHttpBasicHeaderParser_parseFinish(&parser,&hout.super);//どの道エラー 00090 if(!hout.status){ 00091 NyLPC_OnErrorGoto(Error); 00092 } 00093 //Errorで帰ってくるのでparsefinishは不要 00094 //NyLPC_cHttpBasicHeaderParser_parseFinish(&parser,&hout.super); 00095 i_inst->method=hout.super.startline.req.method; 00096 NyLPC_cHttpBasicHeaderParser_finalize(&parser); 00097 //この時点では、メソッドとURLの一部がパースされているはず。 00098 NyLPC_cStr_finalize(&hout.surl); 00099 //フラグをチェックして返す。 00100 return NyLPC_TBool_TRUE; 00101 Error: 00102 NyLPC_cHttpBasicHeaderParser_finalize(&parser); 00103 NyLPC_cStr_finalize(&hout.surl); 00104 return NyLPC_TBool_FALSE; 00105 } 00106 00107 00108 00109 00110 00111
Generated on Tue Jul 12 2022 16:22:57 by
