OSDN Git Service

2011/10/30 18:16:19
authorqwerty2501 <riot313@gmail.com>
Sun, 30 Oct 2011 09:16:19 +0000 (18:16 +0900)
committerqwerty2501 <riot313@gmail.com>
Sun, 30 Oct 2011 09:16:19 +0000 (18:16 +0900)
include/qwerty/qwerty_common.h
nlib/nlib.h
nlib/nlib_myList.c
nlib/nlib_nicoLive.c
nlib_driver/nlib_driver.cpp

index 262a1c2..e012f6f 100644 (file)
@@ -15,7 +15,7 @@
 #define MBToWide(encode,inputBuffer,rsltBuffer,len) MultiByteToWideChar(encode,0,inputBuffer,strlen(inputBuffer) + 1,rsltBuffer,len)
 
 
-
+#define ARRAY_LENGTH(arr)      (sizeof(arr) / sizeof(arr[0]))
 
 
 
@@ -29,10 +29,11 @@ typedef struct  {
 #define DOWNNORD(nord) ((nord) << 8)
 #define UPNORD(nord)   ((nord) >> 8)
 
-#define MAKENORD(child1)                                                                               (child1)
-#define MAKENORD1(child1,child2)                                                               (((child1) << 8) | (child2))
-#define MAKENORD2(child1,child2,child3)                                                        (((child1) << 16) | ((child2) << 8 ) | (child3))
-#define MAKENORD3(child1,child2,child3,child4)                                 (((child1) << 24) | ((child2) << 16 ) | ((child3) << 8) | (child4))
+#define MAKENORD(child1)                                                                               ((UINT64)((UINT64)child1))
+#define MAKENORD1(child1,child2)                                                               ((UINT64)((((UINT64)child1) << 8) | ((UINT64)child2)))
+#define MAKENORD2(child1,child2,child3)                                                        ((UINT64)((((UINT64)child1) << 16) | (((UINT64)child2) << 8 ) | ((UINT64)child3)))
+#define MAKENORD3(child1,child2,child3,child4)                                 ((UINT64)((((UINT64)child1) << 24) | (((UINT64)child2) << 16 ) | (((UINT64)child3) << 8) | ((UINT64)child4)))
+#define MAKENORD4(child1,child2,child3,child4,child5)                  ((UINT64)((((UINT64)child1) << 32) | (((UINT64)child2) << 24 ) | (((UINT64)child3) << 16) | (((UINT64)child4) << 8) | ((UINT64)child5)))
 
 #define LENGTH_2               ((UINT_PTR)2)
 #define LENGTH_4               ((UINT_PTR)4)
index f608b2d..ee4fa6e 100644 (file)
@@ -43,6 +43,12 @@ typedef UINT_PTR             NICOLIVE_EVENT;
 typedef UINT_PTR               NICOLIVE_PARAM;
 
 
+///
+///NicoMyList\82Ì\83R\81[\83\8b\83o\83b\83N\8aÖ\90\94\82Ì\83C\83x\83\93\83g\83^\83C\83v\8c^
+///
+typedef UINT_PTR               NICOMYLIST_EVENT;
+
+
 
 
 ///
@@ -97,7 +103,7 @@ typedef NLIB_RESULT (*NicoRecvCallBack)(NICOLIVE_EVENT eventType,NicoLiveStream_
 ///
 ///\83j\83R\83j\83R\83}\83C\83\8a\83X\83g\83C\83x\83\93\83g\83n\83\93\83h\83\89
 ///
-typedef NLIB_RESULT (*NicoMyListCallBack)(LPVOID option,NicoMyListItem_P pVideo,NLIB_RESULT rslt);
+typedef NLIB_RESULT (*NicoMyListCallBack)(LPVOID option,NicoMyListItem_P pVideo);
 
 
 
@@ -311,7 +317,7 @@ extern "C" {
        ///
        ///\82Æ\82è\82 \82¦\82¸\83}\83C\83\8a\83X\83g\88ê\97\97\8eæ\93¾
        ///
-       NLIB_DECLSPEC NLIB_RESULT NicoMyList_getDefList(NicoVideoAuth_P pAuth,NicoMyListCallBack callback,BOOL mtFlag,LPVOID option);
+       NLIB_DECLSPEC NLIB_RESULT NicoMyList_getDefList(NicoVideoAuth_P pAuth,NicoMyListCallBack callback,LPVOID option);
 
 
 
index 2f4bf2f..26be583 100644 (file)
@@ -16,14 +16,14 @@ typedef struct {
        NLIB_RESULT errcode;
        NicoMyListItem_P pitem;
        LPVOID option;
-
+       NicoMyListCallBack callBack;
 
 }NicoMyListItemContainer,*NicoMyListItemContainer_P;
 
 ///
 ///\83}\83C\83\8a\83X\83g\88ê\97\97\8eæ\93¾\8b¤\92Ê\8f\88\97\9d
 ///
-static NLIB_RESULT NicoMyList_getList(NicoVideoAuth_P pAuth,LPCWSTR objectName,NicoMyListCallBack callback,BOOL mtFlag,LPVOID option);
+static NLIB_RESULT NicoMyList_getList(NicoVideoAuth_P pAuth,LPCWSTR objectName,NicoMyListCallBack callback,LPVOID option);
 
 static NicoMyListItem_P NicoMyListItem_new();
 
@@ -37,16 +37,22 @@ static JSONVoid myListItemDataEndEventHandler(JSONVoid *option,JSONUInt thisHier
 
 static VOID CALLBACK myListItemCallBack(HINTERNET handle,DWORD_PTR context,DWORD code,LPVOID info,DWORD length);
 
-static NLIB_RESULT recvMyList(HINTERNET hGetMyList,NicoMyListItemContainer_P itemContainer,NLIB_RESULT rslt);
+static NLIB_RESULT jsonStrCpy(LPWSTR buf,LPCWSTR in,SIZE_T size);
+
 
+
+//
+//\83}\83N\83\8d
+//
+#define jsonToArray(arr,in) jsonStrCpy((arr),(in),sizeof(arr) / sizeof(arr[0]))
 ///
 ///\82Æ\82è\82 \82¦\82¸\83}\83C\83\8a\83X\83g\88ê\97\97\8eæ\93¾
 ///
-NLIB_RESULT NicoMyList_getDefList(NicoVideoAuth_P pAuth,NicoMyListCallBack callback,BOOL mtFlag,LPVOID option){
+NLIB_RESULT NicoMyList_getDefList(NicoVideoAuth_P pAuth,NicoMyListCallBack callback,LPVOID option){
 
        NLIB_RESULT rslt = NLIB_ERR_OK;
 
-       rslt = NicoMyList_getList(pAuth,L"api/deflist/list",callback,mtFlag,option);
+       rslt = NicoMyList_getList(pAuth,L"api/deflist/list",callback,option);
        
 
 
@@ -62,7 +68,7 @@ NLIB_RESULT NicoMyList_getDefList(NicoVideoAuth_P pAuth,NicoMyListCallBack callb
 //\83v\83\89\83C\83x\81[\83g\8aÖ\90\94
 //
 
-static NLIB_RESULT NicoMyList_getList(NicoVideoAuth_P pAuth,LPCWSTR objectName,NicoMyListCallBack callback,BOOL mtFlag,LPVOID option){
+static NLIB_RESULT NicoMyList_getList(NicoVideoAuth_P pAuth,LPCWSTR objectName,NicoMyListCallBack callback,LPVOID option){
 
        //\95Ï\90\94\90é\8c¾\81A\8f\89\8aú\89»
        NLIB_RESULT rslt = NLIB_ERR_OK;
@@ -71,12 +77,24 @@ static NLIB_RESULT NicoMyList_getList(NicoVideoAuth_P pAuth,LPCWSTR objectName,N
        WCHAR sendBuffer[LENGTH_512] = {L"Cookie: "};
        NicoMyListItemContainer itemContainer;
        
-       
-       LPSTR readBuffer = NULL;
-       JSONParser_P jsonParser = NULL;
+
+       const UINT_PTR readBufSize = LENGTH_65536 * 30;
+
+       LPSTR readBuffer = (LPSTR)malloc(readBufSize);
+
+       DWORD readSize;
+
+       DWORD statusCode;
+       DWORD statusCodeSize = sizeof(statusCode);
+
+       JSONParser_P jsonParser = JSONParser_new();
+
+       JSONParser_setEventHandler(jsonParser,myListItemStructEventHandler,myListItemDataEventHandler,myListItemDataEndEventHandler);
+
+
        
        ZeroMemory(&itemContainer,sizeof(itemContainer));
-
+       itemContainer.callBack = callback;
        itemContainer.option = option;
        wcscat(sendBuffer,pAuth->userSession);
        //hNicoVideoSession = WinHttpConnect(hHttpSession,WWW_NICO_VIDEO_DOMEINNAME,INTERNET_DEFAULT_HTTP_PORT,0);
@@ -87,12 +105,7 @@ static NLIB_RESULT NicoMyList_getList(NicoVideoAuth_P pAuth,LPCWSTR objectName,N
                goto networkerr;
        }
 
-       if(mtFlag == TRUE){
-               if(WINHTTP_INVALID_STATUS_CALLBACK == WinHttpSetStatusCallback(hGetMyList,myListItemCallBack, WINHTTP_CALLBACK_FLAG_ALL_NOTIFICATIONS,0)){
 
-                       goto networkerr;
-               }
-       }
 
        if(WinHttpSendRequest(hGetMyList,sendBuffer,-1,WINHTTP_NO_REQUEST_DATA,0,0,0) == FALSE){
 
@@ -101,51 +114,9 @@ static NLIB_RESULT NicoMyList_getList(NicoVideoAuth_P pAuth,LPCWSTR objectName,N
        }
 
 
-       if(mtFlag == FALSE){
 
-               rslt = recvMyList(hGetMyList,&itemContainer,NLIB_ERR_OK);
 
-       }
-
-end:
-       return rslt;
-       
-networkerr:
-       rslt = NLIB_ERR_FAILED_NETWORK;
-       goto end;
-}
-
-static VOID CALLBACK myListItemCallBack(HINTERNET handle,DWORD_PTR context,DWORD code,LPVOID info,DWORD length){
-
-       
-
-
-
-
-}
-
-static NLIB_RESULT recvMyList(HINTERNET hGetMyList,NicoMyListItemContainer_P itemContainer,NLIB_RESULT rslt){
-
-       
-
-       const UINT_PTR readBufSize = LENGTH_65536 * 30;
-
-       LPSTR readBuffer = (LPSTR)malloc(readBufSize);
-
-       DWORD readSize;
-
-       DWORD statusCode;
-       DWORD statusCodeSize = sizeof(statusCode);
-
-       JSONParser_P jsonParser = JSONParser_new();
-
-       JSONParser_setEventHandler(jsonParser,myListItemStructEventHandler,myListItemDataEventHandler,myListItemDataEndEventHandler);
-
-
-
-       
-
-       itemContainer->pitem = NicoMyListItem_new();
+       itemContainer.pitem = NicoMyListItem_new();
 
        if(WinHttpReceiveResponse(hGetMyList,NULL) == FALSE){
 
@@ -169,20 +140,17 @@ static NLIB_RESULT recvMyList(HINTERNET hGetMyList,NicoMyListItemContainer_P ite
 
        readBuffer[readSize] = '\0';
 
-       if(JSONParser_Parse(jsonParser,readBuffer,JSON_ENCODE_UTF8,itemContainer) != JSON_ERR_OK){
+       if(JSONParser_Parse(jsonParser,readBuffer,JSON_ENCODE_UTF8,&itemContainer) != JSON_ERR_OK){
 
                goto jsonerr;
        }
 
-
-
-
 end:
        free(readBuffer);
        JSONParser_delete(&jsonParser);
-       NicoMyListItem_delete(&itemContainer->pitem);
-
+       NicoMyListItem_delete(&itemContainer.pitem);
        WinHttpCloseHandle(hGetMyList);
+       
 
        return rslt;
 
@@ -193,9 +161,10 @@ jsonerr:
        rslt = NLIB_ERR_JSON_PARSE;
        goto end;
 
+}
+
 
 
-}
 
 static NicoMyListItem_P NicoMyListItem_new(){
 
@@ -271,27 +240,127 @@ static JSONVoid myListItemStructEventHandler(JSONVoid *option,JSONUInt thisHiera
 
 static JSONVoid myListItemDataEventHandler(JSONVoid *option,JSONUInt thisHierarchy,JSONUInt valueType,JSONChar_P name,JSONParameter param){
 
-       switch(valueType){
+       NicoMyListItemContainer_P self = (NicoMyListItemContainer_P)option;
+       
+       if(thisHierarchy == JSONTypeObject){
+               switch(self->nord){
+
+               case MAKENORD3(NicoMyList_Root,NicoMyList_mylist,NicoMyList_mylistitem,NicoMyList_item):
 
+                       if(valueType == JSONTypeDecimal && wcscmp(name,L"create_time") == 0){
 
-       case JSONTypeDecimal:
+                               self->pitem->create_time = wcstoul((LPCWSTR)param,NULL,10);
 
-               dumpln(TEXT("name:[%s]:param[%s]"),name,(LPCWSTR)param);
+                       } else if(valueType == JSONTypeString && wcscmp(name,L"description") == 0){
 
-               break;
+                               self->errcode = jsonToArray(self->pitem->description,(LPCWSTR)param);
 
-       case JSONTypeString:
+                       } else if(valueType == JSONTypeString && wcscmp(name,L"item_id") == 0){
 
-               dumpln(TEXT("name:[%s]:param[%s]"),name,(LPCWSTR)param);
-               
-               break;
+                               self->errcode = jsonToArray(self->pitem->item_id,(LPCWSTR)param);
+
+                       } else if(valueType == JSONTypeString && wcscmp(name,L"item_type") == 0){
+
+                               self->errcode = jsonToArray(self->pitem->item_type,(LPCWSTR)param);
+
+                       } else if(valueType == JSONTypeDecimal && wcscmp(name,L"update_time") == 0){
+
+                               self->pitem->update_time = wcstoul((LPCWSTR)param,NULL,10);
+
+                       } else if(valueType == JSONTypeDecimal && wcscmp(name,L"watch") == 0){
+
+                               self->pitem->watch = wcstoul((LPCWSTR)param,NULL,10);
+                       }
+
+                       break;
+
+               case MAKENORD4(NicoMyList_Root,NicoMyList_mylist,NicoMyList_mylistitem,NicoMyList_item,NicoMyList_item_data):
+
+                       if(valueType == JSONTypeString && wcscmp(name,L"deleted") == 0){
+
+                               self->errcode = jsonToArray(self->pitem->itemData.deleted,(LPCWSTR)param);
+
+                       } else if(valueType == JSONTypeDecimal && wcscmp(name,L"first_retrieve") == 0){
+
+                               self->pitem->itemData.first_retrieve = wcstoul((LPCWSTR)param,NULL,10);
+
+                       } else if(valueType == JSONTypeString && wcscmp(name,L"group_type") == 0){
+
+                               self->errcode = jsonToArray(self->pitem->itemData.group_type,(LPCWSTR)param);
+
+                       } else if(valueType == JSONTypeString && wcscmp(name,L"last_res_body") == 0){
+
+                               self->errcode = jsonToArray(self->pitem->itemData.last_res_body,(LPCWSTR)param);
+
+                       } else if(valueType == JSONTypeString && wcscmp(name,L"length_seconds") == 0){
+
+                               self->errcode = jsonToArray(self->pitem->itemData.length_seconds,(LPCWSTR)param);
+
+                       } else if(valueType == JSONTypeString && wcscmp(name,L"mylist_counter") == 0){
+
+                               self->errcode = jsonToArray(self->pitem->itemData.mylist_counter,(LPCWSTR)param);
+
+                       } else if(valueType == JSONTypeString && wcscmp(name,L"num_res") == 0){
+
+                               self->errcode = jsonToArray(self->pitem->itemData.num_res,(LPCWSTR)param);
+
+                       } else if(valueType == JSONTypeString && wcscmp(name,L"thumbnail_url") == 0){
+
+                               self->errcode = jsonToArray(self->pitem->itemData.thumbnail_url,(LPCWSTR)param);
+
+                       } else if(valueType == JSONTypeString && wcscmp(name,L"title") == 0){
+
+                               self->errcode = jsonToArray(self->pitem->itemData.title,(LPCWSTR)param);
+
+                       } else if(valueType == JSONTypeDecimal && wcscmp(name,L"update_time") == 0){
+
+                               self->pitem->itemData.update_time = wcstoul((LPCWSTR)param,NULL,10);
+
+                       } else if(valueType == JSONTypeString && wcscmp(name,L"video_id") == 0){
+
+                               self->errcode = jsonToArray(self->pitem->itemData.video_id,(LPCWSTR)param);
+
+                       } else if(valueType == JSONTypeString && wcscmp(name,L"view_counter") == 0){
+
+                               self->errcode = jsonToArray(self->pitem->itemData.view_counter,(LPCWSTR)param);
+
+                       } else if(valueType == JSONTypeString && wcscmp(name,L"watch_id") == 0){
+
+                               self->errcode = jsonToArray(self->pitem->itemData.watch_id,(LPCWSTR)param);
+
+                       }
+
+                       break;
+               }
        }
        return;
 }
 
 static JSONVoid myListItemDataEndEventHandler(JSONVoid *option,JSONUInt thisHierarchy,JSONUInt valueType,JSONChar_P name){
+       NicoMyListItemContainer_P self = (NicoMyListItemContainer_P)option;
+       self->nord = UPNORD(self->nord);
+       if(MAKENORD2(NicoMyList_Root,NicoMyList_mylist,NicoMyList_mylistitem) == self->nord){
 
-       UPNORD(((NicoMyListItemContainer_P)option)->nord);
+               self->callBack(self->option,self->pitem);
+               ZeroMemory(self->pitem,sizeof(*self->pitem));
 
+       }
        return;
+}
+
+static NLIB_RESULT jsonStrCpy(LPWSTR buf,LPCWSTR in,SIZE_T size){
+
+       NLIB_RESULT rslt = NLIB_ERR_OK;
+
+       if(wcslen(in) < size){
+
+               wcscpy(buf,in);
+
+       }else {
+
+               rslt = NLIB_ERR_BUFFER_TOOLITTLE;
+
+       }
+
+       return rslt;
 }
\ No newline at end of file
index 6029fb3..1247331 100644 (file)
@@ -1346,7 +1346,7 @@ static unsigned int WINAPI  NicoLiveHeartBeatThread(void* lpBuffer){
 }
 static unsigned int loopCommon(NicoLiveStream_P self,WSAEVENT sendEvent,WSAEVENT resetEvent ,NicoLiveOnSend nicoLiveOnSend){
 
-       unsigned int rslt;
+       unsigned int rslt = 0;
        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,sendEvent};
        DWORD dwResult;                                                                                                                                                                                                 //\83C\83x\83\93\83g\8eó\90M\8c\8b\89Ê
index e353933..b256342 100644 (file)
@@ -161,7 +161,7 @@ NLIB_RESULT callback(NICOLIVE_EVENT eventType,NicoLiveStream_P pNicoLiveStream,L
        return 0;
 }
 
-NLIB_RESULT myListCallBack(LPVOID option,NicoMyListItem_P pVideo,NLIB_RESULT rslt){
+NLIB_RESULT myListCallBack(LPVOID option,NicoMyListItem_P pVideo){
 
 
 
@@ -232,7 +232,7 @@ void nicoLive_mylist(void) {
 
        
 
-       CU_ASSERT_EQUAL(NicoMyList_getDefList(nva,myListCallBack,FALSE,NULL), NLIB_ERR_OK);
+       CU_ASSERT_EQUAL(NicoMyList_getDefList(nva,myListCallBack,NULL), NLIB_ERR_OK);
        check(_heapchk() == _HEAPOK,TEXT("heap\83G\83\89\81[\82Å\82·"));
        dumpln(TEXT("heapchk:%d"),_heapchk());
 
@@ -241,8 +241,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,
 };