mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Added enum for jabber connection status
Moved some UI code from Jabber module
This commit is contained in:
parent
4b0c614cb9
commit
a0e5cd28bb
20
command.c
20
command.c
@ -84,9 +84,9 @@ static int _handle_command(char *command, char *inp)
|
||||
static int _cmd_connect(char *inp)
|
||||
{
|
||||
int result = FALSE;
|
||||
int conn_status = jabber_connection_status();
|
||||
jabber_status_t conn_status = jabber_connection_status();
|
||||
|
||||
if ((conn_status != DISCONNECTED) && (conn_status != STARTED)) {
|
||||
if ((conn_status != JABBER_DISCONNECTED) && (conn_status != JABBER_STARTED)) {
|
||||
cons_not_disconnected();
|
||||
result = TRUE;
|
||||
} else if (strlen(inp) < 10) {
|
||||
@ -101,7 +101,13 @@ static int _cmd_connect(char *inp)
|
||||
inp_block();
|
||||
inp_get_password(passwd);
|
||||
inp_non_block();
|
||||
jabber_connect(user, passwd);
|
||||
|
||||
conn_status = jabber_connect(user, passwd);
|
||||
if (conn_status == JABBER_CONNECTING)
|
||||
cons_good_show("Connecting...");
|
||||
if (conn_status == JABBER_DISCONNECTED)
|
||||
cons_bad_show("Connection to server failed.");
|
||||
|
||||
result = TRUE;
|
||||
}
|
||||
|
||||
@ -122,9 +128,9 @@ static int _cmd_help(void)
|
||||
|
||||
static int _cmd_who(void)
|
||||
{
|
||||
int conn_status = jabber_connection_status();
|
||||
jabber_status_t conn_status = jabber_connection_status();
|
||||
|
||||
if (conn_status != CONNECTED)
|
||||
if (conn_status != JABBER_CONNECTED)
|
||||
cons_not_connected();
|
||||
else
|
||||
jabber_roster_request();
|
||||
@ -137,9 +143,9 @@ static int _cmd_msg(char *inp)
|
||||
char *usr = NULL;
|
||||
char *msg = NULL;
|
||||
|
||||
int conn_status = jabber_connection_status();
|
||||
jabber_status_t conn_status = jabber_connection_status();
|
||||
|
||||
if (conn_status != CONNECTED) {
|
||||
if (conn_status != JABBER_CONNECTED) {
|
||||
cons_not_connected();
|
||||
} else {
|
||||
// copy input
|
||||
|
28
jabber.c
28
jabber.c
@ -36,7 +36,7 @@ static xmpp_ctx_t *_ctx;
|
||||
static xmpp_conn_t *_conn;
|
||||
|
||||
// connection status
|
||||
static int _conn_status = STARTED;
|
||||
static jabber_status_t _conn_status = JABBER_STARTED;
|
||||
|
||||
void xmpp_file_logger(void * const userdata, const xmpp_log_level_t level,
|
||||
const char * const area, const char * const msg);
|
||||
@ -65,12 +65,12 @@ static int _jabber_message_handler(xmpp_conn_t * const conn,
|
||||
static int _roster_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
||||
void * const userdata);
|
||||
|
||||
int jabber_connection_status(void)
|
||||
jabber_status_t jabber_connection_status(void)
|
||||
{
|
||||
return (_conn_status);
|
||||
}
|
||||
|
||||
int jabber_connect(char *user, char *passwd)
|
||||
jabber_status_t jabber_connect(char *user, char *passwd)
|
||||
{
|
||||
xmpp_initialize();
|
||||
|
||||
@ -89,31 +89,27 @@ int jabber_connect(char *user, char *passwd)
|
||||
|
||||
int connect_status = xmpp_connect_client(_conn, NULL, 0, _jabber_conn_handler, _ctx);
|
||||
|
||||
if (connect_status == 0) {
|
||||
cons_good_show("Connecting...");
|
||||
_conn_status = CONNECTING;
|
||||
}
|
||||
else {
|
||||
cons_bad_show("XMPP connection failure");
|
||||
_conn_status = DISCONNECTED;
|
||||
}
|
||||
if (connect_status == 0)
|
||||
_conn_status = JABBER_CONNECTING;
|
||||
else
|
||||
_conn_status = JABBER_DISCONNECTED;
|
||||
|
||||
return _conn_status;
|
||||
}
|
||||
|
||||
void jabber_disconnect(void)
|
||||
{
|
||||
if (_conn_status == CONNECTED) {
|
||||
if (_conn_status == JABBER_CONNECTED) {
|
||||
xmpp_conn_release(_conn);
|
||||
xmpp_ctx_free(_ctx);
|
||||
xmpp_shutdown();
|
||||
_conn_status = DISCONNECTED;
|
||||
_conn_status = JABBER_DISCONNECTED;
|
||||
}
|
||||
}
|
||||
|
||||
void jabber_process_events(void)
|
||||
{
|
||||
if (_conn_status == CONNECTED || _conn_status == CONNECTING)
|
||||
if (_conn_status == JABBER_CONNECTED || _conn_status == JABBER_CONNECTING)
|
||||
xmpp_run_once(_ctx, 10);
|
||||
}
|
||||
|
||||
@ -201,13 +197,13 @@ static void _jabber_conn_handler(xmpp_conn_t * const conn,
|
||||
xmpp_send(conn, pres);
|
||||
xmpp_stanza_release(pres);
|
||||
jabber_roster_request();
|
||||
_conn_status = CONNECTED;
|
||||
_conn_status = JABBER_CONNECTED;
|
||||
}
|
||||
else {
|
||||
cons_bad_show("Login failed.");
|
||||
log_msg(CONN, "disconnected");
|
||||
xmpp_stop(ctx);
|
||||
_conn_status = DISCONNECTED;
|
||||
_conn_status = JABBER_DISCONNECTED;
|
||||
}
|
||||
}
|
||||
|
||||
|
14
jabber.h
14
jabber.h
@ -23,13 +23,15 @@
|
||||
#ifndef JABBER_H
|
||||
#define JABBER_H
|
||||
|
||||
#define STARTED 0
|
||||
#define CONNECTING 1
|
||||
#define CONNECTED 2
|
||||
#define DISCONNECTED 3
|
||||
typedef enum {
|
||||
JABBER_STARTED,
|
||||
JABBER_CONNECTING,
|
||||
JABBER_CONNECTED,
|
||||
JABBER_DISCONNECTED
|
||||
} jabber_status_t;
|
||||
|
||||
int jabber_connection_status(void);
|
||||
int jabber_connect(char *user, char *passwd);
|
||||
jabber_status_t jabber_connection_status(void);
|
||||
jabber_status_t jabber_connect(char *user, char *passwd);
|
||||
void jabber_disconnect(void);
|
||||
void jabber_roster_request(void);
|
||||
void jabber_process_events(void);
|
||||
|
Loading…
Reference in New Issue
Block a user