v1
Tony Olagbaiye 4 years ago
parent f75d1dbea3
commit 86bfc6359c
No known key found for this signature in database
GPG Key ID: 9E2FF3BDEBDFC910

@ -3,10 +3,10 @@
((c-mode ((c-mode
(eval . (setq-local flycheck-clang-include-path (eval . (setq-local flycheck-clang-include-path
(list (expand-file-name "libwebsockets/include" (projectile-project-root)) (list (expand-file-name "libstrophe" (projectile-project-root))
(expand-file-name "json-c" (projectile-project-root))))) (expand-file-name "json-c" (projectile-project-root)))))
(eval . (setq-local company-clang-arguments (eval . (setq-local company-clang-arguments
(list (concat "-I" (expand-file-name "libwebsockets/include" (projectile-project-root))) (list (concat "-I" (expand-file-name "libstrophe" (projectile-project-root)))
(concat "-I" (expand-file-name "json-c" (projectile-project-root)))))) (concat "-I" (expand-file-name "json-c" (projectile-project-root))))))
(eval . (setq-local tags-table-list (expand-file-name ".git/tags" (projectile-project-root)))) (eval . (setq-local tags-table-list (expand-file-name ".git/tags" (projectile-project-root))))
(flycheck-clang-warnings . ("all" "extra" "error-implicit-function-declaration" "no-missing-field-initializers")) (flycheck-clang-warnings . ("all" "extra" "error-implicit-function-declaration" "no-missing-field-initializers"))

@ -6,13 +6,14 @@ RM=rm -f
FIND=find FIND=find
CFLAGS+=$(DBGCFLAGS) -fno-omit-frame-pointer -fPIC -std=gnu99 -g -Wall -Wextra -Werror-implicit-function-declaration -Wno-missing-field-initializers -Ilibstrophe -Ijson-c CFLAGS+=$(DBGCFLAGS) -fno-omit-frame-pointer -fPIC -std=gnu99 -g -Wall -Wextra -Werror-implicit-function-declaration -Wno-missing-field-initializers -Ilibstrophe -Ijson-c
LDFLAGS+=-shared -g $(DBGCFLAGS) $(DBGLDFLAGS) LDFLAGS+=-shared -g $(DBGCFLAGS) $(DBGLDFLAGS)
LDLIBS= LDLIBS=-lssl -lxml2
PREFIX ?= /usr/local PREFIX ?= /usr/local
LIBDIR ?= $(PREFIX)/lib LIBDIR ?= $(PREFIX)/lib
INSTALL ?= /usr/bin/install INSTALL ?= /usr/bin/install
SRCS=xmpp.c \ SRCS=xmpp.c \
xmpp-config.c \
OLDSRCS=slack.c \ OLDSRCS=slack.c \
slack-api.c \ slack-api.c \
@ -51,7 +52,7 @@ weechat-xmpp: $(OBJS)
$(CC) $(LDFLAGS) -o xmpp.so $(OBJS) $(LDLIBS) $(CC) $(LDFLAGS) -o xmpp.so $(OBJS) $(LDLIBS)
libstrophe/.libs/libstrophe.a: libstrophe/.libs/libstrophe.a:
cd libstrophe && ./bootstrap.sh && env CFLAGS= LDFLAGS= ./configure cd libstrophe && ./bootstrap.sh && env CFLAGS=-fPIC LDFLAGS= ./configure
$(MAKE) -C libstrophe $(MAKE) -C libstrophe
libstrophe: libstrophe/.libs/libstrophe.a libstrophe: libstrophe/.libs/libstrophe.a

@ -307,7 +307,7 @@ int slack_command_slack(const void *pointer, void *data,
struct t_gui_buffer *buffer, int argc, struct t_gui_buffer *buffer, int argc,
char **argv, char **argv_eol) char **argv, char **argv_eol)
{ {
/* make C compiler happy */
(void) pointer; (void) pointer;
(void) data; (void) data;
(void) buffer; (void) buffer;
@ -353,7 +353,7 @@ int slack_command_me(const void *pointer, void *data,
struct t_slack_request *request; struct t_slack_request *request;
char *text; char *text;
/* make C compiler happy */
(void) pointer; (void) pointer;
(void) data; (void) data;
(void) buffer; (void) buffer;

@ -54,7 +54,7 @@ int slack_completion_channel_nicks_cb(const void *pointer, void *data,
struct t_slack_channel_member *ptr_member; struct t_slack_channel_member *ptr_member;
struct t_slack_user *ptr_user; struct t_slack_user *ptr_user;
/* make C compiler happy */
(void) pointer; (void) pointer;
(void) data; (void) data;
(void) completion_item; (void) completion_item;
@ -108,7 +108,7 @@ int slack_completion_workspaces_cb(const void *pointer, void *data,
{ {
struct t_slack_workspace *ptr_workspace; struct t_slack_workspace *ptr_workspace;
/* make C compiler happy */
(void) pointer; (void) pointer;
(void) data; (void) data;
(void) completion_item; (void) completion_item;

@ -1,57 +0,0 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, version 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#ifndef _SLACK_CONFIG_H_
#define _SLACK_CONFIG_H_
#define SLACK_CONFIG_NAME "slack"
enum t_slack_config_nick_completion
{
SLACK_CONFIG_NICK_COMPLETION_SMART_OFF = 0,
SLACK_CONFIG_NICK_COMPLETION_SMART_SPEAKERS,
SLACK_CONFIG_NICK_COMPLETION_SMART_SPEAKERS_HIGHLIGHTS,
};
extern struct t_config_file *slack_config_file;
extern struct t_config_section *slack_config_section_workspace_default;
extern struct t_config_section *slack_config_section_workspace;
extern struct t_config_option *slack_config_look_nick_completion_smart;
extern struct t_config_option *slack_config_workspace_default[];
int slack_config_workspace_check_value_cb(const void *pointer, void *data,
struct t_config_option *option,
const char *value);
void slack_config_workspace_change_cb(const void *pointer, void *data,
struct t_config_option *option);
struct t_config_option *slack_config_workspace_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,
int (*callback_check_value)(const void *pointer,
void *data,
struct t_config_option *option,
const char *value),
const void *callback_check_value_pointer,
void *callback_check_value_data,
void (*callback_change)(const void *pointer,
void *data,
struct t_config_option *option),
const void *callback_change_pointer,
void *callback_change_data);
extern int slack_config_init();
extern int slack_config_read();
extern int slack_config_write();
extern void slack_config_free();
#endif /*SLACK_CONFIG_H*/

@ -823,7 +823,7 @@ int slack_workspace_timer_cb(const void *pointer, void *data, int remaining_call
struct t_slack_workspace *ptr_workspace; struct t_slack_workspace *ptr_workspace;
struct t_slack_request *ptr_request; struct t_slack_request *ptr_request;
/* make C compiler happy */
(void) pointer; (void) pointer;
(void) data; (void) data;
(void) remaining_calls; (void) remaining_calls;

@ -4,33 +4,36 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <strophe.h>
#include <weechat/weechat-plugin.h>
#include "weechat-plugin.h" #include "xmpp.h"
#include "slack.h" #include "xmpp-config.h"
#include "slack-config.h"
#include "slack-workspace.h"
struct t_config_file *slack_config_file; struct t_config_file *xmpp_config_file;
struct t_config_section *slack_config_section_workspace_default; //struct t_config_section *xmpp_config_section_workspace_default;
struct t_config_section *slack_config_section_workspace; //struct t_config_section *xmpp_config_section_workspace;
struct t_config_option *slack_config_look_nick_completion_smart; struct t_config_option *xmpp_config_serverdef_jid;
struct t_config_option *xmpp_config_serverdef_password;
struct t_config_option *xmpp_config_look_nick_completion_smart;
struct t_config_option *slack_config_workspace_default[SLACK_WORKSPACE_NUM_OPTIONS]; /*
struct t_config_option *xmpp_config_workspace_default[XMPP_WORKSPACE_NUM_OPTIONS];
int slack_config_workspace_check_value_cb(const void *pointer, void *data, int xmpp_config_workspace_check_value_cb(const void *pointer, void *data,
struct t_config_option *option, struct t_config_option *option,
const char *value) const char *value)
{ {
(void) pointer; (void) pointer;
(void) data; (void) data;
(void) option; (void) option;
(void) value; (void) value;
return 1; return 1;
} }
void slack_config_workspace_change_cb(const void *pointer, void *data, void xmpp_config_workspace_change_cb(const void *pointer, void *data,
struct t_config_option *option) struct t_config_option *option)
{ {
(void) pointer; (void) pointer;
@ -38,7 +41,7 @@ void slack_config_workspace_change_cb(const void *pointer, void *data,
(void) option; (void) option;
} }
void slack_config_workspace_default_change_cb(const void *pointer, void *data, void xmpp_config_workspace_default_change_cb(const void *pointer, void *data,
struct t_config_option *option) struct t_config_option *option)
{ {
(void) pointer; (void) pointer;
@ -47,7 +50,7 @@ void slack_config_workspace_default_change_cb(const void *pointer, void *data,
} }
struct t_config_option * struct t_config_option *
slack_config_workspace_new_option (struct t_config_file *config_file, xmpp_config_workspace_new_option (struct t_config_file *config_file,
struct t_config_section *section, struct t_config_section *section,
int index_option, int index_option,
const char *option_name, const char *option_name,
@ -66,17 +69,17 @@ slack_config_workspace_new_option (struct t_config_file *config_file,
const void *callback_change_pointer, const void *callback_change_pointer,
void *callback_change_data) void *callback_change_data)
{ {
struct t_config_option *new_option; struct t_config_option *new_option;
new_option = NULL; new_option = NULL;
switch (index_option) switch (index_option)
{ {
case SLACK_WORKSPACE_OPTION_TOKEN: case XMPP_WORKSPACE_OPTION_TOKEN:
new_option = weechat_config_new_option ( new_option = weechat_config_new_option (
config_file, section, config_file, section,
option_name, "string", option_name, "string",
N_("slack api token"), N_("xmpp api token"),
NULL, 0, 0, NULL, 0, 0,
default_value, value, default_value, value,
null_value_allowed, null_value_allowed,
@ -88,62 +91,47 @@ slack_config_workspace_new_option (struct t_config_file *config_file,
callback_change_data, callback_change_data,
NULL, NULL, NULL); NULL, NULL, NULL);
break; break;
case SLACK_WORKSPACE_NUM_OPTIONS: case XMPP_WORKSPACE_NUM_OPTIONS:
break; break;
} }
return new_option; return new_option;
} }
void slack_config_workspace_create_default_options(struct t_config_section *section) void xmpp_config_workspace_create_default_options(struct t_config_section *section)
{ {
int i; int i;
for (i = 0; i < SLACK_WORKSPACE_NUM_OPTIONS; i++) for (i = 0; i < XMPP_WORKSPACE_NUM_OPTIONS; i++)
{ {
slack_config_workspace_default[i] = slack_config_workspace_new_option( xmpp_config_workspace_default[i] = xmpp_config_workspace_new_option(
slack_config_file, xmpp_config_file,
section, section,
i, i,
slack_workspace_options[i][0], xmpp_workspace_options[i][0],
slack_workspace_options[i][1], xmpp_workspace_options[i][1],
slack_workspace_options[i][1], xmpp_workspace_options[i][1],
0, 0,
&slack_config_workspace_check_value_cb, &xmpp_config_workspace_check_value_cb,
slack_workspace_options[i][0], xmpp_workspace_options[i][0],
NULL, NULL,
&slack_config_workspace_default_change_cb, &xmpp_config_workspace_default_change_cb,
slack_workspace_options[i][0], xmpp_workspace_options[i][0],
NULL); NULL);
} }
}
int slack_config_reload (const void *pointer, void *data,
struct t_config_file *config_file)
{
/* make C compiler happy */
(void) pointer;
(void) data;
//weechat_config_section_free_options(slack_config_section_workspace_default);
//weechat_config_section_free_options(slack_config_section_workspace);
//slack_workspace_free_all();
return weechat_config_reload(config_file);
} }
int slack_config_workspace_read_cb (const void *pointer, void *data, int xmpp_config_workspace_read_cb (const void *pointer, void *data,
struct t_config_file *config_file, struct t_config_file *config_file,
struct t_config_section *section, struct t_config_section *section,
const char *option_name, const char *value) const char *option_name, const char *value)
{ {
struct t_slack_workspace *ptr_workspace; struct t_xmpp_workspace *ptr_workspace;
int index_option, rc, i; int index_option, rc, i;
char *pos_option, *workspace_domain; char *pos_option, *workspace_domain;
/* make C compiler happy */
(void) pointer; (void) pointer;
(void) data; (void) data;
(void) config_file; (void) config_file;
@ -161,18 +149,18 @@ int slack_config_workspace_read_cb (const void *pointer, void *data,
pos_option++; pos_option++;
if (workspace_domain) if (workspace_domain)
{ {
index_option = slack_workspace_search_option(pos_option); index_option = xmpp_workspace_search_option(pos_option);
if (index_option >= 0) if (index_option >= 0)
{ {
ptr_workspace = slack_workspace_search(workspace_domain); ptr_workspace = xmpp_workspace_search(workspace_domain);
if (!ptr_workspace) if (!ptr_workspace)
ptr_workspace = slack_workspace_alloc(workspace_domain); ptr_workspace = xmpp_workspace_alloc(workspace_domain);
if (ptr_workspace) if (ptr_workspace)
{ {
if (ptr_workspace->reloading_from_config if (ptr_workspace->reloading_from_config
&& !ptr_workspace->reloaded_from_config) && !ptr_workspace->reloaded_from_config)
{ {
for (i = 0; i < SLACK_WORKSPACE_NUM_OPTIONS; i++) for (i = 0; i < XMPP_WORKSPACE_NUM_OPTIONS; i++)
{ {
weechat_config_option_set( weechat_config_option_set(
ptr_workspace->options[i], NULL, 1); ptr_workspace->options[i], NULL, 1);
@ -187,7 +175,7 @@ int slack_config_workspace_read_cb (const void *pointer, void *data,
weechat_printf( weechat_printf(
NULL, NULL,
_("%s%s: error adding workspace \"%s\""), _("%s%s: error adding workspace \"%s\""),
weechat_prefix("error"), SLACK_PLUGIN_NAME, weechat_prefix("error"), XMPP_PLUGIN_NAME,
workspace_domain); workspace_domain);
} }
} }
@ -201,30 +189,29 @@ int slack_config_workspace_read_cb (const void *pointer, void *data,
weechat_printf( weechat_printf(
NULL, NULL,
_("%s%s: error creating workspace option \"%s\""), _("%s%s: error creating workspace option \"%s\""),
weechat_prefix("error"), SLACK_PLUGIN_NAME, option_name); weechat_prefix("error"), XMPP_PLUGIN_NAME, option_name);
} }
return rc; return rc;
} }
int slack_config_workspace_write_cb (const void *pointer, void *data, int xmpp_config_workspace_write_cb (const void *pointer, void *data,
struct t_config_file *config_file, struct t_config_file *config_file,
const char *section_name) const char *section_name)
{ {
struct t_slack_workspace *ptr_workspace; struct t_xmpp_workspace *ptr_workspace;
int i; int i;
/* make C compiler happy */
(void) pointer; (void) pointer;
(void) data; (void) data;
if (!weechat_config_write_line(config_file, section_name, NULL)) if (!weechat_config_write_line(config_file, section_name, NULL))
return WEECHAT_CONFIG_WRITE_ERROR; return WEECHAT_CONFIG_WRITE_ERROR;
for (ptr_workspace = slack_workspaces; ptr_workspace; for (ptr_workspace = xmpp_workspaces; ptr_workspace;
ptr_workspace = ptr_workspace->next_workspace) ptr_workspace = ptr_workspace->next_workspace)
{ {
for (i = 0; i < SLACK_WORKSPACE_NUM_OPTIONS; i++) for (i = 0; i < XMPP_WORKSPACE_NUM_OPTIONS; i++)
{ {
if (!weechat_config_write_option(config_file, if (!weechat_config_write_option(config_file,
ptr_workspace->options[i])) ptr_workspace->options[i]))
@ -234,19 +221,35 @@ int slack_config_workspace_write_cb (const void *pointer, void *data,
return WEECHAT_CONFIG_WRITE_OK; return WEECHAT_CONFIG_WRITE_OK;
} }
*/
int xmpp_config_reload (const void *pointer, void *data,
struct t_config_file *config_file)
{
(void) pointer;
(void) data;
//weechat_config_section_free_options(xmpp_config_section_workspace_default);
//weechat_config_section_free_options(xmpp_config_section_workspace);
//xmpp_workspace_free_all();
return weechat_config_reload(config_file);
}
int slack_config_init() int xmpp_config_init()
{ {
struct t_config_section *ptr_section; struct t_config_section *ptr_section_serverdef;
struct t_config_section *ptr_section_server;
struct t_config_section *ptr_section_look;
slack_config_file = weechat_config_new(SLACK_CONFIG_NAME, xmpp_config_file = weechat_config_new(XMPP_CONFIG_NAME,
&slack_config_reload, NULL, NULL); &xmpp_config_reload, NULL, NULL);
if(!slack_config_file) if(!xmpp_config_file)
return 0; return 0;
ptr_section = weechat_config_new_section( ptr_section_serverdef = weechat_config_new_section(
slack_config_file, "look", xmpp_config_file, "server_default",
0, 0, 0, 0,
NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL,
@ -254,24 +257,17 @@ int slack_config_init()
NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL); NULL, NULL, NULL);
if (!ptr_section) ptr_section_server = weechat_config_new_section(
{ xmpp_config_file, "server",
weechat_config_free(slack_config_file); 0, 0,
slack_config_file = NULL; NULL, NULL, NULL,
return 0; NULL, NULL, NULL,
} NULL, NULL, NULL,
NULL, NULL, NULL,
slack_config_look_nick_completion_smart = weechat_config_new_option ( NULL, NULL, NULL);
slack_config_file, ptr_section,
"nick_completion_smart", "integer",
N_("smart completion for nicks (completes first with last speakers): "
"speakers = all speakers (including highlights), "
"speakers_highlights = only speakers with highlight"),
"off|speakers|speakers_highlights", 0, 0, "speakers", NULL, 0,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
ptr_section = weechat_config_new_section( ptr_section_look = weechat_config_new_section(
slack_config_file, "workspace_default", xmpp_config_file, "look",
0, 0, 0, 0,
NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL,
@ -279,52 +275,93 @@ int slack_config_init()
NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL); NULL, NULL, NULL);
if (!ptr_section) if (!ptr_section_serverdef
|| !ptr_section_server
|| !ptr_section_look)
{ {
weechat_config_free(slack_config_file); weechat_config_free(xmpp_config_file);
slack_config_file = NULL; xmpp_config_file = NULL;
return 0; return 0;
} }
slack_config_section_workspace_default = ptr_section; xmpp_config_serverdef_jid = weechat_config_new_option (
xmpp_config_file, ptr_section_serverdef,
slack_config_workspace_create_default_options(ptr_section); "jid", "string",
N_("XMPP Server JID"),
NULL, 0, 0, "", "", 0,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
ptr_section = weechat_config_new_section( xmpp_config_serverdef_password = weechat_config_new_option (
slack_config_file, "workspace", xmpp_config_file, ptr_section_serverdef,
0, 0, "password", "string",
&slack_config_workspace_read_cb, NULL, NULL, N_("XMPP Server Password"),
&slack_config_workspace_write_cb, NULL, NULL, NULL, 0, 0, "", "", 0,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
NULL, NULL, NULL,
NULL, NULL, NULL);
if (!ptr_section) xmpp_config_look_nick_completion_smart = weechat_config_new_option (
{ xmpp_config_file, ptr_section_look,
weechat_config_free(slack_config_file); "nick_completion_smart", "integer",
slack_config_file = NULL; N_("smart completion for nicks (completes first with last speakers): "
return 0; "speakers = all speakers (including highlights), "
} "speakers_highlights = only speakers with highlight"),
"off|speakers|speakers_highlights", 0, 0, "speakers", NULL, 0,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
slack_config_section_workspace = ptr_section; //ptr_section = weechat_config_new_section(
// xmpp_config_file, "workspace_default",
// 0, 0,
// NULL, NULL, NULL,
// NULL, NULL, NULL,
// NULL, NULL, NULL,
// NULL, NULL, NULL,
// NULL, NULL, NULL);
//if (!ptr_section)
//{
// weechat_config_free(xmpp_config_file);
// xmpp_config_file = NULL;
// return 0;
//}
//xmpp_config_section_workspace_default = ptr_section;
//xmpp_config_workspace_create_default_options(ptr_section);
// ptr_section = weechat_config_new_section(
// xmpp_config_file, "workspace",
// 0, 0,
// &xmpp_config_workspace_read_cb, NULL, NULL,
// &xmpp_config_workspace_write_cb, NULL, NULL,
// NULL, NULL, NULL,
// NULL, NULL, NULL,
// NULL, NULL, NULL);
//if (!ptr_section)
//{
// weechat_config_free(xmpp_config_file);
// xmpp_config_file = NULL;
// return 0;
//}
//xmpp_config_section_workspace = ptr_section;
return 1; return 1;
} }
int slack_config_read() int xmpp_config_read()
{ {
int rc; int rc;
rc = weechat_config_read(slack_config_file); rc = weechat_config_read(xmpp_config_file);
return rc; return rc;
} }
int slack_config_write() int xmpp_config_write()
{ {
return weechat_config_write(slack_config_file); return weechat_config_write(xmpp_config_file);
} }
void slack_config_free() void xmpp_config_free()
{ {
} }

@ -0,0 +1,59 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, version 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#ifndef _XMPP_CONFIG_H_
#define _XMPP_CONFIG_H_
#define XMPP_CONFIG_NAME "xmpp"
enum t_xmpp_config_nick_completion
{
XMPP_CONFIG_NICK_COMPLETION_SMART_OFF = 0,
XMPP_CONFIG_NICK_COMPLETION_SMART_SPEAKERS,
XMPP_CONFIG_NICK_COMPLETION_SMART_SPEAKERS_HIGHLIGHTS,
};
extern struct t_config_file *xmpp_config_file;
//extern struct t_config_section *xmpp_config_section_workspace_default;
//extern struct t_config_section *xmpp_config_section_workspace;
extern struct t_config_option *xmpp_config_serverdef_jid;
extern struct t_config_option *xmpp_config_serverdef_password;
extern struct t_config_option *xmpp_config_look_nick_completion_smart;
//extern struct t_config_option *xmpp_config_workspace_default[];
//int xmpp_config_workspace_check_value_cb(const void *pointer, void *data,
// struct t_config_option *option,
// const char *value);
//void xmpp_config_workspace_change_cb(const void *pointer, void *data,
// struct t_config_option *option);
//struct t_config_option *xmpp_config_workspace_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,
// int (*callback_check_value)(const void *pointer,
// void *data,
// struct t_config_option *option,
// const char *value),
// const void *callback_check_value_pointer,
// void *callback_check_value_data,
// void (*callback_change)(const void *pointer,
// void *data,
// struct t_config_option *option),
// const void *callback_change_pointer,
// void *callback_change_data);
extern int xmpp_config_init();
extern int xmpp_config_read();
extern int xmpp_config_write();
extern void xmpp_config_free();
#endif /*XMPP_CONFIG_H*/

@ -7,10 +7,10 @@
#include <time.h> #include <time.h>
#include <strophe.h> #include <strophe.h>
#include <json.h> #include <json.h>
#include <weechat/weechat-plugin.h>
#include "weechat/weechat-plugin.h"
#include "xmpp.h" #include "xmpp.h"
//#include "slack-config.h" #include "xmpp-config.h"
//#include "slack-command.h" //#include "slack-command.h"
//#include "slack-workspace.h" //#include "slack-workspace.h"
//#include "slack-api.h" //#include "slack-api.h"
@ -31,34 +31,47 @@ struct t_hook *xmpp_hook_timer = NULL;
struct t_gui_bar_item *xmpp_typing_bar_item = NULL; struct t_gui_bar_item *xmpp_typing_bar_item = NULL;
void xmpp_lwsl_emit_weechat(int level, const char *line) xmpp_ctx_t *xmpp_context = NULL;
xmpp_conn_t *xmpp_connection = NULL;
void xmpp_log_emit_weechat(void *const userdata, const xmpp_log_level_t level, const char *const area, const char *const msg)
{ {
char buf[50]; (void) userdata;
//lwsl_timestamp(level, buf, sizeof(buf)); time_t date = time(NULL);
const char *timestamp = weechat_util_get_time_string(&date);
weechat_printf( weechat_printf(
NULL, NULL,
_("%s%s: %s%s"), _("%s%s %d | %s: %s - %s"),
weechat_prefix("error"), XMPP_PLUGIN_NAME, weechat_prefix("error"), XMPP_PLUGIN_NAME,
buf, line); level, timestamp, area, msg);
} }
xmpp_log_t xmpp_logger = {
&xmpp_log_emit_weechat,
NULL
};
int weechat_plugin_init(struct t_weechat_plugin *plugin, int argc, char *argv[]) int weechat_plugin_init(struct t_weechat_plugin *plugin, int argc, char *argv[])
{ {
(void) argc; (void) argc;
(void) argv; (void) argv;
weechat_plugin = plugin; weechat_plugin = plugin;
//lws_set_log_level(LLL_ERR | LLL_WARN /*| LLL_NOTICE | LLL_INFO | LLL_DEBUG if (!xmpp_config_init())
// | LLL_PARSER | LLL_HEADER | LLL_EXT | LLL_CLIENT return WEECHAT_RC_ERROR;
// | LLL_LATENCY | LLL_USER | LLL_COUNT*/,
// xmpp_lwsl_emit_weechat);
//if (!xmpp_config_init()) xmpp_config_read();
// return WEECHAT_RC_ERROR;
//xmpp_config_read(); xmpp_initialize();
xmpp_context = xmpp_ctx_new(NULL, &xmpp_logger);
xmpp_connection = xmpp_conn_new(xmpp_context);
xmpp_conn_set_jid(xmpp_connection,
weechat_config_string(xmpp_config_serverdef_jid));
xmpp_conn_set_pass(xmpp_connection,
weechat_config_string(xmpp_config_serverdef_password));
//xmpp_command_init(); //xmpp_command_init();
@ -87,7 +100,7 @@ int weechat_plugin_init(struct t_weechat_plugin *plugin, int argc, char *argv[])
int weechat_plugin_end(struct t_weechat_plugin *plugin) int weechat_plugin_end(struct t_weechat_plugin *plugin)
{ {
/* make C compiler happy */ // make C compiler happy
(void) plugin; (void) plugin;
if (xmpp_typing_bar_item) if (xmpp_typing_bar_item)
@ -96,11 +109,13 @@ int weechat_plugin_end(struct t_weechat_plugin *plugin)
if (xmpp_hook_timer) if (xmpp_hook_timer)
weechat_unhook(xmpp_hook_timer); weechat_unhook(xmpp_hook_timer);
//xmpp_config_write(); xmpp_config_write();
xmpp_conn_release(xmpp_connection);
//xmpp_workspace_disconnect_all(); xmpp_ctx_free(xmpp_context);
//xmpp_workspace_free_all(); xmpp_shutdown();
return WEECHAT_RC_OK; return WEECHAT_RC_OK;
} }

Loading…
Cancel
Save