📄 pushll.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 Push Implementation Project
==========================================================================
File: PushLL.C
Description:
Author: Martin Ranstorp, Kent Olsson AU-System AB
Revision history:
Date Rev Sign Comment
990930 PA1 MRP First version
991206 PA2 MRP Updated. Working in WAE test environment
000124 PA3 MRP Updated after inspection.
000214 PA4 MRP Copyright added.
000316 PA5 MRP Push API changed.
000511 PA6 MRP Startup scanning changed.
001114 PA7 KEOL Uppdated after change request regarding handling of GetSI and GetSL (reply with initiators URI as well)
001212 PA8 HEAD The repository is now initiated and closed from the application.
002020 PA9 HEAD Instead of storage can now a file-api be used to store push messages.
------------------------------------------------------------------------*/
/* Private include statements */
#include "cmmnrsrc.h"
#include "pushll.h"
#include "push.h"
#include "storage.h"
#include "aapimem.h"
#include "aapipush.h"
#ifdef FILE_PUSH_REPOSITORY
#include "aapifile.h"
#define PUSH_CATEGORY (char) 'P'
#endif
/* Private strucs */
static struct{
UINT8 isInitialized;
#ifdef FILE_PUSH_REPOSITORY
UINT32 storageSize;
UINT32 maxStorageSize;
#else
StorageObject *store;
#endif
} pushMem = {0};
/*========================================================================
INTERNAL FUNCTIONS
=========================================================================*/
/*========================================================================
EXTERNAL FUNCTIONS
=========================================================================*/
/*========================================================================
PUSH_Store
==========================================================================
Purpose: Store an Push in permanent push memory
Params: vsPushContent (MUST be of pPUSHCONTENTSTRUCT type)
Return: 0 =OK, -1 = Error, -2 = Message larger than repository.
=========================================================================*/
INT8 PUSH_Store( void* pContext, void* pvPushContent,
UINT32* piContentID )
{
PUSHCONTENTSTRUCT* pPushContent=NULL;
BYTE *pbData=NULL;
UINT32 iDataSize=0;
UINT16 iUrlLen=0;
UINT16 iSIidLen=0;
UINT16 iMessLen=0;
UINT16 iInitUriLen=0;
BOOL myCheck;
#ifdef FILE_PUSH_REPOSITORY
INT32 iBytesWritten;
INT16 iFile;
#endif
#ifdef WAE_DEBUG
URL_DEBUG_PRINT("End PUSH_Store");
#endif
if (!pushMem.isInitialized) {
return -1;
}
pPushContent = (PUSHCONTENTSTRUCT*)pvPushContent;
/* Push content to store must be defined */
if (pPushContent!=NULL)
{
if (pPushContent->iType == SI) /* content type is SI */
{
/* Get size of Url */
if ((pPushContent->content).pSIContentStruct->pbUrl != NULL)
{
iUrlLen=B_STRINGLENGTH((char*)(pPushContent->content).pSIContentStruct->pbUrl);
}
else
iUrlLen = 1;
/* Get size of SI-id */
if ((pPushContent->content).pSIContentStruct->pwchSIid != NULL)
{
iSIidLen=STRINGLENGTH((pPushContent->content).pSIContentStruct->pwchSIid);
}
else
iSIidLen = 1;
/* Get size of message text */
if ((pPushContent->content).pSIContentStruct->pwchMessage != NULL)
{
iMessLen=STRINGLENGTH((pPushContent->content).pSIContentStruct->pwchMessage);
}
else
iMessLen = 1;
/* Get size of InitUri */
if ((pPushContent->content).pSIContentStruct->pbInitUri != NULL)
{
iInitUriLen=B_STRINGLENGTH((char *)(pPushContent->content).pSIContentStruct->pbInitUri);
}
else
iInitUriLen = 1;
/* Calculate total size of resource */
iDataSize=(22+iUrlLen+(2*iSIidLen)+(2*iMessLen)+ iInitUriLen);
/* Check if enough free memory */
#ifdef FILE_PUSH_REPOSITORY
if (iDataSize>pushMem.maxStorageSize)
return -2;
if ((pushMem.storageSize+iDataSize)<=pushMem.maxStorageSize) {
iFile = FILEa_create (PUSH_CATEGORY, piContentID);
myCheck= (iFile==-1) ? FALSE : TRUE;
}
else
myCheck = FALSE;
#else
if (iDataSize>(((PUSHCONTEXT*)pContext)->Storage).size)
return -2;
myCheck = Storage_AllocateBlock(&((PUSHCONTEXT*)pContext)->Storage, iDataSize, piContentID);
#endif
if (myCheck)
{
/* OK. Copy data to push memory. */
pbData=NEWARRAY(BYTE,iDataSize);
if (pbData==NULL)
{
return -1;
}
pbData[0]=SI;
pbData[1]=PUSH_STORED;
(pPushContent->content).pSIContentStruct->iStatus=PUSH_STORED;
/* Store Created date */
B_COPYSTRINGN(pbData+2,&((pPushContent->content).pSIContentStruct->iCreated),4);
/* Store Expires date */
B_COPYSTRINGN(pbData+6,&((pPushContent->content).pSIContentStruct->iExpires),4);
/* Store Action */
pbData[10]=(pPushContent->content).pSIContentStruct->iAction;
/* Store PortType */
pbData[11]=pPushContent->iPortType;
/* Store iNewChannelId */
pbData[12]=pPushContent->iNewChannelId;
/* Store SIid length */
B_COPYSTRINGN(pbData+13,&iSIidLen,2);
/* Store SIid */
if ((pPushContent->content).pSIContentStruct->pwchSIid != NULL)
{
/* Store SIid */
B_COPYSTRINGN(pbData+15,
(void*)(pPushContent->content).pSIContentStruct->pwchSIid,2*iSIidLen);
}
else
pbData[15] = 0;
/* Store Url length */
B_COPYSTRINGN(pbData+15+2*iSIidLen,&iUrlLen,2);
/* Store url */
if ((pPushContent->content).pSIContentStruct->pbUrl != NULL)
{
/* Store url */
B_COPYSTRINGN(pbData+17+2*iSIidLen,
(void*)(pPushContent->content).pSIContentStruct->pbUrl,iUrlLen);
}
else
pbData[17+2*iSIidLen] = 0;
/* Store message text length */
B_COPYSTRINGN(pbData+17+2*iSIidLen+iUrlLen,&iMessLen,2);
/* Store message */
if ((pPushContent->content).pSIContentStruct->pwchMessage != NULL)
{
/* Store message */
B_COPYSTRINGN(pbData+19+2*iSIidLen+iUrlLen,
(void*)(pPushContent->content).pSIContentStruct->pwchMessage,2*iMessLen);
}
else
pbData[19+2*iSIidLen+iUrlLen] = 0;
/* Store InitUri length */
B_COPYSTRINGN(pbData+19+2*iSIidLen+iUrlLen+2*iMessLen,&iInitUriLen,2);
/* Store inituri */
if ((pPushContent->content).pSIContentStruct->pbInitUri != NULL)
{
/* Store inituri */
B_COPYSTRINGN(pbData+21+2*iSIidLen+iUrlLen+2*iMessLen,
(void*)((pPushContent->content).pSIContentStruct->pbInitUri),iInitUriLen);
}
else
pbData[21+2*iSIidLen+iUrlLen+2*iMessLen] = 0;
/* Store the SI under the ContentID */
#ifdef FILE_PUSH_REPOSITORY
iBytesWritten = FILEa_write(PUSH_CATEGORY, *piContentID, pbData, 0, iDataSize);
myCheck = (iBytesWritten == -1 || iDataSize!=(UINT32) iBytesWritten) ? FALSE : TRUE;
if (!myCheck)
FILEa_delete(PUSH_CATEGORY, *piContentID);
else {
pushMem.storageSize+=iBytesWritten;
FILEa_flush (PUSH_CATEGORY, *piContentID);
}
#else
myCheck = Storage_Put (&((PUSHCONTEXT*)pContext)->Storage,*piContentID, 0, iDataSize, pbData);
#endif
if (myCheck)
{
/* Store the ContentID in the resource */
pPushContent->iId=*piContentID;
DEALLOC(&pbData);
return 0;
}
DEALLOC(&pbData);
}
}
else if (pPushContent->iType == SL) /* content type is SL */
{
/* Get size of Url */
iUrlLen=B_STRINGLENGTH((char*)(pPushContent->content).pSLContentStruct->pbUrl);
/* Get size of InitUri */
if ((pPushContent->content).pSLContentStruct->pbInitUri != NULL)
{
iInitUriLen=B_STRINGLENGTH((char *)(pPushContent->content).pSLContentStruct->pbInitUri);
}
else
iInitUriLen = 1;
/* Calculate total size of resource */
iDataSize=(9+iUrlLen+iInitUriLen);
/* Check if enough free memory */
#ifdef FILE_PUSH_REPOSITORY
if (iDataSize>pushMem.maxStorageSize)
return -2;
if ((pushMem.storageSize+iDataSize)<=pushMem.maxStorageSize) {
iFile = FILEa_create (PUSH_CATEGORY, piContentID);
myCheck= (iFile==-1) ? FALSE : TRUE;
}
else
myCheck = FALSE;
#else
if (iDataSize>(((PUSHCONTEXT*)pContext)->Storage).size)
return -2;
myCheck = Storage_AllocateBlock(&((PUSHCONTEXT*)pContext)->Storage, iDataSize, piContentID);
#endif
if (myCheck)
{
/* OK. Copy data to push memory. */
pbData=NEWARRAY(BYTE,iDataSize);
if (pbData==NULL)
{
return -1;
}
pbData[0]=SL;
pbData[1]=PUSH_STORED;
(pPushContent->content).pSLContentStruct->iStatus=PUSH_STORED;
/* Store Action */
pbData[2]=(pPushContent->content).pSLContentStruct->iAction;
/* Store PortType */
pbData[3]=pPushContent->iPortType;
/* Store iNewChannelId */
pbData[4]=pPushContent->iNewChannelId;
/* Store Url length */
B_COPYSTRINGN(pbData+5,&iUrlLen,2);
/* Store url */
B_COPYSTRINGN(pbData+7,
(void*)(pPushContent->content).pSLContentStruct->pbUrl,iUrlLen);
/* Store InitUri length */
B_COPYSTRINGN(pbData+7+iUrlLen,&iInitUriLen,2);
if ((pPushContent->content).pSLContentStruct->pbInitUri != NULL)
{
/* Store inituri */
B_COPYSTRINGN(pbData+9+iUrlLen,
(void*)((pPushContent->content).pSLContentStruct->pbInitUri),iInitUriLen);
}
else
pbData[9+iUrlLen] = 0;
/* Store the SL under the ContentID */
#ifdef FILE_PUSH_REPOSITORY
iBytesWritten = FILEa_write(PUSH_CATEGORY, *piContentID, pbData, 0, iDataSize);
myCheck = (iBytesWritten == -1 || iDataSize!=(UINT32) iBytesWritten) ? FALSE : TRUE;
if (!myCheck)
FILEa_delete(PUSH_CATEGORY, *piContentID);
else {
pushMem.storageSize+=iBytesWritten;
FILEa_flush (PUSH_CATEGORY, *piContentID);
}
#else
myCheck = Storage_Put (&((PUSHCONTEXT*)pContext)->Storage,*piContentID, 0, iDataSize, pbData);
#endif
if (myCheck)
{
/* Store the ContentID in the resource */
pPushContent->iId=*piContentID;
DEALLOC(&pbData);
return 0;
}
DEALLOC(&pbData);
}
}
}
return -1;
} /* end of PUSH_Store */
/*========================================================================
PUSH_StorePush
==========================================================================
Purpose: Store the Push in memory
Params: pContext, piContentID
Return: 0 =OK, -1 = Error, -2 = Message larger than repository.
=========================================================================*/
INT8 PUSH_StorePush( void* pContext, void* pvContent,
UINT32* iContentID )
{
UINT32 iContId=0;
INT8 bRes;
if (!pushMem.isInitialized) {
return FALSE;
}
bRes=PUSH_Store(pContext,pvContent,&iContId);
if (bRes==0)
{
*iContentID=iContId;
}
return bRes;
} /* end of PUSH_StorePush */
/*========================================================================
PUSH_DeletePush
==========================================================================
Purpose: Delete the Push content
Params: pContext, iContentID
Return: BOOL
=========================================================================*/
BOOL PUSH_DeletePush( void* pContext, UINT32 iContentID, UINT8 iType )
{
BOOL fOK=FALSE;
PUSHCONTENTSTRUCT* pPushContent=NULL;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -