1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-27 13:26:38 +02:00

Remove jabber plugin (will be replaced by script)

This commit is contained in:
Sebastien Helleu
2009-06-14 14:17:17 +02:00
parent 62559459df
commit fe980f2863
52 changed files with 1548 additions and 12220 deletions
-8
View File
@@ -58,14 +58,6 @@ IF(NOT DISABLE_IRC)
ADD_SUBDIRECTORY( irc )
ENDIF(NOT DISABLE_IRC)
IF(ENABLE_JABBER)
# Check for iksemel library
FIND_PACKAGE(Iksemel)
IF(IKSEMEL_FOUND)
ADD_SUBDIRECTORY( jabber )
ENDIF(IKSEMEL_FOUND)
ENDIF(ENABLE_JABBER)
IF(NOT DISABLE_LOGGER)
ADD_SUBDIRECTORY( logger )
ENDIF(NOT DISABLE_LOGGER)
+1 -6
View File
@@ -50,10 +50,6 @@ if PLUGIN_IRC
irc_dir = irc
endif
if PLUGIN_JABBER
jabber_dir = jabber
endif
if PLUGIN_LOGGER
logger_dir = logger
endif
@@ -87,8 +83,7 @@ xfer_dir = xfer
endif
SUBDIRS = . $(alias_dir) $(aspell_dir) $(charset_dir) $(demo_dir) $(fifo_dir) \
$(irc_dir) $(jabber_dir) $(logger_dir) $(relay_dir) $(script_dir) \
$(xfer_dir)
$(irc_dir) $(logger_dir) $(relay_dir) $(script_dir) $(xfer_dir)
EXTRA_DIST = CMakeLists.txt
-45
View File
@@ -1,45 +0,0 @@
# Copyright (c) 2009 FlashCode <flashcode@flashtux.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
ADD_LIBRARY(jabber MODULE
jabber.c jabber.h
jabber-bar-item.c jabber-bar-item.h
jabber-buddy.c jabber-buddy.h
jabber-buffer.c jabber-buffer.h
jabber-command.c jabber-command.h
jabber-completion.c jabber-completion.h
jabber-config.c jabber-config.h
jabber-debug.c jabber-debug.h
jabber-display.c jabber-display.h
jabber-info.c jabber-info.h
jabber-input.c jabber-input.h
jabber-muc.c jabber-muc.h
jabber-server.c jabber-server.h
jabber-upgrade.c jabber-upgrade.h
jabber-xmpp.c jabber-xmpp.h)
SET_TARGET_PROPERTIES(jabber PROPERTIES PREFIX "")
CHECK_INCLUDE_FILES("regex.h" HAVE_REGEX_H)
CHECK_FUNCTION_EXISTS(regexec HAVE_REGEXEC)
IF(GNUTLS_FOUND)
INCLUDE_DIRECTORIES(${GNUTLS_INCLUDE_PATH} ${IKSEMEL_INCLUDE_PATH})
TARGET_LINK_LIBRARIES(jabber ${GNUTLS_LIBRARY} ${IKSEMEL_LIBRARY})
ELSE(GNUTLS_FOUND)
TARGET_LINK_LIBRARIES(jabber ${IKSEMEL_LIBRARY})
ENDIF(GNUTLS_FOUND)
INSTALL(TARGETS jabber LIBRARY DESTINATION lib/${PROJECT_NAME}/plugins)
-57
View File
@@ -1,57 +0,0 @@
# Copyright (c) 2009 FlashCode <flashcode@flashtux.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
INCLUDES = -DLOCALEDIR=\"$(datadir)/locale\" $(GNUTLS_CFLAGS) $(IKSEMEL_CFLAGS)
libdir = ${weechat_libdir}/plugins
lib_LTLIBRARIES = jabber.la
jabber_la_SOURCES = jabber.c \
jabber.h \
jabber-bar-item.c \
jabber-bar-item.h \
jabber-buddy.c \
jabber-buddy.h \
jabber-buffer.c \
jabber-buffer.h \
jabber-command.c \
jabber-command.h \
jabber-completion.c \
jabber-completion.h \
jabber-config.c \
jabber-config.h \
jabber-debug.c \
jabber-debug.h \
jabber-display.c \
jabber-display.h \
jabber-info.c \
jabber-info.h \
jabber-input.c \
jabber-input.h \
jabber-muc.c \
jabber-muc.h \
jabber-server.c \
jabber-server.h \
jabber-upgrade.c \
jabber-upgrade.h \
jabber-xmpp.c \
jabber-xmpp.h
jabber_la_LDFLAGS = -module
jabber_la_LIBADD = $(JABBER_LFLAGS) $(GNUTLS_LFLAGS) $(IKSEMEL_LFLAGS)
EXTRA_DIST = CMakeLists.txt
-190
View File
@@ -1,190 +0,0 @@
/*
* Copyright (c) 2009 by FlashCode <flashcode@flashtux.org>
* See README for License detail, AUTHORS for developers list.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* jabber-bar-item.c: bar items for Jabber plugin */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "../weechat-plugin.h"
#include "jabber.h"
#include "jabber-buffer.h"
#include "jabber-config.h"
#include "jabber-server.h"
#include "jabber-muc.h"
/*
* jabber_bar_item_buffer_name: bar item with buffer name
*/
char *
jabber_bar_item_buffer_name (void *data, struct t_gui_bar_item *item,
struct t_gui_window *window)
{
char buf[512], buf_name[256], modes[128], away[128];
const char *name;
int part_from_muc;
struct t_gui_buffer *buffer;
struct t_jabber_server *server;
struct t_jabber_muc *muc;
/* make C compiler happy */
(void) data;
(void) item;
if (!window)
window = weechat_current_window ();
buf_name[0] = '\0';
modes[0] = '\0';
away[0] = '\0';
buffer = weechat_window_get_pointer (window, "buffer");
if (buffer)
{
jabber_buffer_get_server_muc (buffer, &server, &muc);
if (server || muc)
{
if (server && !muc)
{
if (weechat_config_boolean (jabber_config_look_one_server_buffer))
{
snprintf (buf_name, sizeof (buf_name), "%s%s[<%s%s%s>]",
_("servers"),
JABBER_COLOR_BAR_DELIM,
JABBER_COLOR_STATUS_NAME,
(jabber_current_server) ? jabber_current_server->name : "-",
JABBER_COLOR_BAR_DELIM);
}
else
{
snprintf (buf_name, sizeof (buf_name), "%s%s[%s%s%s]",
_("server"),
JABBER_COLOR_BAR_DELIM,
JABBER_COLOR_STATUS_NAME,
server->name,
JABBER_COLOR_BAR_DELIM);
}
}
else
{
if (muc)
{
part_from_muc = ((muc->type == JABBER_MUC_TYPE_MUC)
&& !muc->buddies);
snprintf (buf_name, sizeof (buf_name),
"%s%s%s%s%s/%s%s%s%s",
(part_from_muc) ? JABBER_COLOR_BAR_DELIM : "",
(part_from_muc) ? "(" : "",
JABBER_COLOR_STATUS_NAME,
server->name,
JABBER_COLOR_BAR_DELIM,
JABBER_COLOR_STATUS_NAME,
muc->name,
(part_from_muc) ? JABBER_COLOR_BAR_DELIM : "",
(part_from_muc) ? ")" : "");
if (!part_from_muc
&& weechat_config_boolean (jabber_config_look_display_muc_modes)
&& muc->modes && muc->modes[0]
&& (strcmp (muc->modes, "+") != 0))
{
snprintf (modes, sizeof (modes),
"%s(%s%s%s)",
JABBER_COLOR_BAR_DELIM,
JABBER_COLOR_STATUS_NAME,
muc->modes,
JABBER_COLOR_BAR_DELIM);
}
}
}
if (server && server->is_away)
{
snprintf (away, sizeof (away), " %s(%s%s%s)",
JABBER_COLOR_BAR_DELIM,
JABBER_COLOR_BAR_FG,
_("away"),
JABBER_COLOR_BAR_DELIM);
}
}
else
{
name = weechat_buffer_get_string (buffer, "name");
if (name)
snprintf (buf_name, sizeof (buf_name), "%s", name);
}
snprintf (buf, sizeof (buf), "%s%s%s%s",
JABBER_COLOR_STATUS_NAME,
buf_name,
modes,
away);
return strdup (buf);
}
return NULL;
}
/*
* jabber_bar_item_input_prompt: bar item with input prompt
*/
char *
jabber_bar_item_input_prompt (void *data, struct t_gui_bar_item *item,
struct t_gui_window *window)
{
struct t_gui_buffer *buffer;
struct t_jabber_server *server;
const char *local_name;
/* make C compiler happy */
(void) data;
(void) item;
if (!window)
window = weechat_current_window ();
buffer = weechat_window_get_pointer (window, "buffer");
if (buffer)
{
jabber_buffer_get_server_muc (buffer, &server, NULL);
if (!server)
return NULL;
local_name = jabber_server_get_local_name (server);
return (local_name) ? strdup (local_name) : NULL;
}
return NULL;
}
/*
* jabber_bar_item_init: initialize Jabber bar items
*/
void
jabber_bar_item_init ()
{
weechat_bar_item_new ("buffer_name", &jabber_bar_item_buffer_name, NULL);
weechat_bar_item_new ("input_prompt", &jabber_bar_item_input_prompt, NULL);
}
-25
View File
@@ -1,25 +0,0 @@
/*
* Copyright (c) 2009 by FlashCode <flashcode@flashtux.org>
* See README for License detail, AUTHORS for developers list.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __WEECHAT_JABBER_BAR_ITEM_H
#define __WEECHAT_JABBER_BAR_ITEM_H 1
extern void jabber_bar_item_init ();
#endif /* jabber-bar-item.h */
-727
View File
@@ -1,727 +0,0 @@
/*
* Copyright (c) 2009 by FlashCode <flashcode@flashtux.org>
* See README for License detail, AUTHORS for developers list.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* jabber-buddy.c: manages buddies list for servers and MUCs */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include "../weechat-plugin.h"
#include "jabber.h"
#include "jabber-buddy.h"
#include "jabber-config.h"
#include "jabber-server.h"
#include "jabber-muc.h"
/*
* jabber_buddy_valid: check if a buddy pointer exists for a server or a muc
* return 1 if buddy exists
* 0 if buddy is not found
*/
int
jabber_buddy_valid (struct t_jabber_server *server, struct t_jabber_muc *muc,
struct t_jabber_buddy *buddy)
{
struct t_jabber_buddy *ptr_buddy;
if (server)
{
for (ptr_buddy = server->buddies; ptr_buddy;
ptr_buddy = ptr_buddy->next_buddy)
{
if (ptr_buddy == buddy)
return 1;
}
}
if (muc)
{
for (ptr_buddy = muc->buddies; ptr_buddy;
ptr_buddy = ptr_buddy->next_buddy)
{
if (ptr_buddy == buddy)
return 1;
}
}
/* buddy not found */
return 0;
}
/*
* jabber_buddy_find_color: find a color for a buddy (according to buddy letters)
*/
const char *
jabber_buddy_find_color (struct t_jabber_buddy *buddy)
{
int i, color;
char color_name[64];
color = 0;
for (i = strlen (buddy->name) - 1; i >= 0; i--)
{
color += (int)(buddy->name[i]);
}
color = (color %
weechat_config_integer (weechat_config_get ("weechat.look.color_nicks_number")));
snprintf (color_name, sizeof (color_name),
"chat_buddy_color%02d", color + 1);
return weechat_color (color_name);
}
/*
* jabber_buddy_get_gui_infos: get GUI infos for a buddy (sort_index, prefix,
* prefix color)
*/
void
jabber_buddy_get_gui_infos (struct t_jabber_buddy *buddy,
char *prefix, int *prefix_color,
struct t_gui_buffer *buffer,
struct t_gui_nick_group **group)
{
if (buddy->flags & JABBER_BUDDY_CHANOWNER)
{
if (prefix)
prefix[0] = '~';
if (prefix_color)
*prefix_color = 1;
if (buffer && group)
*group = weechat_nicklist_search_group (buffer, NULL,
JABBER_BUDDY_GROUP_OP);
}
else if (buddy->flags & JABBER_BUDDY_CHANADMIN)
{
if (prefix)
prefix[0] = '&';
if (prefix_color)
*prefix_color = 1;
if (buffer && group)
*group = weechat_nicklist_search_group (buffer, NULL,
JABBER_BUDDY_GROUP_OP);
}
else if (buddy->flags & JABBER_BUDDY_CHANADMIN2)
{
if (prefix)
prefix[0] = '!';
if (prefix_color)
*prefix_color = 1;
if (buffer && group)
*group = weechat_nicklist_search_group (buffer, NULL,
JABBER_BUDDY_GROUP_OP);
}
else if (buddy->flags & JABBER_BUDDY_OP)
{
if (prefix)
prefix[0] = '@';
if (prefix_color)
*prefix_color = 1;
if (buffer && group)
*group = weechat_nicklist_search_group (buffer, NULL,
JABBER_BUDDY_GROUP_OP);
}
else if (buddy->flags & JABBER_BUDDY_HALFOP)
{
if (prefix)
prefix[0] = '%';
if (prefix_color)
*prefix_color = 2;
if (buffer && group)
*group = weechat_nicklist_search_group (buffer, NULL,
JABBER_BUDDY_GROUP_HALFOP);
}
else if (buddy->flags & JABBER_BUDDY_VOICE)
{
if (prefix)
prefix[0] = '+';
if (prefix_color)
*prefix_color = 3;
if (buffer && group)
*group = weechat_nicklist_search_group (buffer, NULL,
JABBER_BUDDY_GROUP_VOICE);
}
else if (buddy->flags & JABBER_BUDDY_CHANUSER)
{
if (prefix)
prefix[0] = '-';
if (prefix_color)
*prefix_color = 4;
if (buffer && group)
*group = weechat_nicklist_search_group (buffer, NULL,
JABBER_BUDDY_GROUP_CHANUSER);
}
else
{
if (prefix)
prefix[0] = ' ';
if (prefix_color)
*prefix_color = 0;
if (buffer && group)
*group = weechat_nicklist_search_group (buffer, NULL,
JABBER_BUDDY_GROUP_NORMAL);
}
}
/*
* jabber_buddy_new: allocate a new buddy for a muc and add it to the buddy list
*/
struct t_jabber_buddy *
jabber_buddy_new (struct t_jabber_server *server, struct t_jabber_muc *muc,
const char *buddy_name, int is_chanowner, int is_chanadmin,
int is_chanadmin2, int is_op, int is_halfop, int has_voice,
int is_chanuser, int is_away)
{
struct t_jabber_buddy *new_buddy, *ptr_buddy;
char prefix[2], str_prefix_color[64];
const char *local_name;
int prefix_color;
struct t_gui_buffer *ptr_buffer;
struct t_gui_nick_group *ptr_group;
ptr_buffer = (muc) ? muc->buffer : server->buffer;
/* buddy already exists on this muc? */
if (muc)
ptr_buddy = jabber_buddy_search (NULL, muc, buddy_name);
else
ptr_buddy = jabber_buddy_search (server, NULL, buddy_name);
if (ptr_buddy)
{
/* remove old buddy from buddylist */
jabber_buddy_get_gui_infos (ptr_buddy, prefix,
&prefix_color, ptr_buffer, &ptr_group);
weechat_nicklist_remove_nick (ptr_buffer,
weechat_nicklist_search_nick (ptr_buffer,
ptr_group,
ptr_buddy->name));
/* update buddy */
JABBER_BUDDY_SET_FLAG(ptr_buddy, is_chanowner, JABBER_BUDDY_CHANOWNER);
JABBER_BUDDY_SET_FLAG(ptr_buddy, is_chanadmin, JABBER_BUDDY_CHANADMIN);
JABBER_BUDDY_SET_FLAG(ptr_buddy, is_chanadmin2, JABBER_BUDDY_CHANADMIN2);
JABBER_BUDDY_SET_FLAG(ptr_buddy, is_op, JABBER_BUDDY_OP);
JABBER_BUDDY_SET_FLAG(ptr_buddy, is_halfop, JABBER_BUDDY_HALFOP);
JABBER_BUDDY_SET_FLAG(ptr_buddy, has_voice, JABBER_BUDDY_VOICE);
JABBER_BUDDY_SET_FLAG(ptr_buddy, is_chanuser, JABBER_BUDDY_CHANUSER);
JABBER_BUDDY_SET_FLAG(ptr_buddy, is_away, JABBER_BUDDY_AWAY);
/* add new buddy in buddylist */
prefix[0] = ' ';
prefix[1] = '\0';
jabber_buddy_get_gui_infos (ptr_buddy, prefix,
&prefix_color, ptr_buffer, &ptr_group);
snprintf (str_prefix_color, sizeof (str_prefix_color),
"weechat.color.nicklist_prefix%d",
prefix_color);
weechat_nicklist_add_nick (ptr_buffer, ptr_group,
ptr_buddy->name,
(is_away) ?
"weechat.color.nicklist_away" : "bar_fg",
prefix, str_prefix_color, 1);
return ptr_buddy;
}
/* alloc memory for new buddy */
if ((new_buddy = malloc (sizeof (*new_buddy))) == NULL)
return NULL;
/* initialize new buddy */
new_buddy->name = strdup (buddy_name);
new_buddy->host = NULL;
new_buddy->flags = 0;
JABBER_BUDDY_SET_FLAG(new_buddy, is_chanowner, JABBER_BUDDY_CHANOWNER);
JABBER_BUDDY_SET_FLAG(new_buddy, is_chanadmin, JABBER_BUDDY_CHANADMIN);
JABBER_BUDDY_SET_FLAG(new_buddy, is_chanadmin2, JABBER_BUDDY_CHANADMIN2);
JABBER_BUDDY_SET_FLAG(new_buddy, is_op, JABBER_BUDDY_OP);
JABBER_BUDDY_SET_FLAG(new_buddy, is_halfop, JABBER_BUDDY_HALFOP);
JABBER_BUDDY_SET_FLAG(new_buddy, has_voice, JABBER_BUDDY_VOICE);
JABBER_BUDDY_SET_FLAG(new_buddy, is_chanuser, JABBER_BUDDY_CHANUSER);
JABBER_BUDDY_SET_FLAG(new_buddy, is_away, JABBER_BUDDY_AWAY);
local_name = jabber_server_get_local_name (server);
if (weechat_strcasecmp (new_buddy->name, local_name) == 0)
new_buddy->color = JABBER_COLOR_CHAT_NICK_SELF;
else
new_buddy->color = jabber_buddy_find_color (new_buddy);
/* add buddy to end of list */
if (muc)
{
new_buddy->prev_buddy = muc->last_buddy;
if (muc->buddies)
muc->last_buddy->next_buddy = new_buddy;
else
muc->buddies = new_buddy;
muc->last_buddy = new_buddy;
new_buddy->next_buddy = NULL;
muc->buddies_count++;
muc->nick_completion_reset = 1;
}
else
{
new_buddy->prev_buddy = server->last_buddy;
if (server->buddies)
server->last_buddy->next_buddy = new_buddy;
else
server->buddies = new_buddy;
server->last_buddy = new_buddy;
new_buddy->next_buddy = NULL;
server->buddies_count++;
}
/* add buddy to buffer buddylist */
prefix[0] = ' ';
prefix[1] = '\0';
jabber_buddy_get_gui_infos (new_buddy, prefix, &prefix_color,
ptr_buffer, &ptr_group);
snprintf (str_prefix_color, sizeof (str_prefix_color),
"weechat.color.nicklist_prefix%d",
prefix_color);
weechat_nicklist_add_nick (ptr_buffer, ptr_group,
new_buddy->name,
(is_away) ?
"weechat.color.nicklist_away" : "bar_fg",
prefix, str_prefix_color, 1);
/* all is ok, return address of new buddy */
return new_buddy;
}
/*
* jabber_buddy_change: change buddyname
*/
void
jabber_buddy_change (struct t_jabber_server *server, struct t_jabber_muc *muc,
struct t_jabber_buddy *buddy, const char *new_buddy)
{
int buddy_is_me, prefix_color;
struct t_gui_buffer *ptr_buffer;
struct t_gui_nick_group *ptr_group;
char prefix[2], str_prefix_color[64];
const char *local_name;
ptr_buffer = (muc) ? muc->buffer : server->buffer;
/* remove buddy from buddylist */
jabber_buddy_get_gui_infos (buddy, prefix, &prefix_color,
ptr_buffer, &ptr_group);
weechat_nicklist_remove_nick (ptr_buffer,
weechat_nicklist_search_nick (ptr_buffer,
ptr_group,
buddy->name));
/* update buddies speaking */
local_name = jabber_server_get_local_name (server);
buddy_is_me = (strcmp (buddy->name, local_name) == 0) ? 1 : 0;
if (muc && !buddy_is_me)
jabber_muc_buddy_speaking_rename (muc, buddy->name, new_buddy);
/* change buddyname */
if (buddy->name)
free (buddy->name);
buddy->name = strdup (new_buddy);
if (buddy_is_me)
buddy->color = JABBER_COLOR_CHAT_NICK_SELF;
else
buddy->color = jabber_buddy_find_color (buddy);
/* add buddy in buddylist */
prefix[0] = ' ';
prefix[1] = '\0';
jabber_buddy_get_gui_infos (buddy, prefix, &prefix_color,
ptr_buffer, &ptr_group);
snprintf (str_prefix_color, sizeof (str_prefix_color),
"weechat.color.nicklist_prefix%d",
prefix_color);
weechat_nicklist_add_nick (ptr_buffer, ptr_group,
buddy->name, "bar_fg",
prefix, str_prefix_color, 1);
}
/*
* jabber_buddy_set: set a flag for a buddy
*/
void
jabber_buddy_set (struct t_jabber_server *server, struct t_jabber_muc *muc,
struct t_jabber_buddy *buddy, int set, int flag)
{
struct t_gui_buffer *ptr_buffer;
struct t_gui_nick_group *ptr_group;
char prefix[2], str_prefix_color[64];
int prefix_color;
if (server || muc)
{
ptr_buffer = (muc) ? muc->buffer : server->buffer;
/* remove buddy from buddylist */
jabber_buddy_get_gui_infos (buddy, prefix, &prefix_color,
ptr_buffer, &ptr_group);
weechat_nicklist_remove_nick (ptr_buffer,
weechat_nicklist_search_nick (ptr_buffer,
ptr_group,
buddy->name));
/* set flag */
JABBER_BUDDY_SET_FLAG(buddy, set, flag);
/* add buddy in buddylist */
prefix[0] = ' ';
prefix[1] = '\0';
jabber_buddy_get_gui_infos (buddy, prefix, &prefix_color,
ptr_buffer, &ptr_group);
snprintf (str_prefix_color, sizeof (str_prefix_color),
"weechat.color.nicklist_prefix%d",
prefix_color);
weechat_nicklist_add_nick (ptr_buffer, ptr_group,
buddy->name,
(buddy->flags & JABBER_BUDDY_AWAY) ?
"weechat.color.nicklist_away" : "bar_fg",
prefix, str_prefix_color, 1);
}
}
/*
* jabber_buddy_free: free a buddy and remove it from buddies list
*/
void
jabber_buddy_free (struct t_jabber_server *server, struct t_jabber_muc *muc,
struct t_jabber_buddy *buddy)
{
struct t_gui_buffer *ptr_buffer;
struct t_gui_nick_group *ptr_group;
struct t_jabber_buddy *new_buddies;
char prefix;
int prefix_color;
if ((!server && !muc) || !buddy)
return;
ptr_buffer = (muc) ? muc->buffer : server->buffer;
/* remove buddy from buddylist */
jabber_buddy_get_gui_infos (buddy, &prefix, &prefix_color,
ptr_buffer, &ptr_group);
weechat_nicklist_remove_nick (ptr_buffer,
weechat_nicklist_search_nick (ptr_buffer,
ptr_group,
buddy->name));
/* remove buddy */
if (muc)
{
if (muc->last_buddy == buddy)
muc->last_buddy = buddy->prev_buddy;
if (buddy->prev_buddy)
{
(buddy->prev_buddy)->next_buddy = buddy->next_buddy;
new_buddies = muc->buddies;
}
else
new_buddies = buddy->next_buddy;
if (buddy->next_buddy)
(buddy->next_buddy)->prev_buddy = buddy->prev_buddy;
muc->buddies_count--;
}
else
{
if (server->last_buddy == buddy)
server->last_buddy = buddy->prev_buddy;
if (buddy->prev_buddy)
{
(buddy->prev_buddy)->next_buddy = buddy->next_buddy;
new_buddies = server->buddies;
}
else
new_buddies = buddy->next_buddy;
if (buddy->next_buddy)
(buddy->next_buddy)->prev_buddy = buddy->prev_buddy;
server->buddies_count--;
}
/* free data */
if (buddy->name)
free (buddy->name);
if (buddy->host)
free (buddy->host);
free (buddy);
if (muc)
{
muc->buddies = new_buddies;
muc->nick_completion_reset = 1;
}
else
{
server->buddies = new_buddies;
}
}
/*
* jabber_buddy_free_all: free all allocated buddies for a muc
*/
void
jabber_buddy_free_all (struct t_jabber_server *server,
struct t_jabber_muc *muc)
{
if (server)
{
while (server->buddies)
{
jabber_buddy_free (server, NULL, server->buddies);
}
/* sould be zero, but prevent any bug :D */
server->buddies_count = 0;
}
if (muc)
{
while (muc->buddies)
{
jabber_buddy_free (NULL, muc, muc->buddies);
}
/* sould be zero, but prevent any bug :D */
muc->buddies_count = 0;
}
}
/*
* jabber_buddy_search: returns pointer on a buddy
*/
struct t_jabber_buddy *
jabber_buddy_search (struct t_jabber_server *server, struct t_jabber_muc *muc,
const char *buddyname)
{
struct t_jabber_buddy *ptr_buddy;
if (!buddyname)
return NULL;
if (server)
{
for (ptr_buddy = server->buddies; ptr_buddy;
ptr_buddy = ptr_buddy->next_buddy)
{
if (weechat_strcasecmp (ptr_buddy->name, buddyname) == 0)
return ptr_buddy;
}
}
if (muc)
{
for (ptr_buddy = muc->buddies; ptr_buddy;
ptr_buddy = ptr_buddy->next_buddy)
{
if (weechat_strcasecmp (ptr_buddy->name, buddyname) == 0)
return ptr_buddy;
}
}
/* buddy not found */
return NULL;
}
/*
* jabber_buddy_count: returns number of buddies (total, op, halfop, voice) on
* a server or MUC
*/
void
jabber_buddy_count (struct t_jabber_server *server, struct t_jabber_muc *muc,
int *total, int *count_op, int *count_halfop,
int *count_voice, int *count_normal)
{
struct t_jabber_buddy *ptr_buddy;
(*total) = 0;
(*count_op) = 0;
(*count_halfop) = 0;
(*count_voice) = 0;
(*count_normal) = 0;
if (server || muc)
{
for (ptr_buddy = (muc) ? muc->buddies : server->buddies; ptr_buddy;
ptr_buddy = ptr_buddy->next_buddy)
{
(*total)++;
if ((ptr_buddy->flags & JABBER_BUDDY_CHANOWNER) ||
(ptr_buddy->flags & JABBER_BUDDY_CHANADMIN) ||
(ptr_buddy->flags & JABBER_BUDDY_CHANADMIN2) ||
(ptr_buddy->flags & JABBER_BUDDY_OP))
(*count_op)++;
else
{
if (ptr_buddy->flags & JABBER_BUDDY_HALFOP)
(*count_halfop)++;
else
{
if (ptr_buddy->flags & JABBER_BUDDY_VOICE)
(*count_voice)++;
else
(*count_normal)++;
}
}
}
}
}
/*
* jabber_buddy_set_away: set/unset away status for a muc
*/
void
jabber_buddy_set_away (struct t_jabber_server *server,
struct t_jabber_muc *muc,
struct t_jabber_buddy *buddy, int is_away)
{
if (((is_away) && (!(buddy->flags & JABBER_BUDDY_AWAY))) ||
((!is_away) && (buddy->flags & JABBER_BUDDY_AWAY)))
{
if (muc)
jabber_buddy_set (NULL, muc, buddy, is_away, JABBER_BUDDY_AWAY);
else
jabber_buddy_set (server, NULL, buddy, is_away, JABBER_BUDDY_AWAY);
}
}
/*
* jabber_buddy_as_prefix: return string with buddy to display as prefix on
* buffer (string will end by a tab)
*/
char *
jabber_buddy_as_prefix (struct t_jabber_buddy *buddy, const char *buddyname,
const char *force_color)
{
static char result[256];
char prefix[2], str_prefix_color[64];
int prefix_color;
prefix[0] = '\0';
prefix[1] = '\0';
if (weechat_config_boolean (weechat_config_get ("weechat.look.nickmode")))
{
if (buddy)
{
jabber_buddy_get_gui_infos (buddy, &prefix[0], &prefix_color, NULL, NULL);
if ((prefix[0] == ' ')
&& !weechat_config_boolean (weechat_config_get ("weechat.look.nickmode_empty")))
prefix[0] = '\0';
snprintf (str_prefix_color, sizeof (str_prefix_color),
"weechat.color.nicklist_prefix%d",
prefix_color);
}
else
{
prefix[0] = (weechat_config_boolean (weechat_config_get ("weechat.look.nickmode_empty"))) ?
' ' : '\0';
snprintf (str_prefix_color, sizeof (str_prefix_color),
"weechat.color.chat");
}
}
else
{
prefix[0] = '\0';
snprintf (str_prefix_color, sizeof (str_prefix_color), "chat");
}
snprintf (result, sizeof (result), "%s%s%s%s%s%s%s%s\t",
(weechat_config_string (jabber_config_look_nick_prefix)
&& weechat_config_string (jabber_config_look_nick_prefix)[0]) ?
JABBER_COLOR_CHAT_DELIMITERS : "",
(weechat_config_string (jabber_config_look_nick_prefix)
&& weechat_config_string (jabber_config_look_nick_prefix)[0]) ?
weechat_config_string (jabber_config_look_nick_prefix) : "",
weechat_color(weechat_config_string(weechat_config_get(str_prefix_color))),
prefix,
(force_color) ? force_color : ((buddy) ? buddy->color : JABBER_COLOR_CHAT_NICK),
(buddy) ? buddy->name : buddyname,
(weechat_config_string (jabber_config_look_nick_suffix)
&& weechat_config_string (jabber_config_look_nick_suffix)[0]) ?
JABBER_COLOR_CHAT_DELIMITERS : "",
(weechat_config_string (jabber_config_look_nick_suffix)
&& weechat_config_string (jabber_config_look_nick_suffix)[0]) ?
weechat_config_string (jabber_config_look_nick_suffix) : "");
return result;
}
/*
* jabber_buddy_add_to_infolist: add a buddy in an infolist
* return 1 if ok, 0 if error
*/
int
jabber_buddy_add_to_infolist (struct t_infolist *infolist,
struct t_jabber_buddy *buddy)
{
struct t_infolist_item *ptr_item;
if (!infolist || !buddy)
return 0;
ptr_item = weechat_infolist_new_item (infolist);
if (!ptr_item)
return 0;
if (!weechat_infolist_new_var_string (ptr_item, "name", buddy->name))
return 0;
if (!weechat_infolist_new_var_string (ptr_item, "host", buddy->host))
return 0;
if (!weechat_infolist_new_var_integer (ptr_item, "flags", buddy->flags))
return 0;
if (!weechat_infolist_new_var_string (ptr_item, "color", buddy->color))
return 0;
return 1;
}
/*
* jabber_buddy_print_log: print buddy infos in log (usually for crash dump)
*/
void
jabber_buddy_print_log (struct t_jabber_buddy *buddy)
{
weechat_log_printf ("");
weechat_log_printf (" => buddy %s (addr:0x%lx):", buddy->name, buddy);
weechat_log_printf (" host . . . . . : %s", buddy->host);
weechat_log_printf (" flags. . . . . : %d", buddy->flags);
weechat_log_printf (" color. . . . . : '%s'", buddy->color);
weechat_log_printf (" prev_buddy . . : 0x%lx", buddy->prev_buddy);
weechat_log_printf (" next_buddy . . : 0x%lx", buddy->next_buddy);
}
-101
View File
@@ -1,101 +0,0 @@
/*
* Copyright (c) 2009 by FlashCode <flashcode@flashtux.org>
* See README for License detail, AUTHORS for developers list.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __WEECHAT_JABBER_BUDDY_H
#define __WEECHAT_JABBER_BUDDY_H 1
#define JABBER_BUDDY_CHANOWNER 1
#define JABBER_BUDDY_CHANADMIN 2
#define JABBER_BUDDY_CHANADMIN2 4
#define JABBER_BUDDY_OP 8
#define JABBER_BUDDY_HALFOP 16
#define JABBER_BUDDY_VOICE 32
#define JABBER_BUDDY_AWAY 64
#define JABBER_BUDDY_CHANUSER 128
#define JABBER_BUDDY_SET_FLAG(buddy, set, flag) \
if (set) \
buddy->flags |= flag; \
else \
buddy->flags &= 0xFFFF - flag;
#define JABBER_BUDDY_GROUP_OP "1|op"
#define JABBER_BUDDY_GROUP_HALFOP "2|halfop"
#define JABBER_BUDDY_GROUP_VOICE "3|voice"
#define JABBER_BUDDY_GROUP_CHANUSER "4|chanuser"
#define JABBER_BUDDY_GROUP_NORMAL "5|normal"
struct t_jabber_server;
struct t_jabber_muc;
struct t_jabber_buddy
{
char *name; /* buddyname */
char *host; /* full hostname */
int flags; /* chanowner/chanadmin, op, halfop, */
/* voice, away */
const char *color; /* color for buddyname in chat window */
struct t_jabber_buddy *prev_buddy; /* link to previous buddy in MUC */
struct t_jabber_buddy *next_buddy; /* link to next buddy in MUC */
};
extern int jabber_buddy_valid (struct t_jabber_server *server,
struct t_jabber_muc *muc,
struct t_jabber_buddy *buddy);
extern const char *jabber_buddy_find_color (struct t_jabber_buddy *buddy);
extern struct t_jabber_buddy *jabber_buddy_new (struct t_jabber_server *server,
struct t_jabber_muc *muc,
const char *buddy_name,
int is_chanowner,
int is_chanadmin,
int is_chanadmin2,
int is_op,
int is_halfop,
int has_voice,
int is_chanuser,
int is_away);
extern void jabber_buddy_change (struct t_jabber_server *server,
struct t_jabber_muc *muc,
struct t_jabber_buddy *buddy,
const char *new_buddy);
extern void jabber_buddy_set (struct t_jabber_server *server,
struct t_jabber_muc *muc,
struct t_jabber_buddy *buddy, int set, int flag);
extern void jabber_buddy_free (struct t_jabber_server *server,
struct t_jabber_muc *muc,
struct t_jabber_buddy *buddy);
extern void jabber_buddy_free_all (struct t_jabber_server *server,
struct t_jabber_muc *muc);
extern struct t_jabber_buddy *jabber_buddy_search (struct t_jabber_server *server,
struct t_jabber_muc *muc,
const char *buddyname);
extern void jabber_buddy_count (struct t_jabber_server *server,
struct t_jabber_muc *muc, int *total,
int *count_op, int *count_halfop,
int *count_voice, int *count_normal);
extern void jabber_buddy_set_away (struct t_jabber_server *server,
struct t_jabber_muc *muc,
struct t_jabber_buddy *buddy, int is_away);
extern char *jabber_buddy_as_prefix (struct t_jabber_buddy *buddy,
const char *buddyname,
const char *force_color);
extern int jabber_buddy_add_to_infolist (struct t_infolist *infolist,
struct t_jabber_buddy *buddy);
extern void jabber_buddy_print_log (struct t_jabber_buddy *buddy);
#endif /* jabber-buddy.h */
-313
View File
@@ -1,313 +0,0 @@
/*
* Copyright (c) 2009 by FlashCode <flashcode@flashtux.org>
* See README for License detail, AUTHORS for developers list.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* jabber-buffer.c: buffer functions for Jabber plugin */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "../weechat-plugin.h"
#include "jabber.h"
#include "jabber-buffer.h"
#include "jabber-command.h"
#include "jabber-config.h"
#include "jabber-muc.h"
#include "jabber-server.h"
/* buffer for all servers (if using one buffer for all servers) */
struct t_gui_buffer *jabber_buffer_servers = NULL;
/*
* jabber_buffer_get_server_muc: get Jabber server and MUC pointers
* with a buffer pointer
* (buffer may be a server or a MUC)
*/
void
jabber_buffer_get_server_muc (struct t_gui_buffer *buffer,
struct t_jabber_server **server,
struct t_jabber_muc **muc)
{
struct t_jabber_server *ptr_server;
struct t_jabber_muc *ptr_muc;
if (server)
*server = NULL;
if (muc)
*muc = NULL;
if (!buffer)
return;
/* look for a server or MUC using this buffer */
for (ptr_server = jabber_servers; ptr_server;
ptr_server = ptr_server->next_server)
{
if (ptr_server->buffer == buffer)
{
if (server)
{
if (weechat_config_boolean (jabber_config_look_one_server_buffer))
*server = jabber_current_server;
else
*server = ptr_server;
}
return;
}
for (ptr_muc = ptr_server->mucs; ptr_muc;
ptr_muc = ptr_muc->next_muc)
{
if (ptr_muc->buffer == buffer)
{
if (server)
*server = ptr_server;
if (muc)
*muc = ptr_muc;
return;
}
}
}
/* no server or MUC found */
}
/*
* jabber_buffer_build_name: build buffer name with a server and a MUC
*/
char *
jabber_buffer_build_name (const char *server, const char *muc)
{
static char buffer[128];
buffer[0] = '\0';
if (!server && !muc)
return buffer;
if (server && muc)
snprintf (buffer, sizeof (buffer), "%s.%s", server, muc);
else
snprintf (buffer, sizeof (buffer), "%s",
(server) ? server : muc);
return buffer;
}
/*
* jabber_buffer_get_server_prefix: return prefix, with server name if server
* buffers are displayed in only one buffer
*/
char *
jabber_buffer_get_server_prefix (struct t_jabber_server *server,
char *prefix_code)
{
static char buf[256];
const char *prefix;
prefix = (prefix_code && prefix_code[0]) ?
weechat_prefix (prefix_code) : NULL;
if (weechat_config_boolean (jabber_config_look_one_server_buffer) && server)
{
snprintf (buf, sizeof (buf), "%s%s[%s%s%s]%s ",
(prefix) ? prefix : "",
JABBER_COLOR_CHAT_DELIMITERS,
JABBER_COLOR_CHAT_SERVER,
server->name,
JABBER_COLOR_CHAT_DELIMITERS,
JABBER_COLOR_CHAT);
}
else
{
snprintf (buf, sizeof (buf), "%s",
(prefix) ? prefix : "");
}
return buf;
}
/*
* jabber_buffer_merge_servers: merge server buffers in one buffer
*/
void
jabber_buffer_merge_servers ()
{
struct t_jabber_server *ptr_server;
struct t_gui_buffer *ptr_buffer;
int number, number_selected;
char charset_modifier[256];
jabber_buffer_servers = NULL;
jabber_current_server = NULL;
/* choose server buffer with lower number (should be first created) */
number_selected = -1;
for (ptr_server = jabber_servers; ptr_server;
ptr_server = ptr_server->next_server)
{
if (ptr_server->buffer)
{
number = weechat_buffer_get_integer (ptr_server->buffer, "number");
if ((number_selected == -1) || (number < number_selected))
{
jabber_buffer_servers = ptr_server->buffer;
jabber_current_server = ptr_server;
number_selected = number;
}
}
}
if (jabber_buffer_servers)
{
weechat_buffer_set (jabber_buffer_servers,
"name", JABBER_BUFFER_ALL_SERVERS_NAME);
weechat_buffer_set (jabber_buffer_servers,
"short_name", JABBER_BUFFER_ALL_SERVERS_NAME);
weechat_buffer_set (jabber_buffer_servers,
"localvar_set_server", JABBER_BUFFER_ALL_SERVERS_NAME);
weechat_buffer_set (jabber_buffer_servers,
"localvar_set_muc", JABBER_BUFFER_ALL_SERVERS_NAME);
snprintf (charset_modifier, sizeof (charset_modifier),
"jabber.%s", jabber_current_server->name);
weechat_buffer_set (jabber_buffer_servers,
"localvar_set_charset_modifier",
charset_modifier);
weechat_hook_signal_send ("logger_stop",
WEECHAT_HOOK_SIGNAL_POINTER,
jabber_buffer_servers);
weechat_hook_signal_send ("logger_start",
WEECHAT_HOOK_SIGNAL_POINTER,
jabber_buffer_servers);
for (ptr_server = jabber_servers; ptr_server;
ptr_server = ptr_server->next_server)
{
if (ptr_server->buffer
&& (ptr_server->buffer != jabber_buffer_servers))
{
ptr_buffer = ptr_server->buffer;
ptr_server->buffer = jabber_buffer_servers;
weechat_buffer_close (ptr_buffer);
}
}
jabber_server_set_buffer_title (jabber_current_server);
jabber_server_buffer_set_highlight_words (jabber_buffer_servers);
}
}
/*
* jabber_buffer_split_server: split the server buffer into many buffers (one by server)
*/
void
jabber_buffer_split_server ()
{
struct t_jabber_server *ptr_server;
char buffer_name[256], charset_modifier[256];
for (ptr_server = jabber_servers; ptr_server;
ptr_server = ptr_server->next_server)
{
if (ptr_server->buffer && (ptr_server != jabber_current_server))
{
jabber_server_create_buffer (ptr_server, 0);
}
}
if (jabber_current_server)
{
snprintf (buffer_name, sizeof (buffer_name),
"server.%s", jabber_current_server->name);
weechat_buffer_set (jabber_current_server->buffer, "name", buffer_name);
weechat_buffer_set (jabber_current_server->buffer,
"short_name", jabber_current_server->name);
weechat_buffer_set (jabber_current_server->buffer,
"localvar_set_server", jabber_current_server->name);
weechat_buffer_set (jabber_current_server->buffer,
"localvar_set_muc", jabber_current_server->name);
snprintf (charset_modifier, sizeof (charset_modifier),
"jabber.%s", jabber_current_server->name);
weechat_buffer_set (jabber_current_server->buffer,
"localvar_set_charset_modifier",
charset_modifier);
weechat_hook_signal_send ("logger_stop",
WEECHAT_HOOK_SIGNAL_POINTER,
jabber_current_server->buffer);
weechat_hook_signal_send ("logger_start",
WEECHAT_HOOK_SIGNAL_POINTER,
jabber_current_server->buffer);
}
jabber_buffer_servers = NULL;
jabber_current_server = NULL;
}
/*
* jabber_buffer_close_cb: callback called when a buffer is closed
*/
int
jabber_buffer_close_cb (void *data, struct t_gui_buffer *buffer)
{
JABBER_GET_SERVER_MUC(buffer);
/* make C compiler happy */
(void) data;
if (ptr_muc)
{
/* send PART for channel if its buffer is closed */
//if ((ptr_channel->type == JABBER_CHANNEL_TYPE_CHANNEL)
// && (ptr_channel->nicks))
//{
// jabber_command_part_channel (ptr_server, ptr_channel->name, NULL);
//}
jabber_muc_free (ptr_server, ptr_muc);
}
else
{
if (ptr_server)
{
/* send PART on all channels for server, then disconnect from server */
//ptr_channel = ptr_server->channels;
//while (ptr_channel)
//{
// next_channel = ptr_channel->next_channel;
// weechat_buffer_close (ptr_channel->buffer);
// ptr_channel = next_channel;
//}
jabber_server_disconnect (ptr_server, 0);
ptr_server->buffer = NULL;
}
}
if (jabber_buffer_servers == buffer)
jabber_buffer_servers = NULL;
if (ptr_server && (jabber_current_server == ptr_server))
jabber_current_server = NULL;
return WEECHAT_RC_OK;
}
-41
View File
@@ -1,41 +0,0 @@
/*
* Copyright (c) 2009 by FlashCode <flashcode@flashtux.org>
* See README for License detail, AUTHORS for developers list.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __WEECHAT_JABBER_BUFFER_H
#define __WEECHAT_JABBER_BUFFER_H 1
#define JABBER_BUFFER_ALL_SERVERS_NAME "servers"
struct t_gui_buffer;
struct t_jabber_server;
struct t_jabber_muc;
extern struct t_gui_buffer *jabber_buffer_servers;
extern void jabber_buffer_get_server_muc (struct t_gui_buffer *buffer,
struct t_jabber_server **server,
struct t_jabber_muc **muc);
extern char *jabber_buffer_build_name (const char *server, const char *muc);
extern char *jabber_buffer_get_server_prefix (struct t_jabber_server *server,
char *prefix_code);
extern void jabber_buffer_merge_servers ();
extern void jabber_buffer_split_server ();
extern int jabber_buffer_close_cb (void *data, struct t_gui_buffer *buffer);
#endif /* jabber-buffer.h */
-847
View File
@@ -1,847 +0,0 @@
/*
* Copyright (c) 2009 by FlashCode <flashcode@flashtux.org>
* See README for License detail, AUTHORS for developers list.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* jabber-command.c: Jabber commands */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <sys/time.h>
#include <time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include "../weechat-plugin.h"
#include "jabber.h"
#include "jabber-command.h"
#include "jabber-buddy.h"
#include "jabber-buffer.h"
#include "jabber-config.h"
#include "jabber-input.h"
#include "jabber-muc.h"
#include "jabber-server.h"
#include "jabber-display.h"
#include "jabber-xmpp.h"
/*
* jabber_command_quit_server: send QUIT to a server
*/
void
jabber_command_quit_server (struct t_jabber_server *server,
const char *arguments)
{
if (!server)
return;
(void) arguments;
}
/*
* jabber_command_jabber: test
*/
int
jabber_command_jabber (void *data, struct t_gui_buffer *buffer, int argc,
char **argv, char **argv_eol)
{
int i, detailed_list, one_server_found;
struct t_jabber_server *ptr_server2, *server_found, *new_server;
char *server_name;
JABBER_GET_SERVER_MUC(buffer);
/* make C compiler happy */
(void) data;
(void) buffer;
(void) argv_eol;
if ((argc == 1)
|| (weechat_strcasecmp (argv[1], "list") == 0)
|| (weechat_strcasecmp (argv[1], "listfull") == 0))
{
/* list servers */
server_name = NULL;
detailed_list = 0;
for (i = 1; i < argc; i++)
{
if (weechat_strcasecmp (argv[i], "list") == 0)
continue;
if (weechat_strcasecmp (argv[i], "listfull") == 0)
{
detailed_list = 1;
continue;
}
if (!server_name)
server_name = argv[i];
}
if (!server_name)
{
if (jabber_servers)
{
weechat_printf (NULL, "");
weechat_printf (NULL, _("All servers:"));
for (ptr_server2 = jabber_servers; ptr_server2;
ptr_server2 = ptr_server2->next_server)
{
jabber_display_server (ptr_server2, detailed_list);
}
}
else
weechat_printf (NULL, _("No server"));
}
else
{
one_server_found = 0;
for (ptr_server2 = jabber_servers; ptr_server2;
ptr_server2 = ptr_server2->next_server)
{
if (weechat_strcasestr (ptr_server2->name, server_name))
{
if (!one_server_found)
{
weechat_printf (NULL, "");
weechat_printf (NULL,
_("Servers with \"%s\":"),
server_name);
}
one_server_found = 1;
jabber_display_server (ptr_server2, detailed_list);
}
}
if (!one_server_found)
weechat_printf (NULL,
_("No server found with \"%s\""),
server_name);
}
return WEECHAT_RC_OK;
}
if (weechat_strcasecmp (argv[1], "add") == 0)
{
if (argc < 6)
{
JABBER_COMMAND_TOO_FEW_ARGUMENTS(NULL, "server add");
}
if (jabber_server_search (argv[2]))
{
weechat_printf (NULL,
_("%s%s: server \"%s\" already exists, "
"can't create it!"),
weechat_prefix ("error"), JABBER_PLUGIN_NAME,
argv[2]);
return WEECHAT_RC_ERROR;
}
new_server = jabber_server_alloc (argv[2]);
if (!new_server)
{
weechat_printf (NULL,
_("%s%s: unable to create server"),
weechat_prefix ("error"), JABBER_PLUGIN_NAME);
return WEECHAT_RC_ERROR;
}
weechat_config_option_set (new_server->options[JABBER_SERVER_OPTION_USERNAME],
argv[3], 1);
weechat_config_option_set (new_server->options[JABBER_SERVER_OPTION_SERVER],
argv[4], 1);
weechat_config_option_set (new_server->options[JABBER_SERVER_OPTION_PASSWORD],
argv[5], 1);
/* parse arguments */
for (i = 6; i < argc; i++)
{
if (argv[i][0] == '-')
{
if (weechat_strcasecmp (argv[i], "-auto") == 0)
{
weechat_config_option_set (new_server->options[JABBER_SERVER_OPTION_AUTOCONNECT],
"on", 1);
}
if (weechat_strcasecmp (argv[i], "-noauto") == 0)
{
weechat_config_option_set (new_server->options[JABBER_SERVER_OPTION_AUTOCONNECT],
"off", 1);
}
if (weechat_strcasecmp (argv[i], "-ipv6") == 0)
{
weechat_config_option_set (new_server->options[JABBER_SERVER_OPTION_IPV6],
"on", 1);
}
if (weechat_strcasecmp (argv[i], "-tls") == 0)
{
weechat_config_option_set (new_server->options[JABBER_SERVER_OPTION_TLS],
"on", 1);
}
if (weechat_strcasecmp (argv[i], "-sasl") == 0)
{
weechat_config_option_set (new_server->options[JABBER_SERVER_OPTION_SASL],
"on", 1);
}
}
}
weechat_printf (NULL,
_("%s: server %s%s%s created"),
JABBER_PLUGIN_NAME,
JABBER_COLOR_CHAT_SERVER,
new_server->name,
JABBER_COLOR_CHAT);
if (JABBER_SERVER_OPTION_BOOLEAN(new_server, JABBER_SERVER_OPTION_AUTOCONNECT))
jabber_server_connect (new_server);
return WEECHAT_RC_OK;
}
if (weechat_strcasecmp (argv[1], "copy") == 0)
{
if (argc < 4)
{
JABBER_COMMAND_TOO_FEW_ARGUMENTS(NULL, "server copy");
}
/* look for server by name */
server_found = jabber_server_search (argv[2]);
if (!server_found)
{
weechat_printf (NULL,
_("%s%s: server \"%s\" not found for "
"\"%s\" command"),
weechat_prefix ("error"), JABBER_PLUGIN_NAME,
argv[2], "server copy");
return WEECHAT_RC_ERROR;
}
/* check if target name already exists */
if (jabber_server_search (argv[3]))
{
weechat_printf (NULL,
_("%s%s: server \"%s\" already exists for "
"\"%s\" command"),
weechat_prefix ("error"), JABBER_PLUGIN_NAME,
argv[3], "server copy");
return WEECHAT_RC_ERROR;
}
/* copy server */
new_server = jabber_server_copy (server_found, argv[3]);
if (new_server)
{
weechat_printf (NULL,
_("%s: server %s%s%s has been copied to "
"%s%s"),
JABBER_PLUGIN_NAME,
JABBER_COLOR_CHAT_SERVER,
argv[2],
JABBER_COLOR_CHAT,
JABBER_COLOR_CHAT_SERVER,
argv[3]);
return WEECHAT_RC_OK;
}
return WEECHAT_RC_ERROR;
}
if (weechat_strcasecmp (argv[1], "rename") == 0)
{
if (argc < 4)
{
JABBER_COMMAND_TOO_FEW_ARGUMENTS(NULL, "server rename");
}
/* look for server by name */
server_found = jabber_server_search (argv[2]);
if (!server_found)
{
weechat_printf (NULL,
_("%s%s: server \"%s\" not found for "
"\"%s\" command"),
weechat_prefix ("error"), JABBER_PLUGIN_NAME,
argv[2], "server rename");
return WEECHAT_RC_ERROR;
}
/* check if target name already exists */
if (jabber_server_search (argv[3]))
{
weechat_printf (NULL,
_("%s%s: server \"%s\" already exists for "
"\"%s\" command"),
weechat_prefix ("error"), JABBER_PLUGIN_NAME,
argv[3], "server rename");
return WEECHAT_RC_ERROR;
}
/* rename server */
if (jabber_server_rename (server_found, argv[3]))
{
weechat_printf (NULL,
_("%s: server %s%s%s has been renamed to "
"%s%s"),
JABBER_PLUGIN_NAME,
JABBER_COLOR_CHAT_SERVER,
argv[2],
JABBER_COLOR_CHAT,
JABBER_COLOR_CHAT_SERVER,
argv[3]);
return WEECHAT_RC_OK;
}
return WEECHAT_RC_ERROR;
}
if (weechat_strcasecmp (argv[1], "keep") == 0)
{
if (argc < 3)
{
JABBER_COMMAND_TOO_FEW_ARGUMENTS(NULL, "server keep");
}
/* look for server by name */
server_found = jabber_server_search (argv[2]);
if (!server_found)
{
weechat_printf (NULL,
_("%s%s: server \"%s\" not found for "
"\"%s\" command"),
weechat_prefix ("error"), JABBER_PLUGIN_NAME,
argv[2], "server keep");
return WEECHAT_RC_ERROR;
}
/* check that is it temporary server */
if (!server_found->temp_server)
{
weechat_printf (NULL,
_("%s%s: server \"%s\" is not a temporary server"),
weechat_prefix ("error"), JABBER_PLUGIN_NAME,
argv[2], "server keep");
return WEECHAT_RC_ERROR;
}
/* remove temporary flag on server */
server_found->temp_server = 0;
weechat_printf (NULL,
_("%s: server %s%s%s is not temporary any more"),
JABBER_PLUGIN_NAME,
JABBER_COLOR_CHAT_SERVER,
argv[2],
JABBER_COLOR_CHAT);
return WEECHAT_RC_OK;
}
if (weechat_strcasecmp (argv[1], "del") == 0)
{
if (argc < 3)
{
JABBER_COMMAND_TOO_FEW_ARGUMENTS(NULL, "server del");
}
/* look for server by name */
server_found = jabber_server_search (argv[2]);
if (!server_found)
{
weechat_printf (NULL,
_("%s%s: server \"%s\" not found for "
"\"%s\" command"),
weechat_prefix ("error"), JABBER_PLUGIN_NAME,
argv[2], "server del");
return WEECHAT_RC_ERROR;
}
if (server_found->is_connected)
{
weechat_printf (NULL,
_("%s%s: you can not delete server \"%s\" "
"because you are connected to. "
"Try \"/disconnect %s\" before."),
weechat_prefix ("error"), JABBER_PLUGIN_NAME,
argv[2], argv[2]);
return WEECHAT_RC_ERROR;
}
server_name = strdup (server_found->name);
jabber_server_free (server_found);
weechat_printf (NULL,
_("%s: Server %s%s%s has been deleted"),
JABBER_PLUGIN_NAME,
JABBER_COLOR_CHAT_SERVER,
(server_name) ? server_name : "???",
JABBER_COLOR_CHAT);
if (server_name)
free (server_name);
return WEECHAT_RC_OK;
}
if (weechat_strcasecmp (argv[1], "switch") == 0)
{
if (weechat_config_boolean (jabber_config_look_one_server_buffer))
{
if (jabber_current_server)
{
ptr_server2 = jabber_current_server->next_server;
if (!ptr_server2)
ptr_server2 = jabber_servers;
while (ptr_server2 != jabber_current_server)
{
if (ptr_server2->buffer)
{
jabber_current_server = ptr_server2;
break;
}
ptr_server2 = ptr_server2->next_server;
if (!ptr_server2)
ptr_server2 = jabber_servers;
}
}
else
{
for (ptr_server2 = jabber_servers; ptr_server2;
ptr_server2 = ptr_server2->next_server)
{
if (ptr_server2->buffer)
{
jabber_current_server = ptr_server2;
break;
}
}
}
jabber_server_set_current_server (jabber_current_server);
}
return WEECHAT_RC_OK;
}
weechat_printf (NULL,
_("%s%s: unknown option for \"%s\" command"),
weechat_prefix ("error"), JABBER_PLUGIN_NAME, "server");
return WEECHAT_RC_ERROR;
}
/*
* jabber_command_jchat: chat with a buddy
*/
int
jabber_command_jchat (void *data, struct t_gui_buffer *buffer, int argc,
char **argv, char **argv_eol)
{
JABBER_GET_SERVER_MUC(buffer);
if (!ptr_server || !ptr_server->is_connected || !ptr_server->iks_authorized)
return WEECHAT_RC_ERROR;
/* make C compiler happy */
(void) data;
(void) argv;
if (argc > 1)
{
/* create private window if not already opened */
ptr_muc = jabber_muc_search (ptr_server, argv[1]);
if (!ptr_muc)
{
ptr_muc = jabber_muc_new (ptr_server,
JABBER_MUC_TYPE_PRIVATE,
argv[1], 1, 0);
if (!ptr_muc)
{
weechat_printf (ptr_server->buffer,
_("%s%s: cannot create new private "
"buffer \"%s\""),
jabber_buffer_get_server_prefix (ptr_server, "error"),
JABBER_PLUGIN_NAME, argv[1]);
return WEECHAT_RC_ERROR;
}
}
weechat_buffer_set (ptr_muc->buffer, "display", "1");
/* display text if given */
if (argv_eol[2])
{
jabber_xmpp_send_chat_message (ptr_server, ptr_muc, argv_eol[2]);
jabber_input_user_message_display (ptr_muc->buffer, argv_eol[2]);
}
}
else
{
JABBER_COMMAND_TOO_FEW_ARGUMENTS(ptr_server->buffer, "chat");
}
return WEECHAT_RC_OK;
}
/*
* jabber_command_jconnect_one_server: connect to one server
* return 0 if error, 1 if ok
*/
int
jabber_command_jconnect_one_server (struct t_jabber_server *server, int no_join)
{
if (!server)
return 0;
if (server->is_connected)
{
weechat_printf (NULL,
_("%s%s: already connected to server "
"\"%s\"!"),
weechat_prefix ("error"), JABBER_PLUGIN_NAME,
server->name);
return 0;
}
if (server->hook_connect)
{
weechat_printf (NULL,
_("%s%s: currently connecting to server "
"\"%s\"!"),
weechat_prefix ("error"), JABBER_PLUGIN_NAME,
server->name);
return 0;
}
server->disable_autojoin = no_join;
if (jabber_server_connect (server))
{
server->reconnect_start = 0;
server->reconnect_join = (server->mucs) ? 1 : 0;
}
/* connect ok */
return 1;
}
/*
* jabber_command_jconnect: connect to server(s)
*/
int
jabber_command_jconnect (void *data, struct t_gui_buffer *buffer, int argc,
char **argv, char **argv_eol)
{
int i, nb_connect, connect_ok, all_servers, no_join, port, ipv6, tls, sasl;
char *name, *error;
long number;
JABBER_GET_SERVER(buffer);
/* make C compiler happy */
(void) data;
(void) argv_eol;
nb_connect = 0;
connect_ok = 1;
port = JABBER_SERVER_DEFAULT_PORT;
ipv6 = 0;
tls = 0;
sasl = 0;
all_servers = 0;
no_join = 0;
for (i = 1; i < argc; i++)
{
if (weechat_strcasecmp (argv[i], "-all") == 0)
all_servers = 1;
if (weechat_strcasecmp (argv[i], "-nojoin") == 0)
no_join = 1;
if (weechat_strcasecmp (argv[i], "-ipv6") == 0)
ipv6 = 1;
if (weechat_strcasecmp (argv[i], "-tls") == 0)
tls = 1;
if (weechat_strcasecmp (argv[i], "-sasl") == 0)
sasl = 1;
if (weechat_strcasecmp (argv[i], "-port") == 0)
{
if (i == (argc - 1))
{
weechat_printf (NULL,
_("%s%s: missing argument for \"%s\" "
"option"),
weechat_prefix ("error"), JABBER_PLUGIN_NAME,
"-port");
return WEECHAT_RC_ERROR;
}
error = NULL;
number = strtol (argv[++i], &error, 10);
if (error && !error[0])
port = number;
}
}
if (all_servers)
{
for (ptr_server = jabber_servers; ptr_server;
ptr_server = ptr_server->next_server)
{
nb_connect++;
if (!ptr_server->is_connected && (!ptr_server->hook_connect))
{
if (!jabber_command_jconnect_one_server (ptr_server, no_join))
connect_ok = 0;
}
}
}
else
{
for (i = 1; i < argc; i++)
{
if (argv[i][0] != '-')
{
nb_connect++;
ptr_server = jabber_server_search (argv[i]);
if (ptr_server)
{
if (!jabber_command_jconnect_one_server (ptr_server, no_join))
connect_ok = 0;
}
else
{
name = jabber_server_get_name_without_port (argv[i]);
ptr_server = jabber_server_alloc ((name) ? name : argv[i]);
if (name)
free (name);
if (ptr_server)
{
ptr_server->temp_server = 1;
weechat_config_option_set (ptr_server->options[JABBER_SERVER_OPTION_SERVER],
argv[i], 1);
weechat_printf (NULL,
_("%s: server %s%s%s created (temporary server, NOT SAVED!)"),
JABBER_PLUGIN_NAME,
JABBER_COLOR_CHAT_SERVER,
ptr_server->name,
JABBER_COLOR_CHAT);
if (!jabber_command_jconnect_one_server (ptr_server, 0))
connect_ok = 0;
}
else
{
weechat_printf (NULL,
_("%s%s: unable to create server "
"\"%s\""),
weechat_prefix ("error"),
JABBER_PLUGIN_NAME, argv[i]);
}
}
}
else
{
if (weechat_strcasecmp (argv[i], "-port") == 0)
i++;
}
}
}
if (nb_connect == 0)
connect_ok = jabber_command_jconnect_one_server (ptr_server, no_join);
if (!connect_ok)
return WEECHAT_RC_ERROR;
return WEECHAT_RC_OK;
}
/*
* jabber_command_jdisconnect_one_server: disconnect from a server
* return 0 if error, 1 if ok
*/
int
jabber_command_jdisconnect_one_server (struct t_jabber_server *server)
{
if (!server)
return 0;
if ((!server->is_connected) && (!server->hook_connect)
&& (server->reconnect_start == 0))
{
weechat_printf (server->buffer,
_("%s%s: not connected to server \"%s\"!"),
jabber_buffer_get_server_prefix (server, "error"),
JABBER_PLUGIN_NAME, server->name);
return 0;
}
if (server->reconnect_start > 0)
{
weechat_printf (server->buffer,
_("%s%s: auto-reconnection is cancelled"),
jabber_buffer_get_server_prefix (server, NULL),
JABBER_PLUGIN_NAME);
}
jabber_command_quit_server (server, NULL);
jabber_server_disconnect (server, 0);
/* disconnect ok */
return 1;
}
/*
* jabber_command_jdisconnect: disconnect from server(s)
*/
int
jabber_command_jdisconnect (void *data, struct t_gui_buffer *buffer, int argc,
char **argv, char **argv_eol)
{
int i, disconnect_ok;
JABBER_GET_SERVER(buffer);
/* make C compiler happy */
(void) data;
(void) argv_eol;
if (argc < 2)
disconnect_ok = jabber_command_jdisconnect_one_server (ptr_server);
else
{
disconnect_ok = 1;
if (weechat_strcasecmp (argv[1], "-all") == 0)
{
for (ptr_server = jabber_servers; ptr_server;
ptr_server = ptr_server->next_server)
{
if ((ptr_server->is_connected) || (ptr_server->hook_connect)
|| (ptr_server->reconnect_start != 0))
{
if (!jabber_command_jdisconnect_one_server (ptr_server))
disconnect_ok = 0;
}
}
}
else
{
for (i = 1; i < argc; i++)
{
ptr_server = jabber_server_search (argv[i]);
if (ptr_server)
{
if (!jabber_command_jdisconnect_one_server (ptr_server))
disconnect_ok = 0;
}
else
{
weechat_printf (NULL,
_("%s%s: server \"%s\" not found"),
weechat_prefix ("error"),
JABBER_PLUGIN_NAME, argv[i]);
disconnect_ok = 0;
}
}
}
}
if (!disconnect_ok)
return WEECHAT_RC_ERROR;
return WEECHAT_RC_OK;
}
/*
* jabber_command_init: init Jabber commands (create hooks)
*/
void
jabber_command_init ()
{
weechat_hook_command ("jabber",
N_("list, add or remove Jabber servers"),
N_("[list [servername]] | [listfull [servername]] | "
"[add servername username hostname[/port] password "
"[-auto | -noauto] [-ipv6] [-tls] [-sasl]] | "
"[copy servername newservername] | "
"[rename servername newservername] | "
"[keep servername] | [del servername] | "
"[switch]"),
N_(" list: list servers (no parameter implies "
"this list)\n"
" listfull: list servers with detailed info for "
"each server\n"
" add: create a new server\n"
"servername: server name, for internal and "
"display use\n"
" username: username to use on server\n"
" hostname: name or IP address of server, with "
"optional port (default: 5222)\n"
" password: password for username on server\n"
" auto: automatically connect to server "
"when WeeChat starts\n"
" noauto: do not connect to server when "
"WeeChat starts (default)\n"
" ipv6: use IPv6 protocol\n"
" tls: use TLS cryptographic protocol\n"
" sasl: use SASL for authentication\n"
" copy: duplicate a server\n"
" rename: rename a server\n"
" keep: keep server in config file (for "
"temporary servers only)\n"
" del: delete a server\n"
" switch: switch active server (when one "
"buffer is used for all servers, default key: "
"alt-s on server buffer)\n\n"
"Examples:\n"
" /jabber listfull\n"
" /jabber add jabberfr user jabber.fr/5222 "
"password -tls\n"
" /jabber copy jabberfr jabberfr2\n"
" /jabber rename jabberfr jabbfr\n"
" /jabber del jabberfr\n"
" /jabber switch"),
"add|copy|rename|keep|del|list|listfull|switch "
"%(jabber_servers) %(jabber_servers)",
&jabber_command_jabber, NULL);
weechat_hook_command ("jchat",
N_("chat with a buddy"),
N_("buddy [text]"),
N_("buddy: buddy name for chat\n"
" text: text to send"),
"%(nicks) %-", &jabber_command_jchat, NULL);
weechat_hook_command ("jconnect",
N_("connect to Jabber server(s)"),
N_("[-all [-nojoin] | servername [servername ...] "
"[-nojoin] | hostname [-port port] [-ipv6] "
"[-tls] [-sasl]]"),
N_(" -all: connect to all servers\n"
"servername: internal server name to connect\n"
" -nojoin: do not join any MUC (even if "
"autojoin is enabled on server)\n"
" hostname: hostname to connect\n"
" port: port for server (integer, default "
"is 6667)\n"
" ipv6: use IPv6 protocol\n"
" tls: use TLS cryptographic protocol\n"
" saal: use SASL for authentication"),
"%(jabber_servers)|-all|-nojoin|%*",
&jabber_command_jconnect, NULL);
weechat_hook_command ("jdisconnect",
N_("disconnect from Jabber server(s)"),
N_("[-all | servername [servername ...]]"),
N_(" -all: disconnect from all servers\n"
"servername: server name to disconnect"),
"%(jabber_servers)|-all",
&jabber_command_jdisconnect, NULL);
}
-37
View File
@@ -1,37 +0,0 @@
/*
* Copyright (c) 2009 by FlashCode <flashcode@flashtux.org>
* See README for License detail, AUTHORS for developers list.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __WEECHAT_JABBER_COMMAND_H
#define __WEECHAT_JABBER_COMMAND_H 1
struct t_jabber_server;
#define JABBER_COMMAND_TOO_FEW_ARGUMENTS(__buffer, __command) \
weechat_printf (__buffer, \
_("%s%s: too few arguments for \"%s\" command"), \
jabber_buffer_get_server_prefix (ptr_server, "error"), \
JABBER_PLUGIN_NAME, \
__command); \
return WEECHAT_RC_ERROR;
extern void jabber_command_quit_server (struct t_jabber_server *server,
const char *arguments);
extern void jabber_command_init ();
#endif /* jabber-command.h */
-458
View File
@@ -1,458 +0,0 @@
/*
* Copyright (c) 2009 by FlashCode <flashcode@flashtux.org>
* See README for License detail, AUTHORS for developers list.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* jabber-completion.c: completion for Jabber commands */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "../weechat-plugin.h"
#include "jabber.h"
#include "jabber-buddy.h"
#include "jabber-buffer.h"
#include "jabber-completion.h"
#include "jabber-config.h"
#include "jabber-muc.h"
#include "jabber-server.h"
/*
* jabber_completion_server_cb: callback for completion with current server
*/
int
jabber_completion_server_cb (void *data, const char *completion_item,
struct t_gui_buffer *buffer,
struct t_gui_completion *completion)
{
JABBER_GET_SERVER(buffer);
/* make C compiler happy */
(void) data;
(void) completion_item;
if (ptr_server)
{
weechat_hook_completion_list_add (completion, ptr_server->name,
0, WEECHAT_LIST_POS_SORT);
}
return WEECHAT_RC_OK;
}
/*
* jabber_completion_server_local_name_cb: callback for completion with local
* name on server
*/
int
jabber_completion_server_local_name_cb (void *data,
const char *completion_item,
struct t_gui_buffer *buffer,
struct t_gui_completion *completion)
{
const char *local_name;
JABBER_GET_SERVER(buffer);
/* make C compiler happy */
(void) data;
(void) completion_item;
if (ptr_server)
{
local_name = jabber_server_get_local_name (ptr_server);
if (local_name && local_name[0])
{
weechat_hook_completion_list_add (completion, local_name,
1, WEECHAT_LIST_POS_SORT);
}
}
return WEECHAT_RC_OK;
}
/*
* jabber_completion_server_buddies_cb: callback for completion with buddies
* of current server
*/
int
jabber_completion_server_buddies_cb (void *data, const char *completion_item,
struct t_gui_buffer *buffer,
struct t_gui_completion *completion)
{
struct t_jabber_muc *ptr_muc2;
struct t_jabber_buddy *ptr_buddy;
const char *local_name;
JABBER_GET_SERVER_MUC(buffer);
/* make C compiler happy */
(void) data;
(void) completion_item;
if (ptr_server)
{
for (ptr_muc2 = ptr_server->mucs; ptr_muc2;
ptr_muc2 = ptr_muc2->next_muc)
{
if (ptr_muc2->type == JABBER_MUC_TYPE_MUC)
{
for (ptr_buddy = ptr_muc2->buddies; ptr_buddy;
ptr_buddy = ptr_buddy->next_buddy)
{
weechat_hook_completion_list_add (completion,
ptr_buddy->name,
1, WEECHAT_LIST_POS_SORT);
}
}
}
local_name = jabber_server_get_local_name (ptr_server);
if (local_name && local_name[0])
{
/* add local name at the end */
weechat_hook_completion_list_add (completion, local_name,
1, WEECHAT_LIST_POS_END);
}
}
return WEECHAT_RC_OK;
}
/*
* jabber_completion_servers_cb: callback for completion with servers
*/
int
jabber_completion_servers_cb (void *data, const char *completion_item,
struct t_gui_buffer *buffer,
struct t_gui_completion *completion)
{
struct t_jabber_server *ptr_server;
/* make C compiler happy */
(void) data;
(void) completion_item;
(void) buffer;
for (ptr_server = jabber_servers; ptr_server;
ptr_server = ptr_server->next_server)
{
weechat_hook_completion_list_add (completion, ptr_server->name,
0, WEECHAT_LIST_POS_SORT);
}
return WEECHAT_RC_OK;
}
/*
* jabber_completion_muc_cb: callback for completion with current MUC
*/
int
jabber_completion_muc_cb (void *data, const char *completion_item,
struct t_gui_buffer *buffer,
struct t_gui_completion *completion)
{
JABBER_GET_SERVER_MUC(buffer);
/* make C compiler happy */
(void) data;
(void) completion_item;
if (ptr_muc)
{
weechat_hook_completion_list_add (completion, ptr_muc->name,
0, WEECHAT_LIST_POS_SORT);
}
return WEECHAT_RC_OK;
}
/*
* jabber_completion_muc_buddies_cb: callback for completion with buddies
* of current MUC
*/
int
jabber_completion_muc_buddies_cb (void *data, const char *completion_item,
struct t_gui_buffer *buffer,
struct t_gui_completion *completion)
{
struct t_jabber_buddy *ptr_buddy;
const char *buddy, *local_name;
int list_size, i, j;
JABBER_GET_SERVER_MUC(buffer);
/* make C compiler happy */
(void) data;
(void) completion_item;
if (ptr_muc)
{
switch (ptr_muc->type)
{
case JABBER_MUC_TYPE_MUC:
for (ptr_buddy = ptr_muc->buddies; ptr_buddy;
ptr_buddy = ptr_buddy->next_buddy)
{
weechat_hook_completion_list_add (completion,
ptr_buddy->name,
1,
WEECHAT_LIST_POS_SORT);
}
/* add buddies speaking recently on this MUC */
if (weechat_config_boolean (jabber_config_look_nick_completion_smart))
{
/* 0 => buddy speaking ; 1 => buddy speaking to me
(with highlight) */
for (i = 0; i < 2; i++)
{
if (ptr_muc->buddies_speaking[i])
{
list_size = weechat_list_size (ptr_muc->buddies_speaking[i]);
for (j = 0; j < list_size; j++)
{
buddy = weechat_list_string (weechat_list_get (ptr_muc->buddies_speaking[i], j));
if (buddy && jabber_buddy_search (NULL, ptr_muc, buddy))
{
weechat_hook_completion_list_add (completion,
buddy,
1,
WEECHAT_LIST_POS_BEGINNING);
}
}
}
}
}
/* add local name at the end */
local_name = jabber_server_get_local_name (ptr_server);
if (local_name && local_name[0])
{
weechat_hook_completion_list_add (completion,
local_name,
1,
WEECHAT_LIST_POS_END);
}
break;
case JABBER_MUC_TYPE_PRIVATE:
/* remote buddy */
weechat_hook_completion_list_add (completion,
ptr_muc->name,
0,
WEECHAT_LIST_POS_SORT);
/* add local name at the end */
local_name = jabber_server_get_local_name (ptr_server);
if (local_name && local_name[0])
{
weechat_hook_completion_list_add (completion,
local_name,
1,
WEECHAT_LIST_POS_END);
}
break;
}
ptr_muc->nick_completion_reset = 0;
}
return WEECHAT_RC_OK;
}
/*
* jabber_completion_muc_buddies_hosts_cb: callback for completion with buddies
* and hosts of current MUC
*/
int
jabber_completion_muc_buddies_hosts_cb (void *data,
const char *completion_item,
struct t_gui_buffer *buffer,
struct t_gui_completion *completion)
{
struct t_jabber_buddy *ptr_buddy;
char *buf;
int length;
JABBER_GET_SERVER_MUC(buffer);
/* make C compiler happy */
(void) data;
(void) completion_item;
if (ptr_muc)
{
switch (ptr_muc->type)
{
case JABBER_MUC_TYPE_MUC:
for (ptr_buddy = ptr_muc->buddies; ptr_buddy;
ptr_buddy = ptr_buddy->next_buddy)
{
weechat_hook_completion_list_add (completion,
ptr_buddy->name,
1,
WEECHAT_LIST_POS_SORT);
if (ptr_buddy->host)
{
length = strlen (ptr_buddy->name) + 1 +
strlen (ptr_buddy->host) + 1;
buf = malloc (length);
if (buf)
{
snprintf (buf, length, "%s!%s",
ptr_buddy->name, ptr_buddy->host);
weechat_hook_completion_list_add (completion,
buf,
0,
WEECHAT_LIST_POS_SORT);
free (buf);
}
}
}
break;
case JABBER_MUC_TYPE_PRIVATE:
weechat_hook_completion_list_add (completion,
ptr_muc->name,
0,
WEECHAT_LIST_POS_SORT);
}
}
return WEECHAT_RC_OK;
}
/*
* jabber_completion_muc_topic_cb: callback for completion with topic of
* current MUC
*/
int
jabber_completion_muc_topic_cb (void *data, const char *completion_item,
struct t_gui_buffer *buffer,
struct t_gui_completion *completion)
{
JABBER_GET_SERVER_MUC(buffer);
/* make C compiler happy */
(void) data;
(void) completion_item;
if (ptr_muc && ptr_muc->topic && ptr_muc->topic[0])
{
weechat_hook_completion_list_add (completion,
ptr_muc->topic,
0,
WEECHAT_LIST_POS_SORT);
}
return WEECHAT_RC_OK;
}
/*
* jabber_completion_mucs_cb: callback for completion with MUCs
*/
int
jabber_completion_mucs_cb (void *data, const char *completion_item,
struct t_gui_buffer *buffer,
struct t_gui_completion *completion)
{
(void) completion;
struct t_jabber_server *ptr_server;
struct t_jabber_muc *ptr_muc;
/* make C compiler happy */
(void) data;
(void) completion_item;
(void) buffer;
for (ptr_server = jabber_servers; ptr_server;
ptr_server = ptr_server->next_server)
{
for (ptr_muc = ptr_server->mucs; ptr_muc; ptr_muc = ptr_muc->next_muc)
{
weechat_hook_completion_list_add (completion,
ptr_muc->name,
0,
WEECHAT_LIST_POS_SORT);
}
}
return WEECHAT_RC_OK;
}
/*
* jabber_completion_msg_part_cb: callback for completion with default part
* message
*/
int
jabber_completion_msg_part_cb (void *data, const char *completion_item,
struct t_gui_buffer *buffer,
struct t_gui_completion *completion)
{
/* make C compiler happy */
(void) data;
(void) completion_item;
(void) buffer;
if (weechat_config_string (jabber_config_network_default_msg_part)
&& weechat_config_string (jabber_config_network_default_msg_part)[0])
{
weechat_hook_completion_list_add (completion,
weechat_config_string (jabber_config_network_default_msg_part),
0, WEECHAT_LIST_POS_SORT);
}
return WEECHAT_RC_OK;
}
/*
* jabber_completion_init: init completion for Jabber plugin
*/
void
jabber_completion_init ()
{
weechat_hook_completion ("jabber_server", "",
&jabber_completion_server_cb, NULL);
weechat_hook_completion ("jabber_server_local_name", "",
&jabber_completion_server_local_name_cb, NULL);
weechat_hook_completion ("jabber_server_buddies", "",
&jabber_completion_server_buddies_cb, NULL);
weechat_hook_completion ("jabber_servers", "",
&jabber_completion_servers_cb, NULL);
weechat_hook_completion ("jabber_muc", "",
&jabber_completion_muc_cb, NULL);
weechat_hook_completion ("buddy", "",
&jabber_completion_muc_buddies_cb, NULL);
weechat_hook_completion ("jabber_muc_buddies_hosts", "",
&jabber_completion_muc_buddies_hosts_cb, NULL);
weechat_hook_completion ("jabber_muc_topic", "",
&jabber_completion_muc_topic_cb, NULL);
weechat_hook_completion ("jabber_mucs", "",
&jabber_completion_mucs_cb, NULL);
weechat_hook_completion ("jabber_msg_part", "",
&jabber_completion_msg_part_cb, NULL);
}
-25
View File
@@ -1,25 +0,0 @@
/*
* Copyright (c) 2009 by FlashCode <flashcode@flashtux.org>
* See README for License detail, AUTHORS for developers list.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __WEECHAT_JABBER_COMPLETION_H
#define __WEECHAT_JABBER_COMPLETION_H 1
extern void jabber_completion_init ();
#endif /* jabber-completion.h */
File diff suppressed because it is too large Load Diff
-81
View File
@@ -1,81 +0,0 @@
/*
* Copyright (c) 2009 by FlashCode <flashcode@flashtux.org>
* See README for License detail, AUTHORS for developers list.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __WEECHAT_JABBER_CONFIG_H
#define __WEECHAT_JABBER_CONFIG_H 1
#define JABBER_CONFIG_NAME "jabber"
enum t_jabber_config_display_away
{
JABBER_CONFIG_DISPLAY_AWAY_OFF = 0,
JABBER_CONFIG_DISPLAY_AWAY_LOCAL,
JABBER_CONFIG_DISPLAY_AWAY_MUC,
};
extern struct t_config_file *jabber_config_file;
extern struct t_config_section *jabber_config_section_server_default;
extern struct t_config_section *jabber_config_section_server;
extern struct t_config_option *jabber_config_look_color_nicks_in_server_messages;
extern struct t_config_option *jabber_config_look_one_server_buffer;
extern struct t_config_option *jabber_config_look_open_near_server;
extern struct t_config_option *jabber_config_look_nick_prefix;
extern struct t_config_option *jabber_config_look_nick_suffix;
extern struct t_config_option *jabber_config_look_nick_completion_smart;
extern struct t_config_option *jabber_config_look_display_away;
extern struct t_config_option *jabber_config_look_display_muc_modes;
extern struct t_config_option *jabber_config_look_display_nick_modes;
extern struct t_config_option *jabber_config_look_highlight_tags;
extern struct t_config_option *jabber_config_look_show_away_once;
extern struct t_config_option *jabber_config_look_smart_filter;
extern struct t_config_option *jabber_config_look_smart_filter_delay;
extern struct t_config_option *jabber_config_color_message_join;
extern struct t_config_option *jabber_config_color_message_quit;
extern struct t_config_option *jabber_config_color_input_nick;
extern struct t_config_option *jabber_config_network_default_msg_part;
extern struct t_config_option *jabber_config_network_default_msg_quit;
extern struct t_config_option *jabber_config_network_lag_check;
extern struct t_config_option *jabber_config_network_lag_min_show;
extern struct t_config_option *jabber_config_network_lag_disconnect;
extern struct t_config_option *jabber_config_network_anti_flood;
extern struct t_config_option *jabber_config_network_colors_receive;
extern struct t_config_option *jabber_config_network_colors_send;
extern struct t_config_option *jabber_config_server_default[];
extern void jabber_config_server_change_cb (void *data,
struct t_config_option *option);
struct t_config_option *jabber_config_server_new_option (struct t_config_file *config_file,
struct t_config_section *section,
int index_option,
const char *option_name,
const char *default_value,
const char *value,
int null_value_allowed,
void *callback_change,
void *callback_change_data);
extern int jabber_config_init ();
extern int jabber_config_read ();
extern int jabber_config_write (int write_temp_servers);
extern void jabber_config_free ();
#endif /* jabber-config.h */
-176
View File
@@ -1,176 +0,0 @@
/*
* Copyright (c) 2009 by FlashCode <flashcode@flashtux.org>
* See README for License detail, AUTHORS for developers list.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* jabber-debug.c: debug functions for Jabber plugin */
#include <stdlib.h>
#include <string.h>
#include "../weechat-plugin.h"
#include "jabber.h"
#include "jabber-debug.h"
#include "jabber-server.h"
struct t_gui_buffer *jabber_debug_buffer = NULL;
/*
* jabber_debug_buffer_close_cb: callback called when Jabber debug buffer is
* closed
*/
int
jabber_debug_buffer_close_cb (void *data, struct t_gui_buffer *buffer)
{
/* make C compiler happy */
(void) data;
(void) buffer;
jabber_debug_buffer = NULL;
return WEECHAT_RC_OK;
}
/*
* jabber_debug_printf: print a message on Jabber debug buffer
*/
void
jabber_debug_printf (struct t_jabber_server *server, int send, int modified,
const char *message)
{
char *buf, *buf2;
const char *ptr_buf;
int pos_buf, pos_buf2, char_size, i;
if (!weechat_jabber_plugin->debug || !message)
return;
if (!jabber_debug_buffer)
{
jabber_debug_buffer = weechat_buffer_search (JABBER_PLUGIN_NAME,
JABBER_DEBUG_BUFFER_NAME);
if (!jabber_debug_buffer)
{
jabber_debug_buffer = weechat_buffer_new (JABBER_DEBUG_BUFFER_NAME,
NULL, NULL,
&jabber_debug_buffer_close_cb, NULL);
/* failed to create buffer ? then return */
if (!jabber_debug_buffer)
return;
weechat_buffer_set (jabber_debug_buffer,
"title", _("Jabber debug messages"));
weechat_buffer_set (jabber_debug_buffer, "short_name", JABBER_DEBUG_BUFFER_NAME);
weechat_buffer_set (jabber_debug_buffer, "localvar_set_type", "debug");
weechat_buffer_set (jabber_debug_buffer, "localvar_set_server", JABBER_DEBUG_BUFFER_NAME);
weechat_buffer_set (jabber_debug_buffer, "localvar_set_muc", JABBER_DEBUG_BUFFER_NAME);
weechat_buffer_set (jabber_debug_buffer, "localvar_set_no_log", "1");
/* disable all highlights on this debug buffer */
weechat_buffer_set (jabber_debug_buffer, "highlight_words", "-");
}
}
buf = weechat_iconv_to_internal (NULL, message);
buf2 = malloc ((strlen (buf) * 3) + 1);
if (buf2)
{
ptr_buf = (buf) ? buf : message;
pos_buf = 0;
pos_buf2 = 0;
while (ptr_buf[pos_buf])
{
if (ptr_buf[pos_buf] < 32)
{
buf2[pos_buf2++] = '\\';
buf2[pos_buf2++] = (ptr_buf[pos_buf] / 10) + '0';
buf2[pos_buf2++] = (ptr_buf[pos_buf] % 10) + '0';
pos_buf++;
}
else
{
char_size = weechat_utf8_char_size (ptr_buf + pos_buf);
for (i = 0; i < char_size; i++)
{
buf2[pos_buf2++] = ptr_buf[pos_buf++];
}
}
}
buf2[pos_buf2] = '\0';
}
weechat_printf (jabber_debug_buffer,
"%s%s%s%s%s%s\t%s",
(server) ? weechat_color ("chat_server") : "",
(iks_is_secure (server->iks_parser)) ? "[S]" : "",
(server) ? server->name : "",
(server) ? " " : "",
(send) ?
weechat_color ("chat_prefix_quit") :
weechat_color ("chat_prefix_join"),
(send) ?
((modified) ? JABBER_DEBUG_PREFIX_SEND_MOD : JABBER_DEBUG_PREFIX_SEND) :
((modified) ? JABBER_DEBUG_PREFIX_RECV_MOD : JABBER_DEBUG_PREFIX_RECV),
(buf2) ? buf2 : ((buf) ? buf : message));
if (buf)
free (buf);
if (buf2)
free (buf2);
}
/*
* jabber_debug_signal_debug_dump_cb: dump Jabber data in WeeChat log file
*/
int
jabber_debug_signal_debug_dump_cb (void *data, const char *signal,
const char *type_data, void *signal_data)
{
/* make C compiler happy */
(void) data;
(void) signal;
(void) type_data;
(void) signal_data;
weechat_log_printf ("");
weechat_log_printf ("***** \"%s\" plugin dump *****",
weechat_plugin->name);
jabber_server_print_log ();
weechat_log_printf ("");
weechat_log_printf ("***** End of \"%s\" plugin dump *****",
weechat_plugin->name);
return WEECHAT_RC_OK;
}
/*
* jabber_debug_init: initialize debug for Jabber plugin
*/
void
jabber_debug_init ()
{
weechat_hook_signal ("debug_dump", &jabber_debug_signal_debug_dump_cb, NULL);
}
-36
View File
@@ -1,36 +0,0 @@
/*
* Copyright (c) 2009 by FlashCode <flashcode@flashtux.org>
* See README for License detail, AUTHORS for developers list.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __WEECHAT_JABBER_DEBUG_H
#define __WEECHAT_JABBER_DEBUG_H 1
#define JABBER_DEBUG_BUFFER_NAME "jabber_debug"
#define JABBER_DEBUG_PREFIX_RECV "-->"
#define JABBER_DEBUG_PREFIX_RECV_MOD "==>"
#define JABBER_DEBUG_PREFIX_SEND "<--"
#define JABBER_DEBUG_PREFIX_SEND_MOD "<=="
struct t_jabber_server;
extern void jabber_debug_printf (struct t_jabber_server *server, int send,
int modified, const char *message);
extern void jabber_debug_init ();
#endif /* jabber-debug.h */
-224
View File
@@ -1,224 +0,0 @@
/*
* Copyright (c) 2009 by FlashCode <flashcode@flashtux.org>
* See README for License detail, AUTHORS for developers list.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* jabber-display.c: display functions for Jabber plugin */
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include "../weechat-plugin.h"
#include "jabber.h"
#include "jabber-command.h"
#include "jabber-config.h"
#include "jabber-server.h"
/*
* jabber_display_server: display server infos
*/
void
jabber_display_server (struct t_jabber_server *server, int with_detail)
{
int num_mucs, num_pv;
if (with_detail)
{
weechat_printf (NULL, "");
weechat_printf (NULL, _("%sServer: %s%s %s[%s%s%s]%s%s"),
JABBER_COLOR_CHAT,
JABBER_COLOR_CHAT_SERVER,
server->name,
JABBER_COLOR_CHAT_DELIMITERS,
JABBER_COLOR_CHAT,
(server->is_connected) ?
_("connected") : _("not connected"),
JABBER_COLOR_CHAT_DELIMITERS,
JABBER_COLOR_CHAT,
(server->temp_server) ? _(" (temporary)") : "");
if (weechat_config_option_is_null (server->options[JABBER_SERVER_OPTION_USERNAME]))
weechat_printf (NULL, " username . . . . . . : ('%s')",
JABBER_SERVER_OPTION_STRING(server, JABBER_SERVER_OPTION_USERNAME));
else
weechat_printf (NULL, " username . . . . . . : %s'%s'",
JABBER_COLOR_CHAT_VALUE,
weechat_config_string (server->options[JABBER_SERVER_OPTION_USERNAME]));
if (weechat_config_option_is_null (server->options[JABBER_SERVER_OPTION_SERVER]))
weechat_printf (NULL, " server . . . . . . . : ('%s')",
JABBER_SERVER_OPTION_STRING(server, JABBER_SERVER_OPTION_SERVER));
else
weechat_printf (NULL, " server . . . . . . . : %s'%s'",
JABBER_COLOR_CHAT_VALUE,
weechat_config_string (server->options[JABBER_SERVER_OPTION_SERVER]));
if (weechat_config_option_is_null (server->options[JABBER_SERVER_OPTION_PROXY]))
weechat_printf (NULL, " proxy. . . . . . . . : ('%s')",
JABBER_SERVER_OPTION_STRING(server, JABBER_SERVER_OPTION_PROXY));
else
weechat_printf (NULL, " proxy. . . . . . . . : %s'%s'",
JABBER_COLOR_CHAT_VALUE,
weechat_config_string (server->options[JABBER_SERVER_OPTION_PROXY]));
if (weechat_config_option_is_null (server->options[JABBER_SERVER_OPTION_IPV6]))
weechat_printf (NULL, " ipv6 . . . . . . . . : (%s)",
(JABBER_SERVER_OPTION_BOOLEAN(server, JABBER_SERVER_OPTION_IPV6)) ?
_("on") : _("off"));
else
weechat_printf (NULL, " ipv6 . . . . . . . . : %s%s",
JABBER_COLOR_CHAT_VALUE,
weechat_config_boolean (server->options[JABBER_SERVER_OPTION_IPV6]) ?
_("on") : _("off"));
if (weechat_config_option_is_null (server->options[JABBER_SERVER_OPTION_TLS]))
weechat_printf (NULL, " tls. . . . . . . . . : (%s)",
(JABBER_SERVER_OPTION_BOOLEAN(server, JABBER_SERVER_OPTION_TLS)) ?
_("on") : _("off"));
else
weechat_printf (NULL, " tls. . . . . . . . . : %s%s",
JABBER_COLOR_CHAT_VALUE,
weechat_config_boolean (server->options[JABBER_SERVER_OPTION_TLS]) ?
_("on") : _("off"));
if (weechat_config_option_is_null (server->options[JABBER_SERVER_OPTION_SASL]))
weechat_printf (NULL, " sasl . . . . . . . . : (%s)",
(JABBER_SERVER_OPTION_BOOLEAN(server, JABBER_SERVER_OPTION_SASL)) ?
_("on") : _("off"));
else
weechat_printf (NULL, " sasl . . . . . . . . : %s%s",
JABBER_COLOR_CHAT_VALUE,
weechat_config_boolean (server->options[JABBER_SERVER_OPTION_SASL]) ?
_("on") : _("off"));
if (weechat_config_option_is_null (server->options[JABBER_SERVER_OPTION_RESOURCE]))
weechat_printf (NULL, " resource . . . . . . : ('%s')",
JABBER_SERVER_OPTION_STRING(server, JABBER_SERVER_OPTION_RESOURCE));
else
weechat_printf (NULL, " resource . . . . . . : %s'%s'",
JABBER_COLOR_CHAT_VALUE,
weechat_config_string (server->options[JABBER_SERVER_OPTION_RESOURCE]));
if (weechat_config_option_is_null (server->options[JABBER_SERVER_OPTION_PASSWORD]))
weechat_printf (NULL, " password . . . . . . : %s",
_("(hidden)"));
else
weechat_printf (NULL, " password . . . . . . : %s%s",
JABBER_COLOR_CHAT_VALUE,
_("(hidden)"));
if (weechat_config_option_is_null (server->options[JABBER_SERVER_OPTION_LOCAL_ALIAS]))
weechat_printf (NULL, " local_alias. . . . . : ('%s')",
JABBER_SERVER_OPTION_STRING(server, JABBER_SERVER_OPTION_LOCAL_ALIAS));
else
weechat_printf (NULL, " local_alias. . . . . : %s'%s'",
JABBER_COLOR_CHAT_VALUE,
weechat_config_string (server->options[JABBER_SERVER_OPTION_LOCAL_ALIAS]));
if (weechat_config_option_is_null (server->options[JABBER_SERVER_OPTION_AUTOCONNECT]))
weechat_printf (NULL, " autoconnect. . . . . : (%s)",
(JABBER_SERVER_OPTION_BOOLEAN(server, JABBER_SERVER_OPTION_AUTOCONNECT)) ?
_("on") : _("off"));
else
weechat_printf (NULL, " autoconnect. . . . . : %s%s",
JABBER_COLOR_CHAT_VALUE,
weechat_config_boolean (server->options[JABBER_SERVER_OPTION_AUTOCONNECT]) ?
_("on") : _("off"));
if (weechat_config_option_is_null (server->options[JABBER_SERVER_OPTION_AUTORECONNECT]))
weechat_printf (NULL, " autoreconnect. . . . : (%s)",
(JABBER_SERVER_OPTION_BOOLEAN(server, JABBER_SERVER_OPTION_AUTORECONNECT)) ?
_("on") : _("off"));
else
weechat_printf (NULL, " autoreconnect. . . . : %s%s",
JABBER_COLOR_CHAT_VALUE,
weechat_config_boolean (server->options[JABBER_SERVER_OPTION_AUTORECONNECT]) ?
_("on") : _("off"));
if (weechat_config_option_is_null (server->options[JABBER_SERVER_OPTION_AUTORECONNECT_DELAY]))
weechat_printf (NULL, " autoreconnect_delay. : (%d %s)",
JABBER_SERVER_OPTION_INTEGER(server, JABBER_SERVER_OPTION_AUTORECONNECT_DELAY),
NG_("second", "seconds", JABBER_SERVER_OPTION_INTEGER(server, JABBER_SERVER_OPTION_AUTORECONNECT_DELAY)));
else
weechat_printf (NULL, " autoreconnect_delay. : %s%d %s",
JABBER_COLOR_CHAT_VALUE,
weechat_config_integer (server->options[JABBER_SERVER_OPTION_AUTORECONNECT_DELAY]),
NG_("second", "seconds", weechat_config_integer (server->options[JABBER_SERVER_OPTION_AUTORECONNECT_DELAY])));
if (weechat_config_option_is_null (server->options[JABBER_SERVER_OPTION_LOCAL_HOSTNAME]))
weechat_printf (NULL, " local_hostname . . . : ('%s')",
JABBER_SERVER_OPTION_STRING(server, JABBER_SERVER_OPTION_LOCAL_HOSTNAME));
else
weechat_printf (NULL, " local_hostname . . . : %s'%s'",
JABBER_COLOR_CHAT_VALUE,
weechat_config_string (server->options[JABBER_SERVER_OPTION_LOCAL_HOSTNAME]));
if (weechat_config_option_is_null (server->options[JABBER_SERVER_OPTION_COMMAND]))
weechat_printf (NULL, " command. . . . . . . : ('%s')",
JABBER_SERVER_OPTION_STRING(server, JABBER_SERVER_OPTION_COMMAND));
else
weechat_printf (NULL, " command. . . . . . . : %s'%s'",
JABBER_COLOR_CHAT_VALUE,
weechat_config_string (server->options[JABBER_SERVER_OPTION_COMMAND]));
if (weechat_config_option_is_null (server->options[JABBER_SERVER_OPTION_COMMAND_DELAY]))
weechat_printf (NULL, " command_delay. . . . : (%d %s)",
JABBER_SERVER_OPTION_INTEGER(server, JABBER_SERVER_OPTION_COMMAND_DELAY),
NG_("second", "seconds", JABBER_SERVER_OPTION_INTEGER(server, JABBER_SERVER_OPTION_COMMAND_DELAY)));
else
weechat_printf (NULL, " command_delay. . . . : %s%d %s",
JABBER_COLOR_CHAT_VALUE,
weechat_config_integer (server->options[JABBER_SERVER_OPTION_COMMAND_DELAY]),
NG_("second", "seconds", weechat_config_integer (server->options[JABBER_SERVER_OPTION_COMMAND_DELAY])));
if (weechat_config_option_is_null (server->options[JABBER_SERVER_OPTION_AUTOJOIN]))
weechat_printf (NULL, " autojoin . . . . . . : ('%s')",
JABBER_SERVER_OPTION_STRING(server, JABBER_SERVER_OPTION_AUTOJOIN));
else
weechat_printf (NULL, " autojoin . . . . . . : %s'%s'",
JABBER_COLOR_CHAT_VALUE,
weechat_config_string (server->options[JABBER_SERVER_OPTION_AUTOJOIN]));
if (weechat_config_option_is_null (server->options[JABBER_SERVER_OPTION_AUTOREJOIN]))
weechat_printf (NULL, " autorejoin . . . . . : (%s)",
(JABBER_SERVER_OPTION_BOOLEAN(server, JABBER_SERVER_OPTION_AUTOREJOIN)) ?
_("on") : _("off"));
else
weechat_printf (NULL, " autorejoin . . . . . : %s%s",
JABBER_COLOR_CHAT_VALUE,
weechat_config_boolean (server->options[JABBER_SERVER_OPTION_AUTOREJOIN]) ?
_("on") : _("off"));
}
else
{
if (server->is_connected)
{
num_mucs = jabber_server_get_muc_count (server);
num_pv = jabber_server_get_pv_count (server);
weechat_printf (NULL, " %s %s%s %s[%s%s%s]%s%s, %d %s, %d pv",
(server->is_connected) ? "*" : " ",
JABBER_COLOR_CHAT_SERVER,
server->name,
JABBER_COLOR_CHAT_DELIMITERS,
JABBER_COLOR_CHAT,
(server->is_connected) ?
_("connected") : _("not connected"),
JABBER_COLOR_CHAT_DELIMITERS,
JABBER_COLOR_CHAT,
(server->temp_server) ? _(" (temporary)") : "",
num_mucs,
NG_("MUC", "MUCs", num_mucs),
num_pv);
}
else
{
weechat_printf (NULL, " %s%s%s%s",
JABBER_COLOR_CHAT_SERVER,
server->name,
JABBER_COLOR_CHAT,
(server->temp_server) ? _(" (temporary)") : "");
}
}
}
-26
View File
@@ -1,26 +0,0 @@
/*
* Copyright (c) 2009 by FlashCode <flashcode@flashtux.org>
* See README for License detail, AUTHORS for developers list.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __WEECHAT_JABBER_DISPLAY_H
#define __WEECHAT_JABBER_DISPLAY_H 1
extern void jabber_display_server (struct t_jabber_server *server,
int with_detail);
#endif /* jabber-display.h */
-357
View File
@@ -1,357 +0,0 @@
/*
* Copyright (c) 2009 by FlashCode <flashcode@flashtux.org>
* See README for License detail, AUTHORS for developers list.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* jabber-info.c: info and infolist hooks for Jabber plugin */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "../weechat-plugin.h"
#include "jabber.h"
#include "jabber-buddy.h"
#include "jabber-muc.h"
#include "jabber-server.h"
/*
* jabber_info_create_string_with_pointer: create a string with a pointer inside
* a Jabber structure
*/
void
jabber_info_create_string_with_pointer (char **string, void *pointer)
{
if (*string)
{
free (*string);
*string = NULL;
}
if (pointer)
{
*string = malloc (64);
if (*string)
{
snprintf (*string, 64 - 1, "0x%lx", (long unsigned int)pointer);
}
}
}
/*
* jabber_info_get_info_cb: callback called when Jabber info is asked
*/
const char *
jabber_info_get_info_cb (void *data, const char *info_name,
const char *arguments)
{
char *pos_comma, *pos_comma2, *server, *muc, *host;
struct t_jabber_server *ptr_server;
struct t_jabber_muc *ptr_muc;
/* make C compiler happy */
(void) data;
if (weechat_strcasecmp (info_name, "jabber_buffer") == 0)
{
if (arguments && arguments[0])
{
server = NULL;
muc = NULL;
host = NULL;
ptr_server = NULL;
ptr_muc = NULL;
pos_comma = strchr (arguments, ',');
if (pos_comma)
{
server = weechat_strndup (arguments, pos_comma - arguments);
pos_comma2 = strchr (pos_comma + 1, ',');
if (pos_comma2)
{
muc = weechat_strndup (pos_comma + 1,
pos_comma2 - pos_comma - 1);
host = strdup (pos_comma2 + 1);
}
else
muc = strdup (pos_comma + 1);
}
/* replace MUC by buddy in host if MUC is not a MUC (private ?) */
if (muc && host)
{
//if (!jabber_muc_is_muc (muc))
//{
// free (muc);
// muc = NULL;
// buddy = jabber_xmpp_get_buddy_from_host (host);
// if (buddy)
// muc = strdup (buddy);
//}
}
/* search for server or MUC buffer */
if (server)
{
ptr_server = jabber_server_search (server);
if (ptr_server && muc)
ptr_muc = jabber_muc_search (ptr_server, muc);
}
if (server)
free (server);
if (muc)
free (muc);
if (host)
free (host);
if (ptr_muc)
{
jabber_info_create_string_with_pointer (&ptr_muc->buffer_as_string,
ptr_muc->buffer);
return ptr_muc->buffer_as_string;
}
if (ptr_server)
{
jabber_info_create_string_with_pointer (&ptr_server->buffer_as_string,
ptr_server->buffer);
return ptr_server->buffer_as_string;
}
}
}
return NULL;
}
/*
* jabber_info_get_infolist_cb: callback called when Jabber infolist is asked
*/
struct t_infolist *
jabber_info_get_infolist_cb (void *data, const char *infolist_name,
void *pointer, const char *arguments)
{
struct t_infolist *ptr_infolist;
struct t_jabber_server *ptr_server;
struct t_jabber_muc *ptr_muc;
struct t_jabber_buddy *ptr_buddy;
char *pos_comma, *server_name;
/* make C compiler happy */
(void) data;
if (!infolist_name || !infolist_name[0])
return NULL;
if (weechat_strcasecmp (infolist_name, "jabber_server") == 0)
{
if (pointer && !jabber_server_valid (pointer))
return NULL;
ptr_infolist = weechat_infolist_new ();
if (ptr_infolist)
{
if (pointer)
{
/* build list with only one server */
if (!jabber_server_add_to_infolist (ptr_infolist, pointer))
{
weechat_infolist_free (ptr_infolist);
return NULL;
}
return ptr_infolist;
}
else
{
/* build list with all servers */
for (ptr_server = jabber_servers; ptr_server;
ptr_server = ptr_server->next_server)
{
if (!jabber_server_add_to_infolist (ptr_infolist, ptr_server))
{
weechat_infolist_free (ptr_infolist);
return NULL;
}
}
return ptr_infolist;
}
}
}
else if (weechat_strcasecmp (infolist_name, "jabber_muc") == 0)
{
if (arguments && arguments[0])
{
ptr_server = jabber_server_search (arguments);
if (ptr_server)
{
if (pointer && !jabber_muc_valid (ptr_server, pointer))
return NULL;
ptr_infolist = weechat_infolist_new ();
if (ptr_infolist)
{
if (pointer)
{
/* build list with only one MUC */
if (!jabber_muc_add_to_infolist (ptr_infolist, pointer))
{
weechat_infolist_free (ptr_infolist);
return NULL;
}
return ptr_infolist;
}
else
{
/* build list with all MUCs of server */
for (ptr_muc = ptr_server->mucs; ptr_muc;
ptr_muc = ptr_muc->next_muc)
{
if (!jabber_muc_add_to_infolist (ptr_infolist,
ptr_muc))
{
weechat_infolist_free (ptr_infolist);
return NULL;
}
}
return ptr_infolist;
}
}
}
}
}
else if (weechat_strcasecmp (infolist_name, "jabber_buddy") == 0)
{
if (arguments && arguments[0])
{
ptr_server = NULL;
ptr_muc = NULL;
pos_comma = strchr (arguments, ',');
if (pos_comma)
{
server_name = weechat_strndup (arguments, pos_comma - arguments);
if (server_name)
{
ptr_server = jabber_server_search (server_name);
if (ptr_server)
{
ptr_muc = jabber_muc_search (ptr_server,
pos_comma + 1);
}
free (server_name);
}
}
if (ptr_muc)
{
if (pointer && !jabber_buddy_valid (NULL, ptr_muc, pointer))
return NULL;
ptr_infolist = weechat_infolist_new ();
if (ptr_infolist)
{
if (pointer)
{
/* build list with only one buddy */
if (!jabber_buddy_add_to_infolist (ptr_infolist, pointer))
{
weechat_infolist_free (ptr_infolist);
return NULL;
}
return ptr_infolist;
}
else
{
/* build list with all buddies of MUC */
for (ptr_buddy = ptr_muc->buddies; ptr_buddy;
ptr_buddy = ptr_buddy->next_buddy)
{
if (!jabber_buddy_add_to_infolist (ptr_infolist,
ptr_buddy))
{
weechat_infolist_free (ptr_infolist);
return NULL;
}
}
return ptr_infolist;
}
}
}
else if (ptr_server)
{
if (pointer && !jabber_buddy_valid (ptr_server, NULL, pointer))
return NULL;
ptr_infolist = weechat_infolist_new ();
if (ptr_infolist)
{
if (pointer)
{
/* build list with only one buddy */
if (!jabber_buddy_add_to_infolist (ptr_infolist, pointer))
{
weechat_infolist_free (ptr_infolist);
return NULL;
}
return ptr_infolist;
}
else
{
/* build list with all buddies of server */
for (ptr_buddy = ptr_server->buddies; ptr_buddy;
ptr_buddy = ptr_buddy->next_buddy)
{
if (!jabber_buddy_add_to_infolist (ptr_infolist,
ptr_buddy))
{
weechat_infolist_free (ptr_infolist);
return NULL;
}
}
return ptr_infolist;
}
}
}
}
}
return NULL;
}
/*
* jabber_info_init: initialize info and infolist hooks for Jabber plugin
*/
void
jabber_info_init ()
{
/* info hooks */
weechat_hook_info ("jabber_buffer",
N_("get buffer pointer for a Jabber server/MUC"),
&jabber_info_get_info_cb, NULL);
/* infolist hooks */
weechat_hook_infolist ("jabber_server",
N_("list of Jabber servers"),
&jabber_info_get_infolist_cb, NULL);
weechat_hook_infolist ("jabber_muc",
N_("list of MUCs for a Jabber server"),
&jabber_info_get_infolist_cb, NULL);
weechat_hook_infolist ("jabber_buddy",
N_("list of buddies for a Jabber server or MUC"),
&jabber_info_get_infolist_cb, NULL);
}
-25
View File
@@ -1,25 +0,0 @@
/*
* Copyright (c) 2009 by FlashCode <flashcode@flashtux.org>
* See README for License detail, AUTHORS for developers list.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __WEECHAT_JABBER_INFO_H
#define __WEECHAT_JABBER_INFO_H 1
extern void jabber_info_init ();
#endif /* jabber-info.h */
-104
View File
@@ -1,104 +0,0 @@
/*
* Copyright (c) 2009 by FlashCode <flashcode@flashtux.org>
* See README for License detail, AUTHORS for developers list.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* jabber-input.c: Jabber input data (read from user) */
#include <stdlib.h>
#include <string.h>
#include "../weechat-plugin.h"
#include "jabber.h"
#include "jabber-buffer.h"
#include "jabber-server.h"
#include "jabber-muc.h"
#include "jabber-buddy.h"
#include "jabber-config.h"
#include "jabber-xmpp.h"
/*
* jabber_input_user_message_display: display user message
*/
void
jabber_input_user_message_display (struct t_gui_buffer *buffer,
const char *text)
{
struct t_jabber_buddy *ptr_buddy;
const char *local_name;
JABBER_GET_SERVER_MUC(buffer);
local_name = jabber_server_get_local_name (ptr_server);
if (ptr_muc)
{
if (ptr_muc->type == JABBER_MUC_TYPE_MUC)
ptr_buddy = jabber_buddy_search (NULL, ptr_muc, local_name);
else
ptr_buddy = NULL;
weechat_printf_tags (buffer,
jabber_xmpp_tags ("chat_msg", "no_highlight"),
"%s%s",
jabber_buddy_as_prefix ((ptr_buddy) ? ptr_buddy : NULL,
(ptr_buddy) ? NULL : local_name,
JABBER_COLOR_CHAT_NICK_SELF),
text);
}
}
/*
* jabber_input_data_cb: callback for input data in a buffer
*/
int
jabber_input_data_cb (void *data, struct t_gui_buffer *buffer,
const char *input_data)
{
const char *ptr_data;
char *msg;
/* make C compiler happy */
(void) data;
JABBER_GET_SERVER_MUC(buffer);
if (ptr_muc)
{
ptr_data = ((input_data[0] == '/') && (input_data[1] == '/')) ?
input_data + 1 : input_data;
msg = strdup (ptr_data);
if (msg)
{
jabber_xmpp_send_chat_message (ptr_server, ptr_muc, msg);
jabber_input_user_message_display (buffer, msg);
free (msg);
}
}
else
{
weechat_printf (buffer,
_("%s: this buffer is not a MUC!"),
JABBER_PLUGIN_NAME);
}
return WEECHAT_RC_OK;
}
-30
View File
@@ -1,30 +0,0 @@
/*
* Copyright (c) 2009 by FlashCode <flashcode@flashtux.org>
* See README for License detail, AUTHORS for developers list.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __WEECHAT_JABBER_INPUT_H
#define __WEECHAT_JABBER_INPUT_H 1
struct t_gui_buffer;
extern void jabber_input_user_message_display (struct t_gui_buffer *buffer,
const char *text);
extern int jabber_input_data_cb (void *data, struct t_gui_buffer *buffer,
const char *input_data);
#endif /* jabber-input.h */
-683
View File
@@ -1,683 +0,0 @@
/*
* Copyright (c) 2009 by FlashCode <flashcode@flashtux.org>
* See README for License detail, AUTHORS for developers list.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* jabber-muc.c: jabber MUC management */
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include "../weechat-plugin.h"
#include "jabber.h"
#include "jabber-muc.h"
#include "jabber-buffer.h"
#include "jabber-config.h"
#include "jabber-buddy.h"
#include "jabber-server.h"
#include "jabber-input.h"
/*
* jabber_muc_valid: check if a MUC pointer exists for a server
* return 1 if MUC exists
* 0 if MUC is not found
*/
int
jabber_muc_valid (struct t_jabber_server *server, struct t_jabber_muc *muc)
{
struct t_jabber_muc *ptr_muc;
if (!server)
return 0;
for (ptr_muc = server->mucs; ptr_muc; ptr_muc = ptr_muc->next_muc)
{
if (ptr_muc == muc)
return 1;
}
/* MUC not found */
return 0;
}
/*
* jabber_muc_new: allocate a new MUC for a server and add it to MUC list
*/
struct t_jabber_muc *
jabber_muc_new (struct t_jabber_server *server, int muc_type,
const char *muc_name, int switch_to_muc, int auto_switch)
{
struct t_jabber_muc *new_muc;
struct t_gui_buffer *new_buffer;
int buffer_created;
char *buffer_name;
/* alloc memory for new MUCl */
if ((new_muc = malloc (sizeof (*new_muc))) == NULL)
{
weechat_printf (NULL,
_("%s%s: cannot allocate new MUC"),
weechat_prefix ("error"), JABBER_PLUGIN_NAME);
return NULL;
}
/* create buffer for MUC (or use existing one) */
buffer_created = 0;
buffer_name = jabber_buffer_build_name (server->name, muc_name);
new_buffer = weechat_buffer_search (JABBER_PLUGIN_NAME, buffer_name);
if (new_buffer)
weechat_nicklist_remove_all (new_buffer);
else
{
new_buffer = weechat_buffer_new (buffer_name,
&jabber_input_data_cb, NULL,
&jabber_buffer_close_cb, NULL);
if (!new_buffer)
{
free (new_muc);
return NULL;
}
buffer_created = 1;
}
weechat_buffer_set (new_buffer, "short_name", muc_name);
weechat_buffer_set (new_buffer, "localvar_set_type",
(muc_type == JABBER_MUC_TYPE_MUC) ? "channel" : "private");
weechat_buffer_set (new_buffer, "localvar_set_nick",
jabber_server_get_local_name (server));
weechat_buffer_set (new_buffer, "localvar_set_server", server->name);
weechat_buffer_set (new_buffer, "localvar_set_muc", muc_name);
if (buffer_created)
{
weechat_hook_signal_send ("logger_backlog",
WEECHAT_HOOK_SIGNAL_POINTER, new_buffer);
}
if (muc_type == JABBER_MUC_TYPE_MUC)
{
weechat_buffer_set (new_buffer, "nicklist", "1");
weechat_buffer_set (new_buffer, "nicklist_display_groups", "0");
weechat_nicklist_add_group (new_buffer, NULL, JABBER_BUDDY_GROUP_OP,
"weechat.color.nicklist_group", 1);
weechat_nicklist_add_group (new_buffer, NULL, JABBER_BUDDY_GROUP_HALFOP,
"weechat.color.nicklist_group", 1);
weechat_nicklist_add_group (new_buffer, NULL, JABBER_BUDDY_GROUP_VOICE,
"weechat.color.nicklist_group", 1);
weechat_nicklist_add_group (new_buffer, NULL, JABBER_BUDDY_GROUP_CHANUSER,
"weechat.color.nicklist_group", 1);
weechat_nicklist_add_group (new_buffer, NULL, JABBER_BUDDY_GROUP_NORMAL,
"weechat.color.nicklist_group", 1);
}
/* set highlights settings on MUC buffer */
weechat_buffer_set (new_buffer, "highlight_words",
jabber_server_get_local_name (server));
if (weechat_config_string (jabber_config_look_highlight_tags)
&& weechat_config_string (jabber_config_look_highlight_tags)[0])
{
weechat_buffer_set (new_buffer, "highlight_tags",
weechat_config_string (jabber_config_look_highlight_tags));
}
/* initialize new MUC */
new_muc->type = muc_type;
new_muc->name = strdup (muc_name);
new_muc->topic = NULL;
new_muc->modes = NULL;
new_muc->limit = 0;
new_muc->key = NULL;
new_muc->away_message = NULL;
new_muc->nick_completion_reset = 0;
new_muc->buddies_count = 0;
new_muc->buddies = NULL;
new_muc->last_buddy = NULL;
new_muc->buddies_speaking[0] = NULL;
new_muc->buddies_speaking[1] = NULL;
new_muc->buddies_speaking_time = NULL;
new_muc->last_buddy_speaking_time = NULL;
new_muc->buffer = new_buffer;
new_muc->buffer_as_string = NULL;
/* add new MUC to MUCs list */
new_muc->prev_muc = server->last_muc;
new_muc->next_muc = NULL;
if (server->mucs)
(server->last_muc)->next_muc = new_muc;
else
server->mucs = new_muc;
server->last_muc = new_muc;
if (switch_to_muc)
{
weechat_buffer_set (new_buffer, "display",
(auto_switch) ? "auto" : "1");
}
/* all is ok, return address of new muc */
return new_muc;
}
/*
* jabber_muc_set_topic: set topic for a muc
*/
void
jabber_muc_set_topic (struct t_jabber_muc *muc, const char *topic)
{
if (muc->topic)
free (muc->topic);
muc->topic = (topic) ? strdup (topic) : NULL;
weechat_buffer_set (muc->buffer, "title", (muc->topic) ? muc->topic : "");
}
/*
* jabber_muc_search: returns pointer on a muc with name
*/
struct t_jabber_muc *
jabber_muc_search (struct t_jabber_server *server, const char *muc_name)
{
struct t_jabber_muc *ptr_muc;
if (!server || !muc_name)
return NULL;
for (ptr_muc = server->mucs; ptr_muc;
ptr_muc = ptr_muc->next_muc)
{
if (weechat_strcasecmp (ptr_muc->name, muc_name) == 0)
return ptr_muc;
}
return NULL;
}
/*
* jabber_muc_remove_away: remove away for all buddies in a MUC
*/
void
jabber_muc_remove_away (struct t_jabber_muc *muc)
{
struct t_jabber_buddy *ptr_buddy;
if (muc->type == JABBER_MUC_TYPE_MUC)
{
for (ptr_buddy = muc->buddies; ptr_buddy;
ptr_buddy = ptr_buddy->next_buddy)
{
jabber_buddy_set (NULL, muc, ptr_buddy, 0, JABBER_BUDDY_AWAY);
}
}
}
/*
* jabber_muc_set_away: set/unset away status for a MUC
*/
void
jabber_muc_set_away (struct t_jabber_muc *muc, const char *buddy_name,
int is_away)
{
struct t_jabber_buddy *ptr_buddy;
if (muc->type == JABBER_MUC_TYPE_MUC)
{
ptr_buddy = jabber_buddy_search (NULL, muc, buddy_name);
if (ptr_buddy)
jabber_buddy_set_away (NULL, muc, ptr_buddy, is_away);
}
}
/*
* jabber_muc_buddy_speaking_add: add a buddy speaking in a MUC
*/
void
jabber_muc_buddy_speaking_add (struct t_jabber_muc *muc, const char *buddy_name,
int highlight)
{
int size, to_remove, i;
struct t_weelist_item *ptr_item;
if (highlight < 0)
highlight = 0;
if (highlight > 1)
highlight = 1;
/* create list if it does not exist */
if (!muc->buddies_speaking[highlight])
muc->buddies_speaking[highlight] = weechat_list_new ();
/* remove item if it was already in list */
ptr_item = weechat_list_casesearch (muc->buddies_speaking[highlight],
buddy_name);
if (ptr_item)
weechat_list_remove (muc->buddies_speaking[highlight], ptr_item);
/* add buddy in list */
weechat_list_add (muc->buddies_speaking[highlight], buddy_name,
WEECHAT_LIST_POS_END, NULL);
/* reduce list size if it's too big */
size = weechat_list_size (muc->buddies_speaking[highlight]);
if (size > JABBER_MUC_BUDDIES_SPEAKING_LIMIT)
{
to_remove = size - JABBER_MUC_BUDDIES_SPEAKING_LIMIT;
for (i = 0; i < to_remove; i++)
{
weechat_list_remove (muc->buddies_speaking[highlight],
weechat_list_get (muc->buddies_speaking[highlight], 0));
}
}
}
/*
* jabber_muc_buddy_speaking_rename: rename a buddy speaking in a MUC
*/
void
jabber_muc_buddy_speaking_rename (struct t_jabber_muc *muc,
const char *old_nick,
const char *new_nick)
{
struct t_weelist_item *ptr_item;
int i;
for (i = 0; i < 2; i++)
{
if (muc->buddies_speaking[i])
{
ptr_item = weechat_list_search (muc->buddies_speaking[i], old_nick);
if (ptr_item)
weechat_list_set (ptr_item, new_nick);
}
}
}
/*
* jabber_muc_buddy_speaking_time_search: search a buddy speaking time in a MUC
*/
struct t_jabber_muc_speaking *
jabber_muc_buddy_speaking_time_search (struct t_jabber_muc *muc,
const char *buddy_name,
int check_time)
{
struct t_jabber_muc_speaking *ptr_buddy;
time_t time_limit;
time_limit = time (NULL) -
(weechat_config_integer (jabber_config_look_smart_filter_delay) * 60);
for (ptr_buddy = muc->buddies_speaking_time; ptr_buddy;
ptr_buddy = ptr_buddy->next_buddy)
{
if (strcmp (ptr_buddy->buddy, buddy_name) == 0)
{
if (check_time && (ptr_buddy->time_last_message < time_limit))
return NULL;
return ptr_buddy;
}
}
/* buddy speaking time not found */
return NULL;
}
/*
* jabber_muc_buddy_speaking_time_free: free a buddy speaking in a MUC
*/
void
jabber_muc_buddy_speaking_time_free (struct t_jabber_muc *muc,
struct t_jabber_muc_speaking *buddy_speaking)
{
/* free data */
if (buddy_speaking->buddy)
free (buddy_speaking->buddy);
/* remove buddy from list */
if (buddy_speaking->prev_buddy)
(buddy_speaking->prev_buddy)->next_buddy = buddy_speaking->next_buddy;
if (buddy_speaking->next_buddy)
(buddy_speaking->next_buddy)->prev_buddy = buddy_speaking->prev_buddy;
if (muc->buddies_speaking_time == buddy_speaking)
muc->buddies_speaking_time = buddy_speaking->next_buddy;
if (muc->last_buddy_speaking_time == buddy_speaking)
muc->last_buddy_speaking_time = buddy_speaking->prev_buddy;
free (buddy_speaking);
}
/*
* jabber_muc_buddy_speaking_time_free_all: free all buddies speaking in a MUC
*/
void
jabber_muc_buddy_speaking_time_free_all (struct t_jabber_muc *muc)
{
while (muc->buddies_speaking_time)
{
jabber_muc_buddy_speaking_time_free (muc,
muc->buddies_speaking_time);
}
}
/*
* jabber_muc_buddy_speaking_time_remove_old: remove old buddies speaking
*/
void
jabber_muc_buddy_speaking_time_remove_old (struct t_jabber_muc *muc)
{
time_t time_limit;
time_limit = time (NULL) -
(weechat_config_integer (jabber_config_look_smart_filter_delay) * 60);
while (muc->last_buddy_speaking_time)
{
if (muc->last_buddy_speaking_time->time_last_message >= time_limit)
break;
jabber_muc_buddy_speaking_time_free (muc,
muc->last_buddy_speaking_time);
}
}
/*
* jabber_muc_buddy_speaking_time_add: add a buddy speaking time in a MUC
*/
void
jabber_muc_buddy_speaking_time_add (struct t_jabber_muc *muc,
const char *buddy_name,
time_t time_last_message)
{
struct t_jabber_muc_speaking *ptr_buddy, *new_buddy;
ptr_buddy = jabber_muc_buddy_speaking_time_search (muc, buddy_name, 0);
if (ptr_buddy)
jabber_muc_buddy_speaking_time_free (muc, ptr_buddy);
new_buddy = malloc (sizeof (*new_buddy));
if (new_buddy)
{
new_buddy->buddy = strdup (buddy_name);
new_buddy->time_last_message = time_last_message;
/* insert buddy at beginning of list */
new_buddy->prev_buddy = NULL;
new_buddy->next_buddy = muc->buddies_speaking_time;
if (muc->buddies_speaking_time)
muc->buddies_speaking_time->prev_buddy = new_buddy;
else
muc->last_buddy_speaking_time = new_buddy;
muc->buddies_speaking_time = new_buddy;
}
}
/*
* jabber_muc_buddy_speaking_time_rename: rename a buddy speaking time in a MUC
*/
void
jabber_muc_buddy_speaking_time_rename (struct t_jabber_muc *muc,
const char *old_buddy,
const char *new_buddy)
{
struct t_jabber_muc_speaking *ptr_buddy;
if (muc->buddies_speaking_time)
{
ptr_buddy = jabber_muc_buddy_speaking_time_search (muc, old_buddy, 0);
if (ptr_buddy)
{
free (ptr_buddy->buddy);
ptr_buddy->buddy = strdup (new_buddy);
}
}
}
/*
* jabber_muc_free: free a muc and remove it from MUCs list
*/
void
jabber_muc_free (struct t_jabber_server *server, struct t_jabber_muc *muc)
{
struct t_jabber_muc *new_mucs;
if (!server || !muc)
return;
/* remove muc from MUCs list */
if (server->last_muc == muc)
server->last_muc = muc->prev_muc;
if (muc->prev_muc)
{
(muc->prev_muc)->next_muc = muc->next_muc;
new_mucs = server->mucs;
}
else
new_mucs = muc->next_muc;
if (muc->next_muc)
(muc->next_muc)->prev_muc = muc->prev_muc;
/* free data */
if (muc->name)
free (muc->name);
if (muc->topic)
free (muc->topic);
if (muc->modes)
free (muc->modes);
if (muc->key)
free (muc->key);
jabber_buddy_free_all (NULL, muc);
if (muc->away_message)
free (muc->away_message);
if (muc->buddies_speaking[0])
weechat_list_free (muc->buddies_speaking[0]);
if (muc->buddies_speaking[1])
weechat_list_free (muc->buddies_speaking[1]);
jabber_muc_buddy_speaking_time_free_all (muc);
if (muc->buffer_as_string)
free (muc->buffer_as_string);
free (muc);
server->mucs = new_mucs;
}
/*
* jabber_muc_free_all: free all allocated MUCs for a server
*/
void
jabber_muc_free_all (struct t_jabber_server *server)
{
while (server->mucs)
{
jabber_muc_free (server, server->mucs);
}
}
/*
* jabber_muc_add_to_infolist: add a muc in an infolist
* return 1 if ok, 0 if error
*/
int
jabber_muc_add_to_infolist (struct t_infolist *infolist,
struct t_jabber_muc *muc)
{
struct t_infolist_item *ptr_item;
struct t_weelist_item *ptr_list_item;
struct t_jabber_muc_speaking *ptr_buddy;
char option_name[64];
int i, index;
if (!infolist || !muc)
return 0;
ptr_item = weechat_infolist_new_item (infolist);
if (!ptr_item)
return 0;
if (!weechat_infolist_new_var_pointer (ptr_item, "buffer", muc->buffer))
return 0;
if (!weechat_infolist_new_var_string (ptr_item, "buffer_name",
(muc->buffer) ?
weechat_buffer_get_string (muc->buffer, "name") : ""))
return 0;
if (!weechat_infolist_new_var_string (ptr_item, "buffer_short_name",
(muc->buffer) ?
weechat_buffer_get_string (muc->buffer, "short_name") : ""))
return 0;
if (!weechat_infolist_new_var_integer (ptr_item, "type", muc->type))
return 0;
if (!weechat_infolist_new_var_string (ptr_item, "name", muc->name))
return 0;
if (!weechat_infolist_new_var_string (ptr_item, "topic", muc->topic))
return 0;
if (!weechat_infolist_new_var_string (ptr_item, "modes", muc->modes))
return 0;
if (!weechat_infolist_new_var_integer (ptr_item, "limit", muc->limit))
return 0;
if (!weechat_infolist_new_var_string (ptr_item, "key", muc->key))
return 0;
if (!weechat_infolist_new_var_integer (ptr_item, "buddies_count", muc->buddies_count))
return 0;
if (!weechat_infolist_new_var_string (ptr_item, "away_message", muc->away_message))
return 0;
if (!weechat_infolist_new_var_integer (ptr_item, "nick_completion_reset", muc->nick_completion_reset))
return 0;
for (i = 0; i < 2; i++)
{
if (muc->buddies_speaking[i])
{
index = 0;
for (ptr_list_item = weechat_list_get (muc->buddies_speaking[i], 0);
ptr_list_item;
ptr_list_item = weechat_list_next (ptr_list_item))
{
snprintf (option_name, sizeof (option_name),
"buddy_speaking%d_%05d", i, index);
if (!weechat_infolist_new_var_string (ptr_item, option_name,
weechat_list_string (ptr_list_item)))
return 0;
index++;
}
}
}
if (muc->buddies_speaking_time)
{
i = 0;
for (ptr_buddy = muc->last_buddy_speaking_time; ptr_buddy;
ptr_buddy = ptr_buddy->prev_buddy)
{
snprintf (option_name, sizeof (option_name),
"buddy_speaking_time_buddy_%05d", i);
if (!weechat_infolist_new_var_string (ptr_item, option_name,
ptr_buddy->buddy))
return 0;
snprintf (option_name, sizeof (option_name),
"buddy_speaking_time_time_%05d", i);
if (!weechat_infolist_new_var_time (ptr_item, option_name,
ptr_buddy->time_last_message))
return 0;
i++;
}
}
return 1;
}
/*
* jabber_muc_print_log: print muc infos in log (usually for crash dump)
*/
void
jabber_muc_print_log (struct t_jabber_muc *muc)
{
struct t_weelist_item *ptr_item;
struct t_jabber_muc_speaking *ptr_buddy_speaking;
int i, index;
struct t_jabber_buddy *ptr_buddy;
weechat_log_printf ("");
weechat_log_printf (" => muc %s (addr:0x%lx)]", muc->name, muc);
weechat_log_printf (" type . . . . . . . . . . : %d", muc->type);
weechat_log_printf (" topic. . . . . . . . . . : '%s'", muc->topic);
weechat_log_printf (" modes. . . . . . . . . . : '%s'", muc->modes);
weechat_log_printf (" limit. . . . . . . . . . : %d", muc->limit);
weechat_log_printf (" key. . . . . . . . . . . : '%s'", muc->key);
weechat_log_printf (" away_message . . . . . . : '%s'", muc->away_message);
weechat_log_printf (" nick_completion_reset. . : %d", muc->nick_completion_reset);
weechat_log_printf (" buddies_count. . . . . . : %d", muc->buddies_count);
weechat_log_printf (" buddies. . . . . . . . . : 0x%lx", muc->buddies);
weechat_log_printf (" last_buddy . . . . . . . : 0x%lx", muc->last_buddy);
weechat_log_printf (" buddies_speaking[0]. . . : 0x%lx", muc->buddies_speaking[0]);
weechat_log_printf (" buddies_speaking[1]. . . : 0x%lx", muc->buddies_speaking[1]);
weechat_log_printf (" buddies_speaking_time. . : 0x%lx", muc->buddies_speaking_time);
weechat_log_printf (" last_buddy_speaking_time.: 0x%lx", muc->last_buddy_speaking_time);
weechat_log_printf (" buffer . . . . . . . . . : 0x%lx", muc->buffer);
weechat_log_printf (" buffer_as_string . . . . : '%s'", muc->buffer_as_string);
weechat_log_printf (" prev_muc . . . . . . . . : 0x%lx", muc->prev_muc);
weechat_log_printf (" next_muc . . . . . . . . : 0x%lx", muc->next_muc);
for (i = 0; i < 2; i++)
{
if (muc->buddies_speaking[i])
{
weechat_log_printf ("");
index = 0;
for (ptr_item = weechat_list_get (muc->buddies_speaking[i], 0);
ptr_item; ptr_item = weechat_list_next (ptr_item))
{
weechat_log_printf (" buddy speaking[%d][%d]: '%s'",
i, index, weechat_list_string (ptr_item));
index++;
}
}
}
if (muc->buddies_speaking_time)
{
weechat_log_printf ("");
for (ptr_buddy_speaking = muc->buddies_speaking_time;
ptr_buddy_speaking;
ptr_buddy_speaking = ptr_buddy_speaking->next_buddy)
{
weechat_log_printf (" buddy speaking time: '%s', time: %ld",
ptr_buddy_speaking->buddy,
ptr_buddy_speaking->time_last_message);
}
}
for (ptr_buddy = muc->buddies; ptr_buddy;
ptr_buddy = ptr_buddy->next_buddy)
{
jabber_buddy_print_log (ptr_buddy);
}
}
-107
View File
@@ -1,107 +0,0 @@
/*
* Copyright (c) 2009 by FlashCode <flashcode@flashtux.org>
* See README for License detail, AUTHORS for developers list.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __WEECHAT_JABBER_MUC_H
#define __WEECHAT_JABBER_MUC_H 1
/* MUC types */
#define JABBER_MUC_TYPE_UNKNOWN -1
#define JABBER_MUC_TYPE_MUC 0
#define JABBER_MUC_TYPE_PRIVATE 1
#define JABBER_MUC_BUDDIES_SPEAKING_LIMIT 128
struct t_jabber_server;
struct t_jabber_muc_speaking
{
char *buddy; /* buddy speaking */
time_t time_last_message; /* time */
struct t_jabber_muc_speaking *prev_buddy; /* pointer to previous buddy */
struct t_jabber_muc_speaking *next_buddy; /* pointer to next buddy */
};
struct t_jabber_muc
{
int type; /* MUC type */
char *name; /* name of MUC (exemple: "test") */
char *topic; /* topic of MUC (host for pv) */
char *modes; /* MUC modes */
int limit; /* user limit (0 is limit not set) */
char *key; /* MUC key (NULL if no key set) */
char *away_message; /* to display away only once in pv */
int nick_completion_reset; /* 1 for resetting nick completion */
/* there was some join/part on chan */
int buddies_count; /* # buddies in MUC (0 if pv) */
struct t_jabber_buddy *buddies; /* buddies in MUC */
struct t_jabber_buddy *last_buddy; /* last buddy in MUC */
struct t_weelist *buddies_speaking[2]; /* for smart completion: first */
/* list is buddy speaking, second is */
/* speaking to me (highlight) */
struct t_jabber_muc_speaking *buddies_speaking_time; /* for smart filter*/
/* of join/quit messages */
struct t_jabber_muc_speaking *last_buddy_speaking_time;
struct t_gui_buffer *buffer; /* buffer allocated for MUC */
char *buffer_as_string; /* used to return buffer info */
struct t_jabber_muc *prev_muc; /* link to previous MUC */
struct t_jabber_muc *next_muc; /* link to next MUC */
};
extern int jabber_muc_valid (struct t_jabber_server *server,
struct t_jabber_muc *muc);
extern struct t_jabber_muc *jabber_muc_new (struct t_jabber_server *server,
int muc_type,
const char *muc_name,
int switch_to_muc,
int auto_switch);
extern void jabber_muc_set_topic (struct t_jabber_muc *muc,
const char *topic);
extern void jabber_muc_free (struct t_jabber_server *server,
struct t_jabber_muc *muc);
extern void jabber_muc_free_all (struct t_jabber_server *server);
extern struct t_jabber_muc *jabber_muc_search (struct t_jabber_server *server,
const char *muc_name);
extern int jabber_muc_is_muc (const char *string);
extern void jabber_muc_remove_away (struct t_jabber_muc *muc);
extern void jabber_muc_check_away (struct t_jabber_server *server,
struct t_jabber_muc *muc, int force);
extern void jabber_muc_set_away (struct t_jabber_muc *muc,
const char *buddy_name,
int is_away);
extern void jabber_muc_buddy_speaking_add (struct t_jabber_muc *muc,
const char *buddy_name,
int highlight);
extern void jabber_muc_buddy_speaking_rename (struct t_jabber_muc *muc,
const char *old_buddy,
const char *new_buddy);
extern struct t_jabber_muc_speaking *jabber_muc_buddy_speaking_time_search (struct t_jabber_muc *muc,
const char *buddy_name,
int check_time);
extern void jabber_muc_buddy_speaking_time_remove_old (struct t_jabber_muc *muc);
extern void jabber_muc_buddy_speaking_time_add (struct t_jabber_muc *muc,
const char *buddy_name,
time_t time_last_message);
extern void jabber_muc_buddy_speaking_time_rename (struct t_jabber_muc *muc,
const char *old_buddy,
const char *new_buddy);
extern int jabber_muc_add_to_infolist (struct t_infolist *infolist,
struct t_jabber_muc *muc);
extern void jabber_muc_print_log (struct t_jabber_muc *muc);
#endif /* jabber-muc.h */
File diff suppressed because it is too large Load Diff
-205
View File
@@ -1,205 +0,0 @@
/*
* Copyright (c) 2009 by FlashCode <flashcode@flashtux.org>
* See README for License detail, AUTHORS for developers list.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __WEECHAT_JABBER_SERVER_H
#define __WEECHAT_JABBER_SERVER_H 1
#include <sys/time.h>
#include <regex.h>
#ifdef HAVE_GNUTLS
#include <gnutls/gnutls.h>
#endif
#include <iksemel.h>
enum t_jabber_server_option
{
JABBER_SERVER_OPTION_USERNAME = 0, /* username on server */
JABBER_SERVER_OPTION_SERVER, /* server hostname/IP */
JABBER_SERVER_OPTION_PROXY, /* proxy used for server (optional) */
JABBER_SERVER_OPTION_IPV6, /* use IPv6 protocol */
JABBER_SERVER_OPTION_TLS, /* use TLS cryptographic protocol */
JABBER_SERVER_OPTION_SASL, /* use SASL for auth */
JABBER_SERVER_OPTION_RESOURCE, /* resource */
JABBER_SERVER_OPTION_PASSWORD, /* password */
JABBER_SERVER_OPTION_LOCAL_ALIAS, /* local alias */
JABBER_SERVER_OPTION_AUTOCONNECT, /* autoconnect to server at startup */
JABBER_SERVER_OPTION_AUTORECONNECT, /* autoreconnect when disconnected */
JABBER_SERVER_OPTION_AUTORECONNECT_DELAY, /* delay before next reconnect */
JABBER_SERVER_OPTION_LOCAL_HOSTNAME,/* custom local hostname */
JABBER_SERVER_OPTION_COMMAND, /* command to run once connected */
JABBER_SERVER_OPTION_COMMAND_DELAY, /* delay after execution of command */
JABBER_SERVER_OPTION_AUTOJOIN, /* MUCs to automatically join */
JABBER_SERVER_OPTION_AUTOREJOIN, /* auto rejoin MUCs when kicked */
/* number of server options */
JABBER_SERVER_NUM_OPTIONS,
};
#define JABBER_SERVER_OPTION_BOOLEAN(__server, __index) \
((!weechat_config_option_is_null(__server->options[__index])) ? \
weechat_config_boolean(__server->options[__index]) : \
((!weechat_config_option_is_null(jabber_config_server_default[__index])) ? \
weechat_config_boolean(jabber_config_server_default[__index]) \
: weechat_config_boolean_default(jabber_config_server_default[__index])))
#define JABBER_SERVER_OPTION_INTEGER(__server, __index) \
((!weechat_config_option_is_null(__server->options[__index])) ? \
weechat_config_integer(__server->options[__index]) : \
((!weechat_config_option_is_null(jabber_config_server_default[__index])) ? \
weechat_config_integer(jabber_config_server_default[__index]) \
: weechat_config_integer_default(jabber_config_server_default[__index])))
#define JABBER_SERVER_OPTION_STRING(__server, __index) \
((!weechat_config_option_is_null(__server->options[__index])) ? \
weechat_config_string(__server->options[__index]) : \
((!weechat_config_option_is_null(jabber_config_server_default[__index])) ? \
weechat_config_string(jabber_config_server_default[__index]) \
: weechat_config_string_default(jabber_config_server_default[__index])))
#define JABBER_SERVER_DEFAULT_PORT 5222
#define JABBER_SERVER_DEFAULT_RESOURCE "WeeChat"
#define jabber_server_sendf_queued(server, fmt, argz...) \
if (server) \
{ \
server->queue_msg = 1; \
jabber_server_sendf (server, fmt, ##argz); \
server->queue_msg = 0; \
}
struct t_jabber_server
{
/* user choices */
char *name; /* internal name of server */
struct t_config_option *options[JABBER_SERVER_NUM_OPTIONS];
/* internal vars */
int temp_server; /* temporary server (not saved) */
int reloading_from_config; /* 1 if reloading from config file */
int reloaded_from_config; /* 1 if reloaded from config file */
char *address; /* address from "server" option */
int port; /* port from "server" option */
char *current_ip; /* current IP address */
int sock; /* socket for server (IPv4 or IPv6) */
iksparser *iks_parser; /* parser for libiksemel */
char *iks_id_string; /* string with id (user@server/resource) */
iksid *iks_id; /* id for libiksemel */
char *iks_server_name; /* server name for libiksemel */
char *iks_password; /* password for libiksemel */
iksfilter *iks_filter; /* filter for libiksemel */
iks *iks_roster; /* jabber roster (buddy list) */
int iks_features; /* stream features */
int iks_authorized; /* authorized by jabber server */
struct t_hook *hook_connect; /* connection hook */
struct t_hook *hook_fd; /* hook for server socket */
int is_connected; /* 1 if WeeChat is connected to server */
int tls_connected; /* = 1 if connected with TLS */
#ifdef HAVE_GNUTLS
gnutls_session_t gnutls_sess; /* gnutls session (only if TLS is used) */
#endif
time_t reconnect_start; /* this time + delay = reconnect time */
time_t command_time; /* this time + command_delay = time to */
/* autojoin MUCs */
int reconnect_join; /* 1 if opened MUCs to rejoin */
int disable_autojoin; /* 1 if user asked to not autojoin MUCs */
int is_away; /* 1 is user is marked as away */
char *away_message; /* away message, NULL if not away */
time_t away_time; /* time() when user marking as away */
int lag; /* lag (in milliseconds) */
struct timeval lag_check_time; /* last time lag was checked (ping sent) */
time_t lag_next_check; /* time for next check */
struct t_gui_buffer *buffer; /* GUI buffer allocated for server */
char *buffer_as_string; /* used to return buffer info */
int buddies_count; /* # buddies in roster */
struct t_jabber_buddy *buddies; /* buddies in roster */
struct t_jabber_buddy *last_buddy; /* last buddy in roster */
struct t_jabber_muc *mucs; /* MUCs opened on server */
struct t_jabber_muc *last_muc; /* last opened MUC on server */
struct t_jabber_server *prev_server; /* link to previous server */
struct t_jabber_server *next_server; /* link to next server */
};
/* Jabber messages */
struct t_jabber_message
{
struct t_jabber_server *server; /* server pointer for received msg */
char *data; /* message content */
struct t_jabber_message *next_message; /* link to next message */
};
extern struct t_jabber_server *jabber_servers;
extern struct t_jabber_server *jabber_current_server;
#ifdef HAVE_GNUTLS
extern const int gnutls_cert_type_prio[];
extern const int gnutls_prot_prio[];
#endif
extern struct t_jabber_message *jabber_recv_msgq, *jabber_msgq_last_msg;
extern char *jabber_server_option_string[];
extern char *jabber_server_option_default[];
extern int jabber_server_valid (struct t_jabber_server *server);
extern int jabber_server_search_option (const char *option_name);
extern struct t_jabber_server *jabber_server_search (const char *server_name);
extern int jabber_server_get_muc_count (struct t_jabber_server *server);
extern int jabber_server_get_pv_count (struct t_jabber_server *server);
extern char *jabber_server_get_name_without_port (const char *name);
extern const char *jabber_server_get_local_name (struct t_jabber_server *server);
extern void jabber_server_set_server (struct t_jabber_server *server,
const char *address);
extern void jabber_server_set_nicks (struct t_jabber_server *server,
const char *nicks);
extern void jabber_server_buffer_set_highlight_words (struct t_gui_buffer *buffer);
extern struct t_jabber_server *jabber_server_alloc (const char *name);
extern void jabber_server_set_buffer_title (struct t_jabber_server *server);
extern struct t_gui_buffer *jabber_server_create_buffer (struct t_jabber_server *server,
int all_servers);
extern void jabber_server_set_current_server (struct t_jabber_server *server);
extern int jabber_server_iks_transport_connect_async (iksparser *parser,
void **socketptr,
const char *server,
const char *server_name,
int port,
void *notify_data,
iksAsyncNotify *notify_func);
extern int jabber_server_iks_transport_send (void *socket, const char *data,
size_t len);
extern int jabber_server_iks_transport_recv (void *socket, char *buffer,
size_t buf_len, int timeout);
extern void jabber_server_iks_transport_close (void *socket);
extern int jabber_server_connect (struct t_jabber_server *server);
extern void jabber_server_auto_connect ();
extern void jabber_server_disconnect (struct t_jabber_server *server,
int reconnect);
extern void jabber_server_disconnect_all ();
extern void jabber_server_free_data (struct t_jabber_server *server);
extern void jabber_server_free (struct t_jabber_server *server);
extern void jabber_server_free_all ();
extern struct t_jabber_server *jabber_server_copy (struct t_jabber_server *server,
const char *new_name);
extern int jabber_server_rename (struct t_jabber_server *server,
const char *new_server_name);
extern int jabber_server_recv_cb (void *arg_server, int fd);
extern int jabber_server_timer_cb (void *data, int remaining_calls);
extern int jabber_server_add_to_infolist (struct t_infolist *infolist,
struct t_jabber_server *server);
extern void jabber_server_print_log ();
#endif /* jabber-server.h */
-335
View File
@@ -1,335 +0,0 @@
/*
* Copyright (c) 2009 by FlashCode <flashcode@flashtux.org>
* See README for License detail, AUTHORS for developers list.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* jabber-upgrade.c: save/restore Jabber plugin data */
#include <stdio.h>
#include <string.h>
#include "../weechat-plugin.h"
#include "jabber.h"
#include "jabber-upgrade.h"
#include "jabber-buddy.h"
#include "jabber-buffer.h"
#include "jabber-config.h"
#include "jabber-input.h"
#include "jabber-muc.h"
#include "jabber-server.h"
struct t_jabber_server *jabber_upgrade_current_server = NULL;
struct t_jabber_muc *jabber_upgrade_current_muc = NULL;
/*
* jabber_upgrade_save_all_data: save servers/MUCs/buddies info to upgrade
* file
*/
int
jabber_upgrade_save_all_data (struct t_upgrade_file *upgrade_file)
{
struct t_infolist *infolist;
struct t_jabber_server *ptr_server;
struct t_jabber_muc *ptr_muc;
struct t_jabber_buddy *ptr_buddy;
int rc;
for (ptr_server = jabber_servers; ptr_server;
ptr_server = ptr_server->next_server)
{
/* save server */
infolist = weechat_infolist_new ();
if (!infolist)
return 0;
if (!jabber_server_add_to_infolist (infolist, ptr_server))
{
weechat_infolist_free (infolist);
return 0;
}
rc = weechat_upgrade_write_object (upgrade_file,
JABBER_UPGRADE_TYPE_SERVER,
infolist);
weechat_infolist_free (infolist);
if (!rc)
return 0;
for (ptr_muc = ptr_server->mucs; ptr_muc;
ptr_muc = ptr_muc->next_muc)
{
/* save MUC */
infolist = weechat_infolist_new ();
if (!infolist)
return 0;
if (!jabber_muc_add_to_infolist (infolist, ptr_muc))
{
weechat_infolist_free (infolist);
return 0;
}
rc = weechat_upgrade_write_object (upgrade_file,
JABBER_UPGRADE_TYPE_MUC,
infolist);
weechat_infolist_free (infolist);
if (!rc)
return 0;
for (ptr_buddy = ptr_muc->buddies; ptr_buddy;
ptr_buddy = ptr_buddy->next_buddy)
{
/* save buddy */
infolist = weechat_infolist_new ();
if (!infolist)
return 0;
if (!jabber_buddy_add_to_infolist (infolist, ptr_buddy))
{
weechat_infolist_free (infolist);
return 0;
}
rc = weechat_upgrade_write_object (upgrade_file,
JABBER_UPGRADE_TYPE_BUDDY,
infolist);
weechat_infolist_free (infolist);
if (!rc)
return 0;
}
}
}
return 1;
}
/*
* jabber_upgrade_save: save upgrade file
* return 1 if ok, 0 if error
*/
int
jabber_upgrade_save ()
{
int rc;
struct t_upgrade_file *upgrade_file;
upgrade_file = weechat_upgrade_new (JABBER_UPGRADE_FILENAME, 1);
if (!upgrade_file)
return 0;
rc = jabber_upgrade_save_all_data (upgrade_file);
weechat_upgrade_close (upgrade_file);
return rc;
}
/*
* jabber_upgrade_set_buffer_callbacks: restore buffers callbacks (input and
* close) for buffers created by Jabber
* plugin
*/
void
jabber_upgrade_set_buffer_callbacks ()
{
struct t_infolist *infolist;
struct t_gui_buffer *ptr_buffer;
infolist = weechat_infolist_get ("buffer", NULL, NULL);
if (infolist)
{
while (weechat_infolist_next (infolist))
{
if (weechat_infolist_pointer (infolist, "plugin") == weechat_jabber_plugin)
{
ptr_buffer = weechat_infolist_pointer (infolist, "pointer");
weechat_buffer_set_pointer (ptr_buffer, "close_callback", &jabber_buffer_close_cb);
weechat_buffer_set_pointer (ptr_buffer, "input_callback", &jabber_input_data_cb);
}
}
}
}
/*
* jabber_upgrade_read_cb: read callback for upgrade
*/
int
jabber_upgrade_read_cb (void *data,
struct t_upgrade_file *upgrade_file,
int object_id,
struct t_infolist *infolist)
{
int flags, size, i, index;
char *buf, option_name[64];
const char *buffer_name, *str, *buddy;
struct t_jabber_buddy *ptr_buddy;
struct t_gui_buffer *ptr_buffer;
/* make C compiler happy */
(void) data;
(void) upgrade_file;
weechat_infolist_reset_item_cursor (infolist);
while (weechat_infolist_next (infolist))
{
switch (object_id)
{
case JABBER_UPGRADE_TYPE_SERVER:
jabber_upgrade_current_server = jabber_server_search (weechat_infolist_string (infolist, "name"));
if (jabber_upgrade_current_server)
{
jabber_upgrade_current_server->temp_server =
weechat_infolist_integer (infolist, "temp_server");
jabber_upgrade_current_server->buffer = NULL;
buffer_name = weechat_infolist_string (infolist, "buffer_name");
if (buffer_name && buffer_name[0])
{
ptr_buffer = weechat_buffer_search (JABBER_PLUGIN_NAME,
buffer_name);
if (ptr_buffer)
{
jabber_upgrade_current_server->buffer = ptr_buffer;
if (weechat_config_boolean (jabber_config_look_one_server_buffer)
&& !jabber_buffer_servers)
{
jabber_buffer_servers = ptr_buffer;
}
if (weechat_infolist_integer (infolist, "selected"))
jabber_current_server = jabber_upgrade_current_server;
}
}
jabber_upgrade_current_server->reconnect_start = weechat_infolist_time (infolist, "reconnect_start");
jabber_upgrade_current_server->command_time = weechat_infolist_time (infolist, "command_time");
jabber_upgrade_current_server->reconnect_join = weechat_infolist_integer (infolist, "reconnect_join");
jabber_upgrade_current_server->disable_autojoin = weechat_infolist_integer (infolist, "disable_autojoin");
jabber_upgrade_current_server->is_away = weechat_infolist_integer (infolist, "is_away");
str = weechat_infolist_string (infolist, "away_message");
if (str)
jabber_upgrade_current_server->away_message = strdup (str);
jabber_upgrade_current_server->away_time = weechat_infolist_time (infolist, "away_time");
jabber_upgrade_current_server->lag = weechat_infolist_integer (infolist, "lag");
buf = weechat_infolist_buffer (infolist, "lag_check_time", &size);
if (buf)
memcpy (&(jabber_upgrade_current_server->lag_check_time), buf, size);
jabber_upgrade_current_server->lag_next_check = weechat_infolist_time (infolist, "lag_next_check");
}
break;
case JABBER_UPGRADE_TYPE_MUC:
if (jabber_upgrade_current_server)
{
jabber_upgrade_current_muc = jabber_muc_new (jabber_upgrade_current_server,
weechat_infolist_integer (infolist, "type"),
weechat_infolist_string (infolist, "name"),
0, 0);
if (jabber_upgrade_current_muc)
{
str = weechat_infolist_string (infolist, "topic");
if (str)
jabber_muc_set_topic (jabber_upgrade_current_muc, str);
str = weechat_infolist_string (infolist, "modes");
if (str)
jabber_upgrade_current_muc->modes = strdup (str);
jabber_upgrade_current_muc->limit = weechat_infolist_integer (infolist, "limit");
str = weechat_infolist_string (infolist, "key");
if (str)
jabber_upgrade_current_muc->key = strdup (str);
str = weechat_infolist_string (infolist, "away_message");
if (str)
jabber_upgrade_current_muc->away_message = strdup (str);
jabber_upgrade_current_muc->nick_completion_reset = weechat_infolist_integer (infolist, "nick_completion_reset");
for (i = 0; i < 2; i++)
{
index = 0;
while (1)
{
snprintf (option_name, sizeof (option_name),
"buddy_speaking%d_%05d", i, index);
buddy = weechat_infolist_string (infolist, option_name);
if (!buddy)
break;
jabber_muc_buddy_speaking_add (jabber_upgrade_current_muc,
buddy,
i);
index++;
}
}
index = 0;
while (1)
{
snprintf (option_name, sizeof (option_name),
"buddy_speaking_time_buddy_%05d", index);
buddy = weechat_infolist_string (infolist, option_name);
if (!buddy)
break;
snprintf (option_name, sizeof (option_name),
"buddy_speaking_time_time_%05d", index);
jabber_muc_buddy_speaking_time_add (jabber_upgrade_current_muc,
buddy,
weechat_infolist_time (infolist,
option_name));
index++;
}
}
}
break;
case JABBER_UPGRADE_TYPE_BUDDY:
if (jabber_upgrade_current_server)
{
flags = weechat_infolist_integer (infolist, "flags");
ptr_buddy = jabber_buddy_new (jabber_upgrade_current_server,
jabber_upgrade_current_muc,
weechat_infolist_string (infolist, "name"),
flags & JABBER_BUDDY_CHANOWNER,
flags & JABBER_BUDDY_CHANADMIN,
flags & JABBER_BUDDY_CHANADMIN2,
flags & JABBER_BUDDY_OP,
flags & JABBER_BUDDY_HALFOP,
flags & JABBER_BUDDY_VOICE,
flags & JABBER_BUDDY_CHANUSER,
flags & JABBER_BUDDY_AWAY);
if (ptr_buddy)
{
str = weechat_infolist_string (infolist, "host");
if (str)
ptr_buddy->host = strdup (str);
}
}
break;
}
}
return WEECHAT_RC_OK;
}
/*
* jabber_upgrade_load: load upgrade file
* return 1 if ok, 0 if error
*/
int
jabber_upgrade_load ()
{
int rc;
struct t_upgrade_file *upgrade_file;
jabber_upgrade_set_buffer_callbacks ();
upgrade_file = weechat_upgrade_new (JABBER_UPGRADE_FILENAME, 0);
rc = weechat_upgrade_read (upgrade_file, &jabber_upgrade_read_cb, NULL);
return rc;
}
-37
View File
@@ -1,37 +0,0 @@
/*
* Copyright (c) 2009 by FlashCode <flashcode@flashtux.org>
* See README for License detail, AUTHORS for developers list.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __WEECHAT_JABBER_UPGRADE_H
#define __WEECHAT_JABBER_UPGRADE_H 1
#define JABBER_UPGRADE_FILENAME "jabber"
/* For developers: please add new values ONLY AT THE END of enums */
enum t_jabber_upgrade_type
{
JABBER_UPGRADE_TYPE_SERVER = 0,
JABBER_UPGRADE_TYPE_MUC,
JABBER_UPGRADE_TYPE_BUDDY,
};
extern int jabber_upgrade_save ();
extern int jabber_upgrade_load ();
#endif /* jabber-upgrade.h */
-424
View File
@@ -1,424 +0,0 @@
/*
* Copyright (c) 2009 by FlashCode <flashcode@flashtux.org>
* See README for License detail, AUTHORS for developers list.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* jabber-xmpp.c: XMPP protocol for Jabber plugin */
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <iksemel.h>
#include "../weechat-plugin.h"
#include "jabber.h"
#include "jabber-xmpp.h"
#include "jabber-buddy.h"
#include "jabber-buffer.h"
#include "jabber-config.h"
#include "jabber-debug.h"
#include "jabber-muc.h"
#include "jabber-server.h"
/*
* jabber_xmpp_log_level_for_command: get log level for Jabber command
*/
int
jabber_xmpp_log_level_for_command (const char *command)
{
if (!command || !command[0])
return 0;
if (strcmp (command, "chat_msg") == 0)
return 1;
return 3;
}
/*
* jabber_xmpp_tags: build tags list with Jabber command and/or tags
*/
const char *
jabber_xmpp_tags (const char *command, const char *tags)
{
static char string[512];
int log_level;
char str_log_level[32];
log_level = 0;
str_log_level[0] = '\0';
if (command && command[0])
{
log_level = jabber_xmpp_log_level_for_command (command);
if (log_level > 0)
{
snprintf (str_log_level, sizeof (str_log_level),
",log%d", log_level);
}
}
if (command && command[0] && tags && tags[0])
{
snprintf (string, sizeof (string),
"jabber_%s,%s%s", command, tags, str_log_level);
return string;
}
if (command && command[0])
{
snprintf (string, sizeof (string),
"jabber_%s%s", command, str_log_level);
return string;
}
if (tags && tags[0])
{
snprintf (string, sizeof (string), "%s", tags);
return string;
}
return NULL;
}
/*
* jabber_xmpp_recv_chat_message: receive a message
*/
int
jabber_xmpp_recv_chat_message (struct t_jabber_server *server,
iks *node)
{
char *attrib_from, *from, *pos;
char *body;
struct t_jabber_muc *ptr_muc;
attrib_from = iks_find_attrib (node, "from");
if (!attrib_from || !attrib_from[0])
return WEECHAT_RC_ERROR;
body = iks_find_cdata (node, "body");
if (!body)
return WEECHAT_RC_ERROR;
pos = strchr (attrib_from, '/');
from = (pos) ?
weechat_strndup (attrib_from, pos - attrib_from) : strdup (attrib_from);
if (from)
{
ptr_muc = jabber_muc_search (server, from);
if (!ptr_muc)
{
ptr_muc = jabber_muc_new (server,
JABBER_MUC_TYPE_PRIVATE,
from, 0, 0);
if (!ptr_muc)
{
weechat_printf (server->buffer,
_("%s%s: cannot create new "
"private buffer \"%s\""),
jabber_buffer_get_server_prefix (server,
"error"),
JABBER_PLUGIN_NAME, from);
return WEECHAT_RC_ERROR;
}
}
//jabber_muc_set_topic (ptr_channel, address);
weechat_printf_tags (ptr_muc->buffer,
jabber_xmpp_tags ("chat_msg", "notify_private"),
"%s%s",
jabber_buddy_as_prefix (NULL,
from,
JABBER_COLOR_CHAT_NICK_OTHER),
body);
weechat_hook_signal_send ("jabber_pv",
WEECHAT_HOOK_SIGNAL_STRING,
body);
free (from);
}
return WEECHAT_RC_OK;
}
/*
* jabber_xmpp_send_chat_message: send a message to MUC or buddy
*/
void
jabber_xmpp_send_chat_message (struct t_jabber_server *server,
struct t_jabber_muc *muc,
const char *message)
{
iks *msg;
if (muc->type == JABBER_MUC_TYPE_PRIVATE)
{
msg = iks_make_msg (IKS_TYPE_CHAT, muc->name, message);
if (msg)
{
iks_send (server->iks_parser, msg);
iks_delete (msg);
}
}
else
{
// TODO: send message to MUC
}
}
/*
* jabber_xmpp_iks_stream_hook: iksemel stream hook
*/
int
jabber_xmpp_iks_stream_hook (void *user_data, int type, iks *node)
{
struct t_jabber_server *server;
iks *x, *t;
ikspak *pak;
server = (struct t_jabber_server *)user_data;
switch (type)
{
case IKS_NODE_START:
if (JABBER_SERVER_OPTION_BOOLEAN(server, JABBER_SERVER_OPTION_TLS)
&& !iks_is_secure (server->iks_parser))
{
iks_start_tls (server->iks_parser);
}
else
{
if (!JABBER_SERVER_OPTION_BOOLEAN(server, JABBER_SERVER_OPTION_SASL))
{
x = iks_make_auth (server->iks_id,
JABBER_SERVER_OPTION_STRING(server, JABBER_SERVER_OPTION_PASSWORD),
iks_find_attrib (node, "id"));
iks_insert_attrib (x, "id", "auth");
iks_send (server->iks_parser, x);
iks_delete (x);
}
}
break;
case IKS_NODE_NORMAL:
if (strcmp ("stream:features", iks_name (node)) == 0)
{
server->iks_features = iks_stream_features (node);
if (JABBER_SERVER_OPTION_BOOLEAN(server, JABBER_SERVER_OPTION_SASL))
{
if (!JABBER_SERVER_OPTION_BOOLEAN(server, JABBER_SERVER_OPTION_TLS)
|| iks_is_secure (server->iks_parser))
{
if (server->iks_authorized)
{
if (server->iks_features & IKS_STREAM_BIND)
{
t = iks_make_resource_bind (server->iks_id);
iks_send (server->iks_parser, t);
iks_delete (t);
}
if (server->iks_features & IKS_STREAM_SESSION)
{
t = iks_make_session ();
iks_insert_attrib (t, "id", "auth");
iks_send (server->iks_parser, t);
iks_delete (t);
}
}
else
{
if (server->iks_features & IKS_STREAM_SASL_MD5)
{
iks_start_sasl (server->iks_parser,
IKS_SASL_DIGEST_MD5,
server->iks_id->user,
server->iks_password);
}
else if (server->iks_features & IKS_STREAM_SASL_PLAIN)
{
iks_start_sasl (server->iks_parser,
IKS_SASL_PLAIN,
server->iks_id->user,
server->iks_password);
}
}
}
}
}
else if (strcmp ("failure", iks_name (node)) == 0)
{
weechat_printf (server->buffer,
_("%s%s: SASL authentication failed (check "
"SASL option and password)"),
jabber_buffer_get_server_prefix (server,
"error"),
JABBER_PLUGIN_NAME);
jabber_server_disconnect (server, 0);
}
else if (strcmp ("success", iks_name (node)) == 0)
{
server->iks_authorized = 1;
iks_send_header (server->iks_parser, server->iks_id->server);
}
else if (strcmp ("message", iks_name (node)) == 0)
{
jabber_xmpp_recv_chat_message (server, node);
}
else
{
pak = iks_packet (node);
iks_filter_packet (server->iks_filter, pak);
}
break;
case IKS_NODE_STOP:
weechat_printf (server->buffer,
_("%s%s: server disconnected"),
jabber_buffer_get_server_prefix (server, "network"),
JABBER_PLUGIN_NAME);
jabber_server_disconnect (server, 1);
break;
case IKS_NODE_ERROR:
weechat_printf (server->buffer,
_("%s%s: stream error"),
jabber_buffer_get_server_prefix (server,
"error"),
JABBER_PLUGIN_NAME);
break;
}
if (node)
iks_delete (node);
return IKS_OK;
}
/*
* jabber_xmpp_iks_log: log
*/
void
jabber_xmpp_iks_log (void *user_data, const char *data, size_t size,
int is_incoming)
{
/* make C compiler happy */
(void) size;
jabber_debug_printf ((struct t_jabber_server *)user_data,
!is_incoming, 0,
data);
}
/*
* jabber_xmpp_iks_result: iks result
*/
int
jabber_xmpp_iks_result (void *user_data, ikspak *pak)
{
iks *x;
struct t_jabber_server *server;
/* make C compiler happy */
(void) pak;
server = (struct t_jabber_server *)user_data;
weechat_printf (server->buffer,
_("%s%s: login ok"),
jabber_buffer_get_server_prefix (server, NULL),
JABBER_PLUGIN_NAME);
x = iks_make_iq (IKS_TYPE_GET, IKS_NS_ROSTER);
iks_insert_attrib (x, "id", "roster");
iks_send (server->iks_parser, x);
iks_delete (x);
return IKS_FILTER_EAT;
}
/*
* jabber_xmpp_iks_error: iks error
*/
int
jabber_xmpp_iks_error (void *user_data, ikspak *pak)
{
struct t_jabber_server *server;
/* make C compiler happy */
(void) pak;
server = (struct t_jabber_server *)user_data;
weechat_printf (server->buffer,
_("%s%s: authentication failed (check SASL option and "
"password)"),
jabber_buffer_get_server_prefix (server, "error"),
JABBER_PLUGIN_NAME);
jabber_server_disconnect (server, 0);
return IKS_FILTER_EAT;
}
/*
* jabber_xmpp_iks_roster: iks roster
*/
int
jabber_xmpp_iks_roster (void *user_data, ikspak *pak)
{
struct t_jabber_server *server;
char *jid, *id, *pos;
iks *x;
server = (struct t_jabber_server *)user_data;
server->iks_roster = pak->x;
x = iks_child(pak->query);
while (x)
{
if (iks_strcmp (iks_name(x), "item") == 0)
{
jid = iks_find_attrib (x, "jid");
if (jid)
{
pos = strchr (jid, '@');
//id = (pos) ? weechat_strndup (jid, pos - jid) : strdup (jid);
id = strdup (jid);
if (id)
{
jabber_buddy_new (server, NULL, id, 0, 0, 0, 0, 0, 0, 0, 0);
free (id);
}
}
}
x = iks_next (x);
}
if (x)
iks_delete (x);
return IKS_FILTER_EAT;
}
-39
View File
@@ -1,39 +0,0 @@
/*
* Copyright (c) 2009 by FlashCode <flashcode@flashtux.org>
* See README for License detail, AUTHORS for developers list.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __WEECHAT_JABBER_XMPP_H
#define __WEECHAT_JABBER_XMPP_H 1
#include <iksemel.h>
struct t_jabber_server;
struct t_jabber_muc;
extern const char *jabber_xmpp_tags (const char *command, const char *tags);
extern void jabber_xmpp_send_chat_message (struct t_jabber_server *server,
struct t_jabber_muc *muc,
const char *message);
extern int jabber_xmpp_iks_stream_hook (void *user_data, int type, iks *node);
extern void jabber_xmpp_iks_log (void *user_data, const char *data,
size_t size, int is_incoming);
extern int jabber_xmpp_iks_result (void *user_data, ikspak *pak);
extern int jabber_xmpp_iks_error (void *user_data, ikspak *pak);
extern int jabber_xmpp_iks_roster (void *user_data, ikspak *pak);
#endif /* jabber-xmpp.h */
-211
View File
@@ -1,211 +0,0 @@
/*
* Copyright (c) 2009 by FlashCode <flashcode@flashtux.org>
* See README for License detail, AUTHORS for developers list.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* jabber.c: Jabber plugin for WeeChat */
#include <stdlib.h>
#include <string.h>
#include "../weechat-plugin.h"
#include "jabber.h"
#include "jabber-bar-item.h"
#include "jabber-command.h"
#include "jabber-completion.h"
#include "jabber-config.h"
#include "jabber-debug.h"
#include "jabber-info.h"
#include "jabber-server.h"
#include "jabber-upgrade.h"
WEECHAT_PLUGIN_NAME(JABBER_PLUGIN_NAME);
WEECHAT_PLUGIN_DESCRIPTION("Jabber plugin for WeeChat");
WEECHAT_PLUGIN_AUTHOR("FlashCode <flashcode@flashtux.org>");
WEECHAT_PLUGIN_VERSION(WEECHAT_VERSION);
WEECHAT_PLUGIN_LICENSE("GPL3");
struct t_weechat_plugin *weechat_jabber_plugin = NULL;
struct t_hook *jabber_hook_timer = NULL;
int jabber_signal_upgrade_received = 0; /* signal "upgrade" received ? */
/*
* jabber_signal_quit_cb: callback for "quit" signal
*/
int
jabber_signal_quit_cb (void *data, const char *signal, const char *type_data,
void *signal_data)
{
struct t_jabber_server *ptr_server;
/* make C compiler happy */
(void) data;
(void) signal;
if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_STRING) == 0)
{
for (ptr_server = jabber_servers; ptr_server;
ptr_server = ptr_server->next_server)
{
jabber_command_quit_server (ptr_server,
(signal_data) ? (char *)signal_data : NULL);
}
}
return WEECHAT_RC_OK;
}
/*
* jabber_signal_upgrade_cb: callback for "upgrade" signal
*/
int
jabber_signal_upgrade_cb (void *data, const char *signal, const char *type_data,
void *signal_data)
{
/* make C compiler happy */
(void) data;
(void) signal;
(void) type_data;
(void) signal_data;
jabber_signal_upgrade_received = 1;
return WEECHAT_RC_OK;
}
/*
* weechat_plugin_init: initialize Jabber plugin
*/
int
weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
{
int i, auto_connect, upgrading;
weechat_plugin = plugin;
if (!jabber_config_init ())
return WEECHAT_RC_ERROR;
if (jabber_config_read () < 0)
return WEECHAT_RC_ERROR;
jabber_command_init ();
jabber_info_init ();
/* hook some signals */
jabber_debug_init ();
weechat_hook_signal ("quit", &jabber_signal_quit_cb, NULL);
weechat_hook_signal ("upgrade", &jabber_signal_upgrade_cb, NULL);
//weechat_hook_signal ("xfer_send_ready", &jabber_server_xfer_send_ready_cb, NULL);
//weechat_hook_signal ("xfer_resume_ready", &jabber_server_xfer_resume_ready_cb, NULL);
//weechat_hook_signal ("xfer_send_accept_resume", &jabber_server_xfer_send_accept_resume_cb, NULL);
/* hook completions */
jabber_completion_init ();
jabber_bar_item_init ();
/* look at arguments */
auto_connect = 1;
upgrading = 0;
for (i = 0; i < argc; i++)
{
if ((weechat_strcasecmp (argv[i], "-a") == 0)
|| (weechat_strcasecmp (argv[i], "--no-connect") == 0))
{
auto_connect = 0;
}
else if ((weechat_strncasecmp (argv[i], JABBER_PLUGIN_NAME, 3) == 0))
{
/*
if (!jabber_server_alloc_with_url (argv[i]))
{
weechat_printf (NULL,
_("%s%s: error with server from URL "
"(\"%s\"), ignored"),
weechat_prefix ("error"), JABBER_PLUGIN_NAME,
argv[i]);
}
*/
}
else if (weechat_strcasecmp (argv[i], "--upgrade") == 0)
{
upgrading = 1;
}
}
if (upgrading)
{
if (!jabber_upgrade_load ())
{
weechat_printf (NULL,
_("%s%s: WARNING: some network connections may "
"still be opened and not visible, you should "
"restart WeeChat now (with /quit)."),
weechat_prefix ("error"), JABBER_PLUGIN_NAME);
}
}
else
{
if (auto_connect)
jabber_server_auto_connect ();
}
jabber_hook_timer = weechat_hook_timer (1 * 1000, 0, 0,
&jabber_server_timer_cb, NULL);
return WEECHAT_RC_OK;
}
/*
* weechat_plugin_end: end Jabber plugin
*/
int
weechat_plugin_end (struct t_weechat_plugin *plugin)
{
/* make C compiler happy */
(void) plugin;
if (jabber_hook_timer)
weechat_unhook (jabber_hook_timer);
if (jabber_signal_upgrade_received)
{
jabber_config_write (1);
jabber_upgrade_save ();
}
else
{
jabber_config_write (0);
jabber_server_disconnect_all ();
}
jabber_server_free_all ();
jabber_config_free ();
return WEECHAT_RC_OK;
}
-71
View File
@@ -1,71 +0,0 @@
/*
* Copyright (c) 2009 by FlashCode <flashcode@flashtux.org>
* See README for License detail, AUTHORS for developers list.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __WEECHAT_JABBER_H
#define __WEECHAT_JABBER_H 1
#define weechat_plugin weechat_jabber_plugin
#define JABBER_PLUGIN_NAME "jabber"
#define JABBER_GET_SERVER(__buffer) \
struct t_weechat_plugin *buffer_plugin = NULL; \
struct t_jabber_server *ptr_server = NULL; \
buffer_plugin = weechat_buffer_get_pointer (__buffer, "plugin"); \
if (buffer_plugin == weechat_jabber_plugin) \
jabber_buffer_get_server_muc (__buffer, &ptr_server, NULL);
#define JABBER_GET_SERVER_MUC(__buffer) \
struct t_weechat_plugin *buffer_plugin = NULL; \
struct t_jabber_server *ptr_server = NULL; \
struct t_jabber_muc *ptr_muc = NULL; \
buffer_plugin = weechat_buffer_get_pointer (__buffer, "plugin"); \
if (buffer_plugin == weechat_jabber_plugin) \
{ \
jabber_buffer_get_server_muc (__buffer, &ptr_server, &ptr_muc); \
}
#define JABBER_COLOR_CHAT weechat_color("chat")
#define JABBER_COLOR_CHAT_CHANNEL weechat_color("chat_channel")
#define JABBER_COLOR_CHAT_DELIMITERS weechat_color("chat_delimiters")
#define JABBER_COLOR_CHAT_HOST weechat_color("chat_host")
#define JABBER_COLOR_CHAT_NICK weechat_color("chat_nick")
#define JABBER_COLOR_CHAT_NICK_SELF weechat_color("chat_nick_self")
#define JABBER_COLOR_CHAT_NICK_OTHER weechat_color("chat_nick_other")
#define JABBER_COLOR_CHAT_SERVER weechat_color("chat_server")
#define JABBER_COLOR_CHAT_VALUE weechat_color("chat_value")
#define JABBER_COLOR_NICKLIST_PREFIX1 weechat_color("nicklist_prefix1")
#define JABBER_COLOR_NICKLIST_PREFIX2 weechat_color("nicklist_prefix2")
#define JABBER_COLOR_NICKLIST_PREFIX3 weechat_color("nicklist_prefix3")
#define JABBER_COLOR_NICKLIST_PREFIX4 weechat_color("nicklist_prefix4")
#define JABBER_COLOR_NICKLIST_PREFIX5 weechat_color("nicklist_prefix5")
#define JABBER_COLOR_BAR_FG weechat_color("bar_fg")
#define JABBER_COLOR_BAR_BG weechat_color("bar_bg")
#define JABBER_COLOR_BAR_DELIM weechat_color("bar_delim")
#define JABBER_COLOR_STATUS_NUMBER weechat_color(weechat_config_string(weechat_config_get("weechat.color.status_number")))
#define JABBER_COLOR_STATUS_NAME weechat_color(weechat_config_string(weechat_config_get("weechat.color.status_name")))
#define JABBER_COLOR_MESSAGE_JOIN weechat_color(weechat_config_string(jabber_config_color_message_join))
#define JABBER_COLOR_MESSAGE_QUIT weechat_color(weechat_config_string(jabber_config_color_message_quit))
#define JABBER_COLOR_INPUT_NICK weechat_color(weechat_config_string(jabber_config_color_input_nick))
#define JABBER_COLOR_NICK_IN_SERVER_MESSAGE(nick) \
((nick && weechat_config_boolean(jabber_config_look_color_nicks_in_server_messages)) ? \
nick->color : JABBER_COLOR_CHAT_NICK)
extern struct t_weechat_plugin *weechat_jabber_plugin;
#endif /* jabber.h */
+1 -1
View File
@@ -33,7 +33,7 @@ struct t_infolist;
struct t_weelist;
/* API version (used to check that plugin has same API and can be loaded) */
#define WEECHAT_PLUGIN_API_VERSION "20090612-01"
#define WEECHAT_PLUGIN_API_VERSION "20090614-01"
/* macros for defining plugin infos */
#define WEECHAT_PLUGIN_NAME(__name) \