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)
|
static int _cmd_connect(char *inp)
|
||||||
{
|
{
|
||||||
int result = FALSE;
|
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();
|
cons_not_disconnected();
|
||||||
result = TRUE;
|
result = TRUE;
|
||||||
} else if (strlen(inp) < 10) {
|
} else if (strlen(inp) < 10) {
|
||||||
@ -101,7 +101,13 @@ static int _cmd_connect(char *inp)
|
|||||||
inp_block();
|
inp_block();
|
||||||
inp_get_password(passwd);
|
inp_get_password(passwd);
|
||||||
inp_non_block();
|
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;
|
result = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,9 +128,9 @@ static int _cmd_help(void)
|
|||||||
|
|
||||||
static int _cmd_who(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();
|
cons_not_connected();
|
||||||
else
|
else
|
||||||
jabber_roster_request();
|
jabber_roster_request();
|
||||||
@ -137,9 +143,9 @@ static int _cmd_msg(char *inp)
|
|||||||
char *usr = NULL;
|
char *usr = NULL;
|
||||||
char *msg = 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();
|
cons_not_connected();
|
||||||
} else {
|
} else {
|
||||||
// copy input
|
// copy input
|
||||||
|
28
jabber.c
28
jabber.c
@ -36,7 +36,7 @@ static xmpp_ctx_t *_ctx;
|
|||||||
static xmpp_conn_t *_conn;
|
static xmpp_conn_t *_conn;
|
||||||
|
|
||||||
// connection status
|
// 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,
|
void xmpp_file_logger(void * const userdata, const xmpp_log_level_t level,
|
||||||
const char * const area, const char * const msg);
|
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,
|
static int _roster_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
||||||
void * const userdata);
|
void * const userdata);
|
||||||
|
|
||||||
int jabber_connection_status(void)
|
jabber_status_t jabber_connection_status(void)
|
||||||
{
|
{
|
||||||
return (_conn_status);
|
return (_conn_status);
|
||||||
}
|
}
|
||||||
|
|
||||||
int jabber_connect(char *user, char *passwd)
|
jabber_status_t jabber_connect(char *user, char *passwd)
|
||||||
{
|
{
|
||||||
xmpp_initialize();
|
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);
|
int connect_status = xmpp_connect_client(_conn, NULL, 0, _jabber_conn_handler, _ctx);
|
||||||
|
|
||||||
if (connect_status == 0) {
|
if (connect_status == 0)
|
||||||
cons_good_show("Connecting...");
|
_conn_status = JABBER_CONNECTING;
|
||||||
_conn_status = CONNECTING;
|
else
|
||||||
}
|
_conn_status = JABBER_DISCONNECTED;
|
||||||
else {
|
|
||||||
cons_bad_show("XMPP connection failure");
|
|
||||||
_conn_status = DISCONNECTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
return _conn_status;
|
return _conn_status;
|
||||||
}
|
}
|
||||||
|
|
||||||
void jabber_disconnect(void)
|
void jabber_disconnect(void)
|
||||||
{
|
{
|
||||||
if (_conn_status == CONNECTED) {
|
if (_conn_status == JABBER_CONNECTED) {
|
||||||
xmpp_conn_release(_conn);
|
xmpp_conn_release(_conn);
|
||||||
xmpp_ctx_free(_ctx);
|
xmpp_ctx_free(_ctx);
|
||||||
xmpp_shutdown();
|
xmpp_shutdown();
|
||||||
_conn_status = DISCONNECTED;
|
_conn_status = JABBER_DISCONNECTED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void jabber_process_events(void)
|
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);
|
xmpp_run_once(_ctx, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -201,13 +197,13 @@ static void _jabber_conn_handler(xmpp_conn_t * const conn,
|
|||||||
xmpp_send(conn, pres);
|
xmpp_send(conn, pres);
|
||||||
xmpp_stanza_release(pres);
|
xmpp_stanza_release(pres);
|
||||||
jabber_roster_request();
|
jabber_roster_request();
|
||||||
_conn_status = CONNECTED;
|
_conn_status = JABBER_CONNECTED;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
cons_bad_show("Login failed.");
|
cons_bad_show("Login failed.");
|
||||||
log_msg(CONN, "disconnected");
|
log_msg(CONN, "disconnected");
|
||||||
xmpp_stop(ctx);
|
xmpp_stop(ctx);
|
||||||
_conn_status = DISCONNECTED;
|
_conn_status = JABBER_DISCONNECTED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
14
jabber.h
14
jabber.h
@ -23,13 +23,15 @@
|
|||||||
#ifndef JABBER_H
|
#ifndef JABBER_H
|
||||||
#define JABBER_H
|
#define JABBER_H
|
||||||
|
|
||||||
#define STARTED 0
|
typedef enum {
|
||||||
#define CONNECTING 1
|
JABBER_STARTED,
|
||||||
#define CONNECTED 2
|
JABBER_CONNECTING,
|
||||||
#define DISCONNECTED 3
|
JABBER_CONNECTED,
|
||||||
|
JABBER_DISCONNECTED
|
||||||
|
} jabber_status_t;
|
||||||
|
|
||||||
int jabber_connection_status(void);
|
jabber_status_t jabber_connection_status(void);
|
||||||
int jabber_connect(char *user, char *passwd);
|
jabber_status_t jabber_connect(char *user, char *passwd);
|
||||||
void jabber_disconnect(void);
|
void jabber_disconnect(void);
|
||||||
void jabber_roster_request(void);
|
void jabber_roster_request(void);
|
||||||
void jabber_process_events(void);
|
void jabber_process_events(void);
|
||||||
|
Loading…
Reference in New Issue
Block a user