Esempio n. 1
0
void XFE_ReadAttachPanel::addAttachments(MSG_Pane *pane,MSG_AttachmentData* data)
{
    // adopt storage of backend attachment list, free in removeAllAttachments
    _pane=pane;
    _attachments=data;
    
    MSG_AttachmentData* tmp;
    for (tmp = data ; tmp->url ; tmp++) {
        char *itemLabel=NULL;

        // Hack around back-end not naming the sent v-card. Use
        // description field: "Card for ...", to provide some
        // uniqueness among received vcards.
        if (tmp->real_name && XP_STRCASECMP(tmp->real_name,"vcard.vcf")==0 &&
            tmp->description && strlen(tmp->description)>0) {
            itemLabel=(char*)XP_ALLOC(strlen(tmp->description)+4+1);
            sprintf(itemLabel,"%s.vcf",tmp->description);
        }

        // find a label for the attachment
        else if (tmp->real_name && strlen(tmp->real_name)>0) {
            itemLabel=XP_STRDUP(tmp->real_name);
        } else if (tmp->description && strlen(tmp->description)>0) {
            itemLabel=XP_STRDUP(tmp->description);
        } else if (tmp->real_type && strlen(tmp->real_type)>0) {
            itemLabel=XP_STRDUP(tmp->real_type);
        } else {
            itemLabel=XP_STRDUP("attachment");
        }
        // translate problem characters in label to '_'
        char *s=itemLabel;
        while (*s) {
            if (*s==' ' || *s=='/' || *s=='\\')
                *s='_';
            s++;
        }

        XFE_AttachPanelItem *item = new
            XFE_AttachPanelItem(this,
                                tmp->url,
                                itemLabel,
                                tmp->real_type);
        addItem(item);
        // add to drag handler
        if (_attachDrag && item->image()) {
            _attachDrag->addDragWidget(item->image());
        }
        
        if (itemLabel)
            XP_FREE(itemLabel);
    }

    // select first attachment by default
    if (_numItems>0)
        selectItem(_items[0]);
}
Esempio n. 2
0
event_setProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
    JSEvent *event;
    jsint slot, i;
    JSString *str;
    const char *name;
    uint32 temp;

    if (!JSVAL_IS_INT(id))
	return JS_TRUE;

    event = JS_GetInstancePrivate(cx, obj, &lm_event_class, NULL);
    if (!event)
	return JS_TRUE;

    slot = JSVAL_TO_INT(id);

    if (slot==EVENT_TYPE) {
	if (!JSVAL_IS_STRING(*vp) || !(str = JS_ValueToString(cx, *vp)))
	    return JS_FALSE;
	name = JS_GetStringBytes(str);
	for (i = 0; i < NUM_EVENTS; i++) {
	    if (!XP_STRCASECMP(event_names[i].lowerName, name))
		event->type = PR_BIT(i);
	}
    }
    else if ((slot==EVENT_X) || (slot==EVENT_LAYERX))
	return JS_ValueToInt32(cx, *vp, &event->x);
    else if ((slot==EVENT_Y) ||	(slot==EVENT_LAYERY))
	return JS_ValueToInt32(cx, *vp, &event->y);
    else if (slot==EVENT_DOCX)
	return JS_ValueToInt32(cx, *vp, &event->docx);
    else if (slot==EVENT_DOCY)
	return JS_ValueToInt32(cx, *vp, &event->docy);
    else if (slot==EVENT_SCREENX)
	return JS_ValueToInt32(cx, *vp, &event->screenx);
    else if (slot==EVENT_SCREENY)
	return JS_ValueToInt32(cx, *vp, &event->screeny);
    else if (slot==EVENT_WHICH)
	return GetUint32(cx, *vp, &event->which);
    else if (slot==EVENT_MODIFIERS)
	GetUint32(cx, *vp, &temp);
	event->modifiers = temp;
	return JS_TRUE;
    /* Win16 hack */
    /*else if (slot==EVENT_DATA) {
	GetUint32(cx, *vp, &temp);
	event->data = temp;
	return JS_TRUE;
    } */

    return JS_TRUE;
}
Esempio n. 3
0
static void
lo_ParseScriptLanguage(MWContext * context, PA_Tag * tag, int8 * type,
		       JSVersion * version)
{
    PA_Block buff;
    char * str;

    buff = lo_FetchParamValue(context, tag, PARAM_LANGUAGE);
    if (buff != NULL) {
        PA_LOCK(str, char *, buff);
        if ((XP_STRCASECMP(str, js_language_name) == 0) ||
            (XP_STRCASECMP(str, "LiveScript") == 0) ||
            (XP_STRCASECMP(str, "Mocha") == 0)) {
            *type = SCRIPT_TYPE_MOCHA;
            *version = JSVERSION_DEFAULT;
        } 
        else if (XP_STRCASECMP(str, "JavaScript1.1") == 0) {
            *type = SCRIPT_TYPE_MOCHA;
            *version = JSVERSION_1_1;
        } 
        else if (XP_STRCASECMP(str, "JavaScript1.2") == 0) {
            *type = SCRIPT_TYPE_MOCHA;
            *version = JSVERSION_1_2;
        } 
        else if (XP_STRCASECMP(str, "JavaScript1.3") == 0) {
            *type = SCRIPT_TYPE_MOCHA;
            *version = JSVERSION_1_3;
        } 

        else {
            *type = SCRIPT_TYPE_UNKNOWN;
        }
        PA_FREE(buff);
    }
}
Esempio n. 4
0
intn XP_ColorNameToRGB(char *name, uint8 *r, uint8 *g, uint8 *b)
{
	int comp, low, mid, high;

	if (name == NULL)
	{
		return 1;
	}

	low = 0;
	high = TABLESIZE - 1;
	/*
	** Binary search, starting at zero, which is slightly less
	** efficient, but makes the exit condition simple.
	*/
	mid = 0;
	for (;;)
	{
		if(!(comp = XP_STRCASECMP(name, xp_rgb_table[mid].name)))
		{
#ifdef GROSS_DEBUG
			if (mid < 0 || mid >= TABLESIZE) {
			  printf("Found %s out of range\n", name);
			  return 1;
			}
#endif
			*r = xp_rgb_table[mid].r;
			*g = xp_rgb_table[mid].g;
			*b = xp_rgb_table[mid].b;
			return 0;
		}
		if ((high - low) <= 1)
		  return 1;
		if(comp>0)
			low = mid;
		else
			high = mid;
		mid = low + (high-low+1)/2;
	}
	/* NOTREACHED */
	return 1;
}
Esempio n. 5
0
// nyi - extract nice file name from title or url
char *XFE_URLDesktopType::getFilename(int pos)
{
    if (pos<0 || pos>=_numItems || _url[pos]==NULL)
        return XP_STRDUP("unknown");

    // (alastair) code taken from libmsg/msgsend.cpp - be nice just to call into libmsg
    // modified slightly to avoid bug of trailing / generating empty name
    // modified to return truncated label for mail/news URL's

    const char *url=_url[pos];
    
    if (!url || strlen(url)==0)
        return XP_STRDUP("(null)");

    char *s;
    char *s2;
    char *s3;
   
    /* If we know the URL doesn't have a sensible file name in it,
       don't bother emitting a content-disposition. */
    if (!XP_STRNCASECMP(url, "news:", 5))
        return XP_STRDUP("news:");
    if (!XP_STRNCASECMP(url, "snews:", 6))
        return XP_STRDUP("snews:");
    if (!XP_STRNCASECMP(url, "mailbox:", 8))
        return XP_STRDUP("mailbox:");

    char *tmpLabel = XP_STRDUP(url);

    s=tmpLabel;
    /* remove trailing / or \ */
    int len=strlen(s);
    if (s[len-1]=='/' || s[len-1]=='\\')
        s[len-1]='\0';

    s2 = XP_STRCHR (s, ':');
    if (s2) s = s2 + 1;
    /* Take the part of the file name after the last / or \ */
    if (s2 = XP_STRRCHR (s, '/'))
        s = s2+1;
    else if (s2 = XP_STRRCHR (s, '\\'))
        s = s2+1;

    /* if it's a non-file url do some additional massaging */
    if (XP_STRNCASECMP(url,"file:",5)!=0 && url[0]!='/') {
        /* Trim off any named anchors or search data. */
        s3 = XP_STRCHR (s, '?');
        if (s3) *s3 = 0;
        s3 = XP_STRCHR (s, '#');
        if (s3) *s3 = 0;

        /* Check for redundant document name.
         * Use previous URL component to provide more meaningful file name.
         */
        if (s2 &&
            XP_STRCASECMP(s,"index.html")==0 ||
            XP_STRCASECMP(s,"index.htm")==0 ||
            XP_STRCASECMP(s,"index.cgi")==0 ||
            XP_STRCASECMP(s,"index.shtml")==0 ||
            XP_STRCASECMP(s,"home.html")==0 ||
            XP_STRCASECMP(s,"home.htm")==0 ||
            XP_STRCASECMP(s,"home.cgi")==0 ||
            XP_STRCASECMP(s,"home.shtml")==0) {
            /* Trim redundant component and try again */
            *s2='\0';
            s=tmpLabel;
            /* Redo: Take the part of the file name after the last / or \ */
            if (s2 = XP_STRRCHR (s, '/'))
                s = s2+1;
            else if (s2 = XP_STRRCHR (s, '\\'))
                s = s2+1;
        }
    }

    /* Now lose the %XX crap. */
    NET_UnEscape (s);

    char *retLabel=XP_STRDUP(s);
    XP_FREE(tmpLabel);

    return retLabel;
}
Esempio n. 6
0
void
lo_FormatObject(MWContext* context, lo_DocState* state, PA_Tag* tag)
{
	lo_TopState* top_state = state->top_state;
	lo_ObjectStack* top;
	LO_ObjectStruct* object;
	PA_Block buff;
	int16 type = LO_NONE;
	char* str;

#ifdef	ANTHRAX
	XP_Bool javaMimetypeHandler = FALSE;
	char* appletName;
	NET_cinfo* fileInfo;
#endif /* ANTHRAX */
	
	/*
	 * Make a new default object.  Passing LO_OBJECT will create an
	 * LO_Element, which being a union of all other layout element types
	 * is guaranteed to be big enough to transmogrify into one of these
	 * specific types later if necessary.
	 */
	object = (LO_ObjectStruct*) lo_NewElement(context, state, LO_OBJECT, NULL, 0);
	if (object == NULL)
	{
		state->top_state->out_of_memory = TRUE;
		return;
	}
	
	top = top_state->object_stack;
	top->object = object;

	/*
	 * Set up default fields for this object that are common
	 * to all possible object types.
	 */
	object->lo_element.type = LO_NONE;
	object->lo_element.lo_any.ele_id = NEXT_ELEMENT;
	object->lo_element.lo_any.x = state->x;
	object->lo_element.lo_any.x_offset = 0;
	object->lo_element.lo_any.y = state->y;
	object->lo_element.lo_any.y_offset = 0;
	object->lo_element.lo_any.width = 0;
	object->lo_element.lo_any.height = 0;
	object->lo_element.lo_any.next = NULL;
	object->lo_element.lo_any.prev = NULL;

	
	/*
	 * Now attempt to figure out what type of object we have.
	 * If the type can be determined here, great; otherwise
	 * we have to block until the type can be determined by
	 * reading in additional data.
	 *
	 * Initially the type of the object is LO_NONE.  When
	 * we figure out enough to know the type, we set it to
	 * LO_EMBED, LO_JAVA, or LO_IMAGE.  If the type had
	 * already been changed to a different incompatible type,
	 * then the tag is malformed and we should ignore it, so
	 * set the type to LO_UNKNOWN.
	 */
	
#if 0 
	/*
	 * Check the "codetype" attribute, which optionally determines
	 * the MIME type of the object code itself (as opposed to its
	 * data).  The only code type we know about right now is
	 * application/java-vm for Java applets.
	 */
	buff = lo_FetchParamValue(context, tag, PARAM_CODETYPE);
	if (buff != NULL)
	{
		PA_LOCK(str, char *, buff);
		if (pa_TagEqual(APPLICATION_JAVAVM, str))
		{
			/* It's a Java applet */
			if (type == LO_NONE)
				type = LO_JAVA;
			else if (type != LO_JAVA)
				type = LO_UNKNOWN;
		}
		else if (pa_TagEqual(APPLICATION_OLEOBJECT, str) ||
				 pa_TagEqual(APPLICATION_OLEOBJECT2, str))
		{
			/* It's an OLE object */
			if (type == LO_NONE)
				type = LO_EMBED;
			else if (type != LO_EMBED)
				type = LO_UNKNOWN;
		}
		PA_UNLOCK(buff);
		XP_FREE(buff);
	}
#endif

	/*
	 * Check the "classid" attribute, which optionally determines
	 * the specific implementation of the object.  The classid
	 * could be a normal URL, in which case we have to retrieve
	 * that URL and match it against a known code type (see above).
	 * There are also two "magic" URL types supported for classid:
	 * "clsid:", which indicates a COM 376-hex-digit class ID,
	 * and "java:", which indicates a specific java class to run.
	 * Note that the "java:" URL is different from the APPLET
	 * "code" attribute: the "java:" URL specifies a particular
	 * method (e.g. "java:program.run"), while the APPLET CODE
	 * attribute specifies an applet subclass (e.g. "MyApplet.class").
     *
     * Further notes about "java:"
     * We are adding two related "magic" protocol selectors to
     * augment "java:". These are "javaprogram:" and "javabean:".
     * They are used with embedded applications and application
     * objects. "javaprogram:" identifies an object as being a
     * subclass of netscape.application.Application, and is used
     * to start an instance of such application. "javabean:" is
     * used to add an embedded object to an application.
	 */
	buff = lo_FetchParamValue(context, tag, PARAM_CLASSID);
	if (buff != NULL)
	{
		PA_LOCK(str, char *, buff);
		if (XP_STRNCASECMP(str, "clsid:", 6) == 0)
		{
			/*
			 * It's a COM class ID, so make sure we have an
			 * appropriate plug-in to handle ActiveX controls.
			 */
			if (NPL_FindPluginEnabledForType(APPLICATION_OLEOBJECT) != NULL)
			{
				if (type == LO_NONE)
					type = LO_EMBED;
				else if (type != LO_EMBED)
					type = LO_UNKNOWN;
			}
		}
		else if ( (XP_STRNCASECMP(str, "java:", 5) == 0) ||
                  (XP_STRNCASECMP(str, "javaprogram:", 12) == 0) ||
                  (XP_STRNCASECMP(str, "javabean:", 9) == 0) )
		{
			/* It's a Java class */
			if (type == LO_NONE)
				type = LO_JAVA;
			else if (type != LO_JAVA)
				type = LO_UNKNOWN;
		}
		else
		{
			/*
			 * Must be a URL to the code; we'll need to fetch it to
			 * determine the type.  bing: How should we do this?
			 */
		}
		PA_UNLOCK(buff);
		XP_FREE(buff);
	}

	/*
	 * Check the "type" attribute, which optionally determines
	 * the type of the data for the object.  The data type
	 * can be used to infer the object implementation type if
	 * the implementation hasn't been specified via "classid"
	 * or "codetype" (see above).  The two kinds of objects
	 * we currently support with typed data are plug-ins and
	 * images; for plug-ins we can ask libplug if the type is
	 * currently handled by a plug-in; for images we just check
	 * against a hard-coded list of image types we natively
	 * support (yuck).
	 */
	buff = lo_FetchParamValue(context, tag, PARAM_TYPE);
	if (buff != NULL)
	{
		PA_LOCK(str, char *, buff);
		if (NPL_FindPluginEnabledForType(str) != NULL)
		{
			/* It's a plug-in */
			if (type == LO_NONE)
				type = LO_EMBED;
			else if (type != LO_EMBED)
				type = LO_UNKNOWN;
		}

		/*  
			Adding a check for applets that handle mimetypes.
			The pref is stored based on the particular mimetype.
			We do a lookup and if there is an association, the name
			of the applet is placed into "appletName".  
			
			NOTE: PREF_CopyCharPref() allocates memory for appletName
					and we must free it.
					
			9.23.97		amusil
		*/
#ifdef	ANTHRAX
		if((appletName = NPL_FindAppletEnabledForMimetype(str)) != NULL)
			{
			/* Set the type */
			type = LO_JAVA;
			
			/* set the CLASSID to whatever was put into "appletName" */
			lo_SetClassID(tag, appletName);
			
			/* set this so that we know later to translate the DATA/SRC param to a Java arg */
			javaMimetypeHandler = TRUE;
			XP_FREE(appletName);
			}
#endif	/* ANTHRAX */	
		
#if 0
		else if (XP_STRNCASECMP(str, "image/", 6) == 0)
		{
			if (XP_STRCASECMP(str, IMAGE_GIF) ||
				XP_STRCASECMP(str, IMAGE_JPG) ||
				XP_STRCASECMP(str, IMAGE_PJPG) ||
				XP_STRCASECMP(str, IMAGE_XBM) ||
				XP_STRCASECMP(str, IMAGE_XBM2) ||
				XP_STRCASECMP(str, IMAGE_XBM3))
			{
				/* It's an image */
				if (type == LO_NONE)
					type = LO_IMAGE;
				else if (type != LO_IMAGE)
					type = LO_UNKNOWN;
			}
		}
#endif /* if 0 */

#ifdef SHACK
		if (XP_STRNCASECMP(str, "builtin", 7) == 0)
		{
			if (type == LO_NONE)
				type = LO_EMBED;
			else if (type != LO_EMBED)
				type = LO_UNKNOWN;
		}
#endif /* SHACK */

		PA_UNLOCK(buff);
		XP_FREE(buff);
	}
#ifdef	ANTHRAX
	else /* we didn't find a TYPE param, so check the filename to get the type - amusil */
		{
		buff = lo_FetchParamValue(context, tag, PARAM_SRC);
		/* if no src, check if there's a DATA param */
		if(buff == NULL)
			buff = lo_FetchParamValue(context, tag, PARAM_DATA);
			
		
		/* extract the mimetype info */
		PA_LOCK(str, char *, buff);
		fileInfo = NET_cinfo_find_type(str);
		
		str = fileInfo->type;
		if((appletName = NPL_FindAppletEnabledForMimetype(str)) != NULL)
			{
			/* Set the type */
			type = LO_JAVA;
			
			/* set the CLASSID to whatever was put into "appletName" */
			lo_SetClassID(tag, appletName);
			
			/* set this so that we know later to translate the DATA/SRC param to a Java arg */
			javaMimetypeHandler = TRUE;
			XP_FREE(appletName);			/* do we need to free this regardless? */	
			}
		if(buff)
			XP_FREE(buff);
		}
#endif	/* ANTRHAX */


	if (type == LO_EMBED)
	{
		object->lo_element.type = LO_EMBED;
	}
#ifdef JAVA
	else if (type == LO_JAVA)
	{
		if (LJ_GetJavaEnabled() != FALSE)
		{
			/*
			 * Close out the current applet if necessary
			 * (people tend to forget "</APPLET>").
			 */
			if (state->current_java != NULL)
				lo_CloseJavaApp(context, state, state->current_java);
				
			object->lo_element.type = LO_JAVA;
			lo_FormatJavaObject(context, state, tag, (LO_JavaAppStruct*) object);
			
			/* 
				If we determined previously that this is an applet to mimetype
				association, we must set up the SRC or DATA as an arg for the 
				applet.
				
				9.8.97		amusil
			*/
#ifdef	ANTHRAX
			if(javaMimetypeHandler)
				lo_SetJavaArgs((char*)tag->data, state->current_java);
#endif	/* ANTHRAX */
		}
	}
#endif /* JAVA */
#if 0
	else if (type == LO_IMAGE)
	{
		object->type = LO_IMAGE;
		lo_FormatImageObject(context, state, tag, (LO_ImageStruct*) object);
	}
#endif /* if 0 */
	else
	{
		/*
		 * Check for a "data" attribute; if it exists, we can get
		 * the URL later to see what the type of the object should be.
		 */
		buff = lo_FetchParamValue(context, tag, PARAM_DATA);
		if (buff != NULL)
		{
			PA_LOCK(str, char *, buff);
			if (XP_STRNCASECMP(str, "data:", 5) == 0)
			{
				/* bing: deal with magic data URLs here */
				PA_UNLOCK(buff);
				XP_FREE(buff);
			}
			else
			{
				
				/*
				 * Block layout until we can read the PARAM tags
				 * and closing </OBJECT> tag, go get the data URL,
				 * and determine its type.  At that point (in
				 * either LO_NewObjectStream, or lo_ObjectURLExit),
				 * we know the object type and can unblock.
				 */
				top->data_url = str;
				state->top_state->layout_blocking_element = (LO_Element*) object;
				PA_UNLOCK(buff);
				/* Don't free buff; we stored it in the object stack */
			}
		}
		else
		{
			/*
			 * Otherwise we just don't know what to do with this!
			 */
			object->lo_element.type = LO_UNKNOWN;
		}
	}
}
Esempio n. 7
0
/* 
	Process a tag, adding urls to the lists of links, images, or resources.
	The parser calls this routine whenever a tag or between-tag data has been read. 
*/
int crawl_processToken(CRAWL_ParseObj obj, PRBool isTag, void *data) {
	CRAWL_TagError err = CRAWL_TAG_NO_ERR;
	CRAWL_PageInfo page = (CRAWL_PageInfo)data;
	if (isTag) {
		CRAWL_Tag tag = CRAWL_GetTagParsed(obj);
		char *name = CRAWL_GetTagName(tag);
		char *att1, *att2, *att3;
		if (CRAWL_IsEndTag(tag)) return PARSE_GET_NEXT_TOKEN;
		switch (CRAWL_GetTagToken(tag)) {
		case P_ANCHOR:
			att1 = CRAWL_GetAttributeValue(tag, PARAM_HREF); /* <A HREF=?> */
			if (att1 != NULL) err = crawl_processURL(page, att1, LINK_CONTEXT_HREF);
			break;
		case P_AREA:
			att1 = CRAWL_GetAttributeValue(tag, PARAM_HREF); /* <AREA HREF=?> */
			if (att1 != NULL) err = crawl_processURL(page, att1, LINK_CONTEXT_HREF);
			break;
		case P_BASE:
			att1 = CRAWL_GetAttributeValue(tag, PARAM_HREF);
			if (att1 != NULL) {
				page->baseURL = NET_MakeAbsoluteURL(page->url_s->address, att1); /* XP_STRDUP(att1); */
				if (page->baseURL == NULL) err = CRAWL_TAG_NO_MEMORY;
			}
			break;
		case P_IMAGE:
			att1 = CRAWL_GetAttributeValue(tag, PARAM_SRC); /* <IMG SRC=?> */
			if (att1 != NULL) err = crawl_addPageImage(page, att1);
			break;
		case P_BODY:
			att1 = CRAWL_GetAttributeValue(tag, PARAM_BACKGROUND); /* <BODY BACKGROUND=?> */
			if (att1 != NULL) err = crawl_addPageImage(page, att1);
			break;
		case P_GRID_CELL:
			att1 = CRAWL_GetAttributeValue(tag, PARAM_SRC); /* <FRAME SRC=?> */
			if (att1 != NULL) err = crawl_processURL(page, att1, LINK_CONTEXT_FRAME);
			break;
		case P_LAYER:
			att1 = CRAWL_GetAttributeValue(tag, PARAM_SRC); /* <LAYER SRC=?> */
			if (att1 != NULL) err = crawl_processURL(page, att1, LINK_CONTEXT_LAYER);
			att2 = CRAWL_GetAttributeValue(tag, "background"); /* <LAYER BACKGROUND=?> */
			if ((att2 != NULL) && (err == CRAWL_TAG_NO_ERR)) err = crawl_addPageImage(page, att2);
			break;
		case P_EMBED:
			att1 = CRAWL_GetAttributeValue(tag, PARAM_SRC); /* <EMBED SRC=?> */
			if (att1 != NULL) err = crawl_addPageResource(page, att1);
			break;
		case P_SCRIPT:
			att1 = CRAWL_GetAttributeValue(tag, PARAM_ARCHIVE);
			if (att1 != NULL) err = crawl_addPageRequiredResource(page, att1);
			att2 = CRAWL_GetAttributeValue(tag, PARAM_SRC);
			if ((att2 != NULL) && (err == CRAWL_TAG_NO_ERR)) err = crawl_addPageRequiredResource(page, att2);
			break;
		case P_JAVA_APPLET:
			att1 = CRAWL_GetAttributeValue(tag, PARAM_CODEBASE);
			att2 = CRAWL_GetAttributeValue(tag, PARAM_ARCHIVE);
			att3 = CRAWL_GetAttributeValue(tag, PARAM_CODE);
			err = crawl_addPageApplet(page, att1, att2, att3);
			break;
		case P_META:
			att1 = CRAWL_GetAttributeValue(tag, PARAM_HTTP_EQUIV);
			if ((att1 != NULL) && (XP_STRCASECMP(att1, "refresh") == 0)) {
				att2 = CRAWL_GetAttributeValue(tag, PARAM_CONTENT);
				if (att2 != NULL) err = crawl_addPageMetaRefresh(page, att2);
			} else {
			/* robots meta tag: we take NOINDEX to mean don't cache (the document is already
			   cached so we need to remove it from the cache. NOFOLLOW means don't follow the
			   links, which we'll do by aborting the parsing of this page.
			   See http://info.webcrawler.com/mak/projects/robots/exclusion.html
			*/
				att1 = CRAWL_GetAttributeValue(tag, PARAM_NAME);
				if ((att1 != NULL) && (XP_STRCASECMP(att1, "robots") == 0)) {
					att2 = CRAWL_GetAttributeValue(tag, PARAM_CONTENT);
					if (att2 != NULL) {
						if (XP_STRCASESTR(att2, "noindex")) {
							page->dontIndex = PR_TRUE;
						}
						if (XP_STRCASESTR(att2, "nofollow")) {
							page->dontFollow = PR_TRUE;
							return PARSE_STOP;
						}
					}
				}
			}
			break;
		case P_LINK:
			att1 = CRAWL_GetAttributeValue(tag, PARAM_REL);
			if ((att1 != NULL) && (XP_STRCASECMP(att1, "stylesheet") == 0)) {
				att2 = CRAWL_GetAttributeValue(tag, PARAM_HREF);
				if (att2 != NULL) {
					att3 = CRAWL_GetAttributeValue(tag, PARAM_TYPE);
					if ((att3 != NULL) && ((XP_STRCASECMP(att3, "text/javascript") == 0) || (XP_STRCASECMP(att3, "text/css") == 0))) {
						err = crawl_addPageRequiredResource(page, att2);
					} else err = crawl_addPageResource(page, att2);
				}
			}
			break;
		case P_STYLE:
			att1 = CRAWL_GetAttributeValue(tag, PARAM_SRC);
			if (att1 != NULL) {
				att2 = CRAWL_GetAttributeValue(tag, PARAM_TYPE);
				if ((att2 != NULL) && ((XP_STRCASECMP(att2, "text/javascript") == 0) || (XP_STRCASECMP(att2, "text/css") == 0))) {
						err = crawl_addPageRequiredResource(page, att1);
				} else err = crawl_addPageResource(page, att1);
			}
			break;
		default:
			break;
		}
	}
	if (err == CRAWL_TAG_NO_MEMORY) return PARSE_OUT_OF_MEMORY;
	else return PARSE_GET_NEXT_TOKEN;
}
Esempio n. 8
0
void
lo_ProcessScriptTag(MWContext *context, lo_DocState *state, PA_Tag *tag, JSObject *obj)
{
    lo_TopState *top_state;
    pa_DocData *doc_data;
    XP_Bool type_explicitly_set=FALSE;
    XP_Bool saw_archive=FALSE;
#ifdef DEBUG_ScriptPlugin
	char * mimebuf = NULL;
#endif

    top_state = state->top_state;
    doc_data = (pa_DocData *)top_state->doc_data;
    XP_ASSERT(doc_data != NULL || state->in_relayout || tag->lo_data);

    if (tag->is_end == FALSE) {
        PA_Block buff;
        char *str, *url, *archiveSrc, *id, *codebase;

        /* Controversial default language value. */
        top_state->version = JSVERSION_DEFAULT;
        if (tag->type == P_STYLE || tag->type == P_LINK) {
            top_state->in_script = top_state->default_style_script_type;
        }
        else {
            /* in order to get old script behaviour, pretend
             * that the content-type is explicitly set for all scripts
             */
            type_explicitly_set = TRUE;
            top_state->in_script = SCRIPT_TYPE_MOCHA;
        }

        /* XXX account for HTML comment bytes and  "lost" newlines */
        if (lo_IsAnyCurrentAncestorSourced(state))
            top_state->script_bytes = top_state->layout_bytes;
        else
            top_state->script_bytes = top_state->layout_bytes - tag->true_len;
        if (tag->lo_data != NULL) {
            top_state->script_bytes += (int32)tag->lo_data - 1;
            tag->lo_data = NULL;
        } 
        else if (doc_data != NULL) {
            top_state->script_bytes += doc_data->comment_bytes;
        } 
        else {
            XP_ASSERT(state->in_relayout);
        }

	lo_ParseScriptLanguage(context, tag, &top_state->in_script,
			       &top_state->version);
#ifdef DEBUG_ScriptPlugin
		if (top_state->in_script == SCRIPT_TYPE_UNKNOWN)
		{
			mimebuf = npl_Script2mimeType(context,tag);
			if (mimebuf){
				if (NPL_FindPluginEnabledForType(mimebuf)){
					top_state->in_script = SCRIPT_TYPE_PLUGIN;
					XP_ASSERT(top_state->mimetype == NULL);
					StrAllocCopy((char *)top_state->mimetype,mimebuf);
					XP_FREE(mimebuf);
					mimebuf = NULL;
				}
				else{
					XP_FREE(mimebuf);
					mimebuf = NULL;
				}
			}
		}
#endif /* DEBUG_ScriptPlugin */

        buff = lo_FetchParamValue(context, tag, PARAM_TYPE);
        if (buff != NULL) {
            PA_LOCK(str, char *, buff);
            if ((XP_STRCASECMP(str, js_content_type) == 0) ||
                (!XP_STRCASECMP(str, "text/javascript"))) {
		if(tag->type == P_STYLE || tag->type == P_LINK)
		{
		    top_state->in_script = SCRIPT_TYPE_JSSS;
		    top_state->default_style_script_type = SCRIPT_TYPE_JSSS;
		}
		else
		{
		    top_state->in_script = SCRIPT_TYPE_MOCHA;                    
		}
                type_explicitly_set = TRUE;
            } 
            else if ((XP_STRCASECMP(str, TEXT_CSS) == 0)) {
                top_state->in_script = SCRIPT_TYPE_CSS;
                top_state->default_style_script_type = SCRIPT_TYPE_CSS;
                type_explicitly_set = TRUE;
            } 
            else {
                top_state->in_script = SCRIPT_TYPE_UNKNOWN;
                top_state->default_style_script_type = SCRIPT_TYPE_UNKNOWN;
            }
            PA_UNLOCK(buff);
            PA_FREE(buff);
        } 

	/* check for media=screen
	 * don't load the style sheet if there 
	 * is a media not equal to screen
	 */
	buff = lo_FetchParamValue(context, tag, PARAM_MEDIA);
	if (buff) {
	    if (strcasecomp((char*)buff, "screen")) {
		/* set the script type to UNKNOWN
		 * so that it will get thrown away
		 */
		top_state->in_script = SCRIPT_TYPE_UNKNOWN;
	    }
	    PA_FREE(buff);
	}

        /*
         * Flush the line buffer so we can start storing Mocha script
         * source lines in there.
         */
        lo_FlushLineBuffer(context, state);

        url = archiveSrc = id = codebase = NULL;
        if (top_state->in_script != SCRIPT_TYPE_NOT) {
            /*
             * Check for the archive parameter for known languages.
             */
            buff = lo_FetchParamValue(context, tag, PARAM_ARCHIVE);
            if (buff != NULL) {
                saw_archive = TRUE;
                PA_LOCK(str, char *, buff);
                url = NET_MakeAbsoluteURL(top_state->base_url, str);
                PA_UNLOCK(buff);
                PA_FREE(buff);
		if (url == NULL) {
                    top_state->out_of_memory = TRUE;
                    return;
		}
            }

            /* 
             * Look for ID attribute. If it's there we have may have
             * an inline signed script.
             */
            buff = lo_FetchParamValue(context, tag, PARAM_ID);
            if (buff != NULL) {
                PA_LOCK(str, char *, buff);
                StrAllocCopy(id, str);
                PA_UNLOCK(buff);
                PA_FREE(buff);
		if (id == NULL) {
                    top_state->out_of_memory = TRUE;
		    XP_FREEIF(url);
                    return;
		}
            }

            /*
             * Now look for a SRC="url" attribute for known languages.
             * If found, synchronously load the url.
             */
	    buff = lo_FetchParamValue(context, tag, PARAM_SRC);  /* XXX overloaded rv */
            if (buff != NULL) {
		XP_Bool allowFileSrc = FALSE;
                char *absUrl;

                PA_LOCK(str, char *, buff);

		PREF_GetBoolPref(lo_jsAllowFileSrcFromNonFile, &allowFileSrc);
                absUrl = NET_MakeAbsoluteURL(top_state->base_url, str);
		if (absUrl == NULL) {
		    top_state->out_of_memory = TRUE;
		    XP_FREEIF(id);
                } else if (allowFileSrc == FALSE &&
		           NET_URL_Type(absUrl) == FILE_TYPE_URL &&
		           NET_URL_Type(top_state->url) != FILE_TYPE_URL) {
		    /*
		     * Deny access from http: to file: via SCRIPT SRC=...
		     * XXX silently
		     */
                    top_state->in_script = SCRIPT_TYPE_UNKNOWN;
                    XP_FREE(absUrl);
                    XP_FREEIF(url);
		    XP_FREEIF(id);
		} else if (url != NULL) {
                    XP_FREE(absUrl);
                    StrAllocCopy(archiveSrc, str);
		    if (archiveSrc == NULL) {
			top_state->out_of_memory = TRUE;
			XP_FREE(url);
			XP_FREEIF(id);
		    }
                } else {
                    url = absUrl;
                }
                PA_UNLOCK(buff);
                PA_FREE(buff);
		if (top_state->out_of_memory)
		    return;

                /*
                 * If we are doing a <script src=""> mocha script but JS
                 *   is turned off just ignore the tag
                 */
		if (!LM_CanDoJS(context)) {
                    top_state->in_script = SCRIPT_TYPE_UNKNOWN;
                    XP_FREE(url);
		    XP_FREEIF(id);
		    XP_FREEIF(archiveSrc);
                    return;
                }
            }
        }

        /*
         * Set text_divert so we know to accumulate text in line_buf
         * without interpretation.
         */
        state->text_divert = tag->type;

        /*
         * XXX need to stack these to handle blocked SCRIPT tags
         */
        top_state->script_lineno = tag->newline_count + 1;

        /* if we got here as a result of a LINK tag
         * check to make sure rel=stylesheet and then
         * check for an HREF and if one does not exist
         * fail
         */
        if (tag->type == P_LINK) {
            char *cbuff = (char*)lo_FetchParamValue(context, tag, PARAM_REL);
                        
            if (cbuff && !strcasecomp(cbuff, "stylesheet")) {
                XP_FREE(cbuff);

                cbuff = (char*)lo_FetchParamValue(context, tag, PARAM_HREF);

                if (cbuff) {
                    if (saw_archive && url) {
                        archiveSrc = XP_STRDUP(cbuff);
                    } else {
		        XP_FREEIF(url);
                        url = NET_MakeAbsoluteURL(top_state->base_url, cbuff);
                    }
		}
            }

            XP_FREEIF(cbuff);
        }

        if (url != NULL || id != NULL || codebase != NULL) {
            if ((doc_data != NULL) &&
                (state->in_relayout == FALSE) &&
                SCRIPT_EXEC_OK(top_state, state, tag->type, P_SCRIPT)) {
                ScriptData *data;

                data = XP_ALLOC(sizeof(ScriptData));
                if (data == NULL) {
                    top_state->out_of_memory = TRUE;
                    return;
                }
                data->context = context;
                data->state = state;
                data->tag = PA_CloneMDLTag(tag);
                if (data->tag == NULL) {
                    top_state->out_of_memory = TRUE;
		    XP_FREE(data);
                    return;
                }
                data->url = url;
                data->archiveSrc = archiveSrc;
                data->id = id;
                if (codebase == NULL) {
                    StrAllocCopy(codebase, top_state->base_url);
                }
                data->codebase = codebase;
                data->buffer = NULL;
                data->bufferSize = 0;
                data->version = top_state->version;

		/*
		 * Only SCRIPT ARCHIVE= ID= without SRC= is an inline signed
		 * script -- if there is a SRC= attribute, archiveSrc will be
		 * non-null.
		 */
                data->inlineSigned = (JSBool)
		    (url != NULL && archiveSrc == NULL && id != NULL);

                /* Reset version accumulator */
                top_state->version = JSVERSION_UNKNOWN;

                XP_ASSERT (tag->type == P_SCRIPT || tag->type == P_STYLE || 
			   tag->type == P_LINK);

	        /* 
		 * Out-of-line included (by src=) or inline signed script.
		 * Save continuatation data on top_state.  If it's signed,
		 * we'll verify the signature once we see </script> and
		 * have the inline script to verify.
		 */
		top_state->scriptData = data;

            } 
	    else {
                XP_FREE(url);
		XP_FREEIF(id);
		XP_FREEIF(archiveSrc);
            }
        }
    } 
    else {

	/*
	 * We are in the </script> tag now...
	 */

        size_t line_buf_len;
        intn script_type;
        char *scope_to=NULL;
        char *untransformed = NULL;

        script_type = top_state->in_script;
        top_state->in_script = SCRIPT_TYPE_NOT;

	/* guard against superfluous end tags */
	if (script_type == SCRIPT_TYPE_NOT)
	    goto end_tag_out;

	/* convert from CSS to JavaScript here */
        if (tag->type != P_LINK && script_type == SCRIPT_TYPE_CSS) {
            char *new_buffer;
            int32 new_buffer_length;

            CSS_ConvertToJS((char *)state->line_buf, 
                            state->line_buf_len,
                            &new_buffer,
                            &new_buffer_length);

            if (!new_buffer) {
                /* css translator error, unblock layout and return */
                state->text_divert = P_UNKNOWN;
                state->line_buf_len = 0; /* clear script text */
                goto end_tag_out;
            }

            untransformed = (char *) state->line_buf;
            state->line_buf = (PA_Block) new_buffer;
            state->line_buf_len = new_buffer_length;
            state->line_buf_size = new_buffer_length;

            if (state->line_buf_len)
                state->line_buf_len--; /* hack: subtract one to remove final \n */

            script_type = SCRIPT_TYPE_JSSS;
        }

        if (tag->type == P_STYLE) {
            /* mocha scoped to document == jsss */
            scope_to = "document";
        }

        /*
         * Reset these before potentially recursing indirectly through
         * the document.write() built-in function, which writes to the
         * very same doc_data->parser_stream that this <SCRIPT> tag
         * came in on.
         */
        state->text_divert = P_UNKNOWN;
        line_buf_len = state->line_buf_len;
        state->line_buf_len = 0;

        if (script_type != SCRIPT_TYPE_UNKNOWN && 
	    script_type != SCRIPT_TYPE_NOT) {
            /*
             * If mocha is disabled or can't be done in this context we
             *   are going to just ignore the buffer contents
             */
            if (!LM_CanDoJS(context)) {
				top_state->in_script = SCRIPT_TYPE_UNKNOWN;
                goto end_tag_out;
            }

            if ((doc_data != NULL) &&
                (state->in_relayout == FALSE) &&
                SCRIPT_EXEC_OK(top_state, state, tag->type, P_SCRIPT)) {

                /*
                 * First off, make sure layout is blocking on us
                 */
                if (lo_create_script_blockage(context, state, 
					tag->type == P_SCRIPT ? LO_SCRIPT : LO_UNKNOWN)) 
				{
                    ScriptData *data;

                    /*
                     * Extreme hackery.  Hideous and shameful.  See the comment
						* in lo_BlockScriptTag before similar is_end/overflow code
						* and commence vomiting.
                     */
                    lo_BlockScriptTag(context, state, NULL);

		    if (tag->is_end == (PRPackedBool)1) {
			  PA_PushOverflow(doc_data);
			  doc_data->overflow_depth ++;
		    }

		    /*
		     * Set the document.write tag insertion point.
		     */
             top_state->input_write_point[top_state->input_write_level] = &top_state->tags;

		    data = top_state->scriptData;
                    top_state->scriptData = NULL;
                    if (data && data->url) {
			/*
			 * Three cases:
			 * 1.  SCRIPT SRC=: url non-null
			 * 2.  SCRIPT ARCHIVE= SRC=: url, archiveSrc non-null
			 * 3.  SCRIPT ARCHIVE= ID=: url, id non-null
			 * In the last case, we copy the inline script into
			 * data's buffer and let lo_script_archive_exit_fn do
			 * the eval.  We use an inlineSigned flag to avoid a
			 * bunch of (url != NULL && archiveSrc == NULL && id
			 * != NULL) tests.
			 */
			if (data->inlineSigned) {
                            StrAllocCopy(data->buffer, (char *) state->line_buf);
                            data->bufferSize = line_buf_len;
			}
			lo_GetScriptFromURL(data, script_type);
                    }
		    else {
                        JSPrincipals *principals = NULL;
			ETEvalStuff * stuff;
			
                        if (data) {
			    principals = LM_NewJSPrincipals(NULL, data->id, 
							    data->codebase);
                            if (untransformed &&
				!LM_SetUntransformedSource(principals, 
                                                           untransformed,
                                                           (char *) state->line_buf))
                            {
                                top_state->out_of_memory = TRUE;
                            }
                            lo_DestroyScriptData(data);
			}

                        /* 
                         * send the buffer off to be evaluated 
			 */
#ifdef DEBUG_ScriptPlugin
			 			if (script_type == SCRIPT_TYPE_PLUGIN)
						{
							XP_ASSERT(mimebuf == NULL);
							npl_ScriptPlugin(context, state, tag, line_buf_len,top_state->mimetype);
						    lo_unblock_script_tag(context, TRUE);
						}
						else
#endif /* DEBUG_ScriptPlugin */
 

			stuff = (ETEvalStuff *) XP_NEW_ZAP(ETEvalStuff);
			if (!stuff)
			    goto end_tag_out;

			stuff->len = line_buf_len;
			stuff->line_no = top_state->script_lineno;
			if (scope_to)
			    stuff->scope_to = XP_STRDUP(scope_to);
			else
			    stuff->scope_to = NULL;
			stuff->want_result = JS_FALSE;
			stuff->data = context;
			stuff->version = top_state->version;
			stuff->principals = principals;

                        ET_EvaluateScript(context, 
                                          (char *) state->line_buf,
					  stuff,
                                          lo_ScriptEvalExitFn);
                    }

                    /* Reset version accumulator */
                    top_state->version = JSVERSION_UNKNOWN;
                }
            }
        }
      end_tag_out:
	/*
	 * If we got a </SCRIPT> and still have scriptData set here, it must
	 *   be left over from an error case above, so we free it.
	 */
	if (top_state->scriptData) {
	    XP_ASSERT(!top_state->layout_blocking_element);
            lo_DestroyScriptData(top_state->scriptData);
	    top_state->scriptData = NULL;
	}
        XP_FREEIF(untransformed);
    }
}
Esempio n. 9
0
const char *
lm_CheckURL(JSContext *cx, const char *url_string, JSBool checkFile)
{
    char *protocol, *absolute;
    JSObject *obj;
    MochaDecoder *decoder;

    protocol = NET_ParseURL(url_string, GET_PROTOCOL_PART);
    if (!protocol || *protocol == '\0') {
        lo_TopState *top_state;

	obj = JS_GetGlobalObject(cx);
	decoder = JS_GetPrivate(cx, obj);

	LO_LockLayout();
	top_state = lo_GetMochaTopState(decoder->window_context);
        if (top_state && top_state->base_url) {
	    absolute = NET_MakeAbsoluteURL(top_state->base_url,
				           (char *)url_string);	/*XXX*/
            /* 
	     * Temporarily unlock layout so that we don't hold the lock
	     * across a call (lm_CheckPermissions) that may result in 
	     * synchronous event handling.
	     */
	    LO_UnlockLayout();
            if (!lm_CheckPermissions(cx, obj, 
                                     JSTARGET_UNIVERSAL_BROWSER_READ))
            {
                /* Don't leak information about the url of this page. */
                XP_FREEIF(absolute);
                return NULL;
            }
	    LO_LockLayout();
	} else {
	    absolute = NULL;
	}
	if (absolute) {
	    if (protocol) XP_FREE(protocol);
	    protocol = NET_ParseURL(absolute, GET_PROTOCOL_PART);
	}
	LO_UnlockLayout();
    } else {
	absolute = JS_strdup(cx, url_string);
	if (!absolute) {
	    XP_FREE(protocol);
	    return NULL;
	}
	decoder = NULL;
    }

    if (absolute) {

	/* Make sure it's a safe URL type. */
	switch (NET_URL_Type(protocol)) {
	  case FILE_TYPE_URL:
            if (checkFile) {
                const char *subjectOrigin = lm_GetSubjectOriginURL(cx);
                if (subjectOrigin == NULL) {
	            XP_FREE(protocol);
	            return NULL;
                }
                if (NET_URL_Type(subjectOrigin) != FILE_TYPE_URL &&
                    !lm_CanAccessTarget(cx, JSTARGET_UNIVERSAL_FILE_READ)) 
                {
                    XP_FREE(absolute);
                    absolute = NULL;
                }
            }
            break;
	  case FTP_TYPE_URL:
	  case GOPHER_TYPE_URL:
	  case HTTP_TYPE_URL:
	  case MAILTO_TYPE_URL:
	  case NEWS_TYPE_URL:
	  case RLOGIN_TYPE_URL:
	  case TELNET_TYPE_URL:
	  case TN3270_TYPE_URL:
	  case WAIS_TYPE_URL:
	  case SECURE_HTTP_TYPE_URL:
	  case URN_TYPE_URL:
	  case NFS_TYPE_URL:
	  case MOCHA_TYPE_URL:
	  case VIEW_SOURCE_TYPE_URL:
	  case NETHELP_TYPE_URL:
	  case WYSIWYG_TYPE_URL:
	  case LDAP_TYPE_URL:
#ifdef JAVA
	  case MARIMBA_TYPE_URL:
#endif
	    /* These are "safe". */
	    break;
	  case ABOUT_TYPE_URL:
	    if (XP_STRCASECMP(absolute, "about:blank") == 0)
		break;
	    if (XP_STRNCASECMP(absolute, "about:pics", 10) == 0)
		break;
	    /* these are OK if we are signed */
	    if (lm_CanAccessTarget(cx, JSTARGET_UNIVERSAL_BROWSER_READ))
		break;
	    /* FALL THROUGH */
	  default:
	    /* All others are naughty. */
	    XP_FREE(absolute);
	    absolute = NULL;
	    break;
	}
    }

    if (!absolute) {
	JS_ReportError(cx, "illegal URL method '%s'",
		       protocol && *protocol ? protocol : url_string);
    }
    if (protocol)
	XP_FREE(protocol);
    return absolute;
}
Esempio n. 10
0
url_setProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
    JSURL *url;
    const char *href, *name, *checked_href;
    char *new_href, *prop_name;
    JSBool free_href;
    jsval tmp;
    JSString *str;
    MWContext *context;
    LO_AnchorData *anchor_data;
    JSBool ok;
    jsint slot;

    url = JS_GetInstancePrivate(cx, obj, &lm_url_class, NULL);
    if (!url) {
	url = JS_GetInstancePrivate(cx, obj, &lm_location_class, NULL);
	if (!url)
	    return JS_TRUE;
    }

    /* If the property is setting an event handler we find out now so
     * that we can tell the front end to send the event.
     */
    if (JSVAL_IS_STRING(id)) {
	prop_name = JS_GetStringBytes(JSVAL_TO_STRING(id));
	if (XP_STRCASECMP(prop_name, lm_onClick_str) == 0 ||
	    XP_STRCASECMP(prop_name, lm_onMouseDown_str) == 0 ||
	    XP_STRCASECMP(prop_name, lm_onMouseOver_str) == 0 ||
	    XP_STRCASECMP(prop_name, lm_onMouseOut_str) == 0 ||
	    XP_STRCASECMP(prop_name, lm_onMouseUp_str) == 0) {
	    context = url->url_decoder->window_context;
	    if (context) {
		anchor_data = LO_GetLinkByIndex(context, url->layer_id,
						url->index);
		if (anchor_data)
		    anchor_data->event_handler_present = TRUE;
	    }
	}
	return JS_TRUE;
    }
	
    XP_ASSERT(JSVAL_IS_INT(id));
    slot = JSVAL_TO_INT(id);

    if (slot < 0) {
	/* Don't mess with user-defined or method properties. */
	return JS_TRUE;
    }

    if (!JSVAL_IS_STRING(*vp) &&
	!JS_ConvertValue(cx, *vp, JSTYPE_STRING, vp)) {
	return JS_FALSE;
    }

    ok = JS_TRUE;

    switch (slot) {
      case URL_HREF:
	url->href = JSVAL_TO_STRING(*vp);
	href = JS_GetStringBytes(url->href);
	free_href = JS_FALSE;
	break;

      case URL_PROTOCOL:
      case URL_HOST:
      case URL_HOSTNAME:
      case URL_PORT:
      case URL_PATHNAME:
      case URL_HASH:
      case URL_SEARCH:
	/* a component property changed -- recompute href. */
	new_href = NULL;

#define GET_SLOT(aslot, ptmp) {                                               \
    if (aslot == slot) {                                                      \
	*(ptmp) = *vp;                                                        \
    } else {                                                                  \
	if (!JS_GetElement(cx, obj, aslot, ptmp)) {                           \
	    if (new_href) XP_FREE(new_href);                                  \
	    return JS_FALSE;                                               \
	}                                                                     \
    }                                                                         \
}

#define ADD_SLOT(aslot, separator) {                                          \
    GET_SLOT(aslot, &tmp);                                                    \
    name = JS_GetStringBytes(JSVAL_TO_STRING(tmp));                           \
    if (*name) {                                                              \
	if (separator) StrAllocCat(new_href, separator);                      \
	StrAllocCat(new_href, name);                                          \
    }                                                                         \
}

	GET_SLOT(URL_PROTOCOL, &tmp);
	StrAllocCopy(new_href, JS_GetStringBytes(JSVAL_TO_STRING(tmp)));
	if (slot == URL_HOST) {
	    ADD_SLOT(URL_HOST, "//");
	} else {
	    ADD_SLOT(URL_HOSTNAME, "//");
	    ADD_SLOT(URL_PORT, ":");
	}
	ADD_SLOT(URL_PATHNAME, NULL);
	ADD_SLOT(URL_HASH, NULL);
	ADD_SLOT(URL_SEARCH, NULL);

	if (!new_href) {
	    JS_ReportOutOfMemory(cx);
	    return JS_FALSE;
	}

	free_href = JS_TRUE;
	href = new_href;
	str = JS_NewStringCopyZ(cx, href);
	if (!str) {
	    ok = JS_FALSE;
	    goto out;
	}
	url->href = str;
	break;

      case URL_TARGET:
	url->target = JSVAL_TO_STRING(*vp);
	if (url->index != URL_NOT_INDEXED) {
	    context = url->url_decoder->window_context;
	    if (context) {
		anchor_data = LO_GetLinkByIndex(context, url->layer_id,
                                                url->index);
		if (anchor_data) {
		    name = JS_GetStringBytes(url->target);
		    if (!lm_CheckWindowName(cx, name))
			return JS_FALSE;
		    if (!lm_SaveParamString(cx, &anchor_data->target, name))
			return JS_FALSE;
		}
	    }
	}
	/* Note early return, to bypass href update and freeing. */
	return JS_TRUE;

      default:
	/* Don't mess with a user-defined property. */
	return ok;
    }

    if (url->index != URL_NOT_INDEXED) {
	context = url->url_decoder->window_context;
	if (context) {
	    anchor_data = LO_GetLinkByIndex(context, url->layer_id, 
                                            url->index);
	    if (anchor_data) {
		checked_href = lm_CheckURL(cx, href, JS_FALSE);
		if (!checked_href ||
		    !lm_SaveParamString(cx, &anchor_data->anchor,
					checked_href)) {
		    ok = JS_FALSE;
		    goto out;
		}
		XP_FREE((char *)checked_href);
	    }
	}
    }

out:
    if (free_href && href)
	XP_FREE((char *)href);
    return ok;
}
Esempio n. 11
0
JSObject *
LM_ReflectEmbed(MWContext *context, LO_EmbedStruct *lo_embed,
                PA_Tag * tag, int32 layer_id, uint index)
{
    JSObject *obj, *array_obj, *outer_obj, *document;
    MochaDecoder *decoder;
    JSContext *cx;
    char *name;
    int i;

    obj = lo_embed->mocha_object;
    if (obj)
        return obj;

    decoder = LM_GetMochaDecoder(context);
    if (!decoder)
        return NULL;

    cx = decoder->js_context;

    /* get the name */
    name = 0;
    for (i = 0; i < lo_embed->attribute_cnt; i++) {
        if (!XP_STRCASECMP(lo_embed->attribute_list[i], "name")) {
            name = strdup(lo_embed->value_list[i]);
            break;
        }
    }

    /* Get the document object that will hold this applet */
    document = lm_GetDocumentFromLayerId(decoder, layer_id);
    if (!document) {
        LM_PutMochaDecoder(decoder);
        return NULL;
    }
    
    array_obj = lm_GetEmbedArray(decoder, document);
    if (!array_obj) {
        LM_PutMochaDecoder(decoder);
        return NULL;
    }

    /* XXX should pass thru ReallyReflectApplet to whatever calls NewObject */
    outer_obj = lm_GetOuterObject(decoder);

    /* this function does the real work */
    obj = lm_ReallyReflectEmbed(context, lo_embed, layer_id, index);

    if (!obj)
        goto out;

    /* put it in the embed array */
    if (!lm_AddObjectToArray(cx, array_obj, name, index, obj)) {
	obj = NULL;
	goto out;
    }

    /* put it in the document scope */
    if (name && !JS_DefineProperty(cx, outer_obj, name, OBJECT_TO_JSVAL(obj),
				   NULL, NULL,
				   JSPROP_ENUMERATE | JSPROP_READONLY)) {
	PR_LOG(Moja, warn, ("failed to define embed 0x%x as %s\n",
			    lo_embed, name));
	/* XXX remove it altogether? */
    }

    /* cache it in layout data structure */
    lo_embed->mocha_object = obj;

out:
    LM_PutMochaDecoder(decoder);
    return obj;
}
Esempio n. 12
0
static char *
fe_server_handle_command (Display *dpy, Window window, XEvent *event,
			  char *command)
{
	char *name = 0;
	char **av = 0;
	int ac = 0;
	int avsize = 0;
	Boolean raise_p = True;
	int i;
	char *buf;
	char *buf2;
	int32 buf2_size;
	char *head, *tail;
	XtActionProc action = 0;
	Widget widget = XtWindowToWidget (dpy, window);
	MWContext *context = fe_WidgetToMWContext (widget);
	XP_Bool mail_or_news_required = FALSE;
	MWContextType required_type = (MWContextType) (~0);
	XP_Bool make_context_if_necessary = FALSE;
    MWContext *target_context = context;

	XP_ASSERT(context);

	buf = fe_StringTrim (strdup (command));
	buf2_size = strlen (buf) + 200;
	buf2 = (char *) malloc (buf2_size);

	head = buf;
	tail = buf;

	if (! widget)
		{
			PR_snprintf (buf2, buf2_size,
						 XP_GetString(XFE_REMOTE_S_509_INTERNAL_ERROR),
						 (unsigned int) window);
			free (buf);
			return buf2;
		}

	/* extract the name (everything before the first '(', trimmed.) */
	while (1)
		if (*tail == '(' || isspace (*tail) || !*tail)
			{
				*tail = 0;
				tail++;
				name = fe_StringTrim (head);
				break;
			}
		else
			tail++;

	if (!name || !*name)
		{
			PR_snprintf (buf2, buf2_size,
						 XP_GetString(XFE_REMOTE_S_500_UNPARSABLE_COMMAND), 
						 command);
			free (buf);
			return buf2;
		}

	/* look for it in the old remote actions. */
	for (i = 0; i < fe_CommandActionsSize; i++)
		if (!XP_STRCASECMP(name, fe_CommandActions [i].string))
			{
				name = fe_CommandActions [i].string;
				action = fe_CommandActions [i].proc;
				break;
			}

	if (!av)
		{
			avsize = 20;
			av = (char **) calloc (avsize, sizeof (char *));

			/* if it's not an old action, we need to know the name of the
			   command, so we stick it on the front.  This will be dealt
			   with in xfeDoRemoteCommand. */
			if (!action)
				av[ ac++ ] = name;

			while (*tail == '(' || isspace (*tail))
				tail++;

			head = tail;
			while (1)
				{
					if (*tail == ')' || *tail == ',' || *tail == 0)
						{
							char delim = *tail;
							if (ac >= (avsize - 2))
								{
									avsize += 20;
									av = (char **) realloc (av, avsize * sizeof (char *));
								}
							*tail = 0;

							av [ac++] = fe_StringTrim (head);

							if (delim != ',' && !*av[ac-1])
								ac--;
							else if (!strcasecomp (av [ac-1], "noraise"))
								{
									raise_p = False;
									ac--;
								}
							else if (!strcasecomp (av [ac-1], "raise"))
								{
									raise_p = True;
									ac--;
								}

							head = tail+1;
							if (delim != ',')
								break;
						}
					tail++;
				}

			av [ac++] = "<remote>";
		}

	/* If this is GetURL or something like it, make sure the context we pick
	   matches the URL.
	   */
	if (strstr(name, "URL"))
		{
			const char *url = av[0];
			mail_or_news_required = FALSE;
			required_type = (MWContextType) (~0);
#ifdef MOZ_MAIL_NEWS
			if (MSG_RequiresMailWindow (url))
				required_type = MWContextMail;
			else if (MSG_RequiresNewsWindow (url))
				required_type = MWContextNews;
			else if (MSG_RequiresBrowserWindow (url))
#endif
				required_type = MWContextBrowser;
			/* Nothing to do for MSG_RequiresComposeWindow compose. */

			if (required_type != (MWContextType) (~0))
				{
					make_context_if_necessary = TRUE;
				}
		}
    else if (!strcasecomp(name, "openfile"))
      {
        required_type = MWContextBrowser;
        make_context_if_necessary = TRUE;
      }

	if (raise_p)
		XMapRaised (dpy, window);

    if (required_type != (MWContextType) (~0))
      target_context = XP_FindContextOfType(context, required_type);
			
    if (make_context_if_necessary && !target_context)
      target_context = FE_MakeNewWindow(context, NULL, NULL, NULL);

    if (target_context) 
      {
        Cardinal ac2 = ac; /* why is this passed as a pointer??? */
        if (name && action)
          {
            (*action) (CONTEXT_WIDGET(target_context), event, av, &ac2);
          }
        else
          /* now we call our new xfe2 interface to the command mechanism */
          {
            xfeDoRemoteCommand (CONTEXT_WIDGET(target_context),
                                event, av, &ac2);
          }
      }

	PR_snprintf (buf2, buf2_size,
				 XP_GetString(XFE_REMOTE_S_200_EXECUTED_COMMAND),
				 name);
	for (i = 0; i < ac-1; i++)
		{
			strcat (buf2, av [i]);
			if (i < ac-2)
				strcat (buf2, ", ");
		}
	strcat (buf2, ")");

	free (av);

	free (buf);
	return buf2;
}
Esempio n. 13
0
/* returns a unmalloced static string
 * that is only available for temporary use.
 */
PUBLIC char *
xp_FileName (const char *name, XP_FileType type, char* buf, char* configBuf)
{
    const char *conf_dir = xp_unix_config_directory(configBuf);

    switch (type)
    {
    case xpSARCacheIndex:
    {
        const char *sar_cache_dir = FE_SARCacheDir;
        if (!sar_cache_dir || !*sar_cache_dir)
            sar_cache_dir = conf_dir;
        if (sar_cache_dir [strlen (sar_cache_dir) - 1] == '/')
            sprintf (buf, "%.900sarchive.fat", sar_cache_dir);
        else
            sprintf (buf, "%.900s/archive.fat", sar_cache_dir);

        name = buf;
        break;
    }
    case xpSARCache:
    {
        /* WH_TempName() returns relative pathnames for the cache files,
           so that relative paths get written into the cacheFAT database.
           WH_FileName() converts them to absolute if they aren't already
           so that the logic of XP_FileOpen() and XP_FileRename() and who
           knows what else is simpler.
         */
        if (name != NULL && *name == '/')
            break ;

        {
            char *tmp = FE_SARCacheDir;
            if (!tmp || !*tmp) tmp = "/tmp";
            if (tmp [strlen (tmp) - 1] == '/')
                sprintf (buf, "%.500s%.500s", tmp, name);
            else
                sprintf (buf, "%.500s/%.500s", tmp, name);
            name = buf;
        }
        break;
    }
    case xpCacheFAT:
    {
        const char *cache_dir = FE_CacheDir;
        if (!cache_dir || !*cache_dir)
            cache_dir = conf_dir;
        if (cache_dir [strlen (cache_dir) - 1] == '/')
            sprintf (buf, "%.900sindex.db", cache_dir);
        else
            sprintf (buf, "%.900s/index.db", cache_dir);

        name = buf;
        break;
    }
    case xpCache:
    {
        /* WH_TempName() returns relative pathnames for the cache files,
           so that relative paths get written into the cacheFAT database.
           WH_FileName() converts them to absolute if they aren't already
           so that the logic of XP_FileOpen() and XP_FileRename() and who
           knows what else is simpler.
         */
        if (*name != '/')
        {
            char *tmp = FE_CacheDir;
            if (!tmp || !*tmp) tmp = "/tmp";
            if (tmp [strlen (tmp) - 1] == '/')
                sprintf (buf, "%.500s%.500s", tmp, name);
            else
                sprintf (buf, "%.500s/%.500s", tmp, name);
            name = buf;
        }
        break;
    }

    case xpHTTPCookie:
    {
#ifndef OLD_UNIX_FILES
        sprintf (buf, "%.900s/cookies", conf_dir);
#else  /* OLD_UNIX_FILES */
        sprintf (buf, "%.900s/.netscape-cookies", conf_dir);
#endif /* OLD_UNIX_FILES */
        name = buf;
        break;
    }
    case xpRegistry:
    {
        if ( name == NULL || *name == '\0' ) {
#ifndef OLD_UNIX_FILES
            sprintf (buf, "%.900s/registry", conf_dir);
#else  /* OLD_UNIX_FILES */
            sprintf (buf, "%.900s/.netscape-registry", conf_dir);
#endif /* OLD_UNIX_FILES */
            name = buf;
        }
        else {
            XP_ASSERT( name[0] == '/' );
        }
        break;
    }
    case xpProxyConfig:
    {
        sprintf(buf, "%.900s/proxyconf", conf_dir);
        name = buf;
        break;
    }
    case xpTemporary:
    {
        if (*name != '/')
        {
            char *tmp = FE_TempDir;
            if (!tmp || !*tmp) tmp = "/tmp";
            if (tmp [strlen (tmp) - 1] == '/')
                sprintf (buf, "%.500s%.500s", tmp, name);
            else
                sprintf (buf, "%.500s/%.500s", tmp, name);
            name = buf;
        }
        break;
    }
    case xpNewsRC:
    case xpSNewsRC:
    case xpTemporaryNewsRC:
    {
        /* In this case, `name' is "" or "host" or "host:port". */

        char *home = getenv ("HOME");
        const char *newsrc_dir = ((FE_UserNewsRC && *FE_UserNewsRC)
                                  ? FE_UserNewsRC
                                  : (home ? home : ""));
        const char *basename = (type == xpSNewsRC ? ".snewsrc" : ".newsrc");
        const char *suffix = (type == xpTemporaryNewsRC ? ".tmp" : "");
        if (*name)
            sprintf (buf, "%.800s%.1s%.8s-%.128s%.4s",
                     newsrc_dir,
                     (newsrc_dir[XP_STRLEN(newsrc_dir)-1] == '/' ? "" : "/"),
                     basename, name, suffix);
        else
            sprintf (buf, "%.800s%.1s%.128s%.4s",
                     newsrc_dir,
                     (newsrc_dir[XP_STRLEN(newsrc_dir)-1] == '/' ? "" : "/"),
                     basename, suffix);

        name = buf;
        break;
    }
    case xpNewsgroups:
    case xpSNewsgroups:
    {
#ifndef OLD_UNIX_FILES
        sprintf (buf, "%.800s/%snewsgroups-%.128s",
                 conf_dir,
                 type == xpSNewsgroups ? "s" : "",
                 name);
#else  /* OLD_UNIX_FILES */
        sprintf (buf, "%.800s/.netscape-%snewsgroups-%.128s",
                 conf_dir,
                 type == xpSNewsgroups ? "s" : "",
                 name);
#endif /* OLD_UNIX_FILES */
        name = buf;
        break;
    }

    case xpExtCacheIndex:
#ifndef OLD_UNIX_FILES
        sprintf (buf, "%.900s/cachelist", conf_dir);
#else  /* OLD_UNIX_FILES */
        sprintf (buf, "%.900s/.netscape-cache-list", conf_dir);
#endif /* OLD_UNIX_FILES */
        name = buf;
        break;

    case xpGlobalHistory:
        name = FE_GlobalHist;
        break;

    case xpCertDB:
#ifndef OLD_UNIX_FILES
        if ( name ) {
            sprintf (buf, "%.900s/cert%s.db", conf_dir, name);
        } else {
            sprintf (buf, "%.900s/cert.db", conf_dir);
        }
#else  /* OLD_UNIX_FILES */
        sprintf (buf, "%.900s/.netscape-certdb", conf_dir);
#endif /* OLD_UNIX_FILES */
        name = buf;
        break;
    case xpCertDBNameIDX:
#ifndef OLD_UNIX_FILES
        sprintf (buf, "%.900s/cert-nameidx.db", conf_dir);
#else  /* OLD_UNIX_FILES */
        sprintf (buf, "%.900s/.netscape-certdb-nameidx", conf_dir);
#endif /* OLD_UNIX_FILES */
        name = buf;
        break;
    case xpKeyDB:
#ifndef OLD_UNIX_FILES
        if ( name ) {
            sprintf (buf, "%.900s/key%s.db", conf_dir, name);
        } else {
            sprintf (buf, "%.900s/key.db", conf_dir);
        }
#else  /* OLD_UNIX_FILES */
        sprintf (buf, "%.900s/.netscape-keydb", conf_dir);
#endif /* OLD_UNIX_FILES */
        name = buf;
        break;
    case xpSecModuleDB:
        sprintf (buf, "%.900s/secmodule.db", conf_dir);
        name = buf;
        break;

    case xpSignedAppletDB:
    {
#ifndef OLD_UNIX_FILES
        if ( name ) {
            sprintf (buf, "%.900s/signedapplet%s.db", conf_dir, name);
        } else {
            sprintf (buf, "%.900s./signedapplet.db", conf_dir);
        }
#else  /* OLD_UNIX_FILES */
        sprintf (buf, "%.900s/.netscape-signedappletdb", conf_dir);
#endif /* OLD_UNIX_FILES */
        name = buf;
        break;
    }

    case xpFileToPost:
    case xpSignature:
        /* These are always absolute pathnames.
         * BUT, the user can type in whatever so
         * we can't assert if it doesn't begin
         * with a slash
         */
        break;

    case xpExtCache:
    case xpKeyChain:
    case xpURL:
    case xpHotlist:
    case xpBookmarks:
    case xpMimeTypes:
    case xpSocksConfig:
    case xpMailFolder:
#ifdef BSDI
        /* In bsdi, mkdir fails if the directory name is terminated
         * with a '/'. - dp
         */
        if (name[strlen(name)-1] == '/') {
            strcpy(buf, name);
            buf[strlen(buf)-1] = '\0';
            name = buf;
        }
#endif
#ifndef MCC_PROXY
        /*
         * These are always absolute pathnames for the Navigator.
         * Only the proxy (servers) may have pathnames relative
         * to their current working directory (the servers chdir
         * to their admin/config directory on startup.
         *
         */
        if (name) XP_ASSERT (name[0] == '/');
#endif	/* ! MCC_PROXY */

        break;

    case xpMailFolderSummary:
        /* Convert /a/b/c/foo to /a/b/c/.foo.summary (note leading dot) */
    {
        const char *slash;
        slash = strrchr (name, '/');
        if (name) XP_ASSERT (name[0] == '/');
        XP_ASSERT (slash);
        if (!slash) return 0;
        XP_MEMCPY (buf, name, slash - name + 1);
        buf [slash - name + 1] = '.';
        XP_STRCPY (buf + (slash - name) + 2, slash + 1);
        XP_STRCAT (buf, ".summary");
        name = buf;
        break;
    }

    case xpAddrBookNew:
        /* Convert foo.db to /a/b/c/foo.db */
    {
        if ( name ) {
            sprintf (buf, "%.900s/%s", conf_dir, name);
        } else {
            sprintf (buf, "%.900s/abook.nab", conf_dir);
        }
#if defined(DEBUG_tao)
        printf("\n  xpAddrBookNew, xp_FileName, buf=%s\n", buf);
#endif
        name = buf;

        break;
    }

    case xpAddrBook:
        /* Convert /a/b/c/foo to /a/b/c/foo.db (note leading dot) */
    {
        /* Tao_27jan97
         */
        char *dot = NULL;
        int len = 0;
        const char *base = NULL;

        if (name)
            XP_ASSERT (name[0] == '/');

        dot = XP_STRRCHR(name, '.');
        if (dot) {

            len = dot - name + 1;
            XP_STRNCPY_SAFE(buf, name, len);
        }/* if */

        XP_STRCAT (buf, ".nab");


        /* Tao_02jun97 don't convert addrbook.db
         * reuse len, dot
         */
        base = XP_STRRCHR(name, '/');
        if (base && *base == '/')
            base++;

#if defined(DEBUG_tao)
        printf("\n++++  xpAddrBook, before xp_FileName=%s\n", name);
#endif

        if (!base || XP_STRCMP(base, "addrbook.db"))
            /* not old addrbook.db file
             */
            name = buf;
#if defined(DEBUG_tao)
        printf("\n  xpAddrBook, xp_FileName=%s\n", name);
#endif
        break;
    }

    case xpVCardFile:
        /* Convert /a/b/c/foo to /a/b/c/foo.vcf (note leading dot) */
    {
#if 1
        /* Tao_27jan97
         */
        char *dot = NULL;
        int len = 0;

        if (name)
            XP_ASSERT (name[0] == '/');

        dot = XP_STRRCHR(name, '.');
        if (dot) {
            len = dot - name + 1;
            XP_STRNCPY_SAFE(buf, name, len);
        }/* if */

        XP_STRCAT (buf, ".vcf");
        name = buf;
#if defined(DEBUG_tao_)
        printf("\n  xp_FileName=%s\n", name);
#endif
#else
        const char *slash;
        slash = strrchr (name, '/');
        if (name) XP_ASSERT (name[0] == '/');
        XP_ASSERT (slash);
        if (!slash) return 0;
        XP_MEMCPY (buf, name, slash - name + 1);
        XP_STRCAT (buf, ".vcf");
        name = buf;
#endif
        break;
    }

    case xpLDIFFile:
        /* Convert /a/b/c/foo to /a/b/c/foo.ldif (note leading dot) */
    {
#if 1
        /* Tao_27jan97
         */
        char *dot = NULL;
        int len = 0;

        if (name)
            XP_ASSERT (name[0] == '/');

        dot = XP_STRRCHR(name, '.');
        if (dot) {
            len = dot - name + 1;
            XP_STRNCPY_SAFE(buf, name, len);
        }/* if */

        XP_STRCAT (buf, ".ldif");
        name = buf;
#if defined(DEBUG_tao_)
        printf("\n  xp_FileName=%s\n", name);
#endif

#else
        const char *slash;
        slash = strrchr (name, '/');
        if (name) XP_ASSERT (name[0] == '/');
        XP_ASSERT (slash);
        if (!slash) return 0;
        XP_MEMCPY (buf, name, slash - name + 1);
        XP_STRCAT (buf, ".ldif");
        name = buf;
#endif
        break;
    }

    case xpJSMailFilters:
        sprintf(buf, "%.900s/filters.js", conf_dir);
        name = buf;
        break;

    case xpJSHTMLFilters:
        sprintf(buf, "%.900s/hook.js", conf_dir);
        name = buf;
        break;

    case xpNewsSort:
        sprintf(buf, "%.800s/xover-cache/%.128snetscape-newsrule", conf_dir, name);
        break;
    case xpMailSort:
#ifndef OLD_UNIX_FILES
        sprintf(buf, "%.900s/mailrule", conf_dir);
#else  /* OLD_UNIX_FILES */
        sprintf(buf, "%.900s/.netscape-mailrule", conf_dir);
#endif /* OLD_UNIX_FILES */
        name = buf;
        break;
    case xpMailPopState:
#ifndef OLD_UNIX_FILES
        sprintf(buf, "%.900s/popstate", conf_dir);
#else  /* OLD_UNIX_FILES */
        sprintf(buf, "%.900s/.netscape-popstate", conf_dir);
#endif /* OLD_UNIX_FILES */
        name = buf;
        break;
    case xpMailFilterLog:
        sprintf(buf, "%.900s/.netscape-mailfilterlog", conf_dir);
        name = buf;
        break;
    case xpNewsFilterLog:
        sprintf(buf, "%.900s/.netscape-newsfilterlog", conf_dir);
        name = buf;
        break;
    case xpMailSubdirectory:
    {
        char * pEnd = strrchr(name, '/');
        strcpy(buf, name);

        /* strip off the extension */
        if(!pEnd)
            pEnd = buf;

        pEnd = strchr(pEnd, '.');
        if(pEnd)
            *pEnd = '\0';
        strcat(buf, ".sbd/");
        name = buf;
    }
    break;
    case xpXoverCache:
        sprintf(buf, "%.800s/xover-cache/%.128s", conf_dir, name);
        name = buf;
        break;

    case xpNewsHostDatabase:
        sprintf(buf, "%.800s/newsdb", conf_dir);
        name = buf;
        break;

    case xpImapRootDirectory:
    {
        char prefbuf[1024];
        int len = sizeof prefbuf / sizeof *prefbuf;
        if ((PREF_GetCharPref("mail.imap.root_dir",
                              prefbuf, &len) == PREF_NOERROR)
                && *prefbuf == '/')
            /* guard against assert: line 806, file xp_file.c */
            XP_STRNCPY_SAFE(buf, prefbuf, len);
        /* Copy back to the buffer that was passed in.
         * We couldn't have PREF_GetCharPref() just put it there
         * initially because the size of buf wasn't passed in
         * (it happens to be 1024) and PREF_GetCharPref() insists
         * on having a size. Sigh.
         */
        else
        {
            char *home = getenv ("HOME");
            sprintf(buf, "%s/ns_imap", (home ? home : ""));
        }
        name = buf;
        break;
    }

    case xpImapServerDirectory:
    {
        char prefbuf[1024];
        int len = sizeof prefbuf / sizeof *prefbuf;
        if ((PREF_GetCharPref("mail.imap.root_dir",
                              prefbuf, &len) == PREF_NOERROR)
                && *prefbuf == '/')
            /* guard against assert: line 806, file xp_file.c */
            sprintf(buf, "%s/%s", prefbuf, name);
        else
        {
            char *home = getenv ("HOME");
            sprintf(buf, "%s/ns_imap/%s", (home ? home : ""), name);
        }
        name = buf;
        break;
    }

    case xpFolderCache:
        sprintf (buf, "%s/summary.dat", conf_dir);
        name = buf;
        break;

    case xpCryptoPolicy:
    {
        extern void fe_GetProgramDirectory(char *path, int len);
        char *policyFN = "moz40p3";
        char *mozHome  = getenv("MOZILLA_HOME");
        char *lang     = getenv("LANG");
        int   result;
        char  dirName[1024];

        name = buf;
        if (!xp_unix_sprintf_stat(buf, conf_dir, lang, policyFN))
            break;
        if (!xp_unix_sprintf_stat(buf, mozHome, lang, policyFN))
            break;
        fe_GetProgramDirectory(dirName, sizeof dirName);
        if (!xp_unix_sprintf_stat(buf, dirName, lang, policyFN))
            break;

        /* couldn't find it, but must leave a valid file name in buf */
        sprintf(buf, "%.900s/%s", conf_dir, policyFN);
        break;
    }

    case xpPKCS12File:
        /* Convert /a/b/c/foo to /a/b/c/foo.p12 (note leading dot) */
    {
        int len = 0;

        if(name) {
            XP_ASSERT(name[0] == '/');

            /* only append if there is enough space in the buffer */
            /* this should be changed if the size of the buf changes */
            if((XP_STRLEN(name) + 4) <= 1020) {

                /* include NULL in length */
                len = XP_STRLEN(name) + 1;
                XP_STRNCPY_SAFE(buf, name, len);

                /* we want to concatenate ".p12" if it is not the
                 * last 4 characters of the name already.
                 * If len is less than 5 (including the terminating
                 * NULL), it is not ".p12".
                 * If the len is > 5 it may have the .p12, so we want
                 * to check and only append .p12 if the name
                 * specified does not end in .p12.
                 * only side effect -- this allows for the filename
                 * ".p12" which is fine.
                 */
                if((len >= 5) && XP_STRCASECMP(&(name[len-4-1]), ".p12")) {
                    XP_STRCAT(buf, ".p12");
                } else if(len < 5) {
                    /* can't be ".p12", so we append ".p12" */
                    XP_STRCAT(buf, ".p12");
                }
                name = buf;
            }
        }

        break;
    }

    case xpJSCookieFilters:
    {
        sprintf(buf, "%.900s/cookies.js", conf_dir);
        name = buf;
        break;
    }

    case xpLIPrefs:
    {
        sprintf(buf, "%.900s/liprefs.js", conf_dir);
        name = buf;
        break;
    }

    default:
        abort ();
    }

    return (char *) name;
}
Esempio n. 14
0
/* Pseudo-elements as well as property names are converted by this. */
static void ConvertProperty(const char * css1_property, StyleBuffer sb, 
                            int * property_type_return)
{
    XP_Bool upper;
    char ch[2];
    int32 pseudo_class;

    ch[1] = '\0';

    if (property_type_return)
        *property_type_return = CSS_PROPERTY_TYPE_ASSIGNMENT;

    /* The CSS1 float property is translated to align because float is
     * a reserved word in JavaScript.
     */
    if (0 == XP_STRCASECMP(css1_property, "float"))
        StyleBufferWrite("align", 5, sb);
    else {
        if (property_type_return) {
            if (   (0 == XP_STRCASECMP(css1_property, "margin"))
                || (0 == XP_STRCASECMP(css1_property, "padding"))
                || (0 == XP_STRCASECMP(css1_property, "border-width")))
                *property_type_return = CSS_PROPERTY_TYPE_CALL;
        }

        pseudo_class = GetPseudoClass(sb);

        if (0 == XP_STRCASECMP(css1_property, "margin"))
            StyleBufferWrite("margins", 7, sb);
        else if (0 == XP_STRCASECMP(css1_property, "padding"))
            StyleBufferWrite("paddings", 8, sb);
        else if (0 == XP_STRCASECMP(css1_property, "border-width"))
            StyleBufferWrite("borderWidths", 12, sb);
        else if ((CSS_PSEUDO_CLASS_NONE != pseudo_class)
                 && (0 == XP_STRCASECMP(css1_property, "color"))) {
            switch (pseudo_class) {
            case CSS_PSEUDO_CLASS_LINK:
            default:
                StyleBufferWrite("linkColor", 9, sb);
                break;
            case CSS_PSEUDO_CLASS_ACTIVE:
                StyleBufferWrite("activeColor", 11, sb);
                break;
            case CSS_PSEUDO_CLASS_VISITED:
                StyleBufferWrite("visitedColor", 12, sb);
                break;
            }
        }
        else {
            for (upper=0; *css1_property; css1_property++) {

                if (*css1_property == '-') {
                    upper = 1;
                    continue;
                }
       
                ch[0] = (upper ? toupper(*css1_property)
                         : tolower(*css1_property));
                upper = 0;
                StyleBufferWrite(ch, 1, sb);
            }
        }
    }
}