OSDN Git Service

backup
authornyatla <nyatla@47198e57-cb75-475f-84c4-a814cd6f29e0>
Thu, 28 Feb 2013 12:27:08 +0000 (12:27 +0000)
committernyatla <nyatla@47198e57-cb75-475f-84c4-a814cd6f29e0>
Thu, 28 Feb 2013 12:27:08 +0000 (12:27 +0000)
httpdモジュール&URLプリフェッチの動作を確認。

git-svn-id: http://svn.osdn.jp/svnroot/mimic/trunk@195 47198e57-cb75-475f-84c4-a814cd6f29e0

lib/src/api/NyLPC_cHttpRequestPrefixParser.h
lib/src/api/NyLPC_cHttpdConnection.h
lib/src/api/NyLPC_cModShortUrl.h
lib/src/http/NyLPC_cHttpBasicHeaderParser.c
lib/src/http/NyLPC_cHttpShortRequestHeaderParser.c
lib/src/http/NyLPC_cHttpShortRequestHeaderParser.h
projects/example/sample.net.simplehttpd/src/sketch.c

index 13e67d2..ac0b95d 100644 (file)
@@ -31,7 +31,7 @@
 \r
 typedef struct NyLPC_TcHttpRequestPrefixParser NyLPC_TcHttpRequestPrefixParser_t;\r
 \r
-#define NyLPC_TcHttpRequestPrefixParser_MAX_URL_LEN 32\r
+#define NyLPC_TcHttpRequestPrefixParser_MAX_URL_LEN 24\r
 /**\r
  * Httpリクエストの先頭部分を取り出します。\r
  */\r
index 0d6dc24..e812fb5 100644 (file)
@@ -40,6 +40,10 @@ typedef NyLPC_TUInt8 NyLPC_TcHttpdConnection_Status;
 #define NyLPC_cHttpdConnection_ResStatus_ERROR 4\r
 \r
 \r
+/**\r
+ * Httpdのハンドラが引き渡す、HTTPDコネクションクラス。\r
+ *\r
+ */\r
 typedef struct NyLPC_TcHttpdConnection NyLPC_TcHttpdConnection_t;\r
 struct NyLPC_TcHttpdConnection\r
 {\r
index 664f740..0fa48a1 100644 (file)
@@ -44,14 +44,36 @@ struct NyLPC_TcModShortUrl
        struct NyLPC_THttpShortRequestHeader _header;\r
 };\r
 \r
+/**\r
+ * コンストラクタ。\r
+ */\r
+void NyLPC_cModShortUrl_initialize(NyLPC_TcModShortUrl_t* i_inst);\r
+void NyLPC_cModShortUrl_finalize(NyLPC_TcModShortUrl_t* i_inst);\r
+\r
+NyLPC_TBool NyLPC_cModShortUrl_parse(NyLPC_TcModShortUrl_t* i_inst,NyLPC_TcHttpdConnection_t* i_connection);\r
+\r
+/**\r
+ * basicヘッダオブジェクトを返します。\r
+ */\r
+const struct NyLPC_THttpBasicHeader* NyLPC_cModShortUrl_getHeader(const NyLPC_TcModShortUrl_t* i_inst);\r
+/**\r
+ * URLを返します。URL長は最大32文字です。\r
+ */\r
+const NyLPC_TChar* NyLPC_cModShortUrl_getPath(const NyLPC_TcModShortUrl_t* i_inst);\r
+/**\r
+ * URLが一致しているかを返します。\r
+ */\r
+NyLPC_TBool NyLPC_cModShortUrl_isEqualPath(const NyLPC_TcModShortUrl_t* i_inst,const NyLPC_TChar* i_path);\r
+\r
+/**\r
+ * Methodタイプを返します。\r
+ */\r
+NyLPC_THttpMethodType NyLPC_cModShortUrl_getMethod(const NyLPC_TcModShortUrl_t* i_inst);\r
+\r
+\r
 \r
-void NyLPC_cShortUrl_initialize(NyLPC_TcModShortUrl_t* i_inst);\r
-void NyLPC_cShortUrl_finalize(NyLPC_TcModShortUrl_t* i_inst);\r
 \r
 \r
-void NyLPC_cShortUrl_getHeader();\r
-void NyLPC_cShortUrl_getPath();\r
-void NyLPC_cShortUrl_isEqualPath();\r
 \r
 #ifdef __cplusplus\r
 }\r
index eefb287..9ab1d73 100644 (file)
@@ -197,7 +197,7 @@ NyLPC_TInt32 NyLPC_cHttpBasicHeaderParser_parseChar(NyLPC_TcHttpBasicHeaderParse
                }\r
                if(NyLPC_TcHttpBasicHeaderParser_ST_isError(i_inst->_st)){\r
                        //エラー起こしたら終了。\r
-                       return i+1;\r
+                       return i;\r
                }else if(i_inst->_st==NyLPC_TcHttpBasicHeaderParser_ST_EOH){\r
                        //ヘッダ終端なら終了。\r
                        return i+1;\r
index 683e39c..7ed5172 100644 (file)
@@ -61,11 +61,15 @@ void NyLPC_cHttpShortRequestHeaderParser_initialize(NyLPC_TcHttpShortRequestHead
        NyLPC_cHttpBasicHeaderParser_initialize(&(i_inst->super),&_handler);\r
 }\r
 \r
+void NyLPC_cHttpShortRequestHeaderParser_parseInit(NyLPC_TcHttpShortRequestHeaderParser_t* i_inst,struct NyLPC_THttpShortRequestHeader* o_out)\r
+{\r
+       i_inst->url_len=0;\r
+       NyLPC_cHttpBasicHeaderParser_parseInit(&((i_inst)->super),&((o_out)->super));\r
+}\r
+\r
 NyLPC_TBool NyLPC_cHttpShortRequestHeaderParser_parse(NyLPC_TcHttpShortRequestHeaderParser_t* i_inst,NyLPC_TcHttpStream_t* i_stream,struct NyLPC_THttpShortRequestHeader* o_out)\r
 {\r
-       NyLPC_TcHttpShortRequestHeaderParser_t* inst=(NyLPC_TcHttpShortRequestHeaderParser_t*)i_inst;\r
-       inst->url_len=0;\r
-       NyLPC_cHttpBasicHeaderParser_parseInit(&(i_inst->super),&(o_out->super));\r
+       NyLPC_cHttpShortRequestHeaderParser_parseInit(i_inst,o_out);\r
        if(!NyLPC_cHttpBasicHeaderParser_parseStream(&(i_inst->super),i_stream,&(o_out->super)))\r
        {\r
                return NyLPC_TBool_FALSE;\r
index 28abf83..93f9dc9 100644 (file)
@@ -61,7 +61,8 @@ NyLPC_TBool NyLPC_cHttpShortRequestHeaderParser_parse(NyLPC_TcHttpShortRequestHe
 \r
 /** override\r
  */\r
-#define NyLPC_cHttpShortRequestHeaderParser_parseInit(i_inst,o_out) NyLPC_cHttpBasicHeaderParser_parseInit(&((i_inst)->super),&((o_out)->super))\r
+void NyLPC_cHttpShortRequestHeaderParser_parseInit(NyLPC_TcHttpShortRequestHeaderParser_t* i_inst,struct NyLPC_THttpShortRequestHeader* o_out);\r
+\r
 \r
 /** override\r
  */\r
index 5e7aad5..7166e6b 100644 (file)
 \r
 #include "../api/NyLPC_cNet.h"\r
 #include "../api/NyLPC_cHttpd.h"\r
+#include "../api/NyLPC_cModShortUrl.h"\r
 \r
 NyLPC_TcNet_t net;\r
 struct MyHttpd{\r
        NyLPC_TcHttpd_t super;\r
 }httpd;\r
-void handler(NyLPC_TcHttpdConnection_t* i_inst)\r
+\r
+NyLPC_TcModShortUrl_t mod_surl;\r
+\r
+void handler(NyLPC_TcHttpdConnection_t* i_connection)\r
 {\r
+       NyLPC_THttpMethodType m;\r
+       NyLPC_cModShortUrl_parse(&mod_surl,i_connection);\r
+       m=NyLPC_cModShortUrl_getMethod(&mod_surl);\r
+       if(m!=NyLPC_THttpMethodType_HEAD || m!=NyLPC_THttpMethodType_GET){\r
+               NyLPC_cHttpdConnection_sendResponseHeader(i_connection,200,"text/html",NULL);\r
+       }\r
+       if(m==NyLPC_THttpMethodType_GET){\r
+               NyLPC_cHttpdConnection_sendResponseBodyF(i_connection,"<html><body>");\r
+               NyLPC_cHttpdConnection_sendResponseBodyF(i_connection,"your request is %s",NyLPC_cModShortUrl_getPath(&mod_surl));\r
+\r
+               NyLPC_cHttpdConnection_sendResponseBodyF(i_connection,"</body></html>");\r
+       }\r
        return;\r
 }\r
 void setup(void)\r
@@ -25,6 +41,7 @@ void setup(void)
        NyLPC_cNet_initialize(&net);\r
        NyLPC_cHttpd_initialize(&httpd.super,80);\r
        httpd.super.function._handler=handler;\r
+       NyLPC_cModShortUrl_initialize(&mod_surl);\r
 }\r
 \r
 \r