Topic Text   Topic Comments (26)   Topic Properties   Topic Information yavraham@exe...
Topic title: Example Monday September 8, 2008 03:33:59

Download topic text | View in monospace font | Tab width set to 4 (change to 8)

Files in topic:  
[Jump to] D:\WORK\AOD\Client\ContentPushMgrLib\AcontentPushMgr.cpp   {+973,-0}

[Add General Comment] to topic.

File D:\WORK\AOD\Client\ContentPushMgrLib\AcontentPushMgr.cpp (Revision 1.0) [Add File Comment] [Top]
 
1 /*------------------------------------------------------------------------
2 $Workfile: $
3 $Archive: $
4 $Revision: $
5 $Date: $
6
7 Description:
8
9 Copyright ? 2007 Exent Technologies Ltd.
10 ------------------------------------------------------------------------*/
11
12 #include "stdafx.h"
13 #pragma hdrstop
14
15 #define ACONTENTPUSHMGR_CPP
16
17 #define LOGGER_TYPE_FILE_CODE LOGGER_TYPE_FILE_CONTENT_PUSH_MGR
18
19
20 #define XML_VERIFY_MOD L"g1sT7M/oxJ7JSwaN7i1aMtW0B1R6+4IVlpjfQrlLtoxIktn/w8UaLhJrMCC3MghjrrtybJKJkitS 204pwywziIT/pzHtYQDYf6VEYn4sPJxYovioGJz6zDzA+utQgyt7wNyMhe/6KYKHush1tIMcp4gt vqomDy9ZcRik//WvWFU="
21 #define XML_VERIFY_EXP L"AQAB"
22
23
24 #include "UnitInclude.h"
25
26 AContentPushMgr::AContentPushMgr()
27 {
28 m_bInit = false;
29 m_pContentPushCBObj = NULL;
30 m_ProviderId = NULL;
31 m_dwIntervalForRetryOperationInSec = NULL;
32 m_pIInstalledContentsControler = NULL;
33 m_strProxy.erase();
34 }
35
36 /*------------------------------------------------------------------------
37 AContentPushMgr::Init()
38 Description:
39
40 Parameters:
41 wstrInfoPath = wstring
42 providerID = PROVIDERID
43 dwIntervalForRetryOperationInSec = DWORD
44 pIInstalledContentsControler = IInstalledContentsControler*
45 pContentPushCBObj = IContentPushMgrCB*
46 Returns:
47 True if successful
48 ------------------------------------------------------------------------*/
49 bool AContentPushMgr::Init(wstring wstrInfoPath,
50 PROVIDERID providerID,
51 DWORD dwIntervalForRetryOperationInSec,
52 string strProxy,
53 IInstalledContentsControler* pIInstalledContentsControler,
54 IContentPushMgrCB* pContentPushCBObj)
55 {
56
57 if (m_bInit)
58 Term();
59
60 BOOL bRes = m_TimingNotificationMutex.Create( FALSE, NULL, NULL );
61 if( !bRes )
62 {
63 DoLogEx( AERR, AClientSDKErrIDs::CREATE_MUTEX_ERR, "" );
64 return false;
65 }
66
67 m_bInit = true;
68
69 m_pContentPushCBObj = pContentPushCBObj;
70 m_ProviderId = providerID;
71 m_dwIntervalForRetryOperationInSec = dwIntervalForRetryOperationInSec;
72 m_pIInstalledContentsControler = pIInstalledContentsControler;
73 m_strProxy = strProxy;
74
75 // Check if ContentPushMgr has already run successfully
76 if (IsAlreadyRunSuccessfully())
77 return true;
78
79 // Format the AIG's file name
80 WCHAR fileName[MAX_PATH];
81 swprintf( fileName, AIG_FILE_NAME, m_ProviderId );
82 m_wstrAIGXmlFileName = wstrInfoPath + fileName;
83
84 // Initiate timer for doing the main logic (fetching XML, add to download list).
85 // First time, we do it immediately, and then once in "dwIntervalForRetryOperation",
86 DWORD dwFirstTimeIntervalInSec;
87 if (false == GetFirstTimeDelayInterval(dwFirstTimeIntervalInSec))
88 {
89 dwFirstTimeIntervalInSec = INTERVAL_FOR_FIRST_TIME_IN_SEC;
90 }
91 m_pNotificationsTimer = new Exent::Util::TimerThread(dwFirstTimeIntervalInSec*1000,
92 true);
93 m_pNotificationsTimer->Register(this);
94 m_pNotificationsTimer->ReStart();
95
96 return true;
97 }
98
99 /*------------------------------------------------------------------------
100 AContentPushMgr::~AContentPushMgr()
101 Description:
102
103 ------------------------------------------------------------------------*/
104 AContentPushMgr::~AContentPushMgr()
105 {
106 Term();
107 }
108
109 /*------------------------------------------------------------------------
110 AContentPushMgr::Term()
111 Description:
112
113 ------------------------------------------------------------------------*/
114 void AContentPushMgr::Term()
115 {
116
117 if (!IsInit())
118 return;
119
120 AMutexLock lock( &m_TimingNotificationMutex );
121 if( !lock.Wait(CP_MGR_MUTEX_WAIT_TIME_FOR_TERM) )
122 {
123 DoLogEx( AERR, AClientSDKErrIDs::WAIT_ON_LOCK_ERR,"" );
124 }
125
126 // First, cancel the current Http Connection, Then Terminate the timer thread.
127 if (m_pNotificationsTimer)
128 {
129 m_pNotificationsTimer->Pause();
130 }
131
132 CancelCurrentHttpConnection();
133
134 if (m_pNotificationsTimer!=NULL)
135 {
136 m_pNotificationsTimer->UnRegister(this);
137 m_pNotificationsTimer->Close();
138 delete m_pNotificationsTimer;
139 m_pNotificationsTimer = NULL;
140 }
141
142 m_TimingNotificationMutex.Destroy();
143
144 m_bInit = false;
145 }
146
147 /*------------------------------------------------------------------------
148 AContentPushMgr::IsAlreadyRunSuccessfully()
149 Description:
150 Check if the ContentPush module has already run successfully, by checking
151 the corresponding registry key
152 Returns:
153 True if successful
154 ------------------------------------------------------------------------*/
155 bool AContentPushMgr::IsAlreadyRunSuccessfully()
156 {
157 bool bRes = false;
158 bool bRet;
159 ISettingsDB* pSDB = NULL;
160
161 ISettingsMgr* pSMgr = ISettingsMgrFactory::GetInstance();
162 if ( pSMgr == NULL )
163 return false;
164
165 pSDB = pSMgr->GetInstance( "", m_ProviderId );
166 if ( pSDB == NULL )
167 return false;
168
169 bRes = pSDB->GetSetting(PROVIDER_SETTING_CONTENT_PUSH_ALREADY_RUN_SUCCESSFULLY, bRet);
170 if(!bRes)
171 {
172 return false;
173 }
174
175 return bRet;
176 }
177
178 /*------------------------------------------------------------------------
179 GetFirstTimeDelayInterval()
180 Description:
181
182 Returns:
183 True if successful
184 ------------------------------------------------------------------------*/
185 bool AContentPushMgr::GetFirstTimeDelayInterval(DWORD &dwInterval)
186 {
187 bool bRes = false;
188
189 ISettingsDB* pSDB = NULL;
190
191 ISettingsMgr* pSMgr = ISettingsMgrFactory::GetInstance();
192 if ( pSMgr == NULL )
193 return false;
194
195 pSDB = pSMgr->GetInstance( "", m_ProviderId );
196 if ( pSDB == NULL )
197 return false;
198
199 bRes = pSDB->GetSetting(PROVIDER_SETTING_CONTENT_PUSH_FIRST_TIME_DELAY_IN_SEC, dwInterval);
200 if(!bRes)
201 {
202 return false;
203 }
204
205 return bRes;
206 }
207 /*------------------------------------------------------------------------
208 AContentPushMgr::CheckContentPushContentsState()
209 Description:
210 Loop over all current provider's installed contents.
211 we check for contents that aren't AIG contents, or AIG's contents that
212 already been downloded.
213 Returns:
214 CONTENTS_STATE_ON_DISK
215 ------------------------------------------------------------------------*/
216 CONTENTS_STATE_ON_DISK AContentPushMgr::CheckContentPushContentsState()
217 {
218
219 list<CONTENTID> ContentsList;
220 list<CONTENTID>::iterator ContentsListIter;
221 AClientSDKErrIDs::ERROR_ID ErrId = AClientSDKErrIDs::ERR_SUCCESS;
222 CONTENTID ContentId;
223 INSTALLED_CONTENT_INFO ContentInfo;
224 bool bFound = false;
225
226
227 // Get a pointer to ICC
228 if(!m_pIInstalledContentsControler)
229 {
230 return GENERAL_ERROR;
231 }
232 // Get the content list.
233 ErrId = m_pIInstalledContentsControler->GetInstalledContentsIdsList(ContentsList);
234 if(ErrId != AClientSDKErrIDs::ERR_SUCCESS)
235 {
236 return GENERAL_ERROR;
237 }
238 // Loop over the contents and find contents off the current provider
239 for (ContentsListIter = ContentsList.begin() ; ContentsListIter != ContentsList.end() ; ++ContentsListIter)
240 {
241 ContentId = *ContentsListIter;
242 ErrId = m_pIInstalledContentsControler->GetInstalledContentInfo(ContentId, m_ProviderId, false, ContentInfo);
243 string content_name = ContentInfo.BasicContentInfo.strExentName;
244 if(ErrId == AClientSDKErrIDs::ERR_SUCCESS &&
245 !(ContentInfo.dwStatus & CONTENT_STATUS_ERR_PROVIDER_DOESNOT_EXIST))
246 {
247 // If the content is not an AIG's content, we stop.
248 if (m_AigContentsMap.find(ContentId) == m_AigContentsMap.end())
249 {
250 return NOT_AIG_CONTENT_EXIST;
251 }
252
253 //Update AIG's map, if the content found in it
254 m_AigContentsMap[ContentId] = true;
255 }
256 }
257
258 // Loop over the AIG's map, and search for contents that have'nt downloaded yet.
259 AIG_MAP::iterator it;
260 for (it=m_AigContentsMap.begin(); it!=m_AigContentsMap.end(); ++it)
261 {
262 if ((*it).second == false)
263 {
264 return NOT_ALL_AIG_CONTENTS_EXIST;
265 }
266 }
267
268 return ALL_AIG_CONTENTS_EXIST;
269 }
270
271 /*------------------------------------------------------------------------
272 AContentPushMgr::TimingNotification()
273 Description:
274 CB function of the timer.
275 1. If XML dosn't exists - fetch it.
276 2. Get directions for relevan contents
277 Parameters:
278 dwThreadID = DWORD
279 ------------------------------------------------------------------------*/
280 void AContentPushMgr::TimingNotification(DWORD dwThreadID)
281 {
282
283 bool bRet;
284
285 AMutexLock lock( &m_TimingNotificationMutex );
286 if( !lock.Wait(CP_MGR_MUTEX_WAIT_TIME) )
287 {
288 DoLogEx( AERR, AClientSDKErrIDs::WAIT_ON_LOCK_ERR,"" );
289 return;
290 }
291
292 m_pNotificationsTimer->Pause();
293
294 // Check if AIG's XML already exists
295 if (!IsAIGsXmlFileExistsWithContents())
296 {
297 string strUrl;
298 bRet = GetUrlForAIGXmlFile(strUrl);
299 if (!bRet)
300 {
301 DoLogEx( AERR, AClientSDKErrIDs::ContentPushMgrLib::CONTENT_PUSH_MGR_CANNOT_RETRIVE_AIG_XML_URL, "");
302 return;
303 }
304
305 bRet = FetchXml(strUrl, m_wstrAIGXmlFileName);
306 if (!bRet)
307 {
308 DoLogEx( AERR, AClientSDKErrIDs::ContentPushMgrLib::CONTENT_PUSH_MGR_CANNOT_RETRIVE_AIG_LIST, "");
309 m_pNotificationsTimer->ReStart(m_dwIntervalForRetryOperationInSec*1000);
310 return;
311 }
312 }
313
314 bRet = CheckSignature();
315 if (!bRet)
316 {
317 DoLogEx( AERR, AClientSDKErrIDs::ContentPushMgrLib::CONTENT_PUSH_MGR_XML_SIGNATURE_INVALID, "");
318 return;
319 }
320
321 bRet = GetDSUrl(m_strDSUrl);
322 if (!bRet)
323 {
324 DoLogEx( AERR, AClientSDKErrIDs::ContentPushMgrLib::CONTENT_PUSH_MGR_XML_PARSING_ERROR, "");
325 return;
326 }
327
328
329 bRet = UpdateContentsMap();
330 if (!bRet)
331 {
332 m_pNotificationsTimer->ReStart(m_dwIntervalForRetryOperationInSec*1000);
333 DoLogEx( AERR, AClientSDKErrIDs::ContentPushMgrLib::CONTENT_PUSH_MGR_XML_PARSING_ERROR, "");
334 return;
335 }
336
337 if (CheckContentPushContentsState() != NOT_ALL_AIG_CONTENTS_EXIST)
338 {
339 m_pNotificationsTimer->Pause();
340 SetAlreadyRunSuccessfullyFlag();
341 return;
342 }
343
344 bRet = GetDirectionsForRelevantContents();
345 if (!bRet)
346 {
347 DoLogEx( AERR, AClientSDKErrIDs::ContentPushMgrLib::CONTENT_PUSH_MGR_FAILED_TO_GET_DIRECTIONS, "");
348 m_pNotificationsTimer->ReStart(m_dwIntervalForRetryOperationInSec*1000);
349 return;
350 }
351
352 m_pNotificationsTimer->ReStart(m_dwIntervalForRetryOperationInSec*1000);
353
354 }
355
356 /*------------------------------------------------------------------------
357 AContentPushMgr::TimerStopped()
358 Description:
359
360 Parameters:
361 dwThreadID = DWORD
362 ------------------------------------------------------------------------*/
363 void AContentPushMgr::TimerStopped(DWORD dwThreadID)
364 {
365 }
366
367
368 /*------------------------------------------------------------------------
369 AContentPushMgr::SetAlreadyRunSuccessfullyFlag()
370 Description:
371
372 Returns:
373 True if successful
374 ------------------------------------------------------------------------*/
375 bool AContentPushMgr::SetAlreadyRunSuccessfullyFlag()
376 {
377 bool bRes = false;
378 ISettingsDB* pSDB = NULL;
379
380 ISettingsMgr* pSMgr = ISettingsMgrFactory::GetInstance();
381 if ( pSMgr == NULL )
382 return false;
383
384 pSDB = pSMgr->GetInstance( "", m_ProviderId );
385 if ( pSDB == NULL )
386 return false;
387
388 bRes = pSDB->SetBaseSetting(PROVIDER_SETTING_CONTENT_PUSH_ALREADY_RUN_SUCCESSFULLY, true);
389 if(!bRes)
390 {
391 return false;
392 }
393
394 return true;
395 }
396
397 /*------------------------------------------------------------------------
398 AContentPushMgr::OnSucceed()
399 Description:
400 CB function for IGetDirections success.
401 Parameters:
402 dwContext = DWORD
403 wstrDirectionsAsString = std::wstring&
404 ------------------------------------------------------------------------*/
405 void AContentPushMgr::OnSucceed(DWORD dwContext, std::wstring& wstrDirectionsAsString)
406 {
407 string strDirections;
408 bool bRet;
409
410 ABinConverter::WStringToString(wstrDirectionsAsString, strDirections);
411
412 bRet = m_pContentPushCBObj->CP_AddGameToDownloadList((CONTENTID)dwContext,
413 m_ProviderId,
414 false,
415 strDirections,
416 (DWORD)-1);
417 // Updating content state as downloaded.
418 if (bRet == true)
419 {
420 m_AigContentsMap[(CONTENTID)dwContext] = true;
421 }
422
423 // Check if all games have already downloded successfully
424 if (CheckContentPushContentsState() != NOT_ALL_AIG_CONTENTS_EXIST)
425 {
426 m_pNotificationsTimer->Pause();
427 SetAlreadyRunSuccessfullyFlag();
428 }
429 }
430
431
432 /*------------------------------------------------------------------------
433 AContentPushMgr::OnFail()
434 Description:
435 CB function for IGetDirections failure.
436 Parameters:
437 dwContext = DWORD
438 err = GETDIRECTIONS_ERRORCODE
439 dwInfo = DWORD
440 pwszLastError = const WCHAR*
441 ------------------------------------------------------------------------*/
442 void AContentPushMgr::OnFail(DWORD dwContext,GETDIRECTIONS_ERRORCODE err,
443 DWORD dwInfo,
444 const WCHAR* pwszLastError)
445 {
446 // If the content need authentication, or dosn't exist, remove it from CP's map
447 if (err == GETDIRECTIONS_AUTENTICATION_FAILED ||
448 err == GETDIRECTIONS_GAME_NOT_AVAILABLE)
449 {
450 AIG_MAP::iterator it ;
451 it = m_AigContentsMap.find((CONTENTID)dwContext);
452 if (it != m_AigContentsMap.end())
453 {
454 m_AigContentsMap.erase(it);
455 }
456 if (err == GETDIRECTIONS_AUTENTICATION_FAILED)
457 {
458 DoLogEx( AERR, AClientSDKErrIDs::ContentPushMgrLib::CONTENT_PUSH_MGR_NOT_DEMO_CONTENT_EXISTS, "");
459 }
460 if (err == GETDIRECTIONS_GAME_NOT_AVAILABLE)
461 {
462 DoLogEx( AERR, AClientSDKErrIDs::ContentPushMgrLib::CONTENT_PUSH_MGR_CONTENT_ISNT_AVAILBLE, "");
463 }
464 }
465 }
466
467
468 /*------------------------------------------------------------------------
469 AContentPushMgr::IsAIGsXmlFileExistsWithContents()
470 Description:
471
472 Returns:
473 True if successful
474 ------------------------------------------------------------------------*/
475 bool AContentPushMgr::IsAIGsXmlFileExistsWithContents()
476 {
477 AXMLReader XMLReader;
478
479 // Load the xml from file.
480 if(!XMLParser::LoadXmlFromFile(m_wstrAIGXmlFileName , XMLReader))
481 {
482 // File doesn't exists
483 return false;
484 }
485
486 // parsing..
487 wstring wstrAttribName(L"");
488 CBasicStringConv cbsOut("");
489 DWORD dwOut = 0;
490 try
491 {
492 AXMLREADER_LIST itemList;
493 AXMLREADER_LIST::iterator itemListIter;
494 if(!XMLReader.XPathGetNodes(L"//cp:aig",OUT itemList))
495 {
496 return false;
497 }
498
499 if(itemList.empty())
500 {
501 DoLogEx(ADBG, AClientSDKErrIDs::XML_GET_NODE_ERR, "%S", L"//cp:aig");
502 return false;
503 }
504
505 for(itemListIter=itemList.begin();itemListIter!=itemList.end();itemListIter++)
506 {
507 AXMLReader readerItem = *itemListIter;
508
509 wstrAttribName = L"cp:contentid";
510 if(!readerItem.findAttribute(wstrAttribName, OUT cbsOut, L""))
511 {
512 // Empty list
513 DoLogEx(AERR, AClientSDKErrIDs::XML_FIND_ATTRIBUTE_ERR, "%S",L"cp:contentid");
514 return false;
515 }
516
517 // Not empty list
518 return true;
519 }
520 }
521 catch(_com_error comerr)
522 {
523 DoLogEx( AERR, AClientSDKErrIDs::XML_COM_ERR, "%d %s",comerr.Error, comerr.Description());
524 return false;
525 }
526
527 return false;
528 }
529
530
531 /*------------------------------------------------------------------------
532 AContentPushMgr::CancelCurrentHttpConnection()
533 Description:
534
535 ------------------------------------------------------------------------*/
536 void AContentPushMgr::CancelCurrentHttpConnection()
537 {
538 m_HttpConnection.Cancel();
539
540 if ( m_HttpConnection.IsConnected() )
541 {
542 m_HttpConnection.Disconnect();
543 }
544
545 if (m_pIGetDirections)
546 {
547 m_pIGetDirections->CancelAllRequests(0);
548 }
549 }
550
551 /*------------------------------------------------------------------------
552 AContentPushMgr::GetUrlForAIGXmlFile()
553 Description:
554
555 Parameters:
556 strUrl = string&
557 Returns:
558 True if successful
559 ------------------------------------------------------------------------*/
560 bool AContentPushMgr::GetUrlForAIGXmlFile(string& strUrl)
561 {
562 bool bRes = false;
563 ISettingsDB* pSDB = NULL;
564
565 ISettingsMgr* pSMgr = ISettingsMgrFactory::GetInstance();
566 if ( pSMgr == NULL )
567 return false;
568
569 pSDB = pSMgr->GetInstance( "", m_ProviderId );
570 if ( pSDB == NULL )
571 return false;
572
573 bRes = pSDB->GetSetting(PROVIDER_SETTING_CONTENT_PUSH_AIG_LIST_URL, strUrl);
574 if(!bRes)
575 {
576 return false;
577 }
578
579 // Concat MUID to the URL
580 std::string::size_type pos = strUrl.find("?");
581 if (pos == std::string::npos)
582 strUrl += "?";
583 else
584 strUrl += "&";
585 strUrl += CONTENT_PUSH_AIG_MUID_TAG + ASystem::GetRandMuidString();
586
587 return true;
588 }
589
590 /*------------------------------------------------------------------------
591 AContentPushMgr::GetDSUrl()
592 Description:
593 Retrieve the DirectionsSupplier URL from the XML
594 Parameters:
595 strDSUrl = string&
596 Returns:
597 True if successful
598 ------------------------------------------------------------------------*/
599 bool AContentPushMgr::GetDSUrl(string& strDSUrl)
600 {
601 AXMLReader XMLReader;
602 CBasicStringConv tmpString("");
603 string strUrl;
604
605 // Load the xml from file.
606 if(!XMLParser::LoadXmlFromFile(m_wstrAIGXmlFileName , XMLReader))
607 {
608 return false;
609 }
610
611 if(!XMLReader.XPathGetSingleNodeValue(L"//cp:dsurl",tmpString))
612 {
613 return false;
614 }
615
616 strUrl = tmpString.AsString();
617
618 // Add "track=AIG" to the url for server tracking
619 std::string::size_type pos = strUrl.find("?");
620 if (pos == std::string::npos)
621 strDSUrl = strUrl + "?";
622 else
623 strDSUrl = strUrl + "&";
624 strDSUrl += CONTENT_PUSH_AIG_TRACKING_TAG;
625
626 return true;
627 }
628
629 /*------------------------------------------------------------------------
630 AContentPushMgr::UpdateContentsMap()
631 Description:
632 Parse the XML and update the contents map with AIG's contents
633 Returns:
634 True if successful
635 ------------------------------------------------------------------------*/
636 bool AContentPushMgr::UpdateContentsMap()
637 {
638 AXMLReader XMLReader;
639
640 // Load the xml from file.
641 if(!XMLParser::LoadXmlFromFile(m_wstrAIGXmlFileName , XMLReader))
642 {
643 return false;
644 }
645
646 // parsing..
647 wstring wstrAttribName(L"");
648 CBasicStringConv cbsOut("");
649 DWORD dwOut = 0;
650 try
651 {
652 AXMLREADER_LIST itemList;
653 AXMLREADER_LIST::iterator itemListIter;
654 if(!XMLReader.XPathGetNodes(L"//cp:aig",OUT itemList))
655 {
656 return false;
657 }
658
659 if(itemList.empty())
660 {
661 DoLogEx(ADBG, AClientSDKErrIDs::XML_GET_NODE_ERR, "%S", L"//cp:aig");
662 return false;
663 }
664
665 for(itemListIter=itemList.begin();itemListIter!=itemList.end();itemListIter++)
666 {
667 AXMLReader readerItem = *itemListIter;
668
669 wstrAttribName = L"cp:contentid";
670 if(!readerItem.findAttribute(wstrAttribName, OUT cbsOut, L""))
671 {
672 DoLogEx(AERR, AClientSDKErrIDs::XML_FIND_ATTRIBUTE_ERR, "%S",L"cp:contentid");
673 return false;
674 }
675
676 // Insert content to map (value does'nt matter right now)
677 CONTENTID id = cbsOut.AsLong();
678 m_AigContentsMap[id] = 0;
679
680 }
681 }
682 catch(_com_error comerr)
683 {
684 DoLogEx( AERR, AClientSDKErrIDs::XML_COM_ERR, "%d %s",comerr.Error, comerr.Description());
685 return false;
686 }
687
688 return true;
689 }
690
691
692
693 /*------------------------------------------------------------------------
694 AContentPushMgr::FetchXml()
695 Description:
696
697 Parameters:
698 strUrl = string&
699 wstrTargetLocalPath = wstring&
700 Returns:
701 True if successful
702 ------------------------------------------------------------------------*/
703 bool AContentPushMgr::FetchXml( string& strUrl, wstring& wstrTargetLocalPath )
704 {
705 DWORD dwBuffSize = 0;
706 PBYTE pBuff = NULL;
707 DWORD dwBytesWritten = 0;
708
709 if ( !GetFileFromUrlToBuffer( strUrl,
710 pBuff,
711 dwBuffSize ) )
712 {
713 /*LogEx( AERR,
714 AClientSDKErrIDs::ContentPushMgrLib::FAILED_TO_DOWNLOAD_UPDATES ,
715 "%S",
716 m_HttpConnection.GetError() );
717 */
718 return false;
719 }
720
721 HANDLE hFile = CreateFileW( wstrTargetLocalPath.c_str(),
722 GENERIC_WRITE,
723 FILE_SHARE_WRITE,
724 NULL,
725 CREATE_ALWAYS,
726 FILE_ATTRIBUTE_NORMAL,
727 NULL );
728
729 if( hFile == INVALID_HANDLE_VALUE )
730 {
731 DoLogEx( AERR,
732 AClientSDKErrIDs::CREATE_FILE_ERROR,
733 "%S %d",
734 wstrTargetLocalPath.c_str(),
735 GetLastError() );
736
737 return false;
738 }
739
740
741 BOOL bRes = WriteFile( hFile, pBuff, dwBuffSize, &dwBytesWritten, NULL );
742
743 if( !bRes )
744 {
745 DoLogEx( AERR,
746 AClientSDKErrIDs::WRITE_FILE_ERROR,
747 "%S %d",
748 wstrTargetLocalPath.c_str(),
749 GetLastError() );
750
751 CloseHandle(hFile);
752 return false;
753 }
754
755 CloseHandle(hFile);
756
757 return true;
758 }
759
760
761 /*------------------------------------------------------------------------
762 AContentPushMgr::GetFileFromUrlToBuffer()
763 Description: buffer is allocated in function & must deallocated outside
764 if the function returns true
765
766 Parameters:
767 strUrl = IN const string&
768 pBuffer = OUT PBYTE
769 dwBufferSize = OUT DWORD&
770 Returns:
771 True if successful
772 ------------------------------------------------------------------------*/
773 bool AContentPushMgr::GetFileFromUrlToBuffer( IN const string& strUrl,
774 OUT PBYTE& pBuffer,
775 OUT DWORD& dwBufferSize )
776 {
777 if ( strUrl.empty() )
778 {
779 return false;
780 }
781
782 pBuffer = NULL;
783
784 bool bRet;
785 BYTE dummyBuffer[1]={NULL};
786 DWORD dwRequiredBufferSize = sizeof(dummyBuffer)/sizeof(BYTE);
787
788 bRet = m_HttpConnection.GetFromFullUrl( strUrl, dummyBuffer ,dwRequiredBufferSize, m_strProxy);
789
790 if(!bRet)
791 {
792 return false;
793 }
794
795 //We should look what is the required buffer size.
796 if( !m_HttpConnection.GetLastResponse( NULL, dwRequiredBufferSize ) )
797 {
798 return false;
799 }
800
801 if ( dwRequiredBufferSize <= 0 )
802 {
803 return false;
804 }
805
806 // Allocate response buffer.
807 // Adding 1 because of a bug in HttpConnection::GetLastResponse
808 //dwRequiredBufferSize;
809 pBuffer = new BYTE [dwRequiredBufferSize];
810
811 if(NULL == pBuffer)
812 {
813 return false;
814 }
815
816 ZeroMemory(pBuffer, dwRequiredBufferSize);
817
818 dwRequiredBufferSize++;
819
820 if( !m_HttpConnection.GetLastResponse( pBuffer, dwRequiredBufferSize ) )
821 {
822 delete [] pBuffer;
823 pBuffer = NULL;
824 return false;
825 }
826
827 dwBufferSize = dwRequiredBufferSize;
828
829 return true;
830 }
831
832
833 /*------------------------------------------------------------------------
834 AContentPushMgr::GetDirectionsForRelevantContents()
835 Description:
836
837 Returns:
838 True if successful
839 ------------------------------------------------------------------------*/
840 bool AContentPushMgr::GetDirectionsForRelevantContents()
841 {
842 bool bRes;
843
844 m_pIGetDirections = IGetDirectionsFactory::Create();
845 if(!m_pIGetDirections)
846 {
847 DoLogEx(AERR,AClientSDKErrIDs::FACTORY_CREATE_ERR,"");
848 return false;
849 }
850
851 // Init get direction object.
852 bRes = m_pIGetDirections->Init(m_strProxy);
853 if(!bRes)
854 {
855 DoLogEx(AERR,AClientSDKErrIDs::INIT_OBJECT_ERR,"");
856 return false;
857 }
858
859 AIG_MAP::const_iterator it;
860 for (it=m_AigContentsMap.begin(); it!=m_AigContentsMap.end(); ++it)
861 {
862 // Check if the content has already downloaded
863 if ((*it).second == true)
864 {
865 continue;
866 }
867
868 bRes = m_pIGetDirections->GetDirectionsAsync(m_strDSUrl,
869 (*it).first,
870 1,
871 ASystem::GetRandMuidString(),
872 L"",
873 L"",
874 DIRECTIONS_TYPE_DOWNLOAD,
875 NULL,
876 this,
877 (DWORD)((*it).first));
878 if(!bRes)
879 {
880 DoLogEx(AERR,AClientSDKErrIDs::GUI::GetRgmx::GET_DIRECTIONS_ASYNC_ERR,"%d %d %s %S", (*it).first, 1, m_strDSUrl.c_str(), L"");
881 return false;
882 }
883
884 }
885
886 return true;
887 }
888
889 /*------------------------------------------------------------------------
890 AContentPushMgr::IsAigContent()
891 Description:
892
893 Parameters:
894 contentId = CONTENTID
895 Returns:
896 True if successful
897 ------------------------------------------------------------------------*/
898 bool AContentPushMgr::IsAigContent(CONTENTID contentId)
899 {
900 AIG_MAP::iterator it;
901 it = m_AigContentsMap.find(contentId);
902
903 if (it != m_AigContentsMap.end())
904 return true;
905 else
906 return false;
907 }
908
909
910 /*------------------------------------------------------------------------
911 AContentPushMgr::CheckSignature()
912 Description:
913 Check the AIGXML signature
914 Returns:
915 True if successful
916 ------------------------------------------------------------------------*/
917 bool AContentPushMgr::CheckSignature()
918 {
919 IXmlRSASignatureValidator* pValidator = NULL;
920 XML_SIGNATURE_ERR Err = XML_SIGNATURE_OK;
921 bool bRes = true;
922
923 // Creat the validator.
924 pValidator = IXMLEncryptionLibFactory::CreateRSAValidator();
925 if(!pValidator)
926 {
927 return false;
928 }
929
930 try
931 {
932 bRes = pValidator->LoadFromFile(m_wstrAIGXmlFileName);
933 if(!bRes)
934 {
935 bRes = false;
936 throw("");
937 }
938
939 // Set the sign key.
940 Err = pValidator->SetSigningPublicKey(XML_VERIFY_MOD, XML_VERIFY_EXP);
941 if(Err != XML_SIGNATURE_OK)
942 {
943 bRes = false;
944 throw("");
945 }
946
947 // Validate the signature.
948 Err = pValidator->Validate();
949 if(Err != XML_SIGNATURE_OK)
950 {
951 bRes = false;
952 throw("");
953 }
954
955 // Clean the validator object.
956 if(pValidator)
957 {
958 if(pValidator->IsLoaded())
959 {
960 pValidator->Unload();
961 }
962
963 IXMLEncryptionLibFactory::Release(pValidator);
964 pValidator = NULL;
965 }
966 }
967 catch(...)
968 {
969 bRes = false;
970 }
971
972 return bRes;
973 }
 
  
Legend:
Removed 
Changed
 Added

[Add General Comment] to topic.