Table of Contents

## NAME

http_server, http_port, http_put, http_get, http_head, http_delete, http_parse_url - Http data exchanges mini library.

## SYNOPSIS

#include "http_lib.h"

extern char *http_server;

extern int http_port;

extern char *http_proxy_server;

extern int http_proxy_port;

http_retcode http_put
(
char *filename,
char *data,
int length,
int overwrite,
char *type
);

http_retcode http_get
(
char *filename,
char **pdata,
int *plength,
char *typebuf
);

http_retcode http_head
(
char *filename,
int *plength,
char *typebuf
);

http_retcode http_delete(char *filename);

http_retcode http_parse_url
(
char *url,
char **pfilename
);

## PARAMETERS

char *filename (http_put)
Name of the ressource to create.

char *data
Pointer to the data to send.

int length
Length of the data to send.

int overwrite
Flag to request to overwrite the ressource if it was already existing.

char *type
Type of the data, if NULL default type is used.

char *filename (http_get)
Name of the ressource to read.

char **pdata
Address of a pointer variable which will be set to point toward allocated memory containing read data.

int *plength
  (http_get) Address of integer variable which will be set to length of the read data.

char *typebuf (http_get)
Allocated buffer where the read data type is returned. If NULL, the type is not returned.

int *plength
  (http_head) Address of integer variable which will be set to length of the data.

char *typebuf (http_head)
Allocated buffer where the data type is returned. If NULL, the type is not returned.

char *url
Writeable copy of an url.

char **pfilename
Address of a pointer that will be filled with allocated filename the pointer must be equal to NULL before calling or it will be automatically freed (free(3)).

## DESCRIPTION

http_server
Pointer to a mallocated string containing server name or NULL.

http_port
Server port number.

http_proxy_server
Pointer a string containing proxy server name to use or NULL for noproxy.

http_port
Proxy server port number (or 0).

http_put
Put data on the server

This function sends data to the http data server. The data will be stored under the ressource name filename.

http_get
Get data from the server

This function gets data from the http data server. The data is read from the ressource named filename. Address of new new allocated memory block is filled in pdata whose length is returned via plength.

http_head
Request the header

This function outputs the header of thehttp data server. The header is from the ressource named filename. The length and type of data is eventually returned (like for http_get(3)).

http_delete
Delete data on the server

This function request a DELETE on the http data server.

http_parse_url
Parses an url : setting the http_server and http_port global variables and returning the filename to pass to http_get/put/...

## RETURNS

http_put
A negative error code or a positive code from the server.

http_get
A negative error code or a positive code from the server.

http_head
A negative error code or a positive code from the server.

http_delete
A negative error code or a positive code from the server.

http_parse_url
A negative error code or 0 if sucessfully parsed.

Possible values for a http_retcode are as follows:

Client side errors.
ERRHOST No such host.
ERRSOCK Can't create socket.
ERRCONN Can't connect to host.
ERRWRHD Write error on socket while writing header. ERRWRDT Write error on socket while writing data. ERRRDHD Read error on socket while reading result. ERRPAHD Invalid answer from data server. ERRNULL Null data pointer.
ERRNOLG No/Bad length in header.

ERRMEM
  Can't allocate memory. ERRRDDT Read error while reading data. ERRURLH Invalid url - must start with `http://'. ERRURLP Invalid port in url.

Return code by the server.

ERR400
  Invalid query. ERR403 Forbidden.

ERR408
  Request timeout.

ERR500
  Server error.

ERR501
  Not implemented.

ERR503
  Service overloaded.

Succesful results.

OK0
  Successfull parse.

OK201
  Ressource succesfully created.

OK200
  Ressource succesfully read.

## LIMITATIONS

http_put
Filename is truncated to first 256 characters and type to 64.

http_get
Filename is truncated to first 256 characters.

http_head
Filename is truncated to first 256 characters.

http_delete
Filename is truncated to first 256 characters.

Table of Contents

- NAME
- SYNOPSIS
- PARAMETERS
- DESCRIPTION
- RETURNS
- LIMITATIONS