mirror of
https://github.com/profanity-im/profanity.git
synced 2025-01-03 14:57:42 -05:00
Merge remote-tracking branch 'dmitry/nextdev-patches' into nextdev
This commit is contained in:
commit
3588a9d776
@ -266,15 +266,11 @@ static void
|
||||
_chat_session_free(ChatSession session)
|
||||
{
|
||||
if (session != NULL) {
|
||||
if (session->recipient != NULL) {
|
||||
g_free(session->recipient);
|
||||
session->recipient = NULL;
|
||||
}
|
||||
free(session->recipient);
|
||||
if (session->active_timer != NULL) {
|
||||
g_timer_destroy(session->active_timer);
|
||||
session->active_timer = NULL;
|
||||
}
|
||||
g_free(session);
|
||||
free(session);
|
||||
}
|
||||
session = NULL;
|
||||
}
|
||||
|
@ -1041,7 +1041,7 @@ cmd_autocomplete(char *input, int *size)
|
||||
inp_cpy[i] = '\0';
|
||||
found = autocomplete_complete(commands_ac, inp_cpy);
|
||||
if (found != NULL) {
|
||||
auto_msg = (char *) malloc((strlen(found) + 1) * sizeof(char));
|
||||
auto_msg = (char *) malloc(strlen(found) + 1);
|
||||
strcpy(auto_msg, found);
|
||||
inp_replace_input(input, auto_msg, size);
|
||||
free(auto_msg);
|
||||
|
32
src/common.c
32
src/common.c
@ -25,12 +25,14 @@
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <curl/curl.h>
|
||||
#include <curl/easy.h>
|
||||
#include <glib.h>
|
||||
|
||||
#include "log.h"
|
||||
#include "common.h"
|
||||
|
||||
// assume malloc stores at most 8 bytes for size of allocated memory
|
||||
@ -69,29 +71,43 @@ p_slist_free_full(GSList *items, GDestroyNotify free_func)
|
||||
g_slist_free (items);
|
||||
}
|
||||
|
||||
void
|
||||
gboolean
|
||||
create_dir(char *name)
|
||||
{
|
||||
int e;
|
||||
struct stat sb;
|
||||
|
||||
e = stat(name, &sb);
|
||||
if (e != 0)
|
||||
if (errno == ENOENT)
|
||||
e = mkdir(name, S_IRWXU);
|
||||
if (stat(name, &sb) != 0) {
|
||||
if (errno != ENOENT || mkdir(name, S_IRWXU) != 0) {
|
||||
return FALSE;
|
||||
}
|
||||
} else {
|
||||
if ((sb.st_mode & S_IFDIR) != S_IFDIR) {
|
||||
log_debug("create_dir: %s exists and is not a directory!", name);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
gboolean
|
||||
mkdir_recursive(const char *dir)
|
||||
{
|
||||
int i;
|
||||
gboolean result = TRUE;
|
||||
|
||||
for (i = 1; i <= strlen(dir); i++) {
|
||||
if (dir[i] == '/' || dir[i] == '\0') {
|
||||
gchar *next_dir = g_strndup(dir, i);
|
||||
create_dir(next_dir);
|
||||
result = create_dir(next_dir);
|
||||
g_free(next_dir);
|
||||
if (!result) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
char *
|
||||
|
@ -72,8 +72,8 @@ typedef enum {
|
||||
|
||||
gchar* p_utf8_substring(const gchar *str, glong start_pos, glong end_pos);
|
||||
void p_slist_free_full(GSList *items, GDestroyNotify free_func);
|
||||
void create_dir(char *name);
|
||||
void mkdir_recursive(const char *dir);
|
||||
gboolean create_dir(char *name);
|
||||
gboolean mkdir_recursive(const char *dir);
|
||||
char * str_replace(const char *string, const char *substr,
|
||||
const char *replacement);
|
||||
int str_contains(char str[], int size, char ch);
|
||||
|
@ -236,13 +236,13 @@ void
|
||||
accounts_free_account(ProfAccount *account)
|
||||
{
|
||||
if (account != NULL) {
|
||||
FREE_SET_NULL(account->name);
|
||||
FREE_SET_NULL(account->jid);
|
||||
FREE_SET_NULL(account->resource);
|
||||
FREE_SET_NULL(account->server);
|
||||
FREE_SET_NULL(account->last_presence);
|
||||
FREE_SET_NULL(account->login_presence);
|
||||
FREE_SET_NULL(account);
|
||||
free(account->name);
|
||||
free(account->jid);
|
||||
free(account->resource);
|
||||
free(account->server);
|
||||
free(account->last_presence);
|
||||
free(account->login_presence);
|
||||
free(account);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -79,14 +79,9 @@ p_contact_new(const char * const barejid, const char * const name,
|
||||
void
|
||||
p_contact_set_name(const PContact contact, const char * const name)
|
||||
{
|
||||
if (contact->name != NULL) {
|
||||
FREE_SET_NULL(contact->name);
|
||||
}
|
||||
|
||||
FREE_SET_NULL(contact->name);
|
||||
if (name != NULL) {
|
||||
contact->name = strdup(name);
|
||||
} else {
|
||||
FREE_SET_NULL(contact->name);
|
||||
}
|
||||
}
|
||||
|
||||
@ -130,22 +125,23 @@ p_contact_remove_resource(PContact contact, const char * const resource)
|
||||
void
|
||||
p_contact_free(PContact contact)
|
||||
{
|
||||
FREE_SET_NULL(contact->barejid);
|
||||
FREE_SET_NULL(contact->name);
|
||||
FREE_SET_NULL(contact->subscription);
|
||||
FREE_SET_NULL(contact->offline_message);
|
||||
if (contact != NULL) {
|
||||
free(contact->barejid);
|
||||
free(contact->name);
|
||||
free(contact->subscription);
|
||||
free(contact->offline_message);
|
||||
|
||||
if (contact->groups != NULL) {
|
||||
g_slist_free_full(contact->groups, g_free);
|
||||
if (contact->groups != NULL) {
|
||||
g_slist_free_full(contact->groups, g_free);
|
||||
}
|
||||
|
||||
if (contact->last_activity != NULL) {
|
||||
g_date_time_unref(contact->last_activity);
|
||||
}
|
||||
|
||||
g_hash_table_destroy(contact->available_resources);
|
||||
free(contact);
|
||||
}
|
||||
|
||||
if (contact->last_activity != NULL) {
|
||||
g_date_time_unref(contact->last_activity);
|
||||
}
|
||||
|
||||
g_hash_table_destroy(contact->available_resources);
|
||||
|
||||
FREE_SET_NULL(contact);
|
||||
}
|
||||
|
||||
const char *
|
||||
|
14
src/jid.c
14
src/jid.c
@ -108,13 +108,13 @@ void
|
||||
jid_destroy(Jid *jid)
|
||||
{
|
||||
if (jid != NULL) {
|
||||
GFREE_SET_NULL(jid->str);
|
||||
GFREE_SET_NULL(jid->localpart);
|
||||
GFREE_SET_NULL(jid->domainpart);
|
||||
GFREE_SET_NULL(jid->resourcepart);
|
||||
GFREE_SET_NULL(jid->barejid);
|
||||
GFREE_SET_NULL(jid->fulljid);
|
||||
FREE_SET_NULL(jid);
|
||||
g_free(jid->str);
|
||||
g_free(jid->localpart);
|
||||
g_free(jid->domainpart);
|
||||
g_free(jid->resourcepart);
|
||||
g_free(jid->barejid);
|
||||
g_free(jid->fulljid);
|
||||
free(jid);
|
||||
}
|
||||
}
|
||||
|
||||
|
27
src/log.c
27
src/log.c
@ -25,8 +25,6 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "glib.h"
|
||||
|
||||
@ -37,11 +35,6 @@
|
||||
|
||||
#define PROF "prof"
|
||||
|
||||
#ifdef _WIN32
|
||||
// replace 'struct stat' and 'stat()' for windows
|
||||
#define stat _stat
|
||||
#endif
|
||||
|
||||
static FILE *logp;
|
||||
|
||||
static GTimeZone *tz;
|
||||
@ -125,7 +118,7 @@ log_init(log_level_t filter)
|
||||
tz = g_time_zone_new_local();
|
||||
gchar *log_file = _get_log_file();
|
||||
logp = fopen(log_file, "a");
|
||||
g_free(log_file);
|
||||
free(log_file);
|
||||
}
|
||||
|
||||
log_level_t
|
||||
@ -145,9 +138,7 @@ void
|
||||
log_msg(log_level_t level, const char * const area, const char * const msg)
|
||||
{
|
||||
if (level >= level_filter) {
|
||||
struct stat st;
|
||||
int result;
|
||||
gchar *log_file = _get_log_file();
|
||||
long result;
|
||||
dt = g_date_time_new_now(tz);
|
||||
|
||||
gchar *date_fmt = g_date_time_format(dt, "%d/%m/%Y %H:%M:%S");
|
||||
@ -157,12 +148,10 @@ log_msg(log_level_t level, const char * const area, const char * const msg)
|
||||
fflush(logp);
|
||||
g_free(date_fmt);
|
||||
|
||||
result = stat(log_file, &st);
|
||||
if (result == 0 && st.st_size >= prefs_get_max_log_size()) {
|
||||
result = ftell(logp);
|
||||
if (result != -1 && result >= prefs_get_max_log_size()) {
|
||||
_rotate_log_file();
|
||||
}
|
||||
|
||||
g_free(log_file);
|
||||
}
|
||||
}
|
||||
|
||||
@ -200,7 +189,7 @@ _rotate_log_file(void)
|
||||
log_init(log_get_filter());
|
||||
|
||||
free(log_file_new);
|
||||
g_free(log_file);
|
||||
free(log_file);
|
||||
log_info("Log has been rotated");
|
||||
}
|
||||
|
||||
@ -448,7 +437,7 @@ _get_log_filename(const char * const other, const char * const login,
|
||||
{
|
||||
gchar *chatlogs_dir = _get_chatlog_dir();
|
||||
GString *log_file = g_string_new(chatlogs_dir);
|
||||
g_free(chatlogs_dir);
|
||||
free(chatlogs_dir);
|
||||
|
||||
gchar *login_dir = str_replace(login, "@", "_at_");
|
||||
g_string_append_printf(log_file, "/%s", login_dir);
|
||||
@ -516,7 +505,7 @@ _get_chatlog_dir(void)
|
||||
GString *chatlogs_dir = g_string_new(xdg_data);
|
||||
g_string_append(chatlogs_dir, "/profanity/chatlogs");
|
||||
gchar *result = strdup(chatlogs_dir->str);
|
||||
g_free(xdg_data);
|
||||
free(xdg_data);
|
||||
g_string_free(chatlogs_dir, TRUE);
|
||||
|
||||
return result;
|
||||
@ -529,7 +518,7 @@ _get_log_file(void)
|
||||
GString *logfile = g_string_new(xdg_data);
|
||||
g_string_append(logfile, "/profanity/logs/profanity.log");
|
||||
gchar *result = strdup(logfile->str);
|
||||
g_free(xdg_data);
|
||||
free(xdg_data);
|
||||
g_string_free(logfile, TRUE);
|
||||
|
||||
return result;
|
||||
|
20
src/muc.c
20
src/muc.c
@ -442,32 +442,20 @@ static void
|
||||
_free_room(ChatRoom *room)
|
||||
{
|
||||
if (room != NULL) {
|
||||
if (room->room != NULL) {
|
||||
g_free(room->room);
|
||||
room->room = NULL;
|
||||
}
|
||||
if (room->nick != NULL) {
|
||||
g_free(room->nick);
|
||||
room->nick = NULL;
|
||||
}
|
||||
if (room->subject != NULL) {
|
||||
g_free(room->subject);
|
||||
room->subject = NULL;
|
||||
}
|
||||
free(room->room);
|
||||
free(room->nick);
|
||||
free(room->subject);
|
||||
if (room->roster != NULL) {
|
||||
g_hash_table_remove_all(room->roster);
|
||||
room->roster = NULL;
|
||||
}
|
||||
if (room->nick_ac != NULL) {
|
||||
autocomplete_free(room->nick_ac);
|
||||
}
|
||||
if (room->nick_changes != NULL) {
|
||||
g_hash_table_remove_all(room->nick_changes);
|
||||
room->nick_changes = NULL;
|
||||
}
|
||||
g_free(room);
|
||||
free(room);
|
||||
}
|
||||
room = NULL;
|
||||
}
|
||||
|
||||
static
|
||||
|
@ -664,9 +664,15 @@ _create_directories(void)
|
||||
GString *logs_dir = g_string_new(xdg_data);
|
||||
g_string_append(logs_dir, "/profanity/logs");
|
||||
|
||||
mkdir_recursive(themes_dir->str);
|
||||
mkdir_recursive(chatlogs_dir->str);
|
||||
mkdir_recursive(logs_dir->str);
|
||||
if (!mkdir_recursive(themes_dir->str)) {
|
||||
log_error("Error while creating directory %s", themes_dir->str);
|
||||
}
|
||||
if (!mkdir_recursive(chatlogs_dir->str)) {
|
||||
log_error("Error while creating directory %s", chatlogs_dir->str);
|
||||
}
|
||||
if (!mkdir_recursive(logs_dir->str)) {
|
||||
log_error("Error while creating directory %s", logs_dir->str);
|
||||
}
|
||||
|
||||
g_string_free(themes_dir, TRUE);
|
||||
g_string_free(chatlogs_dir, TRUE);
|
||||
|
@ -81,9 +81,10 @@ resource_compare_availability(Resource *first, Resource *second)
|
||||
|
||||
void resource_destroy(Resource *resource)
|
||||
{
|
||||
assert(resource != NULL);
|
||||
FREE_SET_NULL(resource->name);
|
||||
FREE_SET_NULL(resource->status);
|
||||
FREE_SET_NULL(resource->caps_str);
|
||||
FREE_SET_NULL(resource);
|
||||
if (resource != NULL) {
|
||||
free(resource->name);
|
||||
free(resource->status);
|
||||
free(resource->caps_str);
|
||||
free(resource);
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "common.h"
|
||||
#include "tools/autocomplete.h"
|
||||
#include "tools/parser.h"
|
||||
|
||||
@ -59,10 +60,7 @@ void
|
||||
autocomplete_reset(Autocomplete ac)
|
||||
{
|
||||
ac->last_found = NULL;
|
||||
if (ac->search_str != NULL) {
|
||||
free(ac->search_str);
|
||||
ac->search_str = NULL;
|
||||
}
|
||||
FREE_SET_NULL(ac->search_str);
|
||||
}
|
||||
|
||||
void
|
||||
@ -220,7 +218,7 @@ autocomplete_param_with_func(char *input, int *size, char *command,
|
||||
inp_cpy[(*size) - len] = '\0';
|
||||
found = func(inp_cpy);
|
||||
if (found != NULL) {
|
||||
auto_msg = (char *) malloc((len + (strlen(found) + 1)) * sizeof(char));
|
||||
auto_msg = (char *) malloc(len + strlen(found) + 1);
|
||||
strcpy(auto_msg, command_cpy);
|
||||
strcat(auto_msg, found);
|
||||
free(found);
|
||||
@ -249,7 +247,7 @@ autocomplete_param_with_ac(char *input, int *size, char *command,
|
||||
inp_cpy[(*size) - len] = '\0';
|
||||
found = autocomplete_complete(ac, inp_cpy);
|
||||
if (found != NULL) {
|
||||
auto_msg = (char *) malloc((len + (strlen(found) + 1)) * sizeof(char));
|
||||
auto_msg = (char *) malloc(len + strlen(found) + 1);
|
||||
strcpy(auto_msg, command_cpy);
|
||||
strcat(auto_msg, found);
|
||||
free(found);
|
||||
|
@ -784,7 +784,7 @@ cons_show_room_invite(const char * const invitor, const char * const room,
|
||||
notify_invite(display_from, room, reason);
|
||||
}
|
||||
|
||||
FREE_SET_NULL(display_from);
|
||||
free(display_from);
|
||||
|
||||
ui_console_dirty();
|
||||
cons_alert();
|
||||
|
@ -293,8 +293,9 @@ ui_incoming_msg(const char * const from, const char * const message,
|
||||
GTimeVal *tv_stamp, gboolean priv)
|
||||
{
|
||||
gboolean win_created = FALSE;
|
||||
char *display_from;
|
||||
char *display_from = NULL;
|
||||
win_type_t win_type;
|
||||
|
||||
if (priv) {
|
||||
win_type = WIN_PRIVATE;
|
||||
display_from = get_nick_from_full_jid(from);
|
||||
@ -438,7 +439,7 @@ ui_incoming_msg(const char * const from, const char * const message,
|
||||
if (prefs_get_boolean(PREF_NOTIFY_MESSAGE))
|
||||
notify_message(display_from, ui_index);
|
||||
|
||||
FREE_SET_NULL(display_from);
|
||||
free(display_from);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -80,7 +80,7 @@ notify_invite(const char * const from, const char * const room,
|
||||
|
||||
_notify(message->str, 10000, "Incoming message");
|
||||
|
||||
g_string_free(message, FALSE);
|
||||
g_string_free(message, TRUE);
|
||||
}
|
||||
|
||||
void
|
||||
@ -102,7 +102,7 @@ notify_room_message(const char * const handle, const char * const room, int win)
|
||||
|
||||
_notify(text->str, 10000, "incoming message");
|
||||
|
||||
g_string_free(text, FALSE);
|
||||
g_string_free(text, TRUE);
|
||||
}
|
||||
|
||||
void
|
||||
@ -111,7 +111,7 @@ notify_subscription(const char * const from)
|
||||
GString *message = g_string_new("Subscription request: \n");
|
||||
g_string_append(message, from);
|
||||
_notify(message->str, 10000, "Incomming message");
|
||||
g_string_free(message, FALSE);
|
||||
g_string_free(message, TRUE);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -191,7 +191,7 @@ status_bar_print_message(const char * const msg)
|
||||
|
||||
werase(status_bar);
|
||||
|
||||
message = (char *) malloc((strlen(msg) + 1) * sizeof(char));
|
||||
message = (char *) malloc(strlen(msg) + 1);
|
||||
strcpy(message, msg);
|
||||
mvwprintw(status_bar, 0, 10, message);
|
||||
|
||||
|
@ -87,7 +87,7 @@ title_bar_refresh(void)
|
||||
free(current_title);
|
||||
}
|
||||
|
||||
current_title = (char *) malloc((strlen(recipient) + 1) * sizeof(char));
|
||||
current_title = (char *) malloc(strlen(recipient) + 1);
|
||||
strcpy(current_title, recipient);
|
||||
|
||||
title_bar_draw();
|
||||
@ -113,7 +113,7 @@ title_bar_show(const char * const title)
|
||||
if (current_title != NULL)
|
||||
free(current_title);
|
||||
|
||||
current_title = (char *) malloc((strlen(title) + 1) * sizeof(char));
|
||||
current_title = (char *) malloc(strlen(title) + 1);
|
||||
strcpy(current_title, title);
|
||||
_title_bar_draw_title();
|
||||
}
|
||||
@ -138,7 +138,7 @@ title_bar_set_recipient(const char * const from)
|
||||
free(current_title);
|
||||
}
|
||||
|
||||
current_title = (char *) malloc((strlen(from) + 1) * sizeof(char));
|
||||
current_title = (char *) malloc(strlen(from) + 1);
|
||||
strcpy(current_title, from);
|
||||
|
||||
dirty = TRUE;
|
||||
@ -160,10 +160,10 @@ title_bar_set_typing(gboolean is_typing)
|
||||
}
|
||||
|
||||
if (is_typing) {
|
||||
current_title = (char *) malloc((strlen(recipient) + 13) * sizeof(char));
|
||||
current_title = (char *) malloc(strlen(recipient) + 13);
|
||||
sprintf(current_title, "%s (typing...)", recipient);
|
||||
} else {
|
||||
current_title = (char *) malloc((strlen(recipient) + 1) * sizeof(char));
|
||||
current_title = (char *) malloc(strlen(recipient) + 1);
|
||||
strcpy(current_title, recipient);
|
||||
}
|
||||
|
||||
|
@ -122,7 +122,7 @@ caps_create_sha1_str(xmpp_stanza_t * const query)
|
||||
GSList *form_names = NULL;
|
||||
DataForm *form = NULL;
|
||||
FormField *field = NULL;
|
||||
GHashTable *forms = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)stanza_destroy_form);
|
||||
GHashTable *forms = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify)stanza_destroy_form);
|
||||
|
||||
GString *s = g_string_new("");
|
||||
|
||||
@ -134,18 +134,18 @@ caps_create_sha1_str(xmpp_stanza_t * const query)
|
||||
lang = xmpp_stanza_get_attribute(child, "xml:lang");
|
||||
name = xmpp_stanza_get_attribute(child, "name");
|
||||
|
||||
GString *identity_str = g_string_new(g_strdup(category));
|
||||
GString *identity_str = g_string_new(category);
|
||||
g_string_append(identity_str, "/");
|
||||
if (type != NULL) {
|
||||
g_string_append(identity_str, g_strdup(type));
|
||||
g_string_append(identity_str, type);
|
||||
}
|
||||
g_string_append(identity_str, "/");
|
||||
if (lang != NULL) {
|
||||
g_string_append(identity_str, g_strdup(lang));
|
||||
g_string_append(identity_str, lang);
|
||||
}
|
||||
g_string_append(identity_str, "/");
|
||||
if (name != NULL) {
|
||||
g_string_append(identity_str, g_strdup(name));
|
||||
g_string_append(identity_str, name);
|
||||
}
|
||||
g_string_append(identity_str, "<");
|
||||
identities = g_slist_insert_sorted(identities, g_strdup(identity_str->str), (GCompareFunc)octet_compare);
|
||||
@ -156,8 +156,8 @@ caps_create_sha1_str(xmpp_stanza_t * const query)
|
||||
} else if (g_strcmp0(xmpp_stanza_get_name(child), STANZA_NAME_X) == 0) {
|
||||
if (strcmp(xmpp_stanza_get_ns(child), STANZA_NS_DATA) == 0) {
|
||||
form = stanza_create_form(child);
|
||||
form_names = g_slist_insert_sorted(form_names, strdup(form->form_type), (GCompareFunc)octet_compare);
|
||||
g_hash_table_insert(forms, strdup(form->form_type), form);
|
||||
form_names = g_slist_insert_sorted(form_names, g_strdup(form->form_type), (GCompareFunc)octet_compare);
|
||||
g_hash_table_insert(forms, g_strdup(form->form_type), form);
|
||||
}
|
||||
}
|
||||
child = xmpp_stanza_get_next(child);
|
||||
@ -165,13 +165,13 @@ caps_create_sha1_str(xmpp_stanza_t * const query)
|
||||
|
||||
GSList *curr = identities;
|
||||
while (curr != NULL) {
|
||||
g_string_append(s, strdup(curr->data));
|
||||
g_string_append(s, curr->data);
|
||||
curr = g_slist_next(curr);
|
||||
}
|
||||
|
||||
curr = features;
|
||||
while (curr != NULL) {
|
||||
g_string_append(s, strdup(curr->data));
|
||||
g_string_append(s, curr->data);
|
||||
g_string_append(s, "<");
|
||||
curr = g_slist_next(curr);
|
||||
}
|
||||
@ -179,17 +179,17 @@ caps_create_sha1_str(xmpp_stanza_t * const query)
|
||||
curr = form_names;
|
||||
while (curr != NULL) {
|
||||
form = g_hash_table_lookup(forms, curr->data);
|
||||
g_string_append(s, strdup(form->form_type));
|
||||
g_string_append(s, form->form_type);
|
||||
g_string_append(s, "<");
|
||||
|
||||
GSList *curr_field = form->fields;
|
||||
while (curr_field != NULL) {
|
||||
field = curr_field->data;
|
||||
g_string_append(s, strdup(field->var));
|
||||
g_string_append(s, field->var);
|
||||
g_string_append(s, "<");
|
||||
GSList *curr_value = field->values;
|
||||
while (curr_value != NULL) {
|
||||
g_string_append(s, strdup(curr_value->data));
|
||||
g_string_append(s, curr_value->data);
|
||||
g_string_append(s, "<");
|
||||
curr_value = g_slist_next(curr_value);
|
||||
}
|
||||
@ -215,10 +215,10 @@ caps_create_sha1_str(xmpp_stanza_t * const query)
|
||||
char *result = g_base64_encode(md_value, md_len);
|
||||
|
||||
g_string_free(s, TRUE);
|
||||
g_slist_free_full(identities, free);
|
||||
g_slist_free_full(features, free);
|
||||
g_slist_free_full(form_names, free);
|
||||
//g_hash_table_destroy(forms);
|
||||
g_slist_free_full(identities, g_free);
|
||||
g_slist_free_full(features, g_free);
|
||||
g_slist_free_full(form_names, g_free);
|
||||
g_hash_table_destroy(forms);
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -301,17 +301,16 @@ static void
|
||||
_caps_destroy(Capabilities *caps)
|
||||
{
|
||||
if (caps != NULL) {
|
||||
FREE_SET_NULL(caps->category);
|
||||
FREE_SET_NULL(caps->type);
|
||||
FREE_SET_NULL(caps->name);
|
||||
FREE_SET_NULL(caps->software);
|
||||
FREE_SET_NULL(caps->software_version);
|
||||
FREE_SET_NULL(caps->os);
|
||||
FREE_SET_NULL(caps->os_version);
|
||||
free(caps->category);
|
||||
free(caps->type);
|
||||
free(caps->name);
|
||||
free(caps->software);
|
||||
free(caps->software_version);
|
||||
free(caps->os);
|
||||
free(caps->os_version);
|
||||
if (caps->features != NULL) {
|
||||
g_slist_free_full(caps->features, free);
|
||||
caps->features = NULL;
|
||||
}
|
||||
FREE_SET_NULL(caps);
|
||||
free(caps);
|
||||
}
|
||||
}
|
||||
|
@ -312,10 +312,10 @@ static void
|
||||
_identity_destroy(DiscoIdentity *identity)
|
||||
{
|
||||
if (identity != NULL) {
|
||||
FREE_SET_NULL(identity->name);
|
||||
FREE_SET_NULL(identity->type);
|
||||
FREE_SET_NULL(identity->category);
|
||||
FREE_SET_NULL(identity);
|
||||
free(identity->name);
|
||||
free(identity->type);
|
||||
free(identity->category);
|
||||
free(identity);
|
||||
}
|
||||
}
|
||||
|
||||
@ -323,9 +323,9 @@ static void
|
||||
_item_destroy(DiscoItem *item)
|
||||
{
|
||||
if (item != NULL) {
|
||||
FREE_SET_NULL(item->jid);
|
||||
FREE_SET_NULL(item->name);
|
||||
FREE_SET_NULL(item);
|
||||
free(item->jid);
|
||||
free(item->name);
|
||||
free(item);
|
||||
}
|
||||
}
|
||||
|
||||
@ -411,12 +411,13 @@ _iq_handle_discoinfo_result(xmpp_conn_t * const conn, xmpp_stanza_t * const stan
|
||||
log_info("Generated sha-1 does not match given:");
|
||||
log_info("Generated : %s", generated_sha1);
|
||||
log_info("Given : %s", given_sha1);
|
||||
FREE_SET_NULL(generated_sha1);
|
||||
g_free(generated_sha1);
|
||||
g_strfreev(split);
|
||||
free(caps_key);
|
||||
|
||||
return 1;
|
||||
}
|
||||
FREE_SET_NULL(generated_sha1);
|
||||
g_free(generated_sha1);
|
||||
g_strfreev(split);
|
||||
|
||||
// non supported hash, or legacy caps
|
||||
@ -429,6 +430,7 @@ _iq_handle_discoinfo_result(xmpp_conn_t * const conn, xmpp_stanza_t * const stan
|
||||
// already cached
|
||||
if (caps_contains(caps_key)) {
|
||||
log_info("Client info already cached.");
|
||||
free(caps_key);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -212,6 +212,9 @@ _conference_message_handler(xmpp_conn_t * const conn,
|
||||
}
|
||||
|
||||
Jid *jidp = jid_create(invitor_jid);
|
||||
if (jidp == NULL) {
|
||||
return 1;
|
||||
}
|
||||
invitor = jidp->barejid;
|
||||
|
||||
xmpp_stanza_t *reason_st = xmpp_stanza_get_child_by_name(invite, STANZA_NAME_REASON);
|
||||
@ -233,6 +236,9 @@ _conference_message_handler(xmpp_conn_t * const conn,
|
||||
}
|
||||
|
||||
Jid *jidp = jid_create(from);
|
||||
if (jidp == NULL) {
|
||||
return 1;
|
||||
}
|
||||
invitor = jidp->barejid;
|
||||
|
||||
reason = xmpp_stanza_get_attribute(x_groupchat, STANZA_ATTR_REASON);
|
||||
|
@ -156,14 +156,23 @@ presence_sub_request_find(char * search_str)
|
||||
gboolean
|
||||
presence_sub_request_exists(const char * const bare_jid)
|
||||
{
|
||||
GSList *requests = autocomplete_get_list(sub_requests_ac);
|
||||
gboolean result = FALSE;
|
||||
GSList *requests_p = autocomplete_get_list(sub_requests_ac);
|
||||
GSList *requests = requests_p;
|
||||
|
||||
while (requests != NULL) {
|
||||
if (strcmp(requests->data, bare_jid) == 0) {
|
||||
return TRUE;
|
||||
result = TRUE;
|
||||
break;
|
||||
}
|
||||
requests = g_slist_next(requests);
|
||||
}
|
||||
return FALSE;
|
||||
|
||||
if (requests_p != NULL) {
|
||||
g_slist_free_full(requests_p, free);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void
|
||||
@ -220,20 +229,28 @@ presence_update(const resource_presence_t presence_type, const char * const msg,
|
||||
static void
|
||||
_send_room_presence(xmpp_conn_t *conn, xmpp_stanza_t *presence)
|
||||
{
|
||||
GList *rooms = muc_get_active_room_list();
|
||||
GList *rooms_p = muc_get_active_room_list();
|
||||
GList *rooms = rooms_p;
|
||||
|
||||
while (rooms != NULL) {
|
||||
const char *room = rooms->data;
|
||||
const char *nick = muc_get_room_nick(room);
|
||||
char *full_room_jid = create_fulljid(room, nick);
|
||||
|
||||
xmpp_stanza_set_attribute(presence, STANZA_ATTR_TO, full_room_jid);
|
||||
log_debug("Sending presence to room: %s", full_room_jid);
|
||||
xmpp_send(conn, presence);
|
||||
free(full_room_jid);
|
||||
if (nick != NULL) {
|
||||
char *full_room_jid = create_fulljid(room, nick);
|
||||
|
||||
xmpp_stanza_set_attribute(presence, STANZA_ATTR_TO, full_room_jid);
|
||||
log_debug("Sending presence to room: %s", full_room_jid);
|
||||
xmpp_send(conn, presence);
|
||||
free(full_room_jid);
|
||||
}
|
||||
|
||||
rooms = g_list_next(rooms);
|
||||
}
|
||||
g_list_free(rooms);
|
||||
|
||||
if (rooms_p != NULL) {
|
||||
g_list_free(rooms_p);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
@ -347,9 +364,13 @@ _subscribe_handler(xmpp_conn_t * const conn,
|
||||
xmpp_stanza_t * const stanza, void * const userdata)
|
||||
{
|
||||
char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
|
||||
Jid *from_jid = jid_create(from);
|
||||
log_debug("Subscribe presence handler fired for %s", from);
|
||||
|
||||
Jid *from_jid = jid_create(from);
|
||||
if (from_jid == NULL) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
prof_handle_subscription(from_jid->barejid, PRESENCE_SUBSCRIBE);
|
||||
autocomplete_add(sub_requests_ac, strdup(from_jid->barejid));
|
||||
|
||||
@ -368,6 +389,11 @@ _unavailable_handler(xmpp_conn_t * const conn,
|
||||
|
||||
Jid *my_jid = jid_create(jid);
|
||||
Jid *from_jid = jid_create(from);
|
||||
if (my_jid == NULL || from_jid == NULL) {
|
||||
jid_destroy(my_jid);
|
||||
jid_destroy(from_jid);
|
||||
return 1;
|
||||
}
|
||||
|
||||
char *status_str = stanza_get_status(stanza, NULL);
|
||||
|
||||
@ -385,7 +411,7 @@ _unavailable_handler(xmpp_conn_t * const conn,
|
||||
}
|
||||
}
|
||||
|
||||
FREE_SET_NULL(status_str);
|
||||
free(status_str);
|
||||
jid_destroy(my_jid);
|
||||
jid_destroy(from_jid);
|
||||
|
||||
@ -420,6 +446,11 @@ _available_handler(xmpp_conn_t * const conn,
|
||||
|
||||
Jid *my_jid = jid_create(jid);
|
||||
Jid *from_jid = jid_create(from);
|
||||
if (my_jid == NULL || from_jid == NULL) {
|
||||
jid_destroy(my_jid);
|
||||
jid_destroy(from_jid);
|
||||
return 1;
|
||||
}
|
||||
|
||||
char *show_str = stanza_get_show(stanza, "online");
|
||||
char *status_str = stanza_get_status(stanza, NULL);
|
||||
@ -471,8 +502,8 @@ _available_handler(xmpp_conn_t * const conn,
|
||||
last_activity);
|
||||
}
|
||||
|
||||
FREE_SET_NULL(status_str);
|
||||
FREE_SET_NULL(show_str);
|
||||
free(status_str);
|
||||
free(show_str);
|
||||
jid_destroy(my_jid);
|
||||
jid_destroy(from_jid);
|
||||
|
||||
@ -515,6 +546,10 @@ _get_caps_key(xmpp_stanza_t * const stanza)
|
||||
|
||||
log_debug("Presence contains capabilities.");
|
||||
|
||||
if (node == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// xep-0115
|
||||
if ((hash_type != NULL) && (strcmp(hash_type, "sha-1") == 0)) {
|
||||
log_debug("Hash type %s supported.", hash_type);
|
||||
@ -544,6 +579,8 @@ _get_caps_key(xmpp_stanza_t * const stanza)
|
||||
g_string_free(id_str, TRUE);
|
||||
}
|
||||
|
||||
g_free(node);
|
||||
|
||||
return caps_key;
|
||||
}
|
||||
|
||||
@ -556,10 +593,11 @@ _room_presence_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
||||
return 1;
|
||||
}
|
||||
|
||||
const char *jid = xmpp_conn_get_jid(conn);
|
||||
char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
|
||||
Jid *my_jid = jid_create(jid);
|
||||
Jid *from_jid = jid_create(from);
|
||||
if (from_jid == NULL || from_jid->resourcepart == NULL) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
char *room = from_jid->barejid;
|
||||
char *nick = from_jid->resourcepart;
|
||||
@ -592,7 +630,7 @@ _room_presence_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
||||
// handle presence from room members
|
||||
} else {
|
||||
char *type = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_TYPE);
|
||||
char *show_str, *status_str;
|
||||
char *status_str;
|
||||
|
||||
char *caps_key = NULL;
|
||||
if (stanza_contains_caps(stanza)) {
|
||||
@ -608,12 +646,15 @@ _room_presence_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
||||
// handle nickname change
|
||||
if (stanza_is_room_nick_change(stanza)) {
|
||||
char *new_nick = stanza_get_new_nick(stanza);
|
||||
muc_set_roster_pending_nick_change(room, new_nick, nick);
|
||||
if (new_nick != NULL) {
|
||||
muc_set_roster_pending_nick_change(room, new_nick, nick);
|
||||
free(new_nick);
|
||||
}
|
||||
} else {
|
||||
prof_handle_room_member_offline(room, nick, "offline", status_str);
|
||||
}
|
||||
} else {
|
||||
show_str = stanza_get_show(stanza, "online");
|
||||
char *show_str = stanza_get_show(stanza, "online");
|
||||
if (!muc_get_roster_received(room)) {
|
||||
muc_add_to_roster(room, nick, show_str, status_str, caps_key);
|
||||
} else {
|
||||
@ -622,6 +663,7 @@ _room_presence_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
||||
if (old_nick != NULL) {
|
||||
muc_add_to_roster(room, nick, show_str, status_str, caps_key);
|
||||
prof_handle_room_member_nick_change(room, old_nick, nick);
|
||||
free(old_nick);
|
||||
} else {
|
||||
if (!muc_nick_in_roster(room, nick)) {
|
||||
prof_handle_room_member_online(room, nick, show_str, status_str, caps_key);
|
||||
@ -631,13 +673,13 @@ _room_presence_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
||||
}
|
||||
}
|
||||
|
||||
FREE_SET_NULL(show_str);
|
||||
free(show_str);
|
||||
}
|
||||
|
||||
FREE_SET_NULL(status_str);
|
||||
free(status_str);
|
||||
free(caps_key);
|
||||
}
|
||||
|
||||
jid_destroy(my_jid);
|
||||
jid_destroy(from_jid);
|
||||
|
||||
return 1;
|
||||
|
@ -140,7 +140,7 @@ stanza_create_message(xmpp_ctx_t *ctx, const char * const recipient,
|
||||
xmpp_stanza_set_name(chat_state, state);
|
||||
xmpp_stanza_set_ns(chat_state, STANZA_NS_CHATSTATES);
|
||||
xmpp_stanza_add_child(msg, chat_state);
|
||||
xmpp_stanza_release(chat_state);
|
||||
xmpp_stanza_release(chat_state);
|
||||
}
|
||||
|
||||
return msg;
|
||||
@ -840,12 +840,11 @@ void
|
||||
stanza_destroy_form(DataForm *form)
|
||||
{
|
||||
if (form != NULL) {
|
||||
FREE_SET_NULL(form->form_type);
|
||||
if (form->fields != NULL) {
|
||||
GSList *curr_field = form->fields;
|
||||
while (curr_field != NULL) {
|
||||
FormField *field = curr_field->data;
|
||||
FREE_SET_NULL(field->var);
|
||||
free(field->var);
|
||||
if ((field->values) != NULL) {
|
||||
g_slist_free_full(field->values, free);
|
||||
}
|
||||
@ -854,6 +853,7 @@ stanza_destroy_form(DataForm *form)
|
||||
g_slist_free_full(form->fields, free);
|
||||
}
|
||||
|
||||
free(form->form_type);
|
||||
free(form);
|
||||
}
|
||||
}
|
||||
@ -941,7 +941,7 @@ stanza_attach_caps(xmpp_ctx_t * const ctx, xmpp_stanza_t * const presence)
|
||||
xmpp_stanza_add_child(presence, caps);
|
||||
xmpp_stanza_release(caps);
|
||||
xmpp_stanza_release(query);
|
||||
FREE_SET_NULL(sha1);
|
||||
g_free(sha1);
|
||||
}
|
||||
|
||||
const char *
|
||||
|
Loading…
Reference in New Issue
Block a user