This commit is contained in:
rhp%netscape.com 1999-06-25 00:10:13 +00:00
Родитель a2036a841e
Коммит 962a89d0a8
3 изменённых файлов: 225 добавлений и 58 удалений

Просмотреть файл

@ -1,58 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/********************************************************************************************************
Wrapper class for various parsing URL parsing routines...
*********************************************************************************************************/
#ifndef _nsIMimeURLUtils_h__
#define _nsIMimeURLUtils_h__
#include "nsISupports.h"
// {9C4DA768-07EB-11d3-8EE5-00A024669799}
#define NS_IMIME_URLUTILS_IID \
{ 0x9c4da768, 0x7eb, 0x11d3, \
{ 0x8e, 0xe5, 0x0, 0xa0, 0x24, 0x66, 0x97, 0x99 } }
// {9C4DA772-07EB-11d3-8EE5-00A024669799}
#define NS_IMIME_URLUTILS_CID \
{ 0x9c4da772, 0x7eb, 0x11d3, \
{ 0x8e, 0xe5, 0x0, 0xa0, 0x24, 0x66, 0x97, 0x99 } }
class nsIMimeURLUtils : public nsISupports {
public:
static const nsIID& GetIID(void) { static nsIID iid = NS_IMIME_URLUTILS_IID; return iid; }
NS_IMETHOD URLType(const char *URL, PRInt32 *retType) = 0;
NS_IMETHOD ReduceURL (char *url, char **retURL) = 0;
NS_IMETHOD ScanForURLs(const char *input, int32 input_size,
char *output, int output_size, PRBool urls_only) = 0;
NS_IMETHOD MakeAbsoluteURL(char * absolute_url, char * relative_url, char **retURL) = 0;
NS_IMETHOD ScanHTMLForURLs(const char* input, char **retBuf) = 0;
};
#endif /* _nsIMimeURLUtils_h__ */

Просмотреть файл

@ -1295,3 +1295,226 @@ FAIL:
return NS_OK;
}
//
// Also skip '>' as part of host name
//
nsresult
nsMimeURLUtils::ParseURL(const char *url, int parts_requested, char **returnVal)
{
char *rv=0,*colon, *slash, *ques_mark, *hash_mark;
char *atSign, *host, *passwordColon, *gtThan;
assert(url);
if(!url)
{
*returnVal = mime_SACat(&rv, "");
return NS_ERROR_FAILURE;
}
colon = PL_strchr(url, ':'); /* returns a const char */
/* Get the protocol part, not including anything beyond the colon */
if (parts_requested & GET_PROTOCOL_PART) {
if(colon) {
char val = *(colon+1);
*(colon+1) = '\0';
mime_SACopy(&rv, url);
*(colon+1) = val;
/* If the user wants more url info, tack on extra slashes. */
if( (parts_requested & GET_HOST_PART)
|| (parts_requested & GET_USERNAME_PART)
|| (parts_requested & GET_PASSWORD_PART)
)
{
if( *(colon+1) == '/' && *(colon+2) == '/')
mime_SACat(&rv, "//");
/* If there's a third slash consider it file:/// and tack on the last slash. */
if( *(colon+3) == '/' )
mime_SACat(&rv, "/");
}
}
}
/* Get the username if one exists */
if (parts_requested & GET_USERNAME_PART) {
if (colon
&& (*(colon+1) == '/')
&& (*(colon+2) == '/')
&& (*(colon+3) != '\0')) {
if ( (slash = PL_strchr(colon+3, '/')) != NULL)
*slash = '\0';
if ( (atSign = PL_strchr(colon+3, '@')) != NULL) {
*atSign = '\0';
if ( (passwordColon = PL_strchr(colon+3, ':')) != NULL)
*passwordColon = '\0';
mime_SACat(&rv, colon+3);
/* Get the password if one exists */
if (parts_requested & GET_PASSWORD_PART) {
if (passwordColon) {
mime_SACat(&rv, ":");
mime_SACat(&rv, passwordColon+1);
}
}
if (parts_requested & GET_HOST_PART)
mime_SACat(&rv, "@");
if (passwordColon)
*passwordColon = ':';
*atSign = '@';
}
if (slash)
*slash = '/';
}
}
/* Get the host part */
if (parts_requested & GET_HOST_PART) {
if(colon) {
if(*(colon+1) == '/' && *(colon+2) == '/')
{
slash = PL_strchr(colon+3, '/');
if(slash)
*slash = '\0';
if( (atSign = PL_strchr(colon+3, '@')) != NULL)
host = atSign+1;
else
host = colon+3;
ques_mark = PL_strchr(host, '?');
if(ques_mark)
*ques_mark = '\0';
gtThan = PL_strchr(host, '>');
if (gtThan)
*gtThan = '\0';
/*
* Protect systems whose header files forgot to let the client know when
* gethostbyname would trash their stack.
*/
#ifndef MAXHOSTNAMELEN
#ifdef XP_OS2
#error Managed to get into NET_ParseURL without defining MAXHOSTNAMELEN !!!
#endif
#define MAXHOSTNAMELEN 256
#endif
/* limit hostnames to within MAXHOSTNAMELEN characters to keep
* from crashing
*/
if(PL_strlen(host) > MAXHOSTNAMELEN)
{
char * cp;
char old_char;
cp = host+MAXHOSTNAMELEN;
old_char = *cp;
*cp = '\0';
mime_SACat(&rv, host);
*cp = old_char;
}
else
{
mime_SACat(&rv, host);
}
if(slash)
*slash = '/';
if(ques_mark)
*ques_mark = '?';
if (gtThan)
*gtThan = '>';
}
}
}
/* Get the path part */
if (parts_requested & GET_PATH_PART) {
if(colon) {
if(*(colon+1) == '/' && *(colon+2) == '/')
{
/* skip host part */
slash = PL_strchr(colon+3, '/');
}
else
{
/* path is right after the colon
*/
slash = colon+1;
}
if(slash)
{
ques_mark = PL_strchr(slash, '?');
hash_mark = PL_strchr(slash, '#');
if(ques_mark)
*ques_mark = '\0';
if(hash_mark)
*hash_mark = '\0';
mime_SACat(&rv, slash);
if(ques_mark)
*ques_mark = '?';
if(hash_mark)
*hash_mark = '#';
}
}
}
if(parts_requested & GET_HASH_PART) {
hash_mark = PL_strchr(url, '#'); /* returns a const char * */
if(hash_mark)
{
ques_mark = PL_strchr(hash_mark, '?');
if(ques_mark)
*ques_mark = '\0';
mime_SACat(&rv, hash_mark);
if(ques_mark)
*ques_mark = '?';
}
}
if(parts_requested & GET_SEARCH_PART) {
ques_mark = PL_strchr(url, '?'); /* returns a const char * */
if(ques_mark)
{
hash_mark = PL_strchr(ques_mark, '#');
if(hash_mark)
*hash_mark = '\0';
mime_SACat(&rv, ques_mark);
if(hash_mark)
*hash_mark = '#';
}
}
/* copy in a null string if nothing was copied in
*/
if(!rv)
mime_SACopy(&rv, "");
*returnVal = rv;
return NS_OK;
}

Просмотреть файл

@ -47,6 +47,8 @@ public:
NS_IMETHOD MakeAbsoluteURL(char * absolute_url, char * relative_url, char **retURL);
NS_IMETHOD ScanHTMLForURLs(const char* input, char **retBuf);
NS_IMETHOD ParseURL(const char *url, int parts_requested, char **returnVal);
};