edits and highlights!

v1
Tony Olagbaiye 4 years ago
parent 668eb4ace1
commit 24e1df64b0
No known key found for this signature in database
GPG Key ID: 9E2FF3BDEBDFC910

@ -14,7 +14,7 @@
"-ex 'handle SIGPIPE nostop noprint pass'" "-ex 'handle SIGPIPE nostop noprint pass'"
,(concat "--args weechat -a -P 'alias,buflist,exec,irc' -r '/plugin load " ,(concat "--args weechat -a -P 'alias,buflist,exec,irc' -r '/plugin load "
(expand-file-name "xmpp.so" (projectile-project-root)) (expand-file-name "xmpp.so" (projectile-project-root))
"'")) "'; /debug tags"))
" "))) " ")))
(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"))
(flycheck-clang-language-standard . "gnu99") (flycheck-clang-language-standard . "gnu99")

@ -25,6 +25,7 @@ SRCS=plugin.c \
omemo.c \ omemo.c \
user.c \ user.c \
xmpp/presence.c \ xmpp/presence.c \
xmpp/iq.c \
DEPS=axc/build/libaxc.a DEPS=axc/build/libaxc.a
OBJS=$(subst .c,.o,$(SRCS)) OBJS=$(subst .c,.o,$(SRCS))

@ -94,13 +94,18 @@
* [X] Allow /close without crashing * [X] Allow /close without crashing
* [ ] [#B] Handle wide errors gracefully * [ ] [#B] Handle wide errors gracefully
* [ ] [#B] Event-driven MUC entrance * [ ] [#B] Event-driven MUC entrance
* [ ] Pings * [ ] [#C] XMPP Ping (xep-199)
* [X] [#A] Highlight
* [ ] MUCs * [ ] MUCs
* [X] Opening (/enter) * [X] Opening (/enter)
* [ ] Leave on /close * [ ] [#B] Leave on /close
* [X] Receiving * [X] Receiving
* [X] Sending * [X] Sending
* [X] With /msg
* [ ] [#B] Edits * [ ] [#B] Edits
* [X] [#B] Displaying
* [X] [#B] Tagging
* [ ] [#B] Making
* [ ] [#B] Handle errors gracefully * [ ] [#B] Handle errors gracefully
* [X] [#B] Presence/nicklist * [X] [#B] Presence/nicklist
* [X] [#B] Enters * [X] [#B] Enters
@ -111,11 +116,14 @@
* [ ] Presence * [ ] Presence
* [X] Disco * [X] Disco
* [ ] Disco response * [ ] Disco response
* [ ] Key Generation / storage (secured_data?)
* [ ] Messages * [ ] Messages
* [ ] MUC PMs * [ ] [#C] MUC PMs
* [ ] Send typing notifications * [ ] [#A] Send typing notifications
* [ ] Recv typing notifications * [ ] [#A] Recv typing notifications
* [ ] Read receipts * [ ] [#C] Read receipts
* [ ] Service Disco
* [ ] Bookmarks / Roster
* [ ] OTR (libotr) * [ ] OTR (libotr)
* [ ] PGP (libgpgme) * [ ] PGP (libgpgme)
** TODO [#C] Implement completion engine (milestone v0.3) ** TODO [#C] Implement completion engine (milestone v0.3)

@ -74,6 +74,8 @@ struct t_account
struct t_gui_buffer *buffer; struct t_gui_buffer *buffer;
char *buffer_as_string; char *buffer_as_string;
//struct t_device *devices;
//struct t_device *last_device;
struct t_user *users; struct t_user *users;
struct t_user *last_user; struct t_user *last_user;
struct t_channel *channels; struct t_channel *channels;

@ -605,14 +605,14 @@ struct t_channel_member *channel__add_member(struct t_account *account,
char *jid_resource = xmpp_jid_resource(account->context, user->id); char *jid_resource = xmpp_jid_resource(account->context, user->id);
if (weechat_strcasecmp(jid_bare, channel->id) == 0 if (weechat_strcasecmp(jid_bare, channel->id) == 0
&& channel->type == CHANNEL_TYPE_MUC) && channel->type == CHANNEL_TYPE_MUC)
weechat_printf(channel->buffer, "%s%s entered", weechat_printf_date_tags(channel->buffer, 0, "xmpp_presence,enter,log4", "%s%s entered",
weechat_prefix("join"), weechat_prefix("join"),
jid_resource); jid_resource);
else else
weechat_printf(channel->buffer, "%s%s (%s) entered", weechat_printf_date_tags(channel->buffer, 0, "xmpp_presence,enter,log4", "%s%s (%s) entered",
weechat_prefix("join"), weechat_prefix("join"),
xmpp_jid_bare(account->context, user->id), xmpp_jid_bare(account->context, user->id),
xmpp_jid_resource(account->context, user->id)); xmpp_jid_resource(account->context, user->id));
return member; return member;
} }
@ -654,14 +654,14 @@ struct t_channel_member *channel__remove_member(struct t_account *account,
char *jid_resource = xmpp_jid_resource(account->context, user->id); char *jid_resource = xmpp_jid_resource(account->context, user->id);
if (weechat_strcasecmp(jid_bare, channel->id) == 0 if (weechat_strcasecmp(jid_bare, channel->id) == 0
&& channel->type == CHANNEL_TYPE_MUC) && channel->type == CHANNEL_TYPE_MUC)
weechat_printf(channel->buffer, "%s%s left", weechat_printf_date_tags(channel->buffer, 0, "xmpp_presence,leave,log4", "%s%s left",
weechat_prefix("quit"), weechat_prefix("quit"),
jid_resource); jid_resource);
else else
weechat_printf(channel->buffer, "%s%s (%s) left", weechat_printf_date_tags(channel->buffer, 0, "xmpp_presence,leave,log4", "%s%s (%s) left",
weechat_prefix("quit"), weechat_prefix("quit"),
xmpp_jid_bare(account->context, user->id), xmpp_jid_bare(account->context, user->id),
xmpp_jid_resource(account->context, user->id)); xmpp_jid_resource(account->context, user->id));
return member; return member;
} }

@ -544,9 +544,64 @@ int command__open(const void *pointer, void *data,
return WEECHAT_RC_OK; return WEECHAT_RC_OK;
} }
int command__msg(const void *pointer, void *data,
struct t_gui_buffer *buffer, int argc,
char **argv, char **argv_eol)
{
struct t_account *ptr_account = NULL;
struct t_channel *ptr_channel = NULL;
xmpp_stanza_t *message;
char *text;
(void) pointer;
(void) data;
(void) argv;
buffer__get_account_and_channel(buffer, &ptr_account, &ptr_channel);
if (!ptr_account)
return WEECHAT_RC_ERROR;
if (!ptr_channel)
{
weechat_printf (
ptr_account->buffer,
_("%s%s: \"%s\" command can not be executed on a account buffer"),
weechat_prefix("error"), WEECHAT_XMPP_PLUGIN_NAME, "msg");
return WEECHAT_RC_OK;
}
if (!ptr_account->is_connected)
{
weechat_printf(buffer,
_("%s%s: you are not connected to server"),
weechat_prefix("error"), WEECHAT_XMPP_PLUGIN_NAME);
return WEECHAT_RC_OK;
}
if (argc > 1)
{
text = argv_eol[1];
message = xmpp_message_new(ptr_account->context,
ptr_channel->type == CHANNEL_TYPE_MUC ? "groupchat" : "chat",
ptr_channel->name, NULL);
xmpp_message_set_body(message, text);
xmpp_send(ptr_account->connection, message);
xmpp_stanza_release(message);
if (ptr_channel->type != CHANNEL_TYPE_MUC)
weechat_printf_date_tags(ptr_channel->buffer, 0,
"xmpp_message,message,private,notify_none,self_msg,log1",
"%s%s",
user__as_prefix_raw(ptr_account, account_jid(ptr_account)), text);
}
return WEECHAT_RC_OK;
}
int command__me(const void *pointer, void *data, int command__me(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)
{ {
struct t_account *ptr_account = NULL; struct t_account *ptr_account = NULL;
struct t_channel *ptr_channel = NULL; struct t_channel *ptr_channel = NULL;
@ -583,14 +638,18 @@ int command__me(const void *pointer, void *data,
{ {
text = argv_eol[0]; text = argv_eol[0];
message = xmpp_message_new(ptr_account->context, "chat", ptr_channel->name, NULL); message = xmpp_message_new(ptr_account->context,
ptr_channel->type == CHANNEL_TYPE_MUC ? "groupchat" : "chat",
ptr_channel->name, NULL);
xmpp_message_set_body(message, text); xmpp_message_set_body(message, text);
xmpp_send(ptr_account->connection, message); xmpp_send(ptr_account->connection, message);
xmpp_stanza_release(message); xmpp_stanza_release(message);
if (ptr_channel->type != CHANNEL_TYPE_MUC) if (ptr_channel->type != CHANNEL_TYPE_MUC)
weechat_printf(ptr_channel->buffer, "%s%s %s", weechat_printf_date_tags(ptr_channel->buffer, 0,
weechat_prefix("action"), account_jid(ptr_account), "xmpp_message,message,action,private,notify_none,self_msg,log1",
text); "%s%s %s",
weechat_prefix("action"), account_jid(ptr_account),
text);
} }
return WEECHAT_RC_OK; return WEECHAT_RC_OK;
@ -679,9 +738,18 @@ void command__init()
if (!hook) if (!hook)
weechat_printf(NULL, "Failed to setup command /open"); weechat_printf(NULL, "Failed to setup command /open");
hook = weechat_hook_command(
"msg",
N_("send a xmpp message to the current buffer"),
N_("<message>"),
N_("message: message to send"),
NULL, &command__msg, NULL, NULL);
if (!hook)
weechat_printf(NULL, "Failed to setup command /msg");
hook = weechat_hook_command( hook = weechat_hook_command(
"me", "me",
N_("send a xmpp action to the current channel"), N_("send a xmpp action to the current buffer"),
N_("<message>"), N_("<message>"),
N_("message: message to send"), N_("message: message to send"),
NULL, &command__me, NULL, NULL); NULL, &command__me, NULL, NULL);

@ -125,8 +125,8 @@ int connection__message_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void *
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, *delay, *topic; xmpp_stanza_t *body, *delay, *topic, *replace;
const char *type, *from, *from_bare, *to, *timestamp = 0; const char *type, *from, *from_bare, *to, *id, *replace_id, *timestamp;
char *intext; char *intext;
struct tm time = {0}; struct tm time = {0};
time_t date = 0; time_t date = 0;
@ -159,6 +159,9 @@ int connection__message_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void *
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); to = xmpp_stanza_get_to(stanza);
id = xmpp_stanza_get_id(stanza);
replace = xmpp_stanza_get_child_by_name_and_ns(stanza, "replace", "urn:xmpp:message-correct:0");
replace_id = replace ? xmpp_stanza_get_id(replace) : NULL;
intext = xmpp_stanza_get_text(body); intext = xmpp_stanza_get_text(body);
@ -182,19 +185,46 @@ int connection__message_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void *
date = mktime(&time); date = mktime(&time);
} }
char **dyn_tags = weechat_string_dyn_alloc(1);
weechat_string_dyn_concat(dyn_tags, "xmpp_message,message", -1);
if (id)
{
weechat_string_dyn_concat(dyn_tags, ",id_", -1);
weechat_string_dyn_concat(dyn_tags, id, -1);
}
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_string_dyn_concat(dyn_tags, ",private", -1);
user__as_prefix_raw(account, from), if (weechat_string_match(intext, "/me *", 0))
weechat_string_dyn_concat(dyn_tags, ",action", -1);
if (replace)
{
weechat_string_dyn_concat(dyn_tags, ",edit", -1);
weechat_string_dyn_concat(dyn_tags, ",replace_", -1);
weechat_string_dyn_concat(dyn_tags, replace_id, -1);
}
if (date != 0)
weechat_string_dyn_concat(dyn_tags, ",notify_none", -1);
else
weechat_string_dyn_concat(dyn_tags, ",log1", -1);
const char *edit = replace ? "* " : ""; // Losing which message was edited, sadly
if (strcmp(to, channel->id) == 0)
weechat_printf_date_tags(channel->buffer, date, *dyn_tags, "%s%s[to %s]: %s",
edit, 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, *dyn_tags, "%s%s%s %s",
weechat_prefix("action"), from, edit, weechat_prefix("action"), from,
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, *dyn_tags, "%s%s%s",
user__as_prefix_raw(account, from), edit, user__as_prefix_raw(account, from),
intext ? intext : ""); intext ? intext : "");
weechat_string_dyn_free(dyn_tags, 1);
if (intext) if (intext)
xmpp_free(account->context, intext); xmpp_free(account->context, intext);
@ -458,6 +488,21 @@ void connection__handler(xmpp_conn_t *conn, xmpp_conn_event_t status,
weechat_command(account->buffer, *command); weechat_command(account->buffer, *command);
weechat_string_dyn_free(command, 1); weechat_string_dyn_free(command, 1);
children[1] = NULL;
children[0] =
stanza__iq_pubsub_items(account->context, NULL,
strdup("eu.siacs.conversations.axolotl.devicelist"));
children[0] =
stanza__iq_pubsub(account->context, NULL, children,
strdup("http://jabber.org/protocol/pubsub"));
children[0] =
stanza__iq(account->context, NULL, children, NULL, strdup("fetch1"),
strdup(account_jid(account)), strdup(account_jid(account)),
strdup("get"));
xmpp_send(conn, children[0]);
xmpp_stanza_release(children[0]);
omemo__init(account); omemo__init(account);
} else { } else {
account__disconnect(account, 1); account__disconnect(account, 1);

File diff suppressed because it is too large Load Diff

@ -1 +0,0 @@
/nix/store/0nlcxz4fp2zhpjm67wng1g05vv37xiwk-catt-0.12.1

@ -0,0 +1,102 @@
// 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/.
#include <stdlib.h>
#include <strophe.h>
xmpp_stanza_t *stanza__iq(xmpp_ctx_t *context, xmpp_stanza_t *base,
xmpp_stanza_t **children, char *ns, char *id,
char *from, char *to, char *type)
{
xmpp_stanza_t *parent = base ? base : xmpp_iq_new(context, type, id);
xmpp_stanza_t **child = children;
if (ns)
{
xmpp_stanza_set_ns(parent, ns);
free(ns);
}
if (base && id)
{
xmpp_stanza_set_id(parent, id);
free(id);
}
if (from)
{
xmpp_stanza_set_from(parent, from);
free(from);
}
if (to)
{
xmpp_stanza_set_to(parent, to);
free(to);
}
if (base && type)
{
xmpp_stanza_set_attribute(parent, "type", type);
free(type);
}
while (*child)
{
xmpp_stanza_add_child(parent, *child);
xmpp_stanza_release(*child);
++child;
}
return parent;
}
xmpp_stanza_t *stanza__iq_pubsub(xmpp_ctx_t *context, xmpp_stanza_t *base,
xmpp_stanza_t **children, char *ns)
{
xmpp_stanza_t *parent = base;
xmpp_stanza_t **child = children;
if (!parent)
{
parent = xmpp_stanza_new(context);
xmpp_stanza_set_name(parent, "pubsub");
}
if (ns)
{
xmpp_stanza_set_ns(parent, ns);
free(ns);
}
while (*child)
{
xmpp_stanza_add_child(parent, *child);
xmpp_stanza_release(*child);
++child;
}
return parent;
}
xmpp_stanza_t *stanza__iq_pubsub_items(xmpp_ctx_t *context, xmpp_stanza_t *base, char *node)
{
xmpp_stanza_t *parent = base;
if (!parent)
{
parent = xmpp_stanza_new(context);
xmpp_stanza_set_name(parent, "items");
}
if (node)
{
xmpp_stanza_set_attribute(parent, "node", node);
free(node);
}
return parent;
}

@ -7,6 +7,15 @@
xmpp_stanza_t *stanza__presence(xmpp_ctx_t *context, xmpp_stanza_t *base, xmpp_stanza_t *stanza__presence(xmpp_ctx_t *context, xmpp_stanza_t *base,
xmpp_stanza_t **children, const char *ns, xmpp_stanza_t **children, const char *ns,
const char *from, const char *to, const char *type); char *from, char *to, const char *type);
xmpp_stanza_t *stanza__iq(xmpp_ctx_t *context, xmpp_stanza_t *base,
xmpp_stanza_t **children, char *ns, char *id,
char *from, char *to, char *type);
xmpp_stanza_t *stanza__iq_pubsub(xmpp_ctx_t *context, xmpp_stanza_t *base,
xmpp_stanza_t **children, char *ns);
xmpp_stanza_t *stanza__iq_pubsub_items(xmpp_ctx_t *context, xmpp_stanza_t *base, char *node);
#endif /*WEECHAT_XMPP_STANZA_H*/ #endif /*WEECHAT_XMPP_STANZA_H*/

Loading…
Cancel
Save