OSDN Git Service

2012/01/24 21:33:17
[nlite/nlite.git] / nlib / nlib_nicoLive.c
index 19945f2..fb6e9d2 100644 (file)
@@ -1,5 +1,4 @@
-
-
+#include "StdAfx.h"
 #include "nlib_include.h"
 
 
@@ -7,11 +6,6 @@
 
 
 
-
-static XML_Parser xmlParser;
-static CRITICAL_SECTION playerStatusParserCs;
-static INT_PTR res_from = 0;
-
 static NicoLiveHeartBeatContainer heartBeatContainer;
 static CRITICAL_SECTION heartBeatCs;
 
@@ -61,44 +55,6 @@ static CRITICAL_SECTION heartBeatCs;
        }\
        (convPtr)[0] = L'\0'
 
-
-/*
-#define convertTEXT(buf,basePtr,convPtr,endPtr)\
-       (buf) = (convPtr);\
-       for(;(basePtr) < (endPtr);(basePtr)++){\
-               switch(basePtr[0]){\
-               case L'&':\
-                       strcpy((convPtr),"&amp;");\
-                       (convPtr) += strlen(convPtr);\
-                       break;\
-               case L'<':\
-                       strcpy((convPtr),"&lt;");\
-                       (convPtr) += strlen(convPtr);\
-                       break;\
-               case L'>':\
-                       strcpy((convPtr),"&gt;");\
-                       (convPtr) += strlen(convPtr);\
-                       break;\
-               case L'\"':\
-                       strcpy((convPtr),"&quot;");\
-                       (convPtr) += strlen(convPtr);\
-                       break;\
-               case L'\'':\
-                       strcpy((convPtr),"&apos;");\
-                       (convPtr) += strlen(convPtr);\
-                       break;\
-               default:\
-                       WideCharToMultiByte(CP_UTF8,0,(basePtr),1,(convPtr),LENGTH_1024,(LPCSTR)NULL,(LPBOOL)NULL);\
-                       (convPtr) += strlen(convPtr);\
-                       break;\
-               }\
-       }\
-       (convPtr)[0] = '\0'
-*/
-                       
-
-
-
 #define getBaseVpos(server_time,base_time)     (((server_time) - (base_time)) * 100)
 
 #define setMsec(mSec)\
@@ -120,7 +76,7 @@ static CRITICAL_SECTION heartBeatCs;
 ///
 ///\83v\83\8c\83C\83\84\81[\83X\83e\81[\83^\83X\8eæ\93¾
 ///
-static INLINE NLIB_RESULT GetPlayerStatus(NicoLivePlayerStatus_P pPlayerStatus,LPCWSTR userSession,HINTERNET hConnect,LPVOID buffer);
+static INLINE NLIB_RESULT GetPlayerStatus(NicoLivePlayerStatus_P pPlayerStatus,LPCTSTR userSession,HINTERNET hConnect,LPVOID buffer);
 
 ///
 ///nicoLiveHistory\8eæ\93¾
@@ -131,22 +87,10 @@ static INLINE NLIB_RESULT GetNicoLiveHistory(NicoLiveStream_P self,HINTERNET hCo
 
 
 
-///
-///\83v\83\8c\83C\83\84\81[\83X\83e\81[\83^\83X\83p\81[\83T\8f\89\8aú\89»
-///
-static INLINE VOID Parser_Initialize();
 
 
-///
-///\83v\83\8c\83C\83\84\81[\83X\83e\81[\83^\83X\83p\81[\83T\8cã\8f\88\97\9d
-///
-static INLINE VOID Parser_Finalize();
 
 
-///
-///\83v\83\8c\83C\83\84\81[\83X\83e\81[\83^\83X\83p\81[\83X\8f\88\97\9d
-///
-static INLINE VOID XMLParse(LPVOID option,LPCSTR body,XML_StartElementHandler startElementEvent,XML_EndElementHandler endElementEvent,XML_CharacterDataHandler characterDataEvent);
 
 
 
@@ -166,40 +110,56 @@ static unsigned int WINAPI  NicoLiveHeartBeatThread(void* lpBuffer);
 ///
 static unsigned int WINAPI  NicoLiveKeapALiveThread(void* lpBuffer);
 
+
+
+
 ///
 ///\83`\83\83\83b\83g\8eó\90M\83\8b\81[\83v\8aÖ\90\94
 ///
 static BOOL NicoLiveRecvChatLoop(NicoLiveStream_P self);
 
+///
+///\83\8b\81[\83v
+///
+static unsigned int loopCommon(NicoLiveStream_P self,WSAEVENT sendEvent,WSAEVENT resetEvent ,NicoLiveOnSend nicoLiveOnSend,LPDWORD time);
 
 ///
 ///\83R\83\81\83\93\83g\89ð\90Í\8aÖ\90\94
 ///
-static VOID  NicoLiveParseComment(NicoLiveStream_P self,LPWSTR commentBuf,UINT_PTR endSize,LPWSTR* mailCountBuf,SIZE_T* mailCountBufSize,SIZE_T* commentCountSum,SIZE_T* commentBufSize);
+static VOID  NicoLiveParseComment(NicoLiveStream_P self,LPTSTR commentBuf,UINT_PTR endSize,LPTSTR* mailCountBuf,SIZE_T* mailCountBufSize,SIZE_T* commentBufSize);
 
 static void NicoLiveError(void *buf);
 
 static void NicoLiveSelfDisconnect(void *buf);
+
+static VOID OnSendHeartBeat(NicoLiveStream_P self);
+
+static VOID OnSendKeepAllive(NicoLiveStream_P self);
 ///
 ///\83\\83P\83b\83g\8eæ\93¾\8aÖ\90\94
 ///
-static INLINE SOCKET GetConectedSocket(LPCWSTR nordName,LPCWSTR port,int socktype,int addr_famiry,int protocol);
+static INLINE SOCKET GetConectedSocket(LPCTSTR nordName,LPCTSTR port,int socktype,int addr_famiry,int protocol);
+
+
+StreamStatus_P NicoLiveStream_getStreamStatus(NicoLiveStream_P self){
+
+       return &self->playerStatus.stream;
+}
 
 BOOL Initialize_NicoLive(){
 
 
 
-       //\83p\81[\83T\82ð\8f\89\8aú\89»
-       Parser_Initialize();
+
 
        //\83n\81[\83g\83r\81[\83g\83R\83\93\83e\83i\8f\89\8aú\89»
        ZeroMemory(&heartBeatContainer,sizeof(heartBeatContainer));
-       heartBeatContainer.is_restrictSize = sizeof(WCHAR) * LENGTH_1024;
-       heartBeatContainer.is_restrictBuff = (LPWSTR)calloc(1,heartBeatContainer.is_restrictSize);
+       heartBeatContainer.is_restrictSize = sizeof(TCHAR) * LENGTH_1024;
+       heartBeatContainer.is_restrictBuff = (LPTSTR)calloc(1,heartBeatContainer.is_restrictSize);
        heartBeatContainer.heartBeat.is_restrict = heartBeatContainer.is_restrictBuff;
 
-       heartBeatContainer.ticketSize = sizeof(WCHAR) * LENGTH_1024;
-       heartBeatContainer.ticketBuff = (LPWSTR)calloc(1,heartBeatContainer.ticketSize);
+       heartBeatContainer.ticketSize = sizeof(TCHAR) * LENGTH_1024;
+       heartBeatContainer.ticketBuff = (LPTSTR)calloc(1,heartBeatContainer.ticketSize);
        heartBeatContainer.heartBeat.ticket = heartBeatContainer.ticketBuff;
 
        InitializeCriticalSection(&heartBeatCs);
@@ -222,8 +182,7 @@ extern BOOL Finalize_NicoLive(){
        free(heartBeatContainer.ticketBuff);
 
 
-       //\83v\83\8c\83C\83\84\81[\83X\83e\81[\83^\83X\83p\81[\83T\8cã\8f\88\97\9d
-       Parser_Finalize();
+       
 
 
 
@@ -238,6 +197,23 @@ NicoLiveStream_P NicoLiveStream_new(){
        //\90\90¬&\8f\89\8aú\89»
        NicoLiveStream_P self = (NicoLiveStream_P)calloc(1,sizeof(NicoLiveStream));
 
+       //\8f\89\8aú\92l\82Ì\90Ý\92è
+       self->chatManager.onHeartBeatSend = OnSendHeartBeat;
+
+       self->chatManager.onKeepAlliveSend = OnSendKeepAllive;
+
+       InitializeCriticalSection(&self->sessionManager.cs);
+
+       self->chatManager.heartBeatTime = 300000;
+
+       self->chatManager.heartBeatFlag = FALSE;
+
+       self->chatManager.keepAliveTime = 900000;
+
+       self->chatManager.keapALiveFlag = TRUE;
+
+       self->isConnecting = FALSE;
+
        self->chatManager.endEvent = WSACreateEvent();
 
        self->chatManager.startEvent = WSACreateEvent();
@@ -254,25 +230,17 @@ NicoLiveStream_P NicoLiveStream_new(){
 
        self->chatManager.resetEvents[2] = WSACreateEvent();
 
-       self->chatManager.hRecvChatHandle = (HANDLE)_beginthreadex(NULL,0,NicoLiveRecvChat,self,0,&self->chatManager.recvChatThreadID);
-
-       self->chatManager.hHeartBeatHandle = (HANDLE)_beginthreadex(NULL,0,NicoLiveHeartBeatThread,self,0,&self->chatManager.heartBeatThreadID);
 
-       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;
+       //\83X\83\8c\83b\83h\82Ì\8aJ\8en
+       self->chatManager.hRecvChatHandle = (HANDLE)_beginthreadex(NULL,0,NicoLiveRecvChat,self,0,&self->chatManager.recvChatThreadID);
 
-       self->chatManager.keapALiveFlag = TRUE;
+       self->chatManager.hHeartBeatHandle = (HANDLE)_beginthreadex(NULL,0,NicoLiveHeartBeatThread,self,0,&self->chatManager.heartBeatThreadID);
 
-       InitializeCriticalSection(&self->sessionManager.cs);
+       self->chatManager.hKeapALiveHandle = (HANDLE)_beginthreadex(NULL,0,NicoLiveKeapALiveThread,self,0,&self->chatManager.keapALiveThreadID);
 
-       dumpln(TEXT("size%d"),sizeof(NicoLiveStream));
-
-       
 
        return self;
 }
@@ -349,8 +317,9 @@ VOID NicoLiveStream_delete(NicoLiveStream_P* self){
 ///
 VOID NicoLiveStream_setHeartBeatMsec(NicoLiveStream_P self,DWORD msec){
 
-       WSASetEvent(self->chatManager.setHeartBeatTimeEvent);
+       
        self->chatManager.heartBeatTime  = msec;
+       WSASetEvent(self->chatManager.setHeartBeatTimeEvent);
        return;
 }
 
@@ -390,9 +359,9 @@ BOOL NicoLiveStream_getHeartBeatFlag(NicoLiveStream_P self){
 ///
 VOID NicoLiveStream_setKeapALiveMsec(NicoLiveStream_P self,DWORD msec){
 
-       WSASetEvent(self->chatManager.setKeepAliveTimeEvent);
+       
        self->chatManager.keepAliveTime = msec;
-
+       WSASetEvent(self->chatManager.setKeepAliveTimeEvent);
        return;
 
 }
@@ -425,23 +394,25 @@ BOOL NicoLiveStream_getKeapALiveFlag(NicoLiveStream_P self){
 
 }
 
-VOID SetResFrom(INT_PTR res){
+VOID NicoLiveStrream_setResFrom(NicoLiveStream_P self,INT_PTR res){
+
+
 
-       res_from = (-1) * res;
+       self->res_from = (res < 0 || res > 1000) ? 0 : ((-1) * res);
 
 }
 
-INT_PTR GetResFrom(){
+INT_PTR NicoLiveStream_getResFrom(NicoLiveStream_P self){
 
-       return (-1) * res_from;
+       return (-1) * self->res_from;
 }
 
-NLIB_RESULT NicoLiveStream_connect(NicoLiveStream_P self,NicoVideoAuth_P nicoVideoAuth,LPCWSTR url,NicoRecvCallBack callback,LPVOID option){
+NLIB_RESULT NicoLiveStream_connect(NicoLiveStream_P self,NicoVideoAuth_P nicoVideoAuth,LPCTSTR url,NicoRecvCallBack callback,LPVOID option){
 
 #define NICOLIVE_CONNECTIONSTREAM_COOKIE_COUNT         1
 #define LIVENO_LENGTH                                                          LENGTH_NICOLIVEID
 
-       NLIB_RESULT rslt = NLIB_ERR_OK;
+       NLIB_RESULT rslt = NLIB_ERR_CODE_NOTSET;
 
 
 
@@ -450,11 +421,13 @@ NLIB_RESULT NicoLiveStream_connect(NicoLiveStream_P self,NicoVideoAuth_P nicoVid
 
 
        //url\82©\82ç\90Ú\91±\94Ô\8d\86\82ð\92\8a\8fo
-       LPCWSTR pInputLiveNo = url;
-       LPCWSTR psrech = wcsstr(url,L"http://");
-       LPCWSTR pInputLiveNoEnd;
-       WCHAR liveNo[LIVENO_LENGTH] = {0};
-       //HINTERNET hWatchLiveNicVideo = NULL;
+       LPCTSTR pInputLiveNo = url;
+       LPCTSTR psrech = wcsstr(url,L"http://");
+       LPCTSTR pInputLiveNoEnd;
+       TCHAR liveNo[LIVENO_LENGTH] = {0};
+       
+
+       if(self == NULL)goto end;
 
        //\91O\82É\82Â\82È\82¢\82Å\82¢\82½\95ú\91\97\82ð\90Ø\92f
        NicoLiveStream_disConnect(self);
@@ -481,7 +454,7 @@ NLIB_RESULT NicoLiveStream_connect(NicoLiveStream_P self,NicoVideoAuth_P nicoVid
 
        if(pInputLiveNo == NULL){
 
-               rslt = NLIB_LIVENO_FAILED_INPUT;
+               rslt = NLIB_LIVENO_IS_NULL;
                goto end;
 
        }else if(pInputLiveNoEnd - pInputLiveNo + 2 >= LIVENO_LENGTH - 1){
@@ -519,14 +492,14 @@ NLIB_RESULT NicoLiveStream_connect(NicoLiveStream_P self,NicoVideoAuth_P nicoVid
 
 
        {
-               WCHAR objectName[LENGTH_256] = {L"api/getplayerstatus?v="};
+               TCHAR objectName[LENGTH_256] = {L"api/getplayerstatus?v="};
                wcsncat(objectName,liveNo,sizeof(objectName) / sizeof(objectName[0]));
 
 
 
        
 
-               self->sessionManager.getPlayerStatusSession = WinHttpOpenRequest(hWatchLiveNicoConnect,L"GET",objectName,L"1.1",(LPCWSTR)WINHTTP_NO_REFERER,(LPCWSTR*)WINHTTP_DEFAULT_ACCEPT_TYPES,0);
+               self->sessionManager.getPlayerStatusSession = WinHttpOpenRequest(hWatchLiveNicoConnect,L"GET",objectName,L"1.1",(LPCTSTR)WINHTTP_NO_REFERER,(LPCTSTR*)WINHTTP_DEFAULT_ACCEPT_TYPES,0);
        }
 
        //\83v\83\8c\83C\83\84\81[\83X\83e\81[\83^\83X\8eæ\93¾
@@ -539,25 +512,25 @@ NLIB_RESULT NicoLiveStream_connect(NicoLiveStream_P self,NicoVideoAuth_P nicoVid
                goto end;
        }
 
-       if(res_from > 0 || res_from < -1000 ){
 
-               res_from = 0;
-       }
 
        //\90\95ú\91\97\83I\83u\83W\83F\83N\83g\82É\8ae\88ø\90\94\82ð\90Ý\92è
-       self->res_from = res_from;
+
        self->callBack = callback;
        self->option = option;
 
 
        WSASetEvent(self->chatManager.startEvent);
 
+       self->isConnecting = TRUE;
+
+
+       rslt = NLIB_ERR_OK;
        //nicoLiveHistory\82ð\8eæ\93¾(\95K\97v\82È\82µ\81H)
        //GetNicoLiveHistory(self,hWatchLiveNicVideo);
 
 end:
-//     WinHttpCloseHandle(hWatchLiveNicVideo);
-       //freeChunkGlobal(chunk);
+
 
        return rslt;
 }
@@ -566,8 +539,12 @@ end:
 NLIB_RESULT NicoLiveStream_sendHeartBeat(NicoLiveStream_P self){
 
        
-       NLIB_RESULT rslt = NLIB_ERR_OK;
+       NLIB_RESULT rslt = NLIB_ERR_CODE_NOTSET;
 
+       if(self->isConnecting == FALSE){
+               rslt = NLIB_ERR_NOT_LIVECONNECT;
+               goto end;
+       }
        if(self == NULL || self->playerStatus.error != NLIB_ERR_OK){
 
                rslt = NLIB_ERR_PLAYERSTATUS_ERROR;
@@ -583,9 +560,9 @@ NLIB_RESULT NicoLiveStream_sendHeartBeat(NicoLiveStream_P self){
                const UINT_PTR buflen = LENGTH_65536;
                LPVOID buffer = self->sessionManager.buffer;
         
-               LPWSTR objectName = (LPWSTR)buffer;
-               LPWSTR indexPtr;
-               //LPWSTR sendBuffer = (LPWSTR)&objectName[LENGTH_4096];
+               LPTSTR objectName = (LPTSTR)buffer;
+               LPTSTR indexPtr;
+               //LPTSTR sendBuffer = (LPTSTR)&objectName[LENGTH_4096];
                LPSTR recvBuffer = (LPSTR)&objectName[LENGTH_4096];
                DWORD readSize;
                DWORD statusCode;
@@ -604,7 +581,7 @@ NLIB_RESULT NicoLiveStream_sendHeartBeat(NicoLiveStream_P self){
 
        
                if(self->sessionManager.heartBeatSession == NULL){
-                       self->sessionManager.heartBeatSession = WinHttpOpenRequest(hWatchLiveNicoConnect,L"GET",objectName,L"1.1",(LPCWSTR)WINHTTP_NO_REFERER,(LPCWSTR*)WINHTTP_DEFAULT_ACCEPT_TYPES,0);
+                       self->sessionManager.heartBeatSession = WinHttpOpenRequest(hWatchLiveNicoConnect,L"GET",objectName,L"1.1",(LPCTSTR)WINHTTP_NO_REFERER,(LPCTSTR*)WINHTTP_DEFAULT_ACCEPT_TYPES,0);
                
                }
                if(WinHttpSendRequest(self->sessionManager.heartBeatSession,self->userSession,-1,WINHTTP_NO_REQUEST_DATA,0,0,0) == FALSE){
@@ -670,6 +647,8 @@ NLIB_RESULT NicoLiveStream_sendHeartBeat(NicoLiveStream_P self){
 
 
                }
+
+               rslt = NLIB_ERR_OK;
 connectend:
                ZeroMemory(self->sessionManager.buffer,sizeof(self->sessionManager.buffer));
                LeaveCriticalSection(&self->sessionManager.cs);
@@ -686,6 +665,7 @@ end:
 
 VOID NicoLiveStream_disConnect(NicoLiveStream_P self){
 
+       if(self == NULL)goto end;
 
        while(WSAResetEvent(self->chatManager.startEvent) == FALSE);
        while(WSASetEvent(self->chatManager.endEvent)== FALSE);
@@ -709,8 +689,9 @@ VOID NicoLiveStream_disConnect(NicoLiveStream_P self){
 
 
 
+       self->isConnecting = FALSE;
 
-
+end:
 
 
        return;
@@ -723,18 +704,19 @@ VOID NicoLiveStream_disConnect(NicoLiveStream_P self){
 #define NICOLIVE_SENDCHATBUFLEN                        LENGTH_4096
 #define NICOLIVE_SENDFORMAT                            "<chat thread=\"%d\" ticket=\"%S\"  postkey=\"%s\" user_id=\"%S\" premium=\"%d\" locale=\"%S\" vpos=\"%ld\"%s>%S</chat>"
 
-NLIB_RESULT NicoLiveStream_sendChat(NicoLiveStream_P self,LPCWSTR chatbuf,LPCWSTR *mail,LPCWSTR *extends){
+NLIB_RESULT NicoLiveStream_sendChat(NicoLiveStream_P self,LPCTSTR chatbuf,LPCTSTR *mail,LPCTSTR *extends){
 
-       NLIB_RESULT rslt = NLIB_ERR_OK;
+       NLIB_RESULT rslt = NLIB_ERR_CODE_NOTSET;
        EnterCriticalSection(&self->sessionManager.cs);
+       
        {
                const UINT_PTR buflen = LENGTH_65536 * 4;
                LPVOID chunk = self->sessionManager.buffer;
 
                LPSTR postKey;
                LPSTR postKeyBuf = (LPSTR)chunk;
-               LPWSTR postKeyReqBuf = (LPWSTR)&postKeyBuf[NICOLIVE_SENDCHATBUFLEN];
-               LPWSTR cookieBuf = &postKeyReqBuf[NICOLIVE_SENDCHATBUFLEN];
+               LPTSTR postKeyReqBuf = (LPTSTR)&postKeyBuf[NICOLIVE_SENDCHATBUFLEN];
+               LPTSTR cookieBuf = &postKeyReqBuf[NICOLIVE_SENDCHATBUFLEN];
                DWORD statusCode;
                DWORD statusCodeSize = sizeof(statusCode);
                DWORD readSize;
@@ -743,19 +725,23 @@ NLIB_RESULT NicoLiveStream_sendChat(NicoLiveStream_P self,LPCWSTR chatbuf,LPCWST
                HINTERNET hGetPostKeySession = NULL;
                
 
+               if(self->isConnecting == FALSE){
+                       rslt = NLIB_ERR_NOT_LIVECONNECT;
+                       goto errorend;
+               }
                if(chatbuf == NULL || wcslen(chatbuf) >= LENGTH_1024){
 
                        rslt = NLIB_ERR_BUFFER_TOOLITTLE;
-                       goto end;
+                       goto errorend;
 
                }
 
 
                //postkey\8eæ\93¾
-               _swprintf(postKeyReqBuf,L"api/getpostkey?thread=%u&block_no=%u",self->playerStatus.ms.thread,self->chatManager.commentCount / 100);
+               _swprintf(postKeyReqBuf,L"api/getpostkey?thread=%u&block_no=%u",self->playerStatus.ms.thread,self->chatManager.chatNo / 100);
 
                //hWatchLiveNicoVideo = WinHttpConnect(hHttpSession,WTEXT(WATCH_LIVE_NICO_VIDEO_DOMEINNAME),INTERNET_DEFAULT_HTTP_PORT,0);
-               hGetPostKeySession = WinHttpOpenRequest(hWatchLiveNicoConnect,L"GET",postKeyReqBuf,L"1.1",(LPCWSTR)WINHTTP_NO_REFERER,(LPCWSTR*)WINHTTP_DEFAULT_ACCEPT_TYPES,0);
+               hGetPostKeySession = WinHttpOpenRequest(hWatchLiveNicoConnect,L"GET",postKeyReqBuf,L"1.1",(LPCTSTR)WINHTTP_NO_REFERER,(LPCTSTR*)WINHTTP_DEFAULT_ACCEPT_TYPES,0);
 
 
                //_swprintf(cookieBuf,L"Cookie: %s; %s",self->userSession,self->nicoLiveHistory);
@@ -763,29 +749,29 @@ NLIB_RESULT NicoLiveStream_sendChat(NicoLiveStream_P self,LPCWSTR chatbuf,LPCWST
 
                if(WinHttpSendRequest(hGetPostKeySession,self->userSession,-1,WINHTTP_NO_REQUEST_DATA,0,0,0) == FALSE){
 
-                       rslt = NLIB_GETPLAYERSTATUS_FAILED_CONNECT;
-                       goto end;
+                       rslt = NLIB_ERR_LIVE_GETPOSTKEY_FAILED;
+                       goto errorend;
 
                }
 
 
                if(WinHttpReceiveResponse(hGetPostKeySession,NULL) == FALSE){
 
-                       rslt = NLIB_GETPLAYERSTATUS_FAILED_CONNECT;
-                       goto end;
+                       rslt = NLIB_ERR_LIVE_GETPOSTKEY_FAILED;
+                       goto errorend;
 
                }
 
 
                if (WinHttpQueryHeaders(hGetPostKeySession,WINHTTP_QUERY_STATUS_CODE | WINHTTP_QUERY_FLAG_NUMBER,WINHTTP_HEADER_NAME_BY_INDEX,&statusCode,&statusCodeSize,WINHTTP_NO_HEADER_INDEX) == FALSE){
-                       rslt = NLIB_GETPLAYERSTATUS_FAILED_CONNECT;
-                       goto end;
+                       rslt = NLIB_ERR_LIVE_GETPOSTKEY_FAILED;
+                       goto errorend;
                }
 
 
                if (HTTP_STATUS_OK != statusCode){
-                       rslt = NLIB_GETPLAYERSTATUS_FAILED_CONNECT;
-                       goto end;
+                       rslt = NLIB_ERR_LIVE_GETPOSTKEY_FAILED;
+                       goto errorend;
                }
 
 
@@ -794,8 +780,8 @@ NLIB_RESULT NicoLiveStream_sendChat(NicoLiveStream_P self,LPCWSTR chatbuf,LPCWST
 
                if(ReadHttpBody(hGetPostKeySession,(LPBYTE)postKeyBuf,buflen,&readSize) == FALSE){
 
-                       rslt = NLIB_GETPLAYERSTATUS_FAILED_CONNECT;
-                       goto end;
+                       rslt = NLIB_ERR_LIVE_GETPOSTKEY_FAILED;
+                       goto errorend;
 
                }
                postKeyBuf[readSize] = '\0';
@@ -809,7 +795,7 @@ NLIB_RESULT NicoLiveStream_sendChat(NicoLiveStream_P self,LPCWSTR chatbuf,LPCWST
                        LPSTR extendBuf;
                
                        //mail\83R\83}\83\93\83h\8dì\90¬
-                       if(mail == NULL){
+                       if(mail == NULL || mail[0] == NULL){
 
                                mailBuf = "";
 
@@ -823,31 +809,33 @@ NLIB_RESULT NicoLiveStream_sendChat(NicoLiveStream_P self,LPCWSTR chatbuf,LPCWST
                                len = NICOLIVE_SENDCHATBUFLEN - (indexPtr - mailBuf) - 1;
                                if(GetLenToMB(CP_UTF8,mail[0]) >= len){
                                        rslt = NLIB_ERR_BUFFER_TOOLITTLE;
-                                       goto end;
+                                       goto errorend;
 
                                }
 
-                               WideToMB(CP_UTF8,mail[0],indexPtr,len);
-                               indexPtr += strlen(indexPtr);
+                               
+                                       WideToMB(CP_UTF8,mail[0],indexPtr,len);
+                                       indexPtr += strlen(indexPtr);
 
 
-                               for(mail++;mail[0] != NULL;mail++){
+                                       for(mail++;mail[0] != NULL;mail++){
 
-                                       indexPtr[0] = ' ';
-                                       indexPtr++;
+                                               indexPtr[0] = ' ';
+                                               indexPtr++;
 
-                                       len =  NICOLIVE_SENDCHATBUFLEN - (indexPtr - mailBuf) - 1;
+                                               len =  NICOLIVE_SENDCHATBUFLEN - (indexPtr - mailBuf) - 1;
 
-                                       if(GetLenToMB(CP_UTF8,mail[0]) >= len){
-                                               rslt = NLIB_ERR_BUFFER_TOOLITTLE;
-                                               goto end;
+                                               if(GetLenToMB(CP_UTF8,mail[0]) >= len){
+                                                       rslt = NLIB_ERR_BUFFER_TOOLITTLE;
+                                                       goto errorend;
 
-                                       }
+                                               }
 
-                                       WideToMB(CP_UTF8,mail[0],indexPtr,len);
-                                       indexPtr += strlen(indexPtr);
+                                               WideToMB(CP_UTF8,mail[0],indexPtr,len);
+                                               indexPtr += strlen(indexPtr);
 
-                               }
+                                       }
+                               
                                strcpy(indexPtr,"\"");
 
 
@@ -856,7 +844,7 @@ NLIB_RESULT NicoLiveStream_sendChat(NicoLiveStream_P self,LPCWSTR chatbuf,LPCWST
                        }
 
                        //\8ag\92£\91®\90«\8dì\90¬
-                       if(extends == NULL){
+                       if(extends == NULL || extends[0] == NULL){
 
                                extendBuf = "";
 
@@ -870,7 +858,7 @@ NLIB_RESULT NicoLiveStream_sendChat(NicoLiveStream_P self,LPCWSTR chatbuf,LPCWST
 
                                if(GetLenToMB(CP_UTF8,extends[0]) >= len){
                                        rslt = NLIB_ERR_BUFFER_TOOLITTLE;
-                                       goto end;
+                                       goto errorend;
 
                                }
                                WideToMB(CP_UTF8,extends[0],indexPtr,len);
@@ -885,7 +873,7 @@ NLIB_RESULT NicoLiveStream_sendChat(NicoLiveStream_P self,LPCWSTR chatbuf,LPCWST
 
                                if(GetLenToMB(CP_UTF8,extends[1]) >= len){
                                        rslt = NLIB_ERR_BUFFER_TOOLITTLE;
-                                       goto end;
+                                       goto errorend;
 
                                }
                                WideToMB(CP_UTF8,extends[1],indexPtr,len);
@@ -900,7 +888,7 @@ NLIB_RESULT NicoLiveStream_sendChat(NicoLiveStream_P self,LPCWSTR chatbuf,LPCWST
 
                                        if(GetLenToMB(CP_UTF8,extends[0]) >= len){
                                                rslt = NLIB_ERR_BUFFER_TOOLITTLE;
-                                               goto end;
+                                               goto errorend;
 
                                        }
                                        WideToMB(CP_UTF8,extends[0],indexPtr,len);
@@ -915,7 +903,7 @@ NLIB_RESULT NicoLiveStream_sendChat(NicoLiveStream_P self,LPCWSTR chatbuf,LPCWST
 
                                        if(GetLenToMB(CP_UTF8,extends[1]) >= len){
                                                rslt = NLIB_ERR_BUFFER_TOOLITTLE;
-                                               goto end;
+                                               goto errorend;
 
                                        }
                                        WideToMB(CP_UTF8,extends[1],indexPtr,len);
@@ -999,9 +987,9 @@ 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);
+                                       LPTSTR sendBuf = (LPTSTR)&buffer[NICOLIVE_SENDCHATBUFLEN * 4];
+                                       LPTSTR sendPtr = sendBuf;
+                                       LPCTSTR endPtr= chatbuf + wcslen(chatbuf);
 
 
                                        //convertTEXT(indexPtr,chatbuf,indexPtr,endPtr);
@@ -1059,14 +1047,15 @@ NLIB_RESULT NicoLiveStream_sendChat(NicoLiveStream_P self,LPCWSTR chatbuf,LPCWST
                        }
                }
 
+               rslt = NLIB_ERR_OK;
                
-end:
+errorend:
        
-       WinHttpCloseHandle(hGetPostKeySession);
+               WinHttpCloseHandle(hGetPostKeySession);
 
-       ZeroMemory(self->sessionManager.buffer,sizeof(self->sessionManager.buffer));
-       LeaveCriticalSection(&self->sessionManager.cs);
-       }
+               ZeroMemory(self->sessionManager.buffer,sizeof(self->sessionManager.buffer));
+               LeaveCriticalSection(&self->sessionManager.cs);
+               }
 
 
 
@@ -1086,17 +1075,15 @@ end:
 
 
 
-NLIB_RESULT GetPlayerStatus(NicoLivePlayerStatus_P self,LPCWSTR userSession,HINTERNET hConnect,LPVOID buffer){
+NLIB_RESULT GetPlayerStatus(NicoLivePlayerStatus_P self,LPCTSTR userSession,HINTERNET hConnect,LPVOID buffer){
 
        NLIB_RESULT rslt = NLIB_ERR_OK;
 
        
        {
-               //HINTERNET hWatchLiveNicoSession = NULL;
-               //HINTERNET hGetPlayerStatusRequest = NULL;
+               
                const UINT_PTR buflen = LENGTH_65536;
-               //LPVOID buffer = ;
-               //LPWSTR sendBuffer;
+               
                LPSTR recvBuffer = (LPSTR)buffer;
                DWORD readSize;
                DWORD statusCode;
@@ -1132,7 +1119,6 @@ NLIB_RESULT GetPlayerStatus(NicoLivePlayerStatus_P self,LPCWSTR userSession,HINT
                }
 
 
-               //recvBuffer = (LPSTR)sendBuffer;
 
 
                if(ReadHttpBody(hConnect,(LPBYTE)recvBuffer,buflen,&readSize) == FALSE){
@@ -1177,12 +1163,12 @@ static INLINE NLIB_RESULT GetNicoLiveHistory(NicoLiveStream_P self,HINTERNET hCo
 
        EnterCriticalSection(&self->sessionManager.cs);
        {
-       //HINTERNET hNicoVideoConnect = NULL;
+       
        HINTERNET hStreamBrowse = NULL;
 
 
-       WCHAR objectName[GETNICOLIVEHIS_OBJNAMELENGTH] = {L"/watch/"};
-       WCHAR cookie[GETNICOLIVEHIS_COOKIELENGTH] = {L"Cookie: "};
+       TCHAR objectName[GETNICOLIVEHIS_OBJNAMELENGTH] = {L"/watch/"};
+       TCHAR cookie[GETNICOLIVEHIS_COOKIELENGTH] = {L"Cookie: "};
        DWORD statusCode;
        DWORD statusCodeSize = sizeof(statusCode);
        DWORD chunkSize = LENGTH_65536;
@@ -1190,7 +1176,7 @@ static INLINE NLIB_RESULT GetNicoLiveHistory(NicoLiveStream_P self,HINTERNET hCo
        
 
 
-       LPWSTR buffer = (LPWSTR)chunkSize;
+       LPTSTR buffer = (LPTSTR)chunkMemory;
 
 
 
@@ -1203,13 +1189,11 @@ static INLINE NLIB_RESULT GetNicoLiveHistory(NicoLiveStream_P self,HINTERNET hCo
        wcscat(objectName,self->playerStatus.stream.id);
        wcscat(cookie,self->userSession);
 
-       
 
-       //hNicoVideoConnect = hConnect;
 
        
 
-       hStreamBrowse = WinHttpOpenRequest(hNicoVideoConnect,L"GET",objectName,L"1.1",(LPCWSTR)WINHTTP_NO_REFERER,(LPCWSTR*)WINHTTP_DEFAULT_ACCEPT_TYPES,0);
+       hStreamBrowse = WinHttpOpenRequest(hNicoVideoConnect,L"GET",objectName,L"1.1",(LPCTSTR)WINHTTP_NO_REFERER,(LPCTSTR*)WINHTTP_DEFAULT_ACCEPT_TYPES,0);
 
 
 
@@ -1247,9 +1231,9 @@ static INLINE NLIB_RESULT GetNicoLiveHistory(NicoLiveStream_P self,HINTERNET hCo
        }
 
        {
-               LPWSTR start =wcsstr(buffer,L"nicolivehistory=");
+               LPTSTR start =wcsstr(buffer,L"nicolivehistory=");
 
-               LPWSTR end = wcsstr(start,L";");
+               LPTSTR end = wcsstr(start,L";");
 
                UINT_PTR length = end - start;
 
@@ -1281,53 +1265,9 @@ end:
 
 
 
-static INLINE VOID Parser_Initialize(){
-
-
-       xmlParser = XML_ParserCreate((const XML_Char*)NULL);
-
-       check(xmlParser,TEXT("\83p\81[\83T\8f\89\8aú\89»\82É\8e¸\94s\82µ\82Ü\82µ\82½"));
-
-
-
-       InitializeCriticalSection(&playerStatusParserCs);
-
-}
-
-static INLINE VOID Parser_Finalize(){
-
-
-       XML_ParserFree(xmlParser);
-
-       DeleteCriticalSection(&playerStatusParserCs);
-
-
-}
-
-static INLINE VOID XMLParse(LPVOID option,LPCSTR body,XML_StartElementHandler startElementEvent,XML_EndElementHandler endElementEvent,XML_CharacterDataHandler characterDataEvent){
 
-       UserDataContainer userDataContainer;
-       userDataContainer.nord = 0;
-       userDataContainer.userData = option;
 
 
-       EnterCriticalSection(&playerStatusParserCs);
-
-       //\91®\90«\90Ý\92è
-       XML_SetElementHandler(xmlParser,startElementEvent,endElementEvent);
-       XML_SetCharacterDataHandler(xmlParser,characterDataEvent);
-       XML_SetUserData(xmlParser,&userDataContainer);
-
-       //\89ð\90Í
-       XML_Parse(xmlParser,body,strlen(body),TRUE);
-
-       //\83\8a\83Z\83b\83g
-       XML_ParserReset(xmlParser,(const XML_Char*)NULL);
-
-       LeaveCriticalSection(&playerStatusParserCs);
-
-
-}
 
 static unsigned int WINAPI  NicoLiveKeapALiveThread(void* lpBuffer){
 
@@ -1335,99 +1275,39 @@ 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;
+       rslt = loopCommon(self,self->chatManager.setKeepAliveTimeEvent,self->chatManager.resetEvents[2],self->chatManager.onKeepAlliveSend,&self->chatManager.keepAliveTime);
 
-       while(TRUE){
-restart:
-               WSASetEvent(self->chatManager.resetEvents[2]);
-
-               dwResult = WSAWaitForMultipleEvents(sizeof(events) / sizeof(events[0]),events,FALSE,WSA_INFINITE,FALSE);
-
-
-               //\83G\83\89\81[\82Ì\8fê\8d\87
-               if(dwResult == WSA_WAIT_FAILED){
-
-                       goto err;
-               }
-
-
-               switch(dwResult - WSA_WAIT_EVENT_0){
-
-               case 0:
-
-                       goto end;
-
-               case 1:
-                       WSAResetEvent(self->chatManager.resetEvents[2]);
-                       break;
-
-               case 2:
-                       continue;
-
-
-               default:
-
-                       goto err;
-
-               }
-
-               while(TRUE){
-                       WSAResetEvent(self->chatManager.setKeepAliveTimeEvent);
-                       endResult = WSAWaitForMultipleEvents(sizeof(streamEvent) / sizeof(streamEvent[0]),streamEvent,FALSE,self->chatManager.keepAliveTime,FALSE);
-
-                       if(endResult == WSA_WAIT_TIMEOUT){
-
-                               if(self->chatManager.keapALiveFlag){
-                                       LPCWSTR mail[2] = {L"184",NULL};
-                                       NicoLiveStream_sendChat(self,L"/keapalive",mail,NULL);
-                               }
-                       }  else{ 
-                               switch(endResult - WSA_WAIT_EVENT_0){
-
-                               case 0:
-                                       goto restart;
+       _endthreadex(rslt);
 
-                               case 1:
-                                       break;
+       return rslt;
+}
 
-                               default:
-                                       goto err;
+static unsigned int WINAPI  NicoLiveHeartBeatThread(void* lpBuffer){
 
-                               }
-                       }
-               }
+       unsigned int rslt = 0;
 
+       NicoLiveStream_P self = (NicoLiveStream_P)lpBuffer;
 
 
-       }
+       rslt = loopCommon(self,self->chatManager.setHeartBeatTimeEvent,self->chatManager.resetEvents[1],self->chatManager.onHeartBeatSend,&self->chatManager.heartBeatTime);
 
-err:
-       _beginthread(NicoLiveError,0,self);
 
-end:
 
        _endthreadex(rslt);
 
        return rslt;
 }
-
-static unsigned int WINAPI  NicoLiveHeartBeatThread(void* lpBuffer){
+static unsigned int loopCommon(NicoLiveStream_P self,WSAEVENT sendEvent,WSAEVENT resetEvent ,NicoLiveOnSend nicoLiveOnSend,LPDWORD time){
 
        unsigned int rslt = 0;
-
-       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};
+       WSAEVENT streamEvent[2] = {self->chatManager.endEvent,sendEvent};
        DWORD dwResult;                                                                                                                                                                                                 //\83C\83x\83\93\83g\8eó\90M\8c\8b\89Ê
        DWORD endResult;
 
        while(TRUE){
 restart:
-               WSASetEvent(self->chatManager.resetEvents[1]);
+               WSASetEvent(resetEvent);
                
                dwResult = WSAWaitForMultipleEvents(sizeof(events) / sizeof(events[0]),events,FALSE,WSA_INFINITE,FALSE);
 
@@ -1446,7 +1326,7 @@ restart:
                        goto end;
 
                case 1:
-                       WSAResetEvent(self->chatManager.resetEvents[1]);
+                       WSAResetEvent(resetEvent);
                        break;
 
                case 2:
@@ -1460,14 +1340,15 @@ restart:
                }
 
                while(TRUE){
-                       WSAResetEvent(self->chatManager.setHeartBeatTimeEvent);
-                       endResult = WSAWaitForMultipleEvents(sizeof(streamEvent) / sizeof(streamEvent[0]),streamEvent,FALSE,self->chatManager.heartBeatTime,FALSE);
+                       WSAResetEvent(sendEvent);
+                       endResult = WSAWaitForMultipleEvents(sizeof(streamEvent) / sizeof(streamEvent[0]),streamEvent,FALSE,*time,FALSE);
 
                        if(endResult == WSA_WAIT_TIMEOUT){
 
-                               if(self->chatManager.heartBeatFlag){
-                                       NicoLiveStream_sendHeartBeat(self);
-                               }
+                               nicoLiveOnSend(self);
+                               //dumpln(TEXT("onSend"));
+
+                               _heapmin();
                        } else{ 
                                switch(endResult - WSA_WAIT_EVENT_0){
 
@@ -1488,16 +1369,31 @@ restart:
 
        }
 
+end:
+       return rslt;
+
 err:
        _beginthread(NicoLiveError,0,self);
+       rslt = 1;
+       goto end;
+}
 
-end:
+static VOID OnSendHeartBeat(NicoLiveStream_P self){
 
-       _endthreadex(rslt);
+       if(self->chatManager.heartBeatFlag){
+               NicoLiveStream_sendHeartBeat(self);
+       }
 
-       return rslt;
 }
 
+static VOID OnSendKeepAllive(NicoLiveStream_P self){
+       
+       if(self->chatManager.keapALiveFlag){
+               LPCTSTR mail[2] = {L"184",NULL};
+               NicoLiveStream_sendChat(self,L"/keapalive",mail,NULL);
+       }
+
+}
 
 #define NICOLIVE_RECEVE_CHAT_LENGTH    LENGTH_2048
 #define NICOLIVE_REQUEST_CHAT_LENGTH   LENGTH_256
@@ -1506,9 +1402,9 @@ static unsigned int WINAPI NicoLiveRecvChat(void* lpBuffer){
 
        unsigned int rslt = 0;
 
-       //LPWSTR user_id = NULL;
-       //LPWSTR name = NULL;
-       //LPWSTR chatBuf = NULL;
+       //LPTSTR user_id = NULL;
+       //LPTSTR name = NULL;
+       //LPTSTR chatBuf = NULL;
 
 
 
@@ -1637,6 +1533,9 @@ end:
 }
 
 
+
+
+
 static BOOL NicoLiveRecvChatLoop(NicoLiveStream_P self){
 
 
@@ -1644,8 +1543,8 @@ static BOOL NicoLiveRecvChatLoop(NicoLiveStream_P self){
        //\83R\83\81\83\93\83g\8eó\90M\8f\88\97\9d
        //
        BOOL rslt = TRUE;                                                                               //\8c\8b\89Ê
-       LPWSTR commentBuf = NULL;                                                               //\83R\83\81\83\93\83g\83o\83b\83t\83@
-       LPWSTR* mailCountBuf = NULL;                                                    //\83\81\81[\83\8b\83|\83C\83\93\83^\83o\83b\83t\83@
+       LPTSTR commentBuf = NULL;                                                               //\83R\83\81\83\93\83g\83o\83b\83t\83@
+       LPTSTR* mailCountBuf = NULL;                                                    //\83\81\81[\83\8b\83|\83C\83\93\83^\83o\83b\83t\83@
        INT_PTR recevedLen;                                                                             //\8eó\90M\95\8e\9a\97ñ\92·
        INT_PTR messageBufLen;                                                                  //\83o\83b\83t\83@\92·
 
@@ -1655,26 +1554,23 @@ static BOOL NicoLiveRecvChatLoop(NicoLiveStream_P self){
        WSANETWORKEVENTS netEvents;                                                             //\83l\83b\83g\83\8f\81[\83N\83C\83x\83\93\83g
        DWORD dwResult;                                                                                 //\83C\83x\83\93\83g\82ª\83E\83F\83C\83g\8aÖ\90\94\82Ì\8c\8b\89Ê\82ð\8ai\94[\82·\82é\95Ï\90\94
 
-
-       SIZE_T commentBufSize = sizeof(WCHAR) * LENGTH_2048;    //\83R\83\81\83\93\83g\83o\83b\83t\83@\92·
-       SIZE_T mailCountBufSize = sizeof(LPWSTR) * LENGTH_256;  //\83\81\81[\83\8b\82Ì\83|\83C\83\93\83^\97p\83o\83b\83t\83@\92·
-
-
-
+       
+       SIZE_T commentBufSize = sizeof(TCHAR) * LENGTH_2048;    //\83R\83\81\83\93\83g\83o\83b\83t\83@\92·
+       SIZE_T mailCountBufSize = sizeof(LPTSTR) * LENGTH_256;  //\83\81\81[\83\8b\82Ì\83|\83C\83\93\83^\97p\83o\83b\83t\83@\92·
 
 
-       SIZE_T commentCountSum = 0;                                                             //\83R\83\81\83\93\83g\83J\83E\83\93\83g                              
        WSAEVENT hRecvEvent = NULL;
 
        //\8eó\90M\8f\80\94õ\8f\88\97\9d
+       self->chatManager.commentCountSum = 0;
        hRecvEvent = WSACreateEvent();
        self->chatManager.recvBuf[0] = '\0';
        WSAEventSelect(self->chatManager.sock, hRecvEvent, FD_READ | FD_CLOSE);
        hEventArray[0] = hRecvEvent;
        hEventArray[1] = self->chatManager.endEvent;
 
-       commentBuf = (LPWSTR)malloc(commentBufSize);
-       mailCountBuf = (LPWSTR*)malloc(mailCountBufSize);
+       commentBuf = (LPTSTR)malloc(commentBufSize);
+       mailCountBuf = (LPTSTR*)malloc(mailCountBufSize);
 
        //\90Ø\92f\82³\82ê\82é\82Ü\82Å\83\8b\81[\83v
        while(1){
@@ -1719,7 +1615,7 @@ static BOOL NicoLiveRecvChatLoop(NicoLiveStream_P self){
 
 
 
-                               NicoLiveParseComment(self,commentBuf,messageBufLen + recevedLen,mailCountBuf,&mailCountBufSize,&commentCountSum,&commentBufSize);
+                               NicoLiveParseComment(self,commentBuf,messageBufLen + recevedLen,mailCountBuf,&mailCountBufSize,&commentBufSize);
 
 
 
@@ -1753,24 +1649,26 @@ end:
 }
 
 
-static VOID  NicoLiveParseComment(NicoLiveStream_P self,LPWSTR commentBuf,UINT_PTR endSize,LPWSTR* mailCountBuf,SIZE_T* mailCountBufSize,SIZE_T* commentCountSum,SIZE_T* commentBufSize){
 
-       LPWSTR indexPtr;                                                                                //\89ð\90Í\8e\9e\82Ì\8ew\95W\83|\83C\83\93\83^
+
+static VOID  NicoLiveParseComment(NicoLiveStream_P self,LPTSTR commentBuf,UINT_PTR endSize,LPTSTR* mailCountBuf,SIZE_T* mailCountBufSize,SIZE_T* commentBufSize){
+
+       LPTSTR indexPtr;                                                                                //\89ð\90Í\8e\9e\82Ì\8ew\95W\83|\83C\83\93\83^
        NicoLiveChat nicoLiveChat;                                                              //\83`\83\83\83b\83g\83R\83\81\83\93\83g\8ai\94[\97p\8d\\91¢\91Ì
        NicoLiveThreadComment nicoLiveThreadComment;                    //\90Ú\91±\89\9e\93\9a\83R\83\81\83\93\83g\8ai\94[\97p\8d\\91¢\91Ì
        NicoLiveSendResultComment nicoLiveSendResultComment;    //\91\97\90M\89\9e\93\9a\83R\83\81\83\93\83g\8ai\94[\97p\8d\\91¢\91Ì
        NicoLiveChat nicoLiveChatBase;                                                  //\83`\83\83\83b\83g\83R\83\81\83\93\83g\8aî\92ê\8d\\91¢\91Ì
        NicoLiveThreadComment nicoLiveThreadCommentBase;                //\90Ú\91±\89\9e\93\9a\83R\83\81\83\93\83g\8aî\92ê\8d\\91¢\91Ì
        NicoLiveSendResultComment nicoLiveSendResultCommentBase;//\91\97\90M\89\9e\93\9a\83R\83\81\83\93\83g\8aî\92ê\8d\\91¢\91Ì
-       LPWSTR attrNameStart;                                                                   //\91®\90«\96¼\8aJ\8en\83|\83C\83\93\83^
-       LPWSTR attrNameEnd;                                                                             //\91®\90«\96¼\8fI\97¹\83|\83C\83\93\83^
-       LPWSTR attrValueStart;                                                                  //\91®\90«\92l\8aJ\8en\83|\83C\83\93\83^
-       LPWSTR attrValueEnd;                                                                    //\91®\90«\92l\8fI\97¹\83|\83C\83\93\83^
+       LPTSTR attrNameStart;                                                                   //\91®\90«\96¼\8aJ\8en\83|\83C\83\93\83^
+       LPTSTR attrNameEnd;                                                                             //\91®\90«\96¼\8fI\97¹\83|\83C\83\93\83^
+       LPTSTR attrValueStart;                                                                  //\91®\90«\92l\8aJ\8en\83|\83C\83\93\83^
+       LPTSTR attrValueEnd;                                                                    //\91®\90«\92l\8fI\97¹\83|\83C\83\93\83^
        INT_PTR nameLen;                                                                                //\91®\90«\82Ì\96¼\91O\82Ì\92·\82³
-       LPWSTR mailIndexPtr;                                                                    //\83\81\81[\83\8b\91®\90«\92l\89ð\90Í\97p\8ew\95W\83|\83C\83\93\83^
-       LPWSTR xmlTextPtr;                                                                              //xml\83e\83L\83X\83g\8c`\8e®\82Ì\83f\81[\83^\89ð\90Í\8e\9e\82É\8eg\97p\82·\82é\83|\83C\83\93\83^
-       LPWSTR xmlTextEnd;                                                                              //xml\83e\83L\83X\83g\8fI\97¹\83|\83C\83\93\83^
-       LPWSTR* mailIndex;                                                                              //\83\81\81[\83\8b\83R\83}\83\93\83h\83\8a\83X\83g\83|\83C\83\93\83^
+       LPTSTR mailIndexPtr;                                                                    //\83\81\81[\83\8b\91®\90«\92l\89ð\90Í\97p\8ew\95W\83|\83C\83\93\83^
+       LPTSTR xmlTextPtr;                                                                              //xml\83e\83L\83X\83g\8c`\8e®\82Ì\83f\81[\83^\89ð\90Í\8e\9e\82É\8eg\97p\82·\82é\83|\83C\83\93\83^
+       LPTSTR xmlTextEnd;                                                                              //xml\83e\83L\83X\83g\8fI\97¹\83|\83C\83\93\83^
+       LPTSTR* mailIndex;                                                                              //\83\81\81[\83\8b\83R\83}\83\93\83h\83\8a\83X\83g\83|\83C\83\93\83^
        BOOL isReceveChat = FALSE;                                                              //\83`\83\83\83b\83g\8eó\90M\83t\83\89\83O
        SIZE_T commentSizeCh;                                                                   //\8eó\90M\82µ\82½\83R\83\81\83\93\83g\82ð\83\86\83j\83R\81[\83h\82É\95Ï\8a·\82·\82é\82Æ\82«\82Ì\92·\82³
        LPSTR recvBufTmp;                                                                               //\8eó\90M\95\8e\9a\97ñ\91\80\8dì\97p\83|\83C\83\93\83^
@@ -1812,8 +1710,8 @@ static VOID  NicoLiveParseComment(NicoLiveStream_P self,LPWSTR commentBuf,UINT_P
        for (;recvBufTmp + strlen(recvBufTmp) < recvEndPoint;recvBufTmp += strlen(recvBufTmp) + 1){
 
 
-               commentSizeCh = sizeof(WCHAR) * GetLenToWide(CP_UTF8,recvBufTmp);
-               extendMalloc(commentBuf,LPWSTR,*commentBufSize,commentSizeCh);
+               commentSizeCh = sizeof(TCHAR) * GetLenToWide(CP_UTF8,recvBufTmp);
+               extendMalloc(commentBuf,LPTSTR,*commentBufSize,commentSizeCh);
                MBToWide(CP_UTF8,recvBufTmp,commentBuf,*commentBufSize);
 
                traceln(TEXT("comment:\r\n%s"),commentBuf);
@@ -1859,7 +1757,7 @@ static VOID  NicoLiveParseComment(NicoLiveStream_P self,LPWSTR commentBuf,UINT_P
 
                        
 
-                       self->callBack(NICOLIVE_EVENT_RECEVE_CONNECTRESULT,self,self->option,(NICOLIVE_PARAM)&nicoLiveThreadComment,self->chatManager.commentCount);
+                       self->callBack(NICOLIVE_EVENT_RECEVE_CONNECTRESULT,self,self->option,(NICOLIVE_PARAM)&nicoLiveThreadComment,self->chatManager.chatNo);
 
                        //chat\83m\81[\83h\82Ì\8fê\8d\87
                } else if((indexPtr = wcsstr(commentBuf,L"<chat ")) != NULL){
@@ -1933,7 +1831,7 @@ static VOID  NicoLiveParseComment(NicoLiveStream_P self,LPWSTR commentBuf,UINT_P
 
                                        }
 
-                                       extendMalloc(mailCountBuf,LPWSTR*,*mailCountBufSize,nicoLiveChat.mailCount);
+                                       extendMalloc(mailCountBuf,LPTSTR*,*mailCountBufSize,nicoLiveChat.mailCount);
 
                                        nicoLiveChat.mail = mailCountBuf;
                                        mailCountBuf[0] = NULL;
@@ -1965,11 +1863,11 @@ static VOID  NicoLiveParseComment(NicoLiveStream_P self,LPWSTR commentBuf,UINT_P
 
 
 
+                       self->chatManager.chatNo =  wcstoul(nicoLiveChat.no,NULL,10);
 
-                       self->chatManager.commentCount = wcstoul(nicoLiveChat.no,NULL,0);
 
                        
-                       (*commentCountSum)++;
+                       self->chatManager.commentCountSum++;
                        isReceveChat = TRUE;
 
                        check((_heapchk() == _HEAPOK),TEXT("\83q\81[\83v\83G\83\89\81[\82Å\82·"));
@@ -1979,7 +1877,7 @@ static VOID  NicoLiveParseComment(NicoLiveStream_P self,LPWSTR commentBuf,UINT_P
                                
                                _beginthread(NicoLiveSelfDisconnect,0,self);
                        }
-                       self->callBack(NICOLIVE_EVENT_RECEVE_CHAT,self,self->option,(NICOLIVE_PARAM)&nicoLiveChat,self->chatManager.commentCount);
+                       self->callBack(NICOLIVE_EVENT_RECEVE_CHAT,self,self->option,(NICOLIVE_PARAM)&nicoLiveChat,self->chatManager.commentCountSum);
                        
 
                        //chat_result\83m\81[\83h\82Ì\8fê\8d\87
@@ -2013,7 +1911,7 @@ static VOID  NicoLiveParseComment(NicoLiveStream_P self,LPWSTR commentBuf,UINT_P
                        }
 
                        //\83L\81[\83v\83A\83\89\83C\83u\83\8a\83Z\83b\83g
-                       WSAResetEvent(self->chatManager.setKeepAliveTimeEvent);
+                       WSASetEvent(self->chatManager.setKeepAliveTimeEvent);
 
                        self->callBack(NICOLIVE_EVENT_RECEVE_CHATSENDRESULT,self,self->option,(NICOLIVE_PARAM)&nicoLiveSendResultComment,(NICOLIVE_PARAM)NULL);
 
@@ -2022,7 +1920,7 @@ static VOID  NicoLiveParseComment(NicoLiveStream_P self,LPWSTR commentBuf,UINT_P
        }
 
        if(recvBufTmp == recvEndPoint && isReceveChat){
-               self->callBack(NICOLIVE_EVENT_RECEVE_CHATSETTLE,self,self->option,self->chatManager.commentCount,*commentCountSum);
+               self->callBack(NICOLIVE_EVENT_RECEVE_CHATSETTLE,self,self->option,self->chatManager.chatNo,self->chatManager.commentCountSum);
        }
 
 
@@ -2043,6 +1941,8 @@ static VOID  NicoLiveParseComment(NicoLiveStream_P self,LPWSTR commentBuf,UINT_P
 
 }
 
+
+
 static void NicoLiveError(void *buf){
 
        NicoLiveStream_P nl = (NicoLiveStream_P)buf;
@@ -2073,7 +1973,7 @@ static void NicoLiveSelfDisconnect(void *buf){
 
 }
 
-static INLINE SOCKET GetConectedSocket(LPCWSTR nordName,LPCWSTR port,int socktype,int addr_famiry,int protocol){
+static INLINE SOCKET GetConectedSocket(LPCTSTR nordName,LPCTSTR port,int socktype,int addr_famiry,int protocol){
 
 
        SOCKET rslt = INVALID_SOCKET;
@@ -2132,4 +2032,138 @@ static INLINE SOCKET GetConectedSocket(LPCWSTR nordName,LPCWSTR port,int socktyp
 
        return rslt;
 
+}
+
+
+//
+//\83X\83g\83\8a\81[\83\80\83X\83e\81[\83^\83X\8aÖ\98A
+//
+
+///
+///\83X\83g\83\8a\81[\83\80\83X\83e\81[\83^\83X\82ÌID\82ð\8eæ\93¾
+///
+NLIB_DECLSPEC LPCTSTR StreamStatus_getId(StreamStatus_P self){
+
+       return self->id;
+}
+
+
+///
+///\83X\83g\83\8a\81[\83\80\83X\83e\81[\83^\83X\82Ì\83R\83~\83\85\83j\83e\83B\94Ô\8d\86\82ð\8eæ\93¾
+///
+NLIB_DECLSPEC LPCTSTR StreamStatus_getDefaultCommunity(StreamStatus_P self){
+
+       return self->default_community;
+}
+
+
+///
+///\83X\83g\83\8a\81[\83\80\83X\83e\81[\83^\83X\82Ì\83v\83\8d\83o\83C\83_\83^\83C\83v\82ð\8eæ\93¾
+///
+PROVIDERTYPE StreamStatus_getProviderType(StreamStatus_P self){
+
+       return self->provider_type;
+}
+
+
+///
+///\83X\83g\83\8a\81[\83\80\83X\83e\81[\83^\83X\82Ì\83I\81[\83i\81[\83t\83\89\83O\82ð\8eæ\93¾
+///
+BOOL StreamStatus_isOwner(StreamStatus_P self){
+
+       return self->is_owner;
+}
+
+///
+///\83X\83g\83\8a\81[\83\80\83X\83e\81[\83^\83X\82Ì\8aJ\8en\8e\9e\8d\8f\82ð\8eæ\93¾
+///
+time_t StreamStatus_getStartTime(StreamStatus_P self){
+
+       return self->start_time;
+}
+
+///
+///\83X\83g\83\8a\81[\83\80\83X\83e\81[\83^\83X\82Ì\8fI\97¹\8e\9e\8d\8f\82ð\8eæ\93¾
+///
+time_t StreamStatus_getEndTime(StreamStatus_P self){
+
+       return self->end_time;
+}
+
+///
+///\83X\83g\83\8a\81[\83\80\83X\83e\81[\83^\83X\82Ì\8aJ\8fê\8e\9e\8d\8f\82ð\8eæ\93¾
+///
+time_t StreamStatus_getOpenTime(StreamStatus_P self){
+
+       return self->open_time;
+
+}
+
+///
+///\83X\83g\83\8a\81[\83\80\83X\83e\81[\83^\83X\82Ì\83x\81[\83X\8e\9e\8d\8f\82ð\8eæ\93¾
+///
+time_t StreamStatus_getBaseTime(StreamStatus_P self){
+
+       return self->base_time;
+}
+
+
+///
+///\90Ú\91±\92\86\82Ì\95ú\91\97\8fî\95ñ\82ð\96â\82¢\8d\87\82í\82¹\82é
+///
+StreamInfo_P NicoLiveStream_queryStreamInfo(NicoLiveStream_P self){
+       
+       StreamInfo_P rslt = NULL;
+       HINTERNET hRequest = NULL;
+       if(self == NULL || self->isConnecting == FALSE)goto end;
+       EnterCriticalSection(&self->sessionManager.cs);
+       {
+               TCHAR objectName[LENGTH_256] = {TEXT("/api/getplayerstatus?v=")};
+               DWORD statusCode;
+               DWORD statusCodeSize = sizeof(statusCode);
+               LPSTR recvBuffer = (LPSTR)self->sessionManager.buffer;
+               SIZE_T buflen = sizeof(self->sessionManager.buffer);
+               DWORD readSize;
+               _tcscat(objectName,self->playerStatus.stream.id);
+               
+               hRequest = WinHttpOpenRequest(hWatchLiveNicoConnect,TEXT("GET"),objectName,TEXT("1.1"),(LPCTSTR)WINHTTP_NO_REFERER,(LPCTSTR*)WINHTTP_DEFAULT_ACCEPT_TYPES,0);
+               
+
+               if(WinHttpSendRequest(hRequest,self->userSession,-1,WINHTTP_NO_REQUEST_DATA,0,0,0) == FALSE){
+                       goto connectend;
+
+               }
+
+               if(WinHttpReceiveResponse(hRequest,NULL) == FALSE){
+                       goto connectend;
+
+               }
+
+
+               if (WinHttpQueryHeaders(hRequest,WINHTTP_QUERY_STATUS_CODE | WINHTTP_QUERY_FLAG_NUMBER,WINHTTP_HEADER_NAME_BY_INDEX,&statusCode,&statusCodeSize,WINHTTP_NO_HEADER_INDEX) == FALSE){
+                       goto connectend;
+               }
+
+
+               if (HTTP_STATUS_OK != statusCode){
+                       goto connectend;
+               }
+
+
+               if(ReadHttpBody(hRequest,(LPBYTE)recvBuffer,buflen,&readSize) == FALSE){
+                       goto connectend;
+
+               }
+
+               
+       }
+       LeaveCriticalSection(&self->sessionManager.cs);
+connectend:
+       WinHttpCloseHandle(hRequest);
+
+
+end:
+       return rslt;
+
+       
 }
\ No newline at end of file