コード例 #1
0
// create short icon label from full path/url
char *XFE_ComposeAttachFolderView::parseItemLabel(const char *url)
{
    // (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

    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 (!strncasecomp (url, "news:", 5))
        return XP_STRDUP("news:");
    if (!strncasecomp (url, "snews:", 6))
        return XP_STRDUP("snews:");    
    if (!strncasecomp (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 \ */
    s2 = XP_STRRCHR (s, '/');
    if (s2) s = s2+1;
    s2 = XP_STRRCHR (s, '\\');
    if (s2) s = s2+1;

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

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

    char *retLabel=XP_STRDUP(s);
    XP_FREE(tmpLabel);
    
    return retLabel;
}
コード例 #2
0
/* string in place */
char *
unescapeURL(char *inURL)
{
	char *escapedPath = copyString(inURL);

#ifdef XP_WIN
	replacePipeWithColon(escapedPath);
#endif

	NET_UnEscape(escapedPath);
	return (escapedPath);
}
コード例 #3
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;
}
コード例 #4
0
PUBLIC int
NET_ParseNetHelpURL(URL_Struct *URL_s)
{
	/* this is a nethelp: URL
	 * first, see if it's local or remote by checking for the @ 
	 */
	char *remote_addr_ptr = 0;
	char *remote_addr=0;
	char *topic_ptr = 0;
	char *topic = 0;
	char *scheme_specific = 0;
	char *pCharacter;

	XP_Bool appendProjFile = FALSE;
	
	remote_addr_ptr = XP_STRCHR(URL_s->address, '@');
	
	if (!remote_addr_ptr) {
		char *default_URL = 0;

		/* it's local, so we need to get the default, then append the project file */
		net_get_default_help_URL(&default_URL);
		
		if (default_URL) {
			StrAllocCopy(remote_addr, default_URL);
			XP_FREE(default_URL);
		}
		
		appendProjFile = TRUE;
		
	} else {
		*remote_addr_ptr = '\0';
		
		StrAllocCopy(remote_addr, remote_addr_ptr+1);

		if (remote_addr && (remote_addr[XP_STRLEN(remote_addr)] == '/')) {
		/* Check to see if the remote_addr ends in a slash.  If so, we
		   have some appending to do */

			appendProjFile = TRUE;
		}
	}

	if (!remote_addr) {
		/* We've obviously run into some kind of a memory problem here. */
		/* Time to bail */
		return MK_OUT_OF_MEMORY;
	}

	/* By now, the URL_s->address has been stripped of any location information */
	/* First, remove the scheme, which is guaranteed to be there. */
	
	scheme_specific = XP_STRCHR(URL_s->address, ':') + 1;
	
	topic_ptr = XP_STRCHR(scheme_specific, ':');
	
	if (!topic_ptr) {
		/* This is an error case, but we'll handle it anyway by defaulting to
		   the generic topic */
		   
		StrAllocCopy(topic, DEFAULT_HELP_ID);
	} else {
		*topic_ptr = '\0';
		StrAllocCopy(topic, topic_ptr+1);

	}		
	
	if (appendProjFile) {
		/* Now the URL_s->address will contain only the vendor/component information */
		
		/* In an act of incredible lameness, we want to lowercase the
		   vendor/component, since we say that these will default to 
		   lower case in the spec.
		   
		   FIXME!: Note that this may not be correct for double-byte encoded
		   characters, but the Intl team was unable to come up with a good
		   solution here; in general, we probably won't have any issue, since
		   URLs themselves should be in an ASCII-encoding (?).
		*/

		pCharacter = scheme_specific;

		while (*pCharacter)
		{
			*pCharacter = (char) XP_TO_LOWER((unsigned int) *pCharacter);
			pCharacter++;
		}

		
		StrAllocCat(remote_addr, scheme_specific);
		StrAllocCat(remote_addr, DEFAULT_HELP_PROJECT);
	}
	
	FREE(URL_s->address);
	URL_s->address = remote_addr;
	
	/* If there is no topic, then we'll still attempt to load the project file and
	   its window.  The other code below should detect the non-existence of a topic and
	   either revert to a default or do some other elegant solution. */
	   
	if (topic) {
		NET_UnEscape(topic);
		URL_s->fe_data = XP_STRDUP(topic);
	} else {
		URL_s->fe_data = NULL;
	}
	
	FREEIF(topic);
	
	return MK_DATA_LOADED;
}