📄 repll.c
字号:
/*
* Copyright (C) Ericsson Mobile Communications AB, 2000.
* Licensed to AU-System AB.
* All rights reserved.
*
* This software is covered by the license agreement between
* the end user and AU-System AB, and may be used and copied
* only in accordance with the terms of the said agreement.
*
* Neither Ericsson Mobile Communications AB nor AU-System AB
* assumes any responsibility or liability for any errors or inaccuracies in
* this software, or any consequential, incidental or indirect damage arising
* out of the use of the Generic WAP Client software.
*/
/*========================================================================
WAP WTA Implementation Project
==========================================================================
File: RepLL.c
Description:
Author: Jens Pommer, AU-System Radio AB
Revision history:
Date Sign Comment
990803 CEF First version
991001 JPR Functions updated
991006 JPR tMODIFYROOT struct and functions added
991008 JPR Function REP_UpdateResource added
991012 JPR REP_ScanRepository implemented. Functions updated.
991013 JPR WTA_DEBUG included
991019 JPR Updates in functions
991102 JPR Corrections
991105 JPR Merge with file with xTraceAlg and some corrections.
991110 JPR Correction in calls of Free_RepContent
000207 JPR Functions REP_GetNextChToRemove and
REP_RemoveAllStaleChannels added
000207 JPR Updated for new adapters
000215 JPR Function REP_PutChannelInSDLList updated.
000216 JPR Function REP_ScanRepository updated (installing
channels are removed during scan)
000223 JPR Correction in REP_GetStoredResource (memory leak)
000206 JPR Error handling added to REP_StoreChannel
000324 JPR Correction in functions REP_GetNextChToRemove and
REP_PutChannelInSDLList
000406 JPR Correction in function REP_PutChannelInSDLList
000530 JPR Correction in function REP_MergeUpdateRootBlock
000630 JPR Updated for WAP 1.2.1
001011 ASPN Lower-case filenames
010125 JPR Space for User Accessible attribute added in function
REP_StoreChannel
010221 ASPN Correction in REP_GetNextChToRemove, due to the added
attribute User Accessible
010303 ASPN User Accessible and Expiry Date attributes switched
place in memory structure
=========================================================================*/
/* Private include statements */
#include "repll.h"
#include "aapimem.h"
/* Debug in SDL set WTA_DEBUG to 1 */
/*========================================================================
==========================================================================
INTERNAL FUNCTIONS
==========================================================================
=========================================================================*/
/*========================================================================
HELP FUNCTIONS FOR HANDLING THE ROOT BLOCK
=========================================================================*/
/*========================================================================
REP_AddResourceToContext
==========================================================================
The function adds the resource id along with its hash value to the
context.
The function is called by REP_StoreResource
Input: pContext (MUST be pREPCONTEXT), ContentId, and hash value
Output: -
========================================================================*/
void REP_AddResourceToContext (void* pContext, UINT32 iContentId,
UINT32 iHashValue)
{
UINT32 *piTemp=NULL;
UINT16 iNbrRes=0;
UINT16 iCount=0;
BOOL fError=FALSE;
/* Get number of resources */
iNbrRes=((REPCONTEXT*)pContext)->iNumberOfResources;
/* Create new content id list */
piTemp=NEWARRAY(UINT32,iNbrRes+1);
/* Copy old list to new, also check if content id already in list */
while (iCount<iNbrRes)
{
if (((REPCONTEXT*)pContext)->piResourceList[iCount]!=iContentId)
{
piTemp[iCount]=((REPCONTEXT*)pContext)->piResourceList[iCount];
}
else
{
fError=TRUE;
}
iCount++;
}
if (!fError)
{
/* Dealloc old list and store new list */
DEALLOC(&((REPCONTEXT*)pContext)->piResourceList);
((REPCONTEXT*)pContext)->piResourceList=piTemp;
/* Create new hash list */
piTemp=NEWARRAY(UINT32,iNbrRes+1);
iCount=0;
/* Copy hash values */
while (iCount<iNbrRes)
{
piTemp[iCount]=((REPCONTEXT*)pContext)->piHashList[iCount];
iCount++;
}
/* Dealloc old list and store new list */
DEALLOC(&((REPCONTEXT*)pContext)->piHashList);
((REPCONTEXT*)pContext)->piHashList=piTemp;
/* Store new content id and hash value */
((REPCONTEXT*)pContext)->piResourceList[iNbrRes]=iContentId;
((REPCONTEXT*)pContext)->piHashList[iNbrRes]=iHashValue;
/* Increase resource counter in context */
((REPCONTEXT*)pContext)->iNumberOfResources++;
}
else
{
/* Error - delete new list */
DEALLOC(&piTemp);
}
}
/*========================================================================
REP_RemoveModifyList
==========================================================================
The function removes the modify list in the context.
The function is called by REP_UpdateRootBlock
Input: pContext (MUST be pREPCONTEXT).
Output: -
========================================================================*/
void REP_RemoveModifyList (void* pContext)
{
pMODIFYROOT pTemp=NULL;
pMODIFYROOT pRemove=NULL;
pTemp=((REPCONTEXT*)pContext)->pModRoot;
while (pTemp!=NULL)
{
pRemove=pTemp;
pTemp=pTemp->pNext;
DEALLOC(&pRemove);
}
((REPCONTEXT*)pContext)->pModRoot=NULL;
}
/*========================================================================
REP_AddToModifyRoot
==========================================================================
The function creates a new tMODIFYROOT-element and sets the fields
to the inputted values. If the element is not in the pModResources
list in the context it is added. If it already exists, the element in
the list is updated according to the repository.
The function is called by REP_DeleteChannel, REP_GetResourseWithUrl,
REP_StoreResource, REP_ChangeResourceStatus, and REP_ActivateChannel.
Input: pContext (MUST be pREPCONTEXT), ContentId, Action, and
Hash Value (only if action RESOURCE_ADD)
Output: -
========================================================================*/
void REP_AddToModifyRoot (void* pContext, UINT32 iContentId,
UINT8 iAction, UINT32 iHashValue)
{
BYTE bData;
BOOL fAdd=TRUE;
pMODIFYROOT pNew=NULL;
pMODIFYROOT pTemp=NULL;
/* Check if list not null */
if (((REPCONTEXT*)pContext)->pModRoot!=NULL)
{
pTemp=((REPCONTEXT*)pContext)->pModRoot;
/* Check if already in list */
while ((pTemp!=NULL)&&(fAdd))
{
if (pTemp->iContentId==iContentId)
{
/* Found, do not add new */
fAdd=FALSE;
}
else
{
/* Get next element in list */
pTemp=pTemp->pNext;
}
}
}
if (fAdd)
{
/* Create new element */
pNew=NEWSTRUCT(MODIFYROOT);
pNew->iAction=iAction;
pNew->iContentId=iContentId;
pNew->iHashValue=iHashValue;
pNew->pNext=((REPCONTEXT*)pContext)->pModRoot;
/* Add to list */
((REPCONTEXT*)pContext)->pModRoot=pNew;
}
else
{
/* Change element in list */
if (pTemp->iAction!=iAction)
{
/* Check if content exists */
if (Storage_Get(&((REPCONTEXT*)pContext)->Storage,
iContentId,0,1,&bData))
{
if (bData==CONTENTTYPE_RESOURCE)
{
pTemp->iAction=RESOURCE_ADD;
}
else if (bData==CONTENTTYPE_CHANNEL)
{
pTemp->iAction=CHANNEL_ADD;
}
}
else
{
if ((iAction==RESOURCE_REMOVE)||(iAction==RESOURCE_ADD))
{
pTemp->iAction=RESOURCE_REMOVE;
}
else if ((iAction==CHANNEL_REMOVE)||(iAction==CHANNEL_ADD))
{
pTemp->iAction=CHANNEL_REMOVE;
}
}
}
}
}
/*========================================================================
REP_CountResourcesDiff
==========================================================================
The function returns the maximal sum of the resources in the
tMODIFYROOT-element list. Action *RESOURCE_ADD* increases the sum
with one (*RESOURCE_REMOVE* has no effect).
The function is called by REP_UpdateRootBlock
Input: pContext (MUST be pREPCONTEXT).
Output: UINT32
========================================================================*/
UINT32 REP_CountResourcesDiff (void* pContext)
{
INT32 iNbr=0;
pMODIFYROOT pTemp=NULL;
pTemp=((REPCONTEXT*)pContext)->pModRoot;
while (pTemp!=NULL)
{
/* Check action */
if (pTemp->iAction==RESOURCE_ADD)
{
iNbr++;
}
pTemp=pTemp->pNext;
}
return iNbr;
}
/*========================================================================
REP_CountChannelDiff
==========================================================================
The function returns the maximal sum of the channels in the
tMODIFYROOT-element list. Action *CHANNEL_ADD* increases the sum with
one (*CHANNEL_REMOVE* has no effect).
The function is called by REP_UpdateRootBlock
Input: pContext (MUST be pREPCONTEXT).
Output: UINT32
========================================================================*/
UINT32 REP_CountChannelDiff (void* pContext)
{
INT32 iNbr=0;
pMODIFYROOT pTemp=NULL;
pTemp=((REPCONTEXT*)pContext)->pModRoot;
while (pTemp!=NULL)
{
/* Check action */
if (pTemp->iAction==CHANNEL_ADD)
{
iNbr++;
}
pTemp=pTemp->pNext;
}
return iNbr;
}
/*========================================================================
REP_UpdateRootBlockChannels
==========================================================================
The function updates merges the updated root blocks (created by
REP_UpdateRootBlockChannels and REP_UpdateRootBlockResources) and
returns a new root block. The length (piNewSize is also updated
accordingly).
The function is called by REP_UpdateRootBlock
Input: RootBlks, pointer to new size, and ResourceDiff
Output: New root block, size is stored in piNewSize
========================================================================*/
BYTE* REP_MergeUpdateRootBlock (BYTE* pbChRoot, BYTE* pbResRoot,
UINT32* piNewSize)
{
BYTE* pbRootBlk=NULL;
UINT32 iSize=0;
UINT32 iTempId=0;
UINT32 iTempHash=0;
UINT16 iNbrCh=0;
UINT16 iNbrRes=0;
UINT16 iCount=0;
UINT16 iWrite=0;
/* Calculate new total size */
B_COPYSTRINGN(&iNbrCh,pbChRoot+1,2);
B_COPYSTRINGN(&iNbrRes,pbResRoot+3,2);
iSize=5+(iNbrCh*4)+(iNbrRes*8);
/* Create new root block */
pbRootBlk=NEWARRAY(BYTE,iSize);
/* Copy channel parts into new block */
while (iCount<iNbrCh)
{
/* Get next channel id */
B_COPYSTRINGN(&iTempId,pbChRoot+5+(iCount*4),4);
if (iTempId!=0)
{
/* Store channel id */
B_COPYSTRINGN(pbRootBlk+5+(iWrite*4),&iTempId,4);
iWrite++;
}
iCount++;
}
/* Store nbr of channels */
B_COPYSTRINGN(pbRootBlk+1,&iNbrCh,2);
/* Find the start position of the resources in the pbResRoot string */
B_COPYSTRINGN(&iNbrCh,pbResRoot+1,2);
iCount=0;
/* Copy resource parts into new block */
while (iCount<iNbrRes)
{
/* Get next resource id */
B_COPYSTRINGN(&iTempId,pbResRoot+5+((iCount+iNbrCh)*4),4);
if (iTempId!=0)
{
/* Get hash */
B_COPYSTRINGN(&iTempHash,pbResRoot+5+(iNbrRes*4)+((iCount+iNbrCh)*4),4);
/* Store resource id and hash value */
B_COPYSTRINGN(pbRootBlk+5+(iWrite*4),&iTempId,4);
B_COPYSTRINGN(pbRootBlk+5+((iNbrRes+iWrite)*4),&iTempHash,4);
iWrite++;
}
iCount++;
}
/* Store nbr of resources */
B_COPYSTRINGN(pbRootBlk+3,&iNbrRes,2);
/* Store status "Processing" */
pbRootBlk[0]=REPROOT_STATUS_PROCESSING;
/* Update size and return */
*piNewSize=iSize;
return pbRootBlk;
}
/*========================================================================
REP_UpdateRootBlockChannels
==========================================================================
The function updates the channels in the root block according to the
tMODIFYROOT-elements in the context. The input data (pbRootBlk)
contains the old root block, but is large enough to include all
changes.
The function is called by REP_UpdateRootBlock
Input: pContext (MUST be pREPCONTEXT), RootBlk
Output: -
========================================================================*/
void REP_UpdateRootBlockChannels (void* pContext, BYTE* pbRootBlk)
{
UINT16 iNbrCh=0;
UINT32 iCount=0;
UINT32 iTempId=0;
UINT32 iZero=0;
BOOL fFound=FALSE;
pMODIFYROOT pTemp=NULL;
pTemp=((REPCONTEXT*)pContext)->pModRoot;
B_COPYSTRINGN(&iNbrCh,pbRootBlk+1,2);
/* Step through the channels in the Modify List */
while (pTemp!=NULL)
{
if (pTemp->iAction==CHANNEL_ADD)
{
/* Add channel id to root block */
iCount=0;
fFound=FALSE;
/* Find id 0 */
while ((iCount<iNbrCh)&&(!fFound))
{
/* Get id */
B_COPYSTRINGN(&iTempId,pbRootBlk+5+(iCount*4),4);
if (iTempId==0)
{
/* Space found - use this index */
fFound=TRUE;
}
else
{
iCount++;
}
}
/* Store id */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -