OSDN Git Service

バックアップ
authornyatla <nyatla@47198e57-cb75-475f-84c4-a814cd6f29e0>
Mon, 29 Jul 2013 11:54:40 +0000 (11:54 +0000)
committernyatla <nyatla@47198e57-cb75-475f-84c4-a814cd6f29e0>
Mon, 29 Jul 2013 11:54:40 +0000 (11:54 +0000)
TcHttpStreamからTiHttpPtrStreamへの切替
httpheaderパーサのハンドラにNULL許容を追加
NyLPC_TIntxにsigned追加
SSDPクラスの試験

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

22 files changed:
lib/src/NyLPC_stdlib.c
lib/src/http/NyLPC_cHttpBasicHeaderParser.c
lib/src/http/NyLPC_cHttpBasicHeaderParser.h
lib/src/http/NyLPC_cHttpBodyParser.c
lib/src/http/NyLPC_cHttpBodyParser.h
lib/src/http/NyLPC_cHttpBodyWriter.c
lib/src/http/NyLPC_cHttpBodyWriter.h
lib/src/http/NyLPC_cHttpHeaderWriter.c
lib/src/http/NyLPC_cHttpHeaderWriter.h
lib/src/http/NyLPC_cHttpStream.c
lib/src/http/NyLPC_cHttpStream.h
lib/src/http/NyLPC_iHttpPtrStream.h
lib/src/include/NyLPC_stdlib.h
lib/src/net/httpd/NyLPC_cHttpdConnection.c
lib/src/net/httpd/NyLPC_cHttpdConnection.h
lib/src/net/httpd/mod/NyLPC_cModFileIoBaseClass.c
lib/src/net/httpd/mod/NyLPC_cModMiMicSetting.c
lib/src/net/httpd/mod/NyLPC_cModRemoteMcu.c
lib/src/net/httpd/mod/NyLPC_cModUrl.c
lib/src/net/ssdp/NyLPC_cSsdpSocket.c [new file with mode: 0644]
lib/src/net/ssdp/NyLPC_cSsdpSocket.h [new file with mode: 0644]
lib/src/uip/NyLPC_cUdpSocket.h

index 339822a..2a5fc84 100644 (file)
@@ -119,10 +119,7 @@ NyLPC_TUInt8 NyLPC_TTextIdTbl_getMatchId(const NyLPC_TChar* i_str,const struct N
 \r
 \r
 \r
-/**\r
- * same as itoa\r
- */\r
-void NyLPC_itoa(int i_n,char* o_out,int i_digit)\r
+NyLPC_TInt16 NyLPC_itoa(int i_n,char* o_out,int i_digit)\r
 {\r
         int i, sign,v;\r
         if ((sign = i_n) < 0){\r
@@ -138,8 +135,9 @@ void NyLPC_itoa(int i_n,char* o_out,int i_digit)
         }\r
         o_out[i] = '\0';\r
         NyLPC_reverse(o_out);\r
+        return i;\r
 }\r
-void NyLPC_uitoa(int i_n,char* o_out,unsigned int i_digit)\r
+NyLPC_TInt16 NyLPC_uitoa(int i_n,char* o_out,unsigned int i_digit)\r
 {\r
         int i = 0;\r
         int v;\r
@@ -149,6 +147,7 @@ void NyLPC_uitoa(int i_n,char* o_out,unsigned int i_digit)
         }while ((i_n /= i_digit) > 0);\r
         o_out[i] = '\0';\r
         NyLPC_reverse(o_out);\r
+        return i;\r
 }\r
 \r
 void NyLPC_reverse(char* s)\r
index 490c80f..9581d5f 100644 (file)
@@ -233,7 +233,7 @@ NyLPC_TInt32 NyLPC_cHttpBasicHeaderParser_parseChar(NyLPC_TcHttpBasicHeaderParse
  * FALSE-失敗/TRUE-成功\r
  * 関数が成功した場合、NyLPC_cHttpBasicHeaderParser_parseFinishでパーサを閉じることが出来ます。\r
  */\r
-NyLPC_TBool NyLPC_cHttpBasicHeaderParser_parseStream(NyLPC_TcHttpBasicHeaderParser_t* i_inst,NyLPC_TcHttpStream_t* i_stream,struct NyLPC_THttpBasicHeader* o_out)\r
+NyLPC_TBool NyLPC_cHttpBasicHeaderParser_parseStream(NyLPC_TcHttpBasicHeaderParser_t* i_inst,NyLPC_TiHttpPtrStream_t* i_stream,struct NyLPC_THttpBasicHeader* o_out)\r
 {\r
        const char* rp_base;\r
        NyLPC_TInt32 rsize;\r
@@ -574,17 +574,21 @@ static NyLPC_TcHttpBasicHeaderParser_ST parseMessageParam(NyLPC_TcHttpBasicHeade
                return NyLPC_TcHttpBasicHeaderParser_ST_MSGPARAM;//変化なし\r
        case HTTP_LF:\r
                //メッセージフィールドの終端を通知\r
-               if(!i_inst->_handler->messageHandler(i_inst,NULL,0,o_out)){\r
-                       i_inst->_rcode=500;\r
-                       NyLPC_OnErrorGoto(Error);\r
+               if(i_inst->_handler->messageHandler!=NULL){\r
+                       if(!i_inst->_handler->messageHandler(i_inst,NULL,0,o_out)){\r
+                               i_inst->_rcode=500;\r
+                               NyLPC_OnErrorGoto(Error);\r
+                       }\r
                }\r
                NyLPC_cStr_clear(ws);\r
                return NyLPC_TcHttpBasicHeaderParser_ST_MSGHEAD;\r
        default:\r
                //メッセージフィールドの追記\r
-               if(!i_inst->_handler->messageHandler(i_inst,NULL,i_c,o_out)){\r
-                       i_inst->_rcode=500;\r
-                       NyLPC_OnErrorGoto(Error);\r
+               if(i_inst->_handler->messageHandler!=NULL){\r
+                       if(!i_inst->_handler->messageHandler(i_inst,NULL,i_c,o_out)){\r
+                               i_inst->_rcode=500;\r
+                               NyLPC_OnErrorGoto(Error);\r
+                       }\r
                }\r
                break;\r
        }\r
@@ -623,9 +627,11 @@ static NyLPC_TcHttpBasicHeaderParser_ST parseMessage1(NyLPC_TcHttpBasicHeaderPar
                        }\r
                }\r
                //メッセージフィールドの名前を通知\r
-               if(!i_inst->_handler->messageHandler(i_inst,(NyLPC_TChar*)&(i_inst->_wsb),0,o_out)){\r
-                       i_inst->_rcode=500;\r
-                       NyLPC_OnErrorGoto(Error);\r
+               if(i_inst->_handler->messageHandler!=NULL){\r
+                       if(!i_inst->_handler->messageHandler(i_inst,(NyLPC_TChar*)&(i_inst->_wsb),0,o_out)){\r
+                               i_inst->_rcode=500;\r
+                               NyLPC_OnErrorGoto(Error);\r
+                       }\r
                }\r
                //カスタムヘッダ解析へ。\r
                return NyLPC_TcHttpBasicHeaderParser_ST_MSGPARAM;\r
@@ -700,16 +706,20 @@ static NyLPC_TcHttpBasicHeaderParser_ST parseRequestUrl(NyLPC_TcHttpBasicHeaderP
        if(i_c==HTTP_SP){\r
                NyLPC_cStr_clear(&(i_inst->_wsb));\r
                //URLハンドラへ通知\r
-               if(!i_inst->_handler->urlHandler(i_inst,0,o_out)){\r
-                       i_inst->_rcode=500;\r
-                       NyLPC_OnErrorGoto(Error);\r
+               if(i_inst->_handler->urlHandler!=NULL){\r
+                       if(!i_inst->_handler->urlHandler(i_inst,0,o_out)){\r
+                               i_inst->_rcode=500;\r
+                               NyLPC_OnErrorGoto(Error);\r
+                       }\r
                }\r
                return NyLPC_TcHttpBasicHeaderParser_ST_RL_VERSION;\r
        }\r
        //URLパーサへ通知\r
-       if(!i_inst->_handler->urlHandler(i_inst,i_c,o_out)){\r
-               i_inst->_rcode=500;\r
-               NyLPC_OnErrorGoto(Error);\r
+       if(i_inst->_handler->urlHandler!=NULL){\r
+               if(!i_inst->_handler->urlHandler(i_inst,i_c,o_out)){\r
+                       i_inst->_rcode=500;\r
+                       NyLPC_OnErrorGoto(Error);\r
+               }\r
        }\r
        return NyLPC_TcHttpBasicHeaderParser_ST_RL_URL;//変化なし\r
 Error:\r
index 083e08c..9b8c834 100644 (file)
@@ -169,6 +169,10 @@ typedef NyLPC_TBool (*NyLPC_cHttpBasicHeaderParser_urlHandler) (NyLPC_TcHttpBasi
 \r
 \r
 \r
+/**\r
+ * HTTPヘッダパーサハンドラの集合です。\r
+ * ハンドラにNULL指定の場合TRUEを返したと見なします。\r
+ */\r
 struct NyLPC_TcHttpBasicHeaderParser_Handler\r
 {\r
        NyLPC_cHttpBasicHeaderParser_messageHandler messageHandler;\r
@@ -230,7 +234,7 @@ NyLPC_TInt32 NyLPC_cHttpBasicHeaderParser_parseChar(NyLPC_TcHttpBasicHeaderParse
  * 処理が正常に終了したかを返します。\r
  * TRUEの場合、ステータスはEOHに達しています。(parseFinishをコールできます。)\r
  */\r
-NyLPC_TBool NyLPC_cHttpBasicHeaderParser_parseStream(NyLPC_TcHttpBasicHeaderParser_t* i_inst,NyLPC_TcHttpStream_t* i_stream,struct NyLPC_THttpBasicHeader* o_out);\r
+NyLPC_TBool NyLPC_cHttpBasicHeaderParser_parseStream(NyLPC_TcHttpBasicHeaderParser_t* i_inst,NyLPC_TiHttpPtrStream_t* i_stream,struct NyLPC_THttpBasicHeader* o_out);\r
 \r
 \r
 /**\r
index 3ae68d1..9b63fac 100644 (file)
@@ -26,7 +26,7 @@ void NyLPC_cHttpBodyParser_finalize(NyLPC_TcHttpBodyParser_t* i_inst)
  * @return\r
  * エラーの発生状況\r
  */\r
-NyLPC_TBool NyLPC_cHttpBodyParser_parseStream(NyLPC_TcHttpBodyParser_t* i_inst,NyLPC_TcHttpStream_t* i_stream,NyLPC_TChar* i_buf,NyLPC_TInt16 i_buf_size,NyLPC_TInt16* i_out)\r
+NyLPC_TBool NyLPC_cHttpBodyParser_parseStream(NyLPC_TcHttpBodyParser_t* i_inst,NyLPC_TiHttpPtrStream_t* i_stream,NyLPC_TChar* i_buf,NyLPC_TInt16 i_buf_size,NyLPC_TInt16* i_out)\r
 {\r
        NyLPC_TcHttpBodyParser_t* inst=(NyLPC_TcHttpBodyParser_t*)i_inst;\r
        const char* rp_base;\r
index 6c978c3..c05a091 100644 (file)
@@ -36,7 +36,7 @@ void NyLPC_cHttpBodyParser_finalize(NyLPC_TcHttpBodyParser_t* i_inst);
  * @return\r
  * エラーの発生状況\r
  */\r
-NyLPC_TBool NyLPC_cHttpBodyParser_parseStream(NyLPC_TcHttpBodyParser_t* i_inst,NyLPC_TcHttpStream_t* i_stream,NyLPC_TChar* i_buf,NyLPC_TInt16 i_buf_size,NyLPC_TInt16* i_out);\r
+NyLPC_TBool NyLPC_cHttpBodyParser_parseStream(NyLPC_TcHttpBodyParser_t* i_inst,NyLPC_TiHttpPtrStream_t* i_stream,NyLPC_TChar* i_buf,NyLPC_TInt16 i_buf_size,NyLPC_TInt16* i_out);\r
 \r
 #ifdef __cplusplus\r
 }\r
index 25080a4..472e58f 100644 (file)
@@ -55,7 +55,7 @@ static NyLPC_TBool printHandler(void* i_inst,const void* i_buf,NyLPC_TUInt32 i_l
 \r
 void NyLPC_cHttpBodyWriter_initialize(NyLPC_TcHttpBodyWriter_t* i_inst,NyLPC_TcHttpStream_t* i_stream)\r
 {\r
-       i_inst->_ref_stream=i_stream;\r
+       i_inst->_ref_stream=&(i_stream->super);\r
        i_inst->_is_chunked=NyLPC_TUInt8_FALSE;\r
        i_inst->_is_error=NyLPC_TUInt8_FALSE;\r
        i_inst->_size_of_sent=0;\r
index 3e251ba..fa3efc4 100644 (file)
@@ -38,7 +38,7 @@ extern "C" {
 typedef struct NyLPC_TcHttpBodyWriter NyLPC_TcHttpBodyWriter_t;\r
 struct NyLPC_TcHttpBodyWriter\r
 {\r
-       NyLPC_TcHttpStream_t* _ref_stream;\r
+       NyLPC_TiHttpPtrStream_t* _ref_stream;\r
        NyLPC_TUInt8 _is_chunked;\r
        NyLPC_TUInt8 _is_error;\r
        NyLPC_TUInt32 _size_of_sent;\r
index a6a9901..b35eb12 100644 (file)
@@ -32,7 +32,7 @@
 /**\r
  * Httpリクエストヘッダに対応したHttpヘッダライタを構築します。\r
  */\r
-NyLPC_TBool NyLPC_cHttpHeaderWriter_initialize(NyLPC_TcHttpHeaderWriter_t* i_inst,NyLPC_TcHttpStream_t* i_ref_stream,const struct NyLPC_THttpBasicHeader* i_req_header)\r
+NyLPC_TBool NyLPC_cHttpHeaderWriter_initialize(NyLPC_TcHttpHeaderWriter_t* i_inst,NyLPC_TiHttpPtrStream_t* i_ref_stream,const struct NyLPC_THttpBasicHeader* i_req_header)\r
 {\r
        i_inst->_is_chunked=NyLPC_TUInt8_FALSE;\r
        i_inst->_content_length=0;\r
@@ -106,7 +106,7 @@ const static char* getStatusMessage(NyLPC_TUInt16 i_status)
        return NULL;\r
 }\r
 \r
-static NyLPC_TBool writeln(NyLPC_TcHttpStream_t* i_inst,const void* i_data,NyLPC_TInt16 i_length)\r
+static NyLPC_TBool writeln(NyLPC_TiHttpPtrStream_t* i_inst,const void* i_data,NyLPC_TInt16 i_length)\r
 {\r
        if(NyLPC_iHttpPtrStream_write(i_inst,i_data,i_length)){\r
                if(NyLPC_iHttpPtrStream_write(i_inst,"\r\n",2)){\r
index faa6706..ff3aed7 100644 (file)
@@ -47,7 +47,7 @@ struct NyLPC_TcHttpHeaderWriter
        NyLPC_TUInt32 _content_length;\r
        NyLPC_TUInt32 _size_of_sent;\r
 \r
-       NyLPC_TcHttpStream_t* _ref_stream;\r
+       NyLPC_TiHttpPtrStream_t* _ref_stream;\r
 };\r
 \r
 /**\r
@@ -57,7 +57,7 @@ struct NyLPC_TcHttpHeaderWriter
  * ConnectionCloseは有効です。\r
  * </p>\r
  */\r
-NyLPC_TBool NyLPC_cHttpHeaderWriter_initialize(NyLPC_TcHttpHeaderWriter_t* i_inst,NyLPC_TcHttpStream_t* i_ref_stream,const struct NyLPC_THttpBasicHeader* i_req_header);\r
+NyLPC_TBool NyLPC_cHttpHeaderWriter_initialize(NyLPC_TcHttpHeaderWriter_t* i_inst,NyLPC_TiHttpPtrStream_t* i_ref_stream,const struct NyLPC_THttpBasicHeader* i_req_header);\r
 \r
 #define NyLPC_cHttpHeaderWriter_finalize(i)\r
 \r
index 06b1950..9742409 100644 (file)
@@ -111,7 +111,7 @@ static void put_chunked_header(NyLPC_TUInt16 i_val,NyLPC_TUInt8* o_buf)
  */\r
 NyLPC_TBool NyLPC_cHttpStream_initialize(NyLPC_TcHttpStream_t* i_inst,NyLPC_TcTcpSocket_t* i_ref_sock)\r
 {\r
-       i_inst->_interface_httpptrstream=&_interface;\r
+       i_inst->super.absfunc=&_interface;\r
        i_inst->_ref_sock=i_ref_sock;\r
        i_inst->we_type=NyLPC_TiHttpPtrStream_ET_NONE;\r
        i_inst->re_type=NyLPC_TiHttpPtrStream_ET_NONE;\r
@@ -217,7 +217,7 @@ static NyLPC_TBool flush_func(void* i_inst)
 }\r
 static void setReadEncoding_func(void* i_inst,NyLPC_TiHttpPtrStream_ET i_et)\r
 {\r
-       //未実装。\r
+       //未実装。(この関数は不要?)\r
        NyLPC_Abort();\r
        return;\r
 }\r
index 21f05ae..07f48b1 100644 (file)
@@ -64,7 +64,7 @@ typedef struct NyLPC_TcHttpStream NyLPC_TcHttpStream_t;
 \r
 struct NyLPC_TcHttpStream\r
 {\r
-       const struct NyLPC_TiHttpPtrStream_TInterface* _interface_httpptrstream;\r
+       NyLPC_TiHttpPtrStream_t super;\r
        NyLPC_TcTcpSocket_t* _ref_sock;\r
        NyLPC_TUInt8* txb;//送信バッファ\r
        NyLPC_TUInt16 txb_size;//送信バッファサイズ\r
index 06ba5cd..ee9a9c0 100644 (file)
@@ -69,9 +69,13 @@ struct NyLPC_TiHttpPtrStream_TInterface
        NyLPC_TiHttpPtrStream_setReadEncoding setreadencoding;\r
        NyLPC_TiHttpPtrStream_setWriteEncoding setwriteencoding;\r
 };\r
-\r
-\r
-\r
+struct NyLPC_TiHttpPtrStream\r
+{\r
+       /**\r
+        * 継承クラスで実装すべきハンドラ\r
+        */\r
+       const struct NyLPC_TiHttpPtrStream_TInterface* absfunc;\r
+};\r
 \r
 /**\r
  * ストリームからデータを読み出して、そのポインタを返します。\r
@@ -80,7 +84,7 @@ struct NyLPC_TiHttpPtrStream_TInterface
  * 0の場合はタイムアウトです。\r
  * 0未満の場合はエラーです。\r
  */\r
-#define NyLPC_iHttpPtrStream_pread(i_inst,o_buf_ptr) (i_inst)->_interface_httpptrstream->pread((i_inst),(o_buf_ptr))\r
+#define NyLPC_iHttpPtrStream_pread(i_inst,o_buf_ptr) (i_inst)->absfunc->pread((i_inst),(o_buf_ptr))\r
 /**\r
  * ストリームへデータを書き込みます。\r
  * @param i_length\r
@@ -88,14 +92,23 @@ struct NyLPC_TiHttpPtrStream_TInterface
  * @return\r
  * 規定時間内にストリームへの書き込みが完了すると、TRUEを返します。\r
  */\r
-#define NyLPC_iHttpPtrStream_write(i_inst,i_data,i_length) (i_inst)->_interface_httpptrstream->write((i_inst),i_data,i_length)\r
-#define NyLPC_iHttpPtrStream_rseek(i_inst,i_seek) (i_inst)->_interface_httpptrstream->readSeek((i_inst),(i_seek))\r
+#define NyLPC_iHttpPtrStream_write(i_inst,i_data,i_length) (i_inst)->absfunc->write((i_inst),i_data,i_length)\r
+#define NyLPC_iHttpPtrStream_rseek(i_inst,i_seek) (i_inst)->absfunc->readSeek((i_inst),(i_seek))\r
 /**\r
  * バッファに残っているデータを送信し、空にします。\r
  */\r
-#define NyLPC_iHttpPtrStream_flush(i_inst) (i_inst)->_interface_httpptrstream->flush(i_inst)\r
-#define NyLPC_iHttpPtrStream_setReadEncoding(i_inst,i_et) (i_inst)->_interface_httpptrstream->setreadencoding((i_inst),i_et)\r
-#define NyLPC_iHttpPtrStream_setWriteEncoding(i_inst,i_et) (i_inst)->_interface_httpptrstream->setwriteencoding((i_inst),i_et)\r
+#define NyLPC_iHttpPtrStream_flush(i_inst) (i_inst)->absfunc->flush(i_inst)\r
+\r
+/**\r
+ * 読み出しエンコーディングの設定。\r
+ * この関数は削除するかもしれない。使用しないこと。\r
+ * @bug 関数が非対称。cHttpBasicBodyParserがチャンク読み出し処理を肩代わりしている?\r
+ */\r
+#define NyLPC_iHttpPtrStream_setReadEncoding(i_inst,i_et) (i_inst)->absfunc->setreadencoding((i_inst),i_et)\r
+/**\r
+ * 書込みエンコーディングの設定。\r
+ */\r
+#define NyLPC_iHttpPtrStream_setWriteEncoding(i_inst,i_et) (i_inst)->absfunc->setwriteencoding((i_inst),i_et)\r
 \r
 #ifdef __cplusplus\r
 }\r
index e02abb7..661525f 100644 (file)
@@ -193,15 +193,15 @@ typedef char NyLPC_TChar;
 /**\r
  * 符号有り8bit型です。\r
  */\r
-typedef char NyLPC_TInt8;\r
+typedef signed char NyLPC_TInt8;\r
 /**\r
  * 符号有り16bit型です。\r
  */\r
-typedef short NyLPC_TInt16;\r
+typedef signed short NyLPC_TInt16;\r
 /**\r
  * 符号有り32bit型です。\r
  */\r
-typedef long NyLPC_TInt32;\r
+typedef signed long NyLPC_TInt32;\r
 \r
 //----------------------------------------------------------------------\r
 // NyLPC_TUInt8\r
@@ -477,12 +477,17 @@ NyLPC_TUInt8 NyLPC_TTextIdTbl_getMatchId(const NyLPC_TChar* i_str,const struct N
 #define NyLPC_tolower(c) (((c) >= 'A' && (c) <= 'Z' )?((c)+'a' - 'A'):(c))\r
 \r
 /**\r
- * Same as itoa\r
+ * @return\r
+ * 書き込んだ文字列の長さ\r
  */\r
-void NyLPC_itoa(int i_n,char* o_out,int i_digit);\r
+NyLPC_TInt16 NyLPC_itoa(int i_n,char* o_out,int i_digit);\r
 \r
 \r
-void NyLPC_uitoa(int i_n,char* o_out,unsigned int i_digit);\r
+/**\r
+ * @return\r
+ * 書き込んだ文字列の長さ\r
+ */\r
+NyLPC_TInt16 NyLPC_uitoa(int i_n,char* o_out,unsigned int i_digit);\r
 \r
 \r
 /**\r
index d796714..d550f9e 100644 (file)
@@ -42,7 +42,7 @@ NyLPC_TBool NyLPC_cHttpdConnection_send100Continue(NyLPC_TcHttpdConnection_t* i_
                NyLPC_OnErrorGoto(Error_Status);\r
        }\r
        //ステータスラインの記述\r
-       if(!NyLPC_iHttpPtrStream_write(&(i_inst->_in_stream),"HTTP/1.1 100 Continue\r\n\r\n",25)){\r
+       if(!NyLPC_iHttpPtrStream_write(&(i_inst->_in_stream.super),"HTTP/1.1 100 Continue\r\n\r\n",25)){\r
                NyLPC_OnErrorGoto(Error);\r
        }\r
        return NyLPC_TBool_TRUE;\r
@@ -69,7 +69,7 @@ NyLPC_TBool NyLPC_cHttpdConnection_sendResponseHeader2(NyLPC_TcHttpdConnection_t
                NyLPC_OnErrorGoto(Error_Status);\r
        }\r
        //ヘッダ送信\r
-       if(!NyLPC_cHttpHeaderWriter_initialize(h,&(i_inst->_in_stream),NULL)){\r
+       if(!NyLPC_cHttpHeaderWriter_initialize(h,&(i_inst->_in_stream.super),NULL)){\r
                NyLPC_OnErrorGoto(ERROR_SEND);\r
        }\r
        //Headerの転送モードセット\r
@@ -166,7 +166,7 @@ Error:
 static void sendErrorResponse(NyLPC_TcHttpdConnection_t* i_inst,NyLPC_TInt16 i_status)\r
 {\r
        NyLPC_TcHttpHeaderWriter_t* h=&(i_inst->_head_writer);\r
-       if(NyLPC_cHttpHeaderWriter_initialize(h,&i_inst->_in_stream,NULL)){\r
+       if(NyLPC_cHttpHeaderWriter_initialize(h,&i_inst->_in_stream.super,NULL)){\r
                //ヘッダを送信\r
                NyLPC_cHttpHeaderWriter_setConnectionClose(h,NyLPC_TBool_TRUE);\r
                NyLPC_cHttpHeaderWriter_writeHeader(h,i_status);\r
@@ -313,7 +313,7 @@ NyLPC_TBool NyLPC_cHttpdConnection_prevNextPrefetch(NyLPC_TcHttpdConnection_t* i
                NyLPC_cHttpNullRequestHeaderParser_parseChar(&parser,"GET ",4);//決め打ち\r
                NyLPC_cHttpNullRequestHeaderParser_parseChar(&parser,i_inst->_pparser._url,strlen(i_inst->_pparser._url));\r
                //後続をストリームから取り込む\r
-               if(NyLPC_cHttpNullRequestHeaderParser_parseStream(&parser,&(i_inst->_in_stream))){\r
+               if(NyLPC_cHttpNullRequestHeaderParser_parseStream(&parser,&(i_inst->_in_stream.super))){\r
                        if(NyLPC_cHttpNullRequestHeaderParser_parseFinish(&parser)){\r
                                NyLPC_cHttpNullRequestHeaderParser_finalize(&parser);\r
                                //OK:403\r
index d390962..9e435fb 100644 (file)
@@ -136,7 +136,7 @@ void NyLPC_cHttpdConnection_unlock(NyLPC_TcHttpdConnection_t* i_inst);
 /**\r
  * コネクションのStreamを返します。\r
  */\r
-#define NyLPC_cHttpdConnection_refStream(i_inst) (&(i_inst->_in_stream))\r
+#define NyLPC_cHttpdConnection_refStream(i_inst) (&(i_inst->_in_stream.super))\r
 \r
 #define NyLPC_cHttpdConnection_getMethod(i_inst) ((i_inst)->_pparser.method)\r
 #define NyLPC_cHttpdConnection_getReqStatus(i_inst) ((i_inst)->_req_status)\r
index 84d5149..fa1c51b 100644 (file)
@@ -50,17 +50,6 @@ struct TModFileIoHeader
        char fname[FNAME_MAX];//対象ファイル名の格納先\r
 };\r
 \r
-\r
-\r
-\r
-static NyLPC_TBool messageHandler(NyLPC_TcHttpBasicHeaderParser_t* i_inst,const NyLPC_TChar* i_name,NyLPC_TChar i_c,struct NyLPC_THttpBasicHeader* o_out)\r
-{\r
-       (void)i_inst;\r
-       (void)i_name;\r
-       (void)i_c;\r
-       return NyLPC_TBool_TRUE;\r
-}\r
-\r
 #define ST_PARSE_PATH 1\r
 #define ST_PARSE_QUERY_NAME 2\r
 #define ST_PARSE_QUERY_VALUE 3         //Query読み出し中\r
@@ -203,7 +192,7 @@ ERROR:
  */\r
 static const struct NyLPC_TcHttpBasicHeaderParser_Handler handler=\r
 {\r
-       messageHandler,\r
+       NULL,\r
        urlHandler\r
 };\r
 \r
index cc7abab..f01dca6 100644 (file)
@@ -82,15 +82,6 @@ struct TModMiMicSettingRequest
        }content;\r
 };\r
 \r
-\r
-static NyLPC_TBool messageHandler(NyLPC_TcHttpBasicHeaderParser_t* i_inst,const NyLPC_TChar* i_name,NyLPC_TChar i_c,struct NyLPC_THttpBasicHeader* o_out)\r
-{\r
-       (void)i_inst;\r
-       (void)i_name;\r
-       (void)i_c;\r
-       return NyLPC_TBool_TRUE;\r
-}\r
-\r
 #define ST_PARSE_PATH 1\r
 #define ST_PARSE_QUERY_NAME 2\r
 #define ST_PARSE_QUERY_VALUE 3         //Query読み出し中\r
@@ -285,7 +276,7 @@ ERROR:
  */\r
 static const struct NyLPC_TcHttpBasicHeaderParser_Handler handler=\r
 {\r
-       messageHandler,\r
+       NULL,\r
        urlHandler\r
 };\r
 \r
index 52fecd7..4dde4c8 100644 (file)
@@ -80,13 +80,7 @@ static void mvm(NyLPC_TcHttpdConnection_t* i_connection,const struct TModMiMicRe
 static void status(NyLPC_TcHttpdConnection_t* i_connection);\r
 \r
 \r
-static NyLPC_TBool messageHandler(NyLPC_TcHttpBasicHeaderParser_t* i_inst,const NyLPC_TChar* i_name,NyLPC_TChar i_c,struct NyLPC_THttpBasicHeader* o_out)\r
-{\r
-       (void)i_inst;\r
-       (void)i_name;\r
-       (void)i_c;\r
-       return NyLPC_TBool_TRUE;\r
-}\r
+\r
 \r
 #define ST_PARSE_PATH 1\r
 #define ST_PARSE_QUERY_NAME 2\r
@@ -309,7 +303,7 @@ ERROR:
  */\r
 static const struct NyLPC_TcHttpBasicHeaderParser_Handler handler=\r
 {\r
-       messageHandler,\r
+       NULL,\r
        urlHandler\r
 };\r
 \r
index 0b71b06..cfe76bd 100644 (file)
@@ -36,17 +36,11 @@ typedef struct TcHeaderParser
        NyLPC_TInt16 length_of_buf;\r
        NyLPC_TInt16 length_of_url;\r
        NyLPC_TInt16 reason;\r
-       NyLPC_TInt8 skip;\r
-       NyLPC_TInt8 mode;\r
+       NyLPC_TUInt8 skip;\r
+       NyLPC_TUInt8 mode;\r
 }TcHeaderParser_t;\r
 \r
-static NyLPC_TBool NyLPC_cModUrl_messageHandler(NyLPC_TcHttpBasicHeaderParser_t* i_inst,const NyLPC_TChar* i_name,NyLPC_TChar i_c,struct NyLPC_THttpBasicHeader* o_out)\r
-{\r
-       (void)i_inst;\r
-       (void)i_name;\r
-       (void)i_c;\r
-       return NyLPC_TBool_TRUE;\r
-}\r
+\r
 \r
 static NyLPC_TBool NyLPC_cModUrl_urlHandler(NyLPC_TcHttpBasicHeaderParser_t* i_inst,NyLPC_TChar i_c,struct NyLPC_THttpBasicHeader* o_out)\r
 {\r
@@ -85,7 +79,7 @@ static NyLPC_TBool NyLPC_cModUrl_urlHandler(NyLPC_TcHttpBasicHeaderParser_t* i_i
  */\r
 static const struct NyLPC_TcHttpBasicHeaderParser_Handler _handler=\r
 {\r
-       NyLPC_cModUrl_messageHandler,\r
+       NULL,\r
        NyLPC_cModUrl_urlHandler\r
 };\r
 \r
diff --git a/lib/src/net/ssdp/NyLPC_cSsdpSocket.c b/lib/src/net/ssdp/NyLPC_cSsdpSocket.c
new file mode 100644 (file)
index 0000000..4c113c9
--- /dev/null
@@ -0,0 +1,531 @@
+/*********************************************************************************\r
+ * PROJECT: MiMic\r
+ * --------------------------------------------------------------------------------\r
+ *\r
+ * This file is part of MiMic\r
+ * Copyright (C)2011 Ryo Iizuka\r
+ *\r
+ * MiMic is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU Lesser General Public License as published\r
+ * by the Free Software Foundation, either version 3 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU Lesser General Public License\r
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.\r
+ *\r
+ * For further information please contact.\r
+ *     http://nyatla.jp/\r
+ *     <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>\r
+ *\r
+ *********************************************************************************/\r
+#include "NyLPC_cSsdpSocket.h"\r
+#include "NyLPC_uipService.h"\r
+#include "../uip/NyLPC_cUipService_protected.h"\r
+\r
+#include <stdio.h>\r
+#include <string.h>\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+#define PARSE_NULL  0\r
+#define PARSE_ST       0x01\r
+#define PARSE_MAN      0x11\r
+\r
+const static STR_UPNP_ROOT_DEVICE="upnp:rootdevice";\r
+\r
+struct TMSearchHeader\r
+{\r
+       struct NyLPC_THttpBasicHeader super;\r
+\r
+       const struct NyLPC_TUPnPDeviceRecord* _ref_devices;\r
+       NyLPC_TUInt16 _number_of_device;\r
+       /**\r
+        * パーサのステータス\r
+        */\r
+       NyLPC_TUInt8 st;\r
+       /**\r
+        * メモリ位置\r
+        */\r
+       const NyLPC_TChar* _rpos;\r
+       struct{\r
+               const NyLPC_TChar* st_str;\r
+               const NyLPC_TChar* man_str;\r
+               NyLPC_TUInt16 st_len;\r
+               NyLPC_TUInt16 man_len;\r
+       }result;\r
+};\r
+\r
+\r
+\r
+static NyLPC_TBool urlHandler(NyLPC_TcHttpBasicHeaderParser_t* i_inst,NyLPC_TChar i_c,struct NyLPC_THttpBasicHeader* o_out)\r
+{\r
+// *であるかを確認 未実装\r
+       return NyLPC_TBool_TRUE;\r
+}\r
+static NyLPC_TInt16 printIpAddr(const struct NyLPC_TIPv4Addr* i_ip,NyLPC_TChar* i_buf)\r
+{\r
+       NyLPC_TUInt32 ip;\r
+       NyLPC_TUInt8 v;\r
+       NyLPC_TInt8 l;\r
+       NyLPC_TChar* p=i_buf;\r
+       //IPをホストオーダーにする。\r
+       ip=NyLPC_NTOHL(i_ip->v);\r
+       for(l=3;l>=0;l--){\r
+               v=(ip>>(8*l))&0xff;\r
+               if(v<10){\r
+                       //1桁\r
+                       *(p+0)=v+'0';\r
+                       *(p+1)='.';\r
+                       p+=2;\r
+               }else if(v<100){\r
+                       //2桁\r
+                       *(p+0)=(v/10)+'0';\r
+                       *(p+1)=(v%10)+'0';\r
+                       *(p+2)='.';\r
+                       p+=3;\r
+               }else{\r
+                       //3桁\r
+                       *(p+0)=(v/100)+'0';\r
+                       *(p+1)=((v/10)%10)+'0';\r
+                       *(p+2)=(v%10)+'0';\r
+                       *(p+3)='.';\r
+                       p+=4;\r
+               }\r
+       }\r
+       return p-i_buf-1;\r
+}\r
+#define TIMEOUT_IN_MS 100\r
+\r
+/**\r
+ * SERVER MessageHeaderの値\r
+ * 40文字以内であること。\r
+ */\r
+#define SERVER_MESSAGE_HEADER "MiMic/1.4;UPnP/1.0;MiMicUPnP/0.1"\r
+\r
+\r
+/**\r
+ * MsearchResponseを格納したTxパケットをAllocする。\r
+ * @param i_st\r
+ * ST値\r
+ * @param i_udn\r
+ * DDESCのUDNの値\r
+ * @param i_usn\r
+ * USNのサフィックスパラメータ\r
+ * @return\r
+ * MsearchResponseを格納したTXメモリ\r
+ */\r
+static void* allocMsearchResponeTx(\r
+       NyLPC_TcSsdpSocket_t* i_inst,\r
+       const NyLPC_TChar* i_st,\r
+       const NyLPC_TChar* i_udn,\r
+       const NyLPC_TChar* i_usn,\r
+       NyLPC_TUInt16 i_st_len,\r
+       NyLPC_TInt16* o_len)\r
+{\r
+       NyLPC_TChar* obuf;\r
+       NyLPC_TUInt16 l;\r
+       NyLPC_TUInt16 len_usn=(NyLPC_TUInt16)strlen(i_usn);\r
+       NyLPC_TUInt16 len_udn=(NyLPC_TUInt16)(i_udn!=NULL?strlen(i_udn):0);\r
+       NyLPC_TUInt16 len_location=(NyLPC_TUInt16)strlen(i_inst->location_path);\r
+\r
+       //      //161Byte\r
+       //      "HTTP/1.1 200 OK\r\n"                                                   //15+2=17\r
+       //      "CACHE-CONTROL: max-age = 1800\r\n"                     //29+2=31\r
+       //      "SERVER: [:40byte:]\r\n"                                                //8+40+2=50\r
+       //      "EXT: \r\n"                                                                     //5+2 = 7\r
+       //      "LOCATION: http://xxx.xxx.xxx.xxx:nnnnn/%s\r\n" //39+2=41\r
+       //      "USN: %s%s\r\n"                                                                 //5+2=7\r
+       //      "ST: %s\r\n\r\n"                                                                //4+4=8\r
+       l=161+len_location+len_usn+len_udn+i_st_len;\r
+       obuf=NyLPC_cUdpSocket_allocSendBuf(&(i_inst->super),l,&l,TIMEOUT_IN_MS);\r
+       if(obuf==NULL){\r
+               return NULL;\r
+       }\r
+       //必要なメモリサイズを確保できた?\r
+       if(l<161+len_location+len_usn+len_udn+i_st_len)\r
+       {\r
+               NyLPC_cUdpSocket_releaseSendBuf(&i_inst->super,obuf);\r
+               return NULL;\r
+       }\r
+       //ワーク変数lの再初期化\r
+       l=0;\r
+       strcpy(obuf,\r
+               "HTTP/1.1 200 OK\r\n"\r
+               "CACHE-CONTROL: max-age = 120\r\n"\r
+               "SERVER: "SERVER_MESSAGE_HEADER"\r\n"\r
+               "EXT: \r\n"\r
+               "LOCATION: http://");\r
+       l+=strlen(obuf);\r
+       //IP addr:port\r\n\r
+       l+=printIpAddr(NyLPC_cUdpSocket_getSockIP(&i_inst->super),obuf+l);\r
+       *(obuf+l)=':';\r
+       l+=1+NyLPC_itoa(i_inst->location_port,obuf+l+1,10);\r
+       strcpy(obuf+l,i_inst->location_path);l+=len_location;\r
+       *(obuf+l+0)='\r';\r
+       *(obuf+l+1)='\n';\r
+       l+=2;\r
+       //USN: uuid:xxx\r
+       strcpy(obuf+l,"USN: "); l+=5;\r
+       strcpy(obuf+l,i_udn);   l+=len_udn;     //uuid:xxx\r
+       if(i_usn!=NULL){\r
+               *(obuf+l+0)=':';\r
+               *(obuf+l+1)=':';\r
+               l+=2;\r
+               strcpy(obuf+l,i_usn);l+=len_usn;        //usn:xxx\r
+       }\r
+       *(obuf+l+0)='\r';\r
+       *(obuf+l+1)='\n';\r
+       l+=2;\r
+       //ST\r
+       strcpy(obuf+l,"ST: ");  l+=3;\r
+       strcpy(obuf+l,i_st);l+=i_st_len;\r
+       strcpy(obuf+l,"\r\n\r\n");      l+=4;\r
+       *o_len=l;\r
+       return obuf;\r
+}\r
+\r
+\r
+/**\r
+ * MsearchResponseを格納したTxパケットをAllocする。\r
+ * @param i_udn\r
+ * udn\r
+ * @param i_udn\r
+ * DDESCのUDNの値\r
+ * @param i_usn\r
+ * USNのサフィックスパラメータ\r
+ * @return\r
+ * MsearchResponseを格納したTXメモリ\r
+ */\r
+static void* allocNotifyTx(\r
+       NyLPC_TcSsdpSocket_t* i_inst,\r
+       const NyLPC_TChar* i_udn,\r
+       const NyLPC_TChar* i_usn,\r
+       NyLPC_TInt16* o_len)\r
+{\r
+       NyLPC_TChar* obuf;\r
+       NyLPC_TUInt16 l,l2;\r
+       NyLPC_TUInt16 len_usn=(NyLPC_TUInt16)(i_usn!=NULL?strlen(i_usn):0);\r
+       NyLPC_TUInt16 len_udn=(NyLPC_TUInt16)strlen(i_udn);\r
+       NyLPC_TUInt16 len_location=(NyLPC_TUInt16)strlen(i_inst->location_path);\r
+\r
+       //      //193Byte\r
+       //      "NOTIFY * HTTP/1.1\r\n"                                                 //15+2=17\r
+       //      "HOST: 239.255.255.250:1900\r\n"                                //26+2=28\r
+       //      "CACHE-CONTROL: max-age = 1800\r\n"                     //29+2=31\r
+       //      "SERVER: [:40byte:]\r\n"                                                //8+40+2=50\r
+       //      "NTS:alive\r\n"                                                                 //9+2 =11\r
+       //      "LOCATION: http://xxx.xxx.xxx.xxx:nnnnn/%s\r\n" //39+2=41\r
+       //      "USN: %s%s\r\n"                                                                 //5+2=7\r
+       //      "NT: %s\r\n\r\n"                                                                //4+4=8\r
+       l2=193+len_location+len_usn+len_udn+(len_usn>0?len_usn:len_udn);\r
+       obuf=NyLPC_cUdpSocket_allocSendBuf(&(i_inst->super),l2,&l,TIMEOUT_IN_MS);\r
+       if(obuf==NULL){\r
+               return NULL;\r
+       }\r
+       //必要なメモリサイズを確保できた?\r
+       if(l<l2)\r
+       {\r
+               NyLPC_cUdpSocket_releaseSendBuf(&i_inst->super,obuf);\r
+               return NULL;\r
+       }\r
+       //ワーク変数lの再初期化\r
+       l=0;\r
+       strcpy(obuf,\r
+               "NOTIFY * HTTP/1.1\r\n"\r
+               "HOST: 239.255.255.250:1900\r\n"\r
+               "CACHE-CONTROL: max-age = 1800\r\n"\r
+               "SERVER: "SERVER_MESSAGE_HEADER"\r\n"\r
+               "NTS:alive\r\n"\r
+               "LOCATION: http://");\r
+       l+=strlen(obuf);\r
+       //IP addr:port\r\n\r
+       l+=printIpAddr(NyLPC_cUdpSocket_getSockIP(&i_inst->super),obuf+l);\r
+       *(obuf+l)=':';\r
+       l+=1+NyLPC_itoa(i_inst->location_port,obuf+l+1,10);\r
+       strcpy(obuf+l,i_inst->location_path);l+=len_location;\r
+       *(obuf+l+0)='\r';\r
+       *(obuf+l+1)='\n';\r
+       l+=2;\r
+       //USN: uuid:xxx\r
+       strcpy(obuf+l,"USN: "); l+=5;\r
+       strcpy(obuf+l,i_udn);   l+=len_udn;     //uuid:xxx\r
+       if(i_usn!=NULL){\r
+               *(obuf+l+0)=':';\r
+               *(obuf+l+1)=':';\r
+               l+=2;\r
+               strcpy(obuf+l,i_usn);l+=len_usn;        //usn:xxx\r
+       }\r
+       *(obuf+l+0)='\r';\r
+       *(obuf+l+1)='\n';\r
+       l+=2;\r
+       //NT\r
+       strcpy(obuf+l,"NT: ");  l+=4;\r
+       if(len_usn>0){\r
+               strcpy(obuf+l,i_usn);l+=len_usn;\r
+       }else{\r
+               strcpy(obuf+l,i_udn);l+=len_udn;\r
+       }\r
+       strcpy(obuf+l,"\r\n\r\n");      l+=4;\r
+       *o_len=l;\r
+       return obuf;\r
+}\r
+\r
+\r
+\r
+\r
+\r
+\r
+static NyLPC_TBool messageHandler(NyLPC_TcHttpBasicHeaderParser_t* i_inst,const NyLPC_TChar* i_name,NyLPC_TChar i_c,struct NyLPC_THttpBasicHeader* o_out)\r
+{\r
+       struct TMSearchHeader* header=(struct TMSearchHeader*)o_out;\r
+       switch(header->st)\r
+       {\r
+               case PARSE_NULL:\r
+                       if(NyLPC_stricmp(i_name,"ST")==0){\r
+                               //mode==ST\r
+                               header->st=PARSE_ST;\r
+                               header->result.st_str=header->_rpos;\r
+                       }else if(NyLPC_stricmp(i_name,"MAN")==0){\r
+                               //mode=MAN\r
+                               header->st=PARSE_MAN;\r
+                               header->result.man_str=header->_rpos;\r
+                       }else{\r
+                               //無視\r
+                       }\r
+                       break;\r
+               case PARSE_ST:\r
+                       if(i_c=='\0')\r
+                       {\r
+                               header->result.st_len=header->_rpos-header->result.st_str;\r
+                               header->st=PARSE_NULL;\r
+                       }\r
+                       break;\r
+               case PARSE_MAN:\r
+                       if(i_c=='\0'){\r
+                               header->result.man_len=header->_rpos-header->result.man_str;\r
+                               header->st=PARSE_NULL;\r
+                       }\r
+                       break;\r
+               default:\r
+                       break;\r
+       }\r
+       return NyLPC_TBool_TRUE;\r
+}\r
+\r
+/**\r
+ * デフォルトハンドラ\r
+ */\r
+static const struct NyLPC_TcHttpBasicHeaderParser_Handler handler=\r
+{\r
+       messageHandler,\r
+       urlHandler\r
+};\r
+\r
+static NyLPC_TBool parseHeader(struct TMSearchHeader* i_out,const void* i_rx,NyLPC_TInt16 i_rx_size)\r
+{\r
+       NyLPC_TInt16 i;\r
+       NyLPC_TcHttpBasicHeaderParser_t parser;\r
+       //headerの初期化\r
+       i_out->result.st_str=NULL;\r
+       i_out->result.man_str=NULL;\r
+       NyLPC_cHttpBasicHeaderParser_initialize(&parser,&handler);\r
+       NyLPC_cHttpBasicHeaderParser_parseInit(&parser,&(i_out->super));\r
+       for(i=0;i<i_rx_size;i++){\r
+               if(NyLPC_cHttpBasicHeaderParser_parseChar(&parser,((const char*)(i_rx)+i),1,&(i_out->super))<0){\r
+                       NyLPC_cHttpBasicHeaderParser_finalize(&parser);\r
+                       return NyLPC_TBool_FALSE;//ERROR\r
+               }\r
+       }\r
+       NyLPC_cHttpBasicHeaderParser_parseFinish(&parser,&(i_out->super));\r
+       NyLPC_cHttpBasicHeaderParser_finalize(&parser);\r
+       return NyLPC_TBool_TRUE;//OK\r
+}\r
+\r
+static NyLPC_TBool onPacket(NyLPC_TcUdpSocket_t* i_inst,const void* i_buf,const struct NyLPC_TIPv4RxInfo* i_info)\r
+{\r
+       //パケット解析\r
+       void* tx;\r
+       NyLPC_TInt16 tx_len;\r
+       NyLPC_TInt8 i,i2;\r
+       struct TMSearchHeader header;\r
+       NyLPC_TcSsdpSocket_t* sock=(NyLPC_TcSsdpSocket_t*)i_inst;\r
+       if(!parseHeader(&header,i_buf,i_info->size)){\r
+               NyLPC_OnErrorGoto(ERROR1);\r
+       }\r
+       //resultチェック\r
+       if(header.result.man_str!=NULL || header.result.st_str!=NULL){\r
+               NyLPC_OnErrorGoto(ERROR1);\r
+       }\r
+       //MANチェック\r
+       if(strncmp("ssdp:discover",header.result.man_str,header.result.man_len)!=0){\r
+               NyLPC_OnErrorGoto(ERROR1);\r
+       }\r
+       //STによる処理分岐\r
+       if(strncmp("ssdp:all",header.result.st_str,8)==0){\r
+               //全デバイスの送信\r
+       }else if(strncmp("uuid:",header.result.st_str,5)==0){\r
+               //UDNの一致するデバイスの送信\r
+               NyLPC_TInt16 i;\r
+               for(i=sock->number_of_device_record-1;i>=0;i--){\r
+                       if(strncmp(header.result.st_str,sock->ref_device_record[i].udn,header.result.st_len)){\r
+                               //UDN一致\r
+                               tx=allocMsearchResponeTx(\r
+                                       sock,header.result.st_str,\r
+                                       sock->ref_device_record[i].udn,NULL,\r
+                                       header.result.st_len,\r
+                                       &tx_len);\r
+                               if(tx==NULL){\r
+                                       NyLPC_OnErrorGoto(ERROR1);\r
+                               }\r
+                               if(!NyLPC_cUdpSocket_psend(i_inst,&i_info->peer_ip,i_info->peer_port,tx,tx_len)){\r
+                                       NyLPC_OnErrorGoto(ERROR2);\r
+                               }\r
+                               break;//送信処理終了\r
+                       }\r
+               }\r
+       }else if(strncmp(STR_UPNP_ROOT_DEVICE,header.result.st_str,15)==0){\r
+               //rootDeviceはdevice0\r
+               tx=allocMsearchResponeTx(\r
+                       sock,header.result.st_str,\r
+                       sock->ref_device_record[0].udn,sock->ref_device_record[0].device_type,\r
+                       header.result.st_len,\r
+                       &tx_len);\r
+               if(tx==NULL){\r
+                       NyLPC_OnErrorGoto(ERROR1);\r
+               }\r
+               if(!NyLPC_cUdpSocket_psend(i_inst,&i_info->peer_ip,i_info->peer_port,tx,tx_len)){\r
+                       NyLPC_OnErrorGoto(ERROR2);\r
+               }\r
+       }else if(strncmp("urn:",header.result.st_str,4)==0){\r
+               for(i=0;i<header._number_of_device;i++){\r
+                       //urn一致チェック\r
+                       if(strncmp(sock->ref_device_record[i].device_type,header.result.st_str,header.result.st_len)==0){\r
+                               //deviceに一致\r
+                               tx=allocMsearchResponeTx(\r
+                                       sock,header.result.st_str,\r
+                                       sock->ref_device_record[i].udn,sock->ref_device_record[i].device_type,\r
+                                       header.result.st_len,\r
+                                       &tx_len);\r
+                               if(tx==NULL){\r
+                                       NyLPC_OnErrorGoto(ERROR1);\r
+                               }\r
+                               if(!NyLPC_cUdpSocket_psend(i_inst,&i_info->peer_ip,i_info->peer_port,tx,tx_len)){\r
+                                       NyLPC_OnErrorGoto(ERROR2);\r
+                               }\r
+                               continue;\r
+                       }\r
+                       for(i2=0;i2<sock->ref_device_record[i].number_of_service;i2++){\r
+                               if(strncmp(sock->ref_device_record[i].services[i2].service_type,header.result.st_str,header.result.st_len)==0){\r
+                                       //serviceに一致\r
+                                       tx=allocMsearchResponeTx(\r
+                                               sock,header.result.st_str,\r
+                                               sock->ref_device_record[i].udn,sock->ref_device_record[i].services[i2].service_type,\r
+                                               header.result.st_len,\r
+                                               &tx_len);\r
+                                       if(tx==NULL){\r
+                                               NyLPC_OnErrorGoto(ERROR1);\r
+                                       }\r
+                                       if(!NyLPC_cUdpSocket_psend(i_inst,&i_info->peer_ip,i_info->peer_port,tx,tx_len)){\r
+                                               NyLPC_OnErrorGoto(ERROR2);\r
+                                       }\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+       //正常終了\r
+       return NyLPC_TBool_FALSE;\r
+ERROR2:\r
+       NyLPC_cUdpSocket_releaseSendBuf(i_inst,tx);\r
+ERROR1:\r
+       return NyLPC_TBool_FALSE;\r
+}\r
+static const struct NyLPC_TIPv4Addr SSDP_MCAST_IPADDR=NyLPC_TIPv4Addr_pack(239,225,225,250);\r
+\r
+\r
+void NyLPC_cSsdpSocket_initialize(\r
+               NyLPC_TcSsdpSocket_t* i_inst,\r
+               const struct NyLPC_TUPnPDeviceRecord* i_ref_dev_record,NyLPC_TUInt8 i_number_of_devices,\r
+               NyLPC_TUInt16 i_server_port,const NyLPC_TChar* i_ref_location_path)\r
+{\r
+       NyLPC_cUdpSocket_initialize(&(i_inst->super),1900,NULL,0);\r
+       NyLPC_cUdpSocket_joinMulticast(&(i_inst->super),&SSDP_MCAST_IPADDR);\r
+\r
+       i_inst->ref_device_record=i_ref_dev_record;\r
+       i_inst->number_of_device_record=i_number_of_devices;\r
+       i_inst->location_port=i_server_port;\r
+       i_inst->location_path=i_ref_location_path;\r
+}\r
+void NyLPC_cSsdpSocket_finalize(NyLPC_TcSsdpSocket_t* i_inst)\r
+{\r
+       NyLPC_cUdpSocket_finalize(&(i_inst->super));\r
+}\r
+\r
+void NyLPC_cSsdpSocket_notify(NyLPC_TcSsdpSocket_t* i_inst)\r
+{\r
+       void* tx;\r
+       NyLPC_TInt16 tx_len;\r
+       NyLPC_TUInt8 i,i2;\r
+       //rootdevice\r
+       tx=allocNotifyTx(\r
+               i_inst,\r
+               i_inst->ref_device_record[0].udn,STR_UPNP_ROOT_DEVICE,\r
+               &tx_len);\r
+       if(tx==NULL){\r
+               NyLPC_OnErrorGoto(ERROR1);\r
+       }\r
+       if(!NyLPC_cUdpSocket_psend(&i_inst->super,&SSDP_MCAST_IPADDR,1900,tx,tx_len)){\r
+               NyLPC_OnErrorGoto(ERROR2);\r
+       }\r
+       //all device\r
+       for(i=0;i<i_inst->number_of_device_record;i++){\r
+               //uuid\r
+               tx=allocNotifyTx(\r
+                       i_inst,\r
+                       i_inst->ref_device_record[i].udn,NULL,\r
+                       &tx_len);\r
+               if(tx==NULL){\r
+                       NyLPC_OnErrorGoto(ERROR1);\r
+               }\r
+               if(!NyLPC_cUdpSocket_psend(&i_inst->super,&SSDP_MCAST_IPADDR,1900,tx,tx_len)){\r
+                       NyLPC_OnErrorGoto(ERROR2);\r
+               }\r
+               //devicatype\r
+               tx=allocNotifyTx(\r
+                       i_inst,\r
+                       i_inst->ref_device_record[i].udn,i_inst->ref_device_record[i].device_type,\r
+                       &tx_len);\r
+               if(tx==NULL){\r
+                       NyLPC_OnErrorGoto(ERROR1);\r
+               }\r
+               if(!NyLPC_cUdpSocket_psend(&i_inst->super,&SSDP_MCAST_IPADDR,1900,tx,tx_len)){\r
+                       NyLPC_OnErrorGoto(ERROR2);\r
+               }\r
+               for(i2=0;i2<i_inst->ref_device_record[i].number_of_service;i2++){\r
+                       tx=allocNotifyTx(\r
+                               i_inst,\r
+                               i_inst->ref_device_record[i].udn,i_inst->ref_device_record[i].services[i2].service_type,\r
+                               &tx_len);\r
+                       if(tx==NULL){\r
+                               NyLPC_OnErrorGoto(ERROR1);\r
+                       }\r
+                       if(!NyLPC_cUdpSocket_psend(&i_inst->super,&SSDP_MCAST_IPADDR,1900,tx,tx_len)){\r
+                               NyLPC_OnErrorGoto(ERROR2);\r
+                       }\r
+               }\r
+       }\r
+       return;\r
+ERROR2:\r
+       NyLPC_cUdpSocket_releaseSendBuf(&i_inst->super,tx);\r
+ERROR1:\r
+       return;\r
+}\r
+\r
diff --git a/lib/src/net/ssdp/NyLPC_cSsdpSocket.h b/lib/src/net/ssdp/NyLPC_cSsdpSocket.h
new file mode 100644 (file)
index 0000000..050c159
--- /dev/null
@@ -0,0 +1,105 @@
+/*\r
+ * NyLPC_cSsdpSocket.h\r
+ *\r
+ *  Created on: 2013/07/26\r
+ *      Author: nyatla\r
+ */\r
+\r
+#ifndef NYLPC_CSSDPSOCKET_H_\r
+#define NYLPC_CSSDPSOCKET_H_\r
+\r
+#include "NyLPC_net.h"\r
+/**\r
+ * UPnP ServiceRecord\r
+ */\r
+struct NyLPC_TUPnPServiceRecord\r
+{\r
+       /**\r
+        * /root/device/serviceList/service/serviceType\r
+        * ex. schemas-upnp-org:service:xxxx:n\r
+        */\r
+       const NyLPC_TChar* service_type;\r
+};\r
+/**\r
+ * UPnP DeviceRecord\r
+ * UPnPデバイス情報を格納します。\r
+ */\r
+struct NyLPC_TUPnPDeviceRecord\r
+{\r
+       /**\r
+        * /root/device/deviceType\r
+        * ex. schemas-upnp-org:device:xxxx:n\r
+        */\r
+       const NyLPC_TChar* device_type;\r
+       /**\r
+        * /root/device/udn\r
+        */\r
+       const NyLPC_TChar* udn;\r
+       NyLPC_TInt32 number_of_service;\r
+       const struct NyLPC_TUPnPServiceRecord* services;\r
+};\r
+\r
+\r
+\r
+typedef struct NyLPC_TcSsdpSocket NyLPC_TcSsdpSocket_t;\r
+\r
+struct NyLPC_TcSsdpSocket\r
+{\r
+       NyLPC_TcUdpSocket_t super;\r
+       /**\r
+        * locationパス\r
+        */\r
+       const NyLPC_TChar* location_path;\r
+       /**\r
+        * DeviceDescriptionをホストするサーバアドレス\r
+        */\r
+       NyLPC_TUInt16 location_port;\r
+       /**\r
+        * Number of device record that initialized by initializer.\r
+        */\r
+       NyLPC_TInt8 number_of_device_record;\r
+       /**\r
+        * デバイスレコードの配列へのポインタ。initialize関数でセットします。\r
+        * 0番目のレコードはルートデバイスです。\r
+        */\r
+       const struct NyLPC_TUPnPDeviceRecord* ref_device_record;\r
+};\r
+\r
+/**\r
+ * DeviceRecordを参照したSSDPソケットインスタンスを生成します。\r
+ * @param i_inst\r
+ * @param i_ref_dev_record\r
+ * デバイスレコードの配列を指定します。\r
+ * 0番目のデバイスがルートデバイス、以降は embeddedデバイスになります。\r
+ * このオブジェクトはインスタンスが破棄されるまでの間維持してください。\r
+ * @param i_number_of_devices\r
+ * @param i_server_port\r
+ * @param i_ref_location_path\r
+ */\r
+void NyLPC_cSsdpSocket_initialize(\r
+               NyLPC_TcSsdpSocket_t* i_inst,\r
+               const struct NyLPC_TUPnPDeviceRecord* i_ref_dev_record,NyLPC_TUInt8 i_number_of_devices,\r
+               NyLPC_TUInt16 i_server_port,const NyLPC_TChar* i_ref_location_path);\r
+\r
+void NyLPC_cSsdpSocket_finalize(NyLPC_TcSsdpSocket_t* i_inst);\r
+/**\r
+ * この関数はフル\r
+ */\r
+void NyLPC_cSsdpSocket_notify(NyLPC_TcSsdpSocket_t* i_inst);\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+#endif /* NYLPC_CSSDPSOCKET_H_ */\r
index 005f24d..86617db 100644 (file)
@@ -145,6 +145,11 @@ NyLPC_TInt32 NyLPC_cUdpSocket_send(NyLPC_TcUdpSocket_t* i_inst,const struct NyLP
  */\r
 #define NyLPC_cUdpSocket_setOnPerriodicHandler(i_inst,i_handler) (i_inst)->as_handler.periodic=i_handler;\r
 \r
+/**\r
+ * ソケットのローカルIPのアドレスを返す。\r
+ * 値はuipが動作中のみ有効。\r
+ */\r
+#define NyLPC_cUdpSocket_getSockIP(i_inst) (&(i_inst)->uip_udp_conn.lipaddr)\r
 \r
 #ifdef __cplusplus\r
 }\r