|
pianod2
multisource multiuser scriptable networked music player
|
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.
Classes | |
| 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. More... | |
| #define | fb_perror(errfunc) fb_log(FB_WHERE (FB_LOG_ERROR), (errfunc ": %s"), strerror (errno)) |
| Log a message with a form akin to perror. More... | |
| #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. More... | |
| typedef enum fb_socket_state_t | FB_SOCKETSTATE |
| Connection states. More... | |
| typedef enum fb_socketid_t | FB_SOCKETID |
| typedef union fb_socketaddr_t | FB_SOCKETADDR |
| Address of opposing end of a connection. More... | |
| 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. More... | |
| typedef struct fb_http_request_t | FB_HTTPREQUEST |
| Structure which collects HTTP request information as it is read. More... | |
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 } |
Football private declarations.
| #define FAR_FUTURE ((time_t) (((time_t) 0x7fffffff) << ((sizeof (time_t) - 4) * 8))) |
| #define fb_encrypted_socket | ( | id | ) | ((id) == FB_SOCKET_HTTPS_IP4 || (id) == FB_SOCKET_HTTPS_IP6) |
| #define fb_http_socket | ( | id | ) |
| #define fb_ip6_socket | ( | id | ) |
| #define fb_mutex_destroy | ( | mutex | ) | ((void)0) |
| #define fb_mutex_init | ( | mutex | ) | ((void)0) |
| #define fb_mutex_lock | ( | mutex | ) | ((void)0) |
| #define fb_mutex_unlock | ( | mutex | ) | ((void)0) |
| #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_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.
| typedef struct fb_http_request_t FB_HTTPREQUEST |
Structure which collects HTTP request information as it is read.
| typedef struct fb_inputbuffer_t FB_INPUTBUFFER |
Connection input structure.
| typedef struct fb_ioqueue_t FB_IOQUEUE |
Queue structure.
These hold output for a specific connection.
| typedef enum fb_log_types_t FB_LOG_TYPE |
| typedef struct fb_message_t FB_MESSAGE |
Message structure.
May appear in multiple connections' queues.
| typedef struct fb_messagelist_t FB_MESSAGELIST |
Q list structure.
Per-connection list of its messages.
| typedef union fb_socketaddr_t FB_SOCKETADDR |
Address of opposing end of a connection.
| typedef enum fb_socketid_t FB_SOCKETID |
| typedef enum fb_socket_state_t FB_SOCKETSTATE |
Connection states.
| typedef enum fb_socket_type_t FB_SOCKETTYPE |
Magic numbers used to differentiate parameter types sent to fb_fprintf.
| enum fb_log_types_t |
| enum fb_socket_state_t |
Connection states.
| enum fb_socket_type_t |
| enum fb_socketid_t |
| FB_CONNECTION* fb_accept_connection | ( | FB_SERVICE * | service, |
| FB_SOCKETID | id | ||
| ) |
Accept a connection.
| service | The service on which a connection is arriving. |
| id | Identifies the arrival socket (line, HTTP, TLS, IP4 vs IP6) |


| void fb_collect_http_parameter | ( | char * | line, |
| FB_HTTPREQUEST * | request | ||
| ) |
Collect HTTP method parameters that are relevant.
| line | the HTTP header line received. |
| request | the request structure into which details will be stored. |


| void fb_collect_http_request | ( | FB_EVENT * | event, |
| FB_HTTPREQUEST * | request | ||
| ) |
Collect the relevant bits of 'get', 'head' or other HTTP method.
| event | an event, complete with argv structure. |
| request | HTTP request structure into which details will be placed. |


| const char* fb_connection_info | ( | FB_CONNECTION * | connection | ) |
Return a a connection's opposing end as a string.
| connection | the connection to get the string of. |

| int fb_create_argv | ( | const char * | commandline, |
| char *** | result | ||
| ) |
Create an argv-style array. A command line with nothing on it results in 0 and a pointer to an array with one null.
| commandline | The command to split up. This original string remains unaltered. |
| result | The place to put the argv array. |

| int fb_create_argv_from_query_string | ( | const char * | query_string, |
| char *** | result_names, | ||
| char *** | result_values | ||
| ) |
Create arrays of parameter names and values from an HTTP query parameter string. An empty query string results in 0 and pointers arrays with one null.
| query_string | The command to split up. This original string remains unaltered. |
| result_names | The place to put the parameter name array reference. |
| result_values | The place to put the parameter value array reference. |


| void fb_destroy_argv | ( | char ** | argv | ) |
Free up resources used by an argv array.
| argv | The array to release. |

| void fb_destroy_connection | ( | FB_CONNECTION * | connection | ) |
Close and destroy a connection.


| void fb_destroy_httprequest | ( | FB_HTTPREQUEST * | request | ) |
Reset a request structure. Frees dynamically allocated elements and clears structure.
| request | The request structure to reset. |

| void fb_destroy_service | ( | FB_SERVICE * | service | ) |
Destroy a service's resources. Abruptly closes any remaining connections, frees them, closes listener sockets and frees service.
| service | the service to terminate. |


| void fb_dispose_event | ( | FB_EVENT * | event | ) |
Destroy an event and free its resources. Events are all statically allocated, so we never free them in the current implementation. However, dispose frees the dynamically allocated elements and clears out the structure.
| event | the event to free |


| FB_EVENT* fb_execute_http_request | ( | FB_EVENT * | event, |
| FB_CONNECTION * | connection | ||
| ) |
Interpret the collected HTTP request. Return an HTTP error if the request is invalid. If it is a WebSocket request, initiate a WebSocket session. Otherwise serve the request and reset the connection.
| event | a partially filled event applicable to this connection. |
| connection | the connection being served. |


| void fb_free_freelists | ( | void | ) |
Free the free message lists

| bool fb_http_command | ( | const char * | command | ) |
Determine if a request is an HTTP one.
| command | the HTTP request (GET, HEAD, etc.) |


| FB_MESSAGE* fb_messagealloc | ( | void | ) |
Allocate a message block structure. Get it off the free list if its available, otherwise malloc a new one.

| void fb_messagefree | ( | FB_MESSAGE * | freethis | ) |
"Free" a message block by putting it on the free list.

| FB_EVENT* fb_new_connect | ( | FB_EVENT * | event, |
| FB_SERVICE * | service | ||
| ) |
Accept a new connection and return an event announcing it if applicable.
| event | a partially filled event applicable to the new connection. |
| service | the service on which the connection is arriving. |


| FB_MESSAGELIST* fb_qalloc | ( | ) |

| void fb_qfree | ( | FB_MESSAGELIST * | freethis | ) |
"Free" a single message by putting it on the free list.


| bool fb_queue_add | ( | FB_IOQUEUE * | queue, |
| FB_MESSAGE * | message | ||
| ) |
Add a message to a queue. Does not adjust message block use counts.
| queue | the queue to add to. |
| message | the message to add to the queue. |


| void fb_queue_consume | ( | FB_IOQUEUE * | q, |
| size_t | consume | ||
| ) |
Consume bytes at the front of the queue. Bytes consumed must not exceed the remaining bytes in the front message block.
| q | the queue |
| consume | The number of bytes to consume. |


| void fb_queue_destroy | ( | FB_IOQUEUE * | q | ) |
Trash everything in a queue.
| q | the queue to free. |


| bool fb_queue_empty | ( | FB_IOQUEUE * | q | ) |
Check if a queue empty is empty.

| void fb_queue_event | ( | FB_EVENT * | event | ) |
Queue an event. Only used for fallback mode on HTTP port, when we need to deliver a connection arrival and then the command, so size is limited to 1.
| event | the event to queue |

| FB_EVENT* fb_read_input | ( | FB_EVENT * | ev, |
| FB_CONNECTION * | connection | ||
| ) |
Read input based on protocol and state. If applicable, returns an event for the input.
| ev | a partially-filled event applicable to this input |
| connection | the connection from which input is read |


| FB_EVENT* fb_read_websocket_input | ( | FB_EVENT * | event, |
| FB_CONNECTION * | connection | ||
| ) |
Read data from WebSocket connection. Reads a WebSocket packet and decodes it, and returns an event for the payload.
| event | a partially filled event applicable to the connection. |
| connection | the connection to read from. |


| bool fb_recv_input | ( | FB_CONNECTION * | connection, |
| ssize_t | byte_count | ||
| ) |
Read some bytes directly from a socket or via TLS if encrypted. Handle connection closing and errors.
| connection | the connection to read input from. |
| byte_count | the number of bytes to read |


| bool fb_register | ( | int | socket_fd, |
| FB_SOCKETTYPE | type, | ||
| void * | thing | ||
| ) |
Add a socket to the registry.
| socket_fd | The file descriptor of the socket being added. |
| type | Type of socket (service, connection, user...) |
| thing | Pointer of type indicated by 'type'. |


| void fb_schedule_reap | ( | FB_SERVICE * | service | ) |
Schedule a service for reaping when it has no connections left.

| FB_EVENT* fb_send_output | ( | FB_EVENT * | event, |
| FB_CONNECTION * | connection | ||
| ) |
Write output to a connection from the queue. Events are generated for connection closure only; there are none for writing.
If the socket is in a closing state, when the buffer is empty, close the connection.
| event | A partially complete event record, or NULL. If NULL, events are delayed (along with moving state toward closure) until a later time, when an event can be returned for those state changes. |
| connection | The connection whose queued data is to be sent. |


| void fb_set_buffering | ( | int | socket_fd, |
| bool | enable | ||
| ) |
Enable/disable writing on a socket. This is used to remember TLS data buffering.
| socket_fd | the file descriptor to apply flags to |
| enable | true if TLS is buffering, false if it is not. |


| bool fb_set_input_buffer_size | ( | FB_CONNECTION * | connection, |
| size_t | size | ||
| ) |
Expand the input buffer to a specified size.
| connection | The connection whose buffer size is being set. |
| size | the desired size. |

| void fb_set_readable | ( | int | socket_fd, |
| bool | enable | ||
| ) |
Enable/disable reading on a socket.
| socket_fd | the file descriptor to apply flags to |
| enable | true to enable reads from the socket, false to disable |


| void fb_set_writable | ( | int | socket_fd, |
| bool | enable | ||
| ) |
Enable/disable writing on a socket. This is used within Football, enabled when fresh data is queued for a socket and disabled when the buffer is empty.
| socket_fd | the file descriptor to apply flags to |
| enable | true to enable write-polling on the socket |


| bool fb_transfer_by_name | ( | FB_CONNECTION * | connection, |
| const char * | name | ||
| ) |
Transfer a connection to a related service.
| connection | The connection to transfer. |
| name | The name of the service to reassign it to. |


| void fb_unregister | ( | int | socket_fd | ) |
Remove a socket from the registry.
Always succeeds, unless there's a bug.
| socket_fd | the file descriptor to unregister |

| bool fb_websocket_announce_close | ( | FB_CONNECTION * | connection | ) |
Send a WebSocket close packet. This should be called as last thing prior to closing the connection.
| connection | The connection to write the close to. |

| bool fb_websocket_encode | ( | FB_CONNECTION * | connection | ) |
Build WebSocket packets from output. Checks if there's a complete packet (line) in the assembly queue. When there is, assemble a WebSocket packet and put it in the output queue.
| connection | The connection to check. |


| bool fb_websocket_ping | ( | FB_CONNECTION * | connection | ) |
Send a WebSocket ping packet. Some browsers have timeouts, so we need to send pings as keep-alives.
| connection | The connection to check. |

