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

@ -93,9 +93,6 @@ void account__log_emit_weechat(void *const userdata, const xmpp_log_level_t leve
static const char *log_level_name[4] = {"debug", "info", "warn", "error"}; static const char *log_level_name[4] = {"debug", "info", "warn", "error"};
time_t date = time(NULL);
const char *timestamp = weechat_util_get_time_string(&date);
char *xml; char *xml;
if ((level == XMPP_LEVEL_DEBUG) && ((xml = strchr(msg, '<')) != NULL)) if ((level == XMPP_LEVEL_DEBUG) && ((xml = strchr(msg, '<')) != NULL))
{ {
@ -112,7 +109,7 @@ void account__log_emit_weechat(void *const userdata, const xmpp_log_level_t leve
return; return;
} }
xmlNodePtr root = xmlDocGetRootElement(doc); xmlNodePtr root = xmlDocGetRootElement(doc);
const char *tag = root ? root->name : ""; const char *tag = root ? (const char*)root->name : "";
const char *colour = weechat_color("blue"); const char *colour = weechat_color("blue");
if (weechat_strcasecmp(tag, "message")) if (weechat_strcasecmp(tag, "message"))
{ {
@ -143,8 +140,10 @@ void account__log_emit_weechat(void *const userdata, const xmpp_log_level_t leve
fclose(nullfd); fclose(nullfd);
return; return;
} }
const char **lines = weechat_string_split(buf, "\r\n", NULL, char **lines = weechat_string_split((char*)buf, "\r\n", NULL,
0, 0, &size); 0, 0, &size);
if (lines[size-1][0] == 0)
lines[--size] = 0;
weechat_printf( weechat_printf(
account ? account->buffer : NULL, account ? account->buffer : NULL,
_("%s%s (%s): %s"), _("%s%s (%s): %s"),
@ -155,6 +154,7 @@ void account__log_emit_weechat(void *const userdata, const xmpp_log_level_t leve
account ? account->buffer : NULL, account ? account->buffer : NULL,
_("%s%s"), colour, lines[i]); _("%s%s"), colour, lines[i]);
weechat_string_free_split(lines);
fclose(nullfd); fclose(nullfd);
} }
else else
@ -257,7 +257,7 @@ struct t_account *account__alloc(const char *name)
void account__free_data(struct t_account *account) void account__free_data(struct t_account *account)
{ {
int i; //int i;
if (!account) if (!account)
return; return;
@ -535,4 +535,6 @@ int account__timer_cb(const void *pointer, void *data, int remaining_calls)
|| xmpp_conn_is_connected(ptr_account->connection))) || xmpp_conn_is_connected(ptr_account->connection)))
connection__process(ptr_account->context, ptr_account->connection, 10); connection__process(ptr_account->context, ptr_account->connection, 10);
} }
return WEECHAT_RC_OK;
} }

@ -56,7 +56,7 @@ enum t_account_option
struct t_account struct t_account
{ {
const char *name; char *name;
struct t_config_option *options[ACCOUNT_NUM_OPTIONS]; struct t_config_option *options[ACCOUNT_NUM_OPTIONS];
int reloading_from_config; int reloading_from_config;
@ -65,8 +65,8 @@ struct t_account
int disconnected; int disconnected;
xmpp_log_t logger; xmpp_log_t logger;
struct xmpp_ctx_t *context; xmpp_ctx_t *context;
struct xmpp_conn_t *connection; xmpp_conn_t *connection;
struct t_gui_buffer *buffer; struct t_gui_buffer *buffer;
char *buffer_as_string; char *buffer_as_string;

@ -607,23 +607,23 @@ struct t_channel_member *channel__add_member(struct t_account *account,
void channel__send_message(struct t_account *account, struct t_channel *channel, void channel__send_message(struct t_account *account, struct t_channel *channel,
const char *to, const char *body) const char *to, const char *body)
{ {
struct xmpp_stanza_t *message = xmpp_message_new(account->context, xmpp_stanza_t *message = xmpp_message_new(account->context,
channel->type == CHANNEL_TYPE_MUC channel->type == CHANNEL_TYPE_MUC
? "groupchat" : "chat", ? "groupchat" : "chat",
to, NULL); to, NULL);
xmpp_message_set_body(message, body); xmpp_message_set_body(message, body);
char *url = strstr(body, "http"); char *url = strstr(body, "http");
if (url) if (url)
{ {
struct xmpp_stanza_t *message__x = xmpp_stanza_new(account->context); xmpp_stanza_t *message__x = xmpp_stanza_new(account->context);
xmpp_stanza_set_name(message__x, "x"); xmpp_stanza_set_name(message__x, "x");
xmpp_stanza_set_ns(message__x, "jabber:x:oob"); xmpp_stanza_set_ns(message__x, "jabber:x:oob");
struct xmpp_stanza_t *message__x__url = xmpp_stanza_new(account->context); xmpp_stanza_t *message__x__url = xmpp_stanza_new(account->context);
xmpp_stanza_set_name(message__x__url, "url"); xmpp_stanza_set_name(message__x__url, "url");
struct xmpp_stanza_t *message__x__url__text = xmpp_stanza_new(account->context); xmpp_stanza_t *message__x__url__text = xmpp_stanza_new(account->context);
xmpp_stanza_set_text(message__x__url__text, url); xmpp_stanza_set_text(message__x__url__text, url);
xmpp_stanza_add_child(message__x__url, message__x__url__text); xmpp_stanza_add_child(message__x__url, message__x__url__text);
xmpp_stanza_release(message__x__url__text); xmpp_stanza_release(message__x__url__text);

@ -168,8 +168,10 @@ void command__account_add(int argc, char **argv)
{ {
case 5: case 5:
password = argv[4]; password = argv[4];
// fall through
case 4: case 4:
jid = argv[3]; jid = argv[3];
// fall through
case 3: case 3:
name = argv[2]; name = argv[2];
command__add_account(name, jid, password); command__add_account(name, jid, password);
@ -332,7 +334,7 @@ int command__enter(const void *pointer, void *data,
{ {
struct t_account *ptr_account = NULL; struct t_account *ptr_account = NULL;
struct t_channel *ptr_channel = NULL; struct t_channel *ptr_channel = NULL;
struct xmpp_stanza_t *pres; xmpp_stanza_t *pres;
char *jid, *pres_jid, *text; char *jid, *pres_jid, *text;
(void) pointer; (void) pointer;
@ -354,43 +356,49 @@ int command__enter(const void *pointer, void *data,
if (argc > 1) if (argc > 1)
{ {
jid = argv[1]; int n_jid = 0;
pres_jid = argv[1]; char **jids = weechat_string_split(argv[1], ",", NULL, 0, 0, &n_jid);
for (int i = 0; i < n_jid; i++)
if(!xmpp_jid_resource(ptr_account->context, pres_jid))
pres_jid = xmpp_jid_new(
ptr_account->context,
xmpp_jid_node(ptr_account->context, jid),
xmpp_jid_domain(ptr_account->context, jid),
account_nickname(ptr_account)
&& strlen(account_nickname(ptr_account))
? account_nickname(ptr_account)
: xmpp_jid_node(ptr_account->context,
account_jid(ptr_account)));
ptr_channel = channel__search(ptr_account, jid);
if (!ptr_channel)
ptr_channel = channel__new(ptr_account, CHANNEL_TYPE_MUC, jid, jid);
pres = xmpp_presence_new(ptr_account->context);
xmpp_stanza_set_to(pres, pres_jid);
xmpp_stanza_set_from(pres, account_jid(ptr_account));
struct xmpp_stanza_t *pres__x = xmpp_stanza_new(ptr_account->context);
xmpp_stanza_set_name(pres__x, "x");
xmpp_stanza_set_ns(pres__x, "http://jabber.org/protocol/muc");
xmpp_stanza_add_child(pres, pres__x);
xmpp_stanza_release(pres__x);
xmpp_send(ptr_account->connection, pres);
xmpp_stanza_release(pres);
if (argc > 2)
{ {
text = argv_eol[2]; jid = xmpp_jid_bare(ptr_account->context, jids[i]);
pres_jid = jids[i];
if(!xmpp_jid_resource(ptr_account->context, pres_jid))
pres_jid = xmpp_jid_new(
ptr_account->context,
xmpp_jid_node(ptr_account->context, jid),
xmpp_jid_domain(ptr_account->context, jid),
account_nickname(ptr_account)
&& strlen(account_nickname(ptr_account))
? account_nickname(ptr_account)
: xmpp_jid_node(ptr_account->context,
account_jid(ptr_account)));
ptr_channel = channel__search(ptr_account, jid);
if (!ptr_channel)
ptr_channel = channel__new(ptr_account, CHANNEL_TYPE_MUC, jid, jid);
pres = xmpp_presence_new(ptr_account->context);
xmpp_stanza_set_to(pres, pres_jid);
xmpp_stanza_set_from(pres, account_jid(ptr_account));
xmpp_stanza_t *pres__x = xmpp_stanza_new(ptr_account->context);
xmpp_stanza_set_name(pres__x, "x");
xmpp_stanza_set_ns(pres__x, "http://jabber.org/protocol/muc");
xmpp_stanza_add_child(pres, pres__x);
xmpp_stanza_release(pres__x);
xmpp_send(ptr_account->connection, pres);
xmpp_stanza_release(pres);
if (argc > 2)
{
text = argv_eol[2];
channel__send_message(ptr_account, ptr_channel, jid, text); channel__send_message(ptr_account, ptr_channel, jid, text);
}
} }
weechat_string_free_split(jids);
} }
return WEECHAT_RC_OK; return WEECHAT_RC_OK;
@ -402,7 +410,7 @@ int command__open(const void *pointer, void *data,
{ {
struct t_account *ptr_account = NULL; struct t_account *ptr_account = NULL;
struct t_channel *ptr_channel = NULL; struct t_channel *ptr_channel = NULL;
struct xmpp_stanza_t *pres; xmpp_stanza_t *pres;
char *jid, *text; char *jid, *text;
(void) pointer; (void) pointer;
@ -424,7 +432,7 @@ int command__open(const void *pointer, void *data,
if (argc > 1) if (argc > 1)
{ {
jid = argv[1]; jid = xmpp_jid_bare(ptr_account->context, argv[1]);
pres = xmpp_presence_new(ptr_account->context); pres = xmpp_presence_new(ptr_account->context);
xmpp_stanza_set_to(pres, jid); xmpp_stanza_set_to(pres, jid);
@ -453,7 +461,7 @@ int command__me(const void *pointer, void *data,
{ {
struct t_account *ptr_account = NULL; struct t_account *ptr_account = NULL;
struct t_channel *ptr_channel = NULL; struct t_channel *ptr_channel = NULL;
struct xmpp_stanza_t *message; xmpp_stanza_t *message;
char *text; char *text;
(void) pointer; (void) pointer;

@ -190,7 +190,7 @@ config__account_new_option (struct t_config_file *config_file,
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_("XMPP Channel Autojoin"), N_("XMPP MUC Autojoins"),
NULL, 0, 0, NULL, 0, 0,
default_value, value, default_value, value,
null_value_allowed, null_value_allowed,

@ -53,11 +53,11 @@ int version_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void *userdata)
version = xmpp_stanza_new(account->context); version = xmpp_stanza_new(account->context);
xmpp_stanza_set_name(version, "version"); xmpp_stanza_set_name(version, "version");
xmpp_stanza_add_child(query, weechat_version); xmpp_stanza_add_child(query, version);
xmpp_stanza_release(version); xmpp_stanza_release(version);
text = xmpp_stanza_new(account->context); text = xmpp_stanza_new(account->context);
xmpp_stanza_set_text(text, version); xmpp_stanza_set_text(text, weechat_version);
xmpp_stanza_add_child(version, text); xmpp_stanza_add_child(version, text);
xmpp_stanza_release(text); xmpp_stanza_release(text);
@ -74,16 +74,17 @@ int version_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void *userdata)
int presence_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void *userdata) int presence_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void *userdata)
{ {
(void) conn;
struct t_account *account = (struct t_account *)userdata; struct t_account *account = (struct t_account *)userdata;
struct t_user *user; struct t_user *user;
struct t_channel *channel; struct t_channel *channel;
const char *to, *from, *from_bare; const char *from, *from_bare;
from = xmpp_stanza_get_from(stanza); from = xmpp_stanza_get_from(stanza);
if (from == NULL) if (from == NULL)
return 1; return 1;
from_bare = xmpp_jid_bare(account->context, from); from_bare = xmpp_jid_bare(account->context, from);
to = xmpp_stanza_get_to(stanza);
user = user__search(account, from); user = user__search(account, from);
if (!user) if (!user)
@ -103,11 +104,13 @@ int presence_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void *userdata)
int message_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void *userdata) int message_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void *userdata)
{ {
(void) conn;
struct t_account *account = (struct t_account *)userdata; struct t_account *account = (struct t_account *)userdata;
struct t_channel *channel; struct t_channel *channel;
xmpp_stanza_t *body, *reply, *delay, *topic; xmpp_stanza_t *body, *delay, *topic;
const char *type, *from, *from_bare, *to, *timestamp = 0; const char *type, *from, *from_bare, *to, *timestamp = 0;
char *intext, *replytext; char *intext;
struct tm time = {0}; struct tm time = {0};
time_t date = 0; time_t date = 0;
@ -164,7 +167,7 @@ int message_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void *userdata)
if (strcmp(to, channel->id) == 0) if (strcmp(to, channel->id) == 0)
weechat_printf_date_tags(channel->buffer, date, NULL, "%s[to %s]: %s", weechat_printf_date_tags(channel->buffer, date, NULL, "%s[to %s]: %s",
user__as_prefix_raw(account->context, from), user__as_prefix_raw(account, from),
to, intext ? intext : ""); to, intext ? intext : "");
else if (weechat_string_match(intext, "/me *", 0)) else if (weechat_string_match(intext, "/me *", 0))
weechat_printf_date_tags(channel->buffer, date, NULL, "%s%s %s", weechat_printf_date_tags(channel->buffer, date, NULL, "%s%s %s",
@ -172,7 +175,7 @@ int message_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void *userdata)
intext ? intext+4 : ""); intext ? intext+4 : "");
else else
weechat_printf_date_tags(channel->buffer, date, NULL, "%s%s", weechat_printf_date_tags(channel->buffer, date, NULL, "%s%s",
user__as_prefix_raw(account->context, from), user__as_prefix_raw(account, from),
intext ? intext : ""); intext ? intext : "");
if (intext) if (intext)
@ -207,7 +210,7 @@ void connection__handler(xmpp_conn_t *conn, xmpp_conn_event_t status,
xmpp_stanza_set_ns(pres__c, "http://jabber.org/protocol/caps"); xmpp_stanza_set_ns(pres__c, "http://jabber.org/protocol/caps");
xmpp_stanza_set_attribute(pres__c, "hash", "sha-1"); xmpp_stanza_set_attribute(pres__c, "hash", "sha-1");
xmpp_stanza_set_attribute(pres__c, "node", "http://weechat.org"); xmpp_stanza_set_attribute(pres__c, "node", "http://weechat.org");
snprintf(cap_hash, sizeof(cap_hash), "%027d=", time(NULL)); snprintf(cap_hash, sizeof(cap_hash), "%027ld=", time(NULL));
xmpp_stanza_set_attribute(pres__c, "ver", cap_hash); xmpp_stanza_set_attribute(pres__c, "ver", cap_hash);
xmpp_stanza_add_child(pres, pres__c); xmpp_stanza_add_child(pres, pres__c);
xmpp_stanza_release(pres__c); xmpp_stanza_release(pres__c);
@ -226,17 +229,18 @@ void connection__handler(xmpp_conn_t *conn, xmpp_conn_event_t status,
xmpp_send(conn, pres); xmpp_send(conn, pres);
xmpp_stanza_release(pres); xmpp_stanza_release(pres);
command__enter(NULL, NULL, account->buffer, 2, argv, argv_eol); char **command = weechat_string_dyn_alloc(256);
weechat_string_dyn_concat(command, "/enter ", -1);
xmpp_send(conn, pres); weechat_string_dyn_concat(command, account_autojoin(account), -1);
xmpp_stanza_release(pres); weechat_command(account->buffer, *command);
weechat_string_dyn_free(command, 1);
} else { } else {
//weechat_printf(account->buffer, "DEBUG: disconnected"); //weechat_printf(account->buffer, "DEBUG: disconnected");
//xmpp_stop(account->context); //xmpp_stop(account->context);
} }
} }
char *const rand_string(int length) char* rand_string(int length)
{ {
char *string = malloc(length); char *string = malloc(length);
srand(time(NULL)); srand(time(NULL));
@ -255,7 +259,7 @@ int connection__connect(struct t_account *account, xmpp_conn_t **connection,
const char* jid, const char* password, int tls) const char* jid, const char* password, int tls)
{ {
*connection = xmpp_conn_new(account->context); *connection = xmpp_conn_new(account->context);
char *resource = account_resource(account); const char *resource = account_resource(account);
if (!(resource && strlen(resource))) if (!(resource && strlen(resource)))
{ {
char *const rand = rand_string(8); char *const rand = rand_string(8);
@ -273,7 +277,7 @@ int connection__connect(struct t_account *account, xmpp_conn_t **connection,
resource)); resource));
xmpp_conn_set_pass(*connection, password); xmpp_conn_set_pass(*connection, password);
auto flags = xmpp_conn_get_flags(*connection); int flags = xmpp_conn_get_flags(*connection);
switch (tls) switch (tls)
{ {
case 0: case 0:

@ -10,9 +10,9 @@
#include "plugin.h" #include "plugin.h"
#include "config.h" #include "config.h"
#include "account.h"
#include "connection.h" #include "connection.h"
#include "command.h" #include "command.h"
#include "account.h"
#include "buffer.h" #include "buffer.h"
//#include "xmpp-completion.h" //#include "xmpp-completion.h"

Loading…
Cancel
Save