aboutsummaryrefslogtreecommitdiffstats
path: root/protocols/jabber/presence.c
blob: 82ea5f8f0e7885b0e416ae299dce8c32c61abe08 (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
/***************************************************************************\
*                                                                           *
*  BitlBee - An IRC to IM gateway                                           *
*  Jabber module - Handling of presence (tags), etc                         *
*                                                                           *
*  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.              *
*                                                                           *
\***************************************************************************/

#include "jabber.h"

xt_status jabber_pkt_presence(struct xt_node *node, gpointer data)
{
	struct im_connection *ic = data;
	char *from = xt_find_attr(node, "from");
	char *type = xt_find_attr(node, "type");        /* NULL should mean the person is online. */
	struct xt_node *c, *cap;
	struct jabber_buddy *bud, *send_presence = NULL;
	int is_chat = 0;
	char *s;

	if (!from) {
		return XT_HANDLED;
	}

	if ((s = strchr(from, '/'))) {
		*s = 0;
		if (jabber_chat_by_jid(ic, from)) {
			is_chat = 1;
		}
		*s = '/';
	}

	if (type == NULL) {
		if (!(bud = jabber_buddy_by_jid(ic, from, GET_BUDDY_EXACT | GET_BUDDY_CREAT))) {
			/*
			imcb_log( ic, "Warning: Could not handle presence information from JID: %s", from );
			*/
			return XT_HANDLED;
		}

		g_free(bud->away_message);
		if ((c = xt_find_node(node->children, "status")) && c->text_len > 0) {
			bud->away_message = g_strdup(c->text);
		} else {
			bud->away_message = NULL;
		}

		if ((c = xt_find_node(node->children, "show")) && c->text_len > 0) {
			bud->away_state = (void *) jabber_away_state_by_code(c->text);
		} else {
			bud->away_state = NULL;
		}

		if ((c = xt_find_node(node->children, "priority")) && c->text_len > 0) {
			bud->priority = atoi(c->text);
		} else {
			bud->priority = 0;
		}

		if (bud && (cap = xt_find_node(node->children, "c")) &&
		    (s = xt_find_attr(cap, "xmlns")) && strcmp(s, XMLNS_CAPS) == 0) {
			/* This <presence> stanza includes an XEP-0115
			   capabilities part. Not too interesting, but we can
			   see if it has an ext= attribute. */
			s = xt_find_attr(cap, "ext");
			if (s && (strstr(s, "cstates") || strstr(s, "chatstate"))) {
				bud->flags |= JBFLAG_DOES_XEP85;
			}

			/* This field can contain more information like xhtml
			   support, but we don't support that ourselves.
			   Officially the ext= tag was deprecated, but enough
			   clients do send it.

			   (I'm aware that this is not the right way to use
			   this field.) See for an explanation of ext=:
			   http://www.xmpp.org/extensions/attic/xep-0115-1.3.html*/
		}

		if (is_chat) {
			jabber_chat_pkt_presence(ic, bud, node);
		} else {
			send_presence = jabber_buddy_by_jid(ic, bud->bare_jid, 0);
		}
	} else if (strcmp(type, "unavailable") == 0) {
		if ((bud = jabber_buddy_by_jid(ic, from, 0)) == NULL) {
			/*
			imcb_log( ic, "Warning: Received presence information from unknown JID: %s", from );
			*/
			return XT_HANDLED;
		}

		/* Handle this before we delete the JID. */
		if (is_chat) {
			jabber_chat_pkt_presence(ic, bud, node);
		}

		if (strchr(from, '/') == NULL) {
			/* Sometimes servers send a type="unavailable" from a
			   bare JID, which should mean that suddenly all
			   resources for this JID disappeared. */
			jabber_buddy_remove_bare(ic, from);
		} else {
			jabber_buddy_remove(ic, from);
		}

		if (is_chat) {
			/* Nothing else to do for now? */
		} else if ((s = strchr(from, '/'))) {
			*s = 0;

			/* If another resource is still available, send its presence
			   information. */
			if ((send_presence = jabber_buddy_by_jid(ic, from, 0)) == NULL) {
				/* Otherwise, count him/her as offline now. */
				imcb_buddy_status(ic, from, 0, NULL, NULL);
			}

			*s = '/';
		} else {
			imcb_buddy_status(ic, from, 0, NULL, NULL);
		}
	} else if (strcmp(type, "subscribe") == 0) {
		jabber_buddy_ask(ic, from);
	} else if (strcmp(type, "subscribed") == 0) {
		/* Not sure about this one, actually... */
		imcb_log(ic, "%s just accepted your authorization request", from);
	} else if (strcmp(type, "unsubscribe") == 0 || strcmp(type, "unsubscribed") == 0) {
		/* Do nothing here. Plenty of control freaks or over-curious
		   souls get excited when they can see who still has them in
		   their buddy list and who finally removed them. Somehow I
		   got the impression that those are the people who get
		   removed from many buddy lists for "some" reason...

		   If you're one of those people, this is your chance to write
		   your first line of code in C... */
	} else if (strcmp(type, "error") == 0) {
		return jabber_cache_handle_packet(ic, node);

		/*
		struct jabber_error *err;
		if( ( c = xt_find_node( node->children, "error" ) ) )
		{
		        err = jabber_error_parse( c, XMLNS_STANZA_ERROR );
		        imcb_error( ic, "Stanza (%s) error: %s%s%s", node->name,
		                    err->code, err->text ? ": " : "",
		                    err->text ? err->text : "" );
		        jabber_error_free( err );
		} */
	}

	if (send_presence) {
		int is_away = 0;

		if (send_presence->away_state &&
		    strcmp(send_presence->away_state->code, "chat") != 0) {
			is_away = OPT_AWAY;
		}

		imcb_buddy_status(ic, send_presence->bare_jid, OPT_LOGGED_IN | is_away,
		                  is_away ? send_presence->away_state->full_name : NULL,
		                  send_presence->away_message);
	}

	return XT_HANDLED;
}

/* Whenever presence information is updated, call this function to inform the
   server. */
int presence_send_update(struct im_connection *ic)
{
	struct jabber_data *jd = ic->proto_data;
	struct xt_node *node, *cap;
	GSList *l;
	int st;

	node = jabber_make_packet("presence", NULL, NULL, NULL);
	xt_add_child(node, xt_new_node("priority", set_getstr(&ic->acc->set, "priority"), NULL));
	if (jd->away_state) {
		xt_add_child(node, xt_new_node("show", jd->away_state->code, NULL));
	}
	if (jd->away_message) {
		xt_add_child(node, xt_new_node("status", jd->away_message, NULL));
	}

	/* This makes the packet slightly bigger, but clients interested in
	   capabilities can now cache the discovery info. This reduces the
	   usual post-login iq-flood. See XEP-0115. At least libpurple and
	   Trillian seem to do this right. */
	cap = xt_new_node("c", NULL, NULL);
	xt_add_attr(cap, "xmlns", XMLNS_CAPS);
	xt_add_attr(cap, "node", "http://bitlbee.org/xmpp/caps");
	xt_add_attr(cap, "ver", BITLBEE_VERSION);   /* The XEP wants this hashed, but nobody's doing that. */
	xt_add_child(node, cap);

	st = jabber_write_packet(ic, node);

	/* Have to send this update to all groupchats too, the server won't
	   do this automatically. */
	for (l = ic->groupchats; l && st; l = l->next) {
		struct groupchat *c = l->data;
		struct jabber_chat *jc = c->data;

		xt_add_attr(node, "to", jc->my_full_jid);
		st = jabber_write_packet(ic, node);
	}

	xt_free_node(node);
	return st;
}

/* Send a subscribe/unsubscribe request to a buddy. */
int presence_send_request(struct im_connection *ic, char *handle, char *request)
{
	struct xt_node *node;
	int st;

	node = jabber_make_packet("presence", NULL, NULL, NULL);
	xt_add_attr(node, "to", handle);
	xt_add_attr(node, "type", request);

	st = jabber_write_packet(ic, node);

	xt_free_node(node);
	return st;
}
span> ) { struct im_connection *ic = imcb_new( acc ); struct byahoo_data *yd = ic->proto_data = g_new0( struct byahoo_data, 1 ); char *s; yd->logged_in = FALSE; yd->current_status = YAHOO_STATUS_AVAILABLE; if( ( s = strchr( acc->user, '@' ) ) && g_strcasecmp( s, "@yahoo.com" ) == 0 ) imcb_error( ic, "Your Yahoo! username should just be a username. " "Do not include any @domain part." ); imcb_log( ic, "Connecting" ); yd->y2_id = yahoo_init( acc->user, acc->pass ); yahoo_login( yd->y2_id, yd->current_status ); } static void byahoo_logout( struct im_connection *ic ) { struct byahoo_data *yd = (struct byahoo_data *) ic->proto_data; GSList *l; while( ic->groupchats ) imcb_chat_free( ic->groupchats->data ); for( l = yd->buddygroups; l; l = l->next ) { struct byahoo_buddygroups *bg = l->data; g_free( bg->buddy ); g_free( bg->group ); g_free( bg ); } g_slist_free( yd->buddygroups ); yahoo_logoff( 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; if( state && msg == NULL ) { /* Use these states only if msg doesn't contain additional info since away messages are only supported with CUSTOM. */ 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 yd->current_status = YAHOO_STATUS_CUSTOM; } else if( msg ) yd->current_status = YAHOO_STATUS_CUSTOM; else yd->current_status = YAHOO_STATUS_AVAILABLE; yahoo_set_away( yd->y2_id, yd->current_status, msg, state ? 2 : 0 ); } static GList *byahoo_away_states( struct im_connection *ic ) { static GList *m = NULL; if( m == NULL ) { 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" ); } 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; } static void byahoo_auth_allow( struct im_connection *ic, const char *who ) { struct byahoo_data *yd = (struct byahoo_data *) ic->proto_data; yahoo_accept_buddy_ymsg13( yd->y2_id, NULL, who ); } static void byahoo_auth_deny( struct im_connection *ic, const char *who ) { struct byahoo_data *yd = (struct byahoo_data *) ic->proto_data; yahoo_reject_buddy_ymsg13( yd->y2_id, NULL, who, NULL ); } 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; ret->auth_allow = byahoo_auth_allow; ret->auth_deny = byahoo_auth_deny; 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; return yahoo_write_ready( d->id, d->fd, d->data ); } 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 ); if( stat == YAHOO_STATUS_IDLE ) imcb_buddy_times( ic, who, 0, idle ); } 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 ); } /* 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, B_EV_IO_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, B_EV_IO_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( void *data ) { struct byahoo_conf_invitation *inv = data; struct groupchat *b; GSList *l; for( l = inv->ic->groupchats; l; l = l->next ) { b = l->data; if( b == inv->c ) break; } if( b != NULL ) { yahoo_conference_logon( inv->yid, NULL, inv->members, inv->name ); imcb_chat_add_buddy( inv->c, inv->ic->acc->user ); } else { imcb_log( inv->ic, "Duplicate/corrupted invitation to `%s'.", inv->name ); } g_free( inv->name ); g_free( inv ); } static void byahoo_reject_conf( void *data ) { struct byahoo_conf_invitation *inv = data; 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; if( g_strcasecmp( who, ic->acc->user ) == 0 ) /* WTF, Yahoo! seems to echo these now? */ return; 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 = bee_chat_by_title( ic->bee, ic, room ); 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 = bee_chat_by_title( ic->bee, ic, room ); 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 = bee_chat_by_title( ic->bee, ic, room ); 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_auth_request( int id, const char *myid, const char *who, const char *msg ) { struct im_connection *ic = byahoo_get_ic_by_id( id ); imcb_ask_auth( ic, who, NULL ); } void ext_yahoo_contact_added( int id, const char *myid, const char *who, const char *msg ) { struct im_connection *ic = byahoo_get_ic_by_id( id ); imcb_add_buddy( ic, (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){}