OSDN Git Service

2011/10/27 1:18:31
authorqwerty2501 <riot313@gmail.com>
Wed, 26 Oct 2011 16:18:31 +0000 (01:18 +0900)
committerqwerty2501 <riot313@gmail.com>
Wed, 26 Oct 2011 16:18:31 +0000 (01:18 +0900)
nlib/nlib.h
nlib/nlib.vcxproj
nlib/nlib_common.c
nlib/nlib_include.h
nlib/nlib_myList.c
nlib/nlib_nicoLive.c
nlib/nlib_nicoLive.h
nlib/nlib_xmlHandler.c
nlib_driver/nlib_driver.cpp

index dd5a7dc..bd3819c 100644 (file)
@@ -233,46 +233,46 @@ extern "C" {
        ///
        ///\83n\81[\83g\83r\81[\83g\82Ì\8aÔ\8au\82ð\90Ý\92è\81i\83~\83\8a\95b)
        ///
-       NLIB_DECLSPEC VOID SetHeartBeatMsec(DWORD msec);
+       NLIB_DECLSPEC VOID SetHeartBeatMsec(NicoLiveStream_P self,DWORD msec);
 
 
        ///
        ///\83n\81[\83g\83r\81[\83g\82Ì\8aÔ\8au\82ð\8eæ\93¾(\83~\83\8a\95b)
        ///
-       NLIB_DECLSPEC DWORD GetHeartBeatMsec();
+       NLIB_DECLSPEC DWORD GetHeartBeatMsec(NicoLiveStream_P self);
 
        ///
        ///\83n\81[\83g\83r\81[\83g\97L\8cø\81E\96³\8cø\90Ý\92è
        ///
-       NLIB_DECLSPEC VOID SetHeartBeatFlag(BOOL flag);
+       NLIB_DECLSPEC VOID SetHeartBeatFlag(NicoLiveStream_P self,BOOL flag);
 
 
        ///
        ///\83n\81[\83g\83r\81[\83g\97L\8cø\83t\83\89\83O\8eæ\93¾
        ///
-       NLIB_DECLSPEC BOOL GetHeartBeatFlag();
+       NLIB_DECLSPEC BOOL GetHeartBeatFlag(NicoLiveStream_P self);
 
        ///
        ///\83L\81[\83v\83A\83\89\83C\83u\82Ì\8aÔ\8au\82ð\90Ý\92è(\83~\83\8a\95b)
        ///
-       NLIB_DECLSPEC VOID SetKeapALiveMsec(DWORD msec);
+       NLIB_DECLSPEC VOID SetKeapALiveMsec(NicoLiveStream_P self,DWORD msec);
 
        ///
        ///\83L\81[\83v\83A\83\89\83C\83u\82Ì\8aÔ\8au\82ð\8eæ\93¾(\83~\83\8a\95b)
        ///
-       NLIB_DECLSPEC DWORD GetKeapALiveMsec();
+       NLIB_DECLSPEC DWORD GetKeapALiveMsec(NicoLiveStream_P self);
 
 
        ///
        ///\83L\81[\83v\83A\83\89\83C\83u\97L\8cø\81E\96³\8cø\90Ý\92è
        ///
-       NLIB_DECLSPEC VOID SetKeapALiveFlag(BOOL flag);
+       NLIB_DECLSPEC VOID SetKeapALiveFlag(NicoLiveStream_P self,BOOL flag);
 
 
        ///
        ///\83L\81[\83v\83A\83\89\83C\83u\83t\83\89\83O\8eæ\93¾
        ///
-       NLIB_DECLSPEC BOOL GetKeapALiveFlag();
+       NLIB_DECLSPEC BOOL GetKeapALiveFlag(NicoLiveStream_P self);
 
 
        ///
index b646866..e966e03 100644 (file)
@@ -81,7 +81,6 @@
     <ClCompile Include="nlib_common.c" />
     <ClCompile Include="nlib_myList.c" />
     <ClCompile Include="nlib_nicoLive.c" />
-    <ClCompile Include="nlib_memoryManager.c" />
     <ClCompile Include="nlib_nicoVideoAuth.c" />
     <ClCompile Include="nlib_xmlHandler.c" />
   </ItemGroup>
@@ -90,7 +89,6 @@
     <ClInclude Include="nlib_common.h" />
     <ClInclude Include="nlib_define.h" />
     <ClInclude Include="nlib_include.h" />
-    <ClInclude Include="nlib_memoryManager.h" />
     <ClInclude Include="nlib_myList.h" />
     <ClInclude Include="nlib_nicoLive.h" />
     <ClInclude Include="nlib_xmlHandler.h" />
index 6f4b51e..25f86e2 100644 (file)
@@ -49,8 +49,6 @@ NLIB_RESULT InitializeNLIB(){
 
 
 
-       //gFreeList\82ð\8f\89\8aú\89»
-       freeList_Initialize(gFreeList);
 
        //\83N\83b\83L\81[\83\89\83C\83u\83\89\83\8a\82ð\8f\89\8aú\89»
        InitializeShareCookie(appDataPath,localAppDataPath);
@@ -69,8 +67,7 @@ VOID FinalizeNLIB(){
        //\83N\83b\83L\81[\8b¤\97L\83\89\83C\83u\83\89\83\8a\82Ì\8cã\8f\88\97\9d
        FinalizeShareCookie();
 
-       //\83t\83\8a\81[\83\8a\83X\83g\82Ì\8cã\8f\88\97\9d
-       freeList_Finalize(gFreeList);
+
 
        //winHttp\82Ì\8cã\8f\88\97\9d
        WinHttpCloseHandle(hHttpSession);
index eaaed7e..14ed246 100644 (file)
@@ -55,7 +55,7 @@
 #include "nlib_mylist.h"
 #include "nlib_common.h"
 #include "nlib_xmlHandler.h"
-#include "nlib_memoryManager.h"
+
 #include "nlib_nicoLive.h"
 
 
index 477dd4e..a895100 100644 (file)
@@ -45,7 +45,7 @@ NLIB_RESULT NicoMyList_getDefList(NicoVideoAuth_P pAuth,NicoMyListCallBack callb
        
 
 
-end:
+
        
 
        return rslt;
@@ -67,6 +67,7 @@ static NLIB_RESULT NicoMyList_getList(NicoVideoAuth_P pAuth,LPCWSTR objectName,N
        DWORD statusCode;
        DWORD statusCodeSize = sizeof(statusCode);
        DWORD readSize;
+       const UINT_PTR readBufSize = LENGTH_65536 * 30;
        LPSTR readBuffer = NULL;
        JSONParser_P jsonParser = NULL;
        NicoMyListItemContainer itemContainer;
@@ -85,7 +86,7 @@ static NLIB_RESULT NicoMyList_getList(NicoVideoAuth_P pAuth,LPCWSTR objectName,N
 
        }
        
-       readBuffer = (LPSTR)malloc(LENGTH_65536 * 30);
+       readBuffer = (LPSTR)malloc(readBufSize);
 
        jsonParser = JSONParser_new();
 
@@ -108,7 +109,7 @@ static NLIB_RESULT NicoMyList_getList(NicoVideoAuth_P pAuth,LPCWSTR objectName,N
                goto networkerr;
        }
 
-       if(ReadHttpBody(hGetMyList,(LPBYTE)readBuffer,CHUNKMEMORY_MAXSIZE,&readSize) == FALSE){
+       if(ReadHttpBody(hGetMyList,(LPBYTE)readBuffer,readBufSize,&readSize) == FALSE){
                goto networkerr;
 
        }
index d47b602..e9a349d 100644 (file)
@@ -4,7 +4,6 @@
 
 
 
-//NlibProperty nlibProperty;
 
 
 
@@ -16,14 +15,6 @@ static INT_PTR res_from = 0;
 static NicoLiveHeartBeatContainer heartBeatContainer;
 static CRITICAL_SECTION heartBeatCs;
 
-static DWORD heartBeatTime = 300000;
-
-static BOOL heartBeatFlag = TRUE;
-
-
-static DWORD keapALiveTime = 300000;
-
-static BOOL keapALiveFlag = TRUE;
 
 
 //
@@ -71,7 +62,7 @@ static BOOL keapALiveFlag = TRUE;
        (convPtr)[0] = L'\0'
 
 
-
+/*
 #define convertTEXT(buf,basePtr,convPtr,endPtr)\
        (buf) = (convPtr);\
        for(;(basePtr) < (endPtr);(basePtr)++){\
@@ -103,7 +94,7 @@ static BOOL keapALiveFlag = TRUE;
                }\
        }\
        (convPtr)[0] = '\0'
-
+*/
                        
 
 
@@ -188,7 +179,7 @@ static VOID  NicoLiveParseComment(NicoLiveStream_P self,LPWSTR commentBuf,UINT_P
 
 static void NicoLiveError(void *buf);
 
-
+static void NicoLiveSelfDisconnect(void *buf);
 ///
 ///\83\\83P\83b\83g\8eæ\93¾\8aÖ\90\94
 ///
@@ -253,6 +244,10 @@ NicoLiveStream_P NicoLiveStream_new(){
 
        self->chatManager.deleteEvent = WSACreateEvent();
 
+       self->chatManager.setHeartBeatTimeEvent = WSACreateEvent();
+
+       self->chatManager.setKeepAliveTimeEvent = WSACreateEvent();
+
        self->chatManager.resetEvents[0] = WSACreateEvent();
 
        self->chatManager.resetEvents[1] = WSACreateEvent();
@@ -265,6 +260,14 @@ NicoLiveStream_P NicoLiveStream_new(){
 
        self->chatManager.hKeapALiveHandle = (HANDLE)_beginthreadex(NULL,0,NicoLiveKeapALiveThread,self,0,&self->chatManager.keapALiveThreadID);
 
+       self->chatManager.heartBeatTime = 300000;
+
+       self->chatManager.heartBeatFlag = TRUE;
+
+       self->chatManager.keepAliveTime = 300000;
+
+       self->chatManager.keapALiveFlag = TRUE;
+
        dumpln(TEXT("size%d"),sizeof(NicoLiveStream));
 
        
@@ -286,27 +289,34 @@ VOID NicoLiveStream_delete(NicoLiveStream_P* self){
 
        if(INVALID_HANDLE_VALUE  != (*self)->chatManager.hRecvChatHandle){
                WaitForSingleObject( (*self)->chatManager.hRecvChatHandle, INFINITE );
+               CloseHandle((*self)->chatManager.hRecvChatHandle);
        }
 
        if(INVALID_HANDLE_VALUE != (*self)->chatManager.hHeartBeatHandle){
 
                WaitForSingleObject((*self)->chatManager.hHeartBeatHandle,INFINITE);
+               CloseHandle((*self)->chatManager.hHeartBeatHandle);
        }
 
        if(INVALID_HANDLE_VALUE != (*self)->chatManager.hKeapALiveHandle){
 
                WaitForSingleObject((*self)->chatManager.hKeapALiveHandle,INFINITE);
+               CloseHandle((*self)->chatManager.hKeapALiveHandle);
 
        }
 
-       CloseHandle((*self)->chatManager.hRecvChatHandle);
+       
 
-       CloseHandle((*self)->chatManager.hHeartBeatHandle);
+       
 
-       CloseHandle((*self)->chatManager.hKeapALiveHandle);
+       
 
        //\8cã\8f\88\97\9d&\94j\8aü
 
+       WSACloseEvent((*self)->chatManager.setHeartBeatTimeEvent);
+
+       WSACloseEvent((*self)->chatManager.setKeepAliveTimeEvent);
+
        WSACloseEvent((*self)->chatManager.endEvent);
 
        WSACloseEvent((*self)->chatManager.startEvent);
@@ -321,12 +331,6 @@ VOID NicoLiveStream_delete(NicoLiveStream_P* self){
 
 
 
-       //closesocket(self->chatManager.sock);
-
-
-
-
-       //nicoLiveStream_Finalize((**self));
 
        free((*self));
 
@@ -339,19 +343,19 @@ VOID NicoLiveStream_delete(NicoLiveStream_P* self){
 ///
 ///\83n\81[\83g\83r\81[\83g\82Ì\8aÔ\8au\82ð\90Ý\92è\81i\83~\83\8a\95b)
 ///
-VOID SetHeartBeatMsec(DWORD msec){
-
-
-       heartBeatTime = msec;
+VOID SetHeartBeatMsec(NicoLiveStream_P self,DWORD msec){
 
+       WSASetEvent(self->chatManager.setHeartBeatTimeEvent);
+       self->chatManager.heartBeatTime  = msec;
+       return;
 }
 
 ///
 ///\83n\81[\83g\83r\81[\83g\82Ì\8aÔ\8au\82ð\8eæ\93¾(\83~\83\8a\95b)
 ///
-DWORD GetHeartBeatMsec(){
+DWORD GetHeartBeatMsec(NicoLiveStream_P self){
 
-       return heartBeatTime;
+       return self->chatManager.heartBeatTime;
 
 
 }
@@ -359,9 +363,9 @@ DWORD GetHeartBeatMsec(){
 ///
 ///\83n\81[\83g\83r\81[\83g\97L\8cø\81E\96³\8cø\90Ý\92è
 ///
-VOID SetHeartBeatFlag(BOOL flag){
+VOID SetHeartBeatFlag(NicoLiveStream_P self,BOOL flag){
 
-       heartBeatFlag = flag;
+       self->chatManager.heartBeatFlag = flag;
 
 }
 
@@ -369,9 +373,9 @@ VOID SetHeartBeatFlag(BOOL flag){
 ///
 ///\83n\81[\83g\83r\81[\83g\97L\8cø\83t\83\89\83O\8eæ\93¾
 ///
-BOOL GetHeartBeatFlag(){
+BOOL GetHeartBeatFlag(NicoLiveStream_P self){
 
-       return heartBeatFlag;
+       return self->chatManager.heartBeatFlag;
 
 
 }
@@ -380,18 +384,21 @@ BOOL GetHeartBeatFlag(){
 ///
 ///\83L\81[\83v\83A\83\89\83C\83u\82Ì\8aÔ\8au\82ð\90Ý\92è(\83~\83\8a\95b)
 ///
-VOID SetKeapALiveMsec(DWORD msec){
+VOID SetKeapALiveMsec(NicoLiveStream_P self,DWORD msec){
 
-       keapALiveTime = msec;
+       WSASetEvent(self->chatManager.setKeepAliveTimeEvent);
+       self->chatManager.keepAliveTime = msec;
+
+       return;
 
 }
 
 ///
 ///\83L\81[\83v\83A\83\89\83C\83u\82Ì\8aÔ\8au\82ð\8eæ\93¾(\83~\83\8a\95b)
 ///
-DWORD GetKeapALiveMsec(){
+DWORD GetKeapALiveMsec(NicoLiveStream_P self){
 
-       return keapALiveTime;
+       return self->chatManager.keepAliveTime;
 
 }
 
@@ -399,18 +406,18 @@ DWORD GetKeapALiveMsec(){
 ///
 ///\83L\81[\83v\83A\83\89\83C\83u\97L\8cø\81E\96³\8cø\90Ý\92è
 ///
-VOID SetKeapALiveFlag(BOOL flag){
+VOID SetKeapALiveFlag(NicoLiveStream_P self,BOOL flag){
 
-       keapALiveFlag = flag;
+       self->chatManager.keapALiveFlag = flag;
 }
 
 
 ///
 ///\83L\81[\83v\83A\83\89\83C\83u\83t\83\89\83O\8eæ\93¾
 ///
-BOOL GetKeapALiveFlag(){
+BOOL GetKeapALiveFlag(NicoLiveStream_P self){
 
-       return keapALiveFlag;
+       return self->chatManager.keapALiveFlag;
 
 }
 
@@ -564,9 +571,10 @@ NLIB_RESULT NicoLiveStream_sendHeartBeat(NicoLiveStream_P self){
        {
                HINTERNET hWatchLiveNicoSession = NULL;
                HINTERNET hGetPlayerStatusRequest = NULL;
-               ChunkMemory_P chunk = allocChunkGlobal();
+               const UINT_PTR buflen = LENGTH_65536;
+               LPVOID buffer = malloc(buflen);
         
-               LPWSTR objectName = (LPWSTR)chunk->buffer;
+               LPWSTR objectName = (LPWSTR)buffer;
                LPWSTR indexPtr;
                LPWSTR sendBuffer = (LPWSTR)&objectName[LENGTH_4096];
                LPSTR recvBuffer;
@@ -619,7 +627,7 @@ NLIB_RESULT NicoLiveStream_sendHeartBeat(NicoLiveStream_P self){
                recvBuffer = (LPSTR)sendBuffer;
 
 
-               if(ReadHttpBody(hGetPlayerStatusRequest,(LPBYTE)recvBuffer,CHUNKMEMORY_MAXSIZE,&readSize) == FALSE){
+               if(ReadHttpBody(hGetPlayerStatusRequest,(LPBYTE)recvBuffer,buflen,&readSize) == FALSE){
 
                        rslt = NLIB_GETPLAYERSTATUS_FAILED_CONNECT;
                        goto connectend;
@@ -654,7 +662,7 @@ NLIB_RESULT NicoLiveStream_sendHeartBeat(NicoLiveStream_P self){
                }
 
 connectend:
-               freeChunkGlobal(chunk);
+               free(buffer);
                WinHttpCloseHandle(hWatchLiveNicoSession);
                WinHttpCloseHandle(hGetPlayerStatusRequest);
 
@@ -677,24 +685,12 @@ VOID NicoLiveStream_disConnect(NicoLiveStream_P self){
 
        WSAWaitForMultipleEvents(sizeof(self->chatManager.resetEvents) / sizeof(self->chatManager.resetEvents[0]),self->chatManager.resetEvents,TRUE,WSA_INFINITE,FALSE);
 
-       {
 
-               WSAEVENT eventObject = self->chatManager.endEvent;
-               WSAEVENT startObject = self->chatManager.startEvent;
-               WSAEVENT deleteObject = self->chatManager.deleteEvent;
-               HANDLE recvThread = self->chatManager.hRecvChatHandle;
-               DWORD recvThreadID = self->chatManager.recvChatThreadID;
-
-               //nicoLiveStream_Initialize(*self);
-               ZeroMemory(self,sizeof(*self));
-               WSAResetEvent(eventObject);
-               self->chatManager.hRecvChatHandle = recvThread;
-               self->chatManager.recvChatThreadID = recvThreadID;
-               self->chatManager.endEvent = eventObject;
-               self->chatManager.startEvent = startObject;
-               self->chatManager.deleteEvent = deleteObject;
-       }
 
+       //nicoLiveStream_Initialize(*self);
+       ZeroMemory(&self->playerStatus,sizeof(self->playerStatus));
+       WSAResetEvent(self->chatManager.endEvent);
+       
 
 
 
@@ -715,11 +711,11 @@ VOID NicoLiveStream_disConnect(NicoLiveStream_P self){
 NLIB_RESULT NicoLiveStream_sendChat(NicoLiveStream_P self,LPCWSTR chatbuf,LPCWSTR *mail,LPCWSTR *extends){
 
 
-
-       ChunkMemory_P chunkMemory = allocChunkGlobal();
+       const UINT_PTR buflen = LENGTH_65536 * 4;
+       LPVOID chunk = malloc(buflen);
 
        LPSTR postKey;
-       LPSTR postKeyBuf = (LPSTR)chunkMemory->buffer;
+       LPSTR postKeyBuf = (LPSTR)chunk;
        LPWSTR postKeyReqBuf = (LPWSTR)&postKeyBuf[NICOLIVE_SENDCHATBUFLEN];
        LPWSTR cookieBuf = &postKeyReqBuf[NICOLIVE_SENDCHATBUFLEN];
        DWORD statusCode;
@@ -779,7 +775,7 @@ NLIB_RESULT NicoLiveStream_sendChat(NicoLiveStream_P self,LPCWSTR chatbuf,LPCWST
 
 
 
-       if(ReadHttpBody(hGetPostKeySession,(LPBYTE)postKeyBuf,CHUNKMEMORY_MAXSIZE,&readSize) == FALSE){
+       if(ReadHttpBody(hGetPostKeySession,(LPBYTE)postKeyBuf,buflen,&readSize) == FALSE){
 
                rslt = NLIB_GETPLAYERSTATUS_FAILED_CONNECT;
                goto end;
@@ -790,7 +786,7 @@ NLIB_RESULT NicoLiveStream_sendChat(NicoLiveStream_P self,LPCWSTR chatbuf,LPCWST
 
 
        {
-               LPSTR buffer = (LPSTR)&cookieBuf[NICOLIVE_SENDCHATBUFLEN * 4];
+               LPSTR buffer = (LPSTR)&cookieBuf[NICOLIVE_SENDCHATBUFLEN];
                LPSTR indexPtr;
                LPSTR mailBuf;
                LPSTR extendBuf;
@@ -986,12 +982,49 @@ NLIB_RESULT NicoLiveStream_sendChat(NicoLiveStream_P self,LPCWSTR chatbuf,LPCWST
                        strcpy(indexPtr,">");
                        indexPtr += strlen(indexPtr);
                        {
+                               LPWSTR sendBuf = (LPWSTR)&buffer[NICOLIVE_SENDCHATBUFLEN * 4];
+                               LPWSTR sendPtr = sendBuf;
                                LPCWSTR endPtr= chatbuf + wcslen(chatbuf);
-                               convertTEXT(indexPtr,chatbuf,indexPtr,endPtr);
-                               //WideToMB(CP_UTF8,chatbuf,indexPtr,NICOLIVE_SENDCHATBUFLEN - (indexPtr - buffer) - 1);
-                               //indexPtr += strlen(indexPtr);
+
+
+                               //convertTEXT(indexPtr,chatbuf,indexPtr,endPtr);
+
+                               for(;(chatbuf) <= (endPtr);(chatbuf)++){
+                                       switch(chatbuf[0]){
+                                       case L'&':
+                                               wcscpy((sendBuf),L"&amp;");
+                                               (sendBuf) += wcslen(sendBuf);
+                                               break;
+                                       case L'<':
+                                               wcscpy((sendBuf),L"&lt;");
+                                               (sendBuf) += wcslen(sendBuf);
+                                               break;
+                                       case L'>':
+                                               wcscpy((sendBuf),L"&gt;");
+                                               (sendBuf) += wcslen(sendBuf);
+                                               break;
+                                       case L'\"':
+                                               wcscpy((sendBuf),L"&quot;");
+                                               (sendBuf) += wcslen(sendBuf);
+                                               break;
+                                       case L'\'':
+                                               wcscpy((sendBuf),L"&apos;");
+                                               (sendBuf) += wcslen(sendBuf);
+                                               break;
+                                       default:
+                                               sendBuf[0] = chatbuf[0];
+                                               (sendBuf)++;
+                                               break;
+                                       }
+                               }
+
+
+                               WideToMB(CP_UTF8,sendPtr,indexPtr,NICOLIVE_SENDCHATBUFLEN * 4 - (indexPtr - buffer) - 1);
+                               indexPtr += strlen(indexPtr);
+                               
                        }
                        strcpy(indexPtr,"</chat>");
+                       indexPtr[strlen(indexPtr)] = '\0';
 
 
 
@@ -1015,7 +1048,7 @@ NLIB_RESULT NicoLiveStream_sendChat(NicoLiveStream_P self,LPCWSTR chatbuf,LPCWST
 
 
 end:
-
+       free(chunk);
        WinHttpCloseHandle(hGetPostKeySession);
        WinHttpCloseHandle(hWatchLiveNicoVideo);
 
@@ -1041,8 +1074,8 @@ NLIB_RESULT GetPlayerStatus(NicoLivePlayerStatus_P self,LPCWSTR liveNo,LPCWSTR u
 
        HINTERNET hWatchLiveNicoSession = NULL;
        HINTERNET hGetPlayerStatusRequest = NULL;
-       ChunkMemory_P chunkMemory = (ChunkMemory_P)NULL;
-       LPVOID buffer;
+       const UINT_PTR buflen = LENGTH_65536;
+       LPVOID buffer = NULL;
        LPWSTR sendBuffer;
        LPSTR recvBuffer;
        DWORD readSize;
@@ -1067,8 +1100,8 @@ NLIB_RESULT GetPlayerStatus(NicoLivePlayerStatus_P self,LPCWSTR liveNo,LPCWSTR u
 
        }
 
-       chunkMemory = allocChunkGlobal();
-       buffer = getBufChunk(chunkMemory);
+
+       buffer = malloc(buflen);
        sendBuffer = (LPWSTR)buffer;
        wcscpy(sendBuffer,L"Cookie: ");
        wcscat(sendBuffer,userSession);
@@ -1116,7 +1149,7 @@ NLIB_RESULT GetPlayerStatus(NicoLivePlayerStatus_P self,LPCWSTR liveNo,LPCWSTR u
        recvBuffer = (LPSTR)sendBuffer;
 
 
-       if(ReadHttpBody(hGetPlayerStatusRequest,(LPBYTE)recvBuffer,CHUNKMEMORY_MAXSIZE,&readSize) == FALSE){
+       if(ReadHttpBody(hGetPlayerStatusRequest,(LPBYTE)recvBuffer,buflen,&readSize) == FALSE){
 
                rslt = NLIB_GETPLAYERSTATUS_FAILED_CONNECT;
                goto end;
@@ -1140,7 +1173,7 @@ NLIB_RESULT GetPlayerStatus(NicoLivePlayerStatus_P self,LPCWSTR liveNo,LPCWSTR u
 
 end:
 
-       freeChunkGlobal(chunkMemory);
+       free(buffer);
        WinHttpCloseHandle(hGetPlayerStatusRequest);
 
        //hConnect\82ªNULL\8ew\92è\82Å\93n\82³\82ê\82½\8fê\8d\87\81A\82±\82Ì\8aÖ\90\94\82Å\83n\83\93\83h\83\8b\82ð\90\90¬\82µ\82½\82Ì\82Å\95Â\82\82é
@@ -1168,11 +1201,12 @@ static INLINE NLIB_RESULT GetNicoLiveHistory(NicoLiveStream_P self,HINTERNET hCo
        WCHAR cookie[GETNICOLIVEHIS_COOKIELENGTH] = {L"Cookie: "};
        DWORD statusCode;
        DWORD statusCodeSize = sizeof(statusCode);
-       ChunkMemory_P chunkMemory = allocChunkGlobal();
-       DWORD chunkSize = CHUNKMEMORY_MAXSIZE;
+       DWORD chunkSize = LENGTH_65536;
+       LPVOID chunkMemory = malloc(chunkSize);
+       
 
 
-       LPWSTR buffer = (LPWSTR)chunkMemory->buffer;
+       LPWSTR buffer = (LPWSTR)chunkSize;
 
 
 
@@ -1250,7 +1284,7 @@ static INLINE NLIB_RESULT GetNicoLiveHistory(NicoLiveStream_P self,HINTERNET hCo
 
        }
 end:
-       freeChunkGlobal(chunkMemory);
+       free(chunkMemory);
        WinHttpCloseHandle(hStreamBrowse);
 
        if(hConnect == NULL){
@@ -1324,6 +1358,7 @@ static unsigned int WINAPI  NicoLiveKeapALiveThread(void* lpBuffer){
        NicoLiveStream_P self = (NicoLiveStream_P)lpBuffer;
 
        WSAEVENT events[3] = {self->chatManager.deleteEvent,self->chatManager.startEvent,self->chatManager.endEvent};   //\83C\83x\83\93\83g\94z\97ñ
+       WSAEVENT streamEvent[2] = {self->chatManager.endEvent,self->chatManager.setKeepAliveTimeEvent};
        DWORD dwResult;                                                                                                                                                                                                 //\83C\83x\83\93\83g\8eó\90M\8c\8b\89Ê
        DWORD endResult;
 
@@ -1353,6 +1388,7 @@ static unsigned int WINAPI  NicoLiveKeapALiveThread(void* lpBuffer){
                case 2:
                        continue;
 
+
                default:
 
                        goto err;
@@ -1360,23 +1396,31 @@ static unsigned int WINAPI  NicoLiveKeapALiveThread(void* lpBuffer){
                }
 
                while(TRUE){
-                       endResult = WSAWaitForMultipleEvents(1,&self->chatManager.endEvent,FALSE,keapALiveTime,FALSE);
+                       WSAResetEvent(self->chatManager.setKeepAliveTimeEvent);
+                       endResult = WSAWaitForMultipleEvents(sizeof(streamEvent) / sizeof(streamEvent[0]),streamEvent,FALSE,self->chatManager.keepAliveTime,FALSE);
 
                        if(endResult == WSA_WAIT_TIMEOUT){
 
-                               if(keapALiveFlag){
+                               if(self->chatManager.keapALiveFlag){
                                        LPCWSTR mail[2] = {L"184",NULL};
                                        NicoLiveStream_sendChat(self,L"/keapalive",mail,NULL);
                                }
-                       } else if(endResult - WSA_WAIT_EVENT_0 == 0){
+                       }  else{ 
+                               switch(endResult - WSA_WAIT_EVENT_0){
+
+                               case 0:
+                                       goto loopend;
 
-                               break;;
+                               case 1:
+                                       break;
 
-                       } else {
+                               default:
+                                       goto err;
 
-                               goto err;
+                               }
                        }
                }
+loopend:;
 
 
        }
@@ -1398,13 +1442,14 @@ static unsigned int WINAPI  NicoLiveHeartBeatThread(void* lpBuffer){
        NicoLiveStream_P self = (NicoLiveStream_P)lpBuffer;
 
        WSAEVENT events[3] = {self->chatManager.deleteEvent,self->chatManager.startEvent,self->chatManager.endEvent};   //\83C\83x\83\93\83g\94z\97ñ
+       WSAEVENT streamEvent[2] = {self->chatManager.endEvent,self->chatManager.setHeartBeatTimeEvent};
        DWORD dwResult;                                                                                                                                                                                                 //\83C\83x\83\93\83g\8eó\90M\8c\8b\89Ê
        DWORD endResult;
 
        while(TRUE){
 
                WSASetEvent(self->chatManager.resetEvents[1]);
-
+               
                dwResult = WSAWaitForMultipleEvents(sizeof(events) / sizeof(events[0]),events,FALSE,WSA_INFINITE,FALSE);
 
 
@@ -1427,6 +1472,7 @@ static unsigned int WINAPI  NicoLiveHeartBeatThread(void* lpBuffer){
                case 2:
                        continue;
 
+
                default:
 
                        goto err;
@@ -1434,22 +1480,30 @@ static unsigned int WINAPI  NicoLiveHeartBeatThread(void* lpBuffer){
                }
 
                while(TRUE){
-                       endResult = WSAWaitForMultipleEvents(1,&self->chatManager.endEvent,FALSE,heartBeatTime,FALSE);
+                       WSAResetEvent(self->chatManager.setHeartBeatTimeEvent);
+                       endResult = WSAWaitForMultipleEvents(sizeof(streamEvent) / sizeof(streamEvent[0]),streamEvent,FALSE,self->chatManager.heartBeatTime,FALSE);
 
                        if(endResult == WSA_WAIT_TIMEOUT){
 
-                               if(heartBeatFlag){
+                               if(self->chatManager.heartBeatFlag){
                                        NicoLiveStream_sendHeartBeat(self);
                                }
-                       } else if(endResult - WSA_WAIT_EVENT_0 == 0){
+                       } else{ 
+                               switch(endResult - WSA_WAIT_EVENT_0){
 
-                               break;;
+                               case 0:
+                                       goto loopend;
 
-                       } else {
+                               case 1:
+                                       break;
 
-                               goto err;
-                       }
+                               default:
+                                       goto err;
+                               }
+                       } 
                }
+loopend:;
+
 
 
        }
@@ -1575,6 +1629,8 @@ static unsigned int WINAPI NicoLiveRecvChat(void* lpBuffer){
                if(NicoLiveRecvChatLoop(self) == FALSE){
                        goto err;
                }
+
+               
        }
 
 
@@ -1930,10 +1986,15 @@ static VOID  NicoLiveParseComment(NicoLiveStream_P self,LPWSTR commentBuf,UINT_P
 
 
                        self->chatManager.commentCount = wcstoul(nicoLiveChat.no,NULL,0);
+
+                       
                        (*commentCountSum)++;
                        isReceveChat = TRUE;
                        self->callBack(NICOLIVE_EVENT_RECEVE_CHAT,self,self->option,(NICOLIVE_PARAM)&nicoLiveChat,self->chatManager.commentCount);
+                       if(wcscmp(nicoLiveChat.chatBuf,L"/disconnect") == 0 && wcscmp(nicoLiveChat.premium,L"2") == 0){
 
+                               _beginthread(NicoLiveSelfDisconnect,0,self);
+                       }
 
                        //chat_result\83m\81[\83h\82Ì\8fê\8d\87
                } else if((indexPtr = wcsstr(commentBuf,L"<chat_result ")) != NULL){
@@ -2007,6 +2068,22 @@ static void NicoLiveError(void *buf){
 
 }
 
+static void NicoLiveSelfDisconnect(void *buf){
+
+       NicoLiveStream_P nl = (NicoLiveStream_P)buf;
+
+
+
+       NicoLiveStream_disConnect(nl);
+
+       _heapmin();
+
+
+       _endthread();
+       return;
+
+}
+
 static INLINE SOCKET GetConectedSocket(LPCWSTR nordName,LPCWSTR port,int socktype,int addr_famiry,int protocol){
 
 
index 05645ba..14c7ba6 100644 (file)
@@ -60,6 +60,12 @@ typedef struct {
        unsigned keapALiveThreadID;
        CHAR recvBuf[NICOLIVE_CHAT_RECEVE_LENGTH];
        SOCKET sock;
+       WSAEVENT setHeartBeatTimeEvent;
+       DWORD heartBeatTime;
+       BOOL heartBeatFlag;
+       WSAEVENT setKeepAliveTimeEvent;
+       DWORD keepAliveTime;
+       BOOL keapALiveFlag;
        WSAEVENT deleteEvent;
        WSAEVENT startEvent;
        WSAEVENT  endEvent;
index 106d626..e09d851 100644 (file)
@@ -50,7 +50,7 @@ static INLINE NLIB_RESULT StrCpy(LPWSTR buf,UINT_PTR buflen,LPCWSTR pszData,UINT
 ///
 ///UTF8\95Ï\8a·\93à\95\94\8aÖ\90\94
 ///
-static INLINE void ToUTF8(char *buf,const wchar_t *input,int nLength,int maxLength);
+static INLINE VOID ToUTF8(LPSTR buf,LPCWSTR input,INT_PTR nLength,INT_PTR maxLength);
 
 
 
@@ -670,7 +670,7 @@ void NicoLiveHeartBeat_ElementEndHandler(void *userData,const XML_Char *pszName)
 
 }
 
-static INLINE void ToUTF8(char *buf,const wchar_t *input,int nLength,int maxLength){
+static INLINE VOID ToUTF8(LPSTR buf,LPCWSTR input,INT_PTR nLength,INT_PTR maxLength){
 
 
        if(WideCharToMultiByte(CP_UTF8,0,input,nLength,(LPSTR)NULL,0,(LPCSTR)NULL,(LPBOOL)NULL) > maxLength){
index cddaa48..e55b58f 100644 (file)
@@ -155,9 +155,9 @@ void nicoLive_connect(void) {
        
 
        SetResFrom(1000);
-       //SetHeartBeatMsec(5000);
-       //SetKeapALiveMsec(5000);
-       SetKeapALiveFlag(FALSE);
+       SetHeartBeatMsec(nl,5000);
+       SetKeapALiveMsec(nl,5000);
+       //SetKeapALiveFlag(nl,FALSE);
        
        //CU_ASSERT_EQUAL(NicoLiveStream_connect(nl,nva,L"lv66406941",callback,NULL), NLIB_ERR_OK);
        WCHAR housoubuf[LENGTH_1024];
@@ -212,8 +212,8 @@ void nicoLive_mylist(void) {
 
 
 static CU_TestInfo nlive_test[] = {
-  //{ "\90Ú\91±", nicoLive_connect },
-       {"\83}\83C\83\8a\83X\83g",nicoLive_mylist},
+       { "\90Ú\91±", nicoLive_connect },
+       //{"\83}\83C\83\8a\83X\83g",nicoLive_mylist},
   CU_TEST_INFO_NULL,
 };