📄 repll.c
字号:
}
/*========================================================================
REP_StoreResourceHelp
==========================================================================*/
BOOL REP_StoreResourceHelp (void* pContext, pREPCONTENTSTRUCT pResource,
UINT32* piContentID, UINT32* piSize)
{
BYTE *pbData=NULL;
UINT32 iDataSize=0;
UINT16 iUrlLen=0;
UINT32 iHeaderLen=0;
UINT32 iDataLen=0;
UINT32 iHashValue=0;
/* Resource must be defined */
if (pResource!=NULL)
{
/* Get size of url */
iUrlLen=B_STRINGLENGTH((pResource->content).pResContentStruct->pbUrl);
/* Get size of WSP header */
iHeaderLen=(((pResource->content).pResContentStruct->pHeaderHandle)->pbEnd)-
(((pResource->content).pResContentStruct->pHeaderHandle)->pbData);
/* Get size of Data */
iDataLen=(pResource->content).pResContentStruct->iBodyLength;
/* Calculate total size of resource */
iDataSize=(14+iUrlLen+iHeaderLen+iDataLen);
/* Check if enough free memory */
if (Storage_AllocateBlock(&((REPCONTEXT*)pContext)->Storage,
iDataSize, piContentID))
{
/* OK. Copy data to repository. */
pbData=REP_CreateResourceData (pResource,iDataSize,
iHeaderLen,iUrlLen,iDataLen);
if (pbData==NULL)
{
return FALSE;
}
/* Store the resource under the ContentID */
if (Storage_Put (&((REPCONTEXT*)pContext)->Storage,
*piContentID, 0, iDataSize, pbData))
{
DEALLOC(&pbData);
/* Store the ContentID in the resource */
pResource->iId=*piContentID;
/* Calculate hash value */
b_HashURL((pResource->content).
pResContentStruct->pbUrl,&iHashValue);
/* Add resource to tMODIFYROOT list in context with
action RESOURCE_REMOVE */
REP_AddToModifyRoot (pContext,*piContentID,
RESOURCE_ADD,iHashValue);
/* Add resource id to context along with its hash value */
REP_AddResourceToContext (pContext,*piContentID,iHashValue);
/* Return Content Id and size */
*piSize=iDataSize;
/* Deduct from reserved memory */
((REPCONTEXT*)pContext)->iReserved-=iDataSize;
return TRUE;
}
DEALLOC(&pbData);
}
}
return FALSE;
}
/*========================================================================
REP_StoreResource
==========================================================================*/
BOOL REP_StoreResource (void* pContext, pREPCONTENTSTRUCT pResource,
UINT32* piContentID, UINT32* piSize)
{
UINT32 iResourceId=0;
BOOL fResult=FALSE;
fResult=REP_StoreResourceHelp(pContext,pResource,&iResourceId,piSize);
if (fResult)
{
*piContentID=iResourceId;
}
return fResult;
}
/*========================================================================
REP_UpdateResource
==========================================================================*/
BOOL REP_UpdateResource (void* pContext, pREPCONTENTSTRUCT pResource,
UINT32 iContentID, INT32* piSizeChange)
{
UINT32 iOldSize=0;
UINT16 iUrlLen=0;
UINT32 iHeaderLen=0;
UINT32 iDataLen=0;
UINT32 iResourceSize=0;
UINT32 iNewSize=0;
BOOL fResult=FALSE;
#ifdef WTA_DEBUG
xTraceAlg("Update resource");
#endif
/* Resource must be defined */
if (pResource!=NULL)
{
/* Get old size */
iOldSize=Storage_GetBlockSize(&((REPCONTEXT*)pContext)->Storage,iContentID);
if (iOldSize!=0)
{
/* Get size of url */
iUrlLen=B_STRINGLENGTH((pResource->content).pResContentStruct->pbUrl);
/* Get size of WSP header */
iHeaderLen=(((pResource->content).pResContentStruct->pHeaderHandle)->pbEnd)-
(((pResource->content).pResContentStruct->pHeaderHandle)->pbData);
/* Get size of Data */
iDataLen=(pResource->content).pResContentStruct->iBodyLength;
/* Calculate total size of resource */
iResourceSize=(14+iUrlLen+iHeaderLen+iDataLen);
*piSizeChange=iResourceSize-iOldSize;
#ifdef WTA_DEBUG
xTraceAlg("Store resource");
#endif
if (*piSizeChange>0)
{
#ifdef WTA_DEBUG
xTraceAlg("Store resource new on same location");
#endif
/* New resource bigger than old. Check if it will fit. */
if (Storage_NumBytesFree(&((REPCONTEXT*)pContext)->Storage)<
(UINT32)(*piSizeChange))
{
return FALSE;
}
}
/* Remove old resource */
Storage_DeleteBlock(&((REPCONTEXT*)pContext)->Storage,iContentID);
/* Store new resource */
fResult=REP_StoreResourceHelp(pContext,pResource,&iContentID,&iNewSize);
*piSizeChange=iNewSize-iOldSize;
}
}
return fResult;
}
/*========================================================================
REP_GetContentWithID
==========================================================================*/
pREPCONTENTSTRUCT REP_GetContentWithID (void* pContext, UINT32 iContentID,
UINT8 iType)
{
UINT32 iContentSize=0;
BYTE* pbData=NULL;
pREPCONTENTSTRUCT pContent=NULL;
#ifdef WTA_DEBUG
xTraceAlg("REP_GetContentWithId - inside");
#endif
/* If content is REP_ROOTBLK_ID - return NULL */
if (iContentID==REP_ROOTBLK_ID)
{
return NULL;
}
/* Get size of Content */
iContentSize=Storage_GetBlockSize (&((REPCONTEXT*)pContext)->Storage,
iContentID);
if (iContentSize!=0)
{
/* Allocate memory */
pbData=NEWARRAY(BYTE,iContentSize);
/* Get Content */
if (Storage_Get(&((REPCONTEXT*)pContext)->Storage,
iContentID,0,iContentSize,pbData))
{
pContent=NEWSTRUCT(REPCONTENTSTRUCT);
pContent->Type=pbData[0];
pContent->iId=iContentID;
#ifdef WTA_DEBUG
{
char chHex[4];
BYTE bTemp=0;
int i=0;
chHex[2]='.';
chHex[3]=0;
xTraceAlg("REP_GetContentWithId - content found");
for (i=0; i<iContentSize; i++)
{
bTemp=pbData[i];
/* First digit */
if ((bTemp/16)<10)
{
chHex[0]=(bTemp/16)+48;
}
else
{
chHex[0]=(bTemp/16)+55;
}
/* Second digit */
if ((bTemp % 16)<10)
{
chHex[1]=(bTemp % 16)+48;
}
else
{
chHex[1]=(bTemp % 16)+55;
}
URL_DEBUG_PRINT(chHex);
}
}
#endif
/* Check type - channel or resource */
if ((pbData[0]==CONTENTTYPE_CHANNEL)&&(iType==CONTENTTYPE_CHANNEL))
{
#ifdef WTA_DEBUG
xTraceAlg("REP_GetContentWithId - Get channel");
#endif
pContent->content.pChContentStruct=REP_GetStoredChannel (pbData);
}
else if ((pbData[0]==CONTENTTYPE_RESOURCE)&&(iType==CONTENTTYPE_RESOURCE))
{
#ifdef WTA_DEBUG
xTraceAlg("REP_GetContentWithId - Get resource");
#endif
pContent->content.pResContentStruct=REP_GetStoredResource (pbData);
/* Check if error in content retrieval */
if (pContent->content.pResContentStruct==NULL)
{
DEALLOC(&pContent);
/* Remove content id */
Storage_DeleteBlock(&((REPCONTEXT*)pContext)->Storage,
iContentID);
/* Add resource to tMODIFYROOT list in context with
action RESOURCE_REMOVE */
REP_AddToModifyRoot (pContext,iContentID,RESOURCE_REMOVE,0);
}
}
else
{
/* Error */
DEALLOC(&pContent);
}
}
/* Deallocate memory */
DEALLOC(&pbData);
#ifdef WTA_DEBUG
xTraceAlg("REP_GetContentWithId - Exiting");
#endif
}
return pContent;
}
/*========================================================================
REP_RootBlockSafe
==========================================================================*/
void REP_RootBlockSafe (void* pContext, BOOL fSafe)
{
if (pContext!=NULL)
{
/* Change status in root block */
if (fSafe)
{
/* Update root block */
if (REP_UpdateRootBlock (pContext))
{
/* OK - Set status to OK */
REP_ChangeRootBlockStatus(pContext,REPROOT_STATUS_OK);
}
else
{
/* Error - remove root block */
REP_ChangeRootBlockStatus(pContext,REPROOT_STATUS_CORRUPT);
}
}
else
{
REP_ChangeRootBlockStatus(pContext,REPROOT_STATUS_PROCESSING);
}
}
}
/*========================================================================
REP_DecreaseInstallCounter
==========================================================================*/
BOOL REP_DecreaseInstallCounter (void* pContext, UINT32 iContentID)
{
if (REP_ChangeResourceStatus(pContext,iContentID,-1,0))
{
return TRUE;
}
return FALSE;
}
/*========================================================================
REP_StoreChannel
==========================================================================*/
BOOL REP_StoreChannel (void* pContext, pREPCONTENTSTRUCT pChannel,
UINT32* piContentID, UINT32* piSize)
{
UINT16 iTitleLen=0;
UINT16 iAbstractLen=0;
UINT16 iEventIDLen=0;
UINT16 iChannelIDLen=0;
UINT8 iNbrRes=0;
UINT32 iChLen=0;
UINT32 iOffset=0;
UINT32 iContentID=0;
BYTE* pbData=NULL;
BOOL fStoreFailed=FALSE;
if (pChannel!=NULL)
{
/* Get size of title */
if ((pChannel->content).pChContentStruct->pwchTitle!=NULL)
{
iTitleLen=STRINGLENGTH((pChannel->content).pChContentStruct->pwchTitle);
}
/* Get size of abstract */
if ((pChannel->content).pChContentStruct->pwchAbstract!=NULL)
{
iAbstractLen=STRINGLENGTH((pChannel->content).pChContentStruct->pwchAbstract);
}
/* Get size of EventID */
if ((pChannel->content).pChContentStruct->pwchEventId!=NULL)
{
iEventIDLen=STRINGLENGTH((pChannel->content).pChContentStruct->pwchEventId);
}
/* Get size of ChannelID */
if ((pChannel->content).pChContentStruct->pwchchannelid!=NULL)
{
iChannelIDLen=STRINGLENGTH((pChannel->content).pChContentStruct->pwchchannelid);
}
#ifdef WTA_DEBUG
{
char stTemp[10];
URL_DEBUG_PRINT("Event id len (Storing) : ");
_itoa( iEventIDLen, stTemp, 10 );
URL_DEBUG_PRINT(stTemp);
}
#endif
/* Get number of resources */
iNbrRes=(UINT8)(pChannel->content).pChContentStruct->iResCounter;
/* Calculate total size of channel */
iChLen=(16+iTitleLen*2+iAbstractLen*2+iEventIDLen*2+iChannelIDLen*2+iNbrRes*4);
/* Check if enough free memory */
if (Storage_AllocateBlock(&((REPCONTEXT*)pContext)
->Storage, iChLen, &iContentID))
{
/* OK. Copy data to repository. */
pbData=NEWARRAY(BYTE,iChLen);
pbData[0]=CONTENTTYPE_CHANNEL;
pbData[1]=CONTENT_INSTALLING;
(pChannel->content).pChContentStruct->iStatus=CONTENT_INSTALLING;
iOffset=2;
/* Expiry date */
B_COPYSTRINGN(pbData+iOffset,&((pChannel->content).
pChContentStruct->iExpiryDate),4);
/* Store User Accessible */
if ((pChannel->content).pChContentStruct->useraccess)
{
pbData[6]=0x01;
}
else
{
pbData[6]=0x00;
}
iOffset+=5;
/* Store length of title */
B_COPYSTRINGN(pbData+iOffset,&iTitleLen,2);
iOffset+=2;
/* Store title */
if ((pChannel->content).pChContentStruct->pwchTitle!=NULL)
{
B_COPYSTRINGN(pbData+iOffset,((pChannel->content).
pChContentStruct->pwchTitle),2*iTitleLen);
iOffset+=(2*iTitleLen);
}
/* Store length of abstract */
B_COPYSTRINGN(pbData+iOffset,&iAbstractLen,2);
iOffset+=2;
/* Store abstract */
if ((pChannel->content).pChContentStruct->pwchAbstract!=NULL)
{
B_COPYSTRINGN(pbData+iOffset,((pChannel->content).
pChContentStruct->pwchAbstract),(2*iAbstractLen));
iOffset+=(2*iAbstractLen);
}
/* Store length of eventid */
B_COPYSTRINGN(pbData+iOffset,&iEventIDLen,2);
iOffset+=2;
/* Store eventid */
if ((pChannel->content).pChContentStruct->pwchEventId!=NULL)
{
B_COPYSTRINGN(pbData+iOffset,((pChannel->content).
pChContentStruct->pwchEventId),(2*iEventIDLen));
iOffset+=(2*iEventIDLen);
}
/* Store length of channelid */
B_COPYSTRINGN(pbData+iOffset,&iChannelIDLen,2);
iOffset+=2;
/* Store channelid */
if ((pChannel->content).pChContentStruct->pwchchannelid!=NULL)
{
B_COPYSTRINGN(pbData+iOffset,((pChannel->content).
pChContentStruct->pwchchannelid),(2*i
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -