Frameworks/libpurple.framework/Versions/0.6.2/Headers/jabber.h
author Zachary West <zacw@adium.im>
Fri Aug 21 13:25:11 2009 -0700 (2009-08-21)
changeset 2592 e8d15275025e
parent 2571 Frameworks/libpurple.framework/Versions/0.6.0/Headers/jabber.h@75fb8ee8f2e6
permissions -rw-r--r--
im.pidgin.adium.1-4 at 267c6165e02e34318a1823960bd04c0639952f73
     1 /**
     2  * @file jabber.h
     3  *
     4  * purple
     5  *
     6  * Copyright (C) 2003 Nathan Walp <faceprint@faceprint.com>
     7  *
     8  * This program is free software; you can redistribute it and/or modify
     9  * it under the terms of the GNU General Public License as published by
    10  * the Free Software Foundation; either version 2 of the License, or
    11  * (at your option) any later version.
    12  *
    13  * This program is distributed in the hope that it will be useful,
    14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    16  * GNU General Public License for more details.
    17  *
    18  * You should have received a copy of the GNU General Public License
    19  * along with this program; if not, write to the Free Software
    20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
    21  */
    22 #ifndef PURPLE_JABBER_H_
    23 #define PURPLE_JABBER_H_
    24 
    25 typedef enum {
    26 	JABBER_CAP_NONE           = 0,
    27 /*	JABBER_CAP_XHTML          = 1 << 0, */
    28 /*	JABBER_CAP_COMPOSING      = 1 << 1, */
    29 	JABBER_CAP_SI             = 1 << 2,
    30 	JABBER_CAP_SI_FILE_XFER   = 1 << 3,
    31 	JABBER_CAP_BYTESTREAMS    = 1 << 4,
    32 	JABBER_CAP_IBB            = 1 << 5,
    33 	JABBER_CAP_CHAT_STATES    = 1 << 6,
    34 	JABBER_CAP_IQ_SEARCH      = 1 << 7,
    35 	JABBER_CAP_IQ_REGISTER    = 1 << 8,
    36 
    37 	/* Google Talk extensions:
    38 	 * http://code.google.com/apis/talk/jep_extensions/extensions.html
    39 	 */
    40 	JABBER_CAP_GMAIL_NOTIFY   = 1 << 9,
    41 	JABBER_CAP_GOOGLE_ROSTER  = 1 << 10,
    42 
    43 	JABBER_CAP_PING			  = 1 << 11,
    44 	JABBER_CAP_ADHOC		  = 1 << 12,
    45 	JABBER_CAP_BLOCKING       = 1 << 13,
    46 
    47 	JABBER_CAP_ITEMS          = 1 << 14,
    48 
    49 	JABBER_CAP_RETRIEVED      = 1 << 31
    50 } JabberCapabilities;
    51 
    52 typedef struct _JabberStream JabberStream;
    53 
    54 #include <libxml/parser.h>
    55 #include <glib.h>
    56 #include "circbuffer.h"
    57 #include "connection.h"
    58 #include "dnsquery.h"
    59 #include "dnssrv.h"
    60 #include "media.h"
    61 #include "mediamanager.h"
    62 #include "roomlist.h"
    63 #include "sslconn.h"
    64 
    65 #include "iq.h"
    66 #include "jutil.h"
    67 #include "xmlnode.h"
    68 #include "buddy.h"
    69 #include "bosh.h"
    70 
    71 #ifdef HAVE_CYRUS_SASL
    72 #include <sasl/sasl.h>
    73 #endif
    74 
    75 #define CAPS0115_NODE "http://pidgin.im/"
    76 
    77 /* Index into attention_types list */
    78 #define JABBER_BUZZ 0
    79 
    80 extern PurplePlugin *jabber_plugin;
    81 
    82 typedef enum {
    83 	JABBER_STREAM_OFFLINE,
    84 	JABBER_STREAM_CONNECTING,
    85 	JABBER_STREAM_INITIALIZING,
    86 	JABBER_STREAM_INITIALIZING_ENCRYPTION,
    87 	JABBER_STREAM_AUTHENTICATING,
    88 	JABBER_STREAM_REINITIALIZING,
    89 	JABBER_STREAM_CONNECTED
    90 } JabberStreamState;
    91 
    92 struct _JabberStream
    93 {
    94 	int fd;
    95 
    96 	PurpleSrvQueryData *srv_query_data;
    97 
    98 	xmlParserCtxt *context;
    99 	xmlnode *current;
   100 
   101 	enum {
   102 		JABBER_PROTO_0_9,
   103 		JABBER_PROTO_1_0
   104 	} protocol_version;
   105 	enum {
   106 		JABBER_AUTH_UNKNOWN,
   107 		JABBER_AUTH_DIGEST_MD5,
   108 		JABBER_AUTH_PLAIN,
   109 		JABBER_AUTH_IQ_AUTH,
   110 		JABBER_AUTH_CYRUS
   111 	} auth_type;
   112 	char *stream_id;
   113 	JabberStreamState state;
   114 
   115 	/* SASL authentication */
   116 	char *expected_rspauth;
   117 
   118 	GHashTable *buddies;
   119 
   120 	/*
   121 	 * This boolean was added to eliminate a heinous bug where we would
   122 	 * get into a loop with the server and move a buddy back and forth
   123 	 * from one group to another.
   124 	 *
   125 	 * The sequence goes something like this:
   126 	 * 1. Our resource and another resource both approve an authorization
   127 	 *    request at the exact same time.  We put the buddy in group A and
   128 	 *    the other resource put the buddy in group B.
   129 	 * 2. The server receives the roster add for group B and sends us a
   130 	 *    roster push.
   131 	 * 3. We receive this roster push and modify our local blist.  This
   132 	 *    triggers us to send a roster add for group B.
   133 	 * 4. The server recieves our earlier roster add for group A and sends
   134 	 *    us a roster push.
   135 	 * 5. We receive this roster push and modify our local blist.  This
   136 	 *    triggers us to send a roster add for group A.
   137 	 * 6. The server receives our earlier roster add for group B and sends
   138 	 *    us a roster push.
   139 	 * (repeat steps 3 through 6 ad infinitum)
   140 	 *
   141 	 * This boolean is used to short-circuit the sending of a roster add
   142 	 * when we receive a roster push.
   143 	 *
   144 	 * See these bug reports:
   145 	 * http://trac.adiumx.com/ticket/8834
   146 	 * http://developer.pidgin.im/ticket/5484
   147 	 * http://developer.pidgin.im/ticket/6188
   148 	 */
   149 	gboolean currently_parsing_roster_push;
   150 
   151 	GHashTable *chats;
   152 	GList *chat_servers;
   153 	PurpleRoomlist *roomlist;
   154 	GList *user_directories;
   155 
   156 	GHashTable *iq_callbacks;
   157 	int next_id;
   158 
   159 	GList *bs_proxies;
   160 	GList *oob_file_transfers;
   161 	GList *file_transfers;
   162 
   163 	time_t idle;
   164 	time_t old_idle;
   165 
   166 	JabberID *user;
   167 	JabberBuddy *user_jb;
   168 
   169 	PurpleConnection *gc;
   170 	PurpleSslConnection *gsc;
   171 
   172 	gboolean registration;
   173 
   174 	char *initial_avatar_hash;
   175 	char *avatar_hash;
   176 	GSList *pending_avatar_requests;
   177 
   178 	GSList *pending_buddy_info_requests;
   179 
   180 	PurpleCircBuffer *write_buffer;
   181 	guint writeh;
   182 
   183 	gboolean reinit;
   184 
   185 	JabberCapabilities server_caps;
   186 	gboolean googletalk;
   187 	char *server_name;
   188 
   189 	char *gmail_last_time;
   190 	char *gmail_last_tid;
   191 
   192 	char *serverFQDN;
   193 
   194 	/* OK, this stays at the end of the struct, so plugins can depend
   195 	 * on the rest of the stuff being in the right place
   196 	 */
   197 #ifdef HAVE_CYRUS_SASL
   198 	sasl_conn_t *sasl;
   199 	sasl_callback_t *sasl_cb;
   200 #else /* keep the struct the same size */
   201 	void *sasl;
   202 	void *sasl_cb;
   203 #endif
   204 	/* did someone say something about the end of the struct? */
   205 #ifdef HAVE_CYRUS_SASL
   206 	const char *current_mech;
   207 	int auth_fail_count;
   208 #endif
   209 
   210 	int sasl_state;
   211 	int sasl_maxbuf;
   212 	GString *sasl_mechs;
   213 
   214 	gboolean unregistration;
   215 	PurpleAccountUnregistrationCb unregistration_cb;
   216 	void *unregistration_user_data;
   217 
   218 	gboolean vcard_fetched;
   219 	/* Timer at login to push updated avatar */
   220 	guint vcard_timer;
   221 
   222 	/* Entity Capabilities hash */
   223 	char *caps_hash;
   224 
   225 	/* does the local server support PEP? */
   226 	gboolean pep;
   227 
   228 	/* Is Buzz enabled? */
   229 	gboolean allowBuzz;
   230 
   231 	/* A list of JabberAdHocCommands supported by the server */
   232 	GList *commands;
   233 
   234 	/* last presence update to check for differences */
   235 	JabberBuddyState old_state;
   236 	char *old_msg;
   237 	int old_priority;
   238 	char *old_avatarhash;
   239 
   240 	/* same for user tune */
   241 	char *old_artist;
   242 	char *old_title;
   243 	char *old_source;
   244 	char *old_uri;
   245 	int old_length;
   246 	char *old_track;
   247 
   248 	char *certificate_CN;
   249 
   250 	/* A purple timeout tag for the keepalive */
   251 	guint keepalive_timeout;
   252 
   253 	PurpleSrvResponse *srv_rec;
   254 	guint srv_rec_idx;
   255 	guint max_srv_rec_idx;
   256 
   257 	/* BOSH stuff */
   258 	PurpleBOSHConnection *bosh;
   259 
   260 	/**
   261 	 * This linked list contains PurpleUtilFetchUrlData structs
   262 	 * for when we lookup buddy icons from a url
   263 	 */
   264 	GSList *url_datas;
   265 
   266 	/* keep a hash table of JingleSessions */
   267 	GHashTable *sessions;
   268 
   269 	/* maybe this should only be present when USE_VV? */
   270 	gchar *stun_ip;
   271 	int stun_port;
   272 	PurpleDnsQueryData *stun_query;
   273 	/* later add stuff to handle TURN relays... */
   274 };
   275 
   276 typedef gboolean (JabberFeatureEnabled)(JabberStream *js, const gchar *namespace);
   277 
   278 typedef struct _JabberFeature
   279 {
   280 	gchar *namespace;
   281 	JabberFeatureEnabled *is_enabled;
   282 } JabberFeature;
   283 
   284 typedef struct _JabberIdentity
   285 {
   286 	gchar *category;
   287 	gchar *type;
   288 	gchar *name;
   289 	gchar *lang;
   290 } JabberIdentity;
   291 
   292 typedef struct _JabberBytestreamsStreamhost {
   293 	char *jid;
   294 	char *host;
   295 	int port;
   296 	char *zeroconf;
   297 } JabberBytestreamsStreamhost;
   298 
   299 /* what kind of additional features as returned from disco#info are supported? */
   300 extern GList *jabber_features;
   301 extern GList *jabber_identities;
   302 
   303 void jabber_stream_features_parse(JabberStream *js, xmlnode *packet);
   304 void jabber_process_packet(JabberStream *js, xmlnode **packet);
   305 void jabber_send(JabberStream *js, xmlnode *data);
   306 void jabber_send_raw(JabberStream *js, const char *data, int len);
   307 void jabber_send_signal_cb(PurpleConnection *pc, xmlnode **packet,
   308                            gpointer unused);
   309 
   310 void jabber_stream_set_state(JabberStream *js, JabberStreamState state);
   311 
   312 void jabber_register_parse(JabberStream *js, const char *from,
   313                            JabberIqType type, const char *id, xmlnode *query);
   314 void jabber_register_start(JabberStream *js);
   315 
   316 char *jabber_get_next_id(JabberStream *js);
   317 
   318 /** Parse an error into a human-readable string and optionally a disconnect
   319  *  reason.
   320  *  @param js     the stream on which the error occurred.
   321  *  @param packet the error packet
   322  *  @param reason where to store the disconnection reason, or @c NULL if you
   323  *                don't care or you don't intend to close the connection.
   324  */
   325 char *jabber_parse_error(JabberStream *js, xmlnode *packet, PurpleConnectionError *reason);
   326 
   327 void jabber_add_feature(const gchar *namespace, JabberFeatureEnabled cb); /* cb may be NULL */
   328 void jabber_remove_feature(const gchar *namespace);
   329 
   330 /** Adds an identity to this jabber library instance. For list of valid values visit the
   331  *	website of the XMPP Registrar ( http://www.xmpp.org/registrar/disco-categories.html#client ).
   332  *  @param category the category of the identity.
   333  *  @param type the type of the identity.
   334  *  @param language the language localization of the name. Can be NULL.
   335  *  @param name the name of the identity.
   336  */
   337 void jabber_add_identity(const gchar *category, const gchar *type, const gchar *lang, const gchar *name);
   338 
   339 /**
   340  * Returns true if this connection is over a secure (SSL) stream. Use this
   341  * instead of checking js->gsc because BOSH stores its PurpleSslConnection
   342  * members in its own data structure.
   343  */
   344 gboolean jabber_stream_is_ssl(JabberStream *js);
   345 
   346 /** PRPL functions */
   347 const char *jabber_list_icon(PurpleAccount *a, PurpleBuddy *b);
   348 const char* jabber_list_emblem(PurpleBuddy *b);
   349 char *jabber_status_text(PurpleBuddy *b);
   350 void jabber_tooltip_text(PurpleBuddy *b, PurpleNotifyUserInfo *user_info, gboolean full);
   351 GList *jabber_status_types(PurpleAccount *account);
   352 void jabber_login(PurpleAccount *account);
   353 void jabber_close(PurpleConnection *gc);
   354 void jabber_idle_set(PurpleConnection *gc, int idle);
   355 void jabber_blocklist_parse_push(JabberStream *js, const char *from,
   356                                  JabberIqType type, const char *id,
   357                                  xmlnode *child);
   358 void jabber_request_block_list(JabberStream *js);
   359 void jabber_add_deny(PurpleConnection *gc, const char *who);
   360 void jabber_rem_deny(PurpleConnection *gc, const char *who);
   361 void jabber_keepalive(PurpleConnection *gc);
   362 void jabber_register_gateway(JabberStream *js, const char *gateway);
   363 void jabber_register_account(PurpleAccount *account);
   364 void jabber_unregister_account(PurpleAccount *account, PurpleAccountUnregistrationCb cb, void *user_data);
   365 gboolean jabber_send_attention(PurpleConnection *gc, const char *username, guint code);
   366 GList *jabber_attention_types(PurpleAccount *account);
   367 void jabber_convo_closed(PurpleConnection *gc, const char *who);
   368 PurpleChat *jabber_find_blist_chat(PurpleAccount *account, const char *name);
   369 gboolean jabber_offline_message(const PurpleBuddy *buddy);
   370 int jabber_prpl_send_raw(PurpleConnection *gc, const char *buf, int len);
   371 GList *jabber_actions(PurplePlugin *plugin, gpointer context);
   372 
   373 gboolean jabber_audio_enabled(JabberStream *js, const char *unused);
   374 gboolean jabber_video_enabled(JabberStream *js, const char *unused);
   375 gboolean jabber_initiate_media(PurpleAccount *account, const char *who,
   376 		PurpleMediaSessionType type);
   377 PurpleMediaCaps jabber_get_media_caps(PurpleAccount *account, const char *who);
   378 
   379 void jabber_register_commands(void);
   380 void jabber_unregister_commands(void);
   381 
   382 void jabber_init_plugin(PurplePlugin *plugin);
   383 void jabber_uninit_plugin(void);
   384 
   385 #endif /* PURPLE_JABBER_H_ */