Wed Jan 8 2020 09:50:14

Asterisk developer's documentation


jabber.h File Reference

AJI - The Asterisk Jabber Interface. More...

#include <openssl/ssl.h>
#include <openssl/err.h>
#include <iksemel.h>
#include "asterisk/astobj.h"
#include "asterisk/linkedlists.h"

Go to the source code of this file.

Data Structures

struct  aji_buddy
 
struct  aji_buddy_container
 
struct  aji_capabilities
 
struct  aji_client
 
struct  aji_client_container
 
struct  aji_message
 
struct  aji_resource
 
struct  aji_transport_container
 
struct  aji_version
 
struct  aji_client::messages
 

Macros

#define AJI_MAX_ATTRLEN   256
 
#define AJI_MAX_JIDLEN   3071
 
#define AJI_MAX_RESJIDLEN   1023
 
#define IKS_NET_EXPIRED   12
 
#define MUC_NS   "http://jabber.org/protocol/muc"
 
#define NET_IO_BUF_SIZE   4096
 

Enumerations

enum  { AJI_AUTOPRUNE = (1 << 0), AJI_AUTOREGISTER = (1 << 1), AJI_AUTOACCEPT = (1 << 2) }
 
enum  { AJI_XEP0248 = (1 << 0), AJI_PUBSUB = (1 << 1), AJI_PUBSUB_AUTOCREATE = (1 << 2) }
 
enum  aji_btype { AJI_USER = 0, AJI_TRANS = 1, AJI_UTRANS = 2 }
 
enum  aji_state { AJI_DISCONNECTING, AJI_DISCONNECTED, AJI_CONNECTING, AJI_CONNECTED }
 

Functions

void ast_aji_buddy_destroy (struct aji_buddy *obj)
 
int ast_aji_check_roster (void)
 
void ast_aji_client_destroy (struct aji_client *obj)
 
int ast_aji_create_chat (struct aji_client *client, char *room, char *server, char *topic)
 create a chatroom. More...
 
int ast_aji_disconnect (struct aji_client *client)
 disconnect from jabber server. More...
 
struct aji_clientast_aji_get_client (const char *name)
 grab a aji_client structure by label name or JID. Bumps the refcount. (without the resource string) More...
 
struct aji_client_containerast_aji_get_clients (void)
 
void ast_aji_increment_mid (char *mid)
 increments the mid field for messages and other events. More...
 
int ast_aji_invite_chat (struct aji_client *client, char *user, char *room, char *message)
 invite to a chatroom. More...
 
int ast_aji_join_chat (struct aji_client *client, char *room, char *nick)
 join a chatroom. More...
 
int ast_aji_leave_chat (struct aji_client *client, char *room, char *nick)
 leave a chatroom. More...
 
int ast_aji_send (struct aji_client *client, iks *x)
 Wraps raw sending. More...
 
int ast_aji_send_chat (struct aji_client *client, const char *address, const char *message)
 sends messages. More...
 
int ast_aji_send_groupchat (struct aji_client *client, const char *nick, const char *address, const char *message)
 sends message to a groupchat Prior to sending messages to a groupchat, one must be connected to it. More...
 

Detailed Description

Macro Definition Documentation

#define AJI_MAX_ATTRLEN   256

Definition at line 75 of file jabber.h.

Referenced by aji_act_hook().

#define AJI_MAX_JIDLEN   3071
#define AJI_MAX_RESJIDLEN   1023

Definition at line 74 of file jabber.h.

Referenced by aji_join_exec(), aji_leave_exec(), and aji_sendgroup_exec().

#define IKS_NET_EXPIRED   12

Definition at line 57 of file jabber.h.

Referenced by aji_recv(), and aji_recv_loop().

#define MUC_NS   "http://jabber.org/protocol/muc"

Definition at line 77 of file jabber.h.

Referenced by aji_set_group_presence().

#define NET_IO_BUF_SIZE   4096

Definition at line 55 of file jabber.h.

Referenced by aji_recv().

Enumeration Type Documentation

anonymous enum
Enumerator
AJI_AUTOPRUNE 
AJI_AUTOREGISTER 
AJI_AUTOACCEPT 

Definition at line 86 of file jabber.h.

86  {
87  AJI_AUTOPRUNE = (1 << 0),
88  AJI_AUTOREGISTER = (1 << 1),
89  AJI_AUTOACCEPT = (1 << 2),
90 };
anonymous enum
Enumerator
AJI_XEP0248 
AJI_PUBSUB 
AJI_PUBSUB_AUTOCREATE 

Definition at line 92 of file jabber.h.

92  {
93  AJI_XEP0248 = (1 << 0),
94  AJI_PUBSUB = (1 << 1),
95  AJI_PUBSUB_AUTOCREATE = (1 << 2),
96 };
enum aji_btype
Enumerator
AJI_USER 
AJI_TRANS 
AJI_UTRANS 

Definition at line 98 of file jabber.h.

98  {
99  AJI_USER = 0,
100  AJI_TRANS = 1,
101  AJI_UTRANS = 2,
102 };
enum aji_state
Enumerator
AJI_DISCONNECTING 
AJI_DISCONNECTED 
AJI_CONNECTING 
AJI_CONNECTED 

Definition at line 79 of file jabber.h.

Function Documentation

void ast_aji_buddy_destroy ( struct aji_buddy obj)

Destructor function for buddies to be used with ASTOBJ_UNREF

Definition at line 432 of file res_jabber.c.

References ast_free, aji_resource::description, aji_resource::next, and aji_buddy::resources.

Referenced by acf_jabberstatus_read(), aji_client_info_handler(), aji_create_buddy(), aji_dinfo_handler(), aji_handle_presence(), aji_handle_subscribe(), aji_register_query_handler(), aji_status_exec(), ast_aji_client_destroy(), gtalk_alloc(), and jingle_alloc().

433 {
434  struct aji_resource *tmp;
435 
436  while ((tmp = obj->resources)) {
437  obj->resources = obj->resources->next;
438  ast_free(tmp->description);
439  ast_free(tmp);
440  }
441 
442  ast_free(obj);
443 }
char * description
Definition: jabber.h:120
struct aji_resource * next
Definition: jabber.h:123
#define ast_free(a)
Definition: astmm.h:97
struct aji_resource * resources
Definition: jabber.h:137
int ast_aji_check_roster ( void  )
void ast_aji_client_destroy ( struct aji_client obj)

Destructor function for clients to be used with ASTOBJ_UNREF after calls to ast_aji_get_client

Definition at line 410 of file res_jabber.c.

References aji_message_destroy(), ast_aji_buddy_destroy(), ast_free, AST_LIST_HEAD_DESTROY, AST_LIST_LOCK, AST_LIST_REMOVE_HEAD, ASTOBJ_CONTAINER_DESTROY, ASTOBJ_CONTAINER_DESTROYALL, aji_client::buddies, aji_client::f, aji_message::list, aji_client::messages, aji_client::p, and aji_client::stack.

Referenced by acf_jabberreceive_read(), acf_jabberstatus_read(), aji_act_hook(), aji_cli_create_collection(), aji_cli_create_leafnode(), aji_cli_delete_pubsub_node(), aji_cli_list_pubsub_nodes(), aji_cli_purge_pubsub_nodes(), aji_client_connect(), aji_client_info_handler(), aji_create_client(), aji_devstate_cb(), aji_dinfo_handler(), aji_ditems_handler(), aji_handle_pubsub_error(), aji_join_exec(), aji_leave_exec(), aji_log_hook(), aji_mwi_cb(), aji_receive_node_list(), aji_recv_loop(), aji_register_approve_handler(), aji_register_query_handler(), aji_reload(), aji_send_exec(), aji_sendgroup_exec(), aji_status_exec(), ast_aji_disconnect(), gtalk_load_config(), gtalk_newcall(), gtalk_request(), jingle_load_config(), jingle_newcall(), jingle_request(), manager_jabber_send(), and unload_module().

411 {
412  struct aji_message *tmp;
415  iks_filter_delete(obj->f);
416  iks_parser_delete(obj->p);
417  iks_stack_delete(obj->stack);
418  AST_LIST_LOCK(&obj->messages);
419  while ((tmp = AST_LIST_REMOVE_HEAD(&obj->messages, list))) {
420  aji_message_destroy(tmp);
421  }
423  ast_free(obj);
424 }
#define AST_LIST_LOCK(head)
Locks a list.
Definition: linkedlists.h:39
void ast_aji_buddy_destroy(struct aji_buddy *obj)
Definition: res_jabber.c:432
iksparser * p
Definition: jabber.h:161
#define AST_LIST_HEAD_DESTROY(head)
Destroys a list head structure.
Definition: linkedlists.h:638
static void aji_message_destroy(struct aji_message *obj)
Definition: res_jabber.c:451
struct aji_buddy_container buddies
Definition: jabber.h:184
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
Definition: linkedlists.h:818
#define ASTOBJ_CONTAINER_DESTROY(container)
Destroy a container.
Definition: astobj.h:765
#define ASTOBJ_CONTAINER_DESTROYALL(container, destructor)
Empty a container.
Definition: astobj.h:453
#define ast_free(a)
Definition: astmm.h:97
struct aji_message::@188 list
ikstack * stack
Definition: jabber.h:163
struct aji_client::messages messages
iksfilter * f
Definition: jabber.h:162
int ast_aji_create_chat ( struct aji_client client,
char *  room,
char *  server,
char *  topic 
)

create a chatroom.

Open Chat session

Parameters
clientthe configured XMPP client we use to connect to a XMPP server
roomname of room
servername of server
topictopic for the room.
Returns
0.

Definition at line 2646 of file res_jabber.c.

References ast_aji_increment_mid(), ast_aji_send(), ast_log(), LOG_ERROR, and aji_client::mid.

2647 {
2648  int res = 0;
2649  iks *iq = NULL;
2650  iq = iks_new("iq");
2651 
2652  if (iq && client) {
2653  iks_insert_attrib(iq, "type", "get");
2654  iks_insert_attrib(iq, "to", server);
2655  iks_insert_attrib(iq, "id", client->mid);
2656  ast_aji_increment_mid(client->mid);
2657  ast_aji_send(client, iq);
2658  } else {
2659  ast_log(LOG_ERROR, "Out of memory.\n");
2660  }
2661 
2662  iks_delete(iq);
2663 
2664  return res;
2665 }
int ast_aji_send(struct aji_client *client, iks *x)
Wraps raw sending.
Definition: res_jabber.c:1439
#define LOG_ERROR
Definition: logger.h:155
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
char mid[6]
Definition: jabber.h:159
void ast_aji_increment_mid(char *mid)
increments the mid field for messages and other events.
Definition: res_jabber.c:2790
int ast_aji_disconnect ( struct aji_client client)

disconnect from jabber server.

Disconnect jabber client

Parameters
clientthe configured XMPP client we use to connect to a XMPP server
Returns
1.

Definition at line 3153 of file res_jabber.c.

References ast_aji_client_destroy(), ast_verb, ASTOBJ_UNREF, aji_client::p, aji_client::ssl_context, aji_client::ssl_session, and aji_client::stream_flags.

Referenced by unload_module().

3154 {
3155  if (client) {
3156  ast_verb(4, "JABBER: Disconnecting\n");
3157 #ifdef HAVE_OPENSSL
3158  if (client->stream_flags & SECURE) {
3159  SSL_shutdown(client->ssl_session);
3160  SSL_CTX_free(client->ssl_context);
3161  SSL_free(client->ssl_session);
3162  }
3163 #endif
3164  iks_disconnect(client->p);
3165  iks_parser_delete(client->p);
3167  }
3168 
3169  return 1;
3170 }
SSL_CTX * ssl_context
Definition: jabber.h:165
iksparser * p
Definition: jabber.h:161
#define ast_verb(level,...)
Definition: logger.h:243
unsigned int stream_flags
Definition: jabber.h:168
#define ASTOBJ_UNREF(object, destructor)
Decrement the reference count on an object.
Definition: astobj.h:218
void ast_aji_client_destroy(struct aji_client *obj)
Definition: res_jabber.c:410
SSL * ssl_session
Definition: jabber.h:166
struct aji_client* ast_aji_get_client ( const char *  name)

grab a aji_client structure by label name or JID. Bumps the refcount. (without the resource string)

Get a client via its name. Increases refcount of client by 1

Parameters
namelabel or JID
Returns
aji_client.

Definition at line 4575 of file res_jabber.c.

References ast_strdupa, ASTOBJ_CONTAINER_FIND, ASTOBJ_CONTAINER_TRAVERSE, ASTOBJ_REF, clients, and strsep().

Referenced by acf_jabberreceive_read(), acf_jabberstatus_read(), aji_join_exec(), aji_leave_exec(), aji_send_exec(), aji_sendgroup_exec(), aji_status_exec(), gtalk_create_member(), gtalk_newcall(), gtalk_request(), jingle_create_member(), jingle_newcall(), jingle_request(), and manager_jabber_send().

4576 {
4577  struct aji_client *client = NULL;
4578  char *aux = NULL;
4579 
4580  client = ASTOBJ_CONTAINER_FIND(&clients, name);
4581  if (!client && strchr(name, '@')) {
4583  aux = ast_strdupa(iterator->user);
4584  if (strchr(aux, '/')) {
4585  /* strip resource for comparison */
4586  aux = strsep(&aux, "/");
4587  }
4588  if (!strncasecmp(aux, name, strlen(aux))) {
4589  client = ASTOBJ_REF(iterator);
4590  }
4591  });
4592  }
4593 
4594  return client;
4595 }
char * strsep(char **str, const char *delims)
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: utils.h:663
#define ASTOBJ_CONTAINER_TRAVERSE(container, continue, eval)
Iterate through the objects in a container.
Definition: astobj.h:376
static const char name[]
#define ASTOBJ_CONTAINER_FIND(container, namestr)
Find an object in a container.
Definition: astobj.h:401
static struct aji_client_container clients
Definition: res_jabber.c:392
#define ASTOBJ_REF(object)
Increment an object reference count.
Definition: astobj.h:201
struct aji_client_container* ast_aji_get_clients ( void  )

Definition at line 4597 of file res_jabber.c.

References clients.

Referenced by gtalk_load_config(), and jingle_load_config().

4598 {
4599  return &clients;
4600 }
static struct aji_client_container clients
Definition: res_jabber.c:392
void ast_aji_increment_mid ( char *  mid)

increments the mid field for messages and other events.

Parameters
midchar.
Returns
void.

Definition at line 2790 of file res_jabber.c.

Referenced by aji_act_hook(), aji_handle_presence(), aji_pubsub_iq_create(), aji_register_approve_handler(), ast_aji_create_chat(), ast_aji_invite_chat(), gtalk_action(), gtalk_create_candidates(), gtalk_invite(), jingle_accept_call(), jingle_action(), jingle_create_candidates(), jingle_digit(), and jingle_transmit_invite().

2791 {
2792  int i = 0;
2793 
2794  for (i = strlen(mid) - 1; i >= 0; i--) {
2795  if (mid[i] != 'z') {
2796  mid[i] = mid[i] + 1;
2797  i = 0;
2798  } else
2799  mid[i] = 'a';
2800  }
2801 }
char mid[6]
Definition: jabber.h:159
int ast_aji_invite_chat ( struct aji_client client,
char *  user,
char *  room,
char *  message 
)

invite to a chatroom.

Invite to opened Chat session

Parameters
clientthe configured XMPP client we use to connect to a XMPP server
user
room
message
Returns
res.

Definition at line 2698 of file res_jabber.c.

References ast_aji_increment_mid(), ast_aji_send(), ast_log(), LOG_ERROR, and aji_client::mid.

2699 {
2700  int res = 0;
2701  iks *invite, *body, *namespace;
2702 
2703  invite = iks_new("message");
2704  body = iks_new("body");
2705  namespace = iks_new("x");
2706  if (client && invite && body && namespace) {
2707  iks_insert_attrib(invite, "to", user);
2708  iks_insert_attrib(invite, "id", client->mid);
2709  ast_aji_increment_mid(client->mid);
2710  iks_insert_cdata(body, message, 0);
2711  iks_insert_attrib(namespace, "xmlns", "jabber:x:conference");
2712  iks_insert_attrib(namespace, "jid", room);
2713  iks_insert_node(invite, body);
2714  iks_insert_node(invite, namespace);
2715  res = ast_aji_send(client, invite);
2716  } else {
2717  ast_log(LOG_ERROR, "Out of memory.\n");
2718  }
2719 
2720  iks_delete(body);
2721  iks_delete(namespace);
2722  iks_delete(invite);
2723 
2724  return res;
2725 }
int ast_aji_send(struct aji_client *client, iks *x)
Wraps raw sending.
Definition: res_jabber.c:1439
#define LOG_ERROR
Definition: logger.h:155
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
structure to hold users read from users.conf
char mid[6]
Definition: jabber.h:159
void ast_aji_increment_mid(char *mid)
increments the mid field for messages and other events.
Definition: res_jabber.c:2790
int ast_aji_join_chat ( struct aji_client client,
char *  room,
char *  nick 
)

join a chatroom.

Join/leave existing Chat session

Parameters
clientthe configured XMPP client we use to connect to a XMPP server
roomroom to join
nickthe nickname to use in this room
Returns
IKS_OK on success, any other value on failure.

Definition at line 2674 of file res_jabber.c.

References aji_set_group_presence().

Referenced by aji_join_exec().

2675 {
2676  return aji_set_group_presence(client, room, IKS_SHOW_AVAILABLE, nick, NULL);
2677 }
static int aji_set_group_presence(struct aji_client *client, char *room, int level, char *nick, char *desc)
Definition: res_jabber.c:4034
int ast_aji_leave_chat ( struct aji_client client,
char *  room,
char *  nick 
)

leave a chatroom.

Parameters
clientthe configured XMPP client we use to connect to a XMPP server
roomroom to leave
nickthe nickname used in this room
Returns
IKS_OK on success, any other value on failure.

Definition at line 2686 of file res_jabber.c.

References aji_set_group_presence().

Referenced by aji_leave_exec().

2687 {
2688  return aji_set_group_presence(client, room, IKS_SHOW_UNAVAILABLE, nick, NULL);
2689 }
static int aji_set_group_presence(struct aji_client *client, char *room, int level, char *nick, char *desc)
Definition: res_jabber.c:4034
int ast_aji_send_chat ( struct aji_client client,
const char *  address,
const char *  message 
)

sends messages.

Send jabber chat message from connected client to jabber URI

Parameters
clientthe configured XMPP client we use to connect to a XMPP server
address
message
Return values
IKS_OKsuccess
-1failure

Definition at line 2582 of file res_jabber.c.

References aji_send_raw_chat().

Referenced by aji_send_exec(), gtalk_sendtext(), jingle_sendtext(), and manager_jabber_send().

2583 {
2584  return aji_send_raw_chat(client, 0, NULL, address, message);
2585 }
static int aji_send_raw_chat(struct aji_client *client, int groupchat, const char *nick, const char *address, const char *message)
sends messages.
Definition: res_jabber.c:2609
int ast_aji_send_groupchat ( struct aji_client client,
const char *  nick,
const char *  address,
const char *  message 
)

sends message to a groupchat Prior to sending messages to a groupchat, one must be connected to it.

Send jabber chat message from connected client to a groupchat using a given nickname

Parameters
clientthe configured XMPP client we use to connect to a XMPP server
nickthe nickname we use in the chatroom
addressthe user the messages must be sent to
messagethe message to send
Returns
IKS_OK on success, any other value on failure

Definition at line 2596 of file res_jabber.c.

References aji_send_raw_chat().

Referenced by aji_sendgroup_exec().

2596  {
2597  return aji_send_raw_chat(client, 1, nick, address, message);
2598 }
static int aji_send_raw_chat(struct aji_client *client, int groupchat, const char *nick, const char *address, const char *message)
sends messages.
Definition: res_jabber.c:2609