Asterisk - The Open Source Telephony Project  18.5.0
Data Structures | Macros | Enumerations | Functions
xmpp.h File Reference

XMPP Interface. More...

#include <openssl/ssl.h>
#include <openssl/err.h>
#include <iksemel.h>
#include "asterisk/utils.h"
#include "asterisk/astobj2.h"
#include "asterisk/linkedlists.h"
#include "asterisk/stringfields.h"
#include "asterisk/pbx.h"
#include "asterisk/stasis.h"
Include dependency graph for xmpp.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ast_xmpp_buddy
 XMPP Buddy. More...
 
struct  ast_xmpp_capabilities
 Resource capabilities. More...
 
struct  ast_xmpp_client
 XMPP Client Connection. More...
 
struct  ast_xmpp_message
 XMPP Message. More...
 
struct  ast_xmpp_resource
 XMPP Resource. More...
 

Macros

#define IKS_NET_EXPIRED   12
 
#define NET_IO_BUF_SIZE   16384
 
#define XMPP_MAX_ATTRLEN   256
 Maximum size of an attribute. More...
 
#define XMPP_MAX_JIDLEN   3071
 
#define XMPP_MAX_RESJIDLEN   1023
 Maximum size of a resource JID. More...
 

Enumerations

enum  xmpp_state {
  XMPP_STATE_DISCONNECTING, XMPP_STATE_DISCONNECTED, XMPP_STATE_CONNECTING, XMPP_STATE_REQUEST_TLS,
  XMPP_STATE_REQUESTED_TLS, XMPP_STATE_AUTHENTICATE, XMPP_STATE_AUTHENTICATING, XMPP_STATE_ROSTER,
  XMPP_STATE_CONNECTED
}
 Client connection states. More...
 

Functions

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. More...
 
int ast_xmpp_chatroom_join (struct ast_xmpp_client *client, const char *room, const char *nickname)
 Join an XMPP multi-user chatroom. More...
 
int ast_xmpp_chatroom_leave (struct ast_xmpp_client *client, const char *room, const char *nickname)
 Leave an XMPP multi-user chatroom. More...
 
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. More...
 
int ast_xmpp_client_disconnect (struct ast_xmpp_client *client)
 Disconnect an XMPP client connection. More...
 
struct ast_xmpp_clientast_xmpp_client_find (const char *name)
 Find an XMPP client connection using a given name. More...
 
void ast_xmpp_client_lock (struct ast_xmpp_client *client)
 Lock an XMPP client connection. More...
 
int ast_xmpp_client_send (struct ast_xmpp_client *client, iks *stanza)
 Send an XML stanza out using an established XMPP client connection. More...
 
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. More...
 
void ast_xmpp_client_unlock (struct ast_xmpp_client *client)
 Unlock an XMPP client connection. More...
 
void ast_xmpp_client_unref (struct ast_xmpp_client *client)
 Release XMPP client connection reference. More...
 
void ast_xmpp_increment_mid (char *mid)
 Helper function which increments the message identifier. More...
 

Detailed Description

XMPP Interface.

Author
Joshua Colp jcolp.nosp@m.@dig.nosp@m.ium.c.nosp@m.om IKSEMEL http://iksemel.jabberstudio.org

Definition in file xmpp.h.

Macro Definition Documentation

◆ IKS_NET_EXPIRED

#define IKS_NET_EXPIRED   12

Definition at line 41 of file xmpp.h.

Referenced by xmpp_client_receive(), and xmpp_client_thread().

◆ NET_IO_BUF_SIZE

#define NET_IO_BUF_SIZE   16384

Definition at line 38 of file xmpp.h.

Referenced by xmpp_client_receive().

◆ XMPP_MAX_ATTRLEN

#define XMPP_MAX_ATTRLEN   256

Maximum size of an attribute.

Definition at line 68 of file xmpp.h.

Referenced by xmpp_action_hook().

◆ XMPP_MAX_JIDLEN

#define XMPP_MAX_JIDLEN   3071

◆ XMPP_MAX_RESJIDLEN

#define XMPP_MAX_RESJIDLEN   1023

Maximum size of a resource JID.

Definition at line 65 of file xmpp.h.

Referenced by xmpp_join_exec(), xmpp_leave_exec(), and xmpp_sendgroup_exec().

Enumeration Type Documentation

◆ xmpp_state

enum xmpp_state

Client connection states.

Enumerator
XMPP_STATE_DISCONNECTING 

Client is disconnecting

XMPP_STATE_DISCONNECTED 

Client is disconnected

XMPP_STATE_CONNECTING 

Client is connecting

XMPP_STATE_REQUEST_TLS 

Client should request TLS

XMPP_STATE_REQUESTED_TLS 

Client has requested TLS

XMPP_STATE_AUTHENTICATE 

Client needs to authenticate

XMPP_STATE_AUTHENTICATING 

Client is authenticating

XMPP_STATE_ROSTER 

Client is currently getting the roster

XMPP_STATE_CONNECTED 

Client is fully connected

Definition at line 71 of file xmpp.h.

71  {
72  XMPP_STATE_DISCONNECTING, /*!< Client is disconnecting */
73  XMPP_STATE_DISCONNECTED, /*!< Client is disconnected */
74  XMPP_STATE_CONNECTING, /*!< Client is connecting */
75  XMPP_STATE_REQUEST_TLS, /*!< Client should request TLS */
76  XMPP_STATE_REQUESTED_TLS, /*!< Client has requested TLS */
77  XMPP_STATE_AUTHENTICATE, /*!< Client needs to authenticate */
78  XMPP_STATE_AUTHENTICATING, /*!< Client is authenticating */
79  XMPP_STATE_ROSTER, /*!< Client is currently getting the roster */
80  XMPP_STATE_CONNECTED, /*!< Client is fully connected */
81 };

Function Documentation

◆ ast_xmpp_chatroom_invite()

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.

Parameters
clientPointer to the client
userJID of the user
roomName of the chatroom
messageMessage to send with the invitation
Return values
0on success
-1on failure

Definition at line 937 of file res_xmpp.c.

References ast_xmpp_client_lock(), ast_xmpp_client_send(), ast_xmpp_client_unlock(), ast_xmpp_increment_mid(), done, ast_xmpp_client::mid, and NULL.

938 {
939  int res = 0;
940  iks *invite, *body = NULL, *namespace = NULL;
941 
942  if (!(invite = iks_new("message")) || !(body = iks_new("body")) || !(namespace = iks_new("x"))) {
943  res = -1;
944  goto done;
945  }
946 
947  iks_insert_attrib(invite, "to", user);
948  ast_xmpp_client_lock(client);
949  iks_insert_attrib(invite, "id", client->mid);
950  ast_xmpp_increment_mid(client->mid);
951  ast_xmpp_client_unlock(client);
952  iks_insert_cdata(body, message, 0);
953  iks_insert_node(invite, body);
954  iks_insert_attrib(namespace, "xmlns", "jabber:x:conference");
955  iks_insert_attrib(namespace, "jid", room);
956  iks_insert_node(invite, namespace);
957 
958  res = ast_xmpp_client_send(client, invite);
959 
960 done:
961  iks_delete(namespace);
962  iks_delete(body);
963  iks_delete(invite);
964 
965  return res;
966 }
void ast_xmpp_increment_mid(char *mid)
Helper function which increments the message identifier.
Definition: res_xmpp.c:1019
void ast_xmpp_client_lock(struct ast_xmpp_client *client)
Lock an XMPP client connection.
Definition: res_xmpp.c:893
#define NULL
Definition: resample.c:96
int done
Definition: test_amihooks.c:48
structure to hold users read from users.conf
char mid[6]
Definition: xmpp.h:125
void ast_xmpp_client_unlock(struct ast_xmpp_client *client)
Unlock an XMPP client connection.
Definition: res_xmpp.c:898
int ast_xmpp_client_send(struct ast_xmpp_client *client, iks *stanza)
Send an XML stanza out using an established XMPP client connection.
Definition: res_xmpp.c:2537

◆ ast_xmpp_chatroom_join()

int ast_xmpp_chatroom_join ( struct ast_xmpp_client client,
const char *  room,
const char *  nickname 
)

Join an XMPP multi-user chatroom.

Parameters
clientPointer to the client
roomName of the chatroom
nicknameNickname to use
Return values
0on success
-1on failure

Definition at line 1004 of file res_xmpp.c.

References xmpp_client_set_group_presence().

Referenced by xmpp_join_exec().

1005 {
1006  return xmpp_client_set_group_presence(client, room, IKS_SHOW_AVAILABLE, nickname);
1007 }
static int xmpp_client_set_group_presence(struct ast_xmpp_client *client, const char *room, int level, const char *nick)
Definition: res_xmpp.c:968

◆ ast_xmpp_chatroom_leave()

int ast_xmpp_chatroom_leave ( struct ast_xmpp_client client,
const char *  room,
const char *  nickname 
)

Leave an XMPP multi-user chatroom.

Parameters
clientPointer to the client
roomName of the chatroom
nicknameNickname being used
Return values
0on success
-1on failure

Definition at line 1014 of file res_xmpp.c.

References xmpp_client_set_group_presence().

Referenced by xmpp_leave_exec().

1015 {
1016  return xmpp_client_set_group_presence(client, room, IKS_SHOW_UNAVAILABLE, nickname);
1017 }
static int xmpp_client_set_group_presence(struct ast_xmpp_client *client, const char *room, int level, const char *nick)
Definition: res_xmpp.c:968

◆ ast_xmpp_chatroom_send()

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.

Parameters
clientPointer to the client
nicknameNickname to use
addressAddress of the room
messageMessage itself
Return values
0on success
-1on failure

Definition at line 1009 of file res_xmpp.c.

References xmpp_client_send_message().

Referenced by xmpp_sendgroup_exec().

1010 {
1011  return xmpp_client_send_message(client, 1, nickname, address, message);
1012 }
char * address
Definition: f2c.h:59
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.
Definition: res_xmpp.c:904

◆ ast_xmpp_client_disconnect()

int ast_xmpp_client_disconnect ( struct ast_xmpp_client client)

Disconnect an XMPP client connection.

Parameters
clientPointer to the client
Return values
0on success
-1on failure

Definition at line 3528 of file res_xmpp.c.

References AST_PTHREADT_NULL, ast_xmpp_client::device_state_sub, ast_xmpp_client::mwi_sub, NULL, ast_xmpp_client::parser, ast_xmpp_client::ssl_context, ast_xmpp_client::ssl_session, stasis_unsubscribe_and_join(), ast_xmpp_client::stream_flags, ast_xmpp_client::thread, xmpp_client_change_state(), xmpp_pubsub_unsubscribe(), XMPP_STATE_DISCONNECTED, and XMPP_STATE_DISCONNECTING.

Referenced by xmpp_client_config_post_apply(), xmpp_client_destructor(), xmpp_client_reconnect(), and xmpp_client_thread().

3529 {
3530  if ((client->thread != AST_PTHREADT_NULL) && !pthread_equal(pthread_self(), client->thread)) {
3532  pthread_cancel(client->thread);
3533  pthread_join(client->thread, NULL);
3534  client->thread = AST_PTHREADT_NULL;
3535  }
3536 
3537  if (client->mwi_sub) {
3538  client->mwi_sub = stasis_unsubscribe_and_join(client->mwi_sub);
3539  xmpp_pubsub_unsubscribe(client, "message_waiting");
3540  }
3541 
3542  if (client->device_state_sub) {
3544  xmpp_pubsub_unsubscribe(client, "device_state");
3545  }
3546 
3547 #ifdef HAVE_OPENSSL
3548  if (client->stream_flags & SECURE) {
3549  SSL_shutdown(client->ssl_session);
3550  SSL_CTX_free(client->ssl_context);
3551  SSL_free(client->ssl_session);
3552  }
3553 
3554  client->stream_flags = 0;
3555 #endif
3556 
3557  if (client->parser) {
3558  iks_disconnect(client->parser);
3559  }
3560 
3562 
3563  return 0;
3564 }
iksparser * parser
Definition: xmpp.h:127
#define NULL
Definition: resample.c:96
struct stasis_subscription * device_state_sub
Definition: xmpp.h:146
unsigned int stream_flags
Definition: xmpp.h:134
struct stasis_subscription * mwi_sub
Definition: xmpp.h:144
#define AST_PTHREADT_NULL
Definition: lock.h:66
struct stasis_subscription * stasis_unsubscribe_and_join(struct stasis_subscription *subscription)
Cancel a subscription, blocking until the last message is processed.
Definition: stasis.c:1136
pthread_t thread
Definition: xmpp.h:139
SSL_CTX * ssl_context
Definition: xmpp.h:131
static void xmpp_pubsub_unsubscribe(struct ast_xmpp_client *client, const char *node)
Unsubscribe from a PubSub node.
Definition: res_xmpp.c:1388
SSL * ssl_session
Definition: xmpp.h:132
static void xmpp_client_change_state(struct ast_xmpp_client *client, int state)
Internal function which changes the XMPP client state.
Definition: res_xmpp.c:590

◆ ast_xmpp_client_find()

struct ast_xmpp_client* ast_xmpp_client_find ( const char *  name)

Find an XMPP client connection using a given name.

Parameters
nameName of the client connection
Return values
non-NULLon success
NULLon failure
Note
This will return the client connection with the reference count incremented by one.

Definition at line 875 of file res_xmpp.c.

References ao2_cleanup, ao2_global_obj_ref, ao2_ref, globals, NULL, RAII_VAR, and xmpp_config_find().

Referenced by custom_connection_handler().

876 {
878  RAII_VAR(struct ast_xmpp_client_config *, clientcfg, NULL, ao2_cleanup);
879 
880  if (!cfg || !cfg->clients || !(clientcfg = xmpp_config_find(cfg->clients, name))) {
881  return NULL;
882  }
883 
884  ao2_ref(clientcfg->client, +1);
885  return clientcfg->client;
886 }
XMPP Client Configuration.
Definition: res_xmpp.c:444
static void * xmpp_config_find(struct ao2_container *tmp_container, const char *category)
Find function for configuration.
Definition: res_xmpp.c:651
#define ao2_global_obj_ref(holder)
Definition: astobj2.h:925
#define NULL
Definition: resample.c:96
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
#define ao2_ref(o, delta)
Definition: astobj2.h:464
static struct console_pvt globals
static const char name[]
Definition: cdr_mysql.c:74
#define ao2_cleanup(obj)
Definition: astobj2.h:1958

◆ ast_xmpp_client_lock()

void ast_xmpp_client_lock ( struct ast_xmpp_client client)

Lock an XMPP client connection.

Parameters
clientPointer to the client

Definition at line 893 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().

894 {
895  ao2_lock(client);
896 }
#define ao2_lock(a)
Definition: astobj2.h:718

◆ ast_xmpp_client_send()

int ast_xmpp_client_send ( struct ast_xmpp_client client,
iks *  stanza 
)

Send an XML stanza out using an established XMPP client connection.

Parameters
clientPointer to the client
stanzaPointer to the Iksemel stanza
Return values
0on success
-1on failure

Definition at line 2537 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().

2538 {
2539  return xmpp_client_send_raw_message(client, iks_string(iks_stack(stanza), stanza));
2540 }
static int xmpp_client_send_raw_message(struct ast_xmpp_client *client, const char *message)
Internal function which sends a raw message.
Definition: res_xmpp.c:2492

◆ ast_xmpp_client_send_message()

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.

Parameters
clientPointer to the client
userUser the message should be sent to
messageThe message to send
Return values
0on success
-1on failure

Definition at line 932 of file res_xmpp.c.

References NULL, and xmpp_client_send_message().

Referenced by jingle_sendtext(), manager_jabber_send(), xmpp_send_cb(), and xmpp_send_exec().

933 {
934  return xmpp_client_send_message(client, 0, NULL, user, message);
935 }
#define NULL
Definition: resample.c:96
structure to hold users read from users.conf
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.
Definition: res_xmpp.c:904

◆ ast_xmpp_client_unlock()

void ast_xmpp_client_unlock ( struct ast_xmpp_client client)

Unlock an XMPP client connection.

Parameters
clientPointer to the client

Definition at line 898 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().

899 {
900  ao2_unlock(client);
901 }
#define ao2_unlock(a)
Definition: astobj2.h:730

◆ ast_xmpp_client_unref()

void ast_xmpp_client_unref ( struct ast_xmpp_client client)

Release XMPP client connection reference.

Parameters
clientPointer to the client

Definition at line 888 of file res_xmpp.c.

References ao2_ref.

Referenced by jingle_endpoint_destructor(), and jingle_session_destructor().

889 {
890  ao2_ref(client, -1);
891 }
#define ao2_ref(o, delta)
Definition: astobj2.h:464

◆ ast_xmpp_increment_mid()

void ast_xmpp_increment_mid ( char *  mid)

Helper function which increments the message identifier.

Parameters
midPointer to a string containing the message identifier

Definition at line 1019 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().

1020 {
1021  int i = 0;
1022 
1023  for (i = strlen(mid) - 1; i >= 0; i--) {
1024  if (mid[i] != 'z') {
1025  mid[i] = mid[i] + 1;
1026  i = 0;
1027  } else {
1028  mid[i] = 'a';
1029  }
1030  }
1031 }