Esempio n. 1
0
char* strip_linebreaks(char *src)
{
		char* dest=strldup(src,lstrlen(src));
		char *ptr;
		while ((ptr = strstr(dest, "\r")) != NULL)
		{
			memmove(ptr, ptr + 1, lstrlen(ptr + 1)+1);
		}
		while ((ptr = strstr(dest, "\n")) != NULL)
		{
			int addr=ptr-dest;
			dest=renew(dest,lstrlen(dest)+1,7);
			ptr=dest+addr;
			memmove(ptr + 4, ptr + 1, lstrlen(ptr + 1) + 4);
			memcpy(ptr,"<br>",4);
		}
		dest[lstrlen(dest)]='\0';
		return dest;
}
int
parse_url(const char *url, char **ret_hostname, char **ret_file)
{
    int err = 0;
    const char *cl = NULL, *nl = NULL;

    if (ret_hostname) {
	*ret_hostname = NULL;
    }
    if (*ret_file) {
	*ret_file = NULL;
    }
    bail_null(url);

    if (!lc_is_prefix("http://", url, false)) {
	goto bail;
    }

    cl = url + strlen("http://");
    if (!*cl) {
	err = lc_err_bad_path;
	goto bail;
    }

    nl = rindex(cl, '/');
    if (!nl) {
	err = lc_err_bad_path;
	goto bail;
    }

    if (ret_hostname) {
	*ret_hostname = strldup(cl, nl - cl + 1);
    }
    if (ret_file) {
	*ret_file = strdup(nl+1);
    }
bail:
    return (err);
}