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

fixed some bugs, added some more

- Added JABBER_RAW_CONNECT[ING/ED] connection states
- Added cl_ev_connect_raw and session_connect_raw to conform to normal
connection functions
- Fixed SIGABRT during registration
- Added a check in cmd_register to ensure it's actually connected before
registering--but this will always fail atm
This commit is contained in:
swirl 2021-07-04 19:02:38 -04:00
parent 5ea1ccbb46
commit 2cc354b6ae
9 changed files with 96 additions and 15 deletions

View File

@ -9589,7 +9589,7 @@ cmd_register(ProfWin* window, const char* const command, gchar** args)
char* server = args[1]; char* server = args[1];
jabber_conn_status_t conn_status = connection_connect_raw(server, port, tls_policy, auth_policy); jabber_conn_status_t conn_status = cl_ev_connect_raw(server, port, tls_policy, auth_policy);
if (conn_status == JABBER_DISCONNECTED) { if (conn_status == JABBER_DISCONNECTED) {
cons_show_error("Connection attempt to server %s port %d failed.", server, port); cons_show_error("Connection attempt to server %s port %d failed.", server, port);
@ -9598,19 +9598,26 @@ cmd_register(ProfWin* window, const char* const command, gchar** args)
} }
char* username = args[0]; char* username = args[0];
if (connection_get_status() != JABBER_RAW_CONNECTED) { // FIXME: this is ALWAYS the case, as the connection doesn't finish by this time.
cons_show_error("Raw connection attempt failed or not yet completed.");
log_info("Raw connection attempt failed or not yet completed.");
} //else {
char* passwd = ui_ask_password(false); char* passwd = ui_ask_password(false);
char* confirm_passwd = ui_ask_password(true); char* confirm_passwd = ui_ask_password(true);
if (g_strcmp0(passwd, confirm_passwd) == 0) { if (g_strcmp0(passwd, confirm_passwd) == 0) {
log_info("Attempting to register account %s on server %s.", username, server);
iq_register_new_account(username, passwd); iq_register_new_account(username, passwd);
} else { } else {
cons_show("The two passwords do not match."); cons_show("The two passwords do not match.");
} }
free(username);
free(passwd); free(passwd);
free(confirm_passwd); free(confirm_passwd);
//}
options_destroy(options);
log_info("we are leaving the registration process");
return TRUE; return TRUE;
} }

View File

@ -81,6 +81,13 @@ cl_ev_connect_account(ProfAccount* account)
return session_connect_with_account(account); return session_connect_with_account(account);
} }
jabber_conn_status_t
cl_ev_connect_raw(const char* const altdomain, const int port, const char* const tls_policy, const char* const auth_policy)
{
cons_show("Raw connecting to %s", altdomain);
return session_connect_raw(altdomain, port, tls_policy, auth_policy);
}
void void
cl_ev_disconnect(void) cl_ev_disconnect(void)
{ {
@ -262,3 +269,4 @@ cl_ev_send_priv_msg(ProfPrivateWin* privwin, const char* const msg, const char*
jid_destroy(jidp); jid_destroy(jidp);
} }
} }

View File

@ -40,6 +40,7 @@
jabber_conn_status_t cl_ev_connect_jid(const char* const jid, const char* const passwd, const char* const altdomain, const int port, const char* const tls_policy, const char* const auth_policy); jabber_conn_status_t cl_ev_connect_jid(const char* const jid, const char* const passwd, const char* const altdomain, const int port, const char* const tls_policy, const char* const auth_policy);
jabber_conn_status_t cl_ev_connect_account(ProfAccount* account); jabber_conn_status_t cl_ev_connect_account(ProfAccount* account);
jabber_conn_status_t cl_ev_connect_raw(const char* const altdomain, const int port, const char* const tls_policy, const char* const auth_policy);
void cl_ev_disconnect(void); void cl_ev_disconnect(void);
@ -52,3 +53,4 @@ void cl_ev_send_muc_msg(ProfMucWin* mucwin, const char* const msg, const char* c
void cl_ev_send_priv_msg(ProfPrivateWin* privwin, const char* const msg, const char* const oob_url); void cl_ev_send_priv_msg(ProfPrivateWin* privwin, const char* const msg, const char* const oob_url);
#endif #endif

View File

@ -268,3 +268,4 @@ _shutdown(void)
ui_close(); ui_close();
prefs_close(); prefs_close();
} }

View File

@ -342,7 +342,7 @@ connection_connect_raw(const char* const altdomain, int port,
#endif #endif
if (connect_status == 0) { if (connect_status == 0) {
conn.conn_status = JABBER_CONNECTING; conn.conn_status = JABBER_RAW_CONNECTING;
} else { } else {
conn.conn_status = JABBER_DISCONNECTED; conn.conn_status = JABBER_DISCONNECTED;
} }
@ -686,6 +686,21 @@ _connection_handler(xmpp_conn_t* const xmpp_conn, const xmpp_conn_event_t status
break; break;
// raw connection success
case XMPP_CONN_RAW_CONNECT:
log_debug("Connection handler: XMPP_CONN_RAW_CONNECT");
conn.conn_status = JABBER_RAW_CONNECTED;
Jid* my_raw_jid = jid_create(xmpp_conn_get_jid(conn.xmpp_conn));
log_debug("jid: %s", xmpp_conn_get_jid(conn.xmpp_conn));
conn.domain = strdup(my_raw_jid->domainpart);
jid_destroy(my_raw_jid);
conn.features_by_jid = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)g_hash_table_destroy);
g_hash_table_insert(conn.features_by_jid, strdup(conn.domain), g_hash_table_new_full(g_str_hash, g_str_equal, free, NULL));
break;
// disconnected // disconnected
case XMPP_CONN_DISCONNECT: case XMPP_CONN_DISCONNECT:
log_debug("Connection handler: XMPP_CONN_DISCONNECT"); log_debug("Connection handler: XMPP_CONN_DISCONNECT");

View File

@ -2658,14 +2658,15 @@ _mam_rsm_id_handler(xmpp_stanza_t* const stanza, void* const userdata)
void void
iq_register_new_account(const char* const user, const char* const password) iq_register_new_account(const char* const user, const char* const password)
{ {
//char* id = connection_create_stanza_id();
xmpp_ctx_t* const ctx = connection_get_ctx(); xmpp_ctx_t* const ctx = connection_get_ctx();
xmpp_stanza_t* iq = stanza_register_new_account(ctx, user, password); xmpp_stanza_t* iq = stanza_register_new_account(ctx, user, password);
const char* id = xmpp_stanza_get_id(iq); const char* id = xmpp_stanza_get_id(iq);
iq_id_handler_add(id, _register_new_account_result_id_handler, NULL, NULL); iq_id_handler_add(id, _register_new_account_result_id_handler, NULL, NULL); // FIXME: function doesn't seem to ever run?
log_debug("HI hi sending registration stanza");
iq_send_stanza(iq); iq_send_stanza(iq);
log_debug("registration stanza has been sent");
xmpp_stanza_release(iq); xmpp_stanza_release(iq);
} }

View File

@ -204,6 +204,43 @@ session_connect_with_details(const char* const jid, const char* const passwd, co
saved_details.auth_policy); saved_details.auth_policy);
} }
jabber_conn_status_t
session_connect_raw(const char* const altdomain, const int port, const char* const tls_policy,
const char* const auth_policy)
{
assert(altdomain != NULL);
_session_free_saved_account();
_session_free_saved_details();
// save details for reconnect
saved_details.altdomain = strdup(altdomain);
if (port != 0) {
saved_details.port = port;
} else {
saved_details.port = 0;
}
if (tls_policy) {
saved_details.tls_policy = strdup(tls_policy);
} else {
saved_details.tls_policy = NULL;
}
if (auth_policy) {
saved_details.auth_policy = strdup(auth_policy);
} else {
saved_details.auth_policy = NULL;
}
// raw connect
log_info("Raw connecting to server: %s", altdomain);
return connection_connect_raw(
saved_details.altdomain,
saved_details.port,
saved_details.tls_policy,
saved_details.auth_policy);
}
void void
session_autoping_fail(void) session_autoping_fail(void)
{ {
@ -261,6 +298,8 @@ session_process_events(void)
switch (conn_status) { switch (conn_status) {
case JABBER_CONNECTED: case JABBER_CONNECTED:
case JABBER_CONNECTING: case JABBER_CONNECTING:
case JABBER_RAW_CONNECTED:
case JABBER_RAW_CONNECTING:
case JABBER_DISCONNECTING: case JABBER_DISCONNECTING:
connection_check_events(); connection_check_events();
break; break;
@ -543,3 +582,4 @@ _session_free_saved_details(void)
FREE_SET_NULL(saved_details.tls_policy); FREE_SET_NULL(saved_details.tls_policy);
FREE_SET_NULL(saved_details.auth_policy); FREE_SET_NULL(saved_details.auth_policy);
} }

View File

@ -2782,6 +2782,9 @@ stanza_register_new_account(xmpp_ctx_t* ctx, const char* const user, const char*
xmpp_stanza_add_child(register_new_account, password_st); xmpp_stanza_add_child(register_new_account, password_st);
xmpp_stanza_release(password_st); xmpp_stanza_release(password_st);
xmpp_stanza_add_child(iq, register_new_account);
xmpp_stanza_release(register_new_account);
return iq; return iq;
} }

View File

@ -76,7 +76,9 @@ typedef enum {
JABBER_CONNECTING, JABBER_CONNECTING,
JABBER_CONNECTED, JABBER_CONNECTED,
JABBER_DISCONNECTING, JABBER_DISCONNECTING,
JABBER_DISCONNECTED JABBER_DISCONNECTED,
JABBER_RAW_CONNECTING,
JABBER_RAW_CONNECTED
} jabber_conn_status_t; } jabber_conn_status_t;
typedef enum { typedef enum {
@ -183,6 +185,8 @@ void session_init(void);
jabber_conn_status_t session_connect_with_details(const char* const jid, const char* const passwd, jabber_conn_status_t session_connect_with_details(const char* const jid, const char* const passwd,
const char* const altdomain, const int port, const char* const tls_policy, const char* const auth_policy); const char* const altdomain, const int port, const char* const tls_policy, const char* const auth_policy);
jabber_conn_status_t session_connect_with_account(const ProfAccount* const account); jabber_conn_status_t session_connect_with_account(const ProfAccount* const account);
jabber_conn_status_t session_connect_raw(const char* const altdomain, const int port, const char* const tls_policy, const char* const auth_policy);
void session_disconnect(void); void session_disconnect(void);
void session_shutdown(void); void session_shutdown(void);
void session_process_events(void); void session_process_events(void);