コード例 #1
0
ファイル: ParseURL.c プロジェクト: JackieXie168/movgrab
void ParseURL(char *URL, char **Proto, char **Host, char **Port, char **User, char **Password, char **Path, char **Args)
{
char *ptr, *aptr;
char *Token=NULL, *tProto=NULL;


//Even if they pass NULL for protocol, we need to take a copy for use in
//the 'guess the port' section below
ptr=GetToken(URL,":",&tProto,0);
strlwr(tProto);
if (Proto) *Proto=CopyStr(*Proto,tProto);

//some number of '//' follow protocol
while (*ptr=='/') ptr++;

ptr=GetToken(ptr,"/",&Token,0);
ParseHostDetails(Token,Host,Port,User,Password);

//Only split the HTTP CGI arguments from the document path if we were asked to return
//the args seperately
if (Args)
{
	aptr=strrchr(ptr,'?');
	if (aptr) 
	{
		*aptr='\0';
		aptr++;
		*Args=CopyStr(*Args,aptr);
	}
}

//the 'GetToken' call will have thrown away the '/' at the start of the path
//add it back in
if (Path) *Path=MCopyStr(*Path,"/",ptr,NULL);

if (Port && (! StrLen(*Port)))
{
	if (strcmp(tProto,"http")==0) *Port=CopyStr(*Port,"80");
	else if (strcmp(tProto,"https")==0) *Port=CopyStr(*Port,"443");
	else if (strcmp(tProto,"ssh")==0) *Port=CopyStr(*Port,"22");
	else if (strcmp(tProto,"ftp")==0) *Port=CopyStr(*Port,"21");
	else if (strcmp(tProto,"telnet")==0) *Port=CopyStr(*Port,"23");
	else if (strcmp(tProto,"smtp")==0) *Port=CopyStr(*Port,"25");
	else if (strcmp(tProto,"mailto")==0) *Port=CopyStr(*Port,"25");

}

DestroyString(Token);
DestroyString(tProto);
}
コード例 #2
0
ファイル: URL.c プロジェクト: ColumPaget/Crayonizer
void ParseURL(const char *URL, char **Proto, char **Host, char **Port, char **User, char **Password, char **Path, char **Args)
{
    const char *ptr;
    char *Token=NULL, *tProto=NULL, *aptr;

//we might not return a protocol!
    if (Proto) *Proto=CopyStr(*Proto,"");

//Even if they pass NULL for protocol, we need to take a copy for use in
//the 'guess the port' section below
    ptr=strchr(URL,':');
    if (ptr)
    {
        tProto=CopyStrLen(tProto,URL,ptr-URL);
        strlwr(tProto);
        aptr=strchr(tProto, '.');
        if (aptr)
        {
            //protocol name is not allowed to contain '.', so this must be a hostname or
            //ip address.
            ptr=URL;
        }
        else
        {
            if (Proto) *Proto=CopyStr(*Proto,tProto);
            ptr++;
            //some number of '//' follow protocol
            while (*ptr=='/') ptr++;
        }

        ptr=GetToken(ptr,"/",&Token,0);
        ParseHostDetails(Token,Host,Port,User,Password);
    }
    else ptr=URL;

    while (ptr && (*ptr=='/')) ptr++;

    if (ptr)
    {
        if (Path)
        {
            *Path=MCopyStr(*Path,"/",ptr,NULL);

            //Only split the HTTP CGI arguments from the document path if we were
            //asked to return the args seperately
            if (Args)
            {
                aptr=strchr(*Path,'?');
                if (! aptr) aptr=strchr(*Path,'#');
                if (aptr)
                {
                    *aptr='\0';
                    aptr++;
                    *Args=CopyStr(*Args,aptr);
                }
            }
        }
    }

//the 'GetToken' call will have thrown away the '/' at the start of the path
//add it back in

    if (Port && (! StrValid(*Port)) && StrValid(tProto))
    {
        if (strcmp(tProto,"http")==0) *Port=CopyStr(*Port,"80");
        else if (strcmp(tProto,"https")==0) *Port=CopyStr(*Port,"443");
        else if (strcmp(tProto,"ssh")==0) *Port=CopyStr(*Port,"22");
        else if (strcmp(tProto,"ftp")==0) *Port=CopyStr(*Port,"21");
        else if (strcmp(tProto,"telnet")==0) *Port=CopyStr(*Port,"23");
        else if (strcmp(tProto,"smtp")==0) *Port=CopyStr(*Port,"25");
        else if (strcmp(tProto,"mailto")==0) *Port=CopyStr(*Port,"25");

    }


    DestroyString(Token);
    DestroyString(tProto);
}