channel/user.c -> cpp

master
Tony Olagbaiye 3 years ago
parent 5c4aaa629c
commit 7fd3f4ac58
No known key found for this signature in database
GPG Key ID: 9E2FF3BDEBDFC910

@ -16,10 +16,10 @@
#include "config.hh" #include "config.hh"
#include "input.h" #include "input.h"
#include "omemo.h" #include "omemo.h"
#include "account.h" #include "account.hh"
#include "connection.h" #include "connection.h"
#include "user.h" #include "user.hh"
#include "channel.h" #include "channel.hh"
#include "buffer.h" #include "buffer.h"
struct t_account *accounts = NULL; struct t_account *accounts = NULL;
@ -116,7 +116,7 @@ void account__add_device(struct t_account *account,
new_device = account__search_device(account, device->id); new_device = account__search_device(account, device->id);
if (!new_device) if (!new_device)
{ {
new_device = malloc(sizeof(*new_device)); new_device = (struct t_account_device*)malloc(sizeof(*new_device));
new_device->id = device->id; new_device->id = device->id;
new_device->name = strdup(device->name); new_device->name = strdup(device->name);
new_device->label = device->label ? strdup(device->label) : NULL; new_device->label = device->label ? strdup(device->label) : NULL;
@ -177,14 +177,14 @@ xmpp_stanza_t *account__get_devicelist(struct t_account *account)
char id[64] = {0}; char id[64] = {0};
int i = 0; int i = 0;
device = malloc(sizeof(struct t_account_device)); device = (struct t_account_device*)malloc(sizeof(struct t_account_device));
device->id = account->omemo->device_id; device->id = account->omemo->device_id;
snprintf(id, sizeof(id), "%u", device->id); snprintf(id, sizeof(id), "%u", device->id);
device->name = strdup(id); device->name = strdup(id);
device->label = strdup("weechat"); device->label = strdup("weechat");
children = malloc(sizeof(xmpp_stanza_t *) * 128); children = (xmpp_stanza_t **)malloc(sizeof(xmpp_stanza_t *) * 128);
children[i++] = stanza__iq_pubsub_publish_item_list_device( children[i++] = stanza__iq_pubsub_publish_item_list_device(
account->context, NULL, with_noop(device->name), NULL); account->context, NULL, with_noop(device->name), NULL);
@ -231,7 +231,7 @@ struct t_account_mam_query *account__add_mam_query(struct t_account *account,
if (!(mam_query = account__mam_query_search(account, id))) if (!(mam_query = account__mam_query_search(account, id)))
{ {
mam_query = malloc(sizeof(struct t_account_mam_query)); mam_query = (struct t_account_mam_query*)malloc(sizeof(struct t_account_mam_query));
mam_query->id = strdup(id); mam_query->id = strdup(id);
mam_query->with = strdup(channel->id); mam_query->with = strdup(channel->id);
@ -321,7 +321,7 @@ void account__log_emit_weechat(void *const userdata, const xmpp_log_level_t leve
const char *tags = level > XMPP_LEVEL_DEBUG ? "no_log" : NULL; const char *tags = level > XMPP_LEVEL_DEBUG ? "no_log" : NULL;
char *xml; char *xml;
if ((level == XMPP_LEVEL_DEBUG) && ((xml = strchr(msg, '<')) != NULL)) if ((level == XMPP_LEVEL_DEBUG) && ((xml = const_cast<char*>(strchr(msg, '<'))) != NULL))
{ {
FILE *nullfd = fopen("/dev/null", "w+"); FILE *nullfd = fopen("/dev/null", "w+");
xmlGenericErrorContext = nullfd; xmlGenericErrorContext = nullfd;
@ -350,7 +350,7 @@ void account__log_emit_weechat(void *const userdata, const xmpp_log_level_t leve
{ {
colour = weechat_color("red"); colour = weechat_color("red");
} }
xmlChar *buf = malloc(strlen(xml) * 2); xmlChar *buf = (xmlChar*)malloc(strlen(xml) * 2);
if (buf == NULL) { if (buf == NULL) {
weechat_printf( weechat_printf(
account ? account->buffer : NULL, account ? account->buffer : NULL,
@ -407,7 +407,7 @@ struct t_account *account__alloc(const char *name)
return NULL; return NULL;
/* alloc memory for new account */ /* alloc memory for new account */
new_account = malloc(sizeof(*new_account)); new_account = (struct t_account*)malloc(sizeof(*new_account));
if (!new_account) if (!new_account)
{ {
weechat_printf(NULL, weechat_printf(NULL,
@ -466,7 +466,7 @@ struct t_account *account__alloc(const char *name)
strlen(account_options[i][0]) + strlen(account_options[i][0]) +
512 + /* inherited option name(xmpp.account_default.xxx) */ 512 + /* inherited option name(xmpp.account_default.xxx) */
1; 1;
option_name = malloc(length); option_name = (char*)malloc(length);
if (option_name) if (option_name)
{ {
snprintf(option_name, length, "%s.%s << xmpp.account_default.%s", snprintf(option_name, length, "%s.%s << xmpp.account_default.%s",
@ -702,7 +702,7 @@ struct t_gui_buffer *account__create_buffer(struct t_account *account)
weechat_buffer_set(account->buffer, "nicklist", "1"); weechat_buffer_set(account->buffer, "nicklist", "1");
weechat_buffer_set(account->buffer, "nicklist_display_groups", "0"); weechat_buffer_set(account->buffer, "nicklist_display_groups", "0");
weechat_buffer_set_pointer(account->buffer, "nicklist_callback", weechat_buffer_set_pointer(account->buffer, "nicklist_callback",
&buffer__nickcmp_cb); (void*)&buffer__nickcmp_cb);
weechat_buffer_set_pointer(account->buffer, "nicklist_callback_pointer", weechat_buffer_set_pointer(account->buffer, "nicklist_callback_pointer",
account); account);

@ -2,8 +2,13 @@
// License, version 2.0. If a copy of the MPL was not distributed with this // 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/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
#ifndef _ACCOUNT_H_ #pragma once
#define _ACCOUNT_H_
#ifdef __cplusplus
#include <ctime>
#include <cstdint>
#include <strophe.h>
#endif
extern struct t_account *accounts; extern struct t_account *accounts;
extern struct t_account *last_account; extern struct t_account *last_account;
@ -129,9 +134,12 @@ extern char *account_options[][2];
struct t_account *account__search(const char *account_name); struct t_account *account__search(const char *account_name);
struct t_account *account__casesearch (const char *account_name); struct t_account *account__casesearch (const char *account_name);
int account__search_option(const char *option_name); int account__search_option(const char *option_name);
struct t_account_device *account__search_device(struct t_account *account, uint32_t id); struct t_account_device *account__search_device(struct t_account *account,
void account__add_device(struct t_account *account, struct t_account_device *device); uint32_t id);
void account__free_device(struct t_account *account, struct t_account_device *device); void account__add_device(struct t_account *account,
struct t_account_device *device);
void account__free_device(struct t_account *account,
struct t_account_device *device);
void account__free_device_all(struct t_account *account); void account__free_device_all(struct t_account *account);
xmpp_stanza_t *account__get_devicelist(struct t_account *account); xmpp_stanza_t *account__get_devicelist(struct t_account *account);
struct t_account_mam_query *account__add_mam_query(struct t_account *account, struct t_account_mam_query *account__add_mam_query(struct t_account *account,
@ -152,5 +160,3 @@ void account__disconnect_all();
void account__close_connection(struct t_account *account); void account__close_connection(struct t_account *account);
int account__connect(struct t_account *account); int account__connect(struct t_account *account);
int account__timer_cb(const void *pointer, void *data, int remaining_calls); int account__timer_cb(const void *pointer, void *data, int remaining_calls);
#endif /*ACCOUNT_H*/

@ -8,8 +8,8 @@
#include <weechat/weechat-plugin.h> #include <weechat/weechat-plugin.h>
#include "plugin.hh" #include "plugin.hh"
#include "account.h" #include "account.hh"
#include "channel.h" #include "channel.hh"
#include "buffer.h" #include "buffer.h"
void buffer__get_account_and_channel(struct t_gui_buffer *buffer, void buffer__get_account_and_channel(struct t_gui_buffer *buffer,

@ -11,10 +11,10 @@
#include <weechat/weechat-plugin.h> #include <weechat/weechat-plugin.h>
#include "plugin.hh" #include "plugin.hh"
#include "account.h" #include "account.hh"
#include "omemo.h" #include "omemo.h"
#include "user.h" #include "user.hh"
#include "channel.h" #include "channel.hh"
#include "input.h" #include "input.h"
#include "buffer.h" #include "buffer.h"
#include "pgp.h" #include "pgp.h"
@ -116,7 +116,7 @@ struct t_gui_buffer *channel__search_buffer(struct t_account *account,
const char *ptr_type, *ptr_account_name, *ptr_remote_jid; const char *ptr_type, *ptr_account_name, *ptr_remote_jid;
hdata_buffer = weechat_hdata_get("buffer"); hdata_buffer = weechat_hdata_get("buffer");
ptr_buffer = weechat_hdata_get_list(hdata_buffer, "gui_buffers"); ptr_buffer = (struct t_gui_buffer*)weechat_hdata_get_list(hdata_buffer, "gui_buffers");
while (ptr_buffer) while (ptr_buffer)
{ {
@ -140,7 +140,7 @@ struct t_gui_buffer *channel__search_buffer(struct t_account *account,
return ptr_buffer; return ptr_buffer;
} }
} }
ptr_buffer = weechat_hdata_move(hdata_buffer, ptr_buffer, 1); ptr_buffer = (struct t_gui_buffer*)weechat_hdata_move(hdata_buffer, ptr_buffer, 1);
} }
return NULL; return NULL;
@ -178,7 +178,7 @@ struct t_gui_buffer *channel__create_buffer(struct t_account *account,
if (buffer_created) if (buffer_created)
{ {
char *res = strrchr(name, '/'); char *res = (char*)strrchr(name, '/');
if (!weechat_buffer_get_integer(ptr_buffer, "short_name_is_set")) if (!weechat_buffer_get_integer(ptr_buffer, "short_name_is_set"))
weechat_buffer_set(ptr_buffer, "short_name", weechat_buffer_set(ptr_buffer, "short_name",
res ? res + 1 : name); res ? res + 1 : name);
@ -221,7 +221,7 @@ struct t_gui_buffer *channel__create_buffer(struct t_account *account,
weechat_buffer_set(ptr_buffer, "nicklist", "1"); weechat_buffer_set(ptr_buffer, "nicklist", "1");
weechat_buffer_set(ptr_buffer, "nicklist_display_groups", "0"); weechat_buffer_set(ptr_buffer, "nicklist_display_groups", "0");
weechat_buffer_set_pointer(ptr_buffer, "nicklist_callback", weechat_buffer_set_pointer(ptr_buffer, "nicklist_callback",
&buffer__nickcmp_cb); (void*)&buffer__nickcmp_cb);
weechat_buffer_set_pointer(ptr_buffer, "nicklist_callback_pointer", weechat_buffer_set_pointer(ptr_buffer, "nicklist_callback_pointer",
account); account);
} }
@ -293,7 +293,7 @@ struct t_channel *channel__new(struct t_account *account,
if (!ptr_buffer) if (!ptr_buffer)
return NULL; return NULL;
if ((new_channel = malloc(sizeof(*new_channel))) == NULL) if ((new_channel = (struct t_channel*)malloc(sizeof(*new_channel))) == NULL)
return NULL; return NULL;
typing_timer = weechat_hook_timer(1 * 1000, 0, 0, typing_timer = weechat_hook_timer(1 * 1000, 0, 0,
@ -569,7 +569,7 @@ int channel__add_typing(struct t_channel *channel,
new_typing = channel__typing_search(channel, user->id); new_typing = channel__typing_search(channel, user->id);
if (!new_typing) if (!new_typing)
{ {
new_typing = malloc(sizeof(*new_typing)); new_typing = (struct t_channel_typing*)malloc(sizeof(*new_typing));
new_typing->id = strdup(user->id); new_typing->id = strdup(user->id);
new_typing->name = strdup(user->profile.display_name); new_typing->name = strdup(user->profile.display_name);
@ -695,7 +695,7 @@ int channel__add_self_typing(struct t_channel *channel,
new_typing = channel__self_typing_search(channel, user); new_typing = channel__self_typing_search(channel, user);
if (!new_typing) if (!new_typing)
{ {
new_typing = malloc(sizeof(*new_typing)); new_typing = (struct t_channel_typing*)malloc(sizeof(*new_typing));
new_typing->user = user; new_typing->user = user;
new_typing->name = user ? strdup(user->profile.display_name) : NULL; new_typing->name = user ? strdup(user->profile.display_name) : NULL;
@ -739,7 +739,7 @@ void channel__unread_free_all(struct t_channel *channel)
struct t_weelist_item *ptr_item = weechat_list_get(channel->unreads, i); struct t_weelist_item *ptr_item = weechat_list_get(channel->unreads, i);
if (ptr_item) if (ptr_item)
{ {
struct t_channel_unread *unread = weechat_list_user_data(ptr_item); struct t_channel_unread *unread = (struct t_channel_unread *)weechat_list_user_data(ptr_item);
channel__unread_free(unread); channel__unread_free(unread);
@ -896,7 +896,7 @@ struct t_channel_member *channel__add_member(struct t_account *account,
if (!(member = channel__member_search(channel, id))) if (!(member = channel__member_search(channel, id)))
{ {
member = malloc(sizeof(struct t_channel_member)); member = (struct t_channel_member*)malloc(sizeof(struct t_channel_member));
member->id = strdup(id); member->id = strdup(id);
member->role = NULL; member->role = NULL;
@ -1114,7 +1114,7 @@ int channel__send_message(struct t_account *account, struct t_channel *channel,
channel__set_transport(channel, CHANNEL_TRANSPORT_PLAIN, 0); channel__set_transport(channel, CHANNEL_TRANSPORT_PLAIN, 0);
} }
char *url = strstr(body, "http"); char *url = (char*)strstr(body, "http");
if (url && channel->transport == CHANNEL_TRANSPORT_PLAIN) if (url && channel->transport == CHANNEL_TRANSPORT_PLAIN)
{ {
xmpp_stanza_t *message__x = xmpp_stanza_new(account->context); xmpp_stanza_t *message__x = xmpp_stanza_new(account->context);
@ -1184,7 +1184,7 @@ void channel__send_reads(struct t_account *account, struct t_channel *channel)
if (ptr_item) if (ptr_item)
{ {
const char *unread_id = weechat_list_string(ptr_item); const char *unread_id = weechat_list_string(ptr_item);
struct t_channel_unread *unread = weechat_list_user_data(ptr_item); struct t_channel_unread *unread = (struct t_channel_unread*)weechat_list_user_data(ptr_item);
xmpp_stanza_t *message = xmpp_message_new(account->context, NULL, xmpp_stanza_t *message = xmpp_message_new(account->context, NULL,
channel->id, NULL); channel->id, NULL);

@ -2,8 +2,11 @@
// License, version 2.0. If a copy of the MPL was not distributed with this // 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/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
#ifndef _WEECHAT_XMPP_CHANNEL_H_ #pragma once
#define _WEECHAT_XMPP_CHANNEL_H_
#ifdef __cplusplus
#include <ctime>
#endif
#define CHANNEL_MEMBERS_SPEAKING_LIMIT 128 #define CHANNEL_MEMBERS_SPEAKING_LIMIT 128
@ -208,5 +211,3 @@ void channel__send_paused(struct t_account *account, struct t_channel *channel,
void channel__fetch_mam(struct t_account *account, struct t_channel *channel, void channel__fetch_mam(struct t_account *account, struct t_channel *channel,
const char *id, time_t *start, time_t *end, const char *after); const char *id, time_t *start, time_t *end, const char *after);
#endif /*WEECHAT_XMPP_CHANNEL_H*/

@ -11,9 +11,9 @@
#include <weechat/weechat-plugin.h> #include <weechat/weechat-plugin.h>
#include "plugin.hh" #include "plugin.hh"
#include "account.h" #include "account.hh"
#include "user.h" #include "user.hh"
#include "channel.h" #include "channel.hh"
#include "buffer.h" #include "buffer.h"
#include "message.h" #include "message.h"
#include "command.h" #include "command.h"

@ -11,9 +11,9 @@
#include "plugin.hh" #include "plugin.hh"
#include "config.hh" #include "config.hh"
#include "account.h" #include "account.hh"
#include "channel.h" #include "channel.hh"
#include "user.h" #include "user.hh"
#include "buffer.h" #include "buffer.h"
#include "completion.h" #include "completion.h"

@ -9,7 +9,7 @@
#include <weechat/weechat-plugin.h> #include <weechat/weechat-plugin.h>
#include "plugin.hh" #include "plugin.hh"
#include "account.h" #include "account.hh"
#include "config.hh" #include "config.hh"
struct t_config_file *config_file; struct t_config_file *config_file;

@ -14,9 +14,9 @@
#include "plugin.hh" #include "plugin.hh"
#include "xmpp/stanza.hh" #include "xmpp/stanza.hh"
#include "config.hh" #include "config.hh"
#include "account.h" #include "account.hh"
#include "user.h" #include "user.hh"
#include "channel.h" #include "channel.hh"
#include "connection.h" #include "connection.h"
#include "omemo.h" #include "omemo.h"
#include "pgp.h" #include "pgp.h"

@ -8,8 +8,8 @@
#include <weechat/weechat-plugin.h> #include <weechat/weechat-plugin.h>
#include "plugin.hh" #include "plugin.hh"
#include "account.h" #include "account.hh"
#include "channel.h" #include "channel.hh"
#include "buffer.h" #include "buffer.h"
#include "message.h" #include "message.h"
#include "input.h" #include "input.h"

@ -40,9 +40,9 @@ PREFIX ?= /usr/local
LIBDIR ?= $(PREFIX)/lib LIBDIR ?= $(PREFIX)/lib
HDRS=plugin.hh \ HDRS=plugin.hh \
account.h \ account.hh \
buffer.h \ buffer.h \
channel.h \ channel.hh \
command.h \ command.h \
completion.h \ completion.h \
config.hh \ config.hh \
@ -51,14 +51,14 @@ HDRS=plugin.hh \
message.h \ message.h \
omemo.h \ omemo.h \
pgp.h \ pgp.h \
user.h \ user.hh \
util.h \ util.h \
xmpp/stanza.hh \ xmpp/stanza.hh \
SRCS=plugin.cpp \ SRCS=plugin.cpp \
account.c \ account.cpp \
buffer.c \ buffer.c \
channel.c \ channel.cpp \
command.c \ command.c \
completion.c \ completion.c \
config.cpp \ config.cpp \
@ -67,7 +67,7 @@ SRCS=plugin.cpp \
message.c \ message.c \
omemo.c \ omemo.c \
pgp.c \ pgp.c \
user.c \ user.cpp \
util.c \ util.c \
xmpp/presence.cpp \ xmpp/presence.cpp \
xmpp/iq.cpp \ xmpp/iq.cpp \

@ -11,9 +11,9 @@
#include <weechat/weechat-plugin.h> #include <weechat/weechat-plugin.h>
#include "plugin.hh" #include "plugin.hh"
#include "account.h" #include "account.hh"
#include "channel.h" #include "channel.hh"
#include "user.h" #include "user.hh"
#include "message.h" #include "message.h"
static const char format_regex[] = "<([^>]*?)>"; static const char format_regex[] = "<([^>]*?)>";

@ -32,7 +32,7 @@ struct t_pre_key {
#include "plugin.hh" #include "plugin.hh"
#include "xmpp/stanza.hh" #include "xmpp/stanza.hh"
#include "account.h" #include "account.hh"
#include "omemo.h" #include "omemo.h"
#include "util.h" #include "util.h"

@ -12,7 +12,7 @@
#include "plugin.hh" #include "plugin.hh"
#include "config.hh" #include "config.hh"
extern "C" { extern "C" {
#include "account.h" #include "account.hh"
#include "connection.h" #include "connection.h"
#include "command.h" #include "command.h"
#include "input.h" #include "input.h"

Binary file not shown.

@ -10,9 +10,9 @@
#include <weechat/weechat-plugin.h> #include <weechat/weechat-plugin.h>
#include "plugin.hh" #include "plugin.hh"
#include "account.h" #include "account.hh"
#include "user.h" #include "user.hh"
#include "channel.h" #include "channel.hh"
const char *user__get_colour(struct t_user *user) const char *user__get_colour(struct t_user *user)
{ {
@ -166,7 +166,7 @@ struct t_user *user__new(struct t_account *account,
return ptr_user; return ptr_user;
} }
if ((new_user = malloc(sizeof(*new_user))) == NULL) if ((new_user = (struct t_user*)malloc(sizeof(*new_user))) == NULL)
{ {
return NULL; return NULL;
} }

@ -2,8 +2,7 @@
// License, version 2.0. If a copy of the MPL was not distributed with this // 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/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
#ifndef _WEECHAT_XMPP_USER_H_ #pragma once
#define _WEECHAT_XMPP_USER_H_
struct t_user_profile struct t_user_profile
{ {
@ -31,6 +30,7 @@ struct t_user
struct t_user *prev_user; struct t_user *prev_user;
struct t_user *next_user; struct t_user *next_user;
}; };
struct t_channel; struct t_channel;
const char *user__get_colour(struct t_user *user); const char *user__get_colour(struct t_user *user);
@ -57,5 +57,3 @@ void user__nicklist_add(struct t_account *account,
void user__nicklist_remove(struct t_account *account, void user__nicklist_remove(struct t_account *account,
struct t_channel *channel, struct t_channel *channel,
struct t_user *user); struct t_user *user);
#endif /*WEECHAT_XMPP_USER_H*/
Loading…
Cancel
Save