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:
parent
5ea1ccbb46
commit
2cc354b6ae
@ -9589,7 +9589,7 @@ cmd_register(ProfWin* window, const char* const command, gchar** args)
|
||||
|
||||
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) {
|
||||
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];
|
||||
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* confirm_passwd = ui_ask_password(true);
|
||||
|
||||
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);
|
||||
} else {
|
||||
cons_show("The two passwords do not match.");
|
||||
}
|
||||
|
||||
free(username);
|
||||
free(passwd);
|
||||
free(confirm_passwd);
|
||||
//}
|
||||
|
||||
options_destroy(options);
|
||||
|
||||
log_info("we are leaving the registration process");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -81,6 +81,13 @@ cl_ev_connect_account(ProfAccount* 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
|
||||
cl_ev_disconnect(void)
|
||||
{
|
||||
@ -262,3 +269,4 @@ cl_ev_send_priv_msg(ProfPrivateWin* privwin, const char* const msg, const char*
|
||||
jid_destroy(jidp);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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_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);
|
||||
|
||||
@ -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);
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -268,3 +268,4 @@ _shutdown(void)
|
||||
ui_close();
|
||||
prefs_close();
|
||||
}
|
||||
|
||||
|
@ -342,7 +342,7 @@ connection_connect_raw(const char* const altdomain, int port,
|
||||
#endif
|
||||
|
||||
if (connect_status == 0) {
|
||||
conn.conn_status = JABBER_CONNECTING;
|
||||
conn.conn_status = JABBER_RAW_CONNECTING;
|
||||
} else {
|
||||
conn.conn_status = JABBER_DISCONNECTED;
|
||||
}
|
||||
@ -686,6 +686,21 @@ _connection_handler(xmpp_conn_t* const xmpp_conn, const xmpp_conn_event_t status
|
||||
|
||||
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
|
||||
case XMPP_CONN_DISCONNECT:
|
||||
log_debug("Connection handler: XMPP_CONN_DISCONNECT");
|
||||
|
@ -2658,14 +2658,15 @@ _mam_rsm_id_handler(xmpp_stanza_t* const stanza, void* const userdata)
|
||||
void
|
||||
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_stanza_t* iq = stanza_register_new_account(ctx, user, password);
|
||||
|
||||
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);
|
||||
log_debug("registration stanza has been sent");
|
||||
xmpp_stanza_release(iq);
|
||||
}
|
||||
|
||||
|
@ -204,6 +204,43 @@ session_connect_with_details(const char* const jid, const char* const passwd, co
|
||||
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
|
||||
session_autoping_fail(void)
|
||||
{
|
||||
@ -261,6 +298,8 @@ session_process_events(void)
|
||||
switch (conn_status) {
|
||||
case JABBER_CONNECTED:
|
||||
case JABBER_CONNECTING:
|
||||
case JABBER_RAW_CONNECTED:
|
||||
case JABBER_RAW_CONNECTING:
|
||||
case JABBER_DISCONNECTING:
|
||||
connection_check_events();
|
||||
break;
|
||||
@ -543,3 +582,4 @@ _session_free_saved_details(void)
|
||||
FREE_SET_NULL(saved_details.tls_policy);
|
||||
FREE_SET_NULL(saved_details.auth_policy);
|
||||
}
|
||||
|
||||
|
@ -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_release(password_st);
|
||||
|
||||
xmpp_stanza_add_child(iq, register_new_account);
|
||||
xmpp_stanza_release(register_new_account);
|
||||
|
||||
return iq;
|
||||
}
|
||||
|
||||
|
@ -76,7 +76,9 @@ typedef enum {
|
||||
JABBER_CONNECTING,
|
||||
JABBER_CONNECTED,
|
||||
JABBER_DISCONNECTING,
|
||||
JABBER_DISCONNECTED
|
||||
JABBER_DISCONNECTED,
|
||||
JABBER_RAW_CONNECTING,
|
||||
JABBER_RAW_CONNECTED
|
||||
} jabber_conn_status_t;
|
||||
|
||||
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,
|
||||
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_raw(const char* const altdomain, const int port, const char* const tls_policy, const char* const auth_policy);
|
||||
void session_disconnect(void);
|
||||
void session_shutdown(void);
|
||||
void session_process_events(void);
|
||||
|
Loading…
Reference in New Issue
Block a user