4 * Some code copyright (C) 1998-1999, Mark Spencer <markster@marko.net>
5 * Some code copyright (C) 1999-2001, Eric Warmenhoven
6 * Some code copyright (C) 2001-2003, Sean Egan
7 * Some code copyright (C) 2001-2007, Mark Doliner <thekingant@users.sourceforge.net>
8 * Some code copyright (C) 2005, Jonathan Clark <ardentlygnarly@users.sourceforge.net>
9 * Some code copyright (C) 2007, ComBOTS Product GmbH (htfv) <foss@combots.com>
10 * Some code copyright (C) 2008, Aman Gupta
12 * Most libfaim code copyright (C) 1998-2001 Adam Fritzler <afritz@auk.cx>
13 * Some libfaim code copyright (C) 2001-2004 Mark Doliner <thekingant@users.sourceforge.net>
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
34 #include "accountopt.h"
35 #include "buddyicon.h"
36 #include "conversation.h"
40 #include "image-store.h"
48 #include "visibility.h"
52 #include "oscarcommon.h"
56 static PurpleProtocol
*aim_protocol
= NULL
;
57 static PurpleProtocol
*icq_protocol
= NULL
;
59 static guint64 purple_caps
=
61 | OSCAR_CAPABILITY_BUDDYICON
62 | OSCAR_CAPABILITY_DIRECTIM
63 | OSCAR_CAPABILITY_SENDFILE
64 | OSCAR_CAPABILITY_UNICODE
65 | OSCAR_CAPABILITY_INTEROPERATE
66 | OSCAR_CAPABILITY_SHORTCAPS
67 | OSCAR_CAPABILITY_TYPING
68 | OSCAR_CAPABILITY_ICQSERVERRELAY
69 | OSCAR_CAPABILITY_NEWCAPS
70 | OSCAR_CAPABILITY_XTRAZ
71 | OSCAR_CAPABILITY_HTML_MSGS
;
73 static guint8 features_aim
[] = {0x01, 0x01, 0x01, 0x02};
74 static guint8 features_icq
[] = {0x01};
81 struct oscar_ask_directim_data
87 /* All the libfaim->purple callback functions */
89 /* Only used when connecting with the old-style BUCP login */
90 static int purple_parse_auth_resp (OscarData
*, FlapConnection
*, FlapFrame
*, ...);
91 static int purple_parse_auth_securid_request(OscarData
*, FlapConnection
*, FlapFrame
*, ...);
93 static int purple_handle_redirect (OscarData
*, FlapConnection
*, FlapFrame
*, ...);
94 static int purple_info_change (OscarData
*, FlapConnection
*, FlapFrame
*, ...);
95 static int purple_account_confirm (OscarData
*, FlapConnection
*, FlapFrame
*, ...);
96 static int purple_parse_oncoming (OscarData
*, FlapConnection
*, FlapFrame
*, ...);
97 static int purple_parse_offgoing (OscarData
*, FlapConnection
*, FlapFrame
*, ...);
98 static int purple_parse_incoming_im(OscarData
*, FlapConnection
*, FlapFrame
*, ...);
99 static int purple_parse_misses (OscarData
*, FlapConnection
*, FlapFrame
*, ...);
100 static int purple_parse_clientauto (OscarData
*, FlapConnection
*, FlapFrame
*, ...);
101 static int purple_parse_motd (OscarData
*, FlapConnection
*, FlapFrame
*, ...);
102 static int purple_chatnav_info (OscarData
*, FlapConnection
*, FlapFrame
*, ...);
103 static int purple_chat_conversation_join (OscarData
*, FlapConnection
*, FlapFrame
*, ...);
104 static int purple_chat_conversation_left (OscarData
*, FlapConnection
*, FlapFrame
*, ...);
105 static int purple_chat_conversation_info_update (OscarData
*, FlapConnection
*, FlapFrame
*, ...);
106 static int purple_chat_conversation_incoming_msg(OscarData
*, FlapConnection
*, FlapFrame
*, ...);
107 static int purple_email_parseupdate(OscarData
*, FlapConnection
*, FlapFrame
*, ...);
108 static int purple_icon_parseicon (OscarData
*, FlapConnection
*, FlapFrame
*, ...);
109 static int purple_parse_searcherror(OscarData
*, FlapConnection
*, FlapFrame
*, ...);
110 static int purple_parse_searchreply(OscarData
*, FlapConnection
*, FlapFrame
*, ...);
111 static int purple_bosrights (OscarData
*, FlapConnection
*, FlapFrame
*, ...);
112 static int purple_connerr (OscarData
*, FlapConnection
*, FlapFrame
*, ...);
113 static int purple_parse_mtn (OscarData
*, FlapConnection
*, FlapFrame
*, ...);
114 static int purple_parse_locaterights(OscarData
*, FlapConnection
*, FlapFrame
*, ...);
115 static int purple_parse_buddyrights(OscarData
*, FlapConnection
*, FlapFrame
*, ...);
116 static int purple_parse_genericerr (OscarData
*, FlapConnection
*, FlapFrame
*, ...);
117 static int purple_selfinfo (OscarData
*, FlapConnection
*, FlapFrame
*, ...);
118 static int purple_popup (OscarData
*, FlapConnection
*, FlapFrame
*, ...);
119 static int purple_ssi_parseerr (OscarData
*, FlapConnection
*, FlapFrame
*, ...);
120 static int purple_ssi_parserights (OscarData
*, FlapConnection
*, FlapFrame
*, ...);
121 static int purple_ssi_parselist (OscarData
*, FlapConnection
*, FlapFrame
*, ...);
122 static int purple_ssi_parseack (OscarData
*, FlapConnection
*, FlapFrame
*, ...);
123 static int purple_ssi_parseaddmod (OscarData
*, FlapConnection
*, FlapFrame
*, ...);
124 static int purple_ssi_authgiven (OscarData
*, FlapConnection
*, FlapFrame
*, ...);
125 static int purple_ssi_authrequest (OscarData
*, FlapConnection
*, FlapFrame
*, ...);
126 static int purple_ssi_authreply (OscarData
*, FlapConnection
*, FlapFrame
*, ...);
127 static int purple_ssi_gotadded (OscarData
*, FlapConnection
*, FlapFrame
*, ...);
129 static void purple_icons_fetch(PurpleConnection
*gc
);
131 void oscar_set_info(PurpleConnection
*gc
, const char *info
);
132 static void oscar_set_info_and_status(PurpleAccount
*account
, gboolean setinfo
, const char *rawinfo
, gboolean setstatus
, PurpleStatus
*status
);
133 static void oscar_set_extended_status(PurpleConnection
*gc
);
134 static gboolean
purple_ssi_rerequestdata(gpointer data
);
136 void oscar_free_name_data(struct name_data
*data
) {
143 const char *oscar_get_locale_charset(void) {
144 static const char *charset
= NULL
;
146 g_get_charset(&charset
);
151 static char *oscar_icqstatus(int state
) {
152 /* Make a cute little string that shows the status of the dude or dudet */
153 if (state
& AIM_ICQ_STATE_CHAT
)
154 return g_strdup(_("Free For Chat"));
155 else if (state
& AIM_ICQ_STATE_DND
)
156 return g_strdup(_("Do Not Disturb"));
157 else if (state
& AIM_ICQ_STATE_OUT
)
158 return g_strdup(_("Not Available"));
159 else if (state
& AIM_ICQ_STATE_BUSY
)
160 return g_strdup(_("Occupied"));
161 else if (state
& AIM_ICQ_STATE_AWAY
)
162 return g_strdup(_("Away"));
163 else if (state
& AIM_ICQ_STATE_WEBAWARE
)
164 return g_strdup(_("Web Aware"));
165 else if (state
& AIM_ICQ_STATE_INVISIBLE
)
166 return g_strdup(_("Invisible"));
167 else if (state
& AIM_ICQ_STATE_EVIL
)
168 return g_strdup(_("Evil"));
169 else if (state
& AIM_ICQ_STATE_DEPRESSION
)
170 return g_strdup(_("Depression"));
171 else if (state
& AIM_ICQ_STATE_ATHOME
)
172 return g_strdup(_("At home"));
173 else if (state
& AIM_ICQ_STATE_ATWORK
)
174 return g_strdup(_("At work"));
175 else if (state
& AIM_ICQ_STATE_LUNCH
)
176 return g_strdup(_("At lunch"));
178 return g_strdup(_("Online"));
181 static char *extract_name(const char *name
) {
188 x
= strchr(name
, '-');
192 x
= strchr(x
+ 1, '-');
198 for (i
= 0, j
= 0; x
[i
]; i
++) {
204 strncpy(hex
, x
+ ++i
, 2);
207 tmp
[j
++] = strtol(hex
, NULL
, 16);
214 static struct chat_connection
*
215 find_oscar_chat(PurpleConnection
*gc
, int id
)
217 OscarData
*od
= purple_connection_get_protocol_data(gc
);
219 struct chat_connection
*cc
;
221 for (cur
= od
->oscar_chats
; cur
!= NULL
; cur
= cur
->next
)
223 cc
= (struct chat_connection
*)cur
->data
;
231 static struct chat_connection
*
232 find_oscar_chat_by_conn(PurpleConnection
*gc
, FlapConnection
*conn
)
234 OscarData
*od
= purple_connection_get_protocol_data(gc
);
236 struct chat_connection
*cc
;
238 for (cur
= od
->oscar_chats
; cur
!= NULL
; cur
= cur
->next
)
240 cc
= (struct chat_connection
*)cur
->data
;
241 if (cc
->conn
== conn
)
248 static struct chat_connection
*
249 find_oscar_chat_by_conv(PurpleConnection
*gc
, PurpleChatConversation
*conv
)
251 OscarData
*od
= purple_connection_get_protocol_data(gc
);
253 struct chat_connection
*cc
;
255 for (cur
= od
->oscar_chats
; cur
!= NULL
; cur
= cur
->next
)
257 cc
= (struct chat_connection
*)cur
->data
;
258 if (cc
->conv
== conv
)
266 oscar_chat_destroy(struct chat_connection
*cc
)
274 oscar_chat_kill(PurpleConnection
*gc
, struct chat_connection
*cc
)
276 OscarData
*od
= purple_connection_get_protocol_data(gc
);
278 /* Notify the conversation window that we've left the chat */
279 purple_serv_got_chat_left(gc
, purple_chat_conversation_get_id(cc
->conv
));
281 /* Destroy the chat_connection */
282 od
->oscar_chats
= g_slist_remove(od
->oscar_chats
, cc
);
283 oscar_chat_destroy(cc
);
287 * This is called from the callback functions for establishing
288 * a TCP connection with an oscar host if an error occurred.
291 connection_common_error_cb(FlapConnection
*conn
, const gchar
*error_message
)
294 PurpleConnection
*gc
;
299 purple_debug_error("oscar", "unable to connect to FLAP "
300 "server of type 0x%04hx\n", conn
->type
);
302 if (conn
->type
== SNAC_FAMILY_AUTH
)
304 /* This only happens when connecting with the old-style BUCP login */
306 msg
= g_strdup_printf(_("Unable to connect to authentication server: %s"),
308 purple_connection_error(gc
, PURPLE_CONNECTION_ERROR_NETWORK_ERROR
, msg
);
311 else if (conn
->type
== SNAC_FAMILY_LOCATE
)
314 msg
= g_strdup_printf(_("Unable to connect to BOS server: %s"),
316 purple_connection_error(gc
, PURPLE_CONNECTION_ERROR_NETWORK_ERROR
, msg
);
321 /* Maybe we should call this for BOS connections, too? */
322 flap_connection_schedule_destroy(conn
,
323 OSCAR_DISCONNECT_COULD_NOT_CONNECT
, error_message
);
328 * This is called from the callback functions for establishing
329 * a TCP connection with an oscar host. Depending on the type
330 * of host, we do a few different things here.
333 connection_common_established_cb(FlapConnection
*conn
)
336 PurpleConnection
*gc
;
337 PurpleAccount
*account
;
341 account
= purple_connection_get_account(gc
);
343 purple_debug_info("oscar", "connected to FLAP server of type 0x%04hx\n",
346 if (conn
->cookie
== NULL
)
347 flap_connection_send_version(od
, conn
);
350 const gchar
*login_type
= purple_account_get_string(account
, "login_type", OSCAR_DEFAULT_LOGIN
);
352 if (!purple_strequal(login_type
, OSCAR_MD5_LOGIN
))
354 ClientInfo aiminfo
= CLIENTINFO_PURPLE_AIM
;
355 ClientInfo icqinfo
= CLIENTINFO_PURPLE_ICQ
;
356 flap_connection_send_version_with_cookie_and_clientinfo(od
,
357 conn
, conn
->cookielen
, conn
->cookie
,
358 od
->icq
? &icqinfo
: &aiminfo
,
359 purple_account_get_bool(account
, "allow_multiple_logins", OSCAR_DEFAULT_ALLOW_MULTIPLE_LOGINS
));
361 flap_connection_send_version_with_cookie(od
, conn
,
362 conn
->cookielen
, conn
->cookie
);
366 g_free(conn
->cookie
);
370 if (conn
->type
== SNAC_FAMILY_AUTH
)
372 /* This only happens when connecting with the old-style BUCP login */
373 aim_request_login(od
, conn
, purple_account_get_username(account
));
374 purple_debug_info("oscar", "Username sent, waiting for response\n");
375 purple_connection_update_progress(gc
, _("Username sent"), 1, OSCAR_CONNECT_STEPS
);
377 else if (conn
->type
== SNAC_FAMILY_LOCATE
)
379 purple_connection_update_progress(gc
, _("Connection established, cookie sent"), 4, OSCAR_CONNECT_STEPS
);
381 else if (conn
->type
== SNAC_FAMILY_CHAT
)
383 od
->oscar_chats
= g_slist_prepend(od
->oscar_chats
, conn
->new_conn_data
);
384 conn
->new_conn_data
= NULL
;
389 connection_established_cb(gpointer data
, gint source
, const gchar
*error_message
)
391 FlapConnection
*conn
;
395 conn
->connect_data
= NULL
;
400 connection_common_error_cb(conn
, error_message
);
404 conn
->watcher_incoming
= purple_input_add(conn
->fd
,
405 PURPLE_INPUT_READ
, flap_connection_recv_cb
, conn
);
406 connection_common_established_cb(conn
);
410 ssl_connection_established_cb(gpointer data
, PurpleSslConnection
*gsc
,
411 PurpleInputCondition cond
)
413 FlapConnection
*conn
;
417 purple_ssl_input_add(gsc
, flap_connection_recv_cb_ssl
, conn
);
418 connection_common_established_cb(conn
);
422 ssl_connection_error_cb(PurpleSslConnection
*gsc
, PurpleSslErrorType error
,
425 FlapConnection
*conn
;
429 if (conn
->watcher_outgoing
)
431 purple_input_remove(conn
->watcher_outgoing
);
432 conn
->watcher_outgoing
= 0;
435 /* sslconn frees the connection on error */
438 connection_common_error_cb(conn
, purple_ssl_strerror(error
));
442 flap_connection_established_bos(OscarData
*od
, FlapConnection
*conn
)
444 PurpleConnection
*gc
= od
->gc
;
446 aim_srv_reqpersonalinfo(od
, conn
);
448 purple_debug_info("oscar", "ssi: requesting rights and list\n");
449 aim_ssi_reqrights(od
);
451 if (od
->getblisttimer
> 0)
452 g_source_remove(od
->getblisttimer
);
453 od
->getblisttimer
= g_timeout_add_seconds(30, purple_ssi_rerequestdata
, od
);
455 aim_locate_reqrights(od
);
456 aim_buddylist_reqrights(od
, conn
);
457 aim_im_reqparams(od
);
458 aim_bos_reqrights(od
, conn
); /* TODO: Don't call this with ssi */
460 purple_connection_update_progress(gc
, _("Finalizing connection"), 5, OSCAR_CONNECT_STEPS
);
464 flap_connection_established_admin(OscarData
*od
, FlapConnection
*conn
)
466 aim_srv_clientready(od
, conn
);
467 purple_debug_info("oscar", "connected to admin\n");
470 purple_debug_info("oscar", "changing password\n");
471 aim_admin_changepasswd(od
, conn
, od
->newp
, od
->oldp
);
479 purple_debug_info("oscar", "formatting username\n");
480 aim_admin_setnick(od
, conn
, od
->newformatting
);
481 g_free(od
->newformatting
);
482 od
->newformatting
= NULL
;
486 purple_debug_info("oscar", "confirming account\n");
487 aim_admin_reqconfirm(od
, conn
);
491 purple_debug_info("oscar", "requesting email address\n");
492 aim_admin_getinfo(od
, conn
, 0x0011);
493 od
->reqemail
= FALSE
;
496 purple_debug_info("oscar", "setting email address\n");
497 aim_admin_setemail(od
, conn
, od
->email
);
500 od
->setemail
= FALSE
;
505 flap_connection_established_chat(OscarData
*od
, FlapConnection
*conn
)
507 PurpleConnection
*gc
= od
->gc
;
508 struct chat_connection
*chatcon
;
511 aim_srv_clientready(od
, conn
);
513 chatcon
= find_oscar_chat_by_conn(gc
, conn
);
516 chatcon
->conv
= purple_serv_got_joined_chat(gc
, id
++, chatcon
->show
);
521 flap_connection_established_chatnav(OscarData
*od
, FlapConnection
*conn
)
523 aim_srv_clientready(od
, conn
);
524 aim_chatnav_reqrights(od
, conn
);
528 flap_connection_established_alert(OscarData
*od
, FlapConnection
*conn
)
530 aim_email_sendcookies(od
);
531 aim_email_activate(od
);
532 aim_srv_clientready(od
, conn
);
536 flap_connection_established_bart(OscarData
*od
, FlapConnection
*conn
)
538 PurpleConnection
*gc
= od
->gc
;
540 aim_srv_clientready(od
, conn
);
542 od
->iconconnecting
= FALSE
;
544 purple_icons_fetch(gc
);
548 flap_connection_established(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...)
550 conn
->connected
= TRUE
;
551 purple_debug_info("oscar", "FLAP connection of type 0x%04hx is "
552 "now fully connected\n", conn
->type
);
553 if (conn
->type
== SNAC_FAMILY_LOCATE
)
554 flap_connection_established_bos(od
, conn
);
555 else if (conn
->type
== SNAC_FAMILY_ADMIN
)
556 flap_connection_established_admin(od
, conn
);
557 else if (conn
->type
== SNAC_FAMILY_CHAT
)
558 flap_connection_established_chat(od
, conn
);
559 else if (conn
->type
== SNAC_FAMILY_CHATNAV
)
560 flap_connection_established_chatnav(od
, conn
);
561 else if (conn
->type
== SNAC_FAMILY_ALERT
)
562 flap_connection_established_alert(od
, conn
);
563 else if (conn
->type
== SNAC_FAMILY_BART
)
564 flap_connection_established_bart(od
, conn
);
570 idle_reporting_pref_cb(const char *name
, PurplePrefType type
,
571 gconstpointer value
, gpointer data
)
573 PurpleConnection
*gc
;
575 gboolean report_idle
;
579 od
= purple_connection_get_protocol_data(gc
);
580 report_idle
= !purple_strequal((const char *)value
, "none");
581 presence
= aim_ssi_getpresence(&od
->ssi
.local
);
584 aim_ssi_setpresence(od
, presence
| AIM_SSI_PRESENCE_FLAG_SHOWIDLE
);
586 aim_ssi_setpresence(od
, presence
& ~AIM_SSI_PRESENCE_FLAG_SHOWIDLE
);
590 * Should probably make a "Use recent buddies group" account preference
591 * so that this option is surfaced to the user.
594 recent_buddies_pref_cb(const char *name
, PurplePrefType type
,
595 gconstpointer value
, gpointer data
)
597 PurpleConnection
*gc
;
602 od
= purple_connection_get_protocol_data(gc
);
603 presence
= aim_ssi_getpresence(&od
->ssi
.local
);
606 aim_ssi_setpresence(od
, presence
& ~AIM_SSI_PRESENCE_FLAG_NORECENTBUDDIES
);
608 aim_ssi_setpresence(od
, presence
| AIM_SSI_PRESENCE_FLAG_NORECENTBUDDIES
);
611 static const gchar
*login_servers
[] = {
612 AIM_DEFAULT_LOGIN_SERVER
,
613 AIM_DEFAULT_SSL_LOGIN_SERVER
,
614 ICQ_DEFAULT_LOGIN_SERVER
,
615 ICQ_DEFAULT_SSL_LOGIN_SERVER
,
619 oscar_get_login_server(gboolean is_icq
, gboolean use_ssl
)
621 return login_servers
[(is_icq
? 2 : 0) + (use_ssl
? 1 : 0)];
625 compare_handlers(gconstpointer a
, gconstpointer b
)
627 guint aa
= GPOINTER_TO_UINT(a
);
628 guint bb
= GPOINTER_TO_UINT(b
);
629 guint family1
= aa
>> 16;
630 guint family2
= bb
>> 16;
631 guint subtype1
= aa
& 0xFFFF;
632 guint subtype2
= bb
& 0xFFFF;
633 if (family1
!= family2
) {
634 return family1
- family2
;
636 return subtype1
- subtype2
;
640 oscar_login(PurpleAccount
*account
)
642 PurpleConnection
*gc
;
644 const gchar
*encryption_type
;
645 const gchar
*login_type
;
647 GList
*sorted_handlers
;
649 GString
*msg
= g_string_new("");
650 PurpleConnectionFlags flags
;
652 gc
= purple_account_get_connection(account
);
653 od
= oscar_data_new();
655 purple_connection_set_protocol_data(gc
, od
);
657 oscar_data_addhandler(od
, AIM_CB_FAM_SPECIAL
, AIM_CB_SPECIAL_CONNERR
, purple_connerr
, 0);
658 oscar_data_addhandler(od
, AIM_CB_FAM_SPECIAL
, AIM_CB_SPECIAL_CONNINITDONE
, flap_connection_established
, 0);
660 oscar_data_addhandler(od
, SNAC_FAMILY_ADMIN
, 0x0003, purple_info_change
, 0);
661 oscar_data_addhandler(od
, SNAC_FAMILY_ADMIN
, 0x0005, purple_info_change
, 0);
662 oscar_data_addhandler(od
, SNAC_FAMILY_ADMIN
, 0x0007, purple_account_confirm
, 0);
663 oscar_data_addhandler(od
, SNAC_FAMILY_ALERT
, 0x0001, purple_parse_genericerr
, 0);
664 oscar_data_addhandler(od
, SNAC_FAMILY_ALERT
, SNAC_SUBTYPE_ALERT_MAILSTATUS
, purple_email_parseupdate
, 0);
666 /* These are only needed when connecting with the old-style BUCP login */
667 oscar_data_addhandler(od
, SNAC_FAMILY_AUTH
, 0x0003, purple_parse_auth_resp
, 0);
668 oscar_data_addhandler(od
, SNAC_FAMILY_AUTH
, SNAC_SUBTYPE_AUTH_SECURID_REQUEST
, purple_parse_auth_securid_request
, 0);
670 oscar_data_addhandler(od
, SNAC_FAMILY_BART
, SNAC_SUBTYPE_BART_RESPONSE
, purple_icon_parseicon
, 0);
671 oscar_data_addhandler(od
, SNAC_FAMILY_BOS
, 0x0001, purple_parse_genericerr
, 0);
672 oscar_data_addhandler(od
, SNAC_FAMILY_BOS
, 0x0003, purple_bosrights
, 0);
673 oscar_data_addhandler(od
, SNAC_FAMILY_BUDDY
, 0x0001, purple_parse_genericerr
, 0);
674 oscar_data_addhandler(od
, SNAC_FAMILY_BUDDY
, SNAC_SUBTYPE_BUDDY_RIGHTSINFO
, purple_parse_buddyrights
, 0);
675 oscar_data_addhandler(od
, SNAC_FAMILY_BUDDY
, SNAC_SUBTYPE_BUDDY_ONCOMING
, purple_parse_oncoming
, 0);
676 oscar_data_addhandler(od
, SNAC_FAMILY_BUDDY
, SNAC_SUBTYPE_BUDDY_OFFGOING
, purple_parse_offgoing
, 0);
677 oscar_data_addhandler(od
, SNAC_FAMILY_CHAT
, 0x0001, purple_parse_genericerr
, 0);
678 oscar_data_addhandler(od
, SNAC_FAMILY_CHAT
, SNAC_SUBTYPE_CHAT_USERJOIN
, purple_chat_conversation_join
, 0);
679 oscar_data_addhandler(od
, SNAC_FAMILY_CHAT
, SNAC_SUBTYPE_CHAT_USERLEAVE
, purple_chat_conversation_left
, 0);
680 oscar_data_addhandler(od
, SNAC_FAMILY_CHAT
, SNAC_SUBTYPE_CHAT_ROOMINFOUPDATE
, purple_chat_conversation_info_update
, 0);
681 oscar_data_addhandler(od
, SNAC_FAMILY_CHAT
, SNAC_SUBTYPE_CHAT_INCOMINGMSG
, purple_chat_conversation_incoming_msg
, 0);
682 oscar_data_addhandler(od
, SNAC_FAMILY_CHATNAV
, 0x0001, purple_parse_genericerr
, 0);
683 oscar_data_addhandler(od
, SNAC_FAMILY_CHATNAV
, SNAC_SUBTYPE_CHATNAV_INFO
, purple_chatnav_info
, 0);
684 oscar_data_addhandler(od
, SNAC_FAMILY_FEEDBAG
, SNAC_SUBTYPE_FEEDBAG_ERROR
, purple_ssi_parseerr
, 0);
685 oscar_data_addhandler(od
, SNAC_FAMILY_FEEDBAG
, SNAC_SUBTYPE_FEEDBAG_RIGHTSINFO
, purple_ssi_parserights
, 0);
686 oscar_data_addhandler(od
, SNAC_FAMILY_FEEDBAG
, SNAC_SUBTYPE_FEEDBAG_LIST
, purple_ssi_parselist
, 0);
687 oscar_data_addhandler(od
, SNAC_FAMILY_FEEDBAG
, SNAC_SUBTYPE_FEEDBAG_SRVACK
, purple_ssi_parseack
, 0);
688 oscar_data_addhandler(od
, SNAC_FAMILY_FEEDBAG
, SNAC_SUBTYPE_FEEDBAG_ADD
, purple_ssi_parseaddmod
, 0);
689 oscar_data_addhandler(od
, SNAC_FAMILY_FEEDBAG
, SNAC_SUBTYPE_FEEDBAG_MOD
, purple_ssi_parseaddmod
, 0);
690 oscar_data_addhandler(od
, SNAC_FAMILY_FEEDBAG
, SNAC_SUBTYPE_FEEDBAG_RECVAUTH
, purple_ssi_authgiven
, 0);
691 oscar_data_addhandler(od
, SNAC_FAMILY_FEEDBAG
, SNAC_SUBTYPE_FEEDBAG_RECVAUTHREQ
, purple_ssi_authrequest
, 0);
692 oscar_data_addhandler(od
, SNAC_FAMILY_FEEDBAG
, SNAC_SUBTYPE_FEEDBAG_RECVAUTHREP
, purple_ssi_authreply
, 0);
693 oscar_data_addhandler(od
, SNAC_FAMILY_FEEDBAG
, SNAC_SUBTYPE_FEEDBAG_ADDED
, purple_ssi_gotadded
, 0);
694 oscar_data_addhandler(od
, SNAC_FAMILY_ICBM
, SNAC_SUBTYPE_ICBM_INCOMING
, purple_parse_incoming_im
, 0);
695 oscar_data_addhandler(od
, SNAC_FAMILY_ICBM
, SNAC_SUBTYPE_ICBM_MISSEDCALL
, purple_parse_misses
, 0);
696 oscar_data_addhandler(od
, SNAC_FAMILY_ICBM
, SNAC_SUBTYPE_ICBM_CLIENTAUTORESP
, purple_parse_clientauto
, 0);
697 oscar_data_addhandler(od
, SNAC_FAMILY_ICBM
, SNAC_SUBTYPE_ICBM_MTN
, purple_parse_mtn
, 0);
698 oscar_data_addhandler(od
, SNAC_FAMILY_LOCATE
, SNAC_SUBTYPE_LOCATE_RIGHTSINFO
, purple_parse_locaterights
, 0);
699 oscar_data_addhandler(od
, SNAC_FAMILY_OSERVICE
, 0x0001, purple_parse_genericerr
, 0);
700 oscar_data_addhandler(od
, SNAC_FAMILY_OSERVICE
, 0x000f, purple_selfinfo
, 0);
701 oscar_data_addhandler(od
, SNAC_FAMILY_OSERVICE
, SNAC_SUBTYPE_OSERVICE_REDIRECT
, purple_handle_redirect
, 0);
702 oscar_data_addhandler(od
, SNAC_FAMILY_OSERVICE
, SNAC_SUBTYPE_OSERVICE_MOTD
, purple_parse_motd
, 0);
703 oscar_data_addhandler(od
, SNAC_FAMILY_POPUP
, 0x0002, purple_popup
, 0);
704 oscar_data_addhandler(od
, SNAC_FAMILY_USERLOOKUP
, SNAC_SUBTYPE_USERLOOKUP_ERROR
, purple_parse_searcherror
, 0);
705 oscar_data_addhandler(od
, SNAC_FAMILY_USERLOOKUP
, 0x0003, purple_parse_searchreply
, 0);
707 g_string_append(msg
, "Registered handlers: ");
708 handlers
= g_hash_table_get_keys(od
->handlerlist
);
709 sorted_handlers
= g_list_sort(g_list_copy(handlers
), compare_handlers
);
710 for (cur
= sorted_handlers
; cur
; cur
= cur
->next
) {
711 guint x
= GPOINTER_TO_UINT(cur
->data
);
712 g_string_append_printf(msg
, "%04x/%04x, ", x
>> 16, x
& 0xFFFF);
714 g_list_free(sorted_handlers
);
715 g_list_free(handlers
);
716 purple_debug_misc("oscar", "%s\n", msg
->str
);
717 g_string_free(msg
, TRUE
);
719 purple_debug_misc("oscar", "oscar_login: gc = %p\n", gc
);
721 if (!oscar_util_valid_name(purple_account_get_username(account
))) {
723 buf
= g_strdup_printf(_("Unable to sign on as %s because the username is invalid. Usernames must be a valid email address, or start with a letter and contain only letters, numbers and spaces, or contain only numbers."), purple_account_get_username(account
));
724 purple_connection_error(gc
, PURPLE_CONNECTION_ERROR_INVALID_SETTINGS
, buf
);
729 flags
= PURPLE_CONNECTION_FLAG_HTML
;
730 if (purple_strequal(purple_account_get_protocol_id(account
), "prpl-icq")) {
733 flags
|= PURPLE_CONNECTION_FLAG_AUTO_RESP
;
736 /* Set this flag based on the protocol_id rather than the username,
737 because that is what's tied to the get_moods protocol callback. */
738 if (purple_strequal(purple_account_get_protocol_id(account
), "prpl-icq"))
739 flags
|= PURPLE_CONNECTION_FLAG_SUPPORT_MOODS
;
741 purple_connection_set_flags(gc
, flags
);
743 od
->default_port
= purple_account_get_int(account
, "port", OSCAR_DEFAULT_LOGIN_PORT
);
745 login_type
= purple_account_get_string(account
, "login_type", OSCAR_DEFAULT_LOGIN
);
746 encryption_type
= purple_account_get_string(account
, "encryption", OSCAR_DEFAULT_ENCRYPTION
);
747 od
->use_ssl
= purple_strequal(encryption_type
, OSCAR_NO_ENCRYPTION
) == FALSE
;
749 /* Connect to core Purple signals */
750 purple_prefs_connect_callback(purple_connection_get_protocol(gc
), "/purple/away/idle_reporting", idle_reporting_pref_cb
, gc
);
751 purple_prefs_connect_callback(purple_connection_get_protocol(gc
), "/plugins/prpl/oscar/recent_buddies", recent_buddies_pref_cb
, gc
);
754 * On 2008-03-05 AOL released some documentation on the OSCAR protocol
755 * which includes a new login method called clientLogin. It is similar
756 * (though not the same?) as what the AIM 6.0 series uses to
759 * AIM 5.9 and lower use an MD5-based login procedure called "BUCP".
760 * This authentication method is used for both ICQ and AIM when
761 * clientLogin is not enabled.
763 if (purple_strequal(login_type
, OSCAR_CLIENT_LOGIN
)) {
764 /* Note: Actual server/port configuration is ignored here */
765 send_client_login(od
, purple_account_get_username(account
));
766 } else if (purple_strequal(login_type
, OSCAR_KERBEROS_LOGIN
)) {
770 purple_connection_error(
772 PURPLE_CONNECTION_ERROR_NO_SSL_SUPPORT
,
773 _("You required Kerberos authentication but encryption is disabled in your account settings."));
776 server
= purple_account_get_string(account
, "server", AIM_DEFAULT_KDC_SERVER
);
778 * If the account's server is what the oscar protocol has offered as
779 * the default login server through the vast eons (all two of
780 * said default options, AFAIK) and the user wants KDC, we'll
781 * do what we know is best for them and change the setting out
782 * from under them to the KDC login server.
784 if (purple_strequal(server
, oscar_get_login_server(od
->icq
, FALSE
)) ||
785 purple_strequal(server
, oscar_get_login_server(od
->icq
, TRUE
)) ||
786 purple_strequal(server
, AIM_ALT_LOGIN_SERVER
) ||
787 purple_strequal(server
, "")) {
788 purple_debug_info("oscar", "Account uses Kerberos auth, so changing server to default KDC server\n");
789 purple_account_set_string(account
, "server", AIM_DEFAULT_KDC_SERVER
);
790 purple_account_set_int(account
, "port", AIM_DEFAULT_KDC_PORT
);
792 send_kerberos_login(od
, purple_account_get_username(account
));
794 FlapConnection
*newconn
;
797 newconn
= flap_connection_new(od
, SNAC_FAMILY_AUTH
);
800 server
= purple_account_get_string(account
, "server", oscar_get_login_server(od
->icq
, TRUE
));
803 * If the account's server is what the oscar protocol has offered as
804 * the default login server through the vast eons (all two of
805 * said default options, AFAIK) and the user wants SSL, we'll
806 * do what we know is best for them and change the setting out
807 * from under them to the SSL login server.
809 if (purple_strequal(server
, oscar_get_login_server(od
->icq
, FALSE
)) ||
810 purple_strequal(server
, AIM_ALT_LOGIN_SERVER
) ||
811 purple_strequal(server
, AIM_DEFAULT_KDC_SERVER
) ||
812 purple_strequal(server
, "")) {
813 purple_debug_info("oscar", "Account uses SSL, so changing server to default SSL server\n");
814 purple_account_set_string(account
, "server", oscar_get_login_server(od
->icq
, TRUE
));
815 purple_account_set_int(account
, "port", OSCAR_DEFAULT_LOGIN_PORT
),
816 server
= oscar_get_login_server(od
->icq
, TRUE
);
819 newconn
->gsc
= purple_ssl_connect(account
, server
,
820 purple_account_get_int(account
, "port", OSCAR_DEFAULT_LOGIN_PORT
),
821 ssl_connection_established_cb
, ssl_connection_error_cb
, newconn
);
823 server
= purple_account_get_string(account
, "server", oscar_get_login_server(od
->icq
, FALSE
));
826 * See the comment above. We do the reverse here. If they don't want
827 * SSL but their server is set to OSCAR_DEFAULT_SSL_LOGIN_SERVER,
828 * set it back to the default.
830 if (purple_strequal(server
, oscar_get_login_server(od
->icq
, TRUE
)) ||
831 purple_strequal(server
, AIM_DEFAULT_KDC_SERVER
) ||
832 purple_strequal(server
, "")) {
833 purple_debug_info("oscar", "Account does not use SSL, so changing server back to non-SSL\n");
834 purple_account_set_string(account
, "server", oscar_get_login_server(od
->icq
, FALSE
));
835 purple_account_set_int(account
, "port", OSCAR_DEFAULT_LOGIN_PORT
),
836 server
= oscar_get_login_server(od
->icq
, FALSE
);
839 newconn
->connect_data
= purple_proxy_connect(NULL
, account
, server
,
840 purple_account_get_int(account
, "port", OSCAR_DEFAULT_LOGIN_PORT
),
841 connection_established_cb
, newconn
);
844 if (newconn
->gsc
== NULL
&& newconn
->connect_data
== NULL
) {
845 purple_connection_error(gc
, PURPLE_CONNECTION_ERROR_NETWORK_ERROR
,
846 _("Unable to connect"));
851 purple_connection_update_progress(gc
, _("Connecting"), 0, OSCAR_CONNECT_STEPS
);
855 oscar_close(PurpleConnection
*gc
)
859 od
= purple_connection_get_protocol_data(gc
);
861 while (od
->oscar_chats
)
863 struct chat_connection
*cc
= od
->oscar_chats
->data
;
864 od
->oscar_chats
= g_slist_remove(od
->oscar_chats
, cc
);
865 oscar_chat_destroy(cc
);
867 while (od
->create_rooms
)
869 struct create_room
*cr
= od
->create_rooms
->data
;
871 od
->create_rooms
= g_slist_remove(od
->create_rooms
, cr
);
874 oscar_data_destroy(od
);
875 purple_connection_set_protocol_data(gc
, NULL
);
877 purple_prefs_disconnect_by_handle(gc
);
879 purple_debug_info("oscar", "Signed off.\n");
882 int oscar_connect_to_bos(PurpleConnection
*gc
, OscarData
*od
, const char *host
, guint16 port
, guint8
*cookie
, guint16 cookielen
, const char *tls_certname
)
884 PurpleAccount
*account
;
885 FlapConnection
*conn
;
887 account
= purple_connection_get_account(gc
);
889 conn
= flap_connection_new(od
, SNAC_FAMILY_LOCATE
);
890 conn
->cookielen
= cookielen
;
891 conn
->cookie
= g_memdup(cookie
, cookielen
);
894 * Use TLS only if the server provided us with a tls_certname. The server might not specify a tls_certname even if we requested to use TLS,
895 * and that is something we should be prepared to.
899 conn
->gsc
= purple_ssl_connect_with_ssl_cn(account
, host
, port
,
900 ssl_connection_established_cb
, ssl_connection_error_cb
,
905 conn
->connect_data
= purple_proxy_connect(NULL
,
907 connection_established_cb
, conn
);
910 if (conn
->gsc
== NULL
&& conn
->connect_data
== NULL
)
912 purple_connection_error(gc
, PURPLE_CONNECTION_ERROR_NETWORK_ERROR
, _("Unable to connect"));
916 od
->default_port
= port
;
918 purple_connection_update_progress(gc
, _("Received authorization"), 3, OSCAR_CONNECT_STEPS
);
924 * Only used when connecting with the old-style BUCP login.
927 purple_parse_auth_resp(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...)
929 PurpleConnection
*gc
= od
->gc
;
930 PurpleAccount
*account
= purple_connection_get_account(gc
);
931 char *host
; int port
;
933 FlapConnection
*newconn
;
935 struct aim_authresp_info
*info
;
937 port
= purple_account_get_int(account
, "port", od
->default_port
);
940 info
= va_arg(ap
, struct aim_authresp_info
*);
943 purple_debug_info("oscar",
944 "inside auth_resp (Username: %s)\n", info
->bn
);
946 if (info
->errorcode
|| !info
->bosip
|| !info
->cookielen
|| !info
->cookie
) {
948 switch (info
->errorcode
) {
950 /* Unregistered username */
951 purple_connection_error(gc
, PURPLE_CONNECTION_ERROR_INVALID_USERNAME
, _("Username does not exist"));
954 /* Incorrect password */
955 if (!purple_account_get_remember_password(account
))
956 purple_account_set_password(account
, NULL
, NULL
, NULL
);
957 purple_connection_error(gc
, PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED
, _("Incorrect password"));
960 /* Suspended account */
961 purple_connection_error(gc
, PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED
, _("Your account is currently suspended"));
965 /* service temporarily unavailable */
966 purple_connection_error(gc
, PURPLE_CONNECTION_ERROR_NETWORK_ERROR
, _("The AOL Instant Messenger service is temporarily unavailable."));
969 /* username connecting too frequently */
970 purple_connection_error(gc
, PURPLE_CONNECTION_ERROR_OTHER_ERROR
, _("Your username has been connecting and disconnecting too frequently. Wait ten minutes and try again. If you continue to try, you will need to wait even longer."));
975 g_snprintf(buf
, sizeof(buf
), _("The client version you are using is too old. Please upgrade at %s"),
976 oscar_get_ui_info_string("website", PURPLE_WEBSITE
));
977 purple_connection_error(gc
, PURPLE_CONNECTION_ERROR_OTHER_ERROR
, buf
);
981 /* IP address connecting too frequently */
982 purple_connection_error(gc
, PURPLE_CONNECTION_ERROR_OTHER_ERROR
, _("Your IP address has been connecting and disconnecting too frequently. Wait a minute and try again. If you continue to try, you will need to wait even longer."));
985 purple_connection_error(gc
, PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED
, _("Unknown reason"));
988 purple_debug_info("oscar", "Login Error Code 0x%04hx\n", info
->errorcode
);
989 purple_debug_info("oscar", "Error URL: %s\n", info
->errorurl
? info
->errorurl
: "");
993 purple_debug_misc("oscar", "Reg status: %hu\n"
997 info
->email
? info
->email
: "null",
998 info
->bosip
? info
->bosip
: "null");
999 purple_debug_info("oscar", "Closing auth connection...\n");
1000 flap_connection_schedule_destroy(conn
, OSCAR_DISCONNECT_DONE
, NULL
);
1002 for (i
= 0; i
< strlen(info
->bosip
); i
++) {
1003 if (info
->bosip
[i
] == ':') {
1004 port
= atoi(&(info
->bosip
[i
+1]));
1008 host
= g_strndup(info
->bosip
, i
);
1009 newconn
= flap_connection_new(od
, SNAC_FAMILY_LOCATE
);
1010 newconn
->cookielen
= info
->cookielen
;
1011 newconn
->cookie
= g_memdup(info
->cookie
, info
->cookielen
);
1016 * This shouldn't be hardcoded to "bos.oscar.aol.com" except that
1017 * the server isn't sending us a name to use for comparing the
1018 * certificate common name.
1020 newconn
->gsc
= purple_ssl_connect_with_ssl_cn(account
, host
, port
,
1021 ssl_connection_established_cb
, ssl_connection_error_cb
,
1022 "bos.oscar.aol.com", newconn
);
1026 newconn
->connect_data
= purple_proxy_connect(NULL
, account
, host
, port
,
1027 connection_established_cb
, newconn
);
1031 if (newconn
->gsc
== NULL
&& newconn
->connect_data
== NULL
)
1033 purple_connection_error(gc
, PURPLE_CONNECTION_ERROR_NETWORK_ERROR
, _("Unable to connect"));
1037 purple_connection_update_progress(gc
, _("Received authorization"), 3, OSCAR_CONNECT_STEPS
);
1043 * Only used when connecting with the old-style BUCP login.
1046 purple_parse_auth_securid_request_yes_cb(gpointer user_data
, const char *msg
)
1048 PurpleConnection
*gc
= user_data
;
1049 OscarData
*od
= purple_connection_get_protocol_data(gc
);
1051 aim_auth_securid_send(od
, msg
);
1055 * Only used when connecting with the old-style BUCP login.
1058 purple_parse_auth_securid_request_no_cb(gpointer user_data
, const char *value
)
1060 PurpleConnection
*gc
= user_data
;
1063 purple_connection_error(gc
,
1064 PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED
,
1065 _("The SecurID key entered is invalid"));
1069 * Only used when connecting with the old-style BUCP login.
1072 purple_parse_auth_securid_request(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...)
1074 PurpleConnection
*gc
= od
->gc
;
1075 PurpleAccount
*account
= purple_connection_get_account(gc
);
1078 purple_debug_info("oscar", "Got SecurID request\n");
1080 primary
= g_strdup_printf("Enter the SecurID key for %s.", purple_account_get_username(account
));
1081 purple_request_input(gc
, NULL
, _("Enter SecurID"), primary
,
1082 _("Enter the 6 digit number from the digital display."),
1084 _("_OK"), G_CALLBACK(purple_parse_auth_securid_request_yes_cb
),
1085 _("_Cancel"), G_CALLBACK(purple_parse_auth_securid_request_no_cb
),
1086 purple_request_cpar_from_connection(gc
),
1094 purple_handle_redirect(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...)
1096 PurpleConnection
*gc
= od
->gc
;
1097 PurpleAccount
*account
= purple_connection_get_account(gc
);
1098 char *host
, *separator
;
1100 FlapConnection
*newconn
;
1102 struct aim_redirect_data
*redir
;
1105 redir
= va_arg(ap
, struct aim_redirect_data
*);
1108 port
= od
->default_port
;
1109 separator
= strchr(redir
->ip
, ':');
1110 if (separator
!= NULL
)
1112 host
= g_strndup(redir
->ip
, separator
- redir
->ip
);
1113 port
= atoi(separator
+ 1);
1116 host
= g_strdup(redir
->ip
);
1118 if (!redir
->use_ssl
) {
1119 const gchar
*encryption_type
= purple_account_get_string(account
, "encryption", OSCAR_DEFAULT_ENCRYPTION
);
1120 if (purple_strequal(encryption_type
, OSCAR_OPPORTUNISTIC_ENCRYPTION
)) {
1121 purple_debug_warning("oscar", "We won't use SSL for FLAP type 0x%04hx.\n", redir
->group
);
1122 } else if (purple_strequal(encryption_type
, OSCAR_REQUIRE_ENCRYPTION
)) {
1123 purple_debug_error("oscar", "FLAP server %s:%d of type 0x%04hx doesn't support encryption.\n", host
, port
, redir
->group
);
1124 purple_connection_error(
1126 PURPLE_CONNECTION_ERROR_NO_SSL_SUPPORT
,
1127 _("You required encryption in your account settings, but one of the servers doesn't support it."));
1133 * These FLAP servers advertise SSL (type "0x02"), but SSL connections to these hosts
1134 * die a painful death. iChat and Miranda, when using SSL, still do these in plaintext.
1136 if (redir
->use_ssl
&& (redir
->group
== SNAC_FAMILY_ADMIN
||
1137 redir
->group
== SNAC_FAMILY_BART
))
1139 purple_debug_info("oscar", "Ignoring broken SSL for FLAP type 0x%04hx.\n", redir
->group
);
1143 purple_debug_info("oscar", "Connecting to FLAP server %s:%d of type 0x%04hx\n", host
, port
, redir
->group
);
1145 newconn
= flap_connection_new(od
, redir
->group
);
1146 newconn
->cookielen
= redir
->cookielen
;
1147 newconn
->cookie
= g_memdup(redir
->cookie
, redir
->cookielen
);
1148 if (newconn
->type
== SNAC_FAMILY_CHAT
)
1150 struct chat_connection
*cc
;
1151 cc
= g_new0(struct chat_connection
, 1);
1154 cc
->name
= g_strdup(redir
->chat
.room
);
1155 cc
->exchange
= redir
->chat
.exchange
;
1156 cc
->instance
= redir
->chat
.instance
;
1157 cc
->show
= extract_name(redir
->chat
.room
);
1158 newconn
->new_conn_data
= cc
;
1159 purple_debug_info("oscar", "Connecting to chat room %s exchange %hu\n", cc
->name
, cc
->exchange
);
1165 newconn
->gsc
= purple_ssl_connect_with_ssl_cn(account
, host
, port
,
1166 ssl_connection_established_cb
, ssl_connection_error_cb
,
1167 redir
->ssl_cert_cn
, newconn
);
1171 newconn
->connect_data
= purple_proxy_connect(NULL
, account
, host
, port
,
1172 connection_established_cb
, newconn
);
1175 if (newconn
->gsc
== NULL
&& newconn
->connect_data
== NULL
)
1177 flap_connection_schedule_destroy(newconn
,
1178 OSCAR_DISCONNECT_COULD_NOT_CONNECT
,
1179 _("Unable to initialize connection"));
1180 purple_debug_error("oscar", "Unable to connect to FLAP server "
1181 "of type 0x%04hx\n", redir
->group
);
1189 static int purple_parse_oncoming(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...)
1191 PurpleConnection
*gc
;
1192 PurpleAccount
*account
;
1193 PurpleBuddy
*buddy
= NULL
;
1194 PurpleStatus
*previous_status
= NULL
;
1195 struct buddyinfo
*bi
;
1196 time_t time_idle
= 0, signon
= 0;
1198 gboolean buddy_is_away
= FALSE
;
1199 const char *status_id
;
1201 aim_userinfo_t
*info
;
1203 char *itmsurl
= NULL
;
1206 account
= purple_connection_get_account(gc
);
1209 info
= va_arg(ap
, aim_userinfo_t
*);
1212 g_return_val_if_fail(info
!= NULL
, 1);
1213 g_return_val_if_fail(info
->bn
!= NULL
, 1);
1215 buddy
= purple_blist_find_buddy(account
, info
->bn
);
1217 previous_status
= purple_presence_get_active_status(purple_buddy_get_presence(buddy
));
1221 * If this is an AIM buddy and their name has formatting, set their
1224 if (!oscar_util_valid_name_icq(info
->bn
)) {
1225 gboolean bn_has_formatting
= FALSE
;
1227 for (c
= info
->bn
; *c
!= '\0'; c
++) {
1229 bn_has_formatting
= TRUE
;
1233 purple_serv_got_alias(gc
, info
->bn
,
1234 bn_has_formatting
? info
->bn
: NULL
);
1237 if (info
->present
& AIM_USERINFO_PRESENT_FLAGS
) {
1238 if (info
->flags
& AIM_FLAG_AWAY
)
1239 buddy_is_away
= TRUE
;
1241 if (info
->present
& AIM_USERINFO_PRESENT_ICQEXTSTATUS
) {
1242 type
= info
->icqinfo
.status
;
1243 if (!(info
->icqinfo
.status
& AIM_ICQ_STATE_CHAT
) &&
1244 (info
->icqinfo
.status
!= AIM_ICQ_STATE_NORMAL
)) {
1245 buddy_is_away
= TRUE
;
1249 if (oscar_util_valid_name_icq(info
->bn
)) {
1250 if (type
& AIM_ICQ_STATE_CHAT
)
1251 status_id
= OSCAR_STATUS_ID_FREE4CHAT
;
1252 else if (type
& AIM_ICQ_STATE_DND
)
1253 status_id
= OSCAR_STATUS_ID_DND
;
1254 else if (type
& AIM_ICQ_STATE_OUT
)
1255 status_id
= OSCAR_STATUS_ID_NA
;
1256 else if (type
& AIM_ICQ_STATE_BUSY
)
1257 status_id
= OSCAR_STATUS_ID_OCCUPIED
;
1258 else if (type
& AIM_ICQ_STATE_AWAY
)
1259 status_id
= OSCAR_STATUS_ID_AWAY
;
1260 else if (type
& AIM_ICQ_STATE_INVISIBLE
)
1261 status_id
= OSCAR_STATUS_ID_INVISIBLE
;
1262 else if (type
& AIM_ICQ_STATE_EVIL
)
1263 status_id
= OSCAR_STATUS_ID_EVIL
;
1264 else if (type
& AIM_ICQ_STATE_DEPRESSION
)
1265 status_id
= OSCAR_STATUS_ID_DEPRESSION
;
1266 else if (type
& AIM_ICQ_STATE_ATHOME
)
1267 status_id
= OSCAR_STATUS_ID_ATHOME
;
1268 else if (type
& AIM_ICQ_STATE_ATWORK
)
1269 status_id
= OSCAR_STATUS_ID_ATWORK
;
1270 else if (type
& AIM_ICQ_STATE_LUNCH
)
1271 status_id
= OSCAR_STATUS_ID_LUNCH
;
1273 status_id
= OSCAR_STATUS_ID_AVAILABLE
;
1275 if (type
& AIM_ICQ_STATE_INVISIBLE
)
1276 status_id
= OSCAR_STATUS_ID_INVISIBLE
;
1277 else if (buddy_is_away
)
1278 status_id
= OSCAR_STATUS_ID_AWAY
;
1280 status_id
= OSCAR_STATUS_ID_AVAILABLE
;
1283 if (info
->flags
& AIM_FLAG_WIRELESS
) {
1284 purple_protocol_got_user_status(account
, info
->bn
, OSCAR_STATUS_ID_MOBILE
, NULL
);
1286 purple_protocol_got_user_status_deactive(account
, info
->bn
, OSCAR_STATUS_ID_MOBILE
);
1289 message
= (info
->status
&& info
->status_len
> 0)
1290 ? oscar_encoding_to_utf8(info
->status_encoding
, info
->status
, info
->status_len
)
1293 if (purple_strequal(status_id
, OSCAR_STATUS_ID_AVAILABLE
)) {
1294 /* TODO: If itmsurl is NULL, does that mean the URL has been
1295 cleared? Or does it mean the URL should remain unchanged? */
1296 if (info
->itmsurl
!= NULL
) {
1297 itmsurl
= (info
->itmsurl_len
> 0) ? oscar_encoding_to_utf8(info
->itmsurl_encoding
, info
->itmsurl
, info
->itmsurl_len
) : NULL
;
1298 } else if (previous_status
!= NULL
&& purple_status_is_available(previous_status
)) {
1299 itmsurl
= g_strdup(purple_status_get_attr_string(previous_status
, "itmsurl"));
1301 purple_debug_info("oscar", "Activating status '%s' for buddy %s, message = '%s', itmsurl = '%s'\n", status_id
, info
->bn
, message
? message
: "(null)", itmsurl
? itmsurl
: "(null)");
1302 purple_protocol_got_user_status(account
, info
->bn
, status_id
, "message", message
, "itmsurl", itmsurl
, NULL
);
1304 purple_debug_info("oscar", "Activating status '%s' for buddy %s, message = '%s'\n", status_id
, info
->bn
, message
? message
: "(null)");
1305 purple_protocol_got_user_status(account
, info
->bn
, status_id
, "message", message
, NULL
);
1311 /* Login time stuff */
1312 if (info
->present
& AIM_USERINFO_PRESENT_ONLINESINCE
)
1313 signon
= info
->onlinesince
;
1314 else if (info
->present
& AIM_USERINFO_PRESENT_SESSIONLEN
)
1315 signon
= time(NULL
) - info
->sessionlen
;
1316 purple_protocol_got_user_login_time(account
, info
->bn
, signon
);
1318 /* Idle time stuff */
1319 /* info->idletime is the number of minutes that this user has been idle */
1320 if (info
->present
& AIM_USERINFO_PRESENT_IDLE
)
1321 time_idle
= time(NULL
) - info
->idletime
* 60;
1324 purple_protocol_got_user_idle(account
, info
->bn
, TRUE
, time_idle
);
1326 purple_protocol_got_user_idle(account
, info
->bn
, FALSE
, 0);
1328 /* Server stored icon stuff */
1329 bi
= g_hash_table_lookup(od
->buddyinfo
, purple_normalize(account
, info
->bn
));
1331 bi
= g_new0(struct buddyinfo
, 1);
1332 g_hash_table_insert(od
->buddyinfo
, g_strdup(purple_normalize(account
, info
->bn
)), bi
);
1334 bi
->typingnot
= FALSE
;
1335 bi
->ico_informed
= FALSE
;
1336 bi
->ipaddr
= info
->icqinfo
.ipaddr
;
1338 if (info
->iconcsumlen
) {
1339 const char *saved_b16
= NULL
;
1341 PurpleBuddy
*b
= NULL
;
1343 b16
= purple_base16_encode(info
->iconcsum
, info
->iconcsumlen
);
1344 b
= purple_blist_find_buddy(account
, info
->bn
);
1346 saved_b16
= purple_buddy_icons_get_checksum_for_user(b
);
1348 if (!b16
|| !saved_b16
|| !purple_strequal(b16
, saved_b16
)) {
1349 /* Invalidate the old icon for this user */
1350 purple_buddy_icons_set_for_user(account
, info
->bn
, NULL
, 0, NULL
);
1352 /* Fetch the new icon (if we're not already doing so) */
1353 if (g_slist_find_custom(od
->requesticon
, info
->bn
,
1354 (GCompareFunc
)oscar_util_name_compare
) == NULL
)
1356 od
->requesticon
= g_slist_prepend(od
->requesticon
,
1357 g_strdup(purple_normalize(account
, info
->bn
)));
1358 purple_icons_fetch(gc
);
1367 static int purple_parse_offgoing(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...) {
1368 PurpleConnection
*gc
= od
->gc
;
1369 PurpleAccount
*account
= purple_connection_get_account(gc
);
1371 aim_userinfo_t
*info
;
1374 info
= va_arg(ap
, aim_userinfo_t
*);
1377 purple_protocol_got_user_status(account
, info
->bn
, OSCAR_STATUS_ID_OFFLINE
, NULL
);
1378 purple_protocol_got_user_status_deactive(account
, info
->bn
, OSCAR_STATUS_ID_MOBILE
);
1379 g_hash_table_remove(od
->buddyinfo
, purple_normalize(purple_connection_get_account(gc
), info
->bn
));
1384 static int incomingim_chan1(OscarData
*od
, FlapConnection
*conn
, aim_userinfo_t
*userinfo
, struct aim_incomingim_ch1_args
*args
) {
1385 PurpleConnection
*gc
= od
->gc
;
1386 PurpleAccount
*account
= purple_connection_get_account(gc
);
1387 PurpleMessageFlags flags
= 0;
1388 struct buddyinfo
*bi
;
1391 const char *start
, *end
;
1394 purple_debug_misc("oscar", "Received IM from %s\n", userinfo
->bn
);
1396 bi
= g_hash_table_lookup(od
->buddyinfo
, purple_normalize(account
, userinfo
->bn
));
1398 bi
= g_new0(struct buddyinfo
, 1);
1399 g_hash_table_insert(od
->buddyinfo
, g_strdup(purple_normalize(account
, userinfo
->bn
)), bi
);
1402 if (args
->icbmflags
& AIM_IMFLAGS_AWAY
)
1403 flags
|= PURPLE_MESSAGE_AUTO_RESP
;
1405 if (args
->icbmflags
& AIM_IMFLAGS_TYPINGNOT
)
1406 bi
->typingnot
= TRUE
;
1408 bi
->typingnot
= FALSE
;
1410 if ((args
->icbmflags
& AIM_IMFLAGS_HASICON
) && (args
->iconlen
) && (args
->iconsum
) && (args
->iconstamp
)) {
1411 purple_debug_misc("oscar", "%s has an icon\n", userinfo
->bn
);
1412 if ((args
->iconlen
!= bi
->ico_len
) || (args
->iconsum
!= bi
->ico_csum
) || (args
->iconstamp
!= bi
->ico_time
)) {
1413 bi
->ico_need
= TRUE
;
1414 bi
->ico_len
= args
->iconlen
;
1415 bi
->ico_csum
= args
->iconsum
;
1416 bi
->ico_time
= args
->iconstamp
;
1420 img
= purple_buddy_icons_find_account_icon(account
);
1421 if ((img
!= NULL
) &&
1422 (args
->icbmflags
& AIM_IMFLAGS_BUDDYREQ
) && !bi
->ico_sent
&& bi
->ico_informed
) {
1423 gconstpointer data
= purple_image_get_data(img
);
1424 size_t len
= purple_image_get_data_size(img
);
1425 purple_debug_info("oscar",
1426 "Sending buddy icon to %s (%" G_GSIZE_FORMAT
" bytes)\n",
1428 aim_im_sendch2_icon(od
, userinfo
->bn
, data
, len
,
1429 purple_buddy_icons_get_account_icon_timestamp(account
),
1430 aimutil_iconsum(data
, len
));
1432 g_object_unref(img
);
1434 tmp
= g_strdup(args
->msg
);
1437 * Convert iChat color tags to normal font tags.
1439 if (purple_markup_find_tag("body", tmp
, &start
, &end
, &attribs
))
1443 const char *ichattextcolor
, *ichatballooncolor
;
1444 const char *slash_body_start
, *slash_body_end
= NULL
; /* </body> */
1448 * Find the ending </body> so we can strip off the outer <html/>
1451 if (purple_markup_find_tag("/body", end
+ 1, &slash_body_start
, &slash_body_end
, &unused
))
1453 body
= g_strndup(start
, slash_body_end
- start
+ 1);
1454 g_datalist_clear(&unused
);
1458 purple_debug_warning("oscar", "Broken message contains <body> but not </body>!\n");
1459 /* Take everything after <body> */
1460 body
= g_strdup(start
);
1463 ichattextcolor
= g_datalist_get_data(&attribs
, "ichattextcolor");
1464 if (ichattextcolor
!= NULL
)
1466 tmp2
= g_strdup_printf("<font color=\"%s\">%s</font>", ichattextcolor
, body
);
1471 ichatballooncolor
= g_datalist_get_data(&attribs
, "ichatballooncolor");
1472 if (ichatballooncolor
!= NULL
)
1474 tmp2
= g_strdup_printf("<font back=\"%s\">%s</font>", ichatballooncolor
, body
);
1479 g_datalist_clear(&attribs
);
1482 tmp2
= g_strdup_printf("%.*s%s%s", len
, tmp
, body
, slash_body_end
? slash_body_end
+ 1: "</body>");
1490 * Are there <html/> surrounding tags? If so, strip them out, too.
1492 if (purple_markup_find_tag("html", tmp
, &start
, &end
, &attribs
))
1497 g_datalist_clear(&attribs
);
1500 tmp2
= g_strdup_printf("%.*s%s", len
, tmp
, end
+ 1);
1505 if (purple_markup_find_tag("/html", tmp
, &start
, &end
, &attribs
))
1510 g_datalist_clear(&attribs
);
1513 tmp2
= g_strdup_printf("%.*s%s", len
, tmp
, end
+ 1);
1518 purple_serv_got_im(gc
, userinfo
->bn
, tmp
, flags
, (args
->icbmflags
& AIM_IMFLAGS_OFFLINE
) ? args
->timestamp
: time(NULL
));
1525 incomingim_chan2(OscarData
*od
, FlapConnection
*conn
, aim_userinfo_t
*userinfo
, IcbmArgsCh2
*args
)
1527 PurpleConnection
*gc
;
1528 PurpleAccount
*account
;
1529 PurpleMessageFlags flags
= 0;
1530 char *message
= NULL
;
1532 g_return_val_if_fail(od
!= NULL
, 0);
1533 g_return_val_if_fail(od
->gc
!= NULL
, 0);
1536 account
= purple_connection_get_account(gc
);
1537 od
= purple_connection_get_protocol_data(gc
);
1542 purple_debug_misc("oscar", "Incoming rendezvous message of type %"
1543 G_GUINT64_FORMAT
", user %s, status %hu\n",
1544 args
->type
, userinfo
->bn
, args
->status
);
1546 if (args
->msg
!= NULL
) {
1547 message
= oscar_encoding_to_utf8(args
->encoding
, args
->msg
, args
->msglen
);
1550 if (args
->type
& OSCAR_CAPABILITY_CHAT
)
1552 char *utf8name
, *tmp
;
1553 GHashTable
*components
;
1555 if (!args
->info
.chat
.roominfo
.name
|| !args
->info
.chat
.roominfo
.exchange
) {
1559 utf8name
= oscar_encoding_to_utf8(args
->encoding
, args
->info
.chat
.roominfo
.name
, args
->info
.chat
.roominfo
.namelen
);
1561 tmp
= extract_name(utf8name
);
1568 components
= g_hash_table_new_full(g_str_hash
, g_str_equal
, g_free
,
1570 g_hash_table_replace(components
, g_strdup("room"), utf8name
);
1571 g_hash_table_replace(components
, g_strdup("exchange"),
1572 g_strdup_printf("%d", args
->info
.chat
.roominfo
.exchange
));
1573 purple_serv_got_chat_invite(gc
,
1580 else if ((args
->type
& OSCAR_CAPABILITY_SENDFILE
) || (args
->type
& OSCAR_CAPABILITY_DIRECTIM
))
1582 if (args
->status
== AIM_RENDEZVOUS_PROPOSE
)
1584 peer_connection_got_proposition(od
, userinfo
->bn
, message
, args
);
1586 else if (args
->status
== AIM_RENDEZVOUS_CANCEL
)
1588 /* The other user cancelled a peer request */
1589 PeerConnection
*conn
;
1591 conn
= peer_connection_find_by_cookie(od
, userinfo
->bn
, args
->cookie
);
1593 * If conn is NULL it means we haven't tried to create
1594 * a connection with that user. They may be trying to
1595 * do something malicious.
1599 peer_connection_destroy(conn
, OSCAR_DISCONNECT_REMOTE_CLOSED
, NULL
);
1602 else if (args
->status
== AIM_RENDEZVOUS_CONNECTED
)
1605 * Remote user has accepted our peer request. If we
1606 * wanted to we could look up the PeerConnection using
1607 * args->cookie, but we don't need to do anything here.
1612 else if (args
->type
& OSCAR_CAPABILITY_GETFILE
)
1616 else if (args
->type
& OSCAR_CAPABILITY_TALK
)
1620 else if (args
->type
& OSCAR_CAPABILITY_BUDDYICON
)
1622 purple_buddy_icons_set_for_user(account
, userinfo
->bn
,
1623 g_memdup(args
->info
.icon
.icon
, args
->info
.icon
.length
),
1624 args
->info
.icon
.length
,
1628 else if (args
->type
& OSCAR_CAPABILITY_ICQSERVERRELAY
)
1630 purple_debug_info("oscar", "Got an ICQ Server Relay message of "
1631 "type %d\n", args
->info
.rtfmsg
.msgtype
);
1633 if (args
->info
.rtfmsg
.msgtype
== 1) {
1634 if (args
->info
.rtfmsg
.msg
!= NULL
) {
1636 const char *encoding
= args
->encoding
;
1637 size_t len
= strlen(args
->info
.rtfmsg
.msg
);
1640 if (encoding
== NULL
&& !g_utf8_validate(args
->info
.rtfmsg
.msg
, len
, NULL
)) {
1641 /* Yet another wonderful Miranda-related hack. If their user disables the "Send Unicode messages" setting,
1642 * Miranda sends us ch2 messages in whatever Windows codepage is set as default on their user's system (instead of UTF-8).
1643 * Of course, they don't bother to specify that codepage. Let's just fallback to the encoding OUR users can
1644 * specify in account options as a last resort.
1646 encoding
= purple_account_get_string(account
, "encoding", OSCAR_DEFAULT_CUSTOM_ENCODING
);
1647 purple_debug_info("oscar", "Miranda, is that you? Using '%s' as encoding\n", encoding
);
1650 rtfmsg
= oscar_encoding_to_utf8(encoding
, args
->info
.rtfmsg
.msg
, len
);
1652 /* Channel 2 messages are supposed to be plain-text (never mind the name "rtfmsg", even
1653 * the official client doesn't parse them as RTF). Therefore, we should escape them before
1654 * showing to the user. */
1655 tmp
= g_markup_escape_text(rtfmsg
, -1);
1657 tmp2
= purple_strreplace(tmp
, "\r\n", "<br>");
1660 purple_serv_got_im(gc
, userinfo
->bn
, tmp2
, flags
, time(NULL
));
1661 aim_im_send_icq_confirmation(od
, userinfo
->bn
, args
->cookie
);
1664 } else if (args
->info
.rtfmsg
.msgtype
== 26) {
1665 purple_debug_info("oscar", "Sending X-Status Reply\n");
1666 icq_relay_xstatus(od
, userinfo
->bn
, args
->cookie
);
1671 purple_debug_error("oscar", "Unknown request class %"
1672 G_GUINT64_FORMAT
"\n", args
->type
);
1680 /* When someone sends you buddies */
1682 purple_icq_buddyadd(struct name_data
*data
)
1684 PurpleConnection
*gc
= data
->gc
;
1686 purple_blist_request_add_buddy(purple_connection_get_account(gc
), data
->name
, NULL
, data
->nick
);
1688 oscar_free_name_data(data
);
1692 incomingim_chan4(OscarData
*od
, FlapConnection
*conn
, aim_userinfo_t
*userinfo
,
1693 struct aim_incomingim_ch4_args
*args
)
1695 PurpleConnection
*gc
= od
->gc
;
1696 PurpleAccount
*account
= purple_connection_get_account(gc
);
1697 gchar
**msg1
, **msg2
;
1700 if (!args
->type
|| !args
->msg
|| !args
->uin
)
1703 purple_debug_info("oscar",
1704 "Received a channel 4 message of type 0x%02hx.",
1705 (guint16
)args
->type
);
1708 * Split up the message at the delimeter character, then convert each
1709 * string to UTF-8. Unless, of course, this is a type 1 message. If
1710 * this is a type 1 message, then the delimiter 0xfe could be a valid
1711 * character in whatever encoding the message was sent in. Type 1
1712 * messages are always made up of only one part, so we can easily account
1713 * for this suck-ass part of the protocol by splitting the string into at
1714 * most 1 baby string.
1716 msg1
= g_strsplit(args
->msg
, "\376", (args
->type
== 0x01 ? 1 : 0));
1717 for (numtoks
=0; msg1
[numtoks
]; numtoks
++);
1718 msg2
= (gchar
**)g_malloc((numtoks
+1)*sizeof(gchar
*));
1719 for (i
=0; msg1
[i
]; i
++) {
1720 gchar
*uin
= g_strdup_printf("%u", args
->uin
);
1722 purple_str_strip_char(msg1
[i
], '\r');
1723 /* TODO: Should use an encoding other than ASCII? */
1724 msg2
[i
] = oscar_decode_im(account
, uin
, AIM_CHARSET_ASCII
, msg1
[i
], strlen(msg1
[i
]));
1729 switch (args
->type
) {
1730 case 0x01: { /* MacICQ message or basic offline message */
1732 gchar
*uin
= g_strdup_printf("%u", args
->uin
);
1735 /* If the message came from an ICQ user then escape any HTML */
1736 tmp
= g_markup_escape_text(msg2
[0], -1);
1738 purple_serv_got_im(gc
, uin
, tmp
, 0, time(NULL
));
1745 case 0x04: { /* Someone sent you a URL */
1747 if (msg2
[1] != NULL
) {
1748 gchar
*uin
= g_strdup_printf("%u", args
->uin
);
1749 gchar
*message
= g_strdup_printf("<A HREF=\"%s\">%s</A>",
1751 (msg2
[0] && msg2
[0][0]) ? msg2
[0] : msg2
[1]);
1752 purple_serv_got_im(gc
, uin
, message
, 0, time(NULL
));
1759 case 0x06: { /* Someone requested authorization */
1761 gchar
*bn
= g_strdup_printf("%u", args
->uin
);
1762 gchar
*reason
= NULL
;
1764 if (msg2
[5] != NULL
)
1765 reason
= oscar_decode_im(account
, bn
, AIM_CHARSET_LATIN_1
, msg2
[5], strlen(msg2
[5]));
1767 purple_debug_info("oscar",
1768 "Received an authorization request from UIN %u\n",
1770 aim_icq_getalias(od
, bn
, TRUE
, reason
);
1776 case 0x07: { /* Someone has denied you authorization */
1778 gchar
*dialog_msg
= g_strdup_printf(_("The user %u has denied your request to add them to your buddy list for the following reason:\n%s"), args
->uin
, msg2
[0] ? msg2
[0] : _("No reason given."));
1779 purple_notify_info(gc
, NULL
, _("ICQ authorization denied."), dialog_msg
, purple_request_cpar_from_connection(gc
));
1784 case 0x08: { /* Someone has granted you authorization */
1785 gchar
*dialog_msg
= g_strdup_printf(_("The user %u has granted your request to add them to your buddy list."), args
->uin
);
1786 purple_notify_info(gc
, NULL
, "ICQ authorization accepted.", dialog_msg
, purple_request_cpar_from_connection(gc
));
1790 case 0x09: { /* Message from the Godly ICQ server itself, I think */
1792 gchar
*dialog_msg
= g_strdup_printf(_("You have received a special message\n\nFrom: %s [%s]\n%s"), msg2
[0], msg2
[3], msg2
[5]);
1793 purple_notify_info(gc
, NULL
, "ICQ Server Message", dialog_msg
, purple_request_cpar_from_connection(gc
));
1798 case 0x0d: { /* Someone has sent you a pager message from http://www.icq.com/your_uin */
1800 gchar
*dialog_msg
= g_strdup_printf(_("You have received an ICQ page\n\nFrom: %s [%s]\n%s"), msg2
[0], msg2
[3], msg2
[5]);
1801 purple_notify_info(gc
, NULL
, "ICQ Page", dialog_msg
, purple_request_cpar_from_connection(gc
));
1806 case 0x0e: { /* Someone has emailed you at your_uin@pager.icq.com */
1808 gchar
*dialog_msg
= g_strdup_printf(_("You have received an ICQ email from %s [%s]\n\nMessage is:\n%s"), msg2
[0], msg2
[3], msg2
[5]);
1809 purple_notify_info(gc
, NULL
, "ICQ Email", dialog_msg
, purple_request_cpar_from_connection(gc
));
1815 /* Ack for authorizing/denying someone. Or possibly an ack for sending any system notice */
1816 /* Someone added you to their buddy list? */
1819 case 0x13: { /* Someone has sent you some ICQ buddies */
1822 text
= g_strsplit(args
->msg
, "\376", 0);
1824 /* Read the number of contacts that we were sent */
1826 num
= text
[0] ? strtoul(text
[0], NULL
, 10) : 0;
1828 if (num
> 0 && errno
== 0) {
1829 for (i
=0; i
<num
; i
++) {
1830 struct name_data
*data
;
1833 if (!text
[i
*2 + 1] || !text
[i
*2 + 2]) {
1834 /* We're missing the contact name or nickname. Bail out. */
1835 gchar
*tmp
= g_strescape(args
->msg
, NULL
);
1836 purple_debug_error("oscar", "Unknown syntax parsing "
1837 "ICQ buddies. args->msg=%s\n", tmp
);
1842 message
= g_strdup_printf(_("ICQ user %u has sent you a buddy: %s (%s)"), args
->uin
, text
[i
*2+2], text
[i
*2+1]);
1844 data
= g_new(struct name_data
, 1);
1846 data
->name
= g_strdup(text
[i
*2+1]);
1847 data
->nick
= g_strdup(text
[i
*2+2]);
1849 purple_request_action(gc
, NULL
, message
,
1850 _("Do you want to add this buddy "
1851 "to your buddy list?"),
1852 PURPLE_DEFAULT_ACTION_NONE
,
1853 purple_request_cpar_from_connection(gc
),
1855 _("_Add"), G_CALLBACK(purple_icq_buddyadd
),
1856 _("_Decline"), G_CALLBACK(oscar_free_name_data
));
1860 gchar
*tmp
= g_strescape(args
->msg
, NULL
);
1861 purple_debug_error("oscar", "Unknown syntax parsing "
1862 "ICQ buddies. args->msg=%s\n", tmp
);
1869 case 0x1a: { /* Handle SMS or someone has sent you a greeting card or requested buddies? */
1872 guint32 taglen
, smslen
;
1873 char *tagstr
= NULL
, *smsmsg
= NULL
;
1874 PurpleXmlNode
*xmlroot
= NULL
, *xmltmp
= NULL
;
1875 gchar
*uin
= NULL
, *message
= NULL
;
1877 /* From libicq2000-0.3.2/src/ICQ.cpp */
1878 byte_stream_init(&qbs
, (guint8
*)args
->msg
, args
->msglen
);
1879 byte_stream_advance(&qbs
, 21);
1880 /* expected: 01 00 00 20 00 0e 28 f6 00 11 e7 d3 11 bc f3 00 04 ac 96 9d c2 | 00 00 | 06 00 00 00 | 49 43 51 53 43 53 ...*/
1881 /* unexpected: 00 00 26 00 81 1a 18 bc 0e 6c 18 47 a5 91 6f 18 dc c7 6f 1a | 00 00 | 0d 00 00 00 | 49 43 51 57 65 62 4d 65 73 73 61 67 65 ... */
1882 smstype
= byte_stream_getle16(&qbs
);
1885 taglen
= byte_stream_getle32(&qbs
);
1886 if (taglen
> 2000) {
1887 /* Avoid trying to allocate large amounts of memory, in
1888 case we get something unexpected. */
1891 tagstr
= byte_stream_getstr(&qbs
, taglen
);
1894 byte_stream_advance(&qbs
, 3);
1895 byte_stream_advance(&qbs
, 4);
1896 smslen
= byte_stream_getle32(&qbs
);
1897 if (smslen
> 2000) {
1898 /* Avoid trying to allocate large amounts of memory, in
1899 case we get something unexpected. */
1903 smsmsg
= byte_stream_getstr(&qbs
, smslen
);
1905 /* Check if this is an SMS being sent from server */
1906 if ((smstype
== 0) && (purple_strequal(tagstr
, "ICQSMS")) && (smsmsg
!= NULL
))
1908 xmlroot
= purple_xmlnode_from_str(smsmsg
, -1);
1909 if (xmlroot
!= NULL
)
1911 xmltmp
= purple_xmlnode_get_child(xmlroot
, "sender");
1913 uin
= purple_xmlnode_get_data(xmltmp
);
1915 xmltmp
= purple_xmlnode_get_child(xmlroot
, "text");
1917 message
= purple_xmlnode_get_data(xmltmp
);
1919 if ((uin
!= NULL
) && (message
!= NULL
))
1920 purple_serv_got_im(gc
, uin
, message
, 0, time(NULL
));
1924 purple_xmlnode_free(xmlroot
);
1932 purple_debug_info("oscar",
1933 "Received a channel 4 message of unknown type "
1934 "(type 0x%02x).\n", args
->type
& 0xFF);
1944 static int purple_parse_incoming_im(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...) {
1947 aim_userinfo_t
*userinfo
;
1951 channel
= (guint16
)va_arg(ap
, unsigned int);
1952 userinfo
= va_arg(ap
, aim_userinfo_t
*);
1955 case 1: { /* standard message */
1956 struct aim_incomingim_ch1_args
*args
;
1957 args
= va_arg(ap
, struct aim_incomingim_ch1_args
*);
1958 ret
= incomingim_chan1(od
, conn
, userinfo
, args
);
1961 case 2: { /* rendezvous */
1963 args
= va_arg(ap
, IcbmArgsCh2
*);
1964 ret
= incomingim_chan2(od
, conn
, userinfo
, args
);
1968 struct aim_incomingim_ch4_args
*args
;
1969 args
= va_arg(ap
, struct aim_incomingim_ch4_args
*);
1970 ret
= incomingim_chan4(od
, conn
, userinfo
, args
);
1974 purple_debug_warning("oscar",
1975 "ICBM received on unsupported channel (channel "
1976 "0x%04hx).", channel
);
1985 static int purple_parse_misses(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...) {
1986 PurpleConnection
*gc
= od
->gc
;
1987 PurpleAccount
*account
= purple_connection_get_account(gc
);
1990 guint16 nummissed
, reason
;
1991 aim_userinfo_t
*userinfo
;
1994 va_arg(ap
, unsigned int); /* guint16 chan */
1995 userinfo
= va_arg(ap
, aim_userinfo_t
*);
1996 nummissed
= (guint16
)va_arg(ap
, unsigned int);
1997 reason
= (guint16
)va_arg(ap
, unsigned int);
2001 case 0: /* Invalid (0) */
2002 buf
= g_strdup_printf(
2004 "You missed %hu message from %s because it was invalid.",
2005 "You missed %hu messages from %s because they were invalid.",
2010 case 1: /* Message too large */
2011 buf
= g_strdup_printf(
2013 "You missed %hu message from %s because it was too large.",
2014 "You missed %hu messages from %s because they were too large.",
2019 case 2: /* Rate exceeded */
2020 buf
= g_strdup_printf(
2022 "You missed %hu message from %s because the rate limit has been exceeded.",
2023 "You missed %hu messages from %s because the rate limit has been exceeded.",
2028 case 3: /* Evil Sender */
2029 buf
= g_strdup_printf(
2031 "You missed %hu message from %s because his/her warning level is too high.",
2032 "You missed %hu messages from %s because his/her warning level is too high.",
2037 case 4: /* Evil Receiver */
2038 buf
= g_strdup_printf(
2040 "You missed %hu message from %s because your warning level is too high.",
2041 "You missed %hu messages from %s because your warning level is too high.",
2047 buf
= g_strdup_printf(
2049 "You missed %hu message from %s for an unknown reason.",
2050 "You missed %hu messages from %s for an unknown reason.",
2057 if (!purple_conversation_present_error(userinfo
->bn
, account
, buf
)) {
2058 purple_notify_error(od
->gc
, NULL
, buf
, NULL
,
2059 purple_request_cpar_from_connection(od
->gc
));
2067 purple_parse_clientauto_ch2(OscarData
*od
, const char *who
, guint16 reason
, const guchar
*cookie
)
2069 if (reason
== 0x0003)
2071 /* Rendezvous was refused. */
2072 PeerConnection
*conn
;
2074 conn
= peer_connection_find_by_cookie(od
, who
, cookie
);
2078 purple_debug_info("oscar", "Received a rendezvous cancel message "
2079 "for a nonexistant connection from %s.\n", who
);
2083 peer_connection_destroy(conn
, OSCAR_DISCONNECT_REMOTE_REFUSED
, NULL
);
2088 purple_debug_warning("oscar", "Received an unknown rendezvous "
2089 "message from %s. Type 0x%04hx\n", who
, reason
);
2095 static int purple_parse_clientauto_ch4(OscarData
*od
, const char *who
, guint16 reason
, guint32 state
, char *msg
) {
2096 PurpleConnection
*gc
= od
->gc
;
2099 case 0x0003: { /* Reply from an ICQ status message request */
2100 char *statusmsg
, **splitmsg
;
2101 PurpleNotifyUserInfo
*user_info
;
2103 statusmsg
= oscar_icqstatus(state
);
2105 /* Split at (carriage return/newline)'s, then rejoin later with BRs between. */
2106 /* TODO: Don't we need to escape each piece? */
2107 splitmsg
= g_strsplit(msg
, "\r\n", 0);
2109 user_info
= purple_notify_user_info_new();
2111 purple_notify_user_info_add_pair_plaintext(user_info
, _("UIN"), who
);
2112 /* TODO: Check whether it's correct to call add_pair_html,
2113 or if we should be using add_pair_plaintext */
2114 purple_notify_user_info_add_pair_html(user_info
, _("Status"), statusmsg
);
2115 purple_notify_user_info_add_section_break(user_info
);
2116 purple_notify_user_info_add_pair_html(user_info
, NULL
, g_strjoinv("<BR>", splitmsg
));
2119 g_strfreev(splitmsg
);
2121 purple_notify_userinfo(gc
, who
, user_info
, NULL
, NULL
);
2122 purple_notify_user_info_destroy(user_info
);
2126 case 0x0006: { /* Reply from an ICQ status message request */
2127 char *statusmsg
, **splitmsg
;
2128 PurpleNotifyUserInfo
*user_info
;
2130 statusmsg
= oscar_icqstatus(state
);
2132 /* Split at (carriage return/newline)'s, then rejoin later with BRs between. */
2133 /* TODO: Don't we need to escape each piece? */
2134 splitmsg
= g_strsplit(msg
, "\r\n", 0);
2136 user_info
= purple_notify_user_info_new();
2138 purple_notify_user_info_add_pair_plaintext(user_info
, _("UIN"), who
);
2139 /* TODO: Check whether it's correct to call add_pair_html,
2140 or if we should be using add_pair_plaintext */
2141 purple_notify_user_info_add_pair_html(user_info
, _("Status"), statusmsg
);
2142 purple_notify_user_info_add_section_break(user_info
);
2143 purple_notify_user_info_add_pair_html(user_info
, NULL
, g_strjoinv("<BR>", splitmsg
));
2146 g_strfreev(splitmsg
);
2148 purple_notify_userinfo(gc
, who
, user_info
, NULL
, NULL
);
2149 purple_notify_user_info_destroy(user_info
);
2154 purple_debug_warning("oscar",
2155 "Received an unknown client auto-response from %s. "
2156 "Type 0x%04hx\n", who
, reason
);
2158 } /* end of switch */
2163 static int purple_parse_clientauto(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...) {
2165 guint16 chan
, reason
;
2170 chan
= (guint16
)va_arg(ap
, unsigned int);
2171 who
= va_arg(ap
, char *);
2172 reason
= (guint16
)va_arg(ap
, unsigned int);
2174 if (chan
== 0x0002) { /* File transfer declined */
2175 guchar
*cookie
= va_arg(ap
, guchar
*);
2176 ret
= purple_parse_clientauto_ch2(od
, who
, reason
, cookie
);
2177 } else if (chan
== 0x0004) { /* ICQ message */
2180 if (reason
== 0x0003) {
2181 state
= va_arg(ap
, guint32
);
2182 msg
= va_arg(ap
, char *);
2184 ret
= purple_parse_clientauto_ch4(od
, who
, reason
, state
, msg
);
2192 static int purple_parse_genericerr(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...) {
2197 reason
= (guint16
) va_arg(ap
, unsigned int);
2200 purple_debug_error("oscar", "snac threw error (reason 0x%04hx: %s)\n",
2201 reason
, oscar_get_msgerr_reason(reason
));
2205 static int purple_parse_mtn(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...) {
2206 PurpleConnection
*gc
= od
->gc
;
2208 guint16 channel
, event
;
2212 channel
= (guint16
) va_arg(ap
, unsigned int);
2213 bn
= va_arg(ap
, char *);
2214 event
= (guint16
) va_arg(ap
, unsigned int);
2218 case 0x0000: { /* Text has been cleared */
2219 purple_serv_got_typing_stopped(gc
, bn
);
2222 case 0x0001: { /* Paused typing */
2223 purple_serv_got_typing(gc
, bn
, 0, PURPLE_IM_TYPED
);
2226 case 0x0002: { /* Typing */
2227 purple_serv_got_typing(gc
, bn
, 0, PURPLE_IM_TYPING
);
2230 case 0x000f: { /* Closed IM window */
2231 purple_serv_got_typing_stopped(gc
, bn
);
2235 purple_debug_info("oscar", "Received unknown typing "
2236 "notification message from %s. Channel is 0x%04x "
2237 "and event is 0x%04hx.\n", bn
, channel
, event
);
2244 static int purple_parse_motd(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...)
2251 id
= (guint16
) va_arg(ap
, unsigned int);
2252 msg
= va_arg(ap
, char *);
2255 purple_debug_misc("oscar",
2256 "MOTD: %s (%hu)\n", msg
? msg
: "Unknown", id
);
2258 purple_notify_warning(od
->gc
, NULL
,
2259 _("Your AIM connection may be lost."), NULL
,
2260 purple_request_cpar_from_connection(od
->gc
));
2266 static int purple_chatnav_info(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...) {
2271 type
= (guint16
) va_arg(ap
, unsigned int);
2275 GString
*msg
= g_string_new("");
2277 struct aim_chat_exchangeinfo
*exchanges
;
2278 int exchangecount
, i
;
2280 maxrooms
= (guint8
) va_arg(ap
, unsigned int);
2281 exchangecount
= va_arg(ap
, int);
2282 exchanges
= va_arg(ap
, struct aim_chat_exchangeinfo
*);
2284 g_string_append_printf(msg
, "chat info: Max Concurrent Rooms: %d, Exchange List (%d total): ", (int)maxrooms
, exchangecount
);
2285 for (i
= 0; i
< exchangecount
; i
++) {
2286 g_string_append_printf(msg
, "%hu", exchanges
[i
].number
);
2287 if (exchanges
[i
].name
) {
2288 g_string_append_printf(msg
, " %s", exchanges
[i
].name
);
2290 g_string_append(msg
, ", ");
2292 purple_debug_misc("oscar", "%s\n", msg
->str
);
2293 g_string_free(msg
, TRUE
);
2295 while (od
->create_rooms
) {
2296 struct create_room
*cr
= od
->create_rooms
->data
;
2297 purple_debug_info("oscar",
2298 "creating room %s\n", cr
->name
);
2299 aim_chatnav_createroom(od
, conn
, cr
->name
, cr
->exchange
);
2301 od
->create_rooms
= g_slist_remove(od
->create_rooms
, cr
);
2307 char *fqcn
, *name
, *ck
;
2308 guint16 instance
, flags
, maxmsglen
, maxoccupancy
, unknown
, exchange
;
2312 fqcn
= va_arg(ap
, char *);
2313 instance
= (guint16
)va_arg(ap
, unsigned int);
2314 exchange
= (guint16
)va_arg(ap
, unsigned int);
2315 flags
= (guint16
)va_arg(ap
, unsigned int);
2316 createtime
= va_arg(ap
, guint32
);
2317 maxmsglen
= (guint16
)va_arg(ap
, unsigned int);
2318 maxoccupancy
= (guint16
)va_arg(ap
, unsigned int);
2319 createperms
= (guint8
)va_arg(ap
, unsigned int);
2320 unknown
= (guint16
)va_arg(ap
, unsigned int);
2321 name
= va_arg(ap
, char *);
2322 ck
= va_arg(ap
, char *);
2324 purple_debug_misc("oscar",
2325 "created room: %s %hu %hu %hu %u %hu %hu %u %hu %s %s\n",
2326 fqcn
? fqcn
: "(null)", exchange
, instance
, flags
, createtime
,
2327 maxmsglen
, maxoccupancy
, (guint
)createperms
, unknown
,
2328 name
? name
: "(null)", ck
);
2329 aim_chat_join(od
, exchange
, ck
, instance
);
2333 purple_debug_warning("oscar",
2334 "chatnav info: unknown type (%04hx)\n", type
);
2343 static int purple_chat_conversation_join(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...) {
2346 aim_userinfo_t
*info
;
2347 PurpleConnection
*gc
= od
->gc
;
2349 struct chat_connection
*c
= NULL
;
2352 count
= va_arg(ap
, int);
2353 info
= va_arg(ap
, aim_userinfo_t
*);
2356 c
= find_oscar_chat_by_conn(gc
, conn
);
2360 for (i
= 0; i
< count
; i
++)
2361 purple_chat_conversation_add_user(c
->conv
, info
[i
].bn
, NULL
, PURPLE_CHAT_USER_NONE
, TRUE
);
2366 static int purple_chat_conversation_left(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...) {
2369 aim_userinfo_t
*info
;
2370 PurpleConnection
*gc
= od
->gc
;
2372 struct chat_connection
*c
= NULL
;
2375 count
= va_arg(ap
, int);
2376 info
= va_arg(ap
, aim_userinfo_t
*);
2379 c
= find_oscar_chat_by_conn(gc
, conn
);
2383 for (i
= 0; i
< count
; i
++)
2384 purple_chat_conversation_remove_user(c
->conv
, info
[i
].bn
, NULL
);
2389 static int purple_chat_conversation_info_update(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...) {
2391 guint16 maxmsglen
, maxvisiblemsglen
;
2392 PurpleConnection
*gc
= od
->gc
;
2393 struct chat_connection
*ccon
= find_oscar_chat_by_conn(gc
, conn
);
2399 maxmsglen
= (guint16
)va_arg(ap
, unsigned int);
2400 maxvisiblemsglen
= (guint16
)va_arg(ap
, unsigned int);
2403 purple_debug_misc("oscar",
2404 "inside chat_info_update (maxmsglen = %hu, maxvislen = %hu)\n",
2405 maxmsglen
, maxvisiblemsglen
);
2407 ccon
->maxlen
= maxmsglen
;
2408 ccon
->maxvis
= maxvisiblemsglen
;
2413 static int purple_chat_conversation_incoming_msg(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...) {
2414 PurpleConnection
*gc
= od
->gc
;
2415 struct chat_connection
*ccon
= find_oscar_chat_by_conn(gc
, conn
);
2418 aim_userinfo_t
*info
;
2427 info
= va_arg(ap
, aim_userinfo_t
*);
2428 len
= va_arg(ap
, int);
2429 msg
= va_arg(ap
, char *);
2430 charset
= va_arg(ap
, char *);
2433 utf8
= oscar_encoding_to_utf8(charset
, msg
, len
);
2434 purple_serv_got_chat_in(gc
, ccon
->id
, info
->bn
,
2435 PURPLE_MESSAGE_RECV
, utf8
, time(NULL
));
2441 static int purple_email_parseupdate(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...) {
2443 PurpleConnection
*gc
;
2444 PurpleAccount
*account
;
2445 struct aim_emailinfo
*emailinfo
;
2447 char *alertitle
, *alerturl
;
2450 account
= purple_connection_get_account(gc
);
2453 emailinfo
= va_arg(ap
, struct aim_emailinfo
*);
2454 havenewmail
= va_arg(ap
, int);
2455 alertitle
= va_arg(ap
, char *);
2456 alerturl
= va_arg(ap
, char *);
2459 if (account
!= NULL
&& emailinfo
!= NULL
&& purple_account_get_check_mail(account
) &&
2460 emailinfo
->unread
&& havenewmail
) {
2461 gchar
*to
= g_strdup_printf("%s%s%s",
2462 purple_account_get_username(account
),
2463 emailinfo
->domain
? "@" : "",
2464 emailinfo
->domain
? emailinfo
->domain
: "");
2465 const char *tos
[2] = { to
};
2466 const char *urls
[2] = { emailinfo
->url
};
2467 purple_notify_emails(gc
, emailinfo
->nummsgs
, FALSE
, NULL
, NULL
,
2468 tos
, urls
, NULL
, NULL
);
2473 purple_debug_misc("oscar", "Got an alert '%s' %s\n", alertitle
, alerturl
? alerturl
: "");
2478 static int purple_icon_parseicon(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...) {
2479 PurpleConnection
*gc
= od
->gc
;
2482 guint8
*iconcsum
, *icon
;
2483 guint16 iconcsumlen
, iconlen
;
2486 bn
= va_arg(ap
, char *);
2487 va_arg(ap
, int); /* iconsumtype */
2488 iconcsum
= va_arg(ap
, guint8
*);
2489 iconcsumlen
= va_arg(ap
, int);
2490 icon
= va_arg(ap
, guint8
*);
2491 iconlen
= va_arg(ap
, int);
2495 * Some AIM clients will send a blank GIF image with iconlen 90 when
2496 * no icon is set. Ignore these.
2498 if ((iconlen
> 0) && (iconlen
!= 90)) {
2499 char *b16
= purple_base16_encode(iconcsum
, iconcsumlen
);
2500 purple_buddy_icons_set_for_user(purple_connection_get_account(gc
),
2501 bn
, g_memdup(icon
, iconlen
), iconlen
, b16
);
2509 purple_icons_fetch(PurpleConnection
*gc
)
2511 OscarData
*od
= purple_connection_get_protocol_data(gc
);
2512 aim_userinfo_t
*userinfo
;
2513 FlapConnection
*conn
;
2515 conn
= flap_connection_getbytype(od
, SNAC_FAMILY_BART
);
2517 if (!od
->iconconnecting
) {
2518 aim_srv_requestnew(od
, SNAC_FAMILY_BART
);
2519 od
->iconconnecting
= TRUE
;
2525 PurpleAccount
*account
= purple_connection_get_account(gc
);
2526 PurpleImage
*img
= purple_buddy_icons_find_account_icon(account
);
2528 aim_ssi_delicon(od
);
2530 purple_debug_info("oscar",
2531 "Uploading icon to icon server");
2532 aim_bart_upload(od
, purple_image_get_data(img
),
2533 purple_image_get_data_size(img
));
2534 g_object_unref(img
);
2536 od
->set_icon
= FALSE
;
2539 while (od
->requesticon
!= NULL
)
2541 userinfo
= aim_locate_finduserinfo(od
, (char *)od
->requesticon
->data
);
2542 if ((userinfo
!= NULL
) && (userinfo
->iconcsumlen
> 0))
2543 aim_bart_request(od
, od
->requesticon
->data
, userinfo
->iconcsumtype
, userinfo
->iconcsum
, userinfo
->iconcsumlen
);
2545 g_free(od
->requesticon
->data
);
2546 od
->requesticon
= g_slist_delete_link(od
->requesticon
, od
->requesticon
);
2549 purple_debug_misc("oscar", "no more icons to request\n");
2552 static int purple_selfinfo(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...) {
2554 aim_userinfo_t
*info
;
2557 info
= va_arg(ap
, aim_userinfo_t
*);
2560 purple_connection_set_display_name(od
->gc
, info
->bn
);
2565 static int purple_connerr(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...) {
2566 PurpleConnection
*gc
= od
->gc
;
2572 code
= (guint16
)va_arg(ap
, int);
2573 msg
= va_arg(ap
, char *);
2576 purple_debug_info("oscar", "Disconnected. Code is 0x%04x and msg is %s\n",
2577 code
, (msg
!= NULL
? msg
: ""));
2579 g_return_val_if_fail(conn
!= NULL
, 1);
2581 if (conn
->type
== SNAC_FAMILY_CHAT
) {
2582 struct chat_connection
*cc
;
2583 PurpleChatConversation
*chat
= NULL
;
2585 cc
= find_oscar_chat_by_conn(gc
, conn
);
2588 chat
= purple_conversations_find_chat(gc
, cc
->id
);
2593 * TOOD: Have flap_connection_destroy_cb() send us the
2594 * error message stored in 'tmp', which should be
2595 * human-friendly, and print that to the chat room.
2598 buf
= g_strdup_printf(_("You have been disconnected from chat "
2599 "room %s."), cc
->name
);
2600 purple_conversation_write_system_message(
2601 PURPLE_CONVERSATION(chat
), buf
,
2602 PURPLE_MESSAGE_ERROR
);
2605 oscar_chat_kill(gc
, cc
);
2612 static int purple_parse_locaterights(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...)
2614 PurpleConnection
*gc
= od
->gc
;
2615 PurpleAccount
*account
= purple_connection_get_account(gc
);
2620 maxsiglen
= (guint16
) va_arg(ap
, int);
2623 purple_debug_misc("oscar",
2624 "locate rights: max sig len = %d\n", maxsiglen
);
2626 od
->rights
.maxsiglen
= od
->rights
.maxawaymsglen
= (guint
)maxsiglen
;
2628 aim_locate_setcaps(od
, purple_caps
);
2629 oscar_set_info_and_status(account
, TRUE
, purple_account_get_user_info(account
), TRUE
,
2630 purple_account_get_active_status(account
));
2635 static int purple_parse_buddyrights(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...) {
2637 guint16 maxbuddies
, maxwatchers
;
2640 maxbuddies
= (guint16
) va_arg(ap
, unsigned int);
2641 maxwatchers
= (guint16
) va_arg(ap
, unsigned int);
2644 purple_debug_misc("oscar",
2645 "buddy list rights: Max buddies = %hu / Max watchers = %hu\n", maxbuddies
, maxwatchers
);
2647 od
->rights
.maxbuddies
= (guint
)maxbuddies
;
2648 od
->rights
.maxwatchers
= (guint
)maxwatchers
;
2653 static void oscar_format_username(PurpleConnection
*gc
, const char *new_display_name
)
2656 const char *old_display_name
, *username
;
2657 char *tmp
, *at_sign
;
2659 old_display_name
= purple_connection_get_display_name(gc
);
2660 if (old_display_name
&& strchr(old_display_name
, '@')) {
2661 purple_debug_info("oscar", "Cowardly refusing to attempt to format "
2662 "screen name because the current formatting according to "
2663 "the server (%s) appears to be an email address\n",
2668 username
= purple_account_get_username(purple_connection_get_account(gc
));
2669 if (oscar_util_name_compare(username
, new_display_name
)) {
2670 purple_notify_error(gc
, NULL
, _("The new formatting is invalid."),
2671 _("Username formatting can change only capitalization and whitespace."),
2672 purple_request_cpar_from_connection(gc
));
2676 tmp
= g_strdup(new_display_name
);
2679 * If our local username is an email address then strip off the domain.
2680 * This allows formatting to work if the user entered their username as
2681 * 'something@aim.com' or possibly other AOL-owned domains.
2683 at_sign
= strchr(tmp
, '@');
2687 od
= purple_connection_get_protocol_data(gc
);
2688 if (!flap_connection_getbytype(od
, SNAC_FAMILY_ADMIN
)) {
2689 /* We don't have a connection to an "admin" server. Make one. */
2691 g_free(od
->newformatting
);
2692 od
->newformatting
= tmp
;
2693 aim_srv_requestnew(od
, SNAC_FAMILY_ADMIN
);
2695 aim_admin_setnick(od
, flap_connection_getbytype(od
, SNAC_FAMILY_ADMIN
), tmp
);
2700 static int purple_bosrights(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...) {
2701 PurpleConnection
*gc
;
2702 PurpleAccount
*account
;
2703 PurpleStatus
*status
;
2704 gboolean is_available
;
2705 PurplePresence
*presence
;
2706 const char *username
, *message
, *itmsurl
;
2709 guint16 maxpermits
, maxdenies
;
2712 od
= purple_connection_get_protocol_data(gc
);
2713 account
= purple_connection_get_account(gc
);
2716 maxpermits
= (guint16
) va_arg(ap
, unsigned int);
2717 maxdenies
= (guint16
) va_arg(ap
, unsigned int);
2720 purple_debug_misc("oscar",
2721 "BOS rights: Max permit = %hu / Max deny = %hu\n", maxpermits
, maxdenies
);
2723 od
->rights
.maxpermits
= (guint
)maxpermits
;
2724 od
->rights
.maxdenies
= (guint
)maxdenies
;
2726 purple_debug_info("oscar", "buddy list loaded\n");
2728 if (purple_account_get_user_info(account
) != NULL
)
2729 purple_serv_set_info(gc
, purple_account_get_user_info(account
));
2731 username
= purple_account_get_username(account
);
2732 if (!od
->icq
&& !purple_strequal(username
, purple_connection_get_display_name(gc
))) {
2734 * Format the username for AIM accounts if it's different
2735 * than what's currently set.
2737 oscar_format_username(gc
, username
);
2740 /* Set our available message based on the current status */
2741 status
= purple_account_get_active_status(account
);
2742 is_available
= purple_status_is_available(status
);
2744 message
= purple_status_get_attr_string(status
, "message");
2747 tmp
= purple_markup_strip_html(message
);
2748 itmsurl
= purple_status_get_attr_string(status
, "itmsurl");
2749 aim_srv_setextrainfo(od
, FALSE
, 0, is_available
, tmp
, itmsurl
);
2750 aim_srv_set_dc_info(od
);
2753 presence
= purple_status_get_presence(status
);
2754 aim_srv_setidle(od
, !purple_presence_is_idle(presence
) ? 0 : time(NULL
) - purple_presence_get_idle_time(presence
));
2757 oscar_set_extended_status(gc
);
2758 aim_icq_setsecurity(od
,
2759 purple_account_get_bool(account
, "authorization", OSCAR_DEFAULT_AUTHORIZATION
),
2760 purple_account_get_bool(account
, "web_aware", OSCAR_DEFAULT_WEB_AWARE
));
2763 aim_srv_requestnew(od
, SNAC_FAMILY_ALERT
);
2764 aim_srv_requestnew(od
, SNAC_FAMILY_CHATNAV
);
2766 od
->bos
.have_rights
= TRUE
;
2769 * If we've already received our feedbag data then we're not waiting on
2770 * anything else, so send the server clientready.
2772 * Normally we get bos rights before we get our feedbag data, so this
2773 * rarely (never?) happens. And I'm not sure it actually matters if we
2774 * wait for bos rights before calling clientready. But it seems safer
2775 * to do it this way.
2777 if (od
->ssi
.received_data
) {
2778 aim_srv_clientready(od
, conn
);
2780 /* Request offline messages for AIM and ICQ */
2781 aim_im_reqofflinemsgs(od
);
2783 purple_connection_set_state(gc
, PURPLE_CONNECTION_CONNECTED
);
2789 static int purple_popup(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...)
2791 PurpleConnection
*gc
= od
->gc
;
2797 msg
= va_arg(ap
, char *);
2798 url
= va_arg(ap
, char *);
2799 va_arg(ap
, int); /* guint16 wid */
2800 va_arg(ap
, int); /* guint16 hei */
2801 va_arg(ap
, int); /* guint16 delay */
2804 text
= g_strdup_printf("%s<br><a href=\"%s\">%s</a>", msg
, url
, url
);
2805 purple_notify_formatted(gc
, NULL
, _("Pop-Up Message"), NULL
, text
, NULL
, NULL
);
2811 static void oscar_searchresults_add_buddy_cb(PurpleConnection
*gc
, GList
*row
, void *user_data
)
2813 purple_blist_request_add_buddy(purple_connection_get_account(gc
),
2814 g_list_nth_data(row
, 0), NULL
, NULL
);
2817 static int purple_parse_searchreply(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...)
2819 PurpleConnection
*gc
= od
->gc
;
2820 PurpleNotifySearchResults
*results
;
2821 PurpleNotifySearchColumn
*column
;
2825 char *email
, *usernames
;
2828 email
= va_arg(ap
, char *);
2829 num
= va_arg(ap
, int);
2830 usernames
= va_arg(ap
, char *);
2833 results
= purple_notify_searchresults_new();
2835 if (results
== NULL
) {
2836 purple_debug_error("oscar", "purple_parse_searchreply: "
2837 "Unable to display the search results.\n");
2838 purple_notify_error(gc
, NULL
, _("Unable to display the search "
2840 purple_request_cpar_from_connection(gc
));
2844 secondary
= g_strdup_printf(
2845 dngettext(PACKAGE
, "The following username is associated with %s",
2846 "The following usernames are associated with %s",
2850 column
= purple_notify_searchresults_column_new(_("Username"));
2851 purple_notify_searchresults_column_add(results
, column
);
2853 for (i
= 0; i
< num
; i
++) {
2855 row
= g_list_append(NULL
, g_strdup(&usernames
[i
* (MAXSNLEN
+ 1)]));
2856 purple_notify_searchresults_row_add(results
, row
);
2858 purple_notify_searchresults_button_add(results
, PURPLE_NOTIFY_BUTTON_ADD
,
2859 oscar_searchresults_add_buddy_cb
);
2860 purple_notify_searchresults(gc
, NULL
, NULL
, secondary
, results
, NULL
, NULL
);
2867 static int purple_parse_searcherror(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...) {
2873 email
= va_arg(ap
, char *);
2876 buf
= g_strdup_printf(_("No results found for email address %s"), email
);
2877 purple_notify_error(od
->gc
, NULL
, buf
, NULL
,
2878 purple_request_cpar_from_connection(od
->gc
));
2884 static int purple_account_confirm(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...) {
2885 PurpleConnection
*gc
= od
->gc
;
2891 status
= (guint16
) va_arg(ap
, unsigned int); /* status code of confirmation request */
2894 purple_debug_info("oscar",
2895 "account confirmation returned status 0x%04x (%s)\n", status
,
2896 status
? "unknown" : "email sent");
2898 g_snprintf(msg
, sizeof(msg
), _("You should receive an email asking to confirm %s."),
2899 purple_account_get_username(purple_connection_get_account(gc
)));
2900 purple_notify_info(gc
, NULL
, _("Account Confirmation Requested"),
2901 msg
, purple_request_cpar_from_connection(gc
));
2907 static int purple_info_change(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...) {
2908 PurpleConnection
*gc
= od
->gc
;
2911 char *url
, *bn
, *email
;
2915 change
= va_arg(ap
, int);
2916 perms
= (guint16
) va_arg(ap
, unsigned int);
2917 err
= (guint16
) va_arg(ap
, unsigned int);
2918 url
= va_arg(ap
, char *);
2919 bn
= va_arg(ap
, char *);
2920 email
= va_arg(ap
, char *);
2923 purple_debug_misc("oscar",
2924 "account info: because of %s, perms=0x%04x, err=0x%04x, url=%s, bn=%s, email=%s\n",
2925 change
? "change" : "request", perms
, err
,
2926 (url
!= NULL
) ? url
: "(null)",
2927 (bn
!= NULL
) ? bn
: "(null)",
2928 (email
!= NULL
) ? email
: "(null)");
2930 if ((err
> 0) && (url
!= NULL
)) {
2934 dialog_msg
= g_strdup_printf(_("Error 0x%04x: Unable to format username because the requested name differs from the original."), err
);
2935 else if (err
== 0x0006)
2936 dialog_msg
= g_strdup_printf(_("Error 0x%04x: Unable to format username because it is invalid."), err
);
2937 else if (err
== 0x00b)
2938 dialog_msg
= g_strdup_printf(_("Error 0x%04x: Unable to format username because the requested name is too long."), err
);
2939 else if (err
== 0x001d)
2940 dialog_msg
= g_strdup_printf(_("Error 0x%04x: Unable to change email address because there is already a request pending for this username."), err
);
2941 else if (err
== 0x0021)
2942 dialog_msg
= g_strdup_printf(_("Error 0x%04x: Unable to change email address because the given address has too many usernames associated with it."), err
);
2943 else if (err
== 0x0023)
2944 dialog_msg
= g_strdup_printf(_("Error 0x%04x: Unable to change email address because the given address is invalid."), err
);
2946 dialog_msg
= g_strdup_printf(_("Error 0x%04x: Unknown error."), err
);
2947 purple_notify_error(gc
, NULL
, _("Error Changing Account Info"),
2948 dialog_msg
, purple_request_cpar_from_connection(gc
));
2953 if (email
!= NULL
) {
2954 char *dialog_msg
= g_strdup_printf(_("The email address for %s is %s"),
2955 purple_account_get_username(purple_connection_get_account(gc
)), email
);
2956 purple_notify_info(gc
, NULL
, _("Account Info"), dialog_msg
,
2957 purple_request_cpar_from_connection(gc
));
2965 oscar_keepalive(PurpleConnection
*gc
)
2970 od
= purple_connection_get_protocol_data(gc
);
2971 for (l
= od
->oscar_connections
; l
; l
= l
->next
) {
2972 flap_connection_send_keepalive(od
, l
->data
);
2977 oscar_send_typing(PurpleConnection
*gc
, const char *name
, PurpleIMTypingState state
)
2980 PeerConnection
*conn
;
2982 od
= purple_connection_get_protocol_data(gc
);
2983 conn
= peer_connection_find_by_type(od
, name
, OSCAR_CAPABILITY_DIRECTIM
);
2985 if ((conn
!= NULL
) && (conn
->ready
))
2987 peer_odc_send_typing(conn
, state
);
2990 /* Don't send if this turkey is in our deny list */
2991 PurpleAccount
*account
= purple_connection_get_account(gc
);
2994 for (list
=purple_account_privacy_get_denied(account
); (list
&& oscar_util_name_compare(name
, list
->data
)); list
=list
->next
);
2996 struct buddyinfo
*bi
= g_hash_table_lookup(od
->buddyinfo
, purple_normalize(account
, name
));
2997 if (bi
&& bi
->typingnot
) {
2998 if (state
== PURPLE_IM_TYPING
)
2999 aim_im_sendmtn(od
, 0x0001, name
, 0x0002);
3000 else if (state
== PURPLE_IM_TYPED
)
3001 aim_im_sendmtn(od
, 0x0001, name
, 0x0001);
3003 aim_im_sendmtn(od
, 0x0001, name
, 0x0000);
3010 /* TODO: Move this into odc.c! */
3012 purple_odc_send_im(PeerConnection
*conn
, const char *message
, PurpleMessageFlags imflags
)
3020 const char *start
, *end
, *last
;
3023 msg
= g_string_new("<HTML><BODY>");
3024 data
= g_string_new("<BINARY>");
3027 /* for each valid IMG tag... */
3028 while (last
&& *last
&& purple_markup_find_tag("img", last
, &start
, &end
, &attribs
))
3030 PurpleImage
*image
= NULL
;
3034 g_string_append_len(msg
, last
, start
- last
);
3037 src
= g_datalist_get_data(&attribs
, "src");
3039 image
= purple_image_store_get_from_uri(src
);
3041 /* ... if it refers to a valid purple image ... */
3043 /* ... append the message from start to the tag ... */
3044 unsigned long size
= purple_image_get_data_size(image
);
3045 const gchar
*filename
= purple_image_get_friendly_filename(image
);
3046 gconstpointer imgdata
= purple_image_get_data(image
);
3050 /* ... insert a new img tag with the oscar id ... */
3052 g_string_append_printf(msg
,
3053 "<IMG SRC=\"%s\" ID=\"%d\" DATASIZE=\"%lu\">",
3054 filename
, oscar_id
, size
);
3056 g_string_append_printf(msg
,
3057 "<IMG ID=\"%d\" DATASIZE=\"%lu\">",
3060 /* ... and append the data to the binary section ... */
3061 g_string_append_printf(data
, "<DATA ID=\"%d\" SIZE=\"%lu\">",
3063 g_string_append_len(data
, imgdata
, size
);
3064 g_string_append(data
, "</DATA>");
3066 /* If the tag is invalid, skip it, thus no else here */
3068 g_datalist_clear(&attribs
);
3070 /* continue from the end of the tag */
3074 /* append any remaining message data */
3076 g_string_append(msg
, last
);
3078 g_string_append(msg
, "</BODY></HTML>");
3080 /* Convert the message to a good encoding */
3081 tmp
= oscar_encode_im(msg
->str
, &tmplen
, &charset
, NULL
);
3082 g_string_free(msg
, TRUE
);
3083 msg
= g_string_new_len(tmp
, tmplen
);
3086 /* Append any binary data that we may have */
3088 msg
= g_string_append_len(msg
, data
->str
, data
->len
);
3089 msg
= g_string_append(msg
, "</BINARY>");
3091 g_string_free(data
, TRUE
);
3093 purple_debug_info("oscar", "sending direct IM %s using charset %i", msg
->str
, charset
);
3095 peer_odc_send_im(conn
, msg
->str
, msg
->len
, charset
,
3096 imflags
& PURPLE_MESSAGE_AUTO_RESP
);
3097 g_string_free(msg
, TRUE
);
3101 oscar_send_im(PurpleConnection
*gc
, PurpleMessage
*msg
)
3104 PurpleAccount
*account
;
3105 PeerConnection
*conn
;
3108 gboolean is_sms
, is_html
;
3109 const gchar
*name
, *message
;
3110 PurpleMessageFlags imflags
;
3112 name
= purple_message_get_recipient(msg
);
3113 message
= purple_message_get_contents(msg
);
3114 imflags
= purple_message_get_flags(msg
);
3115 od
= purple_connection_get_protocol_data(gc
);
3116 account
= purple_connection_get_account(gc
);
3119 is_sms
= oscar_util_valid_name_sms(name
);
3121 if (od
->icq
&& is_sms
) {
3123 * We're sending to a phone number and this is ICQ,
3124 * so send the message as an SMS using aim_icq_sendsms()
3127 purple_debug_info("oscar", "Sending SMS to %s.\n", name
);
3128 ret
= aim_icq_sendsms(od
, name
, message
, purple_account_get_username(account
));
3129 return (ret
>= 0 ? 1 : ret
);
3132 if (imflags
& PURPLE_MESSAGE_AUTO_RESP
)
3133 tmp1
= oscar_util_format_string(message
, name
);
3135 tmp1
= g_strdup(message
);
3137 conn
= peer_connection_find_by_type(od
, name
, OSCAR_CAPABILITY_DIRECTIM
);
3138 if ((conn
!= NULL
) && (conn
->ready
))
3140 /* If we're directly connected, send a direct IM */
3141 purple_debug_info("oscar", "Sending direct IM with flags %i\n", imflags
);
3142 purple_odc_send_im(conn
, tmp1
, imflags
);
3144 struct buddyinfo
*bi
;
3145 struct aim_sendimext_args args
;
3146 PurpleIMConversation
*im
;
3150 im
= purple_conversations_find_im_with_account(name
, account
);
3152 if (strstr(tmp1
, "<img "))
3153 purple_conversation_write_system_message(PURPLE_CONVERSATION(im
),
3154 _("Your IM Image was not sent. "
3155 "You must be Direct Connected to send IM Images."),
3156 PURPLE_MESSAGE_ERROR
);
3158 buddy
= purple_blist_find_buddy(account
, name
);
3160 bi
= g_hash_table_lookup(od
->buddyinfo
, purple_normalize(account
, name
));
3162 bi
= g_new0(struct buddyinfo
, 1);
3163 g_hash_table_insert(od
->buddyinfo
, g_strdup(purple_normalize(account
, name
)), bi
);
3168 if (!is_sms
&& (!buddy
|| !PURPLE_BUDDY_IS_ONLINE(buddy
)))
3169 args
.flags
|= AIM_IMFLAGS_OFFLINE
;
3172 args
.features
= features_icq
;
3173 args
.featureslen
= sizeof(features_icq
);
3175 args
.features
= features_aim
;
3176 args
.featureslen
= sizeof(features_aim
);
3178 if (imflags
& PURPLE_MESSAGE_AUTO_RESP
)
3179 args
.flags
|= AIM_IMFLAGS_AWAY
;
3183 purple_debug_info("oscar",
3184 "Sending buddy icon request with message\n");
3185 args
.flags
|= AIM_IMFLAGS_BUDDYREQ
;
3186 bi
->ico_need
= FALSE
;
3189 img
= purple_buddy_icons_find_account_icon(account
);
3191 gconstpointer data
= purple_image_get_data(img
);
3192 args
.iconlen
= purple_image_get_data_size(img
);
3193 args
.iconsum
= aimutil_iconsum(data
, args
.iconlen
);
3194 args
.iconstamp
= purple_buddy_icons_get_account_icon_timestamp(account
);
3196 if ((args
.iconlen
!= bi
->ico_me_len
) || (args
.iconsum
!= bi
->ico_me_csum
) || (args
.iconstamp
!= bi
->ico_me_time
)) {
3197 bi
->ico_informed
= FALSE
;
3198 bi
->ico_sent
= FALSE
;
3203 * For some reason sending our icon to people only works
3204 * when we're the ones who initiated the conversation. If
3205 * the other person sends the first IM then they never get
3206 * the icon. We should fix that.
3208 if (!bi
->ico_informed
) {
3209 purple_debug_info("oscar",
3210 "Claiming to have a buddy icon\n");
3211 args
.flags
|= AIM_IMFLAGS_HASICON
;
3212 bi
->ico_me_len
= args
.iconlen
;
3213 bi
->ico_me_csum
= args
.iconsum
;
3214 bi
->ico_me_time
= args
.iconstamp
;
3215 bi
->ico_informed
= TRUE
;
3218 g_object_unref(img
);
3223 if (oscar_util_valid_name_sms(name
)) {
3224 /* Messaging an SMS (mobile) user--strip HTML */
3225 tmp2
= purple_markup_strip_html(tmp1
);
3228 /* ICQ 6 wants its HTML wrapped in these tags. Oblige it. */
3229 tmp2
= g_strdup_printf("<HTML><BODY>%s</BODY></HTML>", tmp1
);
3235 args
.msg
= oscar_encode_im(tmp1
, &args
.msglen
, &args
.charset
, NULL
);
3236 if (is_html
&& (args
.msglen
> MAXMSGLEN
)) {
3237 /* If the length was too long, try stripping the HTML and then running it back through
3238 * purple_strdup_withhtml() and the encoding process. The result may be shorter. */
3239 g_free((char *)args
.msg
);
3241 tmp2
= purple_markup_strip_html(tmp1
);
3244 /* re-escape the entities */
3245 tmp1
= g_markup_escape_text(tmp2
, -1);
3248 tmp2
= purple_strdup_withhtml(tmp1
);
3252 args
.msg
= oscar_encode_im(tmp1
, &args
.msglen
, &args
.charset
, NULL
);
3253 purple_debug_info("oscar", "Sending %s as %s because the original was too long.\n",
3254 message
, (char *)args
.msg
);
3257 purple_debug_info("oscar", "Sending IM, charset=0x%04hx, length=%" G_GSIZE_FORMAT
"\n", args
.charset
, args
.msglen
);
3258 ret
= aim_im_sendch1_ext(od
, &args
);
3259 g_free((char *)args
.msg
);
3271 * As of 26 June 2006, ICQ users can request AIM info from
3272 * everyone, and can request ICQ info from ICQ users, and
3273 * AIM users can only request AIM info.
3275 void oscar_get_info(PurpleConnection
*gc
, const char *name
) {
3276 OscarData
*od
= purple_connection_get_protocol_data(gc
);
3278 if (od
->icq
&& oscar_util_valid_name_icq(name
))
3279 aim_icq_getallinfo(od
, name
);
3281 aim_locate_getinfoshort(od
, name
, 0x00000003);
3284 void oscar_set_idle(PurpleConnection
*gc
, int time
) {
3285 OscarData
*od
= purple_connection_get_protocol_data(gc
);
3286 aim_srv_setidle(od
, time
);
3290 oscar_set_info(PurpleConnection
*gc
, const char *rawinfo
)
3292 PurpleAccount
*account
;
3293 PurpleStatus
*status
;
3295 account
= purple_connection_get_account(gc
);
3296 status
= purple_account_get_active_status(account
);
3297 oscar_set_info_and_status(account
, TRUE
, rawinfo
, FALSE
, status
);
3301 oscar_get_extended_status(PurpleConnection
*gc
)
3303 PurpleAccount
*account
;
3304 PurpleStatus
*status
;
3305 const gchar
*status_id
;
3306 guint32 data
= 0x00000000;
3308 account
= purple_connection_get_account(gc
);
3309 status
= purple_account_get_active_status(account
);
3310 status_id
= purple_status_get_id(status
);
3312 data
|= AIM_ICQ_STATE_HIDEIP
;
3313 if (purple_account_get_bool(account
, "web_aware", OSCAR_DEFAULT_WEB_AWARE
))
3314 data
|= AIM_ICQ_STATE_WEBAWARE
;
3316 if (purple_strequal(status_id
, OSCAR_STATUS_ID_AVAILABLE
))
3317 data
|= AIM_ICQ_STATE_NORMAL
;
3318 else if (purple_strequal(status_id
, OSCAR_STATUS_ID_AWAY
))
3319 data
|= AIM_ICQ_STATE_AWAY
;
3320 else if (purple_strequal(status_id
, OSCAR_STATUS_ID_DND
))
3321 data
|= AIM_ICQ_STATE_AWAY
| AIM_ICQ_STATE_DND
| AIM_ICQ_STATE_BUSY
;
3322 else if (purple_strequal(status_id
, OSCAR_STATUS_ID_NA
))
3323 data
|= AIM_ICQ_STATE_OUT
| AIM_ICQ_STATE_AWAY
;
3324 else if (purple_strequal(status_id
, OSCAR_STATUS_ID_OCCUPIED
))
3325 data
|= AIM_ICQ_STATE_AWAY
| AIM_ICQ_STATE_BUSY
;
3326 else if (purple_strequal(status_id
, OSCAR_STATUS_ID_FREE4CHAT
))
3327 data
|= AIM_ICQ_STATE_CHAT
;
3328 else if (purple_strequal(status_id
, OSCAR_STATUS_ID_INVISIBLE
))
3329 data
|= AIM_ICQ_STATE_INVISIBLE
;
3330 else if (purple_strequal(status_id
, OSCAR_STATUS_ID_EVIL
))
3331 data
|= AIM_ICQ_STATE_EVIL
;
3332 else if (purple_strequal(status_id
, OSCAR_STATUS_ID_DEPRESSION
))
3333 data
|= AIM_ICQ_STATE_DEPRESSION
;
3334 else if (purple_strequal(status_id
, OSCAR_STATUS_ID_ATWORK
))
3335 data
|= AIM_ICQ_STATE_ATWORK
;
3336 else if (purple_strequal(status_id
, OSCAR_STATUS_ID_ATHOME
))
3337 data
|= AIM_ICQ_STATE_ATHOME
;
3338 else if (purple_strequal(status_id
, OSCAR_STATUS_ID_LUNCH
))
3339 data
|= AIM_ICQ_STATE_LUNCH
;
3340 else if (purple_strequal(status_id
, OSCAR_STATUS_ID_CUSTOM
))
3341 data
|= AIM_ICQ_STATE_OUT
| AIM_ICQ_STATE_AWAY
;
3347 oscar_set_extended_status(PurpleConnection
*gc
)
3349 aim_srv_setextrainfo(purple_connection_get_protocol_data(gc
), TRUE
, oscar_get_extended_status(gc
), FALSE
, NULL
, NULL
);
3353 oscar_set_info_and_status(PurpleAccount
*account
, gboolean setinfo
, const char *rawinfo
,
3354 gboolean setstatus
, PurpleStatus
*status
)
3356 PurpleConnection
*gc
= purple_account_get_connection(account
);
3357 OscarData
*od
= purple_connection_get_protocol_data(gc
);
3358 PurpleStatusType
*status_type
;
3359 PurpleStatusPrimitive primitive
;
3361 char *info_encoding
= NULL
;
3365 char *away_encoding
= NULL
;
3369 char *status_text
= NULL
;
3370 const char *itmsurl
= NULL
;
3372 status_type
= purple_status_get_status_type(status
);
3373 primitive
= purple_status_type_get_primitive(status_type
);
3379 else if (od
->rights
.maxsiglen
== 0)
3381 purple_notify_warning(gc
, NULL
, _("Unable to set AIM profile."),
3382 _("You have probably requested to set your "
3383 "profile before the login procedure completed. "
3384 "Your profile remains unset; try setting it "
3385 "again when you are fully connected."),
3386 purple_request_cpar_from_connection(gc
));
3388 else if (rawinfo
!= NULL
)
3390 char *htmlinfo
= purple_strdup_withhtml(rawinfo
);
3391 info
= oscar_encode_im(htmlinfo
, &infolen
, NULL
, &info_encoding
);
3394 if (infolen
> od
->rights
.maxsiglen
)
3397 errstr
= g_strdup_printf(dngettext(PACKAGE
, "The maximum profile length of %d byte "
3398 "has been exceeded. It has been truncated for you.",
3399 "The maximum profile length of %d bytes "
3400 "has been exceeded. It has been truncated for you.",
3401 od
->rights
.maxsiglen
), od
->rights
.maxsiglen
);
3402 purple_notify_warning(gc
, NULL
, _("Profile too long."),
3403 errstr
, purple_request_cpar_from_connection(gc
));
3410 const char *status_html
;
3412 status_html
= purple_status_get_attr_string(status
, "message");
3414 if (status_html
== NULL
|| primitive
== PURPLE_STATUS_AVAILABLE
|| primitive
== PURPLE_STATUS_INVISIBLE
)
3416 /* This is needed for us to un-set any previous away message. */
3417 away
= g_strdup("");
3423 /* We do this for icq too so that they work for old third party clients */
3424 linkified
= purple_markup_linkify(status_html
);
3425 away
= oscar_encode_im(linkified
, &awaylen
, NULL
, &away_encoding
);
3428 if (awaylen
> od
->rights
.maxawaymsglen
)
3432 errstr
= g_strdup_printf(dngettext(PACKAGE
, "The maximum away message length of %d byte "
3433 "has been exceeded. It has been truncated for you.",
3434 "The maximum away message length of %d bytes "
3435 "has been exceeded. It has been truncated for you.",
3436 od
->rights
.maxawaymsglen
), od
->rights
.maxawaymsglen
);
3437 purple_notify_warning(gc
, NULL
,
3438 _("Away message too long."), errstr
,
3439 purple_request_cpar_from_connection(gc
));
3445 aim_locate_setprofile(od
,
3446 info_encoding
, info
, MIN(infolen
, od
->rights
.maxsiglen
),
3447 away_encoding
, away
, MIN(awaylen
, od
->rights
.maxawaymsglen
));
3453 const char *status_html
;
3455 status_html
= purple_status_get_attr_string(status
, "message");
3456 if (status_html
!= NULL
)
3458 status_text
= purple_markup_strip_html(status_html
);
3459 /* If the status_text is longer than 251 characters then truncate it */
3460 if (strlen(status_text
) > MAXAVAILMSGLEN
)
3462 char *tmp
= g_utf8_find_prev_char(status_text
, &status_text
[MAXAVAILMSGLEN
- 2]);
3467 itmsurl
= purple_status_get_attr_string(status
, "itmsurl");
3469 aim_srv_setextrainfo(od
, TRUE
, oscar_get_extended_status(gc
), TRUE
, status_text
, itmsurl
);
3470 g_free(status_text
);
3475 oscar_set_icq_permdeny(PurpleAccount
*account
)
3477 PurpleConnection
*gc
= purple_account_get_connection(account
);
3478 OscarData
*od
= purple_connection_get_protocol_data(gc
);
3479 gboolean invisible
= purple_account_is_status_active(account
, OSCAR_STATUS_ID_INVISIBLE
);
3482 * For ICQ the permit/deny setting controls who can see you
3483 * online. Mimicking the official client's behavior, we use PURPLE_ACCOUNT_PRIVACY_ALLOW_USERS
3484 * when our status is "invisible" and PURPLE_ACCOUNT_PRIVACY_DENY_USERS otherwise.
3485 * In the former case, we are visible only to buddies on our "permanently visible" list.
3486 * In the latter, we are invisible only to buddies on our "permanently invisible" list.
3488 aim_ssi_setpermdeny(od
, invisible
? PURPLE_ACCOUNT_PRIVACY_ALLOW_USERS
: PURPLE_ACCOUNT_PRIVACY_DENY_USERS
);
3492 oscar_set_status(PurpleAccount
*account
, PurpleStatus
*status
)
3494 PurpleConnection
*pc
;
3497 purple_debug_info("oscar", "Set status to %s\n", purple_status_get_name(status
));
3499 /* Either setting a new status active or setting a status inactive.
3500 * (Only possible for independent status (i.e. X-Status moods.) */
3501 if (!purple_status_is_active(status
) && !purple_status_is_independent(status
))
3504 if (!purple_account_is_connected(account
))
3507 pc
= purple_account_get_connection(account
);
3508 od
= purple_connection_get_protocol_data(pc
);
3510 /* There's no need to do the stuff below for mood updates. */
3511 if (purple_status_type_get_primitive(purple_status_get_status_type(status
)) == PURPLE_STATUS_MOOD
) {
3512 aim_locate_setcaps(od
, purple_caps
);
3517 /* Set visibility */
3518 oscar_set_icq_permdeny(account
);
3521 /* Set the AIM-style away message for both AIM and ICQ accounts */
3522 oscar_set_info_and_status(account
, FALSE
, NULL
, TRUE
, status
);
3526 oscar_add_buddy(PurpleConnection
*gc
, PurpleBuddy
*buddy
, PurpleGroup
*group
, const char *msg
)
3529 PurpleAccount
*account
;
3530 const char *bname
, *gname
;
3532 od
= purple_connection_get_protocol_data(gc
);
3533 account
= purple_connection_get_account(gc
);
3534 bname
= purple_buddy_get_name(buddy
);
3535 gname
= purple_group_get_name(group
);
3537 if (!oscar_util_valid_name(bname
)) {
3539 buf
= g_strdup_printf(_("Unable to add the buddy %s because the username is invalid. Usernames must be a valid email address, or start with a letter and contain only letters, numbers and spaces, or contain only numbers."), bname
);
3540 if (!purple_conversation_present_error(bname
, account
, buf
))
3541 purple_notify_error(gc
, NULL
, _("Unable to Add"), buf
, purple_request_cpar_from_connection(gc
));
3544 /* Remove from local list */
3545 purple_blist_remove_buddy(buddy
);
3550 if (od
->ssi
.received_data
) {
3551 if (!aim_ssi_itemlist_finditem(&od
->ssi
.local
, gname
, bname
, AIM_SSI_TYPE_BUDDY
)) {
3552 purple_debug_info("oscar",
3553 "ssi: adding buddy %s to group %s\n", bname
, gname
);
3554 aim_ssi_addbuddy(od
, bname
, gname
, NULL
, purple_buddy_get_alias_only(buddy
), NULL
, NULL
, 0);
3556 /* Mobile users should always be online */
3557 if (bname
[0] == '+') {
3558 purple_protocol_got_user_status(account
, bname
,
3559 OSCAR_STATUS_ID_AVAILABLE
, NULL
);
3560 purple_protocol_got_user_status(account
, bname
,
3561 OSCAR_STATUS_ID_MOBILE
, NULL
);
3563 } else if (aim_ssi_waitingforauth(&od
->ssi
.local
,
3564 aim_ssi_itemlist_findparentname(&od
->ssi
.local
, bname
),
3566 /* Not authorized -- Re-request authorization */
3567 oscar_auth_sendrequest(gc
, bname
, msg
);
3571 /* XXX - Should this be done from AIM accounts, as well? */
3573 aim_icq_getalias(od
, bname
, FALSE
, NULL
);
3576 void oscar_remove_buddy(PurpleConnection
*gc
, PurpleBuddy
*buddy
, PurpleGroup
*group
) {
3577 OscarData
*od
= purple_connection_get_protocol_data(gc
);
3579 if (od
->ssi
.received_data
) {
3580 const char *gname
= purple_group_get_name(group
);
3581 const char *bname
= purple_buddy_get_name(buddy
);
3582 purple_debug_info("oscar",
3583 "ssi: deleting buddy %s from group %s\n", bname
, gname
);
3584 aim_ssi_delbuddy(od
, bname
, gname
);
3588 void oscar_move_buddy(PurpleConnection
*gc
, const char *name
, const char *old_group
, const char *new_group
) {
3589 OscarData
*od
= purple_connection_get_protocol_data(gc
);
3591 if (od
->ssi
.received_data
&& !purple_strequal(old_group
, new_group
)) {
3592 purple_debug_info("oscar",
3593 "ssi: moving buddy %s from group %s to group %s\n", name
, old_group
, new_group
);
3594 aim_ssi_movebuddy(od
, old_group
, new_group
, name
);
3598 void oscar_alias_buddy(PurpleConnection
*gc
, const char *name
, const char *alias
) {
3599 OscarData
*od
= purple_connection_get_protocol_data(gc
);
3601 if (od
->ssi
.received_data
) {
3602 char *gname
= aim_ssi_itemlist_findparentname(&od
->ssi
.local
, name
);
3604 purple_debug_info("oscar",
3605 "ssi: changing the alias for buddy %s to %s\n", name
, alias
? alias
: "(none)");
3606 aim_ssi_aliasbuddy(od
, gname
, name
, alias
);
3612 * FYI, the OSCAR SSI code removes empty groups automatically.
3614 void oscar_rename_group(PurpleConnection
*gc
, const char *old_name
, PurpleGroup
*group
, GList
*moved_buddies
) {
3615 OscarData
*od
= purple_connection_get_protocol_data(gc
);
3617 if (od
->ssi
.received_data
) {
3618 const char *gname
= purple_group_get_name(group
);
3619 if (aim_ssi_itemlist_finditem(&od
->ssi
.local
, gname
, NULL
, AIM_SSI_TYPE_GROUP
)) {
3620 GList
*cur
, *groups
= NULL
;
3621 PurpleAccount
*account
= purple_connection_get_account(gc
);
3623 /* Make a list of what the groups each buddy is in */
3624 for (cur
= moved_buddies
; cur
!= NULL
; cur
= cur
->next
) {
3625 PurpleBlistNode
*node
= cur
->data
;
3626 /* node is PurpleBuddy, parent is a PurpleContact.
3627 * We must go two levels up to get the Group */
3628 groups
= g_list_append(groups
,
3629 purple_buddy_get_group((PurpleBuddy
*)node
));
3632 purple_account_remove_buddies(account
, moved_buddies
, groups
);
3633 purple_account_add_buddies(account
, moved_buddies
, NULL
);
3634 g_list_free(groups
);
3635 purple_debug_info("oscar",
3636 "ssi: moved all buddies from group %s to %s\n", old_name
, gname
);
3638 aim_ssi_rename_group(od
, old_name
, gname
);
3639 purple_debug_info("oscar",
3640 "ssi: renamed group %s to %s\n", old_name
, gname
);
3645 void oscar_remove_group(PurpleConnection
*gc
, PurpleGroup
*group
)
3647 aim_ssi_delgroup(purple_connection_get_protocol_data(gc
), purple_group_get_name(group
));
3650 static gboolean
purple_ssi_rerequestdata(gpointer data
) {
3651 OscarData
*od
= data
;
3653 aim_ssi_reqdata(od
);
3658 static int purple_ssi_parseerr(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...) {
3659 PurpleConnection
*gc
= od
->gc
;
3664 reason
= (guint16
)va_arg(ap
, unsigned int);
3667 purple_debug_error("oscar", "ssi: SNAC error %hu\n", reason
);
3669 if (reason
== 0x0005) {
3670 if (od
->getblisttimer
> 0)
3671 g_source_remove(od
->getblisttimer
);
3673 /* We only show this error the first time it happens */
3674 purple_notify_error(gc
, NULL
,
3675 _("Unable to Retrieve Buddy List"),
3676 _("The AIM servers were temporarily unable to send "
3677 "your buddy list. Your buddy list is not lost, and "
3678 "will probably become available in a few minutes."),
3679 purple_request_cpar_from_connection(gc
));
3680 od
->getblisttimer
= g_timeout_add_seconds(30, purple_ssi_rerequestdata
, od
);
3687 static int purple_ssi_parserights(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...) {
3695 numtypes
= va_arg(ap
, int);
3696 maxitems
= va_arg(ap
, guint16
*);
3699 msg
= g_string_new("ssi rights:");
3700 for (i
=0; i
<numtypes
; i
++)
3701 g_string_append_printf(msg
, " max type 0x%04x=%hd,", i
, maxitems
[i
]);
3702 g_string_append(msg
, "\n");
3703 purple_debug_misc("oscar", "%s", msg
->str
);
3704 g_string_free(msg
, TRUE
);
3707 od
->rights
.maxbuddies
= maxitems
[0];
3709 od
->rights
.maxgroups
= maxitems
[1];
3711 od
->rights
.maxpermits
= maxitems
[2];
3713 od
->rights
.maxdenies
= maxitems
[3];
3718 static int purple_ssi_parselist(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...)
3720 PurpleConnection
*gc
;
3721 PurpleAccount
*account
;
3724 GSList
*cur
, *next
, *buddies
;
3725 struct aim_ssi_item
*curitem
;
3729 guint16 deny_entry_type
= aim_ssi_getdenyentrytype(od
);
3732 od
= purple_connection_get_protocol_data(gc
);
3733 account
= purple_connection_get_account(gc
);
3736 va_arg(ap
, int); /* guint16 fmtver */
3737 va_arg(ap
, int); /* guint16 numitems */
3738 va_arg(ap
, guint32
); /* timestamp */
3741 /* Don't attempt to re-request our buddy list later */
3742 if (od
->getblisttimer
!= 0) {
3743 g_source_remove(od
->getblisttimer
);
3744 od
->getblisttimer
= 0;
3747 purple_debug_info("oscar", "ssi: syncing local list and server list\n");
3749 /*** Begin code for pruning buddies from local list if they're not in server list ***/
3753 for (buddies
= purple_blist_find_buddies(account
, NULL
);
3755 buddies
= g_slist_delete_link(buddies
, buddies
))
3762 g
= purple_buddy_get_group(b
);
3763 gname
= purple_group_get_name(g
);
3764 bname
= purple_buddy_get_name(b
);
3766 if (aim_ssi_itemlist_exists(&od
->ssi
.local
, bname
)) {
3767 /* If the buddy is an ICQ user then load his nickname */
3768 const char *servernick
= purple_blist_node_get_string((PurpleBlistNode
*)b
, "servernick");
3772 purple_serv_got_alias(gc
, bname
, servernick
);
3774 /* Store local alias on server */
3775 alias
= aim_ssi_getalias(&od
->ssi
.local
, gname
, bname
);
3776 balias
= purple_buddy_get_local_alias(b
);
3777 if (!alias
&& balias
&& *balias
)
3778 aim_ssi_aliasbuddy(od
, gname
, bname
, balias
);
3781 purple_debug_info("oscar",
3782 "ssi: removing buddy %s from local list\n", bname
);
3783 /* Queue the buddy for removal from the local list */
3784 cur
= g_slist_prepend(cur
, b
);
3787 while (cur
!= NULL
) {
3788 purple_blist_remove_buddy(cur
->data
);
3789 cur
= g_slist_delete_link(cur
, cur
);
3792 /* Permit list (ICQ doesn't have one) */
3794 next
= purple_account_privacy_get_permitted(account
);
3795 while (next
!= NULL
) {
3798 if (!aim_ssi_itemlist_finditem(&od
->ssi
.local
, NULL
, cur
->data
, AIM_SSI_TYPE_PERMIT
)) {
3799 purple_debug_info("oscar",
3800 "ssi: removing permit %s from local list\n", (const char *)cur
->data
);
3801 purple_account_privacy_permit_remove(account
, cur
->data
, TRUE
);
3807 next
= purple_account_privacy_get_denied(account
);
3808 while (next
!= NULL
) {
3811 if (!aim_ssi_itemlist_finditem(&od
->ssi
.local
, NULL
, cur
->data
, deny_entry_type
)) {
3812 purple_debug_info("oscar",
3813 "ssi: removing deny %s from local list\n", (const char *)cur
->data
);
3814 purple_account_privacy_deny_remove(account
, cur
->data
, TRUE
);
3818 /* Presence settings (idle time visibility) */
3819 tmp
= aim_ssi_getpresence(&od
->ssi
.local
);
3820 if (tmp
!= 0xFFFFFFFF) {
3821 const char *idle_reporting_pref
;
3822 gboolean report_idle
;
3824 idle_reporting_pref
= purple_prefs_get_string("/purple/away/idle_reporting");
3825 report_idle
= !purple_strequal(idle_reporting_pref
, "none");
3828 aim_ssi_setpresence(od
, tmp
| AIM_SSI_PRESENCE_FLAG_SHOWIDLE
);
3830 aim_ssi_setpresence(od
, tmp
& ~AIM_SSI_PRESENCE_FLAG_SHOWIDLE
);
3833 /*** End code for pruning buddies from local list ***/
3835 /*** Begin code for adding from server list to local list ***/
3837 for (curitem
=od
->ssi
.local
.data
; curitem
; curitem
=curitem
->next
) {
3838 if (curitem
->name
&& !g_utf8_validate(curitem
->name
, -1, NULL
)) {
3839 /* Got node with invalid UTF-8 in the name. Skip it. */
3840 purple_debug_warning("oscar", "ssi: server list contains item of "
3841 "type 0x%04hx with a non-utf8 name\n", curitem
->type
);
3845 switch (curitem
->type
) {
3846 case AIM_SSI_TYPE_BUDDY
: { /* Buddy */
3847 if (curitem
->name
) {
3848 struct aim_ssi_item
*groupitem
;
3849 char *gname
, *gname_utf8
, *alias
, *alias_utf8
;
3851 groupitem
= aim_ssi_itemlist_find(&od
->ssi
.local
, curitem
->gid
, 0x0000);
3852 gname
= groupitem
? groupitem
->name
: NULL
;
3853 gname_utf8
= oscar_utf8_try_convert(account
, od
, gname
);
3855 g
= purple_blist_find_group(gname_utf8
);
3857 g
= purple_group_new(gname_utf8
);
3858 purple_blist_add_group(g
, NULL
);
3861 alias
= aim_ssi_getalias_from_item(curitem
);
3862 alias_utf8
= oscar_utf8_try_convert(account
, od
, alias
);
3864 b
= purple_blist_find_buddy_in_group(account
, curitem
->name
, g
);
3866 /* Get server stored alias */
3867 purple_buddy_set_local_alias(b
, alias_utf8
);
3869 b
= purple_buddy_new(account
, curitem
->name
, alias_utf8
);
3871 purple_debug_info("oscar",
3872 "ssi: adding buddy %s to group %s to local list\n", curitem
->name
, gname
);
3873 purple_blist_add_buddy(b
, NULL
, g
, NULL
);
3876 /* Mobile users should always be online */
3877 if (curitem
->name
[0] == '+') {
3878 purple_protocol_got_user_status(account
,
3879 purple_buddy_get_name(b
),
3880 OSCAR_STATUS_ID_AVAILABLE
, NULL
);
3881 purple_protocol_got_user_status(account
,
3882 purple_buddy_get_name(b
),
3883 OSCAR_STATUS_ID_MOBILE
, NULL
);
3892 case AIM_SSI_TYPE_GROUP
: { /* Group */
3893 if (curitem
->name
!= NULL
&& purple_blist_find_group(curitem
->name
) == NULL
) {
3894 g
= purple_group_new(curitem
->name
);
3895 purple_blist_add_group(g
, NULL
);
3899 case AIM_SSI_TYPE_PERMIT
: { /* Permit buddy (unless we're on ICQ) */
3900 if (!od
->icq
&& curitem
->name
) {
3901 for (cur
= purple_account_privacy_get_permitted(account
); (cur
&& oscar_util_name_compare(curitem
->name
, cur
->data
)); cur
= cur
->next
);
3903 purple_debug_info("oscar",
3904 "ssi: adding permit buddy %s to local list\n", curitem
->name
);
3905 purple_account_privacy_permit_add(account
, curitem
->name
, TRUE
);
3910 case AIM_SSI_TYPE_ICQDENY
:
3911 case AIM_SSI_TYPE_DENY
: { /* Deny buddy */
3912 if (curitem
->type
== deny_entry_type
&& curitem
->name
) {
3913 for (cur
= purple_account_privacy_get_denied(account
); (cur
&& oscar_util_name_compare(curitem
->name
, cur
->data
)); cur
= cur
->next
);
3915 purple_debug_info("oscar",
3916 "ssi: adding deny buddy %s to local list\n", curitem
->name
);
3917 purple_account_privacy_deny_add(account
, curitem
->name
, TRUE
);
3922 case AIM_SSI_TYPE_PDINFO
: { /* Permit/deny setting */
3924 * We don't inherit the permit/deny setting from the server
3925 * for ICQ because, for ICQ, this setting controls who can
3926 * see your online status when you are invisible. Thus it is
3927 * a part of your status and not really related to blocking.
3929 if (!od
->icq
&& curitem
->data
) {
3930 guint8 perm_deny
= aim_ssi_getpermdeny(&od
->ssi
.local
);
3931 if (perm_deny
!= 0 && perm_deny
!= purple_account_get_privacy_type(account
))
3933 purple_debug_info("oscar",
3934 "ssi: changing permdeny from %d to %u\n", purple_account_get_privacy_type(account
), (guint
)perm_deny
);
3935 purple_account_set_privacy_type(account
, perm_deny
);
3940 case AIM_SSI_TYPE_PRESENCEPREFS
: { /* Presence setting */
3941 /* We don't want to change Purple's setting because it applies to all accounts */
3943 } /* End of switch on curitem->type */
3944 } /* End of for loop */
3946 /*** End code for adding from server list to local list ***/
3949 oscar_set_icq_permdeny(account
);
3951 oscar_set_aim_permdeny(gc
);
3955 /* Sending the enable causes other people to be able to see you, and you to see them */
3956 /* Make sure your privacy setting/invisibility is set how you want it before this! */
3957 purple_debug_info("oscar",
3958 "ssi: activating server-stored buddy list\n");
3962 * Make sure our server-stored icon is updated correctly in
3963 * the event that the local user set a new icon while this
3964 * account was offline.
3966 img
= purple_buddy_icons_find_account_icon(account
);
3967 oscar_set_icon(gc
, img
);
3968 g_object_unref(img
);
3971 * If we've already received our bos rights then we're not waiting on
3972 * anything else, so send the server clientready.
3974 if (od
->bos
.have_rights
) {
3975 aim_srv_clientready(od
, conn
);
3977 /* Request offline messages for AIM and ICQ */
3978 aim_im_reqofflinemsgs(od
);
3980 purple_connection_set_state(gc
, PURPLE_CONNECTION_CONNECTED
);
3986 static int purple_ssi_parseack(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...) {
3987 PurpleConnection
*gc
= od
->gc
;
3989 struct aim_ssi_tmp
*retval
;
3992 retval
= va_arg(ap
, struct aim_ssi_tmp
*);
3996 purple_debug_misc("oscar",
3997 "ssi: status is 0x%04hx for a 0x%04hx action with name %s\n", retval
->ack
, retval
->action
, retval
->item
? (retval
->item
->name
? retval
->item
->name
: "no name") : "no item");
3999 if (retval
->ack
!= 0xffff)
4000 switch (retval
->ack
) {
4001 case 0x0000: { /* added successfully */
4004 case 0x000c: { /* you are over the limit, the cheat is to the limit, come on fhqwhgads */
4006 buf
= g_strdup_printf(_("Unable to add the buddy %s because you have too many buddies in your buddy list. Please remove one and try again."), (retval
->name
? retval
->name
: _("(no name)")));
4007 if ((retval
->name
!= NULL
) && !purple_conversation_present_error(retval
->name
, purple_connection_get_account(gc
), buf
))
4008 purple_notify_error(gc
, NULL
, _("Unable to Add"), buf
, purple_request_cpar_from_connection(gc
));
4012 case 0x000e: { /* buddy requires authorization */
4013 if ((retval
->action
== SNAC_SUBTYPE_FEEDBAG_ADD
) && (retval
->name
))
4014 oscar_auth_sendrequest(gc
, retval
->name
, NULL
);
4017 default: { /* La la la */
4019 purple_debug_error("oscar", "ssi: Action 0x%04hx was unsuccessful with error 0x%04hx\n", retval
->action
, retval
->ack
);
4020 buf
= g_strdup_printf(_("Unable to add the buddy %s for an unknown reason."),
4021 (retval
->name
? retval
->name
: _("(no name)")));
4022 if ((retval
->name
!= NULL
) && !purple_conversation_present_error(retval
->name
, purple_connection_get_account(gc
), buf
))
4023 purple_notify_error(gc
, NULL
, _("Unable to Add"), buf
, purple_request_cpar_from_connection(gc
));
4028 retval
= retval
->next
;
4035 purple_ssi_parseaddmod(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...)
4037 PurpleConnection
*gc
;
4038 PurpleAccount
*account
;
4039 char *gname
, *gname_utf8
, *alias
, *alias_utf8
;
4042 struct aim_ssi_item
*ssi_item
;
4044 guint16 snac_subtype
, type
;
4048 account
= purple_connection_get_account(gc
);
4051 snac_subtype
= (guint16
)va_arg(ap
, int);
4052 type
= (guint16
)va_arg(ap
, int);
4053 name
= va_arg(ap
, char *);
4056 if ((type
!= 0x0000) || (name
== NULL
))
4059 gname
= aim_ssi_itemlist_findparentname(&od
->ssi
.local
, name
);
4060 gname_utf8
= gname
? oscar_utf8_try_convert(account
, od
, gname
) : NULL
;
4062 alias
= aim_ssi_getalias(&od
->ssi
.local
, gname
, name
);
4063 alias_utf8
= oscar_utf8_try_convert(account
, od
, alias
);
4066 b
= purple_blist_find_buddy(account
, name
);
4069 * You're logged in somewhere else and you aliased one
4070 * of your buddies, so update our local buddy list with
4071 * the person's new alias.
4073 purple_buddy_set_local_alias(b
, alias_utf8
);
4074 } else if (snac_subtype
== 0x0008) {
4076 * You're logged in somewhere else and you added a buddy to
4077 * your server list, so add them to your local buddy list.
4079 b
= purple_buddy_new(account
, name
, alias_utf8
);
4081 if (!(g
= purple_blist_find_group(gname_utf8
))) {
4082 g
= purple_group_new(gname_utf8
);
4083 purple_blist_add_group(g
, NULL
);
4086 purple_debug_info("oscar", "ssi: adding buddy %s to group %s to"
4087 " local list", name
, gname_utf8
? gname_utf8
: "(default)");
4088 purple_blist_add_buddy(b
, NULL
, g
, NULL
);
4090 /* Mobile users should always be online */
4091 if (name
[0] == '+') {
4092 purple_protocol_got_user_status(account
,
4093 name
, OSCAR_STATUS_ID_AVAILABLE
, NULL
);
4094 purple_protocol_got_user_status(account
,
4095 name
, OSCAR_STATUS_ID_MOBILE
, NULL
);
4100 ssi_item
= aim_ssi_itemlist_finditem(&od
->ssi
.local
,
4101 gname
, name
, AIM_SSI_TYPE_BUDDY
);
4102 if (ssi_item
== NULL
)
4104 purple_debug_error("oscar", "purple_ssi_parseaddmod: "
4105 "Could not find ssi item for oncoming buddy %s, "
4106 "group %s\n", name
, gname
);
4115 static int purple_ssi_authgiven(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...) {
4116 PurpleConnection
*gc
= od
->gc
;
4119 gchar
*dialog_msg
, *nombre
;
4120 struct name_data
*data
;
4124 bn
= va_arg(ap
, char *);
4125 va_arg(ap
, char *); /* msg */
4128 purple_debug_info("oscar",
4129 "ssi: %s has given you permission to add him to your buddy list\n", bn
);
4131 buddy
= purple_blist_find_buddy(purple_connection_get_account(gc
), bn
);
4132 if (buddy
&& (purple_buddy_get_alias_only(buddy
)))
4133 nombre
= g_strdup_printf("%s (%s)", bn
, purple_buddy_get_alias_only(buddy
));
4135 nombre
= g_strdup(bn
);
4137 dialog_msg
= g_strdup_printf(_("The user %s has given you permission to add him or her to your buddy list. Do you want to add this user?"), nombre
);
4140 data
= g_new(struct name_data
, 1);
4142 data
->name
= g_strdup(bn
);
4143 data
->nick
= (buddy
? g_strdup(purple_buddy_get_alias_only(buddy
)) : NULL
);
4145 purple_request_yes_no(gc
, NULL
, _("Authorization Given"), dialog_msg
,
4146 PURPLE_DEFAULT_ACTION_NONE
,
4147 purple_request_cpar_from_connection(gc
),
4149 G_CALLBACK(purple_icq_buddyadd
),
4150 G_CALLBACK(oscar_free_name_data
));
4156 static int purple_ssi_authrequest(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...)
4163 bn
= va_arg(ap
, const char *);
4164 msg
= va_arg(ap
, char *);
4167 purple_debug_info("oscar",
4168 "ssi: received authorization request from %s\n", bn
);
4171 purple_debug_warning("oscar", "Received auth request from %s with "
4172 "empty message\n", bn
);
4173 } else if (!g_utf8_validate(msg
, -1, NULL
)) {
4174 purple_debug_warning("oscar", "Received auth request from %s with "
4175 "invalid UTF-8 message\n", bn
);
4179 aim_icq_getalias(od
, bn
, TRUE
, msg
);
4183 static int purple_ssi_authreply(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...) {
4184 PurpleConnection
*gc
= od
->gc
;
4187 gchar
*dialog_msg
, *nombre
;
4192 bn
= va_arg(ap
, char *);
4193 reply
= (guint8
)va_arg(ap
, int);
4194 msg
= va_arg(ap
, char *);
4197 purple_debug_info("oscar",
4198 "ssi: received authorization reply from %s. Reply is 0x%02hx\n", bn
, (guint16
)reply
);
4200 buddy
= purple_blist_find_buddy(purple_connection_get_account(gc
), bn
);
4201 if (buddy
&& (purple_buddy_get_alias_only(buddy
)))
4202 nombre
= g_strdup_printf("%s (%s)", bn
, purple_buddy_get_alias_only(buddy
));
4204 nombre
= g_strdup(bn
);
4208 dialog_msg
= g_strdup_printf(_("The user %s has granted your request to add them to your buddy list."), nombre
);
4209 purple_notify_info(gc
, NULL
, _("Authorization Granted"),
4210 dialog_msg
, purple_request_cpar_from_connection(gc
));
4213 dialog_msg
= g_strdup_printf(_("The user %s has denied your request to add them to your buddy list for the following reason:\n%s"), nombre
, msg
? msg
: _("No reason given."));
4214 purple_notify_info(gc
, NULL
, _("Authorization Denied"),
4215 dialog_msg
, purple_request_cpar_from_connection(gc
));
4223 static int purple_ssi_gotadded(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...) {
4224 PurpleConnection
*gc
= od
->gc
;
4225 PurpleAccount
*account
= purple_connection_get_account(gc
);
4231 bn
= va_arg(ap
, char *);
4234 buddy
= purple_blist_find_buddy(account
, bn
);
4235 purple_debug_info("oscar", "ssi: %s added you to their buddy list\n", bn
);
4236 purple_account_notify_added(account
, bn
, NULL
,
4237 (buddy
? purple_buddy_get_alias_only(buddy
) : NULL
), NULL
);
4242 GList
*oscar_chat_info(PurpleConnection
*gc
) {
4244 PurpleProtocolChatEntry
*pce
;
4246 pce
= g_new0(PurpleProtocolChatEntry
, 1);
4247 pce
->label
= _("_Room:");
4248 pce
->identifier
= "room";
4249 pce
->required
= TRUE
;
4250 m
= g_list_append(m
, pce
);
4252 pce
= g_new0(PurpleProtocolChatEntry
, 1);
4253 pce
->label
= _("_Exchange:");
4254 pce
->identifier
= "exchange";
4255 pce
->required
= TRUE
;
4259 m
= g_list_append(m
, pce
);
4264 GHashTable
*oscar_chat_info_defaults(PurpleConnection
*gc
, const char *chat_name
)
4266 GHashTable
*defaults
;
4268 defaults
= g_hash_table_new_full(g_str_hash
, g_str_equal
, NULL
, g_free
);
4270 if (chat_name
!= NULL
)
4271 g_hash_table_insert(defaults
, "room", g_strdup(chat_name
));
4272 g_hash_table_insert(defaults
, "exchange", g_strdup("4"));
4278 oscar_get_chat_name(GHashTable
*data
)
4280 return g_strdup(g_hash_table_lookup(data
, "room"));
4284 oscar_join_chat(PurpleConnection
*gc
, GHashTable
*data
)
4286 OscarData
*od
= purple_connection_get_protocol_data(gc
);
4287 FlapConnection
*conn
;
4288 char *name
, *exchange
;
4291 name
= g_hash_table_lookup(data
, "room");
4292 exchange
= g_hash_table_lookup(data
, "exchange");
4294 g_return_if_fail(name
!= NULL
&& *name
!= '\0');
4295 g_return_if_fail(exchange
!= NULL
);
4298 exchange_int
= strtol(exchange
, NULL
, 10);
4299 g_return_if_fail(errno
== 0);
4301 purple_debug_info("oscar", "Attempting to join chat room %s.\n", name
);
4303 if ((conn
= flap_connection_getbytype(od
, SNAC_FAMILY_CHATNAV
)))
4305 purple_debug_info("oscar", "chatnav exists, creating room\n");
4306 aim_chatnav_createroom(od
, conn
, name
, exchange_int
);
4308 /* this gets tricky */
4309 struct create_room
*cr
= g_new0(struct create_room
, 1);
4310 purple_debug_info("oscar", "chatnav does not exist, opening chatnav\n");
4311 cr
->exchange
= exchange_int
;
4312 cr
->name
= g_strdup(name
);
4313 od
->create_rooms
= g_slist_prepend(od
->create_rooms
, cr
);
4314 aim_srv_requestnew(od
, SNAC_FAMILY_CHATNAV
);
4319 oscar_chat_invite(PurpleConnection
*gc
, int id
, const char *message
, const char *name
)
4321 OscarData
*od
= purple_connection_get_protocol_data(gc
);
4322 struct chat_connection
*ccon
= find_oscar_chat(gc
, id
);
4327 aim_im_sendch2_chatinvite(od
, name
, message
? message
: "",
4328 ccon
->exchange
, ccon
->name
, 0x0);
4332 oscar_chat_leave(PurpleConnection
*gc
, int id
)
4334 PurpleChatConversation
*conv
;
4335 struct chat_connection
*cc
;
4337 conv
= purple_conversations_find_chat(gc
, id
);
4339 g_return_if_fail(conv
!= NULL
);
4341 purple_debug_info("oscar", "Leaving chat room %s\n",
4342 purple_conversation_get_name(PURPLE_CONVERSATION(conv
)));
4344 cc
= find_oscar_chat(gc
, purple_chat_conversation_get_id(conv
));
4345 flap_connection_schedule_destroy(cc
->conn
, OSCAR_DISCONNECT_DONE
, NULL
);
4346 oscar_chat_kill(gc
, cc
);
4349 int oscar_send_chat(PurpleConnection
*gc
, int id
, PurpleMessage
*msg
)
4351 OscarData
*od
= purple_connection_get_protocol_data(gc
);
4352 PurpleChatConversation
*conv
= NULL
;
4353 struct chat_connection
*c
= NULL
;
4354 char *buf
, *buf2
, *buf3
;
4358 const gchar
*message
= purple_message_get_contents(msg
);
4360 if (!(conv
= purple_conversations_find_chat(gc
, id
)))
4363 if (!(c
= find_oscar_chat_by_conv(gc
, conv
)))
4366 buf
= purple_strdup_withhtml(message
);
4368 if (strstr(buf
, "<img ")) {
4369 purple_conversation_write_system_message(PURPLE_CONVERSATION(conv
),
4370 _("Your IM Image was not sent. "
4371 "You cannot send IM Images in AIM chats."),
4372 PURPLE_MESSAGE_ERROR
);
4375 buf2
= oscar_encode_im(buf
, &len
, &charset
, &charsetstr
);
4377 * Evan S. suggested that maxvis really does mean "number of
4378 * visible characters" and not "number of bytes"
4380 if ((len
> c
->maxlen
) || (len
> c
->maxvis
)) {
4381 /* If the length was too long, try stripping the HTML and then running it back through
4382 * purple_strdup_withhtml() and the encoding process. The result may be shorter. */
4385 buf3
= purple_markup_strip_html(buf
);
4388 buf
= purple_strdup_withhtml(buf3
);
4391 buf2
= oscar_encode_im(buf
, &len
, &charset
, &charsetstr
);
4393 if ((len
> c
->maxlen
) || (len
> c
->maxvis
)) {
4394 purple_debug_warning("oscar",
4395 "Could not send %s because (%" G_GSIZE_FORMAT
" > maxlen %i) or (%" G_GSIZE_FORMAT
" > maxvis %i)\n",
4396 buf2
, len
, c
->maxlen
, len
, c
->maxvis
);
4402 purple_debug_info("oscar", "Sending %s as %s because the original was too long.\n",
4406 aim_chat_send_im(od
, c
->conn
, 0, buf2
, len
, charsetstr
, "en");
4413 PurpleMood
* oscar_get_purple_moods(PurpleAccount
*account
)
4415 return icq_get_purple_moods(account
);
4418 const char *oscar_list_icon_icq(PurpleAccount
*a
, PurpleBuddy
*b
)
4420 const char *name
= b
? purple_buddy_get_name(b
) : NULL
;
4421 if (name
&& !oscar_util_valid_name_sms(name
) && oscar_util_valid_name_icq(name
))
4427 const char *oscar_list_icon_aim(PurpleAccount
*a
, PurpleBuddy
*b
)
4429 const char *name
= b
? purple_buddy_get_name(b
) : NULL
;
4430 if (name
&& !oscar_util_valid_name_sms(name
) && oscar_util_valid_name_icq(name
))
4436 const char *oscar_list_emblem(PurpleBuddy
*b
)
4438 PurpleConnection
*gc
= NULL
;
4439 OscarData
*od
= NULL
;
4440 PurpleAccount
*account
= NULL
;
4441 PurplePresence
*presence
;
4442 aim_userinfo_t
*userinfo
= NULL
;
4445 account
= purple_buddy_get_account(b
);
4446 name
= purple_buddy_get_name(b
);
4447 if (account
!= NULL
)
4448 gc
= purple_account_get_connection(account
);
4450 od
= purple_connection_get_protocol_data(gc
);
4452 userinfo
= aim_locate_finduserinfo(od
, name
);
4454 presence
= purple_buddy_get_presence(b
);
4456 if (purple_presence_is_online(presence
) == FALSE
) {
4458 if ((name
) && (od
) && (od
->ssi
.received_data
) &&
4459 (gname
= aim_ssi_itemlist_findparentname(&od
->ssi
.local
, name
)) &&
4460 (aim_ssi_waitingforauth(&od
->ssi
.local
, gname
, name
))) {
4461 return "not-authorized";
4465 if (userinfo
!= NULL
) {
4466 if (userinfo
->flags
& AIM_FLAG_ADMINISTRATOR
)
4468 if (userinfo
->flags
& AIM_FLAG_ACTIVEBUDDY
)
4470 if (userinfo
->capabilities
& OSCAR_CAPABILITY_SECUREIM
)
4472 if (userinfo
->icqinfo
.status
& AIM_ICQ_STATE_BIRTHDAY
)
4475 /* Make the mood icon override anything below this. */
4476 if (purple_presence_is_status_primitive_active(presence
, PURPLE_STATUS_MOOD
))
4479 if (userinfo
->capabilities
& OSCAR_CAPABILITY_HIPTOP
)
4485 void oscar_tooltip_text(PurpleBuddy
*b
, PurpleNotifyUserInfo
*user_info
, gboolean full
)
4487 PurpleConnection
*gc
;
4488 PurpleAccount
*account
;
4490 aim_userinfo_t
*userinfo
;
4492 if (!PURPLE_BUDDY_IS_ONLINE(b
))
4495 account
= purple_buddy_get_account(b
);
4496 gc
= purple_account_get_connection(account
);
4497 od
= purple_connection_get_protocol_data(gc
);
4498 userinfo
= aim_locate_finduserinfo(od
, purple_buddy_get_name(b
));
4500 oscar_user_info_append_status(gc
, user_info
, b
, userinfo
, /* use_html_status */ FALSE
);
4503 oscar_user_info_append_extra_info(gc
, user_info
, b
, userinfo
);
4506 char *oscar_status_text(PurpleBuddy
*b
)
4508 PurpleConnection
*gc
;
4509 PurpleAccount
*account
;
4511 PurplePresence
*presence
;
4512 PurpleStatus
*status
;
4513 const char *message
;
4516 gc
= purple_account_get_connection(purple_buddy_get_account(b
));
4517 account
= purple_connection_get_account(gc
);
4518 od
= purple_connection_get_protocol_data(gc
);
4519 presence
= purple_buddy_get_presence(b
);
4520 status
= purple_presence_get_active_status(presence
);
4522 if ((od
!= NULL
) && !purple_presence_is_online(presence
))
4524 const char *name
= purple_buddy_get_name(b
);
4525 char *gname
= aim_ssi_itemlist_findparentname(&od
->ssi
.local
, name
);
4526 if (aim_ssi_waitingforauth(&od
->ssi
.local
, gname
, name
))
4527 ret
= g_strdup(_("Not Authorized"));
4529 ret
= g_strdup(_("Offline"));
4533 message
= purple_status_get_attr_string(status
, "message");
4534 if (message
!= NULL
)
4536 gchar
*tmp
= oscar_util_format_string(message
, purple_account_get_username(account
));
4537 ret
= purple_markup_escape_text(tmp
, -1);
4540 else if (purple_status_is_available(status
))
4542 /* Don't show "Available" as status message in case buddy doesn't have a status message */
4546 ret
= g_strdup(purple_status_get_name(status
));
4553 void oscar_set_aim_permdeny(PurpleConnection
*gc
) {
4554 PurpleAccount
*account
= purple_connection_get_account(gc
);
4555 OscarData
*od
= purple_connection_get_protocol_data(gc
);
4558 * Conveniently there is a one-to-one mapping between the
4559 * values of libpurple's PurplePrivacyType and the values used
4560 * by the oscar protocol.
4562 aim_ssi_setpermdeny(od
, purple_account_get_privacy_type(account
));
4565 void oscar_add_permit(PurpleConnection
*gc
, const char *who
) {
4566 OscarData
*od
= purple_connection_get_protocol_data(gc
);
4567 purple_debug_info("oscar", "ssi: About to add a permit\n");
4568 aim_ssi_add_to_private_list(od
, who
, AIM_SSI_TYPE_PERMIT
);
4571 void oscar_add_deny(PurpleConnection
*gc
, const char *who
) {
4572 OscarData
*od
= purple_connection_get_protocol_data(gc
);
4573 purple_debug_info("oscar", "ssi: About to add a deny\n");
4574 aim_ssi_add_to_private_list(od
, who
, aim_ssi_getdenyentrytype(od
));
4577 void oscar_rem_permit(PurpleConnection
*gc
, const char *who
) {
4578 OscarData
*od
= purple_connection_get_protocol_data(gc
);
4579 purple_debug_info("oscar", "ssi: About to delete a permit\n");
4580 aim_ssi_del_from_private_list(od
, who
, AIM_SSI_TYPE_PERMIT
);
4583 void oscar_rem_deny(PurpleConnection
*gc
, const char *who
) {
4584 OscarData
*od
= purple_connection_get_protocol_data(gc
);
4585 purple_debug_info("oscar", "ssi: About to delete a deny\n");
4586 aim_ssi_del_from_private_list(od
, who
, aim_ssi_getdenyentrytype(od
));
4590 oscar_status_types(PurpleAccount
*account
)
4593 GList
*status_types
= NULL
;
4594 PurpleStatusType
*type
;
4596 g_return_val_if_fail(account
!= NULL
, NULL
);
4598 /* Used to flag some statuses as "user settable" or not */
4599 is_icq
= oscar_util_valid_name_icq(purple_account_get_username(account
));
4601 /* Common status types */
4602 /* Really the available message should only be settable for AIM accounts */
4603 type
= purple_status_type_new_with_attrs(PURPLE_STATUS_AVAILABLE
,
4604 OSCAR_STATUS_ID_AVAILABLE
,
4605 NULL
, TRUE
, TRUE
, FALSE
,
4606 "message", _("Message"),
4607 purple_value_new(G_TYPE_STRING
),
4608 "itmsurl", _("iTunes Music Store Link"),
4609 purple_value_new(G_TYPE_STRING
), NULL
);
4610 status_types
= g_list_prepend(status_types
, type
);
4612 type
= purple_status_type_new_with_attrs(PURPLE_STATUS_AVAILABLE
,
4613 OSCAR_STATUS_ID_FREE4CHAT
,
4614 _("Free For Chat"), TRUE
, is_icq
, FALSE
,
4615 "message", _("Message"),
4616 purple_value_new(G_TYPE_STRING
), NULL
);
4618 status_types
= g_list_prepend(status_types
, type
);
4620 type
= purple_status_type_new_with_attrs(PURPLE_STATUS_AVAILABLE
,
4621 OSCAR_STATUS_ID_EVIL
,
4622 _("Evil"), TRUE
, is_icq
, FALSE
,
4623 "message", _("Message"),
4624 purple_value_new(G_TYPE_STRING
), NULL
);
4625 status_types
= g_list_prepend(status_types
, type
);
4628 type
= purple_status_type_new_with_attrs(PURPLE_STATUS_AVAILABLE
,
4629 OSCAR_STATUS_ID_DEPRESSION
,
4630 _("Depression"), TRUE
, is_icq
, FALSE
,
4631 "message", _("Message"),
4632 purple_value_new(G_TYPE_STRING
), NULL
);
4633 status_types
= g_list_prepend(status_types
, type
);
4636 type
= purple_status_type_new_with_attrs(PURPLE_STATUS_AVAILABLE
,
4637 OSCAR_STATUS_ID_ATHOME
,
4638 _("At home"), TRUE
, is_icq
, FALSE
,
4639 "message", _("Message"),
4640 purple_value_new(G_TYPE_STRING
), NULL
);
4641 status_types
= g_list_prepend(status_types
, type
);
4644 type
= purple_status_type_new_with_attrs(PURPLE_STATUS_AVAILABLE
,
4645 OSCAR_STATUS_ID_ATWORK
,
4646 _("At work"), TRUE
, is_icq
, FALSE
,
4647 "message", _("Message"),
4648 purple_value_new(G_TYPE_STRING
), NULL
);
4650 status_types
= g_list_prepend(status_types
, type
);
4653 type
= purple_status_type_new_with_attrs(PURPLE_STATUS_AVAILABLE
,
4654 OSCAR_STATUS_ID_LUNCH
,
4655 _("Lunch"), TRUE
, is_icq
, FALSE
,
4656 "message", _("Message"),
4657 purple_value_new(G_TYPE_STRING
), NULL
);
4659 status_types
= g_list_prepend(status_types
, type
);
4661 type
= purple_status_type_new_with_attrs(PURPLE_STATUS_AWAY
,
4662 OSCAR_STATUS_ID_AWAY
,
4663 NULL
, TRUE
, TRUE
, FALSE
,
4664 "message", _("Message"),
4665 purple_value_new(G_TYPE_STRING
), NULL
);
4666 status_types
= g_list_prepend(status_types
, type
);
4668 type
= purple_status_type_new_with_attrs(PURPLE_STATUS_INVISIBLE
,
4669 OSCAR_STATUS_ID_INVISIBLE
,
4670 NULL
, TRUE
, TRUE
, FALSE
,
4671 "message", _("Message"),
4672 purple_value_new(G_TYPE_STRING
), NULL
);
4674 status_types
= g_list_prepend(status_types
, type
);
4676 type
= purple_status_type_new_full(PURPLE_STATUS_MOBILE
, OSCAR_STATUS_ID_MOBILE
, NULL
, FALSE
, FALSE
, TRUE
);
4677 status_types
= g_list_prepend(status_types
, type
);
4679 /* ICQ-specific status types */
4680 type
= purple_status_type_new_with_attrs(PURPLE_STATUS_UNAVAILABLE
,
4681 OSCAR_STATUS_ID_OCCUPIED
,
4682 _("Occupied"), TRUE
, is_icq
, FALSE
,
4683 "message", _("Message"),
4684 purple_value_new(G_TYPE_STRING
), NULL
);
4685 status_types
= g_list_prepend(status_types
, type
);
4687 type
= purple_status_type_new_with_attrs(PURPLE_STATUS_UNAVAILABLE
,
4688 OSCAR_STATUS_ID_DND
,
4689 _("Do Not Disturb"), TRUE
, is_icq
, FALSE
,
4690 "message", _("Message"),
4691 purple_value_new(G_TYPE_STRING
), NULL
);
4692 status_types
= g_list_prepend(status_types
, type
);
4694 type
= purple_status_type_new_with_attrs(PURPLE_STATUS_EXTENDED_AWAY
,
4696 _("Not Available"), TRUE
, is_icq
, FALSE
,
4697 "message", _("Message"),
4698 purple_value_new(G_TYPE_STRING
), NULL
);
4699 status_types
= g_list_prepend(status_types
, type
);
4701 type
= purple_status_type_new_full(PURPLE_STATUS_OFFLINE
,
4702 OSCAR_STATUS_ID_OFFLINE
,
4703 NULL
, TRUE
, TRUE
, FALSE
);
4704 status_types
= g_list_prepend(status_types
, type
);
4706 type
= purple_status_type_new_with_attrs(PURPLE_STATUS_MOOD
,
4707 "mood", NULL
, TRUE
, is_icq
, TRUE
,
4708 PURPLE_MOOD_NAME
, _("Mood Name"), purple_value_new(G_TYPE_STRING
),
4709 PURPLE_MOOD_COMMENT
, _("Mood Comment"), purple_value_new(G_TYPE_STRING
),
4711 status_types
= g_list_prepend(status_types
, type
);
4713 return g_list_reverse(status_types
);
4716 static void oscar_ssi_editcomment(struct name_data
*data
, const char *text
) {
4717 PurpleConnection
*gc
;
4718 PurpleAccount
*account
;
4724 od
= purple_connection_get_protocol_data(gc
);
4725 account
= purple_connection_get_account(gc
);
4727 b
= purple_blist_find_buddy(account
, data
->name
);
4729 oscar_free_name_data(data
);
4733 g
= purple_buddy_get_group(b
);
4735 oscar_free_name_data(data
);
4739 aim_ssi_editcomment(od
, purple_group_get_name(g
), data
->name
, text
);
4740 oscar_free_name_data(data
);
4743 static void oscar_buddycb_edit_comment(PurpleBlistNode
*node
, gpointer ignore
) {
4746 PurpleConnection
*gc
;
4748 struct name_data
*data
;
4751 gchar
*comment_utf8
;
4753 PurpleAccount
*account
;
4756 g_return_if_fail(PURPLE_IS_BUDDY(node
));
4758 buddy
= (PurpleBuddy
*) node
;
4759 name
= purple_buddy_get_name(buddy
);
4760 account
= purple_buddy_get_account(buddy
);
4761 gc
= purple_account_get_connection(account
);
4762 od
= purple_connection_get_protocol_data(gc
);
4764 if (!(g
= purple_buddy_get_group(buddy
)))
4767 data
= g_new(struct name_data
, 1);
4769 comment
= aim_ssi_getcomment(&od
->ssi
.local
, purple_group_get_name(g
), name
);
4770 comment_utf8
= comment
? oscar_utf8_try_convert(account
, od
, comment
) : NULL
;
4773 data
->name
= g_strdup(name
);
4774 data
->nick
= g_strdup(purple_buddy_get_alias_only(buddy
));
4776 title
= g_strdup_printf(_("Buddy Comment for %s"), data
->name
);
4777 purple_request_input(gc
, title
, _("Buddy Comment:"), NULL
,
4778 comment_utf8
, TRUE
, FALSE
, NULL
,
4779 _("_OK"), G_CALLBACK(oscar_ssi_editcomment
),
4780 _("_Cancel"), G_CALLBACK(oscar_free_name_data
),
4781 purple_request_cpar_from_connection(gc
),
4786 g_free(comment_utf8
);
4790 oscar_ask_directim_yes_cb(struct oscar_ask_directim_data
*data
)
4792 peer_connection_propose(data
->od
, OSCAR_CAPABILITY_DIRECTIM
, data
->who
);
4798 oscar_ask_directim_no_cb(struct oscar_ask_directim_data
*data
)
4804 /* This is called from right-click menu on a buddy node. */
4806 oscar_ask_directim(gpointer object
, gpointer ignored
)
4808 PurpleBlistNode
*node
;
4810 PurpleConnection
*gc
;
4812 struct oscar_ask_directim_data
*data
;
4813 PurpleAccount
*account
;
4817 g_return_if_fail(PURPLE_IS_BUDDY(node
));
4819 buddy
= (PurpleBuddy
*)node
;
4820 account
= purple_buddy_get_account(buddy
);
4821 gc
= purple_account_get_connection(account
);
4823 data
= g_new0(struct oscar_ask_directim_data
, 1);
4824 data
->who
= g_strdup(purple_buddy_get_name(buddy
));
4825 data
->od
= purple_connection_get_protocol_data(gc
);
4826 buf
= g_strdup_printf(_("You have selected to open a Direct IM connection with %s."),
4829 purple_request_action(gc
, NULL
, buf
,
4830 _("Because this reveals your IP address, it "
4831 "may be considered a security risk. Do you "
4832 "wish to continue?"),
4833 0, /* Default action is "connect" */
4834 purple_request_cpar_from_account(account
),
4836 _("C_onnect"), G_CALLBACK(oscar_ask_directim_yes_cb
),
4837 _("_Cancel"), G_CALLBACK(oscar_ask_directim_no_cb
));
4842 oscar_close_directim(gpointer object
, gpointer ignored
)
4844 PurpleBlistNode
*node
;
4846 PurpleAccount
*account
;
4847 PurpleConnection
*gc
;
4848 PurpleIMConversation
*im
;
4850 PeerConnection
*conn
;
4855 g_return_if_fail(PURPLE_IS_BUDDY(node
));
4857 buddy
= (PurpleBuddy
*)node
;
4858 name
= purple_buddy_get_name(buddy
);
4859 account
= purple_buddy_get_account(buddy
);
4860 gc
= purple_account_get_connection(account
);
4861 od
= purple_connection_get_protocol_data(gc
);
4862 conn
= peer_connection_find_by_type(od
, name
, OSCAR_CAPABILITY_DIRECTIM
);
4867 aim_im_sendch2_cancel(conn
);
4869 peer_connection_destroy(conn
, OSCAR_DISCONNECT_LOCAL_CLOSED
, NULL
);
4871 /* OSCAR_DISCONNECT_LOCAL_CLOSED doesn't write anything to the convo
4872 * window. Let the user know that we cancelled the Direct IM. */
4873 im
= purple_im_conversation_new(account
, name
);
4874 purple_conversation_write_system_message(
4875 PURPLE_CONVERSATION(im
), _("You closed the connection."), 0);
4879 static void oscar_get_icqxstatusmsg(PurpleBlistNode
*node
, gpointer ignore
)
4882 PurpleConnection
*gc
;
4884 PurpleAccount
*account
;
4887 g_return_if_fail(PURPLE_IS_BUDDY(node
));
4889 buddy
= (PurpleBuddy
*)node
;
4890 bname
= purple_buddy_get_name(buddy
);
4892 account
= purple_buddy_get_account(buddy
);
4893 gc
= purple_account_get_connection(account
);
4894 od
= purple_connection_get_protocol_data(gc
);
4896 purple_debug_info("oscar", "Manual X-Status Get From %s to %s:\n", bname
, purple_account_get_username(account
));
4898 icq_im_xstatus_request(od
, bname
);
4902 oscar_get_aim_info_cb(PurpleBlistNode
*node
, gpointer ignore
)
4905 PurpleConnection
*gc
;
4907 g_return_if_fail(PURPLE_IS_BUDDY(node
));
4909 buddy
= (PurpleBuddy
*)node
;
4910 gc
= purple_account_get_connection(purple_buddy_get_account(buddy
));
4912 aim_locate_getinfoshort(purple_connection_get_protocol_data(gc
),
4913 purple_buddy_get_name(buddy
), 0x00000003);
4917 oscar_buddy_menu(PurpleBuddy
*buddy
) {
4918 PurpleConnection
*gc
;
4921 PurpleActionMenu
*act
;
4922 aim_userinfo_t
*userinfo
;
4923 PurpleAccount
*account
;
4924 const char *bname
= purple_buddy_get_name(buddy
);
4926 account
= purple_buddy_get_account(buddy
);
4927 gc
= purple_account_get_connection(account
);
4928 od
= purple_connection_get_protocol_data(gc
);
4929 userinfo
= aim_locate_finduserinfo(od
, bname
);
4932 if (od
->icq
&& oscar_util_valid_name_icq(bname
))
4934 act
= purple_action_menu_new(_("Get AIM Info"),
4935 PURPLE_CALLBACK(oscar_get_aim_info_cb
),
4937 menu
= g_list_prepend(menu
, act
);
4940 if (purple_buddy_get_group(buddy
) != NULL
)
4942 /* We only do this if the user is in our buddy list */
4943 act
= purple_action_menu_new(_("Edit Buddy Comment"),
4944 PURPLE_CALLBACK(oscar_buddycb_edit_comment
),
4946 menu
= g_list_prepend(menu
, act
);
4951 act
= purple_action_menu_new(_("Get X-Status Msg"),
4952 PURPLE_CALLBACK(oscar_get_icqxstatusmsg
),
4954 menu
= g_list_prepend(menu
, act
);
4955 menu
= g_list_prepend(menu
, create_visibility_menu_item(od
, bname
));
4959 oscar_util_name_compare(purple_account_get_username(account
), bname
) &&
4960 PURPLE_BUDDY_IS_ONLINE(buddy
))
4962 PeerConnection
*conn
;
4963 conn
= peer_connection_find_by_type(od
, bname
, OSCAR_CAPABILITY_DIRECTIM
);
4965 if (userinfo
->capabilities
& OSCAR_CAPABILITY_DIRECTIM
)
4969 act
= purple_action_menu_new(_("End Direct IM Session"),
4970 PURPLE_CALLBACK(oscar_close_directim
),
4975 act
= purple_action_menu_new(_("Direct IM"),
4976 PURPLE_CALLBACK(oscar_ask_directim
),
4979 menu
= g_list_prepend(menu
, act
);
4983 if (od
->ssi
.received_data
&& purple_buddy_get_group(buddy
) != NULL
)
4986 * We only do this if the user is in our buddy list and we're
4987 * waiting for authorization.
4990 gname
= aim_ssi_itemlist_findparentname(&od
->ssi
.local
, bname
);
4991 if (gname
&& aim_ssi_waitingforauth(&od
->ssi
.local
, gname
, bname
))
4993 act
= purple_action_menu_new(_("Re-request Authorization"),
4994 PURPLE_CALLBACK(oscar_auth_sendrequest_menu
),
4996 menu
= g_list_prepend(menu
, act
);
5000 menu
= g_list_reverse(menu
);
5006 GList
*oscar_blist_node_menu(PurpleBlistNode
*node
) {
5007 if(PURPLE_IS_BUDDY(node
)) {
5008 return oscar_buddy_menu((PurpleBuddy
*) node
);
5015 oscar_icq_privacy_opts(PurpleConnection
*gc
, PurpleRequestFields
*fields
)
5017 OscarData
*od
= purple_connection_get_protocol_data(gc
);
5018 PurpleAccount
*account
= purple_connection_get_account(gc
);
5019 PurpleRequestField
*f
;
5020 gboolean auth
, web_aware
;
5022 f
= purple_request_fields_get_field(fields
, "authorization");
5023 auth
= purple_request_field_bool_get_value(f
);
5025 f
= purple_request_fields_get_field(fields
, "web_aware");
5026 web_aware
= purple_request_field_bool_get_value(f
);
5028 purple_account_set_bool(account
, "authorization", auth
);
5029 purple_account_set_bool(account
, "web_aware", web_aware
);
5031 oscar_set_extended_status(gc
);
5032 aim_icq_setsecurity(od
, auth
, web_aware
);
5036 oscar_show_icq_privacy_opts(PurpleProtocolAction
*action
)
5038 PurpleConnection
*gc
= action
->connection
;
5039 PurpleAccount
*account
= purple_connection_get_account(gc
);
5040 PurpleRequestFields
*fields
;
5041 PurpleRequestFieldGroup
*g
;
5042 PurpleRequestField
*f
;
5043 gboolean auth
, web_aware
;
5045 auth
= purple_account_get_bool(account
, "authorization", OSCAR_DEFAULT_AUTHORIZATION
);
5046 web_aware
= purple_account_get_bool(account
, "web_aware", OSCAR_DEFAULT_WEB_AWARE
);
5048 fields
= purple_request_fields_new();
5050 g
= purple_request_field_group_new(NULL
);
5052 f
= purple_request_field_bool_new("authorization", _("Require authorization"), auth
);
5053 purple_request_field_group_add_field(g
, f
);
5055 f
= purple_request_field_bool_new("web_aware", _("Web aware (enabling this will cause you to receive SPAM!)"), web_aware
);
5056 purple_request_field_group_add_field(g
, f
);
5058 purple_request_fields_add_group(fields
, g
);
5060 purple_request_fields(gc
, _("ICQ Privacy Options"), _("ICQ Privacy Options"),
5062 _("OK"), G_CALLBACK(oscar_icq_privacy_opts
),
5064 purple_request_cpar_from_connection(gc
),
5068 static void oscar_confirm_account(PurpleProtocolAction
*action
)
5070 PurpleConnection
*gc
;
5072 FlapConnection
*conn
;
5074 gc
= action
->connection
;
5075 od
= purple_connection_get_protocol_data(gc
);
5077 conn
= flap_connection_getbytype(od
, SNAC_FAMILY_ADMIN
);
5079 aim_admin_reqconfirm(od
, conn
);
5082 aim_srv_requestnew(od
, SNAC_FAMILY_ADMIN
);
5086 static void oscar_show_email(PurpleProtocolAction
*action
)
5088 PurpleConnection
*gc
= action
->connection
;
5089 OscarData
*od
= purple_connection_get_protocol_data(gc
);
5090 FlapConnection
*conn
= flap_connection_getbytype(od
, SNAC_FAMILY_ADMIN
);
5093 aim_admin_getinfo(od
, conn
, 0x11);
5095 od
->reqemail
= TRUE
;
5096 aim_srv_requestnew(od
, SNAC_FAMILY_ADMIN
);
5100 static void oscar_change_email(PurpleConnection
*gc
, const char *email
)
5102 OscarData
*od
= purple_connection_get_protocol_data(gc
);
5103 FlapConnection
*conn
= flap_connection_getbytype(od
, SNAC_FAMILY_ADMIN
);
5106 aim_admin_setemail(od
, conn
, email
);
5108 od
->setemail
= TRUE
;
5109 od
->email
= g_strdup(email
);
5110 aim_srv_requestnew(od
, SNAC_FAMILY_ADMIN
);
5114 static void oscar_show_change_email(PurpleProtocolAction
*action
)
5116 PurpleConnection
*gc
= action
->connection
;
5117 purple_request_input(gc
, NULL
, _("Change Address To:"), NULL
, NULL
,
5119 _("_OK"), G_CALLBACK(oscar_change_email
),
5121 purple_request_cpar_from_connection(gc
),
5125 static void oscar_show_awaitingauth(PurpleProtocolAction
*action
)
5127 PurpleConnection
*gc
= action
->connection
;
5128 OscarData
*od
= purple_connection_get_protocol_data(gc
);
5129 PurpleAccount
*account
= purple_connection_get_account(gc
);
5130 GSList
*buddies
, *filtered_buddies
, *cur
;
5133 buddies
= purple_blist_find_buddies(account
, NULL
);
5134 filtered_buddies
= NULL
;
5135 for (cur
= buddies
; cur
!= NULL
; cur
= cur
->next
) {
5137 const gchar
*bname
, *gname
;
5140 bname
= purple_buddy_get_name(buddy
);
5141 gname
= purple_group_get_name(purple_buddy_get_group(buddy
));
5142 if (aim_ssi_waitingforauth(&od
->ssi
.local
, gname
, bname
)) {
5143 filtered_buddies
= g_slist_prepend(filtered_buddies
, buddy
);
5147 g_slist_free(buddies
);
5149 filtered_buddies
= g_slist_reverse(filtered_buddies
);
5150 text
= oscar_format_buddies(filtered_buddies
, _("you are not waiting for authorization"));
5151 g_slist_free(filtered_buddies
);
5153 purple_notify_formatted(gc
, NULL
, _("You are awaiting authorization from "
5154 "the following buddies"), _("You can re-request "
5155 "authorization from these buddies by "
5156 "right-clicking on them and selecting "
5157 "\"Re-request Authorization.\""), text
, NULL
, NULL
);
5161 static void search_by_email_cb(PurpleConnection
*gc
, const char *email
)
5163 OscarData
*od
= purple_connection_get_protocol_data(gc
);
5165 aim_search_address(od
, email
);
5168 static void oscar_show_find_email(PurpleProtocolAction
*action
)
5170 PurpleConnection
*gc
= action
->connection
;
5171 purple_request_input(gc
, _("Find Buddy by Email"),
5172 _("Search for a buddy by email address"),
5173 _("Type the email address of the buddy you are "
5175 NULL
, FALSE
, FALSE
, NULL
,
5176 _("_Search"), G_CALLBACK(search_by_email_cb
),
5178 purple_request_cpar_from_connection(gc
),
5182 static void oscar_show_set_info(PurpleProtocolAction
*action
)
5184 PurpleConnection
*gc
= action
->connection
;
5185 purple_account_request_change_user_info(purple_connection_get_account(gc
));
5188 static void oscar_show_set_info_icqurl(PurpleProtocolAction
*action
)
5190 PurpleConnection
*gc
= action
->connection
;
5191 purple_notify_uri(gc
, "http://www.icq.com/whitepages/user_details.php");
5194 static void oscar_change_pass(PurpleProtocolAction
*action
)
5196 PurpleConnection
*gc
= action
->connection
;
5197 purple_account_request_change_password(purple_connection_get_account(gc
));
5201 * Only used when connecting with the old-style BUCP login.
5203 static void oscar_show_chpassurl(PurpleProtocolAction
*action
)
5205 PurpleConnection
*gc
= action
->connection
;
5206 OscarData
*od
= purple_connection_get_protocol_data(gc
);
5207 gchar
*substituted
= purple_strreplace(od
->authinfo
->chpassurl
, "%s", purple_account_get_username(purple_connection_get_account(gc
)));
5208 purple_notify_uri(gc
, substituted
);
5209 g_free(substituted
);
5212 static void oscar_show_imforwardingurl(PurpleProtocolAction
*action
)
5214 PurpleConnection
*gc
= action
->connection
;
5215 purple_notify_uri(gc
, "http://mymobile.aol.com/dbreg/register?action=imf&clientID=1");
5218 void oscar_set_icon(PurpleConnection
*gc
, PurpleImage
*img
)
5220 OscarData
*od
= purple_connection_get_protocol_data(gc
);
5223 aim_ssi_delicon(od
);
5227 gsize digest_len
= 16;
5228 gconstpointer data
= purple_image_get_data(img
);
5229 size_t len
= purple_image_get_data_size(img
);
5231 hash
= g_checksum_new(G_CHECKSUM_MD5
);
5232 g_checksum_update(hash
, data
, len
);
5233 g_checksum_get_digest(hash
, md5
, &digest_len
);
5234 g_checksum_free(hash
);
5236 aim_ssi_seticon(od
, md5
, 16);
5241 * Called by the Purple core to determine whether or not we're
5242 * allowed to send a file to this user.
5245 oscar_can_receive_file(PurpleProtocolXfer
*prplxfer
, PurpleConnection
*gc
, const char *who
)
5248 PurpleAccount
*account
;
5250 od
= purple_connection_get_protocol_data(gc
);
5251 account
= purple_connection_get_account(gc
);
5255 aim_userinfo_t
*userinfo
;
5256 userinfo
= aim_locate_finduserinfo(od
, who
);
5259 * Don't allowing sending a file to a user that does not support
5260 * file transfer, and don't allow sending to ourselves.
5262 if (((userinfo
== NULL
) ||
5263 (userinfo
->capabilities
& OSCAR_CAPABILITY_SENDFILE
)) &&
5264 oscar_util_name_compare(who
, purple_account_get_username(account
)))
5274 oscar_new_xfer(PurpleProtocolXfer
*prplxfer
, PurpleConnection
*gc
, const char *who
)
5278 PurpleAccount
*account
;
5279 PeerConnection
*conn
;
5281 od
= purple_connection_get_protocol_data(gc
);
5282 account
= purple_connection_get_account(gc
);
5284 conn
= peer_connection_new(od
, OSCAR_CAPABILITY_SENDFILE
, who
);
5285 conn
->flags
|= PEER_CONNECTION_FLAG_INITIATED_BY_ME
;
5286 conn
->flags
|= PEER_CONNECTION_FLAG_APPROVED
;
5288 xfer
= g_object_new(
5291 "type", PURPLE_XFER_TYPE_SEND
,
5297 aim_icbm_makecookie(conn
->cookie
);
5298 conn
->xfer
= PURPLE_XFER(xfer
);
5300 return PURPLE_XFER(xfer
);
5304 * Called by the Purple core when the user indicates that a
5305 * file is to be sent to a special someone.
5308 oscar_send_file(PurpleProtocolXfer
*prplxfer
, PurpleConnection
*gc
, const char *who
, const char *file
)
5312 xfer
= oscar_new_xfer(prplxfer
, gc
, who
);
5315 purple_xfer_request_accepted(xfer
, file
);
5317 purple_xfer_request(xfer
);
5321 oscar_get_actions(PurpleConnection
*gc
)
5323 OscarData
*od
= purple_connection_get_protocol_data(gc
);
5325 PurpleProtocolAction
*act
;
5327 act
= purple_protocol_action_new(_("Set User Info..."),
5328 oscar_show_set_info
);
5329 menu
= g_list_prepend(menu
, act
);
5333 act
= purple_protocol_action_new(_("Set User Info (web)..."),
5334 oscar_show_set_info_icqurl
);
5335 menu
= g_list_prepend(menu
, act
);
5338 act
= purple_protocol_action_new(_("Change Password..."),
5340 menu
= g_list_prepend(menu
, act
);
5342 if (od
->authinfo
!= NULL
&& od
->authinfo
->chpassurl
!= NULL
)
5344 /* This only happens when connecting with the old-style BUCP login */
5345 act
= purple_protocol_action_new(_("Change Password (web)"),
5346 oscar_show_chpassurl
);
5347 menu
= g_list_prepend(menu
, act
);
5352 act
= purple_protocol_action_new(_("Configure IM Forwarding (web)"),
5353 oscar_show_imforwardingurl
);
5354 menu
= g_list_prepend(menu
, act
);
5357 menu
= g_list_prepend(menu
, NULL
);
5362 act
= purple_protocol_action_new(_("Set Privacy Options..."),
5363 oscar_show_icq_privacy_opts
);
5364 menu
= g_list_prepend(menu
, act
);
5366 act
= purple_protocol_action_new(_("Show Visible List"), oscar_show_visible_list
);
5367 menu
= g_list_prepend(menu
, act
);
5369 act
= purple_protocol_action_new(_("Show Invisible List"), oscar_show_invisible_list
);
5370 menu
= g_list_prepend(menu
, act
);
5375 act
= purple_protocol_action_new(_("Confirm Account"),
5376 oscar_confirm_account
);
5377 menu
= g_list_prepend(menu
, act
);
5379 act
= purple_protocol_action_new(_("Display Currently Registered Email Address"),
5381 menu
= g_list_prepend(menu
, act
);
5383 act
= purple_protocol_action_new(_("Change Currently Registered Email Address..."),
5384 oscar_show_change_email
);
5385 menu
= g_list_prepend(menu
, act
);
5388 menu
= g_list_prepend(menu
, NULL
);
5390 act
= purple_protocol_action_new(_("Show Buddies Awaiting Authorization"),
5391 oscar_show_awaitingauth
);
5392 menu
= g_list_prepend(menu
, act
);
5394 menu
= g_list_prepend(menu
, NULL
);
5396 act
= purple_protocol_action_new(_("Search for Buddy by Email Address..."),
5397 oscar_show_find_email
);
5398 menu
= g_list_prepend(menu
, act
);
5400 menu
= g_list_reverse(menu
);
5405 void oscar_change_passwd(PurpleConnection
*gc
, const char *old
, const char *new)
5407 OscarData
*od
= purple_connection_get_protocol_data(gc
);
5410 aim_icq_changepasswd(od
, new);
5412 FlapConnection
*conn
;
5413 conn
= flap_connection_getbytype(od
, SNAC_FAMILY_ADMIN
);
5415 aim_admin_changepasswd(od
, conn
, new, old
);
5418 od
->oldp
= g_strdup(old
);
5419 od
->newp
= g_strdup(new);
5420 aim_srv_requestnew(od
, SNAC_FAMILY_ADMIN
);
5426 oscar_convo_closed(PurpleConnection
*gc
, const char *who
)
5429 PeerConnection
*conn
;
5431 od
= purple_connection_get_protocol_data(gc
);
5432 conn
= peer_connection_find_by_type(od
, who
, OSCAR_CAPABILITY_DIRECTIM
);
5437 aim_im_sendch2_cancel(conn
);
5439 peer_connection_destroy(conn
, OSCAR_DISCONNECT_LOCAL_CLOSED
, NULL
);
5444 oscar_normalize(const PurpleAccount
*account
, const char *str
)
5446 static char buf
[BUF_LEN
];
5450 g_return_val_if_fail(str
!= NULL
, NULL
);
5452 /* copy str to buf and skip all blanks */
5454 for (j
= 0; str
[j
]; j
++) {
5455 if (str
[j
] != ' ') {
5457 if (i
>= BUF_LEN
- 1)
5463 tmp1
= g_utf8_strdown(buf
, -1);
5464 tmp2
= g_utf8_normalize(tmp1
, -1, G_NORMALIZE_DEFAULT
);
5465 if (strlen(tmp2
) > sizeof(buf
) - 1) {
5466 purple_debug_error("oscar", "normalized string exceeds buffer length!\n");
5468 g_strlcpy(buf
, tmp2
, sizeof(buf
));
5476 oscar_offline_message(const PurpleBuddy
*buddy
)
5482 oscar_get_max_message_size(PurpleConversation
*conv
)
5484 /* XXX: got from pidgin-otr - verify and document it */
5488 /* TODO: Find somewhere to put this instead of including it in a bunch of places.
5489 * Maybe just change purple_accounts_find() to return anything for the protocol if there is no acct_id.
5491 static PurpleAccount
*find_acct(const char *protocol
, const char *acct_id
)
5493 PurpleAccount
*acct
= NULL
;
5495 /* If we have a specific acct, use it */
5497 acct
= purple_accounts_find(acct_id
, protocol
);
5498 if (acct
&& !purple_account_is_connected(acct
))
5500 } else { /* Otherwise find an active account for the protocol */
5501 GList
*l
= purple_accounts_get_all();
5503 if (purple_strequal(protocol
, purple_account_get_protocol_id(l
->data
))
5504 && purple_account_is_connected(l
->data
)) {
5515 gboolean
oscar_uri_handler(const char *proto
, const char *cmd
, GHashTable
*params
)
5519 PurpleAccount
*acct
;
5521 if (g_ascii_strcasecmp(proto
, "aim") && g_ascii_strcasecmp(proto
, "icq"))
5524 if (params
== NULL
) {
5525 /* All Oscar URI actions require some parameters eventually */
5526 purple_debug_warning("oscar",
5527 "No required params for handling URI");
5531 acct_id
= g_hash_table_lookup(params
, "account");
5532 g_snprintf(prpl
, sizeof(prpl
), "prpl-%s", proto
);
5534 acct
= find_acct(proto
, acct_id
);
5539 /* aim:GoIM?screenname=SCREENNAME&message=MESSAGE */
5540 if (!g_ascii_strcasecmp(cmd
, "GoIM")) {
5541 char *bname
= g_hash_table_lookup(params
, "screenname");
5543 char *message
= g_hash_table_lookup(params
, "message");
5545 PurpleIMConversation
*im
= purple_conversations_find_im_with_account(
5548 im
= purple_im_conversation_new(acct
, bname
);
5549 purple_conversation_present(PURPLE_CONVERSATION(im
));
5552 /* Spaces are encoded as '+' */
5553 g_strdelimit(message
, "+", ' ');
5554 purple_conversation_send_confirm(PURPLE_CONVERSATION(im
), message
);
5558 **If pidgindialogs_im() was in the core, we could use it here.
5559 * It is all purple_request_* based, but I'm not sure it really belongs in the core
5560 pidgindialogs_im();*/
5564 /* aim:GoChat?roomname=CHATROOMNAME&exchange=4 */
5565 else if (!g_ascii_strcasecmp(cmd
, "GoChat")) {
5566 char *rname
= g_hash_table_lookup(params
, "roomname");
5568 /* This is somewhat hacky, but the params aren't useful after this command */
5569 g_hash_table_insert(params
, g_strdup("exchange"), g_strdup("4"));
5570 g_hash_table_insert(params
, g_strdup("room"), g_strdup(rname
));
5571 purple_serv_join_chat(purple_account_get_connection(acct
), params
);
5574 ** Same as above (except that this would have to be re-written using purple_request_*)
5575 pidgin_blist_joinchat_show(); */
5579 /* aim:AddBuddy?screenname=SCREENNAME&groupname=GROUPNAME*/
5580 else if (!g_ascii_strcasecmp(cmd
, "AddBuddy")) {
5581 char *bname
= g_hash_table_lookup(params
, "screenname");
5582 char *gname
= g_hash_table_lookup(params
, "groupname");
5583 purple_blist_request_add_buddy(acct
, bname
, gname
, NULL
);
5590 void oscar_init_account_options(PurpleProtocol
*protocol
, gboolean is_icq
)
5592 PurpleAccountOption
*option
;
5593 static const gchar
*encryption_keys
[] = {
5594 N_("Use encryption if available"),
5595 N_("Require encryption"),
5596 N_("Don't use encryption"),
5599 static const gchar
*encryption_values
[] = {
5600 OSCAR_OPPORTUNISTIC_ENCRYPTION
,
5601 OSCAR_REQUIRE_ENCRYPTION
,
5602 OSCAR_NO_ENCRYPTION
,
5605 static const gchar
*aim_login_keys
[] = {
5606 N_("Use clientLogin authentication"),
5607 N_("Use Kerberos-based authentication"),
5608 N_("Use MD5 based authentication"),
5611 static const gchar
*aim_login_values
[] = {
5613 OSCAR_KERBEROS_LOGIN
,
5617 static const gchar
*icq_login_keys
[] = {
5618 N_("Use clientLogin authentication"),
5619 N_("Use MD5 based authentication"),
5622 static const gchar
*icq_login_values
[] = {
5627 const gchar
**login_keys
;
5628 const gchar
**login_values
;
5629 GList
*encryption_options
= NULL
;
5630 GList
*login_options
= NULL
;
5633 option
= purple_account_option_string_new(_("Server"), "server", oscar_get_login_server(is_icq
, TRUE
));
5634 protocol
->account_options
= g_list_append(protocol
->account_options
, option
);
5636 option
= purple_account_option_int_new(_("Port"), "port", OSCAR_DEFAULT_LOGIN_PORT
);
5637 protocol
->account_options
= g_list_append(protocol
->account_options
, option
);
5639 for (i
= 0; encryption_keys
[i
]; i
++) {
5640 PurpleKeyValuePair
*kvp
= g_new0(PurpleKeyValuePair
, 1);
5641 kvp
->key
= g_strdup(_(encryption_keys
[i
]));
5642 kvp
->value
= g_strdup(encryption_values
[i
]);
5643 encryption_options
= g_list_append(encryption_options
, kvp
);
5645 option
= purple_account_option_list_new(_("Connection security"), "encryption", encryption_options
);
5646 protocol
->account_options
= g_list_append(protocol
->account_options
, option
);
5649 login_keys
= icq_login_keys
;
5650 login_values
= icq_login_values
;
5652 login_keys
= aim_login_keys
;
5653 login_values
= aim_login_values
;
5655 for (i
= 0; login_keys
[i
]; i
++) {
5656 PurpleKeyValuePair
*kvp
= g_new0(PurpleKeyValuePair
, 1);
5657 kvp
->key
= g_strdup(_(login_keys
[i
]));
5658 kvp
->value
= g_strdup(login_values
[i
]);
5659 login_options
= g_list_append(login_options
, kvp
);
5661 option
= purple_account_option_list_new(_("Authentication method"), "login_type", login_options
);
5662 protocol
->account_options
= g_list_append(protocol
->account_options
, option
);
5664 option
= purple_account_option_bool_new(
5665 _("Always use AIM/ICQ proxy server for\nfile transfers and direct IM (slower,\nbut does not reveal your IP address)"), "always_use_rv_proxy",
5666 OSCAR_DEFAULT_ALWAYS_USE_RV_PROXY
);
5667 protocol
->account_options
= g_list_append(protocol
->account_options
, option
);
5670 option
= purple_account_option_string_new(_("Encoding"), "encoding", OSCAR_DEFAULT_CUSTOM_ENCODING
);
5671 protocol
->account_options
= g_list_append(protocol
->account_options
, option
);
5673 option
= purple_account_option_bool_new(_("Allow multiple simultaneous logins"), "allow_multiple_logins",
5674 OSCAR_DEFAULT_ALLOW_MULTIPLE_LOGINS
);
5675 protocol
->account_options
= g_list_append(protocol
->account_options
, option
);
5680 oscar_protocol_init(PurpleProtocol
*protocol
)
5682 protocol
->options
= OPT_PROTO_MAIL_CHECK
| OPT_PROTO_INVITE_MESSAGE
|
5683 OPT_PROTO_AUTHORIZATION_DENIED_MESSAGE
;
5684 protocol
->icon_spec
= purple_buddy_icon_spec_new("gif,jpeg,bmp,ico",
5686 PURPLE_ICON_SCALE_SEND
|
5687 PURPLE_ICON_SCALE_DISPLAY
);
5691 oscar_protocol_class_init(PurpleProtocolClass
*klass
)
5693 klass
->login
= oscar_login
;
5694 klass
->close
= oscar_close
;
5695 klass
->status_types
= oscar_status_types
;
5699 oscar_protocol_client_iface_init(PurpleProtocolClientInterface
*client_iface
)
5701 client_iface
->get_actions
= oscar_get_actions
;
5702 client_iface
->list_emblem
= oscar_list_emblem
;
5703 client_iface
->status_text
= oscar_status_text
;
5704 client_iface
->tooltip_text
= oscar_tooltip_text
;
5705 client_iface
->blist_node_menu
= oscar_blist_node_menu
;
5706 client_iface
->convo_closed
= oscar_convo_closed
;
5707 client_iface
->normalize
= oscar_normalize
;
5708 client_iface
->offline_message
= oscar_offline_message
;
5712 oscar_protocol_server_iface_init(PurpleProtocolServerInterface
*server_iface
)
5714 server_iface
->set_info
= oscar_set_info
;
5715 server_iface
->get_info
= oscar_get_info
;
5716 server_iface
->set_status
= oscar_set_status
;
5717 server_iface
->set_idle
= oscar_set_idle
;
5718 server_iface
->change_passwd
= oscar_change_passwd
;
5719 server_iface
->add_buddy
= oscar_add_buddy
;
5720 server_iface
->remove_buddy
= oscar_remove_buddy
;
5721 server_iface
->keepalive
= oscar_keepalive
;
5722 server_iface
->alias_buddy
= oscar_alias_buddy
;
5723 server_iface
->group_buddy
= oscar_move_buddy
;
5724 server_iface
->rename_group
= oscar_rename_group
;
5725 server_iface
->set_buddy_icon
= oscar_set_icon
;
5726 server_iface
->remove_group
= oscar_remove_group
;
5730 oscar_protocol_im_iface_init(PurpleProtocolIMInterface
*im_iface
)
5732 im_iface
->send
= oscar_send_im
;
5733 im_iface
->send_typing
= oscar_send_typing
;
5737 oscar_protocol_chat_iface_init(PurpleProtocolChatInterface
*chat_iface
)
5739 chat_iface
->info
= oscar_chat_info
;
5740 chat_iface
->info_defaults
= oscar_chat_info_defaults
;
5741 chat_iface
->join
= oscar_join_chat
;
5742 chat_iface
->get_name
= oscar_get_chat_name
;
5743 chat_iface
->invite
= oscar_chat_invite
;
5744 chat_iface
->leave
= oscar_chat_leave
;
5745 chat_iface
->send
= oscar_send_chat
;
5749 oscar_protocol_privacy_iface_init(PurpleProtocolPrivacyInterface
*privacy_iface
)
5751 privacy_iface
->add_deny
= oscar_add_deny
;
5752 privacy_iface
->rem_deny
= oscar_rem_deny
;
5756 oscar_protocol_xfer_iface_init(PurpleProtocolXferInterface
*xfer_iface
)
5758 xfer_iface
->can_receive
= oscar_can_receive_file
;
5759 xfer_iface
->send_file
= oscar_send_file
;
5760 xfer_iface
->new_xfer
= oscar_new_xfer
;
5763 PURPLE_DEFINE_TYPE_EXTENDED(
5764 OscarProtocol
, oscar_protocol
, PURPLE_TYPE_PROTOCOL
, G_TYPE_FLAG_ABSTRACT
,
5766 PURPLE_IMPLEMENT_INTERFACE_STATIC(PURPLE_TYPE_PROTOCOL_CLIENT
,
5767 oscar_protocol_client_iface_init
)
5769 PURPLE_IMPLEMENT_INTERFACE_STATIC(PURPLE_TYPE_PROTOCOL_SERVER
,
5770 oscar_protocol_server_iface_init
)
5772 PURPLE_IMPLEMENT_INTERFACE_STATIC(PURPLE_TYPE_PROTOCOL_IM
,
5773 oscar_protocol_im_iface_init
)
5775 PURPLE_IMPLEMENT_INTERFACE_STATIC(PURPLE_TYPE_PROTOCOL_CHAT
,
5776 oscar_protocol_chat_iface_init
)
5778 PURPLE_IMPLEMENT_INTERFACE_STATIC(PURPLE_TYPE_PROTOCOL_PRIVACY
,
5779 oscar_protocol_privacy_iface_init
)
5781 PURPLE_IMPLEMENT_INTERFACE_STATIC(PURPLE_TYPE_PROTOCOL_XFER
,
5782 oscar_protocol_xfer_iface_init
)
5785 static PurplePluginInfo
*
5786 plugin_query(GError
**error
)
5788 return purple_plugin_info_new(
5790 "name", "Oscar Protocols",
5791 "version", DISPLAY_VERSION
,
5792 "category", N_("Protocol"),
5793 "summary", N_("Oscar (AIM/ICQ) Protocols Plugin"),
5794 "description", N_("Oscar (AIM/ICQ) Protocols Plugin"),
5795 "website", PURPLE_WEBSITE
,
5796 "abi-version", PURPLE_ABI_VERSION
,
5797 "flags", PURPLE_PLUGIN_INFO_FLAGS_INTERNAL
|
5798 PURPLE_PLUGIN_INFO_FLAGS_AUTO_LOAD
,
5804 plugin_load(PurplePlugin
*plugin
, GError
**error
)
5806 oscar_protocol_register_type(plugin
);
5808 aim_protocol_register_type(plugin
);
5809 icq_protocol_register_type(plugin
);
5811 oscar_xfer_register(G_TYPE_MODULE(plugin
));
5813 aim_protocol
= purple_protocols_add(AIM_TYPE_PROTOCOL
, error
);
5817 icq_protocol
= purple_protocols_add(ICQ_TYPE_PROTOCOL
, error
);
5821 purple_signal_connect(purple_get_core(), "uri-handler", aim_protocol
,
5822 PURPLE_CALLBACK(oscar_uri_handler
), NULL
);
5823 purple_signal_connect(purple_get_core(), "uri-handler", icq_protocol
,
5824 PURPLE_CALLBACK(oscar_uri_handler
), NULL
);
5827 purple_prefs_add_none("/plugins/prpl/oscar");
5828 purple_prefs_add_bool("/plugins/prpl/oscar/recent_buddies", FALSE
);
5830 purple_prefs_remove("/plugins/prpl/oscar/show_idle");
5831 purple_prefs_remove("/plugins/prpl/oscar/always_use_rv_proxy");
5837 plugin_unload(PurplePlugin
*plugin
, GError
**error
)
5839 if (!purple_protocols_remove(icq_protocol
, error
))
5842 if (!purple_protocols_remove(aim_protocol
, error
))
5848 PURPLE_PLUGIN_INIT(oscar
, plugin_query
, plugin_load
, plugin_unload
);