File:  [Coherent Logic Development] / ChivanetAimPidgin / oscarprpl / src / c / authorization.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Mon Jan 27 19:48:25 2025 UTC (6 months ago) by snw
Branches: MAIN, CoherentLogicDevelopment
CVS tags: test-tag, start, HEAD
Pidgin AIM Plugin for ChivaNet

    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: /* When you ask other people for authorization */
   29: void
   30: oscar_auth_sendrequest(PurpleConnection *gc, const char *bname, const char *msg)
   31: {
   32: 	OscarData *od;
   33: 	PurpleAccount *account;
   34: 	PurpleBuddy *buddy;
   35: 	PurpleGroup *group;
   36: 	const char *gname;
   37: 
   38: 	od = purple_connection_get_protocol_data(gc);
   39: 	account = purple_connection_get_account(gc);
   40: 	buddy = purple_find_buddy(account, bname);
   41: 	if (buddy != NULL)
   42: 		group = purple_buddy_get_group(buddy);
   43: 	else
   44: 		group = NULL;
   45: 
   46: 	if (group != NULL)
   47: 	{
   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))
   53: 		{
   54: 			aim_ssi_addbuddy(od, bname, gname, NULL, purple_buddy_get_alias_only(buddy), NULL, NULL, TRUE);
   55: 
   56: 			/* Mobile users should always be online */
   57: 			if (bname[0] == '+') {
   58: 				purple_prpl_got_user_status(account,
   59: 						purple_buddy_get_name(buddy),
   60: 						OSCAR_STATUS_ID_AVAILABLE, NULL);
   61: 				purple_prpl_got_user_status(account,
   62: 						purple_buddy_get_name(buddy),
   63: 						OSCAR_STATUS_ID_MOBILE, NULL);
   64: 			}
   65: 		}
   66: 	}
   67: }
   68: 
   69: static void
   70: oscar_auth_grant(gpointer cbdata)
   71: {
   72: 	struct name_data *data = cbdata;
   73: 	PurpleConnection *gc = data->gc;
   74: 	OscarData *od = purple_connection_get_protocol_data(gc);
   75: 
   76: 	aim_ssi_sendauthreply(od, data->name, 0x01, NULL);
   77: 
   78: 	oscar_free_name_data(data);
   79: }
   80: 
   81: static void
   82: oscar_auth_dontgrant(struct name_data *data, char *msg)
   83: {
   84: 	PurpleConnection *gc = data->gc;
   85: 	OscarData *od = purple_connection_get_protocol_data(gc);
   86: 
   87: 	aim_ssi_sendauthreply(od, data->name, 0x00, msg ? msg : _("No reason given."));
   88: 
   89: 	oscar_free_name_data(data);
   90: }
   91: 
   92: static void
   93: oscar_auth_dontgrant_msgprompt(gpointer cbdata)
   94: {
   95: 	struct name_data *data = cbdata;
   96: 	purple_request_input(data->gc, NULL, _("Authorization Denied Message:"),
   97: 					   NULL, _("No reason given."), TRUE, FALSE, NULL,
   98: 					   _("_OK"), G_CALLBACK(oscar_auth_dontgrant),
   99: 					   _("_Cancel"), G_CALLBACK(oscar_free_name_data),
  100: 					   purple_connection_get_account(data->gc), data->name, NULL,
  101: 					   data);
  102: }
  103: 
  104: void
  105: oscar_auth_sendrequest_menu(PurpleBlistNode *node, gpointer ignored)
  106: {
  107: 	PurpleBuddy *buddy;
  108: 	PurpleConnection *gc;
  109: 
  110: 	g_return_if_fail(PURPLE_BLIST_NODE_IS_BUDDY(node));
  111: 
  112: 	buddy = (PurpleBuddy *) node;
  113: 	gc = purple_account_get_connection(purple_buddy_get_account(buddy));
  114: 	oscar_auth_sendrequest(gc, purple_buddy_get_name(buddy), NULL);
  115: }
  116: 
  117: /* When other people ask you for authorization */
  118: void
  119: oscar_auth_recvrequest(PurpleConnection *gc, gchar *name, gchar *nick, gchar *reason)
  120: {
  121: 	PurpleAccount* account = purple_connection_get_account(gc);
  122: 	struct name_data *data = g_new(struct name_data, 1);
  123: 
  124: 	data->gc = gc;
  125: 	data->name = name;
  126: 	data->nick = nick;
  127: 
  128: 	purple_account_request_authorization(account, data->name, NULL, data->nick,
  129: 		reason, purple_find_buddy(account, data->name) != NULL,
  130: 		oscar_auth_grant, oscar_auth_dontgrant_msgprompt, data);
  131: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>