add libomemo

v1
Tony Olagbaiye 3 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"]
path = axc
url = https://github.com/gkdr/axc
[submodule "omemo"]
path = omemo
url = https://github.com/gkdr/libomemo

@ -99,6 +99,7 @@
* [ ] MUC PMs
* [ ] Send typing notifications
* [ ] Recv typing notifications
* [ ] Read receipts
* [ ] OTR (libotr)
* [ ] PGP (libgpgme)
** 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;
const char *header = strndup(msg, xml - msg);
xmlDocPtr *doc = xmlRecoverMemory(xml, strlen(xml));
xmlDocPtr doc = xmlRecoverMemory(xml, strlen(xml));
if (doc == NULL) {
weechat_printf(
account ? account->buffer : NULL,
@ -108,6 +108,21 @@ void account__log_emit_weechat(void *const userdata, const xmpp_log_level_t leve
fclose(nullfd);
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);
if (buf == NULL) {
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++)
weechat_printf(
account ? account->buffer : NULL,
_("%s"), lines[i]);
_("%s%s"), colour, lines[i]);
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->connection = NULL;
new_account->nickname = NULL;
new_account->buffer = NULL;
new_account->buffer_as_string = NULL;
new_account->users = NULL;
@ -497,10 +510,8 @@ int account__connect(struct t_account *account)
account__close_connection(account);
account->is_connected =
connection__connect(account, &account->connection,
weechat_config_string(account->options[ACCOUNT_OPTION_JID]),
weechat_config_string(account->options[ACCOUNT_OPTION_PASSWORD]),
weechat_config_string(account->options[ACCOUNT_OPTION_TLS]));
connection__connect(account, &account->connection, account_jid(account),
account_password(account), account_tls(account));
return account->is_connected;
}

@ -18,6 +18,26 @@ enum t_account_option
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
{
const char *name;
@ -32,8 +52,6 @@ struct t_account
struct xmpp_ctx_t *context;
struct xmpp_conn_t *connection;
char *nickname;
struct t_gui_buffer *buffer;
char *buffer_as_string;
struct t_user *users;

@ -111,21 +111,25 @@ struct t_gui_buffer *channel__create_buffer(struct t_account *account,
else
{
short_name = weechat_buffer_get_string (ptr_buffer, "short_name");
localvar_channel = weechat_buffer_get_string (ptr_buffer,
"localvar_channel");
localvar_channel = weechat_buffer_get_string(ptr_buffer,
"localvar_channel");
if (!short_name ||
(localvar_channel && (strcmp(localvar_channel, short_name) == 0)))
{
weechat_buffer_set (ptr_buffer, "short_name", xmpp_jid_node(account->context,
name));
weechat_buffer_set(ptr_buffer, "short_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, "localvar_set_type",
(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_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",
account->nickname);
account_nickname(account));
weechat_buffer_set(ptr_buffer, "highlight_tags_restrict",
"message");
}
@ -611,8 +615,6 @@ void channel__send_message(struct t_account *account, struct t_channel *channel,
xmpp_stanza_release(message);
if (channel->type != CHANNEL_TYPE_MUC)
weechat_printf(channel->buffer, "%s%s",
user__as_prefix_raw(
account,
weechat_config_string(account->options[ACCOUNT_OPTION_JID])),
user__as_prefix_raw(account, account_jid(account)),
body);
}

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

@ -163,6 +163,8 @@ int connection__connect(struct t_account *account, xmpp_conn_t **connection,
flags |= XMPP_CONN_FLAG_DISABLE_TLS;
break;
case 1:
flags |= ~XMPP_CONN_FLAG_DISABLE_TLS;
flags |= ~XMPP_CONN_FLAG_TRUST_TLS;
break;
case 2:
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();
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,
NULL, NULL);

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

Loading…
Cancel
Save