HTTP Fetcher(3)

NAME

http_fetch - Downloads a file via HTTP.

SYNOPSIS

#include <http_fetcher.h>

int http_fetch(const char *url, char **fileBuf);

DESCRIPTION

Download the file located at url. Memory is allocated to hold the file, and is pointed to by fileBuf. A terminating NULL will be appended to the data. url is a string in the following format: <http://>host<:port></path>. Portions enclosed in "<>" are optional. If no port is specified, port 80 is assumed. If you pass NULL for fileBuf, url will be requested but will not remain in memory (useful for simply registering a hit).

RETURN VALUE

On success, http_fetch returns the number of bytes of data downloaded (HTTP metadata and terminating NULL not included, so the actual size of the allocated buffer will be the return value + 1). On error, -1 is returned, and http_perror can be used to print an informative error message. http_strerror can be used to get a pointer to the current error description message.

SEE ALSO

http_setUserAgent(3), http_setReferer(3), http_setTimeout(3),
http_setRedirects(3), http_parseFilename(3), http_perror(3),
http_strerror(3)