XMPP client and component module. More...
#include "asterisk.h"#include <ctype.h>#include <iksemel.h>#include "asterisk/xmpp.h"#include "asterisk/module.h"#include "asterisk/manager.h"#include "asterisk/app.h"#include "asterisk/message.h"#include "asterisk/event.h"#include "asterisk/cli.h"#include "asterisk/config_options.h"
Go to the source code of this file.
Data Structures | |
| struct | ast_xmpp_client_config |
| XMPP Client Configuration. More... | |
| struct | ast_xmpp_global_config |
| XMPP Global Configuration. More... | |
| struct | xmpp_config |
| struct | xmpp_pak_handler |
| Defined handlers for different PAK types. More... | |
| struct | xmpp_state_handler |
| Defined handlers for XMPP client states. More... | |
Defines | |
| #define | BUDDY_BUCKETS 53 |
| Number of buckets for buddies (per client) | |
| #define | CLIENT_BUCKETS 53 |
| Number of buckets for client connections. | |
| #define | RESOURCE_BUCKETS 53 |
| Number of buckets for resources (per buddy) | |
| #define | STATUS_DISAPPEAR 6 |
| Status for a disappearing buddy. | |
| #define | XMPP_TLS_NS "urn:ietf:params:xml:ns:xmpp-tls" |
| Namespace for TLS support. | |
Enumerations | |
| enum | { XMPP_AUTOPRUNE = (1 << 0), XMPP_AUTOREGISTER = (1 << 1), XMPP_AUTOACCEPT = (1 << 2), XMPP_DEBUG = (1 << 3), XMPP_USETLS = (1 << 4), XMPP_USESASL = (1 << 5), XMPP_FORCESSL = (1 << 6), XMPP_KEEPALIVE = (1 << 7), XMPP_COMPONENT = (1 << 8), XMPP_SEND_TO_DIALPLAN = (1 << 9), XMPP_DISTRIBUTE_EVENTS = (1 << 10) } |
| Supported general configuration flags. More... | |
| enum | { XMPP_XEP0248 = (1 << 0), XMPP_PUBSUB = (1 << 1), XMPP_PUBSUB_AUTOCREATE = (1 << 2) } |
| Supported pubsub configuration flags. More... | |
Functions | |
| static void | __reg_module (void) |
| static void | __unreg_module (void) |
| static int | acf_jabberreceive_read (struct ast_channel *chan, const char *name, char *data, char *buf, size_t buflen) |
| static int | acf_jabberstatus_read (struct ast_channel *chan, const char *name, char *data, char *buf, size_t buflen) |
| static | AO2_GLOBAL_OBJ_STATIC (globals) |
| int | ast_xmpp_chatroom_invite (struct ast_xmpp_client *client, const char *user, const char *room, const char *message) |
| Invite a user to an XMPP multi-user chatroom. | |
| int | ast_xmpp_chatroom_join (struct ast_xmpp_client *client, const char *room, const char *nickname) |
| Join an XMPP multi-user chatroom. | |
| int | ast_xmpp_chatroom_leave (struct ast_xmpp_client *client, const char *room, const char *nickname) |
| Leave an XMPP multi-user chatroom. | |
| int | ast_xmpp_chatroom_send (struct ast_xmpp_client *client, const char *nickname, const char *address, const char *message) |
| Send a message to an XMPP multi-user chatroom. | |
| static void * | ast_xmpp_client_config_alloc (const char *cat) |
| Allocator function for configuration. | |
| static void | ast_xmpp_client_config_destructor (void *obj) |
| Destructor function for configuration. | |
| int | ast_xmpp_client_disconnect (struct ast_xmpp_client *client) |
| Disconnect an XMPP client connection. | |
| struct ast_xmpp_client * | ast_xmpp_client_find (const char *name) |
| Find an XMPP client connection using a given name. | |
| void | ast_xmpp_client_lock (struct ast_xmpp_client *client) |
| Lock an XMPP client connection. | |
| int | ast_xmpp_client_send (struct ast_xmpp_client *client, iks *stanza) |
| Send an XML stanza out using an established XMPP client connection. | |
| int | ast_xmpp_client_send_message (struct ast_xmpp_client *client, const char *user, const char *message) |
| Send a message to a given user using an established XMPP client connection. | |
| void | ast_xmpp_client_unlock (struct ast_xmpp_client *client) |
| Unlock an XMPP client connection. | |
| void | ast_xmpp_client_unref (struct ast_xmpp_client *client) |
| Release XMPP client connection reference. | |
| void | ast_xmpp_increment_mid (char *mid) |
| Helper function which increments the message identifier. | |
| static int | client_bitfield_handler (const struct aco_option *opt, struct ast_variable *var, void *obj) |
| static int | client_buddy_handler (const struct aco_option *opt, struct ast_variable *var, void *obj) |
| static int | client_status_handler (const struct aco_option *opt, struct ast_variable *var, void *obj) |
| CONFIG_INFO_STANDARD (cfg_info, globals, xmpp_config_alloc,.files=ACO_FILES(&res_xmpp_conf),.post_apply_config=xmpp_config_post_apply,) | |
| static int | delete_old_messages (struct ast_xmpp_client *client, char *from) |
| static int | global_bitfield_handler (const struct aco_option *opt, struct ast_variable *var, void *obj) |
| static int | load_module (void) |
| static int | manager_jabber_send (struct mansession *s, const struct message *m) |
| static int | reload (void) |
| static int | unload_module (void) |
| static int | xmpp_action_hook (void *data, int type, iks *node) |
| Action hook for when things occur. | |
| static int | xmpp_buddy_cmp (void *obj, void *arg, int flags) |
| Comparator function for XMPP buddy. | |
| static void | xmpp_buddy_destructor (void *obj) |
| Destructor callback function for XMPP buddy. | |
| static int | xmpp_buddy_hash (const void *obj, const int flags) |
| Hashing function for XMPP buddy. | |
| static char * | xmpp_cli_create_collection (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| Method to expose PubSub collection node creation via CLI. | |
| static char * | xmpp_cli_create_leafnode (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| Method to expose PubSub leaf node creation via CLI. | |
| static char * | xmpp_cli_delete_pubsub_node (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| Method to expose PubSub node deletion via CLI. | |
| static char * | xmpp_cli_list_pubsub_nodes (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| static char * | xmpp_cli_purge_pubsub_nodes (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| Method to purge PubSub nodes via CLI. | |
| static struct ast_xmpp_client * | xmpp_client_alloc (const char *name) |
| Allocator function for ast_xmpp_client. | |
| static int | xmpp_client_authenticate (struct ast_xmpp_client *client, struct ast_xmpp_client_config *cfg, int type, iks *node) |
| Internal function called when we need to authenticate. | |
| static int | xmpp_client_authenticate_digest (struct ast_xmpp_client *client, struct ast_xmpp_client_config *cfg, int type, iks *node) |
| Internal function called when we need to authenticate using non-SASL. | |
| static int | xmpp_client_authenticate_sasl (struct ast_xmpp_client *client, struct ast_xmpp_client_config *cfg, int type, iks *node) |
| Internal function called when we need to authenticate using SASL. | |
| static int | xmpp_client_authenticating (struct ast_xmpp_client *client, struct ast_xmpp_client_config *cfg, int type, iks *node) |
| Internal function called when we are authenticating. | |
| static void | xmpp_client_change_state (struct ast_xmpp_client *client, int state) |
| Internal function which changes the XMPP client state. | |
| static int | xmpp_client_config_merge_buddies (void *obj, void *arg, int flags) |
| static int | xmpp_client_config_post_apply (void *obj, void *arg, int flags) |
| static struct ast_xmpp_buddy * | xmpp_client_create_buddy (struct ao2_container *container, const char *id) |
| Internal function which creates a buddy on a client. | |
| static void | xmpp_client_destructor (void *obj) |
| Destructor callback function for XMPP client. | |
| static void * | xmpp_client_find_or_create (const char *category) |
| Look up existing client or create a new one. | |
| static int | xmpp_client_receive (struct ast_xmpp_client *client, unsigned int timeout) |
| Internal function which receives data from the XMPP client connection. | |
| static int | xmpp_client_reconnect (struct ast_xmpp_client *client) |
| Internal function used to reconnect an XMPP client to its server. | |
| static int | xmpp_client_request_tls (struct ast_xmpp_client *client, struct ast_xmpp_client_config *cfg, int type, iks *node) |
| Internal function called when we need to request TLS support. | |
| static int | xmpp_client_requested_tls (struct ast_xmpp_client *client, struct ast_xmpp_client_config *cfg, int type, iks *node) |
| Internal function called when we receive a response to our TLS initiation request. | |
| static int | xmpp_client_send_disco_info_request (struct ast_xmpp_client *client, const char *to, const char *from) |
| Helper function which sends a discovery information request to a user. | |
| static int | xmpp_client_send_message (struct ast_xmpp_client *client, int group, const char *nick, const char *address, const char *message) |
| Internal function used to send a message to a user or chatroom. | |
| static int | xmpp_client_send_raw_message (struct ast_xmpp_client *client, const char *message) |
| Internal function which sends a raw message. | |
| static int | xmpp_client_service_discovery_get_hook (void *data, ikspak *pak) |
| Hook function called when client receives a service discovery get message. | |
| static int | xmpp_client_service_discovery_result_hook (void *data, ikspak *pak) |
| Hook function called when client receives a service discovery result message. | |
| static int | xmpp_client_set_group_presence (struct ast_xmpp_client *client, const char *room, int level, const char *nick) |
| static void | xmpp_client_set_presence (struct ast_xmpp_client *client, const char *to, const char *from, int level, const char *desc) |
| Internal function which changes the presence status of an XMPP client. | |
| static int | xmpp_client_subscribe_user (void *obj, void *arg, int flags) |
| Callback function which subscribes to a user if needed. | |
| static void * | xmpp_client_thread (void *data) |
| XMPP client connection thread. | |
| static int | xmpp_client_unsubscribe_user (struct ast_xmpp_client *client, const char *user) |
| Helper function which unsubscribes a user and removes them from the roster. | |
| static int | xmpp_component_authenticate (struct ast_xmpp_client *client, struct ast_xmpp_client_config *cfg, int type, iks *node) |
| Internal function called when we should authenticate as a component. | |
| static int | xmpp_component_authenticating (struct ast_xmpp_client *client, struct ast_xmpp_client_config *cfg, int type, iks *node) |
| Internal function called when we authenticated as a component. | |
| static int | xmpp_component_register_get_hook (void *data, ikspak *pak) |
| Hook function called when the component is queried about registration. | |
| static int | xmpp_component_register_set_hook (void *data, ikspak *pak) |
| Hook function called when someone registers to the component. | |
| static int | xmpp_component_service_discovery_get_hook (void *data, ikspak *pak) |
| Hook function called when component receives a service discovery get message. | |
| static int | xmpp_component_service_discovery_items_hook (void *data, ikspak *pak) |
| Hook function called when we receive a service discovery items request. | |
| static void * | xmpp_config_alloc (void) |
| Allocator for XMPP configuration. | |
| static int | xmpp_config_cmp (void *obj, void *arg, int flags) |
| Comparator function for configuration. | |
| static void | xmpp_config_destructor (void *obj) |
| Destructor for XMPP configuration. | |
| static void * | xmpp_config_find (struct ao2_container *tmp_container, const char *category) |
| Find function for configuration. | |
| static int | xmpp_config_hash (const void *obj, const int flags) |
| Hashing function for configuration. | |
| static void | xmpp_config_post_apply (void) |
| static int | xmpp_config_prelink (void *newitem) |
| static int | xmpp_connect_hook (void *data, ikspak *pak) |
| Hook function called when client finishes authenticating with the server. | |
| static char * | xmpp_do_set_debug (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| static void | xmpp_init_event_distribution (struct ast_xmpp_client *client) |
| Initialize collections for event distribution. | |
| static int | xmpp_io_recv (struct ast_xmpp_client *client, char *buffer, size_t buf_len, int timeout) |
| Internal function which polls on an XMPP client and receives data. | |
| static int | xmpp_is_secure (struct ast_xmpp_client *client) |
| Helper function which returns whether an XMPP client connection is secure or not. | |
| static int | xmpp_join_exec (struct ast_channel *chan, const char *data) |
| Application to join a chat room. | |
| static int | xmpp_leave_exec (struct ast_channel *chan, const char *data) |
| Application to leave a chat room. | |
| static void | xmpp_log_hook (void *data, const char *xmpp, size_t size, int incoming) |
| Logging hook function. | |
| static void | xmpp_message_destroy (struct ast_xmpp_message *message) |
| Destroy function for XMPP messages. | |
| static int | xmpp_pak_message (struct ast_xmpp_client *client, struct ast_xmpp_client_config *cfg, iks *node, ikspak *pak) |
| Internal function called when a message is received. | |
| static int | xmpp_pak_presence (struct ast_xmpp_client *client, struct ast_xmpp_client_config *cfg, iks *node, ikspak *pak) |
| Internal function called when a presence message is received. | |
| static int | xmpp_pak_s10n (struct ast_xmpp_client *client, struct ast_xmpp_client_config *cfg, iks *node, ikspak *pak) |
| Internal function called when a subscription message is received. | |
| static int | xmpp_ping_request (struct ast_xmpp_client *client, const char *to, const char *from) |
| Helper function which sends a ping request to a server. | |
| static iks * | xmpp_pubsub_build_node_config (iks *pubsub, const char *node_type, const char *collection_name) |
| static iks * | xmpp_pubsub_build_node_request (struct ast_xmpp_client *client, const char *collection) |
| Build the a node request. | |
| static iks * | xmpp_pubsub_build_publish_skeleton (struct ast_xmpp_client *client, const char *node, const char *event_type, unsigned int cachable) |
| Build the skeleton of a publish. | |
| static void | xmpp_pubsub_create_affiliations (struct ast_xmpp_client *client, const char *node) |
| Add Owner affiliations for pubsub node. | |
| static void | xmpp_pubsub_create_collection (struct ast_xmpp_client *client, const char *collection_name) |
| Create a PubSub collection node. | |
| static void | xmpp_pubsub_create_leaf (struct ast_xmpp_client *client, const char *collection_name, const char *leaf_name) |
| Create a PubSub leaf node. | |
| static void | xmpp_pubsub_create_node (struct ast_xmpp_client *client, const char *node_type, const char *name, const char *collection_name) |
| Create a pubsub node. | |
| static void | xmpp_pubsub_delete_node (struct ast_xmpp_client *client, const char *node_name) |
| Delete a PubSub node. | |
| static int | xmpp_pubsub_delete_node_list (void *data, ikspak *pak) |
| Delete pubsub item lists. | |
| static void | xmpp_pubsub_devstate_cb (const struct ast_event *ast_event, void *data) |
| Callback function for device state events. | |
| static int | xmpp_pubsub_handle_error (void *data, ikspak *pak) |
| static int | xmpp_pubsub_handle_event (void *data, ikspak *pak) |
| Callback for handling PubSub events. | |
| static iks * | xmpp_pubsub_iq_create (struct ast_xmpp_client *client, const char *type) |
| Create an IQ packet. | |
| static void | xmpp_pubsub_mwi_cb (const struct ast_event *ast_event, void *data) |
| Callback function for MWI events. | |
| static void | xmpp_pubsub_publish_device_state (struct ast_xmpp_client *client, const char *device, const char *device_state, unsigned int cachable) |
| Publish device state to a PubSub node. | |
| static void | xmpp_pubsub_publish_mwi (struct ast_xmpp_client *client, const char *mailbox, const char *context, const char *oldmsgs, const char *newmsgs) |
| Publish MWI to a PubSub node. | |
| static void | xmpp_pubsub_purge_nodes (struct ast_xmpp_client *client, const char *collection_name) |
| static int | xmpp_pubsub_receive_node_list (void *data, ikspak *pak) |
| Receive pubsub item lists. | |
| static void | xmpp_pubsub_request_nodes (struct ast_xmpp_client *client, const char *collection) |
| Request item list from pubsub. | |
| static void | xmpp_pubsub_subscribe (struct ast_xmpp_client *client, const char *node) |
| Subscribe to a PubSub node. | |
| static void | xmpp_pubsub_unsubscribe (struct ast_xmpp_client *client, const char *node) |
| Unsubscribe from a PubSub node. | |
| static int | xmpp_resource_cmp (void *obj, void *arg, int flags) |
| Comparator function for XMPP resource. | |
| static void | xmpp_resource_destructor (void *obj) |
| Destructor callback function for XMPP resource. | |
| static int | xmpp_resource_hash (const void *obj, const int flags) |
| Hashing function for XMPP resource. | |
| static int | xmpp_resource_immediate (void *obj, void *arg, int flags) |
| Internal astobj2 callback function which returns the first resource, which is the highest priority one. | |
| static int | xmpp_roster_hook (void *data, ikspak *pak) |
| Hook function called when roster is received from server. | |
| static int | xmpp_send_cb (const struct ast_msg *msg, const char *to, const char *from) |
| static int | xmpp_send_exec (struct ast_channel *chan, const char *data) |
| static int | xmpp_send_stream_header (struct ast_xmpp_client *client, const struct ast_xmpp_client_config *cfg, const char *to) |
| Helper function which sends an XMPP stream header to the server. | |
| static int | xmpp_sendgroup_exec (struct ast_channel *chan, const char *data) |
| Application to send a message to a groupchat. | |
| static char * | xmpp_show_buddies (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| static char * | xmpp_show_clients (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| static int | xmpp_status_exec (struct ast_channel *chan, const char *data) |
Variables | |
| static struct ast_module_info | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER , .description = "Asterisk XMPP Interface" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .reload = reload, .load_pri = AST_MODPRI_CHANNEL_DEPEND, } |
| static const char * | app_ajijoin = "JabberJoin" |
| static const char * | app_ajileave = "JabberLeave" |
| static const char * | app_ajisend = "JabberSend" |
| static const char * | app_ajisendgroup = "JabberSendGroup" |
| static const char * | app_ajistatus = "JabberStatus" |
| static struct ast_module_info * | ast_module_info = &__mod_info |
| static struct aco_type | client_option |
| struct aco_type * | client_options [] = ACO_TYPES(&client_option) |
| static int | debug |
| Global debug status. | |
| static struct aco_type | global_option |
| struct aco_type * | global_options [] = ACO_TYPES(&global_option) |
| static struct ast_custom_function | jabberreceive_function |
| static struct ast_custom_function | jabberstatus_function |
| static ast_cond_t | message_received_condition |
| static ast_mutex_t | messagelock |
| static struct ast_msg_tech | msg_tech |
| struct aco_file | res_xmpp_conf |
| static struct ast_cli_entry | xmpp_cli [] |
| static struct xmpp_pak_handler | xmpp_pak_handlers [] |
| static struct xmpp_state_handler | xmpp_state_handlers [] |
XMPP client and component module.
A reference module for interfacting Asterisk directly as a client or component with an XMPP/Jabber compliant server.
This module is based upon the original res_jabber as done by Matt O'Gorman.
Definition in file res_xmpp.c.
| #define BUDDY_BUCKETS 53 |
Number of buckets for buddies (per client)
Definition at line 310 of file res_xmpp.c.
Referenced by ast_xmpp_client_config_alloc(), and xmpp_client_alloc().
| #define CLIENT_BUCKETS 53 |
Number of buckets for client connections.
Definition at line 307 of file res_xmpp.c.
| #define RESOURCE_BUCKETS 53 |
Number of buckets for resources (per buddy)
Definition at line 313 of file res_xmpp.c.
Referenced by xmpp_client_create_buddy().
| #define STATUS_DISAPPEAR 6 |
Status for a disappearing buddy.
Definition at line 319 of file res_xmpp.c.
Referenced by xmpp_pak_presence().
| #define XMPP_TLS_NS "urn:ietf:params:xml:ns:xmpp-tls" |
Namespace for TLS support.
Definition at line 316 of file res_xmpp.c.
| anonymous enum |
Supported general configuration flags.
| XMPP_AUTOPRUNE | |
| XMPP_AUTOREGISTER | |
| XMPP_AUTOACCEPT | |
| XMPP_DEBUG | |
| XMPP_USETLS | |
| XMPP_USESASL | |
| XMPP_FORCESSL | |
| XMPP_KEEPALIVE | |
| XMPP_COMPONENT | |
| XMPP_SEND_TO_DIALPLAN | |
| XMPP_DISTRIBUTE_EVENTS |
Definition at line 285 of file res_xmpp.c.
{
XMPP_AUTOPRUNE = (1 << 0),
XMPP_AUTOREGISTER = (1 << 1),
XMPP_AUTOACCEPT = (1 << 2),
XMPP_DEBUG = (1 << 3),
XMPP_USETLS = (1 << 4),
XMPP_USESASL = (1 << 5),
XMPP_FORCESSL = (1 << 6),
XMPP_KEEPALIVE = (1 << 7),
XMPP_COMPONENT = (1 << 8),
XMPP_SEND_TO_DIALPLAN = (1 << 9),
XMPP_DISTRIBUTE_EVENTS = (1 << 10),
};
| anonymous enum |
Supported pubsub configuration flags.
Definition at line 300 of file res_xmpp.c.
{
XMPP_XEP0248 = (1 << 0),
XMPP_PUBSUB = (1 << 1),
XMPP_PUBSUB_AUTOCREATE = (1 << 2),
};
| static void __reg_module | ( | void | ) | [static] |
Definition at line 4484 of file res_xmpp.c.
| static void __unreg_module | ( | void | ) | [static] |
Definition at line 4484 of file res_xmpp.c.
| static int acf_jabberreceive_read | ( | struct ast_channel * | chan, |
| const char * | name, | ||
| char * | data, | ||
| char * | buf, | ||
| size_t | buflen | ||
| ) | [static] |
Definition at line 1865 of file res_xmpp.c.
References ao2_cleanup, ao2_global_obj_ref, args, ast_xmpp_message::arrived, AST_APP_ARG, ast_autoservice_start(), ast_autoservice_stop(), ast_channel_name(), ast_cond_timedwait, ast_copy_string(), ast_debug, AST_DECLARE_APP_ARGS, AST_LIST_EMPTY, AST_LIST_LOCK, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_LIST_UNLOCK, ast_log(), ast_mutex_lock, ast_mutex_unlock, AST_NONSTANDARD_APP_ARGS, AST_STANDARD_APP_ARGS, ast_strlen_zero(), ast_tv(), ast_tvadd(), ast_tvdiff_ms(), ast_tvdiff_sec(), ast_tvnow(), ast_xmpp_message::from, globals, LOG_NOTICE, LOG_WARNING, ast_xmpp_message::message, parse(), xmpp_config_find(), XMPP_MAX_JIDLEN, and xmpp_message_destroy().
{
RAII_VAR(struct xmpp_config *, cfg, ao2_global_obj_ref(globals), ao2_cleanup);
RAII_VAR(struct ast_xmpp_client_config *, clientcfg, NULL, ao2_cleanup);
char *parse = NULL;
int timeout, jidlen, resourcelen, found = 0;
struct timeval start;
long diff = 0;
struct ast_xmpp_message *message;
AST_DECLARE_APP_ARGS(args,
AST_APP_ARG(account);
AST_APP_ARG(jid);
AST_APP_ARG(timeout);
);
AST_DECLARE_APP_ARGS(jid,
AST_APP_ARG(screenname);
AST_APP_ARG(resource);
);
if (ast_strlen_zero(data)) {
ast_log(LOG_WARNING, "%s requires arguments (account,jid[,timeout])\n", name);
return -1;
}
parse = ast_strdupa(data);
AST_STANDARD_APP_ARGS(args, parse);
if (args.argc < 2 || args.argc > 3) {
ast_log(LOG_WARNING, "%s requires arguments (account,jid[,timeout])\n", name);
return -1;
}
parse = ast_strdupa(args.jid);
AST_NONSTANDARD_APP_ARGS(jid, parse, '/');
if (jid.argc < 1 || jid.argc > 2 || strlen(args.jid) > XMPP_MAX_JIDLEN) {
ast_log(LOG_WARNING, "Invalid JID : %s\n", parse);
return -1;
}
if (ast_strlen_zero(args.timeout)) {
timeout = 20;
} else {
sscanf(args.timeout, "%d", &timeout);
if (timeout <= 0) {
ast_log(LOG_WARNING, "Invalid timeout specified: '%s'\n", args.timeout);
return -1;
}
}
jidlen = strlen(jid.screenname);
resourcelen = ast_strlen_zero(jid.resource) ? 0 : strlen(jid.resource);
if (!cfg || !cfg->clients || !(clientcfg = xmpp_config_find(cfg->clients, args.account))) {
ast_log(LOG_WARNING, "Could not find client %s, exiting\n", args.account);
return -1;
}
ast_debug(3, "Waiting for an XMPP message from %s\n", args.jid);
start = ast_tvnow();
if (chan && ast_autoservice_start(chan) < 0) {
ast_log(LOG_WARNING, "Cannot start autoservice for channel %s\n", ast_channel_name(chan));
return -1;
}
/* search the messages list, grab the first message that matches with
* the from JID we're expecting, and remove it from the messages list */
while (diff < timeout) {
struct timespec ts = { 0, };
struct timeval wait;
int res = 0;
wait = ast_tvadd(start, ast_tv(timeout, 0));
ts.tv_sec = wait.tv_sec;
ts.tv_nsec = wait.tv_usec * 1000;
/* wait up to timeout seconds for an incoming message */
ast_mutex_lock(&messagelock);
if (AST_LIST_EMPTY(&clientcfg->client->messages)) {
res = ast_cond_timedwait(&message_received_condition, &messagelock, &ts);
}
ast_mutex_unlock(&messagelock);
if (res == ETIMEDOUT) {
ast_debug(3, "No message received from %s in %d seconds\n", args.jid, timeout);
break;
}
AST_LIST_LOCK(&clientcfg->client->messages);
AST_LIST_TRAVERSE_SAFE_BEGIN(&clientcfg->client->messages, message, list) {
if (jid.argc == 1) {
/* no resource provided, compare bare JIDs */
if (strncasecmp(jid.screenname, message->from, jidlen)) {
continue;
}
} else {
/* resource appended, compare bare JIDs and resources */
char *resource = strchr(message->from, '/');
if (!resource || strlen(resource) == 0) {
ast_log(LOG_WARNING, "Remote JID has no resource : %s\n", message->from);
if (strncasecmp(jid.screenname, message->from, jidlen)) {
continue;
}
} else {
resource ++;
if (strncasecmp(jid.screenname, message->from, jidlen) || strncmp(jid.resource, resource, resourcelen)) {
continue;
}
}
}
/* check if the message is not too old */
if (ast_tvdiff_sec(ast_tvnow(), message->arrived) >= clientcfg->message_timeout) {
ast_debug(3, "Found old message from %s, deleting it\n", message->from);
AST_LIST_REMOVE_CURRENT(list);
xmpp_message_destroy(message);
continue;
}
found = 1;
ast_copy_string(buf, message->message, buflen);
AST_LIST_REMOVE_CURRENT(list);
xmpp_message_destroy(message);
break;
}
AST_LIST_TRAVERSE_SAFE_END;
AST_LIST_UNLOCK(&clientcfg->client->messages);
if (found) {
break;
}
/* check timeout */
diff = ast_tvdiff_ms(ast_tvnow(), start);
}
if (chan && ast_autoservice_stop(chan) < 0) {
ast_log(LOG_WARNING, "Cannot stop autoservice for channel %s\n", ast_channel_name(chan));
}
/* return if we timed out */
if (!found) {
ast_log(LOG_NOTICE, "Timed out : no message received from %s\n", args.jid);
return -1;
}
return 0;
}
| static int acf_jabberstatus_read | ( | struct ast_channel * | chan, |
| const char * | name, | ||
| char * | data, | ||
| char * | buf, | ||
| size_t | buflen | ||
| ) | [static] |
Definition at line 1578 of file res_xmpp.c.
References ao2_callback, ao2_cleanup, ao2_find, ao2_global_obj_ref, ao2_ref, args, AST_APP_ARG, AST_DECLARE_APP_ARGS, ast_log(), AST_NONSTANDARD_APP_ARGS, AST_STANDARD_APP_ARGS, ast_strlen_zero(), globals, LOG_ERROR, LOG_NOTICE, LOG_WARNING, OBJ_KEY, OBJ_NODATA, ast_xmpp_resource::resource, ast_xmpp_buddy::resources, ast_xmpp_resource::status, xmpp_config_find(), xmpp_resource_cmp(), and xmpp_resource_immediate().
{
RAII_VAR(struct xmpp_config *, cfg, ao2_global_obj_ref(globals), ao2_cleanup);
RAII_VAR(struct ast_xmpp_client_config *, clientcfg, NULL, ao2_cleanup);
struct ast_xmpp_buddy *buddy;
struct ast_xmpp_resource *resource;
int stat = 7;
AST_DECLARE_APP_ARGS(args,
AST_APP_ARG(sender);
AST_APP_ARG(jid);
);
AST_DECLARE_APP_ARGS(jid,
AST_APP_ARG(screenname);
AST_APP_ARG(resource);
);
if (ast_strlen_zero(data)) {
ast_log(LOG_ERROR, "Usage: JABBER_STATUS(<sender>,<jid>[/<resource>])\n");
return 0;
}
AST_STANDARD_APP_ARGS(args, data);
if (args.argc != 2) {
ast_log(LOG_ERROR, "JABBER_STATUS requires 2 arguments: sender and jid.\n");
return -1;
}
AST_NONSTANDARD_APP_ARGS(jid, args.jid, '/');
if (jid.argc < 1 || jid.argc > 2) {
ast_log(LOG_WARNING, "Wrong JID %s, exiting\n", args.jid);
return -1;
}
if (!cfg || !cfg->clients || !(clientcfg = xmpp_config_find(cfg->clients, args.sender))) {
ast_log(LOG_WARNING, "Could not find sender connection: '%s'\n", args.sender);
return -1;
}
if (!(buddy = ao2_find(clientcfg->client->buddies, jid.screenname, OBJ_KEY))) {
ast_log(LOG_WARNING, "Could not find buddy in list: '%s'\n", jid.screenname);
return -1;
}
if (ast_strlen_zero(jid.resource) || !(resource = ao2_callback(buddy->resources, 0, xmpp_resource_cmp, jid.resource))) {
resource = ao2_callback(buddy->resources, OBJ_NODATA, xmpp_resource_immediate, NULL);
}
ao2_ref(buddy, -1);
if (resource) {
stat = resource->status;
ao2_ref(resource, -1);
} else {
ast_log(LOG_NOTICE, "Resource %s of buddy %s was not found.\n", jid.resource, jid.screenname);
}
snprintf(buf, buflen, "%d", stat);
return 0;
}
| static AO2_GLOBAL_OBJ_STATIC | ( | globals | ) | [static] |
| int ast_xmpp_chatroom_invite | ( | struct ast_xmpp_client * | client, |
| const char * | user, | ||
| const char * | room, | ||
| const char * | message | ||
| ) |
Invite a user to an XMPP multi-user chatroom.
| client | Pointer to the client |
| user | JID of the user |
| room | Name of the chatroom |
| message | Message to send with the invitation |
| 0 | on success |
| -1 | on failure |
Definition at line 791 of file res_xmpp.c.
References ast_xmpp_client_lock(), ast_xmpp_client_send(), ast_xmpp_client_unlock(), ast_xmpp_increment_mid(), and ast_xmpp_client::mid.
{
int res = 0;
iks *invite, *body = NULL, *namespace = NULL;
if (!(invite = iks_new("message")) || !(body = iks_new("body")) || !(namespace = iks_new("x"))) {
res = -1;
goto done;
}
iks_insert_attrib(invite, "to", user);
ast_xmpp_client_lock(client);
iks_insert_attrib(invite, "id", client->mid);
ast_xmpp_increment_mid(client->mid);
ast_xmpp_client_unlock(client);
iks_insert_cdata(body, message, 0);
iks_insert_node(invite, body);
iks_insert_attrib(namespace, "xmlns", "jabber:x:conference");
iks_insert_attrib(namespace, "jid", room);
iks_insert_node(invite, namespace);
res = ast_xmpp_client_send(client, invite);
done:
iks_delete(namespace);
iks_delete(body);
iks_delete(invite);
return res;
}
| int ast_xmpp_chatroom_join | ( | struct ast_xmpp_client * | client, |
| const char * | room, | ||
| const char * | nickname | ||
| ) |
Join an XMPP multi-user chatroom.
| client | Pointer to the client |
| room | Name of the chatroom |
| nickname | Nickname to use |
| 0 | on success |
| -1 | on failure |
Definition at line 858 of file res_xmpp.c.
References xmpp_client_set_group_presence().
Referenced by xmpp_join_exec().
{
return xmpp_client_set_group_presence(client, room, IKS_SHOW_AVAILABLE, nickname);
}
| int ast_xmpp_chatroom_leave | ( | struct ast_xmpp_client * | client, |
| const char * | room, | ||
| const char * | nickname | ||
| ) |
Leave an XMPP multi-user chatroom.
| client | Pointer to the client |
| room | Name of the chatroom |
| nickname | Nickname being used |
| 0 | on success |
| -1 | on failure |
Definition at line 868 of file res_xmpp.c.
References xmpp_client_set_group_presence().
Referenced by xmpp_leave_exec().
{
return xmpp_client_set_group_presence(client, room, IKS_SHOW_UNAVAILABLE, nickname);
}
| int ast_xmpp_chatroom_send | ( | struct ast_xmpp_client * | client, |
| const char * | nickname, | ||
| const char * | address, | ||
| const char * | message | ||
| ) |
Send a message to an XMPP multi-user chatroom.
| client | Pointer to the client |
| nickname | Nickname to use |
| Address | Address of the room |
| message | Message itself |
| 0 | on success |
| -1 | on failure |
Definition at line 863 of file res_xmpp.c.
References xmpp_client_send_message().
Referenced by xmpp_sendgroup_exec().
{
return xmpp_client_send_message(client, 1, nickname, address, message);
}
| static void* ast_xmpp_client_config_alloc | ( | const char * | cat | ) | [static] |
Allocator function for configuration.
Definition at line 528 of file res_xmpp.c.
References ao2_alloc, ao2_container_alloc, ao2_ref, ast_string_field_init, ast_string_field_set, ast_xmpp_client_config_destructor(), ast_xmpp_client_config::buddies, BUDDY_BUCKETS, ast_xmpp_client_config::client, name, xmpp_buddy_cmp(), xmpp_buddy_hash(), and xmpp_client_find_or_create().
{
struct ast_xmpp_client_config *cfg;
if (!(cfg = ao2_alloc(sizeof(*cfg), ast_xmpp_client_config_destructor))) {
return NULL;
}
if (ast_string_field_init(cfg, 512)) {
ao2_ref(cfg, -1);
return NULL;
}
if (!(cfg->client = xmpp_client_find_or_create(cat))) {
ao2_ref(cfg, -1);
return NULL;
}
if (!(cfg->buddies = ao2_container_alloc(BUDDY_BUCKETS, xmpp_buddy_hash, xmpp_buddy_cmp))) {
ao2_ref(cfg, -1);
return NULL;
}
ast_string_field_set(cfg, name, cat);
return cfg;
}
| static void ast_xmpp_client_config_destructor | ( | void * | obj | ) | [static] |
Destructor function for configuration.
Definition at line 405 of file res_xmpp.c.
References ao2_cleanup, ast_string_field_free_memory, ast_xmpp_client_config::buddies, and ast_xmpp_client_config::client.
Referenced by ast_xmpp_client_config_alloc().
{
struct ast_xmpp_client_config *cfg = obj;
ast_string_field_free_memory(cfg);
ao2_cleanup(cfg->client);
ao2_cleanup(cfg->buddies);
}
| int ast_xmpp_client_disconnect | ( | struct ast_xmpp_client * | client | ) |
Disconnect an XMPP client connection.
| client | Pointer to the client |
| 0 | on success |
| -1 | on failure |
Definition at line 3395 of file res_xmpp.c.
References ast_event_unsubscribe(), AST_PTHREADT_NULL, ast_xmpp_client::device_state_sub, ast_xmpp_client::mwi_sub, ast_xmpp_client::parser, SECURE, ast_xmpp_client::ssl_context, ast_xmpp_client::ssl_session, ast_xmpp_client::state, ast_xmpp_client::stream_flags, ast_xmpp_client::thread, xmpp_pubsub_unsubscribe(), XMPP_STATE_DISCONNECTED, and XMPP_STATE_DISCONNECTING.
Referenced by xmpp_client_config_post_apply(), xmpp_client_destructor(), and xmpp_client_reconnect().
{
if ((client->thread != AST_PTHREADT_NULL) && !pthread_equal(pthread_self(), client->thread)) {
client->state = XMPP_STATE_DISCONNECTING;
pthread_join(client->thread, NULL);
client->thread = AST_PTHREADT_NULL;
}
if (client->mwi_sub) {
ast_event_unsubscribe(client->mwi_sub);
client->mwi_sub = NULL;
xmpp_pubsub_unsubscribe(client, "message_waiting");
}
if (client->device_state_sub) {
ast_event_unsubscribe(client->device_state_sub);
client->device_state_sub = NULL;
xmpp_pubsub_unsubscribe(client, "device_state");
}
#ifdef HAVE_OPENSSL
if (client->stream_flags & SECURE) {
SSL_shutdown(client->ssl_session);
SSL_CTX_free(client->ssl_context);
SSL_free(client->ssl_session);
}
client->stream_flags = 0;
#endif
if (client->parser) {
iks_disconnect(client->parser);
}
client->state = XMPP_STATE_DISCONNECTED;
return 0;
}
| struct ast_xmpp_client* ast_xmpp_client_find | ( | const char * | name | ) | [read] |
Find an XMPP client connection using a given name.
| name | Name of the client connection |
| non-NULL | on success |
| NULL | on failure |
Definition at line 729 of file res_xmpp.c.
References ao2_cleanup, ao2_global_obj_ref, ao2_ref, globals, and xmpp_config_find().
Referenced by custom_connection_handler().
{
RAII_VAR(struct xmpp_config *, cfg, ao2_global_obj_ref(globals), ao2_cleanup);
RAII_VAR(struct ast_xmpp_client_config *, clientcfg, NULL, ao2_cleanup);
if (!cfg || !cfg->clients || !(clientcfg = xmpp_config_find(cfg->clients, name))) {
return NULL;
}
ao2_ref(clientcfg->client, +1);
return clientcfg->client;
}
| void ast_xmpp_client_lock | ( | struct ast_xmpp_client * | client | ) |
Lock an XMPP client connection.
| client | Pointer to the client |
Definition at line 747 of file res_xmpp.c.
References ao2_lock.
Referenced by ast_xmpp_chatroom_invite(), xmpp_client_authenticate_digest(), xmpp_client_authenticating(), xmpp_client_send_disco_info_request(), xmpp_component_register_set_hook(), xmpp_pak_message(), xmpp_ping_request(), and xmpp_pubsub_iq_create().
{
ao2_lock(client);
}
| int ast_xmpp_client_send | ( | struct ast_xmpp_client * | client, |
| iks * | stanza | ||
| ) |
Send an XML stanza out using an established XMPP client connection.
| client | Pointer to the client |
| stanza | Pointer to the Iksemel stanza |
| 0 | on success |
| -1 | on failure |
Definition at line 2468 of file res_xmpp.c.
References xmpp_client_send_raw_message().
Referenced by ast_xmpp_chatroom_invite(), jingle_send_error_response(), jingle_send_response(), jingle_send_session_action(), jingle_send_session_info(), jingle_send_session_terminate(), jingle_send_transport_info(), xmpp_client_authenticate_digest(), xmpp_client_authenticate_sasl(), xmpp_client_authenticating(), xmpp_client_send_disco_info_request(), xmpp_client_send_message(), xmpp_client_service_discovery_get_hook(), xmpp_client_set_group_presence(), xmpp_client_set_presence(), xmpp_client_subscribe_user(), xmpp_client_unsubscribe_user(), xmpp_component_register_get_hook(), xmpp_component_register_set_hook(), xmpp_component_service_discovery_get_hook(), xmpp_component_service_discovery_items_hook(), xmpp_connect_hook(), xmpp_pak_s10n(), xmpp_ping_request(), xmpp_pubsub_create_affiliations(), xmpp_pubsub_create_node(), xmpp_pubsub_delete_node(), xmpp_pubsub_handle_error(), xmpp_pubsub_publish_device_state(), xmpp_pubsub_publish_mwi(), xmpp_pubsub_purge_nodes(), xmpp_pubsub_request_nodes(), xmpp_pubsub_subscribe(), and xmpp_pubsub_unsubscribe().
{
return xmpp_client_send_raw_message(client, iks_string(iks_stack(stanza), stanza));
}
| int ast_xmpp_client_send_message | ( | struct ast_xmpp_client * | client, |
| const char * | user, | ||
| const char * | message | ||
| ) |
Send a message to a given user using an established XMPP client connection.
| client | Pointer to the client |
| user | User the message should be sent to |
| message | The message to send |
| 0 | on success |
| -1 | on failure |
Definition at line 786 of file res_xmpp.c.
References xmpp_client_send_message().
Referenced by jingle_sendtext(), manager_jabber_send(), xmpp_send_cb(), and xmpp_send_exec().
{
return xmpp_client_send_message(client, 0, NULL, user, message);
}
| void ast_xmpp_client_unlock | ( | struct ast_xmpp_client * | client | ) |
Unlock an XMPP client connection.
| client | Pointer to the client |
Definition at line 752 of file res_xmpp.c.
References ao2_unlock.
Referenced by ast_xmpp_chatroom_invite(), xmpp_client_authenticate_digest(), xmpp_client_authenticating(), xmpp_client_send_disco_info_request(), xmpp_component_register_set_hook(), xmpp_pak_message(), xmpp_ping_request(), and xmpp_pubsub_iq_create().
{
ao2_unlock(client);
}
| void ast_xmpp_client_unref | ( | struct ast_xmpp_client * | client | ) |
Release XMPP client connection reference.
| client | Pointer to the client |
Definition at line 742 of file res_xmpp.c.
References ao2_ref.
Referenced by jingle_endpoint_destructor(), and jingle_session_destructor().
{
ao2_ref(client, -1);
}
| void ast_xmpp_increment_mid | ( | char * | mid | ) |
Helper function which increments the message identifier.
| mid | Pointer to a string containing the message identifier |
Definition at line 873 of file res_xmpp.c.
Referenced by ast_xmpp_chatroom_invite(), jingle_send_session_action(), jingle_send_session_info(), jingle_send_session_terminate(), jingle_send_transport_info(), xmpp_client_authenticate_digest(), xmpp_client_authenticating(), xmpp_client_send_disco_info_request(), xmpp_component_register_set_hook(), xmpp_ping_request(), and xmpp_pubsub_iq_create().
{
int i = 0;
for (i = strlen(mid) - 1; i >= 0; i--) {
if (mid[i] != 'z') {
mid[i] = mid[i] + 1;
i = 0;
} else {
mid[i] = 'a';
}
}
}
| static int client_bitfield_handler | ( | const struct aco_option * | opt, |
| struct ast_variable * | var, | ||
| void * | obj | ||
| ) | [static] |
Definition at line 4328 of file res_xmpp.c.
References ast_set2_flag, ast_true(), ast_xmpp_client_config::flags, ast_variable::name, ast_variable::value, XMPP_AUTOACCEPT, XMPP_AUTOPRUNE, XMPP_AUTOREGISTER, XMPP_COMPONENT, XMPP_DEBUG, XMPP_DISTRIBUTE_EVENTS, XMPP_FORCESSL, XMPP_KEEPALIVE, XMPP_SEND_TO_DIALPLAN, XMPP_USESASL, and XMPP_USETLS.
Referenced by load_module().
{
struct ast_xmpp_client_config *cfg = obj;
if (!strcasecmp(var->name, "debug")) {
ast_set2_flag(&cfg->flags, ast_true(var->value), XMPP_DEBUG);
} else if (!strcasecmp(var->name, "type")) {
ast_set2_flag(&cfg->flags, !strcasecmp(var->value, "component") ? 1 : 0, XMPP_COMPONENT);
} else if (!strcasecmp(var->name, "distribute_events")) {
ast_set2_flag(&cfg->flags, ast_true(var->value), XMPP_DISTRIBUTE_EVENTS);
} else if (!strcasecmp(var->name, "usetls")) {
ast_set2_flag(&cfg->flags, ast_true(var->value), XMPP_USETLS);
} else if (!strcasecmp(var->name, "usesasl")) {
ast_set2_flag(&cfg->flags, ast_true(var->value), XMPP_USESASL);
} else if (!strcasecmp(var->name, "forceoldssl")) {
ast_set2_flag(&cfg->flags, ast_true(var->value), XMPP_FORCESSL);
} else if (!strcasecmp(var->name, "keepalive")) {
ast_set2_flag(&cfg->flags, ast_true(var->value), XMPP_KEEPALIVE);
} else if (!strcasecmp(var->name, "autoprune")) {
ast_set2_flag(&cfg->flags, ast_true(var->value), XMPP_AUTOPRUNE);
} else if (!strcasecmp(var->name, "autoregister")) {
ast_set2_flag(&cfg->flags, ast_true(var->value), XMPP_AUTOREGISTER);
} else if (!strcasecmp(var->name, "auth_policy")) {
ast_set2_flag(&cfg->flags, !strcasecmp(var->value, "accept") ? 1 : 0, XMPP_AUTOACCEPT);
} else if (!strcasecmp(var->name, "sendtodialplan")) {
ast_set2_flag(&cfg->flags, ast_true(var->value), XMPP_SEND_TO_DIALPLAN);
} else {
return -1;
}
return 0;
}
| static int client_buddy_handler | ( | const struct aco_option * | opt, |
| struct ast_variable * | var, | ||
| void * | obj | ||
| ) | [static] |
Definition at line 4390 of file res_xmpp.c.
References ao2_find, ao2_ref, ast_xmpp_client_config::buddies, OBJ_KEY, ast_variable::value, and xmpp_client_create_buddy().
Referenced by load_module().
{
struct ast_xmpp_client_config *cfg = obj;
struct ast_xmpp_buddy *buddy;
if ((buddy = ao2_find(cfg->buddies, var->value, OBJ_KEY))) {
ao2_ref(buddy, -1);
return -1;
}
if (!(buddy = xmpp_client_create_buddy(cfg->buddies, var->value))) {
return -1;
}
ao2_ref(buddy, -1);
return 0;
}
| static int client_status_handler | ( | const struct aco_option * | opt, |
| struct ast_variable * | var, | ||
| void * | obj | ||
| ) | [static] |
Definition at line 4361 of file res_xmpp.c.
References ast_xmpp_client_config::status, and ast_variable::value.
Referenced by load_module().
{
struct ast_xmpp_client_config *cfg = obj;
if (!strcasecmp(var->value, "unavailable")) {
cfg->status = IKS_SHOW_UNAVAILABLE;
} else if (!strcasecmp(var->value, "available") || !strcasecmp(var->value, "online")) {
cfg->status = IKS_SHOW_AVAILABLE;
} else if (!strcasecmp(var->value, "chat") || !strcasecmp(var->value, "chatty")) {
cfg->status = IKS_SHOW_CHAT;
} else if (!strcasecmp(var->value, "away")) {
cfg->status = IKS_SHOW_AWAY;
} else if (!strcasecmp(var->value, "xa") || !strcasecmp(var->value, "xaway")) {
cfg->status = IKS_SHOW_XA;
} else if (!strcasecmp(var->value, "dnd")) {
cfg->status = IKS_SHOW_DND;
} else if (!strcasecmp(var->value, "invisible")) {
#ifdef IKS_SHOW_INVISIBLE
cfg->status = IKS_SHOW_INVISIBLE;
#else
cfg->status = IKS_SHOW_DND;
#endif
} else {
return -1;
}
return 0;
}
| CONFIG_INFO_STANDARD | ( | cfg_info | , |
| globals | , | ||
| xmpp_config_alloc | , | ||
| . | files = ACO_FILES(&res_xmpp_conf), |
||
| . | post_apply_config = xmpp_config_post_apply |
||
| ) |
| static int delete_old_messages | ( | struct ast_xmpp_client * | client, |
| char * | from | ||
| ) | [static] |
Definition at line 2024 of file res_xmpp.c.
References ao2_cleanup, ao2_global_obj_ref, ast_xmpp_message::arrived, AST_LIST_LOCK, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_LIST_UNLOCK, ast_tvdiff_sec(), ast_tvnow(), ast_xmpp_message::from, globals, ast_xmpp_message::list, ast_xmpp_client::messages, ast_xmpp_client::name, xmpp_config_find(), and xmpp_message_destroy().
Referenced by xmpp_pak_message().
{
RAII_VAR(struct xmpp_config *, cfg, ao2_global_obj_ref(globals), ao2_cleanup);
RAII_VAR(struct ast_xmpp_client_config *, clientcfg, NULL, ao2_cleanup);
int deleted = 0, isold = 0;
struct ast_xmpp_message *message = NULL;
if (!cfg || !cfg->clients || !(clientcfg = xmpp_config_find(cfg->clients, client->name))) {
return 0;
}
AST_LIST_LOCK(&client->messages);
AST_LIST_TRAVERSE_SAFE_BEGIN(&client->messages, message, list) {
if (isold) {
if (!from || !strncasecmp(from, message->from, strlen(from))) {
AST_LIST_REMOVE_CURRENT(list);
xmpp_message_destroy(message);
deleted++;
}
} else if (ast_tvdiff_sec(ast_tvnow(), message->arrived) >= clientcfg->message_timeout) {
isold = 1;
if (!from || !strncasecmp(from, message->from, strlen(from))) {
AST_LIST_REMOVE_CURRENT(list);
xmpp_message_destroy(message);
deleted++;
}
}
}
AST_LIST_TRAVERSE_SAFE_END;
AST_LIST_UNLOCK(&client->messages);
return deleted;
}
| static int global_bitfield_handler | ( | const struct aco_option * | opt, |
| struct ast_variable * | var, | ||
| void * | obj | ||
| ) | [static] |
Definition at line 4305 of file res_xmpp.c.
References ast_set2_flag, ast_true(), ast_xmpp_global_config::general, ast_variable::name, ast_xmpp_global_config::pubsub, ast_variable::value, XMPP_AUTOACCEPT, XMPP_AUTOPRUNE, XMPP_AUTOREGISTER, XMPP_PUBSUB_AUTOCREATE, and XMPP_XEP0248.
Referenced by load_module().
{
struct ast_xmpp_global_config *global = obj;
if (!strcasecmp(var->name, "debug")) {
debug = ast_true(var->value);
} else if (!strcasecmp(var->name, "autoprune")) {
ast_set2_flag(&global->general, ast_true(var->value), XMPP_AUTOPRUNE);
} else if (!strcasecmp(var->name, "autoregister")) {
ast_set2_flag(&global->general, ast_true(var->value), XMPP_AUTOREGISTER);
} else if (!strcasecmp(var->name, "auth_policy")) {
ast_set2_flag(&global->general, !strcasecmp(var->value, "accept") ? 1 : 0, XMPP_AUTOACCEPT);
} else if (!strcasecmp(var->name, "collection_nodes")) {
ast_set2_flag(&global->pubsub, ast_true(var->value), XMPP_XEP0248);
} else if (!strcasecmp(var->name, "pubsub_autocreate")) {
ast_set2_flag(&global->pubsub, ast_true(var->value), XMPP_PUBSUB_AUTOCREATE);
} else {
return -1;
}
return 0;
}
| static int load_module | ( | void | ) | [static] |
Definition at line 4409 of file res_xmpp.c.
References ACO_EXACT, aco_info_destroy(), aco_info_init(), aco_option_register, aco_option_register_custom, aco_process_config(), ACO_PROCESS_ERROR, ARRAY_LEN, ast_cli_register_multiple(), ast_cond_init, ast_custom_function_register, ast_manager_register_xml, AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, ast_msg_tech_register(), ast_mutex_init, ast_register_application_xml, client_bitfield_handler(), client_buddy_handler(), client_status_handler(), context, EVENT_FLAG_SYSTEM, FLDSET, global_bitfield_handler(), manager_jabber_send(), OPT_STRINGFIELD_T, OPT_UINT_T, STRFLDSET, xmpp_join_exec(), xmpp_leave_exec(), xmpp_send_exec(), xmpp_sendgroup_exec(), and xmpp_status_exec().
{
if (aco_info_init(&cfg_info)) {
return AST_MODULE_LOAD_DECLINE;
}
aco_option_register_custom(&cfg_info, "debug", ACO_EXACT, global_options, "no", global_bitfield_handler, 0);
aco_option_register_custom(&cfg_info, "autoprune", ACO_EXACT, global_options, "no", global_bitfield_handler, 0);
aco_option_register_custom(&cfg_info, "autoregister", ACO_EXACT, global_options, "yes", global_bitfield_handler, 0);
aco_option_register_custom(&cfg_info, "collection_nodes", ACO_EXACT, global_options, "no", global_bitfield_handler, 0);
aco_option_register_custom(&cfg_info, "pubsub_autocreate", ACO_EXACT, global_options, "no", global_bitfield_handler, 0);
aco_option_register_custom(&cfg_info, "auth_policy", ACO_EXACT, global_options, "accept", global_bitfield_handler, 0);
aco_option_register(&cfg_info, "username", ACO_EXACT, client_options, NULL, OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_xmpp_client_config, user));
aco_option_register(&cfg_info, "secret", ACO_EXACT, client_options, NULL, OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_xmpp_client_config, password));
aco_option_register(&cfg_info, "serverhost", ACO_EXACT, client_options, NULL, OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_xmpp_client_config, server));
aco_option_register(&cfg_info, "statusmessage", ACO_EXACT, client_options, "Online and Available", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_xmpp_client_config, statusmsg));
aco_option_register(&cfg_info, "pubsub_node", ACO_EXACT, client_options, NULL, OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_xmpp_client_config, pubsubnode));
aco_option_register(&cfg_info, "context", ACO_EXACT, client_options, "default", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_xmpp_client_config, context));
aco_option_register(&cfg_info, "priority", ACO_EXACT, client_options, "1", OPT_UINT_T, 0, FLDSET(struct ast_xmpp_client_config, priority));
aco_option_register(&cfg_info, "port", ACO_EXACT, client_options, "5222", OPT_UINT_T, 0, FLDSET(struct ast_xmpp_client_config, port));
aco_option_register(&cfg_info, "timeout", ACO_EXACT, client_options, "5", OPT_UINT_T, 0, FLDSET(struct ast_xmpp_client_config, message_timeout));
aco_option_register_custom(&cfg_info, "debug", ACO_EXACT, client_options, "no", client_bitfield_handler, 0);
aco_option_register_custom(&cfg_info, "type", ACO_EXACT, client_options, "client", client_bitfield_handler, 0);
aco_option_register_custom(&cfg_info, "distribute_events", ACO_EXACT, client_options, "no", client_bitfield_handler, 0);
aco_option_register_custom(&cfg_info, "usetls", ACO_EXACT, client_options, "yes", client_bitfield_handler, 0);
aco_option_register_custom(&cfg_info, "usesasl", ACO_EXACT, client_options, "yes", client_bitfield_handler, 0);
aco_option_register_custom(&cfg_info, "forceoldssl", ACO_EXACT, client_options, "no", client_bitfield_handler, 0);
aco_option_register_custom(&cfg_info, "keepalive", ACO_EXACT, client_options, "yes", client_bitfield_handler, 0);
aco_option_register_custom(&cfg_info, "autoprune", ACO_EXACT, client_options, "no", client_bitfield_handler, 0);
aco_option_register_custom(&cfg_info, "autoregister", ACO_EXACT, client_options, "yes", client_bitfield_handler, 0);
aco_option_register_custom(&cfg_info, "auth_policy", ACO_EXACT, client_options, "accept", client_bitfield_handler, 0);
aco_option_register_custom(&cfg_info, "sendtodialplan", ACO_EXACT, client_options, "no", client_bitfield_handler, 0);
aco_option_register_custom(&cfg_info, "status", ACO_EXACT, client_options, "available", client_status_handler, 0);
aco_option_register_custom(&cfg_info, "buddy", ACO_EXACT, client_options, NULL, client_buddy_handler, 0);
if (aco_process_config(&cfg_info, 0) == ACO_PROCESS_ERROR) {
aco_info_destroy(&cfg_info);
return AST_MODULE_LOAD_DECLINE;
}
ast_manager_register_xml("JabberSend", EVENT_FLAG_SYSTEM, manager_jabber_send);
ast_register_application_xml(app_ajisend, xmpp_send_exec);
ast_register_application_xml(app_ajisendgroup, xmpp_sendgroup_exec);
ast_register_application_xml(app_ajistatus, xmpp_status_exec);
ast_register_application_xml(app_ajijoin, xmpp_join_exec);
ast_register_application_xml(app_ajileave, xmpp_leave_exec);
ast_cli_register_multiple(xmpp_cli, ARRAY_LEN(xmpp_cli));
ast_custom_function_register(&jabberstatus_function);
ast_custom_function_register(&jabberreceive_function);
ast_msg_tech_register(&msg_tech);
ast_mutex_init(&messagelock);
ast_cond_init(&message_received_condition, NULL);
return AST_MODULE_LOAD_SUCCESS;
}
| static int manager_jabber_send | ( | struct mansession * | s, |
| const struct message * | m | ||
| ) | [static] |
Definition at line 3726 of file res_xmpp.c.
References ao2_cleanup, ao2_global_obj_ref, ast_strlen_zero(), ast_xmpp_client_send_message(), astman_append(), astman_get_header(), astman_send_ack(), astman_send_error(), globals, and xmpp_config_find().
Referenced by load_module().
{
RAII_VAR(struct xmpp_config *, cfg, ao2_global_obj_ref(globals), ao2_cleanup);
RAII_VAR(struct ast_xmpp_client_config *, clientcfg, NULL, ao2_cleanup);
const char *id = astman_get_header(m, "ActionID");
const char *jabber = astman_get_header(m, "Jabber");
const char *screenname = astman_get_header(m, "ScreenName");
const char *message = astman_get_header(m, "Message");
if (ast_strlen_zero(jabber)) {
astman_send_error(s, m, "No transport specified");
return 0;
}
if (ast_strlen_zero(screenname)) {
astman_send_error(s, m, "No ScreenName specified");
return 0;
}
if (ast_strlen_zero(message)) {
astman_send_error(s, m, "No Message specified");
return 0;
}
astman_send_ack(s, m, "Attempting to send Jabber Message");
if (!cfg || !cfg->clients || !(clientcfg = xmpp_config_find(cfg->clients, jabber))) {
astman_send_error(s, m, "Could not find Sender");
return 0;
}
if (strchr(screenname, '@') && !ast_xmpp_client_send_message(clientcfg->client, screenname, message)) {
astman_append(s, "Response: Success\r\n");
} else {
astman_append(s, "Response: Error\r\n");
}
if (!ast_strlen_zero(id)) {
astman_append(s, "ActionID: %s\r\n", id);
}
astman_append(s, "\r\n");
return 0;
}
| static int reload | ( | void | ) | [static] |
Definition at line 4470 of file res_xmpp.c.
References aco_process_config(), ACO_PROCESS_ERROR, and AST_MODULE_LOAD_DECLINE.
{
if (aco_process_config(&cfg_info, 1) == ACO_PROCESS_ERROR) {
return AST_MODULE_LOAD_DECLINE;
}
return 0;
}
| static int unload_module | ( | void | ) | [static] |
Definition at line 4284 of file res_xmpp.c.
References aco_info_destroy(), ao2_global_obj_release, ARRAY_LEN, ast_cli_unregister_multiple(), ast_cond_destroy, ast_custom_function_unregister(), ast_manager_unregister(), ast_msg_tech_unregister(), ast_mutex_destroy, ast_unregister_application(), and globals.
{
ast_msg_tech_unregister(&msg_tech);
ast_cli_unregister_multiple(xmpp_cli, ARRAY_LEN(xmpp_cli));
ast_unregister_application(app_ajisend);
ast_unregister_application(app_ajisendgroup);
ast_unregister_application(app_ajistatus);
ast_unregister_application(app_ajijoin);
ast_unregister_application(app_ajileave);
ast_manager_unregister("JabberSend");
ast_custom_function_unregister(&jabberstatus_function);
ast_custom_function_unregister(&jabberreceive_function);
aco_info_destroy(&cfg_info);
ao2_global_obj_release(globals);
ast_cond_destroy(&message_received_condition);
ast_mutex_destroy(&messagelock);
return 0;
}
| static int xmpp_action_hook | ( | void * | data, |
| int | type, | ||
| iks * | node | ||
| ) | [static] |
Action hook for when things occur.
Definition at line 3325 of file res_xmpp.c.
References ao2_cleanup, ao2_global_obj_ref, ARRAY_LEN, ast_log(), ast_test_flag, xmpp_state_handler::component, ast_xmpp_client::filter, globals, LOG_ERROR, ast_xmpp_client::name, ast_xmpp_client::state, xmpp_pak_handler::type, XMPP_COMPONENT, xmpp_config_find(), XMPP_MAX_ATTRLEN, xmpp_pak_handlers, XMPP_STATE_DISCONNECTING, and xmpp_state_handlers.
Referenced by xmpp_client_config_post_apply().
{
RAII_VAR(struct xmpp_config *, cfg, ao2_global_obj_ref(globals), ao2_cleanup);
RAII_VAR(struct ast_xmpp_client_config *, clientcfg, NULL, ao2_cleanup);
struct ast_xmpp_client *client = data;
ikspak *pak;
int i;
if (!node) {
ast_log(LOG_ERROR, "xmpp_action_hook was called without a packet\n");
return IKS_HOOK;
}
if (!cfg || !cfg->clients || !(clientcfg = xmpp_config_find(cfg->clients, client->name))) {
return IKS_HOOK;
}
/* If the client is disconnecting ignore everything */
if (client->state == XMPP_STATE_DISCONNECTING) {
return IKS_HOOK;
}
pak = iks_packet(node);
/* work around iksemel's impossibility to recognize node names
* containing a colon. Set the namespace of the corresponding
* node accordingly. */
if (iks_has_children(node) && strchr(iks_name(iks_child(node)), ':')) {
char *node_ns = NULL;
char attr[XMPP_MAX_ATTRLEN];
char *node_name = iks_name(iks_child(node));
char *aux = strchr(node_name, ':') + 1;
snprintf(attr, strlen("xmlns:") + (strlen(node_name) - strlen(aux)), "xmlns:%s", node_name);
node_ns = iks_find_attrib(iks_child(node), attr);
if (node_ns) {
pak->ns = node_ns;
pak->query = iks_child(node);
}
}
/* Process through any state handlers */
for (i = 0; i < ARRAY_LEN(xmpp_state_handlers); i++) {
if ((xmpp_state_handlers[i].state == client->state) && (xmpp_state_handlers[i].component == (ast_test_flag(&clientcfg->flags, XMPP_COMPONENT) ? 1 : 0))) {
if (xmpp_state_handlers[i].handler(client, clientcfg, type, node)) {
/* If the handler wants us to stop now, do so */
return IKS_HOOK;
}
break;
}
}
/* Process through any PAK handlers */
for (i = 0; i < ARRAY_LEN(xmpp_pak_handlers); i++) {
if (xmpp_pak_handlers[i].type == pak->type) {
if (xmpp_pak_handlers[i].handler(client, clientcfg, node, pak)) {
/* If the handler wants us to stop now, do so */
return IKS_HOOK;
}
break;
}
}
/* Send the packet through the filter in case any filters want to process it */
iks_filter_packet(client->filter, pak);
iks_delete(node);
return IKS_OK;
}
| static int xmpp_buddy_cmp | ( | void * | obj, |
| void * | arg, | ||
| int | flags | ||
| ) | [static] |
Comparator function for XMPP buddy.
Definition at line 460 of file res_xmpp.c.
References CMP_MATCH, CMP_STOP, ast_xmpp_buddy::id, and OBJ_KEY.
Referenced by ast_xmpp_client_config_alloc(), and xmpp_client_alloc().
{
struct ast_xmpp_buddy *buddy1 = obj, *buddy2 = arg;
const char *id = arg;
return !strcmp(buddy1->id, flags & OBJ_KEY ? id : buddy2->id) ? CMP_MATCH | CMP_STOP : 0;
}
| static void xmpp_buddy_destructor | ( | void * | obj | ) | [static] |
Destructor callback function for XMPP buddy.
Definition at line 710 of file res_xmpp.c.
References ao2_ref, and ast_xmpp_buddy::resources.
Referenced by xmpp_client_create_buddy().
{
struct ast_xmpp_buddy *buddy = obj;
if (buddy->resources) {
ao2_ref(buddy->resources, -1);
}
}
| static int xmpp_buddy_hash | ( | const void * | obj, |
| const int | flags | ||
| ) | [static] |
Hashing function for XMPP buddy.
Definition at line 451 of file res_xmpp.c.
References ast_str_hash(), ast_xmpp_buddy::id, and OBJ_KEY.
Referenced by ast_xmpp_client_config_alloc(), and xmpp_client_alloc().
{
const struct ast_xmpp_buddy *buddy = obj;
const char *id = obj;
return ast_str_hash(flags & OBJ_KEY ? id : buddy->id);
}
| static char* xmpp_cli_create_collection | ( | struct ast_cli_entry * | e, |
| int | cmd, | ||
| struct ast_cli_args * | a | ||
| ) | [static] |
Method to expose PubSub collection node creation via CLI.
Definition at line 4021 of file res_xmpp.c.
References ao2_cleanup, ao2_global_obj_ref, ast_cli_args::argc, ast_cli_args::argv, ast_cli(), CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, globals, name, ast_cli_entry::usage, xmpp_config_find(), and xmpp_pubsub_create_collection().
{
RAII_VAR(struct xmpp_config *, cfg, ao2_global_obj_ref(globals), ao2_cleanup);
RAII_VAR(struct ast_xmpp_client_config *, clientcfg, NULL, ao2_cleanup);
const char *name, *collection_name;
switch (cmd) {
case CLI_INIT:
e->command = "xmpp create collection";
e->usage =
"Usage: xmpp create collection <connection> <collection>\n"
" Creates a PubSub collection node using the account\n"
" as configured in xmpp.conf.\n";
return NULL;
case CLI_GENERATE:
return NULL;
}
if (a->argc != 5) {
return CLI_SHOWUSAGE;
}
name = a->argv[3];
collection_name = a->argv[4];
if (!cfg || !cfg->clients || !(clientcfg = xmpp_config_find(cfg->clients, name))) {
ast_cli(a->fd, "Unable to find client '%s'!\n", name);
return CLI_FAILURE;
}
ast_cli(a->fd, "Creating test PubSub node collection.\n");
xmpp_pubsub_create_collection(clientcfg->client, collection_name);
return CLI_SUCCESS;
}
| static char* xmpp_cli_create_leafnode | ( | struct ast_cli_entry * | e, |
| int | cmd, | ||
| struct ast_cli_args * | a | ||
| ) | [static] |
Method to expose PubSub leaf node creation via CLI.
Definition at line 4061 of file res_xmpp.c.
References ao2_cleanup, ao2_global_obj_ref, ast_cli_args::argc, ast_cli_args::argv, ast_cli(), CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, globals, name, ast_cli_entry::usage, xmpp_config_find(), and xmpp_pubsub_create_leaf().
{
RAII_VAR(struct xmpp_config *, cfg, ao2_global_obj_ref(globals), ao2_cleanup);
RAII_VAR(struct ast_xmpp_client_config *, clientcfg, NULL, ao2_cleanup);
const char *name, *collection_name, *leaf_name;
switch (cmd) {
case CLI_INIT:
e->command = "xmpp create leaf";
e->usage =
"Usage: xmpp create leaf <connection> <collection> <leaf>\n"
" Creates a PubSub leaf node using the account\n"
" as configured in xmpp.conf.\n";
return NULL;
case CLI_GENERATE:
return NULL;
}
if (a->argc != 6) {
return CLI_SHOWUSAGE;
}
name = a->argv[3];
collection_name = a->argv[4];
leaf_name = a->argv[5];
if (!cfg || !cfg->clients || !(clientcfg = xmpp_config_find(cfg->clients, name))) {
ast_cli(a->fd, "Unable to find client '%s'!\n", name);
return CLI_FAILURE;
}
ast_cli(a->fd, "Creating test PubSub node collection.\n");
xmpp_pubsub_create_leaf(clientcfg->client, collection_name, leaf_name);
return CLI_SUCCESS;
}
| static char* xmpp_cli_delete_pubsub_node | ( | struct ast_cli_entry * | e, |
| int | cmd, | ||
| struct ast_cli_args * | a | ||
| ) | [static] |
Method to expose PubSub node deletion via CLI.
| e | pointer to ast_cli_entry structure |
| cmd | |
| a | pointer to ast_cli_args structure |
Definition at line 3983 of file res_xmpp.c.
References ao2_cleanup, ao2_global_obj_ref, ast_cli_args::argc, ast_cli_args::argv, ast_cli(), CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, globals, name, ast_cli_entry::usage, xmpp_config_find(), and xmpp_pubsub_delete_node().
{
RAII_VAR(struct xmpp_config *, cfg, ao2_global_obj_ref(globals), ao2_cleanup);
RAII_VAR(struct ast_xmpp_client_config *, clientcfg, NULL, ao2_cleanup);
const char *name;
switch (cmd) {
case CLI_INIT:
e->command = "xmpp delete node";
e->usage =
"Usage: xmpp delete node <connection> <node>\n"
" Deletes a node on PubSub server\n"
" as configured in xmpp.conf.\n";
return NULL;
case CLI_GENERATE:
return NULL;
}
if (a->argc != 5) {
return CLI_SHOWUSAGE;
}
name = a->argv[3];
if (!cfg || !cfg->clients || !(clientcfg = xmpp_config_find(cfg->clients, name))) {
ast_cli(a->fd, "Unable to find client '%s'!\n", name);
return CLI_FAILURE;
}
xmpp_pubsub_delete_node(clientcfg->client, a->argv[4]);
return CLI_SUCCESS;
}
| static char* xmpp_cli_list_pubsub_nodes | ( | struct ast_cli_entry * | e, |
| int | cmd, | ||
| struct ast_cli_args * | a | ||
| ) | [static] |
Definition at line 3852 of file res_xmpp.c.
References ao2_cleanup, ao2_global_obj_ref, ast_cli_args::argc, ast_cli_args::argv, ast_cli(), CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, globals, name, ast_cli_entry::usage, xmpp_config_find(), and xmpp_pubsub_request_nodes().
{
RAII_VAR(struct xmpp_config *, cfg, ao2_global_obj_ref(globals), ao2_cleanup);
RAII_VAR(struct ast_xmpp_client_config *, clientcfg, NULL, ao2_cleanup);
const char *name = NULL, *collection = NULL;
switch (cmd) {
case CLI_INIT:
e->command = "xmpp list nodes";
e->usage =
"Usage: xmpp list nodes <connection> [collection]\n"
" Lists the user's nodes on the respective connection\n"
" ([connection] as configured in xmpp.conf.)\n";
return NULL;
case CLI_GENERATE:
return NULL;
}
if (a->argc > 5 || a->argc < 4) {
return CLI_SHOWUSAGE;
} else if (a->argc == 4 || a->argc == 5) {
name = a->argv[3];
}
if (a->argc == 5) {
collection = a->argv[4];
}
if (!cfg || !cfg->clients || !(clientcfg = xmpp_config_find(cfg->clients, name))) {
ast_cli(a->fd, "Unable to find client '%s'!\n", name);
return CLI_FAILURE;
}
ast_cli(a->fd, "Listing pubsub nodes.\n");
xmpp_pubsub_request_nodes(clientcfg->client, collection);
return CLI_SUCCESS;
}
| static char* xmpp_cli_purge_pubsub_nodes | ( | struct ast_cli_entry * | e, |
| int | cmd, | ||
| struct ast_cli_args * | a | ||
| ) | [static] |
Method to purge PubSub nodes via CLI.
| e | pointer to ast_cli_entry structure |
| cmd | |
| a | pointer to ast_cli_args structure |
Definition at line 3938 of file res_xmpp.c.
References ao2_cleanup, ao2_global_obj_ref, ast_cli_args::argc, ast_cli_args::argv, ast_cli(), ast_test_flag, CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, globals, name, ast_cli_entry::usage, xmpp_config_find(), xmpp_pubsub_delete_node(), xmpp_pubsub_purge_nodes(), and XMPP_XEP0248.
{
RAII_VAR(struct xmpp_config *, cfg, ao2_global_obj_ref(globals), ao2_cleanup);
RAII_VAR(struct ast_xmpp_client_config *, clientcfg, NULL, ao2_cleanup);
const char *name;
switch (cmd) {
case CLI_INIT:
e->command = "xmpp purge nodes";
e->usage =
"Usage: xmpp purge nodes <connection> <node>\n"
" Purges nodes on PubSub server\n"
" as configured in xmpp.conf.\n";
return NULL;
case CLI_GENERATE:
return NULL;
}
if (a->argc != 5) {
return CLI_SHOWUSAGE;
}
name = a->argv[3];
if (!cfg || !cfg->clients || !(clientcfg = xmpp_config_find(cfg->clients, name))) {
ast_cli(a->fd, "Unable to find client '%s'!\n", name);
return CLI_FAILURE;
}
if (ast_test_flag(&cfg->global->pubsub, XMPP_XEP0248)) {
xmpp_pubsub_purge_nodes(clientcfg->client, a->argv[4]);
} else {
xmpp_pubsub_delete_node(clientcfg->client, a->argv[4]);
}
return CLI_SUCCESS;
}
| static struct ast_xmpp_client* xmpp_client_alloc | ( | const char * | name | ) | [static, read] |
Allocator function for ast_xmpp_client.
Definition at line 469 of file res_xmpp.c.
References ao2_alloc, ao2_container_alloc, ao2_ref, ast_copy_string(), AST_LIST_HEAD_INIT, ast_log(), AST_PTHREADT_NULL, ast_string_field_init, ast_string_field_set, ast_xmpp_client::buddies, BUDDY_BUCKETS, LOG_ERROR, ast_xmpp_client::messages, ast_xmpp_client::mid, ast_xmpp_client::stack, ast_xmpp_client::state, ast_xmpp_client::thread, ast_xmpp_client::timeout, xmpp_buddy_cmp(), xmpp_buddy_hash(), xmpp_client_destructor(), and XMPP_STATE_DISCONNECTED.
Referenced by xmpp_client_find_or_create().
{
struct ast_xmpp_client *client;
if (!(client = ao2_alloc(sizeof(*client), xmpp_client_destructor))) {
return NULL;
}
AST_LIST_HEAD_INIT(&client->messages);
client->thread = AST_PTHREADT_NULL;
if (!(client->buddies = ao2_container_alloc(BUDDY_BUCKETS, xmpp_buddy_hash, xmpp_buddy_cmp))) {
ast_log(LOG_ERROR, "Could not initialize buddy container for '%s'\n", name);
ao2_ref(client, -1);
return NULL;
}
if (ast_string_field_init(client, 512)) {
ast_log(LOG_ERROR, "Could not initialize stringfields for '%s'\n", name);
ao2_ref(client, -1);
return NULL;
}
if (!(client->stack = iks_stack_new(8192, 8192))) {
ast_log(LOG_ERROR, "Could not create an Iksemel stack for '%s'\n", name);
ao2_ref(client, -1);
return NULL;
}
ast_string_field_set(client, name, name);
client->timeout = 50;
client->state = XMPP_STATE_DISCONNECTED;
ast_copy_string(client->mid, "aaaaa", sizeof(client->mid));
return client;
}
| static int xmpp_client_authenticate | ( | struct ast_xmpp_client * | client, |
| struct ast_xmpp_client_config * | cfg, | ||
| int | type, | ||
| iks * | node | ||
| ) | [static] |
Internal function called when we need to authenticate.
Definition at line 2659 of file res_xmpp.c.
References ast_test_flag, ast_xmpp_client_config::flags, xmpp_client_authenticate_digest(), xmpp_client_authenticate_sasl(), and XMPP_USESASL.
{
return ast_test_flag(&cfg->flags, XMPP_USESASL) ? xmpp_client_authenticate_sasl(client, cfg, type, node) : xmpp_client_authenticate_digest(client, cfg, type, node);
}
| static int xmpp_client_authenticate_digest | ( | struct ast_xmpp_client * | client, |
| struct ast_xmpp_client_config * | cfg, | ||
| int | type, | ||
| iks * | node | ||
| ) | [static] |
Internal function called when we need to authenticate using non-SASL.
Definition at line 2562 of file res_xmpp.c.
References ast_log(), ast_sha1_hash(), ast_xmpp_client_lock(), ast_xmpp_client_send(), ast_xmpp_client_unlock(), ast_xmpp_increment_mid(), ast_xmpp_client::filter, ast_xmpp_client::jid, LOG_ERROR, ast_xmpp_client::mid, ast_xmpp_client::name, ast_xmpp_client_config::password, xmpp_client_change_state(), xmpp_connect_hook(), and XMPP_STATE_AUTHENTICATING.
Referenced by xmpp_client_authenticate().
{
iks *iq = NULL, *query = NULL;
char buf[41], sidpass[100];
if (!(iq = iks_new("iq")) || !(query = iks_insert(iq, "query"))) {
ast_log(LOG_ERROR, "Stanzas could not be allocated for authentication on client '%s'\n", client->name);
iks_delete(iq);
return -1;
}
iks_insert_attrib(iq, "type", "set");
iks_insert_cdata(iks_insert(query, "username"), client->jid->user, 0);
iks_insert_cdata(iks_insert(query, "resource"), client->jid->resource, 0);
iks_insert_attrib(query, "xmlns", "jabber:iq:auth");
snprintf(sidpass, sizeof(sidpass), "%s%s", iks_find_attrib(node, "id"), cfg->password);
ast_sha1_hash(buf, sidpass);
iks_insert_cdata(iks_insert(query, "digest"), buf, 0);
ast_xmpp_client_lock(client);
iks_filter_add_rule(client->filter, xmpp_connect_hook, client, IKS_RULE_TYPE, IKS_PAK_IQ, IKS_RULE_SUBTYPE, IKS_TYPE_RESULT, IKS_RULE_ID, client->mid, IKS_RULE_DONE);
iks_insert_attrib(iq, "id", client->mid);
ast_xmpp_increment_mid(client->mid);
ast_xmpp_client_unlock(client);
iks_insert_attrib(iq, "to", client->jid->server);
ast_xmpp_client_send(client, iq);
iks_delete(iq);
xmpp_client_change_state(client, XMPP_STATE_AUTHENTICATING);
return 0;
}
| static int xmpp_client_authenticate_sasl | ( | struct ast_xmpp_client * | client, |
| struct ast_xmpp_client_config * | cfg, | ||
| int | type, | ||
| iks * | node | ||
| ) | [static] |
Internal function called when we need to authenticate using SASL.
Definition at line 2600 of file res_xmpp.c.
References ast_base64encode(), ast_log(), ast_xmpp_client_send(), base64, ast_xmpp_client::jid, len(), LOG_ERROR, ast_xmpp_client::name, ast_xmpp_client::parser, ast_xmpp_client_config::password, xmpp_client_change_state(), xmpp_is_secure(), and XMPP_STATE_AUTHENTICATING.
Referenced by xmpp_client_authenticate().
{
int features, len = strlen(client->jid->user) + strlen(cfg->password) + 3;
iks *auth;
char combined[len];
char base64[(len + 2) * 4 / 3];
if (strcmp(iks_name(node), "stream:features")) {
/* Ignore anything beside stream features */
return 0;
}
features = iks_stream_features(node);
if ((features & IKS_STREAM_SASL_MD5) && !xmpp_is_secure(client)) {
if (iks_start_sasl(client->parser, IKS_SASL_DIGEST_MD5, (char*)client->jid->user, (char*)cfg->password) != IKS_OK) {
ast_log(LOG_ERROR, "Tried to authenticate client '%s' using SASL DIGEST-MD5 but could not\n", client->name);
return -1;
}
xmpp_client_change_state(client, XMPP_STATE_AUTHENTICATING);
return 0;
}
/* Our only other available option is plain so if they don't support it, bail out now */
if (!(features & IKS_STREAM_SASL_PLAIN)) {
ast_log(LOG_ERROR, "Tried to authenticate client '%s' using SASL PLAIN but server does not support it\n", client->name);
return -1;
}
if (!(auth = iks_new("auth"))) {
ast_log(LOG_ERROR, "Could not allocate memory for SASL PLAIN authentication for client '%s'\n", client->name);
return -1;
}
iks_insert_attrib(auth, "xmlns", IKS_NS_XMPP_SASL);
iks_insert_attrib(auth, "mechanism", "PLAIN");
if (strchr(client->jid->user, '/')) {
char *user = ast_strdupa(client->jid->user);
snprintf(combined, sizeof(combined), "%c%s%c%s", 0, strsep(&user, "/"), 0, cfg->password);
} else {
snprintf(combined, sizeof(combined), "%c%s%c%s", 0, client->jid->user, 0, cfg->password);
}
ast_base64encode(base64, (const unsigned char *) combined, len - 1, (len + 2) * 4 / 3);
iks_insert_cdata(auth, base64, 0);
ast_xmpp_client_send(client, auth);
iks_delete(auth);
xmpp_client_change_state(client, XMPP_STATE_AUTHENTICATING);
return 0;
}
| static int xmpp_client_authenticating | ( | struct ast_xmpp_client * | client, |
| struct ast_xmpp_client_config * | cfg, | ||
| int | type, | ||
| iks * | node | ||
| ) | [static] |
Internal function called when we are authenticating.
Definition at line 2665 of file res_xmpp.c.
References ast_log(), ast_xmpp_client_lock(), ast_xmpp_client_send(), ast_xmpp_client_unlock(), ast_xmpp_increment_mid(), ast_xmpp_client::filter, ast_xmpp_client::jid, LOG_ERROR, ast_xmpp_client::mid, ast_xmpp_client::name, xmpp_connect_hook(), and xmpp_send_stream_header().
{
int features;
if (!strcmp(iks_name(node), "success")) {
/* Authentication was a success, yay! */
xmpp_send_stream_header(client, cfg, client->jid->server);
return 0;
} else if (!strcmp(iks_name(node), "failure")) {
/* Authentication was a bust, disconnect and reconnect later */
return -1;
} else if (strcmp(iks_name(node), "stream:features")) {
/* Ignore any other responses */
return 0;
}
features = iks_stream_features(node);
if (features & IKS_STREAM_BIND) {
iks *auth;
if (!(auth = iks_make_resource_bind(client->jid))) {
ast_log(LOG_ERROR, "Failed to allocate memory for stream bind on client '%s'\n", client->name);
return -1;
}
ast_xmpp_client_lock(client);
iks_insert_attrib(auth, "id", client->mid);
ast_xmpp_increment_mid(client->mid);
ast_xmpp_client_unlock(client);
ast_xmpp_client_send(client, auth);
iks_delete(auth);
iks_filter_add_rule(client->filter, xmpp_connect_hook, client, IKS_RULE_TYPE, IKS_PAK_IQ, IKS_RULE_SUBTYPE, IKS_TYPE_RESULT, IKS_RULE_DONE);
}
if (features & IKS_STREAM_SESSION) {
iks *auth;
if (!(auth = iks_make_session())) {
ast_log(LOG_ERROR, "Failed to allocate memory for stream session on client '%s'\n", client->name);
return -1;
}
iks_insert_attrib(auth, "id", "auth");
ast_xmpp_client_lock(client);
ast_xmpp_increment_mid(client->mid);
ast_xmpp_client_unlock(client);
ast_xmpp_client_send(client, auth);
iks_delete(auth);
iks_filter_add_rule(client->filter, xmpp_connect_hook, client, IKS_RULE_TYPE, IKS_PAK_IQ, IKS_RULE_SUBTYPE, IKS_TYPE_RESULT, IKS_RULE_ID, "auth", IKS_RULE_DONE);
}
return 0;
}
| static void xmpp_client_change_state | ( | struct ast_xmpp_client * | client, |
| int | state | ||
| ) | [static] |
Internal function which changes the XMPP client state.
Definition at line 2095 of file res_xmpp.c.
References ast_xmpp_client::state, and state.
Referenced by xmpp_client_authenticate_digest(), xmpp_client_authenticate_sasl(), xmpp_client_reconnect(), xmpp_client_request_tls(), xmpp_client_requested_tls(), xmpp_component_authenticate(), xmpp_component_authenticating(), xmpp_connect_hook(), and xmpp_roster_hook().
| static int xmpp_client_config_merge_buddies | ( | void * | obj, |
| void * | arg, | ||
| int | flags | ||
| ) | [static] |
Definition at line 3653 of file res_xmpp.c.
References ao2_find, ao2_link, ao2_ref, ast_xmpp_buddy::id, and OBJ_KEY.
Referenced by xmpp_client_config_post_apply().
{
struct ast_xmpp_buddy *buddy1 = obj, *buddy2;
struct ao2_container *buddies = arg;
/* If the buddy does not already exist link it into the client buddies container */
if (!(buddy2 = ao2_find(buddies, buddy1->id, OBJ_KEY))) {
ao2_link(buddies, buddy1);
} else {
ao2_ref(buddy2, -1);
}
/* All buddies are unlinked from the configuration buddies container, always */
return 1;
}
| static int xmpp_client_config_post_apply | ( | void * | obj, |
| void * | arg, | ||
| int | flags | ||
| ) | [static] |
Definition at line 3669 of file res_xmpp.c.
References ao2_callback, ast_log(), ast_pthread_create_background, ast_strlen_zero(), ast_test_flag, ast_xmpp_client_disconnect(), ast_xmpp_client::buddies, ast_xmpp_client_config::buddies, ast_xmpp_client_config::client, ast_xmpp_client_config::flags, ast_xmpp_client::jid, LOG_ERROR, ast_xmpp_client_config::name, OBJ_MULTIPLE, OBJ_NODATA, OBJ_UNLINK, ast_xmpp_client::parser, ast_xmpp_client::reconnect, ast_xmpp_client::stack, ast_xmpp_client::state, ast_xmpp_client_config::status, ast_xmpp_client_config::statusmsg, ast_xmpp_client::thread, ast_xmpp_client_config::user, xmpp_action_hook(), XMPP_AUTOREGISTER, xmpp_client_config_merge_buddies(), xmpp_client_set_presence(), xmpp_client_subscribe_user(), xmpp_client_thread(), XMPP_COMPONENT, xmpp_log_hook(), and XMPP_STATE_CONNECTED.
Referenced by xmpp_config_post_apply().
{
struct ast_xmpp_client_config *cfg = obj;
/* Merge buddies as need be */
ao2_callback(cfg->buddies, OBJ_MULTIPLE | OBJ_UNLINK, xmpp_client_config_merge_buddies, cfg->client->buddies);
if (cfg->client->reconnect) {
/* Disconnect the existing session since our role is changing, or we are starting up */
ast_xmpp_client_disconnect(cfg->client);
if (!(cfg->client->parser = iks_stream_new(ast_test_flag(&cfg->flags, XMPP_COMPONENT) ? "jabber:component:accept" : "jabber:client", cfg->client,
xmpp_action_hook))) {
ast_log(LOG_ERROR, "Iksemel stream could not be created for client '%s' - client not active\n", cfg->name);
return -1;
}
iks_set_log_hook(cfg->client->parser, xmpp_log_hook);
/* Create a JID based on the given user, if no resource is given use the default */
if (!strchr(cfg->user, '/') && !ast_test_flag(&cfg->flags, XMPP_COMPONENT)) {
char resource[strlen(cfg->user) + strlen("/asterisk-xmpp") + 1];
snprintf(resource, sizeof(resource), "%s/asterisk-xmpp", cfg->user);
cfg->client->jid = iks_id_new(cfg->client->stack, resource);
} else {
cfg->client->jid = iks_id_new(cfg->client->stack, cfg->user);
}
if (!cfg->client->jid || ast_strlen_zero(cfg->client->jid->user)) {
ast_log(LOG_ERROR, "Jabber identity '%s' could not be created for client '%s' - client not active\n", cfg->user, cfg->name);
return -1;
}
ast_pthread_create_background(&cfg->client->thread, NULL, xmpp_client_thread, cfg->client);
cfg->client->reconnect = 0;
} else if (cfg->client->state == XMPP_STATE_CONNECTED) {
/* If this client is connected update their presence status since it may have changed */
xmpp_client_set_presence(cfg->client, NULL, cfg->client->jid->full, cfg->status, cfg->statusmsg);
/* Subscribe to the status of any newly added buddies */
if (ast_test_flag(&cfg->flags, XMPP_AUTOREGISTER)) {
ao2_callback(cfg->client->buddies, OBJ_NODATA | OBJ_MULTIPLE, xmpp_client_subscribe_user, cfg->client);
}
}
return 0;
}
| static struct ast_xmpp_buddy* xmpp_client_create_buddy | ( | struct ao2_container * | container, |
| const char * | id | ||
| ) | [static, read] |
Internal function which creates a buddy on a client.
Definition at line 2101 of file res_xmpp.c.
References ao2_alloc, ao2_container_alloc, ao2_link, ao2_ref, ast_copy_string(), ast_xmpp_buddy::id, RESOURCE_BUCKETS, ast_xmpp_buddy::resources, ast_xmpp_buddy::subscribe, xmpp_buddy_destructor(), xmpp_resource_cmp(), and xmpp_resource_hash().
Referenced by client_buddy_handler(), xmpp_pak_s10n(), and xmpp_roster_hook().
{
struct ast_xmpp_buddy *buddy;
if (!(buddy = ao2_alloc(sizeof(*buddy), xmpp_buddy_destructor))) {
return NULL;
}
if (!(buddy->resources = ao2_container_alloc(RESOURCE_BUCKETS, xmpp_resource_hash, xmpp_resource_cmp))) {
ao2_ref(buddy, -1);
return NULL;
}
ast_copy_string(buddy->id, id, sizeof(buddy->id));
/* Assume we need to subscribe to get their presence until proven otherwise */
buddy->subscribe = 1;
ao2_link(container, buddy);
return buddy;
}
| static void xmpp_client_destructor | ( | void * | obj | ) | [static] |
Destructor callback function for XMPP client.
Definition at line 427 of file res_xmpp.c.
References ao2_cleanup, AST_LIST_HEAD_DESTROY, AST_LIST_REMOVE_HEAD, ast_xmpp_client_disconnect(), ast_xmpp_client::buddies, ast_xmpp_client::filter, ast_xmpp_message::list, ast_xmpp_message::message, ast_xmpp_client::messages, ast_xmpp_client::stack, and xmpp_message_destroy().
Referenced by xmpp_client_alloc().
{
struct ast_xmpp_client *client = obj;
struct ast_xmpp_message *message;
ast_xmpp_client_disconnect(client);
if (client->filter) {
iks_filter_delete(client->filter);
}
if (client->stack) {
iks_stack_delete(client->stack);
}
ao2_cleanup(client->buddies);
while ((message = AST_LIST_REMOVE_HEAD(&client->messages, list))) {
xmpp_message_destroy(message);
}
AST_LIST_HEAD_DESTROY(&client->messages);
}
| static void* xmpp_client_find_or_create | ( | const char * | category | ) | [static] |
Look up existing client or create a new one.
Definition at line 514 of file res_xmpp.c.
References ao2_cleanup, ao2_global_obj_ref, ao2_ref, globals, xmpp_client_alloc(), and xmpp_config_find().
Referenced by ast_xmpp_client_config_alloc().
{
RAII_VAR(struct xmpp_config *, cfg, ao2_global_obj_ref(globals), ao2_cleanup);
RAII_VAR(struct ast_xmpp_client_config *, clientcfg, NULL, ao2_cleanup);
if (!cfg || !cfg->clients || !(clientcfg = xmpp_config_find(cfg->clients, category))) {
return xmpp_client_alloc(category);
}
ao2_ref(clientcfg->client, +1);
return clientcfg->client;
}
| static int xmpp_client_receive | ( | struct ast_xmpp_client * | client, |
| unsigned int | timeout | ||
| ) | [static] |
Internal function which receives data from the XMPP client connection.
Definition at line 3512 of file res_xmpp.c.
References ast_debug, ast_log(), IKS_NET_EXPIRED, ast_xmpp_client::jid, len(), LOG_WARNING, ast_xmpp_client::name, NET_IO_BUF_SIZE, ast_xmpp_client::parser, xmpp_io_recv(), xmpp_log_hook(), and xmpp_ping_request().
Referenced by xmpp_client_thread().
{
int len, ret, pos = 0, newbufpos = 0;
char buf[NET_IO_BUF_SIZE - 1] = "";
char newbuf[NET_IO_BUF_SIZE - 1] = "";
unsigned char c;
while (1) {
len = xmpp_io_recv(client, buf, NET_IO_BUF_SIZE - 2, timeout);
if (len < 0) return IKS_NET_RWERR;
if (len == 0) return IKS_NET_EXPIRED;
buf[len] = '\0';
/* our iksemel parser won't work as expected if we feed
it with XML packets that contain multiple whitespace
characters between tags */
while (pos < len) {
c = buf[pos];
/* if we stumble on the ending tag character,
we skip any whitespace that follows it*/
if (c == '>') {
while (isspace(buf[pos+1])) {
pos++;
}
}
newbuf[newbufpos] = c;
newbufpos++;
pos++;
}
pos = 0;
newbufpos = 0;
/* Log the message here, because iksemel's logHook is
unaccessible */
xmpp_log_hook(client, buf, len, 1);
if(buf[0] == ' ') {
ast_debug(1, "JABBER: Detected Google Keep Alive. "
"Sending out Ping request for client '%s'\n", client->name);
/* If we just send out the ping here then we will have socket
* read errors because the socket will timeout */
xmpp_ping_request(client, client->jid->server, client->jid->full);
}
/* let iksemel deal with the string length,
and reset our buffer */
ret = iks_parse(client->parser, newbuf, 0, 0);
memset(newbuf, 0, sizeof(newbuf));
switch (ret) {
case IKS_NOMEM:
ast_log(LOG_WARNING, "Parsing failure: Out of memory.\n");
break;
case IKS_BADXML:
ast_log(LOG_WARNING, "Parsing failure: Invalid XML.\n");
break;
case IKS_HOOK:
ast_log(LOG_WARNING, "Parsing failure: Hook returned an error.\n");
break;
}
if (ret != IKS_OK) {
return ret;
}
ast_debug(3, "XML parsing successful\n");
}
return IKS_OK;
}
| static int xmpp_client_reconnect | ( | struct ast_xmpp_client * | client | ) | [static] |
Internal function used to reconnect an XMPP client to its server.
Definition at line 3435 of file res_xmpp.c.
References ao2_cleanup, ao2_global_obj_ref, ast_log(), ast_test_flag, ast_xmpp_client_disconnect(), ast_xmpp_client::filter, globals, ast_xmpp_client::jid, LOG_ERROR, ast_xmpp_client::name, ast_xmpp_client::parser, S_OR, ast_xmpp_client::timeout, xmpp_client_change_state(), XMPP_COMPONENT, xmpp_config_find(), XMPP_STATE_AUTHENTICATE, XMPP_STATE_REQUEST_TLS, and XMPP_USETLS.
Referenced by xmpp_client_thread().
{
struct timeval tv = { .tv_sec = 5, .tv_usec = 0 };
RAII_VAR(struct xmpp_config *, cfg, ao2_global_obj_ref(globals), ao2_cleanup);
RAII_VAR(struct ast_xmpp_client_config *, clientcfg, NULL, ao2_cleanup);
int res = IKS_NET_NOCONN;
if (!cfg || !cfg->clients || !(clientcfg = xmpp_config_find(cfg->clients, client->name))) {
return -1;
}
ast_xmpp_client_disconnect(client);
client->timeout = 50;
iks_parser_reset(client->parser);
if (!client->filter && !(client->filter = iks_filter_new())) {
ast_log(LOG_ERROR, "Could not create IKS filter for client connection '%s'\n", client->name);
return -1;
}
/* If it's a component connect to user otherwise connect to server */
res = iks_connect_via(client->parser, S_OR(clientcfg->server, client->jid->server), clientcfg->port,
ast_test_flag(&clientcfg->flags, XMPP_COMPONENT) ? clientcfg->user : client->jid->server);
/* Set socket timeout options */
setsockopt(iks_fd(client->parser), SOL_SOCKET, SO_RCVTIMEO, (char *)&tv,sizeof(struct timeval));
if (res == IKS_NET_NOCONN) {
ast_log(LOG_ERROR, "No XMPP connection available when trying to connect client '%s'\n", client->name);
return -1;
} else if (res == IKS_NET_NODNS) {
ast_log(LOG_ERROR, "No DNS available for XMPP connection when trying to connect client '%s'\n", client->name);
return -1;
}
/* Depending on the configuration of the client we eiher jump to requesting TLS, or authenticating */
xmpp_client_change_state(client, (ast_test_flag(&clientcfg->flags, XMPP_USETLS) ? XMPP_STATE_REQUEST_TLS : XMPP_STATE_AUTHENTICATE));
return 0;
}
| static int xmpp_client_request_tls | ( | struct ast_xmpp_client * | client, |
| struct ast_xmpp_client_config * | cfg, | ||
| int | type, | ||
| iks * | node | ||
| ) | [static] |
Internal function called when we need to request TLS support.
Definition at line 2474 of file res_xmpp.c.
References ast_log(), LOG_ERROR, ast_xmpp_client::name, ast_xmpp_client::parser, ast_xmpp_client::stream_flags, TRY_SECURE, xmpp_client_change_state(), xmpp_is_secure(), XMPP_STATE_AUTHENTICATE, and XMPP_STATE_REQUESTED_TLS.
{
/* If the client connection is already secure we can jump straight to authenticating */
if (xmpp_is_secure(client)) {
xmpp_client_change_state(client, XMPP_STATE_AUTHENTICATE);
return 0;
}
#ifndef HAVE_OPENSSL
ast_log(LOG_ERROR, "TLS connection for client '%s' cannot be established. OpenSSL is not available.\n", client->name);
return -1;
#else
if (iks_send_raw(client->parser, "<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>") == IKS_NET_TLSFAIL) {
ast_log(LOG_ERROR, "TLS connection for client '%s' cannot be started.\n", client->name);
return -1;
}
client->stream_flags |= TRY_SECURE;
xmpp_client_change_state(client, XMPP_STATE_REQUESTED_TLS);
return 0;
#endif
}
| static int xmpp_client_requested_tls | ( | struct ast_xmpp_client * | client, |
| struct ast_xmpp_client_config * | cfg, | ||
| int | type, | ||
| iks * | node | ||
| ) | [static] |
Internal function called when we receive a response to our TLS initiation request.
Definition at line 2500 of file res_xmpp.c.
References ast_debug, ast_log(), ast_xmpp_client::jid, LOG_ERROR, ast_xmpp_client::name, ast_xmpp_client::parser, SECURE, ast_xmpp_client::ssl_context, ast_xmpp_client::ssl_method, ast_xmpp_client::ssl_session, ast_xmpp_client::stream_flags, TRY_SECURE, xmpp_client_change_state(), xmpp_send_stream_header(), and XMPP_STATE_AUTHENTICATE.
{
#ifdef HAVE_OPENSSL
int sock;
#endif
if (!strcmp(iks_name(node), "success")) {
/* TLS is up and working, we can move on to authenticating now */
xmpp_client_change_state(client, XMPP_STATE_AUTHENTICATE);
return 0;
} else if (!strcmp(iks_name(node), "failure")) {
/* TLS negotiation was a failure, close it on down! */
return -1;
} else if (strcmp(iks_name(node), "proceed")) {
/* Ignore any other responses */
return 0;
}
#ifndef HAVE_OPENSSL
ast_log(LOG_ERROR, "Somehow we managed to try to start TLS negotiation on client '%s' without OpenSSL support, disconnecting\n", client->name);
return -1;
#else
client->ssl_method = SSLv3_method();
if (!(client->ssl_context = SSL_CTX_new((SSL_METHOD *) client->ssl_method))) {
goto failure;
}
if (!(client->ssl_session = SSL_new(client->ssl_context))) {
goto failure;
}
sock = iks_fd(client->parser);
if (!SSL_set_fd(client->ssl_session, sock)) {
goto failure;
}
if (!SSL_connect(client->ssl_session)) {
goto failure;
}
client->stream_flags &= (~TRY_SECURE);
client->stream_flags |= SECURE;
if (xmpp_send_stream_header(client, cfg, client->jid->server) != IKS_OK) {
ast_log(LOG_ERROR, "TLS connection for client '%s' could not be established, failed to send stream header after negotiation\n",
client->name);
return -1;
}
ast_debug(1, "TLS connection for client '%s' started with server\n", client->name);
xmpp_client_change_state(client, XMPP_STATE_AUTHENTICATE);
return 0;
failure:
ast_log(LOG_ERROR, "TLS connection for client '%s' cannot be established. OpenSSL initialization failed.\n", client->name);
return -1;
#endif
}
| static int xmpp_client_send_disco_info_request | ( | struct ast_xmpp_client * | client, |
| const char * | to, | ||
| const char * | from | ||
| ) | [static] |
Helper function which sends a discovery information request to a user.
Definition at line 3079 of file res_xmpp.c.
References ast_xmpp_client_lock(), ast_xmpp_client_send(), ast_xmpp_client_unlock(), ast_xmpp_increment_mid(), and ast_xmpp_client::mid.
Referenced by xmpp_pak_presence().
{
iks *iq, *query;
int res;
if (!(iq = iks_new("iq")) || !(query = iks_new("query"))) {
iks_delete(iq);
return -1;
}
iks_insert_attrib(iq, "type", "get");
iks_insert_attrib(iq, "to", to);
iks_insert_attrib(iq, "from", from);
ast_xmpp_client_lock(client);
iks_insert_attrib(iq, "id", client->mid);
ast_xmpp_increment_mid(client->mid);
ast_xmpp_client_unlock(client);
iks_insert_attrib(query, "xmlns", "http://jabber.org/protocol/disco#info");
iks_insert_node(iq, query);
res = ast_xmpp_client_send(client, iq);
iks_delete(query);
iks_delete(iq);
return res;
}
| static int xmpp_client_send_message | ( | struct ast_xmpp_client * | client, |
| int | group, | ||
| const char * | nick, | ||
| const char * | address, | ||
| const char * | message | ||
| ) | [static] |
Internal function used to send a message to a user or chatroom.
Definition at line 758 of file res_xmpp.c.
References ao2_cleanup, ao2_global_obj_ref, ast_strlen_zero(), ast_test_flag, ast_xmpp_client_send(), globals, ast_xmpp_client::jid, ast_xmpp_client::name, XMPP_COMPONENT, xmpp_config_find(), and XMPP_MAX_JIDLEN.
Referenced by ast_xmpp_chatroom_send(), and ast_xmpp_client_send_message().
{
RAII_VAR(struct xmpp_config *, cfg, ao2_global_obj_ref(globals), ao2_cleanup);
RAII_VAR(struct ast_xmpp_client_config *, clientcfg, NULL, ao2_cleanup);
int res = 0;
char from[XMPP_MAX_JIDLEN];
iks *message_packet;
if (!cfg || !cfg->clients || !(clientcfg = xmpp_config_find(cfg->clients, client->name)) ||
!(message_packet = iks_make_msg(group ? IKS_TYPE_GROUPCHAT : IKS_TYPE_CHAT, address, message))) {
return -1;
}
if (!ast_strlen_zero(nick) && ast_test_flag(&clientcfg->flags, XMPP_COMPONENT)) {
snprintf(from, sizeof(from), "%s@%s/%s", nick, client->jid->full, nick);
} else {
snprintf(from, sizeof(from), "%s", client->jid->full);
}
iks_insert_attrib(message_packet, "from", from);
res = ast_xmpp_client_send(client, message_packet);
iks_delete(message_packet);
return res;
}
| static int xmpp_client_send_raw_message | ( | struct ast_xmpp_client * | client, |
| const char * | message | ||
| ) | [static] |
Internal function which sends a raw message.
Definition at line 2429 of file res_xmpp.c.
References len(), ast_xmpp_client::parser, ast_xmpp_client::ssl_session, xmpp_is_secure(), and xmpp_log_hook().
Referenced by ast_xmpp_client_send(), xmpp_component_authenticate(), and xmpp_send_stream_header().
{
int ret;
#ifdef HAVE_OPENSSL
int len = strlen(message);
if (xmpp_is_secure(client)) {
ret = SSL_write(client->ssl_session, message, len);
if (ret) {
/* Log the message here, because iksemel's logHook is
unaccessible */
xmpp_log_hook(client, message, len, 0);
return IKS_OK;
}
}
#endif
/* If needed, data will be sent unencrypted, and logHook will
be called inside iks_send_raw */
ret = iks_send_raw(client->parser, message);
if (ret != IKS_OK) {
return ret;
}
return IKS_OK;
}
| static int xmpp_client_service_discovery_get_hook | ( | void * | data, |
| ikspak * | pak | ||
| ) | [static] |
Hook function called when client receives a service discovery get message.
Definition at line 2279 of file res_xmpp.c.
References ast_log(), ast_xmpp_client_send(), ast_xmpp_client::jid, LOG_ERROR, and ast_xmpp_client::name.
Referenced by xmpp_connect_hook().
{
struct ast_xmpp_client *client = data;
iks *iq, *disco = NULL, *ident = NULL, *google = NULL, *jingle = NULL, *ice = NULL, *rtp = NULL, *audio = NULL, *video = NULL, *query = NULL;
if (!(iq = iks_new("iq")) || !(query = iks_new("query")) || !(ident = iks_new("identity")) || !(disco = iks_new("feature")) ||
!(google = iks_new("feature")) || !(jingle = iks_new("feature")) || !(ice = iks_new("feature")) || !(rtp = iks_new("feature")) ||
!(audio = iks_new("feature")) || !(video = iks_new("feature"))) {
ast_log(LOG_ERROR, "Could not allocate memory for responding to service discovery request from '%s' on client '%s'\n",
pak->from->full, client->name);
goto end;
}
iks_insert_attrib(iq, "from", client->jid->full);
if (pak->from) {
iks_insert_attrib(iq, "to", pak->from->full);
}
iks_insert_attrib(iq, "type", "result");
iks_insert_attrib(iq, "id", pak->id);
iks_insert_attrib(query, "xmlns", "http://jabber.org/protocol/disco#info");
iks_insert_attrib(ident, "category", "client");
iks_insert_attrib(ident, "type", "pc");
iks_insert_attrib(ident, "name", "asterisk");
iks_insert_attrib(disco, "var", "http://jabber.org/protocol/disco#info");
iks_insert_attrib(google, "var", "http://www.google.com/xmpp/protocol/voice/v1");
iks_insert_attrib(jingle, "var", "urn:xmpp:jingle:1");
iks_insert_attrib(ice, "var", "urn:xmpp:jingle:transports:ice-udp:1");
iks_insert_attrib(rtp, "var", "urn:xmpp:jingle:apps:rtp:1");
iks_insert_attrib(audio, "var", "urn:xmpp:jingle:apps:rtp:audio");
iks_insert_attrib(video, "var", "urn:xmpp:jingle:apps:rtp:video");
iks_insert_node(iq, query);
iks_insert_node(query, ident);
iks_insert_node(query, google);
iks_insert_node(query, disco);
iks_insert_node(query, jingle);
iks_insert_node(query, ice);
iks_insert_node(query, rtp);
iks_insert_node(query, audio);
iks_insert_node(query, video);
ast_xmpp_client_send(client, iq);
end:
iks_delete(query);
iks_delete(video);
iks_delete(audio);
iks_delete(rtp);
iks_delete(ice);
iks_delete(jingle);
iks_delete(google);
iks_delete(ident);
iks_delete(disco);
iks_delete(iq);
return IKS_FILTER_EAT;
}
| static int xmpp_client_service_discovery_result_hook | ( | void * | data, |
| ikspak * | pak | ||
| ) | [static] |
Hook function called when client receives a service discovery result message.
Definition at line 2339 of file res_xmpp.c.
References ao2_callback, ao2_find, ao2_lock, ao2_ref, ao2_unlock, ast_xmpp_client::buddies, ast_xmpp_resource::caps, ast_xmpp_capabilities::jingle, OBJ_KEY, ast_xmpp_resource::resource, ast_xmpp_buddy::resources, and xmpp_resource_cmp().
Referenced by xmpp_component_authenticating(), and xmpp_connect_hook().
{
struct ast_xmpp_client *client = data;
struct ast_xmpp_buddy *buddy;
struct ast_xmpp_resource *resource;
if (!(buddy = ao2_find(client->buddies, pak->from->partial, OBJ_KEY))) {
return IKS_FILTER_EAT;
}
if (!(resource = ao2_callback(buddy->resources, 0, xmpp_resource_cmp, pak->from->resource))) {
ao2_ref(buddy, -1);
return IKS_FILTER_EAT;
}
ao2_lock(resource);
if (iks_find_with_attrib(pak->query, "feature", "var", "urn:xmpp:jingle:1")) {
resource->caps.jingle = 1;
}
ao2_unlock(resource);
ao2_ref(resource, -1);
ao2_ref(buddy, -1);
return IKS_FILTER_EAT;
}
| static int xmpp_client_set_group_presence | ( | struct ast_xmpp_client * | client, |
| const char * | room, | ||
| int | level, | ||
| const char * | nick | ||
| ) | [static] |
Definition at line 822 of file res_xmpp.c.
References ao2_cleanup, ao2_global_obj_ref, ast_test_flag, ast_xmpp_client_send(), globals, ast_xmpp_client::jid, ast_xmpp_client::name, S_OR, XMPP_COMPONENT, xmpp_config_find(), and XMPP_MAX_JIDLEN.
Referenced by ast_xmpp_chatroom_join(), and ast_xmpp_chatroom_leave().
{
RAII_VAR(struct xmpp_config *, cfg, ao2_global_obj_ref(globals), ao2_cleanup);
RAII_VAR(struct ast_xmpp_client_config *, clientcfg, NULL, ao2_cleanup);
int res = 0;
iks *presence = NULL, *x = NULL;
char from[XMPP_MAX_JIDLEN], roomid[XMPP_MAX_JIDLEN];
if (!cfg || !cfg->clients || !(clientcfg = xmpp_config_find(cfg->clients, client->name)) ||
!(presence = iks_make_pres(level, NULL)) || !(x = iks_new("x"))) {
res = -1;
goto done;
}
if (ast_test_flag(&clientcfg->flags, XMPP_COMPONENT)) {
snprintf(from, sizeof(from), "%s@%s/%s", nick, client->jid->full, nick);
snprintf(roomid, sizeof(roomid), "%s/%s", room, nick);
} else {
snprintf(from, sizeof(from), "%s", client->jid->full);
snprintf(roomid, sizeof(roomid), "%s/%s", room, S_OR(nick, client->jid->user));
}
iks_insert_attrib(presence, "to", roomid);
iks_insert_attrib(presence, "from", from);
iks_insert_attrib(x, "xmlns", "http://jabber.org/protocol/muc");
iks_insert_node(presence, x);
res = ast_xmpp_client_send(client, presence);
done:
iks_delete(x);
iks_delete(presence);
return res;
}
| static void xmpp_client_set_presence | ( | struct ast_xmpp_client * | client, |
| const char * | to, | ||
| const char * | from, | ||
| int | level, | ||
| const char * | desc | ||
| ) | [static] |
Internal function which changes the presence status of an XMPP client.
Definition at line 2241 of file res_xmpp.c.
References ao2_cleanup, ao2_global_obj_ref, ast_log(), ast_strlen_zero(), ast_xmpp_client_send(), globals, LOG_ERROR, ast_xmpp_client::name, and xmpp_config_find().
Referenced by xmpp_client_config_post_apply(), xmpp_connect_hook(), xmpp_pak_presence(), and xmpp_pak_s10n().
{
RAII_VAR(struct xmpp_config *, cfg, ao2_global_obj_ref(globals), ao2_cleanup);
RAII_VAR(struct ast_xmpp_client_config *, clientcfg, NULL, ao2_cleanup);
iks *presence = NULL, *cnode = NULL, *priority = NULL;
char priorityS[10];
if (!cfg || !cfg->clients || !(clientcfg = xmpp_config_find(cfg->clients, client->name)) ||
!(presence = iks_make_pres(level, desc)) || !(cnode = iks_new("c")) || !(priority = iks_new("priority"))) {
ast_log(LOG_ERROR, "Unable to allocate stanzas for setting presence status for client '%s'\n", client->name);
goto done;
}
if (!ast_strlen_zero(to)) {
iks_insert_attrib(presence, "to", to);
}
if (!ast_strlen_zero(from)) {
iks_insert_attrib(presence, "from", from);
}
snprintf(priorityS, sizeof(priorityS), "%d", clientcfg->priority);
iks_insert_cdata(priority, priorityS, strlen(priorityS));
iks_insert_node(presence, priority);
iks_insert_attrib(cnode, "node", "http://www.asterisk.org/xmpp/client/caps");
iks_insert_attrib(cnode, "ver", "asterisk-xmpp");
iks_insert_attrib(cnode, "ext", "voice-v1 video-v1 camera-v1");
iks_insert_attrib(cnode, "xmlns", "http://jabber.org/protocol/caps");
iks_insert_node(presence, cnode);
ast_xmpp_client_send(client, presence);
done:
iks_delete(cnode);
iks_delete(presence);
iks_delete(priority);
}
| static int xmpp_client_subscribe_user | ( | void * | obj, |
| void * | arg, | ||
| int | flags | ||
| ) | [static] |
Callback function which subscribes to a user if needed.
Definition at line 2162 of file res_xmpp.c.
References ast_log(), ast_xmpp_client_send(), ast_xmpp_buddy::id, LOG_WARNING, ast_xmpp_client::name, and ast_xmpp_buddy::subscribe.
Referenced by xmpp_client_config_post_apply(), and xmpp_roster_hook().
{
struct ast_xmpp_buddy *buddy = obj;
struct ast_xmpp_client *client = arg;
if (!buddy->subscribe) {
return 0;
}
if (ast_xmpp_client_send(client, iks_make_s10n(IKS_TYPE_SUBSCRIBE, buddy->id,
"Greetings! I am the Asterisk Open Source PBX and I want to subscribe to your presence\n"))) {
ast_log(LOG_WARNING, "Could not send subscription for '%s' on client '%s'\n",
buddy->id, client->name);
}
buddy->subscribe = 0;
return 0;
}
| static void* xmpp_client_thread | ( | void * | data | ) | [static] |
XMPP client connection thread.
Definition at line 3581 of file res_xmpp.c.
References ao2_cleanup, ao2_global_obj_ref, ast_debug, ast_log(), ast_test_flag, globals, IKS_NET_EXPIRED, ast_xmpp_client::jid, LOG_ERROR, LOG_WARNING, ast_xmpp_client::name, ast_xmpp_client::state, ast_xmpp_client::timeout, xmpp_client_receive(), xmpp_client_reconnect(), xmpp_config_find(), XMPP_KEEPALIVE, xmpp_ping_request(), XMPP_STATE_CONNECTED, and XMPP_STATE_DISCONNECTING.
Referenced by xmpp_client_config_post_apply().
{
struct ast_xmpp_client *client = data;
int res = IKS_NET_RWERR;
do {
if (client->state == XMPP_STATE_DISCONNECTING) {
ast_debug(1, "JABBER: Disconnecting client '%s'\n", client->name);
break;
}
if (res == IKS_NET_RWERR || client->timeout == 0) {
ast_debug(3, "Connecting client '%s'\n", client->name);
if ((res = xmpp_client_reconnect(client)) != IKS_OK) {
sleep(4);
res = IKS_NET_RWERR;
}
continue;
}
res = xmpp_client_receive(client, 1);
/* Decrease timeout if no data received, and delete
* old messages globally */
if (res == IKS_NET_EXPIRED) {
client->timeout--;
}
if (res == IKS_HOOK) {
ast_debug(2, "JABBER: Got hook event.\n");
} else if (res == IKS_NET_TLSFAIL) {
ast_log(LOG_ERROR, "JABBER: Failure in TLS.\n");
} else if (!client->timeout && client->state == XMPP_STATE_CONNECTED) {
RAII_VAR(struct xmpp_config *, cfg, ao2_global_obj_ref(globals), ao2_cleanup);
RAII_VAR(struct ast_xmpp_client_config *, clientcfg, NULL, ao2_cleanup);
if (cfg && cfg->clients) {
clientcfg = xmpp_config_find(cfg->clients, client->name);
}
if (clientcfg && ast_test_flag(&clientcfg->flags, XMPP_KEEPALIVE)) {
res = xmpp_ping_request(client, client->jid->server, client->jid->full);
} else {
res = IKS_OK;
}
if (res == IKS_OK) {
client->timeout = 50;
} else {
ast_log(LOG_WARNING, "JABBER: Network Timeout\n");
}
} else if (res == IKS_NET_RWERR) {
ast_log(LOG_WARNING, "JABBER: socket read error\n");
} else if (res == IKS_NET_NOSOCK) {
ast_log(LOG_WARNING, "JABBER: No Socket\n");
} else if (res == IKS_NET_NOCONN) {
ast_log(LOG_WARNING, "JABBER: No Connection\n");
} else if (res == IKS_NET_NODNS) {
ast_log(LOG_WARNING, "JABBER: No DNS\n");
} else if (res == IKS_NET_NOTSUPP) {
ast_log(LOG_WARNING, "JABBER: Not Supported\n");
} else if (res == IKS_NET_DROPPED) {
ast_log(LOG_WARNING, "JABBER: Dropped?\n");
} else {
ast_debug(5, "JABBER: Unknown\n");
}
} while (1);
return NULL;
}
| static int xmpp_client_unsubscribe_user | ( | struct ast_xmpp_client * | client, |
| const char * | user | ||
| ) | [static] |
Helper function which unsubscribes a user and removes them from the roster.
Definition at line 2125 of file res_xmpp.c.
References ast_log(), ast_xmpp_client_send(), ast_xmpp_client::jid, LOG_WARNING, and ast_xmpp_client::name.
Referenced by xmpp_roster_hook().
{
iks *iq, *query = NULL, *item = NULL;
if (ast_xmpp_client_send(client, iks_make_s10n(IKS_TYPE_UNSUBSCRIBE, user,
"Goodbye. Your status is no longer required.\n"))) {
return -1;
}
if (!(iq = iks_new("iq")) || !(query = iks_new("query")) || !(item = iks_new("item"))) {
ast_log(LOG_WARNING, "Could not allocate memory for roster removal of '%s' from client '%s'\n",
user, client->name);
goto done;
}
iks_insert_attrib(iq, "from", client->jid->full);
iks_insert_attrib(iq, "type", "set");
iks_insert_attrib(query, "xmlns", "jabber:iq:roster");
iks_insert_node(iq, query);
iks_insert_attrib(item, "jid", user);
iks_insert_attrib(item, "subscription", "remove");
iks_insert_node(query, item);
if (ast_xmpp_client_send(client, iq)) {
ast_log(LOG_WARNING, "Could not send roster removal request of '%s' from client '%s'\n",
user, client->name);
}
done:
iks_delete(item);
iks_delete(query);
iks_delete(iq);
return 0;
}
| static int xmpp_component_authenticate | ( | struct ast_xmpp_client * | client, |
| struct ast_xmpp_client_config * | cfg, | ||
| int | type, | ||
| iks * | node | ||
| ) | [static] |
Internal function called when we should authenticate as a component.
Definition at line 2726 of file res_xmpp.c.
References ast_log(), ast_sha1_hash(), LOG_ERROR, ast_xmpp_client::name, ast_xmpp_client_config::password, secret, xmpp_client_change_state(), xmpp_client_send_raw_message(), and XMPP_STATE_AUTHENTICATING.
{
char secret[160], shasum[320], message[344];
ikspak *pak = iks_packet(node);
snprintf(secret, sizeof(secret), "%s%s", pak->id, cfg->password);
ast_sha1_hash(shasum, secret);
snprintf(message, sizeof(message), "<handshake>%s</handshake>", shasum);
if (xmpp_client_send_raw_message(client, message) != IKS_OK) {
ast_log(LOG_ERROR, "Unable to send handshake for component '%s'\n", client->name);
return -1;
}
xmpp_client_change_state(client, XMPP_STATE_AUTHENTICATING);
return 0;
}
| static int xmpp_component_authenticating | ( | struct ast_xmpp_client * | client, |
| struct ast_xmpp_client_config * | cfg, | ||
| int | type, | ||
| iks * | node | ||
| ) | [static] |
Internal function called when we authenticated as a component.
Definition at line 2992 of file res_xmpp.c.
References ast_log(), ast_xmpp_client::filter, LOG_ERROR, ast_xmpp_client::name, xmpp_client_change_state(), xmpp_client_service_discovery_result_hook(), xmpp_component_register_get_hook(), xmpp_component_register_set_hook(), xmpp_component_service_discovery_get_hook(), xmpp_component_service_discovery_items_hook(), and XMPP_STATE_CONNECTED.
{
if (strcmp(iks_name(node), "handshake")) {
ast_log(LOG_ERROR, "Failed to authenticate component '%s'\n", client->name);
return -1;
}
iks_filter_add_rule(client->filter, xmpp_component_service_discovery_items_hook, client, IKS_RULE_NS, "http://jabber.org/protocol/disco#items", IKS_RULE_DONE);
iks_filter_add_rule(client->filter, xmpp_component_service_discovery_get_hook, client, IKS_RULE_SUBTYPE, IKS_TYPE_GET, IKS_RULE_NS, "http://jabber.org/protocol/disco#info", IKS_RULE_DONE);
/* This uses the client service discovery result hook on purpose, as the code is common between both */
iks_filter_add_rule(client->filter, xmpp_client_service_discovery_result_hook, client, IKS_RULE_SUBTYPE, IKS_TYPE_RESULT, IKS_RULE_NS, "http://jabber.org/protocol/disco#info", IKS_RULE_DONE);
iks_filter_add_rule(client->filter, xmpp_component_register_get_hook, client, IKS_RULE_SUBTYPE, IKS_TYPE_GET, IKS_RULE_NS, "jabber:iq:register", IKS_RULE_DONE);
iks_filter_add_rule(client->filter, xmpp_component_register_set_hook, client, IKS_RULE_SUBTYPE, IKS_TYPE_SET, IKS_RULE_NS, "jabber:iq:register", IKS_RULE_DONE);
xmpp_client_change_state(client, XMPP_STATE_CONNECTED);
return 0;
}
| static int xmpp_component_register_get_hook | ( | void * | data, |
| ikspak * | pak | ||
| ) | [static] |
Hook function called when the component is queried about registration.
Definition at line 2833 of file res_xmpp.c.
References ao2_cleanup, ao2_find, ao2_global_obj_ref, ao2_ref, ast_log(), ast_xmpp_client_send(), ast_xmpp_client::buddies, globals, LOG_ERROR, LOG_WARNING, ast_xmpp_client::name, OBJ_KEY, and xmpp_config_find().
Referenced by xmpp_component_authenticating().
{
RAII_VAR(struct xmpp_config *, cfg, ao2_global_obj_ref(globals), ao2_cleanup);
RAII_VAR(struct ast_xmpp_client_config *, clientcfg, NULL, ao2_cleanup);
struct ast_xmpp_client *client = data;
iks *iq = NULL, *query = NULL, *error = NULL, *notacceptable = NULL, *instructions = NULL;
struct ast_xmpp_buddy *buddy;
char *node;
if (!cfg || !cfg->clients || !(clientcfg = xmpp_config_find(cfg->clients, client->name)) ||
!(iq = iks_new("iq")) || !(query = iks_new("query")) || !(error = iks_new("error")) || !(notacceptable = iks_new("not-acceptable")) ||
!(instructions = iks_new("instructions"))) {
ast_log(LOG_ERROR, "Failed to allocate stanzas for register get response to '%s' on component '%s'\n",
pak->from->partial, client->name);
goto done;
}
iks_insert_attrib(iq, "from", clientcfg->user);
iks_insert_attrib(iq, "to", pak->from->full);
iks_insert_attrib(iq, "id", pak->id);
iks_insert_attrib(iq, "type", "result");
iks_insert_attrib(query, "xmlns", "jabber:iq:register");
iks_insert_node(iq, query);
if (!(buddy = ao2_find(client->buddies, pak->from->partial, OBJ_KEY))) {
iks_insert_attrib(error, "code", "406");
iks_insert_attrib(error, "type", "modify");
iks_insert_attrib(notacceptable, "xmlns", "urn:ietf:params:xml:ns:xmpp-stanzas");
iks_insert_node(iq, error);
iks_insert_node(error, notacceptable);
ast_log(LOG_ERROR, "Received register attempt from '%s' but buddy is not configured on component '%s'\n",
pak->from->partial, client->name);
} else if (!(node = iks_find_attrib(pak->query, "node"))) {
iks_insert_cdata(instructions, "Welcome to Asterisk - the Open Source PBX.\n", 0);
iks_insert_node(query, instructions);
ao2_ref(buddy, -1);
} else {
ast_log(LOG_WARNING, "Received register get to component '%s' using unsupported node '%s' from '%s'\n",
client->name, node, pak->from->partial);
ao2_ref(buddy, -1);
goto done;
}
if (ast_xmpp_client_send(client, iq)) {
ast_log(LOG_WARNING, "Could not send response to '%s' for received register get on component '%s'\n",
pak->from->partial, client->name);
}
done:
iks_delete(instructions);
iks_delete(notacceptable);
iks_delete(error);
iks_delete(query);
iks_delete(iq);
return IKS_FILTER_EAT;
}
| static int xmpp_component_register_set_hook | ( | void * | data, |
| ikspak * | pak | ||
| ) | [static] |
Hook function called when someone registers to the component.
Definition at line 2894 of file res_xmpp.c.
References ast_log(), ast_xmpp_client_lock(), ast_xmpp_client_send(), ast_xmpp_client_unlock(), ast_xmpp_increment_mid(), ast_xmpp_client::jid, LOG_ERROR, LOG_WARNING, ast_xmpp_client::mid, and ast_xmpp_client::name.
Referenced by xmpp_component_authenticating().
{
struct ast_xmpp_client *client = data;
iks *iq, *presence = NULL, *x = NULL;
if (!(iq = iks_new("iq")) || !(presence = iks_new("presence")) || !(x = iks_new("x"))) {
ast_log(LOG_ERROR, "Failed to allocate stanzas for register set response to '%s' on component '%s'\n",
pak->from->partial, client->name);
goto done;
}
iks_insert_attrib(iq, "from", client->jid->full);
iks_insert_attrib(iq, "to", pak->from->full);
iks_insert_attrib(iq, "id", pak->id);
iks_insert_attrib(iq, "type", "result");
if (ast_xmpp_client_send(client, iq)) {
ast_log(LOG_WARNING, "Could not send response to '%s' for received register set on component '%s'\n",
pak->from->partial, client->name);
goto done;
}
iks_insert_attrib(presence, "from", client->jid->full);
iks_insert_attrib(presence, "to", pak->from->partial);
ast_xmpp_client_lock(client);
iks_insert_attrib(presence, "id", client->mid);
ast_xmpp_increment_mid(client->mid);
ast_xmpp_client_unlock(client);
iks_insert_attrib(presence, "type", "subscribe");
iks_insert_attrib(x, "xmlns", "vcard-temp:x:update");
iks_insert_node(presence, x);
if (ast_xmpp_client_send(client, presence)) {
ast_log(LOG_WARNING, "Could not send subscription to '%s' on component '%s'\n",
pak->from->partial, client->name);
}
done:
iks_delete(x);
iks_delete(presence);
iks_delete(iq);
return IKS_FILTER_EAT;
}
| static int xmpp_component_service_discovery_get_hook | ( | void * | data, |
| ikspak * | pak | ||
| ) | [static] |
Hook function called when component receives a service discovery get message.
Definition at line 2746 of file res_xmpp.c.
References ao2_cleanup, ao2_global_obj_ref, ast_debug, ast_log(), ast_xmpp_client_send(), commands, globals, LOG_ERROR, LOG_WARNING, ast_xmpp_client::name, version, and xmpp_config_find().
Referenced by xmpp_component_authenticating().
{
RAII_VAR(struct xmpp_config *, cfg, ao2_global_obj_ref(globals), ao2_cleanup);
RAII_VAR(struct ast_xmpp_client_config *, clientcfg, NULL, ao2_cleanup);
struct ast_xmpp_client *client = data;
iks *iq = NULL, *query = NULL, *identity = NULL, *disco = NULL, *reg = NULL, *commands = NULL, *gateway = NULL;
iks *version = NULL, *vcard = NULL, *search = NULL, *item = NULL;
char *node;
if (!cfg || !cfg->clients || !(clientcfg = xmpp_config_find(cfg->clients, client->name)) ||
!(iq = iks_new("iq")) || !(query = iks_new("query")) || !(identity = iks_new("identity")) || !(disco = iks_new("feature")) ||
!(reg = iks_new("feature")) || !(commands = iks_new("feature")) || !(gateway = iks_new("feature")) || !(version = iks_new("feature")) ||
!(vcard = iks_new("feature")) || !(search = iks_new("search")) || !(item = iks_new("item"))) {
ast_log(LOG_ERROR, "Failed to allocate stanzas for service discovery get response to '%s' on component '%s'\n",
pak->from->partial, client->name);
goto done;
}
iks_insert_attrib(iq, "from", clientcfg->user);
iks_insert_attrib(iq, "to", pak->from->full);
iks_insert_attrib(iq, "id", pak->id);
iks_insert_attrib(iq, "type", "result");
if (!(node = iks_find_attrib(pak->query, "node"))) {
iks_insert_attrib(query, "xmlns", "http://jabber.org/protocol/disco#info");
iks_insert_attrib(identity, "category", "gateway");
iks_insert_attrib(identity, "type", "pstn");
iks_insert_attrib(identity, "name", "Asterisk The Open Source PBX");
iks_insert_attrib(disco, "var", "http://jabber.org/protocol/disco");
iks_insert_attrib(reg, "var", "jabber:iq:register");
iks_insert_attrib(commands, "var", "http://jabber.org/protocol/commands");
iks_insert_attrib(gateway, "var", "jabber:iq:gateway");
iks_insert_attrib(version, "var", "jabber:iq:version");
iks_insert_attrib(vcard, "var", "vcard-temp");
iks_insert_attrib(search, "var", "jabber:iq:search");
iks_insert_node(iq, query);
iks_insert_node(query, identity);
iks_insert_node(query, disco);
iks_insert_node(query, reg);
iks_insert_node(query, commands);
iks_insert_node(query, gateway);
iks_insert_node(query, version);
iks_insert_node(query, vcard);
iks_insert_node(query, search);
} else if (!strcasecmp(node, "http://jabber.org/protocol/commands")) {
iks_insert_attrib(query, "xmlns", "http://jabber.org/protocol/disco#items");
iks_insert_attrib(query, "node", "http://jabber.org/protocol/commands");
iks_insert_attrib(item, "node", "confirmaccount");
iks_insert_attrib(item, "name", "Confirm account");
iks_insert_attrib(item, "jid", clientcfg->user);
iks_insert_node(iq, query);
iks_insert_node(query, item);
} else if (!strcasecmp(node, "confirmaccount")) {
iks_insert_attrib(query, "xmlns", "http://jabber.org/protocol/disco#info");
iks_insert_attrib(commands, "var", "http://jabber.org/protocol/commands");
iks_insert_node(iq, query);
iks_insert_node(query, commands);
} else {
ast_debug(3, "Unsupported service discovery info request received with node '%s' on component '%s'\n",
node, client->name);
goto done;
}
if (ast_xmpp_client_send(client, iq)) {
ast_log(LOG_WARNING, "Could not send response to service discovery request on component '%s'\n",
client->name);
}
done:
iks_delete(search);
iks_delete(vcard);
iks_delete(version);
iks_delete(gateway);
iks_delete(commands);
iks_delete(reg);
iks_delete(disco);
iks_delete(identity);
iks_delete(query);
iks_delete(iq);
return IKS_FILTER_EAT;
}
| static int xmpp_component_service_discovery_items_hook | ( | void * | data, |
| ikspak * | pak | ||
| ) | [static] |
Hook function called when we receive a service discovery items request.
Definition at line 2941 of file res_xmpp.c.
References ao2_cleanup, ao2_global_obj_ref, ast_log(), ast_xmpp_client_send(), globals, LOG_ERROR, LOG_WARNING, ast_xmpp_client::name, and xmpp_config_find().
Referenced by xmpp_component_authenticating().
{
RAII_VAR(struct xmpp_config *, cfg, ao2_global_obj_ref(globals), ao2_cleanup);
RAII_VAR(struct ast_xmpp_client_config *, clientcfg, NULL, ao2_cleanup);
struct ast_xmpp_client *client = data;
iks *iq = NULL, *query = NULL, *item = NULL, *feature = NULL;
char *node;
if (!cfg || !cfg->clients || !(clientcfg = xmpp_config_find(cfg->clients, client->name)) ||
!(iq = iks_new("iq")) || !(query = iks_new("query")) || !(item = iks_new("item")) || !(feature = iks_new("feature"))) {
ast_log(LOG_ERROR, "Failed to allocate stanzas for service discovery items response to '%s' on component '%s'\n",
pak->from->partial, client->name);
goto done;
}
iks_insert_attrib(iq, "from", clientcfg->user);
iks_insert_attrib(iq, "to", pak->from->full);
iks_insert_attrib(iq, "id", pak->id);
iks_insert_attrib(iq, "type", "result");
iks_insert_attrib(query, "xmlns", "http://jabber.org/protocol/disco#items");
iks_insert_node(iq, query);
if (!(node = iks_find_attrib(pak->query, "node"))) {
iks_insert_attrib(item, "node", "http://jabber.org/protocol/commands");
iks_insert_attrib(item, "name", "Asterisk Commands");
iks_insert_attrib(item, "jid", clientcfg->user);
iks_insert_node(query, item);
} else if (!strcasecmp(node, "http://jabber.org/protocol/commands")) {
iks_insert_attrib(query, "node", "http://jabber.org/protocol/commands");
} else {
ast_log(LOG_WARNING, "Received service discovery items request to component '%s' using unsupported node '%s' from '%s'\n",
client->name, node, pak->from->partial);
goto done;
}
if (ast_xmpp_client_send(client, iq)) {
ast_log(LOG_WARNING, "Could not send response to service discovery items request from '%s' on component '%s'\n",
pak->from->partial, client->name);
}
done:
iks_delete(feature);
iks_delete(item);
iks_delete(query);
iks_delete(iq);
return IKS_FILTER_EAT;
}
| static void* xmpp_config_alloc | ( | void | ) | [static] |
Allocator for XMPP configuration.
Definition at line 581 of file res_xmpp.c.
References ao2_alloc, ao2_container_alloc, ao2_ref, ast_set_flag, xmpp_config::clients, ast_xmpp_global_config::general, xmpp_config::global, XMPP_AUTOACCEPT, XMPP_AUTOREGISTER, xmpp_config_cmp(), xmpp_config_destructor(), xmpp_config_hash(), XMPP_KEEPALIVE, XMPP_USESASL, and XMPP_USETLS.
{
struct xmpp_config *cfg;
if (!(cfg = ao2_alloc(sizeof(*cfg), xmpp_config_destructor))) {
return NULL;
}
if (!(cfg->global = ao2_alloc(sizeof(*cfg->global), NULL))) {
goto error;
}
ast_set_flag(&cfg->global->general, XMPP_AUTOREGISTER | XMPP_AUTOACCEPT | XMPP_USETLS | XMPP_USESASL | XMPP_KEEPALIVE);
if (!(cfg->clients = ao2_container_alloc(1, xmpp_config_hash, xmpp_config_cmp))) {
goto error;
}
return cfg;
error:
ao2_ref(cfg, -1);
return NULL;
}
| static int xmpp_config_cmp | ( | void * | obj, |
| void * | arg, | ||
| int | flags | ||
| ) | [static] |
Comparator function for configuration.
Definition at line 573 of file res_xmpp.c.
References CMP_MATCH, CMP_STOP, match(), ast_xmpp_client_config::name, and OBJ_KEY.
Referenced by xmpp_config_alloc().
| static void xmpp_config_destructor | ( | void * | obj | ) | [static] |
Destructor for XMPP configuration.
Definition at line 557 of file res_xmpp.c.
References ao2_cleanup, xmpp_config::clients, and xmpp_config::global.
Referenced by xmpp_config_alloc().
{
struct xmpp_config *cfg = obj;
ao2_cleanup(cfg->global);
ao2_cleanup(cfg->clients);
}
| static void* xmpp_config_find | ( | struct ao2_container * | tmp_container, |
| const char * | category | ||
| ) | [static] |
Find function for configuration.
Definition at line 508 of file res_xmpp.c.
References ao2_find, and OBJ_KEY.
Referenced by acf_jabberreceive_read(), acf_jabberstatus_read(), ast_xmpp_client_find(), delete_old_messages(), manager_jabber_send(), xmpp_action_hook(), xmpp_cli_create_collection(), xmpp_cli_create_leafnode(), xmpp_cli_delete_pubsub_node(), xmpp_cli_list_pubsub_nodes(), xmpp_cli_purge_pubsub_nodes(), xmpp_client_find_or_create(), xmpp_client_reconnect(), xmpp_client_send_message(), xmpp_client_set_group_presence(), xmpp_client_set_presence(), xmpp_client_thread(), xmpp_component_register_get_hook(), xmpp_component_service_discovery_get_hook(), xmpp_component_service_discovery_items_hook(), xmpp_config_prelink(), xmpp_connect_hook(), xmpp_init_event_distribution(), xmpp_join_exec(), xmpp_leave_exec(), xmpp_log_hook(), xmpp_pubsub_iq_create(), xmpp_roster_hook(), xmpp_send_cb(), xmpp_send_exec(), xmpp_sendgroup_exec(), and xmpp_status_exec().
| static int xmpp_config_hash | ( | const void * | obj, |
| const int | flags | ||
| ) | [static] |
Hashing function for configuration.
Definition at line 565 of file res_xmpp.c.
References ast_str_case_hash(), name, ast_xmpp_client_config::name, and OBJ_KEY.
Referenced by xmpp_config_alloc().
{
const struct ast_xmpp_client_config *cfg = obj;
const char *name = (flags & OBJ_KEY) ? obj : cfg->name;
return ast_str_case_hash(name);
}
| static void xmpp_config_post_apply | ( | void | ) | [static] |
Definition at line 643 of file res_xmpp.c.
References ao2_callback, ao2_cleanup, ao2_global_obj_ref, globals, OBJ_MULTIPLE, OBJ_NODATA, and xmpp_client_config_post_apply().
{
RAII_VAR(struct xmpp_config *, cfg, ao2_global_obj_ref(globals), ao2_cleanup);
ao2_callback(cfg->clients, OBJ_NODATA | OBJ_MULTIPLE, xmpp_client_config_post_apply, NULL);
}
| static int xmpp_config_prelink | ( | void * | newitem | ) | [static] |
Definition at line 605 of file res_xmpp.c.
References ao2_cleanup, ao2_global_obj_ref, ast_log(), ast_strlen_zero(), ast_test_flag, ast_xmpp_client_config::client, ast_xmpp_client_config::flags, globals, LOG_ERROR, ast_xmpp_client_config::name, ast_xmpp_client_config::password, ast_xmpp_client_config::port, ast_xmpp_client_config::priority, ast_xmpp_client::reconnect, ast_xmpp_client_config::server, ast_xmpp_client_config::user, XMPP_COMPONENT, and xmpp_config_find().
{
struct ast_xmpp_client_config *clientcfg = newitem;
RAII_VAR(struct xmpp_config *, cfg, ao2_global_obj_ref(globals), ao2_cleanup);
RAII_VAR(struct ast_xmpp_client_config *, oldclientcfg, NULL, ao2_cleanup);
if (ast_strlen_zero(clientcfg->user)) {
ast_log(LOG_ERROR, "No user specified on client '%s'\n", clientcfg->name);
return -1;
} else if (ast_strlen_zero(clientcfg->password)) {
ast_log(LOG_ERROR, "No password specified on client '%s'\n", clientcfg->name);
return -1;
} else if (ast_strlen_zero(clientcfg->server)) {
ast_log(LOG_ERROR, "No server specified on client '%s'\n", clientcfg->name);
return -1;
}
/* If this is a new connection force a reconnect */
if (!cfg || !cfg->clients || !(oldclientcfg = xmpp_config_find(cfg->clients, clientcfg->name))) {
clientcfg->client->reconnect = 1;
return 0;
}
/* If any configuration options are changing that would require reconnecting set the bit so we will do so if possible */
if (strcmp(clientcfg->user, oldclientcfg->user) ||
strcmp(clientcfg->password, oldclientcfg->password) ||
strcmp(clientcfg->server, oldclientcfg->server) ||
(clientcfg->port != oldclientcfg->port) ||
(ast_test_flag(&clientcfg->flags, XMPP_COMPONENT) != ast_test_flag(&oldclientcfg->flags, XMPP_COMPONENT)) ||
(clientcfg->priority != oldclientcfg->priority)) {
clientcfg->client->reconnect = 1;
} else {
clientcfg->client->reconnect = 0;
}
return 0;
}
| static int xmpp_connect_hook | ( | void * | data, |
| ikspak * | pak | ||
| ) | [static] |
Hook function called when client finishes authenticating with the server.
Definition at line 2369 of file res_xmpp.c.
References ao2_cleanup, ao2_global_obj_ref, ast_log(), ast_test_flag, ast_xmpp_client_send(), ast_xmpp_client::filter, globals, ast_xmpp_client::jid, LOG_ERROR, ast_xmpp_client::name, ast_xmpp_client::stack, xmpp_client_change_state(), xmpp_client_service_discovery_get_hook(), xmpp_client_service_discovery_result_hook(), xmpp_client_set_presence(), xmpp_config_find(), XMPP_DISTRIBUTE_EVENTS, xmpp_init_event_distribution(), xmpp_roster_hook(), and XMPP_STATE_ROSTER.
Referenced by xmpp_client_authenticate_digest(), and xmpp_client_authenticating().
{
RAII_VAR(struct xmpp_config *, cfg, ao2_global_obj_ref(globals), ao2_cleanup);
RAII_VAR(struct ast_xmpp_client_config *, clientcfg, NULL, ao2_cleanup);
struct ast_xmpp_client *client = data;
iks *roster;
if (!cfg || !cfg->clients || !(clientcfg = xmpp_config_find(cfg->clients, client->name))) {
return -1;
}
client->jid = (iks_find_cdata(pak->query, "jid")) ? iks_id_new(client->stack, iks_find_cdata(pak->query, "jid")) : client->jid;
if (ast_test_flag(&clientcfg->flags, XMPP_DISTRIBUTE_EVENTS)) {
xmpp_init_event_distribution(client);
}
if (!(roster = iks_make_iq(IKS_TYPE_GET, IKS_NS_ROSTER))) {
ast_log(LOG_ERROR, "Unable to allocate memory for roster request for client '%s'\n", client->name);
return -1;
}
iks_filter_add_rule(client->filter, xmpp_client_service_discovery_get_hook, client, IKS_RULE_SUBTYPE, IKS_TYPE_GET, IKS_RULE_NS, "http://jabber.org/protocol/disco#info", IKS_RULE_DONE);
iks_filter_add_rule(client->filter, xmpp_client_service_discovery_result_hook, client, IKS_RULE_SUBTYPE, IKS_TYPE_RESULT, IKS_RULE_NS, "http://jabber.org/protocol/disco#info", IKS_RULE_DONE);
iks_insert_attrib(roster, "id", "roster");
ast_xmpp_client_send(client, roster);
iks_filter_remove_hook(client->filter, xmpp_connect_hook);
iks_filter_add_rule(client->filter, xmpp_roster_hook, client, IKS_RULE_TYPE, IKS_PAK_IQ, IKS_RULE_SUBTYPE, IKS_TYPE_RESULT, IKS_RULE_ID, "roster", IKS_RULE_DONE);
xmpp_client_set_presence(client, NULL, client->jid->full, clientcfg->status, clientcfg->statusmsg);
xmpp_client_change_state(client, XMPP_STATE_ROSTER);
return IKS_FILTER_EAT;
}
| static char* xmpp_do_set_debug | ( | struct ast_cli_entry * | e, |
| int | cmd, | ||
| struct ast_cli_args * | a | ||
| ) | [static] |
Definition at line 4103 of file res_xmpp.c.
References ast_cli_args::argc, ast_cli_entry::args, ast_cli_args::argv, ast_cli(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, and ast_cli_entry::usage.
{
switch (cmd) {
case CLI_INIT:
e->command = "xmpp set debug {on|off}";
e->usage =
"Usage: xmpp set debug {on|off}\n"
" Enables/disables dumping of XMPP/Jabber packets for debugging purposes.\n";
return NULL;
case CLI_GENERATE:
return NULL;
}
if (a->argc != e->args) {
return CLI_SHOWUSAGE;
}
if (!strncasecmp(a->argv[e->args - 1], "on", 2)) {
debug = 1;
ast_cli(a->fd, "XMPP Debugging Enabled.\n");
return CLI_SUCCESS;
} else if (!strncasecmp(a->argv[e->args - 1], "off", 3)) {
debug = 0;
ast_cli(a->fd, "XMPP Debugging Disabled.\n");
return CLI_SUCCESS;
}
return CLI_SHOWUSAGE; /* defaults to invalid */
}
| static void xmpp_init_event_distribution | ( | struct ast_xmpp_client * | client | ) | [static] |
Initialize collections for event distribution.
| client | the configured XMPP client we use to connect to a XMPP server |
Definition at line 1444 of file res_xmpp.c.
References ao2_cleanup, ao2_global_obj_ref, ast_enable_distributed_devstate(), AST_EVENT_DEVICE_STATE_CHANGE, ast_event_dump_cache(), AST_EVENT_IE_END, AST_EVENT_MWI, ast_event_subscribe(), ast_event_unsubscribe(), ast_xmpp_client::device_state_sub, ast_xmpp_client::filter, globals, ast_xmpp_client::mwi_sub, ast_xmpp_client::name, xmpp_config_find(), xmpp_pubsub_devstate_cb(), xmpp_pubsub_handle_error(), xmpp_pubsub_handle_event(), xmpp_pubsub_mwi_cb(), xmpp_pubsub_subscribe(), and xmpp_pubsub_unsubscribe().
Referenced by xmpp_connect_hook().
{
RAII_VAR(struct xmpp_config *, cfg, ao2_global_obj_ref(globals), ao2_cleanup);
RAII_VAR(struct ast_xmpp_client_config *, clientcfg, NULL, ao2_cleanup);
if (!cfg || !cfg->clients || !(clientcfg = xmpp_config_find(cfg->clients, client->name))) {
return;
}
xmpp_pubsub_unsubscribe(client, "device_state");
xmpp_pubsub_unsubscribe(client, "message_waiting");
if (!(client->mwi_sub = ast_event_subscribe(AST_EVENT_MWI, xmpp_pubsub_mwi_cb, "xmpp_pubsub_mwi_subscription",
client, AST_EVENT_IE_END))) {
return;
}
if (ast_enable_distributed_devstate()) {
return;
}
if (!(client->device_state_sub = ast_event_subscribe(AST_EVENT_DEVICE_STATE_CHANGE,
xmpp_pubsub_devstate_cb, "xmpp_pubsub_devstate_subscription", client, AST_EVENT_IE_END))) {
ast_event_unsubscribe(client->mwi_sub);
client->mwi_sub = NULL;
return;
}
ast_event_dump_cache(client->device_state_sub);
xmpp_pubsub_subscribe(client, "device_state");
xmpp_pubsub_subscribe(client, "message_waiting");
iks_filter_add_rule(client->filter, xmpp_pubsub_handle_event, client, IKS_RULE_TYPE,
IKS_PAK_MESSAGE, IKS_RULE_FROM, clientcfg->pubsubnode, IKS_RULE_DONE);
iks_filter_add_rule(client->filter, xmpp_pubsub_handle_error, client, IKS_RULE_TYPE,
IKS_PAK_IQ, IKS_RULE_SUBTYPE, IKS_TYPE_ERROR, IKS_RULE_DONE);
}
| static int xmpp_io_recv | ( | struct ast_xmpp_client * | client, |
| char * | buffer, | ||
| size_t | buf_len, | ||
| int | timeout | ||
| ) | [static] |
Internal function which polls on an XMPP client and receives data.
Definition at line 3478 of file res_xmpp.c.
References ast_poll, len(), ast_xmpp_client::parser, ast_xmpp_client::ssl_session, and xmpp_is_secure().
Referenced by xmpp_client_receive().
{
struct pollfd pfd = { .events = POLLIN };
int len, res;
#ifdef HAVE_OPENSSL
if (xmpp_is_secure(client)) {
pfd.fd = SSL_get_fd(client->ssl_session);
if (pfd.fd < 0) {
return -1;
}
} else
#endif /* HAVE_OPENSSL */
pfd.fd = iks_fd(client->parser);
res = ast_poll(&pfd, 1, timeout > 0 ? timeout * 1000 : -1);
if (res > 0) {
#ifdef HAVE_OPENSSL
if (xmpp_is_secure(client)) {
len = SSL_read(client->ssl_session, buffer, buf_len);
} else
#endif /* HAVE_OPENSSL */
len = recv(pfd.fd, buffer, buf_len, 0);
if (len > 0) {
return len;
} else if (len <= 0) {
return -1;
}
}
return res;
}
| static int xmpp_is_secure | ( | struct ast_xmpp_client * | client | ) | [static] |
Helper function which returns whether an XMPP client connection is secure or not.
Definition at line 720 of file res_xmpp.c.
References SECURE, and ast_xmpp_client::stream_flags.
Referenced by xmpp_client_authenticate_sasl(), xmpp_client_request_tls(), xmpp_client_send_raw_message(), and xmpp_io_recv().
{
#ifdef HAVE_OPENSSL
return client->stream_flags & SECURE;
#else
return 0;
#endif
}
| static int xmpp_join_exec | ( | struct ast_channel * | chan, |
| const char * | data | ||
| ) | [static] |
Application to join a chat room.
| chan | ast_channel |
| data | Data is sender|jid|nickname. |
| 0 | success |
| -1 | error |
Definition at line 1651 of file res_xmpp.c.
References ao2_cleanup, ao2_global_obj_ref, args, AST_APP_ARG, AST_DECLARE_APP_ARGS, ast_log(), AST_STANDARD_APP_ARGS, ast_strlen_zero(), ast_test_flag, ast_xmpp_chatroom_join(), globals, LOG_ERROR, XMPP_COMPONENT, xmpp_config_find(), and XMPP_MAX_RESJIDLEN.
Referenced by load_module().
{
RAII_VAR(struct xmpp_config *, cfg, ao2_global_obj_ref(globals), ao2_cleanup);
RAII_VAR(struct ast_xmpp_client_config *, clientcfg, NULL, ao2_cleanup);
char *s, nick[XMPP_MAX_RESJIDLEN];
AST_DECLARE_APP_ARGS(args,
AST_APP_ARG(sender);
AST_APP_ARG(jid);
AST_APP_ARG(nick);
);
if (ast_strlen_zero(data)) {
ast_log(LOG_ERROR, "%s requires arguments (sender,jid[,nickname])\n", app_ajijoin);
return -1;
}
s = ast_strdupa(data);
AST_STANDARD_APP_ARGS(args, s);
if (args.argc < 2 || args.argc > 3) {
ast_log(LOG_ERROR, "%s requires arguments (sender,jid[,nickname])\n", app_ajijoin);
return -1;
}
if (strchr(args.jid, '/')) {
ast_log(LOG_ERROR, "Invalid room name : resource must not be appended\n");
return -1;
}
if (!cfg || !cfg->clients || !(clientcfg = xmpp_config_find(cfg->clients, args.sender))) {
ast_log(LOG_ERROR, "Could not find sender connection: '%s'\n", args.sender);
return -1;
}
if (ast_strlen_zero(args.nick)) {
if (ast_test_flag(&clientcfg->flags, XMPP_COMPONENT)) {
snprintf(nick, sizeof(nick), "asterisk");
} else {
snprintf(nick, sizeof(nick), "%s", clientcfg->client->jid->user);
}
} else {
snprintf(nick, sizeof(nick), "%s", args.nick);
}
if (!ast_strlen_zero(args.jid) && strchr(args.jid, '@')) {
ast_xmpp_chatroom_join(clientcfg->client, args.jid, nick);
} else {
ast_log(LOG_ERROR, "Problem with specified jid of '%s'\n", args.jid);
}
return 0;
}
| static int xmpp_leave_exec | ( | struct ast_channel * | chan, |
| const char * | data | ||
| ) | [static] |
Application to leave a chat room.
| chan | ast_channel |
| data | Data is sender|jid|nickname. |
| 0 | success |
| -1 | error |
Definition at line 1710 of file res_xmpp.c.
References ao2_cleanup, ao2_global_obj_ref, args, AST_APP_ARG, AST_DECLARE_APP_ARGS, ast_log(), AST_STANDARD_APP_ARGS, ast_strlen_zero(), ast_test_flag, ast_xmpp_chatroom_leave(), globals, LOG_ERROR, XMPP_COMPONENT, xmpp_config_find(), and XMPP_MAX_RESJIDLEN.
Referenced by load_module().
{
RAII_VAR(struct xmpp_config *, cfg, ao2_global_obj_ref(globals), ao2_cleanup);
RAII_VAR(struct ast_xmpp_client_config *, clientcfg, NULL, ao2_cleanup);
char *s, nick[XMPP_MAX_RESJIDLEN];
AST_DECLARE_APP_ARGS(args,
AST_APP_ARG(sender);
AST_APP_ARG(jid);
AST_APP_ARG(nick);
);
if (ast_strlen_zero(data)) {
ast_log(LOG_ERROR, "%s requires arguments (sender,jid[,nickname])\n", app_ajileave);
return -1;
}
s = ast_strdupa(data);
AST_STANDARD_APP_ARGS(args, s);
if (args.argc < 2 || args.argc > 3) {
ast_log(LOG_ERROR, "%s requires arguments (sender,jid[,nickname])\n", app_ajileave);
return -1;
}
if (strchr(args.jid, '/')) {
ast_log(LOG_ERROR, "Invalid room name, resource must not be appended\n");
return -1;
}
if (ast_strlen_zero(args.jid) || !strchr(args.jid, '@')) {
ast_log(LOG_ERROR, "No jabber ID specified\n");
return -1;
}
if (!cfg || !cfg->clients || !(clientcfg = xmpp_config_find(cfg->clients, args.sender))) {
ast_log(LOG_ERROR, "Could not find sender connection: '%s'\n", args.sender);
return -1;
}
if (ast_strlen_zero(args.nick)) {
if (ast_test_flag(&clientcfg->flags, XMPP_COMPONENT)) {
snprintf(nick, sizeof(nick), "asterisk");
} else {
snprintf(nick, sizeof(nick), "%s", clientcfg->client->jid->user);
}
} else {
snprintf(nick, sizeof(nick), "%s", args.nick);
}
ast_xmpp_chatroom_leave(clientcfg->client, args.jid, nick);
return 0;
}
| static void xmpp_log_hook | ( | void * | data, |
| const char * | xmpp, | ||
| size_t | size, | ||
| int | incoming | ||
| ) | [static] |
Logging hook function.
Definition at line 2407 of file res_xmpp.c.
References ao2_cleanup, ao2_global_obj_ref, ast_strlen_zero(), ast_test_flag, ast_verbose(), EVENT_FLAG_USER, globals, manager_event, ast_xmpp_client::name, xmpp_config_find(), and XMPP_DEBUG.
Referenced by xmpp_client_config_post_apply(), xmpp_client_receive(), and xmpp_client_send_raw_message().
{
RAII_VAR(struct xmpp_config *, cfg, ao2_global_obj_ref(globals), ao2_cleanup);
RAII_VAR(struct ast_xmpp_client_config *, clientcfg, NULL, ao2_cleanup);
struct ast_xmpp_client *client = data;
if (!ast_strlen_zero(xmpp)) {
manager_event(EVENT_FLAG_USER, "JabberEvent", "Account: %s\r\nPacket: %s\r\n", client->name, xmpp);
}
if (!debug && (!cfg || !cfg->clients || !(clientcfg = xmpp_config_find(cfg->clients, client->name)) || !ast_test_flag(&clientcfg->flags, XMPP_DEBUG))) {
return;
}
if (!incoming) {
ast_verbose("\n<--- XMPP sent to '%s' --->\n%s\n<------------->\n", client->name, xmpp);
} else {
ast_verbose("\n<--- XMPP received from '%s' --->\n%s\n<------------->\n", client->name, xmpp);
}
}
| static void xmpp_message_destroy | ( | struct ast_xmpp_message * | message | ) | [static] |
Destroy function for XMPP messages.
Definition at line 414 of file res_xmpp.c.
References ast_free, ast_xmpp_message::from, and ast_xmpp_message::message.
Referenced by acf_jabberreceive_read(), delete_old_messages(), and xmpp_client_destructor().
| static int xmpp_pak_message | ( | struct ast_xmpp_client * | client, |
| struct ast_xmpp_client_config * | cfg, | ||
| iks * | node, | ||
| ikspak * | pak | ||
| ) | [static] |
Internal function called when a message is received.
Definition at line 3015 of file res_xmpp.c.
References ast_xmpp_message::arrived, ast_calloc, ast_cond_broadcast, ast_copy_string(), ast_debug, AST_LIST_INSERT_HEAD, AST_LIST_LOCK, AST_LIST_UNLOCK, ast_msg_alloc(), ast_msg_destroy(), ast_msg_queue(), ast_msg_set_body(), ast_msg_set_context(), ast_msg_set_from(), ast_msg_set_to(), ast_mutex_lock, ast_mutex_unlock, ast_strdup, ast_strlen_zero(), ast_test_flag, ast_tvnow(), ast_xmpp_client_lock(), ast_xmpp_client_unlock(), ast_xmpp_client_config::context, delete_old_messages(), ast_xmpp_client_config::flags, ast_xmpp_message::from, ast_xmpp_message::id, ast_xmpp_message::message, ast_xmpp_client::messages, ast_xmpp_client::name, S_OR, ast_xmpp_client_config::user, and XMPP_SEND_TO_DIALPLAN.
{
struct ast_xmpp_message *message;
char *body;
int deleted = 0;
ast_debug(3, "XMPP client '%s' received a message\n", client->name);
if (!(body = iks_find_cdata(pak->x, "body"))) {
/* Message contains no body, ignore it. */
return 0;
}
if (!(message = ast_calloc(1, sizeof(*message)))) {
return -1;
}
message->arrived = ast_tvnow();
message->message = ast_strdup(body);
ast_copy_string(message->id, S_OR(pak->id, ""), sizeof(message->id));
message->from = !ast_strlen_zero(pak->from->full) ? ast_strdup(pak->from->full) : NULL;
if (ast_test_flag(&cfg->flags, XMPP_SEND_TO_DIALPLAN)) {
struct ast_msg *msg;
if ((msg = ast_msg_alloc())) {
int res;
ast_xmpp_client_lock(client);
res = ast_msg_set_to(msg, "xmpp:%s", cfg->user);
res |= ast_msg_set_from(msg, "xmpp:%s", message->from);
res |= ast_msg_set_body(msg, "%s", message->message);
res |= ast_msg_set_context(msg, "%s", cfg->context);
ast_xmpp_client_unlock(client);
if (res) {
ast_msg_destroy(msg);
} else {
ast_msg_queue(msg);
}
}
}
/* remove old messages received from this JID
* and insert received message */
deleted = delete_old_messages(client, pak->from->partial);
ast_debug(3, "Deleted %d messages for client %s from JID %s\n", deleted, client->name, pak->from->partial);
AST_LIST_LOCK(&client->messages);
AST_LIST_INSERT_HEAD(&client->messages, message, list);
AST_LIST_UNLOCK(&client->messages);
/* wake up threads waiting for messages */
ast_mutex_lock(&messagelock);
ast_cond_broadcast(&message_received_condition);
ast_mutex_unlock(&messagelock);
return 0;
}
| static int xmpp_pak_presence | ( | struct ast_xmpp_client * | client, |
| struct ast_xmpp_client_config * | cfg, | ||
| iks * | node, | ||
| ikspak * | pak | ||
| ) | [static] |
Internal function called when a presence message is received.
Definition at line 3142 of file res_xmpp.c.
References ao2_alloc, ao2_callback, ao2_find, ao2_link_flags, ao2_lock, ao2_ref, ao2_unlink_flags, ao2_unlock, ast_copy_string(), ast_free, ast_log(), ast_strdup, ast_strlen_zero(), ast_test_flag, ast_xmpp_client::buddies, ast_xmpp_resource::caps, ast_xmpp_resource::description, EVENT_FLAG_USER, ast_xmpp_client_config::flags, ast_xmpp_capabilities::google, ast_xmpp_buddy::id, ast_xmpp_client::jid, LOG_ERROR, LOG_WARNING, manager_event, ast_xmpp_client::name, ast_xmpp_capabilities::node, OBJ_KEY, OBJ_NOLOCK, ast_xmpp_resource::priority, ast_xmpp_resource::resource, ast_xmpp_buddy::resources, S_OR, ast_xmpp_resource::status, status, ast_xmpp_client_config::status, STATUS_DISAPPEAR, ast_xmpp_client_config::statusmsg, type, ast_xmpp_capabilities::version, xmpp_client_send_disco_info_request(), xmpp_client_set_presence(), XMPP_COMPONENT, xmpp_resource_cmp(), and xmpp_resource_destructor().
{
struct ast_xmpp_buddy *buddy;
struct ast_xmpp_resource *resource;
char *type = iks_find_attrib(pak->x, "type");
int status = pak->show ? pak->show : STATUS_DISAPPEAR;
/* If no resource is available this is a general buddy presence update, which we will ignore */
if (!pak->from->resource) {
return 0;
}
if (!(buddy = ao2_find(client->buddies, pak->from->partial, OBJ_KEY))) {
/* Only output the message if it is not about us */
if (strcmp(client->jid->partial, pak->from->partial)) {
ast_log(LOG_WARNING, "Received presence information about '%s' despite not having them in roster on client '%s'\n",
pak->from->partial, client->name);
}
return 0;
}
/* If this is a component presence probe request answer immediately with our presence status */
if (ast_test_flag(&cfg->flags, XMPP_COMPONENT) && !ast_strlen_zero(type) && !strcasecmp(type, "probe")) {
xmpp_client_set_presence(client, pak->from->full, iks_find_attrib(pak->x, "to"), cfg->status, cfg->statusmsg);
}
ao2_lock(buddy->resources);
if (!(resource = ao2_callback(buddy->resources, OBJ_NOLOCK, xmpp_resource_cmp, pak->from->resource))) {
/* Only create the new resource if it is not going away - in reality this should not happen */
if (status != STATUS_DISAPPEAR) {
if (!(resource = ao2_alloc(sizeof(*resource), xmpp_resource_destructor))) {
ast_log(LOG_ERROR, "Could not allocate resource object for resource '%s' of buddy '%s' on client '%s'\n",
pak->from->resource, buddy->id, client->name);
ao2_unlock(buddy->resources);
ao2_ref(buddy, -1);
return 0;
}
ast_copy_string(resource->resource, pak->from->resource, sizeof(resource->resource));
}
} else {
/* We unlink the resource in case the priority changes or in case they are going away */
ao2_unlink_flags(buddy->resources, resource, OBJ_NOLOCK);
}
/* Only update the resource and add it back in if it is not going away */
if (resource && (status != STATUS_DISAPPEAR)) {
char *node, *ver;
/* Try to get the XMPP spec node, and fall back to Google if not found */
if (!(node = iks_find_attrib(iks_find(pak->x, "c"), "node"))) {
node = iks_find_attrib(iks_find(pak->x, "caps:c"), "node");
}
if (!(ver = iks_find_attrib(iks_find(pak->x, "c"), "ver"))) {
ver = iks_find_attrib(iks_find(pak->x, "caps:c"), "ver");
}
if (resource->description) {
ast_free(resource->description);
}
if ((node && strcmp(resource->caps.node, node)) || (ver && strcmp(resource->caps.version, ver))) {
/* For interoperability reasons, proceed even if the resource fails to provide node or version */
if (node) {
ast_copy_string(resource->caps.node, node, sizeof(resource->caps.node));
}
if (ver) {
ast_copy_string(resource->caps.version, ver, sizeof(resource->caps.version));
}
/* Google Talk places the capabilities information directly in presence, so see if it is there */
if (iks_find_with_attrib(pak->x, "c", "node", "http://www.google.com/xmpp/client/caps") ||
iks_find_with_attrib(pak->x, "caps:c", "node", "http://www.google.com/xmpp/client/caps") ||
iks_find_with_attrib(pak->x, "c", "node", "http://www.android.com/gtalk/client/caps") ||
iks_find_with_attrib(pak->x, "caps:c", "node", "http://www.android.com/gtalk/client/caps") ||
iks_find_with_attrib(pak->x, "c", "node", "http://mail.google.com/xmpp/client/caps") ||
iks_find_with_attrib(pak->x, "caps:c", "node", "http://mail.google.com/xmpp/client/caps")) {
resource->caps.google = 1;
}
/* To discover if the buddy supports Jingle we need to query, so do so */
if (xmpp_client_send_disco_info_request(client, pak->from->full, client->jid->full)) {
ast_log(LOG_WARNING, "Could not send discovery information request to resource '%s' of buddy '%s' on client '%s', capabilities may be incomplete\n", resource->resource, buddy->id, client->name);
}
}
resource->status = status;
resource->description = ast_strdup(iks_find_cdata(pak->x, "status"));
resource->priority = atoi((iks_find_cdata(pak->x, "priority")) ? iks_find_cdata(pak->x, "priority") : "0");
ao2_link_flags(buddy->resources, resource, OBJ_NOLOCK);
manager_event(EVENT_FLAG_USER, "JabberStatus",
"Account: %s\r\nJID: %s\r\nResource: %s\r\nStatus: %d\r\nPriority: %d"
"\r\nDescription: %s\r\n",
client->name, pak->from->partial, resource->resource, resource->status,
resource->priority, S_OR(resource->description, ""));
ao2_ref(resource, -1);
} else {
/* This will get hit by presence coming in for an unknown resource, and also when a resource goes away */
if (resource) {
ao2_ref(resource, -1);
}
manager_event(EVENT_FLAG_USER, "JabberStatus",
"Account: %s\r\nJID: %s\r\nStatus: %d\r\n",
client->name, pak->from->partial, pak->show ? pak->show : IKS_SHOW_UNAVAILABLE);
}
ao2_unlock(buddy->resources);
ao2_ref(buddy, -1);
return 0;
}
| static int xmpp_pak_s10n | ( | struct ast_xmpp_client * | client, |
| struct ast_xmpp_client_config * | cfg, | ||
| iks * | node, | ||
| ikspak * | pak | ||
| ) | [static] |
Internal function called when a subscription message is received.
Definition at line 3262 of file res_xmpp.c.
References ao2_find, ao2_lock, ao2_ref, ao2_unlock, ast_log(), ast_test_flag, ast_xmpp_client_send(), ast_xmpp_client::buddies, ast_xmpp_client_config::flags, ast_xmpp_client::jid, LOG_ERROR, LOG_WARNING, ast_xmpp_client::name, OBJ_KEY, OBJ_NOLOCK, status, ast_xmpp_client_config::status, ast_xmpp_client_config::statusmsg, XMPP_AUTOREGISTER, xmpp_client_create_buddy(), xmpp_client_set_presence(), and XMPP_COMPONENT.
{
struct ast_xmpp_buddy *buddy;
switch (pak->subtype) {
case IKS_TYPE_SUBSCRIBE:
if (ast_test_flag(&cfg->flags, XMPP_AUTOREGISTER)) {
iks *presence, *status = NULL;
if ((presence = iks_new("presence")) && (status = iks_new("status"))) {
iks_insert_attrib(presence, "type", "subscribed");
iks_insert_attrib(presence, "to", pak->from->full);
iks_insert_attrib(presence, "from", client->jid->full);
if (pak->id) {
iks_insert_attrib(presence, "id", pak->id);
}
iks_insert_cdata(status, "Asterisk has approved your subscription", 0);
iks_insert_node(presence, status);
if (ast_xmpp_client_send(client, presence)) {
ast_log(LOG_ERROR, "Could not send subscription acceptance to '%s' from client '%s'\n",
pak->from->partial, client->name);
}
} else {
ast_log(LOG_ERROR, "Could not allocate presence stanzas for accepting subscription from '%s' to client '%s'\n",
pak->from->partial, client->name);
}
iks_delete(status);
iks_delete(presence);
}
if (ast_test_flag(&cfg->flags, XMPP_COMPONENT)) {
xmpp_client_set_presence(client, pak->from->full, iks_find_attrib(pak->x, "to"), cfg->status, cfg->statusmsg);
}
/* This purposely flows through so we have the subscriber amongst our buddies */
case IKS_TYPE_SUBSCRIBED:
ao2_lock(client->buddies);
if (!(buddy = ao2_find(client->buddies, pak->from->partial, OBJ_KEY | OBJ_NOLOCK))) {
buddy = xmpp_client_create_buddy(client->buddies, pak->from->partial);
}
if (!buddy) {
ast_log(LOG_WARNING, "Could not find or create buddy '%s' on client '%s'\n",
pak->from->partial, client->name);
} else {
ao2_ref(buddy, -1);
}
ao2_unlock(client->buddies);
break;
default:
break;
}
return 0;
}
| static int xmpp_ping_request | ( | struct ast_xmpp_client * | client, |
| const char * | to, | ||
| const char * | from | ||
| ) | [static] |
Helper function which sends a ping request to a server.
Definition at line 3108 of file res_xmpp.c.
References ast_debug, ast_xmpp_client_lock(), ast_xmpp_client_send(), ast_xmpp_client_unlock(), ast_xmpp_increment_mid(), ast_xmpp_client::mid, and ast_xmpp_client::name.
Referenced by xmpp_client_receive(), and xmpp_client_thread().
{
iks *iq, *ping;
int res;
ast_debug(2, "JABBER: Sending Keep-Alive Ping for client '%s'\n", client->name);
if (!(iq = iks_new("iq")) || !(ping = iks_new("ping"))) {
iks_delete(iq);
return -1;
}
iks_insert_attrib(iq, "type", "get");
iks_insert_attrib(iq, "to", to);
iks_insert_attrib(iq, "from", from);
ast_xmpp_client_lock(client);
iks_insert_attrib(iq, "id", client->mid);
ast_xmpp_increment_mid(client->mid);
ast_xmpp_client_unlock(client);
iks_insert_attrib(ping, "xmlns", "urn:xmpp:ping");
iks_insert_node(iq, ping);
res = ast_xmpp_client_send(client, iq);
iks_delete(ping);
iks_delete(iq);
return res;
}
| static iks* xmpp_pubsub_build_node_config | ( | iks * | pubsub, |
| const char * | node_type, | ||
| const char * | collection_name | ||
| ) | [static] |
Definition at line 962 of file res_xmpp.c.
Referenced by xmpp_pubsub_create_node().
{
iks *configure, *x, *field_owner, *field_node_type, *field_node_config,
*field_deliver_payload, *field_persist_items, *field_access_model,
*field_pubsub_collection;
configure = iks_insert(pubsub, "configure");
x = iks_insert(configure, "x");
iks_insert_attrib(x, "xmlns", "jabber:x:data");
iks_insert_attrib(x, "type", "submit");
field_owner = iks_insert(x, "field");
iks_insert_attrib(field_owner, "var", "FORM_TYPE");
iks_insert_attrib(field_owner, "type", "hidden");
iks_insert_cdata(iks_insert(field_owner, "value"),
"http://jabber.org/protocol/pubsub#owner", 39);
if (node_type) {
field_node_type = iks_insert(x, "field");
iks_insert_attrib(field_node_type, "var", "pubsub#node_type");
iks_insert_cdata(iks_insert(field_node_type, "value"), node_type, strlen(node_type));
}
field_node_config = iks_insert(x, "field");
iks_insert_attrib(field_node_config, "var", "FORM_TYPE");
iks_insert_attrib(field_node_config, "type", "hidden");
iks_insert_cdata(iks_insert(field_node_config, "value"),
"http://jabber.org/protocol/pubsub#node_config", 45);
field_deliver_payload = iks_insert(x, "field");
iks_insert_attrib(field_deliver_payload, "var", "pubsub#deliver_payloads");
iks_insert_cdata(iks_insert(field_deliver_payload, "value"), "1", 1);
field_persist_items = iks_insert(x, "field");
iks_insert_attrib(field_persist_items, "var", "pubsub#persist_items");
iks_insert_cdata(iks_insert(field_persist_items, "value"), "1", 1);
field_access_model = iks_insert(x, "field");
iks_insert_attrib(field_access_model, "var", "pubsub#access_model");
iks_insert_cdata(iks_insert(field_access_model, "value"), "whitelist", 9);
if (node_type && !strcasecmp(node_type, "leaf")) {
field_pubsub_collection = iks_insert(x, "field");
iks_insert_attrib(field_pubsub_collection, "var", "pubsub#collection");
iks_insert_cdata(iks_insert(field_pubsub_collection, "value"), collection_name,
strlen(collection_name));
}
return configure;
}
| static iks* xmpp_pubsub_build_node_request | ( | struct ast_xmpp_client * | client, |
| const char * | collection | ||
| ) | [static] |
Build the a node request.
| client | the configured XMPP client we use to connect to a XMPP server |
| collection | name of the collection for request |
Definition at line 3776 of file res_xmpp.c.
References xmpp_pubsub_iq_create().
Referenced by xmpp_pubsub_purge_nodes(), and xmpp_pubsub_request_nodes().
{
iks *request = xmpp_pubsub_iq_create(client, "get"), *query;
if (!request) {
return NULL;
}
query = iks_insert(request, "query");
iks_insert_attrib(query, "xmlns", "http://jabber.org/protocol/disco#items");
if (collection) {
iks_insert_attrib(query, "node", collection);
}
return request;
}
| static iks* xmpp_pubsub_build_publish_skeleton | ( | struct ast_xmpp_client * | client, |
| const char * | node, | ||
| const char * | event_type, | ||
| unsigned int | cachable | ||
| ) | [static] |
Build the skeleton of a publish.
| client | the configured XMPP client we use to connect to a XMPP server |
| node | Name of the node that will be published to |
| event_type |
Definition at line 925 of file res_xmpp.c.
References ao2_cleanup, ao2_global_obj_ref, AST_DEVSTATE_NOT_CACHABLE, ast_test_flag, globals, publish, xmpp_pubsub_iq_create(), and XMPP_XEP0248.
Referenced by xmpp_pubsub_publish_device_state(), and xmpp_pubsub_publish_mwi().
{
RAII_VAR(struct xmpp_config *, cfg, ao2_global_obj_ref(globals), ao2_cleanup);
iks *request, *pubsub, *publish, *item;
if (!cfg || !cfg->global || !(request = xmpp_pubsub_iq_create(client, "set"))) {
return NULL;
}
pubsub = iks_insert(request, "pubsub");
iks_insert_attrib(pubsub, "xmlns", "http://jabber.org/protocol/pubsub");
publish = iks_insert(pubsub, "publish");
iks_insert_attrib(publish, "node", ast_test_flag(&cfg->global->pubsub, XMPP_XEP0248) ? node : event_type);
item = iks_insert(publish, "item");
iks_insert_attrib(item, "id", node);
if (cachable == AST_DEVSTATE_NOT_CACHABLE) {
iks *options, *x, *field_form_type, *field_persist;
options = iks_insert(pubsub, "publish-options");
x = iks_insert(options, "x");
iks_insert_attrib(x, "xmlns", "jabber:x:data");
iks_insert_attrib(x, "type", "submit");
field_form_type = iks_insert(x, "field");
iks_insert_attrib(field_form_type, "var", "FORM_TYPE");
iks_insert_attrib(field_form_type, "type", "hidden");
iks_insert_cdata(iks_insert(field_form_type, "value"), "http://jabber.org/protocol/pubsub#publish-options", 0);
field_persist = iks_insert(x, "field");
iks_insert_attrib(field_persist, "var", "pubsub#persist_items");
iks_insert_cdata(iks_insert(field_persist, "value"), "0", 1);
}
return item;
}
| static void xmpp_pubsub_create_affiliations | ( | struct ast_xmpp_client * | client, |
| const char * | node | ||
| ) | [static] |
Add Owner affiliations for pubsub node.
| client | the configured XMPP client we use to connect to a XMPP server |
| node | the name of the node to which to add affiliations |
Definition at line 1010 of file res_xmpp.c.
References ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_ref, ast_log(), ast_xmpp_client_send(), ast_xmpp_client::buddies, ast_xmpp_buddy::id, LOG_ERROR, ast_xmpp_client::name, and xmpp_pubsub_iq_create().
Referenced by xmpp_pubsub_create_node().
{
iks *modify_affiliates = xmpp_pubsub_iq_create(client, "set");
iks *pubsub, *affiliations, *affiliate;
struct ao2_iterator i;
struct ast_xmpp_buddy *buddy;
if (!modify_affiliates) {
ast_log(LOG_ERROR, "Could not create IQ for creating affiliations on client '%s'\n", client->name);
return;
}
pubsub = iks_insert(modify_affiliates, "pubsub");
iks_insert_attrib(pubsub, "xmlns", "http://jabber.org/protocol/pubsub#owner");
affiliations = iks_insert(pubsub, "affiliations");
iks_insert_attrib(affiliations, "node", node);
i = ao2_iterator_init(client->buddies, 0);
while ((buddy = ao2_iterator_next(&i))) {
affiliate = iks_insert(affiliations, "affiliation");
iks_insert_attrib(affiliate, "jid", buddy->id);
iks_insert_attrib(affiliate, "affiliation", "owner");
ao2_ref(buddy, -1);
}
ao2_iterator_destroy(&i);
ast_xmpp_client_send(client, modify_affiliates);
iks_delete(modify_affiliates);
}
| static void xmpp_pubsub_create_collection | ( | struct ast_xmpp_client * | client, |
| const char * | collection_name | ||
| ) | [static] |
Create a PubSub collection node.
| client | the configured XMPP client we use to connect to a XMPP server |
| collection_name | The name to use for this collection |
Definition at line 1095 of file res_xmpp.c.
References xmpp_pubsub_create_node().
Referenced by xmpp_cli_create_collection(), and xmpp_pubsub_handle_error().
{
xmpp_pubsub_create_node(client, "collection", collection_name, NULL);
}
| static void xmpp_pubsub_create_leaf | ( | struct ast_xmpp_client * | client, |
| const char * | collection_name, | ||
| const char * | leaf_name | ||
| ) | [static] |
Create a PubSub leaf node.
| client | the configured XMPP client we use to connect to a XMPP server |
| leaf_name | The name to use for this collection |
Definition at line 1107 of file res_xmpp.c.
References xmpp_pubsub_create_node().
Referenced by xmpp_cli_create_leafnode(), and xmpp_pubsub_handle_error().
{
xmpp_pubsub_create_node(client, "leaf", leaf_name, collection_name);
}
| static void xmpp_pubsub_create_node | ( | struct ast_xmpp_client * | client, |
| const char * | node_type, | ||
| const char * | name, | ||
| const char * | collection_name | ||
| ) | [static] |
Create a pubsub node.
| client | the configured XMPP client we use to connect to a XMPP server |
| node_type | the type of node to create |
| name | the name of the node to create |
Definition at line 1047 of file res_xmpp.c.
References ast_xmpp_client_send(), xmpp_pubsub_build_node_config(), xmpp_pubsub_create_affiliations(), and xmpp_pubsub_iq_create().
Referenced by xmpp_pubsub_create_collection(), xmpp_pubsub_create_leaf(), xmpp_pubsub_handle_error(), and xmpp_pubsub_publish_device_state().
{
iks *node, *pubsub, *create;
if (!(node = xmpp_pubsub_iq_create(client, "set"))) {
return;
}
pubsub = iks_insert(node, "pubsub");
iks_insert_attrib(pubsub, "xmlns", "http://jabber.org/protocol/pubsub");
create = iks_insert(pubsub, "create");
iks_insert_attrib(create, "node", name);
xmpp_pubsub_build_node_config(pubsub, node_type, collection_name);
ast_xmpp_client_send(client, node);
xmpp_pubsub_create_affiliations(client, name);
iks_delete(node);
}
| static void xmpp_pubsub_delete_node | ( | struct ast_xmpp_client * | client, |
| const char * | node_name | ||
| ) | [static] |
Delete a PubSub node.
| client | the configured XMPP client we use to connect to a XMPP server |
| node_name | the name of the node to delete return void |
Definition at line 1072 of file res_xmpp.c.
References ast_xmpp_client_send(), and xmpp_pubsub_iq_create().
Referenced by xmpp_cli_delete_pubsub_node(), xmpp_cli_purge_pubsub_nodes(), and xmpp_pubsub_delete_node_list().
{
iks *request, *pubsub, *delete;
if (!(request = xmpp_pubsub_iq_create(client, "set"))) {
return;
}
pubsub = iks_insert(request, "pubsub");
iks_insert_attrib(pubsub, "xmlns", "http://jabber.org/protocol/pubsub#owner");
delete = iks_insert(pubsub, "delete");
iks_insert_attrib(delete, "node", node_name);
ast_xmpp_client_send(client, request);
iks_delete(request);
}
| static int xmpp_pubsub_delete_node_list | ( | void * | data, |
| ikspak * | pak | ||
| ) | [static] |
Delete pubsub item lists.
| data | pointer to ast_xmpp_client structure |
| pak | response from pubsub diso::items query |
Definition at line 3899 of file res_xmpp.c.
References ast_log(), ast_xmpp_client::jid, LOG_WARNING, and xmpp_pubsub_delete_node().
Referenced by xmpp_pubsub_purge_nodes().
{
struct ast_xmpp_client *client = data;
iks *item = NULL;
if (iks_has_children(pak->query)) {
item = iks_first_tag(pak->query);
ast_log(LOG_WARNING, "Connection: %s Node name: %s\n", client->jid->partial,
iks_find_attrib(item, "node"));
while ((item = iks_next_tag(item))) {
xmpp_pubsub_delete_node(client, iks_find_attrib(item, "node"));
}
}
if (item) {
iks_delete(item);
}
return IKS_FILTER_EAT;
}
| static void xmpp_pubsub_devstate_cb | ( | const struct ast_event * | ast_event, |
| void * | data | ||
| ) | [static] |
Callback function for device state events.
| ast_event | |
| data | void pointer to ast_client structure |
Definition at line 1214 of file res_xmpp.c.
References ast_debug, ast_devstate_str(), ast_eid_cmp(), ast_eid_default, ast_event_get_ie_raw(), ast_event_get_ie_str(), ast_event_get_ie_uint(), AST_EVENT_IE_CACHABLE, AST_EVENT_IE_DEVICE, AST_EVENT_IE_EID, AST_EVENT_IE_STATE, and xmpp_pubsub_publish_device_state().
Referenced by xmpp_init_event_distribution().
{
struct ast_xmpp_client *client = data;
const char *device, *device_state;
unsigned int cachable;
if (ast_eid_cmp(&ast_eid_default, ast_event_get_ie_raw(ast_event, AST_EVENT_IE_EID))) {
/* If the event didn't originate from this server, don't send it back out. */
ast_debug(1, "Returning here\n");
return;
}
device = ast_event_get_ie_str(ast_event, AST_EVENT_IE_DEVICE);
device_state = ast_devstate_str(ast_event_get_ie_uint(ast_event, AST_EVENT_IE_STATE));
cachable = ast_event_get_ie_uint(ast_event, AST_EVENT_IE_CACHABLE);
xmpp_pubsub_publish_device_state(client, device, device_state, cachable);
}
| static int xmpp_pubsub_handle_error | ( | void * | data, |
| ikspak * | pak | ||
| ) | [static] |
Definition at line 1371 of file res_xmpp.c.
References ao2_cleanup, ao2_global_obj_ref, ast_debug, ast_log(), ast_test_flag, ast_xmpp_client_send(), globals, LOG_ERROR, xmpp_pubsub_create_collection(), xmpp_pubsub_create_leaf(), xmpp_pubsub_create_node(), xmpp_pubsub_iq_create(), and XMPP_XEP0248.
Referenced by xmpp_init_event_distribution().
{
RAII_VAR(struct xmpp_config *, cfg, ao2_global_obj_ref(globals), ao2_cleanup);
char *node_name, *error;
int error_num;
iks *orig_request, *orig_pubsub = iks_find(pak->x, "pubsub");
struct ast_xmpp_client *client = data;
if (!cfg || !cfg->global) {
ast_log(LOG_ERROR, "No global configuration available\n");
return IKS_FILTER_EAT;
}
if (!orig_pubsub) {
ast_debug(1, "Error isn't a PubSub error, why are we here?\n");
return IKS_FILTER_EAT;
}
orig_request = iks_child(orig_pubsub);
error = iks_find_attrib(iks_find(pak->x, "error"), "code");
node_name = iks_find_attrib(orig_request, "node");
if (!sscanf(error, "%30d", &error_num)) {
return IKS_FILTER_EAT;
}
if (error_num > 399 && error_num < 500 && error_num != 404) {
ast_log(LOG_ERROR,
"Error performing operation on PubSub node %s, %s.\n", node_name, error);
return IKS_FILTER_EAT;
} else if (error_num > 499 && error_num < 600) {
ast_log(LOG_ERROR, "PubSub Server error, %s\n", error);
return IKS_FILTER_EAT;
}
if (!strcasecmp(iks_name(orig_request), "publish")) {
iks *request;
if (ast_test_flag(&cfg->global->pubsub, XMPP_XEP0248)) {
if (iks_find(iks_find(orig_request, "item"), "state")) {
xmpp_pubsub_create_leaf(client, "device_state", node_name);
} else if (iks_find(iks_find(orig_request, "item"), "mailbox")) {
xmpp_pubsub_create_leaf(client, "message_waiting", node_name);
}
} else {
xmpp_pubsub_create_node(client, NULL, node_name, NULL);
}
if ((request = xmpp_pubsub_iq_create(client, "set"))) {
iks_insert_node(request, orig_pubsub);
ast_xmpp_client_send(client, request);
iks_delete(request);
} else {
ast_log(LOG_ERROR, "PubSub publish could not create IQ\n");
}
return IKS_FILTER_EAT;
} else if (!strcasecmp(iks_name(orig_request), "subscribe")) {
if (ast_test_flag(&cfg->global->pubsub, XMPP_XEP0248)) {
xmpp_pubsub_create_collection(client, node_name);
} else {
xmpp_pubsub_create_node(client, NULL, node_name, NULL);
}
}
return IKS_FILTER_EAT;
}
| static int xmpp_pubsub_handle_event | ( | void * | data, |
| ikspak * | pak | ||
| ) | [static] |
Callback for handling PubSub events.
| data | void pointer to ast_xmpp_client structure |
Definition at line 1310 of file res_xmpp.c.
References ast_debug, AST_DEVSTATE_CACHABLE, ast_devstate_val(), ast_eid_cmp(), ast_eid_default, AST_EVENT_DEVICE_STATE_CHANGE, AST_EVENT_IE_CACHABLE, AST_EVENT_IE_CONTEXT, AST_EVENT_IE_DEVICE, AST_EVENT_IE_EID, AST_EVENT_IE_END, AST_EVENT_IE_MAILBOX, AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_OLDMSGS, AST_EVENT_IE_PLTYPE_RAW, AST_EVENT_IE_PLTYPE_STR, AST_EVENT_IE_PLTYPE_UINT, AST_EVENT_IE_STATE, AST_EVENT_MWI, ast_event_new(), ast_event_queue(), ast_event_queue_and_cache(), ast_log(), ast_str_to_eid(), LOG_ERROR, and mailbox.
Referenced by xmpp_init_event_distribution().
{
char *item_id, *device_state, *mailbox, *cachable_str;
int oldmsgs, newmsgs;
iks *item, *item_content;
struct ast_eid pubsub_eid;
struct ast_event *event;
unsigned int cachable = AST_DEVSTATE_CACHABLE;
item = iks_find(iks_find(iks_find(pak->x, "event"), "items"), "item");
if (!item) {
ast_log(LOG_ERROR, "Could not parse incoming PubSub event\n");
return IKS_FILTER_EAT;
}
item_id = iks_find_attrib(item, "id");
item_content = iks_child(item);
ast_str_to_eid(&pubsub_eid, iks_find_attrib(item_content, "eid"));
if (!ast_eid_cmp(&ast_eid_default, &pubsub_eid)) {
ast_debug(1, "Returning here, eid of incoming event matches ours!\n");
return IKS_FILTER_EAT;
}
if (!strcasecmp(iks_name(item_content), "state")) {
if ((cachable_str = iks_find_attrib(item_content, "cachable"))) {
sscanf(cachable_str, "%30d", &cachable);
}
device_state = iks_find_cdata(item, "state");
if (!(event = ast_event_new(AST_EVENT_DEVICE_STATE_CHANGE,
AST_EVENT_IE_DEVICE, AST_EVENT_IE_PLTYPE_STR, item_id, AST_EVENT_IE_STATE,
AST_EVENT_IE_PLTYPE_UINT, ast_devstate_val(device_state), AST_EVENT_IE_EID,
AST_EVENT_IE_PLTYPE_RAW, &pubsub_eid, sizeof(pubsub_eid),
AST_EVENT_IE_CACHABLE, AST_EVENT_IE_PLTYPE_UINT, cachable,
AST_EVENT_IE_END))) {
return IKS_FILTER_EAT;
}
} else if (!strcasecmp(iks_name(item_content), "mailbox")) {
mailbox = strsep(&item_id, "@");
sscanf(iks_find_cdata(item_content, "OLDMSGS"), "%10d", &oldmsgs);
sscanf(iks_find_cdata(item_content, "NEWMSGS"), "%10d", &newmsgs);
if (!(event = ast_event_new(AST_EVENT_MWI,
AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, mailbox,
AST_EVENT_IE_CONTEXT, AST_EVENT_IE_PLTYPE_STR, item_id,
AST_EVENT_IE_OLDMSGS, AST_EVENT_IE_PLTYPE_UINT, oldmsgs,
AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_PLTYPE_UINT, newmsgs,
AST_EVENT_IE_EID, AST_EVENT_IE_PLTYPE_RAW, &pubsub_eid, sizeof(pubsub_eid),
AST_EVENT_IE_END))) {
return IKS_FILTER_EAT;
}
} else {
ast_debug(1, "Don't know how to handle PubSub event of type %s\n",
iks_name(item_content));
return IKS_FILTER_EAT;
}
if (cachable == AST_DEVSTATE_CACHABLE) {
ast_event_queue_and_cache(event);
} else {
ast_event_queue(event);
}
return IKS_FILTER_EAT;
}
| static iks* xmpp_pubsub_iq_create | ( | struct ast_xmpp_client * | client, |
| const char * | type | ||
| ) | [static] |
Create an IQ packet.
| client | the configured XMPP client we use to connect to a XMPP server |
| type | the type of IQ packet to create |
Definition at line 893 of file res_xmpp.c.
References ao2_cleanup, ao2_global_obj_ref, ast_strlen_zero(), ast_xmpp_client_lock(), ast_xmpp_client_unlock(), ast_xmpp_increment_mid(), globals, ast_xmpp_client::jid, ast_xmpp_client::mid, ast_xmpp_client::name, and xmpp_config_find().
Referenced by xmpp_pubsub_build_node_request(), xmpp_pubsub_build_publish_skeleton(), xmpp_pubsub_create_affiliations(), xmpp_pubsub_create_node(), xmpp_pubsub_delete_node(), xmpp_pubsub_handle_error(), xmpp_pubsub_subscribe(), and xmpp_pubsub_unsubscribe().
{
RAII_VAR(struct xmpp_config *, cfg, ao2_global_obj_ref(globals), ao2_cleanup);
RAII_VAR(struct ast_xmpp_client_config *, clientcfg, NULL, ao2_cleanup);
iks *request;
if (!cfg || !cfg->clients || !(clientcfg = xmpp_config_find(cfg->clients, client->name)) ||
!(request = iks_new("iq"))) {
return NULL;
}
if (!ast_strlen_zero(clientcfg->pubsubnode)) {
iks_insert_attrib(request, "to", clientcfg->pubsubnode);
}
iks_insert_attrib(request, "from", client->jid->full);
iks_insert_attrib(request, "type", type);
ast_xmpp_client_lock(client);
ast_xmpp_increment_mid(client->mid);
iks_insert_attrib(request, "id", client->mid);
ast_xmpp_client_unlock(client);
return request;
}
| static void xmpp_pubsub_mwi_cb | ( | const struct ast_event * | ast_event, |
| void * | data | ||
| ) | [static] |
Callback function for MWI events.
| ast_event | |
| data | void pointer to ast_client structure |
Definition at line 1187 of file res_xmpp.c.
References ast_debug, ast_eid_cmp(), ast_eid_default, ast_event_get_ie_raw(), ast_event_get_ie_str(), ast_event_get_ie_uint(), AST_EVENT_IE_CONTEXT, AST_EVENT_IE_EID, AST_EVENT_IE_MAILBOX, AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_OLDMSGS, context, mailbox, and xmpp_pubsub_publish_mwi().
Referenced by xmpp_init_event_distribution().
{
struct ast_xmpp_client *client = data;
const char *mailbox, *context;
char oldmsgs[10], newmsgs[10];
if (ast_eid_cmp(&ast_eid_default, ast_event_get_ie_raw(ast_event, AST_EVENT_IE_EID))) {
/* If the event didn't originate from this server, don't send it back out. */
ast_debug(1, "Returning here\n");
return;
}
mailbox = ast_event_get_ie_str(ast_event, AST_EVENT_IE_MAILBOX);
context = ast_event_get_ie_str(ast_event, AST_EVENT_IE_CONTEXT);
snprintf(oldmsgs, sizeof(oldmsgs), "%d",
ast_event_get_ie_uint(ast_event, AST_EVENT_IE_OLDMSGS));
snprintf(newmsgs, sizeof(newmsgs), "%d",
ast_event_get_ie_uint(ast_event, AST_EVENT_IE_NEWMSGS));
xmpp_pubsub_publish_mwi(client, mailbox, context, oldmsgs, newmsgs);
}
| static void xmpp_pubsub_publish_device_state | ( | struct ast_xmpp_client * | client, |
| const char * | device, | ||
| const char * | device_state, | ||
| unsigned int | cachable | ||
| ) | [static] |
Publish device state to a PubSub node.
| client | the configured XMPP client we use to connect to a XMPP server |
| device | the name of the device whose state to publish |
| device_state | the state to publish |
Definition at line 1151 of file res_xmpp.c.
References ao2_cleanup, ao2_global_obj_ref, ast_eid_default, ast_eid_to_str(), ast_test_flag, ast_xmpp_client_send(), globals, state, XMPP_PUBSUB_AUTOCREATE, xmpp_pubsub_build_publish_skeleton(), xmpp_pubsub_create_node(), and XMPP_XEP0248.
Referenced by xmpp_pubsub_devstate_cb().
{
RAII_VAR(struct xmpp_config *, cfg, ao2_global_obj_ref(globals), ao2_cleanup);
iks *request, *state;
char eid_str[20], cachable_str[2];
if (!cfg || !cfg->global || !(request = xmpp_pubsub_build_publish_skeleton(client, device, "device_state", cachable))) {
return;
}
if (ast_test_flag(&cfg->global->pubsub, XMPP_PUBSUB_AUTOCREATE)) {
if (ast_test_flag(&cfg->global->pubsub, XMPP_XEP0248)) {
xmpp_pubsub_create_node(client, "leaf", device, "device_state");
} else {
xmpp_pubsub_create_node(client, NULL, device, NULL);
}
}
ast_eid_to_str(eid_str, sizeof(eid_str), &ast_eid_default);
state = iks_insert(request, "state");
iks_insert_attrib(state, "xmlns", "http://asterisk.org");
iks_insert_attrib(state, "eid", eid_str);
snprintf(cachable_str, sizeof(cachable_str), "%u", cachable);
iks_insert_attrib(state, "cachable", cachable_str);
iks_insert_cdata(state, device_state, strlen(device_state));
ast_xmpp_client_send(client, iks_root(request));
iks_delete(request);
}
| static void xmpp_pubsub_publish_mwi | ( | struct ast_xmpp_client * | client, |
| const char * | mailbox, | ||
| const char * | context, | ||
| const char * | oldmsgs, | ||
| const char * | newmsgs | ||
| ) | [static] |
Publish MWI to a PubSub node.
| client | the configured XMPP client we use to connect to a XMPP server |
| device | the name of the device whose state to publish |
| device_state | the state to publish |
Definition at line 1120 of file res_xmpp.c.
References AST_DEVSTATE_CACHABLE, ast_eid_default, ast_eid_to_str(), AST_MAX_CONTEXT, AST_MAX_EXTENSION, ast_xmpp_client_send(), and xmpp_pubsub_build_publish_skeleton().
Referenced by xmpp_pubsub_mwi_cb().
{
char full_mailbox[AST_MAX_EXTENSION+AST_MAX_CONTEXT], eid_str[20];
iks *mailbox_node, *request;
snprintf(full_mailbox, sizeof(full_mailbox), "%s@%s", mailbox, context);
if (!(request = xmpp_pubsub_build_publish_skeleton(client, full_mailbox, "message_waiting", AST_DEVSTATE_CACHABLE))) {
return;
}
ast_eid_to_str(eid_str, sizeof(eid_str), &ast_eid_default);
mailbox_node = iks_insert(request, "mailbox");
iks_insert_attrib(mailbox_node, "xmlns", "http://asterisk.org");
iks_insert_attrib(mailbox_node, "eid", eid_str);
iks_insert_cdata(iks_insert(mailbox_node, "NEWMSGS"), newmsgs, strlen(newmsgs));
iks_insert_cdata(iks_insert(mailbox_node, "OLDMSGS"), oldmsgs, strlen(oldmsgs));
ast_xmpp_client_send(client, iks_root(request));
iks_delete(request);
}
| static void xmpp_pubsub_purge_nodes | ( | struct ast_xmpp_client * | client, |
| const char * | collection_name | ||
| ) | [static] |
Definition at line 3920 of file res_xmpp.c.
References ast_xmpp_client_send(), ast_xmpp_client::filter, ast_xmpp_client::mid, xmpp_pubsub_build_node_request(), and xmpp_pubsub_delete_node_list().
Referenced by xmpp_cli_purge_pubsub_nodes().
{
iks *request = xmpp_pubsub_build_node_request(client, collection_name);
ast_xmpp_client_send(client, request);
iks_filter_add_rule(client->filter, xmpp_pubsub_delete_node_list, client, IKS_RULE_TYPE,
IKS_PAK_IQ, IKS_RULE_SUBTYPE, IKS_TYPE_RESULT, IKS_RULE_ID, client->mid,
IKS_RULE_DONE);
ast_xmpp_client_send(client, request);
iks_delete(request);
}
| static int xmpp_pubsub_receive_node_list | ( | void * | data, |
| ikspak * | pak | ||
| ) | [static] |
Receive pubsub item lists.
| data | pointer to ast_xmpp_client structure |
| pak | response from pubsub diso::items query |
Definition at line 3800 of file res_xmpp.c.
References ast_verbose(), ast_xmpp_client::jid, and ast_xmpp_client::name.
Referenced by xmpp_pubsub_request_nodes().
{
struct ast_xmpp_client *client = data;
iks *item = NULL;
if (iks_has_children(pak->query)) {
item = iks_first_tag(pak->query);
ast_verbose("Connection %s: %s\nNode name: %s\n", client->name, client->jid->partial,
iks_find_attrib(item, "node"));
while ((item = iks_next_tag(item))) {
ast_verbose("Node name: %s\n", iks_find_attrib(item, "node"));
}
}
if (item) {
iks_delete(item);
}
return IKS_FILTER_EAT;
}
| static void xmpp_pubsub_request_nodes | ( | struct ast_xmpp_client * | client, |
| const char * | collection | ||
| ) | [static] |
Request item list from pubsub.
| client | the configured XMPP client we use to connect to a XMPP server |
| collection | name of the collection for request |
Definition at line 3828 of file res_xmpp.c.
References ast_log(), ast_xmpp_client_send(), ast_xmpp_client::filter, LOG_ERROR, ast_xmpp_client::mid, ast_xmpp_client::name, xmpp_pubsub_build_node_request(), and xmpp_pubsub_receive_node_list().
Referenced by xmpp_cli_list_pubsub_nodes().
{
iks *request = xmpp_pubsub_build_node_request(client, collection);
if (!request) {
ast_log(LOG_ERROR, "Could not request pubsub nodes on client '%s' - IQ could not be created\n", client->name);
return;
}
iks_filter_add_rule(client->filter, xmpp_pubsub_receive_node_list, client, IKS_RULE_TYPE,
IKS_PAK_IQ, IKS_RULE_SUBTYPE, IKS_TYPE_RESULT, IKS_RULE_ID, client->mid,
IKS_RULE_DONE);
ast_xmpp_client_send(client, request);
iks_delete(request);
}
| static void xmpp_pubsub_subscribe | ( | struct ast_xmpp_client * | client, |
| const char * | node | ||
| ) | [static] |
Subscribe to a PubSub node.
| client | the configured XMPP client we use to connect to a XMPP server |
| node | the name of the node to which to subscribe |
Definition at line 1264 of file res_xmpp.c.
References ao2_cleanup, ao2_global_obj_ref, ast_log(), ast_test_flag, ast_xmpp_client_send(), globals, ast_xmpp_client::jid, LOG_ERROR, ast_xmpp_client::name, subscribe, xmpp_pubsub_iq_create(), and XMPP_XEP0248.
Referenced by xmpp_init_event_distribution().
{
RAII_VAR(struct xmpp_config *, cfg, ao2_global_obj_ref(globals), ao2_cleanup);
iks *request = xmpp_pubsub_iq_create(client, "set");
iks *pubsub, *subscribe;
if (!cfg || !cfg->global || !request) {
ast_log(LOG_ERROR, "Could not create IQ when creating pubsub subscription on client '%s'\n", client->name);
return;
}
pubsub = iks_insert(request, "pubsub");
iks_insert_attrib(pubsub, "xmlns", "http://jabber.org/protocol/pubsub");
subscribe = iks_insert(pubsub, "subscribe");
iks_insert_attrib(subscribe, "jid", client->jid->partial);
iks_insert_attrib(subscribe, "node", node);
if (ast_test_flag(&cfg->global->pubsub, XMPP_XEP0248)) {
iks *options, *x, *sub_options, *sub_type, *sub_depth, *sub_expire;
options = iks_insert(pubsub, "options");
x = iks_insert(options, "x");
iks_insert_attrib(x, "xmlns", "jabber:x:data");
iks_insert_attrib(x, "type", "submit");
sub_options = iks_insert(x, "field");
iks_insert_attrib(sub_options, "var", "FORM_TYPE");
iks_insert_attrib(sub_options, "type", "hidden");
iks_insert_cdata(iks_insert(sub_options, "value"),
"http://jabber.org/protocol/pubsub#subscribe_options", 51);
sub_type = iks_insert(x, "field");
iks_insert_attrib(sub_type, "var", "pubsub#subscription_type");
iks_insert_cdata(iks_insert(sub_type, "value"), "items", 5);
sub_depth = iks_insert(x, "field");
iks_insert_attrib(sub_depth, "var", "pubsub#subscription_depth");
iks_insert_cdata(iks_insert(sub_depth, "value"), "all", 3);
sub_expire = iks_insert(x, "field");
iks_insert_attrib(sub_expire, "var", "pubsub#expire");
iks_insert_cdata(iks_insert(sub_expire, "value"), "presence", 8);
}
ast_xmpp_client_send(client, request);
iks_delete(request);
}
| static void xmpp_pubsub_unsubscribe | ( | struct ast_xmpp_client * | client, |
| const char * | node | ||
| ) | [static] |
Unsubscribe from a PubSub node.
| client | the configured XMPP client we use to connect to a XMPP server |
| node | the name of the node to which to unsubscribe from |
Definition at line 1238 of file res_xmpp.c.
References ast_log(), ast_xmpp_client_send(), ast_xmpp_client::jid, LOG_ERROR, ast_xmpp_client::name, and xmpp_pubsub_iq_create().
Referenced by ast_xmpp_client_disconnect(), and xmpp_init_event_distribution().
{
iks *request = xmpp_pubsub_iq_create(client, "set");
iks *pubsub, *unsubscribe;
if (!request) {
ast_log(LOG_ERROR, "Could not create IQ when creating pubsub unsubscription on client '%s'\n", client->name);
return;
}
pubsub = iks_insert(request, "pubsub");
iks_insert_attrib(pubsub, "xmlns", "http://jabber.org/protocol/pubsub");
unsubscribe = iks_insert(pubsub, "unsubscribe");
iks_insert_attrib(unsubscribe, "jid", client->jid->partial);
iks_insert_attrib(unsubscribe, "node", node);
ast_xmpp_client_send(client, request);
iks_delete(request);
}
| static int xmpp_resource_cmp | ( | void * | obj, |
| void * | arg, | ||
| int | flags | ||
| ) | [static] |
Comparator function for XMPP resource.
Definition at line 701 of file res_xmpp.c.
References CMP_MATCH, CMP_STOP, and ast_xmpp_resource::resource.
Referenced by acf_jabberstatus_read(), xmpp_client_create_buddy(), xmpp_client_service_discovery_result_hook(), xmpp_pak_presence(), and xmpp_status_exec().
{
struct ast_xmpp_resource *resource1 = obj;
const char *resource = arg;
return !strcmp(resource1->resource, resource) ? CMP_MATCH | CMP_STOP : 0;
}
| static void xmpp_resource_destructor | ( | void * | obj | ) | [static] |
Destructor callback function for XMPP resource.
Definition at line 683 of file res_xmpp.c.
References ast_free, ast_xmpp_resource::description, and ast_xmpp_resource::resource.
Referenced by xmpp_pak_presence().
{
struct ast_xmpp_resource *resource = obj;
if (resource->description) {
ast_free(resource->description);
}
}
| static int xmpp_resource_hash | ( | const void * | obj, |
| const int | flags | ||
| ) | [static] |
Hashing function for XMPP resource.
Definition at line 693 of file res_xmpp.c.
References OBJ_KEY, ast_xmpp_resource::priority, and ast_xmpp_resource::resource.
Referenced by xmpp_client_create_buddy().
{
const struct ast_xmpp_resource *resource = obj;
return flags & OBJ_KEY ? -1 : resource->priority;
}
| static int xmpp_resource_immediate | ( | void * | obj, |
| void * | arg, | ||
| int | flags | ||
| ) | [static] |
Internal astobj2 callback function which returns the first resource, which is the highest priority one.
Definition at line 1485 of file res_xmpp.c.
References CMP_MATCH, and CMP_STOP.
Referenced by acf_jabberstatus_read(), and xmpp_status_exec().
| static int xmpp_roster_hook | ( | void * | data, |
| ikspak * | pak | ||
| ) | [static] |
Hook function called when roster is received from server.
Definition at line 2183 of file res_xmpp.c.
References ao2_callback, ao2_cleanup, ao2_find, ao2_global_obj_ref, ao2_ref, ast_log(), ast_test_flag, ast_xmpp_client::buddies, globals, LOG_ERROR, ast_xmpp_client::name, OBJ_KEY, OBJ_MULTIPLE, OBJ_NODATA, ast_xmpp_buddy::subscribe, XMPP_AUTOPRUNE, XMPP_AUTOREGISTER, xmpp_client_change_state(), xmpp_client_create_buddy(), xmpp_client_subscribe_user(), xmpp_client_unsubscribe_user(), xmpp_config_find(), and XMPP_STATE_CONNECTED.
Referenced by xmpp_connect_hook().
{
RAII_VAR(struct xmpp_config *, cfg, ao2_global_obj_ref(globals), ao2_cleanup);
RAII_VAR(struct ast_xmpp_client_config *, clientcfg, NULL, ao2_cleanup);
struct ast_xmpp_client *client = data;
iks *item;
if (!cfg || !cfg->clients || !(clientcfg = xmpp_config_find(cfg->clients, client->name))) {
return IKS_FILTER_EAT;
}
for (item = iks_child(pak->query); item; item = iks_next(item)) {
struct ast_xmpp_buddy *buddy;
if (iks_strcmp(iks_name(item), "item")) {
continue;
}
if (!(buddy = ao2_find(client->buddies, iks_find_attrib(item, "jid"), OBJ_KEY))) {
if (ast_test_flag(&clientcfg->flags, XMPP_AUTOPRUNE)) {
/* The buddy has not been specified in the configuration file, we no longer
* want them on our buddy list or to receive their presence. */
if (xmpp_client_unsubscribe_user(client, iks_find_attrib(item, "jid"))) {
ast_log(LOG_ERROR, "Could not unsubscribe user '%s' on client '%s'\n",
iks_find_attrib(item, "jid"), client->name);
}
continue;
}
if (!(buddy = xmpp_client_create_buddy(client->buddies, iks_find_attrib(item, "jid")))) {
ast_log(LOG_ERROR, "Could not allocate buddy '%s' on client '%s'\n", iks_find_attrib(item, "jid"),
client->name);
continue;
}
}
/* Determine if we need to subscribe to their presence or not */
if (!iks_strcmp(iks_find_attrib(item, "subscription"), "none") ||
!iks_strcmp(iks_find_attrib(item, "subscription"), "from")) {
buddy->subscribe = 1;
} else {
buddy->subscribe = 0;
}
ao2_ref(buddy, -1);
}
/* If autoregister is enabled we need to go through every buddy that we need to subscribe to and do so */
if (ast_test_flag(&clientcfg->flags, XMPP_AUTOREGISTER)) {
ao2_callback(client->buddies, OBJ_NODATA | OBJ_MULTIPLE, xmpp_client_subscribe_user, client);
}
xmpp_client_change_state(client, XMPP_STATE_CONNECTED);
return IKS_FILTER_EAT;
}
| static int xmpp_send_cb | ( | const struct ast_msg * | msg, |
| const char * | to, | ||
| const char * | from | ||
| ) | [static] |
Definition at line 2058 of file res_xmpp.c.
References ao2_cleanup, ao2_global_obj_ref, ast_debug, ast_log(), ast_msg_get_body(), ast_strlen_zero(), ast_xmpp_client_send_message(), globals, LOG_ERROR, LOG_WARNING, and xmpp_config_find().
{
RAII_VAR(struct xmpp_config *, cfg, ao2_global_obj_ref(globals), ao2_cleanup);
RAII_VAR(struct ast_xmpp_client_config *, clientcfg, NULL, ao2_cleanup);
char *sender, *dest;
int res;
sender = ast_strdupa(from);
strsep(&sender, ":");
dest = ast_strdupa(to);
strsep(&dest, ":");
if (ast_strlen_zero(sender)) {
ast_log(LOG_ERROR, "MESSAGE(from) of '%s' invalid for XMPP\n", from);
return -1;
}
if (!cfg || !cfg->clients || !(clientcfg = xmpp_config_find(cfg->clients, sender))) {
ast_log(LOG_WARNING, "Could not finder account to send from as '%s'\n", sender);
return -1;
}
ast_debug(1, "Sending message to '%s' from '%s'\n", dest, clientcfg->name);
if ((res = ast_xmpp_client_send_message(clientcfg->client, dest, ast_msg_get_body(msg))) != IKS_OK) {
ast_log(LOG_WARNING, "Failed to send XMPP message (%d).\n", res);
}
return res == IKS_OK ? 0 : -1;
}
| static int xmpp_send_exec | ( | struct ast_channel * | chan, |
| const char * | data | ||
| ) | [static] |
Definition at line 1771 of file res_xmpp.c.
References ao2_cleanup, ao2_global_obj_ref, args, AST_APP_ARG, AST_DECLARE_APP_ARGS, ast_log(), AST_STANDARD_APP_ARGS, ast_strlen_zero(), ast_xmpp_client_send_message(), globals, LOG_WARNING, and xmpp_config_find().
Referenced by load_module().
{
RAII_VAR(struct xmpp_config *, cfg, ao2_global_obj_ref(globals), ao2_cleanup);
RAII_VAR(struct ast_xmpp_client_config *, clientcfg, NULL, ao2_cleanup);
char *s;
AST_DECLARE_APP_ARGS(args,
AST_APP_ARG(sender);
AST_APP_ARG(recipient);
AST_APP_ARG(message);
);
if (ast_strlen_zero(data)) {
ast_log(LOG_WARNING, "%s requires arguments (account,jid,message)\n", app_ajisend);
return -1;
}
s = ast_strdupa(data);
AST_STANDARD_APP_ARGS(args, s);
if ((args.argc < 3) || ast_strlen_zero(args.message) || !strchr(args.recipient, '@')) {
ast_log(LOG_WARNING, "%s requires arguments (account,jid,message)\n", app_ajisend);
return -1;
}
if (!cfg || !cfg->clients || !(clientcfg = xmpp_config_find(cfg->clients, args.sender))) {
ast_log(LOG_WARNING, "Could not find sender connection: '%s'\n", args.sender);
return -1;
}
ast_xmpp_client_send_message(clientcfg->client, args.recipient, args.message);
return 0;
}
| static int xmpp_send_stream_header | ( | struct ast_xmpp_client * | client, |
| const struct ast_xmpp_client_config * | cfg, | ||
| const char * | to | ||
| ) | [static] |
Helper function which sends an XMPP stream header to the server.
Definition at line 2456 of file res_xmpp.c.
References ast_test_flag, ast_xmpp_client_config::flags, xmpp_client_send_raw_message(), and XMPP_COMPONENT.
Referenced by xmpp_client_authenticating(), and xmpp_client_requested_tls().
{
char *namespace = ast_test_flag(&cfg->flags, XMPP_COMPONENT) ? "jabber:component:accept" : "jabber:client";
char msg[91 + strlen(namespace) + 6 + strlen(to) + 16 + 1];
snprintf(msg, sizeof(msg), "<?xml version='1.0'?>"
"<stream:stream xmlns:stream='http://etherx.jabber.org/streams' xmlns='"
"%s' to='%s' version='1.0'>", namespace, to);
return xmpp_client_send_raw_message(client, msg);
}
| static int xmpp_sendgroup_exec | ( | struct ast_channel * | chan, |
| const char * | data | ||
| ) | [static] |
Application to send a message to a groupchat.
| chan | ast_channel |
| data | Data is sender|groupchat|message. |
| 0 | success |
| -1 | error |
Definition at line 1812 of file res_xmpp.c.
References ao2_cleanup, ao2_global_obj_ref, args, AST_APP_ARG, AST_DECLARE_APP_ARGS, ast_log(), AST_STANDARD_APP_ARGS, ast_strlen_zero(), ast_test_flag, ast_xmpp_chatroom_send(), globals, LOG_ERROR, XMPP_COMPONENT, xmpp_config_find(), and XMPP_MAX_RESJIDLEN.
Referenced by load_module().
{
RAII_VAR(struct xmpp_config *, cfg, ao2_global_obj_ref(globals), ao2_cleanup);
RAII_VAR(struct ast_xmpp_client_config *, clientcfg, NULL, ao2_cleanup);
char *s, nick[XMPP_MAX_RESJIDLEN];
AST_DECLARE_APP_ARGS(args,
AST_APP_ARG(sender);
AST_APP_ARG(groupchat);
AST_APP_ARG(message);
AST_APP_ARG(nick);
);
if (ast_strlen_zero(data)) {
ast_log(LOG_ERROR, "%s requires arguments (sender,groupchatid,message[,nickname])\n", app_ajisendgroup);
return -1;
}
s = ast_strdupa(data);
AST_STANDARD_APP_ARGS(args, s);
if ((args.argc < 3) || (args.argc > 4) || ast_strlen_zero(args.message) || !strchr(args.groupchat, '@')) {
ast_log(LOG_ERROR, "%s requires arguments (sender,groupchatid,message[,nickname])\n", app_ajisendgroup);
return -1;
}
if (!cfg || !cfg->clients || !(clientcfg = xmpp_config_find(cfg->clients, args.sender))) {
ast_log(LOG_ERROR, "Could not find sender connection: '%s'\n", args.sender);
return -1;
}
if (ast_strlen_zero(args.nick) || args.argc == 3) {
if (ast_test_flag(&clientcfg->flags, XMPP_COMPONENT)) {
snprintf(nick, sizeof(nick), "asterisk");
} else {
snprintf(nick, sizeof(nick), "%s", clientcfg->client->jid->user);
}
} else {
snprintf(nick, sizeof(nick), "%s", args.nick);
}
ast_xmpp_chatroom_send(clientcfg->client, nick, args.groupchat, args.message);
return 0;
}
| static char* xmpp_show_buddies | ( | struct ast_cli_entry * | e, |
| int | cmd, | ||
| struct ast_cli_args * | a | ||
| ) | [static] |
Definition at line 4213 of file res_xmpp.c.
References ao2_cleanup, ao2_global_obj_ref, ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_ref, ast_cli(), ast_xmpp_client::buddies, ast_xmpp_resource::caps, CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_xmpp_client_config::client, ast_cli_entry::command, ast_cli_args::fd, globals, ast_xmpp_capabilities::google, ast_xmpp_buddy::id, ast_xmpp_capabilities::jingle, ast_xmpp_client_config::name, ast_xmpp_capabilities::node, ast_xmpp_resource::resource, ast_xmpp_buddy::resources, ast_cli_entry::usage, and ast_xmpp_capabilities::version.
{
RAII_VAR(struct xmpp_config *, cfg, ao2_global_obj_ref(globals), ao2_cleanup);
struct ao2_iterator i;
struct ast_xmpp_client_config *clientcfg;
switch (cmd) {
case CLI_INIT:
e->command = "xmpp show buddies";
e->usage =
"Usage: xmpp show buddies\n"
" Shows buddy lists of our clients\n";
return NULL;
case CLI_GENERATE:
return NULL;
}
if (!cfg || !cfg->clients) {
return NULL;
}
ast_cli(a->fd, "XMPP buddy lists\n");
i = ao2_iterator_init(cfg->clients, 0);
while ((clientcfg = ao2_iterator_next(&i))) {
struct ao2_iterator bud;
struct ast_xmpp_buddy *buddy;
ast_cli(a->fd, "Client: %s\n", clientcfg->name);
bud = ao2_iterator_init(clientcfg->client->buddies, 0);
while ((buddy = ao2_iterator_next(&bud))) {
struct ao2_iterator res;
struct ast_xmpp_resource *resource;
ast_cli(a->fd, "\tBuddy:\t%s\n", buddy->id);
res = ao2_iterator_init(buddy->resources, 0);
while ((resource = ao2_iterator_next(&res))) {
ast_cli(a->fd, "\t\tResource: %s\n", resource->resource);
ast_cli(a->fd, "\t\t\tnode: %s\n", resource->caps.node);
ast_cli(a->fd, "\t\t\tversion: %s\n", resource->caps.version);
ast_cli(a->fd, "\t\t\tGoogle Talk capable: %s\n", resource->caps.google ? "yes" : "no");
ast_cli(a->fd, "\t\t\tJingle capable: %s\n", resource->caps.jingle ? "yes" : "no");
ao2_ref(resource, -1);
}
ao2_iterator_destroy(&res);
ao2_ref(buddy, -1);
}
ao2_iterator_destroy(&bud);
ao2_ref(clientcfg, -1);
}
ao2_iterator_destroy(&i);
return CLI_SUCCESS;
}
| static char* xmpp_show_clients | ( | struct ast_cli_entry * | e, |
| int | cmd, | ||
| struct ast_cli_args * | a | ||
| ) | [static] |
Definition at line 4137 of file res_xmpp.c.
References ao2_cleanup, ao2_container_count(), ao2_global_obj_ref, ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_ref, ast_cli(), CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_xmpp_client_config::client, ast_cli_entry::command, ast_cli_args::fd, globals, ast_xmpp_client_config::name, ast_xmpp_client::state, state, ast_cli_entry::usage, ast_xmpp_client_config::user, XMPP_STATE_AUTHENTICATE, XMPP_STATE_AUTHENTICATING, XMPP_STATE_CONNECTED, XMPP_STATE_CONNECTING, XMPP_STATE_DISCONNECTED, XMPP_STATE_DISCONNECTING, XMPP_STATE_REQUEST_TLS, XMPP_STATE_REQUESTED_TLS, and XMPP_STATE_ROSTER.
{
RAII_VAR(struct xmpp_config *, cfg, ao2_global_obj_ref(globals), ao2_cleanup);
struct ao2_iterator i;
struct ast_xmpp_client_config *clientcfg;
switch (cmd) {
case CLI_INIT:
e->command = "xmpp show connections";
e->usage =
"Usage: xmpp show connections\n"
" Shows state of client and component connections\n";
return NULL;
case CLI_GENERATE:
return NULL;
}
if (!cfg || !cfg->clients) {
return NULL;
}
ast_cli(a->fd, "Jabber Users and their status:\n");
i = ao2_iterator_init(cfg->clients, 0);
while ((clientcfg = ao2_iterator_next(&i))) {
char *state;
switch (clientcfg->client->state) {
case XMPP_STATE_DISCONNECTING:
state = "Disconnecting";
break;
case XMPP_STATE_DISCONNECTED:
state = "Disconnected";
break;
case XMPP_STATE_CONNECTING:
state = "Connecting";
break;
case XMPP_STATE_REQUEST_TLS:
state = "Waiting to request TLS";
break;
case XMPP_STATE_REQUESTED_TLS:
state = "Requested TLS";
break;
case XMPP_STATE_AUTHENTICATE:
state = "Waiting to authenticate";
break;
case XMPP_STATE_AUTHENTICATING:
state = "Authenticating";
break;
case XMPP_STATE_ROSTER:
state = "Retrieving roster";
break;
case XMPP_STATE_CONNECTED:
state = "Connected";
break;
default:
state = "Unknown";
}
ast_cli(a->fd, " [%s] %s - %s\n", clientcfg->name, clientcfg->user, state);
ao2_ref(clientcfg, -1);
}
ao2_iterator_destroy(&i);
ast_cli(a->fd, "----\n");
ast_cli(a->fd, " Number of clients: %d\n", ao2_container_count(cfg->clients));
return CLI_SUCCESS;
}
| static int xmpp_status_exec | ( | struct ast_channel * | chan, |
| const char * | data | ||
| ) | [static] |
Definition at line 1499 of file res_xmpp.c.
References ao2_callback, ao2_cleanup, ao2_find, ao2_global_obj_ref, ao2_ref, args, AST_APP_ARG, AST_DECLARE_APP_ARGS, ast_log(), AST_NONSTANDARD_APP_ARGS, AST_STANDARD_APP_ARGS, ast_strlen_zero(), globals, LOG_ERROR, LOG_NOTICE, LOG_WARNING, OBJ_KEY, OBJ_NODATA, pbx_builtin_setvar_helper(), ast_xmpp_resource::resource, ast_xmpp_buddy::resources, ast_xmpp_resource::status, status, xmpp_config_find(), xmpp_resource_cmp(), and xmpp_resource_immediate().
Referenced by load_module().
{
RAII_VAR(struct xmpp_config *, cfg, ao2_global_obj_ref(globals), ao2_cleanup);
RAII_VAR(struct ast_xmpp_client_config *, clientcfg, NULL, ao2_cleanup);
struct ast_xmpp_buddy *buddy;
struct ast_xmpp_resource *resource;
char *s = NULL, status[2];
int stat = 7;
static int deprecation_warning = 0;
AST_DECLARE_APP_ARGS(args,
AST_APP_ARG(sender);
AST_APP_ARG(jid);
AST_APP_ARG(variable);
);
AST_DECLARE_APP_ARGS(jid,
AST_APP_ARG(screenname);
AST_APP_ARG(resource);
);
if (deprecation_warning++ % 10 == 0) {
ast_log(LOG_WARNING, "JabberStatus is deprecated. Please use the JABBER_STATUS dialplan function in the future.\n");
}
if (ast_strlen_zero(data)) {
ast_log(LOG_ERROR, "Usage: JabberStatus(<sender>,<jid>[/<resource>],<varname>\n");
return 0;
}
s = ast_strdupa(data);
AST_STANDARD_APP_ARGS(args, s);
if (args.argc != 3) {
ast_log(LOG_ERROR, "JabberStatus() requires 3 arguments.\n");
return -1;
}
AST_NONSTANDARD_APP_ARGS(jid, args.jid, '/');
if (jid.argc < 1 || jid.argc > 2) {
ast_log(LOG_WARNING, "Wrong JID %s, exiting\n", args.jid);
return -1;
}
if (!cfg || !cfg->clients || !(clientcfg = xmpp_config_find(cfg->clients, args.sender))) {
ast_log(LOG_WARNING, "Could not find sender connection: '%s'\n", args.sender);
return -1;
}
if (!(buddy = ao2_find(clientcfg->client->buddies, jid.screenname, OBJ_KEY))) {
ast_log(LOG_WARNING, "Could not find buddy in list: '%s'\n", jid.screenname);
return -1;
}
if (ast_strlen_zero(jid.resource) || !(resource = ao2_callback(buddy->resources, 0, xmpp_resource_cmp, jid.resource))) {
resource = ao2_callback(buddy->resources, OBJ_NODATA, xmpp_resource_immediate, NULL);
}
ao2_ref(buddy, -1);
if (resource) {
stat = resource->status;
ao2_ref(resource, -1);
} else {
ast_log(LOG_NOTICE, "Resource '%s' of buddy '%s' was not found\n", jid.resource, jid.screenname);
}
snprintf(status, sizeof(status), "%d", stat);
pbx_builtin_setvar_helper(chan, args.variable, status);
return 0;
}
struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER , .description = "Asterisk XMPP Interface" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .reload = reload, .load_pri = AST_MODPRI_CHANNEL_DEPEND, } [static] |
Definition at line 4484 of file res_xmpp.c.
const char* app_ajijoin = "JabberJoin" [static] |
Definition at line 396 of file res_xmpp.c.
const char* app_ajileave = "JabberLeave" [static] |
Definition at line 397 of file res_xmpp.c.
const char* app_ajisend = "JabberSend" [static] |
Definition at line 393 of file res_xmpp.c.
const char* app_ajisendgroup = "JabberSendGroup" [static] |
Definition at line 394 of file res_xmpp.c.
const char* app_ajistatus = "JabberStatus" [static] |
Definition at line 395 of file res_xmpp.c.
struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 4484 of file res_xmpp.c.
struct aco_type client_option [static] |
Definition at line 659 of file res_xmpp.c.
| struct aco_type* client_options[] = ACO_TYPES(&client_option) |
Definition at line 669 of file res_xmpp.c.
int debug [static] |
Global debug status.
Definition at line 322 of file res_xmpp.c.
Referenced by add_sdp(), aji_create_client(), aji_load_config(), check_peer_ok(), handle_pri_show_debug(), process_sdp(), process_sdp_a_audio(), process_sdp_a_text(), process_sdp_a_video(), set_destination(), and sip_sendtext().
struct aco_type global_option [static] |
Definition at line 650 of file res_xmpp.c.
| struct aco_type* global_options[] = ACO_TYPES(&global_option) |
Definition at line 657 of file res_xmpp.c.
struct ast_custom_function jabberreceive_function [static] |
{
.name = "JABBER_RECEIVE",
.read = acf_jabberreceive_read,
}
Definition at line 2011 of file res_xmpp.c.
struct ast_custom_function jabberstatus_function [static] |
{
.name = "JABBER_STATUS",
.read = acf_jabberstatus_read,
}
Definition at line 1639 of file res_xmpp.c.
ast_cond_t message_received_condition [static] |
Definition at line 399 of file res_xmpp.c.
ast_mutex_t messagelock [static] |
Definition at line 400 of file res_xmpp.c.
struct ast_msg_tech msg_tech [static] |
{
.name = "xmpp",
.msg_send = xmpp_send_cb,
}
Definition at line 2089 of file res_xmpp.c.
| struct aco_file res_xmpp_conf |
{
.filename = "xmpp.conf",
.alias = "jabber.conf",
.types = ACO_TYPES(&global_option, &client_option),
}
Definition at line 671 of file res_xmpp.c.
struct ast_cli_entry xmpp_cli[] [static] |
Definition at line 4273 of file res_xmpp.c.
struct xmpp_pak_handler xmpp_pak_handlers[] [static] |
Referenced by xmpp_action_hook().
struct xmpp_state_handler xmpp_state_handlers[] [static] |
Referenced by xmpp_action_hook().