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

📄 ota.c

📁 WAP browser is based on the Wireless Application Protocol web browser, WAP1.3 will enable mobile pho
💻 C
📖 第 1 页 / 共 3 页
字号:
//---------------------------------------------------------------------------
//OTA.c  NOTE: This file is work in progress for the OTA push/and OTA Prov. stack.
//---------------------------------------------------------------------------

#include "OTA.h"
#include "formBrowser.h"
#include "WAPUniverse.h"
#include 	"../res/WAPUniverse_res.h"

// 


#ifndef __palmos__
    #include <stdio.h>
#endif __palmos__



/*int pushotastack( OtaPtr ota)
{
    unsigned char *ptr;
    int i;

    if (ota->stack == NULL) {
        wmldck->maxstack = 10;
        wmldck->stack=Malloc(wmldck->maxstack);
	    ErrFatalDisplayIf (!wmldck->stack, "Malloc(stack)");
    }
    if (wmldck->stackDepth >= wmldck->maxstack) {   	
        i = wmldck->maxstack;
        wmldck->maxstack+=10;
        ptr = wmldck->stack;
        wmldck->stack=Malloc(wmldck->maxstack);
	    ErrFatalDisplayIf (!wmldck->stack, "Malloc(stack-resize)");
        while (i>0)
           wmldck->stack[--i]=ptr[i];
        Free(ptr);
    }
    wmldck->stack[wmldck->stackDepth++] = wmldck->tag;

    return(0);    
}

void  freewmlstack(WMLDeckPtr wmldck)
{
    wmldck->stackDepth=0;
    if (wmldck->stack != NULL){
        Free(wmldck->stack);
        wmldck->stack = NULL;
    }
     
}

unsigned char popwmlstack(WMLDeckPtr wmldck)
{
    unsigned char c;

    if (wmldck->stack == NULL)
        return(-1);
    wmldck->stackDepth--; 
    c = wmldck->stack[wmldck->stackDepth];        
    if (wmldck->stackDepth == 0) {
        Free(wmldck->stack);
        wmldck->stack = NULL;
    }
    return(c);    
}*/


int getAttributeValue(WMLDeckPtr wmldck,char attrstr[])
{
    unsigned char c;
    int l,j;

            attrstr[0] = 0;
            j=0;
            c = wmldck->data[wmldck->offset++];
            while ((c > 128) || (c==ENTITY) || (c == STR_I) || (c == STR_T)   
                   || (c==SWITCH_PAGE) || (c==PI) 
                   || ((c >= EXT_I_0) && (c <= EXT_I_2))
                   || ((c >= EXT_T_0) && (c <= EXT_T_2))) {

                switch (c) {
                case ENTITY:
                    WspReadInt(wmldck->data,&(wmldck->offset)); 
                    //DisplayError("Unhandled WML ENTITY");
					attrstr[j++]='<';
					attrstr[j++]='!';
					attrstr[j++]='>';
                    attrstr[j] = 0;
                    break;

                case STR_I:
                case EXT_I_0:
                case EXT_I_1:
                case EXT_I_2:     
                    while (wmldck->data[wmldck->offset] != 0) {
                        attrstr[j++]=wmldck->data[wmldck->offset++];
                    }
                    attrstr[j] = 0;
                    wmldck->offset++;   
                    break;

                case PI: // processing instruction
                    //DisplayError("Unhandled WML PI");                
                    break; 

                case EXT_T_0:
                case EXT_T_1:
                case EXT_T_2: // 
                    l = WspReadInt(wmldck->data,&(wmldck->offset));
					attrstr[j++]=c;
                    while (wmldck->strTable[l] !=0)
                        attrstr[j++] = wmldck->strTable[l++];
                    //attrstr[j]=0;
                    //MyErrorFunc(attrstr+1,"var");              
					attrstr[j++]=END;
                    attrstr[j] = 0;
                    // !! TODO : handle escape/noescape
					if (c==EXT_T_0)
						;//escaped
					if (c==EXT_T_0)
						;//unescaped
                    break;
                case STR_T: 
                    l = WspReadInt(wmldck->data,&(wmldck->offset));
                    while (wmldck->strTable[l] !=0)
                        attrstr[j++] = wmldck->strTable[l++];                   
                    attrstr[j] = 0;
                    break;  
                case EXT_0:
                case EXT_1:
                case EXT_2:
                    //Single byte extension tokens		
                    l = wmldck->data[wmldck->offset++];
                    break;
                case OPAQUE: 
                    //DisplayError("UNHANDELD OPAQUE");
                    break;

                default:
                    if ((c >=0x85) && (c <= 0xA1 )) {
                        l=0;
                        while (attrVal[c-0x85][l]!=0)
                            attrstr[j++] = attrVal[c-0x85][l++];                    
                        attrstr[j] = 0;
                    } else {
                        //DisplayError("UNKNOWN ATTRIBUTE");//handle unknowns silently 
                    }
                } //switch	
                c = wmldck->data[wmldck->offset++];
            } //while
        wmldck->offset--;
		return(0);
}

char *getAttributes(WMLDeckPtr wmldck, unsigned char attr, GlobalsType *g)
{
//    static Char attrstr[128];
//	char tmpstr[128];
    unsigned char c,attr_id;

	wmldck->attrstr[0]=0;
    if (wmldck->data[wmldck->offset] & WBXML_has_attributes) {
        wmldck->offset++;
        c= wmldck->data[wmldck->offset++];
        while (c != END) {
            attr_id = c;
			if (attr_id == attr){
   			   getAttributeValue(wmldck,wmldck->attrstr);
			   return(wmldck->attrstr);
			}else{
   			   getAttributeValue(wmldck,wmldck->tmpstr);
			}
            if (wmldck->action == ACTION_SRC)
                srcAttr(wmldck, attr_id,wmldck->tmpstr,g);
            c = wmldck->data[wmldck->offset++];
        }//while
        wmldck->offset--;
    }
    return(NULL);
}

int readElement(WMLDeckPtr wmldck, GlobalsType *g)
{
    int startoffset;
    unsigned char c;
	Char *attr;
	Char *name;
	//char	accessUrl[MAX_URL_LEN+1];
	//int		accessInt = 0;
 	Int16  					linkLen, postLen;
 	RGBColorType       color;  
	IndexedColorType   indexedColor;
	
		//For DO tags
		color.r   = ( UInt8 ) 0;//Set the amount of Red to use (0 - 255)
	    color.g   = ( UInt8 ) 0;//Set the amount of Green to use (0 - 255)
	    color.b   = ( UInt8 ) 210;//255;//Set the amount of Blue to use (0 - 255)
	    indexedColor  = WinRGBToIndex( &color );

    startoffset = wmldck->offset;
    wmldck->tag = wmldck->data[wmldck->offset] & WBXML_tag_id;
    c = wmldck->data[wmldck->offset];

    if ((wmldck->tag >=5) && (wmldck->tag <= 0x3F )) {
        switch (wmldck->action) {
        case ACTION_RENDER :
			switch(wmldck->tag) {
    		case WML_card :
        		attr = getAttributes(wmldck,WML_title,g);
				if (attr){
	        		FrmSetTitle(FrmGetActiveForm(),attr);
	        		/*FntSetFont(boldFont);
	        		palmprintf(attr, g);
	        		FntSetFont(stdFont);
	        		palmprintf("-------------------------------------", g);
	        		renderLn(g);*/
	        		FrmShowObject(FrmGetActiveForm(), FrmGetObjectIndex (FrmGetActiveForm(), buttonMenu));
	        		//if (g->deckTitle)
	        		//	Free(g->deckTitle);
	        		g->deckTitle = Malloc(StrLen(attr)+1);
	        		ErrFatalDisplayIf (!g->deckTitle, "Malloc Failed");
					StrCopy(g->deckTitle,attr);
	        	}
				else {
	        		FrmSetTitle(FrmGetActiveForm(),"WAPUniverse");
	        		FrmShowObject(FrmGetActiveForm(), FrmGetObjectIndex (FrmGetActiveForm(), buttonMenu));
	        		if (g->deckTitle)
	        			Free(g->deckTitle);
	        		g->deckTitle = Malloc(StrLen("Untitled")+1);
	        		ErrFatalDisplayIf (!g->deckTitle, "Malloc Failed");
					StrCopy(g->deckTitle,"Untitled");
	        	}
				wmldck->offset=startoffset;
				attr = getAttributes(wmldck,WML_ontimer,g);
				if (attr){
					if (wmldck->ontimerUrl)
						free(wmldck->ontimerUrl);
					wmldck->ontimerUrl = Malloc(StrLen(attr)+1);
					ErrFatalDisplayIf (!wmldck->ontimerUrl, "Malloc Failed");
					StrCopy(wmldck->ontimerUrl,attr);						
				}
				wmldck->offset=startoffset;
				attr = getAttributes(wmldck,WML_onenterforward,g);
				if (attr){
					followLink(attr, g);
				}
				wmldck->offset=startoffset;
				attr = getAttributes(wmldck,END,g);
				break;
			/*case WML_template://TODO: Add template support
				renderLn(g);
				palmprintf("Got Template", g);
	            attr = getAttributes(wmldck,END,g);
				break;*/
			/*case WML_access://TODO: add access support
				attr = getAttributes(wmldck,WML_domain,g);
				if (attr){
				}
				wmldck->offset=startoffset;
				attr = getAttributes(wmldck,WML_path,g);
				if (attr){
					// We need till next '/'
					while ( (g->WapLastUrl[accessInt] > 8) && (g->WapLastUrl[accessInt]!= '/')){
					    accessUrl[accessInt]=g->WapLastUrl[accessInt++];
					}
					if(StrNCaselessCompare(accessUrl,attr,StrLen(attr))==0)
					{
						browserStopEvt(g);
						MyErrorFunc("WML Deck Access Denied","");
					}
					
				}
				wmldck->offset=startoffset;
				attr = getAttributes(wmldck,END,g);
				break;*/
			case WML_postfield:
				if ( (name = getAttributes(wmldck,WML_name,g))){
					addVar(name,g);
					
					
					if (StrStr (g->HyperLinks->url, "?") || StrStr (g->HyperLinks->url, "|")){//search for ? in the URL
						//if there is a "?" we will just construct the "&name=" here
						if (postStart == true) {//this is the first postfield element for
						//corresponding go element
							linkLen = StrLen(g->HyperLinks->url);
							gstrcopy(g->HyperLinks->url+linkLen, "|");
							linkLen = StrLen(g->HyperLinks->url);
							gstrcopy(g->HyperLinks->url+linkLen, name);
							linkLen = StrLen(g->HyperLinks->url);
							gstrcopy(g->HyperLinks->url+linkLen,"=");
							postStart = false;
						}
						else {
							linkLen = StrLen(g->HyperLinks->url);
							gstrcopy(g->HyperLinks->url+linkLen, "&");
							linkLen = StrLen(g->HyperLinks->url);
							gstrcopy(g->HyperLinks->url+linkLen, name);
							linkLen = StrLen(g->HyperLinks->url);
							gstrcopy(g->HyperLinks->url+linkLen,"=");
						}
						//add it to postBuf
						if (g->post == true) {
							//postLen = StrLen(g->HyperLinks->postBuf);
							//gstrcopy(g->HyperLinks->postBuf+postLen,"&");
							//postLen = StrLen(g->HyperLinks->postBuf);
							//gstrcopy(g->HyperLinks->postBuf+postLen, name);
							//postLen = StrLen(g->HyperLinks->postBuf);
							//gstrcopy(g->HyperLinks->postBuf+postLen,"=");
							//MyErrorFunc(g->HyperLinks->postBuf,"name");//debug
						}
						
					}
					else {//if there is no "?" then add it with the name so we 
						  //create "?name="
						if (postStart == true) {//this is the first postfield element for
						//corresponding go element
							linkLen = StrLen(g->HyperLinks->url);
							gstrcopy(g->HyperLinks->url+linkLen, "|");
							linkLen = StrLen(g->HyperLinks->url);
							gstrcopy(g->HyperLinks->url+linkLen, name);
							linkLen = StrLen(g->HyperLinks->url);
							gstrcopy(g->HyperLinks->url+linkLen,"=");
							postStart = false;
						}
						else {
							linkLen = StrLen(g->HyperLinks->url);
							gstrcopy(g->HyperLinks->url+linkLen, "?");
							linkLen = StrLen(g->HyperLinks->url);
							gstrcopy(g->HyperLinks->url+linkLen, name);
							linkLen = StrLen(g->HyperLinks->url);
							gstrcopy(g->HyperLinks->url+linkLen,"=");
						}
						//add it to postBuf
						if (g->post == true) {
							//gstrcopy(g->HyperLinks->postBuf, name);
							//postLen = StrLen(g->HyperLinks->postBuf);
							//gstrcopy(g->HyperLinks->postBuf+postLen,"=");
							//MyErrorFunc(g->HyperLinks->postBuf,"name");//debug
						}
					}
					  
				}	
				wmldck->offset=startoffset;			
				if ( (attr = getAttributes(wmldck,WML_value,g))){
					setVar(name,attr,g);
					//now we will add the "$(var)" to the url
					linkLen = StrLen(g->HyperLinks->url);
					gstrcopy(g->HyperLinks->url+linkLen, attr);
					//add it to postBuf
					if (g->post == true) {
						//postLen = StrLen(g->HyperLinks->postBuf);
						//gstrcopy(g->HyperLinks->postBuf+postLen, attr);
						//MyErrorFunc(g->HyperLinks->postBuf,"value");//debug
					}
				}
				wmldck->offset=startoffset;
				//if (g->postBuf)
				//	MyErrorFunc(g->postBuf, "");
				attr = getAttributes(wmldck,END,g);
				break;
			case WML_onevent:
				attr = getAttributes(wmldck,WML_type_ontimer,g);
				if (attr){
					g->onEvent = 1;
					needTimer = true;
				}
				wmldck->offset=startoffset;
				attr = getAttributes(wmldck,WML_type_onenterforward,g);
				if (attr){
					g->onEvent = 2;
				}
				wmldck->offset=startoffset;
				attr = getAttributes(wmldck,WML_type_onpick,g);
				if (attr){
					g->onEvent = 3;
				}
				wmldck->offset=startoffset;
				attr = getAttributes(wmldck,END,g);
				break;
			case WML_timer:
				attr = getAttributes(wmldck,WML_value,g);
				if (attr){
						wmldck->timerVal=StrAToI(attr);
				}else{
                        DisplayError("Timer but no Value!"); 				
				}
				wmldck->offset=startoffset;
				attr = getAttributes(wmldck,END,g);
				break;		
			case WML_br:
				//if (g->x > 0)
				renderLn(g);
	            attr = getAttributes(wmldck,END,g);
				break;
			case WML_p:
				//work on alignment
				/*attr = getAttributes(wmldck,WML_align_left,g);
				if (attr){
					renderLn(g);
				}
				wmldck->offset=startoffset;
				if (!attr){
				attr = getAttributes(wmldck,WML_align_center,g);
				if (attr){
					//FntLineWidth (DEF_RECEIVE_BUF, &width);
					j = WspReadInt(wmldck->data,&(wmldck->offset));
					width = TxtCharWidth(wmldck->strTable+j);
					renderLn2(width,g);
				}
				wmldck->offset=startoffset;
				if (!attr){
				attr = getAttributes(wmldck,WML_align_right,g);
				if (attr){
					//FntLineWidth (DEF_RECEIVE_BUF, &width);
					j = WspReadInt(wmldck->data,&(wmldck->offset));

⌨️ 快捷键说明

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