OSDN Git Service

5e7090d4f98e03a96f6f41ca3f9641aca70fb4bb
[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 <exception>
5 #include <string>
6 #include <nlib\nlib.h>
7 #include <nlib\nlib_define.h>
8 #include "nlib_stub.h"
9 #include <stdio.h>
10 #include <memory.h>
11 #include <stdlib.h>
12 #include <process.h>
13 #include <qwerty\windebuger.h>
14
15
16
17 static void *nlibmemory;
18 static BROWSERTYPE browserType;
19 static unsigned int WINAPI commentthread(VOID *usadata);
20 NicoLiveStream_P NicoLiveStream_new(){
21
22         NicoLiveStream_P rslt = (NicoLiveStream_P)malloc(sizeof(NicoLiveStream));
23         ZeroMemory(rslt,sizeof(*rslt));
24         rslt->endEvent = CreateEvent(NULL,TRUE,FALSE,NULL);
25         rslt->receveEvent = CreateEvent(NULL,TRUE,FALSE,NULL);
26         return rslt;
27 }
28
29 VOID NicoLiveStream_delete(NicoLiveStream_P* self){
30
31         NicoLiveStream_disConnect(*self);
32         CloseHandle((*self)->endEvent);
33         CloseHandle((*self)->receveEvent);
34         free(*self);
35         *self = NULL;
36         return;
37 }
38
39 NicoVideoAuth_P NicoVideoAuth_new(){
40
41         return (NicoVideoAuth_P)malloc(65536);
42 }
43
44 VOID NicoVideoAuth_delete(NicoVideoAuth_P *self){
45
46         free(*self);
47         *self= NULL;
48 }
49
50
51 NLIB_RESULT InitializeNLIB(HINTERNET hInternet){
52
53         nlibmemory = malloc(65536);
54
55         return NLIB_ERR_OK;
56 }
57
58
59 VOID FinalizeNLIB(){
60
61         free(nlibmemory);
62 }
63
64 NLIB_RESULT NicoVideoAuth_getNicoVideoAuth(NicoVideoAuth_P self,BROWSERTYPE browserType){
65
66         ::browserType = browserType;
67
68         return NLIB_ERR_OK;
69 }
70
71 #ifndef TEST_CONNECT_RESULT_CHECK
72
73 NLIB_RESULT NicoLiveStream_connect(NicoLiveStream_P self,NicoVideoAuth_P nicoVideoAuth,LPCWSTR url,NicoRecvCallBack callback,LPVOID option){
74         
75         NLIB_RESULT rslt = NLIB_ERR_OK;
76
77         NicoLiveStream_disConnect(self);
78
79         self->callback = callback;
80         self->option = option;
81         self->threadHandle = (HANDLE)_beginthreadex(NULL,0,commentthread,self,0,NULL);
82
83
84
85         return rslt;
86 }
87 #endif
88
89 #ifdef TEST_CONNECT_RESULT_CHECK
90 NLIB_RESULT NicoLiveStream_connect(NicoLiveStream_P self,NicoVideoAuth_P nicoVideoAuth,LPCWSTR url,NicoRecvCallBack callback,LPVOID option){
91         
92         static NLIB_RESULT rslt = NLIB_ERR_OK;
93
94         rslt++;
95
96
97
98         return rslt;
99 }
100
101
102 #endif
103
104 VOID NicoLiveStream_disConnect(NicoLiveStream_P self){
105
106         SetEvent(self->endEvent);
107         if(self->threadHandle != INVALID_HANDLE_VALUE){
108                 WaitForSingleObject(self->threadHandle,INFINITE);
109                 CloseHandle(self->threadHandle);
110         }
111         
112         
113         
114         self->threadHandle = NULL;
115
116         ResetEvent(self->endEvent);
117         return;
118 }
119
120 StreamStatus_P NicoLiveStream_getStreamStatus(NicoLiveStream_P self){
121
122         self->stream.base_time = 1324709820;
123         self->stream.open_time = 1324709820;
124         self->stream.end_time = 1324713599;
125         self->stream.start_time = 1324710000;
126         
127         _tcscpy(self->stream.id,TEXT("lv75313550"));
128         _tcscpy(self->stream.default_community,TEXT("co1345577"));
129
130         self->stream.is_owner = FALSE;
131         self->stream.provider_type = COMMUNITY_PROVIDER_TYPE;
132         
133
134         return &self->stream;
135 }
136
137 NLIB_RESULT NicoLiveStream_sendChat(NicoLiveStream_P self,LPCWSTR chatbuf,LPCWSTR *mail,LPCWSTR *extends){
138
139
140         return 0;
141 }
142
143 void commentthread_inteanal(void* userdata){
144
145         NicoLiveStream_P self = (NicoLiveStream_P)userdata;
146         DWORD rslt;
147         do{
148                 rslt = WaitForSingleObject(self->endEvent,500);
149
150                 if(rslt != WAIT_TIMEOUT){
151                         break;
152                 }
153
154                 SetEvent(self->receveEvent);
155
156         }while(TRUE);
157         _endthread();
158 }
159
160 VOID NicoLiveStrream_setResFrom(NicoLiveStream_P self,INT_PTR res){
161
162         return;
163 }
164
165 unsigned int WINAPI commentthread(VOID *usadata){
166
167         NicoLiveStream_P self = (NicoLiveStream_P)usadata;
168
169         NicoLiveThreadComment threadcomment;
170         threadcomment.last_res = TEXT("256");
171         threadcomment.server_time = 12345467;
172         threadcomment.thread = TEXT("1234567");
173         threadcomment.ticket = TEXT("0x12334445");
174         self->callback(NICOLIVE_EVENT_RECEVE_CONNECTRESULT,self,self->option,(NICOLIVE_PARAM)&threadcomment,0);
175
176         NicoLiveChat liveChat;
177         TCHAR noBuf[sizeof(UINT_PTR) * 8];
178         liveChat.anonymity = TEXT("");
179         TCHAR user_idBuffer[256];
180         liveChat.date = TEXT("1324713598");
181         liveChat.locale = TEXT("jp");
182         LPTSTR mails[] = {TEXT("184"),NULL};
183         liveChat.mail = &mails[0];
184         liveChat.mailCount = ARRAY_LENGTH(mails) - 1;
185         liveChat.name = TEXT("");
186         liveChat.no = noBuf;
187         liveChat.premium = TEXT("1");
188         liveChat.thread = TEXT("1000254");
189         LPCTSTR user_id_format = TEXT("testuser%d");
190         liveChat.user_id = user_idBuffer;
191         liveChat.vpos = TEXT("8852");
192         int commentcount = 0;
193
194         DWORD rslt;
195         srand((unsigned int)time(NULL));
196
197         for(int indexfirst = 0; indexfirst < STARTRECEVECOUNT;indexfirst++){
198                 liveChat.chatBuf = commentcount % 2 == 0 ? TEXT("http://live.nicovideo.jp/watch/lv79715214?alert=1 2545 http://live.nicovideo.jp/watch/lv79715214?alert=1") : TEXT("test");
199                 _stprintf((LPTSTR)liveChat.user_id,user_id_format,rand() % 15);
200                 commentcount++;
201                 _stprintf((LPTSTR)liveChat.no,TEXT("%u"),commentcount);
202                 
203                 self->callback(NICOLIVE_EVENT_RECEVE_CHAT,self,self->option,(NICOLIVE_PARAM)&liveChat,commentcount);
204                 
205         }
206         
207         _beginthread(commentthread_inteanal,0,self);
208         HANDLE eventarray[] = {self->endEvent,self->receveEvent};
209         for(int index = 0,index2; index < RECEVECOUNT;index++){
210
211
212                 for(index2 = 0;index2 < ONERECEVECHATCOUNT;index2++){
213
214                         liveChat.chatBuf = commentcount % 2 == 0 ? TEXT("http://live.nicovideo.jp/watch/lv79715214?alert=1 254 http://live.nicovideo.jp/") : TEXT("<font color=FF0000>sm552447 sm1543514 lv25447 </font >");
215                         _stprintf((LPTSTR)liveChat.user_id,TEXT("%s"),TEXT("0NsZs9X9GFLJaE9Ru3QuV2StCIM"));
216                         commentcount++;
217                         _stprintf((LPTSTR)liveChat.no,TEXT("%u"),commentcount);
218                         
219                         self->callback(NICOLIVE_EVENT_RECEVE_CHAT,self,self->option,(NICOLIVE_PARAM)&liveChat,commentcount);
220                         
221                 }
222
223                 self->callback(NICOLIVE_EVENT_RECEVE_CHATSETTLE,self,self->option,100,commentcount);
224                 ResetEvent(self->receveEvent);
225                 rslt = WaitForMultipleObjects(ARRAY_LENGTH(eventarray),eventarray,FALSE,INFINITE);
226                 
227                 //\83G\83\89\81[\82Ì\8fê\8d\87
228                 if(rslt == WAIT_OBJECT_0 ){
229
230                         goto end;
231                 }
232                 
233                 
234                 
235         }
236 end:
237
238         _endthreadex(0);
239         return 0;
240 }
241
242
243 //
244 //\83X\83g\83\8a\81[\83\80\83X\83e\81[\83^\83X\8aÖ\98A
245 //
246
247 ///
248 ///\83X\83g\83\8a\81[\83\80\83X\83e\81[\83^\83X\82ÌID\82ð\8eæ\93¾
249 ///
250 NLIB_DECLSPEC LPCTSTR StreamStatus_getId(StreamStatus_P self){
251
252         return self->id;
253 }
254
255
256 ///
257 ///\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¾
258 ///
259 NLIB_DECLSPEC LPCTSTR StreamStatus_getDefaultCommunity(StreamStatus_P self){
260
261         return self->default_community;
262 }
263
264
265 ///
266 ///\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¾
267 ///
268 PROVIDERTYPE StreamStatus_getProviderType(StreamStatus_P self){
269
270         return self->provider_type;
271 }
272
273
274 ///
275 ///\83X\83g\83\8a\81[\83\80\83X\83e\81[\83^\83X\82Ì\83I\81[\83i\81[\83t\83\89\83O\82ð\8eæ\93¾
276 ///
277 BOOL StreamStatus_isOwner(StreamStatus_P self){
278
279         return self->is_owner;
280 }
281
282 ///
283 ///\83X\83g\83\8a\81[\83\80\83X\83e\81[\83^\83X\82Ì\8aJ\8en\8e\9e\8d\8f\82ð\8eæ\93¾
284 ///
285 time_t StreamStatus_getStartTime(StreamStatus_P self){
286
287         return self->start_time;
288 }
289
290 ///
291 ///\83X\83g\83\8a\81[\83\80\83X\83e\81[\83^\83X\82Ì\8fI\97¹\8e\9e\8d\8f\82ð\8eæ\93¾
292 ///
293 time_t StreamStatus_getEndTime(StreamStatus_P self){
294
295         return self->end_time;
296 }
297
298 ///
299 ///\83X\83g\83\8a\81[\83\80\83X\83e\81[\83^\83X\82Ì\8aJ\8fê\8e\9e\8d\8f\82ð\8eæ\93¾
300 ///
301 time_t StreamStatus_getOpenTime(StreamStatus_P self){
302
303         return self->open_time;
304
305 }
306
307 ///
308 ///\83X\83g\83\8a\81[\83\80\83X\83e\81[\83^\83X\82Ì\83x\81[\83X\8e\9e\8d\8f\82ð\8eæ\93¾
309 ///
310 time_t StreamStatus_getBaseTime(StreamStatus_P self){
311
312         return self->base_time;
313 }
314
315
316
317 BOOL NicoLiveStream_isPremium(NicoLiveStream_P self){
318
319         return 0;
320
321 }
322
323
324 ///
325 ///\83n\81[\83g\83r\81[\83g\82Ì\8aÔ\8au\82ð\90Ý\92è\81i\83~\83\8a\95b)
326 ///
327 VOID NicoLiveStream_setHeartBeatMsec(NicoLiveStream_P self,DWORD msec){
328
329         
330
331         return;
332 }
333
334 ///
335 ///\83n\81[\83g\83r\81[\83g\82Ì\8aÔ\8au\82ð\8eæ\93¾(\83~\83\8a\95b)
336 ///
337 DWORD NicoLiveStream_getHeartBeatMsec(NicoLiveStream_P self){
338
339         return 300000;
340
341
342 }
343
344 ///
345 ///\83n\81[\83g\83r\81[\83g\97L\8cø\81E\96³\8cø\90Ý\92è
346 ///
347 VOID NicoLiveStream_setHeartBeatFlag(NicoLiveStream_P self,BOOL flag){
348
349         return;
350
351 }
352
353
354 ///
355 ///\83n\81[\83g\83r\81[\83g\97L\8cø\83t\83\89\83O\8eæ\93¾
356 ///
357 BOOL NicoLiveStream_getHeartBeatFlag(NicoLiveStream_P self){
358
359         return FALSE;
360
361
362 }
363
364
365 ///
366 ///\83L\81[\83v\83A\83\89\83C\83u\82Ì\8aÔ\8au\82ð\90Ý\92è(\83~\83\8a\95b)
367 ///
368 VOID NicoLiveStream_setKeapALiveMsec(NicoLiveStream_P self,DWORD msec){
369
370 #ifdef USE_NLIB_KEEPALIVE
371         self->chatManager.keepAliveTime = msec;
372         WSASetEvent(self->chatManager.setKeepAliveTimeEvent);
373 #endif
374         return;
375
376 }
377
378 ///
379 ///\83L\81[\83v\83A\83\89\83C\83u\82Ì\8aÔ\8au\82ð\8eæ\93¾(\83~\83\8a\95b)
380 ///
381 DWORD NicoLiveStream_getKeapALiveMsec(NicoLiveStream_P self){
382
383 #ifdef USE_NLIB_KEEPALIVE
384         return self->chatManager.keepAliveTime;
385 #else 
386         return 0;
387 #endif
388
389 }
390
391
392 ///
393 ///\83L\81[\83v\83A\83\89\83C\83u\97L\8cø\81E\96³\8cø\90Ý\92è
394 ///
395 VOID NicoLiveStream_setKeapALiveFlag(NicoLiveStream_P self,BOOL flag){
396
397 #ifdef USE_NLIB_KEEPALIVE
398         self->chatManager.keapALiveFlag = flag;
399 #endif
400 }
401
402
403 ///
404 ///\83L\81[\83v\83A\83\89\83C\83u\83t\83\89\83O\8eæ\93¾
405 ///
406 BOOL NicoLiveStream_getKeapALiveFlag(NicoLiveStream_P self){
407
408 #ifdef USE_NLIB_KEEPALIVE
409         return self->chatManager.keapALiveFlag;
410 #else 
411         return FALSE;
412 #endif
413
414 }
415
416
417
418 INT_PTR NicoLiveStream_getResFrom(NicoLiveStream_P self){
419
420         return 0;
421 }
422
423 NLIB_RESULT NicoLiveStream_sendHeartBeat(NicoLiveStream_P self){
424
425         return NLIB_ERR_OK;
426 }
427
428
429 ///
430 ///\83X\83g\83\8a\81[\83\80\83X\83e\81[\83^\83X\82ÌID\82ð\8eæ\93¾
431 ///
432 LPCTSTR NicoLiveStream_getId(NicoLiveStream_P self){
433         static const LPCTSTR rslt = TEXT("lv000002");
434         return rslt;
435 }
436
437
438 ///
439 ///\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¾
440 ///
441 LPCTSTR NicoLiveStream_getDefaultCommunity(NicoLiveStream_P self){
442         static const LPCTSTR rslt = TEXT("co1345577");
443         return rslt;
444 }
445
446
447 ///
448 ///\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¾
449 ///
450 PROVIDERTYPE NicoLiveStream_getProviderType(NicoLiveStream_P self){
451
452         return 0;
453 }
454
455
456 ///
457 ///\83X\83g\83\8a\81[\83\80\83X\83e\81[\83^\83X\82Ì\83I\81[\83i\81[\83t\83\89\83O\82ð\8eæ\93¾
458 ///
459 BOOL NicoLiveStream_isOwner(NicoLiveStream_P self){
460
461         return FALSE;
462 }
463
464
465
466 ///
467 ///\83X\83g\83\8a\81[\83\80\83X\83e\81[\83^\83X\82Ì\8aJ\8en\8e\9e\8d\8f\82ð\8eæ\93¾
468 ///
469 time_t NicoLiveStream_getStartTime(NicoLiveStream_P self){
470
471         return 0;
472 }
473
474 ///
475 ///\83X\83g\83\8a\81[\83\80\83X\83e\81[\83^\83X\82Ì\8fI\97¹\8e\9e\8d\8f\82ð\8eæ\93¾
476 ///
477 time_t NicoLiveStream_getEndTime(NicoLiveStream_P self){
478
479         return 0;
480 }
481
482 ///
483 ///\83X\83g\83\8a\81[\83\80\83X\83e\81[\83^\83X\82Ì\8aJ\8fê\8e\9e\8d\8f\82ð\8eæ\93¾
484 ///
485 time_t NicoLiveStream_getOpenTime(NicoLiveStream_P self){
486
487         return 0;
488
489 }
490
491 ///
492 ///\83X\83g\83\8a\81[\83\80\83X\83e\81[\83^\83X\82Ì\83x\81[\83X\8e\9e\8d\8f\82ð\8eæ\93¾
493 ///
494 time_t NicoLiveStream_getBaseTime(NicoLiveStream_P self){
495
496         return 0;
497 }
498
499
500 ///
501 ///\83X\83g\83\8a\81[\83\80\83X\83e\81[\83^\83X\82Ì\83^\83C\83g\83\8b\8eæ\93¾
502 ///
503 LPCTSTR NicoLiveStream_getTitle(NicoLiveStream_P self){
504 #ifdef PLAYERSTATUS_GET_TITLE
505         return self->playerStatus.stream.title;
506 #else
507         static const LPCTSTR rslt = TEXT("");
508         return rslt;
509 #endif
510 }
511
512
513
514
515 LPCTSTR NicoVideoAuth_getUserSession(NicoVideoAuth_P self){
516
517         static const  LPCTSTR rslt = TEXT("user_session=user_session_14018634_55619152528064910");
518         return rslt;
519         
520 }