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

Merge remote-tracking branch 'origin/master' into clear

This commit is contained in:
James Booth 2017-01-16 00:01:51 +00:00
commit 1da55c310b
36 changed files with 279 additions and 198 deletions

View File

@ -360,6 +360,8 @@ cmd_ac_init(void)
autocomplete_add(account_clear_ac, "pgpkeyid");
autocomplete_add(account_clear_ac, "startscript");
autocomplete_add(account_clear_ac, "theme");
autocomplete_add(account_clear_ac, "muc");
autocomplete_add(account_clear_ac, "resource");
account_default_ac = autocomplete_new();
autocomplete_add(account_default_ac, "set");

View File

@ -1953,7 +1953,7 @@ static struct cmd_t command_defs[] =
{ "clear", cmd_account_clear })
CMD_MAINFUNC(cmd_account)
CMD_TAGS(
CMD_TAG_CONNECTION
CMD_TAG_CONNECTION,
CMD_TAG_PRESENCE,
CMD_TAG_CHAT,
CMD_TAG_GROUPCHAT)
@ -1989,7 +1989,9 @@ static struct cmd_t command_defs[] =
"/account clear <account> port",
"/account clear <account> otr",
"/account clear <account> pgpkeyid",
"/account clear <account> startscript")
"/account clear <account> startscript",
"/account clear <account> muc",
"/account clear <account> resource")
CMD_DESC(
"Commands for creating and managing accounts. "
"Calling with no arguments will display information for the current account.")
@ -2012,7 +2014,7 @@ static struct cmd_t command_defs[] =
{ "set <account> resource <resource>", "The resource to be used for this account, defaults to 'profanity'." },
{ "set <account> password <password>", "Password for the account, note this is currently stored in plaintext if set." },
{ "set <account> eval_password <command>", "Shell command evaluated to retrieve password for the account. Can be used to retrieve password from keyring." },
{ "set <account> muc <service>", "The default MUC chat service to use, defaults to 'conference.<domainpart>' where the domain part is from the account JID." },
{ "set <account> muc <service>", "The default MUC chat service to use, defaults to the servers disco info response." },
{ "set <account> nick <nick>", "The default nickname to use when joining chat rooms." },
{ "set <account> otr <policy>", "Override global OTR policy for this account, see /otr." },
{ "set <account> pgpkeyid <pgpkeyid>", "Set the ID of the PGP key for this account, see /pgp." },
@ -2028,7 +2030,9 @@ static struct cmd_t command_defs[] =
{ "clear <account> otr", "Remove the OTR policy setting for this account." },
{ "clear <account> pgpkeyid", "Remove pgpkeyid associated with this account." },
{ "clear <account> startscript", "Remove startscript associated with this account." },
{ "clear <account> theme", "Clear the theme setting for the account, the global theme will be used." })
{ "clear <account> theme", "Clear the theme setting for the account, the global theme will be used." },
{ "clear <account> resource", "Remove the resource setting for this account."},
{ "clear <account> muc", "Remove the default MUC service setting."})
CMD_EXAMPLES(
"/account add me",
"/account set me jid me@chatty",

View File

@ -416,7 +416,7 @@ cmd_connect(ProfWin *window, const char *const command, gchar **args)
account->password = NULL;
}
jid = account_create_full_jid(account);
jid = account_create_connect_jid(account);
account_free(account);
// connect with JID
@ -860,8 +860,7 @@ _account_set_presence_priority(char *account_name, char *presence, char *priorit
char *connected_account = session_get_account_name();
resource_presence_t last_presence = accounts_get_last_presence(connected_account);
if (presence_type == last_presence) {
char *message = connection_get_presence_msg();
cl_ev_presence_send(last_presence, message, 0);
cl_ev_presence_send(last_presence, 0);
}
}
cons_show("Updated %s priority for account %s: %s", presence, account_name, priority);
@ -959,6 +958,14 @@ cmd_account_clear(ProfWin *window, const char *const command, gchar **args)
accounts_clear_theme(account_name);
cons_show("Removed theme for account %s", account_name);
cons_show("");
} else if (strcmp(property, "muc") == 0) {
accounts_clear_muc(account_name);
cons_show("Removed MUC service for account %s", account_name);
cons_show("");
} else if (strcmp(property, "resource") == 0) {
accounts_clear_resource(account_name);
cons_show("Removed resource for account %s", account_name);
cons_show("");
} else {
cons_show("Invalid property: %s", property);
cons_show("");
@ -3426,7 +3433,7 @@ cmd_join(ProfWin *window, const char *const command, gchar **args)
if (args[0] == NULL) {
char *account_name = session_get_account_name();
ProfAccount *account = accounts_get_account(account_name);
if (account->muc_service) {
GString *room_str = g_string_new("");
char *uuid = connection_create_uuid();
g_string_append_printf(room_str, "private-chat-%s@%s", uuid, account->muc_service);
@ -3437,6 +3444,9 @@ cmd_join(ProfWin *window, const char *const command, gchar **args)
g_string_free(room_str, TRUE);
account_free(account);
} else {
cons_show("Account MUC service property not found.");
}
return TRUE;
}
@ -3451,7 +3461,6 @@ cmd_join(ProfWin *window, const char *const command, gchar **args)
char *room = NULL;
char *nick = NULL;
char *passwd = NULL;
GString *room_str = g_string_new("");
char *account_name = session_get_account_name();
ProfAccount *account = accounts_get_account(account_name);
@ -3460,11 +3469,18 @@ cmd_join(ProfWin *window, const char *const command, gchar **args)
room = args[0];
// server not supplied (room), use account preference
} else {
} else if (account->muc_service) {
GString *room_str = g_string_new("");
g_string_append(room_str, args[0]);
g_string_append(room_str, "@");
g_string_append(room_str, account->muc_service);
room = room_str->str;
g_string_free(room_str, FALSE);
// no account preference
} else {
cons_show("Account MUC service property not found.");
return TRUE;
}
// Additional args supplied
@ -3502,7 +3518,6 @@ cmd_join(ProfWin *window, const char *const command, gchar **args)
}
jid_destroy(room_arg);
g_string_free(room_str, TRUE);
account_free(account);
return TRUE;
@ -4307,14 +4322,19 @@ cmd_rooms(ProfWin *window, const char *const command, gchar **args)
return TRUE;
}
if (args[0] == NULL) {
ProfAccount *account = accounts_get_account(session_get_account_name());
iq_room_list_request(account->muc_service);
account_free(account);
} else {
if (args[0]) {
iq_room_list_request(args[0]);
return TRUE;
}
ProfAccount *account = accounts_get_account(session_get_account_name());
if (account->muc_service) {
iq_room_list_request(account->muc_service);
} else {
cons_show("Account MUC service property not found.");
}
account_free(account);
return TRUE;
}
@ -5940,7 +5960,7 @@ cmd_priority(ProfWin *window, const char *const command, gchar **args)
if (res) {
accounts_set_priority_all(session_get_account_name(), intval);
resource_presence_t last_presence = accounts_get_last_presence(session_get_account_name());
cl_ev_presence_send(last_presence, connection_get_presence_msg(), 0);
cl_ev_presence_send(last_presence, 0);
cons_show("Priority set to %d.", intval);
} else {
cons_show(err_msg);
@ -7177,7 +7197,8 @@ _update_presence(const resource_presence_t resource_presence,
if (conn_status != JABBER_CONNECTED) {
cons_show("You are not currently connected.");
} else {
cl_ev_presence_send(resource_presence, msg, 0);
connection_set_presence_msg(msg);
cl_ev_presence_send(resource_presence, 0);
ui_update_presence(resource_presence, msg, show);
}
}

View File

@ -115,17 +115,10 @@ account_new(const gchar *const name, const gchar *const jid,
new_account->priority_xa = priority_xa;
new_account->priority_dnd = priority_dnd;
if (muc_service == NULL) {
GString *g_muc_service = g_string_new("conference.");
Jid *jidp = jid_create(new_account->jid);
g_string_append(g_muc_service, jidp->domainpart);
new_account->muc_service = g_muc_service->str;
g_string_free(g_muc_service, FALSE);
jid_destroy(jidp);
} else {
if (muc_service) {
new_account->muc_service = strdup(muc_service);
} else {
new_account->muc_service = NULL;
}
if (muc_nick == NULL) {
@ -174,7 +167,7 @@ account_new(const gchar *const name, const gchar *const jid,
}
char*
account_create_full_jid(ProfAccount *account)
account_create_connect_jid(ProfAccount *account)
{
if (account->resource) {
return create_fulljid(account->jid, account->resource);
@ -224,7 +217,10 @@ account_eval_password(ProfAccount *account)
void
account_free(ProfAccount *account)
{
if (account) {
if (account == NULL) {
return;
}
free(account->name);
free(account->jid);
free(account->password);
@ -245,4 +241,3 @@ account_free(ProfAccount *account)
g_list_free_full(account->otr_always, g_free);
free(account);
}
}

View File

@ -74,7 +74,7 @@ ProfAccount* account_new(const gchar *const name, const gchar *const jid,
const gchar *const otr_policy, GList *otr_manual, GList *otr_opportunistic,
GList *otr_always, const gchar *const pgp_keyid, const char *const startscript,
const char *const theme, gchar *tls_policy);
char* account_create_full_jid(ProfAccount *account);
char* account_create_connect_jid(ProfAccount *account);
gboolean account_eval_password(ProfAccount *account);
void account_free(ProfAccount *account);

View File

@ -133,8 +133,11 @@ accounts_add(const char *account_name, const char *altdomain, const int port, co
}
}
// doesn't yet exist
if (!g_key_file_has_group(accounts, account_name)) {
if (g_key_file_has_group(accounts, account_name)) {
jid_destroy(jid);
return;
}
g_key_file_set_boolean(accounts, account_name, "enabled", TRUE);
g_key_file_set_string(accounts, account_name, "jid", barejid);
g_key_file_set_string(accounts, account_name, "resource", resource);
@ -149,15 +152,13 @@ accounts_add(const char *account_name, const char *altdomain, const int port, co
}
Jid *jidp = jid_create(barejid);
GString *muc_service = g_string_new("conference.");
g_string_append(muc_service, jidp->domainpart);
g_key_file_set_string(accounts, account_name, "muc.service", muc_service->str);
g_string_free(muc_service, TRUE);
if (jidp->localpart == NULL) {
g_key_file_set_string(accounts, account_name, "muc.nick", jidp->domainpart);
} else {
g_key_file_set_string(accounts, account_name, "muc.nick", jidp->localpart);
}
jid_destroy(jidp);
g_key_file_set_string(accounts, account_name, "presence.last", "online");
@ -171,7 +172,6 @@ accounts_add(const char *account_name, const char *altdomain, const int port, co
_save_accounts();
autocomplete_add(all_ac, account_name);
autocomplete_add(enabled_ac, account_name);
}
jid_destroy(jid);
}
@ -223,7 +223,18 @@ accounts_get_account(const char *const name)
int priority_xa = g_key_file_get_integer(accounts, name, "priority.xa", NULL);
int priority_dnd = g_key_file_get_integer(accounts, name, "priority.dnd", NULL);
gchar *muc_service = g_key_file_get_string(accounts, name, "muc.service", NULL);
gchar *muc_service = NULL;
if (g_key_file_has_key(accounts, name, "muc.service", NULL)) {
muc_service = g_key_file_get_string(accounts, name, "muc.service", NULL);
} else {
jabber_conn_status_t conn_status = connection_get_status();
if (conn_status == JABBER_CONNECTED) {
char* conf_jid = connection_jid_for_feature(XMPP_FEATURE_MUC);
if (conf_jid) {
muc_service = strdup(conf_jid);
}
}
}
gchar *muc_nick = g_key_file_get_string(accounts, name, "muc.nick", NULL);
gchar *otr_policy = NULL;
@ -416,10 +427,6 @@ accounts_set_jid(const char *const account_name, const char *const value)
g_key_file_set_string(accounts, account_name, "resource", jid->resourcepart);
}
GString *muc_service = g_string_new("conference.");
g_string_append(muc_service, jid->domainpart);
g_key_file_set_string(accounts, account_name, "muc.service", muc_service->str);
g_string_free(muc_service, TRUE);
if (jid->localpart == NULL) {
g_key_file_set_string(accounts, account_name, "muc.nick", jid->domainpart);
} else {
@ -568,6 +575,24 @@ accounts_clear_theme(const char *const account_name)
}
}
void
accounts_clear_muc(const char *const account_name)
{
if (accounts_account_exists(account_name)) {
g_key_file_remove_key(accounts, account_name, "muc.service", NULL);
_save_accounts();
}
}
void
accounts_clear_resource(const char *const account_name)
{
if (accounts_account_exists(account_name)) {
g_key_file_remove_key(accounts, account_name, "resource", NULL);
_save_accounts();
}
}
void
accounts_clear_otr(const char *const account_name)
{

View File

@ -93,6 +93,8 @@ void accounts_clear_otr(const char *const account_name);
void accounts_clear_pgp_keyid(const char *const account_name);
void accounts_clear_script_start(const char *const account_name);
void accounts_clear_theme(const char *const account_name);
void accounts_clear_muc(const char *const account_name);
void accounts_clear_resource(const char *const account_name);
void accounts_add_otr_policy(const char *const account_name, const char *const contact_jid, const char *const policy);
#endif

View File

@ -64,9 +64,13 @@ cl_ev_connect_jid(const char *const jid, const char *const passwd, const char *c
jabber_conn_status_t
cl_ev_connect_account(ProfAccount *account)
{
char *jid = account_create_full_jid(account);
cons_show("Connecting with account %s as %s", account->name, jid);
free(jid);
if (account->resource) {
cons_show("Connecting with account %s as %s/%s", account->name, account->jid, account->resource);
} else if (g_strcmp0(account->name, account->jid) == 0) {
cons_show("Connecting with account %s", account->name);
} else {
cons_show("Connecting with account %s as %s", account->name, account->jid);
}
return session_connect_with_account(account);
}
@ -75,7 +79,9 @@ void
cl_ev_disconnect(void)
{
const char *jid = connection_get_fulljid();
cons_show("%s logged out successfully.", jid);
Jid *jidp = jid_create(jid);
cons_show("%s logged out successfully.", jidp->barejid);
jid_destroy(jidp);
ui_disconnected();
ui_close_all_wins();
@ -90,9 +96,10 @@ cl_ev_disconnect(void)
}
void
cl_ev_presence_send(const resource_presence_t presence_type, const char *const msg, const int idle_secs)
cl_ev_presence_send(const resource_presence_t presence_type, const int idle_secs)
{
char *signed_status = NULL;
char *msg = connection_get_presence_msg();
#ifdef HAVE_LIBGPGME
char *account_name = session_get_account_name();
@ -103,7 +110,7 @@ cl_ev_presence_send(const resource_presence_t presence_type, const char *const m
account_free(account);
#endif
presence_send(presence_type, msg, idle_secs, signed_status);
presence_send(presence_type, idle_secs, signed_status);
free(signed_status);
}

View File

@ -42,7 +42,7 @@ jabber_conn_status_t cl_ev_connect_account(ProfAccount *account);
void cl_ev_disconnect(void);
void cl_ev_presence_send(const resource_presence_t presence_type, const char *const msg, const int idle_secs);
void cl_ev_presence_send(const resource_presence_t presence_type, const int idle_secs);
void cl_ev_send_msg(ProfChatWin *chatwin, const char *const msg, const char *const oob_url);
void cl_ev_send_muc_msg(ProfMucWin *mucwin, const char *const msg, const char *const oob_url);

View File

@ -135,19 +135,23 @@ sv_ev_roster_received(void)
GTimeSpan diff_micros = g_date_time_difference(nowdt, lastdt);
int diff_secs = (diff_micros / 1000) / 1000;
if (prefs_get_boolean(PREF_LASTACTIVITY)) {
cl_ev_presence_send(conn_presence, NULL, diff_secs);
connection_set_presence_msg(NULL);
cl_ev_presence_send(conn_presence, diff_secs);
} else {
cl_ev_presence_send(conn_presence, NULL, 0);
connection_set_presence_msg(NULL);
cl_ev_presence_send(conn_presence, 0);
}
g_date_time_unref(lastdt);
} else {
cl_ev_presence_send(conn_presence, NULL, 0);
connection_set_presence_msg(NULL);
cl_ev_presence_send(conn_presence, 0);
}
free(last_activity_str);
g_date_time_unref(nowdt);
} else {
cl_ev_presence_send(conn_presence, NULL, 0);
connection_set_presence_msg(NULL);
cl_ev_presence_send(conn_presence, 0);
}
const char *fulljid = connection_get_fulljid();

View File

@ -493,7 +493,7 @@ api_disco_add_feature(char *plugin_name, char *feature)
// resend presence to update server's disco info data for this client
if (connection_get_status() == JABBER_CONNECTED) {
resource_presence_t last_presence = accounts_get_last_presence(session_get_account_name());
cl_ev_presence_send(last_presence, connection_get_presence_msg(), 0);
cl_ev_presence_send(last_presence, 0);
}
}

View File

@ -214,8 +214,7 @@ plugins_unload(const char *const name)
if (connection_get_status() == JABBER_CONNECTED) {
char* account_name = session_get_account_name();
resource_presence_t last_presence = accounts_get_last_presence(account_name);
char *msg = connection_get_presence_msg();
cl_ev_presence_send(last_presence, msg, 0);
cl_ev_presence_send(last_presence, 0);
}
}
return TRUE;

View File

@ -256,7 +256,6 @@ end:
msg = strdup(FALLBACK_MSG);
}
win_update_entry_message(upload->window, upload->put_url, msg);
//win_update_entry_theme(upload->window, upload->put_url, THEME_THEM);
win_mark_received(upload->window, upload->put_url);
free(msg);

View File

@ -461,7 +461,9 @@ void
cons_show_login_success(ProfAccount *account, gboolean secured)
{
ProfWin *console = wins_get_console();
win_print(console, THEME_DEFAULT, '-', "%s logged in successfully, ", account->jid);
const char *fulljid = connection_get_fulljid();
win_print(console, THEME_DEFAULT, '-', "%s logged in successfully, ", fulljid);
resource_presence_t presence = accounts_get_login_presence(account->name);
const char *presence_str = string_from_resource_presence(presence);

View File

@ -383,11 +383,7 @@ ui_handle_login_account_success(ProfAccount *account, gboolean secured)
title_bar_set_connected(TRUE);
title_bar_set_tls(secured);
GString *fulljid = g_string_new(account->jid);
g_string_append(fulljid, "/");
g_string_append(fulljid, account->resource);
status_bar_print_message(fulljid->str);
g_string_free(fulljid, TRUE);
status_bar_print_message(connection_get_fulljid());
status_bar_update_virtual();
}

View File

@ -1323,16 +1323,6 @@ win_update_entry_message(ProfWin *window, const char *const id, const char *cons
}
}
void
win_update_entry_theme(ProfWin *window, const char *const id, theme_item_t theme_item)
{
ProfBuffEntry *entry = buffer_get_entry_by_id(window->layout->buffer, id);
if (entry) {
entry->theme_item = theme_item;
win_redraw(window);
}
}
void
win_newline(ProfWin *window)
{

View File

@ -82,7 +82,6 @@ void win_sub_print(WINDOW *win, char *msg, gboolean newline, gboolean wrap, int
void win_sub_newline_lazy(WINDOW *win);
void win_mark_received(ProfWin *window, const char *const id);
void win_update_entry_message(ProfWin *window, const char *const id, const char *const message);
void win_update_entry_theme(ProfWin *window, const char *const id, theme_item_t theme_item);
gboolean win_has_active_subwin(ProfWin *window);

View File

@ -125,7 +125,7 @@ caps_add_feature(char *feature)
// resend presence to update server's disco info data for this client
if (connection_get_status() == JABBER_CONNECTED) {
resource_presence_t last_presence = accounts_get_last_presence(session_get_account_name());
cl_ev_presence_send(last_presence, connection_get_presence_msg(), 0);
cl_ev_presence_send(last_presence, 0);
}
}
@ -143,7 +143,7 @@ caps_remove_feature(char *feature)
// resend presence to update server's disco info data for this client
if (connection_get_status() == JABBER_CONNECTED) {
resource_presence_t last_presence = accounts_get_last_presence(session_get_account_name());
cl_ev_presence_send(last_presence, connection_get_presence_msg(), 0);
cl_ev_presence_send(last_presence, 0);
}
}

View File

@ -108,26 +108,21 @@ connection_shutdown(void)
}
jabber_conn_status_t
connection_connect(const char *const fulljid, const char *const passwd, const char *const altdomain, int port,
connection_connect(const char *const jid, const char *const passwd, const char *const altdomain, int port,
const char *const tls_policy)
{
assert(fulljid != NULL);
assert(jid != NULL);
assert(passwd != NULL);
Jid *jid = jid_create(fulljid);
if (jid == NULL) {
log_error("Malformed JID not able to connect: %s", fulljid);
Jid *jidp = jid_create(jid);
if (jidp == NULL) {
log_error("Malformed JID not able to connect: %s", jid);
conn.conn_status = JABBER_DISCONNECTED;
return conn.conn_status;
} else if (jid->fulljid == NULL) {
log_error("Full JID required to connect, received: %s", fulljid);
conn.conn_status = JABBER_DISCONNECTED;
jid_destroy(jid);
return conn.conn_status;
}
jid_destroy(jid);
jid_destroy(jidp);
log_info("Connecting as %s", fulljid);
log_info("Connecting as %s", jid);
if (conn.xmpp_log) {
free(conn.xmpp_log);
@ -150,7 +145,7 @@ connection_connect(const char *const fulljid, const char *const passwd, const ch
log_warning("Failed to get libstrophe conn during connect");
return JABBER_DISCONNECTED;
}
xmpp_conn_set_jid(conn.xmpp_conn, fulljid);
xmpp_conn_set_jid(conn.xmpp_conn, jid);
xmpp_conn_set_pass(conn.xmpp_conn, passwd);
if (!tls_policy || (g_strcmp0(tls_policy, "force") == 0)) {
@ -290,6 +285,10 @@ connection_supports(const char *const feature)
char*
connection_jid_for_feature(const char *const feature)
{
if (conn.features_by_jid == NULL) {
return NULL;
}
GList *jids = g_hash_table_get_keys(conn.features_by_jid);
GList *curr = jids;
@ -345,8 +344,13 @@ connection_get_ctx(void)
const char*
connection_get_fulljid(void)
{
const char *jid = xmpp_conn_get_bound_jid(conn.xmpp_conn);
if (jid) {
return jid;
} else {
return xmpp_conn_get_jid(conn.xmpp_conn);
}
}
GHashTable*
connection_get_features(const char *const jid)

View File

@ -46,7 +46,6 @@ jabber_conn_status_t connection_connect(const char *const fulljid, const char *c
void connection_disconnect(void);
void connection_set_disconnected(void);
void connection_set_presence_msg(const char *const message);
void connection_set_priority(const int priority);
void connection_set_priority(int priority);
void connection_set_disco_items(GSList *items);
@ -54,7 +53,6 @@ void connection_set_disco_items(GSList *items);
xmpp_conn_t* connection_get_conn(void);
xmpp_ctx_t* connection_get_ctx(void);
char *connection_get_domain(void);
char* connection_jid_for_feature(const char *const feature);
GHashTable* connection_get_features(const char *const jid);
void connection_clear_data(void);

View File

@ -106,10 +106,10 @@ jid_create(const gchar *const str)
}
Jid*
jid_create_from_bare_and_resource(const char *const room, const char *const nick)
jid_create_from_bare_and_resource(const char *const barejid, const char *const resource)
{
Jid *result;
char *jid = create_fulljid(room, nick);
char *jid = create_fulljid(barejid, resource);
result = jid_create(jid);
free(jid);

View File

@ -49,7 +49,7 @@ struct jid_t {
typedef struct jid_t Jid;
Jid* jid_create(const gchar *const str);
Jid* jid_create_from_bare_and_resource(const char *const room, const char *const nick);
Jid* jid_create_from_bare_and_resource(const char *const barejid, const char *const resource);
void jid_destroy(Jid *jid);
gboolean jid_is_valid_room_form(Jid *jid);

View File

@ -191,21 +191,20 @@ presence_reset_sub_request_search(void)
}
void
presence_send(const resource_presence_t presence_type, const char *const msg, const int idle, char *signed_status)
presence_send(const resource_presence_t presence_type, const int idle, char *signed_status)
{
if (connection_get_status() != JABBER_CONNECTED) {
log_warning("Error setting presence, not connected.");
return;
}
char *msg = connection_get_presence_msg();
if (msg) {
log_debug("Updating presence: %s, \"%s\"", string_from_resource_presence(presence_type), msg);
} else {
log_debug("Updating presence: %s", string_from_resource_presence(presence_type));
}
connection_set_presence_msg(msg);
const int pri = accounts_get_priority_for_presence_type(session_get_account_name(), presence_type);
connection_set_priority(pri);

View File

@ -118,15 +118,22 @@ session_connect_with_account(const ProfAccount *const account)
}
saved_account.passwd = strdup(account->password);
// connect with fulljid
char *jid = NULL;
if (account->resource) {
Jid *jidp = jid_create_from_bare_and_resource(account->jid, account->resource);
jid = strdup(jidp->fulljid);
jid_destroy(jidp);
} else {
jid = strdup(account->jid);
}
jabber_conn_status_t result = connection_connect(
jidp->fulljid,
jid,
account->password,
account->server,
account->port,
account->tls_policy);
jid_destroy(jidp);
free(jid);
return result;
}
@ -405,10 +412,11 @@ session_check_autoaway(void)
// send away presence with last activity
char *message = prefs_get_string(PREF_AUTOAWAY_MESSAGE);
connection_set_presence_msg(message);
if (prefs_get_boolean(PREF_LASTACTIVITY)) {
cl_ev_presence_send(RESOURCE_AWAY, message, idle_ms / 1000);
cl_ev_presence_send(RESOURCE_AWAY, idle_ms / 1000);
} else {
cl_ev_presence_send(RESOURCE_AWAY, message, 0);
cl_ev_presence_send(RESOURCE_AWAY, 0);
}
int pri = accounts_get_priority_for_presence_type(account, RESOURCE_AWAY);
@ -425,7 +433,8 @@ session_check_autoaway(void)
activity_state = ACTIVITY_ST_IDLE;
// send current presence with last activity
cl_ev_presence_send(curr_presence, curr_status, idle_ms / 1000);
connection_set_presence_msg(curr_status);
cl_ev_presence_send(curr_presence, idle_ms / 1000);
}
}
break;
@ -436,7 +445,8 @@ session_check_autoaway(void)
cons_show("No longer idle.");
// send current presence without last activity
cl_ev_presence_send(curr_presence, curr_status, 0);
connection_set_presence_msg(curr_status);
cl_ev_presence_send(curr_presence, 0);
}
break;
case ACTIVITY_ST_AWAY:
@ -445,10 +455,11 @@ session_check_autoaway(void)
// send extended away presence with last activity
char *message = prefs_get_string(PREF_AUTOXA_MESSAGE);
connection_set_presence_msg(message);
if (prefs_get_boolean(PREF_LASTACTIVITY)) {
cl_ev_presence_send(RESOURCE_XA, message, idle_ms / 1000);
cl_ev_presence_send(RESOURCE_XA, idle_ms / 1000);
} else {
cl_ev_presence_send(RESOURCE_XA, message, 0);
cl_ev_presence_send(RESOURCE_XA, 0);
}
int pri = accounts_get_priority_for_presence_type(account, RESOURCE_XA);
@ -466,7 +477,8 @@ session_check_autoaway(void)
cons_show("No longer idle.");
// send saved presence without last activity
cl_ev_presence_send(saved_presence, saved_status, 0);
connection_set_presence_msg(saved_status);
cl_ev_presence_send(saved_presence, 0);
contact_presence_t contact_pres = contact_presence_from_resource_presence(saved_presence);
title_bar_set_presence(contact_pres);
}
@ -478,7 +490,8 @@ session_check_autoaway(void)
cons_show("No longer idle.");
// send saved presence without last activity
cl_ev_presence_send(saved_presence, saved_status, 0);
connection_set_presence_msg(saved_status);
cl_ev_presence_send(saved_presence, 0);
contact_presence_t contact_pres = contact_presence_from_resource_presence(saved_presence);
title_bar_set_presence(contact_pres);
}
@ -499,10 +512,16 @@ _session_reconnect(void)
return;
}
char *fulljid = create_fulljid(account->jid, account->resource);
char *jid = NULL;
if (account->resource) {
jid = create_fulljid(account->jid, account->resource);
} else {
jid = strdup(account->jid);
}
log_debug("Attempting reconnect with account %s", account->name);
connection_connect(fulljid, saved_account.passwd, account->server, account->port, account->tls_policy);
free(fulljid);
connection_connect(jid, saved_account.passwd, account->server, account->port, account->tls_policy);
free(jid);
account_free(account);
g_timer_start(reconnect_timer);
}

View File

@ -58,6 +58,7 @@
#define XMPP_FEATURE_BLOCKING "urn:xmpp:blocking"
#define XMPP_FEATURE_RECEIPTS "urn:xmpp:receipts"
#define XMPP_FEATURE_LASTACTIVITY "jabber:iq:last"
#define XMPP_FEATURE_MUC "http://jabber.org/protocol/muc"
typedef enum {
JABBER_CONNECTING,
@ -119,6 +120,7 @@ char* session_get_account_name(void);
jabber_conn_status_t connection_get_status(void);
char *connection_get_presence_msg(void);
void connection_set_presence_msg(const char *const message);
const char* connection_get_fulljid(void);
char* connection_create_uuid(void);
void connection_free_uuid(char *uuid);
@ -129,6 +131,7 @@ gboolean connection_is_secured(void);
gboolean connection_send_stanza(const char *const stanza);
GList* connection_get_available_resources(void);
gboolean connection_supports(const char *const feature);
char* connection_jid_for_feature(const char *const feature);
char* message_send_chat(const char *const barejid, const char *const msg, const char *const oob_url,
gboolean request_receipt);
@ -151,7 +154,7 @@ char* presence_sub_request_find(const char *const search_str);
void presence_join_room(const char *const room, const char *const nick, const char *const passwd);
void presence_change_room_nick(const char *const room, const char *const nick);
void presence_leave_chat_room(const char *const room_jid);
void presence_send(resource_presence_t status, const char *const msg, int idle, char *signed_status);
void presence_send(resource_presence_t status, int idle, char *signed_status);
gboolean presence_sub_request_exists(const char *const bare_jid);
void iq_enable_carbons(void);

View File

@ -52,6 +52,7 @@ int main(int argc, char* argv[]) {
PROF_FUNC_TEST(presence_chat_with_message),
PROF_FUNC_TEST(presence_set_priority),
PROF_FUNC_TEST(presence_includes_priority),
PROF_FUNC_TEST(presence_keeps_status),
PROF_FUNC_TEST(presence_received),
PROF_FUNC_TEST(presence_missing_resource_defaults),
@ -89,7 +90,6 @@ int main(int argc, char* argv[]) {
PROF_FUNC_TEST(display_software_version_result_in_chat),
PROF_FUNC_TEST(sends_room_join),
PROF_FUNC_TEST(sends_room_join_with_default_muc_service),
PROF_FUNC_TEST(sends_room_join_with_nick),
PROF_FUNC_TEST(sends_room_join_with_password),
PROF_FUNC_TEST(sends_room_join_with_nick_and_password),

View File

@ -253,7 +253,7 @@ prof_connect_with_roster(char *roster)
// Allow time for profanity to connect
exp_timeout = 30;
assert_true(prof_output_regex("stabber@localhost logged in successfully, .+online.+ \\(priority 0\\)\\."));
assert_true(prof_output_regex("stabber@localhost/profanity logged in successfully, .+online.+ \\(priority 0\\)\\."));
exp_timeout = 10;
stbbr_wait_for("prof_presence_*");
}

View File

@ -17,7 +17,7 @@ disconnect_ends_session(void **state)
prof_connect();
prof_input("/disconnect");
assert_true(prof_output_exact("stabber@localhost/profanity logged out successfully."));
assert_true(prof_output_exact("stabber@localhost logged out successfully."));
prof_input("/roster");
assert_true(prof_output_exact("You are not currently connected."));

View File

@ -26,21 +26,6 @@ sends_room_join(void **state)
));
}
void
sends_room_join_with_default_muc_service(void **state)
{
prof_connect();
prof_input("/join testroom");
assert_true(stbbr_last_received(
"<presence id='*' to='testroom@conference.localhost/stabber'>"
"<x xmlns='http://jabber.org/protocol/muc'/>"
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://www.profanity.im'/>"
"</presence>"
));
}
void
sends_room_join_with_nick(void **state)
{

View File

@ -1,5 +1,4 @@
void sends_room_join(void **state);
void sends_room_join_with_default_muc_service(void **state);
void sends_room_join_with_nick(void **state);
void sends_room_join_with_password(void **state);
void sends_room_join_with_nick_and_password(void **state);

View File

@ -227,6 +227,33 @@ presence_includes_priority(void **state)
assert_true(prof_output_exact("Status set to chat (priority 25), \"Free to talk\"."));
}
void
presence_keeps_status(void **state)
{
prof_connect();
prof_input("/chat \"Free to talk\"");
assert_true(stbbr_received(
"<presence id='prof_presence_4'>"
"<show>chat</show>"
"<status>Free to talk</status>"
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://www.profanity.im'/>"
"</presence>"
));
assert_true(prof_output_exact("Status set to chat (priority 0), \"Free to talk\"."));
prof_input("/priority 25");
assert_true(stbbr_received(
"<presence id='prof_presence_5'>"
"<show>chat</show>"
"<status>Free to talk</status>"
"<priority>25</priority>"
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://www.profanity.im'/>"
"</presence>"
));
assert_true(prof_output_exact("Priority set to 25."));
}
void
presence_received(void **state)
{

View File

@ -10,5 +10,6 @@ void presence_chat(void **state);
void presence_chat_with_message(void **state);
void presence_set_priority(void **state);
void presence_includes_priority(void **state);
void presence_keeps_status(void **state);
void presence_received(void **state);
void presence_missing_resource_defaults(void **state);

View File

@ -25,7 +25,7 @@ rooms_query(void **state)
prof_connect();
prof_input("/rooms");
prof_input("/rooms conference.localhost");
assert_true(prof_output_exact("chatroom@conference.localhost, (A chat room)"));
assert_true(prof_output_exact("hangout@conference.localhost, (Another chat room)"));

View File

@ -196,6 +196,8 @@ void accounts_clear_otr(const char * const account_name) {}
void accounts_clear_pgp_keyid(const char * const account_name) {}
void accounts_clear_script_start(const char * const account_name) {}
void accounts_clear_theme(const char * const account_name) {}
void accounts_clear_muc(const char * const account_name) {}
void accounts_clear_resource(const char * const account_name) {}
void accounts_add_otr_policy(const char * const account_name, const char * const contact_jid, const char * const policy) {}
char* accounts_get_last_activity(const char *const account_name)
{

View File

@ -806,17 +806,15 @@ void cmd_account_set_priority_updates_presence_when_account_connected_with_prese
expect_any(accounts_get_account, name);
will_return(accounts_get_account, account);
#endif
will_return(connection_get_presence_msg, "Free to chat");
expect_value(presence_send, status, RESOURCE_ONLINE);
expect_string(presence_send, msg, "Free to chat");
expect_value(presence_send, idle, 0);
expect_value(presence_send, signed_status, NULL);
expect_cons_show("Updated online priority for account a_account: 10");
expect_cons_show("");
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
assert_true(result);
}

View File

@ -78,6 +78,8 @@ GList * session_get_available_resources(void)
return NULL;
}
void connection_set_presence_msg(const char *const message) {}
gboolean
connection_send_stanza(const char *const stanza)
{
@ -153,10 +155,9 @@ void presence_join_room(const char *const room, const char *const nick, const ch
void presence_change_room_nick(const char * const room, const char * const nick) {}
void presence_leave_chat_room(const char * const room_jid) {}
void presence_send(resource_presence_t status, const char * const msg, int idle, char *signed_status)
void presence_send(resource_presence_t status, int idle, char *signed_status)
{
check_expected(status);
check_expected(msg);
check_expected(idle);
check_expected(signed_status);
}