[f06894d] | 1 | /***************************************************************************\ |
---|
| 2 | * * |
---|
| 3 | * BitlBee - An IRC to IM gateway * |
---|
| 4 | * Jabber module - Main file * |
---|
| 5 | * * |
---|
| 6 | * Copyright 2006 Wilmer van der Gaast <wilmer@gaast.net> * |
---|
| 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 along * |
---|
| 19 | * with this program; if not, write to the Free Software Foundation, Inc., * |
---|
| 20 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * |
---|
| 21 | * * |
---|
| 22 | \***************************************************************************/ |
---|
| 23 | |
---|
| 24 | #ifndef _JABBER_H |
---|
| 25 | #define _JABBER_H |
---|
| 26 | |
---|
| 27 | #include <glib.h> |
---|
| 28 | |
---|
| 29 | #include "xmltree.h" |
---|
| 30 | #include "bitlbee.h" |
---|
| 31 | |
---|
[21167d2] | 32 | typedef enum |
---|
| 33 | { |
---|
[a21a8ac] | 34 | JFLAG_STREAM_STARTED = 1, /* Set when we detected the beginning of the stream |
---|
| 35 | and want to do auth. */ |
---|
[5997488] | 36 | JFLAG_AUTHENTICATED = 2, /* Set when we're successfully authenticatd. */ |
---|
[a21a8ac] | 37 | JFLAG_STREAM_RESTART = 4, /* Set when we want to restart the stream (after |
---|
| 38 | SASL or TLS). */ |
---|
| 39 | JFLAG_WAIT_SESSION = 8, /* Set if we sent a <session> tag and need a reply |
---|
| 40 | before we continue. */ |
---|
[fe7a554] | 41 | JFLAG_WAIT_BIND = 16, /* ... for <bind> tag. */ |
---|
[a21a8ac] | 42 | JFLAG_WANT_TYPING = 32, /* Set if we ever sent a typing notification, this |
---|
[788a1af] | 43 | activates all XEP-85 related code. */ |
---|
[21167d2] | 44 | } jabber_flags_t; |
---|
| 45 | |
---|
[a21a8ac] | 46 | typedef enum |
---|
| 47 | { |
---|
[788a1af] | 48 | JBFLAG_PROBED_XEP85 = 1, /* Set this when we sent our probe packet to make |
---|
[a21a8ac] | 49 | sure it gets sent only once. */ |
---|
[788a1af] | 50 | JBFLAG_DOES_XEP85 = 2, /* Set this when the resource seems to support |
---|
| 51 | XEP85 (typing notification shite). */ |
---|
[0d3f30f] | 52 | } jabber_buddy_flags_t; |
---|
[a21a8ac] | 53 | |
---|
[5e202b0] | 54 | struct jabber_data |
---|
| 55 | { |
---|
| 56 | struct gaim_connection *gc; |
---|
| 57 | |
---|
| 58 | int fd; |
---|
| 59 | void *ssl; |
---|
| 60 | char *txq; |
---|
| 61 | int tx_len; |
---|
| 62 | int r_inpa, w_inpa; |
---|
| 63 | |
---|
| 64 | struct xt_parser *xt; |
---|
| 65 | jabber_flags_t flags; |
---|
| 66 | |
---|
| 67 | char *username; /* USERNAME@server */ |
---|
| 68 | char *server; /* username@SERVER -=> server/domain, not hostname */ |
---|
[172a73f1] | 69 | |
---|
| 70 | /* After changing one of these two (or the priority setting), call |
---|
| 71 | presence_send_update() to inform the server about the changes. */ |
---|
[5e202b0] | 72 | struct jabber_away_state *away_state; |
---|
| 73 | char *away_message; |
---|
| 74 | |
---|
[038d17f] | 75 | GHashTable *node_cache; |
---|
[6a1128d] | 76 | GHashTable *buddies; |
---|
[5e202b0] | 77 | }; |
---|
| 78 | |
---|
| 79 | struct jabber_away_state |
---|
| 80 | { |
---|
| 81 | char code[5]; |
---|
| 82 | char *full_name; |
---|
| 83 | }; |
---|
| 84 | |
---|
[861c199] | 85 | typedef xt_status (*jabber_cache_event) ( struct gaim_connection *gc, struct xt_node *node, struct xt_node *orig ); |
---|
[038d17f] | 86 | |
---|
| 87 | struct jabber_cache_entry |
---|
| 88 | { |
---|
| 89 | struct xt_node *node; |
---|
| 90 | jabber_cache_event func; |
---|
| 91 | }; |
---|
| 92 | |
---|
[6a1128d] | 93 | struct jabber_buddy |
---|
| 94 | { |
---|
[0d3f30f] | 95 | char *bare_jid; |
---|
[a21a8ac] | 96 | char *full_jid; |
---|
[6a1128d] | 97 | char *resource; |
---|
| 98 | |
---|
| 99 | int priority; |
---|
| 100 | struct jabber_away_state *away_state; |
---|
| 101 | char *away_message; |
---|
| 102 | |
---|
| 103 | time_t last_act; |
---|
[0d3f30f] | 104 | jabber_buddy_flags_t flags; |
---|
[6a1128d] | 105 | |
---|
| 106 | struct jabber_buddy *next; |
---|
| 107 | }; |
---|
| 108 | |
---|
[dfa41a4] | 109 | /* Prefixes to use for packet IDs (mainly for IQ packets ATM). Usually the |
---|
| 110 | first one should be used, but when storing a packet in the cache, a |
---|
| 111 | "special" kind of ID is assigned to make it easier later to figure out |
---|
| 112 | if we have to do call an event handler for the response packet. */ |
---|
| 113 | #define JABBER_PACKET_ID "BeeP" |
---|
| 114 | #define JABBER_CACHED_ID "BeeC" |
---|
| 115 | |
---|
[47d3ac4] | 116 | /* RFC 392[01] stuff */ |
---|
| 117 | #define XMLNS_TLS "urn:ietf:params:xml:ns:xmpp-tls" |
---|
| 118 | #define XMLNS_SASL "urn:ietf:params:xml:ns:xmpp-sasl" |
---|
| 119 | #define XMLNS_BIND "urn:ietf:params:xml:ns:xmpp-bind" |
---|
| 120 | #define XMLNS_SESSION "urn:ietf:params:xml:ns:xmpp-session" |
---|
| 121 | #define XMLNS_STANZA_ERROR "urn:ietf:params:xml:ns:xmpp-stanzas" |
---|
| 122 | #define XMLNS_STREAM_ERROR "urn:ietf:params:xml:ns:xmpp-streams" |
---|
| 123 | #define XMLNS_ROSTER "jabber:iq:roster" |
---|
| 124 | |
---|
| 125 | /* Some supported extensions/legacy stuff */ |
---|
| 126 | #define XMLNS_AUTH "jabber:iq:auth" /* XEP-0078 */ |
---|
| 127 | #define XMLNS_VERSION "jabber:iq:version" /* XEP-0092 */ |
---|
| 128 | #define XMLNS_TIME "jabber:iq:time" /* XEP-0090 */ |
---|
| 129 | #define XMLNS_VCARD "vcard-temp" /* XEP-0054 */ |
---|
| 130 | #define XMLNS_CHATSTATES "http://jabber.org/protocol/chatstates" /* 0085 */ |
---|
| 131 | #define XMLNS_DISCOVER "http://jabber.org/protocol/disco#info" /* 0030 */ |
---|
| 132 | |
---|
[21167d2] | 133 | /* iq.c */ |
---|
[f06894d] | 134 | xt_status jabber_pkt_iq( struct xt_node *node, gpointer data ); |
---|
[861c199] | 135 | int jabber_init_iq_auth( struct gaim_connection *gc ); |
---|
| 136 | xt_status jabber_pkt_bind_sess( struct gaim_connection *gc, struct xt_node *node, struct xt_node *orig ); |
---|
[70f6aab8] | 137 | int jabber_get_roster( struct gaim_connection *gc ); |
---|
[1991be6] | 138 | int jabber_get_vcard( struct gaim_connection *gc, char *bare_jid ); |
---|
[cfbb3a6] | 139 | int jabber_add_to_roster( struct gaim_connection *gc, char *handle, char *name ); |
---|
| 140 | int jabber_remove_from_roster( struct gaim_connection *gc, char *handle ); |
---|
[21167d2] | 141 | |
---|
[cfbb3a6] | 142 | /* message.c */ |
---|
[f06894d] | 143 | xt_status jabber_pkt_message( struct xt_node *node, gpointer data ); |
---|
[0b4a0db] | 144 | |
---|
| 145 | /* presence.c */ |
---|
[f06894d] | 146 | xt_status jabber_pkt_presence( struct xt_node *node, gpointer data ); |
---|
[172a73f1] | 147 | int presence_send_update( struct gaim_connection *gc ); |
---|
[cfbb3a6] | 148 | int presence_send_request( struct gaim_connection *gc, char *handle, char *request ); |
---|
[f06894d] | 149 | |
---|
[21167d2] | 150 | /* jabber_util.c */ |
---|
[ebe7b36] | 151 | char *set_eval_priority( set_t *set, char *value ); |
---|
[f06894d] | 152 | char *set_eval_tls( set_t *set, char *value ); |
---|
[21167d2] | 153 | struct xt_node *jabber_make_packet( char *name, char *type, char *to, struct xt_node *children ); |
---|
[259edd4] | 154 | struct xt_node *jabber_make_error_packet( struct xt_node *orig, char *err_cond, char *err_type ); |
---|
[861c199] | 155 | void jabber_cache_add( struct gaim_connection *gc, struct xt_node *node, jabber_cache_event func ); |
---|
[038d17f] | 156 | struct xt_node *jabber_cache_get( struct gaim_connection *gc, char *id ); |
---|
| 157 | void jabber_cache_entry_free( gpointer entry ); |
---|
| 158 | void jabber_cache_clean( struct gaim_connection *gc ); |
---|
[5e202b0] | 159 | const struct jabber_away_state *jabber_away_state_by_code( char *code ); |
---|
| 160 | const struct jabber_away_state *jabber_away_state_by_name( char *name ); |
---|
[8e5e2e9] | 161 | void jabber_buddy_ask( struct gaim_connection *gc, char *handle ); |
---|
[0d3f30f] | 162 | char *jabber_normalize( char *orig ); |
---|
| 163 | |
---|
| 164 | typedef enum |
---|
| 165 | { |
---|
| 166 | GET_BUDDY_CREAT = 1, /* Try to create it, if necessary. */ |
---|
| 167 | GET_BUDDY_EXACT = 2, /* Get an exact message (only makes sense with bare JIDs). */ |
---|
| 168 | } get_buddy_flags_t; |
---|
| 169 | |
---|
[6a1128d] | 170 | struct jabber_buddy *jabber_buddy_add( struct gaim_connection *gc, char *full_jid ); |
---|
[0d3f30f] | 171 | struct jabber_buddy *jabber_buddy_by_jid( struct gaim_connection *gc, char *jid, get_buddy_flags_t flags ); |
---|
[6a1128d] | 172 | int jabber_buddy_remove( struct gaim_connection *gc, char *full_jid ); |
---|
[788a1af] | 173 | int jabber_buddy_remove_bare( struct gaim_connection *gc, char *bare_jid ); |
---|
[5e202b0] | 174 | |
---|
| 175 | extern const struct jabber_away_state jabber_away_state_list[]; |
---|
[21167d2] | 176 | |
---|
| 177 | /* io.c */ |
---|
| 178 | int jabber_write_packet( struct gaim_connection *gc, struct xt_node *node ); |
---|
| 179 | int jabber_write( struct gaim_connection *gc, char *buf, int len ); |
---|
| 180 | gboolean jabber_connected_plain( gpointer data, gint source, b_input_condition cond ); |
---|
[42127dc] | 181 | gboolean jabber_connected_ssl( gpointer data, void *source, b_input_condition cond ); |
---|
[4a0614e] | 182 | gboolean jabber_start_stream( struct gaim_connection *gc ); |
---|
[5bcf70a] | 183 | void jabber_end_stream( struct gaim_connection *gc ); |
---|
[21167d2] | 184 | |
---|
[5997488] | 185 | /* sasl.c */ |
---|
| 186 | xt_status sasl_pkt_mechanisms( struct xt_node *node, gpointer data ); |
---|
| 187 | xt_status sasl_pkt_challenge( struct xt_node *node, gpointer data ); |
---|
| 188 | xt_status sasl_pkt_result( struct xt_node *node, gpointer data ); |
---|
[8d74291] | 189 | gboolean sasl_supported( struct gaim_connection *gc ); |
---|
[5997488] | 190 | |
---|
[f06894d] | 191 | #endif |
---|