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_st * | connect_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__ |
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 struct mio_connect_st _connect_data |
internal structure holding data of the destination where we connect to
| typedef struct mio_connect_st * connect_data |
| 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
| m | the connection that should get it's write queue dumped |
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().
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().
| m | the mio stream to get the last xmlnode stanza in the write queue for. |
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 | ) |
client call to close the socket
| m | the socket, that should be closed |
References log_debug2, LOGT_EXECFLOW, mio_st::state, state_CLOSE, 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(), dialback_check_settings(), dialback_in_read(), dialback_in_read_db(), dialback_out_read(), dialback_out_read_db(), and mio_ssl_starttls().
| 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
| host | the host where to connect to (either a IPv4 or IPv6) | |
| port | the port number to connect to | |
| cb | the application callback function | |
| cb_arg | argument to pass to the application callback function | |
| timeout | how long to wait for a connection to be established (0 for using the default value) | |
| mh | the 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
| mh | the 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!
| rf | handler used for reading, NULL for default (may be MIO_RAW_READ or MIO_SSL_READ) | |
| wf | handler used for writing, NULL for default (may be MIO_RAW_WRITE or MIO_SSL_WRITE) | |
| pf | handler used for parsing, NULL for default (may be MIO_RAW_PARSER or MIO_XML_PARSER) |
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 | ) |
Initialize manged I/O handling
This must be called before MIO is used
References mio_main_st::bounce_uri, karma::dec, mio_main_st::flash_policy, karma::inc, j_atoi(), mio_main_st::k, KARMA_DEC, KARMA_HEARTBEAT, KARMA_INC, KARMA_INIT, KARMA_MAX, karma_new(), KARMA_PENALTY, KARMA_RESETMETER, KARMA_RESTORE, log_warn(), karma::max, mio_ssl_init(), NS_JABBERD_CONFIGFILE, mio_main_st::p, karma::penalty, pmalloco(), pool_new, pstrdup(), mio_main_st::rate_p, mio_main_st::rate_t, register_beat(), karma::reset_meter, karma::restore, mio_main_st::t, karma::val, mio_main_st::webserver_path, xhash_free(), xhash_new(), xhash_put(), xmlnode_get_attrib_ns(), xmlnode_get_data(), xmlnode_get_list_item(), xmlnode_get_tags(), xmlnode_serialize_string(), and mio_main_st::zzz.
Referenced by main().
| void mio_karma | ( | mio | m, | |
| int | val, | |||
| int | max, | |||
| int | inc, | |||
| int | dec, | |||
| int | penalty, | |||
| int | restore | |||
| ) |
sets karma values
References karma::dec, karma::inc, mio_st::k, karma::max, karma::penalty, karma::restore, and karma::val.
copy karma to a mio socket
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
| port | port to listen at | |
| listen_host | IPv4 or IPv6 address to listen at | |
| cb | application callback function | |
| arg | argument to pass to the application callback function | |
| mh | mio_handlers used for this connection |
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
| fd | the file descriptor the caller already has | |
| cb | the callback function, MIO should call on events | |
| arg | the argument MIO should pass to the callback function, when calling it | |
| mh | which mio_handlers MIO should use for this connection |
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
| m | the mio to update the callback function for | |
| cb | the new callback function | |
| arg | the 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
| m | the mio to set the handlers for | |
| mh | the 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.
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.
| m | the mio to write the data to | |
| stanza | xmlnode containing the stanza, that should be written to a stream (gets freed after the data has been written) | |
| buffer | pointer to a buffer of characters, that should be written to the connection | |
| len | number 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().
write the start tag for the root element to a stream
| m | the mio of the stream where to write the start tag for the root element to | |
| root | the root element (freed by this function) | |
| stream_type | type 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().
this holds the parsed configuration file
1.6.1