⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cms_wsp.c

📁 wap 协议栈 包括1.2 和2.0 由c开发 基于brew平台
💻 C
📖 第 1 页 / 共 4 页
字号:
/******************************************************************************

 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 "CmsHttp.h"

#include "Cms_WAPMalloc.h"
#include "Cms_WSP.h"
#include "Cms_WSPGlobalVariable.h"
#include "Cms_WTPGLOBALVARIABLE.h"


#define WSP_CAPS_CLIENT_SDU_SIZE	0x00
#define WSP_CAPS_SERVER_SDU_SIZE	0x01
#define WSP_CAPS_PROTOCOL_OPTIONS	0x02
#define WSP_CAPS_METHOD_MOR		0x03
#define WSP_CAPS_PUSH_MOR		0x04
#define WSP_CAPS_EXTENDED_METHODS    	0x05
#define WSP_CAPS_HEADER_CODE_PAGES    	0x06
#define WSP_CAPS_ALIASES	   	0x07

extern P_CMS_U8 wbxml_to_wml(P_CMS_U8 data, CMS_S32 len);
extern CMS_VOID Cms_ReConnectGateway(unsigned char *ipdata);//2003.10.30
extern void Cms_Set_Useragent (unsigned char * u_a);
extern int CmsWAPWBXMLToWML(unsigned char * data, unsigned int len, unsigned char * result, unsigned int resultlen);
extern CMS_VOID Browser_Handle_Event( WSPEvent * event );
extern void CmsSetContentType( Cms_ContentType_e type );

//extern void Cms_Browser_Set_UAProfile(char *UAProfile);
extern int CMS_GetContentType(unsigned char* contentType , void* param);

WSPMachine * WSPGlobalMachine;

CMS_S32 WSPWorking ; /* 检测wsp回话机是否在工作 */

enum {
	Bad_PDU = -1,
	Connect_PDU = 0x01,
	ConnectReply_PDU = 0x02,
	Redirect_PDU = 0x03,
	Reply_PDU = 0x04,
	Disconnect_PDU = 0x05,
	Push_PDU = 0x06,
	ConfirmedPush_PDU = 0x07,
	Suspend_PDU = 0x08,
	Resume_PDU = 0x09,
	Get_PDU = 0x40,
	Options_PDU = 0x41,
	Head_PDU = 0x42,
	Delete_PDU = 0x43,
	Trace_PDU = 0x44,
	Post_PDU = 0x60,
	Put_PDU = 0x61
};

typedef struct 
{
    CMS_S64 http_status;
	CMS_S64 wsp_status;
} HTTP_WSP_STATUS;

//////////////////////////////////////////////////////////////////////////////////
//added by roger for temp
unsigned char brw_UA[ ] = { 
	0x43, 0x54, 0x4c, 0x2f, 0x28, 0x32, 0x30, 0x30, 0x34, 0x2e, 
	0x30, 0x37, 0x2e, 0x30, 0x31, 0x29, 0x53, 0x57, 0x32, 0x2e, 
	0x30, 0x2e, 0x30, 0x2f, 0x57, 0x41, 0x50, 0x31, 0x2e, 0x32, 
	0x20, 0x50, 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x2f, 0x4d, 
	0x49, 0x44, 0x50, 0x2d, 0x32, 0x2e, 0x30, 0x20, 0x43, 0x6f, 
	0x6e, 0x66, 0x69, 0x67, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 
	0x6e, 0x2f, 0x43, 0x4c, 0x44, 0x43, 0x2d, 0x31, 0x2e, 0x31, 
	
};

#if 0
unsigned char  brw_UA[] = {0x4F ,0x6F ,0x6B ,0x69 ,0x61 ,0x33 ,0x33 ,0x34 ,0x34 ,0x2F ,0x31 ,0x2E ,0x30,
0x20,0x28 ,0x34 ,0x2E ,0x37 ,0x34 ,0x29 ,0x20 ,0x50 ,0x72 ,0x6F ,0x66 ,0x69 ,0x6C ,0x65 ,0x2F,
0x4D,0x49 ,0x44 ,0x50 ,0x2D ,0x31 ,0x2E ,0x30 ,0x20 ,0x43 ,0x6F ,0x6E ,0x66 ,0x69 ,0x67 ,0x75,
0x72,0x61 ,0x74 ,0x69 ,0x6F ,0x6E ,0x2F ,0x43 ,0x4C ,0x44 ,0x43 ,0x2D ,0x31 ,0x2E ,0x30 ,0x00,
0x58,0x2D ,0x57 ,0x41 ,0x50 ,0x2E ,0x54 ,0x4F ,0x44 ,0x00 ,0x01 ,0x00,};
#endif


#if 0
unsigned char brwcap[] = {0x04, 0x80, 0x83, 0xff, 0x7f, 0x04, 
  0x81, 0x83, 0xff, 0x7f, 0x02, 0x83, 0x01, 0x02, 
  0x84, 0x01,};
#endif


unsigned char brwcap[] = {0x04, 0x80, 0x8c, 0x9a, 0x40, //client sdu size
                          0x04, 0x81, 0x8c, 0x9a, 0x40, //server sdu size
                          0x02, 0x83, 0x01,             //method MOR
                          0x02, 0x84, 0x01,};           //push MOR

  unsigned char brwhead[] = {
	0x80, 0x82, //text/html add by teng yong

	0x80, 0x94, //application/x-hdmlc
	0x80, 0x83, //text/plain
	0x80, 0x8c, //multipart/mixed
	0x80, 0x9d, //image/gif
	0x80, 0x9e, //image/jpeg
	0x80, 0xa1, //image/vnd.wap.wbmp
    0x80, 0xa9, //application/vnd.wap.wbxml
	0x80, 0xad, //text/vnd.wap.si
	0x80, 0xaf, //text/vnd.wap.sl
	0x80, 0xb3, //application/vnd.wap.multipart.related
	0x80, 0xb4, //application/vnd.wap.sia

	0x80, 0x61, 0x75, 0x64, 0x69, 0x6f, 0x2f, 0x6d, 0x69, 0x64, 0x69, 0x00, //audio/midi
	0x80, 0x61, 0x75, 0x64, 0x69, 0x6f, 0x2f, 0x6d, 0x69, 0x64, 0x00,	    //audio/mid
	0x80, 0x61, 0x75, 0x64, 0x69, 0x6f, 0x2f, 0x78, 0x2d, 0x6d, 0x69, 0x64, 0x69, 0x00, //audio/x-midi	
	0x80, 0x61, 0x75, 0x64, 0x69, 0x6f, 0x2f, 0x78, 0x2d, 0x6d, 0x69, 0x64, 0x00, //audio/x-mid

    0x80, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 
    0x2f, 0x76, 0x6e, 0x64, 0x2e, 0x77, 0x61, 0x70, 0x2e, 0x6d, 0x6d, 0x73, 
    0x2d, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x00, //application/vnd.wap.mms-message
	
	0x80, 0x74, 0x65, 0x78, 0x74, 0x2f, 0x76, 0x6e, 0x64, 0x2e, 0x73, 0x75, 
	0x6e, 0x2e, 0x6a, 0x32, 0x6d, 0x65, 0x2e, 0x61, 0x70, 0x70, 0x2d, 0x64, 0x65, 0x73, 0x63, 
    0x72, 0x69, 0x70, 0x74, 0x6f, 0x72, 0x00,  //text/vnd.sun.j2me.app-descriptor
	
	0x80, 0x61, 0x70, 0x70, 0x6c, 
    0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x6a, 0x61, 0x76, 0x61, 
    0x00, //application/java
	
	0x80, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 
    0x6e, 0x2f, 0x6a, 0x61, 0x76, 0x61, 0x2d, 0x61, 0x72, 0x63, 0x68, 0x69, 
    0x76, 0x65, 0x00, //application/java-archive
	
	0x80, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 
    0x69, 0x6f, 0x6e, 0x2f, 0x78, 0x2d, 0x6a, 0x61, 0x76, 0x61, 0x2d, 0x61, 
    0x72, 0x63, 0x68, 0x69, 0x76, 0x65, 0x00, //application/x-java-archive

	/* 加drm的支持 */
	0x80, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 
	0x69, 0x6f, 0x6e, 0x2f, 0x76, 0x6e, 0x64, 0x2e, 0x6f, 0x6d, 0x61, 0x2e, 
	0x64, 0x72, 0x6d, 0x2e, 0x6d, 0x65, 0x73, 0x73, 
	0x61, 0x67, 0x65, 0x00,       //application/vnd.oma.drm.message
    
	0x80,0x69, 0x6d, 0x61, 0x67, 0x65, 0x2f, 0x76, 0x6e, 0x64, 0x2e, 0x7a, 0x69, 0x79, 0x69, 0x74, 0x6f, 
    0x6e, 0x67, 0x2e, 0x64, 0x72, 0x6d,0x00,//image/vnd.ziyitong.drm->flash
    
    0x80,0x69, 0x6d, 0x61, 0x67, 0x65, 0x2f, 0x76, 0x6e, 0x64, 0x2e, 0x7a, 0x69, 0x79, 0x69, 0x74, 0x6f, 
    0x6e, 0x67, 0x2e, 0x76, 0x69, 0x73,0x00,//image/vnd.ziyitong.vis->flash
   
	0x80,0x69, 0x6d, 0x61, 0x67, 0x65, 0x2f, 0x76, 0x6e, 0x64, 0x2e, 0x7a, 0x69, 0x79, 0x69, 0x74, 0x6f, 
    0x6e, 0x67, 0x2e, 0x7a, 0x64, 0x64,0x00,//image/vnd.ziyitong.zdd->flash

    0x80, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x43, 0x68, 0x61, 0x6f, 
	0x74, 0x65, 0x78, 0x2d, 0x77, 0x66, 0x64, 0x00, //application/Chaotex-wfd

	0x80, 0x61, 0x75, 0x64, 0x69, 0x6f, 0x2f, 0x6d, 0x70, 0x65, 0x67,0x00,// audio/mpeg
    0x80, 0x61, 0x75, 0x64, 0x69, 0x6f, 0x2f, 0x6d, 0x70, 0x33, 0x00,	// audio/mp3	//yan1.chen test
    0x80, 0x61, 0x75, 0x64, 0x69, 0x6f, 0x2f, 0x61, 0x61, 0x63, 0x00,	// audio/aac	//yan1.chen test
	0x80, 0x61, 0x75, 0x64, 0x69, 0x6f, 0x2f, 0x61, 0x64, 0x70, 0x63, 0x6d, 0x00,   //audio/adpcm
	0x80, 0x76, 0x69, 0x64, 0x65, 0x6f, 0x2f, 0x33, 0x67, 0x70, 0x70, 0x00,         // video/3gpp
	0x80, 0x76, 0x69, 0x64, 0x65, 0x6f, 0x2f, 0x33, 0x67, 0x70, 0x00,				// video/3gpp
	0x80, 0x76, 0x69, 0x64, 0x65, 0x6f, 0x2f, 0x6d, 0x70, 0x34, 0x00,				// video/mp4
	0x80, 0x61, 0x75, 0x64, 0x69, 0x6f, 0x20, 0x2f, 0x78, 0x2d, 0x6d, 0x73, 0x2d, 0x77, 0x6d, 0x61, 0x00, // audio /x-ms-wma
	0x80, 0x61, 0x75, 0x64, 0x69, 0x6f, 0x2f, 0x78, 0x2d, 0x77, 0x61, 0x76, 0x00,  // audio/wav
	0x80, 0x61, 0x75, 0x64, 0x69, 0x6f, 0x2f, 0x78, 0x2d, 0x77, 0x61, 0x76, 0x00, // audio/x-wav

	0x83, 0x99, //language
	0x81, 0x02, 0xea, 0x51, 
	//0x81, 0x84, teng yong delete
  };


  unsigned char mmscap[] = {
	0x04,0x80,0x8F,0xF8,0x00,  //client sdu size
	0x04,0x81,0x8F,0xF8,0x00,    //server sdu size
	0x02,0x82,0xC0,				 //protocal options
	0x02,0x83,0x02,				 //method MOR
	0x02,0x84,0x01               //push MOR
  };

  unsigned char mmshead[] = {
	0x80 , 0x80 ,
	0xa1 , 0x09 ,
	0x80 , 0x77 ,
	0x61 , 0x70 , 0x00 ,
	0x77 , 0x61 , 0x70 ,0x00 , 
	0x83 , 0xc1 , 
	0x81 , 0x83 ,
	0x81 , 0x84 ,
	0x81 , 0xea ,
	0x81 , 0x03 , 0x02 , 0x03 ,0xe8,
	
	0xB3 ,0x80 ,
	0xB2, 0x81 ,
	0xB2 ,0x82 ,
	0xB2 ,0x84 ,

	0x89 ,0x45 ,

	0x6E ,0x63 ,0x6F ,0x64 ,0x69 ,0x6E ,0x67 ,0x2D ,0x56,
	0x65 ,0x72 ,0x73 ,0x69 ,0x6F ,0x6E ,0x00 ,0x45 ,0x6E ,0x63 ,0x6F ,0x64 ,0x69 ,0x6E ,0x67 ,0x2D,
	0x56 ,0x65 ,0x72 ,0x73 ,0x69 ,0x6F ,0x6E ,0x00 ,0x31 ,0x2E ,0x33 ,0x00
  };

static CMS_VOID append_to_event_queue(WSPMachine *machine, WSPEvent *event);
static WSPEvent *remove_from_event_queue(WSPMachine *machine);

static CMS_S32 unpack_reply_pdu(Octstr *pdu, P_CMS_S64 status, Octstr **content_type,
							 HTTPHeader **header, Octstr ** content_data);

static CMS_S32 unpack_uint8(P_CMS_U64 u, Octstr *os, P_CMS_S32 off);
static CMS_S32 unpack_uintvar(P_CMS_U64 u, Octstr *os, P_CMS_S32 off);

static CMS_VOID append_uint8(Octstr *pdu, CMS_S64 n);
static CMS_VOID append_uintvar(Octstr *pdu, CMS_S64 n);
static CMS_VOID append_octstr(Octstr *pdu, Octstr *os);


/* action */
static void null_scr_2_cnting(WSPMachine *machine,WSPEvent *event);
static void null_scr_type0_cnting(WSPMachine *machine, WSPEvent * event );
static void null_scr_type1_cnting(WSPMachine *machine,WSPEvent *event);
static void null_scr_appid_cnting(WSPMachine *machine,WSPEvent *event);
static void null_scr_1_cnting(WSPMachine *machine,WSPEvent *event,Octstr *tmpcapcode);
static void cnting_discnt_1_null(WSPMachine *machine,WSPEvent *event);
static void cnting_trri_cr_cnted(WSPMachine *sm,WSPEvent *current_event);
static void cnting_trri_rd_null(WSPMachine *sm,WSPEvent *current_event);
static void cnting_trai_1_null(WSPMachine *sm,WSPEvent *current_event);
static void cnted_smir_1_waing(WSPMachine *sm,WSPEvent *current_event);
static void waing_trai_1_null(WSPMachine *sm,WSPEvent *current_event);
static void waing_disn_1_null(WSPMachine *sm,WSPEvent *current_event);
static void waing_trri_totaldata_cmpng(WSPMachine *sm,WSPEvent *current_event);
static void cmpng_smrr_1_cnded(WSPMachine *sm,WSPEvent *current_event);


WSPEvent *wsp_event_create(WSPEventType type) 
{
	WSPEvent *event;
	event = (WSPEvent *)malloc((CMS_U32)sizeof(WSPEvent));
	event->type = type;
	event->next = NULL;

	#define INTEGER(name) p->name = 0
	#define OCTSTR(name) p->name = NULL
	#define WTP_MACHINE(name) p->name = NULL
	#define SESSION_MACHINE(name) p->name = NULL
	#define WSP_EVENT(name, fields) \
		{ struct name *p = &event->name; fields }
	#define HTTPHEADER(name) p->name = NULL
	#include "Cms_WSPEventDecl.h"

	return event;
}


CMS_VOID wsp_event_destroy(WSPEvent *event)
{
	if (event != NULL) 
	{
		#define INTEGER(name) p->name = 0
		#define OCTSTR(name) octstr_destroy(p->name)
		#define WTP_MACHINE(name) p->name = NULL
		#define SESSION_MACHINE(name) p->name = NULL
		#define WSP_EVENT(name, fields) \
			{ struct name *p = &event->name; fields }
		#define HTTPHEADER(name) p->name = NULL
		#include "Cms_WSPEventDecl.h"

		free(event);
		event = NULL;
	}
}


CMS_VOID wsp_dispatch_event(WTPMachine *wtp_sm, WSPEvent *event) 
{
	wsp_handle_event( WSPGlobalMachine, event );
}


WSPMachine *wsp_machine_create(CMS_VOID) 
{
	WSPMachine *p = (WSPMachine *)malloc(sizeof(WSPMachine));
	#define OCTSTR(name) p->name = NULL		
	#define INTEGER(name) p->name = 0
	#define EVENT_POINTER(name) p->name = NULL
	#define SESSION_MACHINE(fields) fields
	#include "Cms_WSPMachineDecl.h"
	
	p->state = WSP_NULL;
	
	return p;
}
void wsp_machine_destroy(WSPMachine *machine) 
{
	if (!machine)
	{
        return;
	}
		
	#define OCTSTR(name) octstr_destroy(machine->name)
	#define INTEGER(name) 
	#define EVENT_POINTER(name) //wsp_event_destroy(machine->name)
	#define SESSION_MACHINE(fields) fields
	#include "Cms_WSPMachineDecl.h"
	free(machine);
	return;
}

CMS_VOID wsp_handle_event(WSPMachine *sm, WSPEvent *current_event) 
{
    if(!sm  && current_event)
	{
		wsp_event_destroy(current_event);
		current_event = NULL;
		return;
	}

	if ( WSPWorking == 1 )
	{   
		append_to_event_queue(sm, current_event);
		return;
	}
	
	WSPWorking = 1;
    
	do {
		#define STATE_NAME(name)
		#define ROW(wsp_state, event_type, condition, action, next_state) \
		{ \
	  			struct event_type *e; \
				e = &current_event->event_type; \
		  if (sm->state == wsp_state && \
		     current_event->type == event_type && \
		     (condition)) { \
		     action \
             sm->state = next_state; \
			goto wsp_end; \
			} \
		} 
	
        #include "Cms_WSPStateDecl.h"
		
wsp_end:
	    wsp_event_destroy(current_event);
	    current_event = NULL;
	    current_event = remove_from_event_queue(sm);
	
	} while (current_event != NULL);
	
	WSPWorking = 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -