⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 admin.c

📁 AnyQ服务端源代码(2004/10/28)源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* --------------------------------------------------------------------------
 *
 * License
 *
 * The contents of this file are subject to the Jabber Open Source License
 * Version 1.0 (the "License").  You may not copy or use this file, in either
 * source code or executable form, except in compliance with the License.  You
 * may obtain a copy of the License at http://www.jabber.com/license/ or at
 * http://www.opensource.org/.  
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied.  See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * Copyrights
 * 
 * Portions created by or assigned to Jabber.com, Inc. are 
 * Copyright (c) 1999-2000 Jabber.com, Inc.  All Rights Reserved.  Contact
 * information for Jabber.com, Inc. is available at http://www.jabber.com/.
 *
 * Portions Copyright (c) 1998-1999 Jeremie Miller.
 * 
 * Acknowledgements
 * 
 * Special thanks to the Jabber Open Source Contributors for their
 * suggestions and support of Jabber.
 * 
 * --------------------------------------------------------------------------*/

#include "conference.h"

void con_get_role_list(const char *key, void *data, void *arg)
{
    xmlnode node;
    char *jabberid;
    taffil affiliation;
    trole role;
    jid userid;

    xmlnode result = (xmlnode)arg;
    cnr room = (cnr)xmlnode_get_vattrib(result ,"cnr");

    node = xmlnode_new_tag("item");
    jabberid = pstrdup(xmlnode_pool(node), key);
    userid = jid_new(xmlnode_pool(node), jabberid);

    xmlnode_put_attrib(node, "jid", jabberid);

    affiliation = affiliation_level(room, userid);
    role = role_level(room, userid);

    xmlnode_put_attrib(node, "role", role.msg);
    xmlnode_put_attrib(node, "affiliation", affiliation.msg);

    xmlnode_insert_node(result, node);
    xmlnode_free(node);
}

void con_get_affiliate_list(const char *key, void *data, void *arg)
{
    xmlnode node;
    char *jabberid;
    taffil affiliation;
    jid userid;

    xmlnode result = (xmlnode)arg;
   
    xmlnode item = (xmlnode)data; 
    char *actor = xmlnode_get_attrib(item, "actor");
    char *reason = xmlnode_get_data(item);
   
    cnr room = (cnr)xmlnode_get_vattrib(result ,"cnr");

    node = xmlnode_new_tag("item");

    jabberid = pstrdup(xmlnode_pool(node), key);
    userid = jid_new(xmlnode_pool(node), jabberid);

    xmlnode_put_attrib(node, "jid", jabberid);

    affiliation = affiliation_level(room, userid);

    xmlnode_put_attrib(node, "affiliation", affiliation.msg);

    if(reason != NULL)
        xmlnode_insert_cdata(xmlnode_insert_tag(node, "reason"), reason, -1);

    if(actor != NULL)
        xmlnode_insert_cdata(xmlnode_insert_tag(node, "actor"), actor, -1);

    xmlnode_insert_node(result, node);
    xmlnode_free(node);
}


/* Generate x:data form for configuring lists */
xmlnode con_gen_list(cnr room, char *namespace, char *type)
{
    xmlnode result;

    result = xmlnode_new_tag("query");
    xmlnode_put_attrib(result,"xmlns", namespace);
    xmlnode_put_vattrib(result, "cnr", (void*)room);

    if(j_strcmp(type, "owner") == 0)
	htb_walk(&room->owner, con_get_affiliate_list, (void*)result);
    else if(j_strcmp(type, "admin") == 0)
	htb_walk(&room->admin, con_get_affiliate_list, (void*)result);
    else if(j_strcmp(type, "moderator") == 0)
	htb_walk(&room->moderator, con_get_role_list, (void*)result);
    else if(j_strcmp(type, "member") == 0)
	htb_walk(&room->member, con_get_affiliate_list, (void*)result);
    else if(j_strcmp(type, "participant") == 0)
	htb_walk(&room->participant, con_get_role_list, (void*)result);
    else if(j_strcmp(type, "outcast") == 0)
	htb_walk(&room->outcast, con_get_affiliate_list, (void*)result);

    xmlnode_hide_attrib(result, "cnr");

    return result;
}

void adm_user_kick(cnu user, cnu target, char *reason)
{
    cnr room;
    xmlnode data;
    char *status;
    xmlnode pres;

    if(user == NULL || target == NULL || reason == NULL)
    {
        log_debug(NAME, "[%s] Missing attributes", FZONE);
	return;
    }

    room = target->room;

    data = xmlnode_new_tag("reason");

    if(is_outcast(room, target->realid))
        status = pstrdup(xmlnode_pool(data), STATUS_MUC_BANNED);
    else
	status = pstrdup(xmlnode_pool(data), STATUS_MUC_KICKED);

    xmlnode_put_attrib(data, "status", status);
    xmlnode_put_attrib(data, "actor", jid_full(jid_user(jid_fix(user->realid))));
    xmlnode_insert_cdata(data, reason, -1);

    pres = jutil_presnew(JPACKET__UNAVAILABLE, jid_full(target->realid), NULL);
    target->presence = pres;
    log_debug(NAME, "[%s] Kick/Ban requested. Status code=%s", FZONE, status);

    con_send_alert(target, reason, NULL, status);
    con_user_zap(target, data);

    return;
}

void con_parse_item(cnu sender, jpacket jp)
{
    xmlnode current;
    xmlnode result;
    xmlnode node;
    jid target;
    jid from;
    char *xmlns;
    char *role;
    char *jabberid;
    char *nick;
    char *reason;
    char *affiliation;
    cnu user = NULL;
    cnr room;

    int error = 0;

    if(sender == NULL)
    {
	log_debug(NAME, "[%s] Aborting - Insufficient parameters", FZONE);
	return;
    }

    from = sender->realid;
    room = sender->room;
    node = xmlnode_get_tag(jp->x, "query");
    xmlns = xmlnode_get_attrib(node, "xmlns");

    /* Check for configuration request */
    if(j_strcmp(xmlns, NS_MUC_OWNER) == 0 && xmlnode_get_tag(node, "item") == NULL)
    {
	if(is_owner(room, from))
	{
	    user = htb_get(&room->remote, jid_full(jid_fix(from)));
	    if(user)
	    {
                xdata_room_config(room, user, room->locked, jp->x);
	        xmlnode_free(jp->x);
	    }
	    else
	    {
	        jutil_error(jp->x, TERROR_BAD);
	        deliver(dpacket_new(jp->x), NULL);
	    }
	    return;
        }
        else
        {
	    jutil_error(jp->x, TERROR_NOTALLOWED);
	    deliver(dpacket_new(jp->x), NULL);
	    return;
	}
    }
    
    /* Parse request for errors */
    for(current = xmlnode_get_firstchild(node); current != NULL; current = xmlnode_get_nextsibling(current))
    {
	/* Extract data */
	jabberid = xmlnode_get_attrib(current, "jid");
	nick = xmlnode_get_attrib(current, "nick");
	role = xmlnode_get_attrib(current, "role");
	affiliation = xmlnode_get_attrib(current, "affiliation");
	reason = xmlnode_get_tag_data(current, "reason");
    
	if(jabberid == NULL && nick == NULL && role == NULL && affiliation == NULL)
	{
	    error = 1;
	    log_debug(NAME, "[%s] Skipping - Badly formed request (%s)", FZONE, xmlnode2str(current));
	    insert_item_error(current, "400", "Badly formed request");
	    continue;
	}

	if(jpacket_subtype(jp) == JPACKET__GET)
        {
	    if(jabberid == NULL && nick == NULL)
	    {
		if(!is_admin(room, from))
		{
	            error = 1;
	            log_debug(NAME, "[%s] Skipping - Insufficent level to request admin list", FZONE);
		    insert_item_error(jp->x, "403", "Forbidden list retrieval");
	            continue;
		}

		if(role != NULL && affiliation != NULL)
	        {
	            error = 1;
	            log_debug(NAME, "[%s] Skipping - Badly formed request (%s)", FZONE, xmlnode2str(current));
		    insert_item_error(current, "400", "Badly formatted list request");
	            continue;
	        }

		if(j_strcmp(affiliation, "admin") != 0 && j_strcmp(role, "participant") != 0 && j_strcmp(affiliation, "member") != 0 && j_strcmp(role, "moderator") != 0 && j_strcmp(affiliation, "outcast") != 0 && j_strcmp(affiliation, "owner") != 0)
	        {
	            error = 1;
	            log_debug(NAME, "[%s] Skipping - No such list (%s)", FZONE, xmlnode2str(current));
		    insert_item_error(current, "400", "No such list");
	            continue;
	        }

	        if(j_strcmp(affiliation, "admin") == 0 || j_strcmp(affiliation, "owner") == 0)
	        {
		    if(j_strcmp(xmlns, NS_MUC_OWNER) != 0)
		    {
	                error = 1;
	                log_debug(NAME, "[%s] Skipping - Badly formed namespace (%s)", FZONE, xmlnode2str(current));
			insert_item_error(current, "400", "Invalid Namespace");
	                continue;
		    }

		    if(!is_owner(room, from))

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -