///
///\83v\83\8c\83C\83\84\81[\83X\83e\81[\83^\83X\8eæ\93¾
///
-static INLINE NLIB_RESULT GetPlayerStatus(NicoLivePlayerStatus_P pPlayerStatus,LPCWSTR liveNO,LPCWSTR userSession,HINTERNET hConnect);
+static INLINE NLIB_RESULT GetPlayerStatus(NicoLivePlayerStatus_P pPlayerStatus,LPCWSTR userSession,HINTERNET hConnect,LPVOID buffer);
///
///nicoLiveHistory\8eæ\93¾
self->chatManager.keapALiveFlag = TRUE;
+ InitializeCriticalSection(&self->sessionManager.cs);
+
dumpln(TEXT("size%d"),sizeof(NicoLiveStream));
//\8cã\8f\88\97\9d&\94j\8aü
+ DeleteCriticalSection(&(*self)->sessionManager.cs);
+
WSACloseEvent((*self)->chatManager.setHeartBeatTimeEvent);
WSACloseEvent((*self)->chatManager.setKeepAliveTimeEvent);
///
///\83n\81[\83g\83r\81[\83g\82Ì\8aÔ\8au\82ð\90Ý\92è\81i\83~\83\8a\95b)
///
-VOID SetHeartBeatMsec(NicoLiveStream_P self,DWORD msec){
+VOID NicoLiveStream_setHeartBeatMsec(NicoLiveStream_P self,DWORD msec){
WSASetEvent(self->chatManager.setHeartBeatTimeEvent);
self->chatManager.heartBeatTime = msec;
///
///\83n\81[\83g\83r\81[\83g\82Ì\8aÔ\8au\82ð\8eæ\93¾(\83~\83\8a\95b)
///
-DWORD GetHeartBeatMsec(NicoLiveStream_P self){
+DWORD NicoLiveStream_getHeartBeatMsec(NicoLiveStream_P self){
return self->chatManager.heartBeatTime;
///
///\83n\81[\83g\83r\81[\83g\97L\8cø\81E\96³\8cø\90Ý\92è
///
-VOID SetHeartBeatFlag(NicoLiveStream_P self,BOOL flag){
+VOID NicoLiveStream_setHeartBeatFlag(NicoLiveStream_P self,BOOL flag){
self->chatManager.heartBeatFlag = flag;
///
///\83n\81[\83g\83r\81[\83g\97L\8cø\83t\83\89\83O\8eæ\93¾
///
-BOOL GetHeartBeatFlag(NicoLiveStream_P self){
+BOOL NicoLiveStream_getHeartBeatFlag(NicoLiveStream_P self){
return self->chatManager.heartBeatFlag;
///
///\83L\81[\83v\83A\83\89\83C\83u\82Ì\8aÔ\8au\82ð\90Ý\92è(\83~\83\8a\95b)
///
-VOID SetKeapALiveMsec(NicoLiveStream_P self,DWORD msec){
+VOID NicoLiveStream_setKeapALiveMsec(NicoLiveStream_P self,DWORD msec){
WSASetEvent(self->chatManager.setKeepAliveTimeEvent);
self->chatManager.keepAliveTime = msec;
///
///\83L\81[\83v\83A\83\89\83C\83u\82Ì\8aÔ\8au\82ð\8eæ\93¾(\83~\83\8a\95b)
///
-DWORD GetKeapALiveMsec(NicoLiveStream_P self){
+DWORD NicoLiveStream_getKeapALiveMsec(NicoLiveStream_P self){
return self->chatManager.keepAliveTime;
///
///\83L\81[\83v\83A\83\89\83C\83u\97L\8cø\81E\96³\8cø\90Ý\92è
///
-VOID SetKeapALiveFlag(NicoLiveStream_P self,BOOL flag){
+VOID NicoLiveStream_setKeapALiveFlag(NicoLiveStream_P self,BOOL flag){
self->chatManager.keapALiveFlag = flag;
}
///
///\83L\81[\83v\83A\83\89\83C\83u\83t\83\89\83O\8eæ\93¾
///
-BOOL GetKeapALiveFlag(NicoLiveStream_P self){
+BOOL NicoLiveStream_getKeapALiveFlag(NicoLiveStream_P self){
return self->chatManager.keapALiveFlag;
LPCWSTR psrech = wcsstr(url,L"http://");
LPCWSTR pInputLiveNoEnd;
WCHAR liveNo[LIVENO_LENGTH] = {0};
- HINTERNET hWatchLiveNicVideo = NULL;
+ //HINTERNET hWatchLiveNicVideo = NULL;
//\91O\82É\82Â\82È\82¢\82Å\82¢\82½\95ú\91\97\82ð\90Ø\92f
NicoLiveStream_disConnect(self);
+ wcsncpy(self->userSession,L"Cookie: ",sizeof(self->userSession) / sizeof(self->userSession[0]) - 1);
+ wcsncat(self->userSession,nicoVideoAuth->userSession,sizeof(self->userSession) / sizeof(self->userSession[0]) - 1);
+ self->userSession[sizeof(self->userSession) / sizeof(self->userSession[0]) - 1] = L'\0';
- wcscpy(self->userSession,nicoVideoAuth->userSession);
- //watch.live.nicovideo\82É\90Ú\91±
- hWatchLiveNicVideo = WinHttpConnect(hHttpSession,WTEXT(WATCH_LIVE_NICO_VIDEO_DOMEINNAME),INTERNET_DEFAULT_HTTP_PORT,0);
+ {
+ WCHAR objectName[LENGTH_256] = {L"api/getplayerstatus?v="};
+ wcsncat(objectName,liveNo,sizeof(objectName) / sizeof(objectName[0]));
- if(hWatchLiveNicVideo == NULL){
- rslt = NLIB_ERR_WATCHLIVENICOVIDEO_FAILED_CONNECT;
- goto end;
- }
+
+ self->sessionManager.getPlayerStatusSession = WinHttpOpenRequest(hWatchLiveNicoConnect,L"GET",objectName,L"1.1",(LPCWSTR)WINHTTP_NO_REFERER,(LPCWSTR*)WINHTTP_DEFAULT_ACCEPT_TYPES,0);
+ }
//\83v\83\8c\83C\83\84\81[\83X\83e\81[\83^\83X\8eæ\93¾
- rslt = GetPlayerStatus(&self->playerStatus,liveNo,self->userSession,hWatchLiveNicVideo);
+ EnterCriticalSection(&self->sessionManager.cs);
+ rslt = GetPlayerStatus(&self->playerStatus,self->userSession,self->sessionManager.getPlayerStatusSession,self->sessionManager.buffer);
+ LeaveCriticalSection(&self->sessionManager.cs);
if(rslt != NLIB_ERR_OK){
//GetNicoLiveHistory(self,hWatchLiveNicVideo);
end:
- WinHttpCloseHandle(hWatchLiveNicVideo);
+// WinHttpCloseHandle(hWatchLiveNicVideo);
//freeChunkGlobal(chunk);
return rslt;
}
+ EnterCriticalSection(&self->sessionManager.cs);
{
- HINTERNET hWatchLiveNicoSession = NULL;
- HINTERNET hGetPlayerStatusRequest = NULL;
+ //HINTERNET hWatchLiveNicoSession = NULL;
+ //HINTERNET hGetPlayerStatusRequest = NULL;
const UINT_PTR buflen = LENGTH_65536;
- LPVOID buffer = malloc(buflen);
+ LPVOID buffer = self->sessionManager.buffer;
LPWSTR objectName = (LPWSTR)buffer;
LPWSTR indexPtr;
- LPWSTR sendBuffer = (LPWSTR)&objectName[LENGTH_4096];
- LPSTR recvBuffer;
+ //LPWSTR sendBuffer = (LPWSTR)&objectName[LENGTH_4096];
+ LPSTR recvBuffer = (LPSTR)&objectName[LENGTH_4096];
DWORD readSize;
DWORD statusCode;
DWORD statusCodeSize = sizeof(statusCode);
- hWatchLiveNicoSession = WinHttpConnect(hHttpSession,WTEXT(WATCH_LIVE_NICO_VIDEO_DOMEINNAME),INTERNET_DEFAULT_HTTP_PORT,0);
+ //hWatchLiveNicoSession = hWatchLiveNicoConnect;
wcscpy(objectName,L"/api/heartbeat?v=");
indexPtr = objectName + wcslen(objectName);
wcscpy(indexPtr,self->playerStatus.stream.id);
- wcscpy(sendBuffer,L"Cookie: ");
- indexPtr = sendBuffer + wcslen(sendBuffer);
+ //wcscpy(sendBuffer,L"Cookie: ");
+ //indexPtr = sendBuffer + wcslen(sendBuffer);
wcscpy(indexPtr,self->userSession);
-
- hGetPlayerStatusRequest = WinHttpOpenRequest(hWatchLiveNicoSession,L"GET",objectName,L"1.1",(LPCWSTR)WINHTTP_NO_REFERER,(LPCWSTR*)WINHTTP_DEFAULT_ACCEPT_TYPES,0);
-
- if(WinHttpSendRequest(hGetPlayerStatusRequest,sendBuffer,-1,WINHTTP_NO_REQUEST_DATA,0,0,0) == FALSE){
+ 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);
+
+ }
+ if(WinHttpSendRequest(self->sessionManager.heartBeatSession,self->userSession,-1,WINHTTP_NO_REQUEST_DATA,0,0,0) == FALSE){
rslt = NLIB_ERR_FAILED_NETWORK;
goto connectend;
}
- if(WinHttpReceiveResponse(hGetPlayerStatusRequest,NULL) == FALSE){
+ if(WinHttpReceiveResponse(self->sessionManager.heartBeatSession,NULL) == FALSE){
rslt = NLIB_GETPLAYERSTATUS_FAILED_CONNECT;
goto connectend;
}
- if (WinHttpQueryHeaders(hGetPlayerStatusRequest,WINHTTP_QUERY_STATUS_CODE | WINHTTP_QUERY_FLAG_NUMBER,WINHTTP_HEADER_NAME_BY_INDEX,&statusCode,&statusCodeSize,WINHTTP_NO_HEADER_INDEX) == FALSE){
+ if (WinHttpQueryHeaders(self->sessionManager.heartBeatSession,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 connectend;
}
}
- recvBuffer = (LPSTR)sendBuffer;
+ //recvBuffer = (LPSTR)sendBuffer;
- if(ReadHttpBody(hGetPlayerStatusRequest,(LPBYTE)recvBuffer,buflen,&readSize) == FALSE){
+ if(ReadHttpBody(self->sessionManager.heartBeatSession,(LPBYTE)recvBuffer,buflen,&readSize) == FALSE){
rslt = NLIB_GETPLAYERSTATUS_FAILED_CONNECT;
goto connectend;
}
-
connectend:
- free(buffer);
- WinHttpCloseHandle(hWatchLiveNicoSession);
- WinHttpCloseHandle(hGetPlayerStatusRequest);
+ ZeroMemory(self->sessionManager.buffer,sizeof(self->sessionManager.buffer));
+ LeaveCriticalSection(&self->sessionManager.cs);
+
+
+
}
end:
VOID NicoLiveStream_disConnect(NicoLiveStream_P self){
- WSAResetEvent(self->chatManager.startEvent);
- WSASetEvent(self->chatManager.endEvent);
+ while(WSAResetEvent(self->chatManager.startEvent) == FALSE);
+ while(WSASetEvent(self->chatManager.endEvent)== FALSE);
ZeroMemory(&self->playerStatus,sizeof(self->playerStatus));
WSAResetEvent(self->chatManager.endEvent);
+ WinHttpCloseHandle(self->sessionManager.getPlayerStatusSession);
+ self->sessionManager.getPlayerStatusSession = NULL;
+ WinHttpCloseHandle(self->sessionManager.heartBeatSession);
+ self->sessionManager.heartBeatSession = NULL;
NLIB_RESULT NicoLiveStream_sendChat(NicoLiveStream_P self,LPCWSTR chatbuf,LPCWSTR *mail,LPCWSTR *extends){
-
- const UINT_PTR buflen = LENGTH_65536 * 4;
- LPVOID chunk = malloc(buflen);
-
- LPSTR postKey;
- LPSTR postKeyBuf = (LPSTR)chunk;
- LPWSTR postKeyReqBuf = (LPWSTR)&postKeyBuf[NICOLIVE_SENDCHATBUFLEN];
- LPWSTR cookieBuf = &postKeyReqBuf[NICOLIVE_SENDCHATBUFLEN];
- DWORD statusCode;
- DWORD statusCodeSize = sizeof(statusCode);
- DWORD readSize;
-
- HINTERNET hWatchLiveNicoVideo = NULL;
- HINTERNET hGetPostKeySession = NULL;
NLIB_RESULT rslt = NLIB_ERR_OK;
+ EnterCriticalSection(&self->sessionManager.cs);
+ {
+ const UINT_PTR buflen = LENGTH_65536 * 4;
+ LPVOID chunk = self->sessionManager.buffer;
- if(chatbuf == NULL || wcslen(chatbuf) >= LENGTH_1024){
-
- rslt = NLIB_ERR_BUFFER_TOOLITTLE;
- goto end;
-
- }
-
-
- //postkey\8eæ\93¾
- _swprintf(postKeyReqBuf,L"api/getpostkey?thread=%u&block_no=%u",self->playerStatus.ms.thread,self->chatManager.commentCount / 100);
+ LPSTR postKey;
+ LPSTR postKeyBuf = (LPSTR)chunk;
+ LPWSTR postKeyReqBuf = (LPWSTR)&postKeyBuf[NICOLIVE_SENDCHATBUFLEN];
+ LPWSTR cookieBuf = &postKeyReqBuf[NICOLIVE_SENDCHATBUFLEN];
+ DWORD statusCode;
+ DWORD statusCodeSize = sizeof(statusCode);
+ DWORD readSize;
- hWatchLiveNicoVideo = WinHttpConnect(hHttpSession,WTEXT(WATCH_LIVE_NICO_VIDEO_DOMEINNAME),INTERNET_DEFAULT_HTTP_PORT,0);
- hGetPostKeySession = WinHttpOpenRequest(hWatchLiveNicoVideo,L"GET",postKeyReqBuf,L"1.1",(LPCWSTR)WINHTTP_NO_REFERER,(LPCWSTR*)WINHTTP_DEFAULT_ACCEPT_TYPES,0);
+ //HINTERNET hWatchLiveNicoVideo = NULL;
+ HINTERNET hGetPostKeySession = NULL;
+
+ if(chatbuf == NULL || wcslen(chatbuf) >= LENGTH_1024){
- //_swprintf(cookieBuf,L"Cookie: %s; %s",self->userSession,self->nicoLiveHistory);
- _swprintf(cookieBuf,L"Cookie: %s",self->userSession);
+ rslt = NLIB_ERR_BUFFER_TOOLITTLE;
+ goto end;
- if(WinHttpSendRequest(hGetPostKeySession,cookieBuf,-1,WINHTTP_NO_REQUEST_DATA,0,0,0) == FALSE){
+ }
- rslt = NLIB_GETPLAYERSTATUS_FAILED_CONNECT;
- goto end;
- }
+ //postkey\8eæ\93¾
+ _swprintf(postKeyReqBuf,L"api/getpostkey?thread=%u&block_no=%u",self->playerStatus.ms.thread,self->chatManager.commentCount / 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);
- if(WinHttpReceiveResponse(hGetPostKeySession,NULL) == FALSE){
- rslt = NLIB_GETPLAYERSTATUS_FAILED_CONNECT;
- goto end;
+ //_swprintf(cookieBuf,L"Cookie: %s; %s",self->userSession,self->nicoLiveHistory);
+ _swprintf(cookieBuf,L"Cookie: %s",self->userSession);
- }
+ if(WinHttpSendRequest(hGetPostKeySession,self->userSession,-1,WINHTTP_NO_REQUEST_DATA,0,0,0) == FALSE){
+ rslt = NLIB_GETPLAYERSTATUS_FAILED_CONNECT;
+ goto end;
- 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;
- }
+ }
- if (HTTP_STATUS_OK != statusCode){
- rslt = NLIB_GETPLAYERSTATUS_FAILED_CONNECT;
- goto end;
- }
+ if(WinHttpReceiveResponse(hGetPostKeySession,NULL) == FALSE){
+ rslt = NLIB_GETPLAYERSTATUS_FAILED_CONNECT;
+ goto end;
+ }
+ 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;
+ }
- if(ReadHttpBody(hGetPostKeySession,(LPBYTE)postKeyBuf,buflen,&readSize) == FALSE){
- rslt = NLIB_GETPLAYERSTATUS_FAILED_CONNECT;
- goto end;
+ if (HTTP_STATUS_OK != statusCode){
+ rslt = NLIB_GETPLAYERSTATUS_FAILED_CONNECT;
+ goto end;
+ }
- }
- postKeyBuf[readSize] = '\0';
- postKey = strstr(postKeyBuf,"=") + 1;
- {
- LPSTR buffer = (LPSTR)&cookieBuf[NICOLIVE_SENDCHATBUFLEN];
- LPSTR indexPtr;
- LPSTR mailBuf;
- LPSTR extendBuf;
-
- //mail\83R\83}\83\93\83h\8dì\90¬
- if(mail == NULL){
- mailBuf = "";
- } else {
- INT_PTR len;
- mailBuf = (LPSTR)postKeyReqBuf;
- indexPtr = mailBuf;
- strcpy(indexPtr,"mail=\"");
- indexPtr += strlen(indexPtr);
+ if(ReadHttpBody(hGetPostKeySession,(LPBYTE)postKeyBuf,buflen,&readSize) == FALSE){
- len = NICOLIVE_SENDCHATBUFLEN - (indexPtr - mailBuf) - 1;
- if(GetLenToMB(CP_UTF8,mail[0]) >= len){
- rslt = NLIB_ERR_BUFFER_TOOLITTLE;
- goto end;
-
- }
+ rslt = NLIB_GETPLAYERSTATUS_FAILED_CONNECT;
+ goto end;
- WideToMB(CP_UTF8,mail[0],indexPtr,len);
- indexPtr += strlen(indexPtr);
+ }
+ postKeyBuf[readSize] = '\0';
+ postKey = strstr(postKeyBuf,"=") + 1;
- for(mail++;mail[0] != NULL;mail++){
+ {
+ LPSTR buffer = (LPSTR)&cookieBuf[NICOLIVE_SENDCHATBUFLEN];
+ LPSTR indexPtr;
+ LPSTR mailBuf;
+ LPSTR extendBuf;
+
+ //mail\83R\83}\83\93\83h\8dì\90¬
+ if(mail == NULL){
- indexPtr[0] = ' ';
- indexPtr++;
+ mailBuf = "";
- len = NICOLIVE_SENDCHATBUFLEN - (indexPtr - mailBuf) - 1;
+ } else {
+ INT_PTR len;
+ mailBuf = (LPSTR)postKeyReqBuf;
+ indexPtr = mailBuf;
+ strcpy(indexPtr,"mail=\"");
+ indexPtr += strlen(indexPtr);
+ len = NICOLIVE_SENDCHATBUFLEN - (indexPtr - mailBuf) - 1;
if(GetLenToMB(CP_UTF8,mail[0]) >= len){
rslt = NLIB_ERR_BUFFER_TOOLITTLE;
goto end;
WideToMB(CP_UTF8,mail[0],indexPtr,len);
indexPtr += strlen(indexPtr);
- }
- strcpy(indexPtr,"\"");
+ for(mail++;mail[0] != NULL;mail++){
+ indexPtr[0] = ' ';
+ indexPtr++;
+ len = NICOLIVE_SENDCHATBUFLEN - (indexPtr - mailBuf) - 1;
- }
+ if(GetLenToMB(CP_UTF8,mail[0]) >= len){
+ rslt = NLIB_ERR_BUFFER_TOOLITTLE;
+ goto end;
- //\8ag\92£\91®\90«\8dì\90¬
- if(extends == NULL){
+ }
- extendBuf = "";
+ WideToMB(CP_UTF8,mail[0],indexPtr,len);
+ indexPtr += strlen(indexPtr);
- } else {
- INT_PTR len;
- extendBuf =(LPSTR)cookieBuf;
- indexPtr = extendBuf;
+ }
+ strcpy(indexPtr,"\"");
- len = NICOLIVE_SENDCHATBUFLEN - (indexPtr - extendBuf) - 1;
- if(GetLenToMB(CP_UTF8,extends[0]) >= len){
- rslt = NLIB_ERR_BUFFER_TOOLITTLE;
- goto end;
}
- WideToMB(CP_UTF8,extends[0],indexPtr,len);
-
- indexPtr += strlen(indexPtr);
- strcpy(indexPtr,"=\"");
- indexPtr += strlen(indexPtr);
+ //\8ag\92£\91®\90«\8dì\90¬
+ if(extends == NULL){
+ extendBuf = "";
- len = NICOLIVE_SENDCHATBUFLEN - (indexPtr - extendBuf) - 1;
-
- if(GetLenToMB(CP_UTF8,extends[1]) >= len){
- rslt = NLIB_ERR_BUFFER_TOOLITTLE;
- goto end;
-
- }
- WideToMB(CP_UTF8,extends[1],indexPtr,len);
+ } else {
+ INT_PTR len;
+ extendBuf =(LPSTR)cookieBuf;
+ indexPtr = extendBuf;
- for(extends+= 2;extends[0] != NULL;extends+=2){
-
- indexPtr[0] = ' ';
- indexPtr++;
-
len = NICOLIVE_SENDCHATBUFLEN - (indexPtr - extendBuf) - 1;
if(GetLenToMB(CP_UTF8,extends[0]) >= len){
indexPtr += strlen(indexPtr);
- indexPtr[0] = '=';
- indexPtr++;
+ strcpy(indexPtr,"=\"");
+ indexPtr += strlen(indexPtr);
len = NICOLIVE_SENDCHATBUFLEN - (indexPtr - extendBuf) - 1;
WideToMB(CP_UTF8,extends[1],indexPtr,len);
+ for(extends+= 2;extends[0] != NULL;extends+=2){
- }
- indexPtr += strlen(indexPtr);
- strcpy(indexPtr,"\"");
+ indexPtr[0] = ' ';
+ indexPtr++;
+ len = NICOLIVE_SENDCHATBUFLEN - (indexPtr - extendBuf) - 1;
+ if(GetLenToMB(CP_UTF8,extends[0]) >= len){
+ rslt = NLIB_ERR_BUFFER_TOOLITTLE;
+ goto end;
- }
+ }
+ WideToMB(CP_UTF8,extends[0],indexPtr,len);
- //\83`\83\83\83b\83g\91\97\90M\83R\83\81\83\93\83g\8dì\90¬
- {
- indexPtr = buffer;
- //\96{\93\96\82Í\82±\82¤\82µ\82½\82¢:"<chat thread=\"%d\" ticket=\"%S\" postkey=\"%s\" user_id=\"%S\" premium=\"%d\" locale=\"%S\" vpos=\"%ld\"%s>%S</chat>"
- strcpy(indexPtr,"<chat thread=\"");
- indexPtr += strlen(indexPtr);
- sprintf(indexPtr,"%u",self->playerStatus.ms.thread);
- indexPtr += strlen(indexPtr);
- strcpy(indexPtr,"\" ticket=\"");
- indexPtr += strlen(indexPtr);
- WideToMB(CP_UTF8,self->ticket,indexPtr,NICOLIVE_SENDCHATBUFLEN - (indexPtr - buffer) - 1);
- indexPtr += strlen(indexPtr);
- strcpy(indexPtr,"\" postkey=\"");
- indexPtr += strlen(indexPtr);
- strcpy(indexPtr,postKey);
- indexPtr += strlen(indexPtr);
- strcpy(indexPtr,"\" user_id=\"");
- indexPtr += strlen(indexPtr);
- WideToMB(CP_UTF8,self->playerStatus.user.user_id,indexPtr,NICOLIVE_SENDCHATBUFLEN - (indexPtr - buffer) - 1);
- indexPtr += strlen(indexPtr);
- strcpy(indexPtr,"\" premium=\"");
- indexPtr += strlen(indexPtr);
- sprintf(indexPtr,"%u",self->playerStatus.user.is_premium);
- indexPtr += strlen(indexPtr);
- strcpy(indexPtr,"\" locale=\"");
- indexPtr += strlen(indexPtr);
- WideToMB(CP_UTF8,self->playerStatus.user.userDomain,indexPtr,NICOLIVE_SENDCHATBUFLEN - (indexPtr - buffer) - 1);
- indexPtr += strlen(indexPtr);
- strcpy(indexPtr,"\" vpos=\"");
- indexPtr += strlen(indexPtr);
+ indexPtr += strlen(indexPtr);
+
+ indexPtr[0] = '=';
+ indexPtr++;
+
+
+ len = NICOLIVE_SENDCHATBUFLEN - (indexPtr - extendBuf) - 1;
+
+ if(GetLenToMB(CP_UTF8,extends[1]) >= len){
+ rslt = NLIB_ERR_BUFFER_TOOLITTLE;
+ goto end;
+
+ }
+ WideToMB(CP_UTF8,extends[1],indexPtr,len);
+
+
+
+ }
+ indexPtr += strlen(indexPtr);
+ strcpy(indexPtr,"\"");
+
+
+
+ }
+
+ //\83`\83\83\83b\83g\91\97\90M\83R\83\81\83\93\83g\8dì\90¬
+ {
+ indexPtr = buffer;
+ //\96{\93\96\82Í\82±\82¤\82µ\82½\82¢:"<chat thread=\"%d\" ticket=\"%S\" postkey=\"%s\" user_id=\"%S\" premium=\"%d\" locale=\"%S\" vpos=\"%ld\"%s>%S</chat>"
+ strcpy(indexPtr,"<chat thread=\"");
+ indexPtr += strlen(indexPtr);
+ sprintf(indexPtr,"%u",self->playerStatus.ms.thread);
+ indexPtr += strlen(indexPtr);
+ strcpy(indexPtr,"\" ticket=\"");
+ indexPtr += strlen(indexPtr);
+ WideToMB(CP_UTF8,self->ticket,indexPtr,NICOLIVE_SENDCHATBUFLEN - (indexPtr - buffer) - 1);
+ indexPtr += strlen(indexPtr);
+ strcpy(indexPtr,"\" postkey=\"");
+ indexPtr += strlen(indexPtr);
+ strcpy(indexPtr,postKey);
+ indexPtr += strlen(indexPtr);
+ strcpy(indexPtr,"\" user_id=\"");
+ indexPtr += strlen(indexPtr);
+ WideToMB(CP_UTF8,self->playerStatus.user.user_id,indexPtr,NICOLIVE_SENDCHATBUFLEN - (indexPtr - buffer) - 1);
+ indexPtr += strlen(indexPtr);
+ strcpy(indexPtr,"\" premium=\"");
+ indexPtr += strlen(indexPtr);
+ sprintf(indexPtr,"%u",self->playerStatus.user.is_premium);
+ indexPtr += strlen(indexPtr);
+ strcpy(indexPtr,"\" locale=\"");
+ indexPtr += strlen(indexPtr);
+ WideToMB(CP_UTF8,self->playerStatus.user.userDomain,indexPtr,NICOLIVE_SENDCHATBUFLEN - (indexPtr - buffer) - 1);
+ indexPtr += strlen(indexPtr);
+ strcpy(indexPtr,"\" vpos=\"");
+ indexPtr += strlen(indexPtr);
- timeBeginPeriod(1);
- sprintf(indexPtr,"%u",(self->chatManager.baseVpos + ((timeGetTime() - self->chatManager.commentStartTime) / 10)));
- timeEndPeriod(1);
+ timeBeginPeriod(1);
+ sprintf(indexPtr,"%u",(self->chatManager.baseVpos + ((timeGetTime() - self->chatManager.commentStartTime) / 10)));
+ timeEndPeriod(1);
- indexPtr += strlen(indexPtr);
- strcpy(indexPtr,"\"");
- indexPtr += strlen(indexPtr);
+ indexPtr += strlen(indexPtr);
+ strcpy(indexPtr,"\"");
+ indexPtr += strlen(indexPtr);
- if(strlen(mailBuf) > 0 && strlen(extendBuf) > 0){
+ if(strlen(mailBuf) > 0 && strlen(extendBuf) > 0){
- indexPtr[0] = ' ';
- indexPtr++;
- strcpy(indexPtr,mailBuf);
- indexPtr += strlen(indexPtr);
+ indexPtr[0] = ' ';
+ indexPtr++;
+ strcpy(indexPtr,mailBuf);
+ indexPtr += strlen(indexPtr);
- indexPtr[0] = ' ';
- indexPtr++;
+ indexPtr[0] = ' ';
+ indexPtr++;
- strcpy(indexPtr,extendBuf);
- indexPtr += strlen(indexPtr);
+ strcpy(indexPtr,extendBuf);
+ indexPtr += strlen(indexPtr);
- } else if(strlen(mailBuf) > 0){
- indexPtr[0] = ' ';
- indexPtr++;
- strcpy(indexPtr,mailBuf);
- indexPtr += strlen(indexPtr);
+ } else if(strlen(mailBuf) > 0){
+ indexPtr[0] = ' ';
+ indexPtr++;
+ strcpy(indexPtr,mailBuf);
+ indexPtr += strlen(indexPtr);
- } else if(strlen(extendBuf) > 0){
- indexPtr[0] = ' ';
- indexPtr++;
- strcpy(indexPtr,extendBuf);
+ } else if(strlen(extendBuf) > 0){
+ indexPtr[0] = ' ';
+ indexPtr++;
+ strcpy(indexPtr,extendBuf);
+ indexPtr += strlen(indexPtr);
+ }
+ strcpy(indexPtr,">");
indexPtr += strlen(indexPtr);
- }
- 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);
-
- for(;(chatbuf) <= (endPtr);(chatbuf)++){
- switch(chatbuf[0]){
- case L'&':
- wcscpy((sendBuf),L"&");
- (sendBuf) += wcslen(sendBuf);
- break;
- case L'<':
- wcscpy((sendBuf),L"<");
- (sendBuf) += wcslen(sendBuf);
- break;
- case L'>':
- wcscpy((sendBuf),L">");
- (sendBuf) += wcslen(sendBuf);
- break;
- case L'\"':
- wcscpy((sendBuf),L""");
- (sendBuf) += wcslen(sendBuf);
- break;
- case L'\'':
- wcscpy((sendBuf),L"'");
- (sendBuf) += wcslen(sendBuf);
- break;
- default:
- sendBuf[0] = chatbuf[0];
- (sendBuf)++;
- break;
+ {
+ LPWSTR sendBuf = (LPWSTR)&buffer[NICOLIVE_SENDCHATBUFLEN * 4];
+ LPWSTR sendPtr = sendBuf;
+ LPCWSTR endPtr= chatbuf + wcslen(chatbuf);
+
+
+ //convertTEXT(indexPtr,chatbuf,indexPtr,endPtr);
+
+ for(;(chatbuf) <= (endPtr);(chatbuf)++){
+ switch(chatbuf[0]){
+ case L'&':
+ wcscpy((sendBuf),L"&");
+ (sendBuf) += wcslen(sendBuf);
+ break;
+ case L'<':
+ wcscpy((sendBuf),L"<");
+ (sendBuf) += wcslen(sendBuf);
+ break;
+ case L'>':
+ wcscpy((sendBuf),L">");
+ (sendBuf) += wcslen(sendBuf);
+ break;
+ case L'\"':
+ wcscpy((sendBuf),L""");
+ (sendBuf) += wcslen(sendBuf);
+ break;
+ case L'\'':
+ wcscpy((sendBuf),L"'");
+ (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);
+ WideToMB(CP_UTF8,sendPtr,indexPtr,NICOLIVE_SENDCHATBUFLEN * 4 - (indexPtr - buffer) - 1);
+ indexPtr += strlen(indexPtr);
- }
- strcpy(indexPtr,"</chat>");
- indexPtr[strlen(indexPtr)] = '\0';
+ }
+ strcpy(indexPtr,"</chat>");
+ indexPtr[strlen(indexPtr)] = '\0';
- {
- INT_PTR sendLen = 0;
- INT_PTR sentLen = 0;
- INT_PTR max = strlen(buffer) + 1;
+ {
+ INT_PTR sendLen = 0;
+ INT_PTR sentLen = 0;
+ INT_PTR max = strlen(buffer) + 1;
- do{
- sendLen = send(self->chatManager.sock,buffer,max - sentLen,0);
- sentLen += sendLen;
- } while(sendLen > 0);
+ do{
+ sendLen = send(self->chatManager.sock,buffer,max - sentLen,0);
+ sentLen += sendLen;
+ } while(sendLen > 0);
+ }
}
}
+
+end:
+
+ WinHttpCloseHandle(hGetPostKeySession);
+ ZeroMemory(self->sessionManager.buffer,sizeof(self->sessionManager.buffer));
+ LeaveCriticalSection(&self->sessionManager.cs);
}
-
-end:
- free(chunk);
- WinHttpCloseHandle(hGetPostKeySession);
- WinHttpCloseHandle(hWatchLiveNicoVideo);
-
return rslt;
}
-NLIB_RESULT GetPlayerStatus(NicoLivePlayerStatus_P self,LPCWSTR liveNo,LPCWSTR userSession,HINTERNET hConnect){
+NLIB_RESULT GetPlayerStatus(NicoLivePlayerStatus_P self,LPCWSTR 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 = NULL;
- LPWSTR sendBuffer;
- LPSTR recvBuffer;
- DWORD readSize;
- DWORD statusCode;
- DWORD statusCodeSize = sizeof(statusCode);
-
-#define GETPLAYERSTATUS_OBJECTNAME_LENGTH LENGTH_256
-
- WCHAR objectName[GETPLAYERSTATUS_OBJECTNAME_LENGTH] = {L"api/getplayerstatus?v="};
- const SIZE_T objectNameLen = wcslen(objectName);
- LPWSTR liveNoTmp = &objectName[objectNameLen];
-
- if(wcslen(liveNo) > GETPLAYERSTATUS_OBJECTNAME_LENGTH - objectNameLen - 1){
-
- rslt = NLIB_LIVENO_FAILED_TOOBIG;
- goto end;
-
- } else if(wcslen(userSession) > LENGTH_4096){
-
- rslt = NLIB_USERSESSION_FAILED_TOOBIG;
- goto end;
-
- }
-
-
- buffer = malloc(buflen);
- sendBuffer = (LPWSTR)buffer;
- wcscpy(sendBuffer,L"Cookie: ");
- wcscat(sendBuffer,userSession);
-
-
- wcscpy(liveNoTmp,liveNo);
-
- if(hConnect == NULL){
- hWatchLiveNicoSession = WinHttpConnect(hHttpSession,WTEXT(WATCH_LIVE_NICO_VIDEO_DOMEINNAME),INTERNET_DEFAULT_HTTP_PORT,0);
- } else {
-
- hWatchLiveNicoSession = hConnect;
+
+ {
+ //HINTERNET hWatchLiveNicoSession = NULL;
+ //HINTERNET hGetPlayerStatusRequest = NULL;
+ const UINT_PTR buflen = LENGTH_65536;
+ //LPVOID buffer = ;
+ //LPWSTR sendBuffer;
+ LPSTR recvBuffer = (LPSTR)buffer;
+ DWORD readSize;
+ DWORD statusCode;
+ DWORD statusCodeSize = sizeof(statusCode);
- }
- hGetPlayerStatusRequest = WinHttpOpenRequest(hWatchLiveNicoSession,L"GET",objectName,L"1.1",(LPCWSTR)WINHTTP_NO_REFERER,(LPCWSTR*)WINHTTP_DEFAULT_ACCEPT_TYPES,0);
+
- if(WinHttpSendRequest(hGetPlayerStatusRequest,sendBuffer,-1,WINHTTP_NO_REQUEST_DATA,0,0,0) == FALSE){
+ if(WinHttpSendRequest(hConnect,userSession,-1,WINHTTP_NO_REQUEST_DATA,0,0,0) == FALSE){
- rslt = NLIB_GETPLAYERSTATUS_FAILED_CONNECT;
- goto end;
+ rslt = NLIB_GETPLAYERSTATUS_FAILED_CONNECT;
+ goto end;
- }
+ }
- if(WinHttpReceiveResponse(hGetPlayerStatusRequest,NULL) == FALSE){
+ if(WinHttpReceiveResponse(hConnect,NULL) == FALSE){
- rslt = NLIB_GETPLAYERSTATUS_FAILED_CONNECT;
- goto end;
+ rslt = NLIB_GETPLAYERSTATUS_FAILED_CONNECT;
+ goto end;
- }
+ }
- if (WinHttpQueryHeaders(hGetPlayerStatusRequest,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;
- }
+ if (WinHttpQueryHeaders(hConnect,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;
+ }
- if (HTTP_STATUS_OK != statusCode){
- rslt = NLIB_GETPLAYERSTATUS_FAILED_CONNECT;
- goto end;
- }
+ if (HTTP_STATUS_OK != statusCode){
+ rslt = NLIB_GETPLAYERSTATUS_FAILED_CONNECT;
+ goto end;
+ }
- recvBuffer = (LPSTR)sendBuffer;
+ //recvBuffer = (LPSTR)sendBuffer;
- if(ReadHttpBody(hGetPlayerStatusRequest,(LPBYTE)recvBuffer,buflen,&readSize) == FALSE){
+ if(ReadHttpBody(hConnect,(LPBYTE)recvBuffer,buflen,&readSize) == FALSE){
- rslt = NLIB_GETPLAYERSTATUS_FAILED_CONNECT;
- goto end;
+ rslt = NLIB_GETPLAYERSTATUS_FAILED_CONNECT;
+ goto end;
- }
+ }
- recvBuffer[readSize] = '\0';
+ recvBuffer[readSize] = '\0';
- recvBuffer = strstr(recvBuffer,"<");
+ recvBuffer = strstr(recvBuffer,"<");
- dumpln_mb(CP_UTF8,"%s",recvBuffer);
+ dumpln_mb(CP_UTF8,"%s",recvBuffer);
- XMLParse(self,recvBuffer,NPlayerStatus_ElementStartHandler,NPlayerStatus_ElementEndHandler,NPlayerStatus_CharacterDataHandler);
- rslt = self->error;
- if(rslt != NLIB_ERR_OK){
+ XMLParse(self,recvBuffer,NPlayerStatus_ElementStartHandler,NPlayerStatus_ElementEndHandler,NPlayerStatus_CharacterDataHandler);
+ rslt = self->error;
+ if(rslt != NLIB_ERR_OK){
- goto end;
+ goto end;
+ }
}
-
end:
- 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é
- if(hConnect == NULL){
- WinHttpCloseHandle(hWatchLiveNicoSession);
- }
+
return rslt;
NLIB_RESULT rslt = NLIB_ERR_OK;
- HINTERNET hNicoVideoConnect = NULL;
+ EnterCriticalSection(&self->sessionManager.cs);
+ {
+ //HINTERNET hNicoVideoConnect = NULL;
HINTERNET hStreamBrowse = NULL;
DWORD statusCode;
DWORD statusCodeSize = sizeof(statusCode);
DWORD chunkSize = LENGTH_65536;
- LPVOID chunkMemory = malloc(chunkSize);
+ LPVOID chunkMemory =self->sessionManager.buffer;
wcscat(objectName,self->playerStatus.stream.id);
wcscat(cookie,self->userSession);
- if(hConnect == NULL){
-
- hNicoVideoConnect = WinHttpConnect(hHttpSession,WTEXT(WATCH_LIVE_NICO_VIDEO_DOMEINNAME),INTERNET_DEFAULT_HTTP_PORT,0);
-
- } else {
+
- hNicoVideoConnect = hConnect;
+ //hNicoVideoConnect = hConnect;
- }
+
hStreamBrowse = WinHttpOpenRequest(hNicoVideoConnect,L"GET",objectName,L"1.1",(LPCWSTR)WINHTTP_NO_REFERER,(LPCWSTR*)WINHTTP_DEFAULT_ACCEPT_TYPES,0);
}
end:
- free(chunkMemory);
- WinHttpCloseHandle(hStreamBrowse);
-
- if(hConnect == NULL){
- WinHttpCloseHandle(hNicoVideoConnect);
+ WinHttpCloseHandle(hStreamBrowse);
}
+ ZeroMemory(self->sessionManager.buffer,sizeof(self->sessionManager.buffer));
+ LeaveCriticalSection(&self->sessionManager.cs);
return rslt;
DWORD endResult;
while(TRUE){
-
+restart:
WSASetEvent(self->chatManager.resetEvents[2]);
dwResult = WSAWaitForMultipleEvents(sizeof(events) / sizeof(events[0]),events,FALSE,WSA_INFINITE,FALSE);
goto end;
case 1:
+ WSAResetEvent(self->chatManager.resetEvents[2]);
break;
case 2:
switch(endResult - WSA_WAIT_EVENT_0){
case 0:
- goto loopend;
+ goto restart;
case 1:
break;
}
}
}
-loopend:;
+
}
DWORD endResult;
while(TRUE){
-
+restart:
WSASetEvent(self->chatManager.resetEvents[1]);
dwResult = WSAWaitForMultipleEvents(sizeof(events) / sizeof(events[0]),events,FALSE,WSA_INFINITE,FALSE);
goto end;
case 1:
+ WSAResetEvent(self->chatManager.resetEvents[1]);
break;
case 2:
switch(endResult - WSA_WAIT_EVENT_0){
case 0:
- goto loopend;
+ goto restart;
case 1:
break;
}
}
}
-loopend:;
+
goto end;
case 1:
+ WSAResetEvent(self->chatManager.resetEvents[0]);
break;
case 2:
(*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){
+ if((wcscmp(nicoLiveChat.chatBuf,L"/disconnect") == 0 && wcscmp(nicoLiveChat.premium,L"2") == 0)){
+
_beginthread(NicoLiveSelfDisconnect,0,self);
}
+ self->callBack(NICOLIVE_EVENT_RECEVE_CHAT,self,self->option,(NICOLIVE_PARAM)&nicoLiveChat,self->chatManager.commentCount);
+
//chat_result\83m\81[\83h\82Ì\8fê\8d\87
} else if((indexPtr = wcsstr(commentBuf,L"<chat_result ")) != NULL){
skipXMLSPACE(indexPtr);
}
+ //\83L\81[\83v\83A\83\89\83C\83u\83\8a\83Z\83b\83g
+ WSAResetEvent(self->chatManager.setKeepAliveTimeEvent);
+
self->callBack(NICOLIVE_EVENT_RECEVE_CHATSENDRESULT,self,self->option,(NICOLIVE_PARAM)&nicoLiveSendResultComment,(NICOLIVE_PARAM)NULL);
}
NicoLiveStream_P nl = (NicoLiveStream_P)buf;
-
+ dumpln(TEXT("selfdisconnect"),);
NicoLiveStream_disConnect(nl);