📄 conference_user.c
字号:
/* --------------------------------------------------------------------------
*
* 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"
//extern int deliver__flag;
cnu con_user_new(cnr room, jid id)
{
pool p;
cnu user;
char *key;
log_debug(NAME, "[%s] adding user %s to room %s", FZONE, jid_full(jid_fix(id)), jid_full(jid_fix(room->id)));
p = pool_new(); /* Create pool for user struct */
user = pmalloco(p, sizeof(_cnu));
log_debug(NAME, "[%s] Malloc: _cnu = %d", FZONE, sizeof(_cnu));
user->p = p;
user->realid = jid_new(user->p, jid_full(jid_fix(id)));
user->room = room;
user->presence = jutil_presnew(JPACKET__AVAILABLE, NULL, NULL);
key = j_strdup(jid_full(jid_fix(user->realid)));
htb_put(&room->remote, key, (void*)user);
free(key);
/* Add this user to the room roster */
add_roster(room, user->realid);
/* If admin, switch */
if(is_admin(room, user->realid) && !is_moderator(room, user->realid))
{
log_debug(NAME, "[%s] Adding %s to moderator list", FZONE, jid_full(jid_fix(user->realid)));
/* Update affiliate info */
add_affiliate(room->admin, user->realid, NULL);
add_role(room->moderator, user);
}
else if(is_member(room, user->realid) && !is_admin(room, user->realid))
{
/* Update affiliate information */
add_affiliate(room->member, user->realid, NULL);
}
else if(room->moderated == 1 && room->defaulttype == 1)
{
/* Auto-add to participant list if moderated and member type is default */
add_role(room->participant, user);
}
return user;
}
void _con_user_history_send(cnu to, xmlnode node)
{
if(to == NULL || node == NULL)
{
return;
}
xmlnode_put_attrib(node, "to", jid_full(jid_fix(to->realid)));
deliver(dpacket_new(node), NULL);
return;
}
void _con_user_nick(const char *key, void *data, void *arg)
{
cnu to = (cnu)data;
cnu from = (cnu)arg;
char *old, *status, *reason, *actor;
xmlnode node;
xmlnode result;
xmlnode element;
jid fullid;
/* send unavail pres w/ old nick */
if((old = xmlnode_get_attrib(from->nick,"old")) != NULL)
{
if(xmlnode_get_data(from->nick) != NULL)
{
node = jutil_presnew(JPACKET__UNAVAILABLE, jid_full(jid_fix(to->realid)), NULL);
}
else
{
node = xmlnode_dup(from->presence);
xmlnode_put_attrib(node, "to", jid_full(jid_fix(to->realid)));
}
fullid = jid_new(xmlnode_pool(node), jid_full(from->localid));
jid_set(fullid, old, JID_RESOURCE);
xmlnode_put_attrib(node, "from", jid_full(jid_fix(fullid)));
status = xmlnode_get_attrib(from->nick,"status");
log_debug(NAME, "[%s] status = %s", FZONE, status);
reason = xmlnode_get_attrib(from->nick,"reason");
actor = xmlnode_get_attrib(from->nick,"actor");
if(xmlnode_get_data(from->nick) != NULL)
{
log_debug(NAME, "[%s] Extended presence - Nick Change", FZONE);
result = add_extended_presence(from, to, node, STATUS_MUC_NICKCHANGE, NULL, NULL);
}
else
{
log_debug(NAME, "[%s] Extended presence", FZONE);
result = add_extended_presence(from, to, node, status, reason, actor);
}
deliver(dpacket_new(result), NULL);
xmlnode_free(node);
}
/* if there's a new nick, broadcast that too */
if(xmlnode_get_data(from->nick) != NULL)
{
status = xmlnode_get_attrib(from->nick,"status");
log_debug(NAME, "[%s] status = %s/%s", FZONE, status, STATUS_MUC_CREATED);
if(j_strcmp(status, STATUS_MUC_CREATED) == 0)
node = add_extended_presence(from, to, NULL, status, NULL, NULL);
else
node = add_extended_presence(from, to, NULL, NULL, NULL, NULL);
/* Hide x:delay, not needed */
element = xmlnode_get_tag(node, "x?xmlns=jabber:x:delay");
if(element)
xmlnode_hide(element);
xmlnode_put_attrib(node, "to", jid_full(jid_fix(to->realid)));
fullid = jid_new(xmlnode_pool(node), jid_full(jid_fix(from->localid)));
jid_set(fullid, xmlnode_get_data(from->nick), JID_RESOURCE);
xmlnode_put_attrib(node, "from", jid_full(jid_fix(fullid)));
deliver(dpacket_new(node), NULL);
}
}
void con_user_nick(cnu user, char *nick, xmlnode data)
{
xmlnode node;
char *status, *reason, *actor;
cnr room = user->room;
log_debug(NAME, "[%s] in room %s changing nick for user %s to %s from %s", FZONE, jid_full(jid_fix(room->id)), jid_full(jid_fix(user->realid)), nick, xmlnode_get_data(user->nick));
node = xmlnode_new_tag("n");
xmlnode_put_attrib(node, "old", xmlnode_get_data(user->nick));
if (data)
{
status = xmlnode_get_attrib(data, "status");
reason = xmlnode_get_data(data);
actor = xmlnode_get_attrib(data, "actor");
if(status)
xmlnode_put_attrib(node, "status", status);
if(reason)
xmlnode_put_attrib(node, "reason", reason);
if(actor)
xmlnode_put_attrib(node, "actor", actor);
log_debug(NAME, "[%s] status = %s", FZONE, status);
}
xmlnode_insert_cdata(node,nick,-1);
xmlnode_free(user->nick);
user->nick = node;
//deliver__flag = 0;
htb_walk(&room->local, _con_user_nick, (void*)user);
//deliver__flag = 1;
deliver(NULL, NULL);
/* send nick change notice if availble */
if(room->note_rename != NULL && nick != NULL && xmlnode_get_attrib(node, "old") != NULL && j_strlen(room->note_rename) > 0)
con_room_send(room, jutil_msgnew("groupchat", NULL, NULL, spools(xmlnode_pool(node), xmlnode_get_attrib(node, "old"), " ", room->note_rename, " ", nick, xmlnode_pool(node))), SEND_LEGACY);
}
void _con_user_enter(const char *key, void *data, void *arg)
{
cnu from = (cnu)data;
cnu to = (cnu)arg;
xmlnode node;
jid fullid;
/* mirror */
if(from == to)
return;
node = add_extended_presence(from, to, NULL, NULL, NULL, NULL);
xmlnode_put_attrib(node, "to", jid_full(jid_fix(to->realid)));
fullid = jid_new(xmlnode_pool(node), jid_full(jid_fix(from->localid)));
jid_set(fullid, xmlnode_get_data(from->nick), JID_RESOURCE);
xmlnode_put_attrib(node, "from", jid_full(jid_fix(fullid)));
deliver(dpacket_new(node), NULL);
}
void con_user_enter(cnu user, char *nick, int created)
{
xmlnode node;
xmlnode message;
char *key;
int h, tflag = 0;
cnr room = user->room;
user->localid = jid_new(user->p, jid_full(jid_fix(room->id)));
jid_set(user->localid, shahash(jid_full(jid_fix(user->realid))), JID_RESOURCE);
key = j_strdup(user->localid->resource);
htb_put(&room->local, key, (void*)user);
free(key);
room->count++;
log_debug(NAME, "[%s] officiating user %s in room (created = %d) %s as %s/%s", FZONE, jid_full(jid_fix(user->realid)), created, jid_full(jid_fix(room->id)), nick, user->localid->resource);
/* Send presence back to user to confirm presence received */
if(created == 1)
{
/* Inform if room just created */
node = xmlnode_new_tag("reason");
xmlnode_put_attrib(node, "status", STATUS_MUC_CREATED);
con_user_nick(user, nick, node); /* pushes to everyone (including ourselves) our entrance */
xmlnode_free(node);
}
else
{
con_user_nick(user, nick, NULL); /* pushes to everyone (including ourselves) our entrance */
}
/* Send Room MOTD */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -