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 "buddyicon.h"
35 #include "conversation.h"
39 #include "image-store.h"
44 #include "purpleaccountoption.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
);
753 if (purple_strequal(login_type
, OSCAR_CLIENT_LOGIN
) ||
754 purple_strequal(login_type
, OSCAR_KERBEROS_LOGIN
)) {
755 /* Create a SoupSession to be used for HTTP login requests. */
756 GProxyResolver
*resolver
;
759 resolver
= purple_proxy_get_proxy_resolver(account
, &error
);
760 if (resolver
== NULL
) {
761 purple_debug_error("oscar",
762 "Unable to get account proxy resolver: %s",
764 purple_connection_g_error(gc
, error
);
768 od
->http_conns
= soup_session_new_with_options(
769 SOUP_SESSION_PROXY_RESOLVER
, resolver
, NULL
);
770 g_object_unref(resolver
);
774 * On 2008-03-05 AOL released some documentation on the OSCAR protocol
775 * which includes a new login method called clientLogin. It is similar
776 * (though not the same?) as what the AIM 6.0 series uses to
779 * AIM 5.9 and lower use an MD5-based login procedure called "BUCP".
780 * This authentication method is used for both ICQ and AIM when
781 * clientLogin is not enabled.
783 if (purple_strequal(login_type
, OSCAR_CLIENT_LOGIN
)) {
784 /* Note: Actual server/port configuration is ignored here */
785 send_client_login(od
, purple_account_get_username(account
));
786 } else if (purple_strequal(login_type
, OSCAR_KERBEROS_LOGIN
)) {
790 purple_connection_error(
792 PURPLE_CONNECTION_ERROR_NO_SSL_SUPPORT
,
793 _("You required Kerberos authentication but encryption is disabled in your account settings."));
796 server
= purple_account_get_string(account
, "server", AIM_DEFAULT_KDC_SERVER
);
798 * If the account's server is what the oscar protocol has offered as
799 * the default login server through the vast eons (all two of
800 * said default options, AFAIK) and the user wants KDC, we'll
801 * do what we know is best for them and change the setting out
802 * from under them to the KDC login server.
804 if (purple_strequal(server
, oscar_get_login_server(od
->icq
, FALSE
)) ||
805 purple_strequal(server
, oscar_get_login_server(od
->icq
, TRUE
)) ||
806 purple_strequal(server
, AIM_ALT_LOGIN_SERVER
) ||
807 purple_strequal(server
, "")) {
808 purple_debug_info("oscar", "Account uses Kerberos auth, so changing server to default KDC server\n");
809 purple_account_set_string(account
, "server", AIM_DEFAULT_KDC_SERVER
);
810 purple_account_set_int(account
, "port", AIM_DEFAULT_KDC_PORT
);
812 send_kerberos_login(od
, purple_account_get_username(account
));
814 FlapConnection
*newconn
;
817 newconn
= flap_connection_new(od
, SNAC_FAMILY_AUTH
);
820 server
= purple_account_get_string(account
, "server", oscar_get_login_server(od
->icq
, TRUE
));
823 * If the account's server is what the oscar protocol has offered as
824 * the default login server through the vast eons (all two of
825 * said default options, AFAIK) and the user wants SSL, we'll
826 * do what we know is best for them and change the setting out
827 * from under them to the SSL login server.
829 if (purple_strequal(server
, oscar_get_login_server(od
->icq
, FALSE
)) ||
830 purple_strequal(server
, AIM_ALT_LOGIN_SERVER
) ||
831 purple_strequal(server
, AIM_DEFAULT_KDC_SERVER
) ||
832 purple_strequal(server
, "")) {
833 purple_debug_info("oscar", "Account uses SSL, so changing server to default SSL server\n");
834 purple_account_set_string(account
, "server", oscar_get_login_server(od
->icq
, TRUE
));
835 purple_account_set_int(account
, "port", OSCAR_DEFAULT_LOGIN_PORT
),
836 server
= oscar_get_login_server(od
->icq
, TRUE
);
839 newconn
->gsc
= purple_ssl_connect(account
, server
,
840 purple_account_get_int(account
, "port", OSCAR_DEFAULT_LOGIN_PORT
),
841 ssl_connection_established_cb
, ssl_connection_error_cb
, newconn
);
843 server
= purple_account_get_string(account
, "server", oscar_get_login_server(od
->icq
, FALSE
));
846 * See the comment above. We do the reverse here. If they don't want
847 * SSL but their server is set to OSCAR_DEFAULT_SSL_LOGIN_SERVER,
848 * set it back to the default.
850 if (purple_strequal(server
, oscar_get_login_server(od
->icq
, TRUE
)) ||
851 purple_strequal(server
, AIM_DEFAULT_KDC_SERVER
) ||
852 purple_strequal(server
, "")) {
853 purple_debug_info("oscar", "Account does not use SSL, so changing server back to non-SSL\n");
854 purple_account_set_string(account
, "server", oscar_get_login_server(od
->icq
, FALSE
));
855 purple_account_set_int(account
, "port", OSCAR_DEFAULT_LOGIN_PORT
),
856 server
= oscar_get_login_server(od
->icq
, FALSE
);
859 newconn
->connect_data
= purple_proxy_connect(NULL
, account
, server
,
860 purple_account_get_int(account
, "port", OSCAR_DEFAULT_LOGIN_PORT
),
861 connection_established_cb
, newconn
);
864 if (newconn
->gsc
== NULL
&& newconn
->connect_data
== NULL
) {
865 purple_connection_error(gc
, PURPLE_CONNECTION_ERROR_NETWORK_ERROR
,
866 _("Unable to connect"));
871 purple_connection_update_progress(gc
, _("Connecting"), 0, OSCAR_CONNECT_STEPS
);
875 oscar_close(PurpleConnection
*gc
)
879 od
= purple_connection_get_protocol_data(gc
);
881 g_slist_free_full(od
->oscar_chats
, (GDestroyNotify
)oscar_chat_destroy
);
882 while (od
->create_rooms
)
884 struct create_room
*cr
= od
->create_rooms
->data
;
886 od
->create_rooms
= g_slist_remove(od
->create_rooms
, cr
);
889 oscar_data_destroy(od
);
890 purple_connection_set_protocol_data(gc
, NULL
);
892 purple_prefs_disconnect_by_handle(gc
);
894 purple_debug_info("oscar", "Signed off.\n");
897 int oscar_connect_to_bos(PurpleConnection
*gc
, OscarData
*od
, const char *host
, guint16 port
, guint8
*cookie
, guint16 cookielen
, const char *tls_certname
)
899 PurpleAccount
*account
;
900 FlapConnection
*conn
;
902 account
= purple_connection_get_account(gc
);
904 conn
= flap_connection_new(od
, SNAC_FAMILY_LOCATE
);
905 conn
->cookielen
= cookielen
;
906 conn
->cookie
= g_memdup(cookie
, cookielen
);
909 * 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,
910 * and that is something we should be prepared to.
914 conn
->gsc
= purple_ssl_connect_with_ssl_cn(account
, host
, port
,
915 ssl_connection_established_cb
, ssl_connection_error_cb
,
920 conn
->connect_data
= purple_proxy_connect(NULL
,
922 connection_established_cb
, conn
);
925 if (conn
->gsc
== NULL
&& conn
->connect_data
== NULL
)
927 purple_connection_error(gc
, PURPLE_CONNECTION_ERROR_NETWORK_ERROR
, _("Unable to connect"));
931 od
->default_port
= port
;
933 purple_connection_update_progress(gc
, _("Received authorization"), 3, OSCAR_CONNECT_STEPS
);
939 * Only used when connecting with the old-style BUCP login.
942 purple_parse_auth_resp(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...)
944 PurpleConnection
*gc
= od
->gc
;
945 PurpleAccount
*account
= purple_connection_get_account(gc
);
946 char *host
; int port
;
948 FlapConnection
*newconn
;
950 struct aim_authresp_info
*info
;
952 port
= purple_account_get_int(account
, "port", od
->default_port
);
955 info
= va_arg(ap
, struct aim_authresp_info
*);
958 purple_debug_info("oscar",
959 "inside auth_resp (Username: %s)\n", info
->bn
);
961 if (info
->errorcode
|| !info
->bosip
|| !info
->cookielen
|| !info
->cookie
) {
963 switch (info
->errorcode
) {
965 /* Unregistered username */
966 purple_connection_error(gc
, PURPLE_CONNECTION_ERROR_INVALID_USERNAME
, _("Username does not exist"));
969 /* Incorrect password */
970 if (!purple_account_get_remember_password(account
))
971 purple_account_set_password(account
, NULL
, NULL
, NULL
);
972 purple_connection_error(gc
, PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED
, _("Incorrect password"));
975 /* Suspended account */
976 purple_connection_error(gc
, PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED
, _("Your account is currently suspended"));
980 /* service temporarily unavailable */
981 purple_connection_error(gc
, PURPLE_CONNECTION_ERROR_NETWORK_ERROR
, _("The AOL Instant Messenger service is temporarily unavailable."));
984 /* username connecting too frequently */
985 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."));
990 g_snprintf(buf
, sizeof(buf
), _("The client version you are using is too old. Please upgrade at %s"),
991 oscar_get_ui_info_string("website", PURPLE_WEBSITE
));
992 purple_connection_error(gc
, PURPLE_CONNECTION_ERROR_OTHER_ERROR
, buf
);
996 /* IP address connecting too frequently */
997 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."));
1000 purple_connection_error(gc
, PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED
, _("Unknown reason"));
1003 purple_debug_info("oscar", "Login Error Code 0x%04hx\n", info
->errorcode
);
1004 purple_debug_info("oscar", "Error URL: %s\n", info
->errorurl
? info
->errorurl
: "");
1008 purple_debug_misc("oscar",
1012 info
->regstatus
, info
->email
? info
->email
: "null",
1014 purple_debug_info("oscar", "Closing auth connection...\n");
1015 flap_connection_schedule_destroy(conn
, OSCAR_DISCONNECT_DONE
, NULL
);
1017 for (i
= 0; i
< strlen(info
->bosip
); i
++) {
1018 if (info
->bosip
[i
] == ':') {
1019 port
= atoi(&(info
->bosip
[i
+1]));
1023 host
= g_strndup(info
->bosip
, i
);
1024 newconn
= flap_connection_new(od
, SNAC_FAMILY_LOCATE
);
1025 newconn
->cookielen
= info
->cookielen
;
1026 newconn
->cookie
= g_memdup(info
->cookie
, info
->cookielen
);
1031 * This shouldn't be hardcoded to "bos.oscar.aol.com" except that
1032 * the server isn't sending us a name to use for comparing the
1033 * certificate common name.
1035 newconn
->gsc
= purple_ssl_connect_with_ssl_cn(account
, host
, port
,
1036 ssl_connection_established_cb
, ssl_connection_error_cb
,
1037 "bos.oscar.aol.com", newconn
);
1041 newconn
->connect_data
= purple_proxy_connect(NULL
, account
, host
, port
,
1042 connection_established_cb
, newconn
);
1046 if (newconn
->gsc
== NULL
&& newconn
->connect_data
== NULL
)
1048 purple_connection_error(gc
, PURPLE_CONNECTION_ERROR_NETWORK_ERROR
, _("Unable to connect"));
1052 purple_connection_update_progress(gc
, _("Received authorization"), 3, OSCAR_CONNECT_STEPS
);
1058 * Only used when connecting with the old-style BUCP login.
1061 purple_parse_auth_securid_request_yes_cb(gpointer user_data
, const char *msg
)
1063 PurpleConnection
*gc
= user_data
;
1064 OscarData
*od
= purple_connection_get_protocol_data(gc
);
1066 aim_auth_securid_send(od
, msg
);
1070 * Only used when connecting with the old-style BUCP login.
1073 purple_parse_auth_securid_request_no_cb(gpointer user_data
, const char *value
)
1075 PurpleConnection
*gc
= user_data
;
1078 purple_connection_error(gc
,
1079 PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED
,
1080 _("The SecurID key entered is invalid"));
1084 * Only used when connecting with the old-style BUCP login.
1087 purple_parse_auth_securid_request(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...)
1089 PurpleConnection
*gc
= od
->gc
;
1090 PurpleAccount
*account
= purple_connection_get_account(gc
);
1093 purple_debug_info("oscar", "Got SecurID request\n");
1095 primary
= g_strdup_printf("Enter the SecurID key for %s.", purple_account_get_username(account
));
1096 purple_request_input(gc
, NULL
, _("Enter SecurID"), primary
,
1097 _("Enter the 6 digit number from the digital display."),
1099 _("_OK"), G_CALLBACK(purple_parse_auth_securid_request_yes_cb
),
1100 _("_Cancel"), G_CALLBACK(purple_parse_auth_securid_request_no_cb
),
1101 purple_request_cpar_from_connection(gc
),
1109 purple_handle_redirect(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...)
1111 PurpleConnection
*gc
= od
->gc
;
1112 PurpleAccount
*account
= purple_connection_get_account(gc
);
1113 char *host
, *separator
;
1115 FlapConnection
*newconn
;
1117 struct aim_redirect_data
*redir
;
1120 redir
= va_arg(ap
, struct aim_redirect_data
*);
1123 port
= od
->default_port
;
1124 separator
= strchr(redir
->ip
, ':');
1125 if (separator
!= NULL
)
1127 host
= g_strndup(redir
->ip
, separator
- redir
->ip
);
1128 port
= atoi(separator
+ 1);
1131 host
= g_strdup(redir
->ip
);
1133 if (!redir
->use_ssl
) {
1134 const gchar
*encryption_type
= purple_account_get_string(account
, "encryption", OSCAR_DEFAULT_ENCRYPTION
);
1135 if (purple_strequal(encryption_type
, OSCAR_OPPORTUNISTIC_ENCRYPTION
)) {
1136 purple_debug_warning("oscar", "We won't use SSL for FLAP type 0x%04hx.\n", redir
->group
);
1137 } else if (purple_strequal(encryption_type
, OSCAR_REQUIRE_ENCRYPTION
)) {
1138 purple_debug_error("oscar", "FLAP server %s:%d of type 0x%04hx doesn't support encryption.\n", host
, port
, redir
->group
);
1139 purple_connection_error(
1141 PURPLE_CONNECTION_ERROR_NO_SSL_SUPPORT
,
1142 _("You required encryption in your account settings, but one of the servers doesn't support it."));
1148 * These FLAP servers advertise SSL (type "0x02"), but SSL connections to these hosts
1149 * die a painful death. iChat and Miranda, when using SSL, still do these in plaintext.
1151 if (redir
->use_ssl
&& (redir
->group
== SNAC_FAMILY_ADMIN
||
1152 redir
->group
== SNAC_FAMILY_BART
))
1154 purple_debug_info("oscar", "Ignoring broken SSL for FLAP type 0x%04hx.\n", redir
->group
);
1158 purple_debug_info("oscar", "Connecting to FLAP server %s:%d of type 0x%04hx\n", host
, port
, redir
->group
);
1160 newconn
= flap_connection_new(od
, redir
->group
);
1161 newconn
->cookielen
= redir
->cookielen
;
1162 newconn
->cookie
= g_memdup(redir
->cookie
, redir
->cookielen
);
1163 if (newconn
->type
== SNAC_FAMILY_CHAT
)
1165 struct chat_connection
*cc
;
1166 cc
= g_new0(struct chat_connection
, 1);
1169 cc
->name
= g_strdup(redir
->chat
.room
);
1170 cc
->exchange
= redir
->chat
.exchange
;
1171 cc
->instance
= redir
->chat
.instance
;
1172 cc
->show
= extract_name(redir
->chat
.room
);
1173 newconn
->new_conn_data
= cc
;
1174 purple_debug_info("oscar", "Connecting to chat room %s exchange %hu\n", cc
->name
, cc
->exchange
);
1180 newconn
->gsc
= purple_ssl_connect_with_ssl_cn(account
, host
, port
,
1181 ssl_connection_established_cb
, ssl_connection_error_cb
,
1182 redir
->ssl_cert_cn
, newconn
);
1186 newconn
->connect_data
= purple_proxy_connect(NULL
, account
, host
, port
,
1187 connection_established_cb
, newconn
);
1190 if (newconn
->gsc
== NULL
&& newconn
->connect_data
== NULL
)
1192 flap_connection_schedule_destroy(newconn
,
1193 OSCAR_DISCONNECT_COULD_NOT_CONNECT
,
1194 _("Unable to initialize connection"));
1195 purple_debug_error("oscar", "Unable to connect to FLAP server "
1196 "of type 0x%04hx\n", redir
->group
);
1204 static int purple_parse_oncoming(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...)
1206 PurpleConnection
*gc
;
1207 PurpleAccount
*account
;
1208 PurpleBuddy
*buddy
= NULL
;
1209 PurpleStatus
*previous_status
= NULL
;
1210 struct buddyinfo
*bi
;
1211 time_t time_idle
= 0, signon
= 0;
1213 gboolean buddy_is_away
= FALSE
;
1214 const char *status_id
;
1216 aim_userinfo_t
*info
;
1218 char *itmsurl
= NULL
;
1221 account
= purple_connection_get_account(gc
);
1224 info
= va_arg(ap
, aim_userinfo_t
*);
1227 g_return_val_if_fail(info
!= NULL
, 1);
1228 g_return_val_if_fail(info
->bn
!= NULL
, 1);
1230 buddy
= purple_blist_find_buddy(account
, info
->bn
);
1232 previous_status
= purple_presence_get_active_status(purple_buddy_get_presence(buddy
));
1236 * If this is an AIM buddy and their name has formatting, set their
1239 if (!oscar_util_valid_name_icq(info
->bn
)) {
1240 gboolean bn_has_formatting
= FALSE
;
1242 for (c
= info
->bn
; *c
!= '\0'; c
++) {
1244 bn_has_formatting
= TRUE
;
1248 purple_serv_got_alias(gc
, info
->bn
,
1249 bn_has_formatting
? info
->bn
: NULL
);
1252 if (info
->present
& AIM_USERINFO_PRESENT_FLAGS
) {
1253 if (info
->flags
& AIM_FLAG_AWAY
)
1254 buddy_is_away
= TRUE
;
1256 if (info
->present
& AIM_USERINFO_PRESENT_ICQEXTSTATUS
) {
1257 type
= info
->icqinfo
.status
;
1258 if (!(info
->icqinfo
.status
& AIM_ICQ_STATE_CHAT
) &&
1259 (info
->icqinfo
.status
!= AIM_ICQ_STATE_NORMAL
)) {
1260 buddy_is_away
= TRUE
;
1264 if (oscar_util_valid_name_icq(info
->bn
)) {
1265 if (type
& AIM_ICQ_STATE_CHAT
)
1266 status_id
= OSCAR_STATUS_ID_FREE4CHAT
;
1267 else if (type
& AIM_ICQ_STATE_DND
)
1268 status_id
= OSCAR_STATUS_ID_DND
;
1269 else if (type
& AIM_ICQ_STATE_OUT
)
1270 status_id
= OSCAR_STATUS_ID_NA
;
1271 else if (type
& AIM_ICQ_STATE_BUSY
)
1272 status_id
= OSCAR_STATUS_ID_OCCUPIED
;
1273 else if (type
& AIM_ICQ_STATE_AWAY
)
1274 status_id
= OSCAR_STATUS_ID_AWAY
;
1275 else if (type
& AIM_ICQ_STATE_INVISIBLE
)
1276 status_id
= OSCAR_STATUS_ID_INVISIBLE
;
1277 else if (type
& AIM_ICQ_STATE_EVIL
)
1278 status_id
= OSCAR_STATUS_ID_EVIL
;
1279 else if (type
& AIM_ICQ_STATE_DEPRESSION
)
1280 status_id
= OSCAR_STATUS_ID_DEPRESSION
;
1281 else if (type
& AIM_ICQ_STATE_ATHOME
)
1282 status_id
= OSCAR_STATUS_ID_ATHOME
;
1283 else if (type
& AIM_ICQ_STATE_ATWORK
)
1284 status_id
= OSCAR_STATUS_ID_ATWORK
;
1285 else if (type
& AIM_ICQ_STATE_LUNCH
)
1286 status_id
= OSCAR_STATUS_ID_LUNCH
;
1288 status_id
= OSCAR_STATUS_ID_AVAILABLE
;
1290 if (type
& AIM_ICQ_STATE_INVISIBLE
)
1291 status_id
= OSCAR_STATUS_ID_INVISIBLE
;
1292 else if (buddy_is_away
)
1293 status_id
= OSCAR_STATUS_ID_AWAY
;
1295 status_id
= OSCAR_STATUS_ID_AVAILABLE
;
1298 if (info
->flags
& AIM_FLAG_WIRELESS
) {
1299 purple_protocol_got_user_status(account
, info
->bn
, OSCAR_STATUS_ID_MOBILE
, NULL
);
1301 purple_protocol_got_user_status_deactive(account
, info
->bn
, OSCAR_STATUS_ID_MOBILE
);
1304 message
= (info
->status
&& info
->status_len
> 0)
1305 ? oscar_encoding_to_utf8(info
->status_encoding
, info
->status
, info
->status_len
)
1308 if (purple_strequal(status_id
, OSCAR_STATUS_ID_AVAILABLE
)) {
1309 /* TODO: If itmsurl is NULL, does that mean the URL has been
1310 cleared? Or does it mean the URL should remain unchanged? */
1311 if (info
->itmsurl
!= NULL
) {
1312 itmsurl
= (info
->itmsurl_len
> 0) ? oscar_encoding_to_utf8(info
->itmsurl_encoding
, info
->itmsurl
, info
->itmsurl_len
) : NULL
;
1313 } else if (previous_status
!= NULL
&& purple_status_is_available(previous_status
)) {
1314 itmsurl
= g_strdup(purple_status_get_attr_string(previous_status
, "itmsurl"));
1316 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)");
1317 purple_protocol_got_user_status(account
, info
->bn
, status_id
, "message", message
, "itmsurl", itmsurl
, NULL
);
1319 purple_debug_info("oscar", "Activating status '%s' for buddy %s, message = '%s'\n", status_id
, info
->bn
, message
? message
: "(null)");
1320 purple_protocol_got_user_status(account
, info
->bn
, status_id
, "message", message
, NULL
);
1326 /* Login time stuff */
1327 if (info
->present
& AIM_USERINFO_PRESENT_ONLINESINCE
)
1328 signon
= info
->onlinesince
;
1329 else if (info
->present
& AIM_USERINFO_PRESENT_SESSIONLEN
)
1330 signon
= time(NULL
) - info
->sessionlen
;
1331 purple_protocol_got_user_login_time(account
, info
->bn
, signon
);
1333 /* Idle time stuff */
1334 /* info->idletime is the number of minutes that this user has been idle */
1335 if (info
->present
& AIM_USERINFO_PRESENT_IDLE
)
1336 time_idle
= time(NULL
) - info
->idletime
* 60;
1339 purple_protocol_got_user_idle(account
, info
->bn
, TRUE
, time_idle
);
1341 purple_protocol_got_user_idle(account
, info
->bn
, FALSE
, 0);
1343 /* Server stored icon stuff */
1344 bi
= g_hash_table_lookup(od
->buddyinfo
, purple_normalize(account
, info
->bn
));
1346 bi
= g_new0(struct buddyinfo
, 1);
1347 g_hash_table_insert(od
->buddyinfo
, g_strdup(purple_normalize(account
, info
->bn
)), bi
);
1349 bi
->typingnot
= FALSE
;
1350 bi
->ico_informed
= FALSE
;
1351 bi
->ipaddr
= info
->icqinfo
.ipaddr
;
1353 if (info
->iconcsumlen
) {
1354 const char *saved_b16
= NULL
;
1356 PurpleBuddy
*b
= NULL
;
1358 b16
= purple_base16_encode(info
->iconcsum
, info
->iconcsumlen
);
1359 b
= purple_blist_find_buddy(account
, info
->bn
);
1361 saved_b16
= purple_buddy_icons_get_checksum_for_user(b
);
1363 if (!b16
|| !saved_b16
|| !purple_strequal(b16
, saved_b16
)) {
1364 /* Invalidate the old icon for this user */
1365 purple_buddy_icons_set_for_user(account
, info
->bn
, NULL
, 0, NULL
);
1367 /* Fetch the new icon (if we're not already doing so) */
1368 if (g_slist_find_custom(od
->requesticon
, info
->bn
,
1369 (GCompareFunc
)oscar_util_name_compare
) == NULL
)
1371 od
->requesticon
= g_slist_prepend(od
->requesticon
,
1372 g_strdup(purple_normalize(account
, info
->bn
)));
1373 purple_icons_fetch(gc
);
1382 static int purple_parse_offgoing(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...) {
1383 PurpleConnection
*gc
= od
->gc
;
1384 PurpleAccount
*account
= purple_connection_get_account(gc
);
1386 aim_userinfo_t
*info
;
1389 info
= va_arg(ap
, aim_userinfo_t
*);
1392 purple_protocol_got_user_status(account
, info
->bn
, OSCAR_STATUS_ID_OFFLINE
, NULL
);
1393 purple_protocol_got_user_status_deactive(account
, info
->bn
, OSCAR_STATUS_ID_MOBILE
);
1394 g_hash_table_remove(od
->buddyinfo
, purple_normalize(purple_connection_get_account(gc
), info
->bn
));
1399 static int incomingim_chan1(OscarData
*od
, FlapConnection
*conn
, aim_userinfo_t
*userinfo
, struct aim_incomingim_ch1_args
*args
) {
1400 PurpleConnection
*gc
= od
->gc
;
1401 PurpleAccount
*account
= purple_connection_get_account(gc
);
1402 PurpleMessageFlags flags
= 0;
1403 struct buddyinfo
*bi
;
1406 const char *start
, *end
;
1409 purple_debug_misc("oscar", "Received IM from %s\n", userinfo
->bn
);
1411 bi
= g_hash_table_lookup(od
->buddyinfo
, purple_normalize(account
, userinfo
->bn
));
1413 bi
= g_new0(struct buddyinfo
, 1);
1414 g_hash_table_insert(od
->buddyinfo
, g_strdup(purple_normalize(account
, userinfo
->bn
)), bi
);
1417 if (args
->icbmflags
& AIM_IMFLAGS_AWAY
)
1418 flags
|= PURPLE_MESSAGE_AUTO_RESP
;
1420 if (args
->icbmflags
& AIM_IMFLAGS_TYPINGNOT
)
1421 bi
->typingnot
= TRUE
;
1423 bi
->typingnot
= FALSE
;
1425 if ((args
->icbmflags
& AIM_IMFLAGS_HASICON
) && (args
->iconlen
) && (args
->iconsum
) && (args
->iconstamp
)) {
1426 purple_debug_misc("oscar", "%s has an icon\n", userinfo
->bn
);
1427 if ((args
->iconlen
!= bi
->ico_len
) || (args
->iconsum
!= bi
->ico_csum
) || (args
->iconstamp
!= bi
->ico_time
)) {
1428 bi
->ico_need
= TRUE
;
1429 bi
->ico_len
= args
->iconlen
;
1430 bi
->ico_csum
= args
->iconsum
;
1431 bi
->ico_time
= args
->iconstamp
;
1435 img
= purple_buddy_icons_find_account_icon(account
);
1436 if ((img
!= NULL
) &&
1437 (args
->icbmflags
& AIM_IMFLAGS_BUDDYREQ
) && !bi
->ico_sent
&& bi
->ico_informed
) {
1438 gconstpointer data
= purple_image_get_data(img
);
1439 size_t len
= purple_image_get_data_size(img
);
1440 purple_debug_info("oscar",
1441 "Sending buddy icon to %s (%" G_GSIZE_FORMAT
" bytes)\n",
1443 aim_im_sendch2_icon(od
, userinfo
->bn
, data
, len
,
1444 purple_buddy_icons_get_account_icon_timestamp(account
),
1445 aimutil_iconsum(data
, len
));
1447 g_object_unref(img
);
1449 tmp
= g_strdup(args
->msg
);
1452 * Convert iChat color tags to normal font tags.
1454 if (purple_markup_find_tag("body", tmp
, &start
, &end
, &attribs
))
1458 const char *ichattextcolor
, *ichatballooncolor
;
1459 const char *slash_body_start
, *slash_body_end
= NULL
; /* </body> */
1463 * Find the ending </body> so we can strip off the outer <html/>
1466 if (purple_markup_find_tag("/body", end
+ 1, &slash_body_start
, &slash_body_end
, &unused
))
1468 body
= g_strndup(start
, slash_body_end
- start
+ 1);
1469 g_datalist_clear(&unused
);
1473 purple_debug_warning("oscar", "Broken message contains <body> but not </body>!\n");
1474 /* Take everything after <body> */
1475 body
= g_strdup(start
);
1478 ichattextcolor
= g_datalist_get_data(&attribs
, "ichattextcolor");
1479 if (ichattextcolor
!= NULL
)
1481 tmp2
= g_strdup_printf("<font color=\"%s\">%s</font>", ichattextcolor
, body
);
1486 ichatballooncolor
= g_datalist_get_data(&attribs
, "ichatballooncolor");
1487 if (ichatballooncolor
!= NULL
)
1489 tmp2
= g_strdup_printf("<font back=\"%s\">%s</font>", ichatballooncolor
, body
);
1494 g_datalist_clear(&attribs
);
1497 tmp2
= g_strdup_printf("%.*s%s%s", len
, tmp
, body
, slash_body_end
? slash_body_end
+ 1: "</body>");
1505 * Are there <html/> surrounding tags? If so, strip them out, too.
1507 if (purple_markup_find_tag("html", tmp
, &start
, &end
, &attribs
))
1512 g_datalist_clear(&attribs
);
1515 tmp2
= g_strdup_printf("%.*s%s", len
, tmp
, end
+ 1);
1520 if (purple_markup_find_tag("/html", tmp
, &start
, &end
, &attribs
))
1525 g_datalist_clear(&attribs
);
1528 tmp2
= g_strdup_printf("%.*s%s", len
, tmp
, end
+ 1);
1533 purple_serv_got_im(gc
, userinfo
->bn
, tmp
, flags
, (args
->icbmflags
& AIM_IMFLAGS_OFFLINE
) ? args
->timestamp
: time(NULL
));
1540 incomingim_chan2(OscarData
*od
, FlapConnection
*conn
, aim_userinfo_t
*userinfo
, IcbmArgsCh2
*args
)
1542 PurpleConnection
*gc
;
1543 PurpleAccount
*account
;
1544 PurpleMessageFlags flags
= 0;
1545 char *message
= NULL
;
1547 g_return_val_if_fail(od
!= NULL
, 0);
1548 g_return_val_if_fail(od
->gc
!= NULL
, 0);
1551 account
= purple_connection_get_account(gc
);
1552 od
= purple_connection_get_protocol_data(gc
);
1557 purple_debug_misc("oscar", "Incoming rendezvous message of type %"
1558 G_GUINT64_FORMAT
", user %s, status %hu\n",
1559 args
->type
, userinfo
->bn
, args
->status
);
1561 if (args
->msg
!= NULL
) {
1562 message
= oscar_encoding_to_utf8(args
->encoding
, args
->msg
, args
->msglen
);
1565 if (args
->type
& OSCAR_CAPABILITY_CHAT
)
1567 char *utf8name
, *tmp
;
1568 GHashTable
*components
;
1570 if (!args
->info
.chat
.roominfo
.name
|| !args
->info
.chat
.roominfo
.exchange
) {
1574 utf8name
= oscar_encoding_to_utf8(args
->encoding
, args
->info
.chat
.roominfo
.name
, args
->info
.chat
.roominfo
.namelen
);
1576 tmp
= extract_name(utf8name
);
1583 components
= g_hash_table_new_full(g_str_hash
, g_str_equal
, g_free
,
1585 g_hash_table_replace(components
, g_strdup("room"), utf8name
);
1586 g_hash_table_replace(components
, g_strdup("exchange"),
1587 g_strdup_printf("%d", args
->info
.chat
.roominfo
.exchange
));
1588 purple_serv_got_chat_invite(gc
,
1595 else if ((args
->type
& OSCAR_CAPABILITY_SENDFILE
) || (args
->type
& OSCAR_CAPABILITY_DIRECTIM
))
1597 if (args
->status
== AIM_RENDEZVOUS_PROPOSE
)
1599 peer_connection_got_proposition(od
, userinfo
->bn
, message
, args
);
1601 else if (args
->status
== AIM_RENDEZVOUS_CANCEL
)
1603 /* The other user cancelled a peer request */
1604 PeerConnection
*conn
;
1606 conn
= peer_connection_find_by_cookie(od
, userinfo
->bn
, args
->cookie
);
1608 * If conn is NULL it means we haven't tried to create
1609 * a connection with that user. They may be trying to
1610 * do something malicious.
1614 peer_connection_destroy(conn
, OSCAR_DISCONNECT_REMOTE_CLOSED
, NULL
);
1617 else if (args
->status
== AIM_RENDEZVOUS_CONNECTED
)
1620 * Remote user has accepted our peer request. If we
1621 * wanted to we could look up the PeerConnection using
1622 * args->cookie, but we don't need to do anything here.
1627 else if (args
->type
& OSCAR_CAPABILITY_GETFILE
)
1631 else if (args
->type
& OSCAR_CAPABILITY_TALK
)
1635 else if (args
->type
& OSCAR_CAPABILITY_BUDDYICON
)
1637 purple_buddy_icons_set_for_user(account
, userinfo
->bn
,
1638 g_memdup(args
->info
.icon
.icon
, args
->info
.icon
.length
),
1639 args
->info
.icon
.length
,
1643 else if (args
->type
& OSCAR_CAPABILITY_ICQSERVERRELAY
)
1645 purple_debug_info("oscar", "Got an ICQ Server Relay message of "
1646 "type %d\n", args
->info
.rtfmsg
.msgtype
);
1648 if (args
->info
.rtfmsg
.msgtype
== 1) {
1649 if (args
->info
.rtfmsg
.msg
!= NULL
) {
1651 const char *encoding
= args
->encoding
;
1652 size_t len
= strlen(args
->info
.rtfmsg
.msg
);
1655 if (encoding
== NULL
&& !g_utf8_validate(args
->info
.rtfmsg
.msg
, len
, NULL
)) {
1656 /* Yet another wonderful Miranda-related hack. If their user disables the "Send Unicode messages" setting,
1657 * Miranda sends us ch2 messages in whatever Windows codepage is set as default on their user's system (instead of UTF-8).
1658 * Of course, they don't bother to specify that codepage. Let's just fallback to the encoding OUR users can
1659 * specify in account options as a last resort.
1661 encoding
= purple_account_get_string(account
, "encoding", OSCAR_DEFAULT_CUSTOM_ENCODING
);
1662 purple_debug_info("oscar", "Miranda, is that you? Using '%s' as encoding\n", encoding
);
1665 rtfmsg
= oscar_encoding_to_utf8(encoding
, args
->info
.rtfmsg
.msg
, len
);
1667 /* Channel 2 messages are supposed to be plain-text (never mind the name "rtfmsg", even
1668 * the official client doesn't parse them as RTF). Therefore, we should escape them before
1669 * showing to the user. */
1670 tmp
= g_markup_escape_text(rtfmsg
, -1);
1672 tmp2
= purple_strreplace(tmp
, "\r\n", "<br>");
1675 purple_serv_got_im(gc
, userinfo
->bn
, tmp2
, flags
, time(NULL
));
1676 aim_im_send_icq_confirmation(od
, userinfo
->bn
, args
->cookie
);
1679 } else if (args
->info
.rtfmsg
.msgtype
== 26) {
1680 purple_debug_info("oscar", "Sending X-Status Reply\n");
1681 icq_relay_xstatus(od
, userinfo
->bn
, args
->cookie
);
1686 purple_debug_error("oscar", "Unknown request class %"
1687 G_GUINT64_FORMAT
"\n", args
->type
);
1695 /* When someone sends you buddies */
1697 purple_icq_buddyadd(struct name_data
*data
)
1699 PurpleConnection
*gc
= data
->gc
;
1701 purple_blist_request_add_buddy(purple_connection_get_account(gc
), data
->name
, NULL
, data
->nick
);
1703 oscar_free_name_data(data
);
1707 incomingim_chan4(OscarData
*od
, FlapConnection
*conn
, aim_userinfo_t
*userinfo
,
1708 struct aim_incomingim_ch4_args
*args
)
1710 PurpleConnection
*gc
= od
->gc
;
1711 PurpleAccount
*account
= purple_connection_get_account(gc
);
1712 gchar
**msg1
, **msg2
;
1715 if (!args
->type
|| !args
->msg
|| !args
->uin
)
1718 purple_debug_info("oscar",
1719 "Received a channel 4 message of type 0x%02hx.",
1720 (guint16
)args
->type
);
1723 * Split up the message at the delimeter character, then convert each
1724 * string to UTF-8. Unless, of course, this is a type 1 message. If
1725 * this is a type 1 message, then the delimiter 0xfe could be a valid
1726 * character in whatever encoding the message was sent in. Type 1
1727 * messages are always made up of only one part, so we can easily account
1728 * for this suck-ass part of the protocol by splitting the string into at
1729 * most 1 baby string.
1731 msg1
= g_strsplit(args
->msg
, "\376", (args
->type
== 0x01 ? 1 : 0));
1732 for (numtoks
=0; msg1
[numtoks
]; numtoks
++);
1733 msg2
= (gchar
**)g_malloc((numtoks
+1)*sizeof(gchar
*));
1734 for (i
=0; msg1
[i
]; i
++) {
1735 gchar
*uin
= g_strdup_printf("%u", args
->uin
);
1737 purple_str_strip_char(msg1
[i
], '\r');
1738 /* TODO: Should use an encoding other than ASCII? */
1739 msg2
[i
] = oscar_decode_im(account
, uin
, AIM_CHARSET_ASCII
, msg1
[i
], strlen(msg1
[i
]));
1744 switch (args
->type
) {
1745 case 0x01: { /* MacICQ message or basic offline message */
1747 gchar
*uin
= g_strdup_printf("%u", args
->uin
);
1750 /* If the message came from an ICQ user then escape any HTML */
1751 tmp
= g_markup_escape_text(msg2
[0], -1);
1753 purple_serv_got_im(gc
, uin
, tmp
, 0, time(NULL
));
1760 case 0x04: { /* Someone sent you a URL */
1762 if (msg2
[1] != NULL
) {
1763 gchar
*uin
= g_strdup_printf("%u", args
->uin
);
1764 gchar
*message
= g_strdup_printf("<A HREF=\"%s\">%s</A>",
1766 (msg2
[0] && msg2
[0][0]) ? msg2
[0] : msg2
[1]);
1767 purple_serv_got_im(gc
, uin
, message
, 0, time(NULL
));
1774 case 0x06: { /* Someone requested authorization */
1776 gchar
*bn
= g_strdup_printf("%u", args
->uin
);
1777 gchar
*reason
= NULL
;
1779 if (msg2
[5] != NULL
)
1780 reason
= oscar_decode_im(account
, bn
, AIM_CHARSET_LATIN_1
, msg2
[5], strlen(msg2
[5]));
1782 purple_debug_info("oscar",
1783 "Received an authorization request from UIN %u\n",
1785 aim_icq_getalias(od
, bn
, TRUE
, reason
);
1791 case 0x07: { /* Someone has denied you authorization */
1793 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."));
1794 purple_notify_info(gc
, NULL
, _("ICQ authorization denied."), dialog_msg
, purple_request_cpar_from_connection(gc
));
1799 case 0x08: { /* Someone has granted you authorization */
1800 gchar
*dialog_msg
= g_strdup_printf(_("The user %u has granted your request to add them to your buddy list."), args
->uin
);
1801 purple_notify_info(gc
, NULL
, "ICQ authorization accepted.", dialog_msg
, purple_request_cpar_from_connection(gc
));
1805 case 0x09: { /* Message from the Godly ICQ server itself, I think */
1807 gchar
*dialog_msg
= g_strdup_printf(_("You have received a special message\n\nFrom: %s [%s]\n%s"), msg2
[0], msg2
[3], msg2
[5]);
1808 purple_notify_info(gc
, NULL
, "ICQ Server Message", dialog_msg
, purple_request_cpar_from_connection(gc
));
1813 case 0x0d: { /* Someone has sent you a pager message from http://www.icq.com/your_uin */
1815 gchar
*dialog_msg
= g_strdup_printf(_("You have received an ICQ page\n\nFrom: %s [%s]\n%s"), msg2
[0], msg2
[3], msg2
[5]);
1816 purple_notify_info(gc
, NULL
, "ICQ Page", dialog_msg
, purple_request_cpar_from_connection(gc
));
1821 case 0x0e: { /* Someone has emailed you at your_uin@pager.icq.com */
1823 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]);
1824 purple_notify_info(gc
, NULL
, "ICQ Email", dialog_msg
, purple_request_cpar_from_connection(gc
));
1830 /* Ack for authorizing/denying someone. Or possibly an ack for sending any system notice */
1831 /* Someone added you to their buddy list? */
1834 case 0x13: { /* Someone has sent you some ICQ buddies */
1837 text
= g_strsplit(args
->msg
, "\376", 0);
1839 /* Read the number of contacts that we were sent */
1841 num
= text
[0] ? strtoul(text
[0], NULL
, 10) : 0;
1843 if (num
> 0 && errno
== 0) {
1844 for (i
=0; i
<num
; i
++) {
1845 struct name_data
*data
;
1848 if (!text
[i
*2 + 1] || !text
[i
*2 + 2]) {
1849 /* We're missing the contact name or nickname. Bail out. */
1850 gchar
*tmp
= g_strescape(args
->msg
, NULL
);
1851 purple_debug_error("oscar", "Unknown syntax parsing "
1852 "ICQ buddies. args->msg=%s\n", tmp
);
1857 message
= g_strdup_printf(_("ICQ user %u has sent you a buddy: %s (%s)"), args
->uin
, text
[i
*2+2], text
[i
*2+1]);
1859 data
= g_new(struct name_data
, 1);
1861 data
->name
= g_strdup(text
[i
*2+1]);
1862 data
->nick
= g_strdup(text
[i
*2+2]);
1864 purple_request_action(gc
, NULL
, message
,
1865 _("Do you want to add this buddy "
1866 "to your buddy list?"),
1867 PURPLE_DEFAULT_ACTION_NONE
,
1868 purple_request_cpar_from_connection(gc
),
1870 _("_Add"), G_CALLBACK(purple_icq_buddyadd
),
1871 _("_Decline"), G_CALLBACK(oscar_free_name_data
));
1875 gchar
*tmp
= g_strescape(args
->msg
, NULL
);
1876 purple_debug_error("oscar", "Unknown syntax parsing "
1877 "ICQ buddies. args->msg=%s\n", tmp
);
1884 case 0x1a: { /* Handle SMS or someone has sent you a greeting card or requested buddies? */
1887 guint32 taglen
, smslen
;
1888 char *tagstr
= NULL
, *smsmsg
= NULL
;
1889 PurpleXmlNode
*xmlroot
= NULL
, *xmltmp
= NULL
;
1890 gchar
*uin
= NULL
, *message
= NULL
;
1892 /* From libicq2000-0.3.2/src/ICQ.cpp */
1893 byte_stream_init(&qbs
, (guint8
*)args
->msg
, args
->msglen
);
1894 byte_stream_advance(&qbs
, 21);
1895 /* 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 ...*/
1896 /* 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 ... */
1897 smstype
= byte_stream_getle16(&qbs
);
1900 taglen
= byte_stream_getle32(&qbs
);
1901 if (taglen
> 2000) {
1902 /* Avoid trying to allocate large amounts of memory, in
1903 case we get something unexpected. */
1906 tagstr
= byte_stream_getstr(&qbs
, taglen
);
1909 byte_stream_advance(&qbs
, 3);
1910 byte_stream_advance(&qbs
, 4);
1911 smslen
= byte_stream_getle32(&qbs
);
1912 if (smslen
> 2000) {
1913 /* Avoid trying to allocate large amounts of memory, in
1914 case we get something unexpected. */
1918 smsmsg
= byte_stream_getstr(&qbs
, smslen
);
1920 /* Check if this is an SMS being sent from server */
1921 if (purple_strequal(tagstr
, "ICQSMS") && smsmsg
!= NULL
) {
1922 xmlroot
= purple_xmlnode_from_str(smsmsg
, -1);
1923 if (xmlroot
!= NULL
)
1925 xmltmp
= purple_xmlnode_get_child(xmlroot
, "sender");
1927 uin
= purple_xmlnode_get_data(xmltmp
);
1929 xmltmp
= purple_xmlnode_get_child(xmlroot
, "text");
1931 message
= purple_xmlnode_get_data(xmltmp
);
1933 if ((uin
!= NULL
) && (message
!= NULL
))
1934 purple_serv_got_im(gc
, uin
, message
, 0, time(NULL
));
1938 purple_xmlnode_free(xmlroot
);
1946 purple_debug_info("oscar",
1947 "Received a channel 4 message of unknown type "
1948 "(type 0x%02x).\n", args
->type
& 0xFF);
1958 static int purple_parse_incoming_im(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...) {
1961 aim_userinfo_t
*userinfo
;
1965 channel
= (guint16
)va_arg(ap
, unsigned int);
1966 userinfo
= va_arg(ap
, aim_userinfo_t
*);
1969 case 1: { /* standard message */
1970 struct aim_incomingim_ch1_args
*args
;
1971 args
= va_arg(ap
, struct aim_incomingim_ch1_args
*);
1972 ret
= incomingim_chan1(od
, conn
, userinfo
, args
);
1975 case 2: { /* rendezvous */
1977 args
= va_arg(ap
, IcbmArgsCh2
*);
1978 ret
= incomingim_chan2(od
, conn
, userinfo
, args
);
1982 struct aim_incomingim_ch4_args
*args
;
1983 args
= va_arg(ap
, struct aim_incomingim_ch4_args
*);
1984 ret
= incomingim_chan4(od
, conn
, userinfo
, args
);
1988 purple_debug_warning("oscar",
1989 "ICBM received on unsupported channel (channel "
1990 "0x%04hx).", channel
);
1999 static int purple_parse_misses(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...) {
2000 PurpleConnection
*gc
= od
->gc
;
2001 PurpleAccount
*account
= purple_connection_get_account(gc
);
2004 guint16 nummissed
, reason
;
2005 aim_userinfo_t
*userinfo
;
2008 va_arg(ap
, unsigned int); /* guint16 chan */
2009 userinfo
= va_arg(ap
, aim_userinfo_t
*);
2010 nummissed
= (guint16
)va_arg(ap
, unsigned int);
2011 reason
= (guint16
)va_arg(ap
, unsigned int);
2015 case 0: /* Invalid (0) */
2016 buf
= g_strdup_printf(
2018 "You missed %hu message from %s because it was invalid.",
2019 "You missed %hu messages from %s because they were invalid.",
2024 case 1: /* Message too large */
2025 buf
= g_strdup_printf(
2027 "You missed %hu message from %s because it was too large.",
2028 "You missed %hu messages from %s because they were too large.",
2033 case 2: /* Rate exceeded */
2034 buf
= g_strdup_printf(
2036 "You missed %hu message from %s because the rate limit has been exceeded.",
2037 "You missed %hu messages from %s because the rate limit has been exceeded.",
2042 case 3: /* Evil Sender */
2043 buf
= g_strdup_printf(
2045 "You missed %hu message from %s because his/her warning level is too high.",
2046 "You missed %hu messages from %s because his/her warning level is too high.",
2051 case 4: /* Evil Receiver */
2052 buf
= g_strdup_printf(
2054 "You missed %hu message from %s because your warning level is too high.",
2055 "You missed %hu messages from %s because your warning level is too high.",
2061 buf
= g_strdup_printf(
2063 "You missed %hu message from %s for an unknown reason.",
2064 "You missed %hu messages from %s for an unknown reason.",
2071 if (!purple_conversation_present_error(userinfo
->bn
, account
, buf
)) {
2072 purple_notify_error(od
->gc
, NULL
, buf
, NULL
,
2073 purple_request_cpar_from_connection(od
->gc
));
2081 purple_parse_clientauto_ch2(OscarData
*od
, const char *who
, guint16 reason
, const guchar
*cookie
)
2083 if (reason
== 0x0003)
2085 /* Rendezvous was refused. */
2086 PeerConnection
*conn
;
2088 conn
= peer_connection_find_by_cookie(od
, who
, cookie
);
2092 purple_debug_info("oscar", "Received a rendezvous cancel message "
2093 "for a nonexistant connection from %s.\n", who
);
2097 peer_connection_destroy(conn
, OSCAR_DISCONNECT_REMOTE_REFUSED
, NULL
);
2102 purple_debug_warning("oscar", "Received an unknown rendezvous "
2103 "message from %s. Type 0x%04hx\n", who
, reason
);
2109 static int purple_parse_clientauto_ch4(OscarData
*od
, const char *who
, guint16 reason
, guint32 state
, char *msg
) {
2110 PurpleConnection
*gc
= od
->gc
;
2113 /* Reply from an ICQ status message request */
2116 char *statusmsg
, **splitmsg
;
2117 PurpleNotifyUserInfo
*user_info
;
2119 statusmsg
= oscar_icqstatus(state
);
2121 /* Split at (carriage return/newline)'s, then rejoin later with BRs between. */
2122 /* TODO: Don't we need to escape each piece? */
2123 splitmsg
= g_strsplit(msg
, "\r\n", 0);
2125 user_info
= purple_notify_user_info_new();
2127 purple_notify_user_info_add_pair_plaintext(user_info
, _("UIN"), who
);
2128 /* TODO: Check whether it's correct to call add_pair_html,
2129 or if we should be using add_pair_plaintext */
2130 purple_notify_user_info_add_pair_html(user_info
, _("Status"), statusmsg
);
2131 purple_notify_user_info_add_section_break(user_info
);
2132 purple_notify_user_info_add_pair_html(user_info
, NULL
, g_strjoinv("<BR>", splitmsg
));
2135 g_strfreev(splitmsg
);
2137 purple_notify_userinfo(gc
, who
, user_info
, NULL
, NULL
);
2138 purple_notify_user_info_destroy(user_info
);
2143 purple_debug_warning("oscar",
2144 "Received an unknown client auto-response from %s. "
2145 "Type 0x%04hx\n", who
, reason
);
2147 } /* end of switch */
2152 static int purple_parse_clientauto(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...) {
2154 guint16 chan
, reason
;
2159 chan
= (guint16
)va_arg(ap
, unsigned int);
2160 who
= va_arg(ap
, char *);
2161 reason
= (guint16
)va_arg(ap
, unsigned int);
2163 if (chan
== 0x0002) { /* File transfer declined */
2164 guchar
*cookie
= va_arg(ap
, guchar
*);
2165 ret
= purple_parse_clientauto_ch2(od
, who
, reason
, cookie
);
2166 } else if (chan
== 0x0004) { /* ICQ message */
2169 if (reason
== 0x0003) {
2170 state
= va_arg(ap
, guint32
);
2171 msg
= va_arg(ap
, char *);
2173 ret
= purple_parse_clientauto_ch4(od
, who
, reason
, state
, msg
);
2181 static int purple_parse_genericerr(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...) {
2186 reason
= (guint16
) va_arg(ap
, unsigned int);
2189 purple_debug_error("oscar", "snac threw error (reason 0x%04hx: %s)\n",
2190 reason
, oscar_get_msgerr_reason(reason
));
2194 static int purple_parse_mtn(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...) {
2195 PurpleConnection
*gc
= od
->gc
;
2197 guint16 channel
, event
;
2201 channel
= (guint16
) va_arg(ap
, unsigned int);
2202 bn
= va_arg(ap
, char *);
2203 event
= (guint16
) va_arg(ap
, unsigned int);
2207 case 0x0000: /* Text has been cleared */
2208 case 0x000f: /* Closed IM window */
2209 purple_serv_got_typing_stopped(gc
, bn
);
2212 case 0x0001: /* Paused typing */
2213 purple_serv_got_typing(gc
, bn
, 0, PURPLE_IM_TYPED
);
2216 case 0x0002: /* Typing */
2217 purple_serv_got_typing(gc
, bn
, 0, PURPLE_IM_TYPING
);
2221 purple_debug_info("oscar", "Received unknown typing "
2222 "notification message from %s. Channel is 0x%04x "
2223 "and event is 0x%04hx.\n", bn
, channel
, event
);
2230 static int purple_parse_motd(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...)
2237 id
= (guint16
) va_arg(ap
, unsigned int);
2238 msg
= va_arg(ap
, char *);
2241 purple_debug_misc("oscar",
2242 "MOTD: %s (%hu)\n", msg
? msg
: "Unknown", id
);
2244 purple_notify_warning(od
->gc
, NULL
,
2245 _("Your AIM connection may be lost."), NULL
,
2246 purple_request_cpar_from_connection(od
->gc
));
2252 static int purple_chatnav_info(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...) {
2257 type
= (guint16
) va_arg(ap
, unsigned int);
2261 GString
*msg
= g_string_new("");
2263 struct aim_chat_exchangeinfo
*exchanges
;
2264 int exchangecount
, i
;
2266 maxrooms
= (guint8
) va_arg(ap
, unsigned int);
2267 exchangecount
= va_arg(ap
, int);
2268 exchanges
= va_arg(ap
, struct aim_chat_exchangeinfo
*);
2270 g_string_append_printf(msg
, "chat info: Max Concurrent Rooms: %d, Exchange List (%d total): ", (int)maxrooms
, exchangecount
);
2271 for (i
= 0; i
< exchangecount
; i
++) {
2272 g_string_append_printf(msg
, "%hu", exchanges
[i
].number
);
2273 if (exchanges
[i
].name
) {
2274 g_string_append_printf(msg
, " %s", exchanges
[i
].name
);
2276 g_string_append(msg
, ", ");
2278 purple_debug_misc("oscar", "%s\n", msg
->str
);
2279 g_string_free(msg
, TRUE
);
2281 while (od
->create_rooms
) {
2282 struct create_room
*cr
= od
->create_rooms
->data
;
2283 purple_debug_info("oscar",
2284 "creating room %s\n", cr
->name
);
2285 aim_chatnav_createroom(od
, conn
, cr
->name
, cr
->exchange
);
2287 od
->create_rooms
= g_slist_remove(od
->create_rooms
, cr
);
2293 char *fqcn
, *name
, *ck
;
2294 guint16 instance
, flags
, maxmsglen
, maxoccupancy
, unknown
, exchange
;
2298 fqcn
= va_arg(ap
, char *);
2299 instance
= (guint16
)va_arg(ap
, unsigned int);
2300 exchange
= (guint16
)va_arg(ap
, unsigned int);
2301 flags
= (guint16
)va_arg(ap
, unsigned int);
2302 createtime
= va_arg(ap
, guint32
);
2303 maxmsglen
= (guint16
)va_arg(ap
, unsigned int);
2304 maxoccupancy
= (guint16
)va_arg(ap
, unsigned int);
2305 createperms
= (guint8
)va_arg(ap
, unsigned int);
2306 unknown
= (guint16
)va_arg(ap
, unsigned int);
2307 name
= va_arg(ap
, char *);
2308 ck
= va_arg(ap
, char *);
2310 purple_debug_misc("oscar",
2311 "created room: %s %hu %hu %hu %u %hu %hu %u %hu %s %s\n",
2312 fqcn
? fqcn
: "(null)", exchange
, instance
, flags
, createtime
,
2313 maxmsglen
, maxoccupancy
, (guint
)createperms
, unknown
,
2314 name
? name
: "(null)", ck
);
2315 aim_chat_join(od
, exchange
, ck
, instance
);
2319 purple_debug_warning("oscar",
2320 "chatnav info: unknown type (%04hx)\n", type
);
2329 static int purple_chat_conversation_join(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...) {
2332 aim_userinfo_t
*info
;
2333 PurpleConnection
*gc
= od
->gc
;
2335 struct chat_connection
*c
= NULL
;
2338 count
= va_arg(ap
, int);
2339 info
= va_arg(ap
, aim_userinfo_t
*);
2342 c
= find_oscar_chat_by_conn(gc
, conn
);
2346 for (i
= 0; i
< count
; i
++)
2347 purple_chat_conversation_add_user(c
->conv
, info
[i
].bn
, NULL
, PURPLE_CHAT_USER_NONE
, TRUE
);
2352 static int purple_chat_conversation_left(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...) {
2355 aim_userinfo_t
*info
;
2356 PurpleConnection
*gc
= od
->gc
;
2358 struct chat_connection
*c
= NULL
;
2361 count
= va_arg(ap
, int);
2362 info
= va_arg(ap
, aim_userinfo_t
*);
2365 c
= find_oscar_chat_by_conn(gc
, conn
);
2369 for (i
= 0; i
< count
; i
++)
2370 purple_chat_conversation_remove_user(c
->conv
, info
[i
].bn
, NULL
);
2375 static int purple_chat_conversation_info_update(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...) {
2377 guint16 maxmsglen
, maxvisiblemsglen
;
2378 PurpleConnection
*gc
= od
->gc
;
2379 struct chat_connection
*ccon
= find_oscar_chat_by_conn(gc
, conn
);
2385 maxmsglen
= (guint16
)va_arg(ap
, unsigned int);
2386 maxvisiblemsglen
= (guint16
)va_arg(ap
, unsigned int);
2389 purple_debug_misc("oscar",
2390 "inside chat_info_update (maxmsglen = %hu, maxvislen = %hu)\n",
2391 maxmsglen
, maxvisiblemsglen
);
2393 ccon
->maxlen
= maxmsglen
;
2394 ccon
->maxvis
= maxvisiblemsglen
;
2399 static int purple_chat_conversation_incoming_msg(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...) {
2400 PurpleConnection
*gc
= od
->gc
;
2401 struct chat_connection
*ccon
= find_oscar_chat_by_conn(gc
, conn
);
2404 aim_userinfo_t
*info
;
2413 info
= va_arg(ap
, aim_userinfo_t
*);
2414 len
= va_arg(ap
, int);
2415 msg
= va_arg(ap
, char *);
2416 charset
= va_arg(ap
, char *);
2419 utf8
= oscar_encoding_to_utf8(charset
, msg
, len
);
2420 purple_serv_got_chat_in(gc
, ccon
->id
, info
->bn
,
2421 PURPLE_MESSAGE_RECV
, utf8
, time(NULL
));
2427 static int purple_email_parseupdate(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...) {
2429 PurpleConnection
*gc
;
2430 PurpleAccount
*account
;
2431 struct aim_emailinfo
*emailinfo
;
2433 char *alertitle
, *alerturl
;
2436 account
= purple_connection_get_account(gc
);
2439 emailinfo
= va_arg(ap
, struct aim_emailinfo
*);
2440 havenewmail
= va_arg(ap
, int);
2441 alertitle
= va_arg(ap
, char *);
2442 alerturl
= va_arg(ap
, char *);
2445 if (account
!= NULL
&& emailinfo
!= NULL
&& purple_account_get_check_mail(account
) &&
2446 emailinfo
->unread
&& havenewmail
) {
2447 gchar
*to
= g_strdup_printf("%s%s%s",
2448 purple_account_get_username(account
),
2449 emailinfo
->domain
? "@" : "",
2450 emailinfo
->domain
? emailinfo
->domain
: "");
2451 const char *tos
[2] = { to
};
2452 const char *urls
[2] = { emailinfo
->url
};
2453 purple_notify_emails(gc
, emailinfo
->nummsgs
, FALSE
, NULL
, NULL
,
2454 tos
, urls
, NULL
, NULL
);
2459 purple_debug_misc("oscar", "Got an alert '%s' %s\n", alertitle
, alerturl
? alerturl
: "");
2464 static int purple_icon_parseicon(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...) {
2465 PurpleConnection
*gc
= od
->gc
;
2468 guint8
*iconcsum
, *icon
;
2469 guint16 iconcsumlen
, iconlen
;
2472 bn
= va_arg(ap
, char *);
2473 va_arg(ap
, int); /* iconsumtype */
2474 iconcsum
= va_arg(ap
, guint8
*);
2475 iconcsumlen
= va_arg(ap
, int);
2476 icon
= va_arg(ap
, guint8
*);
2477 iconlen
= va_arg(ap
, int);
2481 * Some AIM clients will send a blank GIF image with iconlen 90 when
2482 * no icon is set. Ignore these.
2484 if ((iconlen
> 0) && (iconlen
!= 90)) {
2485 char *b16
= purple_base16_encode(iconcsum
, iconcsumlen
);
2486 purple_buddy_icons_set_for_user(purple_connection_get_account(gc
),
2487 bn
, g_memdup(icon
, iconlen
), iconlen
, b16
);
2495 purple_icons_fetch(PurpleConnection
*gc
)
2497 OscarData
*od
= purple_connection_get_protocol_data(gc
);
2498 aim_userinfo_t
*userinfo
;
2499 FlapConnection
*conn
;
2501 conn
= flap_connection_getbytype(od
, SNAC_FAMILY_BART
);
2503 if (!od
->iconconnecting
) {
2504 aim_srv_requestnew(od
, SNAC_FAMILY_BART
);
2505 od
->iconconnecting
= TRUE
;
2511 PurpleAccount
*account
= purple_connection_get_account(gc
);
2512 PurpleImage
*img
= purple_buddy_icons_find_account_icon(account
);
2514 aim_ssi_delicon(od
);
2516 purple_debug_info("oscar",
2517 "Uploading icon to icon server");
2518 aim_bart_upload(od
, purple_image_get_data(img
),
2519 purple_image_get_data_size(img
));
2520 g_object_unref(img
);
2522 od
->set_icon
= FALSE
;
2525 while (od
->requesticon
!= NULL
)
2527 userinfo
= aim_locate_finduserinfo(od
, (char *)od
->requesticon
->data
);
2528 if ((userinfo
!= NULL
) && (userinfo
->iconcsumlen
> 0))
2529 aim_bart_request(od
, od
->requesticon
->data
, userinfo
->iconcsumtype
, userinfo
->iconcsum
, userinfo
->iconcsumlen
);
2531 g_free(od
->requesticon
->data
);
2532 od
->requesticon
= g_slist_delete_link(od
->requesticon
, od
->requesticon
);
2535 purple_debug_misc("oscar", "no more icons to request\n");
2538 static int purple_selfinfo(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...) {
2540 aim_userinfo_t
*info
;
2543 info
= va_arg(ap
, aim_userinfo_t
*);
2546 purple_connection_set_display_name(od
->gc
, info
->bn
);
2551 static int purple_connerr(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...) {
2552 PurpleConnection
*gc
= od
->gc
;
2558 code
= (guint16
)va_arg(ap
, int);
2559 msg
= va_arg(ap
, char *);
2562 purple_debug_info("oscar", "Disconnected. Code is 0x%04x and msg is %s\n",
2563 code
, (msg
!= NULL
? msg
: ""));
2565 g_return_val_if_fail(conn
!= NULL
, 1);
2567 if (conn
->type
== SNAC_FAMILY_CHAT
) {
2568 struct chat_connection
*cc
;
2569 PurpleChatConversation
*chat
= NULL
;
2571 cc
= find_oscar_chat_by_conn(gc
, conn
);
2574 chat
= purple_conversations_find_chat(gc
, cc
->id
);
2579 * TOOD: Have flap_connection_destroy_cb() send us the
2580 * error message stored in 'tmp', which should be
2581 * human-friendly, and print that to the chat room.
2584 buf
= g_strdup_printf(_("You have been disconnected from chat "
2585 "room %s."), cc
->name
);
2586 purple_conversation_write_system_message(
2587 PURPLE_CONVERSATION(chat
), buf
,
2588 PURPLE_MESSAGE_ERROR
);
2591 oscar_chat_kill(gc
, cc
);
2598 static int purple_parse_locaterights(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...)
2600 PurpleConnection
*gc
= od
->gc
;
2601 PurpleAccount
*account
= purple_connection_get_account(gc
);
2606 maxsiglen
= (guint16
) va_arg(ap
, int);
2609 purple_debug_misc("oscar",
2610 "locate rights: max sig len = %d\n", maxsiglen
);
2612 od
->rights
.maxsiglen
= od
->rights
.maxawaymsglen
= (guint
)maxsiglen
;
2614 aim_locate_setcaps(od
, purple_caps
);
2615 oscar_set_info_and_status(account
, TRUE
, purple_account_get_user_info(account
), TRUE
,
2616 purple_account_get_active_status(account
));
2621 static int purple_parse_buddyrights(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...) {
2623 guint16 maxbuddies
, maxwatchers
;
2626 maxbuddies
= (guint16
) va_arg(ap
, unsigned int);
2627 maxwatchers
= (guint16
) va_arg(ap
, unsigned int);
2630 purple_debug_misc("oscar",
2631 "buddy list rights: Max buddies = %hu / Max watchers = %hu\n", maxbuddies
, maxwatchers
);
2633 od
->rights
.maxbuddies
= (guint
)maxbuddies
;
2634 od
->rights
.maxwatchers
= (guint
)maxwatchers
;
2639 static void oscar_format_username(PurpleConnection
*gc
, const char *new_display_name
)
2642 const char *old_display_name
, *username
;
2643 char *tmp
, *at_sign
;
2645 old_display_name
= purple_connection_get_display_name(gc
);
2646 if (old_display_name
&& strchr(old_display_name
, '@')) {
2647 purple_debug_info("oscar", "Cowardly refusing to attempt to format "
2648 "screen name because the current formatting according to "
2649 "the server (%s) appears to be an email address\n",
2654 username
= purple_account_get_username(purple_connection_get_account(gc
));
2655 if (oscar_util_name_compare(username
, new_display_name
)) {
2656 purple_notify_error(gc
, NULL
, _("The new formatting is invalid."),
2657 _("Username formatting can change only capitalization and whitespace."),
2658 purple_request_cpar_from_connection(gc
));
2662 tmp
= g_strdup(new_display_name
);
2665 * If our local username is an email address then strip off the domain.
2666 * This allows formatting to work if the user entered their username as
2667 * 'something@aim.com' or possibly other AOL-owned domains.
2669 at_sign
= strchr(tmp
, '@');
2673 od
= purple_connection_get_protocol_data(gc
);
2674 if (!flap_connection_getbytype(od
, SNAC_FAMILY_ADMIN
)) {
2675 /* We don't have a connection to an "admin" server. Make one. */
2677 g_free(od
->newformatting
);
2678 od
->newformatting
= tmp
;
2679 aim_srv_requestnew(od
, SNAC_FAMILY_ADMIN
);
2681 aim_admin_setnick(od
, flap_connection_getbytype(od
, SNAC_FAMILY_ADMIN
), tmp
);
2686 static int purple_bosrights(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...) {
2687 PurpleConnection
*gc
;
2688 PurpleAccount
*account
;
2689 PurpleStatus
*status
;
2690 gboolean is_available
;
2691 PurplePresence
*presence
;
2692 const char *username
, *message
, *itmsurl
;
2695 guint16 maxpermits
, maxdenies
;
2698 od
= purple_connection_get_protocol_data(gc
);
2699 account
= purple_connection_get_account(gc
);
2702 maxpermits
= (guint16
) va_arg(ap
, unsigned int);
2703 maxdenies
= (guint16
) va_arg(ap
, unsigned int);
2706 purple_debug_misc("oscar",
2707 "BOS rights: Max permit = %hu / Max deny = %hu\n", maxpermits
, maxdenies
);
2709 od
->rights
.maxpermits
= (guint
)maxpermits
;
2710 od
->rights
.maxdenies
= (guint
)maxdenies
;
2712 purple_debug_info("oscar", "buddy list loaded\n");
2714 if (purple_account_get_user_info(account
) != NULL
)
2715 purple_serv_set_info(gc
, purple_account_get_user_info(account
));
2717 username
= purple_account_get_username(account
);
2718 if (!od
->icq
&& !purple_strequal(username
, purple_connection_get_display_name(gc
))) {
2720 * Format the username for AIM accounts if it's different
2721 * than what's currently set.
2723 oscar_format_username(gc
, username
);
2726 /* Set our available message based on the current status */
2727 status
= purple_account_get_active_status(account
);
2728 is_available
= purple_status_is_available(status
);
2730 message
= purple_status_get_attr_string(status
, "message");
2733 tmp
= purple_markup_strip_html(message
);
2734 itmsurl
= purple_status_get_attr_string(status
, "itmsurl");
2735 aim_srv_setextrainfo(od
, FALSE
, 0, is_available
, tmp
, itmsurl
);
2736 aim_srv_set_dc_info(od
);
2739 presence
= purple_status_get_presence(status
);
2740 aim_srv_setidle(od
, !purple_presence_is_idle(presence
) ? 0 : time(NULL
) - purple_presence_get_idle_time(presence
));
2743 oscar_set_extended_status(gc
);
2744 aim_icq_setsecurity(od
,
2745 purple_account_get_bool(account
, "authorization", OSCAR_DEFAULT_AUTHORIZATION
),
2746 purple_account_get_bool(account
, "web_aware", OSCAR_DEFAULT_WEB_AWARE
));
2749 aim_srv_requestnew(od
, SNAC_FAMILY_ALERT
);
2750 aim_srv_requestnew(od
, SNAC_FAMILY_CHATNAV
);
2752 od
->bos
.have_rights
= TRUE
;
2755 * If we've already received our feedbag data then we're not waiting on
2756 * anything else, so send the server clientready.
2758 * Normally we get bos rights before we get our feedbag data, so this
2759 * rarely (never?) happens. And I'm not sure it actually matters if we
2760 * wait for bos rights before calling clientready. But it seems safer
2761 * to do it this way.
2763 if (od
->ssi
.received_data
) {
2764 aim_srv_clientready(od
, conn
);
2766 /* Request offline messages for AIM and ICQ */
2767 aim_im_reqofflinemsgs(od
);
2769 purple_connection_set_state(gc
, PURPLE_CONNECTION_CONNECTED
);
2775 static int purple_popup(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...)
2777 PurpleConnection
*gc
= od
->gc
;
2783 msg
= va_arg(ap
, char *);
2784 url
= va_arg(ap
, char *);
2785 va_arg(ap
, int); /* guint16 wid */
2786 va_arg(ap
, int); /* guint16 hei */
2787 va_arg(ap
, int); /* guint16 delay */
2790 text
= g_strdup_printf("%s<br><a href=\"%s\">%s</a>", msg
, url
, url
);
2791 purple_notify_formatted(gc
, NULL
, _("Pop-Up Message"), NULL
, text
, NULL
, NULL
);
2797 static void oscar_searchresults_add_buddy_cb(PurpleConnection
*gc
, GList
*row
, void *user_data
)
2799 purple_blist_request_add_buddy(purple_connection_get_account(gc
),
2800 g_list_nth_data(row
, 0), NULL
, NULL
);
2803 static int purple_parse_searchreply(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...)
2805 PurpleConnection
*gc
= od
->gc
;
2806 PurpleNotifySearchResults
*results
;
2807 PurpleNotifySearchColumn
*column
;
2811 char *email
, *usernames
;
2814 email
= va_arg(ap
, char *);
2815 num
= va_arg(ap
, int);
2816 usernames
= va_arg(ap
, char *);
2819 results
= purple_notify_searchresults_new();
2821 if (results
== NULL
) {
2822 purple_debug_error("oscar", "purple_parse_searchreply: "
2823 "Unable to display the search results.\n");
2824 purple_notify_error(gc
, NULL
, _("Unable to display the search "
2826 purple_request_cpar_from_connection(gc
));
2830 secondary
= g_strdup_printf(
2831 dngettext(PACKAGE
, "The following username is associated with %s",
2832 "The following usernames are associated with %s",
2836 column
= purple_notify_searchresults_column_new(_("Username"));
2837 purple_notify_searchresults_column_add(results
, column
);
2839 for (i
= 0; i
< num
; i
++) {
2841 row
= g_list_append(NULL
, g_strdup(&usernames
[i
* (MAXSNLEN
+ 1)]));
2842 purple_notify_searchresults_row_add(results
, row
);
2844 purple_notify_searchresults_button_add(results
, PURPLE_NOTIFY_BUTTON_ADD
,
2845 oscar_searchresults_add_buddy_cb
);
2846 purple_notify_searchresults(gc
, NULL
, NULL
, secondary
, results
, NULL
, NULL
);
2853 static int purple_parse_searcherror(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...) {
2859 email
= va_arg(ap
, char *);
2862 buf
= g_strdup_printf(_("No results found for email address %s"), email
);
2863 purple_notify_error(od
->gc
, NULL
, buf
, NULL
,
2864 purple_request_cpar_from_connection(od
->gc
));
2870 static int purple_account_confirm(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...) {
2871 PurpleConnection
*gc
= od
->gc
;
2877 status
= (guint16
) va_arg(ap
, unsigned int); /* status code of confirmation request */
2880 purple_debug_info("oscar",
2881 "account confirmation returned status 0x%04x (%s)\n", status
,
2882 status
? "unknown" : "email sent");
2884 g_snprintf(msg
, sizeof(msg
), _("You should receive an email asking to confirm %s."),
2885 purple_account_get_username(purple_connection_get_account(gc
)));
2886 purple_notify_info(gc
, NULL
, _("Account Confirmation Requested"),
2887 msg
, purple_request_cpar_from_connection(gc
));
2893 static int purple_info_change(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...) {
2894 PurpleConnection
*gc
= od
->gc
;
2897 char *url
, *bn
, *email
;
2901 change
= va_arg(ap
, int);
2902 perms
= (guint16
) va_arg(ap
, unsigned int);
2903 err
= (guint16
) va_arg(ap
, unsigned int);
2904 url
= va_arg(ap
, char *);
2905 bn
= va_arg(ap
, char *);
2906 email
= va_arg(ap
, char *);
2909 purple_debug_misc("oscar",
2910 "account info: because of %s, perms=0x%04x, err=0x%04x, url=%s, bn=%s, email=%s\n",
2911 change
? "change" : "request", perms
, err
,
2912 (url
!= NULL
) ? url
: "(null)",
2913 (bn
!= NULL
) ? bn
: "(null)",
2914 (email
!= NULL
) ? email
: "(null)");
2916 if ((err
> 0) && (url
!= NULL
)) {
2920 dialog_msg
= g_strdup_printf(_("Error 0x%04x: Unable to format username because the requested name differs from the original."), err
);
2921 else if (err
== 0x0006)
2922 dialog_msg
= g_strdup_printf(_("Error 0x%04x: Unable to format username because it is invalid."), err
);
2923 else if (err
== 0x00b)
2924 dialog_msg
= g_strdup_printf(_("Error 0x%04x: Unable to format username because the requested name is too long."), err
);
2925 else if (err
== 0x001d)
2926 dialog_msg
= g_strdup_printf(_("Error 0x%04x: Unable to change email address because there is already a request pending for this username."), err
);
2927 else if (err
== 0x0021)
2928 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
);
2929 else if (err
== 0x0023)
2930 dialog_msg
= g_strdup_printf(_("Error 0x%04x: Unable to change email address because the given address is invalid."), err
);
2932 dialog_msg
= g_strdup_printf(_("Error 0x%04x: Unknown error."), err
);
2933 purple_notify_error(gc
, NULL
, _("Error Changing Account Info"),
2934 dialog_msg
, purple_request_cpar_from_connection(gc
));
2939 if (email
!= NULL
) {
2940 char *dialog_msg
= g_strdup_printf(_("The email address for %s is %s"),
2941 purple_account_get_username(purple_connection_get_account(gc
)), email
);
2942 purple_notify_info(gc
, NULL
, _("Account Info"), dialog_msg
,
2943 purple_request_cpar_from_connection(gc
));
2951 oscar_keepalive(PurpleConnection
*gc
)
2956 od
= purple_connection_get_protocol_data(gc
);
2957 for (l
= od
->oscar_connections
; l
; l
= l
->next
) {
2958 flap_connection_send_keepalive(od
, l
->data
);
2963 oscar_send_typing(PurpleConnection
*gc
, const char *name
, PurpleIMTypingState state
)
2966 PeerConnection
*conn
;
2968 od
= purple_connection_get_protocol_data(gc
);
2969 conn
= peer_connection_find_by_type(od
, name
, OSCAR_CAPABILITY_DIRECTIM
);
2971 if ((conn
!= NULL
) && (conn
->ready
))
2973 peer_odc_send_typing(conn
, state
);
2976 /* Don't send if this turkey is in our deny list */
2977 PurpleAccount
*account
= purple_connection_get_account(gc
);
2978 GSList
*list
= purple_account_privacy_get_denied(account
);
2980 if (!g_slist_find_custom(list
, name
, (GCompareFunc
)oscar_util_name_compare
)) {
2981 struct buddyinfo
*bi
= g_hash_table_lookup(od
->buddyinfo
, purple_normalize(account
, name
));
2982 if (bi
&& bi
->typingnot
) {
2983 if (state
== PURPLE_IM_TYPING
)
2984 aim_im_sendmtn(od
, 0x0001, name
, 0x0002);
2985 else if (state
== PURPLE_IM_TYPED
)
2986 aim_im_sendmtn(od
, 0x0001, name
, 0x0001);
2988 aim_im_sendmtn(od
, 0x0001, name
, 0x0000);
2995 /* TODO: Move this into odc.c! */
2997 purple_odc_send_im(PeerConnection
*conn
, const char *message
, PurpleMessageFlags imflags
)
3005 const char *start
, *end
, *last
;
3008 msg
= g_string_new("<HTML><BODY>");
3009 data
= g_string_new("<BINARY>");
3012 /* for each valid IMG tag... */
3013 while (last
&& *last
&& purple_markup_find_tag("img", last
, &start
, &end
, &attribs
))
3015 PurpleImage
*image
= NULL
;
3019 g_string_append_len(msg
, last
, start
- last
);
3022 src
= g_datalist_get_data(&attribs
, "src");
3024 image
= purple_image_store_get_from_uri(src
);
3026 /* ... if it refers to a valid purple image ... */
3028 /* ... append the message from start to the tag ... */
3029 unsigned long size
= purple_image_get_data_size(image
);
3030 const gchar
*filename
= purple_image_get_friendly_filename(image
);
3031 gconstpointer imgdata
= purple_image_get_data(image
);
3035 /* ... insert a new img tag with the oscar id ... */
3037 g_string_append_printf(msg
,
3038 "<IMG SRC=\"%s\" ID=\"%d\" DATASIZE=\"%lu\">",
3039 filename
, oscar_id
, size
);
3041 g_string_append_printf(msg
,
3042 "<IMG ID=\"%d\" DATASIZE=\"%lu\">",
3045 /* ... and append the data to the binary section ... */
3046 g_string_append_printf(data
, "<DATA ID=\"%d\" SIZE=\"%lu\">",
3048 g_string_append_len(data
, imgdata
, size
);
3049 g_string_append(data
, "</DATA>");
3051 /* If the tag is invalid, skip it, thus no else here */
3053 g_datalist_clear(&attribs
);
3055 /* continue from the end of the tag */
3059 /* append any remaining message data */
3061 g_string_append(msg
, last
);
3063 g_string_append(msg
, "</BODY></HTML>");
3065 /* Convert the message to a good encoding */
3066 tmp
= oscar_encode_im(msg
->str
, &tmplen
, &charset
, NULL
);
3067 g_string_free(msg
, TRUE
);
3068 msg
= g_string_new_len(tmp
, tmplen
);
3071 /* Append any binary data that we may have */
3073 msg
= g_string_append_len(msg
, data
->str
, data
->len
);
3074 msg
= g_string_append(msg
, "</BINARY>");
3076 g_string_free(data
, TRUE
);
3078 purple_debug_info("oscar", "sending direct IM %s using charset %i", msg
->str
, charset
);
3080 peer_odc_send_im(conn
, msg
->str
, msg
->len
, charset
,
3081 imflags
& PURPLE_MESSAGE_AUTO_RESP
);
3082 g_string_free(msg
, TRUE
);
3086 oscar_send_im(PurpleConnection
*gc
, PurpleMessage
*msg
)
3089 PurpleAccount
*account
;
3090 PeerConnection
*conn
;
3093 gboolean is_sms
, is_html
;
3094 const gchar
*name
, *message
;
3095 PurpleMessageFlags imflags
;
3097 name
= purple_message_get_recipient(msg
);
3098 message
= purple_message_get_contents(msg
);
3099 imflags
= purple_message_get_flags(msg
);
3100 od
= purple_connection_get_protocol_data(gc
);
3101 account
= purple_connection_get_account(gc
);
3104 is_sms
= oscar_util_valid_name_sms(name
);
3106 if (od
->icq
&& is_sms
) {
3108 * We're sending to a phone number and this is ICQ,
3109 * so send the message as an SMS using aim_icq_sendsms()
3112 purple_debug_info("oscar", "Sending SMS to %s.\n", name
);
3113 ret
= aim_icq_sendsms(od
, name
, message
, purple_account_get_username(account
));
3114 return (ret
>= 0 ? 1 : ret
);
3117 if (imflags
& PURPLE_MESSAGE_AUTO_RESP
)
3118 tmp1
= oscar_util_format_string(message
, name
);
3120 tmp1
= g_strdup(message
);
3122 conn
= peer_connection_find_by_type(od
, name
, OSCAR_CAPABILITY_DIRECTIM
);
3123 if ((conn
!= NULL
) && (conn
->ready
))
3125 /* If we're directly connected, send a direct IM */
3126 purple_debug_info("oscar", "Sending direct IM with flags %i\n", imflags
);
3127 purple_odc_send_im(conn
, tmp1
, imflags
);
3129 struct buddyinfo
*bi
;
3130 struct aim_sendimext_args args
;
3131 PurpleIMConversation
*im
;
3135 im
= purple_conversations_find_im_with_account(name
, account
);
3137 if (strstr(tmp1
, "<img "))
3138 purple_conversation_write_system_message(PURPLE_CONVERSATION(im
),
3139 _("Your IM Image was not sent. "
3140 "You must be Direct Connected to send IM Images."),
3141 PURPLE_MESSAGE_ERROR
);
3143 buddy
= purple_blist_find_buddy(account
, name
);
3145 bi
= g_hash_table_lookup(od
->buddyinfo
, purple_normalize(account
, name
));
3147 bi
= g_new0(struct buddyinfo
, 1);
3148 g_hash_table_insert(od
->buddyinfo
, g_strdup(purple_normalize(account
, name
)), bi
);
3153 if (!is_sms
&& (!buddy
|| !PURPLE_BUDDY_IS_ONLINE(buddy
)))
3154 args
.flags
|= AIM_IMFLAGS_OFFLINE
;
3157 args
.features
= features_icq
;
3158 args
.featureslen
= sizeof(features_icq
);
3160 args
.features
= features_aim
;
3161 args
.featureslen
= sizeof(features_aim
);
3163 if (imflags
& PURPLE_MESSAGE_AUTO_RESP
)
3164 args
.flags
|= AIM_IMFLAGS_AWAY
;
3168 purple_debug_info("oscar",
3169 "Sending buddy icon request with message\n");
3170 args
.flags
|= AIM_IMFLAGS_BUDDYREQ
;
3171 bi
->ico_need
= FALSE
;
3174 img
= purple_buddy_icons_find_account_icon(account
);
3176 gconstpointer data
= purple_image_get_data(img
);
3177 args
.iconlen
= purple_image_get_data_size(img
);
3178 args
.iconsum
= aimutil_iconsum(data
, args
.iconlen
);
3179 args
.iconstamp
= purple_buddy_icons_get_account_icon_timestamp(account
);
3181 if ((args
.iconlen
!= bi
->ico_me_len
) || (args
.iconsum
!= bi
->ico_me_csum
) || (args
.iconstamp
!= bi
->ico_me_time
)) {
3182 bi
->ico_informed
= FALSE
;
3183 bi
->ico_sent
= FALSE
;
3188 * For some reason sending our icon to people only works
3189 * when we're the ones who initiated the conversation. If
3190 * the other person sends the first IM then they never get
3191 * the icon. We should fix that.
3193 if (!bi
->ico_informed
) {
3194 purple_debug_info("oscar",
3195 "Claiming to have a buddy icon\n");
3196 args
.flags
|= AIM_IMFLAGS_HASICON
;
3197 bi
->ico_me_len
= args
.iconlen
;
3198 bi
->ico_me_csum
= args
.iconsum
;
3199 bi
->ico_me_time
= args
.iconstamp
;
3200 bi
->ico_informed
= TRUE
;
3203 g_object_unref(img
);
3208 if (oscar_util_valid_name_sms(name
)) {
3209 /* Messaging an SMS (mobile) user--strip HTML */
3210 tmp2
= purple_markup_strip_html(tmp1
);
3213 /* ICQ 6 wants its HTML wrapped in these tags. Oblige it. */
3214 tmp2
= g_strdup_printf("<HTML><BODY>%s</BODY></HTML>", tmp1
);
3220 args
.msg
= oscar_encode_im(tmp1
, &args
.msglen
, &args
.charset
, NULL
);
3221 if (is_html
&& (args
.msglen
> MAXMSGLEN
)) {
3222 /* If the length was too long, try stripping the HTML and then running it back through
3223 * purple_strdup_withhtml() and the encoding process. The result may be shorter. */
3224 g_free((char *)args
.msg
);
3226 tmp2
= purple_markup_strip_html(tmp1
);
3229 /* re-escape the entities */
3230 tmp1
= g_markup_escape_text(tmp2
, -1);
3233 tmp2
= purple_strdup_withhtml(tmp1
);
3237 args
.msg
= oscar_encode_im(tmp1
, &args
.msglen
, &args
.charset
, NULL
);
3238 purple_debug_info("oscar", "Sending %s as %s because the original was too long.\n",
3239 message
, (char *)args
.msg
);
3242 purple_debug_info("oscar", "Sending IM, charset=0x%04hx, length=%" G_GSIZE_FORMAT
"\n", args
.charset
, args
.msglen
);
3243 ret
= aim_im_sendch1_ext(od
, &args
);
3244 g_free((char *)args
.msg
);
3256 * As of 26 June 2006, ICQ users can request AIM info from
3257 * everyone, and can request ICQ info from ICQ users, and
3258 * AIM users can only request AIM info.
3260 void oscar_get_info(PurpleConnection
*gc
, const char *name
) {
3261 OscarData
*od
= purple_connection_get_protocol_data(gc
);
3263 if (od
->icq
&& oscar_util_valid_name_icq(name
))
3264 aim_icq_getallinfo(od
, name
);
3266 aim_locate_getinfoshort(od
, name
, 0x00000003);
3269 void oscar_set_idle(PurpleConnection
*gc
, int time
) {
3270 OscarData
*od
= purple_connection_get_protocol_data(gc
);
3271 aim_srv_setidle(od
, time
);
3275 oscar_set_info(PurpleConnection
*gc
, const char *rawinfo
)
3277 PurpleAccount
*account
;
3278 PurpleStatus
*status
;
3280 account
= purple_connection_get_account(gc
);
3281 status
= purple_account_get_active_status(account
);
3282 oscar_set_info_and_status(account
, TRUE
, rawinfo
, FALSE
, status
);
3286 oscar_get_extended_status(PurpleConnection
*gc
)
3288 PurpleAccount
*account
;
3289 PurpleStatus
*status
;
3290 const gchar
*status_id
;
3291 guint32 data
= 0x00000000;
3293 account
= purple_connection_get_account(gc
);
3294 status
= purple_account_get_active_status(account
);
3295 status_id
= purple_status_get_id(status
);
3297 data
|= AIM_ICQ_STATE_HIDEIP
;
3298 if (purple_account_get_bool(account
, "web_aware", OSCAR_DEFAULT_WEB_AWARE
))
3299 data
|= AIM_ICQ_STATE_WEBAWARE
;
3301 if (purple_strequal(status_id
, OSCAR_STATUS_ID_AVAILABLE
))
3302 data
|= AIM_ICQ_STATE_NORMAL
;
3303 else if (purple_strequal(status_id
, OSCAR_STATUS_ID_AWAY
))
3304 data
|= AIM_ICQ_STATE_AWAY
;
3305 else if (purple_strequal(status_id
, OSCAR_STATUS_ID_DND
))
3306 data
|= AIM_ICQ_STATE_AWAY
| AIM_ICQ_STATE_DND
| AIM_ICQ_STATE_BUSY
;
3307 else if (purple_strequal(status_id
, OSCAR_STATUS_ID_NA
))
3308 data
|= AIM_ICQ_STATE_OUT
| AIM_ICQ_STATE_AWAY
;
3309 else if (purple_strequal(status_id
, OSCAR_STATUS_ID_OCCUPIED
))
3310 data
|= AIM_ICQ_STATE_AWAY
| AIM_ICQ_STATE_BUSY
;
3311 else if (purple_strequal(status_id
, OSCAR_STATUS_ID_FREE4CHAT
))
3312 data
|= AIM_ICQ_STATE_CHAT
;
3313 else if (purple_strequal(status_id
, OSCAR_STATUS_ID_INVISIBLE
))
3314 data
|= AIM_ICQ_STATE_INVISIBLE
;
3315 else if (purple_strequal(status_id
, OSCAR_STATUS_ID_EVIL
))
3316 data
|= AIM_ICQ_STATE_EVIL
;
3317 else if (purple_strequal(status_id
, OSCAR_STATUS_ID_DEPRESSION
))
3318 data
|= AIM_ICQ_STATE_DEPRESSION
;
3319 else if (purple_strequal(status_id
, OSCAR_STATUS_ID_ATWORK
))
3320 data
|= AIM_ICQ_STATE_ATWORK
;
3321 else if (purple_strequal(status_id
, OSCAR_STATUS_ID_ATHOME
))
3322 data
|= AIM_ICQ_STATE_ATHOME
;
3323 else if (purple_strequal(status_id
, OSCAR_STATUS_ID_LUNCH
))
3324 data
|= AIM_ICQ_STATE_LUNCH
;
3325 else if (purple_strequal(status_id
, OSCAR_STATUS_ID_CUSTOM
))
3326 data
|= AIM_ICQ_STATE_OUT
| AIM_ICQ_STATE_AWAY
;
3332 oscar_set_extended_status(PurpleConnection
*gc
)
3334 aim_srv_setextrainfo(purple_connection_get_protocol_data(gc
), TRUE
, oscar_get_extended_status(gc
), FALSE
, NULL
, NULL
);
3338 oscar_set_info_and_status(PurpleAccount
*account
, gboolean setinfo
, const char *rawinfo
,
3339 gboolean setstatus
, PurpleStatus
*status
)
3341 PurpleConnection
*gc
= purple_account_get_connection(account
);
3342 OscarData
*od
= purple_connection_get_protocol_data(gc
);
3343 PurpleStatusType
*status_type
;
3344 PurpleStatusPrimitive primitive
;
3346 char *info_encoding
= NULL
;
3350 char *away_encoding
= NULL
;
3354 char *status_text
= NULL
;
3355 const char *itmsurl
= NULL
;
3357 status_type
= purple_status_get_status_type(status
);
3358 primitive
= purple_status_type_get_primitive(status_type
);
3364 else if (od
->rights
.maxsiglen
== 0)
3366 purple_notify_warning(gc
, NULL
, _("Unable to set AIM profile."),
3367 _("You have probably requested to set your "
3368 "profile before the login procedure completed. "
3369 "Your profile remains unset; try setting it "
3370 "again when you are fully connected."),
3371 purple_request_cpar_from_connection(gc
));
3373 else if (rawinfo
!= NULL
)
3375 char *htmlinfo
= purple_strdup_withhtml(rawinfo
);
3376 info
= oscar_encode_im(htmlinfo
, &infolen
, NULL
, &info_encoding
);
3379 if (infolen
> od
->rights
.maxsiglen
)
3382 errstr
= g_strdup_printf(dngettext(PACKAGE
, "The maximum profile length of %d byte "
3383 "has been exceeded. It has been truncated for you.",
3384 "The maximum profile length of %d bytes "
3385 "has been exceeded. It has been truncated for you.",
3386 od
->rights
.maxsiglen
), od
->rights
.maxsiglen
);
3387 purple_notify_warning(gc
, NULL
, _("Profile too long."),
3388 errstr
, purple_request_cpar_from_connection(gc
));
3395 const char *status_html
;
3397 status_html
= purple_status_get_attr_string(status
, "message");
3399 if (status_html
== NULL
|| primitive
== PURPLE_STATUS_AVAILABLE
|| primitive
== PURPLE_STATUS_INVISIBLE
)
3401 /* This is needed for us to un-set any previous away message. */
3402 away
= g_strdup("");
3408 /* We do this for icq too so that they work for old third party clients */
3409 linkified
= purple_markup_linkify(status_html
);
3410 away
= oscar_encode_im(linkified
, &awaylen
, NULL
, &away_encoding
);
3413 if (awaylen
> od
->rights
.maxawaymsglen
)
3417 errstr
= g_strdup_printf(dngettext(PACKAGE
, "The maximum away message length of %d byte "
3418 "has been exceeded. It has been truncated for you.",
3419 "The maximum away message length of %d bytes "
3420 "has been exceeded. It has been truncated for you.",
3421 od
->rights
.maxawaymsglen
), od
->rights
.maxawaymsglen
);
3422 purple_notify_warning(gc
, NULL
,
3423 _("Away message too long."), errstr
,
3424 purple_request_cpar_from_connection(gc
));
3430 aim_locate_setprofile(od
,
3431 info_encoding
, info
, MIN(infolen
, od
->rights
.maxsiglen
),
3432 away_encoding
, away
, MIN(awaylen
, od
->rights
.maxawaymsglen
));
3438 const char *status_html
;
3440 status_html
= purple_status_get_attr_string(status
, "message");
3441 if (status_html
!= NULL
)
3443 status_text
= purple_markup_strip_html(status_html
);
3444 /* If the status_text is longer than 251 characters then truncate it */
3445 if (strlen(status_text
) > MAXAVAILMSGLEN
)
3447 char *tmp
= g_utf8_find_prev_char(status_text
, &status_text
[MAXAVAILMSGLEN
- 2]);
3452 itmsurl
= purple_status_get_attr_string(status
, "itmsurl");
3454 aim_srv_setextrainfo(od
, TRUE
, oscar_get_extended_status(gc
), TRUE
, status_text
, itmsurl
);
3455 g_free(status_text
);
3460 oscar_set_icq_permdeny(PurpleAccount
*account
)
3462 PurpleConnection
*gc
= purple_account_get_connection(account
);
3463 OscarData
*od
= purple_connection_get_protocol_data(gc
);
3464 gboolean invisible
= purple_account_is_status_active(account
, OSCAR_STATUS_ID_INVISIBLE
);
3467 * For ICQ the permit/deny setting controls who can see you
3468 * online. Mimicking the official client's behavior, we use PURPLE_ACCOUNT_PRIVACY_ALLOW_USERS
3469 * when our status is "invisible" and PURPLE_ACCOUNT_PRIVACY_DENY_USERS otherwise.
3470 * In the former case, we are visible only to buddies on our "permanently visible" list.
3471 * In the latter, we are invisible only to buddies on our "permanently invisible" list.
3473 aim_ssi_setpermdeny(od
, invisible
? PURPLE_ACCOUNT_PRIVACY_ALLOW_USERS
: PURPLE_ACCOUNT_PRIVACY_DENY_USERS
);
3477 oscar_set_status(PurpleAccount
*account
, PurpleStatus
*status
)
3479 PurpleConnection
*pc
;
3482 purple_debug_info("oscar", "Set status to %s\n", purple_status_get_name(status
));
3484 /* Either setting a new status active or setting a status inactive.
3485 * (Only possible for independent status (i.e. X-Status moods.) */
3486 if (!purple_status_is_active(status
) && !purple_status_is_independent(status
))
3489 if (!purple_account_is_connected(account
))
3492 pc
= purple_account_get_connection(account
);
3493 od
= purple_connection_get_protocol_data(pc
);
3495 /* There's no need to do the stuff below for mood updates. */
3496 if (purple_status_type_get_primitive(purple_status_get_status_type(status
)) == PURPLE_STATUS_MOOD
) {
3497 aim_locate_setcaps(od
, purple_caps
);
3502 /* Set visibility */
3503 oscar_set_icq_permdeny(account
);
3506 /* Set the AIM-style away message for both AIM and ICQ accounts */
3507 oscar_set_info_and_status(account
, FALSE
, NULL
, TRUE
, status
);
3511 oscar_add_buddy(PurpleConnection
*gc
, PurpleBuddy
*buddy
, PurpleGroup
*group
, const char *msg
)
3514 PurpleAccount
*account
;
3515 const char *bname
, *gname
;
3517 od
= purple_connection_get_protocol_data(gc
);
3518 account
= purple_connection_get_account(gc
);
3519 bname
= purple_buddy_get_name(buddy
);
3520 gname
= purple_group_get_name(group
);
3522 if (!oscar_util_valid_name(bname
)) {
3524 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
);
3525 if (!purple_conversation_present_error(bname
, account
, buf
))
3526 purple_notify_error(gc
, NULL
, _("Unable to Add"), buf
, purple_request_cpar_from_connection(gc
));
3529 /* Remove from local list */
3530 purple_blist_remove_buddy(buddy
);
3535 if (od
->ssi
.received_data
) {
3536 if (!aim_ssi_itemlist_finditem(&od
->ssi
.local
, gname
, bname
, AIM_SSI_TYPE_BUDDY
)) {
3537 purple_debug_info("oscar",
3538 "ssi: adding buddy %s to group %s\n", bname
, gname
);
3539 aim_ssi_addbuddy(od
, bname
, gname
, NULL
, purple_buddy_get_alias_only(buddy
), NULL
, NULL
, 0);
3541 /* Mobile users should always be online */
3542 if (bname
[0] == '+') {
3543 purple_protocol_got_user_status(account
, bname
,
3544 OSCAR_STATUS_ID_AVAILABLE
, NULL
);
3545 purple_protocol_got_user_status(account
, bname
,
3546 OSCAR_STATUS_ID_MOBILE
, NULL
);
3548 } else if (aim_ssi_waitingforauth(&od
->ssi
.local
,
3549 aim_ssi_itemlist_findparentname(&od
->ssi
.local
, bname
),
3551 /* Not authorized -- Re-request authorization */
3552 oscar_auth_sendrequest(gc
, bname
, msg
);
3556 /* XXX - Should this be done from AIM accounts, as well? */
3558 aim_icq_getalias(od
, bname
, FALSE
, NULL
);
3561 void oscar_remove_buddy(PurpleConnection
*gc
, PurpleBuddy
*buddy
, PurpleGroup
*group
) {
3562 OscarData
*od
= purple_connection_get_protocol_data(gc
);
3564 if (od
->ssi
.received_data
) {
3565 const char *gname
= purple_group_get_name(group
);
3566 const char *bname
= purple_buddy_get_name(buddy
);
3567 purple_debug_info("oscar",
3568 "ssi: deleting buddy %s from group %s\n", bname
, gname
);
3569 aim_ssi_delbuddy(od
, bname
, gname
);
3573 void oscar_move_buddy(PurpleConnection
*gc
, const char *name
, const char *old_group
, const char *new_group
) {
3574 OscarData
*od
= purple_connection_get_protocol_data(gc
);
3576 if (od
->ssi
.received_data
&& !purple_strequal(old_group
, new_group
)) {
3577 purple_debug_info("oscar",
3578 "ssi: moving buddy %s from group %s to group %s\n", name
, old_group
, new_group
);
3579 aim_ssi_movebuddy(od
, old_group
, new_group
, name
);
3583 void oscar_alias_buddy(PurpleConnection
*gc
, const char *name
, const char *alias
) {
3584 OscarData
*od
= purple_connection_get_protocol_data(gc
);
3586 if (od
->ssi
.received_data
) {
3587 char *gname
= aim_ssi_itemlist_findparentname(&od
->ssi
.local
, name
);
3589 purple_debug_info("oscar",
3590 "ssi: changing the alias for buddy %s to %s\n", name
, alias
? alias
: "(none)");
3591 aim_ssi_aliasbuddy(od
, gname
, name
, alias
);
3597 * FYI, the OSCAR SSI code removes empty groups automatically.
3599 void oscar_rename_group(PurpleConnection
*gc
, const char *old_name
, PurpleGroup
*group
, GList
*moved_buddies
) {
3600 OscarData
*od
= purple_connection_get_protocol_data(gc
);
3602 if (od
->ssi
.received_data
) {
3603 const char *gname
= purple_group_get_name(group
);
3604 if (aim_ssi_itemlist_finditem(&od
->ssi
.local
, gname
, NULL
, AIM_SSI_TYPE_GROUP
)) {
3605 GList
*cur
, *groups
= NULL
;
3606 PurpleAccount
*account
= purple_connection_get_account(gc
);
3608 /* Make a list of what the groups each buddy is in */
3609 for (cur
= moved_buddies
; cur
!= NULL
; cur
= cur
->next
) {
3610 PurpleBlistNode
*node
= cur
->data
;
3611 /* node is PurpleBuddy, parent is a PurpleContact.
3612 * We must go two levels up to get the Group */
3613 groups
= g_list_append(groups
,
3614 purple_buddy_get_group((PurpleBuddy
*)node
));
3617 purple_account_remove_buddies(account
, moved_buddies
, groups
);
3618 purple_account_add_buddies(account
, moved_buddies
, NULL
);
3619 g_list_free(groups
);
3620 purple_debug_info("oscar",
3621 "ssi: moved all buddies from group %s to %s\n", old_name
, gname
);
3623 aim_ssi_rename_group(od
, old_name
, gname
);
3624 purple_debug_info("oscar",
3625 "ssi: renamed group %s to %s\n", old_name
, gname
);
3630 void oscar_remove_group(PurpleConnection
*gc
, PurpleGroup
*group
)
3632 aim_ssi_delgroup(purple_connection_get_protocol_data(gc
), purple_group_get_name(group
));
3635 static gboolean
purple_ssi_rerequestdata(gpointer data
) {
3636 OscarData
*od
= data
;
3638 aim_ssi_reqdata(od
);
3643 static int purple_ssi_parseerr(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...) {
3644 PurpleConnection
*gc
= od
->gc
;
3649 reason
= (guint16
)va_arg(ap
, unsigned int);
3652 purple_debug_error("oscar", "ssi: SNAC error %hu\n", reason
);
3654 if (reason
== 0x0005) {
3655 if (od
->getblisttimer
> 0)
3656 g_source_remove(od
->getblisttimer
);
3658 /* We only show this error the first time it happens */
3659 purple_notify_error(gc
, NULL
,
3660 _("Unable to Retrieve Buddy List"),
3661 _("The AIM servers were temporarily unable to send "
3662 "your buddy list. Your buddy list is not lost, and "
3663 "will probably become available in a few minutes."),
3664 purple_request_cpar_from_connection(gc
));
3665 od
->getblisttimer
= g_timeout_add_seconds(30, purple_ssi_rerequestdata
, od
);
3672 static int purple_ssi_parserights(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...) {
3680 numtypes
= va_arg(ap
, int);
3681 maxitems
= va_arg(ap
, guint16
*);
3684 msg
= g_string_new("ssi rights:");
3685 for (i
=0; i
<numtypes
; i
++)
3686 g_string_append_printf(msg
, " max type 0x%04x=%hd,", i
, maxitems
[i
]);
3687 g_string_append(msg
, "\n");
3688 purple_debug_misc("oscar", "%s", msg
->str
);
3689 g_string_free(msg
, TRUE
);
3692 od
->rights
.maxbuddies
= maxitems
[0];
3694 od
->rights
.maxgroups
= maxitems
[1];
3696 od
->rights
.maxpermits
= maxitems
[2];
3698 od
->rights
.maxdenies
= maxitems
[3];
3703 static int purple_ssi_parselist(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...)
3705 PurpleConnection
*gc
;
3706 PurpleAccount
*account
;
3709 GSList
*cur
, *next
, *buddies
;
3710 struct aim_ssi_item
*curitem
;
3714 guint16 deny_entry_type
= aim_ssi_getdenyentrytype(od
);
3717 od
= purple_connection_get_protocol_data(gc
);
3718 account
= purple_connection_get_account(gc
);
3721 va_arg(ap
, int); /* guint16 fmtver */
3722 va_arg(ap
, int); /* guint16 numitems */
3723 va_arg(ap
, guint32
); /* timestamp */
3726 /* Don't attempt to re-request our buddy list later */
3727 if (od
->getblisttimer
!= 0) {
3728 g_source_remove(od
->getblisttimer
);
3729 od
->getblisttimer
= 0;
3732 purple_debug_info("oscar", "ssi: syncing local list and server list\n");
3734 /*** Begin code for pruning buddies from local list if they're not in server list ***/
3738 for (buddies
= purple_blist_find_buddies(account
, NULL
);
3740 buddies
= g_slist_delete_link(buddies
, buddies
))
3747 g
= purple_buddy_get_group(b
);
3748 gname
= purple_group_get_name(g
);
3749 bname
= purple_buddy_get_name(b
);
3751 if (aim_ssi_itemlist_exists(&od
->ssi
.local
, bname
)) {
3752 /* If the buddy is an ICQ user then load his nickname */
3753 const char *servernick
= purple_blist_node_get_string((PurpleBlistNode
*)b
, "servernick");
3757 purple_serv_got_alias(gc
, bname
, servernick
);
3759 /* Store local alias on server */
3760 alias
= aim_ssi_getalias(&od
->ssi
.local
, gname
, bname
);
3761 balias
= purple_buddy_get_local_alias(b
);
3762 if (!alias
&& balias
&& *balias
)
3763 aim_ssi_aliasbuddy(od
, gname
, bname
, balias
);
3766 purple_debug_info("oscar",
3767 "ssi: removing buddy %s from local list\n", bname
);
3768 /* Queue the buddy for removal from the local list */
3769 cur
= g_slist_prepend(cur
, b
);
3772 g_slist_free_full(cur
, (GDestroyNotify
)purple_blist_remove_buddy
);
3774 /* Permit list (ICQ doesn't have one) */
3776 next
= purple_account_privacy_get_permitted(account
);
3777 while (next
!= NULL
) {
3780 if (!aim_ssi_itemlist_finditem(&od
->ssi
.local
, NULL
, cur
->data
, AIM_SSI_TYPE_PERMIT
)) {
3781 purple_debug_info("oscar",
3782 "ssi: removing permit %s from local list\n", (const char *)cur
->data
);
3783 purple_account_privacy_permit_remove(account
, cur
->data
, TRUE
);
3789 next
= purple_account_privacy_get_denied(account
);
3790 while (next
!= NULL
) {
3793 if (!aim_ssi_itemlist_finditem(&od
->ssi
.local
, NULL
, cur
->data
, deny_entry_type
)) {
3794 purple_debug_info("oscar",
3795 "ssi: removing deny %s from local list\n", (const char *)cur
->data
);
3796 purple_account_privacy_deny_remove(account
, cur
->data
, TRUE
);
3800 /* Presence settings (idle time visibility) */
3801 tmp
= aim_ssi_getpresence(&od
->ssi
.local
);
3802 if (tmp
!= 0xFFFFFFFF) {
3803 const char *idle_reporting_pref
;
3804 gboolean report_idle
;
3806 idle_reporting_pref
= purple_prefs_get_string("/purple/away/idle_reporting");
3807 report_idle
= !purple_strequal(idle_reporting_pref
, "none");
3810 aim_ssi_setpresence(od
, tmp
| AIM_SSI_PRESENCE_FLAG_SHOWIDLE
);
3812 aim_ssi_setpresence(od
, tmp
& ~AIM_SSI_PRESENCE_FLAG_SHOWIDLE
);
3815 /*** End code for pruning buddies from local list ***/
3817 /*** Begin code for adding from server list to local list ***/
3819 for (curitem
=od
->ssi
.local
.data
; curitem
; curitem
=curitem
->next
) {
3820 if (curitem
->name
&& !g_utf8_validate(curitem
->name
, -1, NULL
)) {
3821 /* Got node with invalid UTF-8 in the name. Skip it. */
3822 purple_debug_warning("oscar", "ssi: server list contains item of "
3823 "type 0x%04hx with a non-utf8 name\n", curitem
->type
);
3827 switch (curitem
->type
) {
3828 case AIM_SSI_TYPE_BUDDY
: { /* Buddy */
3829 if (curitem
->name
) {
3830 struct aim_ssi_item
*groupitem
;
3831 char *gname
, *gname_utf8
, *alias
, *alias_utf8
;
3833 groupitem
= aim_ssi_itemlist_find(&od
->ssi
.local
, curitem
->gid
, 0x0000);
3834 gname
= groupitem
? groupitem
->name
: NULL
;
3835 gname_utf8
= oscar_utf8_try_convert(account
, od
, gname
);
3837 g
= purple_blist_find_group(gname_utf8
);
3839 g
= purple_group_new(gname_utf8
);
3840 purple_blist_add_group(g
, NULL
);
3843 alias
= aim_ssi_getalias_from_item(curitem
);
3844 alias_utf8
= oscar_utf8_try_convert(account
, od
, alias
);
3846 b
= purple_blist_find_buddy_in_group(account
, curitem
->name
, g
);
3848 /* Get server stored alias */
3849 purple_buddy_set_local_alias(b
, alias_utf8
);
3851 b
= purple_buddy_new(account
, curitem
->name
, alias_utf8
);
3853 purple_debug_info("oscar",
3854 "ssi: adding buddy %s to group %s to local list\n", curitem
->name
, gname
);
3855 purple_blist_add_buddy(b
, NULL
, g
, NULL
);
3858 /* Mobile users should always be online */
3859 if (curitem
->name
[0] == '+') {
3860 purple_protocol_got_user_status(account
,
3861 purple_buddy_get_name(b
),
3862 OSCAR_STATUS_ID_AVAILABLE
, NULL
);
3863 purple_protocol_got_user_status(account
,
3864 purple_buddy_get_name(b
),
3865 OSCAR_STATUS_ID_MOBILE
, NULL
);
3874 case AIM_SSI_TYPE_GROUP
: { /* Group */
3875 if (curitem
->name
!= NULL
&& purple_blist_find_group(curitem
->name
) == NULL
) {
3876 g
= purple_group_new(curitem
->name
);
3877 purple_blist_add_group(g
, NULL
);
3881 case AIM_SSI_TYPE_PERMIT
: { /* Permit buddy (unless we're on ICQ) */
3882 if (!od
->icq
&& curitem
->name
) {
3883 cur
= purple_account_privacy_get_permitted(account
);
3884 if (!g_slist_find_custom(cur
, curitem
->name
, (GCompareFunc
)oscar_util_name_compare
)) {
3885 purple_debug_info("oscar",
3886 "ssi: adding permit buddy %s to local list\n", curitem
->name
);
3887 purple_account_privacy_permit_add(account
, curitem
->name
, TRUE
);
3892 case AIM_SSI_TYPE_ICQDENY
:
3893 case AIM_SSI_TYPE_DENY
: { /* Deny buddy */
3894 if (curitem
->type
== deny_entry_type
&& curitem
->name
) {
3895 cur
= purple_account_privacy_get_denied(account
);
3896 if (!g_slist_find_custom(cur
, curitem
->name
, (GCompareFunc
)oscar_util_name_compare
)) {
3897 purple_debug_info("oscar",
3898 "ssi: adding deny buddy %s to local list\n", curitem
->name
);
3899 purple_account_privacy_deny_add(account
, curitem
->name
, TRUE
);
3904 case AIM_SSI_TYPE_PDINFO
: { /* Permit/deny setting */
3906 * We don't inherit the permit/deny setting from the server
3907 * for ICQ because, for ICQ, this setting controls who can
3908 * see your online status when you are invisible. Thus it is
3909 * a part of your status and not really related to blocking.
3911 if (!od
->icq
&& curitem
->data
) {
3912 guint8 perm_deny
= aim_ssi_getpermdeny(&od
->ssi
.local
);
3913 if (perm_deny
!= 0 && perm_deny
!= purple_account_get_privacy_type(account
))
3915 purple_debug_info("oscar",
3916 "ssi: changing permdeny from %d to %u\n", purple_account_get_privacy_type(account
), (guint
)perm_deny
);
3917 purple_account_set_privacy_type(account
, perm_deny
);
3922 case AIM_SSI_TYPE_PRESENCEPREFS
: { /* Presence setting */
3923 /* We don't want to change Purple's setting because it applies to all accounts */
3925 } /* End of switch on curitem->type */
3926 } /* End of for loop */
3928 /*** End code for adding from server list to local list ***/
3931 oscar_set_icq_permdeny(account
);
3933 oscar_set_aim_permdeny(gc
);
3937 /* Sending the enable causes other people to be able to see you, and you to see them */
3938 /* Make sure your privacy setting/invisibility is set how you want it before this! */
3939 purple_debug_info("oscar",
3940 "ssi: activating server-stored buddy list\n");
3944 * Make sure our server-stored icon is updated correctly in
3945 * the event that the local user set a new icon while this
3946 * account was offline.
3948 img
= purple_buddy_icons_find_account_icon(account
);
3949 oscar_set_icon(gc
, img
);
3950 g_object_unref(img
);
3953 * If we've already received our bos rights then we're not waiting on
3954 * anything else, so send the server clientready.
3956 if (od
->bos
.have_rights
) {
3957 aim_srv_clientready(od
, conn
);
3959 /* Request offline messages for AIM and ICQ */
3960 aim_im_reqofflinemsgs(od
);
3962 purple_connection_set_state(gc
, PURPLE_CONNECTION_CONNECTED
);
3968 static int purple_ssi_parseack(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...) {
3969 PurpleConnection
*gc
= od
->gc
;
3971 struct aim_ssi_tmp
*retval
;
3974 retval
= va_arg(ap
, struct aim_ssi_tmp
*);
3978 purple_debug_misc("oscar",
3979 "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");
3981 if (retval
->ack
!= 0xffff)
3982 switch (retval
->ack
) {
3983 case 0x0000: { /* added successfully */
3986 case 0x000c: { /* you are over the limit, the cheat is to the limit, come on fhqwhgads */
3988 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)")));
3989 if ((retval
->name
!= NULL
) && !purple_conversation_present_error(retval
->name
, purple_connection_get_account(gc
), buf
))
3990 purple_notify_error(gc
, NULL
, _("Unable to Add"), buf
, purple_request_cpar_from_connection(gc
));
3994 case 0x000e: { /* buddy requires authorization */
3995 if ((retval
->action
== SNAC_SUBTYPE_FEEDBAG_ADD
) && (retval
->name
))
3996 oscar_auth_sendrequest(gc
, retval
->name
, NULL
);
3999 default: { /* La la la */
4001 purple_debug_error("oscar", "ssi: Action 0x%04hx was unsuccessful with error 0x%04hx\n", retval
->action
, retval
->ack
);
4002 buf
= g_strdup_printf(_("Unable to add the buddy %s for an unknown reason."),
4003 (retval
->name
? retval
->name
: _("(no name)")));
4004 if ((retval
->name
!= NULL
) && !purple_conversation_present_error(retval
->name
, purple_connection_get_account(gc
), buf
))
4005 purple_notify_error(gc
, NULL
, _("Unable to Add"), buf
, purple_request_cpar_from_connection(gc
));
4010 retval
= retval
->next
;
4017 purple_ssi_parseaddmod(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...)
4019 PurpleConnection
*gc
;
4020 PurpleAccount
*account
;
4021 char *gname
, *gname_utf8
, *alias
, *alias_utf8
;
4024 struct aim_ssi_item
*ssi_item
;
4026 guint16 snac_subtype
, type
;
4030 account
= purple_connection_get_account(gc
);
4033 snac_subtype
= (guint16
)va_arg(ap
, int);
4034 type
= (guint16
)va_arg(ap
, int);
4035 name
= va_arg(ap
, char *);
4038 if ((type
!= 0x0000) || (name
== NULL
))
4041 gname
= aim_ssi_itemlist_findparentname(&od
->ssi
.local
, name
);
4042 gname_utf8
= gname
? oscar_utf8_try_convert(account
, od
, gname
) : NULL
;
4044 alias
= aim_ssi_getalias(&od
->ssi
.local
, gname
, name
);
4045 alias_utf8
= oscar_utf8_try_convert(account
, od
, alias
);
4048 b
= purple_blist_find_buddy(account
, name
);
4051 * You're logged in somewhere else and you aliased one
4052 * of your buddies, so update our local buddy list with
4053 * the person's new alias.
4055 purple_buddy_set_local_alias(b
, alias_utf8
);
4056 } else if (snac_subtype
== 0x0008) {
4058 * You're logged in somewhere else and you added a buddy to
4059 * your server list, so add them to your local buddy list.
4061 b
= purple_buddy_new(account
, name
, alias_utf8
);
4063 if (!(g
= purple_blist_find_group(gname_utf8
))) {
4064 g
= purple_group_new(gname_utf8
);
4065 purple_blist_add_group(g
, NULL
);
4068 purple_debug_info("oscar", "ssi: adding buddy %s to group %s to"
4069 " local list", name
, gname_utf8
? gname_utf8
: "(default)");
4070 purple_blist_add_buddy(b
, NULL
, g
, NULL
);
4072 /* Mobile users should always be online */
4073 if (name
[0] == '+') {
4074 purple_protocol_got_user_status(account
,
4075 name
, OSCAR_STATUS_ID_AVAILABLE
, NULL
);
4076 purple_protocol_got_user_status(account
,
4077 name
, OSCAR_STATUS_ID_MOBILE
, NULL
);
4082 ssi_item
= aim_ssi_itemlist_finditem(&od
->ssi
.local
,
4083 gname
, name
, AIM_SSI_TYPE_BUDDY
);
4084 if (ssi_item
== NULL
)
4086 purple_debug_error("oscar", "purple_ssi_parseaddmod: "
4087 "Could not find ssi item for oncoming buddy %s, "
4088 "group %s\n", name
, gname
);
4097 static int purple_ssi_authgiven(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...) {
4098 PurpleConnection
*gc
= od
->gc
;
4101 gchar
*dialog_msg
, *nombre
;
4102 struct name_data
*data
;
4106 bn
= va_arg(ap
, char *);
4107 va_arg(ap
, char *); /* msg */
4110 purple_debug_info("oscar",
4111 "ssi: %s has given you permission to add him to your buddy list\n", bn
);
4113 buddy
= purple_blist_find_buddy(purple_connection_get_account(gc
), bn
);
4114 if (buddy
&& (purple_buddy_get_alias_only(buddy
)))
4115 nombre
= g_strdup_printf("%s (%s)", bn
, purple_buddy_get_alias_only(buddy
));
4117 nombre
= g_strdup(bn
);
4119 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
);
4122 data
= g_new(struct name_data
, 1);
4124 data
->name
= g_strdup(bn
);
4125 data
->nick
= (buddy
? g_strdup(purple_buddy_get_alias_only(buddy
)) : NULL
);
4127 purple_request_yes_no(gc
, NULL
, _("Authorization Given"), dialog_msg
,
4128 PURPLE_DEFAULT_ACTION_NONE
,
4129 purple_request_cpar_from_connection(gc
),
4131 G_CALLBACK(purple_icq_buddyadd
),
4132 G_CALLBACK(oscar_free_name_data
));
4138 static int purple_ssi_authrequest(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...)
4145 bn
= va_arg(ap
, const char *);
4146 msg
= va_arg(ap
, char *);
4149 purple_debug_info("oscar",
4150 "ssi: received authorization request from %s\n", bn
);
4153 purple_debug_warning("oscar", "Received auth request from %s with "
4154 "empty message\n", bn
);
4155 } else if (!g_utf8_validate(msg
, -1, NULL
)) {
4156 purple_debug_warning("oscar", "Received auth request from %s with "
4157 "invalid UTF-8 message\n", bn
);
4161 aim_icq_getalias(od
, bn
, TRUE
, msg
);
4165 static int purple_ssi_authreply(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...) {
4166 PurpleConnection
*gc
= od
->gc
;
4169 gchar
*dialog_msg
, *nombre
;
4174 bn
= va_arg(ap
, char *);
4175 reply
= (guint8
)va_arg(ap
, int);
4176 msg
= va_arg(ap
, char *);
4179 purple_debug_info("oscar",
4180 "ssi: received authorization reply from %s. Reply is 0x%02hx\n", bn
, (guint16
)reply
);
4182 buddy
= purple_blist_find_buddy(purple_connection_get_account(gc
), bn
);
4183 if (buddy
&& (purple_buddy_get_alias_only(buddy
)))
4184 nombre
= g_strdup_printf("%s (%s)", bn
, purple_buddy_get_alias_only(buddy
));
4186 nombre
= g_strdup(bn
);
4190 dialog_msg
= g_strdup_printf(_("The user %s has granted your request to add them to your buddy list."), nombre
);
4191 purple_notify_info(gc
, NULL
, _("Authorization Granted"),
4192 dialog_msg
, purple_request_cpar_from_connection(gc
));
4195 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."));
4196 purple_notify_info(gc
, NULL
, _("Authorization Denied"),
4197 dialog_msg
, purple_request_cpar_from_connection(gc
));
4205 static int purple_ssi_gotadded(OscarData
*od
, FlapConnection
*conn
, FlapFrame
*fr
, ...) {
4206 PurpleConnection
*gc
= od
->gc
;
4207 PurpleAccount
*account
= purple_connection_get_account(gc
);
4213 bn
= va_arg(ap
, char *);
4216 buddy
= purple_blist_find_buddy(account
, bn
);
4217 purple_debug_info("oscar", "ssi: %s added you to their buddy list\n", bn
);
4218 purple_account_notify_added(account
, bn
, NULL
,
4219 (buddy
? purple_buddy_get_alias_only(buddy
) : NULL
), NULL
);
4224 GList
*oscar_chat_info(PurpleConnection
*gc
) {
4226 PurpleProtocolChatEntry
*pce
;
4228 pce
= g_new0(PurpleProtocolChatEntry
, 1);
4229 pce
->label
= _("_Room:");
4230 pce
->identifier
= "room";
4231 pce
->required
= TRUE
;
4232 m
= g_list_append(m
, pce
);
4234 pce
= g_new0(PurpleProtocolChatEntry
, 1);
4235 pce
->label
= _("_Exchange:");
4236 pce
->identifier
= "exchange";
4237 pce
->required
= TRUE
;
4241 m
= g_list_append(m
, pce
);
4246 GHashTable
*oscar_chat_info_defaults(PurpleConnection
*gc
, const char *chat_name
)
4248 GHashTable
*defaults
;
4250 defaults
= g_hash_table_new_full(g_str_hash
, g_str_equal
, NULL
, g_free
);
4252 if (chat_name
!= NULL
)
4253 g_hash_table_insert(defaults
, "room", g_strdup(chat_name
));
4254 g_hash_table_insert(defaults
, "exchange", g_strdup("4"));
4260 oscar_get_chat_name(GHashTable
*data
)
4262 return g_strdup(g_hash_table_lookup(data
, "room"));
4266 oscar_join_chat(PurpleConnection
*gc
, GHashTable
*data
)
4268 OscarData
*od
= purple_connection_get_protocol_data(gc
);
4269 FlapConnection
*conn
;
4270 char *name
, *exchange
;
4273 name
= g_hash_table_lookup(data
, "room");
4274 exchange
= g_hash_table_lookup(data
, "exchange");
4276 g_return_if_fail(name
!= NULL
&& *name
!= '\0');
4277 g_return_if_fail(exchange
!= NULL
);
4280 exchange_int
= strtol(exchange
, NULL
, 10);
4281 g_return_if_fail(errno
== 0);
4283 purple_debug_info("oscar", "Attempting to join chat room %s.\n", name
);
4285 if ((conn
= flap_connection_getbytype(od
, SNAC_FAMILY_CHATNAV
)))
4287 purple_debug_info("oscar", "chatnav exists, creating room\n");
4288 aim_chatnav_createroom(od
, conn
, name
, exchange_int
);
4290 /* this gets tricky */
4291 struct create_room
*cr
= g_new0(struct create_room
, 1);
4292 purple_debug_info("oscar", "chatnav does not exist, opening chatnav\n");
4293 cr
->exchange
= exchange_int
;
4294 cr
->name
= g_strdup(name
);
4295 od
->create_rooms
= g_slist_prepend(od
->create_rooms
, cr
);
4296 aim_srv_requestnew(od
, SNAC_FAMILY_CHATNAV
);
4301 oscar_chat_invite(PurpleConnection
*gc
, int id
, const char *message
, const char *name
)
4303 OscarData
*od
= purple_connection_get_protocol_data(gc
);
4304 struct chat_connection
*ccon
= find_oscar_chat(gc
, id
);
4309 aim_im_sendch2_chatinvite(od
, name
, message
? message
: "",
4310 ccon
->exchange
, ccon
->name
, 0x0);
4314 oscar_chat_leave(PurpleConnection
*gc
, int id
)
4316 PurpleChatConversation
*conv
;
4317 struct chat_connection
*cc
;
4319 conv
= purple_conversations_find_chat(gc
, id
);
4321 g_return_if_fail(conv
!= NULL
);
4323 purple_debug_info("oscar", "Leaving chat room %s\n",
4324 purple_conversation_get_name(PURPLE_CONVERSATION(conv
)));
4326 cc
= find_oscar_chat(gc
, purple_chat_conversation_get_id(conv
));
4327 flap_connection_schedule_destroy(cc
->conn
, OSCAR_DISCONNECT_DONE
, NULL
);
4328 oscar_chat_kill(gc
, cc
);
4331 int oscar_send_chat(PurpleConnection
*gc
, int id
, PurpleMessage
*msg
)
4333 OscarData
*od
= purple_connection_get_protocol_data(gc
);
4334 PurpleChatConversation
*conv
= NULL
;
4335 struct chat_connection
*c
= NULL
;
4336 char *buf
, *buf2
, *buf3
;
4340 const gchar
*message
= purple_message_get_contents(msg
);
4342 if (!(conv
= purple_conversations_find_chat(gc
, id
)))
4345 if (!(c
= find_oscar_chat_by_conv(gc
, conv
)))
4348 buf
= purple_strdup_withhtml(message
);
4350 if (strstr(buf
, "<img ")) {
4351 purple_conversation_write_system_message(PURPLE_CONVERSATION(conv
),
4352 _("Your IM Image was not sent. "
4353 "You cannot send IM Images in AIM chats."),
4354 PURPLE_MESSAGE_ERROR
);
4357 buf2
= oscar_encode_im(buf
, &len
, &charset
, &charsetstr
);
4359 * Evan S. suggested that maxvis really does mean "number of
4360 * visible characters" and not "number of bytes"
4362 if ((len
> c
->maxlen
) || (len
> c
->maxvis
)) {
4363 /* If the length was too long, try stripping the HTML and then running it back through
4364 * purple_strdup_withhtml() and the encoding process. The result may be shorter. */
4367 buf3
= purple_markup_strip_html(buf
);
4370 buf
= purple_strdup_withhtml(buf3
);
4373 buf2
= oscar_encode_im(buf
, &len
, &charset
, &charsetstr
);
4375 if ((len
> c
->maxlen
) || (len
> c
->maxvis
)) {
4376 purple_debug_warning("oscar",
4377 "Could not send %s because (%" G_GSIZE_FORMAT
" > maxlen %i) or (%" G_GSIZE_FORMAT
" > maxvis %i)\n",
4378 buf2
, len
, c
->maxlen
, len
, c
->maxvis
);
4384 purple_debug_info("oscar", "Sending %s as %s because the original was too long.\n",
4388 aim_chat_send_im(od
, c
->conn
, 0, buf2
, len
, charsetstr
, "en");
4395 PurpleMood
* oscar_get_purple_moods(PurpleAccount
*account
)
4397 return icq_get_purple_moods(account
);
4400 const char *oscar_list_icon_icq(PurpleAccount
*a
, PurpleBuddy
*b
)
4402 const char *name
= b
? purple_buddy_get_name(b
) : NULL
;
4403 if (name
&& !oscar_util_valid_name_sms(name
) && oscar_util_valid_name_icq(name
))
4409 const char *oscar_list_icon_aim(PurpleAccount
*a
, PurpleBuddy
*b
)
4411 const char *name
= b
? purple_buddy_get_name(b
) : NULL
;
4412 if (name
&& !oscar_util_valid_name_sms(name
) && oscar_util_valid_name_icq(name
))
4418 const char *oscar_list_emblem(PurpleBuddy
*b
)
4420 PurpleConnection
*gc
= NULL
;
4421 OscarData
*od
= NULL
;
4422 PurpleAccount
*account
= NULL
;
4423 PurplePresence
*presence
;
4424 aim_userinfo_t
*userinfo
= NULL
;
4427 account
= purple_buddy_get_account(b
);
4428 name
= purple_buddy_get_name(b
);
4429 if (account
!= NULL
)
4430 gc
= purple_account_get_connection(account
);
4432 od
= purple_connection_get_protocol_data(gc
);
4434 userinfo
= aim_locate_finduserinfo(od
, name
);
4436 presence
= purple_buddy_get_presence(b
);
4438 if (purple_presence_is_online(presence
) == FALSE
) {
4440 if ((name
) && (od
) && (od
->ssi
.received_data
) &&
4441 (gname
= aim_ssi_itemlist_findparentname(&od
->ssi
.local
, name
)) &&
4442 (aim_ssi_waitingforauth(&od
->ssi
.local
, gname
, name
))) {
4443 return "not-authorized";
4447 if (userinfo
!= NULL
) {
4448 if (userinfo
->flags
& AIM_FLAG_ADMINISTRATOR
)
4450 if (userinfo
->flags
& AIM_FLAG_ACTIVEBUDDY
)
4452 if (userinfo
->capabilities
& OSCAR_CAPABILITY_SECUREIM
)
4454 if (userinfo
->icqinfo
.status
& AIM_ICQ_STATE_BIRTHDAY
)
4457 /* Make the mood icon override anything below this. */
4458 if (purple_presence_is_status_primitive_active(presence
, PURPLE_STATUS_MOOD
))
4461 if (userinfo
->capabilities
& OSCAR_CAPABILITY_HIPTOP
)
4467 void oscar_tooltip_text(PurpleBuddy
*b
, PurpleNotifyUserInfo
*user_info
, gboolean full
)
4469 PurpleConnection
*gc
;
4470 PurpleAccount
*account
;
4472 aim_userinfo_t
*userinfo
;
4474 if (!PURPLE_BUDDY_IS_ONLINE(b
))
4477 account
= purple_buddy_get_account(b
);
4478 gc
= purple_account_get_connection(account
);
4479 od
= purple_connection_get_protocol_data(gc
);
4480 userinfo
= aim_locate_finduserinfo(od
, purple_buddy_get_name(b
));
4482 oscar_user_info_append_status(gc
, user_info
, b
, userinfo
, /* use_html_status */ FALSE
);
4485 oscar_user_info_append_extra_info(gc
, user_info
, b
, userinfo
);
4488 char *oscar_status_text(PurpleBuddy
*b
)
4490 PurpleConnection
*gc
;
4491 PurpleAccount
*account
;
4493 PurplePresence
*presence
;
4494 PurpleStatus
*status
;
4495 const char *message
;
4498 gc
= purple_account_get_connection(purple_buddy_get_account(b
));
4499 account
= purple_connection_get_account(gc
);
4500 od
= purple_connection_get_protocol_data(gc
);
4501 presence
= purple_buddy_get_presence(b
);
4502 status
= purple_presence_get_active_status(presence
);
4504 if ((od
!= NULL
) && !purple_presence_is_online(presence
))
4506 const char *name
= purple_buddy_get_name(b
);
4507 char *gname
= aim_ssi_itemlist_findparentname(&od
->ssi
.local
, name
);
4508 if (aim_ssi_waitingforauth(&od
->ssi
.local
, gname
, name
))
4509 ret
= g_strdup(_("Not Authorized"));
4511 ret
= g_strdup(_("Offline"));
4515 message
= purple_status_get_attr_string(status
, "message");
4516 if (message
!= NULL
)
4518 gchar
*tmp
= oscar_util_format_string(message
, purple_account_get_username(account
));
4519 ret
= purple_markup_escape_text(tmp
, -1);
4522 else if (purple_status_is_available(status
))
4524 /* Don't show "Available" as status message in case buddy doesn't have a status message */
4528 ret
= g_strdup(purple_status_get_name(status
));
4535 void oscar_set_aim_permdeny(PurpleConnection
*gc
) {
4536 PurpleAccount
*account
= purple_connection_get_account(gc
);
4537 OscarData
*od
= purple_connection_get_protocol_data(gc
);
4540 * Conveniently there is a one-to-one mapping between the
4541 * values of libpurple's PurplePrivacyType and the values used
4542 * by the oscar protocol.
4544 aim_ssi_setpermdeny(od
, purple_account_get_privacy_type(account
));
4547 void oscar_add_permit(PurpleConnection
*gc
, const char *who
) {
4548 OscarData
*od
= purple_connection_get_protocol_data(gc
);
4549 purple_debug_info("oscar", "ssi: About to add a permit\n");
4550 aim_ssi_add_to_private_list(od
, who
, AIM_SSI_TYPE_PERMIT
);
4553 void oscar_add_deny(PurpleConnection
*gc
, const char *who
) {
4554 OscarData
*od
= purple_connection_get_protocol_data(gc
);
4555 purple_debug_info("oscar", "ssi: About to add a deny\n");
4556 aim_ssi_add_to_private_list(od
, who
, aim_ssi_getdenyentrytype(od
));
4559 void oscar_rem_permit(PurpleConnection
*gc
, const char *who
) {
4560 OscarData
*od
= purple_connection_get_protocol_data(gc
);
4561 purple_debug_info("oscar", "ssi: About to delete a permit\n");
4562 aim_ssi_del_from_private_list(od
, who
, AIM_SSI_TYPE_PERMIT
);
4565 void oscar_rem_deny(PurpleConnection
*gc
, const char *who
) {
4566 OscarData
*od
= purple_connection_get_protocol_data(gc
);
4567 purple_debug_info("oscar", "ssi: About to delete a deny\n");
4568 aim_ssi_del_from_private_list(od
, who
, aim_ssi_getdenyentrytype(od
));
4572 oscar_status_types(PurpleAccount
*account
)
4575 GList
*status_types
= NULL
;
4576 PurpleStatusType
*type
;
4578 g_return_val_if_fail(account
!= NULL
, NULL
);
4580 /* Used to flag some statuses as "user settable" or not */
4581 is_icq
= oscar_util_valid_name_icq(purple_account_get_username(account
));
4583 /* Common status types */
4584 /* Really the available message should only be settable for AIM accounts */
4585 type
= purple_status_type_new_with_attrs(PURPLE_STATUS_AVAILABLE
,
4586 OSCAR_STATUS_ID_AVAILABLE
,
4587 NULL
, TRUE
, TRUE
, FALSE
,
4588 "message", _("Message"),
4589 purple_value_new(G_TYPE_STRING
),
4590 "itmsurl", _("iTunes Music Store Link"),
4591 purple_value_new(G_TYPE_STRING
), NULL
);
4592 status_types
= g_list_prepend(status_types
, type
);
4594 type
= purple_status_type_new_with_attrs(PURPLE_STATUS_AVAILABLE
,
4595 OSCAR_STATUS_ID_FREE4CHAT
,
4596 _("Free For Chat"), TRUE
, is_icq
, FALSE
,
4597 "message", _("Message"),
4598 purple_value_new(G_TYPE_STRING
), NULL
);
4600 status_types
= g_list_prepend(status_types
, type
);
4602 type
= purple_status_type_new_with_attrs(PURPLE_STATUS_AVAILABLE
,
4603 OSCAR_STATUS_ID_EVIL
,
4604 _("Evil"), TRUE
, is_icq
, FALSE
,
4605 "message", _("Message"),
4606 purple_value_new(G_TYPE_STRING
), NULL
);
4607 status_types
= g_list_prepend(status_types
, type
);
4610 type
= purple_status_type_new_with_attrs(PURPLE_STATUS_AVAILABLE
,
4611 OSCAR_STATUS_ID_DEPRESSION
,
4612 _("Depression"), TRUE
, is_icq
, FALSE
,
4613 "message", _("Message"),
4614 purple_value_new(G_TYPE_STRING
), NULL
);
4615 status_types
= g_list_prepend(status_types
, type
);
4618 type
= purple_status_type_new_with_attrs(PURPLE_STATUS_AVAILABLE
,
4619 OSCAR_STATUS_ID_ATHOME
,
4620 _("At home"), TRUE
, is_icq
, FALSE
,
4621 "message", _("Message"),
4622 purple_value_new(G_TYPE_STRING
), NULL
);
4623 status_types
= g_list_prepend(status_types
, type
);
4626 type
= purple_status_type_new_with_attrs(PURPLE_STATUS_AVAILABLE
,
4627 OSCAR_STATUS_ID_ATWORK
,
4628 _("At work"), TRUE
, is_icq
, FALSE
,
4629 "message", _("Message"),
4630 purple_value_new(G_TYPE_STRING
), NULL
);
4632 status_types
= g_list_prepend(status_types
, type
);
4635 type
= purple_status_type_new_with_attrs(PURPLE_STATUS_AVAILABLE
,
4636 OSCAR_STATUS_ID_LUNCH
,
4637 _("Lunch"), TRUE
, is_icq
, FALSE
,
4638 "message", _("Message"),
4639 purple_value_new(G_TYPE_STRING
), NULL
);
4641 status_types
= g_list_prepend(status_types
, type
);
4643 type
= purple_status_type_new_with_attrs(PURPLE_STATUS_AWAY
,
4644 OSCAR_STATUS_ID_AWAY
,
4645 NULL
, TRUE
, TRUE
, FALSE
,
4646 "message", _("Message"),
4647 purple_value_new(G_TYPE_STRING
), NULL
);
4648 status_types
= g_list_prepend(status_types
, type
);
4650 type
= purple_status_type_new_with_attrs(PURPLE_STATUS_INVISIBLE
,
4651 OSCAR_STATUS_ID_INVISIBLE
,
4652 NULL
, TRUE
, TRUE
, FALSE
,
4653 "message", _("Message"),
4654 purple_value_new(G_TYPE_STRING
), NULL
);
4656 status_types
= g_list_prepend(status_types
, type
);
4658 type
= purple_status_type_new_full(PURPLE_STATUS_MOBILE
, OSCAR_STATUS_ID_MOBILE
, NULL
, FALSE
, FALSE
, TRUE
);
4659 status_types
= g_list_prepend(status_types
, type
);
4661 /* ICQ-specific status types */
4662 type
= purple_status_type_new_with_attrs(PURPLE_STATUS_UNAVAILABLE
,
4663 OSCAR_STATUS_ID_OCCUPIED
,
4664 _("Occupied"), TRUE
, is_icq
, FALSE
,
4665 "message", _("Message"),
4666 purple_value_new(G_TYPE_STRING
), NULL
);
4667 status_types
= g_list_prepend(status_types
, type
);
4669 type
= purple_status_type_new_with_attrs(PURPLE_STATUS_UNAVAILABLE
,
4670 OSCAR_STATUS_ID_DND
,
4671 _("Do Not Disturb"), TRUE
, is_icq
, FALSE
,
4672 "message", _("Message"),
4673 purple_value_new(G_TYPE_STRING
), NULL
);
4674 status_types
= g_list_prepend(status_types
, type
);
4676 type
= purple_status_type_new_with_attrs(PURPLE_STATUS_EXTENDED_AWAY
,
4678 _("Not Available"), TRUE
, is_icq
, FALSE
,
4679 "message", _("Message"),
4680 purple_value_new(G_TYPE_STRING
), NULL
);
4681 status_types
= g_list_prepend(status_types
, type
);
4683 type
= purple_status_type_new_full(PURPLE_STATUS_OFFLINE
,
4684 OSCAR_STATUS_ID_OFFLINE
,
4685 NULL
, TRUE
, TRUE
, FALSE
);
4686 status_types
= g_list_prepend(status_types
, type
);
4688 type
= purple_status_type_new_with_attrs(PURPLE_STATUS_MOOD
,
4689 "mood", NULL
, TRUE
, is_icq
, TRUE
,
4690 PURPLE_MOOD_NAME
, _("Mood Name"), purple_value_new(G_TYPE_STRING
),
4691 PURPLE_MOOD_COMMENT
, _("Mood Comment"), purple_value_new(G_TYPE_STRING
),
4693 status_types
= g_list_prepend(status_types
, type
);
4695 return g_list_reverse(status_types
);
4698 static void oscar_ssi_editcomment(struct name_data
*data
, const char *text
) {
4699 PurpleConnection
*gc
;
4700 PurpleAccount
*account
;
4706 od
= purple_connection_get_protocol_data(gc
);
4707 account
= purple_connection_get_account(gc
);
4709 b
= purple_blist_find_buddy(account
, data
->name
);
4711 oscar_free_name_data(data
);
4715 g
= purple_buddy_get_group(b
);
4717 oscar_free_name_data(data
);
4721 aim_ssi_editcomment(od
, purple_group_get_name(g
), data
->name
, text
);
4722 oscar_free_name_data(data
);
4725 static void oscar_buddycb_edit_comment(PurpleBlistNode
*node
, gpointer ignore
) {
4728 PurpleConnection
*gc
;
4730 struct name_data
*data
;
4733 gchar
*comment_utf8
;
4735 PurpleAccount
*account
;
4738 g_return_if_fail(PURPLE_IS_BUDDY(node
));
4740 buddy
= (PurpleBuddy
*) node
;
4741 name
= purple_buddy_get_name(buddy
);
4742 account
= purple_buddy_get_account(buddy
);
4743 gc
= purple_account_get_connection(account
);
4744 od
= purple_connection_get_protocol_data(gc
);
4746 if (!(g
= purple_buddy_get_group(buddy
)))
4749 data
= g_new(struct name_data
, 1);
4751 comment
= aim_ssi_getcomment(&od
->ssi
.local
, purple_group_get_name(g
), name
);
4752 comment_utf8
= comment
? oscar_utf8_try_convert(account
, od
, comment
) : NULL
;
4755 data
->name
= g_strdup(name
);
4756 data
->nick
= g_strdup(purple_buddy_get_alias_only(buddy
));
4758 title
= g_strdup_printf(_("Buddy Comment for %s"), data
->name
);
4759 purple_request_input(gc
, title
, _("Buddy Comment:"), NULL
,
4760 comment_utf8
, TRUE
, FALSE
, NULL
,
4761 _("_OK"), G_CALLBACK(oscar_ssi_editcomment
),
4762 _("_Cancel"), G_CALLBACK(oscar_free_name_data
),
4763 purple_request_cpar_from_connection(gc
),
4768 g_free(comment_utf8
);
4772 oscar_ask_directim_yes_cb(struct oscar_ask_directim_data
*data
)
4774 peer_connection_propose(data
->od
, OSCAR_CAPABILITY_DIRECTIM
, data
->who
);
4780 oscar_ask_directim_no_cb(struct oscar_ask_directim_data
*data
)
4786 /* This is called from right-click menu on a buddy node. */
4788 oscar_ask_directim(gpointer object
, gpointer ignored
)
4790 PurpleBlistNode
*node
;
4792 PurpleConnection
*gc
;
4794 struct oscar_ask_directim_data
*data
;
4795 PurpleAccount
*account
;
4799 g_return_if_fail(PURPLE_IS_BUDDY(node
));
4801 buddy
= (PurpleBuddy
*)node
;
4802 account
= purple_buddy_get_account(buddy
);
4803 gc
= purple_account_get_connection(account
);
4805 data
= g_new0(struct oscar_ask_directim_data
, 1);
4806 data
->who
= g_strdup(purple_buddy_get_name(buddy
));
4807 data
->od
= purple_connection_get_protocol_data(gc
);
4808 buf
= g_strdup_printf(_("You have selected to open a Direct IM connection with %s."),
4811 purple_request_action(gc
, NULL
, buf
,
4812 _("Because this reveals your IP address, it "
4813 "may be considered a security risk. Do you "
4814 "wish to continue?"),
4815 0, /* Default action is "connect" */
4816 purple_request_cpar_from_account(account
),
4818 _("C_onnect"), G_CALLBACK(oscar_ask_directim_yes_cb
),
4819 _("_Cancel"), G_CALLBACK(oscar_ask_directim_no_cb
));
4824 oscar_close_directim(gpointer object
, gpointer ignored
)
4826 PurpleBlistNode
*node
;
4828 PurpleAccount
*account
;
4829 PurpleConnection
*gc
;
4830 PurpleIMConversation
*im
;
4832 PeerConnection
*conn
;
4837 g_return_if_fail(PURPLE_IS_BUDDY(node
));
4839 buddy
= (PurpleBuddy
*)node
;
4840 name
= purple_buddy_get_name(buddy
);
4841 account
= purple_buddy_get_account(buddy
);
4842 gc
= purple_account_get_connection(account
);
4843 od
= purple_connection_get_protocol_data(gc
);
4844 conn
= peer_connection_find_by_type(od
, name
, OSCAR_CAPABILITY_DIRECTIM
);
4849 aim_im_sendch2_cancel(conn
);
4851 peer_connection_destroy(conn
, OSCAR_DISCONNECT_LOCAL_CLOSED
, NULL
);
4853 /* OSCAR_DISCONNECT_LOCAL_CLOSED doesn't write anything to the convo
4854 * window. Let the user know that we cancelled the Direct IM. */
4855 im
= purple_im_conversation_new(account
, name
);
4856 purple_conversation_write_system_message(
4857 PURPLE_CONVERSATION(im
), _("You closed the connection."), 0);
4861 static void oscar_get_icqxstatusmsg(PurpleBlistNode
*node
, gpointer ignore
)
4864 PurpleConnection
*gc
;
4866 PurpleAccount
*account
;
4869 g_return_if_fail(PURPLE_IS_BUDDY(node
));
4871 buddy
= (PurpleBuddy
*)node
;
4872 bname
= purple_buddy_get_name(buddy
);
4874 account
= purple_buddy_get_account(buddy
);
4875 gc
= purple_account_get_connection(account
);
4876 od
= purple_connection_get_protocol_data(gc
);
4878 purple_debug_info("oscar", "Manual X-Status Get From %s to %s:\n", bname
, purple_account_get_username(account
));
4880 icq_im_xstatus_request(od
, bname
);
4884 oscar_get_aim_info_cb(PurpleBlistNode
*node
, gpointer ignore
)
4887 PurpleConnection
*gc
;
4889 g_return_if_fail(PURPLE_IS_BUDDY(node
));
4891 buddy
= (PurpleBuddy
*)node
;
4892 gc
= purple_account_get_connection(purple_buddy_get_account(buddy
));
4894 aim_locate_getinfoshort(purple_connection_get_protocol_data(gc
),
4895 purple_buddy_get_name(buddy
), 0x00000003);
4899 oscar_buddy_menu(PurpleBuddy
*buddy
) {
4900 PurpleConnection
*gc
;
4903 PurpleActionMenu
*act
;
4904 aim_userinfo_t
*userinfo
;
4905 PurpleAccount
*account
;
4906 const char *bname
= purple_buddy_get_name(buddy
);
4908 account
= purple_buddy_get_account(buddy
);
4909 gc
= purple_account_get_connection(account
);
4910 od
= purple_connection_get_protocol_data(gc
);
4911 userinfo
= aim_locate_finduserinfo(od
, bname
);
4914 if (od
->icq
&& oscar_util_valid_name_icq(bname
))
4916 act
= purple_action_menu_new(_("Get AIM Info"),
4917 PURPLE_CALLBACK(oscar_get_aim_info_cb
),
4919 menu
= g_list_prepend(menu
, act
);
4922 if (purple_buddy_get_group(buddy
) != NULL
)
4924 /* We only do this if the user is in our buddy list */
4925 act
= purple_action_menu_new(_("Edit Buddy Comment"),
4926 PURPLE_CALLBACK(oscar_buddycb_edit_comment
),
4928 menu
= g_list_prepend(menu
, act
);
4933 act
= purple_action_menu_new(_("Get X-Status Msg"),
4934 PURPLE_CALLBACK(oscar_get_icqxstatusmsg
),
4936 menu
= g_list_prepend(menu
, act
);
4937 menu
= g_list_prepend(menu
, create_visibility_menu_item(od
, bname
));
4941 oscar_util_name_compare(purple_account_get_username(account
), bname
) &&
4942 PURPLE_BUDDY_IS_ONLINE(buddy
))
4944 PeerConnection
*conn
;
4945 conn
= peer_connection_find_by_type(od
, bname
, OSCAR_CAPABILITY_DIRECTIM
);
4947 if (userinfo
->capabilities
& OSCAR_CAPABILITY_DIRECTIM
)
4951 act
= purple_action_menu_new(_("End Direct IM Session"),
4952 PURPLE_CALLBACK(oscar_close_directim
),
4957 act
= purple_action_menu_new(_("Direct IM"),
4958 PURPLE_CALLBACK(oscar_ask_directim
),
4961 menu
= g_list_prepend(menu
, act
);
4965 if (od
->ssi
.received_data
&& purple_buddy_get_group(buddy
) != NULL
)
4968 * We only do this if the user is in our buddy list and we're
4969 * waiting for authorization.
4972 gname
= aim_ssi_itemlist_findparentname(&od
->ssi
.local
, bname
);
4973 if (gname
&& aim_ssi_waitingforauth(&od
->ssi
.local
, gname
, bname
))
4975 act
= purple_action_menu_new(_("Re-request Authorization"),
4976 PURPLE_CALLBACK(oscar_auth_sendrequest_menu
),
4978 menu
= g_list_prepend(menu
, act
);
4982 menu
= g_list_reverse(menu
);
4988 GList
*oscar_blist_node_menu(PurpleBlistNode
*node
) {
4989 if(PURPLE_IS_BUDDY(node
)) {
4990 return oscar_buddy_menu((PurpleBuddy
*) node
);
4997 oscar_icq_privacy_opts(PurpleConnection
*gc
, PurpleRequestFields
*fields
)
4999 OscarData
*od
= purple_connection_get_protocol_data(gc
);
5000 PurpleAccount
*account
= purple_connection_get_account(gc
);
5001 PurpleRequestField
*f
;
5002 gboolean auth
, web_aware
;
5004 f
= purple_request_fields_get_field(fields
, "authorization");
5005 auth
= purple_request_field_bool_get_value(f
);
5007 f
= purple_request_fields_get_field(fields
, "web_aware");
5008 web_aware
= purple_request_field_bool_get_value(f
);
5010 purple_account_set_bool(account
, "authorization", auth
);
5011 purple_account_set_bool(account
, "web_aware", web_aware
);
5013 oscar_set_extended_status(gc
);
5014 aim_icq_setsecurity(od
, auth
, web_aware
);
5018 oscar_show_icq_privacy_opts(PurpleProtocolAction
*action
)
5020 PurpleConnection
*gc
= action
->connection
;
5021 PurpleAccount
*account
= purple_connection_get_account(gc
);
5022 PurpleRequestFields
*fields
;
5023 PurpleRequestFieldGroup
*g
;
5024 PurpleRequestField
*f
;
5025 gboolean auth
, web_aware
;
5027 auth
= purple_account_get_bool(account
, "authorization", OSCAR_DEFAULT_AUTHORIZATION
);
5028 web_aware
= purple_account_get_bool(account
, "web_aware", OSCAR_DEFAULT_WEB_AWARE
);
5030 fields
= purple_request_fields_new();
5032 g
= purple_request_field_group_new(NULL
);
5034 f
= purple_request_field_bool_new("authorization", _("Require authorization"), auth
);
5035 purple_request_field_group_add_field(g
, f
);
5037 f
= purple_request_field_bool_new("web_aware", _("Web aware (enabling this will cause you to receive SPAM!)"), web_aware
);
5038 purple_request_field_group_add_field(g
, f
);
5040 purple_request_fields_add_group(fields
, g
);
5042 purple_request_fields(gc
, _("ICQ Privacy Options"), _("ICQ Privacy Options"),
5044 _("OK"), G_CALLBACK(oscar_icq_privacy_opts
),
5046 purple_request_cpar_from_connection(gc
),
5050 static void oscar_confirm_account(PurpleProtocolAction
*action
)
5052 PurpleConnection
*gc
;
5054 FlapConnection
*conn
;
5056 gc
= action
->connection
;
5057 od
= purple_connection_get_protocol_data(gc
);
5059 conn
= flap_connection_getbytype(od
, SNAC_FAMILY_ADMIN
);
5061 aim_admin_reqconfirm(od
, conn
);
5064 aim_srv_requestnew(od
, SNAC_FAMILY_ADMIN
);
5068 static void oscar_show_email(PurpleProtocolAction
*action
)
5070 PurpleConnection
*gc
= action
->connection
;
5071 OscarData
*od
= purple_connection_get_protocol_data(gc
);
5072 FlapConnection
*conn
= flap_connection_getbytype(od
, SNAC_FAMILY_ADMIN
);
5075 aim_admin_getinfo(od
, conn
, 0x11);
5077 od
->reqemail
= TRUE
;
5078 aim_srv_requestnew(od
, SNAC_FAMILY_ADMIN
);
5082 static void oscar_change_email(PurpleConnection
*gc
, const char *email
)
5084 OscarData
*od
= purple_connection_get_protocol_data(gc
);
5085 FlapConnection
*conn
= flap_connection_getbytype(od
, SNAC_FAMILY_ADMIN
);
5088 aim_admin_setemail(od
, conn
, email
);
5090 od
->setemail
= TRUE
;
5091 od
->email
= g_strdup(email
);
5092 aim_srv_requestnew(od
, SNAC_FAMILY_ADMIN
);
5096 static void oscar_show_change_email(PurpleProtocolAction
*action
)
5098 PurpleConnection
*gc
= action
->connection
;
5099 purple_request_input(gc
, NULL
, _("Change Address To:"), NULL
, NULL
,
5101 _("_OK"), G_CALLBACK(oscar_change_email
),
5103 purple_request_cpar_from_connection(gc
),
5107 static void oscar_show_awaitingauth(PurpleProtocolAction
*action
)
5109 PurpleConnection
*gc
= action
->connection
;
5110 OscarData
*od
= purple_connection_get_protocol_data(gc
);
5111 PurpleAccount
*account
= purple_connection_get_account(gc
);
5112 GSList
*buddies
, *filtered_buddies
, *cur
;
5115 buddies
= purple_blist_find_buddies(account
, NULL
);
5116 filtered_buddies
= NULL
;
5117 for (cur
= buddies
; cur
!= NULL
; cur
= cur
->next
) {
5119 const gchar
*bname
, *gname
;
5122 bname
= purple_buddy_get_name(buddy
);
5123 gname
= purple_group_get_name(purple_buddy_get_group(buddy
));
5124 if (aim_ssi_waitingforauth(&od
->ssi
.local
, gname
, bname
)) {
5125 filtered_buddies
= g_slist_prepend(filtered_buddies
, buddy
);
5129 g_slist_free(buddies
);
5131 filtered_buddies
= g_slist_reverse(filtered_buddies
);
5132 text
= oscar_format_buddies(filtered_buddies
, _("you are not waiting for authorization"));
5133 g_slist_free(filtered_buddies
);
5135 purple_notify_formatted(gc
, NULL
, _("You are awaiting authorization from "
5136 "the following buddies"), _("You can re-request "
5137 "authorization from these buddies by "
5138 "right-clicking on them and selecting "
5139 "\"Re-request Authorization.\""), text
, NULL
, NULL
);
5143 static void search_by_email_cb(PurpleConnection
*gc
, const char *email
)
5145 OscarData
*od
= purple_connection_get_protocol_data(gc
);
5147 aim_search_address(od
, email
);
5150 static void oscar_show_find_email(PurpleProtocolAction
*action
)
5152 PurpleConnection
*gc
= action
->connection
;
5153 purple_request_input(gc
, _("Find Buddy by Email"),
5154 _("Search for a buddy by email address"),
5155 _("Type the email address of the buddy you are "
5157 NULL
, FALSE
, FALSE
, NULL
,
5158 _("_Search"), G_CALLBACK(search_by_email_cb
),
5160 purple_request_cpar_from_connection(gc
),
5164 static void oscar_show_set_info(PurpleProtocolAction
*action
)
5166 PurpleConnection
*gc
= action
->connection
;
5167 purple_account_request_change_user_info(purple_connection_get_account(gc
));
5170 static void oscar_show_set_info_icqurl(PurpleProtocolAction
*action
)
5172 PurpleConnection
*gc
= action
->connection
;
5173 purple_notify_uri(gc
, "http://www.icq.com/whitepages/user_details.php");
5176 static void oscar_change_pass(PurpleProtocolAction
*action
)
5178 PurpleConnection
*gc
= action
->connection
;
5179 purple_account_request_change_password(purple_connection_get_account(gc
));
5183 * Only used when connecting with the old-style BUCP login.
5185 static void oscar_show_chpassurl(PurpleProtocolAction
*action
)
5187 PurpleConnection
*gc
= action
->connection
;
5188 OscarData
*od
= purple_connection_get_protocol_data(gc
);
5189 gchar
*substituted
= purple_strreplace(od
->authinfo
->chpassurl
, "%s", purple_account_get_username(purple_connection_get_account(gc
)));
5190 purple_notify_uri(gc
, substituted
);
5191 g_free(substituted
);
5194 static void oscar_show_imforwardingurl(PurpleProtocolAction
*action
)
5196 PurpleConnection
*gc
= action
->connection
;
5197 purple_notify_uri(gc
, "http://mymobile.aol.com/dbreg/register?action=imf&clientID=1");
5200 void oscar_set_icon(PurpleConnection
*gc
, PurpleImage
*img
)
5202 OscarData
*od
= purple_connection_get_protocol_data(gc
);
5205 aim_ssi_delicon(od
);
5209 gsize digest_len
= 16;
5210 gconstpointer data
= purple_image_get_data(img
);
5211 size_t len
= purple_image_get_data_size(img
);
5213 hash
= g_checksum_new(G_CHECKSUM_MD5
);
5214 g_checksum_update(hash
, data
, len
);
5215 g_checksum_get_digest(hash
, md5
, &digest_len
);
5216 g_checksum_free(hash
);
5218 aim_ssi_seticon(od
, md5
, 16);
5223 * Called by the Purple core to determine whether or not we're
5224 * allowed to send a file to this user.
5227 oscar_can_receive_file(PurpleProtocolXfer
*prplxfer
, PurpleConnection
*gc
, const char *who
)
5230 PurpleAccount
*account
;
5232 od
= purple_connection_get_protocol_data(gc
);
5233 account
= purple_connection_get_account(gc
);
5237 aim_userinfo_t
*userinfo
;
5238 userinfo
= aim_locate_finduserinfo(od
, who
);
5241 * Don't allowing sending a file to a user that does not support
5242 * file transfer, and don't allow sending to ourselves.
5244 if (((userinfo
== NULL
) ||
5245 (userinfo
->capabilities
& OSCAR_CAPABILITY_SENDFILE
)) &&
5246 oscar_util_name_compare(who
, purple_account_get_username(account
)))
5256 oscar_new_xfer(PurpleProtocolXfer
*prplxfer
, PurpleConnection
*gc
, const char *who
)
5260 PurpleAccount
*account
;
5261 PeerConnection
*conn
;
5263 od
= purple_connection_get_protocol_data(gc
);
5264 account
= purple_connection_get_account(gc
);
5266 conn
= peer_connection_new(od
, OSCAR_CAPABILITY_SENDFILE
, who
);
5267 conn
->flags
|= PEER_CONNECTION_FLAG_INITIATED_BY_ME
;
5268 conn
->flags
|= PEER_CONNECTION_FLAG_APPROVED
;
5270 xfer
= g_object_new(
5273 "type", PURPLE_XFER_TYPE_SEND
,
5279 aim_icbm_makecookie(conn
->cookie
);
5280 conn
->xfer
= PURPLE_XFER(xfer
);
5282 return PURPLE_XFER(xfer
);
5286 * Called by the Purple core when the user indicates that a
5287 * file is to be sent to a special someone.
5290 oscar_send_file(PurpleProtocolXfer
*prplxfer
, PurpleConnection
*gc
, const char *who
, const char *file
)
5294 xfer
= oscar_new_xfer(prplxfer
, gc
, who
);
5297 purple_xfer_request_accepted(xfer
, file
);
5299 purple_xfer_request(xfer
);
5303 oscar_get_actions(PurpleConnection
*gc
)
5305 OscarData
*od
= purple_connection_get_protocol_data(gc
);
5307 PurpleProtocolAction
*act
;
5309 act
= purple_protocol_action_new(_("Set User Info..."),
5310 oscar_show_set_info
);
5311 menu
= g_list_prepend(menu
, act
);
5315 act
= purple_protocol_action_new(_("Set User Info (web)..."),
5316 oscar_show_set_info_icqurl
);
5317 menu
= g_list_prepend(menu
, act
);
5320 act
= purple_protocol_action_new(_("Change Password..."),
5322 menu
= g_list_prepend(menu
, act
);
5324 if (od
->authinfo
!= NULL
&& od
->authinfo
->chpassurl
!= NULL
)
5326 /* This only happens when connecting with the old-style BUCP login */
5327 act
= purple_protocol_action_new(_("Change Password (web)"),
5328 oscar_show_chpassurl
);
5329 menu
= g_list_prepend(menu
, act
);
5334 act
= purple_protocol_action_new(_("Configure IM Forwarding (web)"),
5335 oscar_show_imforwardingurl
);
5336 menu
= g_list_prepend(menu
, act
);
5339 menu
= g_list_prepend(menu
, NULL
);
5344 act
= purple_protocol_action_new(_("Set Privacy Options..."),
5345 oscar_show_icq_privacy_opts
);
5346 menu
= g_list_prepend(menu
, act
);
5348 act
= purple_protocol_action_new(_("Show Visible List"), oscar_show_visible_list
);
5349 menu
= g_list_prepend(menu
, act
);
5351 act
= purple_protocol_action_new(_("Show Invisible List"), oscar_show_invisible_list
);
5352 menu
= g_list_prepend(menu
, act
);
5357 act
= purple_protocol_action_new(_("Confirm Account"),
5358 oscar_confirm_account
);
5359 menu
= g_list_prepend(menu
, act
);
5361 act
= purple_protocol_action_new(_("Display Currently Registered Email Address"),
5363 menu
= g_list_prepend(menu
, act
);
5365 act
= purple_protocol_action_new(_("Change Currently Registered Email Address..."),
5366 oscar_show_change_email
);
5367 menu
= g_list_prepend(menu
, act
);
5370 menu
= g_list_prepend(menu
, NULL
);
5372 act
= purple_protocol_action_new(_("Show Buddies Awaiting Authorization"),
5373 oscar_show_awaitingauth
);
5374 menu
= g_list_prepend(menu
, act
);
5376 menu
= g_list_prepend(menu
, NULL
);
5378 act
= purple_protocol_action_new(_("Search for Buddy by Email Address..."),
5379 oscar_show_find_email
);
5380 menu
= g_list_prepend(menu
, act
);
5382 menu
= g_list_reverse(menu
);
5387 void oscar_change_passwd(PurpleConnection
*gc
, const char *old
, const char *new)
5389 OscarData
*od
= purple_connection_get_protocol_data(gc
);
5392 aim_icq_changepasswd(od
, new);
5394 FlapConnection
*conn
;
5395 conn
= flap_connection_getbytype(od
, SNAC_FAMILY_ADMIN
);
5397 aim_admin_changepasswd(od
, conn
, new, old
);
5400 od
->oldp
= g_strdup(old
);
5401 od
->newp
= g_strdup(new);
5402 aim_srv_requestnew(od
, SNAC_FAMILY_ADMIN
);
5408 oscar_convo_closed(PurpleConnection
*gc
, const char *who
)
5411 PeerConnection
*conn
;
5413 od
= purple_connection_get_protocol_data(gc
);
5414 conn
= peer_connection_find_by_type(od
, who
, OSCAR_CAPABILITY_DIRECTIM
);
5419 aim_im_sendch2_cancel(conn
);
5421 peer_connection_destroy(conn
, OSCAR_DISCONNECT_LOCAL_CLOSED
, NULL
);
5426 oscar_normalize(const PurpleAccount
*account
, const char *str
)
5428 static char buf
[BUF_LEN
];
5432 g_return_val_if_fail(str
!= NULL
, NULL
);
5434 /* copy str to buf and skip all blanks */
5436 for (j
= 0; str
[j
]; j
++) {
5437 if (str
[j
] != ' ') {
5439 if (i
>= BUF_LEN
- 1)
5445 tmp1
= g_utf8_strdown(buf
, -1);
5446 tmp2
= g_utf8_normalize(tmp1
, -1, G_NORMALIZE_DEFAULT
);
5447 if (strlen(tmp2
) > sizeof(buf
) - 1) {
5448 purple_debug_error("oscar", "normalized string exceeds buffer length!\n");
5450 g_strlcpy(buf
, tmp2
, sizeof(buf
));
5458 oscar_offline_message(const PurpleBuddy
*buddy
)
5464 oscar_get_max_message_size(PurpleConversation
*conv
)
5466 /* XXX: got from pidgin-otr - verify and document it */
5470 /* TODO: Find somewhere to put this instead of including it in a bunch of places.
5471 * Maybe just change purple_accounts_find() to return anything for the protocol if there is no acct_id.
5473 static PurpleAccount
*find_acct(const char *protocol
, const char *acct_id
)
5475 PurpleAccount
*acct
= NULL
;
5477 /* If we have a specific acct, use it */
5479 acct
= purple_accounts_find(acct_id
, protocol
);
5480 if (acct
&& !purple_account_is_connected(acct
))
5482 } else { /* Otherwise find an active account for the protocol */
5483 GList
*l
= purple_accounts_get_all();
5485 if (purple_strequal(protocol
, purple_account_get_protocol_id(l
->data
))
5486 && purple_account_is_connected(l
->data
)) {
5497 gboolean
oscar_uri_handler(const char *proto
, const char *cmd
, GHashTable
*params
)
5501 PurpleAccount
*acct
;
5503 if (g_ascii_strcasecmp(proto
, "aim") && g_ascii_strcasecmp(proto
, "icq"))
5506 if (params
== NULL
) {
5507 /* All Oscar URI actions require some parameters eventually */
5508 purple_debug_warning("oscar",
5509 "No required params for handling URI");
5513 acct_id
= g_hash_table_lookup(params
, "account");
5514 g_snprintf(prpl
, sizeof(prpl
), "prpl-%s", proto
);
5516 acct
= find_acct(proto
, acct_id
);
5521 /* aim:GoIM?screenname=SCREENNAME&message=MESSAGE */
5522 if (!g_ascii_strcasecmp(cmd
, "GoIM")) {
5523 char *bname
= g_hash_table_lookup(params
, "screenname");
5525 char *message
= g_hash_table_lookup(params
, "message");
5527 PurpleIMConversation
*im
= purple_conversations_find_im_with_account(
5530 im
= purple_im_conversation_new(acct
, bname
);
5531 purple_conversation_present(PURPLE_CONVERSATION(im
));
5534 /* Spaces are encoded as '+' */
5535 g_strdelimit(message
, "+", ' ');
5536 purple_conversation_send_confirm(PURPLE_CONVERSATION(im
), message
);
5540 **If pidgindialogs_im() was in the core, we could use it here.
5541 * It is all purple_request_* based, but I'm not sure it really belongs in the core
5542 pidgindialogs_im();*/
5546 /* aim:GoChat?roomname=CHATROOMNAME&exchange=4 */
5547 else if (!g_ascii_strcasecmp(cmd
, "GoChat")) {
5548 char *rname
= g_hash_table_lookup(params
, "roomname");
5550 /* This is somewhat hacky, but the params aren't useful after this command */
5551 g_hash_table_insert(params
, g_strdup("exchange"), g_strdup("4"));
5552 g_hash_table_insert(params
, g_strdup("room"), g_strdup(rname
));
5553 purple_serv_join_chat(purple_account_get_connection(acct
), params
);
5556 ** Same as above (except that this would have to be re-written using purple_request_*)
5557 pidgin_blist_joinchat_show(); */
5561 /* aim:AddBuddy?screenname=SCREENNAME&groupname=GROUPNAME*/
5562 else if (!g_ascii_strcasecmp(cmd
, "AddBuddy")) {
5563 char *bname
= g_hash_table_lookup(params
, "screenname");
5564 char *gname
= g_hash_table_lookup(params
, "groupname");
5565 purple_blist_request_add_buddy(acct
, bname
, gname
, NULL
);
5572 void oscar_init_account_options(PurpleProtocol
*protocol
, gboolean is_icq
)
5574 PurpleAccountOption
*option
;
5575 static const gchar
*encryption_keys
[] = {
5576 N_("Use encryption if available"),
5577 N_("Require encryption"),
5578 N_("Don't use encryption"),
5581 static const gchar
*encryption_values
[] = {
5582 OSCAR_OPPORTUNISTIC_ENCRYPTION
,
5583 OSCAR_REQUIRE_ENCRYPTION
,
5584 OSCAR_NO_ENCRYPTION
,
5587 static const gchar
*aim_login_keys
[] = {
5588 N_("Use clientLogin authentication"),
5589 N_("Use Kerberos-based authentication"),
5590 N_("Use MD5 based authentication"),
5593 static const gchar
*aim_login_values
[] = {
5595 OSCAR_KERBEROS_LOGIN
,
5599 static const gchar
*icq_login_keys
[] = {
5600 N_("Use clientLogin authentication"),
5601 N_("Use MD5 based authentication"),
5604 static const gchar
*icq_login_values
[] = {
5609 const gchar
**login_keys
;
5610 const gchar
**login_values
;
5611 GList
*encryption_options
= NULL
;
5612 GList
*login_options
= NULL
;
5615 option
= purple_account_option_string_new(_("Server"), "server", oscar_get_login_server(is_icq
, TRUE
));
5616 protocol
->account_options
= g_list_append(protocol
->account_options
, option
);
5618 option
= purple_account_option_int_new(_("Port"), "port", OSCAR_DEFAULT_LOGIN_PORT
);
5619 protocol
->account_options
= g_list_append(protocol
->account_options
, option
);
5621 for (i
= 0; encryption_keys
[i
]; i
++) {
5622 PurpleKeyValuePair
*kvp
= g_new0(PurpleKeyValuePair
, 1);
5623 kvp
->key
= g_strdup(_(encryption_keys
[i
]));
5624 kvp
->value
= g_strdup(encryption_values
[i
]);
5625 encryption_options
= g_list_append(encryption_options
, kvp
);
5627 option
= purple_account_option_list_new(_("Connection security"), "encryption", encryption_options
);
5628 protocol
->account_options
= g_list_append(protocol
->account_options
, option
);
5631 login_keys
= icq_login_keys
;
5632 login_values
= icq_login_values
;
5634 login_keys
= aim_login_keys
;
5635 login_values
= aim_login_values
;
5637 for (i
= 0; login_keys
[i
]; i
++) {
5638 PurpleKeyValuePair
*kvp
= g_new0(PurpleKeyValuePair
, 1);
5639 kvp
->key
= g_strdup(_(login_keys
[i
]));
5640 kvp
->value
= g_strdup(login_values
[i
]);
5641 login_options
= g_list_append(login_options
, kvp
);
5643 option
= purple_account_option_list_new(_("Authentication method"), "login_type", login_options
);
5644 protocol
->account_options
= g_list_append(protocol
->account_options
, option
);
5646 option
= purple_account_option_bool_new(
5647 _("Always use AIM/ICQ proxy server for\nfile transfers and direct IM (slower,\nbut does not reveal your IP address)"), "always_use_rv_proxy",
5648 OSCAR_DEFAULT_ALWAYS_USE_RV_PROXY
);
5649 protocol
->account_options
= g_list_append(protocol
->account_options
, option
);
5652 option
= purple_account_option_string_new(_("Encoding"), "encoding", OSCAR_DEFAULT_CUSTOM_ENCODING
);
5653 protocol
->account_options
= g_list_append(protocol
->account_options
, option
);
5655 option
= purple_account_option_bool_new(_("Allow multiple simultaneous logins"), "allow_multiple_logins",
5656 OSCAR_DEFAULT_ALLOW_MULTIPLE_LOGINS
);
5657 protocol
->account_options
= g_list_append(protocol
->account_options
, option
);
5662 oscar_protocol_init(OscarProtocol
*self
)
5664 PurpleProtocol
*protocol
= PURPLE_PROTOCOL(self
);
5666 protocol
->options
= OPT_PROTO_MAIL_CHECK
| OPT_PROTO_INVITE_MESSAGE
|
5667 OPT_PROTO_AUTHORIZATION_DENIED_MESSAGE
;
5668 protocol
->icon_spec
= purple_buddy_icon_spec_new("gif,jpeg,bmp,ico",
5670 PURPLE_ICON_SCALE_SEND
|
5671 PURPLE_ICON_SCALE_DISPLAY
);
5675 oscar_protocol_class_init(OscarProtocolClass
*klass
)
5677 PurpleProtocolClass
*protocol_class
= PURPLE_PROTOCOL_CLASS(klass
);
5679 protocol_class
->login
= oscar_login
;
5680 protocol_class
->close
= oscar_close
;
5681 protocol_class
->status_types
= oscar_status_types
;
5685 oscar_protocol_class_finalize(G_GNUC_UNUSED OscarProtocolClass
*klass
)
5690 oscar_protocol_client_iface_init(PurpleProtocolClientInterface
*client_iface
)
5692 client_iface
->get_actions
= oscar_get_actions
;
5693 client_iface
->list_emblem
= oscar_list_emblem
;
5694 client_iface
->status_text
= oscar_status_text
;
5695 client_iface
->tooltip_text
= oscar_tooltip_text
;
5696 client_iface
->blist_node_menu
= oscar_blist_node_menu
;
5697 client_iface
->convo_closed
= oscar_convo_closed
;
5698 client_iface
->normalize
= oscar_normalize
;
5699 client_iface
->offline_message
= oscar_offline_message
;
5703 oscar_protocol_server_iface_init(PurpleProtocolServerInterface
*server_iface
)
5705 server_iface
->set_info
= oscar_set_info
;
5706 server_iface
->get_info
= oscar_get_info
;
5707 server_iface
->set_status
= oscar_set_status
;
5708 server_iface
->set_idle
= oscar_set_idle
;
5709 server_iface
->change_passwd
= oscar_change_passwd
;
5710 server_iface
->add_buddy
= oscar_add_buddy
;
5711 server_iface
->remove_buddy
= oscar_remove_buddy
;
5712 server_iface
->keepalive
= oscar_keepalive
;
5713 server_iface
->alias_buddy
= oscar_alias_buddy
;
5714 server_iface
->group_buddy
= oscar_move_buddy
;
5715 server_iface
->rename_group
= oscar_rename_group
;
5716 server_iface
->set_buddy_icon
= oscar_set_icon
;
5717 server_iface
->remove_group
= oscar_remove_group
;
5721 oscar_protocol_im_iface_init(PurpleProtocolIMInterface
*im_iface
)
5723 im_iface
->send
= oscar_send_im
;
5724 im_iface
->send_typing
= oscar_send_typing
;
5728 oscar_protocol_chat_iface_init(PurpleProtocolChatInterface
*chat_iface
)
5730 chat_iface
->info
= oscar_chat_info
;
5731 chat_iface
->info_defaults
= oscar_chat_info_defaults
;
5732 chat_iface
->join
= oscar_join_chat
;
5733 chat_iface
->get_name
= oscar_get_chat_name
;
5734 chat_iface
->invite
= oscar_chat_invite
;
5735 chat_iface
->leave
= oscar_chat_leave
;
5736 chat_iface
->send
= oscar_send_chat
;
5740 oscar_protocol_privacy_iface_init(PurpleProtocolPrivacyInterface
*privacy_iface
)
5742 privacy_iface
->add_deny
= oscar_add_deny
;
5743 privacy_iface
->rem_deny
= oscar_rem_deny
;
5747 oscar_protocol_xfer_iface_init(PurpleProtocolXferInterface
*xfer_iface
)
5749 xfer_iface
->can_receive
= oscar_can_receive_file
;
5750 xfer_iface
->send_file
= oscar_send_file
;
5751 xfer_iface
->new_xfer
= oscar_new_xfer
;
5754 G_DEFINE_DYNAMIC_TYPE_EXTENDED(
5755 OscarProtocol
, oscar_protocol
, PURPLE_TYPE_PROTOCOL
,
5756 G_TYPE_FLAG_ABSTRACT
,
5758 G_IMPLEMENT_INTERFACE_DYNAMIC(PURPLE_TYPE_PROTOCOL_CLIENT
,
5759 oscar_protocol_client_iface_init
)
5761 G_IMPLEMENT_INTERFACE_DYNAMIC(PURPLE_TYPE_PROTOCOL_SERVER
,
5762 oscar_protocol_server_iface_init
)
5764 G_IMPLEMENT_INTERFACE_DYNAMIC(PURPLE_TYPE_PROTOCOL_IM
,
5765 oscar_protocol_im_iface_init
)
5767 G_IMPLEMENT_INTERFACE_DYNAMIC(PURPLE_TYPE_PROTOCOL_CHAT
,
5768 oscar_protocol_chat_iface_init
)
5770 G_IMPLEMENT_INTERFACE_DYNAMIC(PURPLE_TYPE_PROTOCOL_PRIVACY
,
5771 oscar_protocol_privacy_iface_init
)
5773 G_IMPLEMENT_INTERFACE_DYNAMIC(PURPLE_TYPE_PROTOCOL_XFER
,
5774 oscar_protocol_xfer_iface_init
));
5776 static PurplePluginInfo
*
5777 plugin_query(GError
**error
)
5779 return purple_plugin_info_new(
5781 "name", "Oscar Protocols",
5782 "version", DISPLAY_VERSION
,
5783 "category", N_("Protocol"),
5784 "summary", N_("Oscar (AIM/ICQ) Protocols Plugin"),
5785 "description", N_("Oscar (AIM/ICQ) Protocols Plugin"),
5786 "website", PURPLE_WEBSITE
,
5787 "abi-version", PURPLE_ABI_VERSION
,
5788 "flags", PURPLE_PLUGIN_INFO_FLAGS_INTERNAL
|
5789 PURPLE_PLUGIN_INFO_FLAGS_AUTO_LOAD
,
5795 plugin_load(PurplePlugin
*plugin
, GError
**error
)
5797 oscar_protocol_register_type(G_TYPE_MODULE(plugin
));
5799 aim_protocol_register(plugin
);
5800 icq_protocol_register(plugin
);
5802 oscar_xfer_register(G_TYPE_MODULE(plugin
));
5804 aim_protocol
= purple_protocols_add(AIM_TYPE_PROTOCOL
, error
);
5808 icq_protocol
= purple_protocols_add(ICQ_TYPE_PROTOCOL
, error
);
5812 purple_signal_connect(purple_get_core(), "uri-handler", aim_protocol
,
5813 PURPLE_CALLBACK(oscar_uri_handler
), NULL
);
5814 purple_signal_connect(purple_get_core(), "uri-handler", icq_protocol
,
5815 PURPLE_CALLBACK(oscar_uri_handler
), NULL
);
5818 purple_prefs_add_none("/plugins/prpl/oscar");
5819 purple_prefs_add_bool("/plugins/prpl/oscar/recent_buddies", FALSE
);
5821 purple_prefs_remove("/plugins/prpl/oscar/show_idle");
5822 purple_prefs_remove("/plugins/prpl/oscar/always_use_rv_proxy");
5828 plugin_unload(PurplePlugin
*plugin
, GError
**error
)
5830 if (!purple_protocols_remove(icq_protocol
, error
))
5833 if (!purple_protocols_remove(aim_protocol
, error
))
5839 PURPLE_PLUGIN_INIT(oscar
, plugin_query
, plugin_load
, plugin_unload
);