⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pushll.c

📁 是一个手机功能的模拟程序
💻 C
📖 第 1 页 / 共 3 页
字号:
#ifdef FILE_PUSH_REPOSITORY
	INT32 liFileSize;
#endif

#ifdef WAE_DEBUG
	URL_DEBUG_PRINT("End PUSH_DeletePush");
#endif

	if (!pushMem.isInitialized) {
		return FALSE;
	}

	/* Find the push content to delete */
	pPushContent = (PUSHCONTENTSTRUCT *)PUSH_GetContentWithID(((PUSHCONTEXT*)pContext),iContentID,iType);

    /* Remove the push from push memory */
#ifdef FILE_PUSH_REPOSITORY
	liFileSize=FILEa_getSize(PUSH_CATEGORY, iContentID);
	pushMem.storageSize -= (liFileSize==-1) ? 0 : liFileSize; 
	FILEa_delete(PUSH_CATEGORY, iContentID);
	fOK = TRUE;
#else
	fOK=Storage_DeleteBlock(&((PUSHCONTEXT*)pContext)->Storage,iContentID);
#endif

	if (pPushContent!=NULL)
	{
		ME_Free_PushContentStruct(pPushContent);
		return fOK;
	}
	return FALSE;

} /* end of PUSH_DeletePush */

/*========================================================================
	PUSH_GetStoredSI
==========================================================================
	The function extracts data from the instream and returns the SI
	part of a PUSHCONTENTSTRUCT. The instream must be correct. It is the
	caller's responsibility to deallocate the returned data.

	The function is called by PUSH_GetContentWithId

	Input: Data
	Output: Pointer to SICONTENTSTRUCT
==========================================================================*/
pSICONTENTSTRUCT PUSH_GetStoredSI (BYTE* pbData)
{
	pSICONTENTSTRUCT pContent=NULL;
	UINT32 iOffset=0;
	UINT16 iLen=0;

	if (!pushMem.isInitialized) {
		return NULL;
	}

	pContent=NEWSTRUCT(SICONTENTSTRUCT);
	if (pContent==NULL)
	{
		return NULL;
	}

	
	pContent->iStatus=(UINT8)(pbData[1]);
	pContent->iAction=(UINT8)(pbData[10]);

	/* Copy iCreated */
	B_COPYSTRINGN(&(pContent->iCreated),pbData+2,4);
	/* Copy iExpires */
	B_COPYSTRINGN(&(pContent->iExpires),pbData+6,4);

	/* Get length of SIid and allocate memory */
	B_COPYSTRINGN(&(iLen),pbData+13,2);
	if (pbData[15] == 0 && iLen == 1)																		
		pContent->pwchSIid = NULL;
	else
	{
		pContent->pwchSIid=NEWARRAY(WCHAR,iLen+1);
		if (pContent->pwchSIid==NULL)
		{
			DEALLOC(&(pContent));
			return NULL;
		}
		/* Copy SIid */
		B_COPYSTRINGN(pContent->pwchSIid,pbData+15,iLen*2);
		/* Set termination char */
		pContent->pwchSIid[iLen]=0;
	}
	iOffset=15+iLen*2;

/* Get length of url and allocate memory */
	B_COPYSTRINGN(&(iLen),pbData+iOffset,2);
	if (pbData[iOffset + 2] == 0 && iLen == 1)
	{
		pContent->pbUrl = NULL;
		iOffset+=2;
	}
	else
	{
		pContent->pbUrl=NEWARRAY(BYTE,iLen+1);
		if (pContent->pbUrl==NULL)
		{
			DEALLOC(&(pContent->pwchSIid));
			DEALLOC(&(pContent));
			return NULL;
		}
		iOffset+=2;
		/* Copy url */
		B_COPYSTRINGN(pContent->pbUrl,pbData+iOffset,iLen);  
		/* Set termination char */
		pContent->pbUrl[iLen]=0;	
	}
	iOffset+=iLen;

/* Get length of text message and allocate memory */
	B_COPYSTRINGN(&(iLen),pbData+iOffset,2);
	if (pbData[iOffset + 2] == 0 && iLen == 1)
	{
		pContent->pwchMessage = NULL;
		iOffset+=2;
	}
	else
	{
		pContent->pwchMessage=NEWARRAY(WCHAR,iLen+1);
		if (pContent->pwchMessage==NULL)
		{
			DEALLOC(&(pContent->pwchSIid));
			DEALLOC(&(pContent->pbUrl));
			DEALLOC(&(pContent));
			return NULL;
		}
		iOffset+=2;
		/* Copy message text */
		B_COPYSTRINGN(pContent->pwchMessage,pbData+iOffset,iLen*2);
		/* Set termination char */
		pContent->pwchMessage[iLen]=0;
	}
	
	iOffset = iOffset + 2*iLen; 

	/* Get length of InitUri and allocate memory */
	B_COPYSTRINGN(&(iLen),pbData+iOffset,2);	
	iOffset+=2;	
	if (pbData[iOffset] == 0 && iLen == 1)
		pContent->pbInitUri = NULL;
	else
	{
		pContent->pbInitUri=NEWARRAY(BYTE,iLen+1);
		if (pContent->pbInitUri==NULL)
		{		
			DEALLOC(&(pContent->pwchMessage));
			DEALLOC(&(pContent->pwchSIid));
			DEALLOC(&(pContent->pbUrl));
			DEALLOC(&(pContent));
			return NULL;
		}
		/* Copy message text */
		B_COPYSTRINGN(pContent->pbInitUri,pbData+iOffset,iLen);	
		/* Set termination char */
		pContent->pbInitUri[iLen]=0;
	}

	return pContent;
} /* End of PUSH_GetStoredSI */

/*========================================================================
	PUSH_GetStoredSL
==========================================================================
	The function extracts data from the instream and returns the SL
	part of a PUSHCONTENTSTRUCT. The instream must be correct. It is the
	caller's responsibility to deallocate the returned data.

	The function is called by PUSH_GetContentWithId

	Input: Data
	Output: Pointer to SLCONTENTSTRUCT
==========================================================================*/
pSLCONTENTSTRUCT PUSH_GetStoredSL (BYTE* pbData)
{
	pSLCONTENTSTRUCT pContent=NULL;
	UINT32 iOffset=0;
	UINT16 iLen=0;

	if (!pushMem.isInitialized) {
		return NULL;
	}

	pContent=NEWSTRUCT(SLCONTENTSTRUCT);
	if (pContent==NULL)
	{
		return NULL;
	}
	pContent->iStatus=(UINT8)(pbData[1]);
	pContent->iAction=(UINT8)(pbData[2]);

	/* Get length of url and allocate memory */
	B_COPYSTRINGN(&(iLen),pbData+5,2);
	pContent->pbUrl=NEWARRAY(BYTE,iLen+1);
	if (pContent->pbUrl==NULL)
	{
		DEALLOC(&(pContent));
		return NULL;
	}
	/* Copy url */
	B_COPYSTRINGN(pContent->pbUrl,pbData+7,iLen);  
	/* Set termination char */
	pContent->pbUrl[iLen]=0;
	iOffset = 7 + iLen;

	/* Get length of InitUri and allocate memory */
	B_COPYSTRINGN(&(iLen),pbData+iOffset,2);
	iOffset+=2;
	/* Copy message text */
	if (pbData[iOffset] == 0 && iLen == 1)
		pContent->pbInitUri = NULL;
	else
	{
		pContent->pbInitUri=NEWARRAY(BYTE,iLen+1);
		if (pContent->pbInitUri==NULL)
		{		
			DEALLOC(&(pContent->pbUrl));
			DEALLOC(&(pContent));
			return NULL;
		}
		B_COPYSTRINGN(pContent->pbInitUri,pbData+iOffset,iLen);	
		/* Set termination char */
		pContent->pbInitUri[iLen]=0;
	}
	
	return pContent;

} /* End of PUSH_GetStoredSL */

/*========================================================================
	PUSH_ScanForContent
==========================================================================
	The function scans the memory for content and creates a list of all 
	pushes in the push buffer (pushes that have expired are removed from
	the push buffer). The list is of the type LISTHEADER and the elements 
	in the list are of the type PUSHLISTSTRUCT. It is the caller's 
	responsibility to deallocate the memory. The function should be 
	called repeatedly until it returns FALSE. 

	NOTE! When the function is called the first time, ppContentList 
	should be NULL.

	Input: void* (MUST be pPUSHCONTEXT), void** (MUST be LISTHEADER**)
	Output: TRUE if the function should be called again, FALSE otherwise
==========================================================================*/
BOOL PUSH_ScanForContent( void* pContentList, void* pContext )
{
	UINT16	iNbrOfElm=0;
	UINT32* piContentList=NULL;
	UINT32	iCurId=0;
	BYTE*	pbData=NULL;
	UINT8	iRes;
	pPUSHLISTSTRUCT pPushListStruct=NULL;
	UINT16	iLen=0;
	UINT32	iLen32=0;
	INT32	myLen=0;
	BYTE*	pbTemp = NULL;
	BOOL    myCheck = FALSE;

#ifdef WAE_DEBUG
	URL_DEBUG_PRINT("End PUSH_ScanForContent");
#endif

	if (!pushMem.isInitialized) {     
		return FALSE;
	}

	/* Check ScanPhase */
	switch (((pPUSHCONTEXT)(pContext))->iScanPhase)
	{
	case 1:

		if (pContentList!=NULL)   
		{
			/* First time. Get all contentids */
#ifdef FILE_PUSH_REPOSITORY
			iNbrOfElm=FILEa_getFileIds(PUSH_CATEGORY, NULL, 65535);
			if (iNbrOfElm!=0) {
				piContentList = NEWARRAY (UINT32, iNbrOfElm);
				if (piContentList==NULL)
					return FALSE;
				iNbrOfElm=FILEa_getFileIds(PUSH_CATEGORY, piContentList, iNbrOfElm);
				if (iNbrOfElm==-1) {
					DEALLOC(&piContentList);
					return FALSE;
				}
			}
#else
			if (!Storage_GetAllBlockIds(&((PUSHCONTEXT*)pContext)->Storage, &piContentList,&iNbrOfElm))
				return FALSE;
#endif
			if (iNbrOfElm!=0)
			{
				/* Store data in context */
				((PUSHCONTEXT*)(pContext))->piElementList=piContentList;
				((PUSHCONTEXT*)(pContext))->iNumberOfElements=iNbrOfElm;
				((PUSHCONTEXT*)(pContext))->iCurrentElement=0; 
				/* Go to Phase 2. */
				((pPUSHCONTEXT)(pContext))->iScanPhase=2; 
				return TRUE;
			}
			return FALSE;

		}
		/* Error */
		break;
		
	case 2:

		/* Check if more id:s to scan. */
		if ( ((pPUSHCONTEXT)(pContext))->iCurrentElement <
					((PUSHCONTEXT*)(pContext))->iNumberOfElements )
		{
			/* Get id */
			iCurId=((pPUSHCONTEXT)(pContext))->
				piElementList[((PUSHCONTEXT*)(pContext))->iCurrentElement];

			/* Get size of content */
#ifdef FILE_PUSH_REPOSITORY
			myLen = FILEa_getSize(PUSH_CATEGORY, iCurId);
			iLen32 = myLen!=-1 ? (UINT32) myLen : 0;
			if (iLen32 != 0 && (pushMem.storageSize+iLen32)>pushMem.maxStorageSize) {
				iLen32=0;
				FILEa_delete(PUSH_CATEGORY, iCurId);
			}
			pushMem.storageSize+=iLen32;
#else
			iLen32 = Storage_GetBlockSize(&((PUSHCONTEXT*)pContext)->Storage,iCurId);
#endif
			if (iLen32 != 0)
			{
				pbData=NEWARRAY(BYTE,iLen32);
				/* Get content */
#ifdef FILE_PUSH_REPOSITORY
				myLen = FILEa_read(PUSH_CATEGORY, iCurId, (void *) pbData, 0, iLen32);
				myCheck = myLen!=-1 ? TRUE : FALSE;
#else
				myCheck = Storage_Get(&((PUSHCONTEXT*)pContext)->Storage,iCurId,0,iLen32,pbData);
#endif

				if (myCheck)
				{
					pPushListStruct=NEWSTRUCT(PUSHLISTSTRUCT);
					/* Check type */
					if (pbData[0] == SI)
					{  
						/* Get Expires date */										
						B_COPYSTRINGN(&(pPushListStruct->iExpires),pbData+6,4);		
						/* Get Created date */
						B_COPYSTRINGN(&(pPushListStruct->iCreated),pbData+2,4);
						pPushListStruct->iPushType=(UINT8)pbData[0];
						pPushListStruct->iStatus=(UINT8)pbData[1];
						pPushListStruct->iAction=(UINT8)pbData[10];
						pPushListStruct->iLLPushId=iCurId;
						/* Get length of PushId */
						B_COPYSTRINGN(&iLen,pbData+12,2);
						pPushListStruct->pwchPushId=NEWARRAY(WCHAR,iLen+1);
						/* Get pwchPushId */
						B_COPYSTRINGN(pPushListStruct->pwchPushId,pbData+14,iLen*2);
						/* Set termination char */
						pPushListStruct->pwchPushId[iLen]=0;
						iRes = ME_Push_List_Add(pContentList,(void*)pPushListStruct);
					}   
					else  /* Type is SL  */ 
					{
						pPushListStruct->iPushType=(UINT8)pbData[0];
						pPushListStruct->iStatus=(UINT8)pbData[1];
						pPushListStruct->iAction=(UINT8)pbData[2];
						pPushListStruct->iLLPushId=iCurId;
						/* Get length of PushId */				
						B_COPYSTRINGN(&iLen,pbData+4,2);
						pbTemp = NEWARRAY(BYTE,iLen+1);						
						/* Get pwchPushId */
						B_COPYSTRINGN(pbTemp,pbData+6,iLen);					/*Need pbTemp to convert from BYTE to WCHAR*/
						/*pPushListStruct->pwchPushId=NEWARRAY(WCHAR,iLen+1);*/
						pPushListStruct->pwchPushId = wip_byte2wchar(pbTemp);
						DEALLOC(&pbTemp);

						/* Set termination char */
						pPushListStruct->pwchPushId[iLen]=0;
						iRes = ME_Push_List_Add(pContentList,(void*)pPushListStruct);	
					}
				}
				DEALLOC(&pbData);
			}
			/* Next element in list */
			((PUSHCONTEXT*)(pContext))->iCurrentElement++;
			return TRUE;
		}
		else /* No more in Push memory */
		{
			/* Clean up */
			((PUSHCONTEXT*)(pContext))->iScanPhase=0;
			((PUSHCONTEXT*)(pContext))->iCurrentElement=0;
			((PUSHCONTEXT*)(pContext))->iNumberOfElements=0;
			DEALLOC(&(((PUSHCONTEXT*)(pContext))->piElementList));
			return FALSE;
		}
	} /* end switch */
	return FALSE;

} /* end of PUSH_ScanForContent */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -