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

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

int xdb_room_config(cnr room)
{
    char *roomid;
    char *host;
    char temp[10];
    cni master;
    int status;
    jid store;
    xmlnode node;
    xmlnode element;

    if(room == NULL)
    {
	return -1;
    }

    master = room->master;
    roomid = jid_full(jid_fix(room->id));
    host = room->id->server;

    node = xmlnode_new_tag("room");
    store = jid_new(xmlnode_pool(node), spools(xmlnode_pool(node), shahash(roomid), "@", host, xmlnode_pool(node)));

    xmlnode_insert_cdata(xmlnode_insert_tag(node, "name"), room->name, -1);
    xmlnode_insert_cdata(xmlnode_insert_tag(node, "secret"), room->secret, -1);
    xmlnode_insert_cdata(xmlnode_insert_tag(node, "description"), room->description, -1);
    xmlnode_insert_cdata(xmlnode_insert_tag(node, "subject"), xmlnode_get_attrib(room->topic,"subject"), -1);
    xmlnode_insert_cdata(xmlnode_insert_tag(node, "creator"), jid_full(jid_fix(room->creator)), -1);
    xmlnode_insert_cdata(xmlnode_insert_tag(node, "private"), itoa(room->private, temp), -1);

    element = xmlnode_insert_tag(node, "notice");
    xmlnode_insert_cdata(xmlnode_insert_tag(element, "leave"), room->note_leave, -1);
    xmlnode_insert_cdata(xmlnode_insert_tag(element, "join"), room->note_join, -1);
    xmlnode_insert_cdata(xmlnode_insert_tag(element, "rename"), room->note_rename, -1);

    xmlnode_insert_cdata(xmlnode_insert_tag(node, "public"), itoa(room->public, temp), -1);
    xmlnode_insert_cdata(xmlnode_insert_tag(node, "subjectlock"), itoa(room->subjectlock, temp), -1);
    xmlnode_insert_cdata(xmlnode_insert_tag(node, "maxusers"), itoa(room->maxusers, temp), -1);
    xmlnode_insert_cdata(xmlnode_insert_tag(node, "persistant"), itoa(room->persistant, temp), -1);
    xmlnode_insert_cdata(xmlnode_insert_tag(node, "moderated"), itoa(room->moderated, temp), -1);
    xmlnode_insert_cdata(xmlnode_insert_tag(node, "defaulttype"), itoa(room->defaulttype, temp), -1);
    xmlnode_insert_cdata(xmlnode_insert_tag(node, "privmsg"), itoa(room->privmsg, temp), -1);
    xmlnode_insert_cdata(xmlnode_insert_tag(node, "invitation"), itoa(room->invitation, temp), -1);
    xmlnode_insert_cdata(xmlnode_insert_tag(node, "invites"), itoa(room->invites, temp), -1);
    xmlnode_insert_cdata(xmlnode_insert_tag(node, "legacy"), itoa(room->legacy, temp), -1);
    xmlnode_insert_cdata(xmlnode_insert_tag(node, "visible"), itoa(room->visible, temp), -1);
    xmlnode_insert_cdata(xmlnode_insert_tag(node, "logformat"), itoa(room->logformat, temp), -1);

    if(room->logfile)
	xmlnode_insert_cdata(xmlnode_insert_tag(node, "logging"), "1", -1);
    else
	xmlnode_insert_cdata(xmlnode_insert_tag(node, "logging"), "0", -1);

    status = xdb_set(master->xdbc, store, "muc:room:config", node);
    
    xmlnode_free(node);

    return status;
}

void _xdb_put_list(const char *key, void *data, void *arg)
{
    xmlnode result = (xmlnode)arg;
    xmlnode item;
    jid id;
    char *jabberid;

    jabberid = pstrdup(xmlnode_pool(result), key);

    /* cnu is only available if resource defined in jabber id */
    id = jid_new(xmlnode_pool(result), jabberid);

    if(id == NULL)
    {
        log_debug(NAME, "[%s] Somethings not right here - <%s>", FZONE, jabberid);
    }
    else 
    {
	item = xmlnode_new_tag("item");
	xmlnode_put_attrib(item, "jid", jabberid);
        xmlnode_insert_node(result, item);
        xmlnode_free(item);
    }
}

void _xdb_put_outcast_list(const char *key, void *data, void *arg)
{
    xmlnode result = (xmlnode)arg;
    xmlnode info = (xmlnode)data;
    xmlnode item;
    jid id;
    char *jabberid;

    jabberid = pstrdup(xmlnode_pool(result), key);

    /* cnu is only available if resource defined in jabber id */
    id = jid_new(xmlnode_pool(result), jabberid);

    if(id == NULL)
    {
        log_debug(NAME, "[%s] Somethings not right here - <%s>", FZONE, jabberid);
    }
    else 
    {
	item = xmlnode_new_tag("item");
	xmlnode_put_attrib(item, "jid", jabberid);
	xmlnode_insert_node(item, info);
        xmlnode_insert_node(result, item);

        xmlnode_free(info);
        xmlnode_free(item);
    }
}


int xdb_room_lists_set(cnr room)
{
    char *roomid;
    char *host;
    cni master;
    int status;
    jid store;
    xmlnode node;
    pool p;

    if(room == NULL)
    {
	return -1;
    }

    p = pool_new();
    master = room->master;
    roomid = jid_full(jid_fix(room->id));
    host = room->id->server;

    store = jid_new(p, spools(p, shahash(roomid), "@", host, p));

    node = xmlnode_new_tag("list");
    htb_walk(&room->owner, _xdb_put_list, (void*)node);
    status = xdb_set(master->xdbc, store, "muc:list:owner", node);
    
    node = xmlnode_new_tag("list");
    htb_walk(&room->admin, _xdb_put_list, (void*)node);
    status = xdb_set(master->xdbc, store, "muc:list:admin", node);
    
    node = xmlnode_new_tag("list");
    htb_walk(&room->member, _xdb_put_list, (void*)node);
    status = xdb_set(master->xdbc, store, "muc:list:member", node);

    node = xmlnode_new_tag("list");
    htb_walk(&room->outcast, _xdb_put_outcast_list, (void*)node);
    status = xdb_set(master->xdbc, store, "muc:list:outcast", node);

    xmlnode_free(node);
    pool_free(p);
    return 1;
}

void xdb_room_set(cnr room)
{
    pool p;
    char *host;
    jid fulljid;
    jid roomid;
    cni master;
    xmlnode node;
    xmlnode item;

    if(room == NULL)
    {
        return;
    }

    p = pool_new();
    master = room->master;
    host = room->id->server;

    fulljid = jid_new(p, spools(p, "rooms@", host, p));
    roomid = jid_new(p, spools(p, shahash(jid_full(jid_fix(room->id))),"@", host, p));

    node = xdb_get(master->xdbc, fulljid, "muc:room:list");

    if(node == NULL)
    {
        node = xmlnode_new_tag("registered");
    }

    item = xmlnode_get_tag(node, spools(p, "?jid=", jid_full(jid_fix(roomid)), p));

    if(item == NULL)
    {
	item = xmlnode_insert_tag(node, "item");
	xmlnode_put_attrib(item, "name", jid_full(jid_fix(room->id)));
	xmlnode_put_attrib(item, "jid", jid_full(jid_fix(roomid)));
	xdb_set(master->xdbc, fulljid, "muc:room:list", node);
    }

    xdb_room_config(room);
    xdb_room_lists_set(room);

    xmlnode_free(node);
    pool_free(p);

    return;
}

void _xdb_add_list(htable hash, xmlnode node)
{
    char *user;
    xmlnode current;
    jid userid;

    if(node == NULL)
    {
	return;
    }

    for(current = xmlnode_get_firstchild(node); current != NULL; current = xmlnode_get_nextsibling(current))
    {
	user = xmlnode_get_attrib(current, "jid");

	if (user)
	{
	    userid = jid_new(xmlnode_pool(node), user);
            add_affiliate(hash, userid, xmlnode_get_tag(current, "reason"));
	}
    }

    xmlnode_free(current);
    return;
}

int xdb_room_lists_get(cnr room)
{
    char *roomid;
    char *host;
    cni master;
    jid store;
    xmlnode node;
    pool p;

    if(room == NULL)
    {
	return -1;
    }

    log_debug(NAME, "[%s] asked to restore rooms lists for %s ", FZONE, jid_full(jid_fix(room->id)));

    p = pool_new();
    master = room->master;
    roomid = jid_full(jid_fix(room->id));
    host = room->id->server;

    store = jid_new(p, spools(p, shahash(roomid), "@", host, p));

    node = xdb_get(master->xdbc, store, "muc:list:owner");
    _xdb_add_list(room->owner, node);

    node = xdb_get(master->xdbc, store, "muc:list:admin");
    _xdb_add_list(room->admin, node);

    node = xdb_get(master->xdbc, store, "muc:list:member");
    _xdb_add_list(room->member, node);

    node = xdb_get(master->xdbc, store, "muc:list:outcast");
    _xdb_add_list(room->outcast, node);

    xmlnode_free(node);
    pool_free(p);
    return 1;
}

void xdb_rooms_get(cni master)
{
    char *file, *roomid, *subject;
    cnr room;
    jid jidroom;
    jid fulljid;
    xmlnode node = NULL;
    xmlnode current = NULL;
    xmlnode result = NULL;
    pool p;

    if(master == NULL)
    {
	return;
    }

    p = pool_new();

⌨️ 快捷键说明

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