libwebserver Functions
web_server_init()
NAME
web_server_init - Initialize webserver
SYNOPSIS
#include "web_server.h"
int web_server_init(struct web_server *server, int port, const char *logfile, int flags);
DESCRIPTION
The web_server_init() function initializate the server handler server, start a listen socket at port port, with the logfile logfile to produce webserver log
flags for now is just WS_USESSL - openssl connections (https support)
RETURN VALUE
On success, 1 is returned, On error, 0 is returned
web_server_addhandler()
NAME
web_server_addhandler - adds an request handler
SYNOPSIS
#include "web_server.h"
int web_server_addhandler(struct web_server *server, const char *mstr, void (*func)(), int flags);
DESCRIPTION
The web_server_addhandler() function adds an request handler mstr to server handler server related to function func
mstr is a string containing expressions (as matching files) to match with the client request (GET /blah.html?id=1 HTTP/1.0, will compare blah.html mstr)
Available flags is WS_LOCAL - only local connections can preform the request
RETURN VALUE
On success, 1 is returned, On error, 0 is returned
web_server_run()
NAME
web_server_run - run the server
SYNOPSIS
#include "web_server.h"
int web_server_run(struct web_server *server);
DESCRIPTION
The web_server_run() function processes server server information, this function must be inserted in a loop (functions doesn't loop it self)
RETURN VALUE
On successm 1 is returned, On error, 0 is returned
web_server_useSSLcert()
NAME
web_server_useSSLcert - use certificate
SYNOPSIS
#include "web_server.h"
void web_server_useSSLcert(struct web_server *server, const char *file);
DESCRIPTION
The web_server_useSSLcert() function tells server server to use certificate file file on ssl connections (initializated w/ flag WS_USESSL)
web_client_addstream()
NAME
web_client_addstream - add a output stream to struct client on webserver
SYNOPSIS
#include "web_server.h"
int web_client_addstream(FILE *stream);
DESCRIPTION
The web_client_addstream() function add the stream stream to output stream list in the current client node
NOTE
The web_client_addstream() function must be called only in functions called only by gethandlers web_server_addhandler()
RETURN VALUE
On success, 1 is returned, On error, 0 is returned
web_client_addfile()
NAME
web_client_addfile - add a file to output stream struct client on webserver
SYNOPSIS
#include "web_server.h"
int web_client_addfile(const char *file);
DESCRIPTION
The web_client_addfile() function open file fileand add as stream to output stream list in the current client node
NOTE
The web_client_addfile() function must be called only in functions called only by gethandlers web_server_addhandler()
RETURN VALUE
On Success, 1 is returned, On error, 0 is returned
web_client_HTTPdirective()
NAME
web_client_HTTPdirective - Change the HTTP header status
SYNOPSIS
#include "web_server.h"
void web_client_HTTPdirective(char *directive);
DESCRIPTION
The web_client_HTTPdirective() function change the HTTP header status (i.e. "HTTP/1.1 200 OK") to the string directive
usefull for "HTTP/1.1 401 Authorization Required" (for ask password) and so ever
NOTE
The web_client_HTTPdirective() function must be called only in functions called only by gethandlers web_server_addhandler()
web_log()
NAME
web_log - write to logfile
SYNOPSIS
#include "web_server.h"
void web_log(const char *format,...);
DESCRIPTION
The web_log() is similar to printf, but writes to logfile (determined in web_server_init())
NOTE
ClientInfo
NAME
ClientInfo - a struct to control client Header
SYNOPSIS
Declared in web_server.h
extern struct ClientInfo {
int outfd;
char *inetname;
char *request;
char *method;
char *user;
char *pass;
char *QueryString;
char *PostData;
char *CookieString;
char *(*Header)(char *handle);
char *(*Query)(char *handle);
char *(*Post)(char *handle);
char *(*Cookie)(char *handle);
struct _MultiPart (*MultiPart)(char *handle);
void *__pad[5];
} *ClientInfo;
DESCRIPTION
ClientInfo->outfd is the filedescriptor of current output stream (usefull for cgi handler)
ClientInfo->inetname a string to inetname (i.e. "127.0.0.1")
ClientInfo->request is the requested 'file' (i.e. "GET /index.html HTTP/1.0\r\n" ClientInfo->request is "index.html")
ClientInfo->method is the request method ("GET" or "POST" etc..)
ClientInfo->user
ClientInfo->pass
ClientInfo->QueryString Is the query string (i.e. "GET /index.html?id=5&f=1 HTTP/1.0" ClientInfo->QueryString - is "id=5&f=1"
ClientInfo->PostData Pointer to PostData (data posted after header)
ClientInfo->CookieString
ClientInfo->Header(char *handle) Function to parses the header, and returns Header information (i.e. "Host: http://127.0.0.1:81" ClientInfo->Header("Host") is "http://127.0.0.1:81")
ClientInfo->Query(char *handle) Function that returns the query value from the browser (i.e request "http://somehost.net/req.html?id=5&f=1" ClientInfo->Query("id") is "5"
ClientInfo->Post(char *handle) Function that returns Post data from the forms with method 'POST' handle is the name of some <input> tag
ClientInfo->Cookie(char *handle)
ClientInfo->MultiPart(char *handle) Function that returns a data structure from the forms with method 'POST' and enctype='multipart/form-data' (usefull for uploading files) handle is the name of some <input> tag
the structure is
struct _MultiPart {
char *id;
char *data;
unsigned int size;
char *filename;
void *pad;
};
to be used as ClientInfo->MultiPart("file1").data; ClientInfo->MultiPart("file1").size; ClientInfo->MultiPart("file1").filename;