📄 cms_wsp.c
字号:
CMS_S32 wsp_deduce_pdu_type(Octstr *pdu, CMS_S32 connectionless)
{
CMS_S32 off;
CMS_U64 o;
if (connectionless)
off = 1;
else
off = 0;
if (unpack_uint8(&o, pdu, &off) == -1)
o = Bad_PDU;
return (CMS_S32)o;
}
/*=================== Local functions ===================*/
static CMS_VOID append_to_event_queue(WSPMachine *machine, WSPEvent *event)
{
if (machine->event_queue_head == NULL)
{
machine->event_queue_head = event;
machine->event_queue_tail = event;
event->next = NULL;
}
else
{
machine->event_queue_tail->next = event;
machine->event_queue_tail = event;
event->next = NULL;
}
}
static WSPEvent *remove_from_event_queue(WSPMachine *machine)
{
WSPEvent *event = NULL;
if (machine->event_queue_head == NULL)
event = NULL;
else
{
event = machine->event_queue_head;
machine->event_queue_head = event->next;
if (machine->event_queue_head == NULL)
machine->event_queue_tail = NULL;
event->next = NULL;
}
return event;
}
static CMS_S32 unpack_uint8(P_CMS_U64 u, Octstr *os, P_CMS_S32 off)
{
if (*off >= octstr_len(os))
{
return -1;
}
*u = (CMS_U64)octstr_get_char(os, (CMS_S64)*off);
++(*off);
return 0;
}
static CMS_S32 unpack_uintvar(P_CMS_U64 u, Octstr *os, P_CMS_S32 off)
{
CMS_U64 o;
*u = 0;
do {
if (unpack_uint8(&o, os, off) == -1)
{
return -1;
}
*u = ((*u) << 7) | (o & 0x7F);
} while ((o & 0x80) != 0);
return 0;
}
static CMS_VOID append_uint8(Octstr *pdu, CMS_S64 n)
{
CMS_U8 c;
c = (CMS_U8) n;
octstr_insert_data(pdu, octstr_len(pdu), (P_CMS_U8)&c, 1);
}
static CMS_VOID append_uintvar(Octstr *pdu, CMS_S64 n)
{
CMS_S64 bytes[5];
CMS_U64 u;
CMS_S32 i;
u = n;
for (i = 4; i >= 0; --i)
{
bytes[i] = u & 0x7F;
u >>= 7;
}
for (i = 0; i < 4 && bytes[i] == 0; ++i)
continue;
for (; i < 4; ++i)
append_uint8(pdu, 0x80 | bytes[i]);
append_uint8(pdu, bytes[4]);
}
CMS_S32 unpack_reply_pdu(Octstr *pdu, P_CMS_S64 status, Octstr **content_type,
HTTPHeader **header, Octstr ** content_data)
{
CMS_U64 headerslen;
CMS_S32 off = 1, data_pos;
CMS_U32 u = 0;
CMS_U8 text_content_type[50];
CMS_S32 contentlen = 0;
//CMS_S32 contentoff = 0;
CMS_U32 i=0;
P_CMS_U8 result = NULL;
Cms_ContentType_e FileType = CMS_HTTP_CONTENT_DLING_FILE;
memset(text_content_type,0,50);
unpack_uint8( (P_CMS_U64)&u, pdu, (P_CMS_S32)&off );
/**status = convert_wsp_status_to_http_status( u );*///2003.7.3
*status = u;
////cms_trace("pdutype: %d", u );
////cms_trace("pdutype: %d", u );
////cms_trace("pdutype: %d", u );
if(*status>=0x30 && *status<=0x37)
{
////cms_trace("redirect");
////cms_trace("redirect");
////cms_trace("redirect");
*content_data = octstr_create_from_data(pdu->data + off,octstr_len(pdu) - off);
return 0;
}
else if(*status != 0x20)//http stats 200,ok
{
return 0;
}
unpack_uintvar( &headerslen , pdu, &off);
data_pos = (CMS_S32)(off + headerslen);
unpack_uint8( (P_CMS_U64)&u, pdu, &off );
if(u < 0x80)
{
unpack_uint8( (P_CMS_U64)&u, pdu, &off );
if(u >= 0x80)
{
u -= 0x80;
}
else
{
/*=== 获取content-type ===*/
while(pdu->data[off-2+contentlen] !=0 && contentlen<49)
{
text_content_type[contentlen] = pdu->data[off-2+contentlen];
contentlen++;
}
text_content_type[contentlen] = 0;
/*=== 根据content-type的值决定处理方式 ===*/
if(strstr((char *)text_content_type,"application/vnd.wap.mms-message")!=NULL)
{
/*=== 交给MMS处理 ===*/
u = 0x3e;
}
else if(strstr((char *)text_content_type,"application/vnd.wap.wmlc")!=NULL)
{
/*=== WBXML形式的WML页面 ===*/
u=0x14;
}
#if 0
else if(strstr((char *)text_content_type,"application/xhtml+xml")!=NULL)
{
/*=== 以wml页面的形式处理xhtml脚本 ===*/
u=0x02;
}
#endif
/*== add by roger for temp 04162004==*/
else if(strstr((char *)text_content_type,"image/gif")!=NULL)
{
/*=== got a Gif ===*/
u=0x1D;
}
/*== add by roger for temp 04162004==*/
else if(strstr((char *)text_content_type,"image/png")!=NULL)
{
/*=== got a png ===*/
u=0x20;
}
/*== add by roger ==*/
else if(strstr((char *)text_content_type,"audio/mid")!=NULL)
{
/*=== got a mid==*/
u=0xf0;
}
/*== add by roger ==*/
else if(strstr((char *)text_content_type,"audio/midi")!=NULL)
{
/*=== got a midi ===*/
u=0xf1;
}
/*== add by roger =*/
else if(strstr((char *)text_content_type,"audio/x-mid")!=NULL)
{
/*=== got a x-mid ===*/
u=0xf2;
}
/*== add by roger =*/
else if(strstr((char *)text_content_type,"audio/x-midi")!=NULL)
{
/*=== got a x-midi ===*/
u=0xf3;
}
/*== add by roger ==*/
else if(strstr((char *)text_content_type,"audio/sp-midi")!=NULL)
{
/*=== got a sp-midi ===*/
u=0xf4;
}
else if(strstr((char *)text_content_type,"text/vnd.sun.j2me.app-descriptor")!=NULL)
{
u = 0x23;
////cms_trace("download a jad");
// if(pBrowserInfo)
// {
// pBrowserInfo->FileType = CMS_HTTP_CONTENT_FJAD;
// }
FileType = CMS_HTTP_CONTENT_FJAD;
}
else if(strstr((char *)text_content_type,"application/java-archive")!=NULL)
{
u = 0x22;
////cms_trace("download a jar");
// if(pBrowserInfo)
// {
// pBrowserInfo->FileType = CMS_HTTP_CONTENT_FJAR;
// }
FileType = CMS_HTTP_CONTENT_FJAR;
}
else if(strstr((char *)text_content_type,"text/css")!=NULL)
{
u = 0x3D;
////cms_trace("download a css");
// if(pBrowserInfo)
// {
// pBrowserInfo->FileType = CMS_HTTP_CONTENT_CSS;
// }
FileType = CMS_HTTP_CONTENT_CSS;
}
else if(strstr((char *)text_content_type,"audio/amr")!=NULL)
{
u = 0xFF01; /* 没有标准的编号,临时写的 */
////cms_trace("download a amr file\n");
FileType = CMS_HTTP_CONTENT_AMR;
}
else if(strstr((char *)text_content_type,"audio/mpeg")!=NULL)
{
u = 0xFF02; /* 没有标准的编号,临时写的 */
////cms_trace("download a amr file\n");
FileType = CMS_HTTP_CONTENT_MP3;
}
else if(strstr((char *)text_content_type,"image/vnd.ziyitong.zdd")!=NULL)
{
////cms_trace("image/vnd.ziyitong.zdd\n");
u = 0xFF03; /* 没有标准的编号,临时写的 */
FileType = CMS_HTTP_CONTENT_IMAGE_ZDD;
}
else if(strstr((char *)text_content_type,"image/vnd.ziyitong.vis")!=NULL)
{
////cms_trace("image/vnd.ziyitong.vis\n");
u = 0xFF04; /* 没有标准的编号,临时写的 */
FileType = CMS_HTTP_CONTENT_IMAGE_VIS;
}
else if(strstr((char *)text_content_type,"image/vnd.ziyitong.drm")!=NULL)
{
////cms_trace("image/vnd.ziyitong.drm\n");
u = 0xFF05; /* 没有标准的编号,临时写的 */
FileType = CMS_HTTP_CONTENT_IMAGE_DRM;
}
else if(strstr((char *)text_content_type,"application/vnd.smaf")!=NULL)
{
////cms_trace("application/x-smaf\n");
u = 0xFF06; /* 没有标准的编号,临时写的 */
FileType = CMS_HTTP_BROWSER_MUSIC_SMAF;
}
else if(strstr((char *)text_content_type,"application/x-smaf")!=NULL)
{
////cms_trace("application/x-smaf\n");
u = 0xFF07; /* 没有标准的编号,临时写的 */
FileType = CMS_HTTP_BROWSER_MUSIC_SMAF;
}
else if(strstr((char *)text_content_type,"audio/x-wav")!=NULL)
{
////cms_trace("audio/x-wav\n");
u = 0xFF08; /* 没有标准的编号,临时写的 */
FileType = CMS_HTTP_CONTENT_X_WAVE;
}
else if(strstr((char*)text_content_type,"image/vnd.ziyitong.bil")!=NULL)
{
////cms_trace("image/vnd.ziyitong.bil\n");
u = 0xFF09; /* 没有标准的编号,临时写的 */
FileType = CMS_HTTP_CONTENT_IMAGE_BILL;
}
else if(strstr((char*)text_content_type,"application/Chaotex-wfd")!=NULL)
{
////cms_trace("application/Chaotex-wfd\n");
u = 0xFF0A;
FileType = CMS_HTTP_CONTENT_CHAOTEX;
}
else if(strstr((char*)text_content_type, "application/vnd.oma.drm.message")!=NULL)
{
////cms_trace("application/vnd.oma.drm.message\n");
u = 0xFF0B; /* 没有标准的编号,临时写的 */
FileType = CMS_HTTP_CONTENT_DRM_MESSAGE;
}
else
{
////cms_trace("text_content_type=%s\n", text_content_type);
////cms_trace_data(text_content_type, 50);
//if( -1 == CMS_GetContentType(text_content_type, NULL) )
//{
// ////cms_trace("fail to get text_content type\n");
// u=0x03;
//}
//else
//{
// u = 0xFF0C;
//}
}
}
}
else
{
u=u-0x80;
}
// CmsSetContentType( FileType );
//--------------------------------------
////cms_trace("text_content_type=%s\n", text_content_type);
////cms_trace_data(text_content_type, 50);
////cms_trace("reply u is : 0x%02x",u);
switch ( u )
{
case 0x02:
////cms_trace("download a html");
FileType = CMS_HTTP_CONTENT_HTML;
break;
case 0x14:/* "application/vnd.wap.wmlc", 0x14 ,*/
////cms_trace("download a WMLC");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -