VFS: Moved vfs_split_url() function from netutil.c into utilvfs.c.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
Этот коммит содержится в:
родитель
9df2f96e75
Коммит
bd8a2d4c79
@ -23,16 +23,10 @@
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <sys/types.h>
|
||||
#include <pwd.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "lib/global.h"
|
||||
#include "utilvfs.h"
|
||||
#include <stdlib.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include "netutil.h"
|
||||
|
||||
int got_sigpipe;
|
||||
@ -61,123 +55,3 @@ tcp_init (void)
|
||||
|
||||
_initialized = 1;
|
||||
}
|
||||
|
||||
/** Extract the hostname and username from the path
|
||||
*
|
||||
* Format of the path is [user@]hostname:port/remote-dir, e.g.:
|
||||
*
|
||||
* ftp://sunsite.unc.edu/pub/linux
|
||||
* ftp://miguel@sphinx.nuclecu.unam.mx/c/nc
|
||||
* ftp://tsx-11.mit.edu:8192/
|
||||
* ftp://joe@foo.edu:11321/private
|
||||
* ftp://joe:password@foo.se
|
||||
*
|
||||
* @param path is an input string to be parsed
|
||||
* @param host is an outptun g_malloc()ed hostname
|
||||
* @param user is an outptut g_malloc()ed username
|
||||
* (NULL if not specified)
|
||||
* @param port is an outptut integer port number
|
||||
* @param pass is an outptut g_malloc()ed password
|
||||
* @param default_port is an input default port
|
||||
* @param flags are parsing modifier flags (@see VFS_URL_FLAGS)
|
||||
*
|
||||
* @return g_malloc()ed host, user and pass if they are present.
|
||||
* If the user is empty, e.g. ftp://@roxanne/private, and URL_USE_ANONYMOUS
|
||||
* is not set, then the current login name is supplied.
|
||||
* Return value is a g_malloc()ed string with the pathname relative to the
|
||||
* host.
|
||||
*/
|
||||
char *
|
||||
vfs_split_url (const char *path, char **host, char **user, int *port,
|
||||
char **pass, int default_port, enum VFS_URL_FLAGS flags)
|
||||
{
|
||||
char *dir, *colon, *inner_colon, *at, *rest;
|
||||
char *retval;
|
||||
char * const pcopy = g_strdup (path);
|
||||
const char *pend = pcopy + strlen (pcopy);
|
||||
|
||||
if (pass)
|
||||
*pass = NULL;
|
||||
*port = default_port;
|
||||
*user = NULL;
|
||||
retval = NULL;
|
||||
|
||||
dir = pcopy;
|
||||
if (!(flags & URL_NOSLASH)) {
|
||||
/* locate path component */
|
||||
while (*dir != PATH_SEP && *dir)
|
||||
dir++;
|
||||
if (*dir) {
|
||||
retval = g_strdup (dir);
|
||||
*dir = 0;
|
||||
} else
|
||||
retval = g_strdup (PATH_SEP_STR);
|
||||
}
|
||||
|
||||
/* search for any possible user */
|
||||
at = strrchr (pcopy, '@');
|
||||
|
||||
/* We have a username */
|
||||
if (at) {
|
||||
*at = 0;
|
||||
inner_colon = strchr (pcopy, ':');
|
||||
if (inner_colon) {
|
||||
*inner_colon = 0;
|
||||
inner_colon++;
|
||||
if (pass)
|
||||
*pass = g_strdup (inner_colon);
|
||||
}
|
||||
if (*pcopy != 0)
|
||||
*user = g_strdup (pcopy);
|
||||
|
||||
if (pend == at + 1)
|
||||
rest = at;
|
||||
else
|
||||
rest = at + 1;
|
||||
} else
|
||||
rest = pcopy;
|
||||
|
||||
if (!*user && !(flags & URL_USE_ANONYMOUS))
|
||||
*user = vfs_get_local_username();
|
||||
|
||||
/* Check if the host comes with a port spec, if so, chop it */
|
||||
if ('[' == *rest) {
|
||||
colon = strchr (++rest, ']');
|
||||
if (colon) {
|
||||
colon[0] = '\0';
|
||||
colon[1] = '\0';
|
||||
colon++;
|
||||
} else {
|
||||
g_free (pcopy);
|
||||
g_free (retval);
|
||||
*host = NULL;
|
||||
*port = 0;
|
||||
return NULL;
|
||||
}
|
||||
} else
|
||||
colon = strchr (rest, ':');
|
||||
|
||||
if (colon) {
|
||||
*colon = 0;
|
||||
if (sscanf (colon + 1, "%d", port) == 1) {
|
||||
if (*port <= 0 || *port >= 65536)
|
||||
*port = default_port;
|
||||
} else {
|
||||
while (*(++colon)) {
|
||||
switch (*colon) {
|
||||
case 'C':
|
||||
*port = 1;
|
||||
break;
|
||||
case 'r':
|
||||
*port = 2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (host)
|
||||
*host = g_strdup (rest);
|
||||
|
||||
g_free (pcopy);
|
||||
return retval;
|
||||
}
|
||||
|
@ -28,16 +28,17 @@
|
||||
#include <config.h>
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <pwd.h>
|
||||
#include <grp.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "lib/global.h"
|
||||
#include "lib/unixcompat.h"
|
||||
|
||||
#include "src/wtools.h" /* message() */
|
||||
#include "src/main.h" /* print_vfs_message */
|
||||
#include "src/wtools.h"
|
||||
#include "src/history.h"
|
||||
|
||||
#include "vfs.h"
|
||||
@ -164,6 +165,126 @@ vfs_mkstemps (char **pname, const char *prefix, const char *param_basename)
|
||||
return fd;
|
||||
}
|
||||
|
||||
/** Extract the hostname and username from the path
|
||||
*
|
||||
* Format of the path is [user@]hostname:port/remote-dir, e.g.:
|
||||
*
|
||||
* ftp://sunsite.unc.edu/pub/linux
|
||||
* ftp://miguel@sphinx.nuclecu.unam.mx/c/nc
|
||||
* ftp://tsx-11.mit.edu:8192/
|
||||
* ftp://joe@foo.edu:11321/private
|
||||
* ftp://joe:password@foo.se
|
||||
*
|
||||
* @param path is an input string to be parsed
|
||||
* @param host is an outptun g_malloc()ed hostname
|
||||
* @param user is an outptut g_malloc()ed username
|
||||
* (NULL if not specified)
|
||||
* @param port is an outptut integer port number
|
||||
* @param pass is an outptut g_malloc()ed password
|
||||
* @param default_port is an input default port
|
||||
* @param flags are parsing modifier flags (@see VFS_URL_FLAGS)
|
||||
*
|
||||
* @return g_malloc()ed host, user and pass if they are present.
|
||||
* If the user is empty, e.g. ftp://@roxanne/private, and URL_USE_ANONYMOUS
|
||||
* is not set, then the current login name is supplied.
|
||||
* Return value is a g_malloc()ed string with the pathname relative to the
|
||||
* host.
|
||||
*/
|
||||
char *
|
||||
vfs_split_url (const char *path, char **host, char **user, int *port,
|
||||
char **pass, int default_port, enum VFS_URL_FLAGS flags)
|
||||
{
|
||||
char *dir, *colon, *inner_colon, *at, *rest;
|
||||
char *retval;
|
||||
char * const pcopy = g_strdup (path);
|
||||
const char *pend = pcopy + strlen (pcopy);
|
||||
|
||||
if (pass)
|
||||
*pass = NULL;
|
||||
*port = default_port;
|
||||
*user = NULL;
|
||||
retval = NULL;
|
||||
|
||||
dir = pcopy;
|
||||
if (!(flags & URL_NOSLASH)) {
|
||||
/* locate path component */
|
||||
while (*dir != PATH_SEP && *dir)
|
||||
dir++;
|
||||
if (*dir) {
|
||||
retval = g_strdup (dir);
|
||||
*dir = 0;
|
||||
} else
|
||||
retval = g_strdup (PATH_SEP_STR);
|
||||
}
|
||||
|
||||
/* search for any possible user */
|
||||
at = strrchr (pcopy, '@');
|
||||
|
||||
/* We have a username */
|
||||
if (at) {
|
||||
*at = 0;
|
||||
inner_colon = strchr (pcopy, ':');
|
||||
if (inner_colon) {
|
||||
*inner_colon = 0;
|
||||
inner_colon++;
|
||||
if (pass)
|
||||
*pass = g_strdup (inner_colon);
|
||||
}
|
||||
if (*pcopy != 0)
|
||||
*user = g_strdup (pcopy);
|
||||
|
||||
if (pend == at + 1)
|
||||
rest = at;
|
||||
else
|
||||
rest = at + 1;
|
||||
} else
|
||||
rest = pcopy;
|
||||
|
||||
if (!*user && !(flags & URL_USE_ANONYMOUS))
|
||||
*user = vfs_get_local_username();
|
||||
|
||||
/* Check if the host comes with a port spec, if so, chop it */
|
||||
if ('[' == *rest) {
|
||||
colon = strchr (++rest, ']');
|
||||
if (colon) {
|
||||
colon[0] = '\0';
|
||||
colon[1] = '\0';
|
||||
colon++;
|
||||
} else {
|
||||
g_free (pcopy);
|
||||
g_free (retval);
|
||||
*host = NULL;
|
||||
*port = 0;
|
||||
return NULL;
|
||||
}
|
||||
} else
|
||||
colon = strchr (rest, ':');
|
||||
|
||||
if (colon) {
|
||||
*colon = 0;
|
||||
if (sscanf (colon + 1, "%d", port) == 1) {
|
||||
if (*port <= 0 || *port >= 65536)
|
||||
*port = default_port;
|
||||
} else {
|
||||
while (*(++colon)) {
|
||||
switch (*colon) {
|
||||
case 'C':
|
||||
*port = 1;
|
||||
break;
|
||||
case 'r':
|
||||
*port = 2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (host)
|
||||
*host = g_strdup (rest);
|
||||
|
||||
g_free (pcopy);
|
||||
return retval;
|
||||
}
|
||||
|
||||
/* Parsing code is used by ftpfs, fish and extfs */
|
||||
#define MAXCOLS 30
|
||||
|
||||
|
Загрузка…
Ссылка в новой задаче
Block a user