OSDN Git Service

2012/01/04 16:56:06
[nlite/nlite.git] / nlite_stub / nlite_stub.cpp
1 #define _CRT_SECURE_NO_WARNINGS 1                       //vc++\82Ì\82¨\82¹\82Á\82©\82¢\82È\8cx\8d\90\82ð\8fÁ\82·\83}\83N\83\8d
2 #define  _CRT_NON_CONFORMING_SWPRINTFS 1        //vc++\82Ì\82¨\82¹\82Á\82©\82¢\82È\8cx\8d\90\82ð\8fÁ\82·\83}\83N\83\8d
3
4 #include <nlib\nlib.h>
5 #include <nlib\nlib_define.h>
6 #include "nlib_stub.h"
7 #include <stdio.h>
8 #include <memory.h>
9 #include <stdlib.h>
10 #include <process.h>
11 #include <qwerty\windebuger.h>
12
13
14
15 static void *nlibmemory;
16 static BROWSERTYPE browserType;
17 static unsigned int WINAPI commentthread(VOID *usadata);
18 NicoLiveStream_P NicoLiveStream_new(){
19
20         NicoLiveStream_P rslt = (NicoLiveStream_P)malloc(sizeof(NicoLiveStream));
21         ZeroMemory(rslt,sizeof(*rslt));
22         rslt->endEvent = CreateEvent(NULL,TRUE,FALSE,NULL);
23         return rslt;
24 }
25
26 VOID NicoLiveStream_delete(NicoLiveStream_P* self){
27
28         NicoLiveStream_disConnect(*self);
29         CloseHandle((*self)->endEvent);
30         free(*self);
31         *self = NULL;
32         return;
33 }
34
35 NicoVideoAuth_P NicoVideoAuth_new(){
36
37         return (NicoVideoAuth_P)malloc(65536);
38 }
39
40 VOID NicoVideoAuth_delete(NicoVideoAuth_P *self){
41
42         free(*self);
43         *self= NULL;
44 }
45
46
47 NLIB_RESULT InitializeNLIB(HINTERNET hInternet){
48
49         nlibmemory = malloc(65536);
50
51         return NLIB_ERR_OK;
52 }
53
54
55 VOID FinalizeNLIB(){
56
57         free(nlibmemory);
58 }
59
60 NLIB_RESULT NicoVideoAuth_getNicoVideoAuth(NicoVideoAuth_P self,BROWSERTYPE browserType){
61
62         ::browserType = browserType;
63
64         return NLIB_ERR_OK;
65 }
66
67 NLIB_RESULT NicoLiveStream_connect(NicoLiveStream_P self,NicoVideoAuth_P nicoVideoAuth,LPCWSTR url,NicoRecvCallBack callback,LPVOID option){
68         
69         NLIB_RESULT rslt = NLIB_ERR_OK;
70
71         NicoLiveStream_disConnect(self);
72
73         self->callback = callback;
74         self->option = option;
75         self->threadHandle = (HANDLE)_beginthreadex(NULL,0,commentthread,self,0,NULL);
76
77
78
79         return rslt;
80 }
81
82 VOID NicoLiveStream_disConnect(NicoLiveStream_P self){
83
84         SetEvent(self->endEvent);
85         if(self->threadHandle != INVALID_HANDLE_VALUE){
86                 WaitForSingleObject(self->threadHandle,INFINITE);
87                 CloseHandle(self->threadHandle);
88         }
89         
90         
91         
92         self->threadHandle = NULL;
93
94         ResetEvent(self->endEvent);
95         return;
96 }
97
98 StreamStatus_P NicoLiveStream_getStreamStatus(NicoLiveStream_P self){
99
100         self->stream.base_time = 1324709820;
101         self->stream.open_time = 1324709820;
102         self->stream.end_time = 1324713599;
103         self->stream.start_time = 1324710000;
104         
105         _tcscpy(self->stream.id,TEXT("lv75313550"));
106         _tcscpy(self->stream.default_community,TEXT("co1187609"));
107
108         self->stream.is_owner = FALSE;
109         self->stream.provider_type = COMMUNITY_PROVIDER_TYPE;
110         
111
112         return &self->stream;
113 }
114
115
116 unsigned int WINAPI commentthread(VOID *usadata){
117
118         NicoLiveStream_P self = (NicoLiveStream_P)usadata;
119
120         NicoLiveThreadComment threadcomment;
121         threadcomment.last_res = TEXT("256");
122         threadcomment.server_time = TEXT("12345467");
123         threadcomment.thread = TEXT("1234567");
124         threadcomment.ticket = TEXT("0x12334445");
125         self->callback(NICOLIVE_EVENT_RECEVE_CONNECTRESULT,self,self->option,(NICOLIVE_PARAM)&threadcomment,0);
126
127         NicoLiveChat liveChat;
128         TCHAR noBuf[sizeof(UINT_PTR) * 8];
129         liveChat.anonymity = TEXT("");
130         TCHAR user_idBuffer[256];
131         liveChat.date = TEXT("1324713598");
132         liveChat.locale = TEXT("jp");
133         LPCTSTR mails[] = {TEXT("184"),NULL};
134         liveChat.mail = &mails[0];
135         liveChat.mailCount = ARRAY_LENGTH(mails) - 1;
136         liveChat.name = TEXT("");
137         liveChat.no = noBuf;
138         liveChat.premium = TEXT("1");
139         liveChat.thread = TEXT("1000254");
140         LPCTSTR user_id_format = TEXT("testuser%d");
141         liveChat.user_id = user_idBuffer;
142         liveChat.vpos = TEXT("8852");
143         int commentcount = 1;
144
145         DWORD rslt;
146         srand((unsigned int)time(NULL));
147
148         for(int indexfirst = 0; indexfirst < 10000;indexfirst++){
149                 liveChat.chatBuf = commentcount % 2 == 0 ? TEXT("testcomment\82 \82 \82 \82 \82 \82 \82 \82 \82 \82 \82 \82 \82 \82 \82 \82 \82 \82 \82 \82 \82 \82 \82 \82 \82 \82 \82 \82 \82 \82 \82 \82 \82 \82 \82 \82 \82 \82 \82 \82 \82 \82 ") : TEXT("test");
150                 _stprintf((LPTSTR)liveChat.user_id,user_id_format,rand() % 15);
151                 _stprintf((LPTSTR)liveChat.no,TEXT("%u"),commentcount);
152                 self->callback(NICOLIVE_EVENT_RECEVE_CHAT,self,self->option,(NICOLIVE_PARAM)&liveChat,indexfirst);
153                 commentcount++;
154         }
155
156         
157         for(int index = 0,index2; index < 100;index++){
158
159                 
160                 for(index2 = 0;index2 < 3;index2++){
161
162                         liveChat.chatBuf = commentcount % 2 == 0 ? TEXT("testcomment\82 \82 \82 \82 \82 \82 \82 \82 \82 \82 \82 \82 \82 \82 \82 \82 \82 \82 \82 \82 \82 \82 \82 \82 \82 \82 \82 \82 \82 \82 \82 \82 \82 \82 \82 \82 \82 \82 \82 \82 \82 \82 ") : TEXT("test");
163                         _stprintf((LPTSTR)liveChat.user_id,user_id_format,rand() % 15);
164                         _stprintf((LPTSTR)liveChat.no,TEXT("%u"),commentcount);
165                         self->callback(NICOLIVE_EVENT_RECEVE_CHAT,self,self->option,(NICOLIVE_PARAM)&liveChat,index + index2);
166                         commentcount++;
167                 }
168
169                 self->callback(NICOLIVE_EVENT_RECEVE_CHATSETTLE,self,self->option,100,commentcount);
170                 if(( rslt = WaitForSingleObject(self->endEvent,0)) != WAIT_TIMEOUT){
171
172                         goto end;
173                 }
174
175                 
176                 
177         }
178 end:
179
180         _endthreadex(0);
181         return 0;
182 }