pianod2
multisource multiuser scriptable networked music player
Macros | Functions | Variables
fb_service.c File Reference

Football service and connection creation/destruction. More...

#include <config.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <assert.h>
#include "fb_transport.h"
#include "fb_service.h"
Include dependency graph for fb_service.c:

Macros

#define _BSD_SOURCE   /* strdup, realpath */
 
#define _DEFAULT_SOURCE
 

Functions

bool fb_services_are_open (void)
 Indicate whether there are any services open. More...
 
static bool fb_sanitize_socket (int socket)
 
static bool fb_setup_socket (FB_SERVICE *service, FB_SOCKETID which)
 
FB_SERVICEfb_create_service (const FB_SERVICE_OPTIONS *options)
 Create a new service and initialize its listeners. More...
 
void fb_destroy_service (FB_SERVICE *service)
 
void fb_close_service (FB_SERVICE *service)
 Initiate closure of a service. More...
 
bool fb_validate_connection (FB_SERVICE *service, FB_CONNECTION *connection)
 Validate connection with hosts_access. More...
 
static FB_CONNECTIONfb_new_connection (FB_SERVICE *service)
 
FB_CONNECTIONfb_accept_connection (FB_SERVICE *service, FB_SOCKETID id)
 
static void fb_remove_connection_from_service (FB_SERVICE *service, FB_CONNECTION *connection)
 
bool fb_transfer (FB_CONNECTION *connection, FB_SERVICE *service)
 Transfer a connection to a new service. More...
 
bool fb_transfer_by_name (FB_CONNECTION *connection, const char *name)
 
void fb_destroy_connection (FB_CONNECTION *connection)
 
void fb_close_connection (FB_CONNECTION *connection)
 Initiate connection closure. More...
 
FB_EVENTfb_accept_file (FB_SERVICE *service, char *filename)
 Make a connection that reads from a file. More...
 
FB_EVENTfb_loopback_socket (FB_SERVICE *service)
 Make a connection with a pipe. More...
 
FB_ITERATORfb_new_iterator (FB_SERVICE *service)
 Create a new iterator. More...
 
FB_EVENTfb_iterate_next (FB_ITERATOR *it)
 Get the next iteration. More...
 
void fb_destroy_iterator (FB_ITERATOR *it)
 Destroy an iterator and release its resources. More...
 

Variables

static int fb_open_service_count = 0
 

Detailed Description

Football service and connection creation/destruction.

Macro Definition Documentation

◆ _BSD_SOURCE

#define _BSD_SOURCE   /* strdup, realpath */

◆ _DEFAULT_SOURCE

#define _DEFAULT_SOURCE

Function Documentation

◆ fb_accept_connection()

FB_CONNECTION* fb_accept_connection ( FB_SERVICE service,
FB_SOCKETID  id 
)

Accept a connection.

Parameters
serviceThe service on which a connection is arriving.
idIdentifies the arrival socket (line, HTTP, TLS, IP4 vs IP6)
Returns
a pointer to a new connection, or NULL on failure.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fb_accept_file()

FB_EVENT* fb_accept_file ( FB_SERVICE service,
char *  filename 
)

Make a connection that reads from a file.

Parameters
servicethe service to register the connection with
filenamethe file to read from
Returns
a pointer to the connection, or NULL on failure.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fb_close_connection()

void fb_close_connection ( FB_CONNECTION connection)

Initiate connection closure.

If the socket is in an open state, change its state and enable writes. The next write attempt will generate a close event. If the connection is already on its way out, leave it alone.

Parameters
connectionthe connection to close
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fb_close_service()

void fb_close_service ( FB_SERVICE service)

Initiate closure of a service.

Returns
Nothing.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fb_create_service()

FB_SERVICE* fb_create_service ( const FB_SERVICE_OPTIONS options)

Create a new service and initialize its listeners.

Subsequent changes made to the options do not effect behavior.

Parameters
optionsOptions for the new service's behavior.
Returns
a pointer to the service, or NULL on failure.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fb_destroy_connection()

void fb_destroy_connection ( FB_CONNECTION connection)

Close and destroy a connection.

Returns
Nothing.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fb_destroy_iterator()

void fb_destroy_iterator ( FB_ITERATOR it)

Destroy an iterator and release its resources.

Parameters
itThe iterator

◆ fb_destroy_service()

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.

Parameters
servicethe service to terminate.
Returns
Nothing.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fb_iterate_next()

FB_EVENT* fb_iterate_next ( FB_ITERATOR it)

Get the next iteration.

See also
FB_EVENTTYPE
Parameters
itThe iterator
Returns
An event, or NULL if there are no more connections.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fb_loopback_socket()

FB_EVENT* fb_loopback_socket ( FB_SERVICE service)

Make a connection with a pipe.

Parameters
servicethe service to register the connection with
Returns
a pointer to the connection, or NULL on failure.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fb_new_connection()

static FB_CONNECTION* fb_new_connection ( FB_SERVICE service)
static

Prepare a new connection. Make space in the service's connection array, allocate a connection and (if requested in service options) a user context. Any mutexing is expected to be handled by the caller.

Parameters
servicethe service for the new connection.
Returns
a fully-allocated and zero-initialized FB_CONNECTION.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fb_new_iterator()

FB_ITERATOR* fb_new_iterator ( FB_SERVICE service)

Create a new iterator.

Create and initialize a new iterator for a service.

See also
fb_destroy_iterator().
Returns
an iterator or NULL on error.

◆ fb_remove_connection_from_service()

static void fb_remove_connection_from_service ( FB_SERVICE service,
FB_CONNECTION connection 
)
static

Remove a connection from a service's connection list.

Parameters
serviceThe service to remove from.
connectionThe connection to remove.
Here is the caller graph for this function:

◆ fb_sanitize_socket()

static bool fb_sanitize_socket ( int  socket)
static

Set sane options on a socket after opening.

Parameters
socketThe socket to sanitize.
Returns
True on success, false on error.
Here is the caller graph for this function:

◆ fb_services_are_open()

bool fb_services_are_open ( void  )

Indicate whether there are any services open.

Returns
true if services exist, false otherwise.
Here is the caller graph for this function:

◆ fb_setup_socket()

static bool fb_setup_socket ( FB_SERVICE service,
FB_SOCKETID  which 
)
static

Initialize and set up a listening socket.

Returns
true on success, false on failure
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fb_transfer()

bool fb_transfer ( FB_CONNECTION connection,
FB_SERVICE service 
)

Transfer a connection to a new service.

Parameters
connectionThe connection to transfer.
serviceThe service to reassign it to.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fb_transfer_by_name()

bool fb_transfer_by_name ( FB_CONNECTION connection,
const char *  name 
)

Transfer a connection to a related service.

Parameters
connectionThe connection to transfer.
nameThe name of the service to reassign it to.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fb_validate_connection()

bool fb_validate_connection ( FB_SERVICE service,
FB_CONNECTION connection 
)

Validate connection with hosts_access.

Parameters
serviceThe service on which the connection is arriving.
connectionThe connection.
Returns
True if access is allowed, false if denied.
Here is the caller graph for this function:

Variable Documentation

◆ fb_open_service_count

int fb_open_service_count = 0
static