📄 xdb.c
字号:
fulljid = jid_new(p, spools(p, "rooms@", master->i->id, p));
log_debug(NAME, "[%s] asked to get rooms from xdb ", FZONE);
/* Get master room list */
node = xdb_get(master->xdbc, fulljid, "muc:room:list");
if(node != NULL)
{
xmlnode_free(current);
for(current = xmlnode_get_firstchild(node); current != NULL; current = xmlnode_get_nextsibling(current))
{
if(xmlnode_get_attrib(current, "name") == 0)
{
log_debug(NAME, "[%s] skipping .. no name", FZONE);
continue;
}
roomid = xmlnode_get_attrib(current, "name");
log_debug(NAME, "[%s] asked to get room %s from xdb ", FZONE, roomid);
file = xmlnode_get_attrib(current, "jid");
if(roomid == NULL || file == NULL)
{
log_debug(NAME, "[%s] skipping .. no room/file", FZONE);
continue;
}
fulljid = jid_new(xmlnode_pool(node), spools(xmlnode_pool(node), file, xmlnode_pool(node)));
jidroom = jid_new(xmlnode_pool(node), spools(xmlnode_pool(node), roomid, xmlnode_pool(node)));
result = xdb_get(master->xdbc, fulljid, "muc:room:config");
if(result == NULL)
{
log_debug(NAME, "[%s] skipping .. no room config", FZONE);
continue;
}
room = con_room_new(master, jidroom, NULL, xmlnode_get_tag_data(result,"name"), xmlnode_get_tag_data(result, "secret"), j_atoi(xmlnode_get_tag_data(result, "private"), 0), 0, 0);
room->subjectlock = j_atoi(xmlnode_get_tag_data(result, "subjectlock"), 0);
room->maxusers = j_atoi(xmlnode_get_tag_data(result, "maxusers"), 30);
room->moderated = j_atoi(xmlnode_get_tag_data(result, "moderated"), 0);
room->defaulttype = j_atoi(xmlnode_get_tag_data(result, "defaulttype"), 0);
room->privmsg = j_atoi(xmlnode_get_tag_data(result, "privmsg"), 0);
room->invitation = j_atoi(xmlnode_get_tag_data(result, "invitation"), 0);
room->invites = j_atoi(xmlnode_get_tag_data(result, "invites"), 0);
room->legacy = j_atoi(xmlnode_get_tag_data(result, "legacy"), 1);
room->public = j_atoi(xmlnode_get_tag_data(result, "public"), room->master->public);
room->visible = j_atoi(xmlnode_get_tag_data(result, "visible"), 0);
room->persistant = j_atoi(xmlnode_get_tag_data(result, "persistant"), 0);
room->logformat = j_atoi(xmlnode_get_tag_data(result, "logformat"), LOG_TEXT);
if(j_strcmp(xmlnode_get_tag_data(result, "logging"), "1") == 0)
{
con_room_log_new(room);
if (room->logfile == NULL)
log_alert(NULL, "cannot open log file for room %s", jid_full(jid_fix(room->id)));
else
con_room_log(room, NULL, "LOGGING STARTED");
}
room->creator = jid_new(room->p, xmlnode_get_tag_data(result, "creator"));
room->description = pstrdup(room->p, xmlnode_get_tag_data(result, "description"));
room->name = pstrdup(room->p, xmlnode_get_tag_data(result, "name"));
room->note_join = pstrdup(room->p, xmlnode_get_tag_data(result, "notice/join"));
room->note_rename = pstrdup(room->p, xmlnode_get_tag_data(result, "notice/rename"));
room->note_leave = pstrdup(room->p, xmlnode_get_tag_data(result, "notice/leave"));
subject = pstrdup(room->p, xmlnode_get_tag_data(result, "subject"));
xmlnode_free(room->topic);
room->topic = xmlnode_new_tag("topic");
xmlnode_put_attrib(room->topic, "subject", subject);
xmlnode_insert_cdata(room->topic, "The topic has been set to: ", -1);
xmlnode_insert_cdata(room->topic, subject, -1);
xdb_room_lists_get(room);
xmlnode_free(result);
}
}
else
{
log_debug(NAME, "[%s] skipping .. no results", FZONE);
/* Set XDB, just in case */
xdb_set(master->xdbc, fulljid, "muc:room:list", NULL);
}
xmlnode_free(node);
xmlnode_free(current);
pool_free(p);
}
void xdb_room_clear(cnr room)
{
char *roomid;
char *host;
cni master;
jid store;
jid fulljid;
xmlnode node;
xmlnode item;
pool p;
if(room == NULL)
{
return;
}
p = pool_new();
master = room->master;
roomid = jid_full(jid_fix(room->id));
host = room->id->server;
fulljid = jid_new(p, spools(p, "rooms@", host, p));
store = jid_new(p, spools(p, shahash(roomid), "@", host, p));
log_debug(NAME, "[%s] asked to clear a room from xdb (%s)", FZONE, jid_full(jid_fix(room->id)));
/* Remove from rooms db */
node = xdb_get(master->xdbc, fulljid, "muc:room:list");
if(node != NULL)
{
item = xmlnode_get_tag(node, spools(p, "?jid=", jid_full(jid_fix(store)), p));
if(item)
{
log_debug(NAME, "[%s] Found (%s) in rooms.xml - removing", FZONE, jid_full(jid_fix(room->id)), jid_full(jid_fix(store)));
xmlnode_hide(item);
xdb_set(master->xdbc, fulljid, "muc:room:list", node);
}
else
{
log_debug(NAME, "[%s] (%s) not found in rooms.xml - ignoring", FZONE, jid_full(jid_fix(room->id)), jid_full(jid_fix(store)));
}
}
/* Clear lists */
xdb_set(master->xdbc, store, "muc:list:owner", NULL);
xdb_set(master->xdbc, store, "muc:list:admin", NULL);
xdb_set(master->xdbc, store, "muc:list:member", NULL);
xdb_set(master->xdbc, store, "muc:list:outcast", NULL);
/* Clear room config */
xdb_set(master->xdbc, store, "muc:room:config", NULL);
xmlnode_free(node);
pool_free(p);
return;
}
int set_data(cni master, char *nick, char *jabberid, xmlnode node, int remove)
{
xmlnode item;
xmlnode old;
int status;
jid fulljid, userjid;
char *current = NULL;
char *user = NULL;
char *host = NULL;
pool p;
if(master == NULL || ( nick == NULL && remove != 1 ) || jabberid == NULL)
{
return 0;
}
p = pool_new();
host = master->i->id;
fulljid = jid_new(p, spools(p, "registration@", host, p));
userjid = jid_new(p, jabberid);
if(nick)
{
log_debug(NAME, "[%s] asked to manage xdb nick(%s)", FZONE, nick);
user = pstrdup(p, nick);
for(current = user; *current != '\0'; current++)
*current = tolower(*current); /* lowercase the group name */
}
xmlnode_put_attrib(node, "xmlns", "muc:data");
old = xdb_get(master->xdbc, fulljid, "muc:data");
item = xmlnode_get_tag(old, spools(p, "?jid=", jid_full(jid_user(jid_fix(userjid))), p));
if(old == NULL)
old = xmlnode_new_tag("registered");
if(remove == 1)
{
log_debug(NAME, "[%s] asked to remove xdb info \n>%s<\n>%s< \n ", FZONE, xmlnode2str(old), xmlnode2str(item));
if(item)
xmlnode_hide(item);
}
else
{
log_debug(NAME, "[%s] asked to add xdb info \n>%s<\n>%s< \n ", FZONE, xmlnode2str(old), xmlnode2str(item));
xmlnode_hide(item);
item = xmlnode_new_tag("item");
xmlnode_put_attrib(item, "nick", nick);
xmlnode_put_attrib(item, "keynick", user);
xmlnode_put_attrib(item, "jid", jid_full(jid_user(jid_fix(userjid))));
if(node)
{
xmlnode_insert_node(item, node);
xmlnode_free(node);
}
xmlnode_insert_node(old, item);
xmlnode_free(item);
log_debug(NAME, "[%s] asked to add xdb info \n>%s<\n>%s< \n ", FZONE, xmlnode2str(old), xmlnode2str(item));
}
status = xdb_set(master->xdbc, fulljid, "muc:data", old);
log_debug(NAME, "[%s] xdb status(%d)", FZONE, status);
xmlnode_free(old);
pool_free(p);
return status;
}
xmlnode get_data_bynick(cni master, char *nick)
{
xmlnode node;
xmlnode result;
jid fulljid;
char *current, *user, *host;
pool p;
log_debug(NAME, "[%s] asked to find xdb nick (%s)", FZONE, nick);
if(master == NULL || nick == NULL)
{
return NULL;
}
p = pool_new();
user = pstrdup(p, nick);
host = master->i->id;
for(current = user; *current != '\0'; current++)
*current = tolower(*current); /* lowercase the group name */
fulljid = jid_new(p, spools(p, "registration@", host, p));
node = xdb_get(master->xdbc, fulljid, "muc:data");
/* Set blank data in case file doesn't exist */
if(node == NULL)
{
xdb_set(master->xdbc, fulljid, "muc:data", NULL);
pool_free(p);
return NULL;
}
result = xmlnode_dup(xmlnode_get_tag(node, spools(p, "?keynick=", user, p)));
log_debug(NAME, "[%s] asked to find xdb nick for %s - (%s)", FZONE, user, xmlnode2str(result));
xmlnode_free(node);
pool_free(p);
return result;
}
xmlnode get_data_byjid(cni master, char *jabberid)
{
xmlnode node;
xmlnode result;
jid fulljid, userjid;
char *host;
pool p;
log_debug(NAME, "[%s] asked to find xdb jid (%s)", FZONE, jabberid);
if(master == NULL || jabberid == NULL)
{
return NULL;
}
p = pool_new();
host = master->i->id;
userjid = jid_new(p, jabberid);
fulljid = jid_new(p, spools(p, "registration@", host, p));
node = xdb_get(master->xdbc, fulljid, "muc:data");
/* Set blank data in case file doesn't exist */
if(node == NULL)
{
xdb_set(master->xdbc, fulljid, "muc:data", NULL);
pool_free(p);
return NULL;
}
result = xmlnode_dup(xmlnode_get_tag(node, spools(p, "?jid=", jid_full(jid_user(jid_fix(userjid))), p)));
log_debug(NAME, "[%s] asked to find xdb jid for %s - (%s)", FZONE, jid_full(jid_user(jid_fix(userjid))), xmlnode2str(result));
xmlnode_free(node);
pool_free(p);
return result;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -