libonion
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Macros | Functions
onion.c File Reference
#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
#include <string.h>
#include <errno.h>
#include <stdbool.h>
#include "low.h"
#include "types.h"
#include "onion.h"
#include "handler.h"
#include "types_internal.h"
#include "log.h"
#include "poller.h"
#include "listen_point.h"
#include "sessions.h"
#include "mime.h"
#include "http.h"
#include "https.h"

Macros

#define SOCK_CLOEXEC   0
#define ERROR_500   "<h1>500 - Internal error</h1> Check server logs or contact administrator."
#define ERROR_403   "<h1>403 - Forbidden</h1>"
#define ERROR_404   "<h1>404 - Not found</h1>"
#define ERROR_501   "<h1>501 - Not implemented</h1>"

Functions

ssize_t onion_http_write (onion_request *req, const char *data, size_t len)
oniononion_new (int flags)
 Creates the onion structure to fill with the server data, and later do the onion_listen()Creates an onion structure that can be used to set the server, port, SSL and similar parameters. It works over the onion structure, which is the main structure to control the listening of new connections throught TCP/IP.
void onion_free (onion *onion)
 Removes the allocated data.
void onion_set_client_data (onion *server, void *data, onion_client_data_free_sig *data_free)
 set a client data in the onion, freeing the previous one if it exists. Thread-safe.
void * onion_client_data (onion *server)
 Retrieve the client data in the onion server. Thread-safe.
int onion_listen (onion *o)
 Performs the listening with the given modeThis is the main loop for the onion server.
void onion_listen_stop (onion *server)
 Advises the listener to stop.
void onion_set_root_handler (onion *onion, onion_handler *handler)
 Sets the root handler.
onion_handleronion_get_root_handler (onion *server)
 Returns current root handler.For example when changing root handler, the old one is not deleted (as oposed that when deleting the onion* object it is). So user may use onion_handler_free(onion_get_root_handler(o));.
void onion_set_internal_error_handler (onion *server, onion_handler *handler)
 Sets the internal error handler.
int onion_add_listen_point (onion *server, const char *hostname, const char *port, onion_listen_point *protocol)
 Sets the port to listen to.Default listen point is HTTP at localhost:8080.
onion_listen_pointonion_get_listen_point (onion *server, int nlisten_point)
 Returns the listen point n.
void onion_set_timeout (onion *onion, int timeout)
 Sets the timeout, in millisecondsThe default timeout is 5000 milliseconds.
void onion_set_max_threads (onion *onion, int max_threads)
 Sets the maximum number of threads to use for requests. default 16.Can only be tweaked before listen.
int onion_flags (onion *onion)
 Returns the current flags.
void onion_set_user (onion *server, const char *username)
 User to which drop priviledges when listeningDrops the priviledges of current program as soon as it starts listening.
void onion_url_free_data (onion_url_data **d)
 Removes internal data for this handler.
onion_urlonion_root_url (onion *server)
 If no root handler is set, creates an url handler and returns it.It can also check if the current root handler is a url handler, and if it is, returns it. Else returns NULL.
onion_polleronion_get_poller (onion *server)
 Returns the poller, if any.
void onion_set_port (onion *server, const char *port)
 Sets the port to listen.
void onion_set_hostname (onion *server, const char *hostname)
 Sets the hostname on which to listen.
int onion_set_certificate (onion *onion, onion_ssl_certificate_type type, const char *filename,...)
 Set a certificate for use in the connection.
int onion_set_certificate_va (onion *onion, onion_ssl_certificate_type type, const char *filename, va_list va)
 Set a certificate for use in the connection.
void onion_set_max_post_size (onion *server, size_t max_size)
 Set the maximum POST size on requests.
void onion_set_max_file_size (onion *server, size_t max_size)
 Set the maximum FILE size on requests.
void onion_set_session_backend (onion *server, onion_sessions *sessions_backend)
 Sets a new sessions backend.

Macro Definition Documentation

#define ERROR_403   "<h1>403 - Forbidden</h1>"
#define ERROR_404   "<h1>404 - Not found</h1>"
#define ERROR_500   "<h1>500 - Internal error</h1> Check server logs or contact administrator."
#define ERROR_501   "<h1>501 - Not implemented</h1>"
#define SOCK_CLOEXEC   0

Referenced by onion_new().

Function Documentation

ssize_t onion_http_write ( onion_request req,
const char *  data,
size_t  len 
)
void onion_url_free_data ( onion_url_data **  d)

Removes internal data for this handler.

References onion_handler_t::onion_handler_free(), onion_low_free(), and OUD_REGEXP.

Referenced by onion_root_url(), and onion_url_new().