mark PurpleImageClass as private
[pidgin-git.git] / libpurple / protocols / oscar / authorization.c
blob668265754af43a230bb393743a9db759d057b8f8
1 /*
2 * Purple's oscar protocol plugin
3 * This file is the legal property of its developers.
4 * Please see the AUTHORS file distributed alongside this file.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
22 * Everything related to OSCAR authorization requests.
25 #include "oscar.h"
26 #include "request.h"
28 /* When you ask other people for authorization */
29 void
30 oscar_auth_sendrequest(PurpleConnection *gc, const char *bname, const char *msg)
32 OscarData *od;
33 PurpleAccount *account;
34 PurpleBuddy *buddy;
35 PurpleGroup *group;
36 const char *gname;
38 od = purple_connection_get_protocol_data(gc);
39 account = purple_connection_get_account(gc);
40 buddy = purple_blist_find_buddy(account, bname);
41 if (buddy != NULL)
42 group = purple_buddy_get_group(buddy);
43 else
44 group = NULL;
46 if (group != NULL)
48 gname = purple_group_get_name(group);
49 purple_debug_info("oscar", "ssi: adding buddy %s to group %s\n",
50 bname, gname);
51 aim_ssi_sendauthrequest(od, bname, msg ? msg : _("Please authorize me so I can add you to my buddy list."));
52 if (!aim_ssi_itemlist_finditem(&od->ssi.local, gname, bname, AIM_SSI_TYPE_BUDDY))
54 aim_ssi_addbuddy(od, bname, gname, NULL, purple_buddy_get_alias_only(buddy), NULL, NULL, TRUE);
56 /* Mobile users should always be online */
57 if (bname[0] == '+') {
58 purple_protocol_got_user_status(account,
59 purple_buddy_get_name(buddy),
60 OSCAR_STATUS_ID_AVAILABLE, NULL);
61 purple_protocol_got_user_status(account,
62 purple_buddy_get_name(buddy),
63 OSCAR_STATUS_ID_MOBILE, NULL);
69 static void
70 oscar_auth_grant(const char *message, gpointer cbdata)
72 struct name_data *data = cbdata;
73 PurpleConnection *gc = data->gc;
74 OscarData *od = purple_connection_get_protocol_data(gc);
76 aim_ssi_sendauthreply(od, data->name, 0x01, NULL);
78 oscar_free_name_data(data);
81 static void
82 oscar_auth_dontgrant(const char *msg, gpointer cbdata)
84 struct name_data *data = cbdata;
85 PurpleConnection *gc = data->gc;
86 OscarData *od = purple_connection_get_protocol_data(gc);
88 aim_ssi_sendauthreply(od, data->name, 0x00, msg ? msg : _("No reason given."));
90 oscar_free_name_data(data);
93 void
94 oscar_auth_sendrequest_menu(PurpleBlistNode *node, gpointer ignored)
96 PurpleBuddy *buddy;
97 PurpleConnection *gc;
99 g_return_if_fail(PURPLE_IS_BUDDY(node));
101 buddy = (PurpleBuddy *) node;
102 gc = purple_account_get_connection(purple_buddy_get_account(buddy));
103 oscar_auth_sendrequest(gc, purple_buddy_get_name(buddy), NULL);
106 /* When other people ask you for authorization */
107 void
108 oscar_auth_recvrequest(PurpleConnection *gc, gchar *name, gchar *nick, gchar *reason)
110 PurpleAccount* account = purple_connection_get_account(gc);
111 struct name_data *data = g_new(struct name_data, 1);
113 data->gc = gc;
114 data->name = name;
115 data->nick = nick;
117 purple_account_request_authorization(account, data->name, NULL, data->nick,
118 reason, purple_blist_find_buddy(account, data->name) != NULL,
119 oscar_auth_grant, oscar_auth_dontgrant, data);