3 * Purple is the legal property of its developers, whose names are too numerous
4 * to list here. Please refer to the COPYRIGHT file distributed with this
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
22 #include "glibcompat.h"
39 * Structure representing an account.
48 char *username
; /* The username. */
49 char *alias
; /* How you appear to yourself. */
50 char *password
; /* The account password. */
51 char *user_info
; /* User information. */
53 char *buddy_icon_path
; /* The buddy icon's non-cached path. */
55 gboolean remember_pass
; /* Remember the password. */
58 * TODO: After a GObject representing a protocol is ready, use it
59 * here instead of the protocol ID.
61 char *protocol_id
; /* The ID of the protocol. */
63 PurpleConnection
*gc
; /* The connection handle. */
64 gboolean disconnecting
; /* The account is currently disconnecting */
66 GHashTable
*settings
; /* Protocol-specific settings. */
67 GHashTable
*ui_settings
; /* UI-specific settings. */
69 PurpleProxyInfo
*proxy_info
; /* Proxy information. This will be set */
70 /* to NULL when the account inherits */
71 /* proxy settings from global prefs. */
74 * TODO: Instead of linked lists for permit and deny, use a data
75 * structure that allows fast lookups AND decent performance when
76 * iterating through all items. Fast lookups should help performance
77 * for protocols like MSN, where all your buddies exist in your permit
78 * list therefore the permit list is large. Possibly GTree or
81 GSList
*permit
; /* Permit list. */
82 GSList
*deny
; /* Deny list. */
83 PurpleAccountPrivacyType privacy_type
; /* The permit/deny setting. */
85 GList
*status_types
; /* Status types. */
87 PurplePresence
*presence
; /* Presence. */
88 PurpleLog
*system_log
; /* The system log */
90 PurpleAccountRegistrationCb registration_cb
;
91 void *registration_cb_user_data
;
93 PurpleConnectionErrorInfo
*current_error
; /* Errors */
94 } PurpleAccountPrivate
;
101 } PurpleAccountSetting
;
105 PurpleAccountRequestType type
;
106 PurpleAccount
*account
;
110 PurpleAccountRequestAuthorizationCb auth_cb
;
111 PurpleAccountRequestAuthorizationCb deny_cb
;
113 } PurpleAccountRequestInfo
;
119 } PurpleCallbackBundle
;
121 /* GObject Property enums */
131 PROP_BUDDY_ICON_PATH
,
132 PROP_REMEMBER_PASSWORD
,
137 static GParamSpec
*properties
[PROP_LAST
];
138 static GList
*handles
= NULL
;
140 G_DEFINE_TYPE_WITH_PRIVATE(PurpleAccount
, purple_account
, G_TYPE_OBJECT
);
142 /******************************************************************************
144 *****************************************************************************/
146 purple_account_register_got_password_cb(PurpleAccount
*account
,
147 const gchar
*password
, GError
*error
, gpointer data
)
149 g_return_if_fail(PURPLE_IS_ACCOUNT(account
));
151 _purple_connection_new(account
, TRUE
, password
);
155 purple_account_register(PurpleAccount
*account
)
157 g_return_if_fail(PURPLE_IS_ACCOUNT(account
));
159 purple_debug_info("account", "Registering account %s\n",
160 purple_account_get_username(account
));
162 purple_keyring_get_password(account
,
163 purple_account_register_got_password_cb
, NULL
);
167 purple_account_unregister_got_password_cb(PurpleAccount
*account
,
168 const gchar
*password
, GError
*error
, gpointer data
)
170 PurpleCallbackBundle
*cbb
= data
;
171 PurpleAccountUnregistrationCb cb
;
173 cb
= (PurpleAccountUnregistrationCb
)cbb
->cb
;
174 _purple_connection_new_unregister(account
, password
, cb
, cbb
->data
);
179 struct register_completed_closure
181 PurpleAccount
*account
;
186 purple_account_register_completed_cb(gpointer data
)
188 struct register_completed_closure
*closure
= data
;
189 PurpleAccountPrivate
*priv
;
191 priv
= purple_account_get_instance_private(closure
->account
);
193 if (priv
->registration_cb
)
194 (priv
->registration_cb
)(closure
->account
, closure
->succeeded
,
195 priv
->registration_cb_user_data
);
197 g_object_unref(closure
->account
);
204 request_password_ok_cb(PurpleAccount
*account
, PurpleRequestFields
*fields
)
209 entry
= purple_request_fields_get_string(fields
, "password");
210 remember
= purple_request_fields_get_bool(fields
, "remember");
212 if (!entry
|| !*entry
)
214 purple_notify_error(account
, NULL
,
215 _("Password is required to sign on."), NULL
,
216 purple_request_cpar_from_account(account
));
220 purple_account_set_remember_password(account
, remember
);
222 purple_account_set_password(account
, entry
, NULL
, NULL
);
223 _purple_connection_new(account
, FALSE
, entry
);
227 request_password_cancel_cb(PurpleAccount
*account
, PurpleRequestFields
*fields
)
229 /* Disable the account as the user has cancelled connecting */
230 purple_account_set_enabled(account
, purple_core_get_ui(), FALSE
);
235 purple_account_connect_got_password_cb(PurpleAccount
*account
,
236 const gchar
*password
, GError
*error
, gpointer data
)
238 PurpleProtocol
*protocol
= data
;
240 if ((password
== NULL
|| *password
== '\0') &&
241 !(purple_protocol_get_options(protocol
) & OPT_PROTO_NO_PASSWORD
) &&
242 !(purple_protocol_get_options(protocol
) & OPT_PROTO_PASSWORD_OPTIONAL
))
243 purple_account_request_password(account
,
244 G_CALLBACK(request_password_ok_cb
),
245 G_CALLBACK(request_password_cancel_cb
), account
);
247 _purple_connection_new(account
, FALSE
, password
);
250 static PurpleAccountRequestInfo
*
251 purple_account_request_info_unref(PurpleAccountRequestInfo
*info
)
256 /* TODO: This will leak info->user_data, but there is no callback to just clean that up */
263 purple_account_request_close_info(PurpleAccountRequestInfo
*info
)
265 PurpleAccountUiOps
*ops
;
267 ops
= purple_accounts_get_ui_ops();
269 if (ops
!= NULL
&& ops
->close_account_request
!= NULL
)
270 ops
->close_account_request(info
->ui_handle
);
272 purple_account_request_info_unref(info
);
276 request_auth_cb(const char *message
, void *data
)
278 PurpleAccountRequestInfo
*info
= data
;
280 handles
= g_list_remove(handles
, info
);
282 if (info
->auth_cb
!= NULL
)
283 info
->auth_cb(message
, info
->userdata
);
285 purple_signal_emit(purple_accounts_get_handle(),
286 "account-authorization-granted", info
->account
, info
->user
, message
);
288 purple_account_request_info_unref(info
);
292 request_deny_cb(const char *message
, void *data
)
294 PurpleAccountRequestInfo
*info
= data
;
296 handles
= g_list_remove(handles
, info
);
298 if (info
->deny_cb
!= NULL
)
299 info
->deny_cb(message
, info
->userdata
);
301 purple_signal_emit(purple_accounts_get_handle(),
302 "account-authorization-denied", info
->account
, info
->user
, message
);
304 purple_account_request_info_unref(info
);
308 change_password_cb(PurpleAccount
*account
, PurpleRequestFields
*fields
)
310 const char *orig_pass
, *new_pass_1
, *new_pass_2
;
312 orig_pass
= purple_request_fields_get_string(fields
, "password");
313 new_pass_1
= purple_request_fields_get_string(fields
, "new_password_1");
314 new_pass_2
= purple_request_fields_get_string(fields
, "new_password_2");
316 if (g_utf8_collate(new_pass_1
, new_pass_2
))
318 purple_notify_error(account
, NULL
,
319 _("New passwords do not match."), NULL
,
320 purple_request_cpar_from_account(account
));
325 if ((purple_request_fields_is_field_required(fields
, "password") &&
326 (orig_pass
== NULL
|| *orig_pass
== '\0')) ||
327 (purple_request_fields_is_field_required(fields
, "new_password_1") &&
328 (new_pass_1
== NULL
|| *new_pass_1
== '\0')) ||
329 (purple_request_fields_is_field_required(fields
, "new_password_2") &&
330 (new_pass_2
== NULL
|| *new_pass_2
== '\0')))
332 purple_notify_error(account
, NULL
,
333 _("Fill out all fields completely."), NULL
,
334 purple_request_cpar_from_account(account
));
338 purple_account_change_password(account
, orig_pass
, new_pass_1
);
342 set_user_info_cb(PurpleAccount
*account
, const char *user_info
)
344 PurpleConnection
*gc
;
346 purple_account_set_user_info(account
, user_info
);
347 gc
= purple_account_get_connection(account
);
348 purple_serv_set_info(gc
, user_info
);
351 struct public_alias_closure
353 PurpleAccount
*account
;
358 set_public_alias_unsupported(gpointer data
)
360 struct public_alias_closure
*closure
= data
;
361 PurpleSetPublicAliasFailureCallback failure_cb
= closure
->failure_cb
;
363 failure_cb(closure
->account
,
364 _("This protocol does not support setting a public alias."));
366 g_object_unref(closure
->account
);
373 get_public_alias_unsupported(gpointer data
)
375 struct public_alias_closure
*closure
= data
;
376 PurpleGetPublicAliasFailureCallback failure_cb
= closure
->failure_cb
;
378 failure_cb(closure
->account
,
379 _("This protocol does not support fetching the public alias."));
381 g_object_unref(closure
->account
);
388 delete_setting(void *data
)
390 PurpleAccountSetting
*setting
= (PurpleAccountSetting
*)data
;
393 g_value_unset(&setting
->value
);
399 get_ui_settings_table(PurpleAccount
*account
, const char *ui
)
402 PurpleAccountPrivate
*priv
= purple_account_get_instance_private(account
);
404 table
= g_hash_table_lookup(priv
->ui_settings
, ui
);
407 table
= g_hash_table_new_full(g_str_hash
, g_str_equal
, g_free
,
409 g_hash_table_insert(priv
->ui_settings
, g_strdup(ui
), table
);
415 static PurpleConnectionState
416 purple_account_get_state(PurpleAccount
*account
)
418 PurpleConnection
*gc
;
420 g_return_val_if_fail(PURPLE_IS_ACCOUNT(account
), PURPLE_CONNECTION_DISCONNECTED
);
422 gc
= purple_account_get_connection(account
);
424 return PURPLE_CONNECTION_DISCONNECTED
;
426 return purple_connection_get_state(gc
);
430 purple_account_get_password_got(PurpleAccount
*account
,
431 const gchar
*password
, GError
*error
, gpointer data
)
433 PurpleCallbackBundle
*cbb
= data
;
434 PurpleKeyringReadCallback cb
;
435 PurpleAccountPrivate
*priv
= purple_account_get_instance_private(account
);
437 purple_debug_info("account",
438 "Read password for account %s from async keyring.\n",
439 purple_account_get_username(account
));
441 purple_str_wipe(priv
->password
);
442 priv
->password
= g_strdup(password
);
444 cb
= (PurpleKeyringReadCallback
)cbb
->cb
;
446 cb(account
, password
, error
, cbb
->data
);
452 * This makes sure your permit list contains all buddies from your
453 * buddy list and ONLY buddies from your buddy list.
456 add_all_buddies_to_permit_list(PurpleAccount
*account
, gboolean local
)
459 PurpleAccountPrivate
*priv
= purple_account_get_instance_private(account
);
461 /* Remove anyone in the permit list who is not in the buddylist */
462 for (list
= priv
->permit
; list
!= NULL
; ) {
463 char *person
= list
->data
;
465 if (!purple_blist_find_buddy(account
, person
))
466 purple_account_privacy_permit_remove(account
, person
, local
);
469 /* Now make sure everyone in the buddylist is in the permit list */
470 list
= purple_blist_find_buddies(account
, NULL
);
473 PurpleBuddy
*buddy
= list
->data
;
474 const gchar
*name
= purple_buddy_get_name(buddy
);
476 if (!g_slist_find_custom(priv
->permit
, name
, (GCompareFunc
)g_utf8_collate
))
477 purple_account_privacy_permit_add(account
, name
, local
);
478 list
= g_slist_delete_link(list
, list
);
483 _purple_account_set_current_error(PurpleAccount
*account
,
484 PurpleConnectionErrorInfo
*new_err
)
486 PurpleConnectionErrorInfo
*old_err
;
487 PurpleAccountPrivate
*priv
;
489 g_return_if_fail(PURPLE_IS_ACCOUNT(account
));
490 priv
= purple_account_get_instance_private(account
);
492 old_err
= priv
->current_error
;
494 if(new_err
== old_err
)
497 priv
->current_error
= new_err
;
499 purple_signal_emit(purple_accounts_get_handle(),
500 "account-error-changed",
501 account
, old_err
, new_err
);
502 purple_accounts_schedule_save();
505 g_free(old_err
->description
);
510 /******************************************************************************
512 *****************************************************************************/
513 static PurpleXmlNode
*
514 status_attribute_to_xmlnode(PurpleStatus
*status
, PurpleStatusType
*type
,
515 PurpleStatusAttribute
*attr
)
520 PurpleStatusAttribute
*default_attr
;
521 GValue
*default_value
;
525 id
= purple_status_attribute_get_id(attr
);
526 g_return_val_if_fail(id
, NULL
);
528 attr_value
= purple_status_get_attr_value(status
, id
);
529 g_return_val_if_fail(attr_value
, NULL
);
530 attr_type
= G_VALUE_TYPE(attr_value
);
533 * If attr_value is a different type than it should be
534 * then don't write it to the file.
536 default_attr
= purple_status_type_get_attr(type
, id
);
537 default_value
= purple_status_attribute_get_value(default_attr
);
538 if (attr_type
!= G_VALUE_TYPE(default_value
))
542 * If attr_value is the same as the default for this status
543 * then there is no need to write it to the file.
545 if (attr_type
== G_TYPE_STRING
)
547 const char *string_value
= g_value_get_string(attr_value
);
548 const char *default_string_value
= g_value_get_string(default_value
);
549 if (purple_strequal(string_value
, default_string_value
))
551 value
= g_value_dup_string(attr_value
);
553 else if (attr_type
== G_TYPE_INT
)
555 int int_value
= g_value_get_int(attr_value
);
556 if (int_value
== g_value_get_int(default_value
))
558 value
= g_strdup_printf("%d", int_value
);
560 else if (attr_type
== G_TYPE_BOOLEAN
)
562 gboolean boolean_value
= g_value_get_boolean(attr_value
);
563 if (boolean_value
== g_value_get_boolean(default_value
))
565 value
= g_strdup(boolean_value
?
573 g_return_val_if_fail(value
, NULL
);
575 node
= purple_xmlnode_new("attribute");
577 purple_xmlnode_set_attrib(node
, "id", id
);
578 purple_xmlnode_set_attrib(node
, "value", value
);
585 static PurpleXmlNode
*
586 status_attrs_to_xmlnode(PurpleStatus
*status
)
588 PurpleStatusType
*type
= purple_status_get_status_type(status
);
589 PurpleXmlNode
*node
, *child
;
592 node
= purple_xmlnode_new("attributes");
594 attrs
= purple_status_type_get_attrs(type
);
595 for (attr
= attrs
; attr
!= NULL
; attr
= attr
->next
)
597 child
= status_attribute_to_xmlnode(status
, type
, (PurpleStatusAttribute
*)attr
->data
);
599 purple_xmlnode_insert_child(node
, child
);
605 static PurpleXmlNode
*
606 status_to_xmlnode(PurpleStatus
*status
)
608 PurpleXmlNode
*node
, *child
;
610 node
= purple_xmlnode_new("status");
611 purple_xmlnode_set_attrib(node
, "type", purple_status_get_id(status
));
612 if (purple_status_get_name(status
) != NULL
)
613 purple_xmlnode_set_attrib(node
, "name", purple_status_get_name(status
));
614 purple_xmlnode_set_attrib(node
, "active", purple_status_is_active(status
) ? "true" : "false");
616 child
= status_attrs_to_xmlnode(status
);
617 purple_xmlnode_insert_child(node
, child
);
622 static PurpleXmlNode
*
623 statuses_to_xmlnode(PurplePresence
*presence
)
625 PurpleXmlNode
*node
, *child
;
627 PurpleStatus
*status
;
629 node
= purple_xmlnode_new("statuses");
631 statuses
= purple_presence_get_statuses(presence
);
632 for (; statuses
!= NULL
; statuses
= statuses
->next
)
634 status
= statuses
->data
;
635 if (purple_status_type_is_saveable(purple_status_get_status_type(status
)))
637 child
= status_to_xmlnode(status
);
638 purple_xmlnode_insert_child(node
, child
);
645 static PurpleXmlNode
*
646 proxy_settings_to_xmlnode(const PurpleProxyInfo
*proxy_info
)
648 PurpleXmlNode
*node
, *child
;
649 PurpleProxyType proxy_type
;
654 proxy_type
= purple_proxy_info_get_proxy_type(proxy_info
);
656 node
= purple_xmlnode_new("proxy");
658 child
= purple_xmlnode_new_child(node
, "type");
659 purple_xmlnode_insert_data(child
,
660 (proxy_type
== PURPLE_PROXY_USE_GLOBAL
? "global" :
661 proxy_type
== PURPLE_PROXY_NONE
? "none" :
662 proxy_type
== PURPLE_PROXY_HTTP
? "http" :
663 proxy_type
== PURPLE_PROXY_SOCKS4
? "socks4" :
664 proxy_type
== PURPLE_PROXY_SOCKS5
? "socks5" :
665 proxy_type
== PURPLE_PROXY_TOR
? "tor" :
666 proxy_type
== PURPLE_PROXY_USE_ENVVAR
? "envvar" : "unknown"), -1);
668 if ((value
= purple_proxy_info_get_host(proxy_info
)) != NULL
)
670 child
= purple_xmlnode_new_child(node
, "host");
671 purple_xmlnode_insert_data(child
, value
, -1);
674 if ((int_value
= purple_proxy_info_get_port(proxy_info
)) != 0)
676 g_snprintf(buf
, sizeof(buf
), "%d", int_value
);
677 child
= purple_xmlnode_new_child(node
, "port");
678 purple_xmlnode_insert_data(child
, buf
, -1);
681 if ((value
= purple_proxy_info_get_username(proxy_info
)) != NULL
)
683 child
= purple_xmlnode_new_child(node
, "username");
684 purple_xmlnode_insert_data(child
, value
, -1);
687 if ((value
= purple_proxy_info_get_password(proxy_info
)) != NULL
)
689 child
= purple_xmlnode_new_child(node
, "password");
690 purple_xmlnode_insert_data(child
, value
, -1);
696 static PurpleXmlNode
*
697 current_error_to_xmlnode(PurpleConnectionErrorInfo
*err
)
699 PurpleXmlNode
*node
, *child
;
702 node
= purple_xmlnode_new("current_error");
707 /* It doesn't make sense to have transient errors persist across a
710 if(!purple_connection_error_is_fatal (err
->type
))
713 child
= purple_xmlnode_new_child(node
, "type");
714 g_snprintf(type_str
, sizeof(type_str
), "%u", err
->type
);
715 purple_xmlnode_insert_data(child
, type_str
, -1);
717 child
= purple_xmlnode_new_child(node
, "description");
718 if(err
->description
) {
719 char *utf8ized
= purple_utf8_try_convert(err
->description
);
721 utf8ized
= purple_utf8_salvage(err
->description
);
722 purple_xmlnode_insert_data(child
, utf8ized
, -1);
730 setting_to_xmlnode(gpointer key
, gpointer value
, gpointer user_data
)
733 PurpleAccountSetting
*setting
;
734 PurpleXmlNode
*node
, *child
;
737 name
= (const char *)key
;
738 setting
= (PurpleAccountSetting
*)value
;
739 node
= (PurpleXmlNode
*)user_data
;
741 child
= purple_xmlnode_new_child(node
, "setting");
742 purple_xmlnode_set_attrib(child
, "name", name
);
744 if (G_VALUE_HOLDS_INT(&setting
->value
)) {
745 purple_xmlnode_set_attrib(child
, "type", "int");
746 g_snprintf(buf
, sizeof(buf
), "%d", g_value_get_int(&setting
->value
));
747 purple_xmlnode_insert_data(child
, buf
, -1);
749 else if (G_VALUE_HOLDS_STRING(&setting
->value
) && g_value_get_string(&setting
->value
) != NULL
) {
750 purple_xmlnode_set_attrib(child
, "type", "string");
751 purple_xmlnode_insert_data(child
, g_value_get_string(&setting
->value
), -1);
753 else if (G_VALUE_HOLDS_BOOLEAN(&setting
->value
)) {
754 purple_xmlnode_set_attrib(child
, "type", "bool");
755 g_snprintf(buf
, sizeof(buf
), "%d", g_value_get_boolean(&setting
->value
));
756 purple_xmlnode_insert_data(child
, buf
, -1);
761 ui_setting_to_xmlnode(gpointer key
, gpointer value
, gpointer user_data
)
765 PurpleXmlNode
*node
, *child
;
767 ui
= (const char *)key
;
768 table
= (GHashTable
*)value
;
769 node
= (PurpleXmlNode
*)user_data
;
771 if (g_hash_table_size(table
) > 0)
773 child
= purple_xmlnode_new_child(node
, "settings");
774 purple_xmlnode_set_attrib(child
, "ui", ui
);
775 g_hash_table_foreach(table
, setting_to_xmlnode
, child
);
780 _purple_account_to_xmlnode(PurpleAccount
*account
)
782 PurpleXmlNode
*node
, *child
;
784 PurplePresence
*presence
;
785 const PurpleProxyInfo
*proxy_info
;
786 PurpleAccountPrivate
*priv
= purple_account_get_instance_private(account
);
788 node
= purple_xmlnode_new("account");
790 child
= purple_xmlnode_new_child(node
, "protocol");
791 purple_xmlnode_insert_data(child
, purple_account_get_protocol_id(account
), -1);
793 child
= purple_xmlnode_new_child(node
, "name");
794 purple_xmlnode_insert_data(child
, purple_account_get_username(account
), -1);
796 if (purple_account_get_remember_password(account
))
798 const char *keyring_id
= NULL
;
799 const char *mode
= NULL
;
801 GError
*error
= NULL
;
802 GDestroyNotify destroy
= NULL
;
803 gboolean exported
= purple_keyring_export_password(account
,
804 &keyring_id
, &mode
, &data
, &error
, &destroy
);
807 purple_debug_error("account",
808 "Failed to export password for account %s: %s.\n",
809 purple_account_get_username(account
),
811 } else if (exported
) {
812 child
= purple_xmlnode_new_child(node
, "password");
813 if (keyring_id
!= NULL
)
814 purple_xmlnode_set_attrib(child
, "keyring_id", keyring_id
);
816 purple_xmlnode_set_attrib(child
, "mode", mode
);
818 purple_xmlnode_insert_data(child
, data
, -1);
825 if ((tmp
= purple_account_get_private_alias(account
)) != NULL
)
827 child
= purple_xmlnode_new_child(node
, "alias");
828 purple_xmlnode_insert_data(child
, tmp
, -1);
831 if ((presence
= purple_account_get_presence(account
)) != NULL
)
833 child
= statuses_to_xmlnode(presence
);
834 purple_xmlnode_insert_child(node
, child
);
837 if ((tmp
= purple_account_get_user_info(account
)) != NULL
)
839 /* TODO: Do we need to call purple_str_strip_char(tmp, '\r') here? */
840 child
= purple_xmlnode_new_child(node
, "user-info");
841 purple_xmlnode_insert_data(child
, tmp
, -1);
844 if (g_hash_table_size(priv
->settings
) > 0)
846 child
= purple_xmlnode_new_child(node
, "settings");
847 g_hash_table_foreach(priv
->settings
, setting_to_xmlnode
, child
);
850 if (g_hash_table_size(priv
->ui_settings
) > 0)
852 g_hash_table_foreach(priv
->ui_settings
, ui_setting_to_xmlnode
, node
);
855 if ((proxy_info
= purple_account_get_proxy_info(account
)) != NULL
)
857 child
= proxy_settings_to_xmlnode(proxy_info
);
858 purple_xmlnode_insert_child(node
, child
);
861 child
= current_error_to_xmlnode(priv
->current_error
);
862 purple_xmlnode_insert_child(node
, child
);
867 /******************************************************************************
868 * GObject Implementation
869 *****************************************************************************/
871 purple_account_set_property(GObject
*obj
, guint param_id
, const GValue
*value
,
874 PurpleAccount
*account
= PURPLE_ACCOUNT(obj
);
878 purple_account_set_username(account
, g_value_get_string(value
));
880 case PROP_PRIVATE_ALIAS
:
881 purple_account_set_private_alias(account
, g_value_get_string(value
));
884 purple_account_set_enabled(account
, purple_core_get_ui(),
885 g_value_get_boolean(value
));
887 case PROP_CONNECTION
:
888 purple_account_set_connection(account
, g_value_get_object(value
));
890 case PROP_PROTOCOL_ID
:
891 purple_account_set_protocol_id(account
, g_value_get_string(value
));
894 purple_account_set_user_info(account
, g_value_get_string(value
));
896 case PROP_BUDDY_ICON_PATH
:
897 purple_account_set_buddy_icon_path(account
,
898 g_value_get_string(value
));
900 case PROP_REMEMBER_PASSWORD
:
901 purple_account_set_remember_password(account
,
902 g_value_get_boolean(value
));
904 case PROP_CHECK_MAIL
:
905 purple_account_set_check_mail(account
, g_value_get_boolean(value
));
908 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj
, param_id
, pspec
);
914 purple_account_get_property(GObject
*obj
, guint param_id
, GValue
*value
,
917 PurpleAccount
*account
= PURPLE_ACCOUNT(obj
);
921 g_value_set_string(value
, purple_account_get_username(account
));
923 case PROP_PRIVATE_ALIAS
:
924 g_value_set_string(value
, purple_account_get_private_alias(account
));
927 g_value_set_boolean(value
, purple_account_get_enabled(account
,
928 purple_core_get_ui()));
930 case PROP_CONNECTION
:
931 g_value_set_object(value
, purple_account_get_connection(account
));
933 case PROP_PROTOCOL_ID
:
934 g_value_set_string(value
, purple_account_get_protocol_id(account
));
937 g_value_set_string(value
, purple_account_get_user_info(account
));
939 case PROP_BUDDY_ICON_PATH
:
940 g_value_set_string(value
,
941 purple_account_get_buddy_icon_path(account
));
943 case PROP_REMEMBER_PASSWORD
:
944 g_value_set_boolean(value
,
945 purple_account_get_remember_password(account
));
947 case PROP_CHECK_MAIL
:
948 g_value_set_boolean(value
, purple_account_get_check_mail(account
));
951 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj
, param_id
, pspec
);
957 purple_account_init(PurpleAccount
*account
)
959 PurpleAccountPrivate
*priv
= purple_account_get_instance_private(account
);
961 priv
->settings
= g_hash_table_new_full(g_str_hash
, g_str_equal
,
962 g_free
, delete_setting
);
963 priv
->ui_settings
= g_hash_table_new_full(g_str_hash
, g_str_equal
,
964 g_free
, (GDestroyNotify
)g_hash_table_destroy
);
965 priv
->system_log
= NULL
;
967 priv
->privacy_type
= PURPLE_ACCOUNT_PRIVACY_ALLOW_ALL
;
971 purple_account_constructed(GObject
*object
)
973 PurpleAccount
*account
= PURPLE_ACCOUNT(object
);
974 PurpleAccountPrivate
*priv
= purple_account_get_instance_private(account
);
975 gchar
*username
, *protocol_id
;
976 PurpleProtocol
*protocol
= NULL
;
977 PurpleStatusType
*status_type
;
979 G_OBJECT_CLASS(purple_account_parent_class
)->constructed(object
);
982 "username", &username
,
983 "protocol-id", &protocol_id
,
986 purple_signal_emit(purple_accounts_get_handle(), "account-created",
989 protocol
= purple_protocols_find(protocol_id
);
990 if (protocol
== NULL
) {
996 purple_account_set_status_types(account
,
997 purple_protocol_class_status_types(protocol
, account
));
999 priv
->presence
= PURPLE_PRESENCE(purple_account_presence_new(account
));
1001 status_type
= purple_account_get_status_type_with_primitive(account
,
1002 PURPLE_STATUS_AVAILABLE
);
1003 if (status_type
!= NULL
)
1004 purple_presence_set_status_active(priv
->presence
,
1005 purple_status_type_get_id(status_type
),
1008 purple_presence_set_status_active(priv
->presence
,
1013 g_free(protocol_id
);
1017 purple_account_dispose(GObject
*object
)
1019 PurpleAccount
*account
= PURPLE_ACCOUNT(object
);
1020 PurpleAccountPrivate
*priv
= purple_account_get_instance_private(account
);
1022 if (!purple_account_is_disconnected(account
))
1023 purple_account_disconnect(account
);
1025 if (priv
->presence
) {
1026 g_object_unref(priv
->presence
);
1027 priv
->presence
= NULL
;
1030 G_OBJECT_CLASS(purple_account_parent_class
)->dispose(object
);
1034 purple_account_finalize(GObject
*object
)
1037 PurpleAccount
*account
= PURPLE_ACCOUNT(object
);
1038 PurpleAccountPrivate
*priv
= purple_account_get_instance_private(account
);
1040 purple_debug_info("account", "Destroying account %p\n", account
);
1041 purple_signal_emit(purple_accounts_get_handle(), "account-destroying",
1044 for (l
= purple_conversations_get_all(); l
!= NULL
; l
= l
->next
)
1046 PurpleConversation
*conv
= (PurpleConversation
*)l
->data
;
1048 if (purple_conversation_get_account(conv
) == account
)
1049 purple_conversation_set_account(conv
, NULL
);
1052 purple_account_set_status_types(account
, NULL
);
1054 if (priv
->proxy_info
)
1055 purple_proxy_info_destroy(priv
->proxy_info
);
1057 if(priv
->system_log
)
1058 purple_log_free(priv
->system_log
);
1060 if (priv
->current_error
) {
1061 g_free(priv
->current_error
->description
);
1062 g_free(priv
->current_error
);
1065 g_free(priv
->username
);
1066 g_free(priv
->alias
);
1067 purple_str_wipe(priv
->password
);
1068 g_free(priv
->user_info
);
1069 g_free(priv
->buddy_icon_path
);
1070 g_free(priv
->protocol_id
);
1072 g_hash_table_destroy(priv
->settings
);
1073 g_hash_table_destroy(priv
->ui_settings
);
1075 g_slist_free_full(priv
->deny
, g_free
);
1076 g_slist_free_full(priv
->permit
, g_free
);
1078 G_OBJECT_CLASS(purple_account_parent_class
)->finalize(object
);
1082 purple_account_class_init(PurpleAccountClass
*klass
)
1084 GObjectClass
*obj_class
= G_OBJECT_CLASS(klass
);
1086 obj_class
->dispose
= purple_account_dispose
;
1087 obj_class
->finalize
= purple_account_finalize
;
1088 obj_class
->constructed
= purple_account_constructed
;
1090 /* Setup properties */
1091 obj_class
->get_property
= purple_account_get_property
;
1092 obj_class
->set_property
= purple_account_set_property
;
1094 properties
[PROP_USERNAME
] = g_param_spec_string("username", "Username",
1095 "The username for the account.", NULL
,
1096 G_PARAM_READWRITE
| G_PARAM_CONSTRUCT
| G_PARAM_STATIC_STRINGS
);
1098 properties
[PROP_PRIVATE_ALIAS
] = g_param_spec_string("private-alias",
1100 "The private alias for the account.", NULL
,
1101 G_PARAM_READWRITE
| G_PARAM_STATIC_STRINGS
);
1103 properties
[PROP_USER_INFO
] = g_param_spec_string("user-info",
1105 "Detailed user information for the account.", NULL
,
1106 G_PARAM_READWRITE
| G_PARAM_STATIC_STRINGS
);
1108 properties
[PROP_BUDDY_ICON_PATH
] = g_param_spec_string("buddy-icon-path",
1110 "Path to the buddyicon for the account.", NULL
,
1111 G_PARAM_READWRITE
| G_PARAM_STATIC_STRINGS
);
1113 properties
[PROP_ENABLED
] = g_param_spec_boolean("enabled", "Enabled",
1114 "Whether the account is enabled or not.", FALSE
,
1115 G_PARAM_READWRITE
| G_PARAM_STATIC_STRINGS
);
1117 properties
[PROP_REMEMBER_PASSWORD
] = g_param_spec_boolean(
1118 "remember-password", "Remember password",
1119 "Whether to remember and store the password for this account.",
1120 FALSE
, G_PARAM_READWRITE
| G_PARAM_STATIC_STRINGS
);
1122 properties
[PROP_CHECK_MAIL
] = g_param_spec_boolean("check-mail",
1124 "Whether to check mails for this account.", FALSE
,
1125 G_PARAM_READWRITE
| G_PARAM_STATIC_STRINGS
);
1127 properties
[PROP_CONNECTION
] = g_param_spec_object("connection",
1129 "The connection for the account.", PURPLE_TYPE_CONNECTION
,
1130 G_PARAM_READWRITE
| G_PARAM_STATIC_STRINGS
);
1132 properties
[PROP_PROTOCOL_ID
] = g_param_spec_string("protocol-id",
1134 "ID of the protocol that is responsible for the account.", NULL
,
1135 G_PARAM_READWRITE
| G_PARAM_CONSTRUCT_ONLY
|
1136 G_PARAM_STATIC_STRINGS
);
1138 g_object_class_install_properties(obj_class
, PROP_LAST
, properties
);
1141 /******************************************************************************
1143 *****************************************************************************/
1145 purple_account_new(const char *username
, const char *protocol_id
)
1147 PurpleAccount
*account
;
1149 g_return_val_if_fail(username
!= NULL
, NULL
);
1150 g_return_val_if_fail(protocol_id
!= NULL
, NULL
);
1152 account
= purple_accounts_find(username
, protocol_id
);
1154 if (account
!= NULL
)
1157 account
= g_object_new(PURPLE_TYPE_ACCOUNT
,
1158 "username", username
,
1159 "protocol-id", protocol_id
,
1166 purple_account_connect(PurpleAccount
*account
)
1168 const char *username
;
1169 PurpleProtocol
*protocol
;
1170 PurpleAccountPrivate
*priv
;
1172 g_return_if_fail(PURPLE_IS_ACCOUNT(account
));
1174 username
= purple_account_get_username(account
);
1176 if (!purple_account_get_enabled(account
, purple_core_get_ui())) {
1177 purple_debug_info("account",
1178 "Account %s not enabled, not connecting.\n",
1183 protocol
= purple_protocols_find(purple_account_get_protocol_id(account
));
1184 if (protocol
== NULL
) {
1187 message
= g_strdup_printf(_("Missing protocol for %s"), username
);
1188 purple_notify_error(account
, _("Connection Error"), message
,
1189 NULL
, purple_request_cpar_from_account(account
));
1194 priv
= purple_account_get_instance_private(account
);
1196 purple_debug_info("account", "Connecting to account %s.\n", username
);
1198 if (priv
->password
!= NULL
) {
1199 purple_account_connect_got_password_cb(account
,
1200 priv
->password
, NULL
, protocol
);
1202 purple_keyring_get_password(account
,
1203 purple_account_connect_got_password_cb
, protocol
);
1208 purple_account_set_register_callback(PurpleAccount
*account
, PurpleAccountRegistrationCb cb
, void *user_data
)
1210 PurpleAccountPrivate
*priv
;
1212 g_return_if_fail(PURPLE_IS_ACCOUNT(account
));
1214 priv
= purple_account_get_instance_private(account
);
1216 priv
->registration_cb
= cb
;
1217 priv
->registration_cb_user_data
= user_data
;
1221 purple_account_register_completed(PurpleAccount
*account
, gboolean succeeded
)
1223 struct register_completed_closure
*closure
;
1225 g_return_if_fail(PURPLE_IS_ACCOUNT(account
));
1227 closure
= g_new0(struct register_completed_closure
, 1);
1228 closure
->account
= g_object_ref(account
);
1229 closure
->succeeded
= succeeded
;
1231 g_timeout_add(0, purple_account_register_completed_cb
, closure
);
1235 purple_account_unregister(PurpleAccount
*account
, PurpleAccountUnregistrationCb cb
, void *user_data
)
1237 PurpleCallbackBundle
*cbb
;
1239 g_return_if_fail(PURPLE_IS_ACCOUNT(account
));
1241 purple_debug_info("account", "Unregistering account %s\n",
1242 purple_account_get_username(account
));
1244 cbb
= g_new0(PurpleCallbackBundle
, 1);
1245 cbb
->cb
= PURPLE_CALLBACK(cb
);
1246 cbb
->data
= user_data
;
1248 purple_keyring_get_password(account
,
1249 purple_account_unregister_got_password_cb
, cbb
);
1253 purple_account_disconnect(PurpleAccount
*account
)
1255 PurpleConnection
*gc
;
1256 PurpleAccountPrivate
*priv
;
1257 const char *username
;
1259 g_return_if_fail(PURPLE_IS_ACCOUNT(account
));
1260 g_return_if_fail(!purple_account_is_disconnecting(account
));
1261 g_return_if_fail(!purple_account_is_disconnected(account
));
1263 priv
= purple_account_get_instance_private(account
);
1265 username
= purple_account_get_username(account
);
1266 purple_debug_info("account", "Disconnecting account %s (%p)\n",
1267 username
? username
: "(null)", account
);
1269 priv
->disconnecting
= TRUE
;
1271 gc
= purple_account_get_connection(account
);
1273 purple_account_set_connection(account
, NULL
);
1275 priv
->disconnecting
= FALSE
;
1279 purple_account_is_disconnecting(PurpleAccount
*account
)
1281 PurpleAccountPrivate
*priv
;
1283 g_return_val_if_fail(PURPLE_IS_ACCOUNT(account
), TRUE
);
1285 priv
= purple_account_get_instance_private(account
);
1286 return priv
->disconnecting
;
1290 purple_account_notify_added(PurpleAccount
*account
, const char *remote_user
,
1291 const char *id
, const char *alias
,
1292 const char *message
)
1294 PurpleAccountUiOps
*ui_ops
;
1296 g_return_if_fail(PURPLE_IS_ACCOUNT(account
));
1297 g_return_if_fail(remote_user
!= NULL
);
1299 ui_ops
= purple_accounts_get_ui_ops();
1301 if (ui_ops
!= NULL
&& ui_ops
->notify_added
!= NULL
)
1302 ui_ops
->notify_added(account
, remote_user
, id
, alias
, message
);
1306 purple_account_request_add(PurpleAccount
*account
, const char *remote_user
,
1307 const char *id
, const char *alias
,
1308 const char *message
)
1310 PurpleAccountUiOps
*ui_ops
;
1312 g_return_if_fail(PURPLE_IS_ACCOUNT(account
));
1313 g_return_if_fail(remote_user
!= NULL
);
1315 ui_ops
= purple_accounts_get_ui_ops();
1317 if (ui_ops
!= NULL
&& ui_ops
->request_add
!= NULL
)
1318 ui_ops
->request_add(account
, remote_user
, id
, alias
, message
);
1322 purple_account_request_authorization(PurpleAccount
*account
, const char *remote_user
,
1323 const char *id
, const char *alias
, const char *message
, gboolean on_list
,
1324 PurpleAccountRequestAuthorizationCb auth_cb
, PurpleAccountRequestAuthorizationCb deny_cb
, void *user_data
)
1326 PurpleAccountUiOps
*ui_ops
;
1327 PurpleAccountRequestInfo
*info
;
1329 char *response
= NULL
;
1331 g_return_val_if_fail(PURPLE_IS_ACCOUNT(account
), NULL
);
1332 g_return_val_if_fail(remote_user
!= NULL
, NULL
);
1334 ui_ops
= purple_accounts_get_ui_ops();
1336 plugin_return
= GPOINTER_TO_INT(
1337 purple_signal_emit_return_1(
1338 purple_accounts_get_handle(),
1339 "account-authorization-requested",
1340 account
, remote_user
, message
, &response
1343 switch (plugin_return
)
1345 case PURPLE_ACCOUNT_RESPONSE_IGNORE
:
1348 case PURPLE_ACCOUNT_RESPONSE_ACCEPT
:
1349 if (auth_cb
!= NULL
)
1350 auth_cb(response
, user_data
);
1353 case PURPLE_ACCOUNT_RESPONSE_DENY
:
1354 if (deny_cb
!= NULL
)
1355 deny_cb(response
, user_data
);
1362 if (ui_ops
!= NULL
&& ui_ops
->request_authorize
!= NULL
) {
1363 info
= g_new0(PurpleAccountRequestInfo
, 1);
1364 info
->type
= PURPLE_ACCOUNT_REQUEST_AUTHORIZATION
;
1365 info
->account
= account
;
1366 info
->auth_cb
= auth_cb
;
1367 info
->deny_cb
= deny_cb
;
1368 info
->userdata
= user_data
;
1369 info
->user
= g_strdup(remote_user
);
1370 info
->ref
= 2; /* We hold an extra ref to make sure info remains valid
1371 if any of the callbacks are called synchronously. We
1372 unref it after the function call */
1374 info
->ui_handle
= ui_ops
->request_authorize(account
, remote_user
, id
, alias
, message
,
1375 on_list
, request_auth_cb
, request_deny_cb
, info
);
1377 info
= purple_account_request_info_unref(info
);
1379 handles
= g_list_append(handles
, info
);
1380 return info
->ui_handle
;
1388 purple_account_request_close_with_account(PurpleAccount
*account
)
1392 g_return_if_fail(PURPLE_IS_ACCOUNT(account
));
1394 for (l
= handles
; l
!= NULL
; l
= l_next
) {
1395 PurpleAccountRequestInfo
*info
= l
->data
;
1399 if (info
->account
== account
) {
1400 handles
= g_list_remove(handles
, info
);
1401 purple_account_request_close_info(info
);
1407 purple_account_request_close(void *ui_handle
)
1411 g_return_if_fail(ui_handle
!= NULL
);
1413 for (l
= handles
; l
!= NULL
; l
= l_next
) {
1414 PurpleAccountRequestInfo
*info
= l
->data
;
1418 if (info
->ui_handle
== ui_handle
) {
1419 handles
= g_list_remove(handles
, info
);
1420 purple_account_request_close_info(info
);
1426 purple_account_request_password(PurpleAccount
*account
, GCallback ok_cb
,
1427 GCallback cancel_cb
, void *user_data
)
1430 const gchar
*username
;
1431 PurpleRequestFieldGroup
*group
;
1432 PurpleRequestField
*field
;
1433 PurpleRequestFields
*fields
;
1435 /* Close any previous password request windows */
1436 purple_request_close_with_handle(account
);
1438 username
= purple_account_get_username(account
);
1439 primary
= g_strdup_printf(_("Enter password for %s (%s)"), username
,
1440 purple_account_get_protocol_name(account
));
1442 fields
= purple_request_fields_new();
1443 group
= purple_request_field_group_new(NULL
);
1444 purple_request_fields_add_group(fields
, group
);
1446 field
= purple_request_field_string_new("password", _("Enter Password"), NULL
, FALSE
);
1447 purple_request_field_string_set_masked(field
, TRUE
);
1448 purple_request_field_set_required(field
, TRUE
);
1449 purple_request_field_group_add_field(group
, field
);
1451 field
= purple_request_field_bool_new("remember", _("Save password"), FALSE
);
1452 purple_request_field_group_add_field(group
, field
);
1454 purple_request_fields(account
, NULL
, primary
, NULL
, fields
, _("OK"),
1455 ok_cb
, _("Cancel"), cancel_cb
,
1456 purple_request_cpar_from_account(account
), user_data
);
1461 purple_account_request_change_password(PurpleAccount
*account
)
1463 PurpleRequestFields
*fields
;
1464 PurpleRequestFieldGroup
*group
;
1465 PurpleRequestField
*field
;
1466 PurpleConnection
*gc
;
1467 PurpleProtocol
*protocol
= NULL
;
1470 g_return_if_fail(PURPLE_IS_ACCOUNT(account
));
1471 g_return_if_fail(purple_account_is_connected(account
));
1473 gc
= purple_account_get_connection(account
);
1475 protocol
= purple_connection_get_protocol(gc
);
1477 fields
= purple_request_fields_new();
1479 group
= purple_request_field_group_new(NULL
);
1480 purple_request_fields_add_group(fields
, group
);
1482 field
= purple_request_field_string_new("password", _("Original password"),
1484 purple_request_field_string_set_masked(field
, TRUE
);
1485 if (!protocol
|| !(purple_protocol_get_options(protocol
) & OPT_PROTO_PASSWORD_OPTIONAL
))
1486 purple_request_field_set_required(field
, TRUE
);
1487 purple_request_field_group_add_field(group
, field
);
1489 field
= purple_request_field_string_new("new_password_1",
1492 purple_request_field_string_set_masked(field
, TRUE
);
1493 if (!protocol
|| !(purple_protocol_get_options(protocol
) & OPT_PROTO_PASSWORD_OPTIONAL
))
1494 purple_request_field_set_required(field
, TRUE
);
1495 purple_request_field_group_add_field(group
, field
);
1497 field
= purple_request_field_string_new("new_password_2",
1498 _("New password (again)"),
1500 purple_request_field_string_set_masked(field
, TRUE
);
1501 if (!protocol
|| !(purple_protocol_get_options(protocol
) & OPT_PROTO_PASSWORD_OPTIONAL
))
1502 purple_request_field_set_required(field
, TRUE
);
1503 purple_request_field_group_add_field(group
, field
);
1505 g_snprintf(primary
, sizeof(primary
), _("Change password for %s"),
1506 purple_account_get_username(account
));
1508 /* I'm sticking this somewhere in the code: bologna */
1510 purple_request_fields(purple_account_get_connection(account
), NULL
,
1511 primary
, _("Please enter your current password and your new "
1512 "password."), fields
, _("OK"), G_CALLBACK(change_password_cb
),
1513 _("Cancel"), NULL
, purple_request_cpar_from_account(account
),
1518 purple_account_request_change_user_info(PurpleAccount
*account
)
1520 PurpleConnection
*gc
;
1523 g_return_if_fail(PURPLE_IS_ACCOUNT(account
));
1524 g_return_if_fail(purple_account_is_connected(account
));
1526 gc
= purple_account_get_connection(account
);
1528 g_snprintf(primary
, sizeof(primary
),
1529 _("Change user information for %s"),
1530 purple_account_get_username(account
));
1532 purple_request_input(gc
, _("Set User Info"), primary
, NULL
,
1533 purple_account_get_user_info(account
),
1534 TRUE
, FALSE
, ((gc
!= NULL
) &&
1535 (purple_connection_get_flags(gc
) & PURPLE_CONNECTION_FLAG_HTML
) ? "html" : NULL
),
1536 _("Save"), G_CALLBACK(set_user_info_cb
),
1538 purple_request_cpar_from_account(account
),
1543 purple_account_set_username(PurpleAccount
*account
, const char *username
)
1545 PurpleAccountPrivate
*priv
;
1547 g_return_if_fail(PURPLE_IS_ACCOUNT(account
));
1549 priv
= purple_account_get_instance_private(account
);
1551 g_free(priv
->username
);
1552 priv
->username
= g_strdup(username
);
1554 g_object_notify_by_pspec(G_OBJECT(account
), properties
[PROP_USERNAME
]);
1556 purple_accounts_schedule_save();
1558 /* if the name changes, we should re-write the buddy list
1559 * to disk with the new name */
1560 purple_blist_save_account(purple_blist_get_default(), account
);
1564 purple_account_set_password(PurpleAccount
*account
, const gchar
*password
,
1565 PurpleKeyringSaveCallback cb
, gpointer data
)
1567 PurpleAccountPrivate
*priv
;
1569 g_return_if_fail(PURPLE_IS_ACCOUNT(account
));
1571 priv
= purple_account_get_instance_private(account
);
1573 purple_str_wipe(priv
->password
);
1574 priv
->password
= g_strdup(password
);
1576 purple_accounts_schedule_save();
1578 if (!purple_account_get_remember_password(account
)) {
1579 purple_debug_info("account",
1580 "Password for %s set, not sent to keyring.\n",
1581 purple_account_get_username(account
));
1584 cb(account
, NULL
, data
);
1586 purple_keyring_set_password(account
, password
, cb
, data
);
1591 purple_account_set_private_alias(PurpleAccount
*account
, const char *alias
)
1593 PurpleAccountPrivate
*priv
;
1595 g_return_if_fail(PURPLE_IS_ACCOUNT(account
));
1597 priv
= purple_account_get_instance_private(account
);
1600 * Do nothing if alias and priv->alias are both NULL. Or if
1601 * they're the exact same string.
1603 if (alias
== priv
->alias
)
1606 if ((!alias
&& priv
->alias
) || (alias
&& !priv
->alias
) ||
1607 g_utf8_collate(priv
->alias
, alias
))
1609 char *old
= priv
->alias
;
1611 priv
->alias
= g_strdup(alias
);
1612 g_object_notify_by_pspec(G_OBJECT(account
),
1613 properties
[PROP_PRIVATE_ALIAS
]);
1614 purple_signal_emit(purple_accounts_get_handle(), "account-alias-changed",
1618 purple_accounts_schedule_save();
1623 purple_account_set_user_info(PurpleAccount
*account
, const char *user_info
)
1625 PurpleAccountPrivate
*priv
;
1627 g_return_if_fail(PURPLE_IS_ACCOUNT(account
));
1629 priv
= purple_account_get_instance_private(account
);
1631 g_free(priv
->user_info
);
1632 priv
->user_info
= g_strdup(user_info
);
1634 g_object_notify_by_pspec(G_OBJECT(account
), properties
[PROP_USER_INFO
]);
1636 purple_accounts_schedule_save();
1639 void purple_account_set_buddy_icon_path(PurpleAccount
*account
, const char *path
)
1641 PurpleAccountPrivate
*priv
;
1643 g_return_if_fail(PURPLE_IS_ACCOUNT(account
));
1645 priv
= purple_account_get_instance_private(account
);
1647 g_free(priv
->buddy_icon_path
);
1648 priv
->buddy_icon_path
= g_strdup(path
);
1650 g_object_notify_by_pspec(G_OBJECT(account
),
1651 properties
[PROP_BUDDY_ICON_PATH
]);
1653 purple_accounts_schedule_save();
1657 purple_account_set_protocol_id(PurpleAccount
*account
, const char *protocol_id
)
1659 PurpleAccountPrivate
*priv
;
1661 g_return_if_fail(PURPLE_IS_ACCOUNT(account
));
1662 g_return_if_fail(protocol_id
!= NULL
);
1664 priv
= purple_account_get_instance_private(account
);
1666 g_free(priv
->protocol_id
);
1667 priv
->protocol_id
= g_strdup(protocol_id
);
1669 g_object_notify_by_pspec(G_OBJECT(account
), properties
[PROP_PROTOCOL_ID
]);
1671 purple_accounts_schedule_save();
1675 purple_account_set_connection(PurpleAccount
*account
, PurpleConnection
*gc
)
1677 PurpleAccountPrivate
*priv
;
1679 g_return_if_fail(PURPLE_IS_ACCOUNT(account
));
1681 priv
= purple_account_get_instance_private(account
);
1684 g_object_notify_by_pspec(G_OBJECT(account
), properties
[PROP_CONNECTION
]);
1688 purple_account_set_remember_password(PurpleAccount
*account
, gboolean value
)
1690 PurpleAccountPrivate
*priv
;
1692 g_return_if_fail(PURPLE_IS_ACCOUNT(account
));
1694 priv
= purple_account_get_instance_private(account
);
1695 priv
->remember_pass
= value
;
1697 g_object_notify_by_pspec(G_OBJECT(account
),
1698 properties
[PROP_REMEMBER_PASSWORD
]);
1700 purple_accounts_schedule_save();
1704 purple_account_set_check_mail(PurpleAccount
*account
, gboolean value
)
1706 g_return_if_fail(PURPLE_IS_ACCOUNT(account
));
1708 purple_account_set_bool(account
, "check-mail", value
);
1710 g_object_notify_by_pspec(G_OBJECT(account
), properties
[PROP_CHECK_MAIL
]);
1714 purple_account_set_enabled(PurpleAccount
*account
, const char *ui
,
1717 PurpleConnection
*gc
;
1718 PurpleAccountPrivate
*priv
;
1719 gboolean was_enabled
= FALSE
;
1721 g_return_if_fail(PURPLE_IS_ACCOUNT(account
));
1722 g_return_if_fail(ui
!= NULL
);
1724 was_enabled
= purple_account_get_enabled(account
, ui
);
1726 purple_account_set_ui_bool(account
, ui
, "auto-login", value
);
1727 gc
= purple_account_get_connection(account
);
1729 if(was_enabled
&& !value
)
1730 purple_signal_emit(purple_accounts_get_handle(), "account-disabled", account
);
1731 else if(!was_enabled
&& value
)
1732 purple_signal_emit(purple_accounts_get_handle(), "account-enabled", account
);
1734 g_object_notify_by_pspec(G_OBJECT(account
), properties
[PROP_ENABLED
]);
1736 if ((gc
!= NULL
) && (_purple_connection_wants_to_die(gc
)))
1739 priv
= purple_account_get_instance_private(account
);
1741 if (value
&& purple_presence_is_online(priv
->presence
))
1742 purple_account_connect(account
);
1743 else if (!value
&& !purple_account_is_disconnected(account
))
1744 purple_account_disconnect(account
);
1748 purple_account_set_proxy_info(PurpleAccount
*account
, PurpleProxyInfo
*info
)
1750 PurpleAccountPrivate
*priv
;
1752 g_return_if_fail(PURPLE_IS_ACCOUNT(account
));
1754 priv
= purple_account_get_instance_private(account
);
1756 if (priv
->proxy_info
!= NULL
)
1757 purple_proxy_info_destroy(priv
->proxy_info
);
1759 priv
->proxy_info
= info
;
1761 purple_accounts_schedule_save();
1765 purple_account_set_privacy_type(PurpleAccount
*account
, PurpleAccountPrivacyType privacy_type
)
1767 PurpleAccountPrivate
*priv
;
1769 g_return_if_fail(PURPLE_IS_ACCOUNT(account
));
1771 priv
= purple_account_get_instance_private(account
);
1772 priv
->privacy_type
= privacy_type
;
1776 purple_account_set_status_types(PurpleAccount
*account
, GList
*status_types
)
1778 PurpleAccountPrivate
*priv
;
1780 g_return_if_fail(PURPLE_IS_ACCOUNT(account
));
1782 priv
= purple_account_get_instance_private(account
);
1784 /* Out with the old... */
1785 g_list_free_full(priv
->status_types
,
1786 (GDestroyNotify
)purple_status_type_destroy
);
1788 /* In with the new... */
1789 priv
->status_types
= status_types
;
1793 purple_account_set_status(PurpleAccount
*account
, const char *status_id
,
1794 gboolean active
, ...)
1796 GList
*attrs
= NULL
;
1801 va_start(args
, active
);
1802 while ((id
= va_arg(args
, const char *)) != NULL
)
1804 attrs
= g_list_append(attrs
, (char *)id
);
1805 data
= va_arg(args
, void *);
1806 attrs
= g_list_append(attrs
, data
);
1808 purple_account_set_status_list(account
, status_id
, active
, attrs
);
1814 purple_account_set_status_list(PurpleAccount
*account
, const char *status_id
,
1815 gboolean active
, GList
*attrs
)
1817 PurpleStatus
*status
;
1819 g_return_if_fail(PURPLE_IS_ACCOUNT(account
));
1820 g_return_if_fail(status_id
!= NULL
);
1822 status
= purple_account_get_status(account
, status_id
);
1825 purple_debug_error("account",
1826 "Invalid status ID '%s' for account %s (%s)\n",
1827 status_id
, purple_account_get_username(account
),
1828 purple_account_get_protocol_id(account
));
1832 if (active
|| purple_status_is_independent(status
))
1833 purple_status_set_active_with_attrs_list(status
, active
, attrs
);
1836 * Our current statuses are saved to accounts.xml (so that when we
1837 * reconnect, we go back to the previous status).
1839 purple_accounts_schedule_save();
1843 purple_account_set_public_alias(PurpleAccount
*account
,
1844 const char *alias
, PurpleSetPublicAliasSuccessCallback success_cb
,
1845 PurpleSetPublicAliasFailureCallback failure_cb
)
1847 PurpleConnection
*gc
;
1848 PurpleProtocol
*protocol
= NULL
;
1850 g_return_if_fail(PURPLE_IS_ACCOUNT(account
));
1851 g_return_if_fail(purple_account_is_connected(account
));
1853 gc
= purple_account_get_connection(account
);
1854 protocol
= purple_connection_get_protocol(gc
);
1856 if (PURPLE_PROTOCOL_IMPLEMENTS(protocol
, SERVER
, set_public_alias
))
1857 purple_protocol_server_iface_set_public_alias(protocol
, gc
, alias
, success_cb
, failure_cb
);
1858 else if (failure_cb
) {
1859 struct public_alias_closure
*closure
=
1860 g_new0(struct public_alias_closure
, 1);
1861 closure
->account
= g_object_ref(account
);
1862 closure
->failure_cb
= failure_cb
;
1863 g_timeout_add(0, set_public_alias_unsupported
, closure
);
1868 purple_account_get_public_alias(PurpleAccount
*account
,
1869 PurpleGetPublicAliasSuccessCallback success_cb
,
1870 PurpleGetPublicAliasFailureCallback failure_cb
)
1872 PurpleConnection
*gc
;
1873 PurpleProtocol
*protocol
= NULL
;
1875 g_return_if_fail(PURPLE_IS_ACCOUNT(account
));
1876 g_return_if_fail(purple_account_is_connected(account
));
1878 gc
= purple_account_get_connection(account
);
1879 protocol
= purple_connection_get_protocol(gc
);
1881 if (PURPLE_PROTOCOL_IMPLEMENTS(protocol
, SERVER
, get_public_alias
))
1882 purple_protocol_server_iface_get_public_alias(protocol
, gc
, success_cb
, failure_cb
);
1883 else if (failure_cb
) {
1884 struct public_alias_closure
*closure
=
1885 g_new0(struct public_alias_closure
, 1);
1886 closure
->account
= g_object_ref(account
);
1887 closure
->failure_cb
= failure_cb
;
1888 g_timeout_add(0, get_public_alias_unsupported
, closure
);
1893 purple_account_get_silence_suppression(PurpleAccount
*account
)
1895 return purple_account_get_bool(account
, "silence-suppression", FALSE
);
1899 purple_account_set_silence_suppression(PurpleAccount
*account
, gboolean value
)
1901 g_return_if_fail(PURPLE_IS_ACCOUNT(account
));
1903 purple_account_set_bool(account
, "silence-suppression", value
);
1907 purple_account_clear_settings(PurpleAccount
*account
)
1909 PurpleAccountPrivate
*priv
;
1911 g_return_if_fail(PURPLE_IS_ACCOUNT(account
));
1913 priv
= purple_account_get_instance_private(account
);
1914 g_hash_table_destroy(priv
->settings
);
1916 priv
->settings
= g_hash_table_new_full(g_str_hash
, g_str_equal
,
1917 g_free
, delete_setting
);
1921 purple_account_remove_setting(PurpleAccount
*account
, const char *setting
)
1923 PurpleAccountPrivate
*priv
;
1925 g_return_if_fail(PURPLE_IS_ACCOUNT(account
));
1926 g_return_if_fail(setting
!= NULL
);
1928 priv
= purple_account_get_instance_private(account
);
1930 g_hash_table_remove(priv
->settings
, setting
);
1934 purple_account_set_int(PurpleAccount
*account
, const char *name
, int value
)
1936 PurpleAccountSetting
*setting
;
1937 PurpleAccountPrivate
*priv
;
1939 g_return_if_fail(PURPLE_IS_ACCOUNT(account
));
1940 g_return_if_fail(name
!= NULL
);
1942 priv
= purple_account_get_instance_private(account
);
1944 setting
= g_new0(PurpleAccountSetting
, 1);
1946 g_value_init(&setting
->value
, G_TYPE_INT
);
1947 g_value_set_int(&setting
->value
, value
);
1949 g_hash_table_insert(priv
->settings
, g_strdup(name
), setting
);
1951 purple_accounts_schedule_save();
1955 purple_account_set_string(PurpleAccount
*account
, const char *name
,
1958 PurpleAccountSetting
*setting
;
1959 PurpleAccountPrivate
*priv
;
1961 g_return_if_fail(PURPLE_IS_ACCOUNT(account
));
1962 g_return_if_fail(name
!= NULL
);
1964 priv
= purple_account_get_instance_private(account
);
1966 setting
= g_new0(PurpleAccountSetting
, 1);
1968 g_value_init(&setting
->value
, G_TYPE_STRING
);
1969 g_value_set_string(&setting
->value
, value
);
1971 g_hash_table_insert(priv
->settings
, g_strdup(name
), setting
);
1973 purple_accounts_schedule_save();
1977 purple_account_set_bool(PurpleAccount
*account
, const char *name
, gboolean value
)
1979 PurpleAccountSetting
*setting
;
1980 PurpleAccountPrivate
*priv
;
1982 g_return_if_fail(PURPLE_IS_ACCOUNT(account
));
1983 g_return_if_fail(name
!= NULL
);
1985 priv
= purple_account_get_instance_private(account
);
1987 setting
= g_new0(PurpleAccountSetting
, 1);
1989 g_value_init(&setting
->value
, G_TYPE_BOOLEAN
);
1990 g_value_set_boolean(&setting
->value
, value
);
1992 g_hash_table_insert(priv
->settings
, g_strdup(name
), setting
);
1994 purple_accounts_schedule_save();
1998 purple_account_set_ui_int(PurpleAccount
*account
, const char *ui
,
1999 const char *name
, int value
)
2001 PurpleAccountSetting
*setting
;
2004 g_return_if_fail(PURPLE_IS_ACCOUNT(account
));
2005 g_return_if_fail(ui
!= NULL
);
2006 g_return_if_fail(name
!= NULL
);
2008 setting
= g_new0(PurpleAccountSetting
, 1);
2010 setting
->ui
= g_strdup(ui
);
2011 g_value_init(&setting
->value
, G_TYPE_INT
);
2012 g_value_set_int(&setting
->value
, value
);
2014 table
= get_ui_settings_table(account
, ui
);
2016 g_hash_table_insert(table
, g_strdup(name
), setting
);
2018 purple_accounts_schedule_save();
2022 purple_account_set_ui_string(PurpleAccount
*account
, const char *ui
,
2023 const char *name
, const char *value
)
2025 PurpleAccountSetting
*setting
;
2028 g_return_if_fail(PURPLE_IS_ACCOUNT(account
));
2029 g_return_if_fail(ui
!= NULL
);
2030 g_return_if_fail(name
!= NULL
);
2032 setting
= g_new0(PurpleAccountSetting
, 1);
2034 setting
->ui
= g_strdup(ui
);
2035 g_value_init(&setting
->value
, G_TYPE_STRING
);
2036 g_value_set_string(&setting
->value
, value
);
2038 table
= get_ui_settings_table(account
, ui
);
2040 g_hash_table_insert(table
, g_strdup(name
), setting
);
2042 purple_accounts_schedule_save();
2046 purple_account_set_ui_bool(PurpleAccount
*account
, const char *ui
,
2047 const char *name
, gboolean value
)
2049 PurpleAccountSetting
*setting
;
2052 g_return_if_fail(PURPLE_IS_ACCOUNT(account
));
2053 g_return_if_fail(ui
!= NULL
);
2054 g_return_if_fail(name
!= NULL
);
2056 setting
= g_new0(PurpleAccountSetting
, 1);
2058 setting
->ui
= g_strdup(ui
);
2059 g_value_init(&setting
->value
, G_TYPE_BOOLEAN
);
2060 g_value_set_boolean(&setting
->value
, value
);
2062 table
= get_ui_settings_table(account
, ui
);
2064 g_hash_table_insert(table
, g_strdup(name
), setting
);
2066 purple_accounts_schedule_save();
2070 purple_account_is_connected(PurpleAccount
*account
)
2072 return (purple_account_get_state(account
) == PURPLE_CONNECTION_CONNECTED
);
2076 purple_account_is_connecting(PurpleAccount
*account
)
2078 return (purple_account_get_state(account
) == PURPLE_CONNECTION_CONNECTING
);
2082 purple_account_is_disconnected(PurpleAccount
*account
)
2084 return (purple_account_get_state(account
) == PURPLE_CONNECTION_DISCONNECTED
);
2088 purple_account_get_username(PurpleAccount
*account
)
2090 PurpleAccountPrivate
*priv
;
2092 g_return_val_if_fail(PURPLE_IS_ACCOUNT(account
), NULL
);
2094 priv
= purple_account_get_instance_private(account
);
2095 return priv
->username
;
2099 purple_account_get_password(PurpleAccount
*account
,
2100 PurpleKeyringReadCallback cb
, gpointer data
)
2102 PurpleAccountPrivate
*priv
;
2104 if (account
== NULL
) {
2105 cb(NULL
, NULL
, NULL
, data
);
2109 priv
= purple_account_get_instance_private(account
);
2111 if (priv
->password
!= NULL
) {
2112 purple_debug_info("account",
2113 "Reading password for account %s from cache.\n",
2114 purple_account_get_username(account
));
2115 cb(account
, priv
->password
, NULL
, data
);
2117 PurpleCallbackBundle
*cbb
= g_new0(PurpleCallbackBundle
, 1);
2118 cbb
->cb
= PURPLE_CALLBACK(cb
);
2121 purple_debug_info("account",
2122 "Reading password for account %s from async keyring.\n",
2123 purple_account_get_username(account
));
2124 purple_keyring_get_password(account
,
2125 purple_account_get_password_got
, cbb
);
2130 purple_account_get_private_alias(PurpleAccount
*account
)
2132 PurpleAccountPrivate
*priv
;
2134 g_return_val_if_fail(PURPLE_IS_ACCOUNT(account
), NULL
);
2136 priv
= purple_account_get_instance_private(account
);
2141 purple_account_get_user_info(PurpleAccount
*account
)
2143 PurpleAccountPrivate
*priv
;
2145 g_return_val_if_fail(PURPLE_IS_ACCOUNT(account
), NULL
);
2147 priv
= purple_account_get_instance_private(account
);
2148 return priv
->user_info
;
2152 purple_account_get_buddy_icon_path(PurpleAccount
*account
)
2154 PurpleAccountPrivate
*priv
;
2156 g_return_val_if_fail(PURPLE_IS_ACCOUNT(account
), NULL
);
2158 priv
= purple_account_get_instance_private(account
);
2159 return priv
->buddy_icon_path
;
2163 purple_account_get_protocol_id(PurpleAccount
*account
)
2165 PurpleAccountPrivate
*priv
;
2167 g_return_val_if_fail(PURPLE_IS_ACCOUNT(account
), NULL
);
2169 priv
= purple_account_get_instance_private(account
);
2170 return priv
->protocol_id
;
2174 purple_account_get_protocol_name(PurpleAccount
*account
)
2178 g_return_val_if_fail(PURPLE_IS_ACCOUNT(account
), NULL
);
2180 p
= purple_protocols_find(purple_account_get_protocol_id(account
));
2182 return (p
&& purple_protocol_get_name(p
) ?
2183 _(purple_protocol_get_name(p
)) : _("Unknown"));
2187 purple_account_get_connection(PurpleAccount
*account
)
2189 PurpleAccountPrivate
*priv
;
2191 g_return_val_if_fail(PURPLE_IS_ACCOUNT(account
), NULL
);
2193 priv
= purple_account_get_instance_private(account
);
2198 purple_account_get_name_for_display(PurpleAccount
*account
)
2200 PurpleBuddy
*self
= NULL
;
2201 PurpleConnection
*gc
= NULL
;
2202 const gchar
*name
= NULL
, *username
= NULL
, *displayname
= NULL
;
2204 name
= purple_account_get_private_alias(account
);
2210 username
= purple_account_get_username(account
);
2211 self
= purple_blist_find_buddy((PurpleAccount
*)account
, username
);
2214 const gchar
*calias
= purple_buddy_get_contact_alias(self
);
2216 /* We don't want to return the buddy name if the buddy/contact
2217 * doesn't have an alias set. */
2218 if (!purple_strequal(username
, calias
)) {
2223 gc
= purple_account_get_connection(account
);
2224 displayname
= purple_connection_get_display_name(gc
);
2234 purple_account_get_remember_password(PurpleAccount
*account
)
2236 PurpleAccountPrivate
*priv
;
2238 g_return_val_if_fail(PURPLE_IS_ACCOUNT(account
), FALSE
);
2240 priv
= purple_account_get_instance_private(account
);
2241 return priv
->remember_pass
;
2245 purple_account_get_check_mail(PurpleAccount
*account
)
2247 g_return_val_if_fail(PURPLE_IS_ACCOUNT(account
), FALSE
);
2249 return purple_account_get_bool(account
, "check-mail", FALSE
);
2253 purple_account_get_enabled(PurpleAccount
*account
, const char *ui
)
2255 g_return_val_if_fail(PURPLE_IS_ACCOUNT(account
), FALSE
);
2256 g_return_val_if_fail(ui
!= NULL
, FALSE
);
2258 return purple_account_get_ui_bool(account
, ui
, "auto-login", FALSE
);
2262 purple_account_get_proxy_info(PurpleAccount
*account
)
2264 PurpleAccountPrivate
*priv
;
2266 g_return_val_if_fail(PURPLE_IS_ACCOUNT(account
), NULL
);
2268 priv
= purple_account_get_instance_private(account
);
2269 return priv
->proxy_info
;
2272 PurpleAccountPrivacyType
2273 purple_account_get_privacy_type(PurpleAccount
*account
)
2275 PurpleAccountPrivate
*priv
;
2277 g_return_val_if_fail(PURPLE_IS_ACCOUNT(account
), PURPLE_ACCOUNT_PRIVACY_ALLOW_ALL
);
2279 priv
= purple_account_get_instance_private(account
);
2280 return priv
->privacy_type
;
2284 purple_account_privacy_permit_add(PurpleAccount
*account
, const char *who
,
2285 gboolean local_only
)
2289 PurpleAccountPrivate
*priv
;
2290 PurpleAccountUiOps
*ui_ops
= purple_accounts_get_ui_ops();
2292 g_return_val_if_fail(PURPLE_IS_ACCOUNT(account
), FALSE
);
2293 g_return_val_if_fail(who
!= NULL
, FALSE
);
2295 priv
= purple_account_get_instance_private(account
);
2296 name
= g_strdup(purple_normalize(account
, who
));
2298 if (g_slist_find_custom(priv
->permit
, name
, (GCompareFunc
)g_strcmp0
) != NULL
) {
2299 /* This buddy already exists, so bail out */
2304 priv
->permit
= g_slist_append(priv
->permit
, name
);
2306 if (!local_only
&& purple_account_is_connected(account
))
2307 purple_serv_add_permit(purple_account_get_connection(account
), who
);
2309 if (ui_ops
!= NULL
&& ui_ops
->permit_added
!= NULL
)
2310 ui_ops
->permit_added(account
, who
);
2312 purple_blist_save_account(purple_blist_get_default(), account
);
2314 /* This lets the UI know a buddy has had its privacy setting changed */
2315 buddy
= purple_blist_find_buddy(account
, name
);
2316 if (buddy
!= NULL
) {
2317 purple_signal_emit(purple_blist_get_handle(),
2318 "buddy-privacy-changed", buddy
);
2324 purple_account_privacy_permit_remove(PurpleAccount
*account
, const char *who
,
2325 gboolean local_only
)
2331 PurpleAccountPrivate
*priv
;
2332 PurpleAccountUiOps
*ui_ops
= purple_accounts_get_ui_ops();
2334 g_return_val_if_fail(PURPLE_IS_ACCOUNT(account
), FALSE
);
2335 g_return_val_if_fail(who
!= NULL
, FALSE
);
2337 priv
= purple_account_get_instance_private(account
);
2338 name
= purple_normalize(account
, who
);
2340 l
= g_slist_find_custom(priv
->permit
, name
, (GCompareFunc
)g_strcmp0
);
2342 /* We didn't find the buddy we were looking for, so bail out */
2345 /* We should not free l->data just yet. There can be occasions where
2346 * l->data == who. In such cases, freeing l->data here can cause crashes
2347 * later when who is used. */
2349 priv
->permit
= g_slist_delete_link(priv
->permit
, l
);
2351 if (!local_only
&& purple_account_is_connected(account
))
2352 purple_serv_rem_permit(purple_account_get_connection(account
), who
);
2354 if (ui_ops
!= NULL
&& ui_ops
->permit_removed
!= NULL
)
2355 ui_ops
->permit_removed(account
, who
);
2357 purple_blist_save_account(purple_blist_get_default(), account
);
2359 buddy
= purple_blist_find_buddy(account
, name
);
2360 if (buddy
!= NULL
) {
2361 purple_signal_emit(purple_blist_get_handle(),
2362 "buddy-privacy-changed", buddy
);
2369 purple_account_privacy_deny_add(PurpleAccount
*account
, const char *who
,
2370 gboolean local_only
)
2374 PurpleAccountPrivate
*priv
;
2375 PurpleAccountUiOps
*ui_ops
= purple_accounts_get_ui_ops();
2377 g_return_val_if_fail(PURPLE_IS_ACCOUNT(account
), FALSE
);
2378 g_return_val_if_fail(who
!= NULL
, FALSE
);
2380 priv
= purple_account_get_instance_private(account
);
2381 name
= g_strdup(purple_normalize(account
, who
));
2383 if (g_slist_find_custom(priv
->deny
, name
, (GCompareFunc
)g_strcmp0
) != NULL
) {
2384 /* This buddy already exists, so bail out */
2389 priv
->deny
= g_slist_append(priv
->deny
, name
);
2391 if (!local_only
&& purple_account_is_connected(account
))
2392 purple_serv_add_deny(purple_account_get_connection(account
), who
);
2394 if (ui_ops
!= NULL
&& ui_ops
->deny_added
!= NULL
)
2395 ui_ops
->deny_added(account
, who
);
2397 purple_blist_save_account(purple_blist_get_default(), account
);
2399 buddy
= purple_blist_find_buddy(account
, name
);
2400 if (buddy
!= NULL
) {
2401 purple_signal_emit(purple_blist_get_handle(),
2402 "buddy-privacy-changed", buddy
);
2408 purple_account_privacy_deny_remove(PurpleAccount
*account
, const char *who
,
2409 gboolean local_only
)
2412 const char *normalized
;
2415 PurpleAccountPrivate
*priv
;
2416 PurpleAccountUiOps
*ui_ops
= purple_accounts_get_ui_ops();
2418 g_return_val_if_fail(PURPLE_IS_ACCOUNT(account
), FALSE
);
2419 g_return_val_if_fail(who
!= NULL
, FALSE
);
2421 priv
= purple_account_get_instance_private(account
);
2422 normalized
= purple_normalize(account
, who
);
2424 l
= g_slist_find_custom(priv
->deny
, normalized
, (GCompareFunc
)g_strcmp0
);
2426 /* We didn't find the buddy we were looking for, so bail out */
2429 buddy
= purple_blist_find_buddy(account
, normalized
);
2432 priv
->deny
= g_slist_delete_link(priv
->deny
, l
);
2434 if (!local_only
&& purple_account_is_connected(account
))
2435 purple_serv_rem_deny(purple_account_get_connection(account
), name
);
2437 if (ui_ops
!= NULL
&& ui_ops
->deny_removed
!= NULL
)
2438 ui_ops
->deny_removed(account
, who
);
2440 if (buddy
!= NULL
) {
2441 purple_signal_emit(purple_blist_get_handle(),
2442 "buddy-privacy-changed", buddy
);
2447 purple_blist_save_account(purple_blist_get_default(), account
);
2453 purple_account_privacy_allow(PurpleAccount
*account
, const char *who
)
2456 PurpleAccountPrivacyType type
= purple_account_get_privacy_type(account
);
2457 PurpleAccountPrivate
*priv
= purple_account_get_instance_private(account
);
2460 case PURPLE_ACCOUNT_PRIVACY_ALLOW_ALL
:
2462 case PURPLE_ACCOUNT_PRIVACY_ALLOW_USERS
:
2463 purple_account_privacy_permit_add(account
, who
, FALSE
);
2465 case PURPLE_ACCOUNT_PRIVACY_DENY_USERS
:
2466 purple_account_privacy_deny_remove(account
, who
, FALSE
);
2468 case PURPLE_ACCOUNT_PRIVACY_DENY_ALL
:
2470 /* Empty the allow-list. */
2471 const char *norm
= purple_normalize(account
, who
);
2472 for (list
= priv
->permit
; list
!= NULL
;) {
2473 char *person
= list
->data
;
2475 if (!purple_strequal(norm
, person
))
2476 purple_account_privacy_permit_remove(account
, person
, FALSE
);
2478 purple_account_privacy_permit_add(account
, who
, FALSE
);
2479 purple_account_set_privacy_type(account
, PURPLE_ACCOUNT_PRIVACY_ALLOW_USERS
);
2482 case PURPLE_ACCOUNT_PRIVACY_ALLOW_BUDDYLIST
:
2483 if (!purple_blist_find_buddy(account
, who
)) {
2484 add_all_buddies_to_permit_list(account
, FALSE
);
2485 purple_account_privacy_permit_add(account
, who
, FALSE
);
2486 purple_account_set_privacy_type(account
, PURPLE_ACCOUNT_PRIVACY_ALLOW_USERS
);
2490 g_return_if_reached();
2493 /* Notify the server if the privacy setting was changed */
2494 if (type
!= purple_account_get_privacy_type(account
) && purple_account_is_connected(account
))
2495 purple_serv_set_permit_deny(purple_account_get_connection(account
));
2499 purple_account_privacy_deny(PurpleAccount
*account
, const char *who
)
2502 PurpleAccountPrivacyType type
= purple_account_get_privacy_type(account
);
2503 PurpleAccountPrivate
*priv
= purple_account_get_instance_private(account
);
2506 case PURPLE_ACCOUNT_PRIVACY_ALLOW_ALL
:
2508 /* Empty the deny-list. */
2509 const char *norm
= purple_normalize(account
, who
);
2510 for (list
= priv
->deny
; list
!= NULL
; ) {
2511 char *person
= list
->data
;
2513 if (!purple_strequal(norm
, person
))
2514 purple_account_privacy_deny_remove(account
, person
, FALSE
);
2516 purple_account_privacy_deny_add(account
, who
, FALSE
);
2517 purple_account_set_privacy_type(account
, PURPLE_ACCOUNT_PRIVACY_DENY_USERS
);
2520 case PURPLE_ACCOUNT_PRIVACY_ALLOW_USERS
:
2521 purple_account_privacy_permit_remove(account
, who
, FALSE
);
2523 case PURPLE_ACCOUNT_PRIVACY_DENY_USERS
:
2524 purple_account_privacy_deny_add(account
, who
, FALSE
);
2526 case PURPLE_ACCOUNT_PRIVACY_DENY_ALL
:
2528 case PURPLE_ACCOUNT_PRIVACY_ALLOW_BUDDYLIST
:
2529 if (purple_blist_find_buddy(account
, who
)) {
2530 add_all_buddies_to_permit_list(account
, FALSE
);
2531 purple_account_privacy_permit_remove(account
, who
, FALSE
);
2532 purple_account_set_privacy_type(account
, PURPLE_ACCOUNT_PRIVACY_ALLOW_USERS
);
2536 g_return_if_reached();
2539 /* Notify the server if the privacy setting was changed */
2540 if (type
!= purple_account_get_privacy_type(account
) && purple_account_is_connected(account
))
2541 purple_serv_set_permit_deny(purple_account_get_connection(account
));
2545 purple_account_privacy_get_permitted(PurpleAccount
*account
)
2547 PurpleAccountPrivate
*priv
= NULL
;
2549 g_return_val_if_fail(PURPLE_IS_ACCOUNT(account
), NULL
);
2551 priv
= purple_account_get_instance_private(account
);
2552 return priv
->permit
;
2556 purple_account_privacy_get_denied(PurpleAccount
*account
)
2558 PurpleAccountPrivate
*priv
= NULL
;
2560 g_return_val_if_fail(PURPLE_IS_ACCOUNT(account
), NULL
);
2562 priv
= purple_account_get_instance_private(account
);
2567 purple_account_privacy_check(PurpleAccount
*account
, const char *who
)
2569 PurpleAccountPrivate
*priv
= purple_account_get_instance_private(account
);
2571 switch (purple_account_get_privacy_type(account
)) {
2572 case PURPLE_ACCOUNT_PRIVACY_ALLOW_ALL
:
2575 case PURPLE_ACCOUNT_PRIVACY_DENY_ALL
:
2578 case PURPLE_ACCOUNT_PRIVACY_ALLOW_USERS
:
2579 who
= purple_normalize(account
, who
);
2580 return (g_slist_find_custom(priv
->permit
, who
, (GCompareFunc
)g_strcmp0
) != NULL
);
2582 case PURPLE_ACCOUNT_PRIVACY_DENY_USERS
:
2583 who
= purple_normalize(account
, who
);
2584 return (g_slist_find_custom(priv
->deny
, who
, (GCompareFunc
)g_strcmp0
) == NULL
);
2586 case PURPLE_ACCOUNT_PRIVACY_ALLOW_BUDDYLIST
:
2587 return (purple_blist_find_buddy(account
, who
) != NULL
);
2590 g_return_val_if_reached(TRUE
);
2595 purple_account_get_active_status(PurpleAccount
*account
)
2597 PurpleAccountPrivate
*priv
;
2599 g_return_val_if_fail(PURPLE_IS_ACCOUNT(account
), NULL
);
2601 priv
= purple_account_get_instance_private(account
);
2602 return purple_presence_get_active_status(priv
->presence
);
2606 purple_account_get_status(PurpleAccount
*account
, const char *status_id
)
2608 PurpleAccountPrivate
*priv
;
2610 g_return_val_if_fail(PURPLE_IS_ACCOUNT(account
), NULL
);
2611 g_return_val_if_fail(status_id
!= NULL
, NULL
);
2613 priv
= purple_account_get_instance_private(account
);
2615 return purple_presence_get_status(priv
->presence
, status_id
);
2619 purple_account_get_status_type(PurpleAccount
*account
, const char *id
)
2623 g_return_val_if_fail(PURPLE_IS_ACCOUNT(account
), NULL
);
2624 g_return_val_if_fail(id
!= NULL
, NULL
);
2626 for (l
= purple_account_get_status_types(account
); l
!= NULL
; l
= l
->next
)
2628 PurpleStatusType
*status_type
= (PurpleStatusType
*)l
->data
;
2630 if (purple_strequal(purple_status_type_get_id(status_type
), id
))
2638 purple_account_get_status_type_with_primitive(PurpleAccount
*account
, PurpleStatusPrimitive primitive
)
2642 g_return_val_if_fail(PURPLE_IS_ACCOUNT(account
), NULL
);
2644 for (l
= purple_account_get_status_types(account
); l
!= NULL
; l
= l
->next
)
2646 PurpleStatusType
*status_type
= (PurpleStatusType
*)l
->data
;
2648 if (purple_status_type_get_primitive(status_type
) == primitive
)
2656 purple_account_get_presence(PurpleAccount
*account
)
2658 PurpleAccountPrivate
*priv
;
2660 g_return_val_if_fail(PURPLE_IS_ACCOUNT(account
), NULL
);
2662 priv
= purple_account_get_instance_private(account
);
2663 return priv
->presence
;
2667 purple_account_is_status_active(PurpleAccount
*account
,
2668 const char *status_id
)
2670 PurpleAccountPrivate
*priv
;
2672 g_return_val_if_fail(PURPLE_IS_ACCOUNT(account
), FALSE
);
2673 g_return_val_if_fail(status_id
!= NULL
, FALSE
);
2675 priv
= purple_account_get_instance_private(account
);
2677 return purple_presence_is_status_active(priv
->presence
, status_id
);
2681 purple_account_get_status_types(PurpleAccount
*account
)
2683 PurpleAccountPrivate
*priv
;
2685 g_return_val_if_fail(PURPLE_IS_ACCOUNT(account
), NULL
);
2687 priv
= purple_account_get_instance_private(account
);
2688 return priv
->status_types
;
2692 purple_account_get_int(PurpleAccount
*account
, const char *name
,
2695 PurpleAccountSetting
*setting
;
2696 PurpleAccountPrivate
*priv
;
2698 g_return_val_if_fail(PURPLE_IS_ACCOUNT(account
), default_value
);
2699 g_return_val_if_fail(name
!= NULL
, default_value
);
2701 priv
= purple_account_get_instance_private(account
);
2703 setting
= g_hash_table_lookup(priv
->settings
, name
);
2705 if (setting
== NULL
)
2706 return default_value
;
2708 g_return_val_if_fail(G_VALUE_HOLDS_INT(&setting
->value
), default_value
);
2710 return g_value_get_int(&setting
->value
);
2714 purple_account_get_string(PurpleAccount
*account
, const char *name
,
2715 const char *default_value
)
2717 PurpleAccountSetting
*setting
;
2718 PurpleAccountPrivate
*priv
;
2720 g_return_val_if_fail(PURPLE_IS_ACCOUNT(account
), default_value
);
2721 g_return_val_if_fail(name
!= NULL
, default_value
);
2723 priv
= purple_account_get_instance_private(account
);
2725 setting
= g_hash_table_lookup(priv
->settings
, name
);
2727 if (setting
== NULL
)
2728 return default_value
;
2730 g_return_val_if_fail(G_VALUE_HOLDS_STRING(&setting
->value
), default_value
);
2732 return g_value_get_string(&setting
->value
);
2736 purple_account_get_bool(PurpleAccount
*account
, const char *name
,
2737 gboolean default_value
)
2739 PurpleAccountSetting
*setting
;
2740 PurpleAccountPrivate
*priv
;
2742 g_return_val_if_fail(PURPLE_IS_ACCOUNT(account
), default_value
);
2743 g_return_val_if_fail(name
!= NULL
, default_value
);
2745 priv
= purple_account_get_instance_private(account
);
2747 setting
= g_hash_table_lookup(priv
->settings
, name
);
2749 if (setting
== NULL
)
2750 return default_value
;
2752 g_return_val_if_fail(G_VALUE_HOLDS_BOOLEAN(&setting
->value
), default_value
);
2754 return g_value_get_boolean(&setting
->value
);
2758 purple_account_get_ui_int(PurpleAccount
*account
, const char *ui
,
2759 const char *name
, int default_value
)
2761 PurpleAccountSetting
*setting
;
2762 PurpleAccountPrivate
*priv
;
2765 g_return_val_if_fail(PURPLE_IS_ACCOUNT(account
), default_value
);
2766 g_return_val_if_fail(ui
!= NULL
, default_value
);
2767 g_return_val_if_fail(name
!= NULL
, default_value
);
2769 priv
= purple_account_get_instance_private(account
);
2771 if ((table
= g_hash_table_lookup(priv
->ui_settings
, ui
)) == NULL
)
2772 return default_value
;
2774 if ((setting
= g_hash_table_lookup(table
, name
)) == NULL
)
2775 return default_value
;
2777 g_return_val_if_fail(G_VALUE_HOLDS_INT(&setting
->value
), default_value
);
2779 return g_value_get_int(&setting
->value
);
2783 purple_account_get_ui_string(PurpleAccount
*account
, const char *ui
,
2784 const char *name
, const char *default_value
)
2786 PurpleAccountSetting
*setting
;
2787 PurpleAccountPrivate
*priv
;
2790 g_return_val_if_fail(PURPLE_IS_ACCOUNT(account
), default_value
);
2791 g_return_val_if_fail(ui
!= NULL
, default_value
);
2792 g_return_val_if_fail(name
!= NULL
, default_value
);
2794 priv
= purple_account_get_instance_private(account
);
2796 if ((table
= g_hash_table_lookup(priv
->ui_settings
, ui
)) == NULL
)
2797 return default_value
;
2799 if ((setting
= g_hash_table_lookup(table
, name
)) == NULL
)
2800 return default_value
;
2802 g_return_val_if_fail(G_VALUE_HOLDS_STRING(&setting
->value
), default_value
);
2804 return g_value_get_string(&setting
->value
);
2808 purple_account_get_ui_bool(PurpleAccount
*account
, const char *ui
,
2809 const char *name
, gboolean default_value
)
2811 PurpleAccountSetting
*setting
;
2812 PurpleAccountPrivate
*priv
;
2815 g_return_val_if_fail(PURPLE_IS_ACCOUNT(account
), default_value
);
2816 g_return_val_if_fail(ui
!= NULL
, default_value
);
2817 g_return_val_if_fail(name
!= NULL
, default_value
);
2819 priv
= purple_account_get_instance_private(account
);
2821 if ((table
= g_hash_table_lookup(priv
->ui_settings
, ui
)) == NULL
)
2822 return default_value
;
2824 if ((setting
= g_hash_table_lookup(table
, name
)) == NULL
)
2825 return default_value
;
2827 g_return_val_if_fail(G_VALUE_HOLDS_BOOLEAN(&setting
->value
), default_value
);
2829 return g_value_get_boolean(&setting
->value
);
2833 purple_account_get_log(PurpleAccount
*account
, gboolean create
)
2835 PurpleAccountPrivate
*priv
;
2837 g_return_val_if_fail(PURPLE_IS_ACCOUNT(account
), NULL
);
2839 priv
= purple_account_get_instance_private(account
);
2841 if(!priv
->system_log
&& create
){
2842 PurplePresence
*presence
;
2846 presence
= purple_account_get_presence(account
);
2847 login_time
= purple_presence_get_login_time(presence
);
2848 if (login_time
!= 0) {
2849 dt
= g_date_time_new_from_unix_local(login_time
);
2851 dt
= g_date_time_new_now_local();
2854 priv
->system_log
= purple_log_new(PURPLE_LOG_SYSTEM
,
2855 purple_account_get_username(account
),
2857 g_date_time_unref(dt
);
2860 return priv
->system_log
;
2864 purple_account_destroy_log(PurpleAccount
*account
)
2866 PurpleAccountPrivate
*priv
;
2868 g_return_if_fail(PURPLE_IS_ACCOUNT(account
));
2870 priv
= purple_account_get_instance_private(account
);
2872 if(priv
->system_log
){
2873 purple_log_free(priv
->system_log
);
2874 priv
->system_log
= NULL
;
2879 purple_account_add_buddy(PurpleAccount
*account
, PurpleBuddy
*buddy
, const char *message
)
2881 PurpleProtocol
*protocol
= NULL
;
2882 PurpleConnection
*gc
;
2884 g_return_if_fail(PURPLE_IS_ACCOUNT(account
));
2885 g_return_if_fail(PURPLE_IS_BUDDY(buddy
));
2887 gc
= purple_account_get_connection(account
);
2889 protocol
= purple_connection_get_protocol(gc
);
2891 if (protocol
!= NULL
)
2892 purple_protocol_server_iface_add_buddy(protocol
, gc
, buddy
,
2893 purple_buddy_get_group(buddy
), message
);
2897 purple_account_add_buddies(PurpleAccount
*account
, GList
*buddies
, const char *message
)
2899 PurpleProtocol
*protocol
= NULL
;
2900 PurpleConnection
*gc
= purple_account_get_connection(account
);
2903 protocol
= purple_connection_get_protocol(gc
);
2906 GList
*cur
, *groups
= NULL
;
2908 /* Make a list of what group each buddy is in */
2909 for (cur
= buddies
; cur
!= NULL
; cur
= cur
->next
) {
2910 PurpleBuddy
*buddy
= cur
->data
;
2911 groups
= g_list_append(groups
, purple_buddy_get_group(buddy
));
2914 if (PURPLE_PROTOCOL_IMPLEMENTS(protocol
, SERVER
, add_buddies
))
2915 purple_protocol_server_iface_add_buddies(protocol
, gc
, buddies
, groups
, message
);
2916 else if (PURPLE_PROTOCOL_IMPLEMENTS(protocol
, SERVER
, add_buddy
)) {
2917 GList
*curb
= buddies
, *curg
= groups
;
2919 while ((curb
!= NULL
) && (curg
!= NULL
)) {
2920 purple_protocol_server_iface_add_buddy(protocol
, gc
, curb
->data
, curg
->data
, message
);
2926 g_list_free(groups
);
2931 purple_account_remove_buddy(PurpleAccount
*account
, PurpleBuddy
*buddy
,
2934 PurpleProtocol
*protocol
= NULL
;
2935 PurpleConnection
*gc
= purple_account_get_connection(account
);
2938 protocol
= purple_connection_get_protocol(gc
);
2941 purple_protocol_server_iface_remove_buddy(protocol
, gc
, buddy
, group
);
2945 purple_account_remove_buddies(PurpleAccount
*account
, GList
*buddies
, GList
*groups
)
2947 PurpleProtocol
*protocol
= NULL
;
2948 PurpleConnection
*gc
= purple_account_get_connection(account
);
2951 protocol
= purple_connection_get_protocol(gc
);
2954 if (PURPLE_PROTOCOL_IMPLEMENTS(protocol
, SERVER
, remove_buddies
))
2955 purple_protocol_server_iface_remove_buddies(protocol
, gc
, buddies
, groups
);
2957 GList
*curb
= buddies
;
2958 GList
*curg
= groups
;
2959 while ((curb
!= NULL
) && (curg
!= NULL
)) {
2960 purple_account_remove_buddy(account
, curb
->data
, curg
->data
);
2969 purple_account_remove_group(PurpleAccount
*account
, PurpleGroup
*group
)
2971 PurpleProtocol
*protocol
= NULL
;
2972 PurpleConnection
*gc
= purple_account_get_connection(account
);
2975 protocol
= purple_connection_get_protocol(gc
);
2978 purple_protocol_server_iface_remove_group(protocol
, gc
, group
);
2982 purple_account_change_password(PurpleAccount
*account
, const char *orig_pw
,
2985 PurpleProtocol
*protocol
= NULL
;
2986 PurpleConnection
*gc
= purple_account_get_connection(account
);
2988 purple_account_set_password(account
, new_pw
, NULL
, NULL
);
2991 protocol
= purple_connection_get_protocol(gc
);
2994 purple_protocol_server_iface_change_passwd(protocol
, gc
, orig_pw
, new_pw
);
2997 gboolean
purple_account_supports_offline_message(PurpleAccount
*account
, PurpleBuddy
*buddy
)
2999 PurpleConnection
*gc
;
3000 PurpleProtocol
*protocol
= NULL
;
3002 g_return_val_if_fail(PURPLE_IS_ACCOUNT(account
), FALSE
);
3003 g_return_val_if_fail(PURPLE_IS_BUDDY(buddy
), FALSE
);
3005 gc
= purple_account_get_connection(account
);
3009 protocol
= purple_connection_get_protocol(gc
);
3013 return purple_protocol_client_iface_offline_message(protocol
, buddy
);
3016 const PurpleConnectionErrorInfo
*
3017 purple_account_get_current_error(PurpleAccount
*account
)
3019 PurpleAccountPrivate
*priv
= purple_account_get_instance_private(account
);
3021 return priv
->current_error
;
3025 purple_account_clear_current_error(PurpleAccount
*account
)
3027 _purple_account_set_current_error(account
, NULL
);