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:
Sun Jun 30 14:17:42 2013 +0000
Revision:
41:2389bd6b6f74
Child:
42:f83aa17dcae5
update core r270;

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 MVM_VERSION "ModFileIo/1.0;Json/1.0"
nyatla 41:2389bd6b6f74 34
nyatla 41:2389bd6b6f74 35 #define FNAME_MAX 48
nyatla 41:2389bd6b6f74 36 #define STRBUF_MAX 48
nyatla 41:2389bd6b6f74 37
nyatla 41:2389bd6b6f74 38 struct TModFileIoHeader
nyatla 41:2389bd6b6f74 39 {
nyatla 41:2389bd6b6f74 40 struct NyLPC_THttpBasicHeader super;
nyatla 41:2389bd6b6f74 41 NyLPC_TUInt8 _content_id;
nyatla 41:2389bd6b6f74 42 //解析用
nyatla 41:2389bd6b6f74 43 NyLPC_TUInt8 _qery_name_id;
nyatla 41:2389bd6b6f74 44 NyLPC_TUInt8 _astate;
nyatla 41:2389bd6b6f74 45 NyLPC_TInt16 _prefix_len;
nyatla 41:2389bd6b6f74 46 NyLPC_TcStr_t _tstr;
nyatla 41:2389bd6b6f74 47 NyLPC_TChar _tstr_buf[STRBUF_MAX];
nyatla 41:2389bd6b6f74 48 /** 文字列のパーサ*/
nyatla 41:2389bd6b6f74 49 char fname[FNAME_MAX];//対象ファイル名の格納先
nyatla 41:2389bd6b6f74 50 };
nyatla 41:2389bd6b6f74 51
nyatla 41:2389bd6b6f74 52
nyatla 41:2389bd6b6f74 53
nyatla 41:2389bd6b6f74 54 static NyLPC_TBool messageHandler(NyLPC_TcHttpBasicHeaderParser_t* i_inst,const NyLPC_TChar* i_name,NyLPC_TChar i_c,struct NyLPC_THttpBasicHeader* o_out)
nyatla 41:2389bd6b6f74 55 {
nyatla 41:2389bd6b6f74 56 (void)i_inst;
nyatla 41:2389bd6b6f74 57 (void)i_name;
nyatla 41:2389bd6b6f74 58 (void)i_c;
nyatla 41:2389bd6b6f74 59 return NyLPC_TBool_TRUE;
nyatla 41:2389bd6b6f74 60 }
nyatla 41:2389bd6b6f74 61
nyatla 41:2389bd6b6f74 62 #define ST_PARSE_PATH 1
nyatla 41:2389bd6b6f74 63 #define ST_PARSE_QUERY_NAME 2
nyatla 41:2389bd6b6f74 64 #define ST_PARSE_QUERY_VALUE 3 //Query読み出し中
nyatla 41:2389bd6b6f74 65 #define ST_PARSE_QUERY_VALUE_NAME 4
nyatla 41:2389bd6b6f74 66 /**
nyatla 41:2389bd6b6f74 67 * コンテンツID定義(コンテンツ名に対応)
nyatla 41:2389bd6b6f74 68 */
nyatla 41:2389bd6b6f74 69 #define CONTENT_ID_UPLOAD 2
nyatla 41:2389bd6b6f74 70 #define CONTENT_ID_CREATE 3
nyatla 41:2389bd6b6f74 71 #define CONTENT_ID_REMOVE 4
nyatla 41:2389bd6b6f74 72 #define CONTENT_ID_UNKNOWN 0
nyatla 41:2389bd6b6f74 73
nyatla 41:2389bd6b6f74 74
nyatla 41:2389bd6b6f74 75 #define QNAME_ID_NAME 1
nyatla 41:2389bd6b6f74 76 #define QNAME_ID_UNKNOWN 0
nyatla 41:2389bd6b6f74 77
nyatla 41:2389bd6b6f74 78
nyatla 41:2389bd6b6f74 79 static const struct NyLPC_TTextIdTbl url_tbl[]=
nyatla 41:2389bd6b6f74 80 {
nyatla 41:2389bd6b6f74 81 {"upload.api",CONTENT_ID_UPLOAD},
nyatla 41:2389bd6b6f74 82 {"create.api",CONTENT_ID_CREATE},
nyatla 41:2389bd6b6f74 83 {"remove.api",CONTENT_ID_REMOVE},
nyatla 41:2389bd6b6f74 84 {NULL,CONTENT_ID_UNKNOWN}
nyatla 41:2389bd6b6f74 85 };
nyatla 41:2389bd6b6f74 86
nyatla 41:2389bd6b6f74 87 static const struct NyLPC_TTextIdTbl qname_id_table[]=
nyatla 41:2389bd6b6f74 88 {
nyatla 41:2389bd6b6f74 89 {"name",QNAME_ID_NAME},
nyatla 41:2389bd6b6f74 90 {NULL,QNAME_ID_UNKNOWN}
nyatla 41:2389bd6b6f74 91 };
nyatla 41:2389bd6b6f74 92
nyatla 41:2389bd6b6f74 93
nyatla 41:2389bd6b6f74 94
nyatla 41:2389bd6b6f74 95 static NyLPC_TBool urlHandler(NyLPC_TcHttpBasicHeaderParser_t* i_inst,NyLPC_TChar i_c,struct NyLPC_THttpBasicHeader* o_out)
nyatla 41:2389bd6b6f74 96 {
nyatla 41:2389bd6b6f74 97 struct TModFileIoHeader* out=(struct TModFileIoHeader*)o_out;
nyatla 41:2389bd6b6f74 98 //読み飛ばし
nyatla 41:2389bd6b6f74 99 if(out->_prefix_len<0){
nyatla 41:2389bd6b6f74 100 out->_prefix_len++;
nyatla 41:2389bd6b6f74 101 return NyLPC_TBool_TRUE;//読み飛ばし
nyatla 41:2389bd6b6f74 102 }
nyatla 41:2389bd6b6f74 103 //Path解析
nyatla 41:2389bd6b6f74 104 if(out->_astate==ST_PARSE_PATH){
nyatla 41:2389bd6b6f74 105 if(i_c!='\0' && i_c!='?'){
nyatla 41:2389bd6b6f74 106 if(!NyLPC_cStr_put(&(out->_tstr),i_c)){
nyatla 41:2389bd6b6f74 107 //ERROR
nyatla 41:2389bd6b6f74 108 NyLPC_OnErrorGoto(ERROR);
nyatla 41:2389bd6b6f74 109 }
nyatla 41:2389bd6b6f74 110 }else{
nyatla 41:2389bd6b6f74 111 out->_content_id=NyLPC_TTextIdTbl_getMatchId(NyLPC_cStr_str(&(out->_tstr)),url_tbl);
nyatla 41:2389bd6b6f74 112 switch(out->_content_id)
nyatla 41:2389bd6b6f74 113 {
nyatla 41:2389bd6b6f74 114 case CONTENT_ID_UPLOAD:
nyatla 41:2389bd6b6f74 115 case CONTENT_ID_CREATE:
nyatla 41:2389bd6b6f74 116 case CONTENT_ID_REMOVE:
nyatla 41:2389bd6b6f74 117 break;
nyatla 41:2389bd6b6f74 118 default:
nyatla 41:2389bd6b6f74 119 NyLPC_OnErrorGoto(ERROR);
nyatla 41:2389bd6b6f74 120 }
nyatla 41:2389bd6b6f74 121 NyLPC_cStr_clear(&(out->_tstr));
nyatla 41:2389bd6b6f74 122 out->_astate=ST_PARSE_QUERY_NAME;//クエリ名解析へ
nyatla 41:2389bd6b6f74 123 }
nyatla 41:2389bd6b6f74 124 return NyLPC_TBool_TRUE;
nyatla 41:2389bd6b6f74 125 }
nyatla 41:2389bd6b6f74 126 switch(out->_content_id)
nyatla 41:2389bd6b6f74 127 {
nyatla 41:2389bd6b6f74 128 case CONTENT_ID_UPLOAD:
nyatla 41:2389bd6b6f74 129 case CONTENT_ID_CREATE:
nyatla 41:2389bd6b6f74 130 case CONTENT_ID_REMOVE:
nyatla 41:2389bd6b6f74 131 switch(out->_astate){
nyatla 41:2389bd6b6f74 132 case ST_PARSE_QUERY_NAME:
nyatla 41:2389bd6b6f74 133 if(i_c!='\0' && i_c!='&' && i_c!='='){
nyatla 41:2389bd6b6f74 134 if(!NyLPC_cStr_put(&(out->_tstr),i_c)){
nyatla 41:2389bd6b6f74 135 NyLPC_OnErrorGoto(ERROR);
nyatla 41:2389bd6b6f74 136 }
nyatla 41:2389bd6b6f74 137 }else{
nyatla 41:2389bd6b6f74 138 //Query確定。
nyatla 41:2389bd6b6f74 139 out->_qery_name_id=NyLPC_TTextIdTbl_getMatchId(NyLPC_cStr_str(&(out->_tstr)),qname_id_table);
nyatla 41:2389bd6b6f74 140 NyLPC_cStr_clear(&(out->_tstr));
nyatla 41:2389bd6b6f74 141 //クエリ値がある場合
nyatla 41:2389bd6b6f74 142 switch(out->_qery_name_id){
nyatla 41:2389bd6b6f74 143 case QNAME_ID_NAME:
nyatla 41:2389bd6b6f74 144 out->_astate=ST_PARSE_QUERY_VALUE_NAME;
nyatla 41:2389bd6b6f74 145 break;
nyatla 41:2389bd6b6f74 146 default:
nyatla 41:2389bd6b6f74 147 out->_astate=ST_PARSE_QUERY_VALUE;
nyatla 41:2389bd6b6f74 148 break;
nyatla 41:2389bd6b6f74 149 }
nyatla 41:2389bd6b6f74 150 }
nyatla 41:2389bd6b6f74 151 return NyLPC_TBool_TRUE;
nyatla 41:2389bd6b6f74 152 case ST_PARSE_QUERY_VALUE:
nyatla 41:2389bd6b6f74 153 //未知のクエリは無視
nyatla 41:2389bd6b6f74 154 if(i_c!='\0' && i_c!='&'){
nyatla 41:2389bd6b6f74 155 }else{
nyatla 41:2389bd6b6f74 156 //クエリ値解析完了
nyatla 41:2389bd6b6f74 157 out->_astate=ST_PARSE_QUERY_NAME;
nyatla 41:2389bd6b6f74 158 }
nyatla 41:2389bd6b6f74 159 return NyLPC_TBool_TRUE;
nyatla 41:2389bd6b6f74 160 case ST_PARSE_QUERY_VALUE_NAME:
nyatla 41:2389bd6b6f74 161 if(i_c!='\0' && i_c!='&'){
nyatla 41:2389bd6b6f74 162 if(!NyLPC_cStr_put(&(out->_tstr),i_c)){
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 41:2389bd6b6f74 193 messageHandler,
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 41:2389bd6b6f74 241 NyLPC_cStr_initialize(&single_header._tstr,single_header._tstr_buf,STRBUF_MAX);
nyatla 41:2389bd6b6f74 242
nyatla 41:2389bd6b6f74 243 NyLPC_cHttpBasicHeaderParser_initialize(&sh.parser,&handler);
nyatla 41:2389bd6b6f74 244
nyatla 41:2389bd6b6f74 245 //プリフェッチしたデータを流す
nyatla 41:2389bd6b6f74 246 NyLPC_cHttpBasicHeaderParser_parseInit(&sh.parser,&(single_header.super));
nyatla 41:2389bd6b6f74 247 NyLPC_cHttpdConnection_pushPrefetchInfo(i_connection,&sh.parser,&single_header.super);
nyatla 41:2389bd6b6f74 248 //後続をストリームから取り込む
nyatla 41:2389bd6b6f74 249 if(!NyLPC_cHttpBasicHeaderParser_parseStream(&sh.parser,NyLPC_cHttpdConnection_refStream(i_connection),&(single_header.super))){
nyatla 41:2389bd6b6f74 250 NyLPC_cHttpdUtils_sendErrorResponse(i_connection,500);
nyatla 41:2389bd6b6f74 251 NyLPC_OnErrorGoto(Error1);
nyatla 41:2389bd6b6f74 252 }
nyatla 41:2389bd6b6f74 253 if(!NyLPC_cHttpBasicHeaderParser_parseFinish(&sh.parser,&(single_header.super))){
nyatla 41:2389bd6b6f74 254 NyLPC_cHttpdUtils_sendErrorResponse(i_connection,500);
nyatla 41:2389bd6b6f74 255 NyLPC_OnErrorGoto(Error1);
nyatla 41:2389bd6b6f74 256 }
nyatla 41:2389bd6b6f74 257 //HeaderParserはここで破棄
nyatla 41:2389bd6b6f74 258 NyLPC_cHttpBasicHeaderParser_finalize(&sh.parser);
nyatla 41:2389bd6b6f74 259 }
nyatla 41:2389bd6b6f74 260 //Connection Modeの設定 1.1 && !closeの場合はCONTINUE
nyatla 41:2389bd6b6f74 261 if(single_header.super.connection!=NyLPC_THttpMessgeHeader_Connection_CLOSE && single_header.super.startline.req.version==NyLPC_THttpVersion_11)
nyatla 41:2389bd6b6f74 262 {
nyatla 41:2389bd6b6f74 263 NyLPC_cHttpdConnection_setConnectionMode(i_connection,NyLPC_TcHttpdConnection_CONNECTION_MODE_CONTINUE);
nyatla 41:2389bd6b6f74 264 }
nyatla 41:2389bd6b6f74 265 //返答フェーズ
nyatla 41:2389bd6b6f74 266 {
nyatla 41:2389bd6b6f74 267 method_type=NyLPC_cHttpdConnection_getMethod(i_connection);
nyatla 41:2389bd6b6f74 268
nyatla 41:2389bd6b6f74 269 //CGIの実行
nyatla 41:2389bd6b6f74 270 switch(single_header._content_id)
nyatla 41:2389bd6b6f74 271 {
nyatla 41:2389bd6b6f74 272 case CONTENT_ID_UPLOAD:
nyatla 41:2389bd6b6f74 273 //ファイル名とBodyParserを通知
nyatla 41:2389bd6b6f74 274 if(method_type==NyLPC_THttpMethodType_POST || method_type==NyLPC_THttpMethodType_HEAD)
nyatla 41:2389bd6b6f74 275 {
nyatla 41:2389bd6b6f74 276 NyLPC_cHttpBodyParser_initialize(&sh.body_parser);
nyatla 41:2389bd6b6f74 277 NyLPC_cHttpBodyParser_parseInit(&sh.body_parser,&single_header.super);
nyatla 41:2389bd6b6f74 278 //ハンドラ内ではparseStreamのみ実行
nyatla 41:2389bd6b6f74 279 if(!i_inst->_abstruct_function.upload(i_connection,single_header.fname,&sh.body_parser)){
nyatla 41:2389bd6b6f74 280 NyLPC_cHttpdConnection_setConnectionMode(i_connection,NyLPC_TcHttpdConnection_CONNECTION_MODE_CLOSE);
nyatla 41:2389bd6b6f74 281 }
nyatla 41:2389bd6b6f74 282 if(NyLPC_cHttpBodyParser_parseFinish(&sh.body_parser)){
nyatla 41:2389bd6b6f74 283 NyLPC_cHttpBodyParser_finalize(&sh.body_parser);
nyatla 41:2389bd6b6f74 284 NyLPC_OnErrorGoto(Error2);//エラーメッセージはハンドラ内で送られていると仮定する。
nyatla 41:2389bd6b6f74 285 }
nyatla 41:2389bd6b6f74 286 NyLPC_cHttpBodyParser_finalize(&sh.body_parser);
nyatla 41:2389bd6b6f74 287 }else{
nyatla 41:2389bd6b6f74 288 NyLPC_OnErrorGoto(Error2);
nyatla 41:2389bd6b6f74 289 }
nyatla 41:2389bd6b6f74 290 break;
nyatla 41:2389bd6b6f74 291 case CONTENT_ID_CREATE:
nyatla 41:2389bd6b6f74 292 if(method_type==NyLPC_THttpMethodType_GET || method_type==NyLPC_THttpMethodType_HEAD)
nyatla 41:2389bd6b6f74 293 {
nyatla 41:2389bd6b6f74 294 //イベント起動
nyatla 41:2389bd6b6f74 295 if(!i_inst->_abstruct_function.create(i_connection,single_header.fname)){
nyatla 41:2389bd6b6f74 296 NyLPC_cHttpdConnection_setConnectionMode(i_connection,NyLPC_TcHttpdConnection_CONNECTION_MODE_CLOSE);
nyatla 41:2389bd6b6f74 297 }
nyatla 41:2389bd6b6f74 298 break;
nyatla 41:2389bd6b6f74 299 }
nyatla 41:2389bd6b6f74 300 NyLPC_OnErrorGoto(Error2_405);
nyatla 41:2389bd6b6f74 301 case CONTENT_ID_REMOVE:
nyatla 41:2389bd6b6f74 302 //ファイル名を通知
nyatla 41:2389bd6b6f74 303 if(method_type==NyLPC_THttpMethodType_GET || method_type==NyLPC_THttpMethodType_HEAD)
nyatla 41:2389bd6b6f74 304 {
nyatla 41:2389bd6b6f74 305 //イベント起動
nyatla 41:2389bd6b6f74 306 if(!i_inst->_abstruct_function.remove(i_connection,single_header.fname)){
nyatla 41:2389bd6b6f74 307 NyLPC_cHttpdConnection_setConnectionMode(i_connection,NyLPC_TcHttpdConnection_CONNECTION_MODE_CLOSE);
nyatla 41:2389bd6b6f74 308 }
nyatla 41:2389bd6b6f74 309 break;
nyatla 41:2389bd6b6f74 310 }
nyatla 41:2389bd6b6f74 311 NyLPC_OnErrorGoto(Error2_405);
nyatla 41:2389bd6b6f74 312 default:
nyatla 41:2389bd6b6f74 313 NyLPC_cHttpdUtils_sendErrorResponse(i_connection,400);
nyatla 41:2389bd6b6f74 314 NyLPC_OnErrorGoto(Error2);
nyatla 41:2389bd6b6f74 315 }
nyatla 41:2389bd6b6f74 316 }
nyatla 41:2389bd6b6f74 317 NyLPC_cStr_finalize(&single_header._tstr);
nyatla 41:2389bd6b6f74 318 //占有解除
nyatla 41:2389bd6b6f74 319 NyLPC_cHttpdConnection_unlock(i_connection);
nyatla 41:2389bd6b6f74 320 return NyLPC_TBool_TRUE;
nyatla 41:2389bd6b6f74 321 Error2_405:
nyatla 41:2389bd6b6f74 322 NyLPC_cHttpdUtils_sendErrorResponse(i_connection,405);
nyatla 41:2389bd6b6f74 323 Error2:
nyatla 41:2389bd6b6f74 324 NyLPC_cStr_finalize(&single_header._tstr);
nyatla 41:2389bd6b6f74 325 //VM排他ロックの解除
nyatla 41:2389bd6b6f74 326 NyLPC_cHttpdConnection_unlock(i_connection);
nyatla 41:2389bd6b6f74 327 return NyLPC_TBool_FALSE;
nyatla 41:2389bd6b6f74 328 Error1:
nyatla 41:2389bd6b6f74 329 NyLPC_cHttpBasicHeaderParser_finalize(&parser);
nyatla 41:2389bd6b6f74 330 NyLPC_cStr_finalize(&single_header._tstr);
nyatla 41:2389bd6b6f74 331 //VM排他ロックの解除
nyatla 41:2389bd6b6f74 332 NyLPC_cHttpdConnection_unlock(i_connection);
nyatla 41:2389bd6b6f74 333 return NyLPC_TBool_FALSE;
nyatla 41:2389bd6b6f74 334 }
nyatla 41:2389bd6b6f74 335
nyatla 41:2389bd6b6f74 336