aboutsummaryrefslogtreecommitdiffstats
path: root/protocols/jabber/jabber.h
blob: 1ff0e8dd4a4ebad8c7ddfc7f66ca52ead6328fc1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
/***************************************************************************\
*                                                                           *
*  BitlBee - An IRC to IM gateway                                           *
*  Jabber module - Main file                                                *
*                                                                           *
*  Copyright 2006 Wilmer van der Gaast <wilmer@gaast.net>                   *
*                                                                           *
*  This program is free software; you can redistribute it and/or modify     *
*  it under the terms of the GNU General Public License as published by     *
*  the Free Software Foundation; either version 2 of the License, or        *
*  (at your option) any later version.                                      *
*                                                                           *
*  This program is distributed in the hope that it will be useful,          *
*  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
*  GNU General Public License for more details.                             *
*                                                                           *
*  You should have received a copy of the GNU General Public License along  *
*  with this program; if not, write to the Free Software Foundation, Inc.,  *
*  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.              *
*                                                                           *
\***************************************************************************/

#ifndef _JABBER_H
#define _JABBER_H

#include <glib.h>

#include "xmltree.h"
#include "bitlbee.h"

extern GSList *jabber_connections;

typedef enum
{
	JFLAG_STREAM_STARTED = 1,       /* Set when we detected the beginning of the stream
	                                   and want to do auth. */
	JFLAG_AUTHENTICATED = 2,        /* Set when we're successfully authenticatd. */
	JFLAG_STREAM_RESTART = 4,       /* Set when we want to restart the stream (after
	                                   SASL or TLS). */
	JFLAG_WAIT_SESSION = 8,	        /* Set if we sent a <session> tag and need a reply
	                                   before we continue. */
	JFLAG_WAIT_BIND = 16,           /* ... for <bind> tag. */
	JFLAG_WANT_TYPING = 32,         /* Set if we ever sent a typing notification, this
	                                   activates all XEP-85 related code. */
	JFLAG_XMLCONSOLE = 64,          /* If the user added an xmlconsole buddy. */
} jabber_flags_t;

typedef enum
{
	JBFLAG_PROBED_XEP85 = 1,        /* Set this when we sent our probe packet to make
	                                   sure it gets sent only once. */
	JBFLAG_DOES_XEP85 = 2,          /* Set this when the resource seems to support
	                                   XEP85 (typing notification shite). */
	JBFLAG_IS_CHATROOM = 4,         /* It's convenient to use this JID thingy for
	                                   groupchat state info too. */
	JBFLAG_IS_ANONYMOUS = 8,        /* For anonymous chatrooms, when we don't have
	                                   have a real JID. */
} jabber_buddy_flags_t;

typedef enum
{
	JCFLAG_MESSAGE_SENT = 1,        /* Set this after sending the first message, so
	                                   we can detect echoes/backlogs. */
} jabber_chat_flags_t;

struct jabber_data
{
	struct im_connection *ic;
	
	int fd;
	void *ssl;
	char *txq;
	int tx_len;
	int r_inpa, w_inpa;
	
	struct xt_parser *xt;
	jabber_flags_t flags;
	
	char *username;		/* USERNAME@server */
	char *server;		/* username@SERVER -=> server/domain, not hostname */
	
	/* After changing one of these two (or the priority setting), call
	   presence_send_update() to inform the server about the changes. */
	struct jabber_away_state *away_state;
	char *away_message;
	
	char *cached_id_prefix;
	GHashTable *node_cache;
	GHashTable *buddies;
};

struct jabber_away_state
{
	char code[5];
	char *full_name;
};

typedef xt_status (*jabber_cache_event) ( struct im_connection *ic, struct xt_node *node, struct xt_node *orig );

struct jabber_cache_entry
{
	time_t saved_at;
	struct xt_node *node;
	jabber_cache_event func;
};

struct jabber_buddy
{
	char *bare_jid;
	char *full_jid;
	char *resource;
	
	char *ext_jid; /* The JID to use in BitlBee. The real JID if possible, */
	               /* otherwise something similar to the conference JID. */
	
	int priority;
	struct jabber_away_state *away_state;
	char *away_message;
	
	time_t last_act;
	jabber_buddy_flags_t flags;
	
	struct jabber_buddy *next;
};

struct jabber_chat
{
	int flags;
	char *name;
	char *my_full_jid; /* Separate copy because of case sensitivity. */
	struct jabber_buddy *me;
};

#define JABBER_XMLCONSOLE_HANDLE "xmlconsole"

#define JABBER_PORT_DEFAULT "5222"
#define JABBER_PORT_MIN 5220
#define JABBER_PORT_MAX 5229

/* Prefixes to use for packet IDs (mainly for IQ packets ATM). Usually the
   first one should be used, but when storing a packet in the cache, a
   "special" kind of ID is assigned to make it easier later to figure out
   if we have to do call an event handler for the response packet. Also
   we'll append a hash to make sure we won't trigger on cached packets from
   other BitlBee users. :-) */
#define JABBER_PACKET_ID "BeeP"
#define JABBER_CACHED_ID "BeeC"

/* The number of seconds to keep cached packets before garbage collecting
   them. This gc is done on every keepalive (every minute). */
#define JABBER_CACHE_MAX_AGE 600

/* RFC 392[01] stuff */
#define XMLNS_TLS          "urn:ietf:params:xml:ns:xmpp-tls"
#define XMLNS_SASL         "urn:ietf:params:xml:ns:xmpp-sasl"
#define XMLNS_BIND         "urn:ietf:params:xml:ns:xmpp-bind"
#define XMLNS_SESSION      "urn:ietf:params:xml:ns:xmpp-session"
#define XMLNS_STANZA_ERROR "urn:ietf:params:xml:ns:xmpp-stanzas"
#define XMLNS_STREAM_ERROR "urn:ietf:params:xml:ns:xmpp-streams"
#define XMLNS_ROSTER       "jabber:iq:roster"

/* Some supported extensions/legacy stuff */
#define XMLNS_AUTH         "jabber:iq:auth"                     /* XEP-0078 */
#define XMLNS_VERSION      "jabber:iq:version"                  /* XEP-0092 */
#define XMLNS_TIME         "jabber:iq:time"                     /* XEP-0090 */
#define XMLNS_PING         "urn:xmpp:ping"                      /* XEP-0199 */
#define XMLNS_VCARD        "vcard-temp"                         /* XEP-0054 */
#define XMLNS_DELAY        "jabber:x:delay"                     /* XEP-0091 */
#define XMLNS_CHATSTATES   "http://jabber.org/protocol/chatstates"  /* 0085 */
#define XMLNS_DISCOVER     "http://jabber.org/protocol/disco#info"  /* 0030 */
#define XMLNS_MUC          "http://jabber.org/protocol/muc"     /* XEP-0045 */
#define XMLNS_MUC_USER     "http://jabber.org/protocol/muc#user"/* XEP-0045 */
#define XMLNS_CAPS         "http://jabber.org/protocol/caps"    /* XEP-0115 */

/* iq.c */
xt_status jabber_pkt_iq( struct xt_node *node, gpointer data );
int jabber_init_iq_auth( struct im_connection *ic );
xt_status jabber_pkt_bind_sess( struct im_connection *ic, struct xt_node *node, struct xt_node *orig );
int jabber_get_roster( struct im_connection *ic );
int jabber_get_vcard( struct im_connection *ic, char *bare_jid );
int jabber_add_to_roster( struct im_connection *ic, char *handle, char *name );
int jabber_remove_from_roster( struct im_connection *ic, char *handle );

/* message.c */
xt_status jabber_pkt_message( struct xt_node *node, gpointer data );

/* presence.c */
xt_status jabber_pkt_presence( struct xt_node *node, gpointer data );
int presence_send_update( struct im_connection *ic );
int presence_send_request( struct im_connection *ic, char *handle, char *request );

/* jabber_util.c */
char *set_eval_priority( set_t *set, char *value );
char *set_eval_tls( set_t *set, char *value );
struct xt_node *jabber_make_packet( char *name, char *type, char *to, struct xt_node *children );
struct xt_node *jabber_make_error_packet( struct xt_node *orig, char *err_cond, char *err_type );
void jabber_cache_add( struct im_connection *ic, struct xt_node *node, jabber_cache_event func );
struct xt_node *jabber_cache_get( struct im_connection *ic, char *id );
void jabber_cache_entry_free( gpointer entry );
void jabber_cache_clean( struct im_connection *ic );
xt_status jabber_cache_handle_packet( struct im_connection *ic, struct xt_node *node );
const struct jabber_away_state *jabber_away_state_by_code( char *code );
const struct jabber_away_state *jabber_away_state_by_name( char *name );
void jabber_buddy_ask( struct im_connection *ic, char *handle );
char *jabber_normalize( const char *orig );

typedef enum
{
	GET_BUDDY_CREAT = 1,	/* Try to create it, if necessary. */
	GET_BUDDY_EXACT = 2,	/* Get an exact match (only makes sense with bare JIDs). */
	GET_BUDDY_FIRST = 4,	/* No selection, simply get the first resource for this JID. */
} get_buddy_flags_t;

struct jabber_error
{
	char *code, *text, *type;
};

struct jabber_buddy *jabber_buddy_add( struct im_connection *ic, char *full_jid );
struct jabber_buddy *jabber_buddy_by_jid( struct im_connection *ic, char *jid, get_buddy_flags_t flags );
struct jabber_buddy *jabber_buddy_by_ext_jid( struct im_connection *ic, char *jid, get_buddy_flags_t flags );
int jabber_buddy_remove( struct im_connection *ic, char *full_jid );
int jabber_buddy_remove_bare( struct im_connection *ic, char *bare_jid );
time_t jabber_get_timestamp( struct xt_node *xt );
struct jabber_error *jabber_error_parse( struct xt_node *node, char *xmlns );
void jabber_error_free( struct jabber_error *err );

extern const struct jabber_away_state jabber_away_state_list[];

/* io.c */
int jabber_write_packet( struct im_connection *ic, struct xt_node *node );
int jabber_write( struct im_connection *ic, char *buf, int len );
gboolean jabber_connected_plain( gpointer data, gint source, b_input_condition cond );
gboolean jabber_connected_ssl( gpointer data, void *source, b_input_condition cond );
gboolean jabber_start_stream( struct im_connection *ic );
void jabber_end_stream( struct im_connection *ic );

/* sasl.c */
xt_status sasl_pkt_mechanisms( struct xt_node *node, gpointer data );
xt_status sasl_pkt_challenge( struct xt_node *node, gpointer data );
xt_status sasl_pkt_result( struct xt_node *node, gpointer data );
gboolean sasl_supported( struct im_connection *ic );

/* conference.c */
struct groupchat *jabber_chat_join( struct im_connection *ic, char *room, char *nick, char *password );
struct groupchat *jabber_chat_by_jid( struct im_connection *ic, const char *name );
void jabber_chat_free( struct groupchat *c );
int jabber_chat_msg( struct groupchat *ic, char *message, int flags );
int jabber_chat_topic( struct groupchat *c, char *topic );
int jabber_chat_leave( struct groupchat *c, const char *reason );
void jabber_chat_pkt_presence( struct im_connection *ic, struct jabber_buddy *bud, struct xt_node *node );
void jabber_chat_pkt_message( struct im_connection *ic, struct jabber_buddy *bud, struct xt_node *node );
void jabber_chat_invite( struct groupchat *c, char *who, char *message );

#endif
">); g_free( bg->group ); g_free( bg ); } g_slist_free( yd->buddygroups ); if( yd->logged_in ) yahoo_logoff( yd->y2_id ); else yahoo_close( yd->y2_id ); g_free( yd ); } static void byahoo_get_info(struct im_connection *ic, char *who) { /* Just make an URL and let the user fetch the info */ imcb_log(ic, "%s\n%s: %s%s", _("User Info"), _("For now, fetch yourself"), yahoo_get_profile_url(), who); } static int byahoo_buddy_msg( struct im_connection *ic, char *who, char *what, int flags ) { struct byahoo_data *yd = ic->proto_data; yahoo_send_im( yd->y2_id, NULL, who, what, 1, 0 ); return 1; } static int byahoo_send_typing( struct im_connection *ic, char *who, int typing ) { struct byahoo_data *yd = ic->proto_data; yahoo_send_typing( yd->y2_id, NULL, who, ( typing & OPT_TYPING ) != 0 ); return 1; } static void byahoo_set_away( struct im_connection *ic, char *state, char *msg ) { struct byahoo_data *yd = (struct byahoo_data *) ic->proto_data; ic->away = NULL; if( state && msg && g_strcasecmp( state, msg ) != 0 ) { yd->current_status = YAHOO_STATUS_CUSTOM; ic->away = ""; } else if( state ) { /* Set msg to NULL since (if it isn't NULL already) it's equal to state. msg must be empty if we want to use an existing away state. */ msg = NULL; ic->away = ""; if( g_strcasecmp( state, "Available" ) == 0 ) { yd->current_status = YAHOO_STATUS_AVAILABLE; ic->away = NULL; } else if( g_strcasecmp( state, "Be Right Back" ) == 0 ) yd->current_status = YAHOO_STATUS_BRB; else if( g_strcasecmp( state, "Busy" ) == 0 ) yd->current_status = YAHOO_STATUS_BUSY; else if( g_strcasecmp( state, "Not At Home" ) == 0 ) yd->current_status = YAHOO_STATUS_NOTATHOME; else if( g_strcasecmp( state, "Not At Desk" ) == 0 ) yd->current_status = YAHOO_STATUS_NOTATDESK; else if( g_strcasecmp( state, "Not In Office" ) == 0 ) yd->current_status = YAHOO_STATUS_NOTINOFFICE; else if( g_strcasecmp( state, "On Phone" ) == 0 ) yd->current_status = YAHOO_STATUS_ONPHONE; else if( g_strcasecmp( state, "On Vacation" ) == 0 ) yd->current_status = YAHOO_STATUS_ONVACATION; else if( g_strcasecmp( state, "Out To Lunch" ) == 0 ) yd->current_status = YAHOO_STATUS_OUTTOLUNCH; else if( g_strcasecmp( state, "Stepped Out" ) == 0 ) yd->current_status = YAHOO_STATUS_STEPPEDOUT; else if( g_strcasecmp( state, "Invisible" ) == 0 ) yd->current_status = YAHOO_STATUS_INVISIBLE; else if( g_strcasecmp( state, GAIM_AWAY_CUSTOM ) == 0 ) { yd->current_status = YAHOO_STATUS_AVAILABLE; ic->away = NULL; } } else yd->current_status = YAHOO_STATUS_AVAILABLE; yahoo_set_away( yd->y2_id, yd->current_status, msg, ic->away != NULL ? 2 : 0 ); } static GList *byahoo_away_states( struct im_connection *ic ) { GList *m = NULL; m = g_list_append( m, "Available" ); m = g_list_append( m, "Be Right Back" ); m = g_list_append( m, "Busy" ); m = g_list_append( m, "Not At Home" ); m = g_list_append( m, "Not At Desk" ); m = g_list_append( m, "Not In Office" ); m = g_list_append( m, "On Phone" ); m = g_list_append( m, "On Vacation" ); m = g_list_append( m, "Out To Lunch" ); m = g_list_append( m, "Stepped Out" ); m = g_list_append( m, "Invisible" ); m = g_list_append( m, GAIM_AWAY_CUSTOM ); return m; } static void byahoo_keepalive( struct im_connection *ic ) { struct byahoo_data *yd = ic->proto_data; yahoo_keepalive( yd->y2_id ); } static void byahoo_add_buddy( struct im_connection *ic, char *who, char *group ) { struct byahoo_data *yd = (struct byahoo_data *) ic->proto_data; yahoo_add_buddy( yd->y2_id, who, group ? group : BYAHOO_DEFAULT_GROUP, NULL ); } static void byahoo_remove_buddy( struct im_connection *ic, char *who, char *group ) { struct byahoo_data *yd = (struct byahoo_data *) ic->proto_data; GSList *bgl; yahoo_remove_buddy( yd->y2_id, who, BYAHOO_DEFAULT_GROUP ); for( bgl = yd->buddygroups; bgl; bgl = bgl->next ) { struct byahoo_buddygroups *bg = bgl->data; if( g_strcasecmp( bg->buddy, who ) == 0 ) yahoo_remove_buddy( yd->y2_id, who, bg->group ); } } static void byahoo_chat_msg( struct groupchat *c, char *message, int flags ) { struct byahoo_data *yd = (struct byahoo_data *) c->ic->proto_data; yahoo_conference_message( yd->y2_id, NULL, c->data, c->title, message, 1 ); } static void byahoo_chat_invite( struct groupchat *c, char *who, char *msg ) { struct byahoo_data *yd = (struct byahoo_data *) c->ic->proto_data; yahoo_conference_invite( yd->y2_id, NULL, c->data, c->title, msg ? msg : "" ); } static void byahoo_chat_leave( struct groupchat *c ) { struct byahoo_data *yd = (struct byahoo_data *) c->ic->proto_data; yahoo_conference_logoff( yd->y2_id, NULL, c->data, c->title ); imcb_chat_free( c ); } static struct groupchat *byahoo_chat_with( struct im_connection *ic, char *who ) { struct byahoo_data *yd = (struct byahoo_data *) ic->proto_data; struct groupchat *c; char *roomname; YList *members; roomname = g_strdup_printf( "%s-Bee-%d", ic->acc->user, byahoo_chat_id ); c = imcb_chat_new( ic, roomname ); imcb_chat_add_buddy( c, ic->acc->user ); /* FIXME: Free this thing when the chat's destroyed. We can't *always* do this because it's not always created here. */ c->data = members = g_new0( YList, 1 ); members->data = g_strdup( who ); yahoo_conference_invite( yd->y2_id, NULL, members, roomname, "Please join my groupchat..." ); g_free( roomname ); return c; } void byahoo_initmodule( ) { struct prpl *ret = g_new0(struct prpl, 1); ret->name = "yahoo"; ret->init = byahoo_init; ret->login = byahoo_login; ret->keepalive = byahoo_keepalive; ret->logout = byahoo_logout; ret->buddy_msg = byahoo_buddy_msg; ret->get_info = byahoo_get_info; ret->away_states = byahoo_away_states; ret->set_away = byahoo_set_away; ret->add_buddy = byahoo_add_buddy; ret->remove_buddy = byahoo_remove_buddy; ret->send_typing = byahoo_send_typing; ret->chat_msg = byahoo_chat_msg; ret->chat_invite = byahoo_chat_invite; ret->chat_leave = byahoo_chat_leave; ret->chat_with = byahoo_chat_with; ret->handle_cmp = g_strcasecmp; register_protocol(ret); } static struct im_connection *byahoo_get_ic_by_id( int id ) { GSList *l; struct im_connection *ic; struct byahoo_data *yd; for( l = get_connections(); l; l = l->next ) { ic = l->data; yd = ic->proto_data; if( strcmp( ic->acc->prpl->name, "yahoo" ) == 0 && yd->y2_id == id ) return( ic ); } return( NULL ); } /* Now it's callback time! */ struct byahoo_connect_callback_data { int fd; yahoo_connect_callback callback; gpointer data; int id; }; void byahoo_connect_callback( gpointer data, gint source, b_input_condition cond ) { struct byahoo_connect_callback_data *d = data; if( !byahoo_get_ic_by_id( d->id ) ) { g_free( d ); return; } d->callback( d->fd, 0, d->data ); g_free( d ); } struct byahoo_read_ready_data { int id; int fd; int tag; gpointer data; }; gboolean byahoo_read_ready_callback( gpointer data, gint source, b_input_condition cond ) { struct byahoo_read_ready_data *d = data; if( !byahoo_get_ic_by_id( d->id ) ) /* WTF doesn't libyahoo clean this up? */ return FALSE; yahoo_read_ready( d->id, d->fd, d->data ); return TRUE; } struct byahoo_write_ready_data { int id; int fd; int tag; gpointer data; }; gboolean byahoo_write_ready_callback( gpointer data, gint source, b_input_condition cond ) { struct byahoo_write_ready_data *d = data; if( !byahoo_get_ic_by_id( d->id ) ) /* WTF doesn't libyahoo clean this up? */ return FALSE; yahoo_write_ready( d->id, d->fd, d->data ); return FALSE; } void ext_yahoo_login_response( int id, int succ, const char *url ) { struct im_connection *ic = byahoo_get_ic_by_id( id ); struct byahoo_data *yd = NULL; if( ic == NULL ) { /* libyahoo2 seems to call this one twice when something went wrong sometimes. Don't know why. Because we clean up the connection on the first failure, the second should be ignored. */ return; } yd = (struct byahoo_data *) ic->proto_data; if( succ == YAHOO_LOGIN_OK ) { imcb_connected( ic ); yd->logged_in = TRUE; } else { char *errstr; int allow_reconnect = TRUE; yd->logged_in = FALSE; if( succ == YAHOO_LOGIN_UNAME ) errstr = "Incorrect Yahoo! username"; else if( succ == YAHOO_LOGIN_PASSWD ) errstr = "Incorrect Yahoo! password"; else if( succ == YAHOO_LOGIN_LOCK ) errstr = "Yahoo! account locked"; else if( succ == YAHOO_LOGIN_DUPL ) { errstr = "Logged in on a different machine or device"; allow_reconnect = FALSE; } else if( succ == YAHOO_LOGIN_SOCK ) errstr = "Socket problem"; else errstr = "Unknown error"; if( url && *url ) imcb_error( ic, "Error %d (%s). See %s for more information.", succ, errstr, url ); else imcb_error( ic, "Error %d (%s)", succ, errstr ); imc_logout( ic, allow_reconnect ); } } void ext_yahoo_got_buddies( int id, YList *buds ) { struct im_connection *ic = byahoo_get_ic_by_id( id ); struct byahoo_data *yd = ic->proto_data; YList *bl = buds; while( bl ) { struct yahoo_buddy *b = bl->data; struct byahoo_buddygroups *bg; if( strcmp( b->group, BYAHOO_DEFAULT_GROUP ) != 0 ) { bg = g_new0( struct byahoo_buddygroups, 1 ); bg->buddy = g_strdup( b->id ); bg->group = g_strdup( b->group ); yd->buddygroups = g_slist_append( yd->buddygroups, bg ); } imcb_add_buddy( ic, b->id, b->group ); imcb_rename_buddy( ic, b->id, b->real_name ); bl = bl->next; } } void ext_yahoo_got_ignore( int id, YList *igns ) { } void ext_yahoo_got_identities( int id, YList *ids ) { } void ext_yahoo_got_cookies( int id ) { } void ext_yahoo_status_changed( int id, const char *who, int stat, const char *msg, int away, int idle, int mobile ) { struct im_connection *ic = byahoo_get_ic_by_id( id ); char *state_string = NULL; int flags = OPT_LOGGED_IN; if( away ) flags |= OPT_AWAY; switch (stat) { case YAHOO_STATUS_BRB: state_string = "Be Right Back"; break; case YAHOO_STATUS_BUSY: state_string = "Busy"; break; case YAHOO_STATUS_NOTATHOME: state_string = "Not At Home"; break; case YAHOO_STATUS_NOTATDESK: state_string = "Not At Desk"; break; case YAHOO_STATUS_NOTINOFFICE: state_string = "Not In Office"; break; case YAHOO_STATUS_ONPHONE: state_string = "On Phone"; break; case YAHOO_STATUS_ONVACATION: state_string = "On Vacation"; break; case YAHOO_STATUS_OUTTOLUNCH: state_string = "Out To Lunch"; break; case YAHOO_STATUS_STEPPEDOUT: state_string = "Stepped Out"; break; case YAHOO_STATUS_INVISIBLE: state_string = "Invisible"; break; case YAHOO_STATUS_CUSTOM: state_string = "Away"; break; case YAHOO_STATUS_IDLE: state_string = "Idle"; break; case YAHOO_STATUS_OFFLINE: state_string = "Offline"; flags = 0; break; case YAHOO_STATUS_NOTIFY: state_string = "Notify"; break; } imcb_buddy_status( ic, who, flags, state_string, msg ); /* Not implemented yet... if( stat == YAHOO_STATUS_IDLE ) imcb_buddy_times( ic, who, 0, away ); */ } void ext_yahoo_got_im( int id, const char *me, const char *who, const char *msg, long tm, int stat, int utf8 ) { struct im_connection *ic = byahoo_get_ic_by_id( id ); char *m; if( msg ) { m = byahoo_strip( msg ); imcb_buddy_msg( ic, (char*) who, (char*) m, 0, 0 ); g_free( m ); } } void ext_yahoo_got_file( int id, const char *ignored, const char *who, const char *url, long expires, const char *msg, const char *fname, unsigned long fesize ) { struct im_connection *ic = byahoo_get_ic_by_id( id ); imcb_log( ic, "Got a file transfer (file = %s) from %s. Ignoring for now due to lack of support.", fname, who ); } void ext_yahoo_typing_notify( int id, const char *ignored, const char *who, int stat ) { struct im_connection *ic = byahoo_get_ic_by_id( id ); if( stat == 1 ) imcb_buddy_typing( ic, (char*) who, OPT_TYPING ); else imcb_buddy_typing( ic, (char*) who, 0 ); } void ext_yahoo_system_message( int id, const char *msg ) { struct im_connection *ic = byahoo_get_ic_by_id( id ); imcb_log( ic, "Yahoo! system message: %s", msg ); } void ext_yahoo_webcam_invite( int id, const char *ignored, const char *from ) { struct im_connection *ic = byahoo_get_ic_by_id( id ); imcb_log( ic, "Got a webcam invitation from %s. IRC+webcams is a no-no though...", from ); } void ext_yahoo_error( int id, const char *err, int fatal, int num ) { struct im_connection *ic = byahoo_get_ic_by_id( id ); imcb_error( ic, "%s", err ); if( fatal ) imc_logout( ic, TRUE ); } /* TODO: Clear up the mess of inp and d structures */ int ext_yahoo_add_handler( int id, int fd, yahoo_input_condition cond, void *data ) { struct byahoo_input_data *inp = g_new0( struct byahoo_input_data, 1 ); if( cond == YAHOO_INPUT_READ ) { struct byahoo_read_ready_data *d = g_new0( struct byahoo_read_ready_data, 1 ); d->id = id; d->fd = fd; d->data = data; inp->d = d; d->tag = inp->h = b_input_add( fd, GAIM_INPUT_READ, (b_event_handler) byahoo_read_ready_callback, (gpointer) d ); } else if( cond == YAHOO_INPUT_WRITE ) { struct byahoo_write_ready_data *d = g_new0( struct byahoo_write_ready_data, 1 ); d->id = id; d->fd = fd; d->data = data; inp->d = d; d->tag = inp->h = b_input_add( fd, GAIM_INPUT_WRITE, (b_event_handler) byahoo_write_ready_callback, (gpointer) d ); } else { g_free( inp ); return( -1 ); /* Panic... */ } byahoo_inputs = g_slist_append( byahoo_inputs, inp ); return( inp->h ); } void ext_yahoo_remove_handler( int id, int tag ) { struct byahoo_input_data *inp; GSList *l = byahoo_inputs; while( l ) { inp = l->data; if( inp->h == tag ) { g_free( inp->d ); g_free( inp ); byahoo_inputs = g_slist_remove( byahoo_inputs, inp ); break; } l = l->next; } b_event_remove( tag ); } int ext_yahoo_connect_async( int id, const char *host, int port, yahoo_connect_callback callback, void *data ) { struct byahoo_connect_callback_data *d; int fd; d = g_new0( struct byahoo_connect_callback_data, 1 ); if( ( fd = proxy_connect( host, port, (b_event_handler) byahoo_connect_callback, (gpointer) d ) ) < 0 ) { g_free( d ); return( fd ); } d->fd = fd; d->callback = callback; d->data = data; d->id = id; return( fd ); } /* Because we don't want asynchronous connects in BitlBee, and because libyahoo doesn't seem to use this one anyway, this one is now defunct. */ int ext_yahoo_connect(const char *host, int port) { #if 0 struct sockaddr_in serv_addr; static struct hostent *server; static char last_host[256]; int servfd; char **p; if(last_host[0] || g_strcasecmp(last_host, host)!=0) { if(!(server = gethostbyname(host))) { return -1; } strncpy(last_host, host, 255); } if((servfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) { return -1; } for (p = server->h_addr_list; *p; p++) { memset(&serv_addr, 0, sizeof(serv_addr)); serv_addr.sin_family = AF_INET; memcpy(&serv_addr.sin_addr.s_addr, *p, server->h_length); serv_addr.sin_port = htons(port); if(connect(servfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) == -1) { return -1; } else { return servfd; } } closesocket(servfd); #endif return -1; } static void byahoo_accept_conf( gpointer w, struct byahoo_conf_invitation *inv ) { yahoo_conference_logon( inv->yid, NULL, inv->members, inv->name ); imcb_chat_add_buddy( inv->c, inv->ic->acc->user ); g_free( inv->name ); g_free( inv ); } static void byahoo_reject_conf( gpointer w, struct byahoo_conf_invitation *inv ) { yahoo_conference_decline( inv->yid, NULL, inv->members, inv->name, "User rejected groupchat" ); imcb_chat_free( inv->c ); g_free( inv->name ); g_free( inv ); } void ext_yahoo_got_conf_invite( int id, const char *ignored, const char *who, const char *room, const char *msg, YList *members ) { struct im_connection *ic = byahoo_get_ic_by_id( id ); struct byahoo_conf_invitation *inv; char txt[1024]; YList *m; inv = g_malloc( sizeof( struct byahoo_conf_invitation ) ); memset( inv, 0, sizeof( struct byahoo_conf_invitation ) ); inv->name = g_strdup( room ); inv->c = imcb_chat_new( ic, (char*) room ); inv->c->data = members; inv->yid = id; inv->members = members; inv->ic = ic; for( m = members; m; m = m->next ) if( g_strcasecmp( m->data, ic->acc->user ) != 0 ) imcb_chat_add_buddy( inv->c, m->data ); g_snprintf( txt, 1024, "Got an invitation to chatroom %s from %s: %s", room, who, msg ); imcb_ask( ic, txt, inv, byahoo_accept_conf, byahoo_reject_conf ); } void ext_yahoo_conf_userdecline( int id, const char *ignored, const char *who, const char *room, const char *msg ) { struct im_connection *ic = byahoo_get_ic_by_id( id ); imcb_log( ic, "Invite to chatroom %s rejected by %s: %s", room, who, msg ); } void ext_yahoo_conf_userjoin( int id, const char *ignored, const char *who, const char *room ) { struct im_connection *ic = byahoo_get_ic_by_id( id ); struct groupchat *c; for( c = ic->groupchats; c && strcmp( c->title, room ) != 0; c = c->next ); if( c ) imcb_chat_add_buddy( c, (char*) who ); } void ext_yahoo_conf_userleave( int id, const char *ignored, const char *who, const char *room ) { struct im_connection *ic = byahoo_get_ic_by_id( id ); struct groupchat *c; for( c = ic->groupchats; c && strcmp( c->title, room ) != 0; c = c->next ); if( c ) imcb_chat_remove_buddy( c, (char*) who, "" ); } void ext_yahoo_conf_message( int id, const char *ignored, const char *who, const char *room, const char *msg, int utf8 ) { struct im_connection *ic = byahoo_get_ic_by_id( id ); char *m = byahoo_strip( msg ); struct groupchat *c; for( c = ic->groupchats; c && strcmp( c->title, room ) != 0; c = c->next ); if( c ) imcb_chat_msg( c, (char*) who, (char*) m, 0, 0 ); g_free( m ); } void ext_yahoo_chat_cat_xml( int id, const char *xml ) { } void ext_yahoo_chat_join( int id, const char *who, const char *room, const char *topic, YList *members, int fd ) { } void ext_yahoo_chat_userjoin( int id, const char *me, const char *room, struct yahoo_chat_member *who ) { free(who->id); free(who->alias); free(who->location); free(who); } void ext_yahoo_chat_userleave( int id, const char *me, const char *room, const char *who ) { } void ext_yahoo_chat_message( int id, const char *me, const char *who, const char *room, const char *msg, int msgtype, int utf8 ) { } void ext_yahoo_chat_yahoologout( int id, const char *me ) { } void ext_yahoo_chat_yahooerror( int id, const char *me ) { } void ext_yahoo_contact_added( int id, const char *myid, const char *who, const char *msg ) { /* Groups schmoups. If I want to handle groups properly I can get the buddy data from some internal libyahoo2 structure. */ imcb_add_buddy( byahoo_get_ic_by_id( id ), (char*) who, NULL ); } void ext_yahoo_rejected( int id, const char *who, const char *msg ) { } void ext_yahoo_game_notify( int id, const char *me, const char *who, int stat ) { } void ext_yahoo_mail_notify( int id, const char *from, const char *subj, int cnt ) { struct im_connection *ic = byahoo_get_ic_by_id( id ); if( !set_getbool( &ic->acc->set, "mail_notifications" ) ) ; /* The user doesn't care. */ else if( from && subj ) imcb_log( ic, "Received e-mail message from %s with subject `%s'", from, subj ); else if( cnt > 0 ) imcb_log( ic, "Received %d new e-mails", cnt ); } void ext_yahoo_webcam_invite_reply( int id, const char *me, const char *from, int accept ) { } void ext_yahoo_webcam_closed( int id, const char *who, int reason ) { } void ext_yahoo_got_search_result( int id, int found, int start, int total, YList *contacts ) { } void ext_yahoo_webcam_viewer( int id, const char *who, int connect ) { } void ext_yahoo_webcam_data_request( int id, int send ) { } int ext_yahoo_log( const char *fmt, ... ) { return( 0 ); } void ext_yahoo_got_webcam_image( int id, const char * who, const unsigned char *image, unsigned int image_size, unsigned int real_size, unsigned int timestamp ) { } void ext_yahoo_got_ping( int id, const char *msg) { } void ext_yahoo_got_buddyicon (int id, const char *me, const char *who, const char *url, int checksum) {} void ext_yahoo_got_buddyicon_checksum (int id, const char *me,const char *who, int checksum) {} void ext_yahoo_got_buddyicon_request(int id, const char *me, const char *who){} void ext_yahoo_buddyicon_uploaded(int id, const char *url){}