Asterisk - The Open Source Telephony Project GIT-master-2070bb5
xmpp.h
Go to the documentation of this file.
1/*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 2012, Digium, Inc.
5 *
6 * Joshua Colp <jcolp@digium.com>
7 *
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
13 *
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
17 */
18
19/*! \file
20 * \brief XMPP Interface
21 * \author Joshua Colp <jcolp@digium.com>
22 * IKSEMEL http://iksemel.jabberstudio.org
23 */
24
25#ifndef _ASTERISK_XMPP_H
26#define _ASTERISK_XMPP_H
27
28#ifdef HAVE_OPENSSL
29
30#include <openssl/ssl.h>
31#include <openssl/err.h>
32#define TRY_SECURE 2
33#define SECURE 4
34
35#endif /* HAVE_OPENSSL */
36
37/* file is read by blocks with this size */
38#define NET_IO_BUF_SIZE 16384
39
40/* Return value for timeout connection expiration */
41#define IKS_NET_EXPIRED 12
42
43#include <iksemel.h>
44
45#include "asterisk/utils.h"
46#include "asterisk/astobj2.h"
49#include "asterisk/pbx.h"
50#include "asterisk/stasis.h"
51
52/*
53 * As per RFC 3920 - section 3.1, the maximum length for a full Jabber ID
54 * is 3071 bytes.
55 * The ABNF syntax for jid :
56 * jid = [node "@" ] domain [ "/" resource ]
57 * Each allowable portion of a JID (node identifier, domain identifier,
58 * and resource identifier) MUST NOT be more than 1023 bytes in length,
59 * resulting in a maximum total size (including the '@' and '/' separators)
60 * of 3071 bytes.
61 */
62#define XMPP_MAX_JIDLEN 3071
63
64/*! \brief Maximum size of a resource JID */
65#define XMPP_MAX_RESJIDLEN 1023
66
67/*! \brief Maximum size of an attribute */
68#define XMPP_MAX_ATTRLEN 256
69
70/*! \brief Client connection states */
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};
82
83/*! \brief Resource capabilities */
85 char node[200]; /*!< Node string from the capabilities stanza in presence notification */
86 char version[50]; /*!< Version string from the capabilities stanza in presence notification */
87 unsigned int jingle:1; /*!< Set if the resource supports Jingle */
88 unsigned int google:1; /*!< Set if the resource supports Google Talk */
89};
90
91/*! \brief XMPP Resource */
93 char resource[XMPP_MAX_RESJIDLEN]; /*!< JID of the resource */
94 int status; /*!< Current status of the resource */
95 char *description; /*!< Description of the resource */
96 int priority; /*!< Priority, used for deciding what resource to use */
97 struct ast_xmpp_capabilities caps; /*!< Capabilities of the resource */
98};
99
100/*! \brief XMPP Message */
102 char *from; /*!< Who the message is from */
103 char *message; /*!< Message contents */
104 char id[25]; /*!< Identifier for the message */
105 struct timeval arrived; /*!< When the message arrived */
106 AST_LIST_ENTRY(ast_xmpp_message) list; /*!< Linked list information */
107};
108
109struct ast_endpoint;
110
111/*! \brief XMPP Buddy */
113 char id[XMPP_MAX_JIDLEN]; /*!< JID of the buddy */
114 struct ao2_container *resources; /*!< Resources for the buddy */
115 unsigned int subscribe:1; /*!< Need to subscribe to get their status */
116};
117
118/*! \brief XMPP Client Connection */
121 /*! Name of the client configuration */
123 );
124 /*! Message ID */
125 char mid[6];
126 iksid *jid;
127 iksparser *parser;
128 iksfilter *filter;
129 ikstack *stack;
130#ifdef HAVE_OPENSSL
131 SSL_CTX *ssl_context;
132 SSL *ssl_session;
133 const SSL_METHOD *ssl_method;
134 unsigned int stream_flags;
135#endif /* HAVE_OPENSSL */
139 pthread_t thread;
141 /*! Reconnect this client */
142 unsigned int reconnect:1;
143 /*! If distributing event information the MWI subscription */
145 /*! If distributing event information the device state subscription */
147 /*! The endpoint associated with this client */
149};
150
151/*!
152 * \brief Find an XMPP client connection using a given name
153 *
154 * \param name Name of the client connection
155 *
156 * \retval non-NULL on success
157 * \retval NULL on failure
158 *
159 * \note This will return the client connection with the reference count incremented by one.
160 */
161struct ast_xmpp_client *ast_xmpp_client_find(const char *name);
162
163/*!
164 * \brief Disconnect an XMPP client connection
165 *
166 * \param client Pointer to the client
167 *
168 * \retval 0 on success
169 * \retval -1 on failure
170 */
172
173/*!
174 * \brief Release XMPP client connection reference
175 *
176 * \param client Pointer to the client
177 */
178void ast_xmpp_client_unref(struct ast_xmpp_client *client);
179
180/*!
181 * \brief Lock an XMPP client connection
182 *
183 * \param client Pointer to the client
184 */
185void ast_xmpp_client_lock(struct ast_xmpp_client *client);
186
187/*!
188 * \brief Unlock an XMPP client connection
189 *
190 * \param client Pointer to the client
191 */
192void ast_xmpp_client_unlock(struct ast_xmpp_client *client);
193
194/*!
195 * \brief Send an XML stanza out using an established XMPP client connection
196 *
197 * \param client Pointer to the client
198 * \param stanza Pointer to the Iksemel stanza
199 *
200 * \retval 0 on success
201 * \retval -1 on failure
202 */
203int ast_xmpp_client_send(struct ast_xmpp_client *client, iks *stanza);
204
205/*!
206 * \brief Send a message to a given user using an established XMPP client connection
207 *
208 * \param client Pointer to the client
209 * \param user User the message should be sent to
210 * \param message The message to send
211 *
212 * \retval 0 on success
213 * \retval -1 on failure
214 */
215int ast_xmpp_client_send_message(struct ast_xmpp_client *client, const char *user, const char *message);
216
217/*!
218 * \brief Invite a user to an XMPP multi-user chatroom
219 *
220 * \param client Pointer to the client
221 * \param user JID of the user
222 * \param room Name of the chatroom
223 * \param message Message to send with the invitation
224 *
225 * \retval 0 on success
226 * \retval -1 on failure
227 */
228int ast_xmpp_chatroom_invite(struct ast_xmpp_client *client, const char *user, const char *room, const char *message);
229
230/*!
231 * \brief Join an XMPP multi-user chatroom
232 *
233 * \param client Pointer to the client
234 * \param room Name of the chatroom
235 * \param nickname Nickname to use
236 *
237 * \retval 0 on success
238 * \retval -1 on failure
239 */
240int ast_xmpp_chatroom_join(struct ast_xmpp_client *client, const char *room, const char *nickname);
241
242/*!
243 * \brief Send a message to an XMPP multi-user chatroom
244 *
245 * \param client Pointer to the client
246 * \param nickname Nickname to use
247 * \param address Address of the room
248 * \param message Message itself
249 *
250 * \retval 0 on success
251 * \retval -1 on failure
252 */
253int ast_xmpp_chatroom_send(struct ast_xmpp_client *client, const char *nickname, const char *address, const char *message);
254
255/*!
256 * \brief Leave an XMPP multi-user chatroom
257 *
258 * \param client Pointer to the client
259 * \param room Name of the chatroom
260 * \param nickname Nickname being used
261 *
262 * \retval 0 on success
263 * \retval -1 on failure
264 */
265int ast_xmpp_chatroom_leave(struct ast_xmpp_client *client, const char *room, const char *nickname);
266
267/*!
268 * \brief Helper function which increments the message identifier
269 *
270 * \param mid Pointer to a string containing the message identifier
271 */
272void ast_xmpp_increment_mid(char *mid);
273
274#endif
char * address
Definition: f2c.h:59
static const char name[]
Definition: format_mp3.c:68
struct ssl_ctx_st SSL_CTX
Definition: iostream.h:38
struct ssl_st SSL
Definition: iostream.h:37
A set of macros to manage forward-linked lists.
#define AST_LIST_ENTRY(type)
Declare a forward link structure inside a list entry.
Definition: linkedlists.h:410
#define AST_LIST_HEAD(name, type)
Defines a structure to be used to hold a list of specified type.
Definition: linkedlists.h:173
Core PBX routines and definitions.
Stasis Message Bus API. See Stasis Message Bus API for detailed documentation.
#define AST_DECLARE_STRING_FIELDS(field_list)
Declare the fields needed in a structure.
Definition: stringfields.h:341
#define AST_STRING_FIELD(name)
Declare a string field.
Definition: stringfields.h:303
Generic container type.
XMPP Buddy.
Definition: xmpp.h:112
unsigned int subscribe
Definition: xmpp.h:115
struct ao2_container * resources
Definition: xmpp.h:114
Resource capabilities.
Definition: xmpp.h:84
char version[50]
Definition: xmpp.h:86
unsigned int google
Definition: xmpp.h:88
unsigned int jingle
Definition: xmpp.h:87
XMPP Client Connection.
Definition: xmpp.h:119
pthread_t thread
Definition: xmpp.h:139
enum xmpp_state state
Definition: xmpp.h:136
iksfilter * filter
Definition: xmpp.h:128
struct ast_xmpp_client::@290 messages
struct stasis_subscription * mwi_sub
Definition: xmpp.h:144
int timeout
Definition: xmpp.h:140
struct ao2_container * buddies
Definition: xmpp.h:137
unsigned int reconnect
Definition: xmpp.h:142
iksparser * parser
Definition: xmpp.h:127
struct ast_endpoint * endpoint
Definition: xmpp.h:148
char mid[6]
Definition: xmpp.h:125
struct stasis_subscription * device_state_sub
Definition: xmpp.h:146
const ast_string_field name
Definition: xmpp.h:123
ikstack * stack
Definition: xmpp.h:129
iksid * jid
Definition: xmpp.h:126
XMPP Message.
Definition: xmpp.h:101
char * message
Definition: xmpp.h:103
char * from
Definition: xmpp.h:102
struct ast_xmpp_message::@289 list
struct timeval arrived
Definition: xmpp.h:105
XMPP Resource.
Definition: xmpp.h:92
char resource[XMPP_MAX_RESJIDLEN]
Definition: xmpp.h:93
struct ast_xmpp_capabilities caps
Definition: xmpp.h:97
char * description
Definition: xmpp.h:95
int priority
Definition: xmpp.h:96
Definition: test_heap.c:38
structure to hold users read from users.conf
Utility functions.
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:2534
void ast_xmpp_client_unref(struct ast_xmpp_client *client)
Release XMPP client connection reference.
Definition: res_xmpp.c:894
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.
Definition: res_xmpp.c:1015
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.
Definition: res_xmpp.c:938
void ast_xmpp_client_unlock(struct ast_xmpp_client *client)
Unlock an XMPP client connection.
Definition: res_xmpp.c:904
#define XMPP_MAX_RESJIDLEN
Maximum size of a resource JID.
Definition: xmpp.h:65
int ast_xmpp_chatroom_leave(struct ast_xmpp_client *client, const char *room, const char *nickname)
Leave an XMPP multi-user chatroom.
Definition: res_xmpp.c:1020
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.
Definition: res_xmpp.c:943
void ast_xmpp_increment_mid(char *mid)
Helper function which increments the message identifier.
Definition: res_xmpp.c:1025
#define XMPP_MAX_JIDLEN
Definition: xmpp.h:62
void ast_xmpp_client_lock(struct ast_xmpp_client *client)
Lock an XMPP client connection.
Definition: res_xmpp.c:899
struct ast_xmpp_client * ast_xmpp_client_find(const char *name)
Find an XMPP client connection using a given name.
Definition: res_xmpp.c:881
int ast_xmpp_client_disconnect(struct ast_xmpp_client *client)
Disconnect an XMPP client connection.
Definition: res_xmpp.c:3525
int ast_xmpp_chatroom_join(struct ast_xmpp_client *client, const char *room, const char *nickname)
Join an XMPP multi-user chatroom.
Definition: res_xmpp.c:1010
xmpp_state
Client connection states.
Definition: xmpp.h:71
@ XMPP_STATE_AUTHENTICATE
Definition: xmpp.h:77
@ XMPP_STATE_ROSTER
Definition: xmpp.h:79
@ XMPP_STATE_DISCONNECTED
Definition: xmpp.h:73
@ XMPP_STATE_REQUEST_TLS
Definition: xmpp.h:75
@ XMPP_STATE_REQUESTED_TLS
Definition: xmpp.h:76
@ XMPP_STATE_CONNECTING
Definition: xmpp.h:74
@ XMPP_STATE_DISCONNECTING
Definition: xmpp.h:72
@ XMPP_STATE_AUTHENTICATING
Definition: xmpp.h:78
@ XMPP_STATE_CONNECTED
Definition: xmpp.h:80