Exemple #1
0
char *bftpd_cwd_mappath(char *path)
{
	char *result = malloc(strlen(path) + strlen(cwd) + 16);
	char *path2;
	char *tmp;

        if (! result)
           return NULL;
        path2 = strdup(path);
        if (! path2)
        {
           free(result);
           return NULL;
        }

	if (path[0] == '/')
		strcpy(result, "/");
	else
		strcpy(result, cwd);

	while (strchr(path2, '/')) {
		tmp = strdup(path2);
		*strchr(tmp, '/') = '\0';
		cutto(path2, strlen(tmp) + 1);
		appendpath(result, tmp);
		free(tmp);
	}
	appendpath(result, path2);
	free(path2);
	return result;
}
Exemple #2
0
char *abslink (char *soulink, char *reflink)
{
    int i = 0;
    char _http[] = "http://";
    char *curdir;
    while (_http[i] != '\0' && _http[i] == *(reflink + i))
	i++;
    if (i == 7)
    {
	reflink += i;
	i = 0;
	while (DOMAIN[i] != '\0' && *(reflink + i) != '/' && *(reflink + i) != '\0')
	{
	    if (DOMAIN[i] != *(reflink + i))
		return NULL;
	    i++;
	}
	if (DOMAIN[i] != '\0' || (*(reflink + i) != '/' && *(reflink + i) != '\0'))
	    return NULL;
	reflink = reflink + i + 1;
	if (*reflink == '\0' || *(reflink + strlen (reflink) - 1) == '/')
	{
	    return appendpath (reflink, "index.html");
	}
	return reflink;
    }
    else
    {
	while (*(reflink + i) != ':' && *(reflink + i) != '\0' && *(reflink + i) != '/')
	    i++;
	if (*(reflink + i) == ':' && *(reflink + i + 1) == '/' && *(reflink + i + 2) == '/')
	    return NULL;
    }
    curdir = appendpath (soulink, "..");
    return appendpath (curdir, reflink);
}