📄 push.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: push.c
Description:
Author: Martin Ranstorp, Kent Olsson AU-System AB
Revision history:
Date Rev Sign Comment
990920 PA1 MRP First version.
991206 PA2 MRP Updated. Working in WAE test environment.
000118 PA3 MRP Updated after validation inspection.
000124 PA4 MRP Updated after code inspection.
000208 PA5 JPR Function ME_Push_DateTime2Int moved to PUSHElm.c
000214 PA6 MRP Copyright added.
000316 PA7 MRP Push API changed.
000918 PA8 MRP Updated configuration handling (GWC 4.x).
001114 PA9 KEOL Uppdated after change request regarding handling of GetSI and GetSL (reply with initiators URI as well)
001220 PA10 HEAD Added ME_Push_Get_First=Get first element in the list,
ME_Push_Get_Next=get next element in list, and
ME_Push_Get_PushListStruct=get content of the list element.
------------------------------------------------------------------------*/
/* Private include statements */
#include "push.h"
#include "url.h"
#include "wbxmldef.h"
#include "wbxmldec.h"
#include "wbxmlelm.h"
#include "headdef.h"
#include "wae_cmmn.h"
#include "header.h"
#include "wipdb.h"
#include "dbfunct.h"
#include "aapipush.h"
#define EMPTY 0x0
#define MAX_TID 250
/*========================================================================
INTERNAL FUNCTIONS
=========================================================================*/
/*========================================================================
EXTERNAL FUNCTIONS
=========================================================================*/
/*========================================================================
Functions called from the process Push_ME
=========================================================================*/
/*========================================================================
ME_Push_GetConnection
==========================================================================
Purpose: Check and get first correct address and if ok request connection
Params: pvAddressList
Return: 1 if ok, else 0
=========================================================================*/
UINT8 ME_Push_GetConnection( void* pvAddressList )
{
ADDRESS* pAddressList=NULL;
ADDRESS* pTemp=NULL;
ADDRESS* pTemp2=NULL;
BYTE* pbAddress=NULL;
INT16 itmp2;
INT32 itmp1;
UINT8 iLen=0;
#ifdef WAE_DEBUG
URL_DEBUG_PRINT("Start Push_GetConnection");
#endif
if (pvAddressList!=NULL)
{
pAddressList=(ADDRESS*)pvAddressList;
pTemp=pAddressList;
pbAddress=pTemp->pbAddress;
if (pbAddress!=NULL)
{
itmp1=pTemp->iPortNumber;
itmp2=pTemp->iBearerType;
iLen=pTemp->uiAddressLength;
if (itmp1==-1)
{
itmp1=MODE_ANY;
}
if (pTemp->iBearerType==-1)
{
itmp2=BEARER_ANY;
}
PUSHa_requestConnection(1,(UINT16)itmp1,(UINT8)itmp2,pbAddress,iLen);
while (pTemp!=NULL)
{
pTemp2 = pTemp;
pTemp=pTemp->pNext;
/*DEALLOC(&(pTemp2->pbAddress));*/
DEALLOC(&pTemp2);
}
return 1;
}
}
return 0;
} /* end of ME_Push_GetConnection */
/*========================================================================
ME_Push_GetFreeIdNumber
==========================================================================
Purpose: Get free IdNumber to use
Params: pvList (any list)
Return: UINT16 IdNumber, 0 means failure
=========================================================================*/
UINT16 ME_Push_GetFreeIdNumber(void* pvList)
{
void* pvListElement = NULL;
UINT16 iId = 0;
#ifdef WAE_DEBUG
URL_DEBUG_PRINT("Start ME_Push_GetFreeIdNumber");
#endif
for (iId=1; iId < (UINT16)-1; iId++)
{
pvListElement = SDL_SearchListElement( pvList, iId, NULL );
if( pvListElement == NULL )
{
return iId;
}
}
return 0;
} /* end of ME_Push_GetFreeIdNumber */
/*========================================================================
ME_Free_PushContentStruct
==========================================================================
Purpose: Free the PushContent struct (except the Url's)
Params: vsPushContentStruct
Return: TRUE
=========================================================================*/
void ME_Free_PushContentStruct(void* pvPushContentStruct)
{
PUSHCONTENTSTRUCT* pPushContentStruct=NULL;
#ifdef WAE_DEBUG
URL_DEBUG_PRINT("End Free PushContentStruct");
#endif
if (pvPushContentStruct != NULL)
{
pPushContentStruct = (PUSHCONTENTSTRUCT*)pvPushContentStruct;
if (pPushContentStruct != NULL)
{
if ( pPushContentStruct->iType == SI )
{
DEALLOC(&((pPushContentStruct)->content.pSIContentStruct->pwchSIid));
DEALLOC(&((pPushContentStruct)->content.pSIContentStruct->pwchMessage));
DEALLOC(&((pPushContentStruct)->content.pSIContentStruct->pbUrl) );
DEALLOC(&((pPushContentStruct)->content.pSIContentStruct->pbInitUri) );
DEALLOC(&((pPushContentStruct)->content.pSIContentStruct));
}
else
{
DEALLOC(&((pPushContentStruct)->content.pSLContentStruct->pbUrl) );
DEALLOC(&((pPushContentStruct)->content.pSLContentStruct->pbInitUri) );
DEALLOC(&((pPushContentStruct)->content.pSLContentStruct));
}
DEALLOC(&pPushContentStruct);
}
}
} /* end of ME_Free_PushContentStruct */
/*========================================================================
Push_List functions, each element stores information (of PUSHLISTSTRUCT
type) about a push stored in the Push Buffer.
=========================================================================*/
/*========================================================================
ME_Push_List_Add
==========================================================================
Purpose: Add a new element to the Push List
Params: pvPushList, pvPushListStruct
Return: 1 if ok, else 0
=========================================================================*/
UINT8 ME_Push_List_Add( void* pvPushList, void* pvPushListStruct )
{
UINT16 iId=0;
PUSHLISTSTRUCT* pListStruct=NULL;
#ifdef WAE_DEBUG
URL_DEBUG_PRINT("Start Push_List_Add");
#endif
pListStruct = (PUSHLISTSTRUCT*)pvPushListStruct;
iId=ME_Push_GetFreeIdNumber(pvPushList);
if( (pvPushList != NULL) && (iId != 0) )
{
if( pvPushListStruct != NULL )
{
pListStruct->iIdNumber = iId;
return SDL_AddElementLast( pvPushList,iId, (void*)pListStruct );
}
}
return 0;
} /* end of ME_Push_List_Add */
/*========================================================================
ME_Push_Change_Place_In_List
==========================================================================
Purpose: Change place on OldElement and NewElement in the list
Params: pvPushList, pvPushListStructNew, pvPushListStructOld
Return:
=========================================================================*/
void ME_Push_Change_ElementId_In_List(void* pvPushList, void* pvPushListStructNew, void* pvPushListStructOld)
{
void* pOldListElem = NULL;
void* pNewListElem = NULL;
UINT16 iIdOld, iIdNew;
iIdNew = ((PUSHLISTSTRUCT*)pvPushListStructNew)-> iIdNumber;
iIdOld = ((PUSHLISTSTRUCT*)pvPushListStructOld) -> iIdNumber;
((PUSHLISTSTRUCT*)pvPushListStructNew) -> iIdNumber = ((PUSHLISTSTRUCT*)pvPushListStructOld) -> iIdNumber;
pOldListElem = SDL_SearchListElement( pvPushList, iIdOld, NULL );
pNewListElem = SDL_SearchListElement( pvPushList, iIdNew, NULL );
SDL_ChangeListElementID(pNewListElem, iIdOld);
SDL_ChangeListElementID(pOldListElem, iIdNew);
}
/*========================================================================
ME_Push_List_Delete
==========================================================================
Purpose: Deletes an element from the Push List
Params: pvPushList, pvPushListStruct
Return:
=========================================================================*/
void ME_Push_List_Delete( void* pvPushList, void* pvPushListStruct )
{
PUSHLISTSTRUCT* pPushListStruct = NULL;
void* pvListElement = NULL;
void* pvElementContent = NULL;
#ifdef WAE_DEBUG
URL_DEBUG_PRINT("Start Push_List_Delete");
#endif
if( pvPushList != NULL )
{
pvListElement = SDL_GetNextListElement(pvPushList,NULL);
while ( pvListElement != NULL )
{
pvElementContent = SDL_GetListElementContent(pvListElement);
if( pvElementContent != NULL )
{
pPushListStruct = (PUSHLISTSTRUCT*)pvElementContent;
if ( pPushListStruct == pvPushListStruct )
{
SDL_DeleteListElement(pvPushList,pvListElement);
OSConnectorFree(((PUSHLISTSTRUCT*)pPushListStruct)->pwchPushId);
OSConnectorFree(pPushListStruct);
break;
}
}
pvListElement = SDL_GetNextListElement(pvPushList,pvListElement);
}
}
} /* end of ME_Push_List_Delete */
/*========================================================================
ME_Push_List_Sort
==========================================================================
Purpose: Sort the elements in the Push List
SLs are sorted first in list and then SIs. Oldest first (not
changing incoming order (apart from SLs that is put first in list)).
Params: pvPushList
Return: Sorted PushList
=========================================================================*/
void* ME_Push_List_Sort(void* pvPushList)
{
PUSHLISTSTRUCT* pPushListStruct = NULL;
PUSHLISTSTRUCT* pPushListStructTemp = NULL;
void* pvListElement = NULL;
void* pvElementContent = NULL;
void* pvOldListElementTemp = NULL;
void* pvListElementTemp = NULL;
void* pvElementContentTemp = NULL;
void* pPushListTemp = NULL;
UINT8 iRes;
void* pvTemp;
BOOL bFirst = TRUE;
#ifdef WAE_DEBUG
URL_DEBUG_PRINT("Start Push_List_Sort");
#endif
if ( SDL_GetCardinal(pvPushList)<=1 )
return pvPushList;
/* Create Temporary PushList */
pPushListTemp = SDL_NewList( 0 );
if( pvPushList != NULL )
{
pvListElement = SDL_GetNextListElement( pvPushList, NULL );
while ( pvListElement != NULL )
{
pvElementContent = SDL_GetListElementContent( pvListElement );
if( pvElementContent != NULL )
{
pPushListStruct = (PUSHLISTSTRUCT*)pvElementContent;
pvListElementTemp = SDL_GetNextListElement( pPushListTemp, NULL );
pvOldListElementTemp = NULL;
while (pvListElementTemp != NULL) /* Sort into new list */
{
pvElementContentTemp = SDL_GetListElementContent( pvListElementTemp );
if( pvElementContentTemp != NULL )
{
pPushListStructTemp = (PUSHLISTSTRUCT*)pvElementContentTemp;
/* Check where to put it in temp list */
if ( pPushListStruct->iPushType > pPushListStructTemp->iPushType )
{ /* SI:s after SL */
iRes = SDL_AddElementAfter(pPushListTemp, pPushListStruct->iIdNumber , (void*)pPushListStruct, pvOldListElementTemp );
break;
}
else /* Same or less Push Type */
{
if ( pPushListStruct->iPushType == SI)
{
if ( pPushListStructTemp->iPushType == SI )
{
if ( pPushListStruct->iCreated < pPushListStructTemp->iCreated)
{
iRes = SDL_AddElementAfter(pPushListTemp, pPushListStruct->iIdNumber, (void*)pPushListStruct, pvOldListElementTemp );
break;
}
}
}
}
}
/* Get next temp list element */
pvOldListElementTemp = pvListElementTemp;
pvListElementTemp = SDL_GetNextListElement( pPushListTemp, pvListElementTemp );
if ( pvListElementTemp == NULL )
{ /* Put it last in temp list */
iRes = SDL_AddElementLast(pPushListTemp, pPushListStruct->iIdNumber, (void*)pPushListStruct);
}
} /* end inner loop */
if (bFirst)
{
iRes = SDL_AddElementFirst(pPushListTemp, pPushListStruct->iIdNumber, (void*)pPushListStruct);
bFirst = FALSE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -