Wed Jan 8 2020 09:49:48

Asterisk developer's documentation


jabber.h
Go to the documentation of this file.
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 1999 - 2010, Digium, Inc.
5  *
6  * Matt O'Gorman <mogorman@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 AJI - The Asterisk Jabber Interface
21  * \arg \ref AJI_intro
22  * \ref res_jabber.c
23  * \author Matt O'Gorman <mogorman@digium.com>
24  * \extref IKSEMEL http://iksemel.jabberstudio.org
25  *
26  * \page AJI_intro AJI - The Asterisk Jabber Interface
27  *
28  * The Asterisk Jabber Interface, AJI, publishes an API for
29  * modules to use jabber communication. res_jabber.c implements
30  * a Jabber client and a component that can connect as a service
31  * to Jabber servers.
32  *
33  * \section External dependencies
34  * AJI use the IKSEMEL library found at http://iksemel.jabberstudio.org/
35  *
36  * \section Files
37  * - res_jabber.c
38  * - jabber.h
39  * - chan_gtalk.c
40  *
41  */
42 
43 #ifndef _ASTERISK_JABBER_H
44 #define _ASTERISK_JABBER_H
45 
46 #ifdef HAVE_OPENSSL
47 
48 #include <openssl/ssl.h>
49 #include <openssl/err.h>
50 #define TRY_SECURE 2
51 #define SECURE 4
52 
53 #endif /* HAVE_OPENSSL */
54 /* file is read by blocks with this size */
55 #define NET_IO_BUF_SIZE 4096
56 /* Return value for timeout connection expiration */
57 #define IKS_NET_EXPIRED 12
58 
59 #include <iksemel.h>
60 #include "asterisk/astobj.h"
61 #include "asterisk/linkedlists.h"
62 
63 /*
64  * As per RFC 3920 - section 3.1, the maximum length for a full Jabber ID
65  * is 3071 bytes.
66  * The ABNF syntax for jid :
67  * jid = [node "@" ] domain [ "/" resource ]
68  * Each allowable portion of a JID (node identifier, domain identifier,
69  * and resource identifier) MUST NOT be more than 1023 bytes in length,
70  * resulting in a maximum total size (including the '@' and '/' separators)
71  * of 3071 bytes.
72  */
73 #define AJI_MAX_JIDLEN 3071
74 #define AJI_MAX_RESJIDLEN 1023
75 #define AJI_MAX_ATTRLEN 256
76 
77 #define MUC_NS "http://jabber.org/protocol/muc"
78 
79 enum aji_state {
84 };
85 
86 enum {
87  AJI_AUTOPRUNE = (1 << 0),
88  AJI_AUTOREGISTER = (1 << 1),
89  AJI_AUTOACCEPT = (1 << 2),
90 };
91 
92 enum {
93  AJI_XEP0248 = (1 << 0),
94  AJI_PUBSUB = (1 << 1),
96 };
97 
98 enum aji_btype {
99  AJI_USER = 0,
102 };
103 
104 struct aji_version {
105  char version[50];
106  int jingle;
108  struct aji_version *next;
109 };
110 
112  char node[200];
115 };
116 
117 struct aji_resource {
118  int status;
120  char *description;
121  struct aji_version *cap;
122  int priority;
124 };
125 
126 struct aji_message {
127  char *from;
128  char *message;
129  char id[25];
130  struct timeval arrived;
132 };
133 
134 struct aji_buddy {
135  ASTOBJ_COMPONENTS_FULL(struct aji_buddy, AJI_MAX_JIDLEN, 1);
136  char channel[160];
138  enum aji_btype btype;
139  struct ast_flags flags;
140 };
141 
144 };
145 
147  ASTOBJ_CONTAINER_COMPONENTS(struct aji_transport);
148 };
149 
150 struct aji_client {
152  char password[160];
154  char serverhost[AJI_MAX_RESJIDLEN];
155  char pubsub_node[AJI_MAX_RESJIDLEN];
156  char statusmessage[256];
157  char name_space[256];
158  char sid[10]; /* Session ID */
159  char mid[6]; /* Message ID */
160  iksid *jid;
161  iksparser *p;
162  iksfilter *f;
163  ikstack *stack;
164 #ifdef HAVE_OPENSSL
165  SSL_CTX *ssl_context;
167  const SSL_METHOD *ssl_method;
168  unsigned int stream_flags;
169 #endif /* HAVE_OPENSSL */
171  int port;
172  int debug;
173  int usetls;
174  int forcessl;
175  int usesasl;
178  int timeout;
182  struct ast_flags flags;
183  int component; /* 0 client, 1 component */
184  struct aji_buddy_container buddies;
186  void *jingle;
187  pthread_t thread;
188  int priority;
189  enum ikshowtype status;
190 };
191 
194 };
195 
196 /* !Send XML stanza over the established XMPP connection */
197 int ast_aji_send(struct aji_client *client, iks *x);
198 /*! Send jabber chat message from connected client to jabber URI */
199 int ast_aji_send_chat(struct aji_client *client, const char *address, const char *message);
200 /*! Send jabber chat message from connected client to a groupchat using
201  * a given nickname */
202 int ast_aji_send_groupchat(struct aji_client *client, const char *nick, const char *address, const char *message);
203 /*! Disconnect jabber client */
204 int ast_aji_disconnect(struct aji_client *client);
205 int ast_aji_check_roster(void);
206 void ast_aji_increment_mid(char *mid);
207 /*! Open Chat session */
208 int ast_aji_create_chat(struct aji_client *client,char *room, char *server, char *topic);
209 /*! Invite to opened Chat session */
210 int ast_aji_invite_chat(struct aji_client *client, char *user, char *room, char *message);
211 /*! Join/leave existing Chat session */
212 int ast_aji_join_chat(struct aji_client *client, char *room, char *nick);
213 int ast_aji_leave_chat(struct aji_client *client, char *room, char *nick);
214 /*! Get a client via its name. Increases refcount of client by 1 */
215 struct aji_client *ast_aji_get_client(const char *name);
217 /*! Destructor function for buddies to be used with ASTOBJ_UNREF */
218 void ast_aji_buddy_destroy(struct aji_buddy *obj);
219 /*! Destructor function for clients to be used with ASTOBJ_UNREF after calls to ast_aji_get_client */
220 void ast_aji_client_destroy(struct aji_client *obj);
221 
222 #endif
int status
Definition: jabber.h:118
enum sip_cc_notify_state state
Definition: chan_sip.c:842
char version[50]
Definition: jabber.h:105
aji_state
Definition: jabber.h:79
pthread_t thread
Definition: app_meetme.c:962
char * description
Definition: jabber.h:120
#define AJI_MAX_RESJIDLEN
Definition: jabber.h:74
void ast_aji_buddy_destroy(struct aji_buddy *obj)
Definition: res_jabber.c:432
#define AST_LIST_HEAD(name, type)
Defines a structure to be used to hold a list of specified type.
Definition: linkedlists.h:172
int authorized
Definition: jabber.h:180
struct aji_version * next
Definition: jabber.h:108
int ast_aji_send(struct aji_client *client, iks *x)
Wraps raw sending.
Definition: res_jabber.c:1439
int usetls
Definition: jabber.h:173
int keepalive
Definition: jabber.h:176
SSL_CTX * ssl_context
Definition: jabber.h:165
int ast_aji_disconnect(struct aji_client *client)
disconnect from jabber server.
Definition: res_jabber.c:3153
unsigned int flags
Definition: utils.h:201
const SSL_METHOD * ssl_method
Definition: jabber.h:167
int ast_aji_join_chat(struct aji_client *client, char *room, char *nick)
join a chatroom.
Definition: res_jabber.c:2674
iksparser * p
Definition: jabber.h:161
int message_timeout
Definition: jabber.h:179
int usesasl
Definition: jabber.h:175
char node[200]
Definition: jabber.h:112
char * message
Definition: jabber.h:128
#define ASTOBJ_CONTAINER_COMPONENTS(type)
Create a container for ASTOBJs (with locking support).
Definition: astobj.h:729
struct aji_capabilities * next
Definition: jabber.h:114
int ast_aji_send_chat(struct aji_client *client, const char *address, const char *message)
sends messages.
Definition: res_jabber.c:2582
int ast_aji_check_roster(void)
int ast_aji_create_chat(struct aji_client *client, char *room, char *server, char *topic)
create a chatroom.
Definition: res_jabber.c:2646
char * from
Definition: jabber.h:127
int component
Definition: jabber.h:183
#define ASTOBJ_COMPONENTS(type)
Add ASTOBJ components to a struct (with locking support).
Definition: astobj.h:173
char resource[AJI_MAX_RESJIDLEN]
Definition: jabber.h:119
unsigned int stream_flags
Definition: jabber.h:168
struct aji_version * versions
Definition: jabber.h:113
int ast_aji_invite_chat(struct aji_client *client, char *user, char *room, char *message)
invite to a chatroom.
Definition: res_jabber.c:2698
int port
Definition: jabber.h:171
A set of macros to manage forward-linked lists.
struct aji_resource * next
Definition: jabber.h:123
A set of macros implementing objects and containers. Macros are used for maximum performance, to support multiple inheritance, and to be easily integrated into existing structures without additional malloc calls, etc.
#define ASTOBJ_COMPONENTS_FULL(type, namelen, hashes)
Add ASTOBJ components to a struct (with locking support).
Definition: astobj.h:193
int ast_aji_leave_chat(struct aji_client *client, char *room, char *nick)
leave a chatroom.
Definition: res_jabber.c:2686
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...
Definition: res_jabber.c:2596
iksid * jid
Definition: jabber.h:160
int distribute_events
Definition: jabber.h:181
aji_btype
Definition: jabber.h:98
#define AJI_MAX_JIDLEN
Definition: jabber.h:73
int priority
Definition: jabber.h:122
#define AST_LIST_ENTRY(type)
Declare a forward link structure inside a list entry.
Definition: linkedlists.h:409
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) ...
Definition: res_jabber.c:4575
static const char name[]
int allowguest
Definition: jabber.h:177
int debug
Definition: jabber.h:172
structure to hold users read from users.conf
Structure used to handle boolean flags.
Definition: utils.h:200
void ast_aji_client_destroy(struct aji_client *obj)
Definition: res_jabber.c:410
struct aji_version * cap
Definition: jabber.h:121
struct aji_message::@188 list
int timeout
Definition: jabber.h:178
struct aji_capabilities * parent
Definition: jabber.h:107
struct timeval arrived
Definition: jabber.h:130
ikstack * stack
Definition: jabber.h:163
SSL * ssl_session
Definition: jabber.h:166
struct aji_resource * resources
Definition: jabber.h:137
int forcessl
Definition: jabber.h:174
iksfilter * f
Definition: jabber.h:162
int jingle
Definition: jabber.h:106
void ast_aji_increment_mid(char *mid)
increments the mid field for messages and other events.
Definition: res_jabber.c:2790
jack_status_t status
Definition: app_jack.c:143
struct aji_client_container * ast_aji_get_clients(void)
Definition: res_jabber.c:4597