summaryrefslogtreecommitdiff
path: root/src/rexmpp.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/rexmpp.h')
-rw-r--r--src/rexmpp.h255
1 files changed, 135 insertions, 120 deletions
diff --git a/src/rexmpp.h b/src/rexmpp.h
index c6d4428..0aa6252 100644
--- a/src/rexmpp.h
+++ b/src/rexmpp.h
@@ -10,10 +10,10 @@
#define REXMPP_H
#include <stdint.h>
+#include <stdbool.h>
#include "config.h"
-#include <libxml/tree.h>
#ifdef HAVE_GPGME
#include <gpgme.h>
#endif
@@ -187,6 +187,8 @@ enum tls_pol {
typedef enum rexmpp_err rexmpp_err_t;
+#include "rexmpp_xml.h"
+#include "rexmpp_xml_parser.h"
#include "rexmpp_tcp.h"
#include "rexmpp_socks.h"
#include "rexmpp_dns.h"
@@ -207,8 +209,8 @@ typedef enum rexmpp_err rexmpp_err_t;
*/
typedef void (*rexmpp_iq_callback_t) (rexmpp_t *s,
void *cb_data,
- xmlNodePtr request,
- xmlNodePtr response,
+ rexmpp_xml_t *request,
+ rexmpp_xml_t *response,
int success);
typedef struct rexmpp_iq rexmpp_iq_t;
@@ -217,7 +219,7 @@ typedef struct rexmpp_iq rexmpp_iq_t;
struct rexmpp_iq
{
/** @brief The sent request. */
- xmlNodePtr request;
+ rexmpp_xml_t *request;
/** @brief A callback to call on reply. */
rexmpp_iq_callback_t cb;
/** @brief User-supplied data, to pass to a callback function. */
@@ -226,12 +228,31 @@ struct rexmpp_iq
rexmpp_iq_t *next;
};
+typedef struct rexmpp_muc_ping rexmpp_muc_ping_t;
+
+/** @brief MUC self-ping data. */
+struct rexmpp_muc_ping
+{
+ /** @brief Own occupant JID to ping. */
+ char *jid;
+ /** @brief Optional password to rejoin with. */
+ char *password;
+ /** @brief Ping delay, in seconds. */
+ unsigned int delay;
+ /** @brief Whether a ping is requested (pending) already. */
+ int requested;
+ /** @brief When the MUC was active. */
+ struct timespec last_activity;
+ rexmpp_muc_ping_t *next;
+};
+
typedef void (*log_function_t) (rexmpp_t *s, int priority, const char *format, va_list args);
typedef int (*sasl_property_cb_t) (rexmpp_t *s, rexmpp_sasl_property prop);
-typedef int (*xml_in_cb_t) (rexmpp_t *s, xmlNodePtr node);
-typedef int (*xml_out_cb_t) (rexmpp_t *s, xmlNodePtr node);
-typedef void (*roster_modify_cb_t) (rexmpp_t *s, xmlNodePtr item);
+typedef int (*xml_in_cb_t) (rexmpp_t *s, rexmpp_xml_t *node);
+typedef int (*xml_out_cb_t) (rexmpp_t *s, rexmpp_xml_t *node);
+typedef void (*roster_modify_cb_t) (rexmpp_t *s, rexmpp_xml_t *item);
typedef int (*console_print_cb_t) (rexmpp_t *s, const char *format, va_list args);
+typedef void (*socket_cb_t) (rexmpp_t *s, int socket);
/** @brief Complete connection state */
struct rexmpp
@@ -253,7 +274,7 @@ struct rexmpp
/* Manual host/port configuration. */
const char *manual_host;
uint16_t manual_port;
- int manual_direct_tls;
+ bool manual_direct_tls;
/* Miscellaneous settings */
const char *disco_node;
@@ -263,21 +284,23 @@ struct rexmpp
uint16_t socks_port;
/* Various knobs (these are used instead of loadable modules). */
- int enable_carbons; /* XEP-0280 */
- int manage_roster;
+ bool enable_carbons; /* XEP-0280 */
+ bool manage_roster;
const char *roster_cache_file;
- int track_roster_presence;
- int track_roster_events; /* XEP-0163 */
- int nick_notifications; /* XEP-0172 */
- int retrieve_openpgp_keys; /* XEP-0373 */
- int autojoin_bookmarked_mucs; /* XEP-0402 */
+ bool track_roster_presence;
+ bool track_roster_events; /* XEP-0163 */
+ bool nick_notifications; /* XEP-0172 */
+ bool retrieve_openpgp_keys; /* XEP-0373 */
+ bool autojoin_bookmarked_mucs; /* XEP-0402 */
enum tls_pol tls_policy;
- int enable_jingle;
+ bool enable_jingle;
const char *client_name; /* XEP-0030, XEP-0092 */
const char *client_type; /* XEP-0030 */
const char *client_version; /* XEP-0092 */
const char *local_address; /* For ICE, XEP-0176 */
- int jingle_prefer_rtcp_mux;
+ bool jingle_prefer_rtcp_mux;
+ /* A delay in seconds, to use for MUC self-ping by default */
+ unsigned int muc_ping_default_delay;
/* Resource limits. */
uint32_t stanza_queue_size;
@@ -286,6 +309,12 @@ struct rexmpp
uint32_t iq_cache_size;
uint32_t max_jingle_sessions;
+ /* X.509 settings: for TLS and DTLS, to use for SASL EXTERNAL
+ authentication and DTLS-SRTP on Jingle calls. */
+ const char *x509_key_file;
+ const char *x509_cert_file;
+ const char *x509_trust_file;
+
/* Callbacks. */
log_function_t log_function;
sasl_property_cb_t sasl_property_cb;
@@ -293,44 +322,48 @@ struct rexmpp
xml_out_cb_t xml_out_cb;
roster_modify_cb_t roster_modify_cb;
console_print_cb_t console_print_cb;
+ socket_cb_t socket_cb;
/* Stream-related state. */
struct rexmpp_jid assigned_jid;
- xmlNodePtr stream_features;
- xmlNodePtr roster_items;
+ rexmpp_xml_t *stream_features;
+ rexmpp_xml_t *roster_items;
char *roster_ver;
- xmlNodePtr roster_presence;
- xmlNodePtr roster_events;
+ rexmpp_xml_t *roster_presence;
+ rexmpp_xml_t *roster_events;
/* Other dynamic data. */
- xmlNodePtr disco_info;
+ rexmpp_xml_t *disco_info;
/* Includes Jingle RTP session candidates; rexmpp prioritizes the
ones listed earlier on incoming calls. */
- xmlNodePtr jingle_rtp_description;
+ rexmpp_xml_t *jingle_rtp_description;
/* IQs we're waiting for responses to. */
rexmpp_iq_t *active_iq;
/* Cached IQ requests and responses. */
- xmlNodePtr iq_cache;
+ rexmpp_xml_t *iq_cache;
/* Jingle context. */
- rexmpp_jingle_ctx_t jingle;
+ rexmpp_jingle_ctx_t *jingle;
/* Connection and stream management. */
unsigned int reconnect_number;
time_t reconnect_seconds;
- struct timeval next_reconnect_time;
- xmlNodePtr stanza_queue;
+ struct timespec next_reconnect_time;
+ rexmpp_xml_t *stanza_queue;
uint32_t stanzas_out_count;
uint32_t stanzas_out_acknowledged;
uint32_t stanzas_in_count;
char *stream_id;
/* Server ping configuration and state. */
- int ping_delay;
- int ping_requested;
- time_t last_network_activity;
+ unsigned int ping_delay;
+ bool ping_requested;
+ struct timespec last_network_activity;
+
+ /* MUC self-ping */
+ rexmpp_muc_ping_t *muc_ping;
/* DNS-related structures. */
rexmpp_dns_ctx_t resolver;
@@ -348,7 +381,7 @@ struct rexmpp
int server_socket;
/* Whether the address it's connected to was verified with
DNSSEC. */
- int server_socket_dns_secure;
+ bool server_socket_dns_secure;
/* A structure used to establish a TCP connection. */
rexmpp_tcp_conn_t server_connection;
@@ -359,34 +392,42 @@ struct rexmpp
NULL if there is anything in the send queue). Not appending data
to it, see send_queue for queuing. */
char *send_buffer;
- ssize_t send_buffer_len;
- ssize_t send_buffer_sent;
+ size_t send_buffer_len;
+ size_t send_buffer_sent;
/* A queue of XML elements to send. */
- xmlNodePtr send_queue;
+ rexmpp_xml_t *send_queue;
+
+ /* An input queue of parsed XML structures. */
+ rexmpp_xml_t *input_queue;
+ rexmpp_xml_t *input_queue_last;
/* XML parser context, and current element pointer for building
XML nodes with a SAX2 parser interface. */
- xmlParserCtxtPtr xml_parser;
- xmlNodePtr current_element_root;
- xmlNodePtr current_element;
- xmlNodePtr input_queue;
- xmlNodePtr input_queue_last;
+ rexmpp_xml_parser_ctx_t xml_parser;
+
+ /* The children are stored in reverse order during building. */
+ rexmpp_xml_t *current_element_root;
+ rexmpp_xml_t *current_element;
/* TLS structures. */
- rexmpp_tls_t tls;
+ rexmpp_tls_t *tls;
/* SASL structures. */
- rexmpp_sasl_ctx_t sasl;
+ rexmpp_sasl_ctx_t *sasl;
/* OpenPGP structures */
#ifdef HAVE_GPGME
gpgme_ctx_t pgp_ctx;
+#else
+ void *pgp_ctx;
#endif
/* curl structures */
#ifdef HAVE_CURL
CURLM *curl_multi;
+#else
+ void *curl_multi;
#endif
};
@@ -429,7 +470,7 @@ rexmpp_err_t rexmpp_stop (rexmpp_t *s);
@param[in] node An XML element to send. The library assumes
ownership of the element, so it must not be freed by the caller.
*/
-rexmpp_err_t rexmpp_send (rexmpp_t *s, xmlNodePtr node);
+rexmpp_err_t rexmpp_send (rexmpp_t *s, rexmpp_xml_t *node);
/**
@brief Prepare and send a new info/query request.
@@ -448,7 +489,7 @@ rexmpp_err_t rexmpp_send (rexmpp_t *s, xmlNodePtr node);
rexmpp_err_t rexmpp_iq_new (rexmpp_t *s,
const char *type,
const char *to,
- xmlNodePtr payload,
+ rexmpp_xml_t *payload,
rexmpp_iq_callback_t cb,
void *cb_data);
@@ -460,7 +501,7 @@ rexmpp_err_t rexmpp_iq_new (rexmpp_t *s,
rexmpp_err_t rexmpp_cached_iq_new (rexmpp_t *s,
const char *type,
const char *to,
- xmlNodePtr payload,
+ rexmpp_xml_t *payload,
rexmpp_iq_callback_t cb,
void *cb_data,
int fresh);
@@ -469,9 +510,9 @@ rexmpp_err_t rexmpp_cached_iq_new (rexmpp_t *s,
@brief Reply to an IQ.
*/
void rexmpp_iq_reply (rexmpp_t *s,
- xmlNodePtr req,
+ rexmpp_xml_t *req,
const char *type,
- xmlNodePtr payload);
+ rexmpp_xml_t *payload);
/**
@brief Determines the maximum time to wait before the next
@@ -479,13 +520,13 @@ void rexmpp_iq_reply (rexmpp_t *s,
@param[in] s ::rexmpp
@param[in] max_tv An existing timeout (can be NULL), to return if
there's no more urgent timeouts.
- @param[in,out] tv An allocated timeval structure, to store the time
- in.
+ @param[in,out] tv An allocated timespec structure, to store the
+ time in.
@returns A pointer to either max_tv or tv.
*/
-struct timeval *rexmpp_timeout (rexmpp_t *s,
- struct timeval *max_tv,
- struct timeval *tv);
+struct timespec *rexmpp_timeout (rexmpp_t *s,
+ struct timespec *max_tv,
+ struct timespec *tv);
/**
@brief Sets file descriptors to watch.
@@ -500,35 +541,6 @@ struct timeval *rexmpp_timeout (rexmpp_t *s,
int rexmpp_fds (rexmpp_t *s, fd_set *read_fds, fd_set *write_fds);
/**
- @brief Compose an 'error' element.
-*/
-xmlNodePtr rexmpp_xml_error (const char *type, const char *condition);
-
-/**
- @brief A helper function for XML parsing.
- @param[in] str A string to parse.
- @param[in] str_len String length.
- @returns Parsed XML, or NULL on failure.
-*/
-xmlNodePtr rexmpp_xml_parse (const char *str, int str_len);
-
-/**
- @brief A helper function for XML serialisation.
- @param[in] node An XML node.
- @returns A string (must be freed by the caller).
-*/
-char *rexmpp_xml_serialize (xmlNodePtr node);
-
-/**
- @brief Adds an "id" attribute to an XML stanza.
- @param[in,out] s ::rexmpp
- @param[in] node A pointer to an XML stanza.
- @returns The same pointer as on input, for more convenient
- composition.
-*/
-xmlNodePtr rexmpp_xml_add_id (rexmpp_t *s, xmlNodePtr node);
-
-/**
@brief The logging function.
@param[in] s ::rexmpp
@param[in] priority A syslog priority.
@@ -547,42 +559,6 @@ void rexmpp_log (rexmpp_t *s, int priority, const char *format, ...);
char *rexmpp_get_name (rexmpp_t *s, const char *jid_str);
/**
- @brief Compares two XML elements.
-*/
-int rexmpp_xml_eq (xmlNodePtr n1, xmlNodePtr n2);
-
-/**
- @brief Matches an XML node against a namespace and an element name.
- @param[in] node An XML node to match.
- @param[in] namespace An XML namespace. Can be NULL (matches
- anything), and it is assumed that the default namespace is
- "jabber:client" (so if it is "jabber:client" and an element doesn't
- have a namespace defined, this function counts that as a match).
- @param[in] name Element name. Can be NULL (matches anything).
- @returns 1 on a successful match, 0 otherwise.
-*/
-int rexmpp_xml_match (xmlNodePtr node,
- const char *namespace,
- const char *name);
-
-/**
- @brief Finds a child element of an XML node, which matches the
- given namespace and name.
- @param[in] node The node containing child nodes.
- @param[in] namespace The namespace to look for.
- @param[in] name The element name to look for.
- @returns A pointer to the first matching child node, or NULL if no
- matching child elements found.
-*/
-xmlNodePtr rexmpp_xml_find_child (xmlNodePtr node,
- const char *namespace,
- const char *name);
-
-xmlNodePtr rexmpp_xml_new_node (const char *name, const char *namespace);
-
-char *rexmpp_gen_id (rexmpp_t *s);
-
-/**
@brief Finds a PEP event.
@param[in] s ::rexmpp
@param[in] from JID.
@@ -591,10 +567,10 @@ char *rexmpp_gen_id (rexmpp_t *s);
@returns A pointer to the message announcing an event, or NULL on
failure.
*/
-xmlNodePtr rexmpp_find_event (rexmpp_t *s,
- const char *from,
- const char *node,
- xmlNodePtr *prev_event);
+rexmpp_xml_t *rexmpp_find_event (rexmpp_t *s,
+ const char *from,
+ const char *node,
+ rexmpp_xml_t **prev_event);
void rexmpp_console_feed (rexmpp_t *s, char *str, ssize_t str_len);
@@ -632,4 +608,43 @@ rexmpp_disco_find_feature (rexmpp_t *s,
int fresh,
int max_requests);
+/**
+ @brief Add a MUC JID to self-ping
+ @param[in,out] s ::rexmpp
+ @param[in] jid Own occupant JID to ping
+ @param[in] password Optional password to rejoin with
+ @param[in] delay How often to ping, in seconds
+*/
+rexmpp_err_t rexmpp_muc_ping_set (rexmpp_t *s,
+ const char *occupant_jid,
+ const char *password,
+ unsigned int delay);
+
+/**
+ @brief Remove a MUC JID to self-ping
+ @param[in,out] s ::rexmpp
+ @param[in] jid Own occupant JID
+*/
+rexmpp_err_t rexmpp_muc_ping_remove (rexmpp_t *s,
+ const char *occupant_jid);
+
+/**
+ @brief Join a MUC, optionally setting self-ping
+ @param[in,out] s ::rexmpp
+ @param[in] occupant_jid Occupant JID
+ @param[in] password Optional password
+ @param[in] ping_delay MUC self-ping delay, 0 to not set it
+*/
+rexmpp_err_t rexmpp_muc_join (rexmpp_t *s,
+ const char *occupant_jid,
+ const char *password,
+ unsigned int ping_delay);
+
+/**
+ @brief Leave a MUC, stop self-pinging it
+ @param[in,out] s ::rexmpp
+ @param[in] occupant_jid Occupant JID
+*/
+rexmpp_err_t rexmpp_muc_leave (rexmpp_t *s, const char *occupant_jid);
+
#endif