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

📄 xdata.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"

xmlnode add_xdata_boolean(char *label, char *var, int data)
{
    xmlnode node;
    char value[4];

    snprintf(value, 4, "%i", data);
    node = xmlnode_new_tag("field");
    xmlnode_put_attrib(node,"type","boolean");
    xmlnode_put_attrib(node,"label", label);
    xmlnode_put_attrib(node,"var", var);
    xmlnode_insert_cdata(xmlnode_insert_tag(node,"value"), value, -1);

    return node;
}

xmlnode add_xdata_text(char *label, int type, char *var, char *data)
{
    xmlnode node;

    node = xmlnode_new_tag("field");

    if(type > 1)
	    xmlnode_put_attrib(node,"type","text-multi");
    else if(type == 1)
	    xmlnode_put_attrib(node,"type","text-single");
    else if(type == -1)
	    xmlnode_put_attrib(node,"type","text-private");
    else
	    xmlnode_put_attrib(node,"type","hidden");

    if(label != NULL)
	    xmlnode_put_attrib(node,"label", label);

    xmlnode_put_attrib(node,"var", var);
    xmlnode_insert_cdata(xmlnode_insert_tag(node,"value"), data, -1);

    return node;
}

xmlnode add_xdata_desc(char *label)
{
    xmlnode node;

    node = xmlnode_new_tag("field");
    xmlnode_put_attrib(node,"type","fixed");
    xmlnode_insert_cdata(xmlnode_insert_tag(node,"value"), label, -1);

    return node;
}

void xdata_handler(cnr room, cnu user, jpacket packet)
{
    xmlnode results, element, value, current, node, message;

    spool sp = spool_new(room->p);
    int visible = room->visible;
    char namespace[100];
    
    log_debug(NAME, "[%s] xdata handler", FZONE);
    results = xmlnode_get_tag(packet->x,"x");

    /* Can't find xdata - trying NS_MUC_ADMIN namespace */
    if(results == NULL)
    {
        snprintf(namespace, 100, "?xmlns=%s", NS_MUC_ADMIN);
        element = xmlnode_get_tag(packet->x, namespace);
	results = xmlnode_get_tag(element,"x");
    }

    /* Still no data, try NS_MUC_OWNER namespace */
    if(results == NULL)
    {
        snprintf(namespace, 100, "?xmlns=%s", NS_MUC_OWNER);
        element = xmlnode_get_tag(packet->x, namespace);
	results = xmlnode_get_tag(element,"x");
    }

    /* Still no data, try NS_MUC_USER namespace */
    if(results == NULL)
    {
        snprintf(namespace, 100, "?xmlns=%s", NS_MUC_USER);
        element = xmlnode_get_tag(packet->x, namespace);
	results = xmlnode_get_tag(element,"x");
    }

    /* Still no xdata, just leave */
    if(results == NULL)
    {
	log_debug(NAME, "[%s] No xdata results found", FZONE);
	return;
    }

    if(j_strcmp(xmlnode_get_attrib(results, "type"), "cancel") == 0)
    {
	log_debug(NAME, "[%s] xdata form was cancelled", FZONE);

	/* If form cancelled and room locked, this is declaration of room destroy request */
        if(room->locked == 1)
        {
	    if(room->persistant == 1)
	        xdb_room_clear(room);

	    htb_walk(&room->remote, con_room_leaveall, (void*)NULL);
            con_room_zap(room);
        }
        return;
    }

    value = xmlnode_get_tag(results,"?var=form");
    log_debug(NAME, "[%s] Form type: %s", FZONE, xmlnode_get_tag_data(value,"value"));

    if(is_admin(room, user->realid))
    {
        log_debug(NAME, "[%s] Processing configuration form", FZONE);

	/* Clear any room locks */
        if(room->locked == 1)
        {
	    message = jutil_msgnew("groupchat", jid_full(jid_fix(user->realid)), NULL, spools(packet->p, "Configuration confirmed: This room is now unlocked.", packet->p));
	    xmlnode_put_attrib(message,"from", jid_full(jid_fix(room->id)));
	    //deliver(dpacket_new(message), NULL);

	    room->locked = 0;
	}

	/* Protect text forms from broken clients */
	if(xmlnode_get_tag(results,"?var=title") != NULL)
  	    room->name = pstrdup(room->p, xmlnode_get_tag_data(xmlnode_get_tag(results,"?var=title"),"value"));
	if(xmlnode_get_tag(results,"?var=leave") != NULL)
	    room->note_leave = pstrdup(room->p, xmlnode_get_tag_data(xmlnode_get_tag(results,"?var=leave"),"value"));
	if(xmlnode_get_tag(results,"?var=join") != NULL)
	    room->note_join = pstrdup(room->p, xmlnode_get_tag_data(xmlnode_get_tag(results,"?var=join"),"value"));
	if(xmlnode_get_tag(results,"?var=rename") != NULL)
	    room->note_rename = pstrdup(room->p, xmlnode_get_tag_data(xmlnode_get_tag(results,"?var=rename"),"value"));

	/* Handle text-multi */
	if((node = xmlnode_get_tag(results,"?var=description")) != NULL)
	{
            for(current = xmlnode_get_firstchild(node); current != NULL; current = xmlnode_get_nextsibling(current))
	    {
		spooler(sp, xmlnode_get_data(current), sp);
	    }

	    room->description = spool_print(sp);
	}

	/* Update with results from form if available. If unable, simply use the original value */
	room->subjectlock = j_atoi(xmlnode_get_tag_data(xmlnode_get_tag(results,"?var=subject"),"value"), room->subjectlock);
	room->private = j_atoi(xmlnode_get_tag_data(xmlnode_get_tag(results,"?var=privacy"),"value"),room->private);
	room->public = j_atoi(xmlnode_get_tag_data(xmlnode_get_tag(results,"?var=public"),"value"),room->public);
	room->maxusers = j_atoi(xmlnode_get_tag_data(xmlnode_get_tag(results,"?var=participants"),"value"),room->maxusers);

	if(room->master->dynamic == 0)
	    room->persistant = j_atoi(xmlnode_get_tag_data(xmlnode_get_tag(results,"?var=persistant"),"value"),room->persistant);

	room->moderated = j_atoi(xmlnode_get_tag_data(xmlnode_get_tag(results,"?var=moderated"),"value"),room->moderated);
	room->defaulttype = j_atoi(xmlnode_get_tag_data(xmlnode_get_tag(results,"?var=defaulttype"),"value"),room->defaulttype);
	room->privmsg = j_atoi(xmlnode_get_tag_data(xmlnode_get_tag(results,"?var=privmsg"),"value"),room->privmsg);
	room->invitation = j_atoi(xmlnode_get_tag_data(xmlnode_get_tag(results,"?var=invitation"),"value"),room->invitation);
	room->invites = j_atoi(xmlnode_get_tag_data(xmlnode_get_tag(results,"?var=invites"),"value"),room->invites);
	room->legacy = j_atoi(xmlnode_get_tag_data(xmlnode_get_tag(results,"?var=legacy"),"value"),room->legacy);

	/* Protection against broken clients */
	if(xmlnode_get_tag(results,"?var=password") != NULL && xmlnode_get_tag(results,"?var=secret") != NULL)
	{
	    /* Is both password set and active? */
	    if(j_strcmp(xmlnode_get_tag_data(xmlnode_get_tag(results,"?var=password"),"value"), "1") == 0 && xmlnode_get_tag_data(xmlnode_get_tag(results,"?var=secret"),"value") != NULL)
	    {
		room->secret = pstrdup(room->p, xmlnode_get_tag_data(xmlnode_get_tag(results,"?var=secret"),"value"));
		log_debug(NAME ,"[%s] Switching on room password: %s", FZONE, room->secret);
	    }
	    else 
	    {
		log_debug(NAME, "[%s] Deactivating room password: %s %s", FZONE, xmlnode_get_tag_data(xmlnode_get_tag(results,"?var=password"),"value"), xmlnode_get_tag_data(xmlnode_get_tag(results,"?var=secret"),"value"));
		room->secret = NULL;
	    }
	}

	if(j_strcmp(xmlnode_get_tag_data(xmlnode_get_tag(results,"?var=whois"),"value"), "anyone") == 0)
		room->visible = 1;
	else
		room->visible = 0;

	/* Send Status Alert */
	if(room->visible == 1 && room->visible != visible)
		con_send_room_status(room, STATUS_MUC_SHOWN_JID);
	else if(room->visible == 0 && room->visible != visible)
		con_send_room_status(room, STATUS_MUC_HIDDEN_JID);

	/* Set up log format and restart logging if necessary */
	if(xmlnode_get_tag(results,"?var=logformat"))
	{
	    if(j_strcmp(xmlnode_get_tag_data(xmlnode_get_tag(results,"?var=logformat"),"value"), "xml") == 0)
	    {
		if(room->logfile != NULL && room->logformat != LOG_XML)
		{
		    fclose(room->logfile);
                    room->logformat = LOG_XML;
		    con_room_log_new(room);
		}
		else
		{
		    room->logformat = LOG_XML;
		}
	    }
	    else if(j_strcmp(xmlnode_get_tag_data(xmlnode_get_tag(results,"?var=logformat"),"value"), "xhtml") == 0)
	    {
		if(room->logfile != NULL && room->logformat != LOG_XHTML)
		{
		    fclose(room->logfile);
                    room->logformat = LOG_XHTML;
		    con_room_log_new(room);
		}
		else
		{
		    room->logformat = LOG_XHTML;
		}
	    }
	    else
	    {
		if(room->logfile != NULL && room->logformat != LOG_TEXT)
		{
		    fclose(room->logfile);
                    room->logformat = LOG_TEXT;
		    con_room_log_new(room);
		}
		else

⌨️ 快捷键说明

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