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

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

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers NyLPC_cHttpdUtils.c Source File

NyLPC_cHttpdUtils.c

00001 /*
00002  * NyLPC_cHttpModUtils_protected.c
00003  *
00004  *  Created on: 2013/03/05
00005  *      Author: nyatla
00006  */
00007 #include "NyLPC_cHttpdUtils.h"
00008 #include "NyLPC_cHttpdConnection_protected.h"
00009 
00010 
00011 
00012 NyLPC_TBool NyLPC_cHttpdUtils_sendFixedContentBatch(NyLPC_TcHttpdConnection_t* i_connection,const NyLPC_TChar* i_content_type,const NyLPC_TChar* i_content,NyLPC_TUInt32 i_size)
00013 {
00014     //HEAD or GET
00015     switch(NyLPC_cHttpdConnection_getMethod(i_connection))
00016     {
00017     case NyLPC_THttpMethodType_HEAD:
00018         //HTTP Header
00019         NyLPC_cHttpdConnection_sendResponseHeader2(i_connection,200,i_content_type,i_size,NULL);
00020         break;
00021     case NyLPC_THttpMethodType_GET:
00022         //HTTP Header
00023         NyLPC_cHttpdConnection_sendResponseHeader2(i_connection,200,i_content_type,i_size,NULL);
00024         //HTTP Body
00025         NyLPC_cHttpdConnection_sendResponseBody(i_connection,i_content,i_size);
00026         break;
00027     default:
00028         //ERROR 405
00029         NyLPC_cHttpdConnection_sendResponseHeader2(i_connection,405,"text/html",0,NULL);
00030         return NyLPC_TBool_FALSE;
00031     }
00032     return NyLPC_TBool_TRUE;
00033 }
00034 
00035 void NyLPC_cHttpdUtils_sendErrorResponse(NyLPC_TcHttpdConnection_t* i_connection,int i_status)
00036 {
00037     NyLPC_TUInt8 mt=NyLPC_cHttpdConnection_getMethod(i_connection);
00038     //ConnectionをCLOSEへセット
00039     NyLPC_cHttpdConnection_setConnectionMode(i_connection,NyLPC_TcHttpdConnection_CONNECTION_MODE_CLOSE);
00040     NyLPC_cHttpdConnection_sendResponseHeader(i_connection,i_status,"text/html",NULL);
00041     if(mt!=NyLPC_THttpMethodType_HEAD){
00042         NyLPC_cHttpdConnection_sendResponseBodyF(i_connection,"<!DOCTYPE html><html><head><title>MiMicHTTPD</title></head><body>Status %d</body></html>",i_status);
00043     }
00044 }
00045 
00046 
00047 
00048 /**
00049  * 標準的なJsonヘッダを送信する。
00050  */
00051 NyLPC_TBool NyLPC_cHttpdUtils_sendJsonHeader(NyLPC_TcHttpdConnection_t* i_connection)
00052 {
00053     const static char* additional_header=
00054         "Access-Control-Allow-Origin:*\r\n"
00055         "Pragma: no-cache\r\n"
00056         "Cache-Control: no-cache\r\n";
00057     const static char* content_type="application/json";
00058     return NyLPC_cHttpdConnection_sendResponseHeader(i_connection,200,content_type,additional_header);
00059 }
00060