Пример #1
0
static char *decomposeURL(const char *url,char **host, int *port, char **username,
	char **password) {
    char *pt, *pt2, *upt, *ppt;
    char *path;
    char proto[40];
    /* ftp://[user[:password]@]ftpserver[:port]/url-path */

    *username = NULL; *password = NULL; *port = -1;
    pt = strstr(url,"://");
    if ( pt==NULL ) {
	*host = NULL;
return( copy(url));
    }
    strncpy(proto,url,pt-url<sizeof(proto)?pt-url:sizeof(proto));
    proto[(pt-url)] = '\0';
    pt += 3;

    pt2 = strchr(pt,'/');
    if ( pt2==NULL ) {
	pt2 = pt+strlen(pt);
	path = copy("/");
    } else {
	path = copy(pt2);
    }

    upt = strchr(pt,'@');
    if ( upt!=NULL && upt<pt2 ) {
	ppt = strchr(pt,':');
	if ( ppt==NULL ) {
	    *username = copyn(pt,upt-pt);
	} else {
	    *username = copyn(pt,ppt-pt);
	    *password = copyn(ppt+1,upt-ppt-1);
	}
	pt = upt+1;
    }

    ppt = strchr(pt,':');
    if ( ppt!=NULL && ppt<pt2 ) {
	char *temp = copyn(ppt+1,pt2-ppt-1), *end;
	*port = strtol(temp,&end,10);
	if ( *end!='\0' )
	    *port = -2;
	free(temp);
	pt2 = ppt;
    }
    *host = copyn(pt,pt2-pt);
    if ( *username ) {
	*password = GIO_PasswordCache(proto,*host,*username,*password);
	if ( *password==NULL ) {
	    *password = ff_ask_password(_("Password?"),"",_("Enter password for %s@%s"), *username, *host );
	    *password = GIO_PasswordCache(proto,*host,*username,*password);
	}
    }
return( path );
}
Пример #2
0
char *_GIO_decomposeURL(const unichar_t *url,char **host, int *port, char **username,
	char **password) {
    unichar_t *pt, *pt2, *upt, *ppt;
    char *path;
    char proto[40];
    /* ftp://[user[:password]@]ftpserver[:port]/url-path */

    *username = NULL; *password = NULL; *port = -1;
    pt = uc_strstr(url,"://");
    if ( pt==NULL ) {
	*host = NULL;
return( cu_copy(url));
    }
    cu_strncpy(proto,url,(size_t)(pt-url)<sizeof(proto)?(size_t)(pt-url):sizeof(proto));
    pt += 3;

    pt2 = u_strchr(pt,'/');
    if ( pt2==NULL ) {
	pt2 = pt+u_strlen(pt);
	path = copy("/");
    } else {
	path = cu_copy(pt2);
    }

    upt = u_strchr(pt,'@');
    if ( upt!=NULL && upt<pt2 ) {
	ppt = u_strchr(pt,':');
	if ( ppt==NULL )
	    *username = cu_copyn(pt,upt-pt);
	else {
	    *username = cu_copyn(pt,ppt-pt);
	    *password = cu_copyn(ppt+1,upt-ppt-1);
	}
	pt = upt+1;
    }

    ppt = u_strchr(pt,':');
    if ( ppt!=NULL && ppt<pt2 ) {
	char *temp = cu_copyn(ppt+1,pt2-ppt-1), *end;
	*port = strtol(temp,&end,10);
	if ( *end!='\0' )
	    *port = -2;
	free(temp);
	pt2 = ppt;
    }
    *host = cu_copyn(pt,pt2-pt);
    if ( *username )
	*password = GIO_PasswordCache(proto,*host,*username,*password);
return( path );
}
Пример #3
0
char *
GIODecomposeURL (const uint32_t *url, char **host, int *port, char **username,
                 char **password)
{
  uint32_t *pt, *pt2, *upt, *ppt;
  char *path;
  char proto[40];
  /* ftp://[user[:password]@]ftpserver[:port]/url-path */

  *username = NULL;
  *password = NULL;
  *port = -1;
  pt = uc_strstr (url, "://");
  if (pt == NULL)
    {
      *host = NULL;
      return (x_u32_to_u8 (u32_force_valid (url)));
    }
  cu_strncpy (proto, url,
              pt - url < sizeof (proto) ? pt - url : sizeof (proto));
  pt += 3;

  pt2 = u32_strchr (pt, '/');
  if (pt2 == NULL)
    {
      pt2 = pt + u32_strlen (pt);
      path = xstrdup ("/");
    }
  else
    {
      path = x_u32_to_u8 (u32_force_valid (pt2));
    }

  upt = u32_strchr (pt, '@');
  if (upt != NULL && upt < pt2)
    {
      ppt = u32_strchr (pt, ':');
      if (ppt == NULL)
        *username = x_u32_to_u8 (x_gc_u32_strmbndup (pt, upt - pt));
      else
        {
          *username = x_u32_to_u8 (x_gc_u32_strmbndup (pt, ppt - pt));
          *password = x_u32_to_u8 (x_gc_u32_strmbndup (ppt + 1, upt - ppt - 1));
        }
      pt = upt + 1;
    }

  ppt = u32_strchr (pt, ':');
  if (ppt != NULL && ppt < pt2)
    {
      char *temp = x_u32_to_u8 (x_gc_u32_strmbndup (ppt + 1, pt2 - ppt - 1));
      char *end;
      *port = strtol (temp, &end, 10);
      if (*end != '\0')
        *port = -2;
      free (temp);
      pt2 = ppt;
    }
  *host = x_u32_to_u8 (x_gc_u32_strmbndup (pt, pt2 - pt));
  if (*username)
    *password = GIO_PasswordCache (proto, *host, *username, *password);
  return (path);
}