diff --git a/account.c b/account.cpp similarity index 96% rename from account.c rename to account.cpp index a34a550..a15e3be 100644 --- a/account.c +++ b/account.cpp @@ -16,10 +16,10 @@ #include "config.hh" #include "input.h" #include "omemo.h" -#include "account.h" +#include "account.hh" #include "connection.h" -#include "user.h" -#include "channel.h" +#include "user.hh" +#include "channel.hh" #include "buffer.h" 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); 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->name = strdup(device->name); 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}; 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; snprintf(id, sizeof(id), "%u", device->id); device->name = strdup(id); 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( 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))) { - 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->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; char *xml; - if ((level == XMPP_LEVEL_DEBUG) && ((xml = strchr(msg, '<')) != NULL)) + if ((level == XMPP_LEVEL_DEBUG) && ((xml = const_cast(strchr(msg, '<'))) != NULL)) { FILE *nullfd = fopen("/dev/null", "w+"); xmlGenericErrorContext = nullfd; @@ -350,7 +350,7 @@ void account__log_emit_weechat(void *const userdata, const xmpp_log_level_t leve { colour = weechat_color("red"); } - xmlChar *buf = malloc(strlen(xml) * 2); + xmlChar *buf = (xmlChar*)malloc(strlen(xml) * 2); if (buf == NULL) { weechat_printf( account ? account->buffer : NULL, @@ -407,7 +407,7 @@ struct t_account *account__alloc(const char *name) return NULL; /* alloc memory for new account */ - new_account = malloc(sizeof(*new_account)); + new_account = (struct t_account*)malloc(sizeof(*new_account)); if (!new_account) { weechat_printf(NULL, @@ -466,7 +466,7 @@ struct t_account *account__alloc(const char *name) strlen(account_options[i][0]) + 512 + /* inherited option name(xmpp.account_default.xxx) */ 1; - option_name = malloc(length); + option_name = (char*)malloc(length); if (option_name) { 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_display_groups", "0"); weechat_buffer_set_pointer(account->buffer, "nicklist_callback", - &buffer__nickcmp_cb); + (void*)&buffer__nickcmp_cb); weechat_buffer_set_pointer(account->buffer, "nicklist_callback_pointer", account); diff --git a/account.h b/account.hh similarity index 93% rename from account.h rename to account.hh index 321afd4..aa1a2e5 100644 --- a/account.h +++ b/account.hh @@ -2,8 +2,13 @@ // 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 _ACCOUNT_H_ -#define _ACCOUNT_H_ +#pragma once + +#ifdef __cplusplus +#include +#include +#include +#endif extern struct t_account *accounts; 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__casesearch (const char *account_name); int account__search_option(const char *option_name); -struct t_account_device *account__search_device(struct t_account *account, uint32_t id); -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); +struct t_account_device *account__search_device(struct t_account *account, + uint32_t id); +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); xmpp_stanza_t *account__get_devicelist(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); int account__connect(struct t_account *account); int account__timer_cb(const void *pointer, void *data, int remaining_calls); - -#endif /*ACCOUNT_H*/ diff --git a/buffer.c b/buffer.c index d9db4e3..3782ed8 100644 --- a/buffer.c +++ b/buffer.c @@ -8,8 +8,8 @@ #include #include "plugin.hh" -#include "account.h" -#include "channel.h" +#include "account.hh" +#include "channel.hh" #include "buffer.h" void buffer__get_account_and_channel(struct t_gui_buffer *buffer, diff --git a/channel.c b/channel.cpp similarity index 98% rename from channel.c rename to channel.cpp index 8a7ed86..5194157 100644 --- a/channel.c +++ b/channel.cpp @@ -11,10 +11,10 @@ #include #include "plugin.hh" -#include "account.h" +#include "account.hh" #include "omemo.h" -#include "user.h" -#include "channel.h" +#include "user.hh" +#include "channel.hh" #include "input.h" #include "buffer.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; 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) { @@ -140,7 +140,7 @@ struct t_gui_buffer *channel__search_buffer(struct t_account *account, 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; @@ -178,7 +178,7 @@ struct t_gui_buffer *channel__create_buffer(struct t_account *account, if (buffer_created) { - char *res = strrchr(name, '/'); + char *res = (char*)strrchr(name, '/'); if (!weechat_buffer_get_integer(ptr_buffer, "short_name_is_set")) weechat_buffer_set(ptr_buffer, "short_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_display_groups", "0"); weechat_buffer_set_pointer(ptr_buffer, "nicklist_callback", - &buffer__nickcmp_cb); + (void*)&buffer__nickcmp_cb); weechat_buffer_set_pointer(ptr_buffer, "nicklist_callback_pointer", account); } @@ -293,7 +293,7 @@ struct t_channel *channel__new(struct t_account *account, if (!ptr_buffer) return NULL; - if ((new_channel = malloc(sizeof(*new_channel))) == NULL) + if ((new_channel = (struct t_channel*)malloc(sizeof(*new_channel))) == NULL) return NULL; 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); 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->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); 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->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); 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); @@ -896,7 +896,7 @@ struct t_channel_member *channel__add_member(struct t_account *account, 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->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); } - char *url = strstr(body, "http"); + char *url = (char*)strstr(body, "http"); if (url && channel->transport == CHANNEL_TRANSPORT_PLAIN) { 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) { 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, channel->id, NULL); diff --git a/channel.h b/channel.hh similarity index 98% rename from channel.h rename to channel.hh index 5643679..da5b556 100644 --- a/channel.h +++ b/channel.hh @@ -2,8 +2,11 @@ // 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_CHANNEL_H_ -#define _WEECHAT_XMPP_CHANNEL_H_ +#pragma once + +#ifdef __cplusplus +#include +#endif #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, const char *id, time_t *start, time_t *end, const char *after); - -#endif /*WEECHAT_XMPP_CHANNEL_H*/ diff --git a/command.c b/command.c index 147239c..6a3ef96 100644 --- a/command.c +++ b/command.c @@ -11,9 +11,9 @@ #include #include "plugin.hh" -#include "account.h" -#include "user.h" -#include "channel.h" +#include "account.hh" +#include "user.hh" +#include "channel.hh" #include "buffer.h" #include "message.h" #include "command.h" diff --git a/completion.c b/completion.c index 3bf9da7..b386e0d 100644 --- a/completion.c +++ b/completion.c @@ -11,9 +11,9 @@ #include "plugin.hh" #include "config.hh" -#include "account.h" -#include "channel.h" -#include "user.h" +#include "account.hh" +#include "channel.hh" +#include "user.hh" #include "buffer.h" #include "completion.h" diff --git a/config.cpp b/config.cpp index 4c538f2..3944b3d 100644 --- a/config.cpp +++ b/config.cpp @@ -9,7 +9,7 @@ #include #include "plugin.hh" -#include "account.h" +#include "account.hh" #include "config.hh" struct t_config_file *config_file; diff --git a/connection.c b/connection.c index 643fac7..37be767 100644 --- a/connection.c +++ b/connection.c @@ -14,9 +14,9 @@ #include "plugin.hh" #include "xmpp/stanza.hh" #include "config.hh" -#include "account.h" -#include "user.h" -#include "channel.h" +#include "account.hh" +#include "user.hh" +#include "channel.hh" #include "connection.h" #include "omemo.h" #include "pgp.h" diff --git a/input.c b/input.c index 816ec84..215dad9 100644 --- a/input.c +++ b/input.c @@ -8,8 +8,8 @@ #include #include "plugin.hh" -#include "account.h" -#include "channel.h" +#include "account.hh" +#include "channel.hh" #include "buffer.h" #include "message.h" #include "input.h" diff --git a/makefile b/makefile index b601f45..f43f75a 100644 --- a/makefile +++ b/makefile @@ -40,9 +40,9 @@ PREFIX ?= /usr/local LIBDIR ?= $(PREFIX)/lib HDRS=plugin.hh \ - account.h \ + account.hh \ buffer.h \ - channel.h \ + channel.hh \ command.h \ completion.h \ config.hh \ @@ -51,14 +51,14 @@ HDRS=plugin.hh \ message.h \ omemo.h \ pgp.h \ - user.h \ + user.hh \ util.h \ xmpp/stanza.hh \ SRCS=plugin.cpp \ - account.c \ + account.cpp \ buffer.c \ - channel.c \ + channel.cpp \ command.c \ completion.c \ config.cpp \ @@ -67,7 +67,7 @@ SRCS=plugin.cpp \ message.c \ omemo.c \ pgp.c \ - user.c \ + user.cpp \ util.c \ xmpp/presence.cpp \ xmpp/iq.cpp \ diff --git a/message.c b/message.c index 2d9c2ce..49deb8a 100644 --- a/message.c +++ b/message.c @@ -11,9 +11,9 @@ #include #include "plugin.hh" -#include "account.h" -#include "channel.h" -#include "user.h" +#include "account.hh" +#include "channel.hh" +#include "user.hh" #include "message.h" static const char format_regex[] = "<([^>]*?)>"; diff --git a/omemo.c b/omemo.c index 4709412..d38040c 100644 --- a/omemo.c +++ b/omemo.c @@ -32,7 +32,7 @@ struct t_pre_key { #include "plugin.hh" #include "xmpp/stanza.hh" -#include "account.h" +#include "account.hh" #include "omemo.h" #include "util.h" diff --git a/plugin.cpp b/plugin.cpp index 6490a85..7f3be51 100644 --- a/plugin.cpp +++ b/plugin.cpp @@ -12,7 +12,7 @@ #include "plugin.hh" #include "config.hh" extern "C" { -#include "account.h" +#include "account.hh" #include "connection.h" #include "command.h" #include "input.h" diff --git a/tests/run b/tests/run index f158e82..21b73ce 100755 Binary files a/tests/run and b/tests/run differ diff --git a/user.c b/user.cpp similarity index 98% rename from user.c rename to user.cpp index 78fe334..4cf5c7b 100644 --- a/user.c +++ b/user.cpp @@ -10,9 +10,9 @@ #include #include "plugin.hh" -#include "account.h" -#include "user.h" -#include "channel.h" +#include "account.hh" +#include "user.hh" +#include "channel.hh" 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; } - if ((new_user = malloc(sizeof(*new_user))) == NULL) + if ((new_user = (struct t_user*)malloc(sizeof(*new_user))) == NULL) { return NULL; } diff --git a/user.h b/user.hh similarity index 94% rename from user.h rename to user.hh index ccc9537..02afaee 100644 --- a/user.h +++ b/user.hh @@ -2,8 +2,7 @@ // 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_USER_H_ -#define _WEECHAT_XMPP_USER_H_ +#pragma once struct t_user_profile { @@ -31,6 +30,7 @@ struct t_user struct t_user *prev_user; struct t_user *next_user; }; + struct t_channel; 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, struct t_channel *channel, struct t_user *user); - -#endif /*WEECHAT_XMPP_USER_H*/