comparison libpurple/protocols/oscar/authorization.c @ 30361:9881f18b95b1

Got rid of family_icq.c -> oscar.c callbacks. Now it will be possible to add an error handler for SNAC_FAMILY_ICQ right inside family_icq.c, since all the necessary functions are there. I made a pretty large refactoring along the way, moving the authorization- and userinfo-related functions to separate files and renaming some of them. Hopefully, this will make oscar.c less of mess.
author ivan.komarov@soc.pidgin.im
date Sun, 30 May 2010 13:53:45 +0000
parents
children a8cc50c2279f
comparison
equal deleted inserted replaced
30360:2f25002c9464 30361:9881f18b95b1
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.
5 *
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.
10 *
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.
15 *
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
19 */
20
21 /*
22 * Everything related to OSCAR authorization requests.
23 */
24
25 #include "oscar.h"
26 #include "request.h"
27
28 static void
29 oscar_auth_request(struct name_data *data, char *msg)
30 {
31 PurpleConnection *gc;
32 OscarData *od;
33 PurpleAccount *account;
34 PurpleBuddy *buddy;
35 PurpleGroup *group;
36 const char *bname, *gname;
37
38 gc = data->gc;
39 od = purple_connection_get_protocol_data(gc);
40 account = purple_connection_get_account(gc);
41 buddy = purple_find_buddy(account, data->name);
42 if (buddy != NULL)
43 group = purple_buddy_get_group(buddy);
44 else
45 group = NULL;
46
47 if (group != NULL)
48 {
49 bname = purple_buddy_get_name(buddy);
50 gname = purple_group_get_name(group);
51 purple_debug_info("oscar", "ssi: adding buddy %s to group %s\n",
52 bname, gname);
53 aim_ssi_sendauthrequest(od, data->name, msg ? msg : _("Please authorize me so I can add you to my buddy list."));
54 if (!aim_ssi_itemlist_finditem(od->ssi.local, gname, bname, AIM_SSI_TYPE_BUDDY))
55 {
56 aim_ssi_addbuddy(od, bname, gname, NULL, purple_buddy_get_alias_only(buddy), NULL, NULL, TRUE);
57
58 /* Mobile users should always be online */
59 if (bname[0] == '+') {
60 purple_prpl_got_user_status(account,
61 purple_buddy_get_name(buddy),
62 OSCAR_STATUS_ID_AVAILABLE, NULL);
63 purple_prpl_got_user_status(account,
64 purple_buddy_get_name(buddy),
65 OSCAR_STATUS_ID_MOBILE, NULL);
66 }
67 }
68 }
69
70 oscar_free_name_data(data);
71 }
72
73 static void
74 oscar_auth_grant(gpointer cbdata)
75 {
76 struct name_data *data = cbdata;
77 PurpleConnection *gc = data->gc;
78 OscarData *od = purple_connection_get_protocol_data(gc);
79
80 aim_ssi_sendauthreply(od, data->name, 0x01, NULL);
81
82 oscar_free_name_data(data);
83 }
84
85 static void
86 oscar_auth_dontgrant(struct name_data *data, char *msg)
87 {
88 PurpleConnection *gc = data->gc;
89 OscarData *od = purple_connection_get_protocol_data(gc);
90
91 aim_ssi_sendauthreply(od, data->name, 0x00, msg ? msg : _("No reason given."));
92
93 oscar_free_name_data(data);
94 }
95
96 static void
97 oscar_auth_dontgrant_msgprompt(gpointer cbdata)
98 {
99 struct name_data *data = cbdata;
100 purple_request_input(data->gc, NULL, _("Authorization Denied Message:"),
101 NULL, _("No reason given."), TRUE, FALSE, NULL,
102 _("_OK"), G_CALLBACK(oscar_auth_dontgrant),
103 _("_Cancel"), G_CALLBACK(oscar_free_name_data),
104 purple_connection_get_account(data->gc), data->name, NULL,
105 data);
106 }
107
108 /* When you ask other people for authorization */
109 void
110 oscar_auth_sendrequest(PurpleConnection *gc, const char *name)
111 {
112 struct name_data *data;
113
114 data = g_new0(struct name_data, 1);
115 data->gc = gc;
116 data->name = g_strdup(name);
117
118 purple_request_input(data->gc, NULL, _("Authorization Request Message:"),
119 NULL, _("Please authorize me!"), TRUE, FALSE, NULL,
120 _("_OK"), G_CALLBACK(oscar_auth_request),
121 _("_Cancel"), G_CALLBACK(oscar_free_name_data),
122 purple_connection_get_account(gc), name, NULL,
123 data);
124 }
125
126 void
127 oscar_auth_sendrequest_menu(PurpleBlistNode *node, gpointer ignored)
128 {
129 PurpleBuddy *buddy;
130 PurpleConnection *gc;
131
132 g_return_if_fail(PURPLE_BLIST_NODE_IS_BUDDY(node));
133
134 buddy = (PurpleBuddy *) node;
135 gc = purple_account_get_connection(purple_buddy_get_account(buddy));
136 oscar_auth_sendrequest(gc, purple_buddy_get_name(buddy));
137 }
138
139 /* When other people ask you for authorization */
140 void
141 oscar_auth_recvrequest(PurpleConnection *gc, gchar *name, gchar *nick, gchar *reason)
142 {
143 PurpleAccount* account = purple_connection_get_account(gc);
144 struct name_data *data = g_new(struct name_data, 1);
145
146 data->gc = gc;
147 data->name = name;
148 data->nick = nick;
149
150 purple_account_request_authorization(account, data->name, NULL, data->nick,
151 reason, purple_find_buddy(account, data->name) != NULL,
152 oscar_auth_grant, oscar_auth_dontgrant_msgprompt, data);
153 }