add libomemo

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

3
.gitmodules vendored

@ -1,3 +1,6 @@
[submodule "axc"] [submodule "axc"]
path = axc path = axc
url = https://github.com/gkdr/axc url = https://github.com/gkdr/axc
[submodule "omemo"]
path = omemo
url = https://github.com/gkdr/libomemo

@ -99,6 +99,7 @@
* [ ] MUC PMs * [ ] MUC PMs
* [ ] Send typing notifications * [ ] Send typing notifications
* [ ] Recv typing notifications * [ ] Recv typing notifications
* [ ] Read receipts
* [ ] OTR (libotr) * [ ] OTR (libotr)
* [ ] PGP (libgpgme) * [ ] PGP (libgpgme)
** TODO [#C] Implement completion engine (milestone v0.3) ** TODO [#C] Implement completion engine (milestone v0.3)

@ -100,7 +100,7 @@ void account__log_emit_weechat(void *const userdata, const xmpp_log_level_t leve
xmlGenericErrorContext = nullfd; xmlGenericErrorContext = nullfd;
const char *header = strndup(msg, xml - msg); const char *header = strndup(msg, xml - msg);
xmlDocPtr *doc = xmlRecoverMemory(xml, strlen(xml)); xmlDocPtr doc = xmlRecoverMemory(xml, strlen(xml));
if (doc == NULL) { if (doc == NULL) {
weechat_printf( weechat_printf(
account ? account->buffer : NULL, account ? account->buffer : NULL,
@ -108,6 +108,21 @@ void account__log_emit_weechat(void *const userdata, const xmpp_log_level_t leve
fclose(nullfd); fclose(nullfd);
return; return;
} }
xmlNodePtr root = xmlDocGetRootElement(doc);
const char *tag = root ? root->name : "";
const char *colour = weechat_color("blue");
if (weechat_strcasecmp(tag, "message"))
{
colour = weechat_color("green");
}
else if (weechat_strcasecmp(tag, "presence"))
{
colour = weechat_color("yellow");
}
else if (weechat_strcasecmp(tag, "iq"))
{
colour = weechat_color("red");
}
xmlChar *buf = malloc(strlen(xml) * 2); xmlChar *buf = malloc(strlen(xml) * 2);
if (buf == NULL) { if (buf == NULL) {
weechat_printf( weechat_printf(
@ -135,7 +150,7 @@ void account__log_emit_weechat(void *const userdata, const xmpp_log_level_t leve
for (int i = 1; i < size; i++) for (int i = 1; i < size; i++)
weechat_printf( weechat_printf(
account ? account->buffer : NULL, account ? account->buffer : NULL,
_("%s"), lines[i]); _("%s%s"), colour, lines[i]);
fclose(nullfd); fclose(nullfd);
} }
@ -191,8 +206,6 @@ struct t_account *account__alloc(const char *name)
new_account->context = xmpp_ctx_new(NULL, &new_account->logger); new_account->context = xmpp_ctx_new(NULL, &new_account->logger);
new_account->connection = NULL; new_account->connection = NULL;
new_account->nickname = NULL;
new_account->buffer = NULL; new_account->buffer = NULL;
new_account->buffer_as_string = NULL; new_account->buffer_as_string = NULL;
new_account->users = NULL; new_account->users = NULL;
@ -497,10 +510,8 @@ int account__connect(struct t_account *account)
account__close_connection(account); account__close_connection(account);
account->is_connected = account->is_connected =
connection__connect(account, &account->connection, connection__connect(account, &account->connection, account_jid(account),
weechat_config_string(account->options[ACCOUNT_OPTION_JID]), account_password(account), account_tls(account));
weechat_config_string(account->options[ACCOUNT_OPTION_PASSWORD]),
weechat_config_string(account->options[ACCOUNT_OPTION_TLS]));
return account->is_connected; return account->is_connected;
} }

@ -18,6 +18,26 @@ enum t_account_option
ACCOUNT_NUM_OPTIONS, ACCOUNT_NUM_OPTIONS,
}; };
#define account__option_string(account, option) \
weechat_config_string(account->options[ACCOUNT_OPTION_ ## option])
#define account__option_integer(account, option) \
weechat_config_integer(account->options[ACCOUNT_OPTION_ ## option])
#define account__option_boolean(account, option) \
weechat_config_boolean(account->options[ACCOUNT_OPTION_ ## option])
#define account_option_set(account, option, value) \
weechat_config_option_set(account->options[option], value, 1)
#define account_jid(account) \
weechat_config_string(account->options[ACCOUNT_OPTION_JID])
#define account_password(account) \
weechat_config_string(account->options[ACCOUNT_OPTION_PASSWORD])
#define account_tls(account) \
weechat_config_integer(account->options[ACCOUNT_OPTION_TLS])
#define account_nickname(account) \
weechat_config_string(account->options[ACCOUNT_OPTION_NICKNAME])
#define account_autoconnect(account) \
weechat_config_boolean(account->options[ACCOUNT_OPTION_AUTOCONNECT])
struct t_account struct t_account
{ {
const char *name; const char *name;
@ -32,8 +52,6 @@ struct t_account
struct xmpp_ctx_t *context; struct xmpp_ctx_t *context;
struct xmpp_conn_t *connection; struct xmpp_conn_t *connection;
char *nickname;
struct t_gui_buffer *buffer; struct t_gui_buffer *buffer;
char *buffer_as_string; char *buffer_as_string;
struct t_user *users; struct t_user *users;

@ -111,21 +111,25 @@ struct t_gui_buffer *channel__create_buffer(struct t_account *account,
else else
{ {
short_name = weechat_buffer_get_string (ptr_buffer, "short_name"); short_name = weechat_buffer_get_string (ptr_buffer, "short_name");
localvar_channel = weechat_buffer_get_string (ptr_buffer, localvar_channel = weechat_buffer_get_string(ptr_buffer,
"localvar_channel"); "localvar_channel");
if (!short_name || if (!short_name ||
(localvar_channel && (strcmp(localvar_channel, short_name) == 0))) (localvar_channel && (strcmp(localvar_channel, short_name) == 0)))
{ {
weechat_buffer_set (ptr_buffer, "short_name", xmpp_jid_node(account->context, weechat_buffer_set(ptr_buffer, "short_name",
name)); xmpp_jid_node(account->context, name));
} }
} }
if(!(account_nickname(account) && strlen(account_nickname(account))))
account_option_set(account, ACCOUNT_OPTION_NICKNAME,
xmpp_jid_node(account->context, account_jid(account)));
weechat_buffer_set(ptr_buffer, "name", name); weechat_buffer_set(ptr_buffer, "name", name);
weechat_buffer_set(ptr_buffer, "localvar_set_type", weechat_buffer_set(ptr_buffer, "localvar_set_type",
(type == CHANNEL_TYPE_PM) ? "private" : "channel"); (type == CHANNEL_TYPE_PM) ? "private" : "channel");
weechat_buffer_set(ptr_buffer, "localvar_set_nick", account->nickname); weechat_buffer_set(ptr_buffer, "localvar_set_nick",
account_nickname(account));
weechat_buffer_set(ptr_buffer, "localvar_set_server", account->name); weechat_buffer_set(ptr_buffer, "localvar_set_server", account->name);
weechat_buffer_set(ptr_buffer, "localvar_set_channel", name); weechat_buffer_set(ptr_buffer, "localvar_set_channel", name);
@ -146,7 +150,7 @@ struct t_gui_buffer *channel__create_buffer(struct t_account *account,
} }
weechat_buffer_set(ptr_buffer, "highlight_words_add", weechat_buffer_set(ptr_buffer, "highlight_words_add",
account->nickname); account_nickname(account));
weechat_buffer_set(ptr_buffer, "highlight_tags_restrict", weechat_buffer_set(ptr_buffer, "highlight_tags_restrict",
"message"); "message");
} }
@ -611,8 +615,6 @@ void channel__send_message(struct t_account *account, struct t_channel *channel,
xmpp_stanza_release(message); xmpp_stanza_release(message);
if (channel->type != CHANNEL_TYPE_MUC) if (channel->type != CHANNEL_TYPE_MUC)
weechat_printf(channel->buffer, "%s%s", weechat_printf(channel->buffer, "%s%s",
user__as_prefix_raw( user__as_prefix_raw(account, account_jid(account)),
account,
weechat_config_string(account->options[ACCOUNT_OPTION_JID])),
body); body);
} }

@ -34,7 +34,7 @@ void command__display_account(struct t_account *account)
weechat_color("reset"), weechat_color("reset"),
weechat_color("chat_delimiters"), weechat_color("chat_delimiters"),
weechat_color("chat_server"), weechat_color("chat_server"),
weechat_config_string(account->options[ACCOUNT_OPTION_JID]), account_jid(account),
weechat_color("chat_delimiters"), weechat_color("chat_delimiters"),
weechat_color("reset"), weechat_color("reset"),
(account->is_connected) ? _("connected") : _("not connected"), (account->is_connected) ? _("connected") : _("not connected"),
@ -54,7 +54,7 @@ void command__display_account(struct t_account *account)
weechat_color("reset"), weechat_color("reset"),
weechat_color("chat_delimiters"), weechat_color("chat_delimiters"),
weechat_color("chat_server"), weechat_color("chat_server"),
weechat_config_string(account->options[ACCOUNT_OPTION_JID]), account_jid(account),
weechat_color("chat_delimiters"), weechat_color("chat_delimiters"),
weechat_color("reset")); weechat_color("reset"));
} }
@ -139,14 +139,12 @@ void command__add_account(const char *name, const char *jid, const char *passwor
account->name = strdup(name); account->name = strdup(name);
if (jid) if (jid)
weechat_config_option_set(account->options[ACCOUNT_OPTION_JID], account_option_set(account, ACCOUNT_OPTION_JID, strdup(jid));
strdup(jid), 1);
if (password) if (password)
weechat_config_option_set(account->options[ACCOUNT_OPTION_PASSWORD], account_option_set(account, ACCOUNT_OPTION_PASSWORD, strdup(password));
strdup(password), 1);
if (jid) if (jid)
weechat_config_option_set(account->options[ACCOUNT_OPTION_NICKNAME], account_option_set(account, ACCOUNT_OPTION_NICKNAME,
strdup(xmpp_jid_node(account->context, jid)), 1); strdup(xmpp_jid_node(account->context, jid)));
weechat_printf ( weechat_printf (
NULL, NULL,
@ -364,11 +362,11 @@ int command__enter(const void *pointer, void *data,
ptr_account->context, ptr_account->context,
xmpp_jid_node(ptr_account->context, jid), xmpp_jid_node(ptr_account->context, jid),
xmpp_jid_domain(ptr_account->context, jid), xmpp_jid_domain(ptr_account->context, jid),
weechat_config_string(ptr_account->options[ACCOUNT_OPTION_NICKNAME]) account_nickname(ptr_account)
&& strlen(weechat_config_string(ptr_account->options[ACCOUNT_OPTION_NICKNAME])) && strlen(account_nickname(ptr_account))
? weechat_config_string(ptr_account->options[ACCOUNT_OPTION_NICKNAME]) ? account_nickname(ptr_account)
: xmpp_jid_node(ptr_account->context, : xmpp_jid_node(ptr_account->context,
weechat_config_string(ptr_account->options[ACCOUNT_OPTION_JID]))); account_jid(ptr_account)));
ptr_channel = channel__search(ptr_account, jid); ptr_channel = channel__search(ptr_account, jid);
if (!ptr_channel) if (!ptr_channel)
@ -376,7 +374,7 @@ int command__enter(const void *pointer, void *data,
pres = xmpp_presence_new(ptr_account->context); pres = xmpp_presence_new(ptr_account->context);
xmpp_stanza_set_to(pres, pres_jid); xmpp_stanza_set_to(pres, pres_jid);
xmpp_stanza_set_from(pres, weechat_config_string(ptr_account->options[ACCOUNT_OPTION_JID])); xmpp_stanza_set_from(pres, account_jid(ptr_account));
struct xmpp_stanza_t *pres__x = xmpp_stanza_new(ptr_account->context); struct xmpp_stanza_t *pres__x = xmpp_stanza_new(ptr_account->context);
xmpp_stanza_set_name(pres__x, "x"); xmpp_stanza_set_name(pres__x, "x");
@ -493,8 +491,7 @@ int command__me(const void *pointer, void *data,
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(ptr_channel->buffer, "%s%s %s",
weechat_prefix("action"), weechat_prefix("action"), account_jid(ptr_account),
weechat_config_string(ptr_account->options[ACCOUNT_OPTION_JID]),
text); text);
} }

@ -163,6 +163,8 @@ int connection__connect(struct t_account *account, xmpp_conn_t **connection,
flags |= XMPP_CONN_FLAG_DISABLE_TLS; flags |= XMPP_CONN_FLAG_DISABLE_TLS;
break; break;
case 1: case 1:
flags |= ~XMPP_CONN_FLAG_DISABLE_TLS;
flags |= ~XMPP_CONN_FLAG_TRUST_TLS;
break; break;
case 2: case 2:
flags |= XMPP_CONN_FLAG_TRUST_TLS; flags |= XMPP_CONN_FLAG_TRUST_TLS;

@ -0,0 +1 @@
Subproject commit 7667e54d6488aba85701bb4dd6e09fd98bfb3a2c

@ -48,7 +48,7 @@ int weechat_plugin_init(struct t_weechat_plugin *plugin, int argc, char *argv[])
//completion__init(); //completion__init();
weechat_xmpp_process_timer = weechat_hook_timer(0.1 * 1000, 0, 0, weechat_xmpp_process_timer = weechat_hook_timer(TIMER_INTERVAL_SEC * 1000, 0, 0,
&account__timer_cb, &account__timer_cb,
NULL, NULL); NULL, NULL);

@ -8,6 +8,7 @@
#define weechat_plugin weechat_xmpp_plugin #define weechat_plugin weechat_xmpp_plugin
#define WEECHAT_XMPP_PLUGIN_NAME "xmpp" #define WEECHAT_XMPP_PLUGIN_NAME "xmpp"
#define WEECHAT_XMPP_PLUGIN_VERSION "0.1.1" #define WEECHAT_XMPP_PLUGIN_VERSION "0.1.1"
#define TIMER_INTERVAL_SEC 0.01
extern struct t_weechat_plugin *weechat_xmpp_plugin; extern struct t_weechat_plugin *weechat_xmpp_plugin;

Loading…
Cancel
Save