1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Merge branch 'master' into windows

This commit is contained in:
James Booth 2013-08-25 23:27:42 +01:00
commit d3cfeb9d5c
29 changed files with 861 additions and 279 deletions

View File

@ -10,6 +10,7 @@ profanity_SOURCES = \
src/xmpp/stanza.h src/xmpp/message.h src/xmpp/iq.h src/xmpp/presence.h \ src/xmpp/stanza.h src/xmpp/message.h src/xmpp/iq.h src/xmpp/presence.h \
src/xmpp/capabilities.h src/xmpp/connection.h \ src/xmpp/capabilities.h src/xmpp/connection.h \
src/xmpp/roster.c src/xmpp/roster.h \ src/xmpp/roster.c src/xmpp/roster.h \
src/xmpp/bookmark.c src/xmpp/bookmark.h \
src/ui/ui.h src/ui/window.c src/ui/window.h src/ui/core.c \ src/ui/ui.h src/ui/window.c src/ui/window.h src/ui/core.c \
src/ui/titlebar.c src/ui/statusbar.c src/ui/inputwin.c \ src/ui/titlebar.c src/ui/statusbar.c src/ui/inputwin.c \
src/ui/console.c src/ui/notifier.c src/ui/notifier.h \ src/ui/console.c src/ui/notifier.c src/ui/notifier.h \
@ -37,6 +38,7 @@ tests_testsuite_SOURCES = \
src/xmpp/stanza.h src/xmpp/message.h src/xmpp/iq.h src/xmpp/presence.h \ src/xmpp/stanza.h src/xmpp/message.h src/xmpp/iq.h src/xmpp/presence.h \
src/xmpp/capabilities.h src/xmpp/connection.h \ src/xmpp/capabilities.h src/xmpp/connection.h \
src/xmpp/roster.c src/xmpp/roster.h \ src/xmpp/roster.c src/xmpp/roster.h \
src/xmpp/bookmark.c src/xmpp/bookmark.h \
src/ui/ui.h src/ui/window.c src/ui/window.h src/ui/core.c \ src/ui/ui.h src/ui/window.c src/ui/window.h src/ui/core.c \
src/ui/titlebar.c src/ui/statusbar.c src/ui/inputwin.c \ src/ui/titlebar.c src/ui/statusbar.c src/ui/inputwin.c \
src/ui/console.c src/ui/notifier.c src/ui/notifier.h \ src/ui/console.c src/ui/notifier.c src/ui/notifier.h \

View File

@ -266,15 +266,11 @@ static void
_chat_session_free(ChatSession session) _chat_session_free(ChatSession session)
{ {
if (session != NULL) { if (session != NULL) {
if (session->recipient != NULL) { free(session->recipient);
g_free(session->recipient);
session->recipient = NULL;
}
if (session->active_timer != NULL) { if (session->active_timer != NULL) {
g_timer_destroy(session->active_timer); g_timer_destroy(session->active_timer);
session->active_timer = NULL; session->active_timer = NULL;
} }
g_free(session); free(session);
} }
session = NULL;
} }

View File

@ -44,6 +44,7 @@
#include "tools/tinyurl.h" #include "tools/tinyurl.h"
#include "ui/ui.h" #include "ui/ui.h"
#include "xmpp/xmpp.h" #include "xmpp/xmpp.h"
#include "xmpp/bookmark.h"
/* /*
* Command structure * Command structure
@ -83,6 +84,7 @@ static char * _account_autocomplete(char *input, int *size);
static char * _who_autocomplete(char *input, int *size); static char * _who_autocomplete(char *input, int *size);
static char * _roster_autocomplete(char *input, int *size); static char * _roster_autocomplete(char *input, int *size);
static char * _group_autocomplete(char *input, int *size); static char * _group_autocomplete(char *input, int *size);
static char * _bookmark_autocomplete(char *input, int *size);
static int _strtoi(char *str, int *saveptr, int min, int max); static int _strtoi(char *str, int *saveptr, int min, int max);
@ -128,6 +130,7 @@ static gboolean _cmd_priority(gchar **args, struct cmd_help_t help);
static gboolean _cmd_quit(gchar **args, struct cmd_help_t help); static gboolean _cmd_quit(gchar **args, struct cmd_help_t help);
static gboolean _cmd_reconnect(gchar **args, struct cmd_help_t help); static gboolean _cmd_reconnect(gchar **args, struct cmd_help_t help);
static gboolean _cmd_rooms(gchar **args, struct cmd_help_t help); static gboolean _cmd_rooms(gchar **args, struct cmd_help_t help);
static gboolean _cmd_bookmark(gchar **args, struct cmd_help_t help);
static gboolean _cmd_roster(gchar **args, struct cmd_help_t help); static gboolean _cmd_roster(gchar **args, struct cmd_help_t help);
static gboolean _cmd_software(gchar **args, struct cmd_help_t help); static gboolean _cmd_software(gchar **args, struct cmd_help_t help);
static gboolean _cmd_splash(gchar **args, struct cmd_help_t help); static gboolean _cmd_splash(gchar **args, struct cmd_help_t help);
@ -367,6 +370,15 @@ static struct cmd_t command_defs[] =
"Example : /rooms (if logged in as me@server.org, is equivalent to /rooms conference.server.org)", "Example : /rooms (if logged in as me@server.org, is equivalent to /rooms conference.server.org)",
NULL } } }, NULL } } },
{ "/bookmark",
_cmd_bookmark, parse_args, 0, 4, NULL,
{ "/bookmark [add|list|remove] [room@server] [autojoin on|off] [nick nickname]",
"Manage bookmarks.",
{ "/bookmark [add|list|remove] [room@server] [autojoin on|off] [nick nickname]",
"---------------------------------------------------------------------------",
"Manage bookmarks.",
NULL } } },
{ "/disco", { "/disco",
_cmd_disco, parse_args, 1, 2, NULL, _cmd_disco, parse_args, 1, 2, NULL,
{ "/disco command entity", "Service discovery.", { "/disco command entity", "Service discovery.",
@ -853,6 +865,7 @@ static Autocomplete close_ac;
static Autocomplete wins_ac; static Autocomplete wins_ac;
static Autocomplete roster_ac; static Autocomplete roster_ac;
static Autocomplete group_ac; static Autocomplete group_ac;
static Autocomplete bookmark_ac;
/* /*
* Initialise command autocompleter and history * Initialise command autocompleter and history
@ -978,6 +991,11 @@ cmd_init(void)
autocomplete_add(who_ac, strdup("unavailable")); autocomplete_add(who_ac, strdup("unavailable"));
autocomplete_add(who_ac, strdup("any")); autocomplete_add(who_ac, strdup("any"));
bookmark_ac = autocomplete_new();
autocomplete_add(bookmark_ac, strdup("add"));
autocomplete_add(bookmark_ac, strdup("list"));
autocomplete_add(bookmark_ac, strdup("remove"));
cmd_history_init(); cmd_history_init();
} }
@ -989,6 +1007,7 @@ cmd_close(void)
autocomplete_free(help_ac); autocomplete_free(help_ac);
autocomplete_free(notify_ac); autocomplete_free(notify_ac);
autocomplete_free(sub_ac); autocomplete_free(sub_ac);
autocomplete_free(titlebar_ac);
autocomplete_free(log_ac); autocomplete_free(log_ac);
autocomplete_free(prefs_ac); autocomplete_free(prefs_ac);
autocomplete_free(autoaway_ac); autocomplete_free(autoaway_ac);
@ -1003,6 +1022,7 @@ cmd_close(void)
autocomplete_free(wins_ac); autocomplete_free(wins_ac);
autocomplete_free(roster_ac); autocomplete_free(roster_ac);
autocomplete_free(group_ac); autocomplete_free(group_ac);
autocomplete_free(bookmark_ac);
} }
// Command autocompletion functions // Command autocompletion functions
@ -1022,7 +1042,7 @@ cmd_autocomplete(char *input, int *size)
inp_cpy[i] = '\0'; inp_cpy[i] = '\0';
found = autocomplete_complete(commands_ac, inp_cpy); found = autocomplete_complete(commands_ac, inp_cpy);
if (found != NULL) { if (found != NULL) {
auto_msg = (char *) malloc((strlen(found) + 1) * sizeof(char)); auto_msg = (char *) malloc(strlen(found) + 1);
strcpy(auto_msg, found); strcpy(auto_msg, found);
inp_replace_input(input, auto_msg, size); inp_replace_input(input, auto_msg, size);
free(auto_msg); free(auto_msg);
@ -1072,6 +1092,8 @@ cmd_reset_autocomplete()
autocomplete_reset(wins_ac); autocomplete_reset(wins_ac);
autocomplete_reset(roster_ac); autocomplete_reset(roster_ac);
autocomplete_reset(group_ac); autocomplete_reset(group_ac);
autocomplete_reset(bookmark_ac);
bookmark_autocomplete_reset();
} }
// Command execution // Command execution
@ -1121,7 +1143,6 @@ cmd_execute_default(const char * const inp)
ui_current_print_line("You are not currently connected."); ui_current_print_line("You are not currently connected.");
} else { } else {
message_send_groupchat(inp, recipient); message_send_groupchat(inp, recipient);
free(recipient);
} }
break; break;
@ -1139,7 +1160,6 @@ cmd_execute_default(const char * const inp)
} }
ui_outgoing_msg("me", recipient, inp); ui_outgoing_msg("me", recipient, inp);
free(recipient);
} }
break; break;
@ -1149,7 +1169,6 @@ cmd_execute_default(const char * const inp)
} else { } else {
message_send(inp, recipient); message_send(inp, recipient);
ui_outgoing_msg("me", recipient, inp); ui_outgoing_msg("me", recipient, inp);
free(recipient);
} }
break; break;
@ -1163,7 +1182,6 @@ cmd_execute_default(const char * const inp)
} else { } else {
message_send_duck(inp); message_send_duck(inp);
ui_duck(inp); ui_duck(inp);
free(recipient);
} }
break; break;
@ -1171,6 +1189,8 @@ cmd_execute_default(const char * const inp)
break; break;
} }
free(recipient);
return TRUE; return TRUE;
} }
@ -1197,7 +1217,9 @@ _cmd_complete_parameters(char *input, int *size)
// autocomplete nickname in chat rooms // autocomplete nickname in chat rooms
if (ui_current_win_type() == WIN_MUC) { if (ui_current_win_type() == WIN_MUC) {
Autocomplete nick_ac = muc_get_roster_ac(ui_current_recipient()); char *recipient = ui_current_recipient();
Autocomplete nick_ac = muc_get_roster_ac(recipient);
free(recipient);
if (nick_ac != NULL) { if (nick_ac != NULL) {
gchar *nick_choices[] = { "/msg", "/info", "/caps", "/status", "/software" } ; gchar *nick_choices[] = { "/msg", "/info", "/caps", "/status", "/software" } ;
@ -1255,6 +1277,13 @@ _cmd_complete_parameters(char *input, int *size)
} }
} }
result = autocomplete_param_with_func(input, size, "/join", bookmark_find);
if (result != NULL) {
inp_replace_input(input, result, size);
g_free(result);
return;
}
result = autocomplete_param_with_func(input, size, "/connect", accounts_find_enabled); result = autocomplete_param_with_func(input, size, "/connect", accounts_find_enabled);
if (result != NULL) { if (result != NULL) {
inp_replace_input(input, result, size); inp_replace_input(input, result, size);
@ -1276,7 +1305,8 @@ _cmd_complete_parameters(char *input, int *size)
autocompleter acs[] = { _who_autocomplete, _sub_autocomplete, _notify_autocomplete, autocompleter acs[] = { _who_autocomplete, _sub_autocomplete, _notify_autocomplete,
_autoaway_autocomplete, _titlebar_autocomplete, _theme_autocomplete, _autoaway_autocomplete, _titlebar_autocomplete, _theme_autocomplete,
_account_autocomplete, _roster_autocomplete, _group_autocomplete }; _account_autocomplete, _roster_autocomplete, _group_autocomplete,
_bookmark_autocomplete };
for (i = 0; i < ARRAY_SIZE(acs); i++) { for (i = 0; i < ARRAY_SIZE(acs); i++) {
result = acs[i](input, size); result = acs[i](input, size);
@ -1979,6 +2009,8 @@ _cmd_who(gchar **args, struct cmd_help_t help)
ui_room_roster(room, filtered, presence); ui_room_roster(room, filtered, presence);
} }
free(room);
// not in groupchat window // not in groupchat window
} else { } else {
cons_show(""); cons_show("");
@ -2143,6 +2175,8 @@ _cmd_msg(gchar **args, struct cmd_help_t help)
ui_current_print_line("No such participant \"%s\" in room.", usr); ui_current_print_line("No such participant \"%s\" in room.", usr);
} }
free(room_name);
return TRUE; return TRUE;
} else { } else {
@ -2464,17 +2498,20 @@ _cmd_info(gchar **args, struct cmd_help_t help)
jabber_conn_status_t conn_status = jabber_get_connection_status(); jabber_conn_status_t conn_status = jabber_get_connection_status();
win_type_t win_type = ui_current_win_type(); win_type_t win_type = ui_current_win_type();
PContact pcontact = NULL; PContact pcontact = NULL;
char *recipient;
if (conn_status != JABBER_CONNECTED) { if (conn_status != JABBER_CONNECTED) {
cons_show("You are not currently connected."); cons_show("You are not currently connected.");
return TRUE; return TRUE;
} }
recipient = ui_current_recipient();
switch (win_type) switch (win_type)
{ {
case WIN_MUC: case WIN_MUC:
if (usr != NULL) { if (usr != NULL) {
pcontact = muc_get_participant(ui_current_recipient(), usr); pcontact = muc_get_participant(recipient, usr);
if (pcontact != NULL) { if (pcontact != NULL) {
cons_show_info(pcontact); cons_show_info(pcontact);
} else { } else {
@ -2488,11 +2525,11 @@ _cmd_info(gchar **args, struct cmd_help_t help)
if (usr != NULL) { if (usr != NULL) {
cons_show("No parameter required for /info in chat."); cons_show("No parameter required for /info in chat.");
} else { } else {
pcontact = roster_get_contact(ui_current_recipient()); pcontact = roster_get_contact(recipient);
if (pcontact != NULL) { if (pcontact != NULL) {
cons_show_info(pcontact); cons_show_info(pcontact);
} else { } else {
cons_show("No such contact \"%s\" in roster.", ui_current_recipient()); cons_show("No such contact \"%s\" in roster.", recipient);
} }
} }
break; break;
@ -2500,7 +2537,7 @@ _cmd_info(gchar **args, struct cmd_help_t help)
if (usr != NULL) { if (usr != NULL) {
ui_current_print_line("No parameter required when in chat."); ui_current_print_line("No parameter required when in chat.");
} else { } else {
Jid *jid = jid_create(ui_current_recipient()); Jid *jid = jid_create(recipient);
pcontact = muc_get_participant(jid->barejid, jid->resourcepart); pcontact = muc_get_participant(jid->barejid, jid->resourcepart);
if (pcontact != NULL) { if (pcontact != NULL) {
cons_show_info(pcontact); cons_show_info(pcontact);
@ -2530,6 +2567,8 @@ _cmd_info(gchar **args, struct cmd_help_t help)
break; break;
} }
free(recipient);
return TRUE; return TRUE;
} }
@ -2539,6 +2578,7 @@ _cmd_caps(gchar **args, struct cmd_help_t help)
jabber_conn_status_t conn_status = jabber_get_connection_status(); jabber_conn_status_t conn_status = jabber_get_connection_status();
win_type_t win_type = ui_current_win_type(); win_type_t win_type = ui_current_win_type();
PContact pcontact = NULL; PContact pcontact = NULL;
char *recipient;
if (conn_status != JABBER_CONNECTED) { if (conn_status != JABBER_CONNECTED) {
cons_show("You are not currently connected."); cons_show("You are not currently connected.");
@ -2549,13 +2589,15 @@ _cmd_caps(gchar **args, struct cmd_help_t help)
{ {
case WIN_MUC: case WIN_MUC:
if (args[0] != NULL) { if (args[0] != NULL) {
pcontact = muc_get_participant(ui_current_recipient(), args[0]); recipient = ui_current_recipient();
pcontact = muc_get_participant(recipient, args[0]);
if (pcontact != NULL) { if (pcontact != NULL) {
Resource *resource = p_contact_get_resource(pcontact, args[0]); Resource *resource = p_contact_get_resource(pcontact, args[0]);
cons_show_caps(args[0], resource); cons_show_caps(args[0], resource);
} else { } else {
cons_show("No such participant \"%s\" in room.", args[0]); cons_show("No such participant \"%s\" in room.", args[0]);
} }
free(recipient);
} else { } else {
cons_show("No nickname supplied to /caps in chat room."); cons_show("No nickname supplied to /caps in chat room.");
} }
@ -2588,10 +2630,15 @@ _cmd_caps(gchar **args, struct cmd_help_t help)
if (args[0] != NULL) { if (args[0] != NULL) {
cons_show("No parameter needed to /caps when in private chat."); cons_show("No parameter needed to /caps when in private chat.");
} else { } else {
Jid *jid = jid_create(ui_current_recipient()); recipient = ui_current_recipient();
Jid *jid = jid_create(recipient);
if (jid) {
pcontact = muc_get_participant(jid->barejid, jid->resourcepart); pcontact = muc_get_participant(jid->barejid, jid->resourcepart);
Resource *resource = p_contact_get_resource(pcontact, jid->resourcepart); Resource *resource = p_contact_get_resource(pcontact, jid->resourcepart);
cons_show_caps(jid->resourcepart, resource); cons_show_caps(jid->resourcepart, resource);
jid_destroy(jid);
}
free(recipient);
} }
break; break;
default: default:
@ -2608,6 +2655,7 @@ _cmd_software(gchar **args, struct cmd_help_t help)
jabber_conn_status_t conn_status = jabber_get_connection_status(); jabber_conn_status_t conn_status = jabber_get_connection_status();
win_type_t win_type = ui_current_win_type(); win_type_t win_type = ui_current_win_type();
PContact pcontact = NULL; PContact pcontact = NULL;
char *recipient;
if (conn_status != JABBER_CONNECTED) { if (conn_status != JABBER_CONNECTED) {
cons_show("You are not currently connected."); cons_show("You are not currently connected.");
@ -2618,14 +2666,16 @@ _cmd_software(gchar **args, struct cmd_help_t help)
{ {
case WIN_MUC: case WIN_MUC:
if (args[0] != NULL) { if (args[0] != NULL) {
pcontact = muc_get_participant(ui_current_recipient(), args[0]); recipient = ui_current_recipient();
pcontact = muc_get_participant(recipient, args[0]);
if (pcontact != NULL) { if (pcontact != NULL) {
Jid *jid = jid_create_from_bare_and_resource(ui_current_recipient(), args[0]); Jid *jid = jid_create_from_bare_and_resource(recipient, args[0]);
iq_send_software_version(jid->fulljid); iq_send_software_version(jid->fulljid);
jid_destroy(jid); jid_destroy(jid);
} else { } else {
cons_show("No such participant \"%s\" in room.", args[0]); cons_show("No such participant \"%s\" in room.", args[0]);
} }
free(recipient);
} else { } else {
cons_show("No nickname supplied to /software in chat room."); cons_show("No nickname supplied to /software in chat room.");
} }
@ -2635,11 +2685,12 @@ _cmd_software(gchar **args, struct cmd_help_t help)
if (args[0] != NULL) { if (args[0] != NULL) {
Jid *jid = jid_create(args[0]); Jid *jid = jid_create(args[0]);
if (jid->fulljid == NULL) { if (jid == NULL || jid->fulljid == NULL) {
cons_show("You must provide a full jid to the /software command."); cons_show("You must provide a full jid to the /software command.");
} else { } else {
iq_send_software_version(jid->fulljid); iq_send_software_version(jid->fulljid);
} }
jid_destroy(jid);
} else { } else {
cons_show("You must provide a jid to the /software command."); cons_show("You must provide a jid to the /software command.");
} }
@ -2648,7 +2699,9 @@ _cmd_software(gchar **args, struct cmd_help_t help)
if (args[0] != NULL) { if (args[0] != NULL) {
cons_show("No parameter needed to /software when in private chat."); cons_show("No parameter needed to /software when in private chat.");
} else { } else {
iq_send_software_version(ui_current_recipient()); recipient = ui_current_recipient();
iq_send_software_version(recipient);
free(recipient);
} }
break; break;
default: default:
@ -2803,6 +2856,73 @@ _cmd_rooms(gchar **args, struct cmd_help_t help)
return TRUE; return TRUE;
} }
static gboolean
_cmd_bookmark(gchar **args, struct cmd_help_t help)
{
jabber_conn_status_t conn_status = jabber_get_connection_status();
gchar *cmd = args[0];
if (conn_status != JABBER_CONNECTED) {
cons_show("You are not currenlty connect.");
return TRUE;
}
/* TODO: /bookmark list room@server */
if (cmd == NULL || strcmp(cmd, "list") == 0) {
cons_show_bookmarks(bookmark_get_list());
} else {
gboolean autojoin = FALSE;
gboolean jid_release = FALSE;
gchar *jid = NULL;
gchar *nick = NULL;
int idx = 1;
while (args[idx] != NULL) {
gchar *opt = args[idx];
if (strcmp(opt, "autojoin") == 0) {
autojoin = TRUE;
} else if (jid == NULL) {
jid = opt;
} else if (nick == NULL) {
nick = opt;
} else {
cons_show("Usage: %s", help.usage);
}
++idx;
}
if (jid == NULL) {
win_type_t win_type = ui_current_win_type();
if (win_type == WIN_MUC) {
jid = ui_current_recipient();
jid_release = TRUE;
nick = muc_get_room_nick(jid);
} else {
cons_show("Usage: %s", help.usage);
return TRUE;
}
}
if (strcmp(cmd, "add") == 0) {
bookmark_add(jid, nick, autojoin);
} else if (strcmp(cmd, "remove") == 0) {
bookmark_remove(jid, autojoin);
} else {
cons_show("Usage: %s", help.usage);
}
if (jid_release) {
free(jid);
}
}
return TRUE;
}
static gboolean static gboolean
_cmd_disco(gchar **args, struct cmd_help_t help) _cmd_disco(gchar **args, struct cmd_help_t help)
{ {
@ -3593,6 +3713,34 @@ _group_autocomplete(char *input, int *size)
return NULL; return NULL;
} }
static char *
_bookmark_autocomplete(char *input, int *size)
{
char *result = NULL;
if (strcmp(input, "/bookmark add ") == 0) {
GString *str = g_string_new(input);
str = g_string_append(str, "autojoin");
result = str->str;
g_string_free(str, FALSE);
return result;
}
result = autocomplete_param_with_func(input, size, "/bookmark list", bookmark_find);
if (result != NULL) {
return result;
}
result = autocomplete_param_with_func(input, size, "/bookmark remove", bookmark_find);
if (result != NULL) {
return result;
}
result = autocomplete_param_with_ac(input, size, "/bookmark", bookmark_ac);
return result;
}
static char * static char *
_notify_autocomplete(char *input, int *size) _notify_autocomplete(char *input, int *size)
{ {

View File

@ -25,21 +25,20 @@
#include <errno.h> #include <errno.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <curl/curl.h> #include <curl/curl.h>
#include <curl/easy.h> #include <curl/easy.h>
#include <glib.h> #include <glib.h>
#include "log.h"
#include "common.h" #include "common.h"
// assume malloc stores at most 8 bytes for size of allocated memory // assume malloc stores at most 8 bytes for size of allocated memory
// and page size is at least 4KB // and page size is at least 4KB
#define READ_BUF_SIZE 4088 #define READ_BUF_SIZE 4088
// for generating ids
static int unique_id = 0;
struct curl_data_t struct curl_data_t
{ {
char *buffer; char *buffer;
@ -72,31 +71,45 @@ p_slist_free_full(GSList *items, GDestroyNotify free_func)
g_slist_free (items); g_slist_free (items);
} }
void gboolean
create_dir(char *name) create_dir(char *name)
{ {
int e;
struct stat sb; struct stat sb;
e = stat(name, &sb); if (stat(name, &sb) != 0) {
if (e != 0) if (errno != ENOENT || mkdir(name, S_IRWXU) != 0) {
if (errno == ENOENT) return FALSE;
e = mkdir(name, S_IRWXU); }
} else {
if ((sb.st_mode & S_IFDIR) != S_IFDIR) {
log_debug("create_dir: %s exists and is not a directory!", name);
return FALSE;
}
} }
void return TRUE;
}
gboolean
mkdir_recursive(const char *dir) mkdir_recursive(const char *dir)
{ {
int i; int i;
gboolean result = TRUE;
for (i = 1; i <= strlen(dir); i++) { for (i = 1; i <= strlen(dir); i++) {
if (dir[i] == '/' || dir[i] == '\0') { if (dir[i] == '/' || dir[i] == '\0') {
gchar *next_dir = g_strndup(dir, i); gchar *next_dir = g_strndup(dir, i);
create_dir(next_dir); result = create_dir(next_dir);
g_free(next_dir); g_free(next_dir);
if (!result) {
break;
} }
} }
} }
return result;
}
char * char *
str_replace(const char *string, const char *substr, str_replace(const char *string, const char *substr,
const char *replacement) const char *replacement)
@ -400,10 +413,12 @@ xdg_get_data_home(void)
char * char *
get_unique_id(void) get_unique_id(void)
{ {
static unsigned long unique_id;
char *result = NULL; char *result = NULL;
unique_id++;
GString *result_str = g_string_new(""); GString *result_str = g_string_new("");
g_string_printf(result_str, "prof%d", unique_id);
unique_id++;
g_string_printf(result_str, "prof%lu", unique_id);
result = result_str->str; result = result_str->str;
g_string_free(result_str, FALSE); g_string_free(result_str, FALSE);

View File

@ -42,18 +42,16 @@
#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0])) #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
#define FREE_SET_NULL(resource) \ #define FREE_SET_NULL(resource) \
{ \ do { \
if (resource != NULL) { \
free(resource); \ free(resource); \
resource = NULL; \ resource = NULL; \
} \ } while (0)
}
#define GFREE_SET_NULL(resource) \ #define GFREE_SET_NULL(resource) \
{ \ do { \
g_free(resource); \ g_free(resource); \
resource = NULL; \ resource = NULL; \
} } while (0)
typedef enum { typedef enum {
CONTACT_OFFLINE, CONTACT_OFFLINE,
@ -74,8 +72,8 @@ typedef enum {
gchar* p_utf8_substring(const gchar *str, glong start_pos, glong end_pos); gchar* p_utf8_substring(const gchar *str, glong start_pos, glong end_pos);
void p_slist_free_full(GSList *items, GDestroyNotify free_func); void p_slist_free_full(GSList *items, GDestroyNotify free_func);
void create_dir(char *name); gboolean create_dir(char *name);
void mkdir_recursive(const char *dir); gboolean mkdir_recursive(const char *dir);
char * str_replace(const char *string, const char *substr, char * str_replace(const char *string, const char *substr,
const char *replacement); const char *replacement);
int str_contains(char str[], int size, char ch); int str_contains(char str[], int size, char ch);

View File

@ -72,10 +72,7 @@ accounts_load(void)
_fix_legacy_accounts(account_names[i]); _fix_legacy_accounts(account_names[i]);
} }
for (i = 0; i < naccounts; i++) { g_strfreev(account_names);
free(account_names[i]);
}
free(account_names);
} }
void void
@ -166,6 +163,7 @@ accounts_get_account(const char * const name)
gchar *jid = g_key_file_get_string(accounts, name, "jid", NULL); gchar *jid = g_key_file_get_string(accounts, name, "jid", NULL);
if (jid != NULL) { if (jid != NULL) {
account->jid = strdup(jid); account->jid = strdup(jid);
g_free(jid);
} else { } else {
account->jid = strdup(name); account->jid = strdup(name);
g_key_file_set_string(accounts, name, "jid", name); g_key_file_set_string(accounts, name, "jid", name);
@ -177,6 +175,7 @@ accounts_get_account(const char * const name)
gchar *server = g_key_file_get_string(accounts, name, "server", NULL); gchar *server = g_key_file_get_string(accounts, name, "server", NULL);
if (server != NULL) { if (server != NULL) {
account->server = strdup(server); account->server = strdup(server);
g_free(server);
} else { } else {
account->server = NULL; account->server = NULL;
} }
@ -184,6 +183,7 @@ accounts_get_account(const char * const name)
gchar *resource = g_key_file_get_string(accounts, name, "resource", NULL); gchar *resource = g_key_file_get_string(accounts, name, "resource", NULL);
if (resource != NULL) { if (resource != NULL) {
account->resource = strdup(resource); account->resource = strdup(resource);
g_free(resource);
} else { } else {
account->resource = NULL; account->resource = NULL;
} }
@ -195,6 +195,10 @@ accounts_get_account(const char * const name)
account->last_presence = strdup(presence); account->last_presence = strdup(presence);
} }
if (presence != NULL) {
g_free(presence);
}
presence = g_key_file_get_string(accounts, name, "presence.login", NULL); presence = g_key_file_get_string(accounts, name, "presence.login", NULL);
if (presence == NULL) { if (presence == NULL) {
account->login_presence = strdup("online"); account->login_presence = strdup("online");
@ -206,6 +210,10 @@ accounts_get_account(const char * const name)
account->login_presence = strdup(presence); account->login_presence = strdup(presence);
} }
if (presence != NULL) {
g_free(presence);
}
account->priority_online = g_key_file_get_integer(accounts, name, "priority.online", NULL); account->priority_online = g_key_file_get_integer(accounts, name, "priority.online", NULL);
account->priority_chat = g_key_file_get_integer(accounts, name, "priority.chat", NULL); account->priority_chat = g_key_file_get_integer(accounts, name, "priority.chat", NULL);
account->priority_away = g_key_file_get_integer(accounts, name, "priority.away", NULL); account->priority_away = g_key_file_get_integer(accounts, name, "priority.away", NULL);
@ -236,13 +244,13 @@ void
accounts_free_account(ProfAccount *account) accounts_free_account(ProfAccount *account)
{ {
if (account != NULL) { if (account != NULL) {
FREE_SET_NULL(account->name); free(account->name);
FREE_SET_NULL(account->jid); free(account->jid);
FREE_SET_NULL(account->resource); free(account->resource);
FREE_SET_NULL(account->server); free(account->server);
FREE_SET_NULL(account->last_presence); free(account->last_presence);
FREE_SET_NULL(account->login_presence); free(account->login_presence);
FREE_SET_NULL(account); free(account);
} }
} }
@ -302,7 +310,7 @@ accounts_rename(const char * const account_name, const char * const new_name)
char *value = g_key_file_get_string(accounts, account_name, string_keys[i], NULL); char *value = g_key_file_get_string(accounts, account_name, string_keys[i], NULL);
if (value != NULL) { if (value != NULL) {
g_key_file_set_string(accounts, new_name, string_keys[i], value); g_key_file_set_string(accounts, new_name, string_keys[i], value);
free(value); g_free(value);
} }
} }
@ -469,45 +477,59 @@ accounts_set_login_presence(const char * const account_name, const char * const
resource_presence_t resource_presence_t
accounts_get_last_presence(const char * const account_name) accounts_get_last_presence(const char * const account_name)
{ {
resource_presence_t result;
gchar *setting = g_key_file_get_string(accounts, account_name, "presence.last", NULL); gchar *setting = g_key_file_get_string(accounts, account_name, "presence.last", NULL);
if (setting == NULL || (strcmp(setting, "online") == 0)) { if (setting == NULL || (strcmp(setting, "online") == 0)) {
return RESOURCE_ONLINE; result = RESOURCE_ONLINE;
} else if (strcmp(setting, "chat") == 0) { } else if (strcmp(setting, "chat") == 0) {
return RESOURCE_CHAT; result = RESOURCE_CHAT;
} else if (strcmp(setting, "away") == 0) { } else if (strcmp(setting, "away") == 0) {
return RESOURCE_AWAY; result = RESOURCE_AWAY;
} else if (strcmp(setting, "xa") == 0) { } else if (strcmp(setting, "xa") == 0) {
return RESOURCE_XA; result = RESOURCE_XA;
} else if (strcmp(setting, "dnd") == 0) { } else if (strcmp(setting, "dnd") == 0) {
return RESOURCE_DND; result = RESOURCE_DND;
} else { } else {
log_warning("Error reading presence.last for account: '%s', value: '%s', defaulting to 'online'", log_warning("Error reading presence.last for account: '%s', value: '%s', defaulting to 'online'",
account_name, setting); account_name, setting);
return RESOURCE_ONLINE; result = RESOURCE_ONLINE;
} }
if (setting != NULL) {
g_free(setting);
}
return result;
} }
resource_presence_t resource_presence_t
accounts_get_login_presence(const char * const account_name) accounts_get_login_presence(const char * const account_name)
{ {
resource_presence_t result;
gchar *setting = g_key_file_get_string(accounts, account_name, "presence.login", NULL); gchar *setting = g_key_file_get_string(accounts, account_name, "presence.login", NULL);
if (setting == NULL || (strcmp(setting, "online") == 0)) { if (setting == NULL || (strcmp(setting, "online") == 0)) {
return RESOURCE_ONLINE; result = RESOURCE_ONLINE;
} else if (strcmp(setting, "chat") == 0) { } else if (strcmp(setting, "chat") == 0) {
return RESOURCE_CHAT; result = RESOURCE_CHAT;
} else if (strcmp(setting, "away") == 0) { } else if (strcmp(setting, "away") == 0) {
return RESOURCE_AWAY; result = RESOURCE_AWAY;
} else if (strcmp(setting, "xa") == 0) { } else if (strcmp(setting, "xa") == 0) {
return RESOURCE_XA; result = RESOURCE_XA;
} else if (strcmp(setting, "dnd") == 0) { } else if (strcmp(setting, "dnd") == 0) {
return RESOURCE_DND; result = RESOURCE_DND;
} else if (strcmp(setting, "last") == 0) { } else if (strcmp(setting, "last") == 0) {
return accounts_get_last_presence(account_name); result = accounts_get_last_presence(account_name);
} else { } else {
log_warning("Error reading presence.login for account: '%s', value: '%s', defaulting to 'online'", log_warning("Error reading presence.login for account: '%s', value: '%s', defaulting to 'online'",
account_name, setting); account_name, setting);
return RESOURCE_ONLINE; result = RESOURCE_ONLINE;
} }
if (setting != NULL) {
g_free(setting);
}
return result;
} }
static void static void
@ -543,8 +565,9 @@ static void
_save_accounts(void) _save_accounts(void)
{ {
gsize g_data_size; gsize g_data_size;
char *g_accounts_data = g_key_file_to_data(accounts, &g_data_size, NULL); gchar *g_accounts_data = g_key_file_to_data(accounts, &g_data_size, NULL);
g_file_set_contents(accounts_loc, g_accounts_data, g_data_size, NULL); g_file_set_contents(accounts_loc, g_accounts_data, g_data_size, NULL);
g_free(g_accounts_data);
} }
static gchar * static gchar *

View File

@ -79,14 +79,9 @@ p_contact_new(const char * const barejid, const char * const name,
void void
p_contact_set_name(const PContact contact, const char * const name) 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) { if (name != NULL) {
contact->name = strdup(name); contact->name = strdup(name);
} else {
FREE_SET_NULL(contact->name);
} }
} }
@ -130,10 +125,11 @@ p_contact_remove_resource(PContact contact, const char * const resource)
void void
p_contact_free(PContact contact) p_contact_free(PContact contact)
{ {
FREE_SET_NULL(contact->barejid); if (contact != NULL) {
FREE_SET_NULL(contact->name); free(contact->barejid);
FREE_SET_NULL(contact->subscription); free(contact->name);
FREE_SET_NULL(contact->offline_message); free(contact->subscription);
free(contact->offline_message);
if (contact->groups != NULL) { if (contact->groups != NULL) {
g_slist_free_full(contact->groups, g_free); g_slist_free_full(contact->groups, g_free);
@ -144,8 +140,8 @@ p_contact_free(PContact contact)
} }
g_hash_table_destroy(contact->available_resources); g_hash_table_destroy(contact->available_resources);
free(contact);
FREE_SET_NULL(contact); }
} }
const char * const char *

View File

@ -34,13 +34,14 @@ jid_create(const gchar * const str)
{ {
Jid *result = NULL; Jid *result = NULL;
if (str == NULL) { /* if str is NULL g_strdup returns NULL */
gchar *trimmed = g_strdup(str);
if (trimmed == NULL) {
return NULL; return NULL;
} }
gchar *trimmed = g_strdup(str);
if (strlen(trimmed) == 0) { if (strlen(trimmed) == 0) {
g_free(trimmed);
return NULL; return NULL;
} }
@ -50,10 +51,12 @@ jid_create(const gchar * const str)
} }
if (!g_utf8_validate(trimmed, -1, NULL)) { if (!g_utf8_validate(trimmed, -1, NULL)) {
g_free(trimmed);
return NULL; return NULL;
} }
result = malloc(sizeof(struct jid_t)); result = malloc(sizeof(struct jid_t));
result->str = NULL;
result->localpart = NULL; result->localpart = NULL;
result->domainpart = NULL; result->domainpart = NULL;
result->resourcepart = NULL; result->resourcepart = NULL;
@ -81,13 +84,11 @@ jid_create(const gchar * const str)
} }
if (result->domainpart == NULL) { if (result->domainpart == NULL) {
free(trimmed); jid_destroy(result);
return NULL; return NULL;
} }
result->str = g_strdup(trimmed); result->str = trimmed;
free(trimmed);
return result; return result;
} }
@ -107,13 +108,13 @@ void
jid_destroy(Jid *jid) jid_destroy(Jid *jid)
{ {
if (jid != NULL) { if (jid != NULL) {
FREE_SET_NULL(jid->str); g_free(jid->str);
FREE_SET_NULL(jid->localpart); g_free(jid->localpart);
FREE_SET_NULL(jid->domainpart); g_free(jid->domainpart);
FREE_SET_NULL(jid->resourcepart); g_free(jid->resourcepart);
FREE_SET_NULL(jid->barejid); g_free(jid->barejid);
FREE_SET_NULL(jid->fulljid); g_free(jid->fulljid);
FREE_SET_NULL(jid); free(jid);
} }
} }
@ -181,18 +182,18 @@ char *
get_room_from_full_jid(const char * const full_room_jid) get_room_from_full_jid(const char * const full_room_jid)
{ {
char **tokens = g_strsplit(full_room_jid, "/", 0); char **tokens = g_strsplit(full_room_jid, "/", 0);
char *room_part; char *room_part = NULL;
if (tokens == NULL || tokens[0] == NULL) { if (tokens != NULL) {
return NULL; if (tokens[0] != NULL) {
} else {
room_part = strdup(tokens[0]); room_part = strdup(tokens[0]);
}
g_strfreev(tokens); g_strfreev(tokens);
}
return room_part; return room_part;
} }
}
/* /*
* Get the nickname part of the full JID, e.g. * Get the nickname part of the full JID, e.g.
@ -203,16 +204,15 @@ char *
get_nick_from_full_jid(const char * const full_room_jid) get_nick_from_full_jid(const char * const full_room_jid)
{ {
char **tokens = g_strsplit(full_room_jid, "/", 0); char **tokens = g_strsplit(full_room_jid, "/", 0);
char *nick_part; char *nick_part = NULL;
if (tokens == NULL || tokens[1] == NULL) { if (tokens != NULL) {
return NULL; if (tokens[0] != NULL && tokens[1] != NULL) {
} else {
nick_part = strdup(tokens[1]); nick_part = strdup(tokens[1]);
}
g_strfreev(tokens); g_strfreev(tokens);
}
return nick_part; return nick_part;
} }
}

View File

@ -25,8 +25,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include "glib.h" #include "glib.h"
@ -37,11 +35,6 @@
#define PROF "prof" #define PROF "prof"
#ifdef _WIN32
// replace 'struct stat' and 'stat()' for windows
#define stat _stat
#endif
static FILE *logp; static FILE *logp;
static GTimeZone *tz; static GTimeZone *tz;
@ -125,7 +118,7 @@ log_init(log_level_t filter)
tz = g_time_zone_new_local(); tz = g_time_zone_new_local();
gchar *log_file = _get_log_file(); gchar *log_file = _get_log_file();
logp = fopen(log_file, "a"); logp = fopen(log_file, "a");
g_free(log_file); free(log_file);
} }
log_level_t log_level_t
@ -145,9 +138,7 @@ void
log_msg(log_level_t level, const char * const area, const char * const msg) log_msg(log_level_t level, const char * const area, const char * const msg)
{ {
if (level >= level_filter) { if (level >= level_filter) {
struct stat st; long result;
int result;
gchar *log_file = _get_log_file();
dt = g_date_time_new_now(tz); dt = g_date_time_new_now(tz);
gchar *date_fmt = g_date_time_format(dt, "%d/%m/%Y %H:%M:%S"); 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); fflush(logp);
g_free(date_fmt); g_free(date_fmt);
result = stat(log_file, &st); result = ftell(logp);
if (result == 0 && st.st_size >= prefs_get_max_log_size()) { if (result != -1 && result >= prefs_get_max_log_size()) {
_rotate_log_file(); _rotate_log_file();
} }
g_free(log_file);
} }
} }
@ -200,7 +189,7 @@ _rotate_log_file(void)
log_init(log_get_filter()); log_init(log_get_filter());
free(log_file_new); free(log_file_new);
g_free(log_file); free(log_file);
log_info("Log has been rotated"); log_info("Log has been rotated");
} }
@ -216,7 +205,6 @@ chat_log_init(void)
void void
groupchat_log_init(void) groupchat_log_init(void)
{ {
session_started = g_date_time_new_now_local();
log_info("Initialising groupchat logs"); log_info("Initialising groupchat logs");
groupchat_logs = g_hash_table_new_full(g_str_hash, (GEqualFunc) _key_equals, g_free, groupchat_logs = g_hash_table_new_full(g_str_hash, (GEqualFunc) _key_equals, g_free,
(GDestroyNotify)_free_chat_log); (GDestroyNotify)_free_chat_log);
@ -320,8 +308,6 @@ GSList *
chat_log_get_previous(const gchar * const login, const gchar * const recipient, chat_log_get_previous(const gchar * const login, const gchar * const recipient,
GSList *history) GSList *history)
{ {
GTimeZone *tz = g_time_zone_new_local();
GDateTime *now = g_date_time_new_now_local(); GDateTime *now = g_date_time_new_now_local();
GDateTime *log_date = g_date_time_new(tz, GDateTime *log_date = g_date_time_new(tz,
g_date_time_get_year(session_started), g_date_time_get_year(session_started),
@ -360,8 +346,6 @@ chat_log_get_previous(const gchar * const login, const gchar * const recipient,
log_date = g_date_time_ref(next); log_date = g_date_time_ref(next);
} }
g_time_zone_unref(tz);
return history; return history;
} }
@ -448,7 +432,7 @@ _get_log_filename(const char * const other, const char * const login,
{ {
gchar *chatlogs_dir = _get_chatlog_dir(); gchar *chatlogs_dir = _get_chatlog_dir();
GString *log_file = g_string_new(chatlogs_dir); GString *log_file = g_string_new(chatlogs_dir);
g_free(chatlogs_dir); free(chatlogs_dir);
gchar *login_dir = str_replace(login, "@", "_at_"); gchar *login_dir = str_replace(login, "@", "_at_");
g_string_append_printf(log_file, "/%s", login_dir); g_string_append_printf(log_file, "/%s", login_dir);
@ -516,7 +500,7 @@ _get_chatlog_dir(void)
GString *chatlogs_dir = g_string_new(xdg_data); GString *chatlogs_dir = g_string_new(xdg_data);
g_string_append(chatlogs_dir, "/profanity/chatlogs"); g_string_append(chatlogs_dir, "/profanity/chatlogs");
gchar *result = strdup(chatlogs_dir->str); gchar *result = strdup(chatlogs_dir->str);
g_free(xdg_data); free(xdg_data);
g_string_free(chatlogs_dir, TRUE); g_string_free(chatlogs_dir, TRUE);
return result; return result;
@ -529,7 +513,7 @@ _get_log_file(void)
GString *logfile = g_string_new(xdg_data); GString *logfile = g_string_new(xdg_data);
g_string_append(logfile, "/profanity/logs/profanity.log"); g_string_append(logfile, "/profanity/logs/profanity.log");
gchar *result = strdup(logfile->str); gchar *result = strdup(logfile->str);
g_free(xdg_data); free(xdg_data);
g_string_free(logfile, TRUE); g_string_free(logfile, TRUE);
return result; return result;

View File

@ -456,32 +456,20 @@ static void
_free_room(ChatRoom *room) _free_room(ChatRoom *room)
{ {
if (room != NULL) { if (room != NULL) {
if (room->room != NULL) { free(room->room);
g_free(room->room); free(room->nick);
room->room = NULL; free(room->subject);
}
if (room->nick != NULL) {
g_free(room->nick);
room->nick = NULL;
}
if (room->subject != NULL) {
g_free(room->subject);
room->subject = NULL;
}
if (room->roster != NULL) { if (room->roster != NULL) {
g_hash_table_remove_all(room->roster); g_hash_table_remove_all(room->roster);
room->roster = NULL;
} }
if (room->nick_ac != NULL) { if (room->nick_ac != NULL) {
autocomplete_free(room->nick_ac); autocomplete_free(room->nick_ac);
} }
if (room->nick_changes != NULL) { if (room->nick_changes != NULL) {
g_hash_table_remove_all(room->nick_changes); g_hash_table_remove_all(room->nick_changes);
room->nick_changes = NULL;
} }
g_free(room); free(room);
} }
room = NULL;
} }
static static

View File

@ -664,9 +664,15 @@ _create_directories(void)
GString *logs_dir = g_string_new(xdg_data); GString *logs_dir = g_string_new(xdg_data);
g_string_append(logs_dir, "/profanity/logs"); g_string_append(logs_dir, "/profanity/logs");
mkdir_recursive(themes_dir->str); if (!mkdir_recursive(themes_dir->str)) {
mkdir_recursive(chatlogs_dir->str); log_error("Error while creating directory %s", themes_dir->str);
mkdir_recursive(logs_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(themes_dir, TRUE);
g_string_free(chatlogs_dir, TRUE); g_string_free(chatlogs_dir, TRUE);

View File

@ -81,9 +81,10 @@ resource_compare_availability(Resource *first, Resource *second)
void resource_destroy(Resource *resource) void resource_destroy(Resource *resource)
{ {
assert(resource != NULL); if (resource != NULL) {
FREE_SET_NULL(resource->name); free(resource->name);
FREE_SET_NULL(resource->status); free(resource->status);
FREE_SET_NULL(resource->caps_str); free(resource->caps_str);
FREE_SET_NULL(resource); free(resource);
}
} }

View File

@ -24,6 +24,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "common.h"
#include "tools/autocomplete.h" #include "tools/autocomplete.h"
#include "tools/parser.h" #include "tools/parser.h"
@ -59,10 +60,7 @@ void
autocomplete_reset(Autocomplete ac) autocomplete_reset(Autocomplete ac)
{ {
ac->last_found = NULL; ac->last_found = NULL;
if (ac->search_str != NULL) { FREE_SET_NULL(ac->search_str);
free(ac->search_str);
ac->search_str = NULL;
}
} }
void void
@ -220,7 +218,7 @@ autocomplete_param_with_func(char *input, int *size, char *command,
inp_cpy[(*size) - len] = '\0'; inp_cpy[(*size) - len] = '\0';
found = func(inp_cpy); found = func(inp_cpy);
if (found != NULL) { 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); strcpy(auto_msg, command_cpy);
strcat(auto_msg, found); strcat(auto_msg, found);
free(found); free(found);
@ -249,7 +247,7 @@ autocomplete_param_with_ac(char *input, int *size, char *command,
inp_cpy[(*size) - len] = '\0'; inp_cpy[(*size) - len] = '\0';
found = autocomplete_complete(ac, inp_cpy); found = autocomplete_complete(ac, inp_cpy);
if (found != NULL) { 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); strcpy(auto_msg, command_cpy);
strcat(auto_msg, found); strcat(auto_msg, found);
free(found); free(found);

View File

@ -38,6 +38,7 @@
#include "ui/windows.h" #include "ui/windows.h"
#include "ui/ui.h" #include "ui/ui.h"
#include "xmpp/xmpp.h" #include "xmpp/xmpp.h"
#include "xmpp/bookmark.h"
#define CONS_WIN_TITLE "_cons" #define CONS_WIN_TITLE "_cons"
@ -598,6 +599,34 @@ cons_show_room_list(GSList *rooms, const char * const conference_node)
cons_alert(); cons_alert();
} }
void
cons_show_bookmarks(const GList *list)
{
Bookmark *item;
cons_show("");
cons_show("Bookmarks:");
/* TODO: show status (connected or not) and window number */
while (list != NULL) {
item = list->data;
win_print_time(console, '-');
wprintw(console->win, " %s", item->jid);
if (item->nick != NULL) {
wprintw(console->win, "/%s", item->nick);
}
if (item->autojoin) {
wprintw(console->win, " (autojoin)");
}
wprintw(console->win, "\n");
list = g_list_next(list);
}
ui_console_dirty();
cons_alert();
}
void void
cons_show_disco_info(const char *jid, GSList *identities, GSList *features) cons_show_disco_info(const char *jid, GSList *identities, GSList *features)
{ {
@ -613,15 +642,15 @@ cons_show_disco_info(const char *jid, GSList *identities, GSList *features)
DiscoIdentity *identity = identities->data; // anme trpe, cat DiscoIdentity *identity = identities->data; // anme trpe, cat
GString *identity_str = g_string_new(" "); GString *identity_str = g_string_new(" ");
if (identity->name != NULL) { if (identity->name != NULL) {
identity_str = g_string_append(identity_str, strdup(identity->name)); identity_str = g_string_append(identity_str, identity->name);
identity_str = g_string_append(identity_str, " "); identity_str = g_string_append(identity_str, " ");
} }
if (identity->type != NULL) { if (identity->type != NULL) {
identity_str = g_string_append(identity_str, strdup(identity->type)); identity_str = g_string_append(identity_str, identity->type);
identity_str = g_string_append(identity_str, " "); identity_str = g_string_append(identity_str, " ");
} }
if (identity->category != NULL) { if (identity->category != NULL) {
identity_str = g_string_append(identity_str, strdup(identity->category)); identity_str = g_string_append(identity_str, identity->category);
} }
cons_show(identity_str->str); cons_show(identity_str->str);
g_string_free(identity_str, FALSE); g_string_free(identity_str, FALSE);
@ -712,7 +741,7 @@ cons_show_room_invite(const char * const invitor, const char * const room,
notify_invite(display_from, room, reason); notify_invite(display_from, room, reason);
} }
FREE_SET_NULL(display_from); free(display_from);
wins_refresh_console(); wins_refresh_console();
cons_alert(); cons_alert();
@ -1278,7 +1307,7 @@ _show_roster_contacts(GSList *list, gboolean show_groups)
title = g_string_append(title, p_contact_barejid(contact)); title = g_string_append(title, p_contact_barejid(contact));
if (p_contact_name(contact) != NULL) { if (p_contact_name(contact) != NULL) {
title = g_string_append(title, " ("); title = g_string_append(title, " (");
title = g_string_append(title, strdup(p_contact_name(contact))); title = g_string_append(title, p_contact_name(contact));
title = g_string_append(title, ")"); title = g_string_append(title, ")");
} }
@ -1325,7 +1354,7 @@ _show_roster_contacts(GSList *list, gboolean show_groups)
if (groups != NULL) { if (groups != NULL) {
GString *groups_str = g_string_new(" Groups : "); GString *groups_str = g_string_new(" Groups : ");
while (groups != NULL) { while (groups != NULL) {
g_string_append(groups_str, strdup(groups->data)); g_string_append(groups_str, groups->data);
if (g_slist_next(groups) != NULL) { if (g_slist_next(groups) != NULL) {
g_string_append(groups_str, ", "); g_string_append(groups_str, ", ");
} }

View File

@ -249,8 +249,9 @@ ui_incoming_msg(const char * const from, const char * const message,
GTimeVal *tv_stamp, gboolean priv) GTimeVal *tv_stamp, gboolean priv)
{ {
gboolean win_created = FALSE; gboolean win_created = FALSE;
char *display_from; char *display_from = NULL;
win_type_t win_type; win_type_t win_type;
if (priv) { if (priv) {
win_type = WIN_PRIVATE; win_type = WIN_PRIVATE;
display_from = get_nick_from_full_jid(from); display_from = get_nick_from_full_jid(from);
@ -394,7 +395,7 @@ ui_incoming_msg(const char * const from, const char * const message,
if (prefs_get_boolean(PREF_NOTIFY_MESSAGE)) if (prefs_get_boolean(PREF_NOTIFY_MESSAGE))
notify_message(display_from, ui_index); notify_message(display_from, ui_index);
FREE_SET_NULL(display_from); free(display_from);
} }
void void
@ -447,15 +448,15 @@ ui_contact_online(const char * const barejid, const char * const resource,
// use nickname if exists // use nickname if exists
if (p_contact_name(contact) != NULL) { if (p_contact_name(contact) != NULL) {
g_string_append(display_str, strdup(p_contact_name(contact))); g_string_append(display_str, p_contact_name(contact));
} else { } else {
g_string_append(display_str, strdup(barejid)); g_string_append(display_str, barejid);
} }
// add resource if not default provided by profanity // add resource if not default provided by profanity
if (strcmp(jid->resourcepart, "__prof_default") != 0) { if (strcmp(jid->resourcepart, "__prof_default") != 0) {
g_string_append(display_str, " ("); g_string_append(display_str, " (");
g_string_append(display_str, strdup(jid->resourcepart)); g_string_append(display_str, jid->resourcepart);
g_string_append(display_str, ")"); g_string_append(display_str, ")");
} }
@ -489,15 +490,15 @@ ui_contact_offline(const char * const from, const char * const show,
// use nickname if exists // use nickname if exists
if (p_contact_name(contact) != NULL) { if (p_contact_name(contact) != NULL) {
g_string_append(display_str, strdup(p_contact_name(contact))); g_string_append(display_str, p_contact_name(contact));
} else { } else {
g_string_append(display_str, strdup(jidp->barejid)); g_string_append(display_str, jidp->barejid);
} }
// add resource if not default provided by profanity // add resource if not default provided by profanity
if (strcmp(jidp->resourcepart, "__prof_default") != 0) { if (strcmp(jidp->resourcepart, "__prof_default") != 0) {
g_string_append(display_str, " ("); g_string_append(display_str, " (");
g_string_append(display_str, strdup(jidp->resourcepart)); g_string_append(display_str, jidp->resourcepart);
g_string_append(display_str, ")"); g_string_append(display_str, ")");
} }

View File

@ -80,7 +80,7 @@ notify_invite(const char * const from, const char * const room,
_notify(message->str, 10000, "Incoming message"); _notify(message->str, 10000, "Incoming message");
g_string_free(message, FALSE); g_string_free(message, TRUE);
} }
void void
@ -102,7 +102,7 @@ notify_room_message(const char * const handle, const char * const room, int win)
_notify(text->str, 10000, "incoming message"); _notify(text->str, 10000, "incoming message");
g_string_free(text, FALSE); g_string_free(text, TRUE);
} }
void void
@ -111,7 +111,7 @@ notify_subscription(const char * const from)
GString *message = g_string_new("Subscription request: \n"); GString *message = g_string_new("Subscription request: \n");
g_string_append(message, from); g_string_append(message, from);
_notify(message->str, 10000, "Incomming message"); _notify(message->str, 10000, "Incomming message");
g_string_free(message, FALSE); g_string_free(message, TRUE);
} }
void void

View File

@ -22,6 +22,7 @@
#include "config.h" #include "config.h"
#include <assert.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
@ -63,6 +64,8 @@ create_status_bar(void)
mvwprintw(status_bar, 0, cols - 31, _active); mvwprintw(status_bar, 0, cols - 31, _active);
wattroff(status_bar, COLOUR_STATUS_BRACKET); wattroff(status_bar, COLOUR_STATUS_BRACKET);
if (last_time != NULL)
g_date_time_unref(last_time);
last_time = g_date_time_new_now_local(); last_time = g_date_time_new_now_local();
dirty = TRUE; dirty = TRUE;
@ -76,6 +79,8 @@ status_bar_refresh(void)
if (elapsed >= 60000000) { if (elapsed >= 60000000) {
dirty = TRUE; dirty = TRUE;
if (last_time != NULL)
g_date_time_unref(last_time);
last_time = g_date_time_new_now_local(); last_time = g_date_time_new_now_local();
} }
@ -113,6 +118,8 @@ status_bar_resize(void)
if (message != NULL) if (message != NULL)
mvwprintw(status_bar, 0, 10, message); mvwprintw(status_bar, 0, 10, message);
if (last_time != NULL)
g_date_time_unref(last_time);
last_time = g_date_time_new_now_local(); last_time = g_date_time_new_now_local();
dirty = TRUE; dirty = TRUE;
} }
@ -184,14 +191,12 @@ status_bar_get_password(void)
void void
status_bar_print_message(const char * const msg) status_bar_print_message(const char * const msg)
{ {
if (message != NULL) {
free(message);
message = NULL;
}
werase(status_bar); werase(status_bar);
message = (char *) malloc((strlen(msg) + 1) * sizeof(char)); if (message != NULL) {
free(message);
}
message = (char *) malloc(strlen(msg) + 1);
strcpy(message, msg); strcpy(message, msg);
mvwprintw(status_bar, 0, 10, message); mvwprintw(status_bar, 0, 10, message);
@ -270,6 +275,7 @@ static void
_status_bar_update_time(void) _status_bar_update_time(void)
{ {
gchar *date_fmt = g_date_time_format(last_time, "%H:%M"); gchar *date_fmt = g_date_time_format(last_time, "%H:%M");
assert(date_fmt != NULL);
wattron(status_bar, COLOUR_STATUS_BRACKET); wattron(status_bar, COLOUR_STATUS_BRACKET);
mvwaddch(status_bar, 0, 1, '['); mvwaddch(status_bar, 0, 1, '[');
@ -279,7 +285,7 @@ _status_bar_update_time(void)
mvwaddch(status_bar, 0, 7, ']'); mvwaddch(status_bar, 0, 7, ']');
wattroff(status_bar, COLOUR_STATUS_BRACKET); wattroff(status_bar, COLOUR_STATUS_BRACKET);
free(date_fmt); g_free(date_fmt);
dirty = TRUE; dirty = TRUE;
} }

View File

@ -87,7 +87,7 @@ title_bar_refresh(void)
free(current_title); free(current_title);
} }
current_title = (char *) malloc((strlen(recipient) + 1) * sizeof(char)); current_title = (char *) malloc(strlen(recipient) + 1);
strcpy(current_title, recipient); strcpy(current_title, recipient);
title_bar_draw(); title_bar_draw();
@ -113,7 +113,7 @@ title_bar_show(const char * const title)
if (current_title != NULL) if (current_title != NULL)
free(current_title); free(current_title);
current_title = (char *) malloc((strlen(title) + 1) * sizeof(char)); current_title = (char *) malloc(strlen(title) + 1);
strcpy(current_title, title); strcpy(current_title, title);
_title_bar_draw_title(); _title_bar_draw_title();
} }
@ -138,7 +138,7 @@ title_bar_set_recipient(const char * const from)
free(current_title); free(current_title);
} }
current_title = (char *) malloc((strlen(from) + 1) * sizeof(char)); current_title = (char *) malloc(strlen(from) + 1);
strcpy(current_title, from); strcpy(current_title, from);
dirty = TRUE; dirty = TRUE;
@ -160,10 +160,10 @@ title_bar_set_typing(gboolean is_typing)
} }
if (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); sprintf(current_title, "%s (typing...)", recipient);
} else { } else {
current_title = (char *) malloc((strlen(recipient) + 1) * sizeof(char)); current_title = (char *) malloc(strlen(recipient) + 1);
strcpy(current_title, recipient); strcpy(current_title, recipient);
} }

View File

@ -179,6 +179,7 @@ void cons_show_software_version(const char * const jid,
const char * const version, const char * const os); const char * const version, const char * const os);
void cons_show_account_list(gchar **accounts); void cons_show_account_list(gchar **accounts);
void cons_show_room_list(GSList *room, const char * const conference_node); void cons_show_room_list(GSList *room, const char * const conference_node);
void cons_show_bookmarks(const GList *list);
void cons_show_disco_items(GSList *items, const char * const jid); void cons_show_disco_items(GSList *items, const char * const jid);
void cons_show_disco_info(const char *from, GSList *identities, GSList *features); void cons_show_disco_info(const char *from, GSList *identities, GSList *features);
void cons_show_room_invite(const char * const invitor, const char * const room, void cons_show_room_invite(const char * const invitor, const char * const room,

245
src/xmpp/bookmark.c Normal file
View File

@ -0,0 +1,245 @@
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <strophe.h>
#include "log.h"
#include "muc.h"
#include "ui/ui.h"
#include "xmpp/connection.h"
#include "xmpp/stanza.h"
#include "xmpp/xmpp.h"
#include "xmpp/bookmark.h"
#define BOOKMARK_TIMEOUT 5000
/* TODO: replace with a preference */
#define BOOKMARK_AUTOJOIN_MAX 5
static int autojoin_count;
static Autocomplete bookmark_ac;
static GList *bookmark_list;
static int _bookmark_handle_result(xmpp_conn_t * const conn,
xmpp_stanza_t * const stanza, void * const userdata);
static int _bookmark_handle_delete(xmpp_conn_t * const conn,
void * const userdata);
static void _bookmark_item_destroy(gpointer item);
void
bookmark_request(void)
{
char *id;
xmpp_conn_t *conn = connection_get_conn();
xmpp_ctx_t *ctx = connection_get_ctx();
xmpp_stanza_t *iq;
id = get_unique_id();
if (!id) {
return;
}
autojoin_count = 0;
if (bookmark_ac != NULL) {
autocomplete_free(bookmark_ac);
}
bookmark_ac = autocomplete_new();
if (bookmark_list != NULL) {
g_list_free_full(bookmark_list, _bookmark_item_destroy);
bookmark_list = NULL;
}
xmpp_timed_handler_add(conn, _bookmark_handle_delete, BOOKMARK_TIMEOUT, id);
xmpp_id_handler_add(conn, _bookmark_handle_result, id, id);
iq = stanza_create_storage_bookmarks(ctx);
xmpp_stanza_set_id(iq, id);
xmpp_send(conn, iq);
xmpp_stanza_release(iq);
}
void
bookmark_add(const char *jid, const char *nick, gboolean autojoin)
{
/* TODO: send request */
/* TODO: manage bookmark_list */
/* this may be command for modifying */
autocomplete_remove(bookmark_ac, jid);
autocomplete_add(bookmark_ac, strdup(jid));
}
void
bookmark_remove(const char *jid, gboolean autojoin)
{
/* TODO: manage bookmark_list */
if (autojoin) {
/* TODO: just set autojoin=0 */
} else {
/* TODO: send request */
autocomplete_remove(bookmark_ac, jid);
}
}
const GList *
bookmark_get_list(void)
{
return bookmark_list;
}
char *
bookmark_find(char *search_str)
{
return autocomplete_complete(bookmark_ac, search_str);
}
void
bookmark_autocomplete_reset(void)
{
if (bookmark_ac != NULL) {
autocomplete_reset(bookmark_ac);
}
}
static int
_bookmark_handle_result(xmpp_conn_t * const conn,
xmpp_stanza_t * const stanza, void * const userdata)
{
xmpp_ctx_t *ctx = connection_get_ctx();
char *id = (char *)userdata;
xmpp_stanza_t *ptr;
xmpp_stanza_t *nick;
char *name;
char *jid;
char *autojoin;
gboolean autojoin_val;
Jid *my_jid;
Bookmark *item;
xmpp_timed_handler_delete(conn, _bookmark_handle_delete);
g_free(id);
name = xmpp_stanza_get_name(stanza);
if (!name || strcmp(name, STANZA_NAME_IQ) != 0) {
return 0;
}
ptr = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_QUERY);
if (!ptr) {
return 0;
}
ptr = xmpp_stanza_get_child_by_name(ptr, STANZA_NAME_STORAGE);
if (!ptr) {
return 0;
}
if (bookmark_ac == NULL) {
bookmark_ac = autocomplete_new();
}
my_jid = jid_create(jabber_get_fulljid());
ptr = xmpp_stanza_get_children(ptr);
while (ptr) {
name = xmpp_stanza_get_name(ptr);
if (!name || strcmp(name, STANZA_NAME_CONFERENCE) != 0) {
ptr = xmpp_stanza_get_next(ptr);
continue;
}
jid = xmpp_stanza_get_attribute(ptr, STANZA_ATTR_JID);
if (!jid) {
ptr = xmpp_stanza_get_next(ptr);
continue;
}
log_debug("Handle bookmark for %s", jid);
name = NULL;
nick = xmpp_stanza_get_child_by_name(ptr, "nick");
if (nick) {
char *tmp;
tmp = xmpp_stanza_get_text(nick);
if (tmp) {
name = strdup(tmp);
xmpp_free(ctx, tmp);
}
}
autojoin = xmpp_stanza_get_attribute(ptr, "autojoin");
if (autojoin && (strcmp(autojoin, "1") == 0 || strcmp(autojoin, "true") == 0)) {
autojoin_val = TRUE;
} else {
autojoin_val = FALSE;
}
autocomplete_add(bookmark_ac, strdup(jid));
item = malloc(sizeof(*item));
item->jid = strdup(jid);
item->nick = name;
item->autojoin = autojoin_val;
bookmark_list = g_list_append(bookmark_list, item);
/* TODO: preference whether autojoin */
if (autojoin_val) {
if (autojoin_count < BOOKMARK_AUTOJOIN_MAX) {
Jid *room_jid;
++autojoin_count;
if (name == NULL) {
name = my_jid->localpart;
}
log_debug("Autojoin %s with nick=%s", jid, name);
room_jid = jid_create_from_bare_and_resource(jid, name);
if (!muc_room_is_active(room_jid)) {
presence_join_room(room_jid);
/* TODO: this should be removed after fixing #195 */
ui_room_join(room_jid);
}
jid_destroy(room_jid);
} else {
log_debug("Rejected autojoin %s (maximum has been reached)", jid);
}
}
ptr = xmpp_stanza_get_next(ptr);
}
jid_destroy(my_jid);
return 0;
}
static int
_bookmark_handle_delete(xmpp_conn_t * const conn,
void * const userdata)
{
char *id = (char *)userdata;
assert(id != NULL);
log_debug("Timeout for handler with id=%s", id);
xmpp_id_handler_delete(conn, _bookmark_handle_result, id);
g_free(id);
return 0;
}
static void
_bookmark_item_destroy(gpointer item)
{
Bookmark *p = (Bookmark *)item;
if (p == NULL) {
return;
}
free(p->jid);
free(p->nick);
free(p);
}

22
src/xmpp/bookmark.h Normal file
View File

@ -0,0 +1,22 @@
#ifndef BOOKMARK_H
#define BOOKMARK_H
#include <glib.h>
struct bookmark_t {
char *jid;
char *nick;
gboolean autojoin;
};
typedef struct bookmark_t Bookmark;
void bookmark_request(void);
void bookmark_add(const char *jid, const char *nick, gboolean autojoin);
void bookmark_remove(const char *jid, gboolean autojoin);
const GList *bookmark_get_list(void);
char *bookmark_find(char *search_str);
void bookmark_autocomplete_reset(void);
#endif

View File

@ -122,7 +122,7 @@ caps_create_sha1_str(xmpp_stanza_t * const query)
GSList *form_names = NULL; GSList *form_names = NULL;
DataForm *form = NULL; DataForm *form = NULL;
FormField *field = 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(""); 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"); lang = xmpp_stanza_get_attribute(child, "xml:lang");
name = xmpp_stanza_get_attribute(child, "name"); 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, "/"); g_string_append(identity_str, "/");
if (type != NULL) { if (type != NULL) {
g_string_append(identity_str, g_strdup(type)); g_string_append(identity_str, type);
} }
g_string_append(identity_str, "/"); g_string_append(identity_str, "/");
if (lang != NULL) { if (lang != NULL) {
g_string_append(identity_str, g_strdup(lang)); g_string_append(identity_str, lang);
} }
g_string_append(identity_str, "/"); g_string_append(identity_str, "/");
if (name != NULL) { if (name != NULL) {
g_string_append(identity_str, g_strdup(name)); g_string_append(identity_str, name);
} }
g_string_append(identity_str, "<"); g_string_append(identity_str, "<");
identities = g_slist_insert_sorted(identities, g_strdup(identity_str->str), (GCompareFunc)octet_compare); 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) { } else if (g_strcmp0(xmpp_stanza_get_name(child), STANZA_NAME_X) == 0) {
if (strcmp(xmpp_stanza_get_ns(child), STANZA_NS_DATA) == 0) { if (strcmp(xmpp_stanza_get_ns(child), STANZA_NS_DATA) == 0) {
form = stanza_create_form(child); form = stanza_create_form(child);
form_names = g_slist_insert_sorted(form_names, strdup(form->form_type), (GCompareFunc)octet_compare); form_names = g_slist_insert_sorted(form_names, g_strdup(form->form_type), (GCompareFunc)octet_compare);
g_hash_table_insert(forms, strdup(form->form_type), form); g_hash_table_insert(forms, g_strdup(form->form_type), form);
} }
} }
child = xmpp_stanza_get_next(child); child = xmpp_stanza_get_next(child);
@ -165,13 +165,13 @@ caps_create_sha1_str(xmpp_stanza_t * const query)
GSList *curr = identities; GSList *curr = identities;
while (curr != NULL) { while (curr != NULL) {
g_string_append(s, strdup(curr->data)); g_string_append(s, curr->data);
curr = g_slist_next(curr); curr = g_slist_next(curr);
} }
curr = features; curr = features;
while (curr != NULL) { while (curr != NULL) {
g_string_append(s, strdup(curr->data)); g_string_append(s, curr->data);
g_string_append(s, "<"); g_string_append(s, "<");
curr = g_slist_next(curr); curr = g_slist_next(curr);
} }
@ -179,17 +179,17 @@ caps_create_sha1_str(xmpp_stanza_t * const query)
curr = form_names; curr = form_names;
while (curr != NULL) { while (curr != NULL) {
form = g_hash_table_lookup(forms, curr->data); 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, "<"); g_string_append(s, "<");
GSList *curr_field = form->fields; GSList *curr_field = form->fields;
while (curr_field != NULL) { while (curr_field != NULL) {
field = curr_field->data; field = curr_field->data;
g_string_append(s, strdup(field->var)); g_string_append(s, field->var);
g_string_append(s, "<"); g_string_append(s, "<");
GSList *curr_value = field->values; GSList *curr_value = field->values;
while (curr_value != NULL) { while (curr_value != NULL) {
g_string_append(s, strdup(curr_value->data)); g_string_append(s, curr_value->data);
g_string_append(s, "<"); g_string_append(s, "<");
curr_value = g_slist_next(curr_value); 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); char *result = g_base64_encode(md_value, md_len);
g_string_free(s, TRUE); g_string_free(s, TRUE);
g_slist_free_full(identities, free); g_slist_free_full(identities, g_free);
g_slist_free_full(features, free); g_slist_free_full(features, g_free);
g_slist_free_full(form_names, free); g_slist_free_full(form_names, g_free);
//g_hash_table_destroy(forms); g_hash_table_destroy(forms);
return result; return result;
} }
@ -280,13 +280,14 @@ caps_create_query_response_stanza(xmpp_ctx_t * const ctx)
xmpp_stanza_add_child(query, feature_version); xmpp_stanza_add_child(query, feature_version);
xmpp_stanza_add_child(query, feature_ping); xmpp_stanza_add_child(query, feature_ping);
xmpp_stanza_release(identity); xmpp_stanza_release(feature_ping);
xmpp_stanza_release(feature_muc);
xmpp_stanza_release(feature_discoinfo);
xmpp_stanza_release(feature_discoitems);
xmpp_stanza_release(feature_caps);
xmpp_stanza_release(feature_version); xmpp_stanza_release(feature_version);
xmpp_stanza_release(feature_muc);
xmpp_stanza_release(feature_discoitems);
xmpp_stanza_release(feature_discoinfo);
xmpp_stanza_release(feature_chatstates); xmpp_stanza_release(feature_chatstates);
xmpp_stanza_release(feature_caps);
xmpp_stanza_release(identity);
return query; return query;
} }
@ -301,17 +302,16 @@ static void
_caps_destroy(Capabilities *caps) _caps_destroy(Capabilities *caps)
{ {
if (caps != NULL) { if (caps != NULL) {
FREE_SET_NULL(caps->category); free(caps->category);
FREE_SET_NULL(caps->type); free(caps->type);
FREE_SET_NULL(caps->name); free(caps->name);
FREE_SET_NULL(caps->software); free(caps->software);
FREE_SET_NULL(caps->software_version); free(caps->software_version);
FREE_SET_NULL(caps->os); free(caps->os);
FREE_SET_NULL(caps->os_version); free(caps->os_version);
if (caps->features != NULL) { if (caps->features != NULL) {
g_slist_free_full(caps->features, free); g_slist_free_full(caps->features, free);
caps->features = NULL;
} }
FREE_SET_NULL(caps); free(caps);
} }
} }

View File

@ -33,6 +33,7 @@
#include "log.h" #include "log.h"
#include "muc.h" #include "muc.h"
#include "profanity.h" #include "profanity.h"
#include "xmpp/bookmark.h"
#include "xmpp/capabilities.h" #include "xmpp/capabilities.h"
#include "xmpp/connection.h" #include "xmpp/connection.h"
#include "xmpp/iq.h" #include "xmpp/iq.h"
@ -494,6 +495,7 @@ _connection_handler(xmpp_conn_t * const conn,
} }
roster_request(); roster_request();
bookmark_request();
jabber_conn.conn_status = JABBER_CONNECTED; jabber_conn.conn_status = JABBER_CONNECTED;
if (prefs_get_reconnect() != 0) { if (prefs_get_reconnect() != 0) {

View File

@ -247,6 +247,12 @@ _iq_handle_version_get(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
xmpp_send(conn, response); xmpp_send(conn, response);
g_free(version_str);
xmpp_stanza_release(name_txt);
xmpp_stanza_release(version_txt);
xmpp_stanza_release(name);
xmpp_stanza_release(version);
xmpp_stanza_release(query);
xmpp_stanza_release(response); xmpp_stanza_release(response);
} }
@ -302,6 +308,7 @@ _iq_handle_discoinfo_get(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
xmpp_stanza_add_child(response, query); xmpp_stanza_add_child(response, query);
xmpp_send(conn, response); xmpp_send(conn, response);
xmpp_stanza_release(query);
xmpp_stanza_release(response); xmpp_stanza_release(response);
} }
@ -312,10 +319,10 @@ static void
_identity_destroy(DiscoIdentity *identity) _identity_destroy(DiscoIdentity *identity)
{ {
if (identity != NULL) { if (identity != NULL) {
FREE_SET_NULL(identity->name); free(identity->name);
FREE_SET_NULL(identity->type); free(identity->type);
FREE_SET_NULL(identity->category); free(identity->category);
FREE_SET_NULL(identity); free(identity);
} }
} }
@ -323,9 +330,9 @@ static void
_item_destroy(DiscoItem *item) _item_destroy(DiscoItem *item)
{ {
if (item != NULL) { if (item != NULL) {
FREE_SET_NULL(item->jid); free(item->jid);
FREE_SET_NULL(item->name); free(item->name);
FREE_SET_NULL(item); free(item);
} }
} }
@ -411,12 +418,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 sha-1 does not match given:");
log_info("Generated : %s", generated_sha1); log_info("Generated : %s", generated_sha1);
log_info("Given : %s", given_sha1); log_info("Given : %s", given_sha1);
FREE_SET_NULL(generated_sha1); g_free(generated_sha1);
g_strfreev(split); g_strfreev(split);
free(caps_key);
return 1; return 1;
} }
FREE_SET_NULL(generated_sha1); g_free(generated_sha1);
g_strfreev(split); g_strfreev(split);
// non supported hash, or legacy caps // non supported hash, or legacy caps
@ -429,14 +437,12 @@ _iq_handle_discoinfo_result(xmpp_conn_t * const conn, xmpp_stanza_t * const stan
// already cached // already cached
if (caps_contains(caps_key)) { if (caps_contains(caps_key)) {
log_info("Client info already cached."); log_info("Client info already cached.");
free(caps_key);
return 1; return 1;
} }
log_debug("Client info not cached"); log_debug("Client info not cached");
DataForm *form = NULL;
FormField *formField = NULL;
const char *category = NULL; const char *category = NULL;
const char *type = NULL; const char *type = NULL;
const char *name = NULL; const char *name = NULL;
@ -455,7 +461,8 @@ _iq_handle_discoinfo_result(xmpp_conn_t * const conn, xmpp_stanza_t * const stan
xmpp_stanza_t *softwareinfo = xmpp_stanza_get_child_by_ns(query, STANZA_NS_DATA); xmpp_stanza_t *softwareinfo = xmpp_stanza_get_child_by_ns(query, STANZA_NS_DATA);
if (softwareinfo != NULL) { if (softwareinfo != NULL) {
form = stanza_create_form(softwareinfo); DataForm *form = stanza_create_form(softwareinfo);
FormField *formField = NULL;
if (g_strcmp0(form->form_type, STANZA_DATAFORM_SOFTWARE) == 0) { if (g_strcmp0(form->form_type, STANZA_DATAFORM_SOFTWARE) == 0) {
GSList *field = form->fields; GSList *field = form->fields;
@ -475,6 +482,8 @@ _iq_handle_discoinfo_result(xmpp_conn_t * const conn, xmpp_stanza_t * const stan
field = g_slist_next(field); field = g_slist_next(field);
} }
} }
stanza_destroy_form(form);
} }
xmpp_stanza_t *child = xmpp_stanza_get_children(query); xmpp_stanza_t *child = xmpp_stanza_get_children(query);
@ -489,7 +498,6 @@ _iq_handle_discoinfo_result(xmpp_conn_t * const conn, xmpp_stanza_t * const stan
caps_add(caps_key, category, type, name, software, software_version, caps_add(caps_key, category, type, name, software, software_version,
os, os_version, features); os, os_version, features);
//stanza_destroy_form(form);
free(caps_key); free(caps_key);
} }

View File

@ -212,6 +212,9 @@ _conference_message_handler(xmpp_conn_t * const conn,
} }
Jid *jidp = jid_create(invitor_jid); Jid *jidp = jid_create(invitor_jid);
if (jidp == NULL) {
return 1;
}
invitor = jidp->barejid; invitor = jidp->barejid;
xmpp_stanza_t *reason_st = xmpp_stanza_get_child_by_name(invite, STANZA_NAME_REASON); 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); Jid *jidp = jid_create(from);
if (jidp == NULL) {
return 1;
}
invitor = jidp->barejid; invitor = jidp->barejid;
reason = xmpp_stanza_get_attribute(x_groupchat, STANZA_ATTR_REASON); reason = xmpp_stanza_get_attribute(x_groupchat, STANZA_ATTR_REASON);
@ -274,6 +280,7 @@ _groupchat_message_handler(xmpp_conn_t * const conn,
message = xmpp_stanza_get_text(subject); message = xmpp_stanza_get_text(subject);
if (message != NULL) { if (message != NULL) {
prof_handle_room_subject(jid->barejid, message); prof_handle_room_subject(jid->barejid, message);
xmpp_free(ctx, message);
} }
jid_destroy(jid); jid_destroy(jid);

View File

@ -156,14 +156,23 @@ presence_sub_request_find(char * search_str)
gboolean gboolean
presence_sub_request_exists(const char * const bare_jid) 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) { while (requests != NULL) {
if (strcmp(requests->data, bare_jid) == 0) { if (strcmp(requests->data, bare_jid) == 0) {
return TRUE; result = TRUE;
break;
} }
requests = g_slist_next(requests); requests = g_slist_next(requests);
} }
return FALSE;
if (requests_p != NULL) {
g_slist_free_full(requests_p, free);
}
return result;
} }
void void
@ -220,20 +229,28 @@ presence_update(const resource_presence_t presence_type, const char * const msg,
static void static void
_send_room_presence(xmpp_conn_t *conn, xmpp_stanza_t *presence) _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) { while (rooms != NULL) {
const char *room = rooms->data; const char *room = rooms->data;
const char *nick = muc_get_room_nick(room); const char *nick = muc_get_room_nick(room);
if (nick != NULL) {
char *full_room_jid = create_fulljid(room, nick); char *full_room_jid = create_fulljid(room, nick);
xmpp_stanza_set_attribute(presence, STANZA_ATTR_TO, full_room_jid); xmpp_stanza_set_attribute(presence, STANZA_ATTR_TO, full_room_jid);
log_debug("Sending presence to room: %s", full_room_jid); log_debug("Sending presence to room: %s", full_room_jid);
xmpp_send(conn, presence); xmpp_send(conn, presence);
free(full_room_jid); free(full_room_jid);
}
rooms = g_list_next(rooms); rooms = g_list_next(rooms);
} }
g_list_free(rooms);
if (rooms_p != NULL) {
g_list_free(rooms_p);
}
} }
void void
@ -347,9 +364,13 @@ _subscribe_handler(xmpp_conn_t * const conn,
xmpp_stanza_t * const stanza, void * const userdata) xmpp_stanza_t * const stanza, void * const userdata)
{ {
char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); 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); 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); prof_handle_subscription(from_jid->barejid, PRESENCE_SUBSCRIBE);
autocomplete_add(sub_requests_ac, strdup(from_jid->barejid)); 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 *my_jid = jid_create(jid);
Jid *from_jid = jid_create(from); 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); 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(my_jid);
jid_destroy(from_jid); jid_destroy(from_jid);
@ -420,6 +446,11 @@ _available_handler(xmpp_conn_t * const conn,
Jid *my_jid = jid_create(jid); Jid *my_jid = jid_create(jid);
Jid *from_jid = jid_create(from); 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 *show_str = stanza_get_show(stanza, "online");
char *status_str = stanza_get_status(stanza, NULL); char *status_str = stanza_get_status(stanza, NULL);
@ -471,8 +502,9 @@ _available_handler(xmpp_conn_t * const conn,
last_activity); last_activity);
} }
FREE_SET_NULL(status_str); free(caps_key);
FREE_SET_NULL(show_str); free(status_str);
free(show_str);
jid_destroy(my_jid); jid_destroy(my_jid);
jid_destroy(from_jid); jid_destroy(from_jid);
@ -515,6 +547,10 @@ _get_caps_key(xmpp_stanza_t * const stanza)
log_debug("Presence contains capabilities."); log_debug("Presence contains capabilities.");
if (node == NULL) {
return NULL;
}
// xep-0115 // xep-0115
if ((hash_type != NULL) && (strcmp(hash_type, "sha-1") == 0)) { if ((hash_type != NULL) && (strcmp(hash_type, "sha-1") == 0)) {
log_debug("Hash type %s supported.", hash_type); log_debug("Hash type %s supported.", hash_type);
@ -544,6 +580,8 @@ _get_caps_key(xmpp_stanza_t * const stanza)
g_string_free(id_str, TRUE); g_string_free(id_str, TRUE);
} }
g_free(node);
return caps_key; return caps_key;
} }
@ -556,10 +594,11 @@ _room_presence_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
return 1; return 1;
} }
const char *jid = xmpp_conn_get_jid(conn);
char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
Jid *my_jid = jid_create(jid);
Jid *from_jid = jid_create(from); Jid *from_jid = jid_create(from);
if (from_jid == NULL || from_jid->resourcepart == NULL) {
return 1;
}
char *room = from_jid->barejid; char *room = from_jid->barejid;
char *nick = from_jid->resourcepart; char *nick = from_jid->resourcepart;
@ -592,7 +631,7 @@ _room_presence_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
// handle presence from room members // handle presence from room members
} else { } else {
char *type = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_TYPE); char *type = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_TYPE);
char *show_str, *status_str; char *status_str;
char *caps_key = NULL; char *caps_key = NULL;
if (stanza_contains_caps(stanza)) { if (stanza_contains_caps(stanza)) {
@ -608,12 +647,15 @@ _room_presence_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
// handle nickname change // handle nickname change
if (stanza_is_room_nick_change(stanza)) { if (stanza_is_room_nick_change(stanza)) {
char *new_nick = stanza_get_new_nick(stanza); char *new_nick = stanza_get_new_nick(stanza);
if (new_nick != NULL) {
muc_set_roster_pending_nick_change(room, new_nick, nick); muc_set_roster_pending_nick_change(room, new_nick, nick);
free(new_nick);
}
} else { } else {
prof_handle_room_member_offline(room, nick, "offline", status_str); prof_handle_room_member_offline(room, nick, "offline", status_str);
} }
} else { } else {
show_str = stanza_get_show(stanza, "online"); char *show_str = stanza_get_show(stanza, "online");
if (!muc_get_roster_received(room)) { if (!muc_get_roster_received(room)) {
muc_add_to_roster(room, nick, show_str, status_str, caps_key); muc_add_to_roster(room, nick, show_str, status_str, caps_key);
} else { } else {
@ -622,6 +664,7 @@ _room_presence_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
if (old_nick != NULL) { if (old_nick != NULL) {
muc_add_to_roster(room, nick, show_str, status_str, caps_key); muc_add_to_roster(room, nick, show_str, status_str, caps_key);
prof_handle_room_member_nick_change(room, old_nick, nick); prof_handle_room_member_nick_change(room, old_nick, nick);
free(old_nick);
} else { } else {
if (!muc_nick_in_roster(room, nick)) { if (!muc_nick_in_roster(room, nick)) {
prof_handle_room_member_online(room, nick, show_str, status_str, caps_key); prof_handle_room_member_online(room, nick, show_str, status_str, caps_key);
@ -631,13 +674,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); jid_destroy(from_jid);
return 1; return 1;

View File

@ -567,7 +567,7 @@ _roster_handle_push(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
while (resources != NULL) { while (resources != NULL) {
GString *fulljid = g_string_new(strdup(barejid)); GString *fulljid = g_string_new(strdup(barejid));
g_string_append(fulljid, "/"); g_string_append(fulljid, "/");
g_string_append(fulljid, strdup(resources->data)); g_string_append(fulljid, resources->data);
autocomplete_remove(fulljid_ac, fulljid->str); autocomplete_remove(fulljid_ac, fulljid->str);
g_string_free(fulljid, TRUE); g_string_free(fulljid, TRUE);
resources = g_list_next(resources); resources = g_list_next(resources);

View File

@ -35,6 +35,63 @@
static int _field_compare(FormField *f1, FormField *f2); static int _field_compare(FormField *f1, FormField *f2);
#if 0
xmpp_stanza_t *
stanza_create_storage_bookmarks(xmpp_ctx_t *ctx)
{
xmpp_stanza_t *iq, *pubsub, *items;
/* TODO: check pointers for NULL */
iq = xmpp_stanza_new(ctx);
pubsub = xmpp_stanza_new(ctx);
items = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(iq, STANZA_NAME_IQ);
xmpp_stanza_set_type(iq, STANZA_TYPE_GET);
xmpp_stanza_set_name(pubsub, STANZA_NAME_PUBSUB);
xmpp_stanza_set_ns(pubsub, STANZA_NS_PUBSUB);
xmpp_stanza_set_name(items, STANZA_NAME_ITEMS);
xmpp_stanza_set_attribute(items, "node", "storage:bookmarks");
xmpp_stanza_add_child(pubsub, items);
xmpp_stanza_add_child(iq, pubsub);
xmpp_stanza_release(items);
xmpp_stanza_release(pubsub);
return iq;
}
#endif
xmpp_stanza_t *
stanza_create_storage_bookmarks(xmpp_ctx_t *ctx)
{
xmpp_stanza_t *iq, *query, *storage;
/* TODO: check pointers for NULL */
iq = xmpp_stanza_new(ctx);
query = xmpp_stanza_new(ctx);
storage = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(iq, STANZA_NAME_IQ);
xmpp_stanza_set_type(iq, STANZA_TYPE_GET);
xmpp_stanza_set_ns(iq, "jabber:client");
xmpp_stanza_set_name(query, STANZA_NAME_QUERY);
xmpp_stanza_set_ns(query, "jabber:iq:private");
xmpp_stanza_set_name(storage, STANZA_NAME_STORAGE);
xmpp_stanza_set_ns(storage, "storage:bookmarks");
xmpp_stanza_add_child(query, storage);
xmpp_stanza_add_child(iq, query);
xmpp_stanza_release(storage);
xmpp_stanza_release(query);
return iq;
}
xmpp_stanza_t * xmpp_stanza_t *
stanza_create_chat_state(xmpp_ctx_t *ctx, const char * const recipient, stanza_create_chat_state(xmpp_ctx_t *ctx, const char * const recipient,
const char * const state) const char * const state)
@ -815,12 +872,11 @@ void
stanza_destroy_form(DataForm *form) stanza_destroy_form(DataForm *form)
{ {
if (form != NULL) { if (form != NULL) {
FREE_SET_NULL(form->form_type);
if (form->fields != NULL) { if (form->fields != NULL) {
GSList *curr_field = form->fields; GSList *curr_field = form->fields;
while (curr_field != NULL) { while (curr_field != NULL) {
FormField *field = curr_field->data; FormField *field = curr_field->data;
FREE_SET_NULL(field->var); free(field->var);
if ((field->values) != NULL) { if ((field->values) != NULL) {
g_slist_free_full(field->values, free); g_slist_free_full(field->values, free);
} }
@ -829,6 +885,7 @@ stanza_destroy_form(DataForm *form)
g_slist_free_full(form->fields, free); g_slist_free_full(form->fields, free);
} }
free(form->form_type);
free(form); free(form);
} }
} }
@ -916,7 +973,7 @@ stanza_attach_caps(xmpp_ctx_t * const ctx, xmpp_stanza_t * const presence)
xmpp_stanza_add_child(presence, caps); xmpp_stanza_add_child(presence, caps);
xmpp_stanza_release(caps); xmpp_stanza_release(caps);
xmpp_stanza_release(query); xmpp_stanza_release(query);
FREE_SET_NULL(sha1); g_free(sha1);
} }
const char * const char *

View File

@ -52,6 +52,9 @@
#define STANZA_NAME_INVITE "invite" #define STANZA_NAME_INVITE "invite"
#define STANZA_NAME_REASON "reason" #define STANZA_NAME_REASON "reason"
#define STANZA_NAME_GROUP "group" #define STANZA_NAME_GROUP "group"
#define STANZA_NAME_PUBSUB "pubsub"
#define STANZA_NAME_STORAGE "storage"
#define STANZA_NAME_CONFERENCE "conference"
#define STANZA_TYPE_CHAT "chat" #define STANZA_TYPE_CHAT "chat"
#define STANZA_TYPE_GROUPCHAT "groupchat" #define STANZA_TYPE_GROUPCHAT "groupchat"
@ -100,6 +103,7 @@
#define STANZA_NS_VERSION "jabber:iq:version" #define STANZA_NS_VERSION "jabber:iq:version"
#define STANZA_NS_CONFERENCE "jabber:x:conference" #define STANZA_NS_CONFERENCE "jabber:x:conference"
#define STANZA_NS_CAPTCHA "urn:xmpp:captcha" #define STANZA_NS_CAPTCHA "urn:xmpp:captcha"
#define STANZA_NS_PUBSUB "http://jabber.org/protocol/pubsub"
#define STANZA_DATAFORM_SOFTWARE "urn:xmpp:dataforms:softwareinfo" #define STANZA_DATAFORM_SOFTWARE "urn:xmpp:dataforms:softwareinfo"
@ -113,6 +117,8 @@ typedef struct data_form_t {
GSList *fields; GSList *fields;
} DataForm; } DataForm;
xmpp_stanza_t* stanza_create_storage_bookmarks(xmpp_ctx_t *ctx);
xmpp_stanza_t* stanza_create_chat_state(xmpp_ctx_t *ctx, xmpp_stanza_t* stanza_create_chat_state(xmpp_ctx_t *ctx,
const char * const recipient, const char * const state); const char * const recipient, const char * const state);