mirror of
https://github.com/profanity-im/profanity.git
synced 2025-02-02 15:08:15 -05:00
Handles failed logins correctly
This commit is contained in:
parent
3be10300f4
commit
03b90cf5ab
@ -19,6 +19,7 @@ int handle_start_command(char *cmd)
|
||||
result = QUIT_PROF;
|
||||
} else if (strncmp(cmd, "/help", 5) == 0) {
|
||||
cons_help();
|
||||
gui_refresh();
|
||||
result = AWAIT_COMMAND;
|
||||
} else if (strncmp(cmd, "/connect ", 9) == 0) {
|
||||
char *user;
|
||||
@ -28,10 +29,14 @@ int handle_start_command(char *cmd)
|
||||
status_bar_refresh();
|
||||
char passwd[20];
|
||||
inp_get_password(passwd);
|
||||
jabber_connect(user, passwd);
|
||||
result = START_MAIN;
|
||||
int connect_status = jabber_connect(user, passwd);
|
||||
if (connect_status == CONNECTING)
|
||||
result = START_MAIN;
|
||||
else
|
||||
result = AWAIT_COMMAND;
|
||||
} else {
|
||||
cons_bad_command(cmd);
|
||||
gui_refresh();
|
||||
result = AWAIT_COMMAND;
|
||||
}
|
||||
|
||||
|
@ -32,6 +32,11 @@ void inp_non_block(void)
|
||||
wtimeout(inp_win, 0);
|
||||
}
|
||||
|
||||
void inp_block(void)
|
||||
{
|
||||
wtimeout(inp_win, -1);
|
||||
}
|
||||
|
||||
void inp_poll_char(int *ch, char command[], int *size)
|
||||
{
|
||||
int inp_y = 0;
|
||||
|
26
jabber.c
26
jabber.c
@ -12,6 +12,9 @@ static xmpp_log_t *_log;
|
||||
static xmpp_ctx_t *_ctx;
|
||||
static xmpp_conn_t *_conn;
|
||||
|
||||
// connection status
|
||||
static int _conn_status = CONNECTING;
|
||||
|
||||
void xmpp_file_logger(void * const userdata, const xmpp_log_level_t level,
|
||||
const char * const area, const char * const msg);
|
||||
|
||||
@ -39,7 +42,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);
|
||||
|
||||
void jabber_connect(char *user, char *passwd)
|
||||
int jabber_connection_status(void)
|
||||
{
|
||||
return (_conn_status);
|
||||
}
|
||||
|
||||
int jabber_connect(char *user, char *passwd)
|
||||
{
|
||||
xmpp_initialize();
|
||||
|
||||
@ -52,10 +60,16 @@ void jabber_connect(char *user, char *passwd)
|
||||
|
||||
int connect_status = xmpp_connect_client(_conn, NULL, 0, _jabber_conn_handler, _ctx);
|
||||
|
||||
if (connect_status == -1)
|
||||
cons_show("XMPP connection failure");
|
||||
else
|
||||
if (connect_status == 0) {
|
||||
cons_show("Connecting...");
|
||||
_conn_status = CONNECTING;
|
||||
}
|
||||
else {
|
||||
cons_show("XMPP connection failure");
|
||||
_conn_status = DISCONNECTED;
|
||||
}
|
||||
|
||||
return _conn_status;
|
||||
}
|
||||
|
||||
void jabber_disconnect(void)
|
||||
@ -63,6 +77,7 @@ void jabber_disconnect(void)
|
||||
xmpp_conn_release(_conn);
|
||||
xmpp_ctx_free(_ctx);
|
||||
xmpp_shutdown();
|
||||
_conn_status = DISCONNECTED;
|
||||
}
|
||||
|
||||
void jabber_process_events(void)
|
||||
@ -137,6 +152,7 @@ static void _jabber_conn_handler(xmpp_conn_t * const conn,
|
||||
if (status == XMPP_CONN_CONNECT) {
|
||||
char line[100];
|
||||
sprintf(line, "%s logged in successfully.", xmpp_conn_get_jid(conn));
|
||||
title_bar_connected();
|
||||
|
||||
cons_show(line);
|
||||
status_bar_print_message(xmpp_conn_get_jid(conn));
|
||||
@ -151,11 +167,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;
|
||||
}
|
||||
else {
|
||||
cons_show("Login failed.");
|
||||
log_msg(CONN, "disconnected");
|
||||
xmpp_stop(ctx);
|
||||
_conn_status = DISCONNECTED;
|
||||
}
|
||||
}
|
||||
|
||||
|
7
jabber.h
7
jabber.h
@ -1,7 +1,12 @@
|
||||
#ifndef JABBER_H
|
||||
#define JABBER_H
|
||||
|
||||
void jabber_connect(char *user, char *passwd);
|
||||
#define CONNECTING 0
|
||||
#define CONNECTED 1
|
||||
#define DISCONNECTED 2
|
||||
|
||||
int jabber_connection_status(void);
|
||||
int jabber_connect(char *user, char *passwd);
|
||||
void jabber_disconnect(void);
|
||||
void jabber_roster_request(void);
|
||||
void jabber_process_events(void);
|
||||
|
5
main.c
5
main.c
@ -4,10 +4,13 @@
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int exit_status = LOGIN_FAIL;
|
||||
log_init();
|
||||
gui_init();
|
||||
|
||||
profanity_start();
|
||||
while (exit_status == LOGIN_FAIL) {
|
||||
exit_status = profanity_start();
|
||||
}
|
||||
|
||||
gui_close();
|
||||
log_close();
|
||||
|
24
profanity.c
24
profanity.c
@ -9,15 +9,19 @@
|
||||
#include "jabber.h"
|
||||
#include "command.h"
|
||||
|
||||
static void _profanity_main(void);
|
||||
static int _profanity_main(void);
|
||||
static void _profanity_event_loop(int *ch, char *cmd, int *size);
|
||||
static void _process_special_keys(int *ch);
|
||||
|
||||
void profanity_start(void)
|
||||
int profanity_start(void)
|
||||
{
|
||||
int exit_status = QUIT;
|
||||
int cmd_result = AWAIT_COMMAND;
|
||||
char cmd[50];
|
||||
|
||||
title_bar_disconnected();
|
||||
gui_refresh();
|
||||
|
||||
while (cmd_result == AWAIT_COMMAND) {
|
||||
title_bar_refresh();
|
||||
status_bar_refresh();
|
||||
@ -26,11 +30,13 @@ void profanity_start(void)
|
||||
}
|
||||
|
||||
if (cmd_result == START_MAIN) {
|
||||
_profanity_main();
|
||||
exit_status = _profanity_main();
|
||||
}
|
||||
|
||||
return exit_status;
|
||||
}
|
||||
|
||||
static void _profanity_main(void)
|
||||
static int _profanity_main(void)
|
||||
{
|
||||
int cmd_result = TRUE;
|
||||
|
||||
@ -40,14 +46,22 @@ static void _profanity_main(void)
|
||||
char cmd[100];
|
||||
int size = 0;
|
||||
|
||||
while(ch != '\n')
|
||||
while(ch != '\n') {
|
||||
_profanity_event_loop(&ch, cmd, &size);
|
||||
|
||||
int conn_status = jabber_connection_status();
|
||||
if (conn_status == DISCONNECTED) {
|
||||
inp_block();
|
||||
return LOGIN_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
cmd[size++] = '\0';
|
||||
cmd_result = handle_command(cmd);
|
||||
}
|
||||
|
||||
jabber_disconnect();
|
||||
return QUIT;
|
||||
}
|
||||
|
||||
static void _profanity_event_loop(int *ch, char *cmd, int *size)
|
||||
|
@ -1,6 +1,9 @@
|
||||
#ifndef PROFANITY_H
|
||||
#define PROFANITY_H
|
||||
|
||||
void profanity_start(void);
|
||||
#define QUIT 0
|
||||
#define LOGIN_FAIL 1
|
||||
|
||||
int profanity_start(void);
|
||||
|
||||
#endif
|
||||
|
16
title_bar.c
16
title_bar.c
@ -15,6 +15,22 @@ void create_title_bar(void)
|
||||
title_bar_show(title);
|
||||
}
|
||||
|
||||
void title_bar_connected(void)
|
||||
{
|
||||
int rows, cols;
|
||||
getmaxyx(stdscr, rows, cols);
|
||||
|
||||
mvwprintw(title_bar, 0, cols - 12, " connected");
|
||||
}
|
||||
|
||||
void title_bar_disconnected(void)
|
||||
{
|
||||
int rows, cols;
|
||||
getmaxyx(stdscr, rows, cols);
|
||||
|
||||
mvwprintw(title_bar, 0, cols - 12, "disconnected");
|
||||
}
|
||||
|
||||
void title_bar_refresh(void)
|
||||
{
|
||||
touchwin(title_bar);
|
||||
|
@ -21,6 +21,8 @@ void create_input_window(void);
|
||||
// title bar actions
|
||||
void title_bar_refresh(void);
|
||||
void title_bar_show(char *title);
|
||||
void title_bar_connected(void);
|
||||
void title_bar_disconnected(void);
|
||||
|
||||
// main window actions
|
||||
int win_is_active(int i);
|
||||
@ -51,6 +53,7 @@ void inp_poll_char(int *ch, char command[], int *size);
|
||||
void inp_clear(void);
|
||||
void inp_put_back(void);
|
||||
void inp_non_block(void);
|
||||
void inp_block(void);
|
||||
void inp_get_password(char *passwd);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user