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

📄 repll.c

📁 是一个手机功能的模拟程序
💻 C
📖 第 1 页 / 共 5 页
字号:

	The function is called by REP_CompareUrl and REP_CalculateHashValues

	Input: pContext (MUST be pREPCONTEXT) and Resource Id
	Output: Url, NULL if error.
========================================================================*/
BYTE* REP_GetResourceUrl (void* pContext, UINT32 iResourceId)
{
	BYTE* pbUrl=NULL;
	BYTE abData[6];
	UINT16 iLen=0;

	/* Get resource header */
	if (Storage_Get(&((REPCONTEXT*)pContext)->Storage,iResourceId,0,6,abData))
	{
		/* OK - get length of url */
		B_COPYSTRINGN(&(iLen),abData+4,2);

		if (iLen!=0)
		{
			/* Allocate memory for url and termination char */
			pbUrl=NEWARRAY(BYTE,iLen+1);

			/* Get url */
			if (Storage_Get(&((REPCONTEXT*)pContext)->Storage,
													iResourceId,6,iLen,pbUrl))
			{
				/* Set termination char */
				pbUrl[iLen]=0;
			}
			else
			{
				/* Error */
				DEALLOC(&pbUrl);
			}
		}
	}

	return pbUrl;
}


/*========================================================================
	REP_CompareUrl
==========================================================================
	The function compares the inputted url with the url of the resource
	stored at the inputted resource id. If the urls are equivalent, TRUE
	is returned, otherwise FALSE is returned.

	The function is called by REP_GetResourceWithUrl

	Input: pContext (MUST be pREPCONTEXT) url, and ResourceId
	Output: TRUE/FALSE
==========================================================================*/
BOOL REP_CompareUrl (void* pContext, BYTE* pbUrl, UINT32 iResourceId)
{
	BOOL fResult=FALSE;
	BYTE* pbTemp=NULL;

	/* Get stored resource url */
	pbTemp=REP_GetResourceUrl(pContext,iResourceId);

	if (pbTemp!=NULL)
	{
		/* Compare url:s */
		fResult=b_EqualURL(pbUrl,pbTemp,ALL_COMP);

		/* Dealloc temporary memory */
		DEALLOC(&pbTemp);
	}

	return fResult;
}


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

	The function is called by REP_GetContentWithId

	Input: Data
	Output: Pointer to CHCONTENTSTRUCT
==========================================================================*/
pCHCONTENTSTRUCT REP_GetStoredChannel (BYTE* pbData)
{
	pCHCONTENTSTRUCT pChannel=NULL;
	UINT16 iLen=0;
	UINT8 iLen8=0;
	UINT32 iOffset=0;

	#ifdef WTA_DEBUG
		xTraceAlg("Inside REP_GetStoredChannel");
	#endif

	/* Create struct */
	pChannel=NEWSTRUCT(CHCONTENTSTRUCT);
	pChannel->iStatus=0;
	pChannel->iExpiryDate=0;
	pChannel->pwchTitle=NULL;
	pChannel->pwchAbstract=NULL;
	pChannel->pwchEventId=NULL;
	pChannel->piAllResInChList=NULL;
	pChannel->iResCounter=0;

	/* Store in struct */
	pChannel->iStatus=pbData[1];

	/* Copy User Accessible */
	if (pbData[6]==0x00)
	{
		pChannel->useraccess=FALSE;
	}
	else
	{
		pChannel->useraccess=TRUE;
	}
	
	/* Copy expiry date */
	B_COPYSTRINGN(&(pChannel->iExpiryDate),pbData+2,4);
	iOffset+=7;
	
	/* Get length of title */
	B_COPYSTRINGN(&(iLen),pbData+iOffset,2);
	iOffset+=2;
	
	/* Copy title */
	if (iLen!=0)
	{
		pChannel->pwchTitle=NEWARRAY(WCHAR,iLen+1);
		B_COPYSTRINGN(pChannel->pwchTitle,pbData+iOffset,iLen*2);
		iOffset+=iLen*2;

		/* Set termination char */
		pChannel->pwchTitle[iLen]=0;
	}
	else
	{
		pChannel->pwchTitle=NULL;
	}

	/* Get length of abstract */
	B_COPYSTRINGN(&(iLen),pbData+iOffset,2);
	iOffset+=2;

	if (iLen!=0)
	{
		/* Copy abstract */
		pChannel->pwchAbstract=NEWARRAY(WCHAR,iLen+1);
		B_COPYSTRINGN(pChannel->pwchAbstract,pbData+iOffset,iLen*2);
		iOffset+=iLen*2;
		
		/* Set termination char */
		pChannel->pwchAbstract[iLen]=0;
	}
	else
	{
		pChannel->pwchAbstract=NULL;
	}

	#ifdef WTA_DEBUG
		xTraceAlg("REP_GetStoredChannel - after abstract");
	#endif
		
	/* Get length of eventid */
	B_COPYSTRINGN(&(iLen),pbData+iOffset,2);
	iOffset+=2;

	#ifdef WTA_DEBUG
	{
		char stTemp[10];

		URL_DEBUG_PRINT("Event id len : ");
		_itoa( iLen, stTemp, 10 );
		URL_DEBUG_PRINT(stTemp);
	}
	#endif

	if (iLen!=0)
	{
		/* Copy eventid */
		pChannel->pwchEventId=NEWARRAY(WCHAR,iLen+1);
		B_COPYSTRINGN(pChannel->pwchEventId,pbData+iOffset,iLen*2);
		iOffset+=iLen*2;
		
		/* Set termination char */
		pChannel->pwchEventId[iLen]=0;
	}
	else
	{
		pChannel->pwchEventId=NULL;
	}

	/* Get length of channelid */
	B_COPYSTRINGN(&(iLen),pbData+iOffset,2);
	iOffset+=2;

	if (iLen!=0)
	{
		/* Copy channelid */
		pChannel->pwchchannelid=NEWARRAY(WCHAR,iLen+1);
		B_COPYSTRINGN(pChannel->pwchchannelid,pbData+iOffset,iLen*2);
		iOffset+=iLen*2;
		
		/* Set termination char */
		pChannel->pwchchannelid[iLen]=0;
	}
	else
	{
		pChannel->pwchchannelid=NULL;
	}

	#ifdef WTA_DEBUG
		xTraceAlg("REP_GetStoredChannel - Getting Res List Len");
	#endif

	/* Get length of ResList */
	B_COPYSTRINGN(&(iLen8),pbData+iOffset,1);
	pChannel->iResCounter=iLen8;
	iOffset+=1;

	#ifdef WTA_DEBUG
		xTraceAlg("REP_GetStoredChannel - Getting Res List");
	#endif

	/* Copy ResList */
	pChannel->piAllResInChList=NEWARRAY(UINT32,(iLen8*4));
	B_COPYSTRINGN(pChannel->piAllResInChList,pbData+iOffset,(iLen8*4));

	#ifdef WTA_DEBUG
		xTraceAlg("REP_GetStoredChannel - Exiting");
	#endif

	return pChannel;
}


/*========================================================================
	REP_GetStoredResource
==========================================================================
	The function extracts data from the instream and returns the resource
	part of a REPCONTENTSTRUCT. The instream must be correct. It is the
	caller's responsibility to deallocate the returned data. The function
	returns NULL if the WSP_PreParseHeaders returns NULL or sets the 
	error flag.

	The function is called by REP_GetContentWithId.

	Input: Data
	Output: Pointer to RESCONTENTSTRUCT
==========================================================================*/
pRESCONTENTSTRUCT REP_GetStoredResource (BYTE* pbData)
{
	pRESCONTENTSTRUCT pResource=NULL;
	UINT32 iOffset=0;
	UINT16 iLen=0;
	UINT32 iLen32=0;
	BOOL fError=FALSE;

	pResource=NEWSTRUCT(RESCONTENTSTRUCT);

	pResource->iStatus=(UINT8)(pbData[1]);
	pResource->iRefCounter=(UINT8)(pbData[2]);
	pResource->iInstallCounter=(UINT8)(pbData[3]);

	iOffset=4;

	/* Get length of url and allocate memory */
	B_COPYSTRINGN(&(iLen),pbData+iOffset,2);
	pResource->pbUrl=NEWARRAY(BYTE,iLen+1);
	iOffset+=2;

	/* Copy url */
	B_COPYSTRINGN(pResource->pbUrl,pbData+iOffset,iLen);
	iOffset+=iLen;

	/* Set termination char */
	pResource->pbUrl[iLen]=0;

	/* Get length of header and allocate memory */
	B_COPYSTRINGN(&(iLen32),pbData+iOffset,4);
	iOffset+=4;

	/* Check scheme. If not FILE, do */

	/* Preparse header and store in resource */
	pResource->pHeaderHandle=
				WSP_PreParseHeaders(pbData+iOffset,iLen32,&fError);

	if ((fError)||(pResource->pHeaderHandle==NULL))
	{
		/* Error in pre-parse - remove all data and return NULL */
		WSP_EmptyHeaderList(pResource->pHeaderHandle);
		pResource->pHeaderHandle=NULL;

		DEALLOC(&(pResource->pbUrl));
		DEALLOC(&pResource);

		/* Fatal error. All channels using this resource MUST be 
		   deleted - or the resource MUST be updated. */

		/* ... */

		return NULL;
	}

	/* If FILE scheme, do */

	/* ... */

	/* Step past header */
	iOffset+=iLen32;
	
	/* Get length of data and allocate memory */
	B_COPYSTRINGN(&(iLen32),pbData+iOffset,4);
	pResource->iBodyLength=iLen32;
	pResource->pbBodyData=NEWARRAY(BYTE,iLen32);
	iOffset+=4;

	/* Copy data */
	B_COPYSTRINGN(pResource->pbBodyData,pbData+iOffset,iLen32);

	return pResource;
}


/*========================================================================
	REP_ChangeResourceStatus
==========================================================================
	The function changes the RefCounter and the InstallCounter of the
	specified resource. The counter are modified with the values in the
	iInstMod and iRefMod parameters. If the change of counters affects the
	status of the resource, it is changes accordingly. If both the Ref-
	Counter and the InstallCounter reaches 0, the resource is removed.

	The function also creates a tMODIFYROOT-element if the change of
	the resource also affects the root block (i.e., if the resource is
	removed from the repository, it is also removed from the root block.)

	The function is called by REP_PutChannelInSDLList, REP_GetResourse-
	WithUrl, REP_DecreaseInstallCounter, REP_InstallChannel and 
	REP_ActivateChannel

	Input: pContext (MUST be pREPCONTEXT) ContentId, iInstMod, iRefMod
	Output: TRUE if OK, FALSE if error
==========================================================================*/
BOOL REP_ChangeResourceStatus (void* pContext, UINT32 iContentId, 
							  INT8 iInstMod, INT8 iRefMod)
{
	BYTE abData[4];
	BOOL fRemove=FALSE;

	/* Find resource */
	if (Storage_Get(&((REPCONTEXT*)pContext)->Storage,iContentId,0,4,abData))
	{
		if (abData[0]==CONTENTTYPE_RESOURCE)
		{
			/* Change counters */
			abData[2]=(UINT8)(abData[2]+iRefMod);
			abData[3]=(UINT8)(abData[3]+iInstMod);

			/* Change status */
			if ((abData[3]==0)&&(abData[2]!=0))
			{
				/* Activate resource */
				abData[1]=CONTENT_ACTIVE;
			}
			else if (abData[3]!=0)
			{
				/* Status installing */
				abData[1]=CONTENT_INSTALLING;
			}
			else if ((abData[3]==0)&&(abData[2]==0))
			{
				/* Remove resource */
				fRemove=TRUE;
			}

			if (fRemove)
			{
				/* Remove from repository */
				Storage_DeleteBlock (&((REPCONTEXT*)pContext)->Storage, 
																iContentId);

				/* Add resource to tMODIFYROOT list in context with
				   action RESOURCE_REMOVE */
				REP_AddToModifyRoot (pContext,iContentId,RESOURCE_REMOVE,0);

				return TRUE;
			}
			else
			{
				/* Update resource */
				if (Storage_Put(&((REPCONTEXT*)pContext)->Storage,
												iContentId,0,4,abData))
				{
					/* OK */
					return TRUE;
				}
			}
		}
	}

	return FALSE;
}


/*========================================================================
	REP_CreateResourceData
==========================================================================
	The function created the data for a resource to be stored in the
	repository.

	Called by REP_StoreResource and REP_UpdateResource

	Input: pContext (MUST be pREPCONTEXT) ContentId, iInstMod, iRefMod
	Output: TRUE if OK, FALSE if error
==========================================================================*/
BYTE* REP_CreateResourceData (pREPCONTENTSTRUCT pResource, UINT32 iDataSize,
							  UINT32 iHeaderLen, UINT32 iUrlLen, UINT32 iDataLen)
{
	BYTE* pbData=NULL;

	/* Create new data array */
	pbData=NEWARRAY(BYTE,iDataSize);

	pbData[0]=CONTENTTYPE_RESOURCE;
	pbData[1]=CONTENT_INSTALLING;
	(pResource->content).pResContentStruct->iStatus=CONTENT_INSTALLING;

	/* Store no of referring channels and install counter */
	pbData[2]=(pResource->content).pResContentStruct->iRefCounter;
	pbData[3]=(pResource->content).pResContentStruct->iInstallCounter;

	/* Store length of url */
	B_COPYSTRINGN(pbData+4,&iUrlLen,2);
	
	/* Store url */
	B_COPYSTRINGN(pbData+6,
		(pResource->content).pResContentStruct->pbUrl,iUrlLen);

	/* Store header length */
	B_COPYSTRINGN(pbData+6+iUrlLen,&iHeaderLen,4);

	/* Store WSP headers */
	B_COPYSTRINGN(pbData+10+iUrlLen,(pResource->content).
		pResContentStruct->pHeaderHandle->pbData,iHeaderLen);

	/* Store data length */
	B_COPYSTRINGN(pbData+10+iUrlLen+iHeaderLen,&iDataLen,4);

	/* Store data */
	B_COPYSTRINGN(pbData+14+iUrlLen+iHeaderLen,
		(pResource->content).pResContentStruct->pbBodyData,iDataLen);

	return pbData;
}






/*========================================================================
	HELP FUNCTIONS FOR REP_ScanRepository
=========================================================================*/

/*========================================================================
	REP_RemoveAllUnrefResources
==========================================================================
	The function removes all non-'id 0' in the piResourceList from the 
	hash list and from the repository. The function should be called 
	until it returns FALSE. The function uses the iCurrentElement to keep 
	track of the next element to evaluate.

	The function is called by REP_ScanRepository

	Input: pContext (MUST be pREPCONTEXT)

⌨️ 快捷键说明

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