football
socket abstraction layer
Data Structures | Macros | Typedefs | Enumerations | Functions
fb_service.h File Reference

Football private declarations. More...

#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <time.h>
#include <stdbool.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include "fb_public.h"
#include "fb_transport.h"

Go to the source code of this file.

Data Structures

union  fb_socketaddr_t
 Address of opposing end of a connection. More...
 
struct  fb_service_t
 Football service state structure. More...
 
struct  fb_message_t
 Message structure. More...
 
struct  fb_messagelist_t
 Q list structure. More...
 
struct  fb_ioqueue_t
 Queue structure. More...
 
struct  fb_inputbuffer_t
 Connection input structure. More...
 
struct  fb_http_request_t
 Structure which collects HTTP request information as it is read. More...
 
struct  fb_connection_t
 Connection state information. More...
 
struct  fb_iterator_t
 Iterator for connections on a football service. More...
 

Macros

#define FB_WHERE(level)   __FILE__, __LINE__, __func__, (level)
 Use FB_WHERE to send the log type; this macro includes the file, line and function when NDEBUG is not set.
 
#define fb_perror(errfunc)   fb_log(FB_WHERE (FB_LOG_ERROR), (errfunc ": %s"), strerror (errno))
 Log a message with a form akin to perror.
 
#define fb_mutex_init(mutex)   ((void)0)
 
#define fb_mutex_destroy(mutex)   ((void)0)
 
#define fb_mutex_lock(mutex)   ((void)0)
 
#define fb_mutex_unlock(mutex)   ((void)0)
 
#define fb_http_socket(id)
 
#define fb_ip6_socket(id)
 
#define fb_encrypted_socket(id)   ((id) == FB_SOCKET_HTTPS_IP4 || (id) == FB_SOCKET_HTTPS_IP6)
 
#define FAR_FUTURE   ((time_t) (((time_t) 0x7fffffff) << ((sizeof (time_t) - 4) * 8)))
 

Typedefs

typedef enum fb_log_types_t FB_LOG_TYPE
 
typedef enum fb_socket_type_t FB_SOCKETTYPE
 Magic numbers used to differentiate parameter types sent to fb_fprintf.
 
typedef enum fb_socket_state_t FB_SOCKETSTATE
 Connection states.
 
typedef enum fb_socketid_t FB_SOCKETID
 
typedef union fb_socketaddr_t FB_SOCKETADDR
 Address of opposing end of a connection.
 
typedef struct fb_message_t FB_MESSAGE
 Message structure. More...
 
typedef struct fb_messagelist_t FB_MESSAGELIST
 Q list structure. More...
 
typedef struct fb_ioqueue_t FB_IOQUEUE
 Queue structure. More...
 
typedef struct fb_inputbuffer_t FB_INPUTBUFFER
 Connection input structure.
 
typedef struct fb_http_request_t FB_HTTPREQUEST
 Structure which collects HTTP request information as it is read.
 

Enumerations

enum  fb_log_types_t {
  FB_LOG_ERROR = 0 , FB_LOG_WARNING = 0x01 , FB_LOG_PARSER = 0x04 , FB_LOG_IO_TRACE = 0x08 ,
  FB_LOG_CONN_STATUS = 0x10 , FB_LOG_CONN_ERROR = 0x20 , FB_LOG_TLS_STATUS = 0x100 , FB_LOG_TLS_ERROR = 0x200 ,
  FB_LOG_HTTP_STATUS = 0x1000 , FB_LOG_HTTP_ERROR = 0x2000 , FB_LOG_HTTP_TRAFFIC = 0x4000
}
 
enum  fb_socket_type_t { FB_SOCKTYPE_SERVICE = 0x3692 , FB_SOCKTYPE_CONNECTION = 0x5285 , FB_SOCKTYPE_USER = 0xa9f7 , FB_SOCKTYPE_EVENT = 0xbd53 }
 Magic numbers used to differentiate parameter types sent to fb_fprintf. More...
 
enum  fb_socket_state_t {
  FB_SOCKET_STATE_TLS_HANDSHAKE , FB_SOCKET_STATE_GREETING , FB_SOCKET_STATE_GATHERING_HEADER , FB_SOCKET_STATE_OPEN ,
  FB_SOCKET_STATE_FLUSHING , FB_SOCKET_STATE_CLOSING
}
 Connection states. More...
 
enum  fb_socketid_t {
  FB_SOCKET_LINE_IP4 , FB_SOCKET_LINE_IP6 , FB_SOCKET_HTTP_IP4 , FB_SOCKET_HTTP_IP6 ,
  FB_SOCKET_HTTPS_IP4 , FB_SOCKET_HTTPS_IP6 , FB_SOCKET_COUNT
}
 

Functions

void fb_free_freelists (void)
 
FB_MESSAGEfb_messagealloc (void)
 
void fb_messagefree (FB_MESSAGE *freethis)
 
FB_MESSAGELISTfb_qalloc ()
 
void fb_qfree (FB_MESSAGELIST *freethis)
 
bool fb_queue_add (FB_IOQUEUE *queue, FB_MESSAGE *message)
 
bool fb_queue_empty (FB_IOQUEUE *q)
 
void fb_queue_consume (FB_IOQUEUE *q, size_t consume)
 
void fb_queue_destroy (FB_IOQUEUE *q)
 
void fb_destroy_service (struct fb_service_t *service)
 
void fb_schedule_reap (FB_SERVICE *service)
 
bool fb_transfer_by_name (FB_CONNECTION *connection, const char *name)
 
void fb_queue_event (FB_EVENT *event)
 
void fb_dispose_event (FB_EVENT *event)
 
bool fb_register (int socket, FB_SOCKETTYPE type, void *thing)
 Add a socket to the registry. More...
 
void fb_unregister (int socket)
 Remove a socket from the registry. More...
 
FB_CONNECTIONfb_accept_connection (FB_SERVICE *service, FB_SOCKETID id)
 
void fb_destroy_connection (FB_CONNECTION *connection)
 
bool fb_set_input_buffer_size (FB_CONNECTION *connection, size_t size)
 
bool fb_recv_input (FB_CONNECTION *connection, ssize_t byte_count)
 
FB_EVENTfb_read_input (FB_EVENT *event, FB_CONNECTION *connection)
 
FB_EVENTfb_new_connect (FB_EVENT *event, FB_SERVICE *service)
 
FB_EVENTfb_send_output (FB_EVENT *event, FB_CONNECTION *connection)
 
FB_EVENTfb_read_websocket_input (FB_EVENT *event, FB_CONNECTION *connection)
 
bool fb_websocket_ping (FB_CONNECTION *connection)
 
bool fb_websocket_announce_close (FB_CONNECTION *connection)
 
bool fb_websocket_encode (FB_CONNECTION *connection)
 
void fb_destroy_httprequest (FB_HTTPREQUEST *request)
 
void fb_collect_http_request (FB_EVENT *event, FB_HTTPREQUEST *request)
 
void fb_collect_http_parameter (char *line, FB_HTTPREQUEST *request)
 
bool fb_http_command (const char *command)
 
FB_EVENTfb_execute_http_request (FB_EVENT *event, FB_CONNECTION *connection)
 
int fb_create_argv (const char *commandline, char ***result)
 
int fb_create_argv_from_query_string (const char *query_string, char ***result, char ***remainders)
 
void fb_destroy_argv (char **argv)
 
const char * fb_connection_info (FB_CONNECTION *connection)
 
void fb_set_buffering (int socket_fd, bool enable)
 
void fb_set_readable (int socket, bool enable)
 
void fb_set_writable (int socket, bool enable)
 

Detailed Description

Football private declarations.

Macro Definition Documentation

◆ fb_http_socket

#define fb_http_socket (   id)
Value:
((id) == FB_SOCKET_HTTP_IP4 || (id) == FB_SOCKET_HTTP_IP6 || \
(id) == FB_SOCKET_HTTPS_IP4 || (id) == FB_SOCKET_HTTPS_IP6)

◆ fb_ip6_socket

#define fb_ip6_socket (   id)
Value:
((id) == FB_SOCKET_LINE_IP6 || (id) == FB_SOCKET_HTTP_IP6 || \
(id) == FB_SOCKET_HTTPS_IP6)

Typedef Documentation

◆ FB_IOQUEUE

typedef struct fb_ioqueue_t FB_IOQUEUE

Queue structure.

These hold output for a specific connection.

◆ FB_MESSAGE

typedef struct fb_message_t FB_MESSAGE

Message structure.

May appear in multiple connections' queues.

◆ FB_MESSAGELIST

Q list structure.

Per-connection list of its messages.

Enumeration Type Documentation

◆ fb_socket_state_t

Connection states.

Enumerator
FB_SOCKET_STATE_TLS_HANDSHAKE 

Connection has not yet completed TLS handshake.

FB_SOCKET_STATE_GREETING 

HTTP/TLS connection is awaiting a request.

FB_SOCKET_STATE_GATHERING_HEADER 

HTTP/HTTPS request in process, still reading headering.

FB_SOCKET_STATE_OPEN 

Line-oriented or WebSocket session in process.

FB_SOCKET_STATE_FLUSHING 

Line-oriented or WebSocket session is closing, flushing output.

FB_SOCKET_STATE_CLOSING 

Line-oriented or WebSocket connection has finished flushing.

◆ fb_socket_type_t

Magic numbers used to differentiate parameter types sent to fb_fprintf.

Enumerator
FB_SOCKTYPE_SERVICE 

Random numbers.

Function Documentation

◆ fb_register()

bool fb_register ( int  socket_fd,
FB_SOCKETTYPE  type,
void *  thing 
)

Add a socket to the registry.

Parameters
socket_fdThe file descriptor of the socket being added.
typeType of socket (service, connection, user...)
thingPointer of type indicated by 'type'.
Returns
true on success, false on failure

◆ fb_unregister()

void fb_unregister ( int  socket_fd)

Remove a socket from the registry.

Always succeeds, unless there's a bug.

Parameters
socket_fdthe file descriptor to unregister