Thu Apr 16 06:44:47 2015

Asterisk developer's documentation


jabber.h

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 1999 - 2010, Digium, Inc.
00005  *
00006  * Matt O'Gorman <mogorman@digium.com>
00007  *
00008  * See http://www.asterisk.org for more information about
00009  * the Asterisk project. Please do not directly contact
00010  * any of the maintainers of this project for assistance;
00011  * the project provides a web site, mailing lists and IRC
00012  * channels for your use.
00013  *
00014  * This program is free software, distributed under the terms of
00015  * the GNU General Public License Version 2. See the LICENSE file
00016  * at the top of the source tree.
00017  */
00018 
00019 /*! \file
00020  * \brief AJI - The Asterisk Jabber Interface
00021  * \arg \ref AJI_intro
00022  * \ref res_jabber.c
00023  * \author Matt O'Gorman <mogorman@digium.com>
00024  * \extref IKSEMEL http://iksemel.jabberstudio.org
00025  *
00026  * \page AJI_intro AJI - The Asterisk Jabber Interface
00027  * 
00028  * The Asterisk Jabber Interface, AJI, publishes an API for
00029  * modules to use jabber communication. res_jabber.c implements
00030  * a Jabber client and a component that can connect as a service
00031  * to Jabber servers.
00032  *
00033  * \section External dependencies
00034  * AJI use the IKSEMEL library found at http://iksemel.jabberstudio.org/
00035  *
00036  * \section Files
00037  * - res_jabber.c
00038  * - jabber.h
00039  * - chan_gtalk.c
00040  *
00041  */
00042 
00043 #ifndef _ASTERISK_JABBER_H
00044 #define _ASTERISK_JABBER_H
00045 
00046 #ifdef HAVE_OPENSSL
00047 
00048 #include <openssl/ssl.h>
00049 #include <openssl/err.h>
00050 #define TRY_SECURE 2
00051 #define SECURE 4
00052 
00053 #endif /* HAVE_OPENSSL */
00054 /* file is read by blocks with this size */
00055 #define NET_IO_BUF_SIZE 4096
00056 /* Return value for timeout connection expiration */
00057 #define IKS_NET_EXPIRED 12
00058 
00059 #include <iksemel.h>
00060 #include "asterisk/astobj.h"
00061 #include "asterisk/linkedlists.h"
00062 
00063 /* 
00064  * As per RFC 3920 - section 3.1, the maximum length for a full Jabber ID 
00065  * is 3071 bytes.
00066  * The ABNF syntax for jid :
00067  * jid = [node "@" ] domain [ "/" resource ]
00068  * Each allowable portion of a JID (node identifier, domain identifier,
00069  * and resource identifier) MUST NOT be more than 1023 bytes in length,
00070  * resulting in a maximum total size (including the '@' and '/' separators) 
00071  * of 3071 bytes.
00072  */
00073 #define AJI_MAX_JIDLEN 3071
00074 #define AJI_MAX_RESJIDLEN 1023
00075 #define AJI_MAX_ATTRLEN   256
00076 
00077 #define MUC_NS "http://jabber.org/protocol/muc"
00078 
00079 enum aji_state {
00080    AJI_DISCONNECTING,
00081    AJI_DISCONNECTED,
00082    AJI_CONNECTING,
00083    AJI_CONNECTED
00084 };
00085 
00086 enum {
00087    AJI_AUTOPRUNE = (1 << 0),
00088    AJI_AUTOREGISTER = (1 << 1),
00089    AJI_AUTOACCEPT = (1 << 2),
00090 };
00091 
00092 enum {
00093    AJI_XEP0248 = (1 << 0),
00094    AJI_PUBSUB = (1 << 1),
00095    AJI_PUBSUB_AUTOCREATE = (1 << 2),
00096 };
00097 
00098 enum aji_btype {
00099    AJI_USER = 0,
00100    AJI_TRANS = 1,
00101    AJI_UTRANS = 2,
00102 };
00103 
00104 struct aji_version {
00105    char version[50];
00106    int jingle;
00107    struct aji_capabilities *parent;
00108    struct aji_version *next;
00109 };
00110 
00111 struct aji_capabilities {
00112    char node[200];
00113    struct aji_version *versions;
00114    struct aji_capabilities *next;
00115 };
00116 
00117 struct aji_resource {
00118    int status;
00119    char resource[AJI_MAX_RESJIDLEN];
00120    char *description;
00121    struct aji_version *cap;
00122    int priority;
00123    struct aji_resource *next;
00124 };
00125 
00126 struct aji_message {
00127    char *from;
00128    char *message;
00129    char id[25];
00130    struct timeval arrived;
00131    AST_LIST_ENTRY(aji_message) list;
00132 };
00133 
00134 struct aji_buddy {
00135    ASTOBJ_COMPONENTS_FULL(struct aji_buddy, AJI_MAX_JIDLEN, 1);
00136    char channel[160];
00137    struct aji_resource *resources;
00138    enum aji_btype btype;
00139    struct ast_flags flags;
00140 };
00141 
00142 struct aji_buddy_container {
00143    ASTOBJ_CONTAINER_COMPONENTS(struct aji_buddy);
00144 };
00145 
00146 struct aji_transport_container {
00147    ASTOBJ_CONTAINER_COMPONENTS(struct aji_transport);
00148 };
00149 
00150 struct aji_client {
00151    ASTOBJ_COMPONENTS(struct aji_client);
00152    char password[160];
00153    char user[AJI_MAX_JIDLEN];
00154    char serverhost[AJI_MAX_RESJIDLEN];
00155    char pubsub_node[AJI_MAX_RESJIDLEN];
00156    char statusmessage[256];
00157    char name_space[256];
00158    char sid[10]; /* Session ID */
00159    char mid[6]; /* Message ID */
00160    iksid *jid;
00161    iksparser *p;
00162    iksfilter *f;
00163    ikstack *stack;
00164 #ifdef HAVE_OPENSSL
00165    SSL_CTX *ssl_context;
00166    SSL *ssl_session;
00167    const SSL_METHOD *ssl_method;
00168    unsigned int stream_flags;
00169 #endif /* HAVE_OPENSSL */
00170    enum aji_state state;
00171    int port;
00172    int debug;
00173    int usetls;
00174    int forcessl;
00175    int usesasl;
00176    int keepalive;
00177    int allowguest;
00178    int timeout;
00179    int message_timeout;
00180    int authorized;
00181    int distribute_events;
00182    struct ast_flags flags;
00183    int component; /* 0 client,  1 component */
00184    struct aji_buddy_container buddies;
00185    AST_LIST_HEAD(messages,aji_message) messages;
00186    void *jingle;
00187    pthread_t thread;
00188    int priority;
00189    enum ikshowtype status;
00190 };
00191 
00192 struct aji_client_container{
00193    ASTOBJ_CONTAINER_COMPONENTS(struct aji_client);
00194 };
00195 
00196 /* !Send XML stanza over the established XMPP connection */
00197 int ast_aji_send(struct aji_client *client, iks *x);
00198 /*! Send jabber chat message from connected client to jabber URI */
00199 int ast_aji_send_chat(struct aji_client *client, const char *address, const char *message);
00200 /*! Send jabber chat message from connected client to a groupchat using 
00201  *  a given nickname */
00202 int ast_aji_send_groupchat(struct aji_client *client, const char *nick, const char *address, const char *message);
00203 /*! Disconnect jabber client */
00204 int ast_aji_disconnect(struct aji_client *client);
00205 int ast_aji_check_roster(void);
00206 void ast_aji_increment_mid(char *mid);
00207 /*! Open Chat session */
00208 int ast_aji_create_chat(struct aji_client *client,char *room, char *server, char *topic);
00209 /*! Invite to opened Chat session */
00210 int ast_aji_invite_chat(struct aji_client *client, char *user, char *room, char *message);
00211 /*! Join/leave existing Chat session */
00212 int ast_aji_join_chat(struct aji_client *client, char *room, char *nick);
00213 int ast_aji_leave_chat(struct aji_client *client, char *room, char *nick);
00214 /*! Get a client via its name. Increases refcount of client by 1 */
00215 struct aji_client *ast_aji_get_client(const char *name);
00216 struct aji_client_container *ast_aji_get_clients(void);
00217 /*! Destructor function for buddies to be used with ASTOBJ_UNREF */
00218 void ast_aji_buddy_destroy(struct aji_buddy *obj);
00219 /*! Destructor function for clients to be used with ASTOBJ_UNREF after calls to ast_aji_get_client */
00220 void ast_aji_client_destroy(struct aji_client *obj);
00221 
00222 #endif

Generated on Thu Apr 16 06:44:47 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6