This is Webservice SDK for mbed. LPCXpresso1769/LPC1768/FRDM-K64F/LPC4088

Dependents:   MbedFileServer_1768MiniDK2 RedWireBridge IssueDebug_gcc MiMicRemoteMCU-for-Mbed ... more

libMiMic(MiMic library for mbed)は、WebService機能を提供するSDKです。 mbedでWebAPIに対応したネットワークデバイスを簡単に作ることが出来ます。

libMiMicはMiMic projectで開発しています。MiMic projectについてはこちらをご覧ください。 http://nyatla.jp/mimic/wp/

構成

libMiMicはmbedRTOS上で動作し、ユーザアプリケーションにAPIを提供します。コアAPIはC言語で記述されていますが、使用頻度の高いものについてはmbed向けのC++APIが準備されています。

/media/uploads/nyatla/libmimic-sdk.png

※libMiMicはmbedの標準イーサネットドライバをしようしていません。

標準イーサネットドライバと同時に使用することはできません。

  • MiMicIP - IPv4スタックです。レテンシとメモリ消費量を抑えたuipベースのライブラリです。
  • ARP/ICMP/UDP/TCP - 基礎的なソケットAPIを提供します。APIは独自です。
  • HTTP/1.1 Server - HTTP/1.1に対応したサーバです。マルチセッション・Chunked・持続性接続に対応しています。
  • HTTP Modules - HTTP/1.1の機能モジュールです。以下のモジュールがあります。
    • ROM file provider - ROMに格納したファイルイメージを公開します。
    • File system provider - mbedファイルシステムを公開します。
    • Onchip configuration - プログラムフラッシュを利用して設定を保存します。
    • MiMicVM processor - RPCリクエスト(MiMicVM)を処理します。
    • FileUpload - ファイルアップロードを受け取ります。
    • URL decoder - HTTPリクエストを解析します。
    • UPnP handler -UPnPメッセージを処理します。
    • WebSocket - Websocketサーバです。
  • mDNS - マルチキャストDNSサービスです。
  • UPnP - UPnP/1.0の機能を提供します。UPnP handlerと協調して動作します。(現在はデバイス探索(SSDP)・デスクリプション(Description)のみ実装してあります。)
  • DHCP/APIPA - ゼロコンフィギュレーション用のモジュールです。
  • HTTP/1.1 Client
  • mbed C++ class library - mbed向けのC++CPIです。C言語のものより簡単です。

対応機種

  • mbed(mbed LPC1768)
  • LPCXpresso1769

プログラム

Import programMiMicRemoteMCU-for-Mbed

MiMic RemoteMCU for mbed. This program provides MCU control API over REST API. It can control MCU from Javascript,PHP or any HTTP rest client directly. And, The application has self development environment.

Import programMbedFileServer

The program publishes files at local directory and SD filesystem. It is a full-fledged webServer somewhat.

サンプル

Import programMiMicSimpleHttpd

This is a simplest HTTP server made ​​of libMiMic. It will echo back a request path.

Import programUPnPBasicDevice

Simplest UPnP basic device example. This program to run UPnP basic device on the mbed.

Import programWebSocketSample

MiMicSDK Websocket module sample program.

Import programHttpClientSamlpe

A http client sample program.

Import programTcpSocketClientSamlpe

MiMicSDK Tcp client socket sample program.

Import programUdpSocketSamlpe

Udp socket sample program. This program will send back the received packet.

チュートリアル

English

libMiMic(MiMic library for mbed) is SDK which provides Webservice functions. It can be created networking device easily using mbed.

See more MiMic information, See MiMic project website. http://nyatla.jp/mimic/wp/

Structure

libMiMic run on mbed RTOS and provides networking API to user application. This library has C++ class API for the mbed, and low-level C language API.

/media/uploads/nyatla/libmimic-sdk.png

For WebService general, it can be written in a simple C + + API.

libMiMic does not have the standard Ethernet driver of mbed. It is not possible that will be used with the standard Ethernet driver.

  • MiMicIP - IPv4 protocol stack. This is based uip which is reduced memory and latency.
  • ARP / ICMP / UDP / TCP - Those are provide basic IP protocols.
  • HTTP/1.1 Server - The Http server compatible HTTP/1.1. It supports multi-session, chunked transport, persistent connection.
  • HTTP Modules - There are addon-module for HTTP server. The following modules.
    • ROM file module - Publish the file images in ROM.
    • File system module - Publish thefiles in mbed file system.
    • Onchip configuration module - To save the network settings to the program flash via REST.
    • MiMicVM module - To handle the (MiMicVM) RPC request.
    • FileUpload module - Accept a file via HTTP POST.
    • URL dedoce module - A versatility URL decoder.
    • UPnP handle module - To handle UPnP messages.
    • UPnP - This provides UPnP/1.0 device functions. It works together with UPnP handler.
    • Websocket - websocket (version13) server
  • mDNS Service - DNS-SD protocol server.
  • UPnP - This provides UPnP/1.0 device functions which works with UPnP handler. (You have been implemented (SSDP) ? description only (Description) device search now.) It is a module zero configuration for - DHCP / APIPA. mbed C + + class library - C of mbed for + + is the CPI. It is simple than that of the C language.
  • DHCP/APIPA - It support zero-cpnfigulation.
  • mbed C++ class library. Almost APIs for Web applications are available.
  • HTTP/1.1 Client

Supported target

  • mbed(mbed LPC1768)
  • LPCXpresso1769

Application

Import programMiMicRemoteMCU-for-Mbed

MiMic RemoteMCU for mbed. This program provides MCU control API over REST API. It can control MCU from Javascript,PHP or any HTTP rest client directly. And, The application has self development environment.

Import programMbedFileServer

The program publishes files at local directory and SD filesystem. It is a full-fledged webServer somewhat.

Sample

Import programMiMicSimpleHttpd

This is a simplest HTTP server made ​​of libMiMic. It will echo back a request path.

Import programUPnPBasicDevice

Simplest UPnP basic device example. This program to run UPnP basic device on the mbed.

Import programWebSocketSample

MiMicSDK Websocket module sample program.

Import programHttpClientSamlpe

A http client sample program.

Import programTcpSocketClientSamlpe

MiMicSDK Tcp client socket sample program.

Import programUdpSocketSamlpe

Udp socket sample program. This program will send back the received packet.

Tutorial

Committer:
nyatla
Date:
Fri Sep 13 06:38:16 2013 +0000
Revision:
57:bc4330dfa62f
Parent:
48:00d211aac2ec
update mimic core r329;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nyatla 41:2389bd6b6f74 1 /*********************************************************************************
nyatla 41:2389bd6b6f74 2 * PROJECT: MiMic
nyatla 41:2389bd6b6f74 3 * --------------------------------------------------------------------------------
nyatla 41:2389bd6b6f74 4 *
nyatla 41:2389bd6b6f74 5 * This file is part of MiMic
nyatla 41:2389bd6b6f74 6 * Copyright (C)2011 Ryo Iizuka
nyatla 41:2389bd6b6f74 7 *
nyatla 41:2389bd6b6f74 8 * MiMic is free software: you can redistribute it and/or modify
nyatla 41:2389bd6b6f74 9 * it under the terms of the GNU Lesser General Public License as published
nyatla 41:2389bd6b6f74 10 * by the Free Software Foundation, either version 3 of the License, or
nyatla 41:2389bd6b6f74 11 * (at your option) any later version.
nyatla 41:2389bd6b6f74 12 *
nyatla 41:2389bd6b6f74 13 * This program is distributed in the hope that it will be useful,
nyatla 41:2389bd6b6f74 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nyatla 41:2389bd6b6f74 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
nyatla 41:2389bd6b6f74 16 * GNU General Public License for more details.
nyatla 41:2389bd6b6f74 17 *
nyatla 41:2389bd6b6f74 18 * You should have received a copy of the GNU Lesser General Public License
nyatla 41:2389bd6b6f74 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
nyatla 41:2389bd6b6f74 20 *
nyatla 41:2389bd6b6f74 21 * For further information please contact.
nyatla 41:2389bd6b6f74 22 * http://nyatla.jp/
nyatla 41:2389bd6b6f74 23 * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
nyatla 41:2389bd6b6f74 24 *
nyatla 41:2389bd6b6f74 25 *********************************************************************************/
nyatla 41:2389bd6b6f74 26 #include "NyLPC_cModFileIoBaseClass.h"
nyatla 41:2389bd6b6f74 27 #include "NyLPC_stdlib.h"
nyatla 41:2389bd6b6f74 28 #include "NyLPC_http.h"
nyatla 41:2389bd6b6f74 29 #include "../NyLPC_cHttpdConnection_protected.h"
nyatla 41:2389bd6b6f74 30 #include "../NyLPC_cHttpdUtils.h"
nyatla 41:2389bd6b6f74 31 #include "NyLPC_net.h"
nyatla 41:2389bd6b6f74 32
nyatla 41:2389bd6b6f74 33 #define FNAME_MAX 48
nyatla 41:2389bd6b6f74 34 #define STRBUF_MAX 48
nyatla 41:2389bd6b6f74 35
nyatla 41:2389bd6b6f74 36 struct TModFileIoHeader
nyatla 41:2389bd6b6f74 37 {
nyatla 41:2389bd6b6f74 38 struct NyLPC_THttpBasicHeader super;
nyatla 42:f83aa17dcae5 39 NyLPC_TcUrlEncode_t urlencode;
nyatla 41:2389bd6b6f74 40 NyLPC_TUInt8 _content_id;
nyatla 41:2389bd6b6f74 41 //解析用
nyatla 41:2389bd6b6f74 42 NyLPC_TUInt8 _qery_name_id;
nyatla 41:2389bd6b6f74 43 NyLPC_TUInt8 _astate;
nyatla 41:2389bd6b6f74 44 NyLPC_TInt16 _prefix_len;
nyatla 41:2389bd6b6f74 45 NyLPC_TcStr_t _tstr;
nyatla 41:2389bd6b6f74 46 NyLPC_TChar _tstr_buf[STRBUF_MAX];
nyatla 41:2389bd6b6f74 47 /** 文字列のパーサ*/
nyatla 41:2389bd6b6f74 48 char fname[FNAME_MAX];//対象ファイル名の格納先
nyatla 41:2389bd6b6f74 49 };
nyatla 41:2389bd6b6f74 50
nyatla 41:2389bd6b6f74 51 #define ST_PARSE_PATH 1
nyatla 41:2389bd6b6f74 52 #define ST_PARSE_QUERY_NAME 2
nyatla 41:2389bd6b6f74 53 #define ST_PARSE_QUERY_VALUE 3 //Query読み出し中
nyatla 41:2389bd6b6f74 54 #define ST_PARSE_QUERY_VALUE_NAME 4
nyatla 41:2389bd6b6f74 55 /**
nyatla 41:2389bd6b6f74 56 * コンテンツID定義(コンテンツ名に対応)
nyatla 41:2389bd6b6f74 57 */
nyatla 41:2389bd6b6f74 58 #define CONTENT_ID_UPLOAD 2
nyatla 41:2389bd6b6f74 59 #define CONTENT_ID_CREATE 3
nyatla 41:2389bd6b6f74 60 #define CONTENT_ID_REMOVE 4
nyatla 41:2389bd6b6f74 61 #define CONTENT_ID_UNKNOWN 0
nyatla 41:2389bd6b6f74 62
nyatla 41:2389bd6b6f74 63
nyatla 41:2389bd6b6f74 64 #define QNAME_ID_NAME 1
nyatla 41:2389bd6b6f74 65 #define QNAME_ID_UNKNOWN 0
nyatla 41:2389bd6b6f74 66
nyatla 41:2389bd6b6f74 67
nyatla 41:2389bd6b6f74 68 static const struct NyLPC_TTextIdTbl url_tbl[]=
nyatla 41:2389bd6b6f74 69 {
nyatla 41:2389bd6b6f74 70 {"upload.api",CONTENT_ID_UPLOAD},
nyatla 41:2389bd6b6f74 71 {"create.api",CONTENT_ID_CREATE},
nyatla 41:2389bd6b6f74 72 {"remove.api",CONTENT_ID_REMOVE},
nyatla 41:2389bd6b6f74 73 {NULL,CONTENT_ID_UNKNOWN}
nyatla 41:2389bd6b6f74 74 };
nyatla 41:2389bd6b6f74 75
nyatla 41:2389bd6b6f74 76 static const struct NyLPC_TTextIdTbl qname_id_table[]=
nyatla 41:2389bd6b6f74 77 {
nyatla 41:2389bd6b6f74 78 {"name",QNAME_ID_NAME},
nyatla 41:2389bd6b6f74 79 {NULL,QNAME_ID_UNKNOWN}
nyatla 41:2389bd6b6f74 80 };
nyatla 41:2389bd6b6f74 81
nyatla 41:2389bd6b6f74 82
nyatla 41:2389bd6b6f74 83
nyatla 41:2389bd6b6f74 84 static NyLPC_TBool urlHandler(NyLPC_TcHttpBasicHeaderParser_t* i_inst,NyLPC_TChar i_c,struct NyLPC_THttpBasicHeader* o_out)
nyatla 41:2389bd6b6f74 85 {
nyatla 41:2389bd6b6f74 86 struct TModFileIoHeader* out=(struct TModFileIoHeader*)o_out;
nyatla 42:f83aa17dcae5 87 NyLPC_TChar c;
nyatla 41:2389bd6b6f74 88 //読み飛ばし
nyatla 41:2389bd6b6f74 89 if(out->_prefix_len<0){
nyatla 41:2389bd6b6f74 90 out->_prefix_len++;
nyatla 41:2389bd6b6f74 91 return NyLPC_TBool_TRUE;//読み飛ばし
nyatla 41:2389bd6b6f74 92 }
nyatla 41:2389bd6b6f74 93 //Path解析
nyatla 41:2389bd6b6f74 94 if(out->_astate==ST_PARSE_PATH){
nyatla 41:2389bd6b6f74 95 if(i_c!='\0' && i_c!='?'){
nyatla 41:2389bd6b6f74 96 if(!NyLPC_cStr_put(&(out->_tstr),i_c)){
nyatla 41:2389bd6b6f74 97 //ERROR
nyatla 41:2389bd6b6f74 98 NyLPC_OnErrorGoto(ERROR);
nyatla 41:2389bd6b6f74 99 }
nyatla 41:2389bd6b6f74 100 }else{
nyatla 41:2389bd6b6f74 101 out->_content_id=NyLPC_TTextIdTbl_getMatchId(NyLPC_cStr_str(&(out->_tstr)),url_tbl);
nyatla 41:2389bd6b6f74 102 switch(out->_content_id)
nyatla 41:2389bd6b6f74 103 {
nyatla 41:2389bd6b6f74 104 case CONTENT_ID_UPLOAD:
nyatla 41:2389bd6b6f74 105 case CONTENT_ID_CREATE:
nyatla 41:2389bd6b6f74 106 case CONTENT_ID_REMOVE:
nyatla 41:2389bd6b6f74 107 break;
nyatla 41:2389bd6b6f74 108 default:
nyatla 41:2389bd6b6f74 109 NyLPC_OnErrorGoto(ERROR);
nyatla 41:2389bd6b6f74 110 }
nyatla 41:2389bd6b6f74 111 NyLPC_cStr_clear(&(out->_tstr));
nyatla 41:2389bd6b6f74 112 out->_astate=ST_PARSE_QUERY_NAME;//クエリ名解析へ
nyatla 41:2389bd6b6f74 113 }
nyatla 41:2389bd6b6f74 114 return NyLPC_TBool_TRUE;
nyatla 41:2389bd6b6f74 115 }
nyatla 41:2389bd6b6f74 116 switch(out->_content_id)
nyatla 41:2389bd6b6f74 117 {
nyatla 41:2389bd6b6f74 118 case CONTENT_ID_UPLOAD:
nyatla 41:2389bd6b6f74 119 case CONTENT_ID_CREATE:
nyatla 41:2389bd6b6f74 120 case CONTENT_ID_REMOVE:
nyatla 41:2389bd6b6f74 121 switch(out->_astate){
nyatla 41:2389bd6b6f74 122 case ST_PARSE_QUERY_NAME:
nyatla 41:2389bd6b6f74 123 if(i_c!='\0' && i_c!='&' && i_c!='='){
nyatla 41:2389bd6b6f74 124 if(!NyLPC_cStr_put(&(out->_tstr),i_c)){
nyatla 41:2389bd6b6f74 125 NyLPC_OnErrorGoto(ERROR);
nyatla 41:2389bd6b6f74 126 }
nyatla 41:2389bd6b6f74 127 }else{
nyatla 41:2389bd6b6f74 128 //Query確定。
nyatla 41:2389bd6b6f74 129 out->_qery_name_id=NyLPC_TTextIdTbl_getMatchId(NyLPC_cStr_str(&(out->_tstr)),qname_id_table);
nyatla 41:2389bd6b6f74 130 NyLPC_cStr_clear(&(out->_tstr));
nyatla 41:2389bd6b6f74 131 //クエリ値がある場合
nyatla 41:2389bd6b6f74 132 switch(out->_qery_name_id){
nyatla 41:2389bd6b6f74 133 case QNAME_ID_NAME:
nyatla 42:f83aa17dcae5 134 NyLPC_cUrlEncode_reset(&out->urlencode);
nyatla 41:2389bd6b6f74 135 out->_astate=ST_PARSE_QUERY_VALUE_NAME;
nyatla 41:2389bd6b6f74 136 break;
nyatla 41:2389bd6b6f74 137 default:
nyatla 41:2389bd6b6f74 138 out->_astate=ST_PARSE_QUERY_VALUE;
nyatla 41:2389bd6b6f74 139 break;
nyatla 41:2389bd6b6f74 140 }
nyatla 41:2389bd6b6f74 141 }
nyatla 41:2389bd6b6f74 142 return NyLPC_TBool_TRUE;
nyatla 41:2389bd6b6f74 143 case ST_PARSE_QUERY_VALUE:
nyatla 41:2389bd6b6f74 144 //未知のクエリは無視
nyatla 41:2389bd6b6f74 145 if(i_c!='\0' && i_c!='&'){
nyatla 41:2389bd6b6f74 146 }else{
nyatla 41:2389bd6b6f74 147 //クエリ値解析完了
nyatla 41:2389bd6b6f74 148 out->_astate=ST_PARSE_QUERY_NAME;
nyatla 41:2389bd6b6f74 149 }
nyatla 41:2389bd6b6f74 150 return NyLPC_TBool_TRUE;
nyatla 41:2389bd6b6f74 151 case ST_PARSE_QUERY_VALUE_NAME:
nyatla 41:2389bd6b6f74 152 if(i_c!='\0' && i_c!='&'){
nyatla 42:f83aa17dcae5 153 //URLデコードしながら蓄積
nyatla 42:f83aa17dcae5 154 switch(NyLPC_cUrlEncode_decode(&out->urlencode,i_c,&c)){
nyatla 42:f83aa17dcae5 155 case NyLPC_TcUrlEncode_ST_NEXT:
nyatla 42:f83aa17dcae5 156 break;
nyatla 42:f83aa17dcae5 157 case NyLPC_TcUrlEncode_ST_DONE:
nyatla 42:f83aa17dcae5 158 if(!NyLPC_cStr_put(&(out->_tstr),c)){
nyatla 42:f83aa17dcae5 159 NyLPC_OnErrorGoto(ERROR);
nyatla 42:f83aa17dcae5 160 }
nyatla 42:f83aa17dcae5 161 break;
nyatla 42:f83aa17dcae5 162 default:
nyatla 41:2389bd6b6f74 163 NyLPC_OnErrorGoto(ERROR);
nyatla 41:2389bd6b6f74 164 }
nyatla 41:2389bd6b6f74 165 return NyLPC_TBool_TRUE;
nyatla 41:2389bd6b6f74 166 }else{
nyatla 41:2389bd6b6f74 167 if(NyLPC_cStr_len(&out->_tstr)<1){
nyatla 41:2389bd6b6f74 168 //ファイル名短すぎ
nyatla 41:2389bd6b6f74 169 NyLPC_OnErrorGoto(ERROR);
nyatla 41:2389bd6b6f74 170 }
nyatla 41:2389bd6b6f74 171 //ファイル名を保存
nyatla 41:2389bd6b6f74 172 strcpy(out->fname,(const char*)NyLPC_cStr_str(&out->_tstr));
nyatla 41:2389bd6b6f74 173 //終端しているなら、次のクエリへ
nyatla 41:2389bd6b6f74 174 out->_astate=ST_PARSE_QUERY_NAME;
nyatla 41:2389bd6b6f74 175 }
nyatla 41:2389bd6b6f74 176 return NyLPC_TBool_TRUE;
nyatla 41:2389bd6b6f74 177 default:
nyatla 41:2389bd6b6f74 178 break;
nyatla 41:2389bd6b6f74 179 }
nyatla 41:2389bd6b6f74 180 NyLPC_OnErrorGoto(ERROR);
nyatla 41:2389bd6b6f74 181 default:
nyatla 41:2389bd6b6f74 182 NyLPC_OnErrorGoto(ERROR);
nyatla 41:2389bd6b6f74 183 }
nyatla 41:2389bd6b6f74 184 return NyLPC_TBool_TRUE;
nyatla 41:2389bd6b6f74 185 ERROR:
nyatla 41:2389bd6b6f74 186 return NyLPC_TBool_FALSE;
nyatla 41:2389bd6b6f74 187 }
nyatla 41:2389bd6b6f74 188 /**
nyatla 41:2389bd6b6f74 189 * デフォルトハンドラ
nyatla 41:2389bd6b6f74 190 */
nyatla 41:2389bd6b6f74 191 static const struct NyLPC_TcHttpBasicHeaderParser_Handler handler=
nyatla 41:2389bd6b6f74 192 {
nyatla 48:00d211aac2ec 193 NULL,
nyatla 41:2389bd6b6f74 194 urlHandler
nyatla 41:2389bd6b6f74 195 };
nyatla 41:2389bd6b6f74 196
nyatla 41:2389bd6b6f74 197
nyatla 41:2389bd6b6f74 198 /**
nyatla 41:2389bd6b6f74 199 * コンストラクタ。
nyatla 41:2389bd6b6f74 200 */
nyatla 41:2389bd6b6f74 201 void NyLPC_cModFileIoBaseClass_initialize(NyLPC_TcModFileIoBaseClass_t* i_inst,const NyLPC_TChar* i_ref_root_path)
nyatla 41:2389bd6b6f74 202 {
nyatla 41:2389bd6b6f74 203 NyLPC_cModRomFiles_initialize(&i_inst->super,i_ref_root_path,NULL,0);
nyatla 41:2389bd6b6f74 204 }
nyatla 41:2389bd6b6f74 205 void NyLPC_cModFileIoBaseClass_finalize(NyLPC_TcModFileIoBaseClass_t* i_inst)
nyatla 41:2389bd6b6f74 206 {
nyatla 41:2389bd6b6f74 207 NyLPC_cModRomFiles_finalize(&i_inst->super);
nyatla 41:2389bd6b6f74 208 }
nyatla 41:2389bd6b6f74 209 /**
nyatla 41:2389bd6b6f74 210 * モジュールがコネクションをハンドリングできるかを返します。
nyatla 41:2389bd6b6f74 211 */
nyatla 41:2389bd6b6f74 212 NyLPC_TBool NyLPC_cModFileIoBaseClass_canHandle(NyLPC_TcModFileIoBaseClass_t* i_inst,NyLPC_TcHttpdConnection_t* i_connection)
nyatla 41:2389bd6b6f74 213 {
nyatla 41:2389bd6b6f74 214 return NyLPC_cModRomFiles_canHandle(&i_inst->super,i_connection);
nyatla 41:2389bd6b6f74 215 }
nyatla 41:2389bd6b6f74 216
nyatla 41:2389bd6b6f74 217 static struct TModFileIoHeader single_header;
nyatla 41:2389bd6b6f74 218
nyatla 41:2389bd6b6f74 219
nyatla 41:2389bd6b6f74 220 /**
nyatla 41:2389bd6b6f74 221 * モジュールを実行します。
nyatla 41:2389bd6b6f74 222 */
nyatla 41:2389bd6b6f74 223 NyLPC_TBool NyLPC_cModFileIoBaseClass_execute(NyLPC_TcModFileIoBaseClass_t* i_inst,NyLPC_TcHttpdConnection_t* i_connection)
nyatla 41:2389bd6b6f74 224 {
nyatla 41:2389bd6b6f74 225 union{
nyatla 41:2389bd6b6f74 226 NyLPC_TcHttpBasicHeaderParser_t parser;
nyatla 41:2389bd6b6f74 227 NyLPC_TcHttpBodyParser_t body_parser;
nyatla 41:2389bd6b6f74 228 }sh;
nyatla 41:2389bd6b6f74 229 NyLPC_TUInt8 method_type;
nyatla 41:2389bd6b6f74 230 //リクエストParse済へ遷移(この関数の後はModが責任を持ってリクエストを返却)
nyatla 41:2389bd6b6f74 231 NyLPC_cHttpdConnection_setReqStatusParsed(i_connection);
nyatla 41:2389bd6b6f74 232
nyatla 41:2389bd6b6f74 233 //排他ロック
nyatla 41:2389bd6b6f74 234 NyLPC_cHttpdConnection_lock(i_connection);
nyatla 41:2389bd6b6f74 235 {//parser
nyatla 41:2389bd6b6f74 236
nyatla 41:2389bd6b6f74 237 //URL解析の準備
nyatla 41:2389bd6b6f74 238 single_header._prefix_len=-((NyLPC_TInt16)strlen(i_inst->super._ref_root_path)+2);
nyatla 41:2389bd6b6f74 239 single_header._astate=ST_PARSE_PATH;
nyatla 41:2389bd6b6f74 240 single_header.fname[0]='\0';
nyatla 42:f83aa17dcae5 241 NyLPC_cUrlEncode_initialize(&single_header.urlencode);
nyatla 41:2389bd6b6f74 242 NyLPC_cStr_initialize(&single_header._tstr,single_header._tstr_buf,STRBUF_MAX);
nyatla 41:2389bd6b6f74 243
nyatla 41:2389bd6b6f74 244 NyLPC_cHttpBasicHeaderParser_initialize(&sh.parser,&handler);
nyatla 41:2389bd6b6f74 245
nyatla 41:2389bd6b6f74 246 //プリフェッチしたデータを流す
nyatla 41:2389bd6b6f74 247 NyLPC_cHttpBasicHeaderParser_parseInit(&sh.parser,&(single_header.super));
nyatla 41:2389bd6b6f74 248 NyLPC_cHttpdConnection_pushPrefetchInfo(i_connection,&sh.parser,&single_header.super);
nyatla 41:2389bd6b6f74 249 //後続をストリームから取り込む
nyatla 41:2389bd6b6f74 250 if(!NyLPC_cHttpBasicHeaderParser_parseStream(&sh.parser,NyLPC_cHttpdConnection_refStream(i_connection),&(single_header.super))){
nyatla 41:2389bd6b6f74 251 NyLPC_cHttpdUtils_sendErrorResponse(i_connection,500);
nyatla 41:2389bd6b6f74 252 NyLPC_OnErrorGoto(Error1);
nyatla 41:2389bd6b6f74 253 }
nyatla 41:2389bd6b6f74 254 if(!NyLPC_cHttpBasicHeaderParser_parseFinish(&sh.parser,&(single_header.super))){
nyatla 41:2389bd6b6f74 255 NyLPC_cHttpdUtils_sendErrorResponse(i_connection,500);
nyatla 41:2389bd6b6f74 256 NyLPC_OnErrorGoto(Error1);
nyatla 41:2389bd6b6f74 257 }
nyatla 42:f83aa17dcae5 258 //HeaderParserはここで破棄(URLEncode,cSTRも)
nyatla 41:2389bd6b6f74 259 NyLPC_cHttpBasicHeaderParser_finalize(&sh.parser);
nyatla 42:f83aa17dcae5 260 NyLPC_cUrlEncode_finalize(&single_header.urlencode);
nyatla 42:f83aa17dcae5 261 NyLPC_cStr_finalize(&single_header._tstr);
nyatla 41:2389bd6b6f74 262 }
nyatla 43:a182f2b5ff41 263 //Request::ConnectionがClose設定,又はHTTP1.1では無い場合,CLOSE
nyatla 43:a182f2b5ff41 264 if(single_header.super.connection==NyLPC_THttpMessgeHeader_Connection_CLOSE || single_header.super.startline.req.version!=NyLPC_THttpVersion_11)
nyatla 41:2389bd6b6f74 265 {
nyatla 43:a182f2b5ff41 266 NyLPC_cHttpdConnection_setConnectionMode(i_connection,NyLPC_TcHttpdConnection_CONNECTION_MODE_CLOSE);
nyatla 41:2389bd6b6f74 267 }
nyatla 41:2389bd6b6f74 268 //返答フェーズ
nyatla 41:2389bd6b6f74 269 {
nyatla 41:2389bd6b6f74 270 method_type=NyLPC_cHttpdConnection_getMethod(i_connection);
nyatla 41:2389bd6b6f74 271
nyatla 41:2389bd6b6f74 272 //CGIの実行
nyatla 41:2389bd6b6f74 273 switch(single_header._content_id)
nyatla 41:2389bd6b6f74 274 {
nyatla 41:2389bd6b6f74 275 case CONTENT_ID_UPLOAD:
nyatla 41:2389bd6b6f74 276 //ファイル名とBodyParserを通知
nyatla 42:f83aa17dcae5 277 if(method_type==NyLPC_THttpMethodType_POST)
nyatla 41:2389bd6b6f74 278 {
nyatla 42:f83aa17dcae5 279 NyLPC_cHttpdConnection_send100Continue(i_connection);
nyatla 41:2389bd6b6f74 280 NyLPC_cHttpBodyParser_initialize(&sh.body_parser);
nyatla 41:2389bd6b6f74 281 NyLPC_cHttpBodyParser_parseInit(&sh.body_parser,&single_header.super);
nyatla 41:2389bd6b6f74 282 //ハンドラ内ではparseStreamのみ実行
nyatla 41:2389bd6b6f74 283 if(!i_inst->_abstruct_function.upload(i_connection,single_header.fname,&sh.body_parser)){
nyatla 41:2389bd6b6f74 284 NyLPC_cHttpdConnection_setConnectionMode(i_connection,NyLPC_TcHttpdConnection_CONNECTION_MODE_CLOSE);
nyatla 41:2389bd6b6f74 285 }
nyatla 41:2389bd6b6f74 286 if(NyLPC_cHttpBodyParser_parseFinish(&sh.body_parser)){
nyatla 41:2389bd6b6f74 287 NyLPC_cHttpBodyParser_finalize(&sh.body_parser);
nyatla 41:2389bd6b6f74 288 NyLPC_OnErrorGoto(Error2);//エラーメッセージはハンドラ内で送られていると仮定する。
nyatla 41:2389bd6b6f74 289 }
nyatla 41:2389bd6b6f74 290 NyLPC_cHttpBodyParser_finalize(&sh.body_parser);
nyatla 41:2389bd6b6f74 291 }else{
nyatla 41:2389bd6b6f74 292 NyLPC_OnErrorGoto(Error2);
nyatla 41:2389bd6b6f74 293 }
nyatla 41:2389bd6b6f74 294 break;
nyatla 41:2389bd6b6f74 295 case CONTENT_ID_CREATE:
nyatla 41:2389bd6b6f74 296 if(method_type==NyLPC_THttpMethodType_GET || method_type==NyLPC_THttpMethodType_HEAD)
nyatla 41:2389bd6b6f74 297 {
nyatla 41:2389bd6b6f74 298 //イベント起動
nyatla 41:2389bd6b6f74 299 if(!i_inst->_abstruct_function.create(i_connection,single_header.fname)){
nyatla 41:2389bd6b6f74 300 NyLPC_cHttpdConnection_setConnectionMode(i_connection,NyLPC_TcHttpdConnection_CONNECTION_MODE_CLOSE);
nyatla 41:2389bd6b6f74 301 }
nyatla 41:2389bd6b6f74 302 break;
nyatla 41:2389bd6b6f74 303 }
nyatla 41:2389bd6b6f74 304 NyLPC_OnErrorGoto(Error2_405);
nyatla 41:2389bd6b6f74 305 case CONTENT_ID_REMOVE:
nyatla 41:2389bd6b6f74 306 //ファイル名を通知
nyatla 41:2389bd6b6f74 307 if(method_type==NyLPC_THttpMethodType_GET || method_type==NyLPC_THttpMethodType_HEAD)
nyatla 41:2389bd6b6f74 308 {
nyatla 41:2389bd6b6f74 309 //イベント起動
nyatla 41:2389bd6b6f74 310 if(!i_inst->_abstruct_function.remove(i_connection,single_header.fname)){
nyatla 41:2389bd6b6f74 311 NyLPC_cHttpdConnection_setConnectionMode(i_connection,NyLPC_TcHttpdConnection_CONNECTION_MODE_CLOSE);
nyatla 41:2389bd6b6f74 312 }
nyatla 41:2389bd6b6f74 313 break;
nyatla 41:2389bd6b6f74 314 }
nyatla 41:2389bd6b6f74 315 NyLPC_OnErrorGoto(Error2_405);
nyatla 41:2389bd6b6f74 316 default:
nyatla 41:2389bd6b6f74 317 NyLPC_cHttpdUtils_sendErrorResponse(i_connection,400);
nyatla 41:2389bd6b6f74 318 NyLPC_OnErrorGoto(Error2);
nyatla 41:2389bd6b6f74 319 }
nyatla 41:2389bd6b6f74 320 }
nyatla 41:2389bd6b6f74 321 //占有解除
nyatla 41:2389bd6b6f74 322 NyLPC_cHttpdConnection_unlock(i_connection);
nyatla 41:2389bd6b6f74 323 return NyLPC_TBool_TRUE;
nyatla 41:2389bd6b6f74 324 Error2_405:
nyatla 41:2389bd6b6f74 325 NyLPC_cHttpdUtils_sendErrorResponse(i_connection,405);
nyatla 41:2389bd6b6f74 326 Error2:
nyatla 41:2389bd6b6f74 327 //VM排他ロックの解除
nyatla 41:2389bd6b6f74 328 NyLPC_cHttpdConnection_unlock(i_connection);
nyatla 41:2389bd6b6f74 329 return NyLPC_TBool_FALSE;
nyatla 41:2389bd6b6f74 330 Error1:
nyatla 41:2389bd6b6f74 331 NyLPC_cHttpBasicHeaderParser_finalize(&parser);
nyatla 41:2389bd6b6f74 332 NyLPC_cStr_finalize(&single_header._tstr);
nyatla 42:f83aa17dcae5 333 NyLPC_cUrlEncode_finalize(&single_header.urlencode);
nyatla 41:2389bd6b6f74 334 //VM排他ロックの解除
nyatla 41:2389bd6b6f74 335 NyLPC_cHttpdConnection_unlock(i_connection);
nyatla 41:2389bd6b6f74 336 return NyLPC_TBool_FALSE;
nyatla 41:2389bd6b6f74 337 }
nyatla 41:2389bd6b6f74 338
nyatla 41:2389bd6b6f74 339