jabberd14 1.6.2
Data Structures | Typedefs | Functions | Variables
mio.cc File Reference

MIO -- Managed Input/Output. More...

#include <jabberd.h>
#include <errno.h>

Data Structures

struct  mio_connect_st
 internal structure holding data of the destination where we connect to More...

Typedefs

typedef struct mio_connect_st _connect_data
 internal structure holding data of the destination where we connect to
typedef struct mio_connect_stconnect_data

Functions

int _mio_write_dump (mio m)
void mio_init (void)
void mio_stop (void)
mio mio_new (int fd, mio_std_cb cb, void *arg, mio_handlers mh)
void mio_reset (mio m, mio_std_cb cb, void *arg)
void mio_close (mio m)
void mio_write (mio m, xmlnode stanza, char const *buffer, int len)
void mio_write_root (mio m, xmlnode root, int stream_type)
void mio_karma (mio m, int val, int max, int inc, int dec, int penalty, int restore)
void mio_karma2 (mio m, struct karma *k)
void mio_rate (mio m, int rate_time, int max_points)
xmlnode mio_cleanup (mio m)
void mio_connect (char *host, int port, mio_std_cb cb, void *cb_arg, int timeout, mio_handlers mh)
mio mio_listen (int port, char const *listen_host, mio_std_cb cb, void *arg, mio_handlers mh)
mio_handlers mio_handlers_new (mio_read_func rf, mio_write_func wf, mio_parser_func pf)
void mio_handlers_free (mio_handlers mh)
void mio_set_handlers (mio m, mio_handlers mh)

Variables

ios mio__data = NULL
xmlnode greymatter__

Detailed Description

MIO -- Managed Input/Output.

The purpose of this file, is mainly to provide support, to any component of jabberd, for abstraced I/O functions. This works much like tstreams, and will incorporate the functionality of io_select initially, but will be expanded to support any socket handling model, such as polld, SIGIO, etc

This works to abstract the socket work, and hide it from the component, this way, the component does not have to deal with any complexeties of socket functions.


Typedef Documentation

typedef struct mio_connect_st _connect_data

internal structure holding data of the destination where we connect to

typedef struct mio_connect_st * connect_data

Function Documentation

int _mio_write_dump ( mio  m)

Dump this socket's write queue.

Tries to write * as much of the write queue as it can, before the write call would block the server

Parameters:
mthe connection that should get it's write queue dumped
Returns:
-1 on error, 0 on success, and 1 if more data to write

References mio_st::cb, mio_st::cb_arg, mio_wb_q_st::cur, mio_st::fd, mio_wb_q_st::len, log_debug2, LOGT_BYTES, LOGT_IO, mio_st::mh, MIO_ERROR, mio_wb_q_st::next, mio_wb_q_st::p, pool_free(), mio_st::queue, mio_st::tail, mio_handlers_st::write, and ZONE.

Referenced by mio_xml_starttls().

xmlnode mio_cleanup ( mio  m)

pops the last xmlnode from the queue

This function removes the last xmlnode from a write queue. This is normally used to get unsent stanzas from the queue in case of an error happens and the stanzas cannot be delivered.

The returned xmlnodes have to be freed by the caller.

Elements in the write queue, that have no xmlnode attached, but are just character data are deleted by this function and the memory associated with these items is freed by mio_cleanup().

Parameters:
mthe mio stream to get the last xmlnode stanza in the write queue for.
Returns:
last stanza item in the write queue (has to be freed by the caller), or NULL if no further stanzas

References mio_wb_q_st::next, mio_wb_q_st::p, pool_free(), mio_st::queue, mio_st::tail, and mio_wb_q_st::x.

void mio_close ( mio  m)
void mio_connect ( char *  host,
int  port,
mio_std_cb  cb,
void *  cb_arg,
int  timeout,
mio_handlers  mh 
)

request to connect to a remote host

Parameters:
hostthe host where to connect to (either a IPv4 or IPv6)
portthe port number to connect to
cbthe application callback function
cb_argargument to pass to the application callback function
timeouthow long to wait for a connection to be established (0 for using the default value)
mhthe mio_handlers used to select the desired type of socket (e.g. an XML stream or a TLS protected socket)

References mio_connect_st::cb, mio_connect_st::cb_arg, mio_connect_st::ip, mio_connect_st::mh, mio_handlers_new(), mio_connect_st::p, pmalloco(), pool_new, mio_connect_st::port, pstrdup(), register_beat(), and mio_connect_st::t.

Referenced by dialback_out_connect().

void mio_handlers_free ( mio_handlers  mh)

free a mio_handlers structure

Parameters:
mhthe mio_handlers structure that should be freed

References mio_handlers_st::p, and pool_free().

Referenced by mio_set_handlers().

mio_handlers mio_handlers_new ( mio_read_func  rf,
mio_write_func  wf,
mio_parser_func  pf 
)

create a mio_handlers instance, that can be passed to mio_listen() or mio_accept()

The mio_handlers can be used to setup different 'types' of sockets

Default is to have an unencrypted socket reading plain bytes.

If you are requesting a TLS protected socket (using MIO_SSL_READ and MIO_SSL_WRITE), you also have to modify the accepted function in the returned mio_handlers afterwards!

Parameters:
rfhandler used for reading, NULL for default (may be MIO_RAW_READ or MIO_SSL_READ)
wfhandler used for writing, NULL for default (may be MIO_RAW_WRITE or MIO_SSL_WRITE)
pfhandler used for parsing, NULL for default (may be MIO_RAW_PARSER or MIO_XML_PARSER)
Returns:
new instance of mio_handlers

References MIO_RAW_PARSER, MIO_RAW_READ, MIO_RAW_WRITE, mio_handlers_st::p, mio_handlers_st::parser, pmalloco(), pool_new, mio_handlers_st::read, and mio_handlers_st::write.

Referenced by mio_connect(), mio_listen(), and pthsock_client().

void mio_init ( void  )
void mio_karma ( mio  m,
int  val,
int  max,
int  inc,
int  dec,
int  penalty,
int  restore 
)
void mio_karma2 ( mio  m,
struct karma k 
)

copy karma to a mio socket

Parameters:
mthe mio to copy the karma to
kthe karma to copy to the mio

References mio_st::k, and karma_copy().

Referenced by dialback(), mio_new(), and pthsock_client().

mio mio_listen ( int  port,
char const *  listen_host,
mio_std_cb  cb,
void *  arg,
mio_handlers  mh 
)

call to start listening with select

Parameters:
portport to listen at
listen_hostIPv4 or IPv6 address to listen at
cbapplication callback function
argargument to pass to the application callback function
mhmio_handlers used for this connection
Returns:
the listening mio object that has been created, NULL on failure

References log_alert(), log_debug2, LOGT_IO, make_netsocket(), mio_handlers_new(), mio_new(), NETSOCKET_SERVER, mio_st::our_ip, mio_st::p, pstrdup(), mio_st::type, type_LISTEN, and ZONE.

Referenced by dialback(), xmppd::proxy65::proxy65::proxy65(), and pthsock_client().

mio mio_new ( int  fd,
mio_std_cb  cb,
void *  arg,
mio_handlers  mh 
)

creates a new mio object from a file descriptor

Parameters:
fdthe file descriptor the caller already has
cbthe callback function, MIO should call on events
argthe argument MIO should pass to the callback function, when calling it
mhwhich mio_handlers MIO should use for this connection
Returns:
pointer to the new MIO object, NULL on failure

References mio_st::cb, mio_st::cb_arg, mio_st::fd, mio_main_st::k, log_debug2, LOGT_EXECFLOW, mio_karma2(), mio_rate(), mio_set_handlers(), mio_st::p, pmalloco(), pool_new, mio_main_st::rate_p, mio_main_st::rate_t, mio_st::state, state_ACTIVE, mio_st::type, type_NORMAL, ZONE, mio_main_st::zzz, and mio_main_st::zzz_active.

Referenced by mio_listen().

void mio_rate ( mio  m,
int  rate_time,
int  max_points 
)

sets connection rate limits

References mio_st::flags, jlimit_free(), jlimit_new(), mio_st::rate, and mio_st::rated.

Referenced by dialback(), mio_new(), and pthsock_client().

void mio_reset ( mio  m,
mio_std_cb  cb,
void *  arg 
)

resets the callback function

Parameters:
mthe mio to update the callback function for
cbthe new callback function
argthe new argument MIO should pass to the callback function

References mio_st::cb, and mio_st::cb_arg.

Referenced by xmppd::proxy65::connected_sockets::connected_sockets(), dialback_in_read(), dialback_in_read_db(), dialback_out_read(), and xmppd::proxy65::socks5stub::socks5stub().

void mio_set_handlers ( mio  m,
mio_handlers  mh 
)

reset the handlers of a mio structure

Parameters:
mthe mio to set the handlers for
mhthe new handlers to set

References mio_st::mh, and mio_handlers_free().

Referenced by mio_new().

void mio_stop ( void  )

Cleanup function when server is shutting down, closes all sockets, so that everything can be cleaned up properly.

References log_debug2, LOGT_CLEANUP, mio_main_st::master__list, mio_st::next, mio_main_st::p, pool_free(), mio_main_st::shutdown, mio_main_st::t, and ZONE.

void mio_write ( mio  m,
xmlnode  stanza,
char const *  buffer,
int  len 
)

writes a str, or XML stanza to the client socket

You can only write the xmlnode OR the buffer to the mio. If the buffer argument is not equal to NULL, the buffer is used and the xmlnode is ignored.

Parameters:
mthe mio to write the data to
stanzaxmlnode containing the stanza, that should be written to a stream (gets freed after the data has been written)
bufferpointer to a buffer of characters, that should be written to the connection
lennumber of bytes contained in the buffer, that should be written (-1 to write a zero terminated string contained in the buffer)

References mio_wb_q_st::cur, mio_wb_q_st::data, mio_wb_q_st::len, log_debug2, LOGT_EXECFLOW, LOGT_IO, LOGT_STRANGE, mio_wb_q_st::next, mio_st::out_ns, mio_wb_q_st::p, pmalloco(), pool_free(), pool_new, mio_st::queue, queue_CDATA, queue_XMLNODE, mio_st::tail, mio_st::type, mio_wb_q_st::type, type_NUL, mio_wb_q_st::x, xmlnode_pool(), xmlnode_serialize_string(), ZONE, mio_main_st::zzz, and mio_main_st::zzz_active.

Referenced by _dialback_beat_idle(), _dialback_beat_in_idle(), _dialback_beat_out_idle(), _mio_xml_parser(), xmppd::proxy65::connected_sockets::connected_sockets(), dialback_check_settings(), dialback_in_read(), dialback_in_read_db(), dialback_in_verify(), dialback_miod_write(), dialback_out_connection(), dialback_out_packet(), dialback_out_read(), dialback_out_read_db(), mio_write_root(), and xmppd::resolver::resolver::send_query().

void mio_write_root ( mio  m,
xmlnode  root,
int  stream_type 
)

write the start tag for the root element to a stream

Parameters:
mthe mio of the stream where to write the start tag for the root element to
rootthe root element (freed by this function)
stream_typetype of stream: 0 for 'jabber:server', 1 for 'jabber:client', 2 for 'jabber:component:accept'

References mio_write(), NS_CLIENT, NS_COMPONENT_ACCEPT, NS_SERVER, NS_XMLNS, mio_st::out_ns, xmppd::ns_decl_list::update(), xmlnode_free(), xmlnode_get_attrib_ns(), and xstream_header_char().

Referenced by dialback_in_read(), and dialback_out_read().


Variable Documentation

this holds the parsed configuration file

ios mio__data = NULL

global data for mio