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

Merge branch 'master' into plugins

This commit is contained in:
James Booth 2014-06-15 22:50:05 +01:00
commit d2c1ecfbf4
11 changed files with 62 additions and 27 deletions

View File

@ -397,7 +397,7 @@ xdg_get_data_home(void)
} }
char * char *
generate_unique_id(char *prefix) create_unique_id(char *prefix)
{ {
static unsigned long unique_id; static unsigned long unique_id;
char *result = NULL; char *result = NULL;

View File

@ -99,7 +99,7 @@ resource_presence_t resource_presence_from_string(const char * const str);
contact_presence_t contact_presence_from_resource_presence(resource_presence_t resource_presence); contact_presence_t contact_presence_from_resource_presence(resource_presence_t resource_presence);
char * p_sha1_hash(char *str); char * p_sha1_hash(char *str);
char * generate_unique_id(char *prefix); char * create_unique_id(char *prefix);
int cmp_win_num(gconstpointer a, gconstpointer b); int cmp_win_num(gconstpointer a, gconstpointer b);
int get_next_available_win_num(GList *used); int get_next_available_win_num(GList *used);

View File

@ -576,18 +576,18 @@ _free_room(ChatRoom *room)
free(room->subject); free(room->subject);
free(room->password); free(room->password);
if (room->roster != NULL) { if (room->roster != NULL) {
g_hash_table_remove_all(room->roster); g_hash_table_destroy(room->roster);
} }
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_destroy(room->nick_changes);
} }
free(room);
if (room->pending_broadcasts != NULL) { if (room->pending_broadcasts != NULL) {
g_list_free_full(room->pending_broadcasts, free); g_list_free_full(room->pending_broadcasts, free);
} }
free(room);
} }
} }

View File

@ -104,10 +104,12 @@ static void
cb_write_fingerprints(void *opdata) cb_write_fingerprints(void *opdata)
{ {
gcry_error_t err = 0; gcry_error_t err = 0;
gchar *data_home = xdg_get_data_home();
gchar *account_dir = str_replace(jid, "@", "_at_");
gchar *data_home = xdg_get_data_home();
GString *basedir = g_string_new(data_home); GString *basedir = g_string_new(data_home);
free(data_home);
gchar *account_dir = str_replace(jid, "@", "_at_");
g_string_append(basedir, "/profanity/otr/"); g_string_append(basedir, "/profanity/otr/");
g_string_append(basedir, account_dir); g_string_append(basedir, account_dir);
g_string_append(basedir, "/"); g_string_append(basedir, "/");
@ -174,9 +176,10 @@ _otr_on_connect(ProfAccount *account)
log_info("Loading OTR key for %s", jid); log_info("Loading OTR key for %s", jid);
gchar *data_home = xdg_get_data_home(); gchar *data_home = xdg_get_data_home();
gchar *account_dir = str_replace(jid, "@", "_at_");
GString *basedir = g_string_new(data_home); GString *basedir = g_string_new(data_home);
free(data_home);
gchar *account_dir = str_replace(jid, "@", "_at_");
g_string_append(basedir, "/profanity/otr/"); g_string_append(basedir, "/profanity/otr/");
g_string_append(basedir, account_dir); g_string_append(basedir, account_dir);
g_string_append(basedir, "/"); g_string_append(basedir, "/");
@ -256,9 +259,10 @@ _otr_keygen(ProfAccount *account)
jid = strdup(account->jid); jid = strdup(account->jid);
gchar *data_home = xdg_get_data_home(); gchar *data_home = xdg_get_data_home();
gchar *account_dir = str_replace(jid, "@", "_at_");
GString *basedir = g_string_new(data_home); GString *basedir = g_string_new(data_home);
free(data_home);
gchar *account_dir = str_replace(jid, "@", "_at_");
g_string_append(basedir, "/profanity/otr/"); g_string_append(basedir, "/profanity/otr/");
g_string_append(basedir, account_dir); g_string_append(basedir, account_dir);
g_string_append(basedir, "/"); g_string_append(basedir, "/");

View File

@ -154,11 +154,13 @@ wins_get_by_recipient(const char * const recipient)
while (curr != NULL) { while (curr != NULL) {
ProfWin *window = curr->data; ProfWin *window = curr->data;
if (g_strcmp0(window->from, recipient) == 0) { if (g_strcmp0(window->from, recipient) == 0) {
g_list_free(values);
return window; return window;
} }
curr = g_list_next(curr); curr = g_list_next(curr);
} }
g_list_free(values);
return NULL; return NULL;
} }
@ -172,11 +174,13 @@ wins_get_num(ProfWin *window)
gconstpointer num_p = curr->data; gconstpointer num_p = curr->data;
ProfWin *curr_win = g_hash_table_lookup(windows, num_p); ProfWin *curr_win = g_hash_table_lookup(windows, num_p);
if (g_strcmp0(curr_win->from, window->from) == 0) { if (g_strcmp0(curr_win->from, window->from) == 0) {
g_list_free(keys);
return GPOINTER_TO_INT(num_p); return GPOINTER_TO_INT(num_p);
} }
curr = g_list_next(curr); curr = g_list_next(curr);
} }
g_list_free(keys);
return -1; return -1;
} }
@ -238,6 +242,7 @@ wins_new(const char * const from, win_type_t type)
int cols = getmaxx(stdscr); int cols = getmaxx(stdscr);
ProfWin *new = win_create(from, cols, type); ProfWin *new = win_create(from, cols, type);
g_hash_table_insert(windows, GINT_TO_POINTER(result), new); g_hash_table_insert(windows, GINT_TO_POINTER(result), new);
g_list_free(keys);
return new; return new;
} }

View File

@ -401,8 +401,9 @@ _send_bookmarks(void)
xmpp_stanza_t *iq = xmpp_stanza_new(ctx); xmpp_stanza_t *iq = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(iq, STANZA_NAME_IQ); xmpp_stanza_set_name(iq, STANZA_NAME_IQ);
char *id = generate_unique_id("bookmarks_update"); char *id = create_unique_id("bookmarks_update");
xmpp_stanza_set_id(iq, id); xmpp_stanza_set_id(iq, id);
free(id);
xmpp_stanza_set_type(iq, STANZA_TYPE_SET); xmpp_stanza_set_type(iq, STANZA_TYPE_SET);
xmpp_stanza_t *query = xmpp_stanza_new(ctx); xmpp_stanza_t *query = xmpp_stanza_new(ctx);

View File

@ -238,6 +238,7 @@ caps_create_query_response_stanza(xmpp_ctx_t * const ctx)
#endif #endif
} }
xmpp_stanza_set_attribute(identity, "name", name_str->str); xmpp_stanza_set_attribute(identity, "name", name_str->str);
g_string_free(name_str, TRUE);
xmpp_stanza_t *feature_caps = xmpp_stanza_new(ctx); xmpp_stanza_t *feature_caps = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(feature_caps, STANZA_NAME_FEATURE); xmpp_stanza_set_name(feature_caps, STANZA_NAME_FEATURE);

View File

@ -118,7 +118,13 @@ _jabber_connect_with_account(const ProfAccount * const account)
log_info("Connecting using account: %s", account->name); log_info("Connecting using account: %s", account->name);
// save account name and password for reconnect // save account name and password for reconnect
if (saved_account.name != NULL) {
free(saved_account.name);
}
saved_account.name = strdup(account->name); saved_account.name = strdup(account->name);
if (saved_account.passwd != NULL) {
free(saved_account.passwd);
}
saved_account.passwd = strdup(account->password); saved_account.passwd = strdup(account->password);
// connect with fulljid // connect with fulljid
@ -203,7 +209,11 @@ _jabber_disconnect(void)
static void static void
_jabber_shutdown(void) _jabber_shutdown(void)
{ {
_connection_free_saved_account();
_connection_free_saved_details();
_connection_free_session_data();
xmpp_shutdown(); xmpp_shutdown();
free(jabber_conn.log);
} }
static void static void
@ -353,6 +363,9 @@ _jabber_connect(const char * const fulljid, const char * const passwd,
jid_destroy(jid); jid_destroy(jid);
log_info("Connecting as %s", fulljid); log_info("Connecting as %s", fulljid);
if (jabber_conn.log != NULL) {
free(jabber_conn.log);
}
jabber_conn.log = _xmpp_get_file_logger(); jabber_conn.log = _xmpp_get_file_logger();
if (jabber_conn.conn != NULL) { if (jabber_conn.conn != NULL) {

View File

@ -116,7 +116,7 @@ _presence_subscription(const char * const jid, const jabber_subscr_t action)
} }
xmpp_stanza_t *presence = xmpp_stanza_new(ctx); xmpp_stanza_t *presence = xmpp_stanza_new(ctx);
char *id = generate_unique_id("sub"); char *id = create_unique_id("sub");
xmpp_stanza_set_id(presence, id); xmpp_stanza_set_id(presence, id);
xmpp_stanza_set_name(presence, STANZA_NAME_PRESENCE); xmpp_stanza_set_name(presence, STANZA_NAME_PRESENCE);
xmpp_stanza_set_type(presence, type); xmpp_stanza_set_type(presence, type);
@ -125,6 +125,7 @@ _presence_subscription(const char * const jid, const jabber_subscr_t action)
xmpp_stanza_release(presence); xmpp_stanza_release(presence);
jid_destroy(jidp); jid_destroy(jidp);
free(id);
} }
static GSList * static GSList *
@ -207,7 +208,7 @@ _presence_update(const resource_presence_t presence_type, const char * const msg
connection_set_priority(pri); connection_set_priority(pri);
xmpp_stanza_t *presence = stanza_create_presence(ctx); xmpp_stanza_t *presence = stanza_create_presence(ctx);
char *id = generate_unique_id("presence"); char *id = create_unique_id("presence");
xmpp_stanza_set_id(presence, id); xmpp_stanza_set_id(presence, id);
stanza_attach_show(ctx, presence, show); stanza_attach_show(ctx, presence, show);
stanza_attach_status(ctx, presence, msg); stanza_attach_status(ctx, presence, msg);
@ -224,6 +225,7 @@ _presence_update(const resource_presence_t presence_type, const char * const msg
last = STANZA_TEXT_ONLINE; last = STANZA_TEXT_ONLINE;
} }
accounts_set_last_presence(jabber_get_account_name(), last); accounts_set_last_presence(jabber_get_account_name(), last);
free(id);
} }
static void static void
@ -545,6 +547,7 @@ _available_handler(xmpp_conn_t * const conn,
if (priority_str != NULL) { if (priority_str != NULL) {
priority = atoi(priority_str); priority = atoi(priority_str);
} }
free(priority_str);
} }
resource_presence_t presence = resource_presence_from_string(show_str); resource_presence_t presence = resource_presence_from_string(show_str);
@ -622,9 +625,10 @@ _get_caps_key(xmpp_stanza_t * const stanza)
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);
caps_key = strdup(node); caps_key = strdup(node);
id = generate_unique_id("caps"); id = create_unique_id("caps");
_send_caps_request(node, caps_key, id, from); _send_caps_request(node, caps_key, id, from);
free(id);
// unsupported hash or legacy capabilities // unsupported hash or legacy capabilities
} else { } else {

View File

@ -127,7 +127,7 @@ _roster_send_add_to_group(const char * const group, PContact contact)
new_groups = g_slist_append(new_groups, strdup(group)); new_groups = g_slist_append(new_groups, strdup(group));
// add an id handler to handle the response // add an id handler to handle the response
char *unique_id = generate_unique_id(NULL); char *unique_id = create_unique_id(NULL);
GroupData *data = malloc(sizeof(GroupData)); GroupData *data = malloc(sizeof(GroupData));
data->group = strdup(group); data->group = strdup(group);
if (p_contact_name(contact) != NULL) { if (p_contact_name(contact) != NULL) {
@ -176,7 +176,7 @@ _roster_send_remove_from_group(const char * const group, PContact contact)
xmpp_ctx_t * const ctx = connection_get_ctx(); xmpp_ctx_t * const ctx = connection_get_ctx();
// add an id handler to handle the response // add an id handler to handle the response
char *unique_id = generate_unique_id(NULL); char *unique_id = create_unique_id(NULL);
GroupData *data = malloc(sizeof(GroupData)); GroupData *data = malloc(sizeof(GroupData));
data->group = strdup(group); data->group = strdup(group);
if (p_contact_name(contact) != NULL) { if (p_contact_name(contact) != NULL) {

View File

@ -100,7 +100,7 @@ stanza_create_bookmarks_pubsub_add(xmpp_ctx_t *ctx, const char * const jid,
{ {
xmpp_stanza_t *stanza = xmpp_stanza_new(ctx); xmpp_stanza_t *stanza = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(stanza, STANZA_NAME_IQ); xmpp_stanza_set_name(stanza, STANZA_NAME_IQ);
char *id = generate_unique_id("bookmark_add"); char *id = create_unique_id("bookmark_add");
xmpp_stanza_set_id(stanza, id); xmpp_stanza_set_id(stanza, id);
xmpp_stanza_set_type(stanza, STANZA_TYPE_SET); xmpp_stanza_set_type(stanza, STANZA_TYPE_SET);
@ -196,8 +196,9 @@ stanza_create_chat_state(xmpp_ctx_t *ctx, const char * const recipient,
xmpp_stanza_set_name(msg, STANZA_NAME_MESSAGE); xmpp_stanza_set_name(msg, STANZA_NAME_MESSAGE);
xmpp_stanza_set_type(msg, STANZA_TYPE_CHAT); xmpp_stanza_set_type(msg, STANZA_TYPE_CHAT);
xmpp_stanza_set_attribute(msg, STANZA_ATTR_TO, recipient); xmpp_stanza_set_attribute(msg, STANZA_ATTR_TO, recipient);
char *id = generate_unique_id(NULL); char *id = create_unique_id(NULL);
xmpp_stanza_set_id(msg, id); xmpp_stanza_set_id(msg, id);
free(id);
chat_state = xmpp_stanza_new(ctx); chat_state = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(chat_state, state); xmpp_stanza_set_name(chat_state, state);
@ -219,8 +220,9 @@ stanza_create_message(xmpp_ctx_t *ctx, const char * const recipient,
xmpp_stanza_set_name(msg, STANZA_NAME_MESSAGE); xmpp_stanza_set_name(msg, STANZA_NAME_MESSAGE);
xmpp_stanza_set_type(msg, type); xmpp_stanza_set_type(msg, type);
xmpp_stanza_set_attribute(msg, STANZA_ATTR_TO, recipient); xmpp_stanza_set_attribute(msg, STANZA_ATTR_TO, recipient);
char *id = generate_unique_id(NULL); char *id = create_unique_id(NULL);
xmpp_stanza_set_id(msg, id); xmpp_stanza_set_id(msg, id);
free(id);
body = xmpp_stanza_new(ctx); body = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(body, STANZA_NAME_BODY); xmpp_stanza_set_name(body, STANZA_NAME_BODY);
@ -322,8 +324,9 @@ stanza_create_invite(xmpp_ctx_t *ctx, const char * const room,
message = xmpp_stanza_new(ctx); message = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(message, STANZA_NAME_MESSAGE); xmpp_stanza_set_name(message, STANZA_NAME_MESSAGE);
xmpp_stanza_set_attribute(message, STANZA_ATTR_TO, contact); xmpp_stanza_set_attribute(message, STANZA_ATTR_TO, contact);
char *id = generate_unique_id(NULL); char *id = create_unique_id(NULL);
xmpp_stanza_set_id(message, id); xmpp_stanza_set_id(message, id);
free(id);
x = xmpp_stanza_new(ctx); x = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(x, STANZA_NAME_X); xmpp_stanza_set_name(x, STANZA_NAME_X);
@ -347,8 +350,9 @@ stanza_create_room_join_presence(xmpp_ctx_t * const ctx,
xmpp_stanza_t *presence = xmpp_stanza_new(ctx); xmpp_stanza_t *presence = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(presence, STANZA_NAME_PRESENCE); xmpp_stanza_set_name(presence, STANZA_NAME_PRESENCE);
xmpp_stanza_set_attribute(presence, STANZA_ATTR_TO, full_room_jid); xmpp_stanza_set_attribute(presence, STANZA_ATTR_TO, full_room_jid);
char *id = generate_unique_id("join"); char *id = create_unique_id("join");
xmpp_stanza_set_id(presence, id); xmpp_stanza_set_id(presence, id);
free(id);
xmpp_stanza_t *x = xmpp_stanza_new(ctx); xmpp_stanza_t *x = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(x, STANZA_NAME_X); xmpp_stanza_set_name(x, STANZA_NAME_X);
@ -359,7 +363,7 @@ stanza_create_room_join_presence(xmpp_ctx_t * const ctx,
xmpp_stanza_t *pass = xmpp_stanza_new(ctx); xmpp_stanza_t *pass = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(pass, "password"); xmpp_stanza_set_name(pass, "password");
xmpp_stanza_t *text = xmpp_stanza_new(ctx); xmpp_stanza_t *text = xmpp_stanza_new(ctx);
xmpp_stanza_set_text(text, strdup(passwd)); xmpp_stanza_set_text(text, passwd);
xmpp_stanza_add_child(pass, text); xmpp_stanza_add_child(pass, text);
xmpp_stanza_add_child(x, pass); xmpp_stanza_add_child(x, pass);
xmpp_stanza_release(text); xmpp_stanza_release(text);
@ -377,8 +381,9 @@ stanza_create_room_newnick_presence(xmpp_ctx_t *ctx,
const char * const full_room_jid) const char * const full_room_jid)
{ {
xmpp_stanza_t *presence = xmpp_stanza_new(ctx); xmpp_stanza_t *presence = xmpp_stanza_new(ctx);
char *id = generate_unique_id("sub"); char *id = create_unique_id("sub");
xmpp_stanza_set_id(presence, id); xmpp_stanza_set_id(presence, id);
free(id);
xmpp_stanza_set_name(presence, STANZA_NAME_PRESENCE); xmpp_stanza_set_name(presence, STANZA_NAME_PRESENCE);
xmpp_stanza_set_attribute(presence, STANZA_ATTR_TO, full_room_jid); xmpp_stanza_set_attribute(presence, STANZA_ATTR_TO, full_room_jid);
@ -397,8 +402,9 @@ stanza_create_room_leave_presence(xmpp_ctx_t *ctx, const char * const room,
xmpp_stanza_set_name(presence, STANZA_NAME_PRESENCE); xmpp_stanza_set_name(presence, STANZA_NAME_PRESENCE);
xmpp_stanza_set_type(presence, STANZA_TYPE_UNAVAILABLE); xmpp_stanza_set_type(presence, STANZA_TYPE_UNAVAILABLE);
xmpp_stanza_set_attribute(presence, STANZA_ATTR_TO, full_jid->str); xmpp_stanza_set_attribute(presence, STANZA_ATTR_TO, full_jid->str);
char *id = generate_unique_id("leave"); char *id = create_unique_id("leave");
xmpp_stanza_set_id(presence, id); xmpp_stanza_set_id(presence, id);
free(id);
g_string_free(full_jid, TRUE); g_string_free(full_jid, TRUE);
@ -510,8 +516,9 @@ stanza_create_ping_iq(xmpp_ctx_t *ctx)
xmpp_stanza_t *iq = xmpp_stanza_new(ctx); xmpp_stanza_t *iq = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(iq, STANZA_NAME_IQ); xmpp_stanza_set_name(iq, STANZA_NAME_IQ);
xmpp_stanza_set_type(iq, STANZA_TYPE_GET); xmpp_stanza_set_type(iq, STANZA_TYPE_GET);
char *id = generate_unique_id("ping"); char *id = create_unique_id("ping");
xmpp_stanza_set_id(iq, id); xmpp_stanza_set_id(iq, id);
free(id);
xmpp_stanza_t *ping = xmpp_stanza_new(ctx); xmpp_stanza_t *ping = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(ping, STANZA_NAME_PING); xmpp_stanza_set_name(ping, STANZA_NAME_PING);