begin scaffolding objects

v1
Tony Olagbaiye 4 years ago
parent 09ce7489b7
commit 7c15319f50
No known key found for this signature in database
GPG Key ID: 9E2FF3BDEBDFC910

@ -9,8 +9,14 @@
(list (concat "-I" (expand-file-name "libstrophe" (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 gud-gdb-command-name
(string-join `("gdb"
"-ex 'handle SIGPIPE nostop noprint pass'"
,(concat "--args weechat -a -P 'alias,buflist,exec,irc' -r '/plugin load "
(expand-file-name "xmpp.so" (projectile-project-root))
"'"))
" ")))
(flycheck-clang-warnings . ("all" "extra" "error-implicit-function-declaration" "no-missing-field-initializers"))
(flycheck-clang-language-standard . "gnu99")
(flycheck-checker . c/c++-clang)
(projectile-project-compilation-cmd . "scan-build-3.8 make -j8")))

@ -46,4 +46,4 @@ use_guix()
export CC=gcc
}
use guix --with-debug-info=weechat --with-debug-info=libstrophe
use guix --with-debug-info=weechat --with-debug-info=libstrophe gdb

@ -13,16 +13,18 @@ PREFIX ?= /usr/local
LIBDIR ?= $(PREFIX)/lib
SRCS=plugin.c \
account.c \
buffer.c \
channel.c \
command.c \
config.c \
connection.c \
input.c \
message.c \
omemo.c \
user.c \
account.c \
buffer.c \
channel.c \
command.c \
completion.c \
config.c \
connection.c \
input.c \
message.c \
omemo.c \
user.c \
xmpp/presence.c \
DEPS=axc/build/libaxc.a
OBJS=$(subst .c,.o,$(SRCS))

@ -74,7 +74,7 @@
since part of weechat and it's default plugins use SIGPIPE as control.
I have no real requests for style of pull requests besides a wish that
you keep vaguely to the style I have adopted for this project.
you keep vaguely to the indentation style I use for this project.
Happy coding!

@ -596,6 +596,42 @@ int command__me(const void *pointer, void *data,
return WEECHAT_RC_OK;
}
int command__xml(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 *stanza;
(void) pointer;
(void) data;
(void) argv;
buffer__get_account_and_channel(buffer, &ptr_account, &ptr_channel);
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)
{
stanza = xmpp_stanza_new_from_string(ptr_account->context,
argv_eol[0]);
if (!stanza)
return WEECHAT_RC_ERROR;
xmpp_send(ptr_account->connection, stanza);
xmpp_stanza_release(stanza);
}
return WEECHAT_RC_OK;
}
void command__init()
{
struct t_hook *hook;
@ -641,7 +677,7 @@ void command__init()
N_("jid: jid to target"),
NULL, &command__open, NULL, NULL);
if (!hook)
weechat_printf(NULL, "Failed to setup command /chat");
weechat_printf(NULL, "Failed to setup command /open");
hook = weechat_hook_command(
"me",
@ -651,4 +687,13 @@ void command__init()
NULL, &command__me, NULL, NULL);
if (!hook)
weechat_printf(NULL, "Failed to setup command /me");
hook = weechat_hook_command(
"xml",
N_("send a raw xml stanza"),
N_("<stanza>"),
N_("stanza: xml to send"),
NULL, &command__xml, NULL, NULL);
if (!hook)
weechat_printf(NULL, "Failed to setup command /xml");
}

@ -0,0 +1,155 @@
// 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 <string.h>
#include <stdio.h>
#include <strophe.h>
#include <weechat/weechat-plugin.h>
#include "plugin.h"
#include "config.h"
#include "account.h"
#include "channel.h"
#include "user.h"
#include "buffer.h"
#include "completion.h"
void completion__channel_nicks_add_speakers(struct t_gui_completion *completion,
struct t_account *account,
struct t_channel *channel,
int highlight)
{
struct t_user *user;
const char *member;
int list_size, i;
if (channel->members_speaking[highlight])
{
list_size = weechat_list_size(channel->members_speaking[highlight]);
for (i = 0; i < list_size; i++)
{
member = weechat_list_string (
weechat_list_get(channel->members_speaking[highlight], i));
if (member)
{
user = user__search(account, member);
if (user)
weechat_hook_completion_list_add(completion,
user->profile.display_name,
1, WEECHAT_LIST_POS_BEGINNING);
}
}
}
}
int completion__channel_nicks_cb(const void *pointer, void *data,
const char *completion_item,
struct t_gui_buffer *buffer,
struct t_gui_completion *completion)
{
struct t_account *ptr_account;
struct t_channel *ptr_channel;
struct t_channel_member *ptr_member;
struct t_user *ptr_user;
/* make C compiler happy */
(void) pointer;
(void) data;
(void) completion_item;
ptr_account = NULL;
ptr_channel = NULL;
buffer__get_account_and_channel(buffer, &ptr_account, &ptr_channel);
if (ptr_channel)
{
switch (ptr_channel->type)
{
case CHANNEL_TYPE_MUC:
case CHANNEL_TYPE_PM:
for (ptr_member = ptr_channel->members; ptr_member;
ptr_member = ptr_member->next_member)
{
ptr_user = user__search(ptr_account, ptr_member->id);
if (ptr_user)
weechat_hook_completion_list_add(completion,
ptr_user->profile.display_name,
1, WEECHAT_LIST_POS_SORT);
}
/* add recent speakers on channel */
if (weechat_config_integer(config_look_nick_completion_smart) == CONFIG_NICK_COMPLETION_SMART_SPEAKERS)
{
completion__channel_nicks_add_speakers(completion, ptr_account, ptr_channel, 0);
}
/* add members whose make highlights on me recently on this channel */
if (weechat_config_integer(config_look_nick_completion_smart) == CONFIG_NICK_COMPLETION_SMART_SPEAKERS_HIGHLIGHTS)
{
completion__channel_nicks_add_speakers(completion, ptr_account, ptr_channel, 1);
}
/* add self member at the end */
weechat_hook_completion_list_add(completion,
ptr_account->name,
1, WEECHAT_LIST_POS_END);
break;
}
}
return WEECHAT_RC_OK;
}
int completion__accounts_cb(const void *pointer, void *data,
const char *completion_item,
struct t_gui_buffer *buffer,
struct t_gui_completion *completion)
{
struct t_account *ptr_account;
/* make C compiler happy */
(void) pointer;
(void) data;
(void) completion_item;
(void) buffer;
for (ptr_account = accounts; ptr_account;
ptr_account = ptr_account->next_account)
{
weechat_hook_completion_list_add(completion, account_jid(ptr_account),
0, WEECHAT_LIST_POS_SORT);
}
return WEECHAT_RC_OK;
}
void completion__init()
{
struct t_config_option *option;
const char *default_template;
weechat_hook_completion("nick",
N_("nicks of current Slack channel"),
&completion__channel_nicks_cb,
NULL, NULL);
weechat_hook_completion("account",
N_("xmpp accounts"),
&completion__accounts_cb,
NULL, NULL);
option = weechat_config_get("weechat.completion.default_template");
default_template = weechat_config_string(option);
if (!weechat_strcasestr(default_template, "%(account)"))
{
size_t length = snprintf(NULL, 0, "%s|%s",
default_template,
"%(account)") + 1;
char *new_template = malloc(length);
snprintf(new_template, length, "%s|%s",
default_template,
"%(account)");
weechat_config_option_set(option, new_template, 1);
free(new_template);
}
}

@ -0,0 +1,10 @@
// 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 _WEECHAT_XMPP_COMPLETION_H_
#define _WEECHAT_XMPP_COMPLETION_H_
void completion__init();
#endif /*WEECHAT_XMPP_COMPLETION_H*/

@ -6,15 +6,18 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/utsname.h>
#include <strophe.h>
#include <weechat/weechat-plugin.h>
#include "plugin.h"
#include "xmpp/stanza.h"
#include "config.h"
#include "account.h"
#include "user.h"
#include "channel.h"
#include "connection.h"
#include "omemo.h"
void connection__init()
{
@ -27,7 +30,7 @@ int connection__version_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void *
const char *ns;
struct t_account *account = (struct t_account *)userdata;
const char *weechat_name = "weechat";
const char *weechat_version = weechat_info_get("version", NULL);
char *weechat_version = weechat_info_get("version", NULL);
weechat_printf(NULL, "Received version request from %s", xmpp_stanza_get_from(stanza));
@ -66,8 +69,8 @@ int connection__version_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void *
xmpp_send(conn, reply);
xmpp_stanza_release(reply);
if (version)
free (version);
if (weechat_version)
free(weechat_version);
return 1;
}
@ -198,16 +201,18 @@ int connection__message_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void *
return 1;
}
#include <sys/utsname.h>
int connection__iq_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void *userdata)
{
(void) conn;
struct t_account *account = (struct t_account *)userdata;
xmpp_stanza_t *reply, *query, *identity, *feature, *x, *field, *value, *text;
char client_name[64], *node;
const char *node;
static struct utsname osinfo;
char *client_name = weechat_string_eval_expression("weechat ${info:version}",
NULL, NULL, NULL);
reply = xmpp_stanza_reply(stanza);
xmpp_stanza_set_type(reply, "result");
@ -219,8 +224,6 @@ int connection__iq_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void *userd
identity = xmpp_stanza_new(account->context);
xmpp_stanza_set_name(identity, "identity");
xmpp_stanza_set_attribute(identity, "category", "client");
snprintf(client_name, sizeof(client_name),
"weechat %s", weechat_info_get("version", NULL));
xmpp_stanza_set_attribute(identity, "name", client_name);
xmpp_stanza_set_attribute(identity, "type", "pc");
xmpp_stanza_add_child(query, identity);
@ -246,9 +249,10 @@ int connection__iq_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void *userd
xmpp_stanza_set_ns(x, "jabber:x:data");
xmpp_stanza_set_attribute(x, "type", "result");
if (uname(&osinfo) >= 0)
if (uname(&osinfo) < 0)
{
osinfo.machine;
*osinfo.sysname = 0;
*osinfo.release = 0;
}
{
@ -392,6 +396,8 @@ int connection__iq_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void *userd
xmpp_send(conn, reply);
xmpp_stanza_release(reply);
free(client_name);
return 1;
}
@ -405,7 +411,7 @@ void connection__handler(xmpp_conn_t *conn, xmpp_conn_event_t status,
(void)stream_error;
if (status == XMPP_CONN_CONNECT) {
xmpp_stanza_t *pres, *pres__c, *pres__status, *pres__status__text;
xmpp_stanza_t *pres, *pres__c, *pres__status, *pres__status__text, **children;
char cap_hash[28+1] = {0};
xmpp_handler_add(conn, connection__version_handler,
@ -418,8 +424,7 @@ void connection__handler(xmpp_conn_t *conn, xmpp_conn_event_t status,
NULL, "iq", "get", account);
/* Send initial <presence/> so that we appear online to contacts */
pres = xmpp_presence_new(account->context);
xmpp_stanza_set_from(pres, account_jid(account));
children = malloc(sizeof(*children) * (2 + 1));
pres__c = xmpp_stanza_new(account->context);
xmpp_stanza_set_name(pres__c, "c");
@ -428,8 +433,7 @@ void connection__handler(xmpp_conn_t *conn, xmpp_conn_event_t status,
xmpp_stanza_set_attribute(pres__c, "node", "http://weechat.org");
snprintf(cap_hash, sizeof(cap_hash), "%027ld=", time(NULL));
xmpp_stanza_set_attribute(pres__c, "ver", cap_hash);
xmpp_stanza_add_child(pres, pres__c);
xmpp_stanza_release(pres__c);
children[0] = pres__c;
pres__status = xmpp_stanza_new(account->context);
xmpp_stanza_set_name(pres__status, "status");
@ -439,9 +443,12 @@ void connection__handler(xmpp_conn_t *conn, xmpp_conn_event_t status,
xmpp_stanza_add_child(pres__status, pres__status__text);
xmpp_stanza_release(pres__status__text);
xmpp_stanza_add_child(pres, pres__status);
xmpp_stanza_release(pres__status);
children[1] = pres__status;
children[2] = NULL;
pres = stanza__presence(account->context, NULL,
children, NULL, strdup(account_jid(account)),
NULL, NULL);
xmpp_send(conn, pres);
xmpp_stanza_release(pres);
@ -450,8 +457,9 @@ void connection__handler(xmpp_conn_t *conn, xmpp_conn_event_t status,
weechat_string_dyn_concat(command, account_autojoin(account), -1);
weechat_command(account->buffer, *command);
weechat_string_dyn_free(command, 1);
omemo__init(account);
} else {
//weechat_printf(account->buffer, "DEBUG: disconnected");
//xmpp_stop(account->context);
}
}

@ -14,7 +14,7 @@
#include "connection.h"
#include "command.h"
#include "buffer.h"
//#include "xmpp-completion.h"
#include "completion.h"
WEECHAT_PLUGIN_NAME(WEECHAT_XMPP_PLUGIN_NAME);
@ -46,7 +46,7 @@ int weechat_plugin_init(struct t_weechat_plugin *plugin, int argc, char *argv[])
command__init();
//completion__init();
completion__init();
weechat_xmpp_process_timer = weechat_hook_timer(TIMER_INTERVAL_SEC * 1000, 0, 0,
&account__timer_cb,

@ -2,8 +2,8 @@
// 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 _WEECHAT_XMPP_H_
#define _WEECHAT_XMPP_H_
#ifndef _WEECHAT_XMPP_PLUGIN_H_
#define _WEECHAT_XMPP_PLUGIN_H_
#define weechat_plugin weechat_xmpp_plugin
#define WEECHAT_XMPP_PLUGIN_NAME "xmpp"
@ -12,4 +12,4 @@
extern struct t_weechat_plugin *weechat_xmpp_plugin;
#endif /*WEECHAT_XMPP_H*/
#endif /*WEECHAT_XMPP_PLUGIN_H*/

File diff suppressed because it is too large Load Diff

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

@ -0,0 +1,48 @@
// 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__presence(xmpp_ctx_t *context, xmpp_stanza_t *base,
xmpp_stanza_t **children, char *ns,
char *from, char *to, char *type)
{
xmpp_stanza_t *parent = base ? base : xmpp_presence_new(context);
xmpp_stanza_t **child = children;
if (ns)
{
xmpp_stanza_set_ns(parent, ns);
free(ns);
}
if (from)
{
xmpp_stanza_set_from(parent, from);
free(from);
}
if (to)
{
xmpp_stanza_set_to(parent, to);
free(to);
}
if (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;
}

@ -0,0 +1,12 @@
// 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 _WEECHAT_XMPP_STANZA_H_
#define _WEECHAT_XMPP_STANZA_H_
xmpp_stanza_t *stanza__presence(xmpp_ctx_t *context, xmpp_stanza_t *base,
xmpp_stanza_t **children, const char *ns,
const char *from, const char *to, const char *type);
#endif /*WEECHAT_XMPP_STANZA_H*/
Loading…
Cancel
Save