📄 cms_wap12.c
字号:
/******************************************************************************
C M O D U L E F I L E
(c) Copyright MobileSoft Technology (NanJing) Co., LTD. 2001-2002
ALL RIGHTS RESERVED
*******************************************************************************
Project Name: WAP STACK Ver1.20
Written By : MobileSoft Technology
File Name : Cms_Malloc.c
Last Modify : 06/22/2002
******************************************************************************/
#include "stdio.h"
#include "string.h"
//#include "CmsNetWork.h"
#include "Cms_WAPMain.h"
#include "Cms_WAPTypes.h"
#include "Cms_WAPMalloc.h"
#include "Cms_WSP.h"
#include "Cms_WTPTimer.h"
#include "Cms_WAPStatus.h"
//#include "cmshttp.h"
#ifdef _WTLS
#include "CmsWtls.h"
#endif
extern WSPMachine* WSPGlobalMachine;
extern WTPMachine* WTPGlobalMachine;
extern unsigned char redirect_host[8];
extern unsigned short redirect_port;
extern CMS_U64 next_tid ;
extern CMS_S32 WTPRCR;
extern CMS_S32 WTPAEC;
extern CMS_S32 WTPNACK;
extern CMS_S32 HoldOn;
extern CMS_S32 WTPWorking;
extern wapproc statproc;
//extern mmsproc mproc;
extern WSPEvent *WSPCreateSMethodInvokeRequest(CMS_S32 method_type, P_CMS_U8 url, HTTPHeader *headers,
P_CMS_U8 content_type, P_CMS_U8 data, CMS_U32 dataLen);
extern CMS_VOID Cms_WAPStackInit(int target);
extern CMS_S32 Cms_ConnectGateway(CMS_VOID);
extern CMS_VOID Cms_UDPToWAP(P_CMS_U8 buf, CMS_S32 bytes);
extern CMS_VOID Cms_UDPSendData(P_CMS_U8 data, CMS_S32 len);
extern CMS_VOID Cms_UDPRecvData(P_CMS_U8 data, P_CMS_S32 len);
//void Cms_WAPOpen(unsigned char * host, long port, wapproc proc);
//unsigned char Cms_UDPInput(void );
// add for temp
#ifdef __CMS_TOOLKIT__
extern WTP_Sar_Progress cmsWtpSarPregress;
#endif
#ifdef _WTLS
extern int Cms_Brower_GetSecuritySetting(void);
extern int Cms_IsBrowserRunning(void);
extern void CmsSetWtlsConnectFlag(int iFlag);
extern void wtls_reset(void);
#endif
CMS_VOID WAP_GlobalV_Init(CMS_VOID)
{
WSPGlobalMachine = NULL;
WTPGlobalMachine = NULL;
next_tid = 0;
memset(redirect_host,0,sizeof(redirect_host));
redirect_port = 0;
WTPRCR = 0;
WTPAEC = 0;
WTPNACK = 0;
HoldOn = 0;
WTPWorking = 0;
}
CMS_VOID Cms_WAPInit(int target) // 1 for mms ; 2 for wap browser
{
Cms_WAPStackInit(target);
}
CMS_VOID Cms_WAPDone(CMS_VOID)
{
if(WTPGlobalMachine)
{
mms_StopTimer(WTPGlobalMachine->timer_id);
wtp_machine_destroy(WTPGlobalMachine);
WTPGlobalMachine = NULL;
}
if(WSPGlobalMachine)
{
wsp_machine_destroy(WSPGlobalMachine);
WSPGlobalMachine = NULL;
}
#ifdef _WTLS
CmsSetWtlsConnectFlag(0);
wtls_reset();
#endif
cmsFreeSarProgress();
memset(redirect_host,0,sizeof(redirect_host));
redirect_port = 0;
next_tid = 0;
}
CMS_VOID Cms_WAPReset(CMS_VOID)
{
if(NULL != WTPGlobalMachine)
{
wtp_timer_init();
mms_StopTimer(WTPGlobalMachine->timer_id);
WTPGlobalMachine->get_first = 0;
WTPGlobalMachine->get_last = 0;
}
cmsFreeSarProgress();
memset(&cmsWtpSarPregress,0,sizeof(WTP_Sar_Progress));
memset(redirect_host,0,sizeof(redirect_host));
redirect_port = 0;
//cms_trace("access CmsWAPReset over\n");
return;
}
//add for temp by roger
CMS_VOID Cms_BrwWAPReset(CMS_VOID)
{
//cms_trace("access Cms_BrwWAPReset: in\n" );
wtp_timer_init();
//cms_trace("\n access: after timer_init \n");
if(NULL != WTPGlobalMachine)
{
mms_StopTimer(WTPGlobalMachine->timer_id);
//cms_trace("\n access: after timer_stop \n");
}
if( NULL != WTPGlobalMachine )
{
//cms_trace("\naccess: reset the WTPGlobalMachine \n");
WTPGlobalMachine->get_first = 0;
WTPGlobalMachine->get_last = 0;
}
cmsFreeSarProgress();
//cms_trace(" access : after free SarProgress ");
memset(&cmsWtpSarPregress,0,sizeof(WTP_Sar_Progress));
if( NULL != redirect_host)
{
//cms_trace("\naccess: reset the redirect_host \n");
memset(redirect_host,0,sizeof(redirect_host));
}
redirect_port = 0;
//cms_trace("\n access: before brw_NetDisconnect \n");
//brw_NetDisconnect();
// cms_trace("access Cms_BrwWAPReset: out\n" );
}
CMS_VOID Cms_WAPConnect(CMS_VOID)
{
/* 连接网关,函数定义在WAPBOX中 */
Cms_ConnectGateway();
}
/* GET方式发出请求 */
CMS_VOID Cms_WAPGet(P_CMS_U8 url)
{
WSPEvent * wsp_event = NULL;
wsp_event = WSPCreateSMethodInvokeRequest( 0x40, url, NULL,(P_CMS_U8)"wml",NULL, 0);
wsp_handle_event(WSPGlobalMachine, wsp_event);
}
/* POST方式发出请求 */
CMS_VOID Cms_WAPPost(P_CMS_U8 url, P_CMS_U8 param, CMS_U32 paramLen)
{
WSPEvent * wsp_event = NULL;
wsp_event = WSPCreateSMethodInvokeRequest( 0x60, url, NULL, NULL, param, paramLen);
wsp_handle_event(WSPGlobalMachine, wsp_event);
}
/*WSP/WTP协议栈发出数据*/
CMS_VOID Cms_WAPSendUDP(P_CMS_U8 buf, CMS_S32 len)
{
unsigned char tempHost[] = {0x0a, 0x00, 0x00, 0xac, 0x00, 0x00, 0x00, 0x00};
int tempPort = 9203;
#ifdef _WTLS
if(Cms_Brower_GetSecuritySetting() && Cms_IsBrowserRunning())
{
cms_trace("WTLS send data to udp,by lee\r\n");
cms_trace_data(buf,len);
brw_SendPDU(buf, len, tempHost, tempPort);
//brw_SendPDU(buf, len, WTPGlobalMachine->udp_host,WTPGlobalMachine->udp_port);
}
else
#endif
if (WTPGlobalMachine)
{
Cms_UDPSendData(buf, len);
}
return;
}
/* WSP/WTP协议栈接收数据 */
CMS_BOOL Cms_UDPInput(CMS_VOID)
{
//unsigned char tempHost[] = {0x0a, 0x00, 0x00, 0xac, 0x00, 0x00, 0x00, 0x00};
//int tempPort = 9203;
unsigned char data[WTP_MTU+100];
int len=0;
CMS_BOOL ret = 0;
memset(data,0,sizeof(data));
#ifdef _WTLS
if(Cms_Brower_GetSecuritySetting() && Cms_IsBrowserRunning())
{
brw_RecvPDU(data, (long*)&len, tempHost, tempPort);
//brw_RecvPDU(data, (long*)&len, WTPGlobalMachine->udp_host,WTPGlobalMachine->udp_port);
}
else
#endif
if (WTPGlobalMachine)
{
Cms_UDPRecvData((unsigned char* )data,(int*)&len);
}
if(len == 0)
{
ret = 0;
}
else
{
#ifdef _WTLS
if( 1 == Cms_Brower_GetSecuritySetting() && 1 == Cms_IsBrowserRunning())
{
/* send to wtls stack */
Cms_UDPToWtls( data,len );
}
else
#endif
{
/* send to wap12 stack */
Cms_UDPToWAP( data, len );
}
ret = 1;
}
return ret;
}
/* 返回浏览器的事件 */
CMS_VOID Browser_Handle_Event( WSPEvent * event )
{
//cms_trace("access Browser_Handle_Event: in\n" );
if(!event)
{
return;
}
//cms_trace("access Browser_Handle_Event: event->type = %d\n",event->type );
switch (event->type )
{
case SConnectConfirmation: /*连接WAP网关成功*/
{
if(statproc)
{
(*statproc)(WAP_CONNECT,NULL,0);
}
}
break;
case SDisconnectIndication: //---include user abort
{
if(statproc)
{
if(event->SDisconnectIndication.discon_reason == WSP_ABORT_USERREQ)
(*statproc)(WAP_USERABORT,NULL,0);
else
(*statproc)(WAP_DISCONNECT,NULL,0);
}
}
break;
case SMethodInvokeConfirmation: /*请求已超时*/
{
if(statproc)
{
(*statproc)(WAP_TIMEOUT,NULL,0);
}
}
break;
case SMethodInvokeAbort: /*---include user abort*/
{
if(statproc)
{
if(event->SMethodInvokeAbort.abort_code == WSP_ABORT_USERREQ)
(*statproc)(WAP_USERABORT,NULL,0);
else
(*statproc)(WAP_ERROR_DATA,NULL,0);
}
}
break;
case SMethodResultIndication:
{
//CmsDebugFunc((unsigned char*)"aaaaaaa",(short)4,(void*)&event->SMethodResultIndication.status);
switch(event->SMethodResultIndication.status)
{
case 0x20:
{
CMS_S64 datalen = 0;
datalen=octstr_len(event->SMethodResultIndication.content_data);
//CmsDebugFunc((unsigned char*)"aaaaaac",(short)4,(void*)&datalen);
if(statproc)
{
//event->SMethodResultIndication.content_data->data将在下面的函数中释放
if(datalen)
{
//cms_trace("access Browser_Handle_Event: 0x20\n");
(*statproc)((CMS_S32)WAP_DATA,(char*)event->SMethodResultIndication.content_data->data,(CMS_S32)datalen);
event->SMethodResultIndication.content_data->data = NULL;
event->SMethodResultIndication.content_data->len = 0;
//cms_trace("access Browser_Handle_Event: 0x20 end\n");
}
else
{
//CmsDebugFunc((unsigned char*)"aaaaaae",(short)4,(void*)&datalen);
(*statproc)((CMS_S32)WAP_NO_DATA,(char*)NULL,(CMS_S32)0);
}
//CmsDebugFunc((unsigned char*)"aaaaaac",(short)4,(void*)&datalen);
}
}
break;
case WAP_CREATE:
{
if(statproc)
{
(*statproc)((CMS_S32)WAP_CREATE,(char*)NULL,(CMS_S32)0);
}
}
break;
case WAP_ACCEPTED:
{
if(statproc)
{
(*statproc)((CMS_S32)WAP_ACCEPTED,(char*)NULL,(CMS_S32)0);
}
}
break;
case WAP_NON_AUTHORITATIVE_INFORMATION:
{
if(statproc)
{
(*statproc)((CMS_S32)WAP_NON_AUTHORITATIVE_INFORMATION,(char*)NULL,(CMS_S32)0);
}
}
break;
case WAP_NO_CONTENT:
{
if(statproc)
{
(*statproc)((CMS_S32)WAP_NO_CONTENT,(char*)NULL,(CMS_S32)0);
}
}
break;
case WAP_RESET_CONTENT:
{
if(statproc)
{
(*statproc)((CMS_S32)WAP_RESET_CONTENT,(char*)NULL,(CMS_S32)0);
}
}
break;
case WAP_PARTIAL_CONTENT:
{
if(statproc)
{
(*statproc)((CMS_S32)WAP_PARTIAL_CONTENT,(char*)NULL,(CMS_S32)0);
}
}
break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -