From 7e8ab90d3995adc059de04f0475dd046a365aac6 Mon Sep 17 00:00:00 2001 From: Peter Vilim Date: Wed, 14 Jan 2015 17:14:00 -0600 Subject: [PATCH 001/252] Strip quote chars from name autocomplete --- src/command/command.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/command/command.c b/src/command/command.c index 86185f59..f18191bc 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -98,6 +98,7 @@ static char * _role_autocomplete(char *input, int *size); static char * _resource_autocomplete(char *input, int *size); static char * _titlebar_autocomplete(char *input, int *size); static char * _inpblock_autocomplete(char *input, int *size); +static char * _strip_quotes_from_names(char *input, int *size); GHashTable *commands = NULL; @@ -1932,6 +1933,8 @@ _cmd_complete_parameters(char *input, int *size) if (nick_ac != NULL) { gchar *nick_choices[] = { "/msg", "/info", "/caps", "/status", "/software" } ; + // Remove quote character before and after names when doing autocomplete + input = _strip_quotes_from_names(input, size); for (i = 0; i < ARRAY_SIZE(nick_choices); i++) { result = autocomplete_param_with_ac(input, size, nick_choices[i], nick_ac, TRUE); @@ -1946,6 +1949,8 @@ _cmd_complete_parameters(char *input, int *size) // otherwise autocomplete using roster } else { gchar *contact_choices[] = { "/msg", "/info", "/status" }; + // Remove quote character before and after names when doing autocomplete + input = _strip_quotes_from_names(input, size); for (i = 0; i < ARRAY_SIZE(contact_choices); i++) { result = autocomplete_param_with_func(input, size, contact_choices[i], roster_contact_autocomplete); @@ -2984,3 +2989,21 @@ _account_autocomplete(char *input, int *size) found = autocomplete_param_with_ac(input, size, "/account", account_ac, TRUE); return found; } + +static char * +_strip_quotes_from_names(char *input, int *size) { + // Remove starting quote if it exists + if(strchr(input, '"') != NULL) { + if(strchr(input, ' ') + 1 == strchr(input, '"')) { + memmove(strchr(input, '"'), strchr(input, '"')+1, strchr(input, '\0') - strchr(input, '"')); + } + } + + // Remove ending quote if it exists + if(strchr(input, '"') != NULL) { + if(strchr(input, '\0') - 1 == strchr(input, '"')) { + memmove(strchr(input, '"'), strchr(input, '"')+1, strchr(input, '\0') - strchr(input, '"')); + } + } + return input; +} From 89260280d13b8ae7166913affa5f973f260c8b7c Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 17 Jan 2015 22:03:22 +0000 Subject: [PATCH 002/252] Fix backspace for utf8 wide chars --- src/ui/inputwin.c | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index 85ddc79a..5279de7c 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -588,29 +588,21 @@ _handle_edit(int key_type, const wint_t ch) static void _handle_backspace(void) { - int inp_x = getcurx(inp_win); + int col = getcurx(inp_win); int display_size = utf8_display_len(input); + int input_len_utf8 = g_utf8_strlen(input, -1); roster_reset_search_attempts(); + if (display_size > 0) { - // if at end, delete last char - if (inp_x >= display_size) { - gchar *start = g_utf8_substring(input, 0, inp_x-1); - for (input_len_bytes = 0; input_len_bytes < strlen(start); input_len_bytes++) { - input[input_len_bytes] = start[input_len_bytes]; - } - input[input_len_bytes] = '\0'; - - g_free(start); - - _clear_input(); - waddstr(inp_win, input); - wmove(inp_win, 0, inp_x -1); + if (col >= display_size) { + gchar *new_input = g_utf8_substring(input, 0, input_len_utf8-1); + inp_replace_input(new_input); // if in middle, delete and shift chars left - } else if (inp_x > 0 && inp_x < display_size) { - gchar *start = g_utf8_substring(input, 0, inp_x - 1); - gchar *end = g_utf8_substring(input, inp_x, input_len_bytes); + } else if (col > 0 && col < display_size) { + gchar *start = g_utf8_substring(input, 0, col - 1); + gchar *end = g_utf8_substring(input, col, input_len_bytes); GString *new = g_string_new(start); g_string_append(new, end); @@ -625,11 +617,11 @@ _handle_backspace(void) _clear_input(); waddstr(inp_win, input); - wmove(inp_win, 0, inp_x -1); + wmove(inp_win, 0, col -1); } // if gone off screen to left, jump left (half a screen worth) - if (inp_x <= pad_start) { + if (col <= pad_start) { pad_start = pad_start - (cols / 2); if (pad_start < 0) { pad_start = 0; From 8954adc62019cd4147c0c05cb183326ee25ad546 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 18 Jan 2015 19:55:48 +0000 Subject: [PATCH 003/252] Handle wide chars for arrow keys and backspace --- src/ui/inputwin.c | 350 ++++++++++++++++++++++++++-------------------- 1 file changed, 199 insertions(+), 151 deletions(-) diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index 5279de7c..a482e292 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -61,7 +61,7 @@ #include "ui/windows.h" #include "xmpp/xmpp.h" -#define _inp_win_update_virtual() pnoutrefresh(inp_win, 0, pad_start, rows-1, 0, rows-1, cols-1) +#define _inp_win_update_virtual() pnoutrefresh(inp_win, 0, pad_start, wrows-1, 0, wrows-1, wcols-1) #define KEY_CTRL_A 0001 #define KEY_CTRL_B 0002 @@ -79,11 +79,12 @@ static WINDOW *inp_win; static History history; -static char input[INP_WIN_MAX]; -static int input_len_bytes; +static char line[INP_WIN_MAX]; +static int line_bytes_len; +static int line_utf8_pos; static int pad_start = 0; -static int rows, cols; +static int wrows, wcols; static int _handle_edit(int key_type, const wint_t ch); static int _handle_alt_key(int key); @@ -101,25 +102,27 @@ create_input_window(void) #else ESCDELAY = 25; #endif - getmaxyx(stdscr, rows, cols); + getmaxyx(stdscr, wrows, wcols); inp_win = newpad(1, INP_WIN_MAX); wbkgd(inp_win, theme_attrs(THEME_INPUT_TEXT));; keypad(inp_win, TRUE); wmove(inp_win, 0, 0); _inp_win_update_virtual(); history = history_new(MAX_HISTORY); + line_bytes_len = 0; + line_utf8_pos = 0; } void inp_win_resize(void) { int inp_x; - getmaxyx(stdscr, rows, cols); + getmaxyx(stdscr, wrows, wcols); inp_x = getcurx(inp_win); // if lost cursor off screen, move contents to show it - if (inp_x >= pad_start + cols) { - pad_start = inp_x - (cols / 2); + if (inp_x >= pad_start + wcols) { + pad_start = inp_x - (wcols / 2); if (pad_start < 0) { pad_start = 0; } @@ -144,15 +147,14 @@ inp_block(void) char * inp_read(int *key_type, wint_t *ch) { - int display_size = utf8_display_len(input); - // echo off, and get some more input noecho(); *key_type = wget_wch(inp_win, ch); + int display_len = utf8_display_len(line); gboolean in_command = FALSE; - if ((display_size > 0 && input[0] == '/') || - (display_size == 0 && *ch == '/')) { + if ((display_len > 0 && line[0] == '/') || + (display_len == 0 && *ch == '/')) { in_command = TRUE; } @@ -166,59 +168,71 @@ inp_read(int *key_type, wint_t *ch) // if it wasn't an arrow key etc if (!_handle_edit(*key_type, *ch)) { if (_printable(*ch) && *key_type != KEY_CODE_YES) { - if (input_len_bytes >= INP_WIN_MAX) { + if (line_bytes_len >= INP_WIN_MAX) { *ch = ERR; return NULL; } - int inp_x = getcurx(inp_win); + int col = getcurx(inp_win); + int utf8_len = g_utf8_strlen(line, -1); // handle insert if not at end of input - if (inp_x < display_size) { + if (line_utf8_pos < utf8_len) { char bytes[MB_CUR_MAX]; - size_t utf_len = wcrtomb(bytes, *ch, NULL); + size_t utf8_ch_len = wcrtomb(bytes, *ch, NULL); + bytes[utf8_ch_len] = '\0'; - char *next_ch = g_utf8_offset_to_pointer(input, inp_x); - char *offset; - for (offset = &input[input_len_bytes - 1]; offset >= next_ch; offset--) { - *(offset + utf_len) = *offset; - } - int i; - for (i = 0; i < utf_len; i++) { - *(next_ch + i) = bytes[i]; - } + gchar *start = g_utf8_substring(line, 0, line_utf8_pos); + gchar *end = g_utf8_substring(line, line_utf8_pos, utf8_len); + GString *new_line = g_string_new(start); + g_string_append(new_line, bytes); + g_string_append(new_line, end); - input_len_bytes += utf_len; - input[input_len_bytes] = '\0'; - waddstr(inp_win, next_ch); - wmove(inp_win, 0, inp_x + 1); + int old_pos = line_utf8_pos; + inp_replace_input(new_line->str); + line_utf8_pos = old_pos+1; - if (inp_x - pad_start > cols-3) { - pad_start++; - _inp_win_update_virtual(); + g_free(start); + g_free(end); + g_string_free(new_line, TRUE); + + col++; + gunichar uni = g_utf8_get_char(bytes); + if (g_unichar_iswide(uni)) { + col++; } + wmove(inp_win, 0, col); // otherwise just append } else { + int display_len = utf8_display_len(line); char bytes[MB_CUR_MAX+1]; - size_t utf_len = wcrtomb(bytes, *ch, NULL); + size_t utf8_ch_len = wcrtomb(bytes, *ch, NULL); // wcrtomb can return (size_t) -1 - if (utf_len < MB_CUR_MAX) { + if (utf8_ch_len < MB_CUR_MAX) { int i; - for (i = 0 ; i < utf_len; i++) { - input[input_len_bytes++] = bytes[i]; + for (i = 0 ; i < utf8_ch_len; i++) { + line[line_bytes_len++] = bytes[i]; } - input[input_len_bytes] = '\0'; + line[line_bytes_len] = '\0'; - bytes[utf_len] = '\0'; + bytes[utf8_ch_len] = '\0'; waddstr(inp_win, bytes); - display_size++; + + line_utf8_pos++; + + col++; + gunichar uni = g_utf8_get_char(bytes); + if (g_unichar_iswide(uni)) { + col++; + } + wmove(inp_win, 0, col); // if gone over screen size follow input - int rows, cols; - getmaxyx(stdscr, rows, cols); - if (display_size - pad_start > cols-2) { + int wrows, wcols; + getmaxyx(stdscr, wrows, wcols); + if (display_len - pad_start > wcols-2) { pad_start++; _inp_win_update_virtual(); } @@ -231,13 +245,22 @@ inp_read(int *key_type, wint_t *ch) echo(); + char *result = NULL; if (*ch == '\n') { - input[input_len_bytes] = '\0'; - input_len_bytes = 0; - return strdup(input); - } else { - return NULL; + line[line_bytes_len] = '\0'; + result = strdup(line); + line[0] = '\0'; + line_bytes_len = 0; + line_utf8_pos = 0; } + + if (*ch != ERR && *key_type != ERR) { + cons_debug("CURR COL = %d", getcurx(inp_win)); + cons_debug("CURR UNI = %d", line_utf8_pos); + cons_debug(""); + } + + return result; } void @@ -262,11 +285,11 @@ inp_put_back(void) void inp_replace_input(const char * const new_input) { - strncpy(input, new_input, INP_WIN_MAX); - input_len_bytes = strlen(input); + strncpy(line, new_input, INP_WIN_MAX); + line_bytes_len = strlen(line); inp_win_reset(); - input[input_len_bytes] = '\0'; - waddstr(inp_win, input); + waddstr(inp_win, line); + _go_to_end(); } @@ -301,15 +324,16 @@ _handle_edit(int key_type, const wint_t ch) { char *prev = NULL; char *next = NULL; - int inp_x = getcurx(inp_win); + int col = getcurx(inp_win); int next_ch; - int display_size = utf8_display_len(input); + int display_size = utf8_display_len(line); + int utf8_len = g_utf8_strlen(line, -1); // CTRL-LEFT - if ((key_type == KEY_CODE_YES) && (ch == 547 || ch == 545 || ch == 544 || ch == 540 || ch == 539) && (inp_x > 0)) { - input[input_len_bytes] = '\0'; - gchar *curr_ch = g_utf8_offset_to_pointer(input, inp_x); - curr_ch = g_utf8_find_prev_char(input, curr_ch); + if ((key_type == KEY_CODE_YES) && (ch == 547 || ch == 545 || ch == 544 || ch == 540 || ch == 539) && (col > 0)) { + line[line_bytes_len] = '\0'; + gchar *curr_ch = g_utf8_offset_to_pointer(line, col); + curr_ch = g_utf8_find_prev_char(line, curr_ch); gchar *prev_ch; gunichar curr_uni; gunichar prev_uni; @@ -318,9 +342,9 @@ _handle_edit(int key_type, const wint_t ch) curr_uni = g_utf8_get_char(curr_ch); if (g_unichar_isspace(curr_uni)) { - curr_ch = g_utf8_find_prev_char(input, curr_ch); + curr_ch = g_utf8_find_prev_char(line, curr_ch); } else { - prev_ch = g_utf8_find_prev_char(input, curr_ch); + prev_ch = g_utf8_find_prev_char(line, curr_ch); if (prev_ch == NULL) { curr_ch = NULL; break; @@ -336,17 +360,17 @@ _handle_edit(int key_type, const wint_t ch) } if (curr_ch == NULL) { - inp_x = 0; - wmove(inp_win, 0, inp_x); + col = 0; + wmove(inp_win, 0, col); } else { - glong offset = g_utf8_pointer_to_offset(input, curr_ch); - inp_x = offset; - wmove(inp_win, 0, inp_x); + glong offset = g_utf8_pointer_to_offset(line, curr_ch); + col = offset; + wmove(inp_win, 0, col); } // if gone off screen to left, jump left (half a screen worth) - if (inp_x <= pad_start) { - pad_start = pad_start - (cols / 2); + if (col <= pad_start) { + pad_start = pad_start - (wcols / 2); if (pad_start < 0) { pad_start = 0; } @@ -356,15 +380,15 @@ _handle_edit(int key_type, const wint_t ch) return 1; // CTRL-RIGHT - } else if ((key_type == KEY_CODE_YES) && (ch == 562 || ch == 560 || ch == 555 || ch == 559 || ch == 554) && (inp_x < display_size)) { - input[input_len_bytes] = '\0'; - gchar *curr_ch = g_utf8_offset_to_pointer(input, inp_x); + } else if ((key_type == KEY_CODE_YES) && (ch == 562 || ch == 560 || ch == 555 || ch == 559 || ch == 554) && (col < display_size)) { + line[line_bytes_len] = '\0'; + gchar *curr_ch = g_utf8_offset_to_pointer(line, col); gchar *next_ch = g_utf8_find_next_char(curr_ch, NULL); gunichar curr_uni; gunichar next_uni; gboolean moved = FALSE; - while (g_utf8_pointer_to_offset(input, next_ch) < display_size) { + while (g_utf8_pointer_to_offset(line, next_ch) < display_size) { curr_uni = g_utf8_get_char(curr_ch); next_uni = g_utf8_get_char(next_ch); curr_ch = next_ch; @@ -378,21 +402,21 @@ _handle_edit(int key_type, const wint_t ch) } if (next_ch == NULL) { - inp_x = display_size; - wmove(inp_win, 0, inp_x); + col = display_size; + wmove(inp_win, 0, col); } else { - glong offset = g_utf8_pointer_to_offset(input, curr_ch); + glong offset = g_utf8_pointer_to_offset(line, curr_ch); if (offset == display_size - 1) { - inp_x = offset + 1; + col = offset + 1; } else { - inp_x = offset; + col = offset; } - wmove(inp_win, 0, inp_x); + wmove(inp_win, 0, col); } // if gone off screen to right, jump right (half a screen worth) - if (inp_x > pad_start + cols) { - pad_start = pad_start + (cols / 2); + if (col > pad_start + wcols) { + pad_start = pad_start + (wcols / 2); _inp_win_update_virtual(); } @@ -418,7 +442,7 @@ _handle_edit(int key_type, const wint_t ch) if (next_ch != ERR) { return _handle_alt_key(next_ch); } else { - input_len_bytes = 0; + line_bytes_len = 0; inp_win_reset(); return 1; } @@ -438,35 +462,35 @@ _handle_edit(int key_type, const wint_t ch) return 0; } case KEY_CTRL_D: - if (inp_x == display_size-1) { - gchar *start = g_utf8_substring(input, 0, inp_x); - for (input_len_bytes = 0; input_len_bytes < strlen(start); input_len_bytes++) { - input[input_len_bytes] = start[input_len_bytes]; + if (col == display_size-1) { + gchar *start = g_utf8_substring(line, 0, col); + for (line_bytes_len = 0; line_bytes_len < strlen(start); line_bytes_len++) { + line[line_bytes_len] = start[line_bytes_len]; } - input[input_len_bytes] = '\0'; + line[line_bytes_len] = '\0'; g_free(start); _clear_input(); - waddstr(inp_win, input); - } else if (inp_x < display_size-1) { - gchar *start = g_utf8_substring(input, 0, inp_x); - gchar *end = g_utf8_substring(input, inp_x+1, input_len_bytes); + waddstr(inp_win, line); + } else if (col < display_size-1) { + gchar *start = g_utf8_substring(line, 0, col); + gchar *end = g_utf8_substring(line, col+1, line_bytes_len); GString *new = g_string_new(start); g_string_append(new, end); - for (input_len_bytes = 0; input_len_bytes < strlen(new->str); input_len_bytes++) { - input[input_len_bytes] = new->str[input_len_bytes]; + for (line_bytes_len = 0; line_bytes_len < strlen(new->str); line_bytes_len++) { + line[line_bytes_len] = new->str[line_bytes_len]; } - input[input_len_bytes] = '\0'; + line[line_bytes_len] = '\0'; g_free(start); g_free(end); g_string_free(new, FALSE); _clear_input(); - waddstr(inp_win, input); - wmove(inp_win, 0, inp_x); + waddstr(inp_win, line); + wmove(inp_win, 0, col); } return 1; @@ -475,11 +499,21 @@ _handle_edit(int key_type, const wint_t ch) return 0; } case KEY_CTRL_B: - if (inp_x > 0) { - wmove(inp_win, 0, inp_x-1); + if (line_utf8_pos > 0) { + col--; + gchar *curr_ch = g_utf8_offset_to_pointer(line, line_utf8_pos); + gchar *prev_ch = g_utf8_find_prev_char(line, curr_ch); + if (prev_ch) { + gunichar uni = g_utf8_get_char(prev_ch); + if (g_unichar_iswide(uni)) { + col--; + } + } + wmove(inp_win, 0, col); + line_utf8_pos--; // current position off screen to left - if (inp_x - 1 < pad_start) { + if (col - 1 < pad_start) { pad_start--; _inp_win_update_virtual(); } @@ -491,11 +525,20 @@ _handle_edit(int key_type, const wint_t ch) return 0; } case KEY_CTRL_F: - if (inp_x < display_size) { - wmove(inp_win, 0, inp_x+1); + if (line_utf8_pos < utf8_len) { + col++; + gchar *curr_ch = g_utf8_offset_to_pointer(line, line_utf8_pos); + if (curr_ch) { + gunichar uni = g_utf8_get_char(curr_ch); + if (g_unichar_iswide(uni)) { + col++; + } + } + wmove(inp_win, 0, col); + line_utf8_pos++; // current position off screen to right - if ((inp_x + 1 - pad_start) >= cols) { + if ((col + 1 - pad_start) >= wcols) { pad_start++; _inp_win_update_virtual(); } @@ -507,8 +550,8 @@ _handle_edit(int key_type, const wint_t ch) return 0; } case KEY_CTRL_P: - input[input_len_bytes] = '\0'; - prev = history_previous(history, input); + line[line_bytes_len] = '\0'; + prev = history_previous(history, line); if (prev) { inp_replace_input(prev); } @@ -519,13 +562,13 @@ _handle_edit(int key_type, const wint_t ch) return 0; } case KEY_CTRL_N: - input[input_len_bytes] = '\0'; - next = history_next(history, input); + line[line_bytes_len] = '\0'; + next = history_next(history, line); if (next) { inp_replace_input(next); - } else if (input_len_bytes != 0) { - input[input_len_bytes] = '\0'; - history_append(history, input); + } else if (line_bytes_len != 0) { + line[line_bytes_len] = '\0'; + history_append(history, line); inp_replace_input(""); } return 1; @@ -549,16 +592,16 @@ _handle_edit(int key_type, const wint_t ch) return 1; case 9: // tab - if (input_len_bytes != 0) { - input[input_len_bytes] = '\0'; - if ((strncmp(input, "/", 1) != 0) && (ui_current_win_type() == WIN_MUC)) { - char *result = muc_autocomplete(input); + if (line_bytes_len != 0) { + line[line_bytes_len] = '\0'; + if ((strncmp(line, "/", 1) != 0) && (ui_current_win_type() == WIN_MUC)) { + char *result = muc_autocomplete(line); if (result) { inp_replace_input(result); free(result); } - } else if (strncmp(input, "/", 1) == 0) { - char *result = cmd_autocomplete(input); + } else if (strncmp(line, "/", 1) == 0) { + char *result = cmd_autocomplete(line); if (result) { inp_replace_input(result); free(result); @@ -589,40 +632,44 @@ static void _handle_backspace(void) { int col = getcurx(inp_win); - int display_size = utf8_display_len(input); - int input_len_utf8 = g_utf8_strlen(input, -1); + int utf8_len = g_utf8_strlen(line, -1); roster_reset_search_attempts(); - if (display_size > 0) { + if (utf8_len > 0) { // if at end, delete last char - if (col >= display_size) { - gchar *new_input = g_utf8_substring(input, 0, input_len_utf8-1); - inp_replace_input(new_input); + if (line_utf8_pos >= utf8_len) { + gchar *new_line = g_utf8_substring(line, 0, utf8_len-1); + inp_replace_input(new_line); // if in middle, delete and shift chars left - } else if (col > 0 && col < display_size) { - gchar *start = g_utf8_substring(input, 0, col - 1); - gchar *end = g_utf8_substring(input, col, input_len_bytes); - GString *new = g_string_new(start); - g_string_append(new, end); + } else if (line_utf8_pos > 0 && line_utf8_pos < utf8_len) { + gchar *del_char = g_utf8_offset_to_pointer(line, line_utf8_pos-1); + gunichar uni = g_utf8_get_char(del_char); - for (input_len_bytes = 0; input_len_bytes < strlen(new->str); input_len_bytes++) { - input[input_len_bytes] = new->str[input_len_bytes]; - } - input[input_len_bytes] = '\0'; + gchar *start = g_utf8_substring(line, 0, line_utf8_pos-1); + gchar *end = g_utf8_substring(line, line_utf8_pos, utf8_len); + GString *new_line = g_string_new(start); + g_string_append(new_line, end); + + int old_pos = line_utf8_pos; + inp_replace_input(new_line->str); + line_utf8_pos = old_pos-1; g_free(start); g_free(end); - g_string_free(new, FALSE); + g_string_free(new_line, TRUE); - _clear_input(); - waddstr(inp_win, input); - wmove(inp_win, 0, col -1); + col--; + if (g_unichar_iswide(uni)) { + col--; + } + + wmove(inp_win, 0, col); } // if gone off screen to left, jump left (half a screen worth) if (col <= pad_start) { - pad_start = pad_start - (cols / 2); + pad_start = pad_start - (wcols / 2); if (pad_start < 0) { pad_start = 0; } @@ -690,9 +737,9 @@ _delete_previous_word(void) int end_del = getcurx(inp_win); int start_del = end_del; - input[input_len_bytes] = '\0'; - gchar *curr_ch = g_utf8_offset_to_pointer(input, end_del); - curr_ch = g_utf8_find_prev_char(input, curr_ch); + line[line_bytes_len] = '\0'; + gchar *curr_ch = g_utf8_offset_to_pointer(line, end_del); + curr_ch = g_utf8_find_prev_char(line, curr_ch); gchar *prev_ch; gunichar curr_uni; gunichar prev_uni; @@ -701,9 +748,9 @@ _delete_previous_word(void) curr_uni = g_utf8_get_char(curr_ch); if (g_unichar_isspace(curr_uni)) { - curr_ch = g_utf8_find_prev_char(input, curr_ch); + curr_ch = g_utf8_find_prev_char(line, curr_ch); } else { - prev_ch = g_utf8_find_prev_char(input, curr_ch); + prev_ch = g_utf8_find_prev_char(line, curr_ch); if (prev_ch == NULL) { curr_ch = NULL; break; @@ -721,31 +768,31 @@ _delete_previous_word(void) if (curr_ch == NULL) { start_del = 0; } else { - start_del = g_utf8_pointer_to_offset(input, curr_ch); + start_del = g_utf8_pointer_to_offset(line, curr_ch); } - gint len = g_utf8_strlen(input, -1); - gchar *start_string = g_utf8_substring(input, 0, start_del); - gchar *end_string = g_utf8_substring(input, end_del, len); + gint len = g_utf8_strlen(line, -1); + gchar *start_string = g_utf8_substring(line, 0, start_del); + gchar *end_string = g_utf8_substring(line, end_del, len); int i; for (i = 0; i < strlen(start_string); i++) { - input[i] = start_string[i]; + line[i] = start_string[i]; } for (i = 0; i < strlen(end_string); i++) { - input[strlen(start_string)+i] = end_string[i]; + line[strlen(start_string)+i] = end_string[i]; } - input_len_bytes = strlen(start_string)+i; - input[input_len_bytes] = '\0'; + line_bytes_len = strlen(start_string)+i; + line[line_bytes_len] = '\0'; _clear_input(); - waddstr(inp_win, input); + waddstr(inp_win, line); wmove(inp_win, 0, start_del); // if gone off screen to left, jump left (half a screen worth) if (start_del <= pad_start) { - pad_start = pad_start - (cols / 2); + pad_start = pad_start - (wcols / 2); if (pad_start < 0) { pad_start = 0; } @@ -757,10 +804,11 @@ _delete_previous_word(void) static void _go_to_end(void) { - int display_size = utf8_display_len(input); - wmove(inp_win, 0, display_size); - if (display_size > cols-2) { - pad_start = display_size - cols + 1; + int display_len = utf8_display_len(line); + wmove(inp_win, 0, display_len); + line_utf8_pos = g_utf8_strlen(line, -1); + if (display_len > wcols-2) { + pad_start = display_len - wcols + 1; _inp_win_update_virtual(); } } From 9ecdb39433cdf5c32b6c0a02d45952ac258da44a Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 18 Jan 2015 22:55:51 +0000 Subject: [PATCH 004/252] Refactor inputwin.c --- src/common.c | 12 +++ src/common.h | 8 ++ src/ui/inputwin.c | 226 +++++++++++++++++++++++++--------------------- 3 files changed, 142 insertions(+), 104 deletions(-) diff --git a/src/common.c b/src/common.c index 7638da31..6c130798 100644 --- a/src/common.c +++ b/src/common.c @@ -224,6 +224,18 @@ utf8_display_len(const char * const str) return len; } +gboolean +utf8_is_printable(const wint_t ch) +{ + char bytes[MB_CUR_MAX+1]; + size_t utf_len = wcrtomb(bytes, ch, NULL); + bytes[utf_len] = '\0'; + + gunichar unichar = g_utf8_get_char(bytes); + + return g_unichar_isprint(unichar) && (ch != KEY_MOUSE); +} + char * prof_getline(FILE *stream) { diff --git a/src/common.h b/src/common.h index 26d4a99a..8d35f99b 100644 --- a/src/common.h +++ b/src/common.h @@ -36,6 +36,13 @@ #define COMMON_H #include +#include + +#ifdef HAVE_NCURSESW_NCURSES_H +#include +#elif HAVE_NCURSES_H +#include +#endif #include @@ -105,6 +112,7 @@ char * str_replace(const char *string, const char *substr, const char *replacement); int str_contains(const char str[], int size, char ch); int utf8_display_len(const char * const str); +gboolean utf8_is_printable(const wint_t ch); char * prof_getline(FILE *stream); char* release_get_latest(void); gboolean release_is_new(char *found_version); diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index a482e292..f91a5ef2 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -79,8 +79,9 @@ static WINDOW *inp_win; static History history; +// input line static char line[INP_WIN_MAX]; -static int line_bytes_len; +// current position in the utf8 string static int line_utf8_pos; static int pad_start = 0; @@ -88,11 +89,15 @@ static int wrows, wcols; static int _handle_edit(int key_type, const wint_t ch); static int _handle_alt_key(int key); + +static void _handle_delete_previous_word(void); static void _handle_backspace(void); -static int _printable(const wint_t ch); + static void _clear_input(void); static void _go_to_end(void); -static void _delete_previous_word(void); + +static gboolean _is_ctrl_left(int key_type, const wint_t ch); +static gboolean _is_ctrl_right(int key_type, const wint_t ch); void create_input_window(void) @@ -109,20 +114,20 @@ create_input_window(void) wmove(inp_win, 0, 0); _inp_win_update_virtual(); history = history_new(MAX_HISTORY); - line_bytes_len = 0; line_utf8_pos = 0; + line[0] = '\0'; } void inp_win_resize(void) { - int inp_x; + int col; getmaxyx(stdscr, wrows, wcols); - inp_x = getcurx(inp_win); + col = getcurx(inp_win); // if lost cursor off screen, move contents to show it - if (inp_x >= pad_start + wcols) { - pad_start = inp_x - (wcols / 2); + if (col >= pad_start + wcols) { + pad_start = col - (wcols / 2); if (pad_start < 0) { pad_start = 0; } @@ -151,24 +156,25 @@ inp_read(int *key_type, wint_t *ch) noecho(); *key_type = wget_wch(inp_win, ch); - int display_len = utf8_display_len(line); + int bytes_len = strlen(line); + gboolean in_command = FALSE; - if ((display_len > 0 && line[0] == '/') || - (display_len == 0 && *ch == '/')) { + if ((bytes_len > 0 && line[0] == '/') || + (bytes_len == 0 && *ch == '/')) { in_command = TRUE; } if (*key_type == ERR) { prof_handle_idle(); } - if ((*key_type != ERR) && (*key_type != KEY_CODE_YES) && !in_command && _printable(*ch)) { + if ((*key_type != ERR) && (*key_type != KEY_CODE_YES) && !in_command && utf8_is_printable(*ch)) { prof_handle_activity(); } // if it wasn't an arrow key etc if (!_handle_edit(*key_type, *ch)) { - if (_printable(*ch) && *key_type != KEY_CODE_YES) { - if (line_bytes_len >= INP_WIN_MAX) { + if (utf8_is_printable(*ch) && *key_type != KEY_CODE_YES) { + if (bytes_len >= INP_WIN_MAX) { *ch = ERR; return NULL; } @@ -205,7 +211,6 @@ inp_read(int *key_type, wint_t *ch) // otherwise just append } else { - int display_len = utf8_display_len(line); char bytes[MB_CUR_MAX+1]; size_t utf8_ch_len = wcrtomb(bytes, *ch, NULL); @@ -213,9 +218,9 @@ inp_read(int *key_type, wint_t *ch) if (utf8_ch_len < MB_CUR_MAX) { int i; for (i = 0 ; i < utf8_ch_len; i++) { - line[line_bytes_len++] = bytes[i]; + line[bytes_len++] = bytes[i]; } - line[line_bytes_len] = '\0'; + line[bytes_len] = '\0'; bytes[utf8_ch_len] = '\0'; waddstr(inp_win, bytes); @@ -232,7 +237,7 @@ inp_read(int *key_type, wint_t *ch) // if gone over screen size follow input int wrows, wcols; getmaxyx(stdscr, wrows, wcols); - if (display_len - pad_start > wcols-2) { + if (col - pad_start > wcols-2) { pad_start++; _inp_win_update_virtual(); } @@ -247,14 +252,14 @@ inp_read(int *key_type, wint_t *ch) char *result = NULL; if (*ch == '\n') { - line[line_bytes_len] = '\0'; result = strdup(line); line[0] = '\0'; - line_bytes_len = 0; line_utf8_pos = 0; } if (*ch != ERR && *key_type != ERR) { + cons_debug("BYTE LEN = %d", bytes_len); + cons_debug("UTF8 LEN = %d", utf8_display_len(line)); cons_debug("CURR COL = %d", getcurx(inp_win)); cons_debug("CURR UNI = %d", line_utf8_pos); cons_debug(""); @@ -285,11 +290,9 @@ inp_put_back(void) void inp_replace_input(const char * const new_input) { + _clear_input(); strncpy(line, new_input, INP_WIN_MAX); - line_bytes_len = strlen(line); - inp_win_reset(); waddstr(inp_win, line); - _go_to_end(); } @@ -297,7 +300,6 @@ void inp_win_reset(void) { _clear_input(); - pad_start = 0; _inp_win_update_virtual(); } @@ -312,6 +314,10 @@ _clear_input(void) { werase(inp_win); wmove(inp_win, 0, 0); + pad_start = 0; + + line[0] = '\0'; + line_utf8_pos = 0; } /* @@ -322,27 +328,29 @@ _clear_input(void) static int _handle_edit(int key_type, const wint_t ch) { - char *prev = NULL; - char *next = NULL; int col = getcurx(inp_win); - int next_ch; - int display_size = utf8_display_len(line); int utf8_len = g_utf8_strlen(line, -1); // CTRL-LEFT - if ((key_type == KEY_CODE_YES) && (ch == 547 || ch == 545 || ch == 544 || ch == 540 || ch == 539) && (col > 0)) { - line[line_bytes_len] = '\0'; - gchar *curr_ch = g_utf8_offset_to_pointer(line, col); - curr_ch = g_utf8_find_prev_char(line, curr_ch); - gchar *prev_ch; - gunichar curr_uni; - gunichar prev_uni; + if (line_utf8_pos > 0 && _is_ctrl_left(key_type, ch)) { + gchar *curr_ch = g_utf8_offset_to_pointer(line, line_utf8_pos); + gunichar curr_uni = g_utf8_get_char(curr_ch); + line_utf8_pos--; + col--; + if (g_unichar_iswide(curr_uni)) { + col--; + } + curr_ch = g_utf8_find_prev_char(line, curr_ch); + + gchar *prev_ch; + gunichar prev_uni; while (curr_ch != NULL) { curr_uni = g_utf8_get_char(curr_ch); - if (g_unichar_isspace(curr_uni)) { curr_ch = g_utf8_find_prev_char(line, curr_ch); + line_utf8_pos--; + col--; } else { prev_ch = g_utf8_find_prev_char(line, curr_ch); if (prev_ch == NULL) { @@ -350,6 +358,11 @@ _handle_edit(int key_type, const wint_t ch) break; } else { prev_uni = g_utf8_get_char(prev_ch); + line_utf8_pos--; + col--; + if (g_unichar_iswide(prev_uni)) { + col--; + } if (g_unichar_isspace(prev_uni)) { break; } else { @@ -363,8 +376,8 @@ _handle_edit(int key_type, const wint_t ch) col = 0; wmove(inp_win, 0, col); } else { - glong offset = g_utf8_pointer_to_offset(line, curr_ch); - col = offset; + col++; + line_utf8_pos++; wmove(inp_win, 0, col); } @@ -380,39 +393,37 @@ _handle_edit(int key_type, const wint_t ch) return 1; // CTRL-RIGHT - } else if ((key_type == KEY_CODE_YES) && (ch == 562 || ch == 560 || ch == 555 || ch == 559 || ch == 554) && (col < display_size)) { - line[line_bytes_len] = '\0'; - gchar *curr_ch = g_utf8_offset_to_pointer(line, col); - gchar *next_ch = g_utf8_find_next_char(curr_ch, NULL); - gunichar curr_uni; - gunichar next_uni; - gboolean moved = FALSE; + } else if (line_utf8_pos < utf8_len && _is_ctrl_right(key_type, ch)) { + gchar *curr_ch = g_utf8_offset_to_pointer(line, line_utf8_pos); + gunichar curr_uni = g_utf8_get_char(curr_ch); - while (g_utf8_pointer_to_offset(line, next_ch) < display_size) { - curr_uni = g_utf8_get_char(curr_ch); - next_uni = g_utf8_get_char(next_ch); - curr_ch = next_ch; - next_ch = g_utf8_find_next_char(next_ch, NULL); - - if (!g_unichar_isspace(curr_uni) && g_unichar_isspace(next_uni) && moved) { + // find next word if in whitespace + while (g_unichar_isspace(curr_uni)) { + col++; + line_utf8_pos++; + curr_ch = g_utf8_find_next_char(curr_ch, NULL); + if (!curr_ch) { break; - } else { - moved = TRUE; + } + curr_uni = g_utf8_get_char(curr_ch); + } + + if (curr_ch) { + while (!g_unichar_isspace(curr_uni)) { + line_utf8_pos++; + col++; + if (g_unichar_iswide(curr_uni)) { + col++; + } + curr_ch = g_utf8_find_next_char(curr_ch, NULL); + if (!curr_ch || line_utf8_pos >= utf8_len) { + break; + } + curr_uni = g_utf8_get_char(curr_ch); } } - if (next_ch == NULL) { - col = display_size; - wmove(inp_win, 0, col); - } else { - glong offset = g_utf8_pointer_to_offset(line, curr_ch); - if (offset == display_size - 1) { - col = offset + 1; - } else { - col = offset; - } - wmove(inp_win, 0, col); - } + wmove(inp_win, 0, col); // if gone off screen to right, jump right (half a screen worth) if (col > pad_start + wcols) { @@ -434,6 +445,9 @@ _handle_edit(int key_type, const wint_t ch) // other editing keys } else { + int bytes_len = strlen(line); + int next_ch; + switch(ch) { case 27: // ESC @@ -442,7 +456,6 @@ _handle_edit(int key_type, const wint_t ch) if (next_ch != ERR) { return _handle_alt_key(next_ch); } else { - line_bytes_len = 0; inp_win_reset(); return 1; } @@ -462,27 +475,27 @@ _handle_edit(int key_type, const wint_t ch) return 0; } case KEY_CTRL_D: - if (col == display_size-1) { - gchar *start = g_utf8_substring(line, 0, col); - for (line_bytes_len = 0; line_bytes_len < strlen(start); line_bytes_len++) { - line[line_bytes_len] = start[line_bytes_len]; - } - line[line_bytes_len] = '\0'; + if (line_utf8_pos == utf8_len) { + return 1; + } else if (line_utf8_pos == utf8_len-1) { + gchar *curr_ch = g_utf8_offset_to_pointer(line, line_utf8_pos); + int bytes_len_ch = strlen(curr_ch); + bytes_len -= bytes_len_ch; + line[bytes_len] = '\0'; + line_utf8_pos--; + wdelch(inp_win); - g_free(start); - - _clear_input(); - waddstr(inp_win, line); - } else if (col < display_size-1) { + return 1; + } else if (line_utf8_pos < utf8_len-1) { gchar *start = g_utf8_substring(line, 0, col); - gchar *end = g_utf8_substring(line, col+1, line_bytes_len); + gchar *end = g_utf8_substring(line, col+1, bytes_len); GString *new = g_string_new(start); g_string_append(new, end); - for (line_bytes_len = 0; line_bytes_len < strlen(new->str); line_bytes_len++) { - line[line_bytes_len] = new->str[line_bytes_len]; + for (bytes_len = 0; bytes_len < strlen(new->str); bytes_len++) { + line[bytes_len] = new->str[bytes_len]; } - line[line_bytes_len] = '\0'; + line[bytes_len] = '\0'; g_free(start); g_free(end); @@ -550,8 +563,8 @@ _handle_edit(int key_type, const wint_t ch) return 0; } case KEY_CTRL_P: - line[line_bytes_len] = '\0'; - prev = history_previous(history, line); + line[bytes_len] = '\0'; + char *prev = history_previous(history, line); if (prev) { inp_replace_input(prev); } @@ -562,12 +575,12 @@ _handle_edit(int key_type, const wint_t ch) return 0; } case KEY_CTRL_N: - line[line_bytes_len] = '\0'; - next = history_next(history, line); + line[bytes_len] = '\0'; + char *next = history_next(history, line); if (next) { inp_replace_input(next); - } else if (line_bytes_len != 0) { - line[line_bytes_len] = '\0'; + } else if (bytes_len != 0) { + line[bytes_len] = '\0'; history_append(history, line); inp_replace_input(""); } @@ -580,6 +593,7 @@ _handle_edit(int key_type, const wint_t ch) case KEY_CTRL_A: wmove(inp_win, 0, 0); pad_start = 0; + line_utf8_pos = 0; _inp_win_update_virtual(); return 1; @@ -592,8 +606,8 @@ _handle_edit(int key_type, const wint_t ch) return 1; case 9: // tab - if (line_bytes_len != 0) { - line[line_bytes_len] = '\0'; + if (bytes_len != 0) { + line[bytes_len] = '\0'; if ((strncmp(line, "/", 1) != 0) && (ui_current_win_type() == WIN_MUC)) { char *result = muc_autocomplete(line); if (result) { @@ -611,13 +625,13 @@ _handle_edit(int key_type, const wint_t ch) return 1; case KEY_CTRL_W: - _delete_previous_word(); + _handle_delete_previous_word(); return 1; break; case KEY_CTRL_U: while (getcurx(inp_win) > 0) { - _delete_previous_word(); + _handle_delete_previous_word(); } return 1; break; @@ -723,7 +737,7 @@ _handle_alt_key(int key) break; case 263: case 127: - _delete_previous_word(); + _handle_delete_previous_word(); break; default: break; @@ -732,12 +746,11 @@ _handle_alt_key(int key) } static void -_delete_previous_word(void) +_handle_delete_previous_word(void) { int end_del = getcurx(inp_win); int start_del = end_del; - line[line_bytes_len] = '\0'; gchar *curr_ch = g_utf8_offset_to_pointer(line, end_del); curr_ch = g_utf8_find_prev_char(line, curr_ch); gchar *prev_ch; @@ -783,8 +796,8 @@ _delete_previous_word(void) line[strlen(start_string)+i] = end_string[i]; } - line_bytes_len = strlen(start_string)+i; - line[line_bytes_len] = '\0'; + int bytes_len = strlen(start_string)+i; + line[bytes_len] = '\0'; _clear_input(); waddstr(inp_win, line); @@ -807,18 +820,23 @@ _go_to_end(void) int display_len = utf8_display_len(line); wmove(inp_win, 0, display_len); line_utf8_pos = g_utf8_strlen(line, -1); + if (display_len > wcols-2) { pad_start = display_len - wcols + 1; _inp_win_update_virtual(); } } -static int -_printable(const wint_t ch) +static gboolean +_is_ctrl_left(int key_type, const wint_t ch) { - char bytes[MB_CUR_MAX+1]; - size_t utf_len = wcrtomb(bytes, ch, NULL); - bytes[utf_len] = '\0'; - gunichar unichar = g_utf8_get_char(bytes); - return g_unichar_isprint(unichar) && (ch != KEY_MOUSE); + return ((key_type == KEY_CODE_YES) + && (ch == 547 || ch == 545 || ch == 544 || ch == 540 || ch == 539)); } + +static gboolean +_is_ctrl_right(int key_type, const wint_t ch) +{ + return ((key_type == KEY_CODE_YES) + && (ch == 562 || ch == 560 || ch == 555 || ch == 559 || ch == 554)); +} \ No newline at end of file From 0e8092afef2e6172fc1fc27cd5a7e4f216456095 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 19 Jan 2015 20:51:41 +0000 Subject: [PATCH 005/252] Inlined static functions in inputwin --- src/ui/inputwin.c | 211 +++++++++++++++++++++++++++++++++++----------- src/ui/inputwin.h | 1 - 2 files changed, 162 insertions(+), 50 deletions(-) diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index f91a5ef2..dba2f9d5 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -93,9 +93,6 @@ static int _handle_alt_key(int key); static void _handle_delete_previous_word(void); static void _handle_backspace(void); -static void _clear_input(void); -static void _go_to_end(void); - static gboolean _is_ctrl_left(int key_type, const wint_t ch); static gboolean _is_ctrl_right(int key_type, const wint_t ch); @@ -195,7 +192,23 @@ inp_read(int *key_type, wint_t *ch) g_string_append(new_line, end); int old_pos = line_utf8_pos; - inp_replace_input(new_line->str); + werase(inp_win); + wmove(inp_win, 0, 0); + pad_start = 0; + line[0] = '\0'; + line_utf8_pos = 0; + strncpy(line, new_line->str, INP_WIN_MAX); + waddstr(inp_win, line); + + int display_len = utf8_display_len(line); + wmove(inp_win, 0, display_len); + line_utf8_pos = g_utf8_strlen(line, -1); + + if (display_len > wcols-2) { + pad_start = display_len - wcols + 1; + _inp_win_update_virtual(); + } + line_utf8_pos = old_pos+1; g_free(start); @@ -271,7 +284,11 @@ inp_read(int *key_type, wint_t *ch) void inp_get_password(char *passwd) { - _clear_input(); + werase(inp_win); + wmove(inp_win, 0, 0); + pad_start = 0; + line[0] = '\0'; + line_utf8_pos = 0; _inp_win_update_virtual(); doupdate(); noecho(); @@ -287,19 +304,14 @@ inp_put_back(void) _inp_win_update_virtual(); } -void -inp_replace_input(const char * const new_input) -{ - _clear_input(); - strncpy(line, new_input, INP_WIN_MAX); - waddstr(inp_win, line); - _go_to_end(); -} - void inp_win_reset(void) { - _clear_input(); + werase(inp_win); + wmove(inp_win, 0, 0); + pad_start = 0; + line[0] = '\0'; + line_utf8_pos = 0; _inp_win_update_virtual(); } @@ -309,17 +321,6 @@ inp_history_append(char *inp) history_append(history, inp); } -static void -_clear_input(void) -{ - werase(inp_win); - wmove(inp_win, 0, 0); - pad_start = 0; - - line[0] = '\0'; - line_utf8_pos = 0; -} - /* * Deal with command editing, return 1 if ch was an edit * key press: up, down, left, right or backspace @@ -445,6 +446,7 @@ _handle_edit(int key_type, const wint_t ch) // other editing keys } else { + int display_len; int bytes_len = strlen(line); int next_ch; @@ -501,7 +503,11 @@ _handle_edit(int key_type, const wint_t ch) g_free(end); g_string_free(new, FALSE); - _clear_input(); + werase(inp_win); + wmove(inp_win, 0, 0); + pad_start = 0; + line[0] = '\0'; + line_utf8_pos = 0; waddstr(inp_win, line); wmove(inp_win, 0, col); } @@ -566,7 +572,22 @@ _handle_edit(int key_type, const wint_t ch) line[bytes_len] = '\0'; char *prev = history_previous(history, line); if (prev) { - inp_replace_input(prev); + werase(inp_win); + wmove(inp_win, 0, 0); + pad_start = 0; + line[0] = '\0'; + line_utf8_pos = 0; + strncpy(line, prev, INP_WIN_MAX); + waddstr(inp_win, line); + + int display_len = utf8_display_len(line); + wmove(inp_win, 0, display_len); + line_utf8_pos = g_utf8_strlen(line, -1); + + if (display_len > wcols-2) { + pad_start = display_len - wcols + 1; + _inp_win_update_virtual(); + } } return 1; @@ -578,11 +599,41 @@ _handle_edit(int key_type, const wint_t ch) line[bytes_len] = '\0'; char *next = history_next(history, line); if (next) { - inp_replace_input(next); + werase(inp_win); + wmove(inp_win, 0, 0); + pad_start = 0; + line[0] = '\0'; + line_utf8_pos = 0; + strncpy(line, next, INP_WIN_MAX); + waddstr(inp_win, line); + + int display_len = utf8_display_len(line); + wmove(inp_win, 0, display_len); + line_utf8_pos = g_utf8_strlen(line, -1); + + if (display_len > wcols-2) { + pad_start = display_len - wcols + 1; + _inp_win_update_virtual(); + } } else if (bytes_len != 0) { line[bytes_len] = '\0'; history_append(history, line); - inp_replace_input(""); + werase(inp_win); + wmove(inp_win, 0, 0); + pad_start = 0; + line[0] = '\0'; + line_utf8_pos = 0; + strncpy(line, "", INP_WIN_MAX); + waddstr(inp_win, line); + + int display_len = utf8_display_len(line); + wmove(inp_win, 0, display_len); + line_utf8_pos = g_utf8_strlen(line, -1); + + if (display_len > wcols-2) { + pad_start = display_len - wcols + 1; + _inp_win_update_virtual(); + } } return 1; @@ -602,7 +653,14 @@ _handle_edit(int key_type, const wint_t ch) return 0; } case KEY_CTRL_E: - _go_to_end(); + display_len = utf8_display_len(line); + wmove(inp_win, 0, display_len); + line_utf8_pos = g_utf8_strlen(line, -1); + + if (display_len > wcols-2) { + pad_start = display_len - wcols + 1; + _inp_win_update_virtual(); + } return 1; case 9: // tab @@ -611,13 +669,45 @@ _handle_edit(int key_type, const wint_t ch) if ((strncmp(line, "/", 1) != 0) && (ui_current_win_type() == WIN_MUC)) { char *result = muc_autocomplete(line); if (result) { - inp_replace_input(result); + werase(inp_win); + wmove(inp_win, 0, 0); + pad_start = 0; + line[0] = '\0'; + line_utf8_pos = 0; + strncpy(line, result, INP_WIN_MAX); + waddstr(inp_win, line); + + int display_len = utf8_display_len(line); + wmove(inp_win, 0, display_len); + line_utf8_pos = g_utf8_strlen(line, -1); + + if (display_len > wcols-2) { + pad_start = display_len - wcols + 1; + _inp_win_update_virtual(); + } + free(result); } } else if (strncmp(line, "/", 1) == 0) { char *result = cmd_autocomplete(line); if (result) { - inp_replace_input(result); + werase(inp_win); + wmove(inp_win, 0, 0); + pad_start = 0; + line[0] = '\0'; + line_utf8_pos = 0; + strncpy(line, result, INP_WIN_MAX); + waddstr(inp_win, line); + + int display_len = utf8_display_len(line); + wmove(inp_win, 0, display_len); + line_utf8_pos = g_utf8_strlen(line, -1); + + if (display_len > wcols-2) { + pad_start = display_len - wcols + 1; + _inp_win_update_virtual(); + } + free(result); } } @@ -653,7 +743,22 @@ _handle_backspace(void) // if at end, delete last char if (line_utf8_pos >= utf8_len) { gchar *new_line = g_utf8_substring(line, 0, utf8_len-1); - inp_replace_input(new_line); + werase(inp_win); + wmove(inp_win, 0, 0); + pad_start = 0; + line[0] = '\0'; + line_utf8_pos = 0; + strncpy(line, new_line, INP_WIN_MAX); + waddstr(inp_win, line); + + int display_len = utf8_display_len(line); + wmove(inp_win, 0, display_len); + line_utf8_pos = g_utf8_strlen(line, -1); + + if (display_len > wcols-2) { + pad_start = display_len - wcols + 1; + _inp_win_update_virtual(); + } // if in middle, delete and shift chars left } else if (line_utf8_pos > 0 && line_utf8_pos < utf8_len) { @@ -666,7 +771,23 @@ _handle_backspace(void) g_string_append(new_line, end); int old_pos = line_utf8_pos; - inp_replace_input(new_line->str); + werase(inp_win); + wmove(inp_win, 0, 0); + pad_start = 0; + line[0] = '\0'; + line_utf8_pos = 0; + strncpy(line, new_line->str, INP_WIN_MAX); + waddstr(inp_win, line); + + int display_len = utf8_display_len(line); + wmove(inp_win, 0, display_len); + line_utf8_pos = g_utf8_strlen(line, -1); + + if (display_len > wcols-2) { + pad_start = display_len - wcols + 1; + _inp_win_update_virtual(); + } + line_utf8_pos = old_pos-1; g_free(start); @@ -799,7 +920,12 @@ _handle_delete_previous_word(void) int bytes_len = strlen(start_string)+i; line[bytes_len] = '\0'; - _clear_input(); + werase(inp_win); + wmove(inp_win, 0, 0); + pad_start = 0; + line[0] = '\0'; + line_utf8_pos = 0; + waddstr(inp_win, line); wmove(inp_win, 0, start_del); @@ -814,19 +940,6 @@ _handle_delete_previous_word(void) } } -static void -_go_to_end(void) -{ - int display_len = utf8_display_len(line); - wmove(inp_win, 0, display_len); - line_utf8_pos = g_utf8_strlen(line, -1); - - if (display_len > wcols-2) { - pad_start = display_len - wcols + 1; - _inp_win_update_virtual(); - } -} - static gboolean _is_ctrl_left(int key_type, const wint_t ch) { diff --git a/src/ui/inputwin.h b/src/ui/inputwin.h index 39fde720..ecca4d5b 100644 --- a/src/ui/inputwin.h +++ b/src/ui/inputwin.h @@ -43,7 +43,6 @@ void inp_put_back(void); void inp_non_block(gint); void inp_block(void); void inp_get_password(char *passwd); -void inp_replace_input(const char * const new_input); void inp_history_append(char *inp); #endif From 2ed78fe5afaa0197de65a0edbf2423b5d7fe9792 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 20 Jan 2015 00:09:47 +0000 Subject: [PATCH 006/252] Extracted keyhandler for printable characters --- Makefile.am | 3 + src/ui/core.c | 2 +- src/ui/inputwin.c | 129 +++++++++++---------------------- src/ui/inputwin.h | 6 +- src/ui/keyhandlers.c | 123 ++++++++++++++++++++++++++++++++ src/ui/keyhandlers.h | 42 +++++++++++ tests/test_keyhandlers.c | 150 +++++++++++++++++++++++++++++++++++++++ tests/test_keyhandlers.h | 11 +++ tests/testsuite.c | 10 +++ 9 files changed, 385 insertions(+), 91 deletions(-) create mode 100644 src/ui/keyhandlers.c create mode 100644 src/ui/keyhandlers.h create mode 100644 tests/test_keyhandlers.c create mode 100644 tests/test_keyhandlers.h diff --git a/Makefile.am b/Makefile.am index d9fa9729..abd1a1ff 100644 --- a/Makefile.am +++ b/Makefile.am @@ -19,6 +19,7 @@ core_sources = \ src/ui/titlebar.h src/ui/statusbar.h src/ui/inputwin.h \ src/ui/console.c src/ui/notifier.c \ src/ui/windows.c src/ui/windows.h \ + src/ui/keyhandlers.c src/ui/keyhandlers.h \ src/ui/rosterwin.c src/ui/occupantswin.c \ src/ui/buffer.c src/ui/buffer.h \ src/command/command.h src/command/command.c \ @@ -58,6 +59,7 @@ tests_sources = \ src/config/theme.c src/config/theme.h \ src/ui/windows.c src/ui/windows.h \ src/ui/window.c src/ui/window.h \ + src/ui/keyhandlers.c src/ui/keyhandlers.h \ src/ui/buffer.c \ src/ui/titlebar.c src/ui/statusbar.c src/ui/inputwin.c \ src/ui/titlebar.h src/ui/statusbar.h src/ui/inputwin.h \ @@ -92,6 +94,7 @@ tests_sources = \ tests/test_server_events.c tests/test_server_events.h \ tests/test_autocomplete.c tests/test_autocomplete.h \ tests/test_chat_session.c tests/test_chat_session.h \ + tests/test_keyhandlers.c tests/test_keyhandlers.h \ tests/testsuite.c main_source = src/main.c diff --git a/src/ui/core.c b/src/ui/core.c index 14ea2c17..e295a3ad 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -212,7 +212,7 @@ ui_inp_history_append(char *inp) void ui_input_clear(void) { - inp_win_reset(); + inp_win_clear(); } void diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index dba2f9d5..59292482 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -60,8 +60,7 @@ #include "ui/inputwin.h" #include "ui/windows.h" #include "xmpp/xmpp.h" - -#define _inp_win_update_virtual() pnoutrefresh(inp_win, 0, pad_start, wrows-1, 0, wrows-1, wcols-1) +#include "ui/keyhandlers.h" #define KEY_CTRL_A 0001 #define KEY_CTRL_B 0002 @@ -74,7 +73,6 @@ #define KEY_CTRL_W 0027 #define MAX_HISTORY 100 -#define INP_WIN_MAX 1000 static WINDOW *inp_win; static History history; @@ -85,7 +83,6 @@ static char line[INP_WIN_MAX]; static int line_utf8_pos; static int pad_start = 0; -static int wrows, wcols; static int _handle_edit(int key_type, const wint_t ch); static int _handle_alt_key(int key); @@ -96,6 +93,8 @@ static void _handle_backspace(void); static gboolean _is_ctrl_left(int key_type, const wint_t ch); static gboolean _is_ctrl_right(int key_type, const wint_t ch); +static void _inp_win_update_virtual(void); + void create_input_window(void) { @@ -104,7 +103,6 @@ create_input_window(void) #else ESCDELAY = 25; #endif - getmaxyx(stdscr, wrows, wcols); inp_win = newpad(1, INP_WIN_MAX); wbkgd(inp_win, theme_attrs(THEME_INPUT_TEXT));; keypad(inp_win, TRUE); @@ -118,9 +116,8 @@ create_input_window(void) void inp_win_resize(void) { - int col; - getmaxyx(stdscr, wrows, wcols); - col = getcurx(inp_win); + int col = getcurx(inp_win); + int wcols = getmaxx(stdscr); // if lost cursor off screen, move contents to show it if (col >= pad_start + wcols) { @@ -177,85 +174,13 @@ inp_read(int *key_type, wint_t *ch) } int col = getcurx(inp_win); - int utf8_len = g_utf8_strlen(line, -1); + int wcols = getmaxx(stdscr); + key_printable(line, &line_utf8_pos, &col, &pad_start, *ch, wcols); - // handle insert if not at end of input - if (line_utf8_pos < utf8_len) { - char bytes[MB_CUR_MAX]; - size_t utf8_ch_len = wcrtomb(bytes, *ch, NULL); - bytes[utf8_ch_len] = '\0'; - - gchar *start = g_utf8_substring(line, 0, line_utf8_pos); - gchar *end = g_utf8_substring(line, line_utf8_pos, utf8_len); - GString *new_line = g_string_new(start); - g_string_append(new_line, bytes); - g_string_append(new_line, end); - - int old_pos = line_utf8_pos; - werase(inp_win); - wmove(inp_win, 0, 0); - pad_start = 0; - line[0] = '\0'; - line_utf8_pos = 0; - strncpy(line, new_line->str, INP_WIN_MAX); - waddstr(inp_win, line); - - int display_len = utf8_display_len(line); - wmove(inp_win, 0, display_len); - line_utf8_pos = g_utf8_strlen(line, -1); - - if (display_len > wcols-2) { - pad_start = display_len - wcols + 1; - _inp_win_update_virtual(); - } - - line_utf8_pos = old_pos+1; - - g_free(start); - g_free(end); - g_string_free(new_line, TRUE); - - col++; - gunichar uni = g_utf8_get_char(bytes); - if (g_unichar_iswide(uni)) { - col++; - } - wmove(inp_win, 0, col); - - // otherwise just append - } else { - char bytes[MB_CUR_MAX+1]; - size_t utf8_ch_len = wcrtomb(bytes, *ch, NULL); - - // wcrtomb can return (size_t) -1 - if (utf8_ch_len < MB_CUR_MAX) { - int i; - for (i = 0 ; i < utf8_ch_len; i++) { - line[bytes_len++] = bytes[i]; - } - line[bytes_len] = '\0'; - - bytes[utf8_ch_len] = '\0'; - waddstr(inp_win, bytes); - - line_utf8_pos++; - - col++; - gunichar uni = g_utf8_get_char(bytes); - if (g_unichar_iswide(uni)) { - col++; - } - wmove(inp_win, 0, col); - - // if gone over screen size follow input - int wrows, wcols; - getmaxyx(stdscr, wrows, wcols); - if (col - pad_start > wcols-2) { - pad_start++; - _inp_win_update_virtual(); - } - } - } + werase(inp_win); + waddstr(inp_win, line); + wmove(inp_win, 0, col); + _inp_win_update_virtual(); cmd_reset_autocomplete(); } @@ -271,7 +196,7 @@ inp_read(int *key_type, wint_t *ch) } if (*ch != ERR && *key_type != ERR) { - cons_debug("BYTE LEN = %d", bytes_len); + cons_debug("BYTE LEN = %d", strlen(line)); cons_debug("UTF8 LEN = %d", utf8_display_len(line)); cons_debug("CURR COL = %d", getcurx(inp_win)); cons_debug("CURR UNI = %d", line_utf8_pos); @@ -305,7 +230,7 @@ inp_put_back(void) } void -inp_win_reset(void) +inp_win_clear(void) { werase(inp_win); wmove(inp_win, 0, 0); @@ -383,6 +308,7 @@ _handle_edit(int key_type, const wint_t ch) } // if gone off screen to left, jump left (half a screen worth) + int wcols = getmaxx(stdscr); if (col <= pad_start) { pad_start = pad_start - (wcols / 2); if (pad_start < 0) { @@ -427,6 +353,7 @@ _handle_edit(int key_type, const wint_t ch) wmove(inp_win, 0, col); // if gone off screen to right, jump right (half a screen worth) + int wcols = getmaxx(stdscr); if (col > pad_start + wcols) { pad_start = pad_start + (wcols / 2); _inp_win_update_virtual(); @@ -458,7 +385,12 @@ _handle_edit(int key_type, const wint_t ch) if (next_ch != ERR) { return _handle_alt_key(next_ch); } else { - inp_win_reset(); + werase(inp_win); + wmove(inp_win, 0, 0); + pad_start = 0; + line[0] = '\0'; + line_utf8_pos = 0; + _inp_win_update_virtual(); return 1; } @@ -557,6 +489,7 @@ _handle_edit(int key_type, const wint_t ch) line_utf8_pos++; // current position off screen to right + int wcols = getmaxx(stdscr); if ((col + 1 - pad_start) >= wcols) { pad_start++; _inp_win_update_virtual(); @@ -584,6 +517,7 @@ _handle_edit(int key_type, const wint_t ch) wmove(inp_win, 0, display_len); line_utf8_pos = g_utf8_strlen(line, -1); + int wcols = getmaxx(stdscr); if (display_len > wcols-2) { pad_start = display_len - wcols + 1; _inp_win_update_virtual(); @@ -611,6 +545,7 @@ _handle_edit(int key_type, const wint_t ch) wmove(inp_win, 0, display_len); line_utf8_pos = g_utf8_strlen(line, -1); + int wcols = getmaxx(stdscr); if (display_len > wcols-2) { pad_start = display_len - wcols + 1; _inp_win_update_virtual(); @@ -630,6 +565,7 @@ _handle_edit(int key_type, const wint_t ch) wmove(inp_win, 0, display_len); line_utf8_pos = g_utf8_strlen(line, -1); + int wcols = getmaxx(stdscr); if (display_len > wcols-2) { pad_start = display_len - wcols + 1; _inp_win_update_virtual(); @@ -657,6 +593,7 @@ _handle_edit(int key_type, const wint_t ch) wmove(inp_win, 0, display_len); line_utf8_pos = g_utf8_strlen(line, -1); + int wcols = getmaxx(stdscr); if (display_len > wcols-2) { pad_start = display_len - wcols + 1; _inp_win_update_virtual(); @@ -681,6 +618,7 @@ _handle_edit(int key_type, const wint_t ch) wmove(inp_win, 0, display_len); line_utf8_pos = g_utf8_strlen(line, -1); + int wcols = getmaxx(stdscr); if (display_len > wcols-2) { pad_start = display_len - wcols + 1; _inp_win_update_virtual(); @@ -703,6 +641,7 @@ _handle_edit(int key_type, const wint_t ch) wmove(inp_win, 0, display_len); line_utf8_pos = g_utf8_strlen(line, -1); + int wcols = getmaxx(stdscr); if (display_len > wcols-2) { pad_start = display_len - wcols + 1; _inp_win_update_virtual(); @@ -755,6 +694,7 @@ _handle_backspace(void) wmove(inp_win, 0, display_len); line_utf8_pos = g_utf8_strlen(line, -1); + int wcols = getmaxx(stdscr); if (display_len > wcols-2) { pad_start = display_len - wcols + 1; _inp_win_update_virtual(); @@ -783,6 +723,7 @@ _handle_backspace(void) wmove(inp_win, 0, display_len); line_utf8_pos = g_utf8_strlen(line, -1); + int wcols = getmaxx(stdscr); if (display_len > wcols-2) { pad_start = display_len - wcols + 1; _inp_win_update_virtual(); @@ -804,6 +745,7 @@ _handle_backspace(void) // if gone off screen to left, jump left (half a screen worth) if (col <= pad_start) { + int wcols = getmaxx(stdscr); pad_start = pad_start - (wcols / 2); if (pad_start < 0) { pad_start = 0; @@ -931,6 +873,7 @@ _handle_delete_previous_word(void) // if gone off screen to left, jump left (half a screen worth) if (start_del <= pad_start) { + int wcols = getmaxx(stdscr); pad_start = pad_start - (wcols / 2); if (pad_start < 0) { pad_start = 0; @@ -952,4 +895,12 @@ _is_ctrl_right(int key_type, const wint_t ch) { return ((key_type == KEY_CODE_YES) && (ch == 562 || ch == 560 || ch == 555 || ch == 559 || ch == 554)); +} + +static void +_inp_win_update_virtual(void) +{ + int wrows, wcols; + getmaxyx(stdscr, wrows, wcols); + pnoutrefresh(inp_win, 0, pad_start, wrows-1, 0, wrows-1, wcols-1); } \ No newline at end of file diff --git a/src/ui/inputwin.h b/src/ui/inputwin.h index ecca4d5b..a4de16f0 100644 --- a/src/ui/inputwin.h +++ b/src/ui/inputwin.h @@ -35,9 +35,13 @@ #ifndef UI_INPUTWIN_H #define UI_INPUTWIN_H +#include + +#define INP_WIN_MAX 1000 + void create_input_window(void); char* inp_read(int *key_type, wint_t *ch); -void inp_win_reset(void); +void inp_win_clear(void); void inp_win_resize(void); void inp_put_back(void); void inp_non_block(gint); diff --git a/src/ui/keyhandlers.c b/src/ui/keyhandlers.c new file mode 100644 index 00000000..513997ef --- /dev/null +++ b/src/ui/keyhandlers.c @@ -0,0 +1,123 @@ +/* + * keyhandlers.c + * + * Copyright (C) 2012 - 2014 James Booth + * + * This file is part of Profanity. + * + * Profanity is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Profanity is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Profanity. If not, see . + * + * In addition, as a special exception, the copyright holders give permission to + * link the code of portions of this program with the OpenSSL library under + * certain conditions as described in each individual source file, and + * distribute linked combinations including the two. + * + * You must obey the GNU General Public License in all respects for all of the + * code used other than OpenSSL. If you modify file(s) with this exception, you + * may extend this exception to your version of the file(s), but you are not + * obligated to do so. If you do not wish to do so, delete this exception + * statement from your version. If you delete this exception statement from all + * source files in the program, then also delete it here. + * + */ + +#include +#include +#include + +#include + +#include "ui/inputwin.h" +#include "common.h" + +void +key_printable(char * const line, int * const line_utf8_pos, int * const col, int * const pad_start, const wint_t ch, const int wcols) +{ + int utf8_len = g_utf8_strlen(line, -1); + + // handle insert if not at end of input + if (*line_utf8_pos < utf8_len) { + // create new line + char bytes[MB_CUR_MAX]; + size_t utf8_ch_len = wcrtomb(bytes, ch, NULL); + bytes[utf8_ch_len] = '\0'; + gchar *start = g_utf8_substring(line, 0, *line_utf8_pos); + gchar *end = g_utf8_substring(line, *line_utf8_pos, utf8_len); + GString *new_line_str = g_string_new(start); + g_string_append(new_line_str, bytes); + g_string_append(new_line_str, end); + char *new_line = new_line_str->str; + g_free(start); + g_free(end); + g_string_free(new_line_str, FALSE); + + // replace old line + strncpy(line, new_line, INP_WIN_MAX); + free(new_line); + + // set utf8 position + (*line_utf8_pos)++; + + // set col position + (*col)++; + gunichar uni = g_utf8_get_char(bytes); + if (g_unichar_iswide(uni)) { + (*col)++; + } + + // set pad_start + int display_len = utf8_display_len(line); + (*pad_start) = 0; + if (display_len > wcols-2) { + (*pad_start) = display_len - wcols + 1; + } + + // otherwise just append + } else { + char bytes[MB_CUR_MAX+1]; + size_t utf8_ch_len = wcrtomb(bytes, ch, NULL); + + // wcrtomb can return (size_t) -1 + if (utf8_ch_len < MB_CUR_MAX) { + // update old line + int i; + int bytes_len = strlen(line); + + for (i = 0 ; i < utf8_ch_len; i++) { + line[bytes_len++] = bytes[i]; + } + line[bytes_len] = '\0'; + + // set utf8 position + (*line_utf8_pos)++; + + // set col position + (*col)++; + bytes[utf8_ch_len] = '\0'; + gunichar uni = g_utf8_get_char(bytes); + if (g_unichar_iswide(uni)) { + (*col)++; + } + + // set pad_start + // if gone over screen size follow input + if (*col - *pad_start > wcols-2) { + (*pad_start)++; + if (g_unichar_iswide(uni)) { + (*pad_start)++; + } + } + } + } +} \ No newline at end of file diff --git a/src/ui/keyhandlers.h b/src/ui/keyhandlers.h new file mode 100644 index 00000000..cb1b14d8 --- /dev/null +++ b/src/ui/keyhandlers.h @@ -0,0 +1,42 @@ +/* + * keyhandlers.c + * + * Copyright (C) 2012 - 2014 James Booth + * + * This file is part of Profanity. + * + * Profanity is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Profanity is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Profanity. If not, see . + * + * In addition, as a special exception, the copyright holders give permission to + * link the code of portions of this program with the OpenSSL library under + * certain conditions as described in each individual source file, and + * distribute linked combinations including the two. + * + * You must obey the GNU General Public License in all respects for all of the + * code used other than OpenSSL. If you modify file(s) with this exception, you + * may extend this exception to your version of the file(s), but you are not + * obligated to do so. If you do not wish to do so, delete this exception + * statement from your version. If you delete this exception statement from all + * source files in the program, then also delete it here. + * + */ + +#ifndef UI_KEYHANDLERS_H +#define UI_KEYHANDLERS_H + +#include + +void key_printable(char * const line, int * const line_utf8_pos, int * const col, int * const pad_start, const wint_t ch, const int wcols); + +#endif diff --git a/tests/test_keyhandlers.c b/tests/test_keyhandlers.c new file mode 100644 index 00000000..e01133e1 --- /dev/null +++ b/tests/test_keyhandlers.c @@ -0,0 +1,150 @@ +#include "ui/keyhandlers.h" +#include "ui/inputwin.h" +#include +#include +#include +#include +#include +#include + +#include + +static char line[INP_WIN_MAX]; + +void append_non_wide_to_empty(void **state) +{ + setlocale(LC_ALL, ""); + line[0] = '\0'; + int line_utf8_pos = 0; + int col = 0; + int pad_start = 0; + + key_printable(line, &line_utf8_pos, &col, &pad_start, 'a', 80); + + assert_string_equal("a", line); + assert_int_equal(line_utf8_pos, 1); + assert_int_equal(col, 1); + assert_int_equal(pad_start, 0); +} + +void append_wide_to_empty(void **state) +{ + setlocale(LC_ALL, ""); + line[0] = '\0'; + int line_utf8_pos = 0; + int col = 0; + int pad_start = 0; + + key_printable(line, &line_utf8_pos, &col, &pad_start, 0x56DB, 80); + + assert_string_equal("四", line); + assert_int_equal(line_utf8_pos, 1); + assert_int_equal(col, 2); + assert_int_equal(pad_start, 0); +} + +void append_non_wide_to_non_wide(void **state) +{ + setlocale(LC_ALL, ""); + strncpy(line, "a", 1); + line[1] = '\0'; + int line_utf8_pos = 1; + int col = 1; + int pad_start = 0; + + key_printable(line, &line_utf8_pos, &col, &pad_start, 'b', 80); + + assert_string_equal("ab", line); + assert_int_equal(line_utf8_pos, 2); + assert_int_equal(col, 2); + assert_int_equal(pad_start, 0); +} + +void append_wide_to_non_wide(void **state) +{ + setlocale(LC_ALL, ""); + strncpy(line, "a", 1); + line[1] = '\0'; + int line_utf8_pos = 1; + int col = 1; + int pad_start = 0; + + key_printable(line, &line_utf8_pos, &col, &pad_start, 0x56DB, 80); + + assert_string_equal("a四", line); + assert_int_equal(line_utf8_pos, 2); + assert_int_equal(col, 3); + assert_int_equal(pad_start, 0); +} + +void append_non_wide_to_wide(void **state) +{ + setlocale(LC_ALL, ""); + g_utf8_strncpy(line, "四", 1); + line[strlen(line)] = '\0'; + int line_utf8_pos = 1; + int col = 2; + int pad_start = 0; + + key_printable(line, &line_utf8_pos, &col, &pad_start, 'b', 80); + + assert_string_equal("四b", line); + assert_int_equal(line_utf8_pos, 2); + assert_int_equal(col, 3); + assert_int_equal(pad_start, 0); +} + +void append_wide_to_wide(void **state) +{ + setlocale(LC_ALL, ""); + g_utf8_strncpy(line, "四", 1); + line[strlen(line)] = '\0'; + int line_utf8_pos = 1; + int col = 2; + int pad_start = 0; + + key_printable(line, &line_utf8_pos, &col, &pad_start, 0x4E09, 80); + + assert_string_equal("四三", line); + assert_int_equal(line_utf8_pos, 2); + assert_int_equal(col, 4); + assert_int_equal(pad_start, 0); +} + +void append_no_wide_when_overrun(void **state) +{ + setlocale(LC_ALL, ""); + g_utf8_strncpy(line, "0123456789四1234567", 18); + line[strlen(line)] = '\0'; + int line_utf8_pos = 18; + int col = 19; + int pad_start = 0; + + key_printable(line, &line_utf8_pos, &col, &pad_start, 'z', 20); + key_printable(line, &line_utf8_pos, &col, &pad_start, 'z', 20); + key_printable(line, &line_utf8_pos, &col, &pad_start, 'z', 20); + + assert_string_equal("0123456789四1234567zzz", line); + assert_int_equal(line_utf8_pos, 21); + assert_int_equal(col, 22); + assert_int_equal(pad_start, 3); +} + +void append_wide_when_overrun(void **state) +{ + setlocale(LC_ALL, ""); + g_utf8_strncpy(line, "0123456789四1234567", 18); + line[strlen(line)] = '\0'; + int line_utf8_pos = 18; + int col = 19; + int pad_start = 0; + + key_printable(line, &line_utf8_pos, &col, &pad_start, 0x4E09, 20); + key_printable(line, &line_utf8_pos, &col, &pad_start, 0x4E09, 20); + key_printable(line, &line_utf8_pos, &col, &pad_start, 0x4E09, 20); + + assert_string_equal("0123456789四1234567三三三", line); + assert_int_equal(line_utf8_pos, 21); + assert_int_equal(col, 25); + assert_int_equal(pad_start, 6); +} \ No newline at end of file diff --git a/tests/test_keyhandlers.h b/tests/test_keyhandlers.h new file mode 100644 index 00000000..142a05ef --- /dev/null +++ b/tests/test_keyhandlers.h @@ -0,0 +1,11 @@ +void append_non_wide_to_empty(void **state); +void append_wide_to_empty(void **state); + +void append_non_wide_to_non_wide(void **state); +void append_wide_to_non_wide(void **state); + +void append_non_wide_to_wide(void **state); +void append_wide_to_wide(void **state); + +void append_no_wide_when_overrun(void **state); +void append_wide_when_overrun(void **state); \ No newline at end of file diff --git a/tests/testsuite.c b/tests/testsuite.c index cf511c59..4964d99d 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -35,6 +35,7 @@ #include "test_cmd_win.h" #include "test_cmd_disconnect.h" #include "test_form.h" +#include "test_keyhandlers.h" int main(int argc, char* argv[]) { const UnitTest all_tests[] = { @@ -622,6 +623,15 @@ int main(int argc, char* argv[]) { unit_test(remove_text_multi_value_removes_when_many), unit_test(clears_chat_sessions), + + unit_test(append_non_wide_to_empty), + unit_test(append_wide_to_empty), + unit_test(append_non_wide_to_non_wide), + unit_test(append_wide_to_non_wide), + unit_test(append_non_wide_to_wide), + unit_test(append_wide_to_wide), + unit_test(append_no_wide_when_overrun), + unit_test(append_wide_when_overrun), }; return run_tests(all_tests); From 58239244bb703d770aa423d8fcea19522771ae0d Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 20 Jan 2015 00:56:35 +0000 Subject: [PATCH 007/252] Added key insert handler tests --- tests/test_keyhandlers.c | 117 +++++++++++++++++++++++++++++++++------ tests/test_keyhandlers.h | 7 ++- tests/testsuite.c | 4 ++ 3 files changed, 111 insertions(+), 17 deletions(-) diff --git a/tests/test_keyhandlers.c b/tests/test_keyhandlers.c index e01133e1..2e29ec6d 100644 --- a/tests/test_keyhandlers.c +++ b/tests/test_keyhandlers.c @@ -11,19 +11,36 @@ static char line[INP_WIN_MAX]; +static int utf8_pos_to_col(char *str, int utf8_pos) +{ + int col = 0; + + int i = 0; + for (i = 0; i Date: Tue, 20 Jan 2015 23:02:04 +0000 Subject: [PATCH 008/252] Added key insert tests, extracted key_ctrl_left handler --- src/ui/inputwin.c | 68 +----- src/ui/keyhandlers.c | 94 ++++++-- src/ui/keyhandlers.h | 2 + tests/test_keyhandlers.c | 452 ++++++++++++++++++++++++++++++++++++++- tests/test_keyhandlers.h | 36 +++- tests/testsuite.c | 29 ++- 6 files changed, 586 insertions(+), 95 deletions(-) diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index 59292482..7b5c33d0 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -256,67 +256,12 @@ _handle_edit(int key_type, const wint_t ch) { int col = getcurx(inp_win); int utf8_len = g_utf8_strlen(line, -1); + int wcols = getmaxx(stdscr); // CTRL-LEFT - if (line_utf8_pos > 0 && _is_ctrl_left(key_type, ch)) { - gchar *curr_ch = g_utf8_offset_to_pointer(line, line_utf8_pos); - gunichar curr_uni = g_utf8_get_char(curr_ch); - line_utf8_pos--; - col--; - if (g_unichar_iswide(curr_uni)) { - col--; - } - - curr_ch = g_utf8_find_prev_char(line, curr_ch); - - gchar *prev_ch; - gunichar prev_uni; - while (curr_ch != NULL) { - curr_uni = g_utf8_get_char(curr_ch); - if (g_unichar_isspace(curr_uni)) { - curr_ch = g_utf8_find_prev_char(line, curr_ch); - line_utf8_pos--; - col--; - } else { - prev_ch = g_utf8_find_prev_char(line, curr_ch); - if (prev_ch == NULL) { - curr_ch = NULL; - break; - } else { - prev_uni = g_utf8_get_char(prev_ch); - line_utf8_pos--; - col--; - if (g_unichar_iswide(prev_uni)) { - col--; - } - if (g_unichar_isspace(prev_uni)) { - break; - } else { - curr_ch = prev_ch; - } - } - } - } - - if (curr_ch == NULL) { - col = 0; - wmove(inp_win, 0, col); - } else { - col++; - line_utf8_pos++; - wmove(inp_win, 0, col); - } - - // if gone off screen to left, jump left (half a screen worth) - int wcols = getmaxx(stdscr); - if (col <= pad_start) { - pad_start = pad_start - (wcols / 2); - if (pad_start < 0) { - pad_start = 0; - } - - _inp_win_update_virtual(); - } + if (_is_ctrl_left(key_type, ch)) { + key_ctrl_left(line, &line_utf8_pos, &col, &pad_start, wcols); + wmove(inp_win, 0, col); return 1; // CTRL-RIGHT @@ -353,7 +298,6 @@ _handle_edit(int key_type, const wint_t ch) wmove(inp_win, 0, col); // if gone off screen to right, jump right (half a screen worth) - int wcols = getmaxx(stdscr); if (col > pad_start + wcols) { pad_start = pad_start + (wcols / 2); _inp_win_update_virtual(); @@ -464,7 +408,7 @@ _handle_edit(int key_type, const wint_t ch) line_utf8_pos--; // current position off screen to left - if (col - 1 < pad_start) { + if (col < pad_start) { pad_start--; _inp_win_update_virtual(); } @@ -490,7 +434,7 @@ _handle_edit(int key_type, const wint_t ch) // current position off screen to right int wcols = getmaxx(stdscr); - if ((col + 1 - pad_start) >= wcols) { + if ((col - pad_start) >= wcols) { pad_start++; _inp_win_update_virtual(); } diff --git a/src/ui/keyhandlers.c b/src/ui/keyhandlers.c index 513997ef..d7c3c616 100644 --- a/src/ui/keyhandlers.c +++ b/src/ui/keyhandlers.c @@ -48,7 +48,6 @@ key_printable(char * const line, int * const line_utf8_pos, int * const col, int // handle insert if not at end of input if (*line_utf8_pos < utf8_len) { - // create new line char bytes[MB_CUR_MAX]; size_t utf8_ch_len = wcrtomb(bytes, ch, NULL); bytes[utf8_ch_len] = '\0'; @@ -62,35 +61,29 @@ key_printable(char * const line, int * const line_utf8_pos, int * const col, int g_free(end); g_string_free(new_line_str, FALSE); - // replace old line strncpy(line, new_line, INP_WIN_MAX); free(new_line); - // set utf8 position - (*line_utf8_pos)++; - - // set col position - (*col)++; gunichar uni = g_utf8_get_char(bytes); - if (g_unichar_iswide(uni)) { - (*col)++; + if (*col == (*pad_start + wcols)) { + (*pad_start)++; + if (g_unichar_iswide(uni)) { + (*pad_start)++; + } } - // set pad_start - int display_len = utf8_display_len(line); - (*pad_start) = 0; - if (display_len > wcols-2) { - (*pad_start) = display_len - wcols + 1; + (*line_utf8_pos)++; + + (*col)++; + if (g_unichar_iswide(uni)) { + (*col)++; } // otherwise just append } else { char bytes[MB_CUR_MAX+1]; size_t utf8_ch_len = wcrtomb(bytes, ch, NULL); - - // wcrtomb can return (size_t) -1 if (utf8_ch_len < MB_CUR_MAX) { - // update old line int i; int bytes_len = strlen(line); @@ -99,10 +92,8 @@ key_printable(char * const line, int * const line_utf8_pos, int * const col, int } line[bytes_len] = '\0'; - // set utf8 position (*line_utf8_pos)++; - // set col position (*col)++; bytes[utf8_ch_len] = '\0'; gunichar uni = g_utf8_get_char(bytes); @@ -110,9 +101,7 @@ key_printable(char * const line, int * const line_utf8_pos, int * const col, int (*col)++; } - // set pad_start - // if gone over screen size follow input - if (*col - *pad_start > wcols-2) { + if (*col - *pad_start > wcols-1) { (*pad_start)++; if (g_unichar_iswide(uni)) { (*pad_start)++; @@ -120,4 +109,63 @@ key_printable(char * const line, int * const line_utf8_pos, int * const col, int } } } -} \ No newline at end of file +} + +void +key_ctrl_left(const char * const line, int * const line_utf8_pos, int * const col, int * const pad_start, const int wcols) +{ + if (*line_utf8_pos == 0) { + return; + } + + gchar *curr_ch = g_utf8_offset_to_pointer(line, *line_utf8_pos); + gunichar curr_uni = g_utf8_get_char(curr_ch); + (*line_utf8_pos)--; + (*col)--; + if (g_unichar_iswide(curr_uni)) { + (*col)--; + } + + curr_ch = g_utf8_find_prev_char(line, curr_ch); + + gchar *prev_ch; + gunichar prev_uni; + while (curr_ch != NULL) { + curr_uni = g_utf8_get_char(curr_ch); + if (g_unichar_isspace(curr_uni)) { + curr_ch = g_utf8_find_prev_char(line, curr_ch); + (*line_utf8_pos)--; + (*col)--; + } else { + prev_ch = g_utf8_find_prev_char(line, curr_ch); + if (prev_ch == NULL) { + curr_ch = NULL; + break; + } else { + prev_uni = g_utf8_get_char(prev_ch); + (*line_utf8_pos)--; + (*col)--; + if (g_unichar_iswide(prev_uni)) { + (*col)--; + } + if (g_unichar_isspace(prev_uni)) { + break; + } else { + curr_ch = prev_ch; + } + } + } + } + + if (curr_ch == NULL) { + (*col) = 0; + (*line_utf8_pos) = 0; + } else { + (*col)++; + (*line_utf8_pos)++; + } + + if (*col < *pad_start) { + *pad_start = *col; + } +} diff --git a/src/ui/keyhandlers.h b/src/ui/keyhandlers.h index cb1b14d8..d8153356 100644 --- a/src/ui/keyhandlers.h +++ b/src/ui/keyhandlers.h @@ -39,4 +39,6 @@ void key_printable(char * const line, int * const line_utf8_pos, int * const col, int * const pad_start, const wint_t ch, const int wcols); +void key_ctrl_left(const char * const line, int * const line_utf8_pos, int * const col, int * const pad_start, const int wcols); + #endif diff --git a/tests/test_keyhandlers.c b/tests/test_keyhandlers.c index 2e29ec6d..32582c2e 100644 --- a/tests/test_keyhandlers.c +++ b/tests/test_keyhandlers.c @@ -63,7 +63,7 @@ void append_wide_to_empty(void **state) void append_non_wide_to_non_wide(void **state) { setlocale(LC_ALL, ""); - strncpy(line, "a", 1); + g_utf8_strncpy(line, "a", 1); line[1] = '\0'; int line_utf8_pos = 1; int col = utf8_pos_to_col(line, line_utf8_pos); @@ -80,7 +80,7 @@ void append_non_wide_to_non_wide(void **state) void append_wide_to_non_wide(void **state) { setlocale(LC_ALL, ""); - strncpy(line, "a", 1); + g_utf8_strncpy(line, "a", 1); line[1] = '\0'; int line_utf8_pos = 1; int col = utf8_pos_to_col(line, line_utf8_pos); @@ -128,7 +128,7 @@ void append_wide_to_wide(void **state) assert_int_equal(pad_start, 0); } -void append_no_wide_when_overrun(void **state) +void append_non_wide_when_overrun(void **state) { setlocale(LC_ALL, ""); g_utf8_strncpy(line, "0123456789四1234567", 18); @@ -232,4 +232,450 @@ void insert_wide_to_wide(void **state) assert_int_equal(line_utf8_pos, 3); assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos)); assert_int_equal(pad_start, 0); +} + +void insert_single_non_wide_when_pad_scrolled(void **state) +{ + setlocale(LC_ALL, ""); + g_utf8_strncpy(line, "AAAAAAAAAAAAAAA", 15); + line[strlen(line)] = '\0'; + int line_utf8_pos = 2; + int col = utf8_pos_to_col(line, line_utf8_pos); + int pad_start = 2; + + key_printable(line, &line_utf8_pos, &col, &pad_start, 'B', 12); + + assert_string_equal("AABAAAAAAAAAAAAA", line); + assert_int_equal(line_utf8_pos, 3); + assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos)); + assert_int_equal(pad_start, 2); +} + +void insert_many_non_wide_when_pad_scrolled(void **state) +{ + setlocale(LC_ALL, ""); + g_utf8_strncpy(line, "AAAAAAAAAAAAAAA", 15); + line[strlen(line)] = '\0'; + int line_utf8_pos = 2; + int col = utf8_pos_to_col(line, line_utf8_pos); + int pad_start = 2; + + key_printable(line, &line_utf8_pos, &col, &pad_start, 'B', 12); + key_printable(line, &line_utf8_pos, &col, &pad_start, 'C', 12); + key_printable(line, &line_utf8_pos, &col, &pad_start, 'D', 12); + + assert_string_equal("AABCDAAAAAAAAAAAAA", line); + assert_int_equal(line_utf8_pos, 5); + assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos)); + assert_int_equal(pad_start, 2); +} + +void insert_single_wide_when_pad_scrolled(void **state) +{ + setlocale(LC_ALL, ""); + g_utf8_strncpy(line, "AAAAAAAAAAAAAAA", 15); + line[strlen(line)] = '\0'; + int line_utf8_pos = 2; + int col = utf8_pos_to_col(line, line_utf8_pos); + int pad_start = 2; + + key_printable(line, &line_utf8_pos, &col, &pad_start, 0x4E09, 12); + + assert_string_equal("AA三AAAAAAAAAAAAA", line); + assert_int_equal(line_utf8_pos, 3); + assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos)); + assert_int_equal(pad_start, 2); +} + +void insert_many_wide_when_pad_scrolled(void **state) +{ + setlocale(LC_ALL, ""); + g_utf8_strncpy(line, "AAAAAAAAAAAAAAA", 15); + line[strlen(line)] = '\0'; + int line_utf8_pos = 2; + int col = utf8_pos_to_col(line, line_utf8_pos); + int pad_start = 2; + + key_printable(line, &line_utf8_pos, &col, &pad_start, 0x304C, 12); + key_printable(line, &line_utf8_pos, &col, &pad_start, 0x304C, 12); + key_printable(line, &line_utf8_pos, &col, &pad_start, 0x4E09, 12); + + assert_string_equal("AAがが三AAAAAAAAAAAAA", line); + assert_int_equal(line_utf8_pos, 5); + assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos)); + assert_int_equal(pad_start, 2); +} + +void insert_single_non_wide_last_column(void **state) +{ + setlocale(LC_ALL, ""); + g_utf8_strncpy(line, "abcdefghijklmno", 15); + line[strlen(line)] = '\0'; + int line_utf8_pos = 7; + int col = utf8_pos_to_col(line, line_utf8_pos); + int pad_start = 2; + + key_printable(line, &line_utf8_pos, &col, &pad_start, '1', 5); + + assert_string_equal("abcdefg1hijklmno", line); + assert_int_equal(line_utf8_pos, 8); + assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos)); + assert_int_equal(pad_start, 3); +} + +void insert_many_non_wide_last_column(void **state) +{ + setlocale(LC_ALL, ""); + g_utf8_strncpy(line, "abcdefghijklmno", 15); + line[strlen(line)] = '\0'; + int line_utf8_pos = 7; + int col = utf8_pos_to_col(line, line_utf8_pos); + int pad_start = 2; + + key_printable(line, &line_utf8_pos, &col, &pad_start, '1', 5); + key_printable(line, &line_utf8_pos, &col, &pad_start, '2', 5); + + assert_string_equal("abcdefg12hijklmno", line); + assert_int_equal(line_utf8_pos, 9); + assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos)); + assert_int_equal(pad_start, 4); +} + +void insert_single_wide_last_column(void **state) +{ + setlocale(LC_ALL, ""); + g_utf8_strncpy(line, "abcdefghijklmno", 15); + line[strlen(line)] = '\0'; + int line_utf8_pos = 7; + int col = utf8_pos_to_col(line, line_utf8_pos); + int pad_start = 2; + + key_printable(line, &line_utf8_pos, &col, &pad_start, 0x4E09, 5); + + assert_string_equal("abcdefg三hijklmno", line); + assert_int_equal(line_utf8_pos, 8); + assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos)); + assert_int_equal(pad_start, 4); +} + +void insert_many_wide_last_column(void **state) +{ + setlocale(LC_ALL, ""); + g_utf8_strncpy(line, "abcdefghijklmno", 15); + line[strlen(line)] = '\0'; + int line_utf8_pos = 7; + int col = utf8_pos_to_col(line, line_utf8_pos); + int pad_start = 2; + + key_printable(line, &line_utf8_pos, &col, &pad_start, 0x4E09, 5); + key_printable(line, &line_utf8_pos, &col, &pad_start, 0x304C, 5); + + assert_string_equal("abcdefg三がhijklmno", line); + assert_int_equal(line_utf8_pos, 9); + assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos)); + assert_int_equal(pad_start, 6); +} + +void ctrl_left_when_at_start(void **state) +{ + setlocale(LC_ALL, ""); + g_utf8_strncpy(line, "abcd efghij klmn opqr", 21); + line[strlen(line)] = '\0'; + int line_utf8_pos = 0; + int col = utf8_pos_to_col(line, line_utf8_pos); + int pad_start = 0; + + key_ctrl_left(line, &line_utf8_pos, &col, &pad_start, 80); + + assert_int_equal(line_utf8_pos, 0); + assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos)); + assert_int_equal(pad_start, 0); +} + +void ctrl_left_when_in_first_word(void **state) +{ + setlocale(LC_ALL, ""); + g_utf8_strncpy(line, "abcd efghij klmn opqr", 21); + line[strlen(line)] = '\0'; + int line_utf8_pos = 2; + int col = utf8_pos_to_col(line, line_utf8_pos); + int pad_start = 0; + + key_ctrl_left(line, &line_utf8_pos, &col, &pad_start, 80); + + assert_int_equal(line_utf8_pos, 0); + assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos)); + assert_int_equal(pad_start, 0); +} + +void ctrl_left_when_in_first_space(void **state) +{ + setlocale(LC_ALL, ""); + g_utf8_strncpy(line, "abcd efghij klmn opqr", 21); + line[strlen(line)] = '\0'; + int line_utf8_pos = 4; + int col = utf8_pos_to_col(line, line_utf8_pos); + int pad_start = 0; + + key_ctrl_left(line, &line_utf8_pos, &col, &pad_start, 80); + + assert_int_equal(line_utf8_pos, 0); + assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos)); + assert_int_equal(pad_start, 0); +} + +void ctrl_left_when_at_start_of_second_word(void **state) +{ + setlocale(LC_ALL, ""); + g_utf8_strncpy(line, "abcd efghij klmn opqr", 21); + line[strlen(line)] = '\0'; + int line_utf8_pos = 5; + int col = utf8_pos_to_col(line, line_utf8_pos); + int pad_start = 0; + + key_ctrl_left(line, &line_utf8_pos, &col, &pad_start, 80); + + assert_int_equal(line_utf8_pos, 0); + assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos)); + assert_int_equal(pad_start, 0); +} + +void ctrl_left_when_in_second_word(void **state) +{ + setlocale(LC_ALL, ""); + g_utf8_strncpy(line, "abcd efghij klmn opqr", 21); + line[strlen(line)] = '\0'; + int line_utf8_pos = 8; + int col = utf8_pos_to_col(line, line_utf8_pos); + int pad_start = 0; + + key_ctrl_left(line, &line_utf8_pos, &col, &pad_start, 80); + + assert_int_equal(line_utf8_pos, 5); + assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos)); + assert_int_equal(pad_start, 0); +} + +void ctrl_left_when_at_end_of_second_word(void **state) +{ + setlocale(LC_ALL, ""); + g_utf8_strncpy(line, "abcd efghij klmn opqr", 21); + line[strlen(line)] = '\0'; + int line_utf8_pos = 10; + int col = utf8_pos_to_col(line, line_utf8_pos); + int pad_start = 0; + + key_ctrl_left(line, &line_utf8_pos, &col, &pad_start, 80); + + assert_int_equal(line_utf8_pos, 5); + assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos)); + assert_int_equal(pad_start, 0); +} + +void ctrl_left_when_in_second_space(void **state) +{ + setlocale(LC_ALL, ""); + g_utf8_strncpy(line, "abcd efghij klmn opqr", 21); + line[strlen(line)] = '\0'; + int line_utf8_pos = 11; + int col = utf8_pos_to_col(line, line_utf8_pos); + int pad_start = 0; + + key_ctrl_left(line, &line_utf8_pos, &col, &pad_start, 80); + + assert_int_equal(line_utf8_pos, 5); + assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos)); + assert_int_equal(pad_start, 0); +} + +void ctrl_left_when_at_start_of_third_word(void **state) +{ + setlocale(LC_ALL, ""); + g_utf8_strncpy(line, "abcd efghij klmn opqr", 21); + line[strlen(line)] = '\0'; + int line_utf8_pos = 12; + int col = utf8_pos_to_col(line, line_utf8_pos); + int pad_start = 0; + + key_ctrl_left(line, &line_utf8_pos, &col, &pad_start, 80); + + assert_int_equal(line_utf8_pos, 5); + assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos)); + assert_int_equal(pad_start, 0); +} + +void ctrl_left_when_in_third_word(void **state) +{ + setlocale(LC_ALL, ""); + g_utf8_strncpy(line, "abcd efghij klmn opqr", 21); + line[strlen(line)] = '\0'; + int line_utf8_pos = 14; + int col = utf8_pos_to_col(line, line_utf8_pos); + int pad_start = 0; + + key_ctrl_left(line, &line_utf8_pos, &col, &pad_start, 80); + + assert_int_equal(line_utf8_pos, 12); + assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos)); + assert_int_equal(pad_start, 0); +} + +void ctrl_left_when_at_end_of_third_word(void **state) +{ + setlocale(LC_ALL, ""); + g_utf8_strncpy(line, "abcd efghij klmn opqr", 21); + line[strlen(line)] = '\0'; + int line_utf8_pos = 15; + int col = utf8_pos_to_col(line, line_utf8_pos); + int pad_start = 0; + + key_ctrl_left(line, &line_utf8_pos, &col, &pad_start, 80); + + assert_int_equal(line_utf8_pos, 12); + assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos)); + assert_int_equal(pad_start, 0); +} + +void ctrl_left_when_in_third_space(void **state) +{ + setlocale(LC_ALL, ""); + g_utf8_strncpy(line, "abcd efghij klmn opqr", 21); + line[strlen(line)] = '\0'; + int line_utf8_pos = 16; + int col = utf8_pos_to_col(line, line_utf8_pos); + int pad_start = 0; + + key_ctrl_left(line, &line_utf8_pos, &col, &pad_start, 80); + + assert_int_equal(line_utf8_pos, 12); + assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos)); + assert_int_equal(pad_start, 0); +} + +void ctrl_left_when_at_end(void **state) +{ + setlocale(LC_ALL, ""); + g_utf8_strncpy(line, "abcd efghij klmn opqr", 21); + line[strlen(line)] = '\0'; + int line_utf8_pos = 20; + int col = utf8_pos_to_col(line, line_utf8_pos); + int pad_start = 0; + + key_ctrl_left(line, &line_utf8_pos, &col, &pad_start, 80); + + assert_int_equal(line_utf8_pos, 17); + assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos)); + assert_int_equal(pad_start, 0); +} + +void ctrl_left_when_in_only_whitespace(void **state) +{ + setlocale(LC_ALL, ""); + g_utf8_strncpy(line, " ", 7); + line[strlen(line)] = '\0'; + int line_utf8_pos = 5; + int col = utf8_pos_to_col(line, line_utf8_pos); + int pad_start = 0; + + key_ctrl_left(line, &line_utf8_pos, &col, &pad_start, 80); + + assert_int_equal(line_utf8_pos, 0); + assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos)); + assert_int_equal(pad_start, 0); +} + +void ctrl_left_when_start_whitespace_start_of_word(void **state) +{ + setlocale(LC_ALL, ""); + g_utf8_strncpy(line, " hello", 9); + line[strlen(line)] = '\0'; + int line_utf8_pos = 4; + int col = utf8_pos_to_col(line, line_utf8_pos); + int pad_start = 0; + + key_ctrl_left(line, &line_utf8_pos, &col, &pad_start, 80); + + assert_int_equal(line_utf8_pos, 0); + assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos)); + assert_int_equal(pad_start, 0); +} + +void ctrl_left_when_start_whitespace_middle_of_word(void **state) +{ + setlocale(LC_ALL, ""); + g_utf8_strncpy(line, " hello", 9); + line[strlen(line)] = '\0'; + int line_utf8_pos = 7; + int col = utf8_pos_to_col(line, line_utf8_pos); + int pad_start = 0; + + key_ctrl_left(line, &line_utf8_pos, &col, &pad_start, 80); + + assert_int_equal(line_utf8_pos, 4); + assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos)); + assert_int_equal(pad_start, 0); +} + +void ctrl_left_in_whitespace_between_words(void **state) +{ + setlocale(LC_ALL, ""); + g_utf8_strncpy(line, "hey hello", 12); + line[strlen(line)] = '\0'; + int line_utf8_pos = 5; + int col = utf8_pos_to_col(line, line_utf8_pos); + int pad_start = 0; + + key_ctrl_left(line, &line_utf8_pos, &col, &pad_start, 80); + + assert_int_equal(line_utf8_pos, 0); + assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos)); + assert_int_equal(pad_start, 0); +} + +void ctrl_left_in_whitespace_between_words_start_of_word(void **state) +{ + setlocale(LC_ALL, ""); + g_utf8_strncpy(line, "hey hello", 12); + line[strlen(line)] = '\0'; + int line_utf8_pos = 7; + int col = utf8_pos_to_col(line, line_utf8_pos); + int pad_start = 0; + + key_ctrl_left(line, &line_utf8_pos, &col, &pad_start, 80); + + assert_int_equal(line_utf8_pos, 0); + assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos)); + assert_int_equal(pad_start, 0); +} + +void ctrl_left_in_whitespace_between_words_middle_of_word(void **state) +{ + setlocale(LC_ALL, ""); + g_utf8_strncpy(line, "hey hello", 12); + line[strlen(line)] = '\0'; + int line_utf8_pos = 9; + int col = utf8_pos_to_col(line, line_utf8_pos); + int pad_start = 0; + + key_ctrl_left(line, &line_utf8_pos, &col, &pad_start, 80); + + assert_int_equal(line_utf8_pos, 7); + assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos)); + assert_int_equal(pad_start, 0); +} + +void ctrl_left_when_word_overrun_to_left(void **state) +{ + setlocale(LC_ALL, ""); + g_utf8_strncpy(line, "someword anotherword", 20); + line[strlen(line)] = '\0'; + int line_utf8_pos = 18; + int col = utf8_pos_to_col(line, line_utf8_pos); + int pad_start = 14; + + key_ctrl_left(line, &line_utf8_pos, &col, &pad_start, 80); + + assert_int_equal(line_utf8_pos, 9); + assert_int_equal(col, utf8_pos_to_col(line, line_utf8_pos)); + assert_int_equal(pad_start, 9); } \ No newline at end of file diff --git a/tests/test_keyhandlers.h b/tests/test_keyhandlers.h index f70ee81e..4db5f340 100644 --- a/tests/test_keyhandlers.h +++ b/tests/test_keyhandlers.h @@ -1,16 +1,40 @@ void append_non_wide_to_empty(void **state); void append_wide_to_empty(void **state); - void append_non_wide_to_non_wide(void **state); void append_wide_to_non_wide(void **state); - void append_non_wide_to_wide(void **state); void append_wide_to_wide(void **state); - -void append_no_wide_when_overrun(void **state); +void append_non_wide_when_overrun(void **state); void append_wide_when_overrun(void **state); - void insert_non_wide_to_non_wide(void **state); void insert_wide_to_non_wide(void **state); void insert_non_wide_to_wide(void **state); -void insert_wide_to_wide(void **state); \ No newline at end of file +void insert_wide_to_wide(void **state); +void insert_single_non_wide_when_pad_scrolled(void **state); +void insert_many_non_wide_when_pad_scrolled(void **state); +void insert_single_wide_when_pad_scrolled(void **state); +void insert_many_wide_when_pad_scrolled(void **state); +void insert_single_non_wide_last_column(void **state); +void insert_many_non_wide_last_column(void **state); +void insert_single_wide_last_column(void **state); +void insert_many_wide_last_column(void **state); + +void ctrl_left_when_at_start(void **state); +void ctrl_left_when_in_first_word(void **state); +void ctrl_left_when_in_first_space(void **state); +void ctrl_left_when_at_start_of_second_word(void **state); +void ctrl_left_when_in_second_word(void **state); +void ctrl_left_when_at_end_of_second_word(void **state); +void ctrl_left_when_in_second_space(void **state); +void ctrl_left_when_at_start_of_third_word(void **state); +void ctrl_left_when_in_third_word(void **state); +void ctrl_left_when_at_end_of_third_word(void **state); +void ctrl_left_when_in_third_space(void **state); +void ctrl_left_when_at_end(void **state); +void ctrl_left_when_in_only_whitespace(void **state); +void ctrl_left_when_start_whitespace_start_of_word(void **state); +void ctrl_left_when_start_whitespace_middle_of_word(void **state); +void ctrl_left_in_whitespace_between_words(void **state); +void ctrl_left_in_whitespace_between_words_start_of_word(void **state); +void ctrl_left_in_whitespace_between_words_middle_of_word(void **state); +void ctrl_left_when_word_overrun_to_left(void **state); \ No newline at end of file diff --git a/tests/testsuite.c b/tests/testsuite.c index 3a60317e..1a5e0f7e 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -630,12 +630,39 @@ int main(int argc, char* argv[]) { unit_test(append_wide_to_non_wide), unit_test(append_non_wide_to_wide), unit_test(append_wide_to_wide), - unit_test(append_no_wide_when_overrun), + unit_test(append_non_wide_when_overrun), unit_test(append_wide_when_overrun), unit_test(insert_non_wide_to_non_wide), unit_test(insert_wide_to_non_wide), unit_test(insert_non_wide_to_wide), unit_test(insert_wide_to_wide), + unit_test(insert_single_non_wide_when_pad_scrolled), + unit_test(insert_many_non_wide_when_pad_scrolled), + unit_test(insert_single_wide_when_pad_scrolled), + unit_test(insert_many_wide_when_pad_scrolled), + unit_test(insert_single_non_wide_last_column), + unit_test(insert_many_non_wide_last_column), + unit_test(insert_single_wide_last_column), + unit_test(insert_many_wide_last_column), + unit_test(ctrl_left_when_at_start), + unit_test(ctrl_left_when_in_first_word), + unit_test(ctrl_left_when_in_first_space), + unit_test(ctrl_left_when_at_start_of_second_word), + unit_test(ctrl_left_when_in_second_word), + unit_test(ctrl_left_when_at_end_of_second_word), + unit_test(ctrl_left_when_in_second_space), + unit_test(ctrl_left_when_at_start_of_third_word), + unit_test(ctrl_left_when_in_third_word), + unit_test(ctrl_left_when_at_end_of_third_word), + unit_test(ctrl_left_when_in_third_space), + unit_test(ctrl_left_when_at_end), + unit_test(ctrl_left_when_in_only_whitespace), + unit_test(ctrl_left_when_start_whitespace_start_of_word), + unit_test(ctrl_left_when_start_whitespace_middle_of_word), + unit_test(ctrl_left_in_whitespace_between_words), + unit_test(ctrl_left_in_whitespace_between_words_start_of_word), + unit_test(ctrl_left_in_whitespace_between_words_middle_of_word), + unit_test(ctrl_left_when_word_overrun_to_left), }; return run_tests(all_tests); From 2cdbfc7eb7d90ed286c6c5f432990166cdec0b93 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 27 Jan 2015 22:13:09 +0000 Subject: [PATCH 009/252] Added gnu readline --- configure.ac | 2 + src/profanity.c | 62 +++++-- src/ui/core.c | 6 + src/ui/inputwin.c | 80 ++++----- src/ui/inputwin.h | 1 + src/ui/keyhandlers.c | 55 +++++- src/ui/keyhandlers.h | 5 +- src/ui/ui.h | 1 + tests/helpers.c | 18 ++ tests/helpers.h | 2 + tests/test_keyhandlers.c | 365 ++++++++++++++++++++++----------------- tests/test_keyhandlers.h | 35 ++-- tests/testsuite.c | 36 ++-- tests/ui/stub_ui.c | 3 + 14 files changed, 428 insertions(+), 243 deletions(-) diff --git a/configure.ac b/configure.ac index 7369f112..2794ad43 100644 --- a/configure.ac +++ b/configure.ac @@ -133,6 +133,8 @@ PKG_CHECK_MODULES([glib], [glib-2.0 >= 2.26], [], [AC_MSG_ERROR([glib 2.26 or higher is required for profanity])]) PKG_CHECK_MODULES([curl], [libcurl], [], [AC_MSG_ERROR([libcurl is required for profanity])]) +AC_CHECK_LIB([readline], [main], [], + [AC_MSG_ERROR([libreadline is required for profanity])]) AS_IF([test "x$PLATFORM" = xosx], [LIBS="-lcurl $LIBS"]) diff --git a/src/profanity.c b/src/profanity.c index 13297124..c105d33f 100644 --- a/src/profanity.c +++ b/src/profanity.c @@ -43,6 +43,8 @@ #include #include +#include +#include #include "profanity.h" #include "chat_session.h" @@ -71,6 +73,20 @@ static void _create_directories(void); static void _connect_default(const char * const account); static gboolean idle = FALSE; +static void cb_linehandler(char *); +static gboolean cmd_result = TRUE; + +static void +cb_linehandler(char *line) +{ + /* Can use ^D (stty eof) or `exit' to exit. */ + if (*line) { + add_history(line); + } + rl_redisplay(); + cmd_result = cmd_process_input(line); + free(line); +} void prof_run(const int disable_tls, char *log_level, char *account_name) @@ -79,26 +95,44 @@ prof_run(const int disable_tls, char *log_level, char *account_name) _connect_default(account_name); ui_update(); - char *line = NULL; - gboolean cmd_result = TRUE; + fd_set fds; + int r; + rl_callback_handler_install(NULL, cb_linehandler); log_info("Starting main event loop"); + struct timeval t; + t.tv_sec = 0; + t.tv_usec = 10000; + while(cmd_result) { - while(!line) { - _check_autoaway(); - line = ui_readline(); -#ifdef HAVE_LIBOTR - otr_poll(); -#endif - notify_remind(); - jabber_process_events(); - ui_update(); + _check_autoaway(); + + FD_ZERO(&fds); + FD_SET(fileno (rl_instream), &fds); + r = select(FD_SETSIZE, &fds, NULL, NULL, &t); + if (r < 0) { + perror ("rltest: select"); + rl_callback_handler_remove(); + break; } - cmd_result = cmd_process_input(line); - ui_input_clear(); - FREE_SET_NULL(line); + + if (FD_ISSET (fileno (rl_instream), &fds)) { + rl_callback_read_char(); + ui_write(rl_line_buffer, rl_point); + } + + +// line = ui_readline(); +#ifdef HAVE_LIBOTR + otr_poll(); +#endif + notify_remind(); + jabber_process_events(); + ui_update(); } + + rl_callback_handler_remove(); } void diff --git a/src/ui/core.c b/src/ui/core.c index e295a3ad..efebdb5e 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -177,6 +177,12 @@ ui_close(void) endwin(); } +void +ui_write(char *line, int offset) +{ + inp_write(line, offset); +} + char* ui_readline(void) { diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index 7b5c33d0..64c65a96 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -131,6 +131,43 @@ inp_win_resize(void) _inp_win_update_virtual(); } +static int +offset_to_col(char *str, int offset) +{ + int i = 0; + int col = 0; + mbstate_t internal; + + while (i != offset && str[i] != '\n') { + gunichar uni = g_utf8_get_char(&str[i]); + size_t ch_len = mbrlen(&str[i], 4, &internal); + i += ch_len; + col++; + if (g_unichar_iswide(uni)) { + col++; + } + } + + return col; +} + +void +inp_write(char *line, int offset) +{ + int col = offset_to_col(line, offset); + + cons_debug("LEN BYTES: %d", strlen(line)); + cons_debug("LEN UTF8 : %d", g_utf8_strlen(line, -1)); + cons_debug("OFFSET : %d", offset); + cons_debug("COL : %d", col); + cons_debug(""); + + werase(inp_win); + waddstr(inp_win, line); + wmove(inp_win, 0, col); + _inp_win_update_virtual(); +} + void inp_non_block(gint timeout) { @@ -174,8 +211,8 @@ inp_read(int *key_type, wint_t *ch) } int col = getcurx(inp_win); - int wcols = getmaxx(stdscr); - key_printable(line, &line_utf8_pos, &col, &pad_start, *ch, wcols); + int maxx = getmaxx(stdscr); + key_printable(line, &line_utf8_pos, &col, &pad_start, *ch, maxx); werase(inp_win); waddstr(inp_win, line); @@ -265,44 +302,9 @@ _handle_edit(int key_type, const wint_t ch) return 1; // CTRL-RIGHT - } else if (line_utf8_pos < utf8_len && _is_ctrl_right(key_type, ch)) { - gchar *curr_ch = g_utf8_offset_to_pointer(line, line_utf8_pos); - gunichar curr_uni = g_utf8_get_char(curr_ch); - - // find next word if in whitespace - while (g_unichar_isspace(curr_uni)) { - col++; - line_utf8_pos++; - curr_ch = g_utf8_find_next_char(curr_ch, NULL); - if (!curr_ch) { - break; - } - curr_uni = g_utf8_get_char(curr_ch); - } - - if (curr_ch) { - while (!g_unichar_isspace(curr_uni)) { - line_utf8_pos++; - col++; - if (g_unichar_iswide(curr_uni)) { - col++; - } - curr_ch = g_utf8_find_next_char(curr_ch, NULL); - if (!curr_ch || line_utf8_pos >= utf8_len) { - break; - } - curr_uni = g_utf8_get_char(curr_ch); - } - } - + } else if (_is_ctrl_right(key_type, ch)) { + key_ctrl_right(line, &line_utf8_pos, &col, &pad_start, wcols); wmove(inp_win, 0, col); - - // if gone off screen to right, jump right (half a screen worth) - if (col > pad_start + wcols) { - pad_start = pad_start + (wcols / 2); - _inp_win_update_virtual(); - } - return 1; // ALT-LEFT diff --git a/src/ui/inputwin.h b/src/ui/inputwin.h index a4de16f0..d27bfef7 100644 --- a/src/ui/inputwin.h +++ b/src/ui/inputwin.h @@ -48,5 +48,6 @@ void inp_non_block(gint); void inp_block(void); void inp_get_password(char *passwd); void inp_history_append(char *inp); +void inp_write(char *line, int offset); #endif diff --git a/src/ui/keyhandlers.c b/src/ui/keyhandlers.c index d7c3c616..0836737b 100644 --- a/src/ui/keyhandlers.c +++ b/src/ui/keyhandlers.c @@ -42,7 +42,7 @@ #include "common.h" void -key_printable(char * const line, int * const line_utf8_pos, int * const col, int * const pad_start, const wint_t ch, const int wcols) +key_printable(char * const line, int * const line_utf8_pos, int * const col, int * const pad_start, const wint_t ch, const int maxx) { int utf8_len = g_utf8_strlen(line, -1); @@ -65,7 +65,7 @@ key_printable(char * const line, int * const line_utf8_pos, int * const col, int free(new_line); gunichar uni = g_utf8_get_char(bytes); - if (*col == (*pad_start + wcols)) { + if (*col == (*pad_start + maxx)) { (*pad_start)++; if (g_unichar_iswide(uni)) { (*pad_start)++; @@ -101,7 +101,7 @@ key_printable(char * const line, int * const line_utf8_pos, int * const col, int (*col)++; } - if (*col - *pad_start > wcols-1) { + if (*col - *pad_start > maxx-1) { (*pad_start)++; if (g_unichar_iswide(uni)) { (*pad_start)++; @@ -112,7 +112,7 @@ key_printable(char * const line, int * const line_utf8_pos, int * const col, int } void -key_ctrl_left(const char * const line, int * const line_utf8_pos, int * const col, int * const pad_start, const int wcols) +key_ctrl_left(const char * const line, int * const line_utf8_pos, int * const col, int * const pad_start, const int maxx) { if (*line_utf8_pos == 0) { return; @@ -120,6 +120,7 @@ key_ctrl_left(const char * const line, int * const line_utf8_pos, int * const co gchar *curr_ch = g_utf8_offset_to_pointer(line, *line_utf8_pos); gunichar curr_uni = g_utf8_get_char(curr_ch); + (*line_utf8_pos)--; (*col)--; if (g_unichar_iswide(curr_uni)) { @@ -145,7 +146,7 @@ key_ctrl_left(const char * const line, int * const line_utf8_pos, int * const co prev_uni = g_utf8_get_char(prev_ch); (*line_utf8_pos)--; (*col)--; - if (g_unichar_iswide(prev_uni)) { + if (g_unichar_iswide(curr_uni)) { (*col)--; } if (g_unichar_isspace(prev_uni)) { @@ -169,3 +170,47 @@ key_ctrl_left(const char * const line, int * const line_utf8_pos, int * const co *pad_start = *col; } } + +void +key_ctrl_right(const char * const line, int * const line_utf8_pos, int * const col, int * const pad_start, const int maxx) +{ + int utf8_len = g_utf8_strlen(line, -1); + if (*line_utf8_pos >= utf8_len) { + return; + } + + gchar *curr_ch = g_utf8_offset_to_pointer(line, *line_utf8_pos); + gunichar curr_uni = g_utf8_get_char(curr_ch); + + // find next word if in whitespace + while (g_unichar_isspace(curr_uni)) { + (*col)++; + (*line_utf8_pos)++; + curr_ch = g_utf8_find_next_char(curr_ch, NULL); + if (!curr_ch) { + break; + } + curr_uni = g_utf8_get_char(curr_ch); + } + + if (curr_ch) { + while (!g_unichar_isspace(curr_uni)) { + (*line_utf8_pos)++; + (*col)++; + if (g_unichar_iswide(curr_uni)) { + (*col)++; + } + curr_ch = g_utf8_find_next_char(curr_ch, NULL); + if (!curr_ch || *line_utf8_pos >= utf8_len) { + break; + } + curr_uni = g_utf8_get_char(curr_ch); + } + } + + // if gone off screen to right, jump right (half a screen worth) +// if (col > pad_start + wcols) { +// pad_start = pad_start + (wcols / 2); +// _inp_win_update_virtual(); +// } +} diff --git a/src/ui/keyhandlers.h b/src/ui/keyhandlers.h index d8153356..62a2c0d6 100644 --- a/src/ui/keyhandlers.h +++ b/src/ui/keyhandlers.h @@ -37,8 +37,9 @@ #include -void key_printable(char * const line, int * const line_utf8_pos, int * const col, int * const pad_start, const wint_t ch, const int wcols); +void key_printable(char * const line, int * const line_utf8_pos, int * const col, int * const pad_start, const wint_t ch, const int maxx); -void key_ctrl_left(const char * const line, int * const line_utf8_pos, int * const col, int * const pad_start, const int wcols); +void key_ctrl_left(const char * const line, int * const line_utf8_pos, int * const col, int * const pad_start, const int maxx); +void key_ctrl_right(const char * const line, int * const line_utf8_pos, int * const col, int * const pad_start, const int maxx); #endif diff --git a/src/ui/ui.h b/src/ui/ui.h index 99e73b4a..23315af9 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -230,6 +230,7 @@ void ui_statusbar_new(const int win); char * ui_readline(void); void ui_input_clear(void); void ui_input_nonblocking(gboolean); +void ui_write(char *line, int offset); void ui_invalid_command_usage(const char * const usage, void (*setting_func)(void)); diff --git a/tests/helpers.c b/tests/helpers.c index 10310886..564b2716 100644 --- a/tests/helpers.c +++ b/tests/helpers.c @@ -85,6 +85,24 @@ void close_chat_sessions(void **state) close_preferences(NULL); } +int +utf8_pos_to_col(char *str, int utf8_pos) +{ + int col = 0; + + int i = 0; + for (i = 0; i #include #include @@ -9,26 +7,15 @@ #include +#include "ui/keyhandlers.h" +#include "ui/inputwin.h" +#include "tests/helpers.h" + static char line[INP_WIN_MAX]; -static int utf8_pos_to_col(char *str, int utf8_pos) -{ - int col = 0; +// append - int i = 0; - for (i = 0; i Date: Wed, 28 Jan 2015 19:50:16 +0000 Subject: [PATCH 010/252] Strip only trailing newline from eval_password --- src/command/commands.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/command/commands.c b/src/command/commands.c index 60ef3780..25314c2e 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -154,7 +154,10 @@ cmd_connect(gchar **args, struct cmd_help_t help) cons_show("Error evaluating password, see logs for details."); return TRUE; } - g_strstrip(account->password); + // strip trailing newline + if (g_str_has_suffix(account->password, "\n")) { + account->password[strlen(account->password)-1] = '\0'; + } } else { log_error("popen failed when running eval_password."); cons_show("Error evaluating password, see logs for details."); From 351ff752a7b11408e62f00cb8b5778a58e8fdda7 Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 28 Jan 2015 20:35:00 +0000 Subject: [PATCH 011/252] Renamed command group presence->presences to avoid clash --- src/command/command.c | 2 +- src/command/commands.c | 2 +- src/config/theme.c | 2 +- src/ui/console.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index 8e16276b..f1926dbb 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -1141,7 +1141,7 @@ cmd_init(void) autocomplete_add(help_ac, "basic"); autocomplete_add(help_ac, "chatting"); autocomplete_add(help_ac, "groupchat"); - autocomplete_add(help_ac, "presence"); + autocomplete_add(help_ac, "presences"); autocomplete_add(help_ac, "contacts"); autocomplete_add(help_ac, "service"); autocomplete_add(help_ac, "settings"); diff --git a/src/command/commands.c b/src/command/commands.c index 25314c2e..2059c982 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -714,7 +714,7 @@ cmd_help(gchar **args, struct cmd_help_t help) "/rooms", "/tiny", "/who", "/nick", "/privileges", "/info", "/occupants" }; _cmd_show_filtered_help("Groupchat commands", filter, ARRAY_SIZE(filter)); - } else if (strcmp(args[0], "presence") == 0) { + } else if (strcmp(args[0], "presences") == 0) { gchar *filter[] = { "/autoaway", "/away", "/chat", "/dnd", "/online", "/priority", "/account", "/status", "/statuses", "/who", "/xa" }; diff --git a/src/config/theme.c b/src/config/theme.c index 6d3c5938..a5dbd0dd 100644 --- a/src/config/theme.c +++ b/src/config/theme.c @@ -592,7 +592,7 @@ theme_attrs(theme_item_t attrs) case THEME_BLACK_BOLD: result = COLOR_PAIR(52); break; case THEME_MAGENTA: result = COLOR_PAIR(53); break; case THEME_MAGENTA_BOLD: result = COLOR_PAIR(53); break; - default: break; + default: break; } if (g_hash_table_lookup(bold_items, GINT_TO_POINTER(attrs))) { diff --git a/src/ui/console.c b/src/ui/console.c index dd50d6d3..cdf5d1b8 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -1402,7 +1402,7 @@ cons_help(void) cons_show("/help basic - List basic commands for getting started."); cons_show("/help chatting - List chat commands."); cons_show("/help groupchat - List groupchat commands."); - cons_show("/help presence - List commands to change presence."); + cons_show("/help presences - List commands to change presence."); cons_show("/help contacts - List commands for manipulating your roster."); cons_show("/help service - List service discovery commands."); cons_show("/help settings - List commands for changing settings."); From 5b26879e3137c833baf393878d955420360b8edb Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 28 Jan 2015 20:59:25 +0000 Subject: [PATCH 012/252] Updated /wrap help --- src/command/command.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/command/command.c b/src/command/command.c index f1926dbb..7be6603d 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -615,7 +615,7 @@ static struct cmd_t command_defs[] = { "/wrap on|off", "Word wrapping.", { "/wrap on|off", "------------", - "Enable or disable word wrapping.", + "Enable or disable word wrapping in the main window.", NULL } } }, { "/time", From 83bd207316037a8086f15f37c0e187a2ffba2e14 Mon Sep 17 00:00:00 2001 From: James Booth Date: Fri, 30 Jan 2015 23:28:02 +0000 Subject: [PATCH 013/252] Moved readline code to inputwin.c --- src/profanity.c | 45 ++----------------- src/ui/core.c | 105 ++++++++++++++++++++++----------------------- src/ui/inputwin.c | 56 +++++++++++++++++++++++- src/ui/inputwin.h | 2 + src/ui/ui.h | 2 +- tests/ui/stub_ui.c | 4 +- 6 files changed, 113 insertions(+), 101 deletions(-) diff --git a/src/profanity.c b/src/profanity.c index c105d33f..f3c53003 100644 --- a/src/profanity.c +++ b/src/profanity.c @@ -43,8 +43,6 @@ #include #include -#include -#include #include "profanity.h" #include "chat_session.h" @@ -73,20 +71,7 @@ static void _create_directories(void); static void _connect_default(const char * const account); static gboolean idle = FALSE; -static void cb_linehandler(char *); -static gboolean cmd_result = TRUE; - -static void -cb_linehandler(char *line) -{ - /* Can use ^D (stty eof) or `exit' to exit. */ - if (*line) { - add_history(line); - } - rl_redisplay(); - cmd_result = cmd_process_input(line); - free(line); -} +static gboolean cont = TRUE; void prof_run(const int disable_tls, char *log_level, char *account_name) @@ -95,35 +80,13 @@ prof_run(const int disable_tls, char *log_level, char *account_name) _connect_default(account_name); ui_update(); - fd_set fds; - int r; - rl_callback_handler_install(NULL, cb_linehandler); - log_info("Starting main event loop"); - struct timeval t; - t.tv_sec = 0; - t.tv_usec = 10000; - - while(cmd_result) { + while(cont) { _check_autoaway(); - FD_ZERO(&fds); - FD_SET(fileno (rl_instream), &fds); - r = select(FD_SETSIZE, &fds, NULL, NULL, &t); - if (r < 0) { - perror ("rltest: select"); - rl_callback_handler_remove(); - break; - } + cont = ui_readline(); - if (FD_ISSET (fileno (rl_instream), &fds)) { - rl_callback_read_char(); - ui_write(rl_line_buffer, rl_point); - } - - -// line = ui_readline(); #ifdef HAVE_LIBOTR otr_poll(); #endif @@ -131,8 +94,6 @@ prof_run(const int disable_tls, char *log_level, char *account_name) jabber_process_events(); ui_update(); } - - rl_callback_handler_remove(); } void diff --git a/src/ui/core.c b/src/ui/core.c index efebdb5e..3520f81d 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -82,7 +82,7 @@ static Display *display; static GTimer *ui_idle_time; -static void _win_handle_switch(const wint_t ch); +//static void _win_handle_switch(const wint_t ch); static void _win_show_history(int win_index, const char * const contact); static void _ui_draw_term_title(void); @@ -174,39 +174,36 @@ ui_close(void) { notifier_uninit(); wins_destroy(); + inp_close(); endwin(); } -void -ui_write(char *line, int offset) -{ - inp_write(line, offset); -} - -char* +gboolean ui_readline(void) { - int key_type; - wint_t ch; + return inp_readline(); - char *line = inp_read(&key_type, &ch); - _win_handle_switch(ch); - - ProfWin *current = wins_get_current(); - win_handle_page(current, ch, key_type); - - if (ch == KEY_RESIZE) { - ui_resize(); - } - - if (ch != ERR && key_type != ERR) { - ui_reset_idle_time(); - ui_input_nonblocking(TRUE); - } else { - ui_input_nonblocking(FALSE); - } - - return line; +// int key_type; +// wint_t ch; +// +// char *line = inp_read(&key_type, &ch); +// _win_handle_switch(ch); +// +// ProfWin *current = wins_get_current(); +// win_handle_page(current, ch, key_type); +// +// if (ch == KEY_RESIZE) { +// ui_resize(); +// } +// +// if (ch != ERR && key_type != ERR) { +// ui_reset_idle_time(); +// ui_input_nonblocking(TRUE); +// } else { +// ui_input_nonblocking(FALSE); +// } +// +// return line; } void @@ -2945,32 +2942,32 @@ ui_hide_roster(void) } } -static void -_win_handle_switch(const wint_t ch) -{ - if (ch == KEY_F(1)) { - ui_switch_win(1); - } else if (ch == KEY_F(2)) { - ui_switch_win(2); - } else if (ch == KEY_F(3)) { - ui_switch_win(3); - } else if (ch == KEY_F(4)) { - ui_switch_win(4); - } else if (ch == KEY_F(5)) { - ui_switch_win(5); - } else if (ch == KEY_F(6)) { - ui_switch_win(6); - } else if (ch == KEY_F(7)) { - ui_switch_win(7); - } else if (ch == KEY_F(8)) { - ui_switch_win(8); - } else if (ch == KEY_F(9)) { - ui_switch_win(9); - } else if (ch == KEY_F(10)) { - ui_switch_win(0); - } -} - +//static void +//_win_handle_switch(const wint_t ch) +//{ +// if (ch == KEY_F(1)) { +// ui_switch_win(1); +// } else if (ch == KEY_F(2)) { +// ui_switch_win(2); +// } else if (ch == KEY_F(3)) { +// ui_switch_win(3); +// } else if (ch == KEY_F(4)) { +// ui_switch_win(4); +// } else if (ch == KEY_F(5)) { +// ui_switch_win(5); +// } else if (ch == KEY_F(6)) { +// ui_switch_win(6); +// } else if (ch == KEY_F(7)) { +// ui_switch_win(7); +// } else if (ch == KEY_F(8)) { +// ui_switch_win(8); +// } else if (ch == KEY_F(9)) { +// ui_switch_win(9); +// } else if (ch == KEY_F(10)) { +// ui_switch_win(0); +// } +//} +// static void _win_show_history(int win_index, const char * const contact) { diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index 64c65a96..4b3ec296 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -39,6 +39,9 @@ #include #include +#include +#include + #ifdef HAVE_NCURSESW_NCURSES_H #include #elif HAVE_NCURSES_H @@ -77,6 +80,11 @@ static WINDOW *inp_win; static History history; +static struct timeval p_rl_timeout; +static fd_set fds; +static int r; +static gboolean cmd_result = TRUE; + // input line static char line[INP_WIN_MAX]; // current position in the utf8 string @@ -95,6 +103,17 @@ static gboolean _is_ctrl_right(int key_type, const wint_t ch); static void _inp_win_update_virtual(void); +static void +cb_linehandler(char *line) +{ + if (*line) { + add_history(line); + } + rl_redisplay(); + cmd_result = cmd_process_input(line); + free(line); +} + void create_input_window(void) { @@ -103,6 +122,10 @@ create_input_window(void) #else ESCDELAY = 25; #endif + p_rl_timeout.tv_sec = 0; + p_rl_timeout.tv_usec = 500000; + rl_callback_handler_install(NULL, cb_linehandler); + inp_win = newpad(1, INP_WIN_MAX); wbkgd(inp_win, theme_attrs(THEME_INPUT_TEXT));; keypad(inp_win, TRUE); @@ -169,9 +192,9 @@ inp_write(char *line, int offset) } void -inp_non_block(gint timeout) +inp_non_block(gint block_timeout) { - wtimeout(inp_win, timeout); + wtimeout(inp_win, block_timeout); } void @@ -180,6 +203,35 @@ inp_block(void) wtimeout(inp_win, -1); } +gboolean +inp_readline(void) +{ + FD_ZERO(&fds); + FD_SET(fileno (rl_instream), &fds); + r = select(FD_SETSIZE, &fds, NULL, NULL, &p_rl_timeout); + if (r < 0) { + log_error("Readline failed."); + rl_callback_handler_remove(); + return false; + } + + if (FD_ISSET (fileno (rl_instream), &fds)) { + rl_callback_read_char(); + inp_write(rl_line_buffer, rl_point); + } + + p_rl_timeout.tv_sec = 0; + p_rl_timeout.tv_usec = 500000; + + return cmd_result; +} + +void +inp_close(void) +{ + rl_callback_handler_remove(); +} + char * inp_read(int *key_type, wint_t *ch) { diff --git a/src/ui/inputwin.h b/src/ui/inputwin.h index d27bfef7..7193e049 100644 --- a/src/ui/inputwin.h +++ b/src/ui/inputwin.h @@ -40,6 +40,8 @@ #define INP_WIN_MAX 1000 void create_input_window(void); +gboolean inp_readline(void); +void inp_close(void); char* inp_read(int *key_type, wint_t *ch); void inp_win_clear(void); void inp_win_resize(void); diff --git a/src/ui/ui.h b/src/ui/ui.h index 23315af9..2cfb6e6e 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -227,7 +227,7 @@ void ui_update_presence(const resource_presence_t resource_presence, void ui_about(void); void ui_statusbar_new(const int win); -char * ui_readline(void); +gboolean ui_readline(void); void ui_input_clear(void); void ui_input_nonblocking(gboolean); void ui_write(char *line, int offset); diff --git a/tests/ui/stub_ui.c b/tests/ui/stub_ui.c index 6b9050c3..6127e4f0 100644 --- a/tests/ui/stub_ui.c +++ b/tests/ui/stub_ui.c @@ -323,9 +323,9 @@ void ui_update_presence(const resource_presence_t resource_presence, void ui_about(void) {} void ui_statusbar_new(const int win) {} -char * ui_readline(void) +gboolean ui_readline(void) { - return NULL; + return TRUE; } void ui_inp_history_append(char *inp) {} From a9ed64911d29819f20fe8cafae87af61b6f53e14 Mon Sep 17 00:00:00 2001 From: James Booth Date: Fri, 30 Jan 2015 23:42:51 +0000 Subject: [PATCH 014/252] Removed history and various key handlers --- Makefile.am | 6 - src/command/command.c | 5 - src/tools/history.c | 283 -------------- src/tools/history.h | 45 --- src/ui/core.c | 6 - src/ui/inputwin.c | 844 ++++++++++-------------------------------- src/ui/keyhandlers.c | 216 ----------- src/ui/keyhandlers.h | 45 --- tests/test_history.c | 219 ----------- tests/test_history.h | 13 - tests/testsuite.c | 66 ---- 11 files changed, 205 insertions(+), 1543 deletions(-) delete mode 100644 src/tools/history.c delete mode 100644 src/tools/history.h delete mode 100644 src/ui/keyhandlers.c delete mode 100644 src/ui/keyhandlers.h delete mode 100644 tests/test_history.c delete mode 100644 tests/test_history.h diff --git a/Makefile.am b/Makefile.am index abd1a1ff..300116b1 100644 --- a/Makefile.am +++ b/Makefile.am @@ -19,7 +19,6 @@ core_sources = \ src/ui/titlebar.h src/ui/statusbar.h src/ui/inputwin.h \ src/ui/console.c src/ui/notifier.c \ src/ui/windows.c src/ui/windows.h \ - src/ui/keyhandlers.c src/ui/keyhandlers.h \ src/ui/rosterwin.c src/ui/occupantswin.c \ src/ui/buffer.c src/ui/buffer.h \ src/command/command.h src/command/command.c \ @@ -28,7 +27,6 @@ core_sources = \ src/tools/parser.h \ src/tools/p_sha1.h src/tools/p_sha1.c \ src/tools/autocomplete.c src/tools/autocomplete.h \ - src/tools/history.c src/tools/history.h \ src/tools/tinyurl.c src/tools/tinyurl.h \ src/config/accounts.c src/config/accounts.h \ src/config/account.c src/config/account.h \ @@ -51,7 +49,6 @@ tests_sources = \ src/tools/parser.h \ src/tools/p_sha1.h src/tools/p_sha1.c \ src/tools/autocomplete.c src/tools/autocomplete.h \ - src/tools/history.c src/tools/history.h \ src/tools/tinyurl.c src/tools/tinyurl.h \ src/config/accounts.h \ src/config/account.c src/config/account.h \ @@ -59,7 +56,6 @@ tests_sources = \ src/config/theme.c src/config/theme.h \ src/ui/windows.c src/ui/windows.h \ src/ui/window.c src/ui/window.h \ - src/ui/keyhandlers.c src/ui/keyhandlers.h \ src/ui/buffer.c \ src/ui/titlebar.c src/ui/statusbar.c src/ui/inputwin.c \ src/ui/titlebar.h src/ui/statusbar.h src/ui/inputwin.h \ @@ -85,7 +81,6 @@ tests_sources = \ tests/test_common.c tests/test_common.h \ tests/test_contact.c tests/test_contact.h \ tests/test_form.c tests/test_form.h \ - tests/test_history.c tests/test_history.h \ tests/test_jid.c tests/test_jid.h \ tests/test_muc.c tests/test_muc.h \ tests/test_parser.c tests/test_parser.h \ @@ -94,7 +89,6 @@ tests_sources = \ tests/test_server_events.c tests/test_server_events.h \ tests/test_autocomplete.c tests/test_autocomplete.h \ tests/test_chat_session.c tests/test_chat_session.h \ - tests/test_keyhandlers.c tests/test_keyhandlers.h \ tests/testsuite.c main_source = src/main.c diff --git a/src/command/command.c b/src/command/command.c index 8e16276b..909c954c 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -1736,11 +1736,6 @@ cmd_process_input(char *inp) gboolean result = FALSE; g_strstrip(inp); - // add line to history if something typed - if (strlen(inp) > 0) { - ui_inp_history_append(inp); - } - // just carry on if no input if (strlen(inp) == 0) { result = TRUE; diff --git a/src/tools/history.c b/src/tools/history.c deleted file mode 100644 index def10feb..00000000 --- a/src/tools/history.c +++ /dev/null @@ -1,283 +0,0 @@ -/* - * history.c - * - * Copyright (C) 2012 - 2014 James Booth - * - * This file is part of Profanity. - * - * Profanity is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Profanity is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Profanity. If not, see . - * - * In addition, as a special exception, the copyright holders give permission to - * link the code of portions of this program with the OpenSSL library under - * certain conditions as described in each individual source file, and - * distribute linked combinations including the two. - * - * You must obey the GNU General Public License in all respects for all of the - * code used other than OpenSSL. If you modify file(s) with this exception, you - * may extend this exception to your version of the file(s), but you are not - * obligated to do so. If you do not wish to do so, delete this exception - * statement from your version. If you delete this exception statement from all - * source files in the program, then also delete it here. - * - */ - -#include -#include - -#include - -#include "history.h" - -struct history_session_t { - GList *items; - GList *sess_curr; - GList *sess_new; - GList *orig_curr; -}; - -struct history_t { - GList *items; - guint max_size; - struct history_session_t session; -}; - -static void _replace_history_with_session(History history); -static gboolean _adding_new(History history); -static void _reset_session(History history); -static gboolean _has_session(History history); -static void _remove_first(History history); -static void _update_current_session_item(History history, char *item); -static void _add_to_history(History history, char *item); -static void _remove_last_session_item(History history); -static void _replace_current_with_original(History history); -static void _create_session(History history); -static void _session_previous(History history); -static void _session_next(History history); - -History -history_new(unsigned int size) -{ - History new_history = malloc(sizeof(struct history_t)); - new_history->items = NULL; - new_history->max_size = size; - - _reset_session(new_history); - - return new_history; -} - -void -history_append(History history, char *item) -{ - char *copied = ""; - if (item != NULL) { - copied = strdup(item); - } - - if (history->items == NULL) { - _add_to_history(history, copied); - return; - } - - if (!_has_session(history)) { - if (g_list_length(history->items) == history->max_size) { - _remove_first(history); - } - - _add_to_history(history, copied); - - } else { - _update_current_session_item(history, copied); - - if (_adding_new(history)) { - if (strcmp(history->session.sess_curr->data, "") == 0) { - _remove_last_session_item(history); - } - - _replace_history_with_session(history); - - } else { - _remove_last_session_item(history); - - char *new = strdup(history->session.sess_curr->data); - history->session.items = g_list_append(history->session.items, new); - - _replace_current_with_original(history); - _replace_history_with_session(history); - } - } -} - -char * -history_previous(History history, char *item) -{ - // no history - if (history->items == NULL) { - return NULL; - } - - char *copied = ""; - if (item != NULL) { - copied = strdup(item); - } - - if (!_has_session(history)) { - _create_session(history); - - // add the new item - history->session.items = g_list_append(history->session.items, copied); - history->session.sess_new = g_list_last(history->session.items); - - char *result = strdup(history->session.sess_curr->data); - return result; - } else { - _update_current_session_item(history, copied); - _session_previous(history); - } - - char *result = strdup(history->session.sess_curr->data); - return result; -} - -char * -history_next(History history, char *item) -{ - // no history, or no session, return NULL - if ((history->items == NULL) || (history->session.items == NULL)) { - return NULL; - } - - if (g_list_next(history->session.sess_curr) == NULL) { - return NULL; - } - - char *copied = ""; - if (item != NULL) { - copied = strdup(item); - } - - _update_current_session_item(history, copied); - _session_next(history); - - char *result = strdup(history->session.sess_curr->data); - return result; -} - -static void -_replace_history_with_session(History history) -{ - g_list_free(history->items); - history->items = g_list_copy(history->session.items); - - if (g_list_length(history->items) > history->max_size) { - _remove_first(history); - } - - _reset_session(history); -} - -static gboolean -_adding_new(History history) -{ - return (history->session.sess_curr == - g_list_last(history->session.items)); -} - -static void -_reset_session(History history) -{ - history->session.items = NULL; - history->session.sess_curr = NULL; - history->session.sess_new = NULL; - history->session.orig_curr = NULL; -} - -static gboolean -_has_session(History history) -{ - return (history->session.items != NULL); -} - -static void -_remove_first(History history) -{ - GList *first = g_list_first(history->items); - char *first_item = first->data; - history->items = g_list_remove(history->items, first_item); -} - -static void -_update_current_session_item(History history, char *item) -{ - history->session.sess_curr->data = item; -} - -static void -_add_to_history(History history, char *item) -{ - history->items = g_list_append(history->items, item); -} - -static void -_remove_last_session_item(History history) -{ - history->session.items = g_list_reverse(history->session.items); - GList *first = g_list_first(history->session.items); - history->session.items = - g_list_remove(history->session.items, first->data); - history->session.items = g_list_reverse(history->session.items); -} - -static void -_replace_current_with_original(History history) -{ - history->session.sess_curr->data = strdup(history->session.orig_curr->data); -} - -static void -_create_session(History history) -{ - history->session.items = g_list_copy(history->items); - history->session.sess_curr = g_list_last(history->session.items); - history->session.orig_curr = g_list_last(history->items); -} - -static void -_session_previous(History history) -{ - history->session.sess_curr = - g_list_previous(history->session.sess_curr); - if (history->session.orig_curr == NULL) - history->session.orig_curr = g_list_last(history->items); - else - history->session.orig_curr = - g_list_previous(history->session.orig_curr); - - if (history->session.sess_curr == NULL) { - history->session.sess_curr = g_list_first(history->session.items); - history->session.orig_curr = g_list_first(history->items); - } -} - -static void -_session_next(History history) -{ - history->session.sess_curr = g_list_next(history->session.sess_curr); - history->session.orig_curr = g_list_next(history->session.orig_curr); - - if (history->session.sess_curr == NULL) { - history->session.sess_curr = g_list_last(history->session.items); - history->session.orig_curr = NULL; - } -} diff --git a/src/tools/history.h b/src/tools/history.h deleted file mode 100644 index 7b334718..00000000 --- a/src/tools/history.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * history.h - * - * Copyright (C) 2012 - 2014 James Booth - * - * This file is part of Profanity. - * - * Profanity is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Profanity is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Profanity. If not, see . - * - * In addition, as a special exception, the copyright holders give permission to - * link the code of portions of this program with the OpenSSL library under - * certain conditions as described in each individual source file, and - * distribute linked combinations including the two. - * - * You must obey the GNU General Public License in all respects for all of the - * code used other than OpenSSL. If you modify file(s) with this exception, you - * may extend this exception to your version of the file(s), but you are not - * obligated to do so. If you do not wish to do so, delete this exception - * statement from your version. If you delete this exception statement from all - * source files in the program, then also delete it here. - * - */ - -#ifndef HISTORY_H -#define HISTORY_H - -typedef struct history_t *History; - -History history_new(unsigned int size); -char * history_previous(History history, char *item); -char * history_next(History history, char *item); -void history_append(History history, char *item); - -#endif diff --git a/src/ui/core.c b/src/ui/core.c index 3520f81d..84a442f2 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -206,12 +206,6 @@ ui_readline(void) // return line; } -void -ui_inp_history_append(char *inp) -{ - inp_history_append(inp); -} - void ui_input_clear(void) { diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index 4b3ec296..d669f67b 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -53,7 +53,6 @@ #include "config/accounts.h" #include "config/preferences.h" #include "config/theme.h" -#include "tools/history.h" #include "log.h" #include "muc.h" #include "profanity.h" @@ -63,7 +62,6 @@ #include "ui/inputwin.h" #include "ui/windows.h" #include "xmpp/xmpp.h" -#include "ui/keyhandlers.h" #define KEY_CTRL_A 0001 #define KEY_CTRL_B 0002 @@ -78,7 +76,6 @@ #define MAX_HISTORY 100 static WINDOW *inp_win; -static History history; static struct timeval p_rl_timeout; static fd_set fds; @@ -92,15 +89,6 @@ static int line_utf8_pos; static int pad_start = 0; -static int _handle_edit(int key_type, const wint_t ch); -static int _handle_alt_key(int key); - -static void _handle_delete_previous_word(void); -static void _handle_backspace(void); - -static gboolean _is_ctrl_left(int key_type, const wint_t ch); -static gboolean _is_ctrl_right(int key_type, const wint_t ch); - static void _inp_win_update_virtual(void); static void @@ -131,7 +119,6 @@ create_input_window(void) keypad(inp_win, TRUE); wmove(inp_win, 0, 0); _inp_win_update_virtual(); - history = history_new(MAX_HISTORY); line_utf8_pos = 0; line[0] = '\0'; } @@ -207,15 +194,14 @@ gboolean inp_readline(void) { FD_ZERO(&fds); - FD_SET(fileno (rl_instream), &fds); + FD_SET(fileno(rl_instream), &fds); r = select(FD_SETSIZE, &fds, NULL, NULL, &p_rl_timeout); if (r < 0) { log_error("Readline failed."); - rl_callback_handler_remove(); return false; } - if (FD_ISSET (fileno (rl_instream), &fds)) { + if (FD_ISSET(fileno(rl_instream), &fds)) { rl_callback_read_char(); inp_write(rl_line_buffer, rl_point); } @@ -232,68 +218,68 @@ inp_close(void) rl_callback_handler_remove(); } -char * -inp_read(int *key_type, wint_t *ch) -{ - // echo off, and get some more input - noecho(); - *key_type = wget_wch(inp_win, ch); - - int bytes_len = strlen(line); - - gboolean in_command = FALSE; - if ((bytes_len > 0 && line[0] == '/') || - (bytes_len == 0 && *ch == '/')) { - in_command = TRUE; - } - - if (*key_type == ERR) { - prof_handle_idle(); - } - if ((*key_type != ERR) && (*key_type != KEY_CODE_YES) && !in_command && utf8_is_printable(*ch)) { - prof_handle_activity(); - } - - // if it wasn't an arrow key etc - if (!_handle_edit(*key_type, *ch)) { - if (utf8_is_printable(*ch) && *key_type != KEY_CODE_YES) { - if (bytes_len >= INP_WIN_MAX) { - *ch = ERR; - return NULL; - } - - int col = getcurx(inp_win); - int maxx = getmaxx(stdscr); - key_printable(line, &line_utf8_pos, &col, &pad_start, *ch, maxx); - - werase(inp_win); - waddstr(inp_win, line); - wmove(inp_win, 0, col); - _inp_win_update_virtual(); - - cmd_reset_autocomplete(); - } - } - - echo(); - - char *result = NULL; - if (*ch == '\n') { - result = strdup(line); - line[0] = '\0'; - line_utf8_pos = 0; - } - - if (*ch != ERR && *key_type != ERR) { - cons_debug("BYTE LEN = %d", strlen(line)); - cons_debug("UTF8 LEN = %d", utf8_display_len(line)); - cons_debug("CURR COL = %d", getcurx(inp_win)); - cons_debug("CURR UNI = %d", line_utf8_pos); - cons_debug(""); - } - - return result; -} +//char * +//inp_read(int *key_type, wint_t *ch) +//{ +// // echo off, and get some more input +// noecho(); +// *key_type = wget_wch(inp_win, ch); +// +// int bytes_len = strlen(line); +// +// gboolean in_command = FALSE; +// if ((bytes_len > 0 && line[0] == '/') || +// (bytes_len == 0 && *ch == '/')) { +// in_command = TRUE; +// } +// +// if (*key_type == ERR) { +// prof_handle_idle(); +// } +// if ((*key_type != ERR) && (*key_type != KEY_CODE_YES) && !in_command && utf8_is_printable(*ch)) { +// prof_handle_activity(); +// } +// +// // if it wasn't an arrow key etc +// if (!_handle_edit(*key_type, *ch)) { +// if (utf8_is_printable(*ch) && *key_type != KEY_CODE_YES) { +// if (bytes_len >= INP_WIN_MAX) { +// *ch = ERR; +// return NULL; +// } +// +// int col = getcurx(inp_win); +// int maxx = getmaxx(stdscr); +// key_printable(line, &line_utf8_pos, &col, &pad_start, *ch, maxx); +// +// werase(inp_win); +// waddstr(inp_win, line); +// wmove(inp_win, 0, col); +// _inp_win_update_virtual(); +// +// cmd_reset_autocomplete(); +// } +// } +// +// echo(); +// +// char *result = NULL; +// if (*ch == '\n') { +// result = strdup(line); +// line[0] = '\0'; +// line_utf8_pos = 0; +// } +// +// if (*ch != ERR && *key_type != ERR) { +// cons_debug("BYTE LEN = %d", strlen(line)); +// cons_debug("UTF8 LEN = %d", utf8_display_len(line)); +// cons_debug("CURR COL = %d", getcurx(inp_win)); +// cons_debug("CURR UNI = %d", line_utf8_pos); +// cons_debug(""); +// } +// +// return result; +//} void inp_get_password(char *passwd) @@ -329,572 +315,152 @@ inp_win_clear(void) _inp_win_update_virtual(); } -void -inp_history_append(char *inp) -{ - history_append(history, inp); -} - /* * Deal with command editing, return 1 if ch was an edit * key press: up, down, left, right or backspace * return 0 if it wasn't */ -static int -_handle_edit(int key_type, const wint_t ch) -{ - int col = getcurx(inp_win); - int utf8_len = g_utf8_strlen(line, -1); - int wcols = getmaxx(stdscr); - - // CTRL-LEFT - if (_is_ctrl_left(key_type, ch)) { - key_ctrl_left(line, &line_utf8_pos, &col, &pad_start, wcols); - wmove(inp_win, 0, col); - return 1; - - // CTRL-RIGHT - } else if (_is_ctrl_right(key_type, ch)) { - key_ctrl_right(line, &line_utf8_pos, &col, &pad_start, wcols); - wmove(inp_win, 0, col); - return 1; - - // ALT-LEFT - } else if ((key_type == KEY_CODE_YES) && (ch == 537 || ch == 542)) { - ui_previous_win(); - return 1; - - // ALT-RIGHT - } else if ((key_type == KEY_CODE_YES) && (ch == 552 || ch == 557)) { - ui_next_win(); - return 1; - - // other editing keys - } else { - int display_len; - int bytes_len = strlen(line); - int next_ch; - - switch(ch) { - - case 27: // ESC - // check for ALT-key - next_ch = wgetch(inp_win); - if (next_ch != ERR) { - return _handle_alt_key(next_ch); - } else { - werase(inp_win); - wmove(inp_win, 0, 0); - pad_start = 0; - line[0] = '\0'; - line_utf8_pos = 0; - _inp_win_update_virtual(); - return 1; - } - - case 127: - _handle_backspace(); - return 1; - case KEY_BACKSPACE: - if (key_type != KEY_CODE_YES) { - return 0; - } - _handle_backspace(); - return 1; - - case KEY_DC: // DEL - if (key_type != KEY_CODE_YES) { - return 0; - } - case KEY_CTRL_D: - if (line_utf8_pos == utf8_len) { - return 1; - } else if (line_utf8_pos == utf8_len-1) { - gchar *curr_ch = g_utf8_offset_to_pointer(line, line_utf8_pos); - int bytes_len_ch = strlen(curr_ch); - bytes_len -= bytes_len_ch; - line[bytes_len] = '\0'; - line_utf8_pos--; - wdelch(inp_win); - - return 1; - } else if (line_utf8_pos < utf8_len-1) { - gchar *start = g_utf8_substring(line, 0, col); - gchar *end = g_utf8_substring(line, col+1, bytes_len); - GString *new = g_string_new(start); - g_string_append(new, end); - - for (bytes_len = 0; bytes_len < strlen(new->str); bytes_len++) { - line[bytes_len] = new->str[bytes_len]; - } - line[bytes_len] = '\0'; - - g_free(start); - g_free(end); - g_string_free(new, FALSE); - - werase(inp_win); - wmove(inp_win, 0, 0); - pad_start = 0; - line[0] = '\0'; - line_utf8_pos = 0; - waddstr(inp_win, line); - wmove(inp_win, 0, col); - } - return 1; - - case KEY_LEFT: - if (key_type != KEY_CODE_YES) { - return 0; - } - case KEY_CTRL_B: - if (line_utf8_pos > 0) { - col--; - gchar *curr_ch = g_utf8_offset_to_pointer(line, line_utf8_pos); - gchar *prev_ch = g_utf8_find_prev_char(line, curr_ch); - if (prev_ch) { - gunichar uni = g_utf8_get_char(prev_ch); - if (g_unichar_iswide(uni)) { - col--; - } - } - wmove(inp_win, 0, col); - line_utf8_pos--; - - // current position off screen to left - if (col < pad_start) { - pad_start--; - _inp_win_update_virtual(); - } - } - return 1; - - case KEY_RIGHT: - if (key_type != KEY_CODE_YES) { - return 0; - } - case KEY_CTRL_F: - if (line_utf8_pos < utf8_len) { - col++; - gchar *curr_ch = g_utf8_offset_to_pointer(line, line_utf8_pos); - if (curr_ch) { - gunichar uni = g_utf8_get_char(curr_ch); - if (g_unichar_iswide(uni)) { - col++; - } - } - wmove(inp_win, 0, col); - line_utf8_pos++; - - // current position off screen to right - int wcols = getmaxx(stdscr); - if ((col - pad_start) >= wcols) { - pad_start++; - _inp_win_update_virtual(); - } - } - return 1; - - case KEY_UP: - if (key_type != KEY_CODE_YES) { - return 0; - } - case KEY_CTRL_P: - line[bytes_len] = '\0'; - char *prev = history_previous(history, line); - if (prev) { - werase(inp_win); - wmove(inp_win, 0, 0); - pad_start = 0; - line[0] = '\0'; - line_utf8_pos = 0; - strncpy(line, prev, INP_WIN_MAX); - waddstr(inp_win, line); - - int display_len = utf8_display_len(line); - wmove(inp_win, 0, display_len); - line_utf8_pos = g_utf8_strlen(line, -1); - - int wcols = getmaxx(stdscr); - if (display_len > wcols-2) { - pad_start = display_len - wcols + 1; - _inp_win_update_virtual(); - } - } - return 1; - - case KEY_DOWN: - if (key_type != KEY_CODE_YES) { - return 0; - } - case KEY_CTRL_N: - line[bytes_len] = '\0'; - char *next = history_next(history, line); - if (next) { - werase(inp_win); - wmove(inp_win, 0, 0); - pad_start = 0; - line[0] = '\0'; - line_utf8_pos = 0; - strncpy(line, next, INP_WIN_MAX); - waddstr(inp_win, line); - - int display_len = utf8_display_len(line); - wmove(inp_win, 0, display_len); - line_utf8_pos = g_utf8_strlen(line, -1); - - int wcols = getmaxx(stdscr); - if (display_len > wcols-2) { - pad_start = display_len - wcols + 1; - _inp_win_update_virtual(); - } - } else if (bytes_len != 0) { - line[bytes_len] = '\0'; - history_append(history, line); - werase(inp_win); - wmove(inp_win, 0, 0); - pad_start = 0; - line[0] = '\0'; - line_utf8_pos = 0; - strncpy(line, "", INP_WIN_MAX); - waddstr(inp_win, line); - - int display_len = utf8_display_len(line); - wmove(inp_win, 0, display_len); - line_utf8_pos = g_utf8_strlen(line, -1); - - int wcols = getmaxx(stdscr); - if (display_len > wcols-2) { - pad_start = display_len - wcols + 1; - _inp_win_update_virtual(); - } - } - return 1; - - case KEY_HOME: - if (key_type != KEY_CODE_YES) { - return 0; - } - case KEY_CTRL_A: - wmove(inp_win, 0, 0); - pad_start = 0; - line_utf8_pos = 0; - _inp_win_update_virtual(); - return 1; - - case KEY_END: - if (key_type != KEY_CODE_YES) { - return 0; - } - case KEY_CTRL_E: - display_len = utf8_display_len(line); - wmove(inp_win, 0, display_len); - line_utf8_pos = g_utf8_strlen(line, -1); - - int wcols = getmaxx(stdscr); - if (display_len > wcols-2) { - pad_start = display_len - wcols + 1; - _inp_win_update_virtual(); - } - return 1; - - case 9: // tab - if (bytes_len != 0) { - line[bytes_len] = '\0'; - if ((strncmp(line, "/", 1) != 0) && (ui_current_win_type() == WIN_MUC)) { - char *result = muc_autocomplete(line); - if (result) { - werase(inp_win); - wmove(inp_win, 0, 0); - pad_start = 0; - line[0] = '\0'; - line_utf8_pos = 0; - strncpy(line, result, INP_WIN_MAX); - waddstr(inp_win, line); - - int display_len = utf8_display_len(line); - wmove(inp_win, 0, display_len); - line_utf8_pos = g_utf8_strlen(line, -1); - - int wcols = getmaxx(stdscr); - if (display_len > wcols-2) { - pad_start = display_len - wcols + 1; - _inp_win_update_virtual(); - } - - free(result); - } - } else if (strncmp(line, "/", 1) == 0) { - char *result = cmd_autocomplete(line); - if (result) { - werase(inp_win); - wmove(inp_win, 0, 0); - pad_start = 0; - line[0] = '\0'; - line_utf8_pos = 0; - strncpy(line, result, INP_WIN_MAX); - waddstr(inp_win, line); - - int display_len = utf8_display_len(line); - wmove(inp_win, 0, display_len); - line_utf8_pos = g_utf8_strlen(line, -1); - - int wcols = getmaxx(stdscr); - if (display_len > wcols-2) { - pad_start = display_len - wcols + 1; - _inp_win_update_virtual(); - } - - free(result); - } - } - } - return 1; - - case KEY_CTRL_W: - _handle_delete_previous_word(); - return 1; - break; - - case KEY_CTRL_U: - while (getcurx(inp_win) > 0) { - _handle_delete_previous_word(); - } - return 1; - break; - - default: - return 0; - } - } -} - -static void -_handle_backspace(void) -{ - int col = getcurx(inp_win); - int utf8_len = g_utf8_strlen(line, -1); - roster_reset_search_attempts(); - - if (utf8_len > 0) { - // if at end, delete last char - if (line_utf8_pos >= utf8_len) { - gchar *new_line = g_utf8_substring(line, 0, utf8_len-1); - werase(inp_win); - wmove(inp_win, 0, 0); - pad_start = 0; - line[0] = '\0'; - line_utf8_pos = 0; - strncpy(line, new_line, INP_WIN_MAX); - waddstr(inp_win, line); - - int display_len = utf8_display_len(line); - wmove(inp_win, 0, display_len); - line_utf8_pos = g_utf8_strlen(line, -1); - - int wcols = getmaxx(stdscr); - if (display_len > wcols-2) { - pad_start = display_len - wcols + 1; - _inp_win_update_virtual(); - } - - // if in middle, delete and shift chars left - } else if (line_utf8_pos > 0 && line_utf8_pos < utf8_len) { - gchar *del_char = g_utf8_offset_to_pointer(line, line_utf8_pos-1); - gunichar uni = g_utf8_get_char(del_char); - - gchar *start = g_utf8_substring(line, 0, line_utf8_pos-1); - gchar *end = g_utf8_substring(line, line_utf8_pos, utf8_len); - GString *new_line = g_string_new(start); - g_string_append(new_line, end); - - int old_pos = line_utf8_pos; - werase(inp_win); - wmove(inp_win, 0, 0); - pad_start = 0; - line[0] = '\0'; - line_utf8_pos = 0; - strncpy(line, new_line->str, INP_WIN_MAX); - waddstr(inp_win, line); - - int display_len = utf8_display_len(line); - wmove(inp_win, 0, display_len); - line_utf8_pos = g_utf8_strlen(line, -1); - - int wcols = getmaxx(stdscr); - if (display_len > wcols-2) { - pad_start = display_len - wcols + 1; - _inp_win_update_virtual(); - } - - line_utf8_pos = old_pos-1; - - g_free(start); - g_free(end); - g_string_free(new_line, TRUE); - - col--; - if (g_unichar_iswide(uni)) { - col--; - } - - wmove(inp_win, 0, col); - } - - // if gone off screen to left, jump left (half a screen worth) - if (col <= pad_start) { - int wcols = getmaxx(stdscr); - pad_start = pad_start - (wcols / 2); - if (pad_start < 0) { - pad_start = 0; - } - - _inp_win_update_virtual(); - } - } - -} - -static int -_handle_alt_key(int key) -{ - switch (key) - { - case '1': - ui_switch_win(1); - break; - case '2': - ui_switch_win(2); - break; - case '3': - ui_switch_win(3); - break; - case '4': - ui_switch_win(4); - break; - case '5': - ui_switch_win(5); - break; - case '6': - ui_switch_win(6); - break; - case '7': - ui_switch_win(7); - break; - case '8': - ui_switch_win(8); - break; - case '9': - ui_switch_win(9); - break; - case '0': - ui_switch_win(0); - break; - case KEY_LEFT: - ui_previous_win(); - break; - case KEY_RIGHT: - ui_next_win(); - break; - case 263: - case 127: - _handle_delete_previous_word(); - break; - default: - break; - } - return 1; -} - -static void -_handle_delete_previous_word(void) -{ - int end_del = getcurx(inp_win); - int start_del = end_del; - - gchar *curr_ch = g_utf8_offset_to_pointer(line, end_del); - curr_ch = g_utf8_find_prev_char(line, curr_ch); - gchar *prev_ch; - gunichar curr_uni; - gunichar prev_uni; - - while (curr_ch != NULL) { - curr_uni = g_utf8_get_char(curr_ch); - - if (g_unichar_isspace(curr_uni)) { - curr_ch = g_utf8_find_prev_char(line, curr_ch); - } else { - prev_ch = g_utf8_find_prev_char(line, curr_ch); - if (prev_ch == NULL) { - curr_ch = NULL; - break; - } else { - prev_uni = g_utf8_get_char(prev_ch); - if (g_unichar_isspace(prev_uni)) { - break; - } else { - curr_ch = prev_ch; - } - } - } - } - - if (curr_ch == NULL) { - start_del = 0; - } else { - start_del = g_utf8_pointer_to_offset(line, curr_ch); - } - - gint len = g_utf8_strlen(line, -1); - gchar *start_string = g_utf8_substring(line, 0, start_del); - gchar *end_string = g_utf8_substring(line, end_del, len); - - int i; - for (i = 0; i < strlen(start_string); i++) { - line[i] = start_string[i]; - } - for (i = 0; i < strlen(end_string); i++) { - line[strlen(start_string)+i] = end_string[i]; - } - - int bytes_len = strlen(start_string)+i; - line[bytes_len] = '\0'; - - werase(inp_win); - wmove(inp_win, 0, 0); - pad_start = 0; - line[0] = '\0'; - line_utf8_pos = 0; - - waddstr(inp_win, line); - wmove(inp_win, 0, start_del); - - // if gone off screen to left, jump left (half a screen worth) - if (start_del <= pad_start) { - int wcols = getmaxx(stdscr); - pad_start = pad_start - (wcols / 2); - if (pad_start < 0) { - pad_start = 0; - } - - _inp_win_update_virtual(); - } -} - -static gboolean -_is_ctrl_left(int key_type, const wint_t ch) -{ - return ((key_type == KEY_CODE_YES) - && (ch == 547 || ch == 545 || ch == 544 || ch == 540 || ch == 539)); -} - -static gboolean -_is_ctrl_right(int key_type, const wint_t ch) -{ - return ((key_type == KEY_CODE_YES) - && (ch == 562 || ch == 560 || ch == 555 || ch == 559 || ch == 554)); -} - +//static int +//_handle_edit(int key_type, const wint_t ch) +//{ +// // ALT-LEFT +// if ((key_type == KEY_CODE_YES) && (ch == 537 || ch == 542)) { +// ui_previous_win(); +// return 1; +// +// // ALT-RIGHT +// } else if ((key_type == KEY_CODE_YES) && (ch == 552 || ch == 557)) { +// ui_next_win(); +// return 1; +// +// // other editing keys +// } else { +// int bytes_len = strlen(line); +// int next_ch; +// +// switch(ch) { +// +// case 27: // ESC +// // check for ALT-key +// next_ch = wgetch(inp_win); +// if (next_ch != ERR) { +// return _handle_alt_key(next_ch); +// } else { +// werase(inp_win); +// wmove(inp_win, 0, 0); +// pad_start = 0; +// line[0] = '\0'; +// line_utf8_pos = 0; +// _inp_win_update_virtual(); +// return 1; +// } +// +// case 9: // tab +// if (bytes_len != 0) { +// line[bytes_len] = '\0'; +// if ((strncmp(line, "/", 1) != 0) && (ui_current_win_type() == WIN_MUC)) { +// char *result = muc_autocomplete(line); +// if (result) { +// werase(inp_win); +// wmove(inp_win, 0, 0); +// pad_start = 0; +// line[0] = '\0'; +// line_utf8_pos = 0; +// strncpy(line, result, INP_WIN_MAX); +// waddstr(inp_win, line); +// +// int display_len = utf8_display_len(line); +// wmove(inp_win, 0, display_len); +// line_utf8_pos = g_utf8_strlen(line, -1); +// +// int wcols = getmaxx(stdscr); +// if (display_len > wcols-2) { +// pad_start = display_len - wcols + 1; +// _inp_win_update_virtual(); +// } +// +// free(result); +// } +// } else if (strncmp(line, "/", 1) == 0) { +// char *result = cmd_autocomplete(line); +// if (result) { +// werase(inp_win); +// wmove(inp_win, 0, 0); +// pad_start = 0; +// line[0] = '\0'; +// line_utf8_pos = 0; +// strncpy(line, result, INP_WIN_MAX); +// waddstr(inp_win, line); +// +// int display_len = utf8_display_len(line); +// wmove(inp_win, 0, display_len); +// line_utf8_pos = g_utf8_strlen(line, -1); +// +// int wcols = getmaxx(stdscr); +// if (display_len > wcols-2) { +// pad_start = display_len - wcols + 1; +// _inp_win_update_virtual(); +// } +// +// free(result); +// } +// } +// } +// return 1; +// +// default: +// return 0; +// } +// } +//} + +//static int +//_handle_alt_key(int key) +//{ +// switch (key) +// { +// case '1': +// ui_switch_win(1); +// break; +// case '2': +// ui_switch_win(2); +// break; +// case '3': +// ui_switch_win(3); +// break; +// case '4': +// ui_switch_win(4); +// break; +// case '5': +// ui_switch_win(5); +// break; +// case '6': +// ui_switch_win(6); +// break; +// case '7': +// ui_switch_win(7); +// break; +// case '8': +// ui_switch_win(8); +// break; +// case '9': +// ui_switch_win(9); +// break; +// case '0': +// ui_switch_win(0); +// break; +// case KEY_LEFT: +// ui_previous_win(); +// break; +// case KEY_RIGHT: +// ui_next_win(); +// break; +// default: +// break; +// } +// return 1; +//} +// static void _inp_win_update_virtual(void) { diff --git a/src/ui/keyhandlers.c b/src/ui/keyhandlers.c deleted file mode 100644 index 0836737b..00000000 --- a/src/ui/keyhandlers.c +++ /dev/null @@ -1,216 +0,0 @@ -/* - * keyhandlers.c - * - * Copyright (C) 2012 - 2014 James Booth - * - * This file is part of Profanity. - * - * Profanity is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Profanity is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Profanity. If not, see . - * - * In addition, as a special exception, the copyright holders give permission to - * link the code of portions of this program with the OpenSSL library under - * certain conditions as described in each individual source file, and - * distribute linked combinations including the two. - * - * You must obey the GNU General Public License in all respects for all of the - * code used other than OpenSSL. If you modify file(s) with this exception, you - * may extend this exception to your version of the file(s), but you are not - * obligated to do so. If you do not wish to do so, delete this exception - * statement from your version. If you delete this exception statement from all - * source files in the program, then also delete it here. - * - */ - -#include -#include -#include - -#include - -#include "ui/inputwin.h" -#include "common.h" - -void -key_printable(char * const line, int * const line_utf8_pos, int * const col, int * const pad_start, const wint_t ch, const int maxx) -{ - int utf8_len = g_utf8_strlen(line, -1); - - // handle insert if not at end of input - if (*line_utf8_pos < utf8_len) { - char bytes[MB_CUR_MAX]; - size_t utf8_ch_len = wcrtomb(bytes, ch, NULL); - bytes[utf8_ch_len] = '\0'; - gchar *start = g_utf8_substring(line, 0, *line_utf8_pos); - gchar *end = g_utf8_substring(line, *line_utf8_pos, utf8_len); - GString *new_line_str = g_string_new(start); - g_string_append(new_line_str, bytes); - g_string_append(new_line_str, end); - char *new_line = new_line_str->str; - g_free(start); - g_free(end); - g_string_free(new_line_str, FALSE); - - strncpy(line, new_line, INP_WIN_MAX); - free(new_line); - - gunichar uni = g_utf8_get_char(bytes); - if (*col == (*pad_start + maxx)) { - (*pad_start)++; - if (g_unichar_iswide(uni)) { - (*pad_start)++; - } - } - - (*line_utf8_pos)++; - - (*col)++; - if (g_unichar_iswide(uni)) { - (*col)++; - } - - // otherwise just append - } else { - char bytes[MB_CUR_MAX+1]; - size_t utf8_ch_len = wcrtomb(bytes, ch, NULL); - if (utf8_ch_len < MB_CUR_MAX) { - int i; - int bytes_len = strlen(line); - - for (i = 0 ; i < utf8_ch_len; i++) { - line[bytes_len++] = bytes[i]; - } - line[bytes_len] = '\0'; - - (*line_utf8_pos)++; - - (*col)++; - bytes[utf8_ch_len] = '\0'; - gunichar uni = g_utf8_get_char(bytes); - if (g_unichar_iswide(uni)) { - (*col)++; - } - - if (*col - *pad_start > maxx-1) { - (*pad_start)++; - if (g_unichar_iswide(uni)) { - (*pad_start)++; - } - } - } - } -} - -void -key_ctrl_left(const char * const line, int * const line_utf8_pos, int * const col, int * const pad_start, const int maxx) -{ - if (*line_utf8_pos == 0) { - return; - } - - gchar *curr_ch = g_utf8_offset_to_pointer(line, *line_utf8_pos); - gunichar curr_uni = g_utf8_get_char(curr_ch); - - (*line_utf8_pos)--; - (*col)--; - if (g_unichar_iswide(curr_uni)) { - (*col)--; - } - - curr_ch = g_utf8_find_prev_char(line, curr_ch); - - gchar *prev_ch; - gunichar prev_uni; - while (curr_ch != NULL) { - curr_uni = g_utf8_get_char(curr_ch); - if (g_unichar_isspace(curr_uni)) { - curr_ch = g_utf8_find_prev_char(line, curr_ch); - (*line_utf8_pos)--; - (*col)--; - } else { - prev_ch = g_utf8_find_prev_char(line, curr_ch); - if (prev_ch == NULL) { - curr_ch = NULL; - break; - } else { - prev_uni = g_utf8_get_char(prev_ch); - (*line_utf8_pos)--; - (*col)--; - if (g_unichar_iswide(curr_uni)) { - (*col)--; - } - if (g_unichar_isspace(prev_uni)) { - break; - } else { - curr_ch = prev_ch; - } - } - } - } - - if (curr_ch == NULL) { - (*col) = 0; - (*line_utf8_pos) = 0; - } else { - (*col)++; - (*line_utf8_pos)++; - } - - if (*col < *pad_start) { - *pad_start = *col; - } -} - -void -key_ctrl_right(const char * const line, int * const line_utf8_pos, int * const col, int * const pad_start, const int maxx) -{ - int utf8_len = g_utf8_strlen(line, -1); - if (*line_utf8_pos >= utf8_len) { - return; - } - - gchar *curr_ch = g_utf8_offset_to_pointer(line, *line_utf8_pos); - gunichar curr_uni = g_utf8_get_char(curr_ch); - - // find next word if in whitespace - while (g_unichar_isspace(curr_uni)) { - (*col)++; - (*line_utf8_pos)++; - curr_ch = g_utf8_find_next_char(curr_ch, NULL); - if (!curr_ch) { - break; - } - curr_uni = g_utf8_get_char(curr_ch); - } - - if (curr_ch) { - while (!g_unichar_isspace(curr_uni)) { - (*line_utf8_pos)++; - (*col)++; - if (g_unichar_iswide(curr_uni)) { - (*col)++; - } - curr_ch = g_utf8_find_next_char(curr_ch, NULL); - if (!curr_ch || *line_utf8_pos >= utf8_len) { - break; - } - curr_uni = g_utf8_get_char(curr_ch); - } - } - - // if gone off screen to right, jump right (half a screen worth) -// if (col > pad_start + wcols) { -// pad_start = pad_start + (wcols / 2); -// _inp_win_update_virtual(); -// } -} diff --git a/src/ui/keyhandlers.h b/src/ui/keyhandlers.h deleted file mode 100644 index 62a2c0d6..00000000 --- a/src/ui/keyhandlers.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * keyhandlers.c - * - * Copyright (C) 2012 - 2014 James Booth - * - * This file is part of Profanity. - * - * Profanity is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Profanity is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Profanity. If not, see . - * - * In addition, as a special exception, the copyright holders give permission to - * link the code of portions of this program with the OpenSSL library under - * certain conditions as described in each individual source file, and - * distribute linked combinations including the two. - * - * You must obey the GNU General Public License in all respects for all of the - * code used other than OpenSSL. If you modify file(s) with this exception, you - * may extend this exception to your version of the file(s), but you are not - * obligated to do so. If you do not wish to do so, delete this exception - * statement from your version. If you delete this exception statement from all - * source files in the program, then also delete it here. - * - */ - -#ifndef UI_KEYHANDLERS_H -#define UI_KEYHANDLERS_H - -#include - -void key_printable(char * const line, int * const line_utf8_pos, int * const col, int * const pad_start, const wint_t ch, const int maxx); - -void key_ctrl_left(const char * const line, int * const line_utf8_pos, int * const col, int * const pad_start, const int maxx); -void key_ctrl_right(const char * const line, int * const line_utf8_pos, int * const col, int * const pad_start, const int maxx); - -#endif diff --git a/tests/test_history.c b/tests/test_history.c deleted file mode 100644 index 1584b390..00000000 --- a/tests/test_history.c +++ /dev/null @@ -1,219 +0,0 @@ -#include -#include -#include -#include -#include - -#include "tools/history.h" - -void previous_on_empty_returns_null(void **state) -{ - History history = history_new(10); - char *item = history_previous(history, "inp"); - - assert_null(item); -} - -void next_on_empty_returns_null(void **state) -{ - History history = history_new(10); - char *item = history_next(history, "inp"); - - assert_null(item); -} - -void previous_once_returns_last(void **state) -{ - History history = history_new(10); - history_append(history, "Hello"); - - char *item = history_previous(history, "inp"); - - assert_string_equal("Hello", item); -} - -void previous_twice_when_one_returns_first(void **state) -{ - History history = history_new(10); - history_append(history, "Hello"); - - char *item1 = history_previous(history, NULL); - char *item2 = history_previous(history, item1); - - assert_string_equal("Hello", item2); -} - -void previous_always_stops_at_first(void **state) -{ - History history = history_new(10); - history_append(history, "Hello"); - - char *item1 = history_previous(history, NULL); - char *item2 = history_previous(history, item1); - char *item3 = history_previous(history, item2); - char *item4 = history_previous(history, item3); - char *item5 = history_previous(history, item4); - char *item6 = history_previous(history, item5); - - assert_string_equal("Hello", item6); -} - -void previous_goes_to_correct_element(void **state) -{ - History history = history_new(10); - history_append(history, "Hello"); - history_append(history, "world"); - history_append(history, "whats"); - history_append(history, "going"); - history_append(history, "on"); - history_append(history, "here"); - - char *item1 = history_previous(history, NULL); - char *item2 = history_previous(history, item1); - char *item3 = history_previous(history, item2); - - assert_string_equal("going", item3); -} - -void prev_then_next_returns_empty(void **state) -{ - History history = history_new(10); - history_append(history, "Hello"); - - char *item1 = history_previous(history, NULL); - char *item2 = history_next(history, item1); - - assert_string_equal("", item2); -} - -void prev_with_val_then_next_returns_val(void **state) -{ - History history = history_new(10); - history_append(history, "Hello"); - - char *item1 = history_previous(history, "Oioi"); - char *item2 = history_next(history, item1); - - assert_string_equal("Oioi", item2); -} - -void prev_with_val_then_next_twice_returns_null(void **state) -{ - History history = history_new(10); - history_append(history, "Hello"); - - char *item1 = history_previous(history, "Oioi"); - char *item2 = history_next(history, item1); - char *item3 = history_next(history, item2); - - assert_null(item3); -} - -void navigate_then_append_new(void **state) -{ - History history = history_new(10); - history_append(history, "Hello"); - history_append(history, "again"); - history_append(history, "testing"); - history_append(history, "history"); - history_append(history, "append"); - - char *item1 = history_previous(history, "new text"); - assert_string_equal("append", item1); - - char *item2 = history_previous(history, item1); - assert_string_equal("history", item2); - - char *item3 = history_previous(history, item2); - assert_string_equal("testing", item3); - - char *item4 = history_next(history, item3); - assert_string_equal("history", item4); - - char *item5 = history_next(history, item4); - assert_string_equal("append", item5); - - char *item6 = history_next(history, item5); - assert_string_equal("new text", item6); -} - -void edit_item_mid_history(void **state) -{ - History history = history_new(10); - history_append(history, "Hello"); - history_append(history, "again"); - history_append(history, "testing"); - history_append(history, "history"); - history_append(history, "append"); - - char *item1 = history_previous(history, "new item"); - assert_string_equal("append", item1); - - char *item2 = history_previous(history, item1); - assert_string_equal("history", item2); - - char *item3 = history_previous(history, item2); - assert_string_equal("testing", item3); - - char *item4 = history_previous(history, "EDITED"); - assert_string_equal("again", item4); - - char *item5 = history_previous(history, item4); - assert_string_equal("Hello", item5); - - char *item6 = history_next(history, item5); - assert_string_equal("again", item6); - - char *item7 = history_next(history, item6); - assert_string_equal("EDITED", item7); - - char *item8 = history_next(history, item7); - assert_string_equal("history", item8); - - char *item9 = history_next(history, item8); - assert_string_equal("append", item9); - - char *item10 = history_next(history, item9); - assert_string_equal("new item", item10); -} - -void edit_previous_and_append(void **state) -{ - History history = history_new(10); - history_append(history, "Hello"); - history_append(history, "again"); - history_append(history, "testing"); - history_append(history, "history"); - history_append(history, "append"); - - char *item1 = history_previous(history, "new item"); - assert_string_equal("append", item1); - - char *item2 = history_previous(history, item1); - assert_string_equal("history", item2); - - char *item3 = history_previous(history, item2); - assert_string_equal("testing", item3); - - history_append(history, "EDITED"); - - char *item4 = history_previous(history, NULL); - assert_string_equal("EDITED", item4); -} - -void start_session_add_new_submit_previous(void **state) -{ - History history = history_new(10); - history_append(history, "hello"); - - char *item1 = history_previous(history, NULL); - assert_string_equal("hello", item1); - - char *item2 = history_next(history, item1); - assert_string_equal("", item2); - - char *item3 = history_previous(history, "new text"); - assert_string_equal("hello", item3); - - history_append(history, item3); -} diff --git a/tests/test_history.h b/tests/test_history.h deleted file mode 100644 index e6e8ec3f..00000000 --- a/tests/test_history.h +++ /dev/null @@ -1,13 +0,0 @@ -void previous_on_empty_returns_null(void **state); -void next_on_empty_returns_null(void **state); -void previous_once_returns_last(void **state); -void previous_twice_when_one_returns_first(void **state); -void previous_always_stops_at_first(void **state); -void previous_goes_to_correct_element(void **state); -void prev_then_next_returns_empty(void **state); -void prev_with_val_then_next_returns_val(void **state); -void prev_with_val_then_next_twice_returns_null(void **state); -void navigate_then_append_new(void **state); -void edit_item_mid_history(void **state); -void edit_previous_and_append(void **state); -void start_session_add_new_submit_previous(void **state); diff --git a/tests/testsuite.c b/tests/testsuite.c index ca53961f..92abee4b 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -21,7 +21,6 @@ #include "test_cmd_sub.h" #include "test_cmd_statuses.h" #include "test_cmd_otr.h" -#include "test_history.h" #include "test_jid.h" #include "test_parser.h" #include "test_roster_list.h" @@ -35,7 +34,6 @@ #include "test_cmd_win.h" #include "test_cmd_disconnect.h" #include "test_form.h" -#include "test_keyhandlers.h" int main(int argc, char* argv[]) { const UnitTest all_tests[] = { @@ -104,20 +102,6 @@ int main(int argc, char* argv[]) { unit_test(add_two_same_adds_one), unit_test(add_two_same_updates), - unit_test(previous_on_empty_returns_null), - unit_test(next_on_empty_returns_null), - unit_test(previous_once_returns_last), - unit_test(previous_twice_when_one_returns_first), - unit_test(previous_always_stops_at_first), - unit_test(previous_goes_to_correct_element), - unit_test(prev_then_next_returns_empty), - unit_test(prev_with_val_then_next_returns_val), - unit_test(prev_with_val_then_next_twice_returns_null), - unit_test(navigate_then_append_new), - unit_test(edit_item_mid_history), - unit_test(edit_previous_and_append), - unit_test(start_session_add_new_submit_previous), - unit_test(create_jid_from_null_returns_null), unit_test(create_jid_from_empty_string_returns_null), unit_test(create_jid_from_full_returns_full), @@ -623,56 +607,6 @@ int main(int argc, char* argv[]) { unit_test(remove_text_multi_value_removes_when_many), unit_test(clears_chat_sessions), - - unit_test(append_to_empty), - unit_test(append_wide_to_empty), - - unit_test(append_to_single), - unit_test(append_wide_to_single_non_wide), - unit_test(append_non_wide_to_single_wide), - unit_test(append_wide_to_single_wide), - - unit_test(append_non_wide_when_overrun), - - unit_test(insert_non_wide_to_non_wide), - unit_test(insert_single_non_wide_when_pad_scrolled), - unit_test(insert_many_non_wide_when_pad_scrolled), - unit_test(insert_single_non_wide_last_column), - unit_test(insert_many_non_wide_last_column), - - unit_test(ctrl_left_when_no_input), - unit_test(ctrl_left_when_at_start), - unit_test(ctrl_left_when_in_first_word), - unit_test(ctrl_left_when_in_first_space), - unit_test(ctrl_left_when_at_start_of_second_word), - unit_test(ctrl_left_when_in_second_word), - unit_test(ctrl_left_when_at_end_of_second_word), - unit_test(ctrl_left_when_in_second_space), - unit_test(ctrl_left_when_at_start_of_third_word), - unit_test(ctrl_left_when_in_third_word), - unit_test(ctrl_left_when_at_end_of_third_word), - unit_test(ctrl_left_when_in_third_space), - unit_test(ctrl_left_when_at_end), - unit_test(ctrl_left_when_in_only_whitespace), - unit_test(ctrl_left_when_start_whitespace_start_of_word), - unit_test(ctrl_left_when_start_whitespace_middle_of_word), - unit_test(ctrl_left_in_whitespace_between_words), - unit_test(ctrl_left_in_whitespace_between_words_start_of_word), - unit_test(ctrl_left_in_whitespace_between_words_middle_of_word), - unit_test(ctrl_left_when_word_overrun_to_left), - - unit_test(ctrl_right_when_no_input), - unit_test(ctrl_right_when_at_end), - unit_test(ctrl_right_one_word_at_start), - unit_test(ctrl_right_one_word_in_middle), - unit_test(ctrl_right_one_word_at_end), - unit_test(ctrl_right_two_words_from_middle_first), - unit_test(ctrl_right_two_words_from_end_first), - unit_test(ctrl_right_two_words_from_space), - unit_test(ctrl_right_two_words_from_start_second), - unit_test(ctrl_right_one_word_leading_whitespace), - unit_test(ctrl_right_two_words_in_whitespace), - unit_test(ctrl_right_trailing_whitespace_from_middle), }; return run_tests(all_tests); From 784a2ea862fb824a6f76191591590689fc704ac8 Mon Sep 17 00:00:00 2001 From: James Booth Date: Fri, 30 Jan 2015 23:44:17 +0000 Subject: [PATCH 015/252] Removed commented code --- src/ui/inputwin.c | 216 ---------------------------------------------- 1 file changed, 216 deletions(-) diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index d669f67b..501ae95f 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -165,13 +165,6 @@ void inp_write(char *line, int offset) { int col = offset_to_col(line, offset); - - cons_debug("LEN BYTES: %d", strlen(line)); - cons_debug("LEN UTF8 : %d", g_utf8_strlen(line, -1)); - cons_debug("OFFSET : %d", offset); - cons_debug("COL : %d", col); - cons_debug(""); - werase(inp_win); waddstr(inp_win, line); wmove(inp_win, 0, col); @@ -218,69 +211,6 @@ inp_close(void) rl_callback_handler_remove(); } -//char * -//inp_read(int *key_type, wint_t *ch) -//{ -// // echo off, and get some more input -// noecho(); -// *key_type = wget_wch(inp_win, ch); -// -// int bytes_len = strlen(line); -// -// gboolean in_command = FALSE; -// if ((bytes_len > 0 && line[0] == '/') || -// (bytes_len == 0 && *ch == '/')) { -// in_command = TRUE; -// } -// -// if (*key_type == ERR) { -// prof_handle_idle(); -// } -// if ((*key_type != ERR) && (*key_type != KEY_CODE_YES) && !in_command && utf8_is_printable(*ch)) { -// prof_handle_activity(); -// } -// -// // if it wasn't an arrow key etc -// if (!_handle_edit(*key_type, *ch)) { -// if (utf8_is_printable(*ch) && *key_type != KEY_CODE_YES) { -// if (bytes_len >= INP_WIN_MAX) { -// *ch = ERR; -// return NULL; -// } -// -// int col = getcurx(inp_win); -// int maxx = getmaxx(stdscr); -// key_printable(line, &line_utf8_pos, &col, &pad_start, *ch, maxx); -// -// werase(inp_win); -// waddstr(inp_win, line); -// wmove(inp_win, 0, col); -// _inp_win_update_virtual(); -// -// cmd_reset_autocomplete(); -// } -// } -// -// echo(); -// -// char *result = NULL; -// if (*ch == '\n') { -// result = strdup(line); -// line[0] = '\0'; -// line_utf8_pos = 0; -// } -// -// if (*ch != ERR && *key_type != ERR) { -// cons_debug("BYTE LEN = %d", strlen(line)); -// cons_debug("UTF8 LEN = %d", utf8_display_len(line)); -// cons_debug("CURR COL = %d", getcurx(inp_win)); -// cons_debug("CURR UNI = %d", line_utf8_pos); -// cons_debug(""); -// } -// -// return result; -//} - void inp_get_password(char *passwd) { @@ -315,152 +245,6 @@ inp_win_clear(void) _inp_win_update_virtual(); } -/* - * Deal with command editing, return 1 if ch was an edit - * key press: up, down, left, right or backspace - * return 0 if it wasn't - */ -//static int -//_handle_edit(int key_type, const wint_t ch) -//{ -// // ALT-LEFT -// if ((key_type == KEY_CODE_YES) && (ch == 537 || ch == 542)) { -// ui_previous_win(); -// return 1; -// -// // ALT-RIGHT -// } else if ((key_type == KEY_CODE_YES) && (ch == 552 || ch == 557)) { -// ui_next_win(); -// return 1; -// -// // other editing keys -// } else { -// int bytes_len = strlen(line); -// int next_ch; -// -// switch(ch) { -// -// case 27: // ESC -// // check for ALT-key -// next_ch = wgetch(inp_win); -// if (next_ch != ERR) { -// return _handle_alt_key(next_ch); -// } else { -// werase(inp_win); -// wmove(inp_win, 0, 0); -// pad_start = 0; -// line[0] = '\0'; -// line_utf8_pos = 0; -// _inp_win_update_virtual(); -// return 1; -// } -// -// case 9: // tab -// if (bytes_len != 0) { -// line[bytes_len] = '\0'; -// if ((strncmp(line, "/", 1) != 0) && (ui_current_win_type() == WIN_MUC)) { -// char *result = muc_autocomplete(line); -// if (result) { -// werase(inp_win); -// wmove(inp_win, 0, 0); -// pad_start = 0; -// line[0] = '\0'; -// line_utf8_pos = 0; -// strncpy(line, result, INP_WIN_MAX); -// waddstr(inp_win, line); -// -// int display_len = utf8_display_len(line); -// wmove(inp_win, 0, display_len); -// line_utf8_pos = g_utf8_strlen(line, -1); -// -// int wcols = getmaxx(stdscr); -// if (display_len > wcols-2) { -// pad_start = display_len - wcols + 1; -// _inp_win_update_virtual(); -// } -// -// free(result); -// } -// } else if (strncmp(line, "/", 1) == 0) { -// char *result = cmd_autocomplete(line); -// if (result) { -// werase(inp_win); -// wmove(inp_win, 0, 0); -// pad_start = 0; -// line[0] = '\0'; -// line_utf8_pos = 0; -// strncpy(line, result, INP_WIN_MAX); -// waddstr(inp_win, line); -// -// int display_len = utf8_display_len(line); -// wmove(inp_win, 0, display_len); -// line_utf8_pos = g_utf8_strlen(line, -1); -// -// int wcols = getmaxx(stdscr); -// if (display_len > wcols-2) { -// pad_start = display_len - wcols + 1; -// _inp_win_update_virtual(); -// } -// -// free(result); -// } -// } -// } -// return 1; -// -// default: -// return 0; -// } -// } -//} - -//static int -//_handle_alt_key(int key) -//{ -// switch (key) -// { -// case '1': -// ui_switch_win(1); -// break; -// case '2': -// ui_switch_win(2); -// break; -// case '3': -// ui_switch_win(3); -// break; -// case '4': -// ui_switch_win(4); -// break; -// case '5': -// ui_switch_win(5); -// break; -// case '6': -// ui_switch_win(6); -// break; -// case '7': -// ui_switch_win(7); -// break; -// case '8': -// ui_switch_win(8); -// break; -// case '9': -// ui_switch_win(9); -// break; -// case '0': -// ui_switch_win(0); -// break; -// case KEY_LEFT: -// ui_previous_win(); -// break; -// case KEY_RIGHT: -// ui_next_win(); -// break; -// default: -// break; -// } -// return 1; -//} -// static void _inp_win_update_virtual(void) { From 1cf5592b1fd59b4a9277a5c969403f717d50a7cc Mon Sep 17 00:00:00 2001 From: James Booth Date: Fri, 30 Jan 2015 23:46:34 +0000 Subject: [PATCH 016/252] Removed unused variables --- src/ui/inputwin.c | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index 501ae95f..55bf8912 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -63,18 +63,6 @@ #include "ui/windows.h" #include "xmpp/xmpp.h" -#define KEY_CTRL_A 0001 -#define KEY_CTRL_B 0002 -#define KEY_CTRL_D 0004 -#define KEY_CTRL_E 0005 -#define KEY_CTRL_F 0006 -#define KEY_CTRL_N 0016 -#define KEY_CTRL_P 0020 -#define KEY_CTRL_U 0025 -#define KEY_CTRL_W 0027 - -#define MAX_HISTORY 100 - static WINDOW *inp_win; static struct timeval p_rl_timeout; @@ -82,11 +70,6 @@ static fd_set fds; static int r; static gboolean cmd_result = TRUE; -// input line -static char line[INP_WIN_MAX]; -// current position in the utf8 string -static int line_utf8_pos; - static int pad_start = 0; static void _inp_win_update_virtual(void); @@ -119,8 +102,6 @@ create_input_window(void) keypad(inp_win, TRUE); wmove(inp_win, 0, 0); _inp_win_update_virtual(); - line_utf8_pos = 0; - line[0] = '\0'; } void @@ -217,8 +198,6 @@ inp_get_password(char *passwd) werase(inp_win); wmove(inp_win, 0, 0); pad_start = 0; - line[0] = '\0'; - line_utf8_pos = 0; _inp_win_update_virtual(); doupdate(); noecho(); @@ -240,8 +219,6 @@ inp_win_clear(void) werase(inp_win); wmove(inp_win, 0, 0); pad_start = 0; - line[0] = '\0'; - line_utf8_pos = 0; _inp_win_update_virtual(); } From f94b6ef0a213df2834ceece34036cf4c4990ba9a Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 31 Jan 2015 00:20:25 +0000 Subject: [PATCH 017/252] Added idle and activity handlers --- src/profanity.c | 2 ++ src/ui/inputwin.c | 25 +++++++++++++++---------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/profanity.c b/src/profanity.c index f3c53003..cb3ce4eb 100644 --- a/src/profanity.c +++ b/src/profanity.c @@ -99,6 +99,7 @@ prof_run(const int disable_tls, char *log_level, char *account_name) void prof_handle_idle(void) { + cons_debug("IDLE"); jabber_conn_status_t status = jabber_get_connection_status(); if (status == JABBER_CONNECTED) { GSList *recipients = ui_get_chat_recipients(); @@ -120,6 +121,7 @@ prof_handle_idle(void) void prof_handle_activity(void) { + cons_debug("ACTIVITY"); win_type_t win_type = ui_current_win_type(); jabber_conn_status_t status = jabber_get_connection_status(); diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index 55bf8912..b736fca3 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -142,16 +142,6 @@ offset_to_col(char *str, int offset) return col; } -void -inp_write(char *line, int offset) -{ - int col = offset_to_col(line, offset); - werase(inp_win); - waddstr(inp_win, line); - wmove(inp_win, 0, col); - _inp_win_update_virtual(); -} - void inp_non_block(gint block_timeout) { @@ -164,6 +154,16 @@ inp_block(void) wtimeout(inp_win, -1); } +void +inp_write(char *line, int offset) +{ + int col = offset_to_col(line, offset); + werase(inp_win); + waddstr(inp_win, line); + wmove(inp_win, 0, col); + _inp_win_update_virtual(); +} + gboolean inp_readline(void) { @@ -177,7 +177,12 @@ inp_readline(void) if (FD_ISSET(fileno(rl_instream), &fds)) { rl_callback_read_char(); + if (rl_line_buffer && rl_line_buffer[0] != '/') { + prof_handle_activity(); + } inp_write(rl_line_buffer, rl_point); + } else { + prof_handle_idle(); } p_rl_timeout.tv_sec = 0; From e161337b7f41be415f9e66ae8596268593f5c319 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 31 Jan 2015 00:31:08 +0000 Subject: [PATCH 018/252] Debug input block --- src/ui/core.c | 1 + src/ui/inputwin.c | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/ui/core.c b/src/ui/core.c index 84a442f2..e7477e57 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -240,6 +240,7 @@ ui_input_nonblocking(gboolean reset) } } + log_info("TIMEOUT: %d", timeout); inp_non_block(timeout); } diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index b736fca3..929f85fb 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -66,6 +66,7 @@ static WINDOW *inp_win; static struct timeval p_rl_timeout; +static int timeout_millis = 0; static fd_set fds; static int r; static gboolean cmd_result = TRUE; @@ -94,7 +95,7 @@ create_input_window(void) ESCDELAY = 25; #endif p_rl_timeout.tv_sec = 0; - p_rl_timeout.tv_usec = 500000; + p_rl_timeout.tv_usec = timeout_millis * 1000; rl_callback_handler_install(NULL, cb_linehandler); inp_win = newpad(1, INP_WIN_MAX); @@ -145,7 +146,7 @@ offset_to_col(char *str, int offset) void inp_non_block(gint block_timeout) { - wtimeout(inp_win, block_timeout); + timeout_millis = block_timeout; } void @@ -186,7 +187,7 @@ inp_readline(void) } p_rl_timeout.tv_sec = 0; - p_rl_timeout.tv_usec = 500000; + p_rl_timeout.tv_usec = timeout_millis * 1000; return cmd_result; } From b3448eb265c7b656c07d3a72ea498dc6b5c5b888 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 31 Jan 2015 01:11:41 +0000 Subject: [PATCH 019/252] Moved input blocking code to inputwin.c --- src/profanity.c | 2 -- src/ui/core.c | 31 +++---------------------------- src/ui/inputwin.c | 35 ++++++++++++++++++++++++++++++----- src/ui/inputwin.h | 1 + 4 files changed, 34 insertions(+), 35 deletions(-) diff --git a/src/profanity.c b/src/profanity.c index cb3ce4eb..f3c53003 100644 --- a/src/profanity.c +++ b/src/profanity.c @@ -99,7 +99,6 @@ prof_run(const int disable_tls, char *log_level, char *account_name) void prof_handle_idle(void) { - cons_debug("IDLE"); jabber_conn_status_t status = jabber_get_connection_status(); if (status == JABBER_CONNECTED) { GSList *recipients = ui_get_chat_recipients(); @@ -121,7 +120,6 @@ prof_handle_idle(void) void prof_handle_activity(void) { - cons_debug("ACTIVITY"); win_type_t win_type = ui_current_win_type(); jabber_conn_status_t status = jabber_get_connection_status(); diff --git a/src/ui/core.c b/src/ui/core.c index e7477e57..ed21b233 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -215,33 +215,7 @@ ui_input_clear(void) void ui_input_nonblocking(gboolean reset) { - static gint timeout = 0; - static gint no_input_count = 0; - - if (! prefs_get_boolean(PREF_INPBLOCK_DYNAMIC)) { - inp_non_block(prefs_get_inpblock()); - return; - } - - if (reset) { - timeout = 0; - no_input_count = 0; - } - - if (timeout < prefs_get_inpblock()) { - no_input_count++; - - if (no_input_count % 10 == 0) { - timeout += no_input_count; - - if (timeout > prefs_get_inpblock()) { - timeout = prefs_get_inpblock(); - } - } - } - - log_info("TIMEOUT: %d", timeout); - inp_non_block(timeout); + inp_nonblocking(reset); } void @@ -2250,7 +2224,8 @@ ui_ask_password(void) status_bar_update_virtual(); inp_block(); inp_get_password(passwd); - inp_non_block(prefs_get_inpblock()); +// inp_non_block(prefs_get_inpblock()); + inp_nonblocking(TRUE); return passwd; } diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index 929f85fb..fe75bc61 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -66,7 +66,9 @@ static WINDOW *inp_win; static struct timeval p_rl_timeout; -static int timeout_millis = 0; +static gint inp_timeout = 0; +static gint no_input_count = 0; + static fd_set fds; static int r; static gboolean cmd_result = TRUE; @@ -95,7 +97,7 @@ create_input_window(void) ESCDELAY = 25; #endif p_rl_timeout.tv_sec = 0; - p_rl_timeout.tv_usec = timeout_millis * 1000; + p_rl_timeout.tv_usec = inp_timeout * 1000; rl_callback_handler_install(NULL, cb_linehandler); inp_win = newpad(1, INP_WIN_MAX); @@ -144,9 +146,29 @@ offset_to_col(char *str, int offset) } void -inp_non_block(gint block_timeout) +inp_nonblocking(gboolean reset) { - timeout_millis = block_timeout; + if (! prefs_get_boolean(PREF_INPBLOCK_DYNAMIC)) { + inp_timeout = prefs_get_inpblock(); + return; + } + + if (reset) { + inp_timeout = 0; + no_input_count = 0; + } + + if (inp_timeout < prefs_get_inpblock()) { + no_input_count++; + + if (no_input_count % 10 == 0) { + inp_timeout += no_input_count; + + if (inp_timeout > prefs_get_inpblock()) { + inp_timeout = prefs_get_inpblock(); + } + } + } } void @@ -181,13 +203,16 @@ inp_readline(void) if (rl_line_buffer && rl_line_buffer[0] != '/') { prof_handle_activity(); } + ui_reset_idle_time(); + inp_nonblocking(TRUE); inp_write(rl_line_buffer, rl_point); } else { + inp_nonblocking(FALSE); prof_handle_idle(); } p_rl_timeout.tv_sec = 0; - p_rl_timeout.tv_usec = timeout_millis * 1000; + p_rl_timeout.tv_usec = inp_timeout * 1000; return cmd_result; } diff --git a/src/ui/inputwin.h b/src/ui/inputwin.h index 7193e049..081fc56b 100644 --- a/src/ui/inputwin.h +++ b/src/ui/inputwin.h @@ -41,6 +41,7 @@ void create_input_window(void); gboolean inp_readline(void); +void inp_nonblocking(gboolean reset); void inp_close(void); char* inp_read(int *key_type, wint_t *ch); void inp_win_clear(void); From 2b11baa564e9b558cfc050b5f28505f37900f2c1 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 31 Jan 2015 01:58:15 +0000 Subject: [PATCH 020/252] Added readline tab handler --- src/ui/inputwin.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index fe75bc61..649590bc 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -88,6 +88,32 @@ cb_linehandler(char *line) free(line); } +int +tab_handler(int count, int key) +{ + if (rl_point != rl_end) { + return 0; + } + + if ((strncmp(rl_line_buffer, "/", 1) != 0) && (ui_current_win_type() == WIN_MUC)) { + char *result = muc_autocomplete(rl_line_buffer); + if (result) { + rl_replace_line(result, 0); + rl_point = rl_end; + inp_write(result, rl_point); + } + } else if (strncmp(rl_line_buffer, "/", 1) == 0) { + char *result = cmd_autocomplete(rl_line_buffer); + if (result) { + rl_replace_line(result, 0); + rl_point = rl_end; + inp_write(result, rl_point); + } + } + + return 0; +} + void create_input_window(void) { @@ -99,7 +125,7 @@ create_input_window(void) p_rl_timeout.tv_sec = 0; p_rl_timeout.tv_usec = inp_timeout * 1000; rl_callback_handler_install(NULL, cb_linehandler); - + rl_bind_key('\t', tab_handler); inp_win = newpad(1, INP_WIN_MAX); wbkgd(inp_win, theme_attrs(THEME_INPUT_TEXT));; keypad(inp_win, TRUE); @@ -205,6 +231,7 @@ inp_readline(void) } ui_reset_idle_time(); inp_nonblocking(TRUE); + rl_redisplay(); inp_write(rl_line_buffer, rl_point); } else { inp_nonblocking(FALSE); From fe10f2b2e38818cdc77b226ee498d0956d3bba40 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 31 Jan 2015 16:51:09 +0000 Subject: [PATCH 021/252] Clear autocompleters on printable chars --- src/ui/inputwin.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index 649590bc..372048a2 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -91,7 +91,7 @@ cb_linehandler(char *line) int tab_handler(int count, int key) { - if (rl_point != rl_end) { + if (rl_point != rl_end || !rl_line_buffer) { return 0; } @@ -126,6 +126,7 @@ create_input_window(void) p_rl_timeout.tv_usec = inp_timeout * 1000; rl_callback_handler_install(NULL, cb_linehandler); rl_bind_key('\t', tab_handler); + inp_win = newpad(1, INP_WIN_MAX); wbkgd(inp_win, theme_attrs(THEME_INPUT_TEXT));; keypad(inp_win, TRUE); @@ -213,6 +214,17 @@ inp_write(char *line, int offset) _inp_win_update_virtual(); } +static int +_printable(const wint_t ch) +{ + char bytes[MB_CUR_MAX+1]; + size_t utf_len = wcrtomb(bytes, ch, NULL); + bytes[utf_len] = '\0'; + gunichar unichar = g_utf8_get_char(bytes); + + return g_unichar_isprint(unichar) && (ch != KEY_MOUSE); +} + gboolean inp_readline(void) { @@ -225,13 +237,18 @@ inp_readline(void) } if (FD_ISSET(fileno(rl_instream), &fds)) { + if (_printable(rl_executing_key)) { + cmd_reset_autocomplete(); + } + rl_callback_read_char(); + if (rl_line_buffer && rl_line_buffer[0] != '/') { prof_handle_activity(); } + ui_reset_idle_time(); inp_nonblocking(TRUE); - rl_redisplay(); inp_write(rl_line_buffer, rl_point); } else { inp_nonblocking(FALSE); From e6f27de55221f0f41362b81ca927d5d55682d14f Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 31 Jan 2015 18:02:42 +0000 Subject: [PATCH 022/252] Added SIGWINCH handler --- src/ui/core.c | 10 ++++++++-- src/ui/inputwin.c | 11 ++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/ui/core.c b/src/ui/core.c index ed21b233..254dd554 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -41,6 +41,9 @@ #include #include #include +#include +#include + #ifdef HAVE_LIBXSS #include #endif @@ -91,7 +94,6 @@ ui_init(void) { log_info("Initialising UI"); initscr(); - raw(); keypad(stdscr, TRUE); if (prefs_get_boolean(PREF_MOUSE)) { mousemask(ALL_MOUSE_EVENTS, NULL); @@ -221,9 +223,13 @@ ui_input_nonblocking(gboolean reset) void ui_resize(void) { - log_info("Resizing UI"); + struct winsize w; + ioctl(STDOUT_FILENO, TIOCGWINSZ, &w); erase(); + resizeterm(w.ws_row, w.ws_col); refresh(); + + log_info("Resizing UI"); title_bar_resize(); wins_resize_all(); status_bar_resize(); diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index 372048a2..627f9da7 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -114,6 +114,12 @@ tab_handler(int count, int key) return 0; } +void +resize_signal_handler(int signal) +{ + ui_resize(); +} + void create_input_window(void) { @@ -127,10 +133,13 @@ create_input_window(void) rl_callback_handler_install(NULL, cb_linehandler); rl_bind_key('\t', tab_handler); + signal(SIGWINCH, resize_signal_handler); + inp_win = newpad(1, INP_WIN_MAX); wbkgd(inp_win, theme_attrs(THEME_INPUT_TEXT));; keypad(inp_win, TRUE); wmove(inp_win, 0, 0); + _inp_win_update_virtual(); } @@ -233,7 +242,7 @@ inp_readline(void) r = select(FD_SETSIZE, &fds, NULL, NULL, &p_rl_timeout); if (r < 0) { log_error("Readline failed."); - return false; + return TRUE; } if (FD_ISSET(fileno(rl_instream), &fds)) { From 28dd5458777a7655a558c14e17d79464c8ab4324 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 31 Jan 2015 22:00:22 +0000 Subject: [PATCH 023/252] Added paging handlers --- src/ui/core.c | 28 ++++++++ src/ui/inputwin.c | 149 +++++++++++++++++++++++++++++++++++++++++-- src/ui/ui.h | 5 ++ src/ui/window.c | 159 +++++++++++++++++++++++++++------------------- src/ui/window.h | 7 +- 5 files changed, 279 insertions(+), 69 deletions(-) diff --git a/src/ui/core.c b/src/ui/core.c index 254dd554..5b9970fc 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -208,6 +208,34 @@ ui_readline(void) // return line; } +void +ui_page_up(void) +{ + ProfWin *current = wins_get_current(); + win_page_up(current); +} + +void +ui_page_down(void) +{ + ProfWin *current = wins_get_current(); + win_page_down(current); +} + +void +ui_subwin_page_up(void) +{ + ProfWin *current = wins_get_current(); + win_sub_page_up(current); +} + +void +ui_subwin_page_down(void) +{ + ProfWin *current = wins_get_current(); + win_sub_page_down(current); +} + void ui_input_clear(void) { diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index 627f9da7..c6d15dce 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -88,6 +88,12 @@ cb_linehandler(char *line) free(line); } +void +resize_signal_handler(int signal) +{ + ui_resize(); +} + int tab_handler(int count, int key) { @@ -114,10 +120,144 @@ tab_handler(int count, int key) return 0; } -void -resize_signal_handler(int signal) +int +alt1_handler(int count, int key) { - ui_resize(); + ui_switch_win(1); + return 0; +} + +int +alt2_handler(int count, int key) +{ + ui_switch_win(2); + return 0; +} + +int +alt3_handler(int count, int key) +{ + ui_switch_win(3); + return 0; +} + +int +alt4_handler(int count, int key) +{ + ui_switch_win(4); + return 0; +} + +int +alt5_handler(int count, int key) +{ + ui_switch_win(5); + return 0; +} + +int +alt6_handler(int count, int key) +{ + ui_switch_win(6); + return 0; +} + +int +alt7_handler(int count, int key) +{ + ui_switch_win(7); + return 0; +} + +int +alt8_handler(int count, int key) +{ + ui_switch_win(8); + return 0; +} + +int +alt9_handler(int count, int key) +{ + ui_switch_win(9); + return 0; +} + +int +alt0_handler(int count, int key) +{ + ui_switch_win(0); + return 0; +} + +int +altleft_handler(int count, int key) +{ + ui_previous_win(); + return 0; +} + +int +altright_handler(int count, int key) +{ + ui_next_win(); + return 0; +} + +int +pageup_handler(int count, int key) +{ + ui_page_up(); + return 0; +} + +int +pagedown_handler(int count, int key) +{ + ui_page_down(); + return 0; +} + +int +altpageup_handler(int count, int key) +{ + ui_subwin_page_up(); + return 0; +} + +int +altpagedown_handler(int count, int key) +{ + ui_subwin_page_down(); + return 0; +} + +int +startup_hook(void) +{ + rl_bind_keyseq("\\e1", alt1_handler); + rl_bind_keyseq("\\e2", alt2_handler); + rl_bind_keyseq("\\e3", alt3_handler); + rl_bind_keyseq("\\e4", alt4_handler); + rl_bind_keyseq("\\e5", alt5_handler); + rl_bind_keyseq("\\e6", alt6_handler); + rl_bind_keyseq("\\e7", alt7_handler); + rl_bind_keyseq("\\e8", alt8_handler); + rl_bind_keyseq("\\e9", alt9_handler); + rl_bind_keyseq("\\e0", alt0_handler); + + rl_bind_keyseq("\\e[1;3D", altleft_handler); + rl_bind_keyseq("\\e[1;3C", altright_handler); + + rl_bind_keyseq("\\e[5~", pageup_handler); + rl_bind_keyseq("\\e[6~", pagedown_handler); + + rl_bind_keyseq("\\e[5;3~", altpageup_handler); + rl_bind_keyseq("\\e[6;3~", altpagedown_handler); + + rl_bind_key('\t', tab_handler); + + return 0; } void @@ -130,8 +270,8 @@ create_input_window(void) #endif p_rl_timeout.tv_sec = 0; p_rl_timeout.tv_usec = inp_timeout * 1000; + rl_startup_hook = startup_hook; rl_callback_handler_install(NULL, cb_linehandler); - rl_bind_key('\t', tab_handler); signal(SIGWINCH, resize_signal_handler); @@ -140,6 +280,7 @@ create_input_window(void) keypad(inp_win, TRUE); wmove(inp_win, 0, 0); + _inp_win_update_virtual(); } diff --git a/src/ui/ui.h b/src/ui/ui.h index 2cfb6e6e..5008593f 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -218,6 +218,11 @@ void ui_tidy_wins(void); void ui_prune_wins(void); gboolean ui_swap_wins(int source_win, int target_win); +void ui_page_up(void); +void ui_page_down(void); +void ui_subwin_page_up(void); +void ui_subwin_page_down(void); + void ui_auto_away(void); void ui_end_auto_away(void); void ui_titlebar_presence(contact_presence_t presence); diff --git a/src/ui/window.c b/src/ui/window.c index dfec5aab..915acb3c 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -358,7 +358,101 @@ win_free(ProfWin* window) } void -win_handle_page(ProfWin *window, const wint_t ch, const int result) +win_page_up(ProfWin *window) +{ + int rows = getmaxy(stdscr); + int y = getcury(window->layout->win); + int page_space = rows - 4; + int *page_start = &(window->layout->y_pos); + + *page_start -= page_space; + + // went past beginning, show first page + if (*page_start < 0) + *page_start = 0; + + window->layout->paged = 1; + win_update_virtual(window); + + // switch off page if last line and space line visible + if ((y) - *page_start == page_space) { + window->layout->paged = 0; + } +} + +void +win_page_down(ProfWin *window) +{ + int rows = getmaxy(stdscr); + int y = getcury(window->layout->win); + int page_space = rows - 4; + int *page_start = &(window->layout->y_pos); + + *page_start += page_space; + + // only got half a screen, show full screen + if ((y - (*page_start)) < page_space) + *page_start = y - page_space; + + // went past end, show full screen + else if (*page_start >= y) + *page_start = y - page_space - 1; + + window->layout->paged = 1; + win_update_virtual(window); + + // switch off page if last line and space line visible + if ((y) - *page_start == page_space) { + window->layout->paged = 0; + } +} + +void +win_sub_page_down(ProfWin *window) +{ + + if (window->layout->type == LAYOUT_SPLIT) { + int rows = getmaxy(stdscr); + int page_space = rows - 4; + ProfLayoutSplit *split_layout = (ProfLayoutSplit*)window->layout; + int sub_y = getcury(split_layout->subwin); + int *sub_y_pos = &(split_layout->sub_y_pos); + + *sub_y_pos += page_space; + + // only got half a screen, show full screen + if ((sub_y- (*sub_y_pos)) < page_space) + *sub_y_pos = sub_y - page_space; + + // went past end, show full screen + else if (*sub_y_pos >= sub_y) + *sub_y_pos = sub_y - page_space - 1; + + win_update_virtual(window); + } +} + +void +win_sub_page_up(ProfWin *window) +{ + if (window->layout->type == LAYOUT_SPLIT) { + int rows = getmaxy(stdscr); + int page_space = rows - 4; + ProfLayoutSplit *split_layout = (ProfLayoutSplit*)window->layout; + int *sub_y_pos = &(split_layout->sub_y_pos); + + *sub_y_pos -= page_space; + + // went past beginning, show first page + if (*sub_y_pos < 0) + *sub_y_pos = 0; + + win_update_virtual(window); + } +} + +void +win_mouse(ProfWin *window, const wint_t ch, const int result) { int rows = getmaxy(stdscr); int y = getcury(window->layout->win); @@ -402,69 +496,6 @@ win_handle_page(ProfWin *window, const wint_t ch, const int result) } } } - - // page up - if (ch == KEY_PPAGE) { - *page_start -= page_space; - - // went past beginning, show first page - if (*page_start < 0) - *page_start = 0; - - window->layout->paged = 1; - win_update_virtual(window); - - // page down - } else if (ch == KEY_NPAGE) { - *page_start += page_space; - - // only got half a screen, show full screen - if ((y - (*page_start)) < page_space) - *page_start = y - page_space; - - // went past end, show full screen - else if (*page_start >= y) - *page_start = y - page_space - 1; - - window->layout->paged = 1; - win_update_virtual(window); - } - - // switch off page if last line and space line visible - if ((y) - *page_start == page_space) { - window->layout->paged = 0; - } - - if (window->layout->type == LAYOUT_SPLIT) { - ProfLayoutSplit *split_layout = (ProfLayoutSplit*)window->layout; - int sub_y = getcury(split_layout->subwin); - int *sub_y_pos = &(split_layout->sub_y_pos); - - // alt up arrow - if ((result == KEY_CODE_YES) && ((ch == 565) || (ch == 337))) { - *sub_y_pos -= page_space; - - // went past beginning, show first page - if (*sub_y_pos < 0) - *sub_y_pos = 0; - - win_update_virtual(window); - - // alt down arrow - } else if ((result == KEY_CODE_YES) && ((ch == 524) || (ch == 336))) { - *sub_y_pos += page_space; - - // only got half a screen, show full screen - if ((sub_y- (*sub_y_pos)) < page_space) - *sub_y_pos = sub_y - page_space; - - // went past end, show full screen - else if (*sub_y_pos >= sub_y) - *sub_y_pos = sub_y - page_space - 1; - - win_update_virtual(window); - } - } } void diff --git a/src/ui/window.h b/src/ui/window.h index fd10a1d7..66e4a5f2 100644 --- a/src/ui/window.h +++ b/src/ui/window.h @@ -178,9 +178,14 @@ void win_show_subwin(ProfWin *window); int win_roster_cols(void); int win_occpuants_cols(void); void win_printline_nowrap(WINDOW *win, char *msg); -void win_handle_page(ProfWin *current, const wint_t ch, const int result); +void win_mouse(ProfWin *current, const wint_t ch, const int result); int win_unread(ProfWin *window); gboolean win_has_active_subwin(ProfWin *window); +void win_page_up(ProfWin *window); +void win_page_down(ProfWin *window); +void win_sub_page_down(ProfWin *window); +void win_sub_page_up(ProfWin *window); + #endif From baa122e7dcd2cf9a996868e9f51f187a9b626f47 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 31 Jan 2015 22:08:00 +0000 Subject: [PATCH 024/252] Added function key bindings --- src/ui/inputwin.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index c6d15dce..2737101b 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -246,6 +246,17 @@ startup_hook(void) rl_bind_keyseq("\\e9", alt9_handler); rl_bind_keyseq("\\e0", alt0_handler); + rl_bind_keyseq("\\eOP", alt1_handler); + rl_bind_keyseq("\\eOQ", alt2_handler); + rl_bind_keyseq("\\eOR", alt3_handler); + rl_bind_keyseq("\\eOS", alt4_handler); + rl_bind_keyseq("\\e[15~", alt5_handler); + rl_bind_keyseq("\\e[17~", alt6_handler); + rl_bind_keyseq("\\e[18~", alt7_handler); + rl_bind_keyseq("\\e[19~", alt8_handler); + rl_bind_keyseq("\\e[20~", alt9_handler); + rl_bind_keyseq("\\e[21~", alt0_handler); + rl_bind_keyseq("\\e[1;3D", altleft_handler); rl_bind_keyseq("\\e[1;3C", altright_handler); From 84688c063e1b1684cebf7251f39a32e07f77c6b7 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 31 Jan 2015 22:12:27 +0000 Subject: [PATCH 025/252] Removed commented code, renamed win switch handlers --- src/ui/core.c | 22 ----------------- src/ui/inputwin.c | 60 +++++++++++++++++++++++------------------------ 2 files changed, 30 insertions(+), 52 deletions(-) diff --git a/src/ui/core.c b/src/ui/core.c index 5b9970fc..7131b005 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -184,28 +184,6 @@ gboolean ui_readline(void) { return inp_readline(); - -// int key_type; -// wint_t ch; -// -// char *line = inp_read(&key_type, &ch); -// _win_handle_switch(ch); -// -// ProfWin *current = wins_get_current(); -// win_handle_page(current, ch, key_type); -// -// if (ch == KEY_RESIZE) { -// ui_resize(); -// } -// -// if (ch != ERR && key_type != ERR) { -// ui_reset_idle_time(); -// ui_input_nonblocking(TRUE); -// } else { -// ui_input_nonblocking(FALSE); -// } -// -// return line; } void diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index 2737101b..083b6c4e 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -121,70 +121,70 @@ tab_handler(int count, int key) } int -alt1_handler(int count, int key) +win1_handler(int count, int key) { ui_switch_win(1); return 0; } int -alt2_handler(int count, int key) +win2_handler(int count, int key) { ui_switch_win(2); return 0; } int -alt3_handler(int count, int key) +win3_handler(int count, int key) { ui_switch_win(3); return 0; } int -alt4_handler(int count, int key) +win4_handler(int count, int key) { ui_switch_win(4); return 0; } int -alt5_handler(int count, int key) +win5_handler(int count, int key) { ui_switch_win(5); return 0; } int -alt6_handler(int count, int key) +win6_handler(int count, int key) { ui_switch_win(6); return 0; } int -alt7_handler(int count, int key) +win7_handler(int count, int key) { ui_switch_win(7); return 0; } int -alt8_handler(int count, int key) +win8_handler(int count, int key) { ui_switch_win(8); return 0; } int -alt9_handler(int count, int key) +win9_handler(int count, int key) { ui_switch_win(9); return 0; } int -alt0_handler(int count, int key) +win0_handler(int count, int key) { ui_switch_win(0); return 0; @@ -235,27 +235,27 @@ altpagedown_handler(int count, int key) int startup_hook(void) { - rl_bind_keyseq("\\e1", alt1_handler); - rl_bind_keyseq("\\e2", alt2_handler); - rl_bind_keyseq("\\e3", alt3_handler); - rl_bind_keyseq("\\e4", alt4_handler); - rl_bind_keyseq("\\e5", alt5_handler); - rl_bind_keyseq("\\e6", alt6_handler); - rl_bind_keyseq("\\e7", alt7_handler); - rl_bind_keyseq("\\e8", alt8_handler); - rl_bind_keyseq("\\e9", alt9_handler); - rl_bind_keyseq("\\e0", alt0_handler); + rl_bind_keyseq("\\e1", win1_handler); + rl_bind_keyseq("\\e2", win2_handler); + rl_bind_keyseq("\\e3", win3_handler); + rl_bind_keyseq("\\e4", win4_handler); + rl_bind_keyseq("\\e5", win5_handler); + rl_bind_keyseq("\\e6", win6_handler); + rl_bind_keyseq("\\e7", win7_handler); + rl_bind_keyseq("\\e8", win8_handler); + rl_bind_keyseq("\\e9", win9_handler); + rl_bind_keyseq("\\e0", win0_handler); - rl_bind_keyseq("\\eOP", alt1_handler); - rl_bind_keyseq("\\eOQ", alt2_handler); - rl_bind_keyseq("\\eOR", alt3_handler); - rl_bind_keyseq("\\eOS", alt4_handler); - rl_bind_keyseq("\\e[15~", alt5_handler); - rl_bind_keyseq("\\e[17~", alt6_handler); - rl_bind_keyseq("\\e[18~", alt7_handler); - rl_bind_keyseq("\\e[19~", alt8_handler); - rl_bind_keyseq("\\e[20~", alt9_handler); - rl_bind_keyseq("\\e[21~", alt0_handler); + rl_bind_keyseq("\\eOP", win1_handler); + rl_bind_keyseq("\\eOQ", win2_handler); + rl_bind_keyseq("\\eOR", win3_handler); + rl_bind_keyseq("\\eOS", win4_handler); + rl_bind_keyseq("\\e[15~", win5_handler); + rl_bind_keyseq("\\e[17~", win6_handler); + rl_bind_keyseq("\\e[18~", win7_handler); + rl_bind_keyseq("\\e[19~", win8_handler); + rl_bind_keyseq("\\e[20~", win9_handler); + rl_bind_keyseq("\\e[21~", win0_handler); rl_bind_keyseq("\\e[1;3D", altleft_handler); rl_bind_keyseq("\\e[1;3C", altright_handler); From 3b3ffcfb3770a781a38a93d930df38f9d4a37c28 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 31 Jan 2015 22:14:41 +0000 Subject: [PATCH 026/252] Added mock ui functions to tests --- tests/ui/stub_ui.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/ui/stub_ui.c b/tests/ui/stub_ui.c index 6127e4f0..d681ec15 100644 --- a/tests/ui/stub_ui.c +++ b/tests/ui/stub_ui.c @@ -178,6 +178,11 @@ int ui_win_unread(int index) return 0; } +void ui_page_up(void) {} +void ui_page_down(void) {} +void ui_subwin_page_up(void) {} +void ui_subwin_page_down(void) {} + char * ui_ask_password(void) { return mock_ptr_type(char *); From a19c0a5989c45ced8460284fe6591bebe08d22ac Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 31 Jan 2015 22:29:44 +0000 Subject: [PATCH 027/252] Added scroll handler --- src/ui/inputwin.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index 083b6c4e..ee800e56 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -365,6 +365,26 @@ inp_block(void) wtimeout(inp_win, -1); } +void +inp_win_handle_scroll(void) +{ + int col = getcurx(inp_win); + int wcols = getmaxx(stdscr); + + // if lost cursor off screen, move contents to show it + if (col >= pad_start + (wcols -2)) { + pad_start = col - (wcols / 2); + if (pad_start < 0) { + pad_start = 0; + } + } else if (col <= pad_start) { + pad_start = pad_start - (wcols / 2); + if (pad_start < 0) { + pad_start = 0; + } + } +} + void inp_write(char *line, int offset) { @@ -372,6 +392,8 @@ inp_write(char *line, int offset) werase(inp_win); waddstr(inp_win, line); wmove(inp_win, 0, col); + inp_win_handle_scroll(); + _inp_win_update_virtual(); } From e8b6c505cb825422ee467c9210ba0b87097aa85d Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 1 Feb 2015 00:14:11 +0000 Subject: [PATCH 028/252] Handle word wrapping wide chars --- src/ui/inputwin.c | 2 +- src/ui/window.c | 45 ++++++++++++++++++++++++++++++++------------- 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index ee800e56..165a0b32 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -485,5 +485,5 @@ _inp_win_update_virtual(void) { int wrows, wcols; getmaxyx(stdscr, wrows, wcols); - pnoutrefresh(inp_win, 0, pad_start, wrows-1, 0, wrows-1, wcols-1); + pnoutrefresh(inp_win, 0, pad_start, wrows-1, 0, wrows-1, wcols-2); } \ No newline at end of file diff --git a/src/ui/window.c b/src/ui/window.c index 915acb3c..37da8e9d 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -37,6 +37,7 @@ #include #include #include +#include #include #ifdef HAVE_NCURSESW_NCURSES_H @@ -985,7 +986,6 @@ _win_indent(WINDOW *win, int size) static void _win_print_wrapped(WINDOW *win, const char * const message) { - int linei = 0; int wordi = 0; char *word = malloc(strlen(message) + 1); @@ -998,18 +998,27 @@ _win_print_wrapped(WINDOW *win, const char * const message) } free(time_pref); - while (message[linei] != '\0') { - if (message[linei] == ' ') { + gchar *curr_ch = g_utf8_offset_to_pointer(message, 0); + + while (*curr_ch != '\0') { + if (*curr_ch == ' ') { waddch(win, ' '); - linei++; - } else if (message[linei] == '\n') { + curr_ch = g_utf8_next_char(curr_ch); + } else if (*curr_ch == '\n') { waddch(win, '\n'); _win_indent(win, indent); - linei++; + curr_ch = g_utf8_next_char(curr_ch); } else { + // get word wordi = 0; - while (message[linei] != ' ' && message[linei] != '\n' && message[linei] != '\0') { - word[wordi++] = message[linei++]; + mbstate_t internal; + while (*curr_ch != ' ' && *curr_ch != '\n' && *curr_ch != '\0') { + size_t ch_len = mbrlen(curr_ch, 4, &internal); + int offset = 0; + while (offset < ch_len) { + word[wordi++] = curr_ch[offset++]; + } + curr_ch = g_utf8_next_char(curr_ch); } word[wordi] = '\0'; @@ -1017,17 +1026,27 @@ _win_print_wrapped(WINDOW *win, const char * const message) int maxx = getmaxx(win); // word larger than line - if (strlen(word) > (maxx - indent)) { - int i; - for (i = 0; i < wordi; i++) { + if (utf8_display_len(word) > (maxx - indent)) { + gchar *word_ch = g_utf8_offset_to_pointer(word, 0); + while(*word_ch != '\0') { curx = getcurx(win); if (curx < indent) { _win_indent(win, indent); } - waddch(win, word[i]); + + gchar copy[wordi++]; + g_utf8_strncpy(copy, word_ch, 1); + + if (curx + utf8_display_len(copy) > maxx) { + waddch(win, '\n'); + _win_indent(win, indent); + } + waddstr(win, copy); + + word_ch = g_utf8_next_char(word_ch); } } else { - if (curx + strlen(word) > maxx) { + if (curx + utf8_display_len(word) > maxx) { waddch(win, '\n'); _win_indent(win, indent); } From a9af8785a7b96af0288f3bb2cbc7128293a29917 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 1 Feb 2015 00:35:42 +0000 Subject: [PATCH 029/252] Added more ignore characters to handle activity --- src/ui/inputwin.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index 165a0b32..e6782206 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -426,7 +426,7 @@ inp_readline(void) rl_callback_read_char(); - if (rl_line_buffer && rl_line_buffer[0] != '/') { + if (rl_line_buffer && rl_line_buffer[0] != '/' && rl_line_buffer[0] != '\0' && rl_line_buffer[0] != '\n') { prof_handle_activity(); } From 702ea0b5f38970d7a3e135ca39c2b255767de4f6 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 1 Feb 2015 20:14:07 +0000 Subject: [PATCH 030/252] Use getc wrapper for autocomplete reset check --- src/ui/inputwin.c | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index e6782206..5a152620 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -77,6 +77,17 @@ static int pad_start = 0; static void _inp_win_update_virtual(void); +static int +_printable(const wint_t ch) +{ + char bytes[MB_CUR_MAX+1]; + size_t utf_len = wcrtomb(bytes, ch, NULL); + bytes[utf_len] = '\0'; + gunichar unichar = g_utf8_get_char(bytes); + + return g_unichar_isprint(unichar) && (ch != KEY_MOUSE); +} + static void cb_linehandler(char *line) { @@ -88,6 +99,16 @@ cb_linehandler(char *line) free(line); } +int +prof_rl_getc(FILE *filein) +{ + int ch = rl_getc(filein); + if (_printable(ch)) { + cmd_reset_autocomplete(); + } + return ch; +} + void resize_signal_handler(int signal) { @@ -282,6 +303,7 @@ create_input_window(void) p_rl_timeout.tv_sec = 0; p_rl_timeout.tv_usec = inp_timeout * 1000; rl_startup_hook = startup_hook; + rl_getc_function = prof_rl_getc; rl_callback_handler_install(NULL, cb_linehandler); signal(SIGWINCH, resize_signal_handler); @@ -397,17 +419,6 @@ inp_write(char *line, int offset) _inp_win_update_virtual(); } -static int -_printable(const wint_t ch) -{ - char bytes[MB_CUR_MAX+1]; - size_t utf_len = wcrtomb(bytes, ch, NULL); - bytes[utf_len] = '\0'; - gunichar unichar = g_utf8_get_char(bytes); - - return g_unichar_isprint(unichar) && (ch != KEY_MOUSE); -} - gboolean inp_readline(void) { @@ -420,10 +431,6 @@ inp_readline(void) } if (FD_ISSET(fileno(rl_instream), &fds)) { - if (_printable(rl_executing_key)) { - cmd_reset_autocomplete(); - } - rl_callback_read_char(); if (rl_line_buffer && rl_line_buffer[0] != '/' && rl_line_buffer[0] != '\0' && rl_line_buffer[0] != '\n') { From 51a54260064db3fc5d43456b15d821f192e9d12f Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 1 Feb 2015 21:01:00 +0000 Subject: [PATCH 031/252] Added include for timeval struct --- src/ui/inputwin.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index 5a152620..4ac34c97 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -38,6 +38,7 @@ #include #include #include +#include #include #include From e3feacddd6667fd8e111d0ee54846c6aeabe3a7d Mon Sep 17 00:00:00 2001 From: Olivier LE MOAL Date: Mon, 2 Feb 2015 11:10:05 +0100 Subject: [PATCH 032/252] Add XEP-0280 support --- src/server_events.c | 5 +++++ src/server_events.h | 1 + src/xmpp/connection.c | 1 + src/xmpp/iq.c | 10 ++++++++++ src/xmpp/message.c | 38 ++++++++++++++++++++++++++++++++++++++ src/xmpp/stanza.c | 18 ++++++++++++++++++ src/xmpp/stanza.h | 5 +++++ src/xmpp/xmpp.h | 1 + 8 files changed, 79 insertions(+) diff --git a/src/server_events.c b/src/server_events.c index fbf534ac..bf880a9d 100644 --- a/src/server_events.c +++ b/src/server_events.c @@ -296,6 +296,11 @@ handle_incoming_private_message(char *fulljid, char *message) ui_incoming_private_msg(fulljid, message, NULL); } +void +handle_carbon(char *barejid, char *message){ + ui_outgoing_chat_msg("me", barejid, message); +} + void handle_incoming_message(char *barejid, char *resource, char *message) { diff --git a/src/server_events.h b/src/server_events.h index 6a12dc6e..3ec6a332 100644 --- a/src/server_events.h +++ b/src/server_events.h @@ -101,6 +101,7 @@ void handle_group_remove(const char * const contact, void handle_roster_remove(const char * const barejid); void handle_roster_add(const char * const barejid, const char * const name); void handle_autoping_cancel(void); +void handle_carbon(char *barejid, char *message); void handle_message_error(const char * const from, const char * const type, const char * const err_msg); void handle_presence_error(const char *from, const char * const type, diff --git a/src/xmpp/connection.c b/src/xmpp/connection.c index 915525e4..8bb7c74c 100644 --- a/src/xmpp/connection.c +++ b/src/xmpp/connection.c @@ -463,6 +463,7 @@ _connection_handler(xmpp_conn_t * const conn, message_add_handlers(); presence_add_handlers(); iq_add_handlers(); + iq_enable_carbons(); roster_request(); bookmark_request(); diff --git a/src/xmpp/iq.c b/src/xmpp/iq.c index 7fedf0ed..071b07c5 100644 --- a/src/xmpp/iq.c +++ b/src/xmpp/iq.c @@ -152,6 +152,16 @@ iq_room_list_request(gchar *conferencejid) xmpp_stanza_release(iq); } +void +iq_enable_carbons() +{ + xmpp_conn_t * const conn = connection_get_conn(); + xmpp_ctx_t * const ctx = connection_get_ctx(); + xmpp_stanza_t *iq = stanza_enable_carbons(ctx); + xmpp_send(conn, iq); + xmpp_stanza_release(iq); +} + void iq_disco_info_request(gchar *jid) { diff --git a/src/xmpp/message.c b/src/xmpp/message.c index e96c1a74..4f341f6a 100644 --- a/src/xmpp/message.c +++ b/src/xmpp/message.c @@ -423,6 +423,44 @@ _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, return 1; } + // check if carbon message + xmpp_stanza_t *received = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_CARBONS); + if(received != NULL){ + xmpp_stanza_t *forwarded = xmpp_stanza_get_child_by_ns(received, STANZA_NS_FORWARD); + xmpp_stanza_t *message = xmpp_stanza_get_child_by_name(forwarded, STANZA_NAME_MESSAGE); + + xmpp_ctx_t *ctx = connection_get_ctx(); + + gchar *to = xmpp_stanza_get_attribute(message, STANZA_ATTR_TO); + gchar *from = xmpp_stanza_get_attribute(message, STANZA_ATTR_FROM); + + Jid *jid_from = jid_create(from); + Jid *jid_to = jid_create(to); + Jid *my_jid = jid_create(jabber_get_fulljid()); + + // check for and deal with message + xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(message, STANZA_NAME_BODY); + if (body != NULL) { + char *message = xmpp_stanza_get_text(body); + if (message != NULL) { + // if we are the recipient, treat as standard incoming message + if(g_strcmp0(my_jid->barejid, jid_to->barejid) == 0){ + handle_incoming_message(jid_from->barejid, jid_from->resourcepart, message); + } + // else treat as a sent message + else{ + handle_carbon(jid_to->barejid, message); + } + xmpp_free(ctx, message); + } + } + + jid_destroy(jid_from); + jid_destroy(jid_to); + jid_destroy(my_jid); + return 1; + } + // ignore handled namespaces xmpp_stanza_t *conf = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_CONFERENCE); xmpp_stanza_t *mucuser = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_MUC_USER); diff --git a/src/xmpp/stanza.c b/src/xmpp/stanza.c index 4f1d412d..06177800 100644 --- a/src/xmpp/stanza.c +++ b/src/xmpp/stanza.c @@ -198,6 +198,24 @@ stanza_create_bookmarks_pubsub_add(xmpp_ctx_t *ctx, const char * const jid, } #endif +xmpp_stanza_t * +stanza_enable_carbons(xmpp_ctx_t *ctx){ + xmpp_stanza_t *iq = xmpp_stanza_new(ctx); + char *id = create_unique_id(NULL); + + xmpp_stanza_set_name(iq, STANZA_NAME_IQ); + xmpp_stanza_set_type(iq, STANZA_TYPE_SET); + xmpp_stanza_set_id(iq, id); + + xmpp_stanza_t *carbon_enable = xmpp_stanza_new(ctx); + xmpp_stanza_set_name(carbon_enable, STANZA_NAME_ENABLE); + xmpp_stanza_set_ns(carbon_enable, STANZA_NS_CARBONS); + + xmpp_stanza_add_child(iq, carbon_enable); + + return iq; +} + xmpp_stanza_t * stanza_create_chat_state(xmpp_ctx_t *ctx, const char * const fulljid, const char * const state) { diff --git a/src/xmpp/stanza.h b/src/xmpp/stanza.h index 84282401..0c5a2b01 100644 --- a/src/xmpp/stanza.h +++ b/src/xmpp/stanza.h @@ -77,6 +77,7 @@ #define STANZA_NAME_VALUE "value" #define STANZA_NAME_DESTROY "destroy" #define STANZA_NAME_ACTOR "actor" +#define STANZA_NAME_ENABLE "enable" // error conditions #define STANZA_NAME_BAD_REQUEST "bad-request" @@ -154,6 +155,8 @@ #define STANZA_NS_CONFERENCE "jabber:x:conference" #define STANZA_NS_CAPTCHA "urn:xmpp:captcha" #define STANZA_NS_PUBSUB "http://jabber.org/protocol/pubsub" +#define STANZA_NS_CARBONS "urn:xmpp:carbons:2" +#define STANZA_NS_FORWARD "urn:xmpp:forward:0" #define STANZA_DATAFORM_SOFTWARE "urn:xmpp:dataforms:softwareinfo" @@ -178,6 +181,8 @@ typedef enum { xmpp_stanza_t* stanza_create_bookmarks_storage_request(xmpp_ctx_t *ctx); +xmpp_stanza_t * stanza_enable_carbons(xmpp_ctx_t *ctx); + xmpp_stanza_t* stanza_create_chat_state(xmpp_ctx_t *ctx, const char * const fulljid, const char * const state); diff --git a/src/xmpp/xmpp.h b/src/xmpp/xmpp.h index a004a4bf..41355e30 100644 --- a/src/xmpp/xmpp.h +++ b/src/xmpp/xmpp.h @@ -172,6 +172,7 @@ void presence_update(resource_presence_t status, const char * const msg, gboolean presence_sub_request_exists(const char * const bare_jid); // iq functions +void iq_enable_carbons(); void iq_send_software_version(const char * const fulljid); void iq_room_list_request(gchar *conferencejid); void iq_disco_info_request(gchar *jid); From 5954c0d2fe398213b29a8b4aa60340d49bf9946e Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 2 Feb 2015 21:27:58 +0000 Subject: [PATCH 033/252] Readline osx compatibility --- configure.ac | 9 +++++++-- src/ui/core.c | 4 ++++ src/ui/inputwin.c | 18 ++++++++++-------- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/configure.ac b/configure.ac index 2794ad43..59d7f82a 100644 --- a/configure.ac +++ b/configure.ac @@ -133,8 +133,8 @@ PKG_CHECK_MODULES([glib], [glib-2.0 >= 2.26], [], [AC_MSG_ERROR([glib 2.26 or higher is required for profanity])]) PKG_CHECK_MODULES([curl], [libcurl], [], [AC_MSG_ERROR([libcurl is required for profanity])]) -AC_CHECK_LIB([readline], [main], [], - [AC_MSG_ERROR([libreadline is required for profanity])]) +###AC_CHECK_LIB([readline], [main], [], +### [AC_MSG_ERROR([libreadline is required for profanity])]) AS_IF([test "x$PLATFORM" = xosx], [LIBS="-lcurl $LIBS"]) @@ -234,6 +234,11 @@ AM_CPPFLAGS="$AM_CPPFLAGS $glib_CFLAGS $curl_CFLAGS $libnotify_CFLAGS" AM_CPPFLAGS="$AM_CPPFLAGS -DTHEMES_PATH=\"\\\"$THEMES_PATH\\\"\"" LIBS="$glib_LIBS $curl_LIBS $libnotify_LIBS $LIBS" +LIBS="-lreadline $LIBS" +AM_CPPFLAGS="-I/usr/local/opt/readline/include $AM_CPPFLAGS" +AM_LDFLAGS="-L/usr/local/opt/readline/lib $AM_LDFLAGS" +AC_SUBST(AM_LDFLAGS) + AC_SUBST(AM_CFLAGS) AC_SUBST(AM_CPPFLAGS) diff --git a/src/ui/core.c b/src/ui/core.c index 47aa9d10..d6b45bde 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -94,6 +94,10 @@ ui_init(void) { log_info("Initialising UI"); initscr(); + nonl(); + cbreak(); + noecho(); + leaveok(stdscr, FALSE); keypad(stdscr, TRUE); if (prefs_get_boolean(PREF_MOUSE)) { mousemask(ALL_MOUSE_EVENTS, NULL); diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index 4ac34c97..0c1c617e 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -92,10 +92,9 @@ _printable(const wint_t ch) static void cb_linehandler(char *line) { - if (*line) { + if (line && *line) { add_history(line); } - rl_redisplay(); cmd_result = cmd_process_input(line); free(line); } @@ -103,7 +102,7 @@ cb_linehandler(char *line) int prof_rl_getc(FILE *filein) { - int ch = rl_getc(filein); + int ch = getc(stdin); if (_printable(ch)) { cmd_reset_autocomplete(); } @@ -128,14 +127,12 @@ tab_handler(int count, int key) if (result) { rl_replace_line(result, 0); rl_point = rl_end; - inp_write(result, rl_point); } } else if (strncmp(rl_line_buffer, "/", 1) == 0) { char *result = cmd_autocomplete(rl_line_buffer); if (result) { rl_replace_line(result, 0); rl_point = rl_end; - inp_write(result, rl_point); } } @@ -296,15 +293,19 @@ startup_hook(void) void create_input_window(void) { +/* #ifdef NCURSES_REENTRANT set_escdelay(25); #else ESCDELAY = 25; #endif +*/ p_rl_timeout.tv_sec = 0; p_rl_timeout.tv_usec = inp_timeout * 1000; - rl_startup_hook = startup_hook; + + rl_readline_name = "profanity"; rl_getc_function = prof_rl_getc; + rl_startup_hook = startup_hook; rl_callback_handler_install(NULL, cb_linehandler); signal(SIGWINCH, resize_signal_handler); @@ -314,7 +315,6 @@ create_input_window(void) keypad(inp_win, TRUE); wmove(inp_win, 0, 0); - _inp_win_update_virtual(); } @@ -433,6 +433,8 @@ inp_readline(void) if (FD_ISSET(fileno(rl_instream), &fds)) { rl_callback_read_char(); + cons_debug("LINE: %s", rl_line_buffer); + cons_debug("POS : %d", rl_point); if (rl_line_buffer && rl_line_buffer[0] != '/' && rl_line_buffer[0] != '\0' && rl_line_buffer[0] != '\n') { prof_handle_activity(); @@ -494,4 +496,4 @@ _inp_win_update_virtual(void) int wrows, wcols; getmaxyx(stdscr, wrows, wcols); pnoutrefresh(inp_win, 0, pad_start, wrows-1, 0, wrows-1, wcols-2); -} \ No newline at end of file +} From 1c157b04df75a71672d97ba970fc1a24a2f10a3c Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 2 Feb 2015 23:17:47 +0000 Subject: [PATCH 034/252] Fixed arrow keys with debug --- src/ui/core.c | 1 - src/ui/inputwin.c | 9 +++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/ui/core.c b/src/ui/core.c index d6b45bde..de3bafd2 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -97,7 +97,6 @@ ui_init(void) nonl(); cbreak(); noecho(); - leaveok(stdscr, FALSE); keypad(stdscr, TRUE); if (prefs_get_boolean(PREF_MOUSE)) { mousemask(ALL_MOUSE_EVENTS, NULL); diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index 0c1c617e..02278adf 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -102,7 +102,7 @@ cb_linehandler(char *line) int prof_rl_getc(FILE *filein) { - int ch = getc(stdin); + int ch = rl_getc(filein); if (_printable(ch)) { cmd_reset_autocomplete(); } @@ -293,13 +293,11 @@ startup_hook(void) void create_input_window(void) { -/* #ifdef NCURSES_REENTRANT set_escdelay(25); #else ESCDELAY = 25; #endif -*/ p_rl_timeout.tv_sec = 0; p_rl_timeout.tv_usec = inp_timeout * 1000; @@ -433,16 +431,15 @@ inp_readline(void) if (FD_ISSET(fileno(rl_instream), &fds)) { rl_callback_read_char(); - cons_debug("LINE: %s", rl_line_buffer); - cons_debug("POS : %d", rl_point); if (rl_line_buffer && rl_line_buffer[0] != '/' && rl_line_buffer[0] != '\0' && rl_line_buffer[0] != '\n') { prof_handle_activity(); } ui_reset_idle_time(); - inp_nonblocking(TRUE); + cons_show(""); inp_write(rl_line_buffer, rl_point); + inp_nonblocking(TRUE); } else { inp_nonblocking(FALSE); prof_handle_idle(); From 2a12a4d93bcb898225003a8d38e7f28662075b70 Mon Sep 17 00:00:00 2001 From: Olivier LE MOAL Date: Tue, 3 Feb 2015 15:27:56 +0100 Subject: [PATCH 035/252] Add preference/commands for carbons message --- src/command/command.c | 10 ++++++++++ src/command/commands.c | 16 ++++++++++++++++ src/command/commands.h | 1 + src/config/preferences.c | 5 ++++- src/config/preferences.h | 1 + src/ui/console.c | 9 +++++++++ src/ui/ui.h | 1 + src/xmpp/connection.c | 6 +++++- src/xmpp/iq.c | 10 ++++++++++ src/xmpp/stanza.c | 28 ++++++++++++++++++++++++---- src/xmpp/stanza.h | 3 +++ src/xmpp/xmpp.h | 1 + 12 files changed, 85 insertions(+), 6 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index 7be6603d..f44a21f5 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -858,6 +858,16 @@ static struct cmd_t command_defs[] = "shared : Share logs between all instances, accepts 'on' or 'off', defaults to 'on'.", NULL } } }, + { "/carbons", + cmd_carbons, parse_args, 1, 1, &cons_carbons_setting, + { "/carbons on|off", "Message carbons.", + { "/carbons on|off", + "---------------", + "Enable or disable message carbons.", + "", + "Example : /carbons on", + NULL } } }, + { "/reconnect", cmd_reconnect, parse_args, 1, 1, &cons_reconnect_setting, { "/reconnect seconds", "Set reconnect interval.", diff --git a/src/command/commands.c b/src/command/commands.c index 2059c982..477471d5 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -3882,6 +3882,22 @@ cmd_history(gchar **args, struct cmd_help_t help) return result; } +gboolean +cmd_carbons(gchar **args, struct cmd_help_t help) +{ + gboolean result = _cmd_set_boolean_preference(args[0], help, + "Carbons message", PREF_CARBONS); + + // enable carbons + if (strcmp(args[0], "on") == 0) { + iq_enable_carbons(); + } + else if (strcmp(args[0], "off") == 0){ + iq_disable_carbons(); + } + return result; +} + gboolean cmd_away(gchar **args, struct cmd_help_t help) { diff --git a/src/command/commands.h b/src/command/commands.h index f4e040a9..1c16d635 100644 --- a/src/command/commands.h +++ b/src/command/commands.h @@ -85,6 +85,7 @@ gboolean cmd_grlog(gchar **args, struct cmd_help_t help); gboolean cmd_group(gchar **args, struct cmd_help_t help); gboolean cmd_help(gchar **args, struct cmd_help_t help); gboolean cmd_history(gchar **args, struct cmd_help_t help); +gboolean cmd_carbons(gchar **args, struct cmd_help_t help); gboolean cmd_info(gchar **args, struct cmd_help_t help); gboolean cmd_intype(gchar **args, struct cmd_help_t help); gboolean cmd_invite(gchar **args, struct cmd_help_t help); diff --git a/src/config/preferences.c b/src/config/preferences.c index 67f12b18..47ef9391 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -558,6 +558,7 @@ _get_group(preference_t pref) return PREF_GROUP_PRESENCE; case PREF_CONNECT_ACCOUNT: case PREF_DEFAULT_ACCOUNT: + case PREF_CARBONS: return PREF_GROUP_CONNECTION; case PREF_OTR_WARN: case PREF_OTR_LOG: @@ -593,6 +594,8 @@ _get_key(preference_t pref) return "intype"; case PREF_HISTORY: return "history"; + case PREF_CARBONS: + return "carbons"; case PREF_MOUSE: return "mouse"; case PREF_OCCUPANTS: @@ -698,7 +701,7 @@ _get_default_boolean(preference_t pref) case PREF_OCCUPANTS: case PREF_MUC_PRIVILEGES: case PREF_PRESENCE: - case PREF_WRAP: + case PREF_WRAP: case PREF_INPBLOCK_DYNAMIC: return TRUE; default: diff --git a/src/config/preferences.h b/src/config/preferences.h index 68286f09..aa23e48a 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -59,6 +59,7 @@ typedef enum { PREF_FLASH, PREF_INTYPE, PREF_HISTORY, + PREF_CARBONS, PREF_MOUSE, PREF_OCCUPANTS, PREF_OCCUPANTS_SIZE, diff --git a/src/ui/console.c b/src/ui/console.c index cdf5d1b8..82bac1e0 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -1167,6 +1167,15 @@ cons_history_setting(void) cons_show("Chat history (/history) : OFF"); } +void +cons_carbons_setting(void) +{ + if (prefs_get_boolean(PREF_CARBONS)) + cons_show("Message carbons (/carbons) : ON"); + else + cons_show("Message carbons (/carbons) : OFF"); +} + void cons_show_chat_prefs(void) { diff --git a/src/ui/ui.h b/src/ui/ui.h index 99e73b4a..44ff42f4 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -308,6 +308,7 @@ void cons_outtype_setting(void); void cons_intype_setting(void); void cons_gone_setting(void); void cons_history_setting(void); +void cons_carbons_setting(void); void cons_log_setting(void); void cons_chlog_setting(void); void cons_grlog_setting(void); diff --git a/src/xmpp/connection.c b/src/xmpp/connection.c index 8bb7c74c..34fba22d 100644 --- a/src/xmpp/connection.c +++ b/src/xmpp/connection.c @@ -463,10 +463,14 @@ _connection_handler(xmpp_conn_t * const conn, message_add_handlers(); presence_add_handlers(); iq_add_handlers(); - iq_enable_carbons(); roster_request(); bookmark_request(); + + if (prefs_get_boolean(PREF_CARBONS)){ + iq_enable_carbons(); + } + jabber_conn.conn_status = JABBER_CONNECTED; if (prefs_get_reconnect() != 0) { diff --git a/src/xmpp/iq.c b/src/xmpp/iq.c index 071b07c5..be22b01f 100644 --- a/src/xmpp/iq.c +++ b/src/xmpp/iq.c @@ -162,6 +162,16 @@ iq_enable_carbons() xmpp_stanza_release(iq); } +void +iq_disable_carbons() +{ + xmpp_conn_t * const conn = connection_get_conn(); + xmpp_ctx_t * const ctx = connection_get_ctx(); + xmpp_stanza_t *iq = stanza_disable_carbons(ctx); + xmpp_send(conn, iq); + xmpp_stanza_release(iq); +} + void iq_disco_info_request(gchar *jid) { diff --git a/src/xmpp/stanza.c b/src/xmpp/stanza.c index 06177800..b0d7de86 100644 --- a/src/xmpp/stanza.c +++ b/src/xmpp/stanza.c @@ -206,12 +206,32 @@ stanza_enable_carbons(xmpp_ctx_t *ctx){ xmpp_stanza_set_name(iq, STANZA_NAME_IQ); xmpp_stanza_set_type(iq, STANZA_TYPE_SET); xmpp_stanza_set_id(iq, id); + free(id); - xmpp_stanza_t *carbon_enable = xmpp_stanza_new(ctx); - xmpp_stanza_set_name(carbon_enable, STANZA_NAME_ENABLE); - xmpp_stanza_set_ns(carbon_enable, STANZA_NS_CARBONS); + xmpp_stanza_t *carbons_enable = xmpp_stanza_new(ctx); + xmpp_stanza_set_name(carbons_enable, STANZA_NAME_ENABLE); + xmpp_stanza_set_ns(carbons_enable, STANZA_NS_CARBONS); - xmpp_stanza_add_child(iq, carbon_enable); + xmpp_stanza_add_child(iq, carbons_enable); + + return iq; +} + +xmpp_stanza_t * +stanza_disable_carbons(xmpp_ctx_t *ctx){ + xmpp_stanza_t *iq = xmpp_stanza_new(ctx); + char *id = create_unique_id(NULL); + + xmpp_stanza_set_name(iq, STANZA_NAME_IQ); + xmpp_stanza_set_type(iq, STANZA_TYPE_SET); + xmpp_stanza_set_id(iq, id); + free(id); + + xmpp_stanza_t *carbons_disable = xmpp_stanza_new(ctx); + xmpp_stanza_set_name(carbons_disable, STANZA_NAME_DISABLE); + xmpp_stanza_set_ns(carbons_disable, STANZA_NS_CARBONS); + + xmpp_stanza_add_child(iq, carbons_disable); return iq; } diff --git a/src/xmpp/stanza.h b/src/xmpp/stanza.h index 0c5a2b01..e4f3ce57 100644 --- a/src/xmpp/stanza.h +++ b/src/xmpp/stanza.h @@ -78,6 +78,7 @@ #define STANZA_NAME_DESTROY "destroy" #define STANZA_NAME_ACTOR "actor" #define STANZA_NAME_ENABLE "enable" +#define STANZA_NAME_DISABLE "disable" // error conditions #define STANZA_NAME_BAD_REQUEST "bad-request" @@ -183,6 +184,8 @@ xmpp_stanza_t* stanza_create_bookmarks_storage_request(xmpp_ctx_t *ctx); xmpp_stanza_t * stanza_enable_carbons(xmpp_ctx_t *ctx); +xmpp_stanza_t * stanza_disable_carbons(xmpp_ctx_t *ctx); + xmpp_stanza_t* stanza_create_chat_state(xmpp_ctx_t *ctx, const char * const fulljid, const char * const state); diff --git a/src/xmpp/xmpp.h b/src/xmpp/xmpp.h index 41355e30..1fc32665 100644 --- a/src/xmpp/xmpp.h +++ b/src/xmpp/xmpp.h @@ -173,6 +173,7 @@ gboolean presence_sub_request_exists(const char * const bare_jid); // iq functions void iq_enable_carbons(); +void iq_disable_carbons(); void iq_send_software_version(const char * const fulljid); void iq_room_list_request(gchar *conferencejid); void iq_disco_info_request(gchar *jid); From a89e04b9d5ef8b65181ddcd1bc3c3ad261406e1a Mon Sep 17 00:00:00 2001 From: Olivier LE MOAL Date: Tue, 3 Feb 2015 15:48:19 +0100 Subject: [PATCH 036/252] Fix help for message carbons --- src/command/command.c | 3 +-- src/config/preferences.c | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index f44a21f5..d22786af 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -864,8 +864,7 @@ static struct cmd_t command_defs[] = { "/carbons on|off", "---------------", "Enable or disable message carbons.", - "", - "Example : /carbons on", + "The message carbons feature ensures that both sides of all conversations are shared with all the user's clients that implement this protocol.", NULL } } }, { "/reconnect", diff --git a/src/config/preferences.c b/src/config/preferences.c index 47ef9391..7753ad71 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -701,7 +701,7 @@ _get_default_boolean(preference_t pref) case PREF_OCCUPANTS: case PREF_MUC_PRIVILEGES: case PREF_PRESENCE: - case PREF_WRAP: + case PREF_WRAP: case PREF_INPBLOCK_DYNAMIC: return TRUE; default: From 62c1a59f388a55d6a4002e29b03d477262cbbb2d Mon Sep 17 00:00:00 2001 From: Olivier LE MOAL Date: Tue, 3 Feb 2015 18:19:04 +0100 Subject: [PATCH 037/252] Add /carbons in /help settings --- src/command/commands.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/command/commands.c b/src/command/commands.c index 477471d5..29615913 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -730,7 +730,7 @@ cmd_help(gchar **args, struct cmd_help_t help) } else if (strcmp(args[0], "settings") == 0) { gchar *filter[] = { "/account", "/autoaway", "/autoping", "/autoconnect", "/beep", - "/chlog", "/flash", "/gone", "/grlog", "/history", "/intype", + "/carbons", "/chlog", "/flash", "/gone", "/grlog", "/history", "/intype", "/log", "/mouse", "/notify", "/outtype", "/prefs", "/priority", "/reconnect", "/roster", "/splash", "/states", "/statuses", "/theme", "/titlebar", "/vercheck", "/privileges", "/occupants", "/presence", "/wrap" }; From ecfc2a3904c6e2bb4053df42203a359bab1d51be Mon Sep 17 00:00:00 2001 From: Olivier LE MOAL Date: Tue, 3 Feb 2015 18:52:31 +0100 Subject: [PATCH 038/252] Add declarations to tests headers --- tests/ui/stub_ui.c | 1 + tests/xmpp/stub_xmpp.c | 2 ++ 2 files changed, 3 insertions(+) diff --git a/tests/ui/stub_ui.c b/tests/ui/stub_ui.c index 51b82d42..fe650921 100644 --- a/tests/ui/stub_ui.c +++ b/tests/ui/stub_ui.c @@ -457,6 +457,7 @@ void cons_outtype_setting(void) {} void cons_intype_setting(void) {} void cons_gone_setting(void) {} void cons_history_setting(void) {} +void cons_carbons_setting(void) {} void cons_log_setting(void) {} void cons_chlog_setting(void) {} void cons_grlog_setting(void) {} diff --git a/tests/xmpp/stub_xmpp.c b/tests/xmpp/stub_xmpp.c index 281857f0..02c0acf8 100644 --- a/tests/xmpp/stub_xmpp.c +++ b/tests/xmpp/stub_xmpp.c @@ -119,6 +119,8 @@ gboolean presence_sub_request_exists(const char * const bare_jid) } // iq functions +void iq_disable_carbons(); +void iq_enable_carbons(); void iq_send_software_version(const char * const fulljid) {} void iq_room_list_request(gchar *conferencejid) From 89f472512f3ea88337bcfbee51431f1f7a1934b9 Mon Sep 17 00:00:00 2001 From: Olivier LE MOAL Date: Tue, 3 Feb 2015 19:09:37 +0100 Subject: [PATCH 039/252] Fix stub --- tests/xmpp/stub_xmpp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/xmpp/stub_xmpp.c b/tests/xmpp/stub_xmpp.c index 02c0acf8..dc9a258e 100644 --- a/tests/xmpp/stub_xmpp.c +++ b/tests/xmpp/stub_xmpp.c @@ -119,8 +119,8 @@ gboolean presence_sub_request_exists(const char * const bare_jid) } // iq functions -void iq_disable_carbons(); -void iq_enable_carbons(); +void iq_disable_carbons() {}; +void iq_enable_carbons() {}; void iq_send_software_version(const char * const fulljid) {} void iq_room_list_request(gchar *conferencejid) From 836fdd2eb1fdba1dab6bd2b93ad65deb64185dd5 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 3 Feb 2015 21:04:51 +0000 Subject: [PATCH 040/252] Remove state passed to wide char len check --- src/ui/inputwin.c | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index 02278adf..9321706a 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -334,26 +334,6 @@ inp_win_resize(void) _inp_win_update_virtual(); } -static int -offset_to_col(char *str, int offset) -{ - int i = 0; - int col = 0; - mbstate_t internal; - - while (i != offset && str[i] != '\n') { - gunichar uni = g_utf8_get_char(&str[i]); - size_t ch_len = mbrlen(&str[i], 4, &internal); - i += ch_len; - col++; - if (g_unichar_iswide(uni)) { - col++; - } - } - - return col; -} - void inp_nonblocking(gboolean reset) { @@ -406,6 +386,25 @@ inp_win_handle_scroll(void) } } +int +offset_to_col(char *str, int offset) +{ + int i = 0; + int col = 0; + + while (i < offset && str[i] != '\0') { + gunichar uni = g_utf8_get_char(&str[i]); + size_t ch_len = mbrlen(&str[i], 4, NULL); + i += ch_len; + col++; + if (g_unichar_iswide(uni)) { + col++; + } + } + + return col; +} + void inp_write(char *line, int offset) { @@ -437,7 +436,6 @@ inp_readline(void) } ui_reset_idle_time(); - cons_show(""); inp_write(rl_line_buffer, rl_point); inp_nonblocking(TRUE); } else { From b76501f0bc908cbbb7850adf1e9e49eed95b0d31 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 3 Feb 2015 21:08:34 +0000 Subject: [PATCH 041/252] Removed mbstate_t use --- src/ui/window.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/ui/window.c b/src/ui/window.c index 37da8e9d..46d2e85c 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -1011,9 +1011,8 @@ _win_print_wrapped(WINDOW *win, const char * const message) } else { // get word wordi = 0; - mbstate_t internal; while (*curr_ch != ' ' && *curr_ch != '\n' && *curr_ch != '\0') { - size_t ch_len = mbrlen(curr_ch, 4, &internal); + size_t ch_len = mbrlen(curr_ch, 4, NULL); int offset = 0; while (offset < ch_len) { word[wordi++] = curr_ch[offset++]; From 82ddbf332d65ce56f4152915060ff7241bfbe7b9 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 3 Feb 2015 21:38:48 +0000 Subject: [PATCH 042/252] Added OSX readline keyseq bindings --- configure.ac | 2 ++ src/ui/inputwin.c | 13 +++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index 59d7f82a..77d2a7a0 100644 --- a/configure.ac +++ b/configure.ac @@ -34,6 +34,8 @@ AC_DEFINE_UNQUOTED([PACKAGE_STATUS], ["$PACKAGE_STATUS"], [Status of this build] AS_IF([test "x$PLATFORM" = xcygwin], [AC_DEFINE([PLATFORM_CYGWIN], [1], [Cygwin])]) +AS_IF([test "x$PLATFORM" = xosx], + [AC_DEFINE([PLATFORM_OSX], [1], [OSx])]) ### Options AC_ARG_ENABLE([notifications], diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index 9321706a..d0d0dfe6 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -276,14 +276,19 @@ startup_hook(void) rl_bind_keyseq("\\e[20~", win9_handler); rl_bind_keyseq("\\e[21~", win0_handler); +#ifdef PLATFORM_OSX + rl_bind_keyseq("\\e[1;9D", altleft_handler); + rl_bind_keyseq("\\e[1;9C", altright_handler); + rl_bind_keyseq("\\e\\e[5~", altpageup_handler); + rl_bind_keyseq("\\e\\e[6~", altpagedown_handler); +#else rl_bind_keyseq("\\e[1;3D", altleft_handler); rl_bind_keyseq("\\e[1;3C", altright_handler); - - rl_bind_keyseq("\\e[5~", pageup_handler); - rl_bind_keyseq("\\e[6~", pagedown_handler); - rl_bind_keyseq("\\e[5;3~", altpageup_handler); rl_bind_keyseq("\\e[6;3~", altpagedown_handler); +#endif + rl_bind_keyseq("\\e[5~", pageup_handler); + rl_bind_keyseq("\\e[6~", pagedown_handler); rl_bind_key('\t', tab_handler); From f80f79e0b54ec24bd0491a97733b159b5f9113cf Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 3 Feb 2015 22:04:30 +0000 Subject: [PATCH 043/252] Added configure conditions for OSX brew installed readline --- configure.ac | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/configure.ac b/configure.ac index 77d2a7a0..19c9b984 100644 --- a/configure.ac +++ b/configure.ac @@ -135,8 +135,8 @@ PKG_CHECK_MODULES([glib], [glib-2.0 >= 2.26], [], [AC_MSG_ERROR([glib 2.26 or higher is required for profanity])]) PKG_CHECK_MODULES([curl], [libcurl], [], [AC_MSG_ERROR([libcurl is required for profanity])]) -###AC_CHECK_LIB([readline], [main], [], -### [AC_MSG_ERROR([libreadline is required for profanity])]) +AC_CHECK_LIB([readline], [main], [], + [AC_MSG_ERROR([libreadline is required for profanity])]) AS_IF([test "x$PLATFORM" = xosx], [LIBS="-lcurl $LIBS"]) @@ -236,10 +236,12 @@ AM_CPPFLAGS="$AM_CPPFLAGS $glib_CFLAGS $curl_CFLAGS $libnotify_CFLAGS" AM_CPPFLAGS="$AM_CPPFLAGS -DTHEMES_PATH=\"\\\"$THEMES_PATH\\\"\"" LIBS="$glib_LIBS $curl_LIBS $libnotify_LIBS $LIBS" -LIBS="-lreadline $LIBS" -AM_CPPFLAGS="-I/usr/local/opt/readline/include $AM_CPPFLAGS" -AM_LDFLAGS="-L/usr/local/opt/readline/lib $AM_LDFLAGS" -AC_SUBST(AM_LDFLAGS) +### Use brew installed gnu readline +AS_IF([test "x$PLATFORM" = xosx], [ + LIBS="-lreadline $LIBS" + AM_CPPFLAGS="-I/usr/local/opt/readline/include $AM_CPPFLAGS" + AM_LDFLAGS="-L/usr/local/opt/readline/lib $AM_LDFLAGS" + AC_SUBST(AM_LDFLAGS)]) AC_SUBST(AM_CFLAGS) AC_SUBST(AM_CPPFLAGS) From af345b6700f37ae190985c4e27f5ba01931da63e Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 3 Feb 2015 22:24:47 +0000 Subject: [PATCH 044/252] Updated navigation help --- src/ui/console.c | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/src/ui/console.c b/src/ui/console.c index cdf5d1b8..579d9c49 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -1419,27 +1419,10 @@ cons_navigation_help(void) cons_show(""); cons_show("Navigation:"); cons_show(""); - cons_show("Alt-1 : This console window."); - cons_show("F1 : This console window."); - cons_show("Alt-2..Alt-0 : Chat windows."); - cons_show("F2..F10 : Chat windows."); + cons_show("Alt-1..Alt-0, F1..F10 : Choose window."); cons_show("Alt-LEFT, Alt-RIGHT : Previous/next chat window"); - cons_show("UP, DOWN : Navigate input history."); - cons_show("Ctrl-n, Ctrl-p : Navigate input history."); - cons_show("LEFT, RIGHT, HOME, END : Move cursor."); - cons_show("Ctrl-b, Ctrl-f, Ctrl-a, Ctrl-e : Move cursor."); - cons_show("Ctrl-LEFT, Ctrl-RIGHT : Jump word."); - cons_show("Ctrl-w : Delete previous word."); - cons_show("Alt-Backspace : Delete previous word."); - cons_show("Backspace : Delete previous character."); - cons_show("DEL : Delete next character."); - cons_show("Ctrl-d : Delete next character."); - cons_show("ESC : Clear current input."); - cons_show("Ctrl-u : Delete all previous characters."); - cons_show("TAB : Autocomplete."); - cons_show("PAGE UP, PAGE DOWN : Page the main window."); - cons_show("Shift-UP, Shift-DOWN : Page occupants/roster panel."); - cons_show("Ctrl-UP, Ctrl-DOWN : Page occupants/roster panel."); + cons_show("PAGEUP, PAGEDOWN : Page the main window."); + cons_show("Alt-PAGEUP, Alt-PAGEDOWN : Page occupants/roster panel."); cons_show(""); cons_alert(); From 8b58eb68d302b6b7c2c6e6319daf8cb064c38d54 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 3 Feb 2015 23:07:15 +0000 Subject: [PATCH 045/252] Tidied inputwin.c --- src/ui/inputwin.c | 636 ++++++++++++++++++++++++---------------------- 1 file changed, 332 insertions(+), 304 deletions(-) diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index d0d0dfe6..f9e123c5 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -65,6 +65,7 @@ #include "xmpp/xmpp.h" static WINDOW *inp_win; +static int pad_start = 0; static struct timeval p_rl_timeout; static gint inp_timeout = 0; @@ -74,226 +75,33 @@ static fd_set fds; static int r; static gboolean cmd_result = TRUE; -static int pad_start = 0; - static void _inp_win_update_virtual(void); +static int _inp_printable(const wint_t ch); +static void _inp_win_handle_scroll(void); +static void _inp_resize_signal_handler(int signal); +static int _inp_offset_to_col(char *str, int offset); +static void _inp_write(char *line, int offset); -static int -_printable(const wint_t ch) -{ - char bytes[MB_CUR_MAX+1]; - size_t utf_len = wcrtomb(bytes, ch, NULL); - bytes[utf_len] = '\0'; - gunichar unichar = g_utf8_get_char(bytes); - - return g_unichar_isprint(unichar) && (ch != KEY_MOUSE); -} - -static void -cb_linehandler(char *line) -{ - if (line && *line) { - add_history(line); - } - cmd_result = cmd_process_input(line); - free(line); -} - -int -prof_rl_getc(FILE *filein) -{ - int ch = rl_getc(filein); - if (_printable(ch)) { - cmd_reset_autocomplete(); - } - return ch; -} - -void -resize_signal_handler(int signal) -{ - ui_resize(); -} - -int -tab_handler(int count, int key) -{ - if (rl_point != rl_end || !rl_line_buffer) { - return 0; - } - - if ((strncmp(rl_line_buffer, "/", 1) != 0) && (ui_current_win_type() == WIN_MUC)) { - char *result = muc_autocomplete(rl_line_buffer); - if (result) { - rl_replace_line(result, 0); - rl_point = rl_end; - } - } else if (strncmp(rl_line_buffer, "/", 1) == 0) { - char *result = cmd_autocomplete(rl_line_buffer); - if (result) { - rl_replace_line(result, 0); - rl_point = rl_end; - } - } - - return 0; -} - -int -win1_handler(int count, int key) -{ - ui_switch_win(1); - return 0; -} - -int -win2_handler(int count, int key) -{ - ui_switch_win(2); - return 0; -} - -int -win3_handler(int count, int key) -{ - ui_switch_win(3); - return 0; -} - -int -win4_handler(int count, int key) -{ - ui_switch_win(4); - return 0; -} - -int -win5_handler(int count, int key) -{ - ui_switch_win(5); - return 0; -} - -int -win6_handler(int count, int key) -{ - ui_switch_win(6); - return 0; -} - -int -win7_handler(int count, int key) -{ - ui_switch_win(7); - return 0; -} - -int -win8_handler(int count, int key) -{ - ui_switch_win(8); - return 0; -} - -int -win9_handler(int count, int key) -{ - ui_switch_win(9); - return 0; -} - -int -win0_handler(int count, int key) -{ - ui_switch_win(0); - return 0; -} - -int -altleft_handler(int count, int key) -{ - ui_previous_win(); - return 0; -} - -int -altright_handler(int count, int key) -{ - ui_next_win(); - return 0; -} - -int -pageup_handler(int count, int key) -{ - ui_page_up(); - return 0; -} - -int -pagedown_handler(int count, int key) -{ - ui_page_down(); - return 0; -} - -int -altpageup_handler(int count, int key) -{ - ui_subwin_page_up(); - return 0; -} - -int -altpagedown_handler(int count, int key) -{ - ui_subwin_page_down(); - return 0; -} - -int -startup_hook(void) -{ - rl_bind_keyseq("\\e1", win1_handler); - rl_bind_keyseq("\\e2", win2_handler); - rl_bind_keyseq("\\e3", win3_handler); - rl_bind_keyseq("\\e4", win4_handler); - rl_bind_keyseq("\\e5", win5_handler); - rl_bind_keyseq("\\e6", win6_handler); - rl_bind_keyseq("\\e7", win7_handler); - rl_bind_keyseq("\\e8", win8_handler); - rl_bind_keyseq("\\e9", win9_handler); - rl_bind_keyseq("\\e0", win0_handler); - - rl_bind_keyseq("\\eOP", win1_handler); - rl_bind_keyseq("\\eOQ", win2_handler); - rl_bind_keyseq("\\eOR", win3_handler); - rl_bind_keyseq("\\eOS", win4_handler); - rl_bind_keyseq("\\e[15~", win5_handler); - rl_bind_keyseq("\\e[17~", win6_handler); - rl_bind_keyseq("\\e[18~", win7_handler); - rl_bind_keyseq("\\e[19~", win8_handler); - rl_bind_keyseq("\\e[20~", win9_handler); - rl_bind_keyseq("\\e[21~", win0_handler); - -#ifdef PLATFORM_OSX - rl_bind_keyseq("\\e[1;9D", altleft_handler); - rl_bind_keyseq("\\e[1;9C", altright_handler); - rl_bind_keyseq("\\e\\e[5~", altpageup_handler); - rl_bind_keyseq("\\e\\e[6~", altpagedown_handler); -#else - rl_bind_keyseq("\\e[1;3D", altleft_handler); - rl_bind_keyseq("\\e[1;3C", altright_handler); - rl_bind_keyseq("\\e[5;3~", altpageup_handler); - rl_bind_keyseq("\\e[6;3~", altpagedown_handler); -#endif - rl_bind_keyseq("\\e[5~", pageup_handler); - rl_bind_keyseq("\\e[6~", pagedown_handler); - - rl_bind_key('\t', tab_handler); - - return 0; -} +static int _inp_rl_getc(FILE *stream); +static void _inp_rl_linehandler(char *line); +static int _inp_rl_tab_handler(int count, int key); +static int _inp_rl_win1_handler(int count, int key); +static int _inp_rl_win2_handler(int count, int key); +static int _inp_rl_win3_handler(int count, int key); +static int _inp_rl_win4_handler(int count, int key); +static int _inp_rl_win5_handler(int count, int key); +static int _inp_rl_win6_handler(int count, int key); +static int _inp_rl_win7_handler(int count, int key); +static int _inp_rl_win8_handler(int count, int key); +static int _inp_rl_win9_handler(int count, int key); +static int _inp_rl_win0_handler(int count, int key); +static int _inp_rl_altleft_handler(int count, int key); +static int _inp_rl_altright_handler(int count, int key); +static int _inp_rl_pageup_handler(int count, int key); +static int _inp_rl_pagedown_handler(int count, int key); +static int _inp_rl_altpageup_handler(int count, int key); +static int _inp_rl_altpagedown_handler(int count, int key); +static int _inp_rl_startup_hook(void); void create_input_window(void) @@ -307,11 +115,11 @@ create_input_window(void) p_rl_timeout.tv_usec = inp_timeout * 1000; rl_readline_name = "profanity"; - rl_getc_function = prof_rl_getc; - rl_startup_hook = startup_hook; - rl_callback_handler_install(NULL, cb_linehandler); + rl_getc_function = _inp_rl_getc; + rl_startup_hook = _inp_rl_startup_hook; + rl_callback_handler_install(NULL, _inp_rl_linehandler); - signal(SIGWINCH, resize_signal_handler); + signal(SIGWINCH, _inp_resize_signal_handler); inp_win = newpad(1, INP_WIN_MAX); wbkgd(inp_win, theme_attrs(THEME_INPUT_TEXT));; @@ -321,6 +129,38 @@ create_input_window(void) _inp_win_update_virtual(); } +gboolean +inp_readline(void) +{ + FD_ZERO(&fds); + FD_SET(fileno(rl_instream), &fds); + r = select(FD_SETSIZE, &fds, NULL, NULL, &p_rl_timeout); + if (r < 0) { + log_error("Readline failed."); + return TRUE; + } + + if (FD_ISSET(fileno(rl_instream), &fds)) { + rl_callback_read_char(); + + if (rl_line_buffer && rl_line_buffer[0] != '/' && rl_line_buffer[0] != '\0' && rl_line_buffer[0] != '\n') { + prof_handle_activity(); + } + + ui_reset_idle_time(); + _inp_write(rl_line_buffer, rl_point); + inp_nonblocking(TRUE); + } else { + inp_nonblocking(FALSE); + prof_handle_idle(); + } + + p_rl_timeout.tv_sec = 0; + p_rl_timeout.tv_usec = inp_timeout * 1000; + + return cmd_result; +} + void inp_win_resize(void) { @@ -371,88 +211,6 @@ inp_block(void) wtimeout(inp_win, -1); } -void -inp_win_handle_scroll(void) -{ - int col = getcurx(inp_win); - int wcols = getmaxx(stdscr); - - // if lost cursor off screen, move contents to show it - if (col >= pad_start + (wcols -2)) { - pad_start = col - (wcols / 2); - if (pad_start < 0) { - pad_start = 0; - } - } else if (col <= pad_start) { - pad_start = pad_start - (wcols / 2); - if (pad_start < 0) { - pad_start = 0; - } - } -} - -int -offset_to_col(char *str, int offset) -{ - int i = 0; - int col = 0; - - while (i < offset && str[i] != '\0') { - gunichar uni = g_utf8_get_char(&str[i]); - size_t ch_len = mbrlen(&str[i], 4, NULL); - i += ch_len; - col++; - if (g_unichar_iswide(uni)) { - col++; - } - } - - return col; -} - -void -inp_write(char *line, int offset) -{ - int col = offset_to_col(line, offset); - werase(inp_win); - waddstr(inp_win, line); - wmove(inp_win, 0, col); - inp_win_handle_scroll(); - - _inp_win_update_virtual(); -} - -gboolean -inp_readline(void) -{ - FD_ZERO(&fds); - FD_SET(fileno(rl_instream), &fds); - r = select(FD_SETSIZE, &fds, NULL, NULL, &p_rl_timeout); - if (r < 0) { - log_error("Readline failed."); - return TRUE; - } - - if (FD_ISSET(fileno(rl_instream), &fds)) { - rl_callback_read_char(); - - if (rl_line_buffer && rl_line_buffer[0] != '/' && rl_line_buffer[0] != '\0' && rl_line_buffer[0] != '\n') { - prof_handle_activity(); - } - - ui_reset_idle_time(); - inp_write(rl_line_buffer, rl_point); - inp_nonblocking(TRUE); - } else { - inp_nonblocking(FALSE); - prof_handle_idle(); - } - - p_rl_timeout.tv_sec = 0; - p_rl_timeout.tv_usec = inp_timeout * 1000; - - return cmd_result; -} void inp_close(void) @@ -497,3 +255,273 @@ _inp_win_update_virtual(void) getmaxyx(stdscr, wrows, wcols); pnoutrefresh(inp_win, 0, pad_start, wrows-1, 0, wrows-1, wcols-2); } + +static void +_inp_write(char *line, int offset) +{ + int col = _inp_offset_to_col(line, offset); + werase(inp_win); + waddstr(inp_win, line); + wmove(inp_win, 0, col); + _inp_win_handle_scroll(); + + _inp_win_update_virtual(); +} + +static int +_inp_printable(const wint_t ch) +{ + char bytes[MB_CUR_MAX+1]; + size_t utf_len = wcrtomb(bytes, ch, NULL); + bytes[utf_len] = '\0'; + gunichar unichar = g_utf8_get_char(bytes); + + return g_unichar_isprint(unichar) && (ch != KEY_MOUSE); +} + +static int +_inp_offset_to_col(char *str, int offset) +{ + int i = 0; + int col = 0; + + while (i < offset && str[i] != '\0') { + gunichar uni = g_utf8_get_char(&str[i]); + size_t ch_len = mbrlen(&str[i], 4, NULL); + i += ch_len; + col++; + if (g_unichar_iswide(uni)) { + col++; + } + } + + return col; +} + +static void +_inp_resize_signal_handler(int signal) +{ + ui_resize(); +} + +static void +_inp_win_handle_scroll(void) +{ + int col = getcurx(inp_win); + int wcols = getmaxx(stdscr); + + // if lost cursor off screen, move contents to show it + if (col >= pad_start + (wcols -2)) { + pad_start = col - (wcols / 2); + if (pad_start < 0) { + pad_start = 0; + } + } else if (col <= pad_start) { + pad_start = pad_start - (wcols / 2); + if (pad_start < 0) { + pad_start = 0; + } + } +} + +// Readline callbacks + +static void +_inp_rl_linehandler(char *line) +{ + if (line && *line) { + add_history(line); + } + cmd_result = cmd_process_input(line); + free(line); +} + +static int +_inp_rl_getc(FILE *stream) +{ + int ch = rl_getc(stream); + if (_inp_printable(ch)) { + cmd_reset_autocomplete(); + } + return ch; +} + +static int +_inp_rl_tab_handler(int count, int key) +{ + if (rl_point != rl_end || !rl_line_buffer) { + return 0; + } + + if ((strncmp(rl_line_buffer, "/", 1) != 0) && (ui_current_win_type() == WIN_MUC)) { + char *result = muc_autocomplete(rl_line_buffer); + if (result) { + rl_replace_line(result, 0); + rl_point = rl_end; + } + } else if (strncmp(rl_line_buffer, "/", 1) == 0) { + char *result = cmd_autocomplete(rl_line_buffer); + if (result) { + rl_replace_line(result, 0); + rl_point = rl_end; + } + } + + return 0; +} + +static int +_inp_rl_win1_handler(int count, int key) +{ + ui_switch_win(1); + return 0; +} + +static int +_inp_rl_win2_handler(int count, int key) +{ + ui_switch_win(2); + return 0; +} + +static int +_inp_rl_win3_handler(int count, int key) +{ + ui_switch_win(3); + return 0; +} + +static int +_inp_rl_win4_handler(int count, int key) +{ + ui_switch_win(4); + return 0; +} + +static int +_inp_rl_win5_handler(int count, int key) +{ + ui_switch_win(5); + return 0; +} + +static int +_inp_rl_win6_handler(int count, int key) +{ + ui_switch_win(6); + return 0; +} + +static int +_inp_rl_win7_handler(int count, int key) +{ + ui_switch_win(7); + return 0; +} + +static int +_inp_rl_win8_handler(int count, int key) +{ + ui_switch_win(8); + return 0; +} + +static int +_inp_rl_win9_handler(int count, int key) +{ + ui_switch_win(9); + return 0; +} + +static int +_inp_rl_win0_handler(int count, int key) +{ + ui_switch_win(0); + return 0; +} + +static int +_inp_rl_altleft_handler(int count, int key) +{ + ui_previous_win(); + return 0; +} + +static int +_inp_rl_altright_handler(int count, int key) +{ + ui_next_win(); + return 0; +} + +static int +_inp_rl_pageup_handler(int count, int key) +{ + ui_page_up(); + return 0; +} + +static int +_inp_rl_pagedown_handler(int count, int key) +{ + ui_page_down(); + return 0; +} + +static int +_inp_rl_altpageup_handler(int count, int key) +{ + ui_subwin_page_up(); + return 0; +} + +static int +_inp_rl_altpagedown_handler(int count, int key) +{ + ui_subwin_page_down(); + return 0; +} + +static int +_inp_rl_startup_hook(void) +{ + rl_bind_keyseq("\\e1", _inp_rl_win1_handler); + rl_bind_keyseq("\\e2", _inp_rl_win2_handler); + rl_bind_keyseq("\\e3", _inp_rl_win3_handler); + rl_bind_keyseq("\\e4", _inp_rl_win4_handler); + rl_bind_keyseq("\\e5", _inp_rl_win5_handler); + rl_bind_keyseq("\\e6", _inp_rl_win6_handler); + rl_bind_keyseq("\\e7", _inp_rl_win7_handler); + rl_bind_keyseq("\\e8", _inp_rl_win8_handler); + rl_bind_keyseq("\\e9", _inp_rl_win9_handler); + rl_bind_keyseq("\\e0", _inp_rl_win0_handler); + + rl_bind_keyseq("\\eOP", _inp_rl_win1_handler); + rl_bind_keyseq("\\eOQ", _inp_rl_win2_handler); + rl_bind_keyseq("\\eOR", _inp_rl_win3_handler); + rl_bind_keyseq("\\eOS", _inp_rl_win4_handler); + rl_bind_keyseq("\\e[15~", _inp_rl_win5_handler); + rl_bind_keyseq("\\e[17~", _inp_rl_win6_handler); + rl_bind_keyseq("\\e[18~", _inp_rl_win7_handler); + rl_bind_keyseq("\\e[19~", _inp_rl_win8_handler); + rl_bind_keyseq("\\e[20~", _inp_rl_win9_handler); + rl_bind_keyseq("\\e[21~", _inp_rl_win0_handler); + +#ifdef PLATFORM_OSX + rl_bind_keyseq("\\e[1;9D", _inp_rl_altleft_handler); + rl_bind_keyseq("\\e[1;9C", _inp_rl_altright_handler); + rl_bind_keyseq("\\e\\e[5~", _inp_rl_altpageup_handler); + rl_bind_keyseq("\\e\\e[6~", _inp_rl_altpagedown_handler); +#else + rl_bind_keyseq("\\e[1;3D", _inp_rl_altleft_handler); + rl_bind_keyseq("\\e[1;3C", _inp_rl_altright_handler); + rl_bind_keyseq("\\e[5;3~", _inp_rl_altpageup_handler); + rl_bind_keyseq("\\e[6;3~", _inp_rl_altpagedown_handler); +#endif + rl_bind_keyseq("\\e[5~", _inp_rl_pageup_handler); + rl_bind_keyseq("\\e[6~", _inp_rl_pagedown_handler); + + rl_bind_key('\t', _inp_rl_tab_handler); + + return 0; +} \ No newline at end of file From 7ab301869f919ef815c7dbb024a7b19ceaec671f Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 3 Feb 2015 23:27:06 +0000 Subject: [PATCH 046/252] Moved readline startup hook --- src/ui/inputwin.c | 88 +++++++++++++++++++++++------------------------ 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index f9e123c5..0ee1d721 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -326,6 +326,50 @@ _inp_win_handle_scroll(void) // Readline callbacks +static int +_inp_rl_startup_hook(void) +{ + rl_bind_keyseq("\\e1", _inp_rl_win1_handler); + rl_bind_keyseq("\\e2", _inp_rl_win2_handler); + rl_bind_keyseq("\\e3", _inp_rl_win3_handler); + rl_bind_keyseq("\\e4", _inp_rl_win4_handler); + rl_bind_keyseq("\\e5", _inp_rl_win5_handler); + rl_bind_keyseq("\\e6", _inp_rl_win6_handler); + rl_bind_keyseq("\\e7", _inp_rl_win7_handler); + rl_bind_keyseq("\\e8", _inp_rl_win8_handler); + rl_bind_keyseq("\\e9", _inp_rl_win9_handler); + rl_bind_keyseq("\\e0", _inp_rl_win0_handler); + + rl_bind_keyseq("\\eOP", _inp_rl_win1_handler); + rl_bind_keyseq("\\eOQ", _inp_rl_win2_handler); + rl_bind_keyseq("\\eOR", _inp_rl_win3_handler); + rl_bind_keyseq("\\eOS", _inp_rl_win4_handler); + rl_bind_keyseq("\\e[15~", _inp_rl_win5_handler); + rl_bind_keyseq("\\e[17~", _inp_rl_win6_handler); + rl_bind_keyseq("\\e[18~", _inp_rl_win7_handler); + rl_bind_keyseq("\\e[19~", _inp_rl_win8_handler); + rl_bind_keyseq("\\e[20~", _inp_rl_win9_handler); + rl_bind_keyseq("\\e[21~", _inp_rl_win0_handler); + +#ifdef PLATFORM_OSX + rl_bind_keyseq("\\e[1;9D", _inp_rl_altleft_handler); + rl_bind_keyseq("\\e[1;9C", _inp_rl_altright_handler); + rl_bind_keyseq("\\e\\e[5~", _inp_rl_altpageup_handler); + rl_bind_keyseq("\\e\\e[6~", _inp_rl_altpagedown_handler); +#else + rl_bind_keyseq("\\e[1;3D", _inp_rl_altleft_handler); + rl_bind_keyseq("\\e[1;3C", _inp_rl_altright_handler); + rl_bind_keyseq("\\e[5;3~", _inp_rl_altpageup_handler); + rl_bind_keyseq("\\e[6;3~", _inp_rl_altpagedown_handler); +#endif + rl_bind_keyseq("\\e[5~", _inp_rl_pageup_handler); + rl_bind_keyseq("\\e[6~", _inp_rl_pagedown_handler); + + rl_bind_key('\t', _inp_rl_tab_handler); + + return 0; +} + static void _inp_rl_linehandler(char *line) { @@ -481,47 +525,3 @@ _inp_rl_altpagedown_handler(int count, int key) ui_subwin_page_down(); return 0; } - -static int -_inp_rl_startup_hook(void) -{ - rl_bind_keyseq("\\e1", _inp_rl_win1_handler); - rl_bind_keyseq("\\e2", _inp_rl_win2_handler); - rl_bind_keyseq("\\e3", _inp_rl_win3_handler); - rl_bind_keyseq("\\e4", _inp_rl_win4_handler); - rl_bind_keyseq("\\e5", _inp_rl_win5_handler); - rl_bind_keyseq("\\e6", _inp_rl_win6_handler); - rl_bind_keyseq("\\e7", _inp_rl_win7_handler); - rl_bind_keyseq("\\e8", _inp_rl_win8_handler); - rl_bind_keyseq("\\e9", _inp_rl_win9_handler); - rl_bind_keyseq("\\e0", _inp_rl_win0_handler); - - rl_bind_keyseq("\\eOP", _inp_rl_win1_handler); - rl_bind_keyseq("\\eOQ", _inp_rl_win2_handler); - rl_bind_keyseq("\\eOR", _inp_rl_win3_handler); - rl_bind_keyseq("\\eOS", _inp_rl_win4_handler); - rl_bind_keyseq("\\e[15~", _inp_rl_win5_handler); - rl_bind_keyseq("\\e[17~", _inp_rl_win6_handler); - rl_bind_keyseq("\\e[18~", _inp_rl_win7_handler); - rl_bind_keyseq("\\e[19~", _inp_rl_win8_handler); - rl_bind_keyseq("\\e[20~", _inp_rl_win9_handler); - rl_bind_keyseq("\\e[21~", _inp_rl_win0_handler); - -#ifdef PLATFORM_OSX - rl_bind_keyseq("\\e[1;9D", _inp_rl_altleft_handler); - rl_bind_keyseq("\\e[1;9C", _inp_rl_altright_handler); - rl_bind_keyseq("\\e\\e[5~", _inp_rl_altpageup_handler); - rl_bind_keyseq("\\e\\e[6~", _inp_rl_altpagedown_handler); -#else - rl_bind_keyseq("\\e[1;3D", _inp_rl_altleft_handler); - rl_bind_keyseq("\\e[1;3C", _inp_rl_altright_handler); - rl_bind_keyseq("\\e[5;3~", _inp_rl_altpageup_handler); - rl_bind_keyseq("\\e[6;3~", _inp_rl_altpagedown_handler); -#endif - rl_bind_keyseq("\\e[5~", _inp_rl_pageup_handler); - rl_bind_keyseq("\\e[6~", _inp_rl_pagedown_handler); - - rl_bind_key('\t', _inp_rl_tab_handler); - - return 0; -} \ No newline at end of file From b2536e91c0a9eac16aee999aa6550b2fc3de6b87 Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 4 Feb 2015 01:04:56 +0000 Subject: [PATCH 047/252] Fixed input timout returning EINVAL on OSX --- src/ui/inputwin.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index 0ee1d721..f29b5318 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -39,6 +39,7 @@ #include #include #include +#include #include #include @@ -111,8 +112,13 @@ create_input_window(void) #else ESCDELAY = 25; #endif - p_rl_timeout.tv_sec = 0; - p_rl_timeout.tv_usec = inp_timeout * 1000; + if (inp_timeout == 1000) { + p_rl_timeout.tv_sec = 1; + p_rl_timeout.tv_usec = 0; + } else { + p_rl_timeout.tv_sec = 0; + p_rl_timeout.tv_usec = inp_timeout * 1000; + } rl_readline_name = "profanity"; rl_getc_function = _inp_rl_getc; @@ -134,9 +140,11 @@ inp_readline(void) { FD_ZERO(&fds); FD_SET(fileno(rl_instream), &fds); + errno = 0; r = select(FD_SETSIZE, &fds, NULL, NULL, &p_rl_timeout); if (r < 0) { - log_error("Readline failed."); + char *err_msg = strerror(errno); + log_error("Readline failed: %s", err_msg); return TRUE; } @@ -155,8 +163,13 @@ inp_readline(void) prof_handle_idle(); } - p_rl_timeout.tv_sec = 0; - p_rl_timeout.tv_usec = inp_timeout * 1000; + if (inp_timeout == 1000) { + p_rl_timeout.tv_sec = 1; + p_rl_timeout.tv_usec = 0; + } else { + p_rl_timeout.tv_sec = 0; + p_rl_timeout.tv_usec = inp_timeout * 1000; + } return cmd_result; } From d64c4a69d76aa982f1631449169e35e6eb77bc89 Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 4 Feb 2015 22:22:18 +0000 Subject: [PATCH 048/252] Removed unused functions from inputwin.c --- src/ui/inputwin.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/ui/inputwin.h b/src/ui/inputwin.h index 081fc56b..a88211c4 100644 --- a/src/ui/inputwin.h +++ b/src/ui/inputwin.h @@ -43,14 +43,10 @@ void create_input_window(void); gboolean inp_readline(void); void inp_nonblocking(gboolean reset); void inp_close(void); -char* inp_read(int *key_type, wint_t *ch); void inp_win_clear(void); void inp_win_resize(void); void inp_put_back(void); -void inp_non_block(gint); void inp_block(void); void inp_get_password(char *passwd); -void inp_history_append(char *inp); -void inp_write(char *line, int offset); #endif From 30180ac8bb125e4cae03c415201f796863d4c80b Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 4 Feb 2015 23:35:28 +0000 Subject: [PATCH 049/252] Move SIGWINCH handling to ui/core.c, ignore signal whilst resizing --- src/profanity.c | 1 + src/ui/core.c | 15 +++++++++++++++ src/ui/inputwin.c | 9 --------- src/ui/ui.h | 1 + tests/ui/stub_ui.c | 1 + 5 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/profanity.c b/src/profanity.c index f3c53003..f863a323 100644 --- a/src/profanity.c +++ b/src/profanity.c @@ -204,6 +204,7 @@ _init(const int disable_tls, char *log_level) signal(SIGPIPE, SIG_IGN); signal(SIGINT, SIG_IGN); signal(SIGTSTP, SIG_IGN); + signal(SIGWINCH, ui_sigwinch_handler); _create_directories(); log_level_t prof_log_level = log_level_from_string(log_level); prefs_load(); diff --git a/src/ui/core.c b/src/ui/core.c index de3bafd2..add80dff 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -79,6 +79,8 @@ static char *win_title; static int inp_size; +static gboolean perform_resize = FALSE; + #ifdef HAVE_LIBXSS static Display *display; #endif @@ -120,6 +122,12 @@ ui_init(void) win_update_virtual(window); } +void +ui_sigwinch_handler(int sig) +{ + perform_resize = TRUE; +} + void ui_update(void) { @@ -137,6 +145,13 @@ ui_update(void) status_bar_update_virtual(); inp_put_back(); doupdate(); + + if (perform_resize) { + signal(SIGWINCH, SIG_IGN); + ui_resize(); + perform_resize = FALSE; + signal(SIGWINCH, ui_sigwinch_handler); + } } void diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index f29b5318..1e78bbcc 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -79,7 +79,6 @@ static gboolean cmd_result = TRUE; static void _inp_win_update_virtual(void); static int _inp_printable(const wint_t ch); static void _inp_win_handle_scroll(void); -static void _inp_resize_signal_handler(int signal); static int _inp_offset_to_col(char *str, int offset); static void _inp_write(char *line, int offset); @@ -125,8 +124,6 @@ create_input_window(void) rl_startup_hook = _inp_rl_startup_hook; rl_callback_handler_install(NULL, _inp_rl_linehandler); - signal(SIGWINCH, _inp_resize_signal_handler); - inp_win = newpad(1, INP_WIN_MAX); wbkgd(inp_win, theme_attrs(THEME_INPUT_TEXT));; keypad(inp_win, TRUE); @@ -311,12 +308,6 @@ _inp_offset_to_col(char *str, int offset) return col; } -static void -_inp_resize_signal_handler(int signal) -{ - ui_resize(); -} - static void _inp_win_handle_scroll(void) { diff --git a/src/ui/ui.h b/src/ui/ui.h index 5008593f..92f570d5 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -62,6 +62,7 @@ GSList* ui_get_chat_recipients(void); gboolean ui_switch_win(const int i); void ui_next_win(void); void ui_previous_win(void); +void ui_sigwinch_handler(int sig); void ui_gone_secure(const char * const barejid, gboolean trusted); void ui_gone_insecure(const char * const barejid); diff --git a/tests/ui/stub_ui.c b/tests/ui/stub_ui.c index d681ec15..e0556ac8 100644 --- a/tests/ui/stub_ui.c +++ b/tests/ui/stub_ui.c @@ -91,6 +91,7 @@ void ui_smp_answer_failure(const char * const barejid) {} void ui_otr_authenticating(const char * const barejid) {} void ui_otr_authetication_waiting(const char * const recipient) {} +void ui_sigwinch_handler(int sig) {} unsigned long ui_get_idle_time(void) { From a70aa0255fc438894e563f80dfb4ab88278a1118 Mon Sep 17 00:00:00 2001 From: James Booth Date: Thu, 5 Feb 2015 00:58:23 +0000 Subject: [PATCH 050/252] Moved command processing to main loop, allow resize during password prompt --- src/profanity.c | 10 ++++++++- src/ui/core.c | 10 ++------- src/ui/inputwin.c | 51 +++++++++++++++++++++++++++++++++------------- src/ui/inputwin.h | 4 ++-- src/ui/ui.h | 2 +- tests/ui/stub_ui.c | 4 ++-- 6 files changed, 53 insertions(+), 28 deletions(-) diff --git a/src/profanity.c b/src/profanity.c index f863a323..86730649 100644 --- a/src/profanity.c +++ b/src/profanity.c @@ -82,10 +82,18 @@ prof_run(const int disable_tls, char *log_level, char *account_name) log_info("Starting main event loop"); + char *line = NULL; while(cont) { _check_autoaway(); - cont = ui_readline(); + line = ui_readline(); + if (line) { + cont = cmd_process_input(line); + free(line); + line = NULL; + } else { + cont = TRUE; + } #ifdef HAVE_LIBOTR otr_poll(); diff --git a/src/ui/core.c b/src/ui/core.c index add80dff..0fde3387 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -198,7 +198,7 @@ ui_close(void) endwin(); } -gboolean +char * ui_readline(void) { return inp_readline(); @@ -2249,15 +2249,9 @@ ui_win_unread(int index) char * ui_ask_password(void) { - char *passwd = malloc(sizeof(char) * (MAX_PASSWORD_SIZE + 1)); status_bar_get_password(); status_bar_update_virtual(); - inp_block(); - inp_get_password(passwd); -// inp_non_block(prefs_get_inpblock()); - inp_nonblocking(TRUE); - - return passwd; + return inp_get_password(); } void diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index 1e78bbcc..5f13377a 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -74,7 +74,8 @@ static gint no_input_count = 0; static fd_set fds; static int r; -static gboolean cmd_result = TRUE; +static char *inp_line = NULL; +static gboolean get_password = FALSE; static void _inp_win_update_virtual(void); static int _inp_printable(const wint_t ch); @@ -132,9 +133,11 @@ create_input_window(void) _inp_win_update_virtual(); } -gboolean +char * inp_readline(void) { + free(inp_line); + inp_line = NULL; FD_ZERO(&fds); FD_SET(fileno(rl_instream), &fds); errno = 0; @@ -142,13 +145,16 @@ inp_readline(void) if (r < 0) { char *err_msg = strerror(errno); log_error("Readline failed: %s", err_msg); - return TRUE; + return NULL; } if (FD_ISSET(fileno(rl_instream), &fds)) { rl_callback_read_char(); - if (rl_line_buffer && rl_line_buffer[0] != '/' && rl_line_buffer[0] != '\0' && rl_line_buffer[0] != '\n') { + if (rl_line_buffer && + rl_line_buffer[0] != '/' && + rl_line_buffer[0] != '\0' && + rl_line_buffer[0] != '\n') { prof_handle_activity(); } @@ -168,7 +174,11 @@ inp_readline(void) p_rl_timeout.tv_usec = inp_timeout * 1000; } - return cmd_result; + if (inp_line) { + return strdup(inp_line); + } else { + return NULL; + } } void @@ -213,6 +223,8 @@ inp_nonblocking(gboolean reset) } } } + + log_info("Timeout: %d", inp_timeout); } void @@ -228,19 +240,29 @@ inp_close(void) rl_callback_handler_remove(); } -void -inp_get_password(char *passwd) +char* +inp_get_password(void) { werase(inp_win); wmove(inp_win, 0, 0); pad_start = 0; _inp_win_update_virtual(); doupdate(); - noecho(); - mvwgetnstr(inp_win, 0, 1, passwd, MAX_PASSWORD_SIZE); - wmove(inp_win, 0, 0); - echo(); + char *password = NULL; + get_password = TRUE; + while (!password) { + password = inp_readline(); + ui_update(); + werase(inp_win); + wmove(inp_win, 0, 0); + pad_start = 0; + _inp_win_update_virtual(); + doupdate(); + } + get_password = FALSE; + status_bar_clear(); + return password; } void @@ -378,10 +400,11 @@ static void _inp_rl_linehandler(char *line) { if (line && *line) { - add_history(line); + if (!get_password) { + add_history(line); + } } - cmd_result = cmd_process_input(line); - free(line); + inp_line = line; } static int diff --git a/src/ui/inputwin.h b/src/ui/inputwin.h index a88211c4..b9026863 100644 --- a/src/ui/inputwin.h +++ b/src/ui/inputwin.h @@ -40,13 +40,13 @@ #define INP_WIN_MAX 1000 void create_input_window(void); -gboolean inp_readline(void); +char* inp_readline(void); void inp_nonblocking(gboolean reset); void inp_close(void); void inp_win_clear(void); void inp_win_resize(void); void inp_put_back(void); void inp_block(void); -void inp_get_password(char *passwd); +char* inp_get_password(void); #endif diff --git a/src/ui/ui.h b/src/ui/ui.h index 92f570d5..1062eac1 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -233,7 +233,7 @@ void ui_update_presence(const resource_presence_t resource_presence, void ui_about(void); void ui_statusbar_new(const int win); -gboolean ui_readline(void); +char* ui_readline(void); void ui_input_clear(void); void ui_input_nonblocking(gboolean); void ui_write(char *line, int offset); diff --git a/tests/ui/stub_ui.c b/tests/ui/stub_ui.c index e0556ac8..2d67a543 100644 --- a/tests/ui/stub_ui.c +++ b/tests/ui/stub_ui.c @@ -329,9 +329,9 @@ void ui_update_presence(const resource_presence_t resource_presence, void ui_about(void) {} void ui_statusbar_new(const int win) {} -gboolean ui_readline(void) +char* ui_readline(void) { - return TRUE; + return NULL; } void ui_inp_history_append(char *inp) {} From 113cb6cf9a26fd8518ccfcf07207ddb69f2f2f84 Mon Sep 17 00:00:00 2001 From: James Booth Date: Thu, 5 Feb 2015 01:00:06 +0000 Subject: [PATCH 051/252] Removed debug logging --- src/ui/inputwin.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index 5f13377a..b3216a16 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -223,8 +223,6 @@ inp_nonblocking(gboolean reset) } } } - - log_info("Timeout: %d", inp_timeout); } void From 2e83d23873983303665b2ce25587bdb771f770b5 Mon Sep 17 00:00:00 2001 From: James Booth Date: Fri, 6 Feb 2015 00:20:06 +0000 Subject: [PATCH 052/252] Removed unused function --- src/ui/inputwin.c | 7 ------- src/ui/inputwin.h | 1 - 2 files changed, 8 deletions(-) diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index b3216a16..5ae6656e 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -225,13 +225,6 @@ inp_nonblocking(gboolean reset) } } -void -inp_block(void) -{ - wtimeout(inp_win, -1); -} - - void inp_close(void) { diff --git a/src/ui/inputwin.h b/src/ui/inputwin.h index b9026863..91cbb0b2 100644 --- a/src/ui/inputwin.h +++ b/src/ui/inputwin.h @@ -46,7 +46,6 @@ void inp_close(void); void inp_win_clear(void); void inp_win_resize(void); void inp_put_back(void); -void inp_block(void); char* inp_get_password(void); #endif From f08657fa9afee6ea74dfdb9660dd4d23f20ee43f Mon Sep 17 00:00:00 2001 From: James Booth Date: Fri, 6 Feb 2015 14:11:21 +0000 Subject: [PATCH 053/252] Handle home scroll --- src/ui/inputwin.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index 5ae6656e..6f043b31 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -327,8 +327,9 @@ _inp_win_handle_scroll(void) int col = getcurx(inp_win); int wcols = getmaxx(stdscr); - // if lost cursor off screen, move contents to show it - if (col >= pad_start + (wcols -2)) { + if (col == 0) { + pad_start = 0; + } else if (col >= pad_start + (wcols -2)) { pad_start = col - (wcols / 2); if (pad_start < 0) { pad_start = 0; From f447ac418983b94a71afecbd1d9057344adddee1 Mon Sep 17 00:00:00 2001 From: James Booth Date: Fri, 6 Feb 2015 21:39:53 +0000 Subject: [PATCH 054/252] Free win layout --- src/ui/window.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ui/window.c b/src/ui/window.c index dfec5aab..54f1b99f 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -330,6 +330,7 @@ win_free(ProfWin* window) buffer_free(window->layout->buffer); delwin(window->layout->win); } + free(window->layout); if (window->type == WIN_CHAT) { ProfChatWin *chatwin = (ProfChatWin*)window; From 8977c9c721f0d8cf6f25f908f93ec6f6f8196bac Mon Sep 17 00:00:00 2001 From: James Booth Date: Fri, 6 Feb 2015 21:40:35 +0000 Subject: [PATCH 055/252] Removed duplicate time_ac --- src/command/command.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index 7be6603d..9698f0bd 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -1466,10 +1466,6 @@ cmd_init(void) autocomplete_add(time_ac, "seconds"); autocomplete_add(time_ac, "off"); - time_ac = autocomplete_new(); - autocomplete_add(time_ac, "minutes"); - autocomplete_add(time_ac, "seconds"); - resource_ac = autocomplete_new(); autocomplete_add(resource_ac, "set"); autocomplete_add(resource_ac, "off"); From 1e35b76bf9767667c0a2dafb7d016a34ae6cac33 Mon Sep 17 00:00:00 2001 From: James Booth Date: Fri, 6 Feb 2015 21:41:24 +0000 Subject: [PATCH 056/252] Added callgrind.out files to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index be11f141..09d5c04d 100644 --- a/.gitignore +++ b/.gitignore @@ -64,3 +64,4 @@ profanity.workspace m4/ test.sh clean-test.sh +callgrind.out.* From bec95afc8b4ba3d86b0a74d68285042c7c40948e Mon Sep 17 00:00:00 2001 From: James Booth Date: Fri, 6 Feb 2015 22:03:40 +0000 Subject: [PATCH 057/252] Removed strdup passed to autocompleter --- src/contact.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/contact.c b/src/contact.c index f16f1679..943be374 100644 --- a/src/contact.c +++ b/src/contact.c @@ -381,7 +381,7 @@ void p_contact_set_presence(const PContact contact, Resource *resource) { g_hash_table_replace(contact->available_resources, strdup(resource->name), resource); - autocomplete_add(contact->resource_ac, strdup(resource->name)); + autocomplete_add(contact->resource_ac, resource->name); } void From e0dfe4832be53987ea5beb5c39e9985d5bc1aa15 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 8 Feb 2015 00:42:21 +0000 Subject: [PATCH 058/252] Added code to generate HTML command reference for website --- .gitignore | 3 +++ src/command/command.c | 53 +++++++++++++++++++++++++++++++++++++++++++ src/command/command.h | 2 ++ src/main.c | 13 +++++------ 4 files changed, 64 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 09d5c04d..7f15f3c9 100644 --- a/.gitignore +++ b/.gitignore @@ -65,3 +65,6 @@ m4/ test.sh clean-test.sh callgrind.out.* +gen_docs.sh +main_fragment.html +toc_fragment.html diff --git a/src/command/command.c b/src/command/command.c index 9698f0bd..1a673568 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include @@ -2990,3 +2991,55 @@ _account_autocomplete(const char * const input) found = autocomplete_param_with_ac(input, "/account", account_ac, TRUE); return found; } + +static int +_cmp_command(Command *cmd1, Command *cmd2) +{ + return g_strcmp0(cmd1->cmd, cmd2->cmd); +} + +void +command_docgen(void) +{ + GList *cmds = NULL; + unsigned int i; + for (i = 0; i < ARRAY_SIZE(command_defs); i++) { + Command *pcmd = command_defs+i; + cmds = g_list_insert_sorted(cmds, pcmd, (GCompareFunc)_cmp_command); + } + + FILE *toc_fragment = fopen("toc_fragment.html", "w"); + FILE *main_fragment = fopen("main_fragment.html", "w"); + + fputs("
    • \n", toc_fragment); + fputs("
      \n", main_fragment); + + GList *curr = cmds; + while (curr) { + Command *pcmd = curr->data; + + fprintf(toc_fragment, "%s,\n", &pcmd->cmd[1], pcmd->cmd); + + fprintf(main_fragment, "\n", &pcmd->cmd[1]); + fprintf(main_fragment, "

      %s

      \n", pcmd->cmd); + fputs("

      Usage:

      \n", main_fragment); + fprintf(main_fragment, "

      %s

      \n", pcmd->help.usage); + + fputs("

      Details:

      \n", main_fragment); + fputs("

      ", main_fragment);
      +        int i = 2;
      +        while (pcmd->help.long_help[i] != NULL) {
      +            fprintf(main_fragment, "%s\n", pcmd->help.long_help[i++]);
      +        }
      +        fputs("

      \n
      back to top


      \n", main_fragment); + fputs("\n", main_fragment); + + curr = g_list_next(curr); + } + + fputs("
\n", toc_fragment); + + fclose(toc_fragment); + fclose(main_fragment); + g_list_free(cmds); +} \ No newline at end of file diff --git a/src/command/command.h b/src/command/command.h index ffbccfa4..8be1143f 100644 --- a/src/command/command.h +++ b/src/command/command.h @@ -66,4 +66,6 @@ void cmd_history_append(char *inp); char *cmd_history_previous(char *inp); char *cmd_history_next(char *inp); +void command_docgen(void); + #endif diff --git a/src/main.c b/src/main.c index f3b6a17f..7ee5affe 100644 --- a/src/main.c +++ b/src/main.c @@ -40,13 +40,7 @@ #endif #include "profanity.h" - -#ifdef HAVE_LIBOTR -#include "otr/otr.h" -#endif -#include "xmpp/xmpp.h" - -#include "ui/ui.h" +#include "command/command.h" static gboolean disable_tls = FALSE; static gboolean version = FALSE; @@ -56,6 +50,11 @@ static char *account_name = NULL; int main(int argc, char **argv) { + if (argc == 2 && g_strcmp0(argv[1], "docgen") == 0 && g_strcmp0(PACKAGE_STATUS, "development") == 0) { + command_docgen(); + return 0; + } + static GOptionEntry entries[] = { { "version", 'v', 0, G_OPTION_ARG_NONE, &version, "Show version information", NULL }, From 916a3d94517bd227aa48936dc19e7a44fc17dfea Mon Sep 17 00:00:00 2001 From: Christian Storm Date: Sun, 8 Feb 2015 12:15:01 +0100 Subject: [PATCH 059/252] Bind ^L to own clear method to retain ui elements When using readline's standard ^L binding, the screen is completely cleared, including status and title bar. By binding ^L to profanity's clear method, status and title bar are retained. --- src/ui/inputwin.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index 6f043b31..328b92d6 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -86,6 +86,7 @@ static void _inp_write(char *line, int offset); static int _inp_rl_getc(FILE *stream); static void _inp_rl_linehandler(char *line); static int _inp_rl_tab_handler(int count, int key); +static int _inp_rl_clear_handler(int count, int key); static int _inp_rl_win1_handler(int count, int key); static int _inp_rl_win2_handler(int count, int key); static int _inp_rl_win3_handler(int count, int key); @@ -384,6 +385,7 @@ _inp_rl_startup_hook(void) rl_bind_keyseq("\\e[6~", _inp_rl_pagedown_handler); rl_bind_key('\t', _inp_rl_tab_handler); + rl_bind_key(CTRL('L'), _inp_rl_clear_handler); return 0; } @@ -409,6 +411,13 @@ _inp_rl_getc(FILE *stream) return ch; } +static int +_inp_rl_clear_handler(int count, int key) +{ + ui_clear_current(); + return 0; +} + static int _inp_rl_tab_handler(int count, int key) { From 44c5b34a710f7c90b455ec92146530f95e25ab90 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 8 Feb 2015 20:59:51 +0000 Subject: [PATCH 060/252] Moved quote stripper to common, added tests --- src/command/command.c | 29 +++------------------------- src/common.c | 22 ++++++++++++++++++++++ src/common.h | 1 + tests/test_common.c | 44 +++++++++++++++++++++++++++++++++++++++++++ tests/test_common.h | 6 +++++- tests/testsuite.c | 4 ++++ 6 files changed, 79 insertions(+), 27 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index 4a8c73e9..9f17596b 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -76,8 +76,6 @@ static gboolean _cmd_execute_alias(const char * const inp, gboolean *ran); static char * _cmd_complete_parameters(const char * const input); -static char * _strip_quotes_from_names(const char * const input); - static char * _sub_autocomplete(const char * const input); static char * _notify_autocomplete(const char * const input); static char * _theme_autocomplete(const char * const input); @@ -1970,7 +1968,7 @@ _cmd_complete_parameters(const char * const input) gchar *nick_choices[] = { "/msg", "/info", "/caps", "/status", "/software" } ; // Remove quote character before and after names when doing autocomplete - char *unquoted = _strip_quotes_from_names(input); + char *unquoted = strip_arg_quotes(input); for (i = 0; i < ARRAY_SIZE(nick_choices); i++) { result = autocomplete_param_with_ac(unquoted, nick_choices[i], nick_ac, TRUE); if (result) { @@ -1985,7 +1983,7 @@ _cmd_complete_parameters(const char * const input) } else { gchar *contact_choices[] = { "/msg", "/info", "/status" }; // Remove quote character before and after names when doing autocomplete - char *unquoted = _strip_quotes_from_names(input); + char *unquoted = strip_arg_quotes(input); for (i = 0; i < ARRAY_SIZE(contact_choices); i++) { result = autocomplete_param_with_func(unquoted, contact_choices[i], roster_contact_autocomplete); if (result) { @@ -3052,25 +3050,4 @@ command_docgen(void) fclose(toc_fragment); fclose(main_fragment); g_list_free(cmds); -} - -static char * -_strip_quotes_from_names(const char * const input) { - char *unquoted = strdup(input); - - // Remove starting quote if it exists - if(strchr(unquoted, '"') != NULL) { - if(strchr(unquoted, ' ') + 1 == strchr(unquoted, '"')) { - memmove(strchr(unquoted, '"'), strchr(unquoted, '"')+1, strchr(unquoted, '\0') - strchr(unquoted, '"')); - } - } - - // Remove ending quote if it exists - if(strchr(unquoted, '"') != NULL) { - if(strchr(unquoted, '\0') - 1 == strchr(unquoted, '"')) { - memmove(strchr(unquoted, '"'), strchr(unquoted, '"')+1, strchr(unquoted, '\0') - strchr(unquoted, '"')); - } - } - - return unquoted; -} +} \ No newline at end of file diff --git a/src/common.c b/src/common.c index 7638da31..95deecbb 100644 --- a/src/common.c +++ b/src/common.c @@ -566,3 +566,25 @@ get_file_or_linked(char *loc, char *basedir) return true_loc; } + +char * +strip_arg_quotes(const char * const input) +{ + char *unquoted = strdup(input); + + // Remove starting quote if it exists + if(strchr(unquoted, '"') != NULL) { + if(strchr(unquoted, ' ') + 1 == strchr(unquoted, '"')) { + memmove(strchr(unquoted, '"'), strchr(unquoted, '"')+1, strchr(unquoted, '\0') - strchr(unquoted, '"')); + } + } + + // Remove ending quote if it exists + if(strchr(unquoted, '"') != NULL) { + if(strchr(unquoted, '\0') - 1 == strchr(unquoted, '"')) { + memmove(strchr(unquoted, '"'), strchr(unquoted, '"')+1, strchr(unquoted, '\0') - strchr(unquoted, '"')); + } + } + + return unquoted; +} \ No newline at end of file diff --git a/src/common.h b/src/common.h index 26d4a99a..c22706ec 100644 --- a/src/common.h +++ b/src/common.h @@ -123,5 +123,6 @@ int cmp_win_num(gconstpointer a, gconstpointer b); int get_next_available_win_num(GList *used); char* get_file_or_linked(char *loc, char *basedir); +char * strip_arg_quotes(const char * const input); #endif diff --git a/tests/test_common.c b/tests/test_common.c index 0c4530a0..980f2198 100644 --- a/tests/test_common.c +++ b/tests/test_common.c @@ -587,3 +587,47 @@ void utf8_display_len_all_wide(void **state) assert_int_equal(8, result); } +void strip_quotes_does_nothing_when_no_quoted(void **state) +{ + char *input = "/cmd test string"; + + char *result = strip_arg_quotes(input); + + assert_string_equal("/cmd test string", result); + + free(result); +} + +void strip_quotes_strips_first(void **state) +{ + char *input = "/cmd \"test string"; + + char *result = strip_arg_quotes(input); + + assert_string_equal("/cmd test string", result); + + free(result); +} + +void strip_quotes_strips_last(void **state) +{ + char *input = "/cmd test string\""; + + char *result = strip_arg_quotes(input); + + assert_string_equal("/cmd test string", result); + + free(result); +} + +void strip_quotes_strips_both(void **state) +{ + char *input = "/cmd \"test string\""; + + char *result = strip_arg_quotes(input); + + assert_string_equal("/cmd test string", result); + + free(result); +} + diff --git a/tests/test_common.h b/tests/test_common.h index 1866e73d..b4b98e5a 100644 --- a/tests/test_common.h +++ b/tests/test_common.h @@ -51,4 +51,8 @@ void utf8_display_len_1_non_wide(void **state); void utf8_display_len_1_wide(void **state); void utf8_display_len_non_wide(void **state); void utf8_display_len_wide(void **state); -void utf8_display_len_all_wide(void **state); \ No newline at end of file +void utf8_display_len_all_wide(void **state); +void strip_quotes_does_nothing_when_no_quoted(void **state); +void strip_quotes_strips_first(void **state); +void strip_quotes_strips_last(void **state); +void strip_quotes_strips_both(void **state); diff --git a/tests/testsuite.c b/tests/testsuite.c index cf511c59..ddfb45cd 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -91,6 +91,10 @@ int main(int argc, char* argv[]) { unit_test(utf8_display_len_non_wide), unit_test(utf8_display_len_wide), unit_test(utf8_display_len_all_wide), + unit_test(strip_quotes_does_nothing_when_no_quoted), + unit_test(strip_quotes_strips_first), + unit_test(strip_quotes_strips_last), + unit_test(strip_quotes_strips_both), unit_test(clear_empty), unit_test(reset_after_create), From 268c33e1c6e7ee5a4a26299311289933c66460e2 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 9 Feb 2015 19:50:41 +0000 Subject: [PATCH 061/252] Free resource lists on /account command --- .gitignore | 2 +- src/ui/console.c | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 7f15f3c9..37449348 100644 --- a/.gitignore +++ b/.gitignore @@ -25,7 +25,7 @@ configure.scan stamp-h1 *~ *dirstamp -valgrind.out +valgrind*.out* core bugs/ TODO diff --git a/src/ui/console.c b/src/ui/console.c index cdf5d1b8..2c37c40c 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -717,20 +717,24 @@ cons_show_account(ProfAccount *account) GList *resources = jabber_get_available_resources(); GList *ordered_resources = NULL; - if (resources != NULL) { + GList *curr = resources; + if (curr != NULL) { win_save_println(console, "Resources:"); // sort in order of availabiltiy - while (resources != NULL) { - Resource *resource = resources->data; + while (curr != NULL) { + Resource *resource = curr->data; ordered_resources = g_list_insert_sorted(ordered_resources, resource, (GCompareFunc)resource_compare_availability); - resources = g_list_next(resources); + curr = g_list_next(curr); } } - while (ordered_resources != NULL) { - Resource *resource = ordered_resources->data; + g_list_free(resources); + + curr = ordered_resources; + while (curr != NULL) { + Resource *resource = curr->data; const char *resource_presence = string_from_resource_presence(resource->presence); theme_item_t presence_colour = theme_main_presence_attrs(resource_presence); win_save_vprint(console, '-', NULL, NO_EOL, presence_colour, "", " %s (%d), %s", resource->name, resource->priority, resource_presence); @@ -785,8 +789,9 @@ cons_show_account(ProfAccount *account) caps_destroy(caps); } - ordered_resources = g_list_next(ordered_resources); + curr = g_list_next(curr); } + g_list_free(ordered_resources); } cons_alert(); From 23aaa51a2af836d705a49bde561d9b8431695499 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 9 Feb 2015 19:59:04 +0000 Subject: [PATCH 062/252] Free utf8 substrings for delete word (ctrl-w) --- src/ui/inputwin.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index 85ddc79a..b2d5e420 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -747,6 +747,9 @@ _delete_previous_word(void) input_len_bytes = strlen(start_string)+i; input[input_len_bytes] = '\0'; + g_free(start_string); + g_free(end_string); + _clear_input(); waddstr(inp_win, input); wmove(inp_win, 0, start_del); From 893b58bf4e0f6329ac36caac4408aa1200912e30 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 9 Feb 2015 20:11:51 +0000 Subject: [PATCH 063/252] Use chat_state_free to free chat states --- src/ui/window.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ui/window.c b/src/ui/window.c index 54f1b99f..1cdf2f26 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -336,7 +336,7 @@ win_free(ProfWin* window) ProfChatWin *chatwin = (ProfChatWin*)window; free(chatwin->barejid); free(chatwin->resource_override); - free(chatwin->state); + chat_state_free(chatwin->state); } if (window->type == WIN_MUC) { From aad7b3ed8ac245252e8d400ee79205a196989a11 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 9 Feb 2015 20:15:24 +0000 Subject: [PATCH 064/252] Free GTimer on switch to console --- src/ui/titlebar.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ui/titlebar.c b/src/ui/titlebar.c index 326dbf8b..a3299946 100644 --- a/src/ui/titlebar.c +++ b/src/ui/titlebar.c @@ -109,8 +109,11 @@ void title_bar_console(void) { werase(win); - typing = FALSE; + if (typing_elapsed) { + g_timer_destroy(typing_elapsed); + } typing_elapsed = NULL; + typing = FALSE; _title_bar_draw(); } From 6682f243ce2cbb46a1323bcd5fdf3a672b5a5d00 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 9 Feb 2015 21:21:22 +0000 Subject: [PATCH 065/252] Free theme list after use --- src/command/command.c | 11 ++++++----- src/config/theme.c | 4 +++- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index 9f17596b..f05d2a79 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -1659,7 +1659,7 @@ cmd_reset_autocomplete() autocomplete_reset(autoconnect_ac); autocomplete_reset(theme_ac); if (theme_load_ac != NULL) { - autocomplete_reset(theme_load_ac); + autocomplete_free(theme_load_ac); theme_load_ac = NULL; } autocomplete_reset(account_ac); @@ -2473,11 +2473,12 @@ _theme_autocomplete(const char * const input) if (theme_load_ac == NULL) { theme_load_ac = autocomplete_new(); GSList *themes = theme_list(); - while (themes != NULL) { - autocomplete_add(theme_load_ac, themes->data); - themes = g_slist_next(themes); + GSList *curr = themes; + while (curr != NULL) { + autocomplete_add(theme_load_ac, curr->data); + curr = g_slist_next(curr); } - g_slist_free(themes); + g_slist_free_full(themes, g_free); autocomplete_add(theme_load_ac, "default"); } result = autocomplete_param_with_ac(input, "/theme set", theme_load_ac, TRUE); diff --git a/src/config/theme.c b/src/config/theme.c index a5dbd0dd..26d48091 100644 --- a/src/config/theme.c +++ b/src/config/theme.c @@ -192,7 +192,9 @@ GSList * theme_list(void) { GSList *result = NULL; - _theme_list_dir(_get_themes_dir(), &result); + char *themes_dir = _get_themes_dir(); + _theme_list_dir(themes_dir, &result); + free(themes_dir); #ifdef THEMES_PATH _theme_list_dir(THEMES_PATH, &result); #endif From 50601d4db30431a4da18694f065e922593d9599c Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 9 Feb 2015 21:36:04 +0000 Subject: [PATCH 066/252] Removed strdup calls when creating capabilities --- src/xmpp/capabilities.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/xmpp/capabilities.c b/src/xmpp/capabilities.c index 164313e1..1a9eed74 100644 --- a/src/xmpp/capabilities.c +++ b/src/xmpp/capabilities.c @@ -154,49 +154,49 @@ _caps_by_ver(const char * const ver) char *category = g_key_file_get_string(cache, ver, "category", NULL); if (category) { - new_caps->category = strdup(category); + new_caps->category = category; } else { new_caps->category = NULL; } char *type = g_key_file_get_string(cache, ver, "type", NULL); if (type) { - new_caps->type = strdup(type); + new_caps->type = type; } else { new_caps->type = NULL; } char *name = g_key_file_get_string(cache, ver, "name", NULL); if (name) { - new_caps->name = strdup(name); + new_caps->name = name; } else { new_caps->name = NULL; } char *software = g_key_file_get_string(cache, ver, "software", NULL); if (software) { - new_caps->software = strdup(software); + new_caps->software = software; } else { new_caps->software = NULL; } char *software_version = g_key_file_get_string(cache, ver, "software_version", NULL); if (software_version) { - new_caps->software_version = strdup(software_version); + new_caps->software_version = software_version; } else { new_caps->software_version = NULL; } char *os = g_key_file_get_string(cache, ver, "os", NULL); if (os) { - new_caps->os = strdup(os); + new_caps->os = os; } else { new_caps->os = NULL; } char *os_version = g_key_file_get_string(cache, ver, "os_version", NULL); if (os_version) { - new_caps->os_version = strdup(os_version); + new_caps->os_version = os_version; } else { new_caps->os_version = NULL; } From 1a98f1404bd44579954358aa95dbb3c45c84f3f3 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 9 Feb 2015 21:46:54 +0000 Subject: [PATCH 067/252] Free resource lists --- src/ui/window.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/ui/window.c b/src/ui/window.c index 1cdf2f26..aba2f40a 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -650,8 +650,6 @@ win_show_info(ProfWin *window, PContact contact) const char *name = p_contact_name(contact); const char *presence = p_contact_presence(contact); const char *sub = p_contact_subscription(contact); - GList *resources = p_contact_get_available_resources(contact); - GList *ordered_resources = NULL; GDateTime *last_activity = p_contact_last_activity(contact); theme_item_t presence_colour = theme_main_presence_attrs(presence); @@ -687,20 +685,25 @@ win_show_info(ProfWin *window, PContact contact) g_date_time_unref(now); } + GList *resources = p_contact_get_available_resources(contact); + GList *ordered_resources = NULL; if (resources != NULL) { win_save_print(window, '-', NULL, 0, 0, "", "Resources:"); // sort in order of availabiltiy - while (resources != NULL) { - Resource *resource = resources->data; + GList *curr = resources; + while (curr != NULL) { + Resource *resource = curr->data; ordered_resources = g_list_insert_sorted(ordered_resources, resource, (GCompareFunc)resource_compare_availability); - resources = g_list_next(resources); + curr = g_list_next(curr); } } + g_list_free(resources); - while (ordered_resources != NULL) { - Resource *resource = ordered_resources->data; + GList *curr = ordered_resources; + while (curr != NULL) { + Resource *resource = curr->data; const char *resource_presence = string_from_resource_presence(resource->presence); theme_item_t presence_colour = theme_main_presence_attrs(resource_presence); win_save_vprint(window, '-', NULL, NO_EOL, presence_colour, "", " %s (%d), %s", resource->name, resource->priority, resource_presence); @@ -755,8 +758,9 @@ win_show_info(ProfWin *window, PContact contact) caps_destroy(caps); } - ordered_resources = g_list_next(ordered_resources); + curr = g_list_next(curr); } + g_list_free(ordered_resources); } void From 75f791da8f28f575f9772180f3a31841814fe817 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 9 Feb 2015 21:53:55 +0000 Subject: [PATCH 068/252] Free hash table keys before modifying hash table --- src/ui/windows.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ui/windows.c b/src/ui/windows.c index 5ecada12..5993df19 100644 --- a/src/ui/windows.c +++ b/src/ui/windows.c @@ -408,9 +408,9 @@ wins_new_xmlconsole(void) { GList *keys = g_hash_table_get_keys(windows); int result = get_next_available_win_num(keys); + g_list_free(keys); ProfWin *newwin = win_create_xmlconsole(); g_hash_table_insert(windows, GINT_TO_POINTER(result), newwin); - g_list_free(keys); return newwin; } @@ -419,9 +419,9 @@ wins_new_chat(const char * const barejid) { GList *keys = g_hash_table_get_keys(windows); int result = get_next_available_win_num(keys); + g_list_free(keys); ProfWin *newwin = win_create_chat(barejid); g_hash_table_insert(windows, GINT_TO_POINTER(result), newwin); - g_list_free(keys); return newwin; } @@ -430,9 +430,9 @@ wins_new_muc(const char * const roomjid) { GList *keys = g_hash_table_get_keys(windows); int result = get_next_available_win_num(keys); + g_list_free(keys); ProfWin *newwin = win_create_muc(roomjid); g_hash_table_insert(windows, GINT_TO_POINTER(result), newwin); - g_list_free(keys); return newwin; } @@ -441,9 +441,9 @@ wins_new_muc_config(const char * const roomjid, DataForm *form) { GList *keys = g_hash_table_get_keys(windows); int result = get_next_available_win_num(keys); + g_list_free(keys); ProfWin *newwin = win_create_muc_config(roomjid, form); g_hash_table_insert(windows, GINT_TO_POINTER(result), newwin); - g_list_free(keys); return newwin; } @@ -452,9 +452,9 @@ wins_new_private(const char * const fulljid) { GList *keys = g_hash_table_get_keys(windows); int result = get_next_available_win_num(keys); + g_list_free(keys); ProfWin *newwin = win_create_private(fulljid); g_hash_table_insert(windows, GINT_TO_POINTER(result), newwin); - g_list_free(keys); return newwin; } From 38e6dc0e852b0aac3704827f50719c42869c134d Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 9 Feb 2015 21:59:17 +0000 Subject: [PATCH 069/252] Free expected_node for legacy caps --- src/xmpp/iq.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/xmpp/iq.c b/src/xmpp/iq.c index 7fedf0ed..bc12b780 100644 --- a/src/xmpp/iq.c +++ b/src/xmpp/iq.c @@ -631,6 +631,8 @@ _caps_response_handler_for_jid(xmpp_conn_t *const conn, xmpp_stanza_t * const st Capabilities *capabilities = caps_create(query); caps_add_by_jid(jid, capabilities); + free(jid); + return 0; } @@ -640,10 +642,12 @@ _caps_response_handler_legacy(xmpp_conn_t *const conn, xmpp_stanza_t * const sta { const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID); xmpp_stanza_t *query = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_QUERY); + char *expected_node = (char *)userdata; char *type = xmpp_stanza_get_type(stanza); // ignore non result if ((g_strcmp0(type, "get") == 0) || (g_strcmp0(type, "set") == 0)) { + free(expected_node); return 1; } @@ -656,6 +660,7 @@ _caps_response_handler_legacy(xmpp_conn_t *const conn, xmpp_stanza_t * const sta const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); if (!from) { log_info("No from attribute"); + free(expected_node); return 0; } @@ -664,22 +669,23 @@ _caps_response_handler_legacy(xmpp_conn_t *const conn, xmpp_stanza_t * const sta char *error_message = stanza_get_error_message(stanza); log_warning("Error received for capabilities response from %s: ", from, error_message); free(error_message); + free(expected_node); return 0; } if (query == NULL) { log_warning("No query element found."); + free(expected_node); return 0; } char *node = xmpp_stanza_get_attribute(query, STANZA_ATTR_NODE); if (node == NULL) { log_warning("No node attribute found"); + free(expected_node); return 0; } - char *expected_node = (char *)userdata; - // nodes match if (g_strcmp0(expected_node, node) == 0) { log_info("Legacy capabilities, nodes match %s", node); From a9c69670fa246fefb2095aac1b8cf9581e2cd67c Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 9 Feb 2015 22:03:17 +0000 Subject: [PATCH 070/252] Free filtered lists for who command --- src/command/commands.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/command/commands.c b/src/command/commands.c index 2059c982..6eca1bd1 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -1069,6 +1069,7 @@ _who_roster(gchar **args, struct cmd_help_t help) cons_show_contacts(filtered); } } + g_slist_free(filtered); // unavailable } else if (strcmp("unavailable", presence) == 0) { @@ -1097,6 +1098,7 @@ _who_roster(gchar **args, struct cmd_help_t help) cons_show_contacts(filtered); } } + g_slist_free(filtered); // online, available resources } else if (strcmp("online", presence) == 0) { @@ -1125,6 +1127,7 @@ _who_roster(gchar **args, struct cmd_help_t help) cons_show_contacts(filtered); } } + g_slist_free(filtered); // offline, no available resources } else if (strcmp("offline", presence) == 0) { @@ -1153,6 +1156,7 @@ _who_roster(gchar **args, struct cmd_help_t help) cons_show_contacts(filtered); } } + g_slist_free(filtered); // show specific status } else { @@ -1181,6 +1185,7 @@ _who_roster(gchar **args, struct cmd_help_t help) cons_show_contacts(filtered); } } + g_slist_free(filtered); } g_slist_free(list); From 5c9dd2802a6aefcaa67cbf03a65128b595b587c9 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 9 Feb 2015 22:08:47 +0000 Subject: [PATCH 071/252] Free lists on get muc and private windows --- src/ui/windows.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ui/windows.c b/src/ui/windows.c index 5993df19..3132902f 100644 --- a/src/ui/windows.c +++ b/src/ui/windows.c @@ -132,6 +132,7 @@ wins_get_muc(const char * const roomjid) if (window->type == WIN_MUC) { ProfMucWin *mucwin = (ProfMucWin*)window; if (g_strcmp0(mucwin->roomjid, roomjid) == 0) { + g_list_free(values); return mucwin; } } @@ -153,6 +154,7 @@ wins_get_private(const char * const fulljid) if (window->type == WIN_PRIVATE) { ProfPrivateWin *privatewin = (ProfPrivateWin*)window; if (g_strcmp0(privatewin->fulljid, fulljid) == 0) { + g_list_free(values); return privatewin; } } From 48f9f3b3b0d4e12f55ba5ea2c34695e899916c3d Mon Sep 17 00:00:00 2001 From: Olivier LE MOAL Date: Mon, 2 Feb 2015 11:10:05 +0100 Subject: [PATCH 072/252] Add XEP-0280 support --- src/command/command.c | 9 +++++++++ src/command/commands.c | 18 +++++++++++++++++- src/command/commands.h | 1 + src/config/preferences.c | 3 +++ src/config/preferences.h | 1 + src/server_events.c | 5 +++++ src/server_events.h | 1 + src/ui/console.c | 9 +++++++++ src/ui/ui.h | 1 + src/xmpp/connection.c | 5 +++++ src/xmpp/iq.c | 20 ++++++++++++++++++++ src/xmpp/message.c | 38 ++++++++++++++++++++++++++++++++++++++ src/xmpp/stanza.c | 38 ++++++++++++++++++++++++++++++++++++++ src/xmpp/stanza.h | 8 ++++++++ src/xmpp/xmpp.h | 2 ++ tests/ui/stub_ui.c | 1 + tests/xmpp/stub_xmpp.c | 2 ++ 17 files changed, 161 insertions(+), 1 deletion(-) diff --git a/src/command/command.c b/src/command/command.c index f05d2a79..b4daadcc 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -859,6 +859,15 @@ static struct cmd_t command_defs[] = "shared : Share logs between all instances, accepts 'on' or 'off', defaults to 'on'.", NULL } } }, + { "/carbons", + cmd_carbons, parse_args, 1, 1, &cons_carbons_setting, + { "/carbons on|off", "Message carbons.", + { "/carbons on|off", + "---------------", + "Enable or disable message carbons.", + "The message carbons feature ensures that both sides of all conversations are shared with all the user's clients that implement this protocol.", + NULL } } }, + { "/reconnect", cmd_reconnect, parse_args, 1, 1, &cons_reconnect_setting, { "/reconnect seconds", "Set reconnect interval.", diff --git a/src/command/commands.c b/src/command/commands.c index 6eca1bd1..f6784fb5 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -730,7 +730,7 @@ cmd_help(gchar **args, struct cmd_help_t help) } else if (strcmp(args[0], "settings") == 0) { gchar *filter[] = { "/account", "/autoaway", "/autoping", "/autoconnect", "/beep", - "/chlog", "/flash", "/gone", "/grlog", "/history", "/intype", + "/carbons", "/chlog", "/flash", "/gone", "/grlog", "/history", "/intype", "/log", "/mouse", "/notify", "/outtype", "/prefs", "/priority", "/reconnect", "/roster", "/splash", "/states", "/statuses", "/theme", "/titlebar", "/vercheck", "/privileges", "/occupants", "/presence", "/wrap" }; @@ -3887,6 +3887,22 @@ cmd_history(gchar **args, struct cmd_help_t help) return result; } +gboolean +cmd_carbons(gchar **args, struct cmd_help_t help) +{ + gboolean result = _cmd_set_boolean_preference(args[0], help, + "Carbons message", PREF_CARBONS); + + // enable carbons + if (strcmp(args[0], "on") == 0) { + iq_enable_carbons(); + } + else if (strcmp(args[0], "off") == 0){ + iq_disable_carbons(); + } + return result; +} + gboolean cmd_away(gchar **args, struct cmd_help_t help) { diff --git a/src/command/commands.h b/src/command/commands.h index f4e040a9..1c16d635 100644 --- a/src/command/commands.h +++ b/src/command/commands.h @@ -85,6 +85,7 @@ gboolean cmd_grlog(gchar **args, struct cmd_help_t help); gboolean cmd_group(gchar **args, struct cmd_help_t help); gboolean cmd_help(gchar **args, struct cmd_help_t help); gboolean cmd_history(gchar **args, struct cmd_help_t help); +gboolean cmd_carbons(gchar **args, struct cmd_help_t help); gboolean cmd_info(gchar **args, struct cmd_help_t help); gboolean cmd_intype(gchar **args, struct cmd_help_t help); gboolean cmd_invite(gchar **args, struct cmd_help_t help); diff --git a/src/config/preferences.c b/src/config/preferences.c index 67f12b18..7753ad71 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -558,6 +558,7 @@ _get_group(preference_t pref) return PREF_GROUP_PRESENCE; case PREF_CONNECT_ACCOUNT: case PREF_DEFAULT_ACCOUNT: + case PREF_CARBONS: return PREF_GROUP_CONNECTION; case PREF_OTR_WARN: case PREF_OTR_LOG: @@ -593,6 +594,8 @@ _get_key(preference_t pref) return "intype"; case PREF_HISTORY: return "history"; + case PREF_CARBONS: + return "carbons"; case PREF_MOUSE: return "mouse"; case PREF_OCCUPANTS: diff --git a/src/config/preferences.h b/src/config/preferences.h index 68286f09..aa23e48a 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -59,6 +59,7 @@ typedef enum { PREF_FLASH, PREF_INTYPE, PREF_HISTORY, + PREF_CARBONS, PREF_MOUSE, PREF_OCCUPANTS, PREF_OCCUPANTS_SIZE, diff --git a/src/server_events.c b/src/server_events.c index fbf534ac..bf880a9d 100644 --- a/src/server_events.c +++ b/src/server_events.c @@ -296,6 +296,11 @@ handle_incoming_private_message(char *fulljid, char *message) ui_incoming_private_msg(fulljid, message, NULL); } +void +handle_carbon(char *barejid, char *message){ + ui_outgoing_chat_msg("me", barejid, message); +} + void handle_incoming_message(char *barejid, char *resource, char *message) { diff --git a/src/server_events.h b/src/server_events.h index 6a12dc6e..3ec6a332 100644 --- a/src/server_events.h +++ b/src/server_events.h @@ -101,6 +101,7 @@ void handle_group_remove(const char * const contact, void handle_roster_remove(const char * const barejid); void handle_roster_add(const char * const barejid, const char * const name); void handle_autoping_cancel(void); +void handle_carbon(char *barejid, char *message); void handle_message_error(const char * const from, const char * const type, const char * const err_msg); void handle_presence_error(const char *from, const char * const type, diff --git a/src/ui/console.c b/src/ui/console.c index 2c37c40c..e5383f06 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -1172,6 +1172,15 @@ cons_history_setting(void) cons_show("Chat history (/history) : OFF"); } +void +cons_carbons_setting(void) +{ + if (prefs_get_boolean(PREF_CARBONS)) + cons_show("Message carbons (/carbons) : ON"); + else + cons_show("Message carbons (/carbons) : OFF"); +} + void cons_show_chat_prefs(void) { diff --git a/src/ui/ui.h b/src/ui/ui.h index 99e73b4a..44ff42f4 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -308,6 +308,7 @@ void cons_outtype_setting(void); void cons_intype_setting(void); void cons_gone_setting(void); void cons_history_setting(void); +void cons_carbons_setting(void); void cons_log_setting(void); void cons_chlog_setting(void); void cons_grlog_setting(void); diff --git a/src/xmpp/connection.c b/src/xmpp/connection.c index 915525e4..34fba22d 100644 --- a/src/xmpp/connection.c +++ b/src/xmpp/connection.c @@ -466,6 +466,11 @@ _connection_handler(xmpp_conn_t * const conn, roster_request(); bookmark_request(); + + if (prefs_get_boolean(PREF_CARBONS)){ + iq_enable_carbons(); + } + jabber_conn.conn_status = JABBER_CONNECTED; if (prefs_get_reconnect() != 0) { diff --git a/src/xmpp/iq.c b/src/xmpp/iq.c index bc12b780..90b87676 100644 --- a/src/xmpp/iq.c +++ b/src/xmpp/iq.c @@ -152,6 +152,26 @@ iq_room_list_request(gchar *conferencejid) xmpp_stanza_release(iq); } +void +iq_enable_carbons() +{ + xmpp_conn_t * const conn = connection_get_conn(); + xmpp_ctx_t * const ctx = connection_get_ctx(); + xmpp_stanza_t *iq = stanza_enable_carbons(ctx); + xmpp_send(conn, iq); + xmpp_stanza_release(iq); +} + +void +iq_disable_carbons() +{ + xmpp_conn_t * const conn = connection_get_conn(); + xmpp_ctx_t * const ctx = connection_get_ctx(); + xmpp_stanza_t *iq = stanza_disable_carbons(ctx); + xmpp_send(conn, iq); + xmpp_stanza_release(iq); +} + void iq_disco_info_request(gchar *jid) { diff --git a/src/xmpp/message.c b/src/xmpp/message.c index e96c1a74..4f341f6a 100644 --- a/src/xmpp/message.c +++ b/src/xmpp/message.c @@ -423,6 +423,44 @@ _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, return 1; } + // check if carbon message + xmpp_stanza_t *received = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_CARBONS); + if(received != NULL){ + xmpp_stanza_t *forwarded = xmpp_stanza_get_child_by_ns(received, STANZA_NS_FORWARD); + xmpp_stanza_t *message = xmpp_stanza_get_child_by_name(forwarded, STANZA_NAME_MESSAGE); + + xmpp_ctx_t *ctx = connection_get_ctx(); + + gchar *to = xmpp_stanza_get_attribute(message, STANZA_ATTR_TO); + gchar *from = xmpp_stanza_get_attribute(message, STANZA_ATTR_FROM); + + Jid *jid_from = jid_create(from); + Jid *jid_to = jid_create(to); + Jid *my_jid = jid_create(jabber_get_fulljid()); + + // check for and deal with message + xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(message, STANZA_NAME_BODY); + if (body != NULL) { + char *message = xmpp_stanza_get_text(body); + if (message != NULL) { + // if we are the recipient, treat as standard incoming message + if(g_strcmp0(my_jid->barejid, jid_to->barejid) == 0){ + handle_incoming_message(jid_from->barejid, jid_from->resourcepart, message); + } + // else treat as a sent message + else{ + handle_carbon(jid_to->barejid, message); + } + xmpp_free(ctx, message); + } + } + + jid_destroy(jid_from); + jid_destroy(jid_to); + jid_destroy(my_jid); + return 1; + } + // ignore handled namespaces xmpp_stanza_t *conf = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_CONFERENCE); xmpp_stanza_t *mucuser = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_MUC_USER); diff --git a/src/xmpp/stanza.c b/src/xmpp/stanza.c index 4f1d412d..b0d7de86 100644 --- a/src/xmpp/stanza.c +++ b/src/xmpp/stanza.c @@ -198,6 +198,44 @@ stanza_create_bookmarks_pubsub_add(xmpp_ctx_t *ctx, const char * const jid, } #endif +xmpp_stanza_t * +stanza_enable_carbons(xmpp_ctx_t *ctx){ + xmpp_stanza_t *iq = xmpp_stanza_new(ctx); + char *id = create_unique_id(NULL); + + xmpp_stanza_set_name(iq, STANZA_NAME_IQ); + xmpp_stanza_set_type(iq, STANZA_TYPE_SET); + xmpp_stanza_set_id(iq, id); + free(id); + + xmpp_stanza_t *carbons_enable = xmpp_stanza_new(ctx); + xmpp_stanza_set_name(carbons_enable, STANZA_NAME_ENABLE); + xmpp_stanza_set_ns(carbons_enable, STANZA_NS_CARBONS); + + xmpp_stanza_add_child(iq, carbons_enable); + + return iq; +} + +xmpp_stanza_t * +stanza_disable_carbons(xmpp_ctx_t *ctx){ + xmpp_stanza_t *iq = xmpp_stanza_new(ctx); + char *id = create_unique_id(NULL); + + xmpp_stanza_set_name(iq, STANZA_NAME_IQ); + xmpp_stanza_set_type(iq, STANZA_TYPE_SET); + xmpp_stanza_set_id(iq, id); + free(id); + + xmpp_stanza_t *carbons_disable = xmpp_stanza_new(ctx); + xmpp_stanza_set_name(carbons_disable, STANZA_NAME_DISABLE); + xmpp_stanza_set_ns(carbons_disable, STANZA_NS_CARBONS); + + xmpp_stanza_add_child(iq, carbons_disable); + + return iq; +} + xmpp_stanza_t * stanza_create_chat_state(xmpp_ctx_t *ctx, const char * const fulljid, const char * const state) { diff --git a/src/xmpp/stanza.h b/src/xmpp/stanza.h index 84282401..e4f3ce57 100644 --- a/src/xmpp/stanza.h +++ b/src/xmpp/stanza.h @@ -77,6 +77,8 @@ #define STANZA_NAME_VALUE "value" #define STANZA_NAME_DESTROY "destroy" #define STANZA_NAME_ACTOR "actor" +#define STANZA_NAME_ENABLE "enable" +#define STANZA_NAME_DISABLE "disable" // error conditions #define STANZA_NAME_BAD_REQUEST "bad-request" @@ -154,6 +156,8 @@ #define STANZA_NS_CONFERENCE "jabber:x:conference" #define STANZA_NS_CAPTCHA "urn:xmpp:captcha" #define STANZA_NS_PUBSUB "http://jabber.org/protocol/pubsub" +#define STANZA_NS_CARBONS "urn:xmpp:carbons:2" +#define STANZA_NS_FORWARD "urn:xmpp:forward:0" #define STANZA_DATAFORM_SOFTWARE "urn:xmpp:dataforms:softwareinfo" @@ -178,6 +182,10 @@ typedef enum { xmpp_stanza_t* stanza_create_bookmarks_storage_request(xmpp_ctx_t *ctx); +xmpp_stanza_t * stanza_enable_carbons(xmpp_ctx_t *ctx); + +xmpp_stanza_t * stanza_disable_carbons(xmpp_ctx_t *ctx); + xmpp_stanza_t* stanza_create_chat_state(xmpp_ctx_t *ctx, const char * const fulljid, const char * const state); diff --git a/src/xmpp/xmpp.h b/src/xmpp/xmpp.h index a004a4bf..1fc32665 100644 --- a/src/xmpp/xmpp.h +++ b/src/xmpp/xmpp.h @@ -172,6 +172,8 @@ void presence_update(resource_presence_t status, const char * const msg, gboolean presence_sub_request_exists(const char * const bare_jid); // iq functions +void iq_enable_carbons(); +void iq_disable_carbons(); void iq_send_software_version(const char * const fulljid); void iq_room_list_request(gchar *conferencejid); void iq_disco_info_request(gchar *jid); diff --git a/tests/ui/stub_ui.c b/tests/ui/stub_ui.c index 51b82d42..fe650921 100644 --- a/tests/ui/stub_ui.c +++ b/tests/ui/stub_ui.c @@ -457,6 +457,7 @@ void cons_outtype_setting(void) {} void cons_intype_setting(void) {} void cons_gone_setting(void) {} void cons_history_setting(void) {} +void cons_carbons_setting(void) {} void cons_log_setting(void) {} void cons_chlog_setting(void) {} void cons_grlog_setting(void) {} diff --git a/tests/xmpp/stub_xmpp.c b/tests/xmpp/stub_xmpp.c index 281857f0..dc9a258e 100644 --- a/tests/xmpp/stub_xmpp.c +++ b/tests/xmpp/stub_xmpp.c @@ -119,6 +119,8 @@ gboolean presence_sub_request_exists(const char * const bare_jid) } // iq functions +void iq_disable_carbons() {}; +void iq_enable_carbons() {}; void iq_send_software_version(const char * const fulljid) {} void iq_room_list_request(gchar *conferencejid) From 6bee6cb0fbc7215091cbcbe9d146835a1a5405cb Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 10 Feb 2015 19:30:18 +0000 Subject: [PATCH 073/252] Free string on backspace --- src/ui/inputwin.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index b2d5e420..269d6fa7 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -611,17 +611,17 @@ _handle_backspace(void) } else if (inp_x > 0 && inp_x < display_size) { gchar *start = g_utf8_substring(input, 0, inp_x - 1); gchar *end = g_utf8_substring(input, inp_x, input_len_bytes); - GString *new = g_string_new(start); - g_string_append(new, end); + GString *new_str = g_string_new(start); + g_string_append(new_str, end); - for (input_len_bytes = 0; input_len_bytes < strlen(new->str); input_len_bytes++) { - input[input_len_bytes] = new->str[input_len_bytes]; + for (input_len_bytes = 0; input_len_bytes < strlen(new_str->str); input_len_bytes++) { + input[input_len_bytes] = new_str->str[input_len_bytes]; } input[input_len_bytes] = '\0'; g_free(start); g_free(end); - g_string_free(new, FALSE); + g_string_free(new_str, TRUE); _clear_input(); waddstr(inp_win, input); From 30739ed157efcacd38dee69e35872f8ca9215b2f Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 10 Feb 2015 19:39:18 +0000 Subject: [PATCH 074/252] Free contact list --- src/command/commands.c | 1 + src/ui/console.c | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index 6eca1bd1..af5c8cc8 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -1188,6 +1188,7 @@ _who_roster(gchar **args, struct cmd_help_t help) g_slist_free(filtered); } + list = g_slist_nth(list, 0); g_slist_free(list); } diff --git a/src/ui/console.c b/src/ui/console.c index 2c37c40c..8d6f88b4 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -402,17 +402,18 @@ cons_show_sent_subs(void) GSList *contacts = roster_get_contacts(); PContact contact = NULL; cons_show("Awaiting subscription responses from:"); - while (contacts != NULL) { - contact = (PContact) contacts->data; + GSList *curr = contacts; + while (curr != NULL) { + contact = (PContact) curr->data; if (p_contact_pending_out(contact)) { cons_show(" %s", p_contact_barejid(contact)); } - contacts = g_slist_next(contacts); + curr = g_slist_next(curr); } + g_slist_free(contacts); } else { cons_show("No pending requests sent."); } - cons_alert(); } From 75d766387677c783694df9ccfda9dffbb3bf4ef7 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 10 Feb 2015 19:42:13 +0000 Subject: [PATCH 075/252] Free wins summary list --- src/ui/console.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ui/console.c b/src/ui/console.c index 8d6f88b4..c1bfe450 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -251,6 +251,7 @@ cons_show_wins(void) win_save_println(console, curr->data); curr = g_slist_next(curr); } + g_slist_free_full(window_strings, free); cons_show(""); cons_alert(); From 22b92c751445b14e35b9b0e94479f79d2434c0a5 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 10 Feb 2015 19:53:34 +0000 Subject: [PATCH 076/252] Used g_hash_table_destroy to free logs --- src/log.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/log.c b/src/log.c index c525c3d9..4270a54f 100644 --- a/src/log.c +++ b/src/log.c @@ -236,7 +236,7 @@ chat_log_init(void) { session_started = g_date_time_new_now_local(); log_info("Initialising chat logs"); - logs = g_hash_table_new_full(g_str_hash, (GEqualFunc) _key_equals, g_free, + logs = g_hash_table_new_full(g_str_hash, (GEqualFunc) _key_equals, free, (GDestroyNotify)_free_chat_log); } @@ -244,7 +244,7 @@ void groupchat_log_init(void) { log_info("Initialising groupchat logs"); - groupchat_logs = g_hash_table_new_full(g_str_hash, (GEqualFunc) _key_equals, g_free, + groupchat_logs = g_hash_table_new_full(g_str_hash, (GEqualFunc) _key_equals, free, (GDestroyNotify)_free_chat_log); } @@ -396,8 +396,8 @@ chat_log_get_previous(const gchar * const login, const gchar * const recipient) void chat_log_close(void) { - g_hash_table_remove_all(logs); - g_hash_table_remove_all(groupchat_logs); + g_hash_table_destroy(logs); + g_hash_table_destroy(groupchat_logs); g_date_time_unref(session_started); } From e565812d09cc3b257792cbafbb7ee1aa37d238c3 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 10 Feb 2015 20:30:50 +0000 Subject: [PATCH 077/252] Free roster list --- src/command/commands.c | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index af5c8cc8..3c1a0980 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -1046,12 +1046,13 @@ _who_roster(gchar **args, struct cmd_help_t help) } else if (strcmp("available", presence) == 0) { GSList *filtered = NULL; - while (list != NULL) { - PContact contact = list->data; + GSList *curr = list; + while (curr != NULL) { + PContact contact = curr->data; if (p_contact_is_available(contact)) { filtered = g_slist_append(filtered, contact); } - list = g_slist_next(list); + curr = g_slist_next(curr); } if (group != NULL) { @@ -1075,12 +1076,13 @@ _who_roster(gchar **args, struct cmd_help_t help) } else if (strcmp("unavailable", presence) == 0) { GSList *filtered = NULL; - while (list != NULL) { - PContact contact = list->data; + GSList *curr = list; + while (curr != NULL) { + PContact contact = curr->data; if (!p_contact_is_available(contact)) { filtered = g_slist_append(filtered, contact); } - list = g_slist_next(list); + curr = g_slist_next(curr); } if (group != NULL) { @@ -1104,12 +1106,13 @@ _who_roster(gchar **args, struct cmd_help_t help) } else if (strcmp("online", presence) == 0) { GSList *filtered = NULL; - while (list != NULL) { - PContact contact = list->data; + GSList *curr = list; + while (curr != NULL) { + PContact contact = curr->data; if (p_contact_has_available_resource(contact)) { filtered = g_slist_append(filtered, contact); } - list = g_slist_next(list); + curr = g_slist_next(curr); } if (group != NULL) { @@ -1133,12 +1136,13 @@ _who_roster(gchar **args, struct cmd_help_t help) } else if (strcmp("offline", presence) == 0) { GSList *filtered = NULL; - while (list != NULL) { - PContact contact = list->data; + GSList *curr = list; + while (curr != NULL) { + PContact contact = curr->data; if (!p_contact_has_available_resource(contact)) { filtered = g_slist_append(filtered, contact); } - list = g_slist_next(list); + curr = g_slist_next(curr); } if (group != NULL) { @@ -1162,12 +1166,13 @@ _who_roster(gchar **args, struct cmd_help_t help) } else { GSList *filtered = NULL; - while (list != NULL) { - PContact contact = list->data; + GSList *curr = list; + while (curr != NULL) { + PContact contact = curr->data; if (strcmp(p_contact_presence(contact), presence) == 0) { filtered = g_slist_append(filtered, contact); } - list = g_slist_next(list); + curr = g_slist_next(curr); } if (group != NULL) { @@ -1188,7 +1193,6 @@ _who_roster(gchar **args, struct cmd_help_t help) g_slist_free(filtered); } - list = g_slist_nth(list, 0); g_slist_free(list); } From 6ab937c3e37b71315ab8661c6188ded49dfa182b Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 10 Feb 2015 20:39:57 +0000 Subject: [PATCH 078/252] Copy list when sorting windows for /wins --- src/common.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/common.c b/src/common.c index 95deecbb..3af4f550 100644 --- a/src/common.c +++ b/src/common.c @@ -488,25 +488,34 @@ cmp_win_num(gconstpointer a, gconstpointer b) int get_next_available_win_num(GList *used) { - used = g_list_sort(used, cmp_win_num); // only console used if (g_list_length(used) == 1) { return 2; } else { + GList *sorted = NULL; + GList *curr = used; + while (curr) { + sorted = g_list_insert_sorted(sorted, curr->data, cmp_win_num); + curr = g_list_next(curr); + } + int result = 0; int last_num = 1; - GList *curr = used; + curr = sorted; // skip console curr = g_list_next(curr); while (curr != NULL) { int curr_num = GPOINTER_TO_INT(curr->data); + if (((last_num != 9) && ((last_num + 1) != curr_num)) || ((last_num == 9) && (curr_num != 0))) { result = last_num + 1; if (result == 10) { result = 0; } + g_list_free(sorted); return (result); + } else { last_num = curr_num; if (last_num == 0) { @@ -520,6 +529,7 @@ get_next_available_win_num(GList *used) result = 0; } + g_list_free(sorted); return result; } } From 1e2ef973348a58b0ba58eb020cc91e4f41a1d10e Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 10 Feb 2015 21:26:59 +0000 Subject: [PATCH 079/252] Fixed parameter order for /tiny in private and group chat fixes #502 --- src/command/commands.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index 3c1a0980..9e9191d4 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -3116,11 +3116,11 @@ cmd_tiny(gchar **args, struct cmd_help_t help) #endif } else if (win_type == WIN_PRIVATE) { ProfPrivateWin *privatewin = wins_get_current_private(); - message_send_private(tiny, privatewin->fulljid); + message_send_private(privatewin->fulljid, tiny); ui_outgoing_private_msg("me", privatewin->fulljid, tiny); } else if (win_type == WIN_MUC) { ProfMucWin *mucwin = wins_get_current_muc(); - message_send_groupchat(tiny, mucwin->roomjid); + message_send_groupchat(mucwin->roomjid, tiny); } free(tiny); } else { From b3be26a21406b549426f6c94c91e8b2a6bf32701 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 10 Feb 2015 23:16:09 +0000 Subject: [PATCH 080/252] Updated copyright --- LICENSE.txt | 2 +- docs/profanity.1 | 4 ++-- src/chat_session.c | 2 +- src/chat_session.h | 2 +- src/chat_state.c | 2 +- src/chat_state.h | 2 +- src/command/command.c | 2 +- src/command/command.h | 2 +- src/command/commands.c | 2 +- src/command/commands.h | 2 +- src/common.c | 2 +- src/common.h | 2 +- src/config/account.c | 2 +- src/config/account.h | 2 +- src/config/accounts.c | 2 +- src/config/accounts.h | 2 +- src/config/preferences.c | 2 +- src/config/preferences.h | 2 +- src/config/theme.c | 2 +- src/config/theme.h | 2 +- src/contact.c | 2 +- src/contact.h | 2 +- src/jid.c | 2 +- src/jid.h | 2 +- src/log.c | 2 +- src/log.h | 2 +- src/main.c | 4 ++-- src/muc.c | 2 +- src/muc.h | 2 +- src/otr/otr.c | 2 +- src/otr/otr.h | 2 +- src/otr/otrlib.h | 2 +- src/otr/otrlibv3.c | 2 +- src/otr/otrlibv4.c | 2 +- src/profanity.c | 2 +- src/profanity.h | 2 +- src/resource.c | 2 +- src/resource.h | 2 +- src/roster_list.c | 2 +- src/roster_list.h | 2 +- src/server_events.c | 2 +- src/server_events.h | 2 +- src/tools/autocomplete.c | 2 +- src/tools/autocomplete.h | 2 +- src/tools/history.c | 2 +- src/tools/history.h | 2 +- src/tools/parser.c | 2 +- src/tools/parser.h | 2 +- src/tools/tinyurl.c | 2 +- src/tools/tinyurl.h | 2 +- src/ui/buffer.c | 2 +- src/ui/buffer.h | 2 +- src/ui/console.c | 4 ++-- src/ui/core.c | 2 +- src/ui/inputwin.c | 2 +- src/ui/inputwin.h | 2 +- src/ui/notifier.c | 2 +- src/ui/occupantswin.c | 2 +- src/ui/rosterwin.c | 2 +- src/ui/statusbar.c | 2 +- src/ui/statusbar.h | 2 +- src/ui/titlebar.c | 2 +- src/ui/titlebar.h | 2 +- src/ui/ui.h | 2 +- src/ui/window.c | 2 +- src/ui/window.h | 2 +- src/ui/windows.c | 2 +- src/ui/windows.h | 2 +- src/xmpp/bookmark.c | 2 +- src/xmpp/bookmark.h | 2 +- src/xmpp/capabilities.c | 2 +- src/xmpp/capabilities.h | 2 +- src/xmpp/connection.c | 2 +- src/xmpp/connection.h | 2 +- src/xmpp/form.c | 2 +- src/xmpp/form.h | 2 +- src/xmpp/iq.c | 2 +- src/xmpp/iq.h | 2 +- src/xmpp/message.c | 2 +- src/xmpp/message.h | 2 +- src/xmpp/presence.c | 2 +- src/xmpp/presence.h | 2 +- src/xmpp/roster.c | 2 +- src/xmpp/roster.h | 2 +- src/xmpp/stanza.c | 2 +- src/xmpp/stanza.h | 2 +- src/xmpp/xmpp.h | 2 +- 87 files changed, 90 insertions(+), 90 deletions(-) diff --git a/LICENSE.txt b/LICENSE.txt index 609ce80c..e1990985 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,5 +1,5 @@ Profanity -Copyright (C) 2012 - 2014 James Booth +Copyright (C) 2012 - 2015 James Booth Profanity is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/docs/profanity.1 b/docs/profanity.1 index a65281fb..5b87d381 100644 --- a/docs/profanity.1 +++ b/docs/profanity.1 @@ -1,4 +1,4 @@ -.TH Profanity 1 "March 2014" "Profanity XMPP client" +.TH Profanity 1 "February 2015" "Profanity XMPP client" .SH NAME Profanity \- a simple console based XMPP chat client. .SH SYNOPSIS @@ -62,7 +62,7 @@ or with a Github account by logging issues on the issue tracker at: .PP .SH LICENSE -Copyright (C) 2012 \- 2014 James Booth . +Copyright (C) 2012 \- 2015 James Booth . License GPLv3+: GNU GPL version 3 or later This is free software; you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. diff --git a/src/chat_session.c b/src/chat_session.c index fbe06f76..555452cb 100644 --- a/src/chat_session.c +++ b/src/chat_session.c @@ -1,7 +1,7 @@ /* * chat_session.c * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/chat_session.h b/src/chat_session.h index 585a523b..f51a8341 100644 --- a/src/chat_session.h +++ b/src/chat_session.h @@ -1,7 +1,7 @@ /* * chat_session.h * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/chat_state.c b/src/chat_state.c index 99a83f43..8ddb6f1e 100644 --- a/src/chat_state.c +++ b/src/chat_state.c @@ -1,7 +1,7 @@ /* * chat_state.c * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/chat_state.h b/src/chat_state.h index ba394a56..7f0d8832 100644 --- a/src/chat_state.h +++ b/src/chat_state.h @@ -1,7 +1,7 @@ /* * chat_state.h * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/command/command.c b/src/command/command.c index f05d2a79..e810f8af 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -1,7 +1,7 @@ /* * command.c * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/command/command.h b/src/command/command.h index 8be1143f..b500404b 100644 --- a/src/command/command.h +++ b/src/command/command.h @@ -1,7 +1,7 @@ /* * command.h * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/command/commands.c b/src/command/commands.c index 9e9191d4..63cdedf7 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -1,7 +1,7 @@ /* * commands.c * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/command/commands.h b/src/command/commands.h index f4e040a9..aeb34661 100644 --- a/src/command/commands.h +++ b/src/command/commands.h @@ -1,7 +1,7 @@ /* * commands.h * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/common.c b/src/common.c index 3af4f550..17c74b94 100644 --- a/src/common.c +++ b/src/common.c @@ -1,7 +1,7 @@ /* * common.c * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/common.h b/src/common.h index c22706ec..ea6eeaa2 100644 --- a/src/common.h +++ b/src/common.h @@ -1,7 +1,7 @@ /* * common.h * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/config/account.c b/src/config/account.c index 6df00382..3896286b 100644 --- a/src/config/account.c +++ b/src/config/account.c @@ -1,7 +1,7 @@ /* * account.c * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/config/account.h b/src/config/account.h index ab43234d..c237a19e 100644 --- a/src/config/account.h +++ b/src/config/account.h @@ -1,7 +1,7 @@ /* * account.h * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/config/accounts.c b/src/config/accounts.c index 4d4d47d0..dd0d6eb4 100644 --- a/src/config/accounts.c +++ b/src/config/accounts.c @@ -1,7 +1,7 @@ /* * accounts.c * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/config/accounts.h b/src/config/accounts.h index cbbe88e6..50307b5b 100644 --- a/src/config/accounts.h +++ b/src/config/accounts.h @@ -1,7 +1,7 @@ /* * accounts.h * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/config/preferences.c b/src/config/preferences.c index 67f12b18..11a0b217 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -1,7 +1,7 @@ /* * preferences.c * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/config/preferences.h b/src/config/preferences.h index 68286f09..2a23261f 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -1,7 +1,7 @@ /* * preferences.h * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/config/theme.c b/src/config/theme.c index 26d48091..e9389417 100644 --- a/src/config/theme.c +++ b/src/config/theme.c @@ -1,7 +1,7 @@ /* * theme.c * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/config/theme.h b/src/config/theme.h index a6a580f8..f2e38404 100644 --- a/src/config/theme.h +++ b/src/config/theme.h @@ -1,7 +1,7 @@ /* * theme.h * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/contact.c b/src/contact.c index 943be374..cd7d5d9d 100644 --- a/src/contact.c +++ b/src/contact.c @@ -1,7 +1,7 @@ /* * contact.c * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/contact.h b/src/contact.h index 17a3b210..a08aef43 100644 --- a/src/contact.h +++ b/src/contact.h @@ -1,7 +1,7 @@ /* * contact.h * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/jid.c b/src/jid.c index 690f36ca..d1c25ddb 100644 --- a/src/jid.c +++ b/src/jid.c @@ -1,7 +1,7 @@ /* * jid.c * - * Copyright (C) 2012 -2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/jid.h b/src/jid.h index 64c147f9..6d530c5a 100644 --- a/src/jid.h +++ b/src/jid.h @@ -1,7 +1,7 @@ /* * jid.h * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/log.c b/src/log.c index 4270a54f..004d4dcf 100644 --- a/src/log.c +++ b/src/log.c @@ -1,7 +1,7 @@ /* * log.c * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/log.h b/src/log.h index 8ffc6f22..fdfd6caa 100644 --- a/src/log.h +++ b/src/log.h @@ -1,7 +1,7 @@ /* * log.h * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/main.c b/src/main.c index 7ee5affe..3bb7eeb6 100644 --- a/src/main.c +++ b/src/main.c @@ -1,7 +1,7 @@ /* * main.c * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * @@ -89,7 +89,7 @@ main(int argc, char **argv) g_print("Profanity, version %s\n", PACKAGE_VERSION); } - g_print("Copyright (C) 2012 - 2014 James Booth <%s>.\n", PACKAGE_BUGREPORT); + g_print("Copyright (C) 2012 - 2015 James Booth <%s>.\n", PACKAGE_BUGREPORT); g_print("License GPLv3+: GNU GPL version 3 or later \n"); g_print("\n"); g_print("This is free software; you are free to change and redistribute it.\n"); diff --git a/src/muc.c b/src/muc.c index f50f3879..0d606873 100644 --- a/src/muc.c +++ b/src/muc.c @@ -1,7 +1,7 @@ /* * muc.c * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/muc.h b/src/muc.h index 01f8b44b..16f217d0 100644 --- a/src/muc.h +++ b/src/muc.h @@ -1,7 +1,7 @@ /* * muc.h * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/otr/otr.c b/src/otr/otr.c index bd1c2ce3..7c500e71 100644 --- a/src/otr/otr.c +++ b/src/otr/otr.c @@ -1,7 +1,7 @@ /* * otr.c * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/otr/otr.h b/src/otr/otr.h index 155e287b..58d5c04b 100644 --- a/src/otr/otr.h +++ b/src/otr/otr.h @@ -1,7 +1,7 @@ /* * otr.h * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/otr/otrlib.h b/src/otr/otrlib.h index da1c8547..0310c9e6 100644 --- a/src/otr/otrlib.h +++ b/src/otr/otrlib.h @@ -1,7 +1,7 @@ /* * otrlib.h * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/otr/otrlibv3.c b/src/otr/otrlibv3.c index 77b00660..77b0ee77 100644 --- a/src/otr/otrlibv3.c +++ b/src/otr/otrlibv3.c @@ -1,7 +1,7 @@ /* * otrlibv3.c * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/otr/otrlibv4.c b/src/otr/otrlibv4.c index 62379d0f..e090ead4 100644 --- a/src/otr/otrlibv4.c +++ b/src/otr/otrlibv4.c @@ -1,7 +1,7 @@ /* * otrlibv4.c * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/profanity.c b/src/profanity.c index 13297124..f694ea68 100644 --- a/src/profanity.c +++ b/src/profanity.c @@ -1,7 +1,7 @@ /* * profanity.c * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/profanity.h b/src/profanity.h index f01169f8..269c616a 100644 --- a/src/profanity.h +++ b/src/profanity.h @@ -1,7 +1,7 @@ /* * profanity.h * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/resource.c b/src/resource.c index 844cb1d3..620dd38d 100644 --- a/src/resource.c +++ b/src/resource.c @@ -1,7 +1,7 @@ /* * resource.c * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/resource.h b/src/resource.h index 5c39d969..43bb6d18 100644 --- a/src/resource.h +++ b/src/resource.h @@ -1,7 +1,7 @@ /* * resource.h * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/roster_list.c b/src/roster_list.c index 44d05ff0..4ec5ea4f 100644 --- a/src/roster_list.c +++ b/src/roster_list.c @@ -1,7 +1,7 @@ /* * roster_list.c * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/roster_list.h b/src/roster_list.h index e193085b..6c66d142 100644 --- a/src/roster_list.h +++ b/src/roster_list.h @@ -1,7 +1,7 @@ /* * roster_list.h * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/server_events.c b/src/server_events.c index fbf534ac..206146e9 100644 --- a/src/server_events.c +++ b/src/server_events.c @@ -1,7 +1,7 @@ /* * server_events.c * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/server_events.h b/src/server_events.h index 6a12dc6e..4e04f507 100644 --- a/src/server_events.h +++ b/src/server_events.h @@ -1,7 +1,7 @@ /* * server_events.h * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/tools/autocomplete.c b/src/tools/autocomplete.c index 2623c828..7624f1df 100644 --- a/src/tools/autocomplete.c +++ b/src/tools/autocomplete.c @@ -1,7 +1,7 @@ /* * autocomplete.c * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/tools/autocomplete.h b/src/tools/autocomplete.h index 70cd8f30..c4b94b09 100644 --- a/src/tools/autocomplete.h +++ b/src/tools/autocomplete.h @@ -1,7 +1,7 @@ /* * autocomplete.h * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/tools/history.c b/src/tools/history.c index def10feb..826df693 100644 --- a/src/tools/history.c +++ b/src/tools/history.c @@ -1,7 +1,7 @@ /* * history.c * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/tools/history.h b/src/tools/history.h index 7b334718..4a903cbc 100644 --- a/src/tools/history.h +++ b/src/tools/history.h @@ -1,7 +1,7 @@ /* * history.h * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/tools/parser.c b/src/tools/parser.c index e91b227d..98fc21d4 100644 --- a/src/tools/parser.c +++ b/src/tools/parser.c @@ -1,7 +1,7 @@ /* * parser.c * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/tools/parser.h b/src/tools/parser.h index eeb97df3..34fa55a0 100644 --- a/src/tools/parser.h +++ b/src/tools/parser.h @@ -1,7 +1,7 @@ /* * parser.h * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/tools/tinyurl.c b/src/tools/tinyurl.c index 3addc646..34e8967a 100644 --- a/src/tools/tinyurl.c +++ b/src/tools/tinyurl.c @@ -1,7 +1,7 @@ /* * tinyurl.c * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/tools/tinyurl.h b/src/tools/tinyurl.h index 9557228f..f69570c3 100644 --- a/src/tools/tinyurl.h +++ b/src/tools/tinyurl.h @@ -1,7 +1,7 @@ /* * tinyurl.h * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/ui/buffer.c b/src/ui/buffer.c index 52397b4b..da505867 100644 --- a/src/ui/buffer.c +++ b/src/ui/buffer.c @@ -1,7 +1,7 @@ /* * buffer.c * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/ui/buffer.h b/src/ui/buffer.h index 34d6b04f..5258b8c1 100644 --- a/src/ui/buffer.h +++ b/src/ui/buffer.h @@ -1,7 +1,7 @@ /* * buffer.h * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/ui/console.c b/src/ui/console.c index c1bfe450..01d1c73a 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -1,7 +1,7 @@ /* * console.c * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * @@ -176,7 +176,7 @@ cons_about(void) } } - win_save_vprint(console, '-', NULL, 0, 0, "", "Copyright (C) 2012 - 2014 James Booth <%s>.", PACKAGE_BUGREPORT); + win_save_vprint(console, '-', NULL, 0, 0, "", "Copyright (C) 2012 - 2015 James Booth <%s>.", PACKAGE_BUGREPORT); win_save_println(console, "License GPLv3+: GNU GPL version 3 or later "); win_save_println(console, ""); win_save_println(console, "This is free software; you are free to change and redistribute it."); diff --git a/src/ui/core.c b/src/ui/core.c index 85d5748a..fc6c0ed4 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -1,7 +1,7 @@ /* * core.c * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index 269d6fa7..bc042b3f 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -1,7 +1,7 @@ /* * inputwin.c * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/ui/inputwin.h b/src/ui/inputwin.h index 39fde720..4a2767c2 100644 --- a/src/ui/inputwin.h +++ b/src/ui/inputwin.h @@ -1,7 +1,7 @@ /* * inputwin.c * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/ui/notifier.c b/src/ui/notifier.c index 7ca8f705..693817d6 100644 --- a/src/ui/notifier.c +++ b/src/ui/notifier.c @@ -1,7 +1,7 @@ /* * notifier.c * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/ui/occupantswin.c b/src/ui/occupantswin.c index 429c2fdf..d865eeed 100644 --- a/src/ui/occupantswin.c +++ b/src/ui/occupantswin.c @@ -1,7 +1,7 @@ /* * occupantswin.c * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/ui/rosterwin.c b/src/ui/rosterwin.c index 828ed429..763490c3 100644 --- a/src/ui/rosterwin.c +++ b/src/ui/rosterwin.c @@ -1,7 +1,7 @@ /* * rosterwin.c * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/ui/statusbar.c b/src/ui/statusbar.c index 2ef20913..58f3fc58 100644 --- a/src/ui/statusbar.c +++ b/src/ui/statusbar.c @@ -1,7 +1,7 @@ /* * statusbar.c * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/ui/statusbar.h b/src/ui/statusbar.h index 5c37867b..7d2c5ea0 100644 --- a/src/ui/statusbar.h +++ b/src/ui/statusbar.h @@ -1,7 +1,7 @@ /* * statusbar.h * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/ui/titlebar.c b/src/ui/titlebar.c index a3299946..7b80c889 100644 --- a/src/ui/titlebar.c +++ b/src/ui/titlebar.c @@ -1,7 +1,7 @@ /* * titlebar.c * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/ui/titlebar.h b/src/ui/titlebar.h index 08a56514..66237f86 100644 --- a/src/ui/titlebar.h +++ b/src/ui/titlebar.h @@ -1,7 +1,7 @@ /* * titlebar.h * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/ui/ui.h b/src/ui/ui.h index 99e73b4a..65dabeb5 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -1,7 +1,7 @@ /* * ui.h * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/ui/window.c b/src/ui/window.c index aba2f40a..85cc875c 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -1,7 +1,7 @@ /* * window.c * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/ui/window.h b/src/ui/window.h index fd10a1d7..87a4bb79 100644 --- a/src/ui/window.h +++ b/src/ui/window.h @@ -1,7 +1,7 @@ /* * window.h * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/ui/windows.c b/src/ui/windows.c index 3132902f..dba5290c 100644 --- a/src/ui/windows.c +++ b/src/ui/windows.c @@ -1,7 +1,7 @@ /* * windows.c * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/ui/windows.h b/src/ui/windows.h index c144a5a2..97183d51 100644 --- a/src/ui/windows.h +++ b/src/ui/windows.h @@ -1,7 +1,7 @@ /* * windows.h * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/xmpp/bookmark.c b/src/xmpp/bookmark.c index 94adabea..1cf11f93 100644 --- a/src/xmpp/bookmark.c +++ b/src/xmpp/bookmark.c @@ -1,7 +1,7 @@ /* * bookmark.c * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/xmpp/bookmark.h b/src/xmpp/bookmark.h index f9392182..c8de8147 100644 --- a/src/xmpp/bookmark.h +++ b/src/xmpp/bookmark.h @@ -1,7 +1,7 @@ /* * bookmark.h * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/xmpp/capabilities.c b/src/xmpp/capabilities.c index 1a9eed74..54144330 100644 --- a/src/xmpp/capabilities.c +++ b/src/xmpp/capabilities.c @@ -1,7 +1,7 @@ /* * capabilities.c * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/xmpp/capabilities.h b/src/xmpp/capabilities.h index 692ac49d..85f1d989 100644 --- a/src/xmpp/capabilities.h +++ b/src/xmpp/capabilities.h @@ -1,7 +1,7 @@ /* * capabilities.h * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/xmpp/connection.c b/src/xmpp/connection.c index 915525e4..375dfcba 100644 --- a/src/xmpp/connection.c +++ b/src/xmpp/connection.c @@ -1,7 +1,7 @@ /* * connection.c * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/xmpp/connection.h b/src/xmpp/connection.h index f9e2cf22..63f7cde0 100644 --- a/src/xmpp/connection.h +++ b/src/xmpp/connection.h @@ -1,7 +1,7 @@ /* * connection.h * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/xmpp/form.c b/src/xmpp/form.c index 1facc754..02d26ba0 100644 --- a/src/xmpp/form.c +++ b/src/xmpp/form.c @@ -1,7 +1,7 @@ /* * form.c * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/xmpp/form.h b/src/xmpp/form.h index fa14e1c5..86cd4b7b 100644 --- a/src/xmpp/form.h +++ b/src/xmpp/form.h @@ -1,7 +1,7 @@ /* * form.h * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/xmpp/iq.c b/src/xmpp/iq.c index bc12b780..e1aa773a 100644 --- a/src/xmpp/iq.c +++ b/src/xmpp/iq.c @@ -1,7 +1,7 @@ /* * iq.c * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/xmpp/iq.h b/src/xmpp/iq.h index 8c803ab5..d3a22fe4 100644 --- a/src/xmpp/iq.h +++ b/src/xmpp/iq.h @@ -1,7 +1,7 @@ /* * iq.h * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/xmpp/message.c b/src/xmpp/message.c index e96c1a74..7d504e48 100644 --- a/src/xmpp/message.c +++ b/src/xmpp/message.c @@ -1,7 +1,7 @@ /* * message.c * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/xmpp/message.h b/src/xmpp/message.h index b3410dc9..6fbc27bd 100644 --- a/src/xmpp/message.h +++ b/src/xmpp/message.h @@ -1,7 +1,7 @@ /* * message.h * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/xmpp/presence.c b/src/xmpp/presence.c index 65384a0d..a0d9e0f1 100644 --- a/src/xmpp/presence.c +++ b/src/xmpp/presence.c @@ -1,7 +1,7 @@ /* * presence.c * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/xmpp/presence.h b/src/xmpp/presence.h index e704aea0..90b83473 100644 --- a/src/xmpp/presence.h +++ b/src/xmpp/presence.h @@ -1,7 +1,7 @@ /* * presence.h * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/xmpp/roster.c b/src/xmpp/roster.c index 3449c8d5..e6f4c2ca 100644 --- a/src/xmpp/roster.c +++ b/src/xmpp/roster.c @@ -1,7 +1,7 @@ /* * roster.c * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/xmpp/roster.h b/src/xmpp/roster.h index c29a674a..68811a5c 100644 --- a/src/xmpp/roster.h +++ b/src/xmpp/roster.h @@ -1,7 +1,7 @@ /* * roster.h * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/xmpp/stanza.c b/src/xmpp/stanza.c index 4f1d412d..563aa982 100644 --- a/src/xmpp/stanza.c +++ b/src/xmpp/stanza.c @@ -1,7 +1,7 @@ /* * stanza.c * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/xmpp/stanza.h b/src/xmpp/stanza.h index 84282401..b61e8ab8 100644 --- a/src/xmpp/stanza.h +++ b/src/xmpp/stanza.h @@ -1,7 +1,7 @@ /* * stanza.h * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * diff --git a/src/xmpp/xmpp.h b/src/xmpp/xmpp.h index a004a4bf..79bc0579 100644 --- a/src/xmpp/xmpp.h +++ b/src/xmpp/xmpp.h @@ -1,7 +1,7 @@ /* * xmpp.h * - * Copyright (C) 2012 - 2014 James Booth + * Copyright (C) 2012 - 2015 James Booth * * This file is part of Profanity. * From f4459f7f67af388baa5bab9bbbdf89392dfd432f Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 10 Feb 2015 23:30:21 +0000 Subject: [PATCH 081/252] Updated man page --- docs/profanity.1 | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/docs/profanity.1 b/docs/profanity.1 index 5b87d381..63cd0677 100644 --- a/docs/profanity.1 +++ b/docs/profanity.1 @@ -3,7 +3,7 @@ Profanity \- a simple console based XMPP chat client. .SH SYNOPSIS .B profanity -[\-vhd] [\-l level] +[\-vhd] [\-l level] [\-a account] .SH DESCRIPTION .B Profanity is a simple lightweight console based XMPP chat client. Its emphasis is @@ -15,19 +15,21 @@ at: .SH OPTIONS .TP .BI "\-v, \-\-version" -Show version information. +Show version and build information. .TP .BI "\-h, \-\-help" Show help on command line arguments. .TP -.BI "\-a, \-\-account" -Auto connect to an account on startup. +.BI "\-a, \-\-account "ACCOUNT +Auto connect to an account on startup, +.I ACCOUNT +must be an existing account. .TP .BI "\-d, \-\-disable\-tls" Disable TLS for servers that either don't support it, or claim to but do not complete the handshake. .TP -.BI "\-l, \-\-log="LEVEL +.BI "\-l, \-\-log "LEVEL Set the logging level, .I LEVEL may be set to DEBUG, INFO (the default), WARN or ERROR. @@ -45,10 +47,10 @@ is stored in , details on configuring Profanity can be found at . .PP .SH BUGS -Bugs can either be reported by sending a mail directly to: +Bugs can either be reported by raising an issue at the Github issue tracker: .br .PP - + .br .PP or to the mailing list at: @@ -57,10 +59,12 @@ or to the mailing list at: .br .PP -or with a Github account by logging issues on the issue tracker at: +or by sending a mail directly to: +.br +.PP + .br .PP - .SH LICENSE Copyright (C) 2012 \- 2015 James Booth . License GPLv3+: GNU GPL version 3 or later From 421ce2876a2b59b4ef3e04348be9c442a92997f5 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 10 Feb 2015 23:40:23 +0000 Subject: [PATCH 082/252] Changed default inpblock delay to 1 second --- src/config/preferences.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config/preferences.c b/src/config/preferences.c index 11a0b217..a1f82940 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -62,7 +62,7 @@ #define PREF_GROUP_ALIAS "alias" #define PREF_GROUP_OTR "otr" -#define INPBLOCK_DEFAULT 20 +#define INPBLOCK_DEFAULT 1000 static gchar *prefs_loc; static GKeyFile *prefs; From 0bf9d324ff6a1c4f2ce724f6c54d0b39e157a3c8 Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 11 Feb 2015 00:01:17 +0000 Subject: [PATCH 083/252] Updated CHANGELOG --- CHANGELOG | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 815f6e55..2d9970c7 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,16 +1,17 @@ 0.4.6 ===== -- 16 colour support +- 16 colour support (/theme colours) - UI preferences included in themes -- Word wrapping (/wrap) -- Show hide time (/time) -- Show or hide and customise roster panel (/roster) +- /wrap - Word wrapping +- /time - Show/hide time in main window, and configure precision +- /roster - Show/hide and customise roster panel +- /roster and /occupants panel size settings (% of screen width) +- /account default - Set default account for /connect - /account remove -- Added default account for /connect -- Additional readline style shortcuts -- Improved chat session handling -- Override resource during chat and resource display settings (/resource) -- Disable terminal title by default, additonal title on exit -- Dynamic input blocking timeout to use less CPU -- eval_password property on accounts for retrieving password from keyring/keychain +- /presence - Show/hide contact presence in titlebar +- /resource - Override resource during chat, resource display settings +- Improved chat session handling +- Lower CPU usage with dynamic input blocking timeout +- Keychain/keyring integration using account eval_password property +- Disable term window title by default From 9951da0c8fbb0dd3fa26b74165b7cb64b25d7cf9 Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 11 Feb 2015 00:17:07 +0000 Subject: [PATCH 084/252] Free jid on caps response handler --- src/xmpp/iq.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/xmpp/iq.c b/src/xmpp/iq.c index e1aa773a..c0a982fa 100644 --- a/src/xmpp/iq.c +++ b/src/xmpp/iq.c @@ -586,12 +586,14 @@ static int _caps_response_handler_for_jid(xmpp_conn_t *const conn, xmpp_stanza_t * const stanza, void * const userdata) { + char *jid = (char *)userdata; const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID); xmpp_stanza_t *query = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_QUERY); char *type = xmpp_stanza_get_type(stanza); // ignore non result if ((g_strcmp0(type, "get") == 0) || (g_strcmp0(type, "set") == 0)) { + free(jid); return 1; } @@ -604,6 +606,7 @@ _caps_response_handler_for_jid(xmpp_conn_t *const conn, xmpp_stanza_t * const st const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); if (!from) { log_info("No from attribute"); + free(jid); return 0; } @@ -612,21 +615,23 @@ _caps_response_handler_for_jid(xmpp_conn_t *const conn, xmpp_stanza_t * const st char *error_message = stanza_get_error_message(stanza); log_warning("Error received for capabilities response from %s: ", from, error_message); free(error_message); + free(jid); return 0; } if (query == NULL) { log_warning("No query element found."); + free(jid); return 0; } char *node = xmpp_stanza_get_attribute(query, STANZA_ATTR_NODE); if (node == NULL) { log_warning("No node attribute found"); + free(jid); return 0; } - char *jid = (char *)userdata; log_info("Associating capabilities with: %s", jid); Capabilities *capabilities = caps_create(query); caps_add_by_jid(jid, capabilities); From d02b364b3ca8728c9b2fdc181400906050e9fd45 Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 11 Feb 2015 23:58:11 +0000 Subject: [PATCH 085/252] Tidy help --- src/command/command.c | 206 ++++++++++++++++++------------------------ 1 file changed, 87 insertions(+), 119 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index e810f8af..491bf5f2 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -112,18 +112,13 @@ static struct cmd_t command_defs[] = { { "/help", cmd_help, parse_args, 0, 1, NULL, - { "/help [area|command]", "Get help on using Profanity.", + { "/help [area|command]", "Help on using Profanity.", { "/help [area|command]", - "-------------------------", - "Use with no arguments to get a help summary.", - "Supply an area to see help for commands related to specific features.", - "Supply a command (without the leading slash) to see help for that command.", - "", - "Example : /help commands", - "Example : /help presence", - "Example : /help who", - "", - "For more detailed help, see the user guide at http://www.profanity.im/userguide.html.", + "--------------------", + "Help on using Profanity.", + "area - Summary help for commands in a certain area of functionality.", + "command - Full help for a specific command, for example '/help connect'.", + "Use with no arguments to see a list of areas.", NULL } } }, { "/about", @@ -136,21 +131,15 @@ static struct cmd_t command_defs[] = { "/connect", cmd_connect, parse_args, 0, 5, NULL, - { "/connect [account] [server value] [port value]", "Login to a chat service.", + { "/connect [account] [server value] [port value]", "Account login.", { "/connect [account] [server value] [port value]", "----------------------------------------------", - "Connect to an XMPP service using the specified account.", - "Use the server property to specify a server if required.", - "Change the default port (5222, or 5223 for SSL) with the port property.", - "An account is automatically created if one does not exist.", - "If no account is specified, then the default account is used." - "See the /account command for more details.", - "", - "Example: /connect", - "Example: /connect myuser@gmail.com", - "Example: /connect myuser@mycompany.com server talk.google.com", - "Example: /connect bob@someplace port 5678", - "Example: /connect me@chatty server chatty.com port 5443", + "Login to a chat service.", + "account - The local account you wish to connect with, or a JID if connecting for the first time.", + "server value - Supply a server if it is different to the domain part of your JID.", + "port value - The port to use if different to the default (5222, or 5223 for SSL).", + "If no account is specified, the default is used if one is configured.", + "A local account is created with the JID as it's name if it doesn't already exist.", NULL } } }, { "/disconnect", @@ -163,48 +152,40 @@ static struct cmd_t command_defs[] = { "/msg", cmd_msg, parse_args_with_freetext, 1, 2, NULL, - { "/msg contact|nick [message]", "Start chat with user.", + { "/msg contact|nick [message]", "Start chat with a user.", { "/msg contact|nick [message]", "---------------------------", - "Open a chat window for the contact and send the message if one is supplied.", - "When in a chat room, supply a nickname to start private chat with a room member.", + "Send a one to one chat message, or a private message to a chat room occupant.", + "contact - The contact's JID, or nickname if one has been set in your roster.", + "nick - A chat room occupant, to whom you wish to send a private message.", + "message - The message to send", + "If the message is omitted, a new chat window will be opened without sending a message.", "Use quotes if the nickname includes spaces.", - "", - "Example : /msg myfriend@server.com Hey, here's a message!", - "Example : /msg otherfriend@server.com", - "Example : /msg Bob Here is a private message", - "Example : /msg \"My Friend\" Hi, how are you?", NULL } } }, { "/roster", cmd_roster, parse_args_with_freetext, 0, 3, NULL, - { "/roster [online|show|hide|by|size|add|remove|nick|clearnick] [offline|resource] [percent] [group|presence|none] [jid] [nickname]", "Manage your roster.", - { "/roster [online|show|hide|by|size|add|remove|nick|clearnick] [offline|resource] [percent] [group|presence|none] [jid] [nickname]", - "-------------------------------------------------------------------------------------------------------------------------", - "View, add to, and remove from your roster.", + { "/roster [command] [args..]", "Manage your roster.", + { "/roster [command] [args..]", + "--------------------------", + "Manage your roster, and roster display settings.", + "command - online|show|hide|by|size|add|remove|nick|clearnick", + "online - Show all online contacts in your roster.", + "show - Show the roster panel.", + "show offline - Show offline contacts in the roster panel.", + "show resource - Show contact's connected resources in the roster panel.", + "hide - Hide the roster panel.", + "hide offline - Hide offline contacts in the roster panel.", + "hide resource - Hide contact's connected resources in the roster panel.", + "by group - Group contacts in the roster panel by roster group.", + "by presence - Group contacts in the roster panel by presence.", + "by none - No grouping in the roster panel.", + "size - Percentage of the screen taken up by the roster (1-99).", + "add jid [nick] - Add a new item to the roster.", + "remove jid - Removes an item from the roster.", + "nick jid nick - Change a contacts nickname.", + "clearnick jid - Removes the current nickname.", "Passing no arguments lists all contacts in your roster.", - "online - Show all online contacts in your roster.", - "show - Show the roster panel in the console window.", - "hide - Hide the roster panel.", - "show offline - Show offline contacts in the roster panel.", - "hide offline - Hide offline contacts in the roster panel.", - "show resource - Show contact's connected resources in the roster panel.", - "hide resource - Hide contact's connected resources in the roster panel.", - "by group - Group contacts in the roster panel by roster group.", - "by presence - Group contacts in the roster panel by presence.", - "by none - No grouping in the roster panel.", - "size - Percentage of the screen taken up by the roster (1-99).", - "add - Add a new item, jid is required, nickname is optional.", - "remove - Removes a contact, jid is required.", - "nick - Changes a contacts nickname, both jid and nickname are required,", - "clearnick - Removes the current nickname, jid is required.", - "", - "Example : /roster (show your roster)", - "Example : /roster add someone@contacts.org (add the contact)", - "Example : /roster add someone@contacts.org Buddy (add the contact with nickname 'Buddy')", - "Example : /roster remove someone@contacts.org (remove the contact)", - "Example : /roster nick myfriend@chat.org My Friend", - "Example : /roster clearnick kai@server.com (clears nickname)", NULL } } }, { "/group", @@ -213,31 +194,22 @@ static struct cmd_t command_defs[] = { "/group [show|add|remove] [group] [contact]", "------------------------------------------", "View, add to, and remove from roster groups.", + "show group - List all roster items a group.", + "add group contact - Added a contact to a group.", + "remove group contact - Remove a contact from a group.", "Passing no argument will list all roster groups.", - "The 'show' command takes 'group' as an argument, and lists all roster items in that group.", - "The 'add' command takes 'group' and 'contact' arguments, and adds the contact to the group.", - "The 'remove' command takes 'group' and 'contact' arguments and removes the contact from the group,", - "", - "Example : /group", - "Example : /group show friends", - "Example : /group add friends newfriend@server.org", - "Example : /group add family Brother (using contacts nickname)", - "Example : /group remove colleagues boss@work.com", NULL } } }, { "/info", cmd_info, parse_args, 0, 1, NULL, - { "/info [contact|nick]", "Show basic information about a contact, room, or room member.", + { "/info [contact|nick]", "Show information about a contact, room, or room member.", { "/info [contact|nick]", "--------------------", - "Show basic information about a contact, room, or room member.", - "If in the console, a contact must be specified.", - "If in a chat window the parameter is not required, the current recipient will be used.", - "If in a chat room, providing no arguments will display information about the room.", - "If in a chat room, supplying a nick will show information about the occupant.", - "", - "Example : /info mybuddy@chat.server.org", - "Example : /info kai", + "Show information about a contact, room, or room member.", + "contact - The contact you wish to view information about.", + "nick - When in a chat room, the occupant you wish to view information about.", + "Passing no argument in a chat window will use the current recipient.", + "Passing no argument in a chat room will display information about the room.", NULL } } }, { "/caps", @@ -245,14 +217,10 @@ static struct cmd_t command_defs[] = { "/caps [fulljid|nick]", "Find out a contacts client software capabilities.", { "/caps [fulljid|nick]", "--------------------", - "Find out a contact, or room members client software capabilities.", - "If in the console window or a regular chat window, a full JID is required.", - "If in a chat room, the nickname is required.", - "If in private chat, no parameter is required.", - "", - "Example : /caps mybuddy@chat.server.org/laptop (contact's laptop resource)", - "Example : /caps mybuddy@chat.server.org/phone (contact's phone resource)", - "Example : /caps bruce (room member)", + "Find out a contacts, or room members client software capabilities.", + "fulljid - If in the console or a chat window, the full JID for which you wish to see capabilities.", + "nick - If in a chat room, nickname for which you wish to see capabilities.", + "If in private chat initiated from a chat room, no parameter is required.", NULL } } }, { "/software", @@ -260,15 +228,11 @@ static struct cmd_t command_defs[] = { "/software [fulljid|nick]", "Find out software version information about a contacts resource.", { "/software [fulljid|nick]", "------------------------", - "Find out a contact, or room members software version information, if such requests are supported.", - "If in the console window or a regular chat window, a full JID is required.", - "If in a chat room, the nickname is required.", - "If in private chat, no parameter is required.", + "Find out a contact, or room members software version information.", + "fulljid - If in the console or a chat window, the full JID for which you wish to see software information.", + "nick - If in a chat room, nickname for which you wish to see software information.", + "If in private chat initiated from a chat room, no parameter is required.", "If the contact's software does not support software version requests, nothing will be displayed.", - "", - "Example : /software mybuddy@chat.server.org/laptop (contact's laptop resource)", - "Example : /software mybuddy@chat.server.org/phone (contact's phone resource)", - "Example : /software bruce (room member)", NULL } } }, { "/status", @@ -277,22 +241,21 @@ static struct cmd_t command_defs[] = { "/status [contact|nick]", "----------------------", "Find out a contact, or room members presence information.", + "contact - The contact who's presence you which to see.", + "nick - If in a chat room, the occupant who's presence you wish to see.", "If in a chat window the parameter is not required, the current recipient will be used.", - "", - "Example : /status buddy@server.com", - "Example : /status jon", NULL } } }, { "/resource", cmd_resource, parse_args, 1, 2, &cons_resource_setting, - { "/resource set|off|title|message [resource]", "Set the contact's resource.", + { "/resource set|off|title|message [resource]", "Set the contact's resource, display settings.", { "/resource set|off|title|message [resource]", "------------------------------------------", - "Set the resource to use when chatting to a contact and manage resource display settings.", - "set resource - Set the resource.", + "Override chat session resource, and manage resource display settings.", + "set resource - Set the resource to which messages will be sent.", "off - Let the server choose which resource to route messages to.", "title on|off - Show or hide the current resource in the titlebar.", - "message on|off - Show or hide the resource from which a message was recieved.", + "message on|off - Show or hide the resource when showing an incoming message.", NULL } } }, { "/join", @@ -301,15 +264,12 @@ static struct cmd_t command_defs[] = { "/join room[@server] [nick value] [password value]", "-------------------------------------------------", "Join a chat room at the conference server.", - "If nick is specified you will join with this nickname.", - "Otherwise the account preference 'muc.nick' will be used which by default is the localpart of your JID (before the @).", - "If no server is supplied, the account preference 'muc.service' is used, which is 'conference.' by default.", + "room - Bare room JID, the chat server is determined by the 'muc.service' account property, 'conference.' by default.", + "room@server - Full room JID.", + "nick value - Nickname to use in the room", + "password value - Password if the room requires it.", + "If no nickname is specfied the account preference 'muc.nick' will be used which by default is the localpart of your JID.", "If the room doesn't exist, and the server allows it, a new one will be created.", - "", - "Example : /join jdev@conference.jabber.org", - "Example : /join jdev@conference.jabber.org nick mynick", - "Example : /join private@conference.jabber.org nick mynick password mypassword", - "Example : /join jdev (as user@jabber.org will join jdev@conference.jabber.org)", NULL } } }, { "/leave", @@ -325,8 +285,9 @@ static struct cmd_t command_defs[] = { "/invite contact [message]", "Invite contact to chat room.", { "/invite contact [message]", "-------------------------", - "Send a direct invite to the specified contact to the current chat room.", - "If a message is supplied it will be sent as the reason for the invite.", + "Send a direct invite to the current chat room.", + "contact - The contact you wish to invite", + "message - An optional message to send with the invite.", NULL } } }, { "/invites", @@ -334,9 +295,7 @@ static struct cmd_t command_defs[] = { "/invites", "Show outstanding chat room invites.", { "/invites", "--------", - "Show all rooms that you have been invited to, and have not yet been accepted or declind.", - "Use \"/join \" to accept a room invitation.", - "Use \"/decline \" to decline a room invitation.", + "Show all rooms that you have been invited to, and not accepted or declind.", NULL } } }, { "/decline", @@ -344,7 +303,8 @@ static struct cmd_t command_defs[] = { "/decline room", "Decline a chat room invite.", { "/decline room", "-------------", - "Decline invitation to a chat room, the room will no longer be in the list of outstanding invites.", + "Decline a chat room ivivation.", + "room - The room for the invite you wish to decline.", NULL } } }, { "/room", @@ -352,6 +312,7 @@ static struct cmd_t command_defs[] = { "/room accept|destroy|config", "Room configuration.", { "/room accept|destroy|config", "---------------------------", + "Chat room configuration.", "accept - Accept default room configuration.", "destroy - Reject default room configuration.", "config - Edit room configuration.", @@ -362,6 +323,7 @@ static struct cmd_t command_defs[] = { "/kick nick [reason]", "Kick occupants from chat rooms.", { "/kick nick [reason]", "-------------------", + "Kick occupants from chat rooms.", "nick - Nickname of the occupant to kick from the room.", "reason - Optional reason for kicking the occupant.", NULL } } }, @@ -371,6 +333,7 @@ static struct cmd_t command_defs[] = { "/ban jid [reason]", "Ban users from chat rooms.", { "/ban jid [reason]", "-----------------", + "Ban users from chat rooms.", "jid - Bare JID of the user to ban from the room.", "reason - Optional reason for banning the user.", NULL } } }, @@ -380,6 +343,7 @@ static struct cmd_t command_defs[] = { "/subject set|clear [subject]", "Set or clear room subject.", { "/subject set|clear [subject]", "----------------------------", + "Set or clear room subject.", "set subject - Set the room subject.", "clear - Clear the room subject.", NULL } } }, @@ -389,6 +353,7 @@ static struct cmd_t command_defs[] = { "/affiliation set|list [affiliation] [jid] [reason]", "Manage room affiliations.", { "/affiliation set|list [affiliation] [jid] [reason]", "--------------------------------------------------", + "Manage room affiliations.", "set affiliation jid [reason]- Set the affiliation of user with jid, with an optional reason.", "list [affiliation] - List all users with the specified affiliation, or all if none specified.", "The affiliation may be one of owner, admin, member, outcast or none.", @@ -399,6 +364,7 @@ static struct cmd_t command_defs[] = { "/role set|list [role] [nick] [reason]", "Manage room roles.", { "/role set|list [role] [nick] [reason]", "-------------------------------------", + "Manage room roles.", "set role nick [reason] - Set the role of occupant with nick, with an optional reason.", "list [role] - List all occupants with the specified role, or all if none specified.", "The role may be one of moderator, participant, visitor or none.", @@ -409,10 +375,11 @@ static struct cmd_t command_defs[] = { "/occupants show|hide|default|size [show|hide] [percent]", "Show or hide room occupants.", { "/occupants show|hide|default|size [show|hide] [percent]", "-------------------------------------------------------", - "show - Show the occupants panel in chat rooms.", - "hide - Hide the occupants panel in chat rooms.", - "default - Whether occupants are shown by default in new rooms, 'show' or 'hide'", - "size - Percentage of the screen taken by the occupants list in rooms (1-99).", + "Show or hide room occupants, and occupants panel display settings.", + "show - Show the occupants panel in chat rooms.", + "hide - Hide the occupants panel in chat rooms.", + "default show|hide - Whether occupants are shown by default in new rooms, 'show' or 'hide'", + "size percent - Percentage of the screen taken by the occupants list in rooms (1-99).", NULL } } }, { "/form", @@ -420,13 +387,14 @@ static struct cmd_t command_defs[] = { "/form show|submit|cancel|help [tag]", "Form handling.", { "/form show|submit|cancel|help [tag]", "-----------------------------------", + "Form configuration." "show - Show the current form.", "submit - Submit the current form.", "cancel - Cancel changes to the current form.", "help [tag] - Display help for form, or a specific field.", NULL } } }, - { "/rooms", + { "/rooms", // TODO help review cmd_rooms, parse_args, 0, 1, NULL, { "/rooms [conference-service]", "List chat rooms.", { "/rooms [conference-service]", @@ -3051,4 +3019,4 @@ command_docgen(void) fclose(toc_fragment); fclose(main_fragment); g_list_free(cmds); -} \ No newline at end of file +} From c9a6e10c2621a5df3285c881fa98eb00707fc6ad Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 14 Feb 2015 16:20:15 +0000 Subject: [PATCH 086/252] Use single quotes for terminal notifier notifications to avoid variable expansion --- src/ui/notifier.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/ui/notifier.c b/src/ui/notifier.c index 693817d6..e8bc61e3 100644 --- a/src/ui/notifier.c +++ b/src/ui/notifier.c @@ -243,10 +243,9 @@ _notify(const char * const message, int timeout, Shell_NotifyIcon(NIM_MODIFY, &nid); #endif #ifdef HAVE_OSXNOTIFY - GString *notify_command = g_string_new("terminal-notifier -title \"Profanity\" -message \""); + GString *notify_command = g_string_new("terminal-notifier -title \"Profanity\" -message '"); - char *escaped_double = str_replace(message, "\"", "\\\""); - char *escaped_single = str_replace(escaped_double, "`", "\\`"); + char *escaped_single = str_replace(message, "'", "'\\''"); if (escaped_single[0] == '<') { g_string_append(notify_command, "\\<"); @@ -264,8 +263,7 @@ _notify(const char * const message, int timeout, g_string_append(notify_command, escaped_single); } - g_string_append(notify_command, "\""); - free(escaped_double); + g_string_append(notify_command, "'"); free(escaped_single); char *term_name = getenv("TERM_PROGRAM"); @@ -288,4 +286,4 @@ _notify(const char * const message, int timeout, g_string_free(notify_command, TRUE); #endif -} \ No newline at end of file +} From 2605b84a7043d98f105f18a0866776e021be81f2 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 16 Feb 2015 22:37:17 +0000 Subject: [PATCH 087/252] Tidy help --- src/command/command.c | 186 ++++++++++++++++++++++++------------------ 1 file changed, 107 insertions(+), 79 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index 491bf5f2..81633443 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -116,8 +116,10 @@ static struct cmd_t command_defs[] = { "/help [area|command]", "--------------------", "Help on using Profanity.", + "", "area - Summary help for commands in a certain area of functionality.", "command - Full help for a specific command, for example '/help connect'.", + "", "Use with no arguments to see a list of areas.", NULL } } }, @@ -135,9 +137,11 @@ static struct cmd_t command_defs[] = { "/connect [account] [server value] [port value]", "----------------------------------------------", "Login to a chat service.", + "", "account - The local account you wish to connect with, or a JID if connecting for the first time.", "server value - Supply a server if it is different to the domain part of your JID.", "port value - The port to use if different to the default (5222, or 5223 for SSL).", + "", "If no account is specified, the default is used if one is configured.", "A local account is created with the JID as it's name if it doesn't already exist.", NULL } } }, @@ -156,9 +160,11 @@ static struct cmd_t command_defs[] = { "/msg contact|nick [message]", "---------------------------", "Send a one to one chat message, or a private message to a chat room occupant.", + "", "contact - The contact's JID, or nickname if one has been set in your roster.", "nick - A chat room occupant, to whom you wish to send a private message.", "message - The message to send", + "", "If the message is omitted, a new chat window will be opened without sending a message.", "Use quotes if the nickname includes spaces.", NULL } } }, @@ -169,7 +175,9 @@ static struct cmd_t command_defs[] = { "/roster [command] [args..]", "--------------------------", "Manage your roster, and roster display settings.", + "", "command - online|show|hide|by|size|add|remove|nick|clearnick", + "", "online - Show all online contacts in your roster.", "show - Show the roster panel.", "show offline - Show offline contacts in the roster panel.", @@ -185,6 +193,7 @@ static struct cmd_t command_defs[] = "remove jid - Removes an item from the roster.", "nick jid nick - Change a contacts nickname.", "clearnick jid - Removes the current nickname.", + "", "Passing no arguments lists all contacts in your roster.", NULL } } }, @@ -194,9 +203,11 @@ static struct cmd_t command_defs[] = { "/group [show|add|remove] [group] [contact]", "------------------------------------------", "View, add to, and remove from roster groups.", + "", "show group - List all roster items a group.", "add group contact - Added a contact to a group.", "remove group contact - Remove a contact from a group.", + "", "Passing no argument will list all roster groups.", NULL } } }, @@ -206,8 +217,10 @@ static struct cmd_t command_defs[] = { "/info [contact|nick]", "--------------------", "Show information about a contact, room, or room member.", + "", "contact - The contact you wish to view information about.", "nick - When in a chat room, the occupant you wish to view information about.", + "", "Passing no argument in a chat window will use the current recipient.", "Passing no argument in a chat room will display information about the room.", NULL } } }, @@ -218,8 +231,10 @@ static struct cmd_t command_defs[] = { "/caps [fulljid|nick]", "--------------------", "Find out a contacts, or room members client software capabilities.", + "", "fulljid - If in the console or a chat window, the full JID for which you wish to see capabilities.", "nick - If in a chat room, nickname for which you wish to see capabilities.", + "", "If in private chat initiated from a chat room, no parameter is required.", NULL } } }, @@ -229,8 +244,10 @@ static struct cmd_t command_defs[] = { "/software [fulljid|nick]", "------------------------", "Find out a contact, or room members software version information.", + "", "fulljid - If in the console or a chat window, the full JID for which you wish to see software information.", "nick - If in a chat room, nickname for which you wish to see software information.", + "", "If in private chat initiated from a chat room, no parameter is required.", "If the contact's software does not support software version requests, nothing will be displayed.", NULL } } }, @@ -241,8 +258,10 @@ static struct cmd_t command_defs[] = { "/status [contact|nick]", "----------------------", "Find out a contact, or room members presence information.", + "", "contact - The contact who's presence you which to see.", "nick - If in a chat room, the occupant who's presence you wish to see.", + "", "If in a chat window the parameter is not required, the current recipient will be used.", NULL } } }, @@ -252,6 +271,7 @@ static struct cmd_t command_defs[] = { "/resource set|off|title|message [resource]", "------------------------------------------", "Override chat session resource, and manage resource display settings.", + "", "set resource - Set the resource to which messages will be sent.", "off - Let the server choose which resource to route messages to.", "title on|off - Show or hide the current resource in the titlebar.", @@ -264,10 +284,12 @@ static struct cmd_t command_defs[] = { "/join room[@server] [nick value] [password value]", "-------------------------------------------------", "Join a chat room at the conference server.", + "", "room - Bare room JID, the chat server is determined by the 'muc.service' account property, 'conference.' by default.", "room@server - Full room JID.", "nick value - Nickname to use in the room", "password value - Password if the room requires it.", + "", "If no nickname is specfied the account preference 'muc.nick' will be used which by default is the localpart of your JID.", "If the room doesn't exist, and the server allows it, a new one will be created.", NULL } } }, @@ -286,6 +308,7 @@ static struct cmd_t command_defs[] = { "/invite contact [message]", "-------------------------", "Send a direct invite to the current chat room.", + "", "contact - The contact you wish to invite", "message - An optional message to send with the invite.", NULL } } }, @@ -304,6 +327,7 @@ static struct cmd_t command_defs[] = { "/decline room", "-------------", "Decline a chat room ivivation.", + "", "room - The room for the invite you wish to decline.", NULL } } }, @@ -313,6 +337,7 @@ static struct cmd_t command_defs[] = { "/room accept|destroy|config", "---------------------------", "Chat room configuration.", + "", "accept - Accept default room configuration.", "destroy - Reject default room configuration.", "config - Edit room configuration.", @@ -324,6 +349,7 @@ static struct cmd_t command_defs[] = { "/kick nick [reason]", "-------------------", "Kick occupants from chat rooms.", + "", "nick - Nickname of the occupant to kick from the room.", "reason - Optional reason for kicking the occupant.", NULL } } }, @@ -334,6 +360,7 @@ static struct cmd_t command_defs[] = { "/ban jid [reason]", "-----------------", "Ban users from chat rooms.", + "", "jid - Bare JID of the user to ban from the room.", "reason - Optional reason for banning the user.", NULL } } }, @@ -344,6 +371,7 @@ static struct cmd_t command_defs[] = { "/subject set|clear [subject]", "----------------------------", "Set or clear room subject.", + "", "set subject - Set the room subject.", "clear - Clear the room subject.", NULL } } }, @@ -354,8 +382,10 @@ static struct cmd_t command_defs[] = { "/affiliation set|list [affiliation] [jid] [reason]", "--------------------------------------------------", "Manage room affiliations.", + "", "set affiliation jid [reason]- Set the affiliation of user with jid, with an optional reason.", "list [affiliation] - List all users with the specified affiliation, or all if none specified.", + "", "The affiliation may be one of owner, admin, member, outcast or none.", NULL } } }, @@ -365,8 +395,10 @@ static struct cmd_t command_defs[] = { "/role set|list [role] [nick] [reason]", "-------------------------------------", "Manage room roles.", + "", "set role nick [reason] - Set the role of occupant with nick, with an optional reason.", "list [role] - List all occupants with the specified role, or all if none specified.", + "", "The role may be one of moderator, participant, visitor or none.", NULL } } }, @@ -376,6 +408,7 @@ static struct cmd_t command_defs[] = { "/occupants show|hide|default|size [show|hide] [percent]", "-------------------------------------------------------", "Show or hide room occupants, and occupants panel display settings.", + "", "show - Show the occupants panel in chat rooms.", "hide - Hide the occupants panel in chat rooms.", "default show|hide - Whether occupants are shown by default in new rooms, 'show' or 'hide'", @@ -387,7 +420,8 @@ static struct cmd_t command_defs[] = { "/form show|submit|cancel|help [tag]", "Form handling.", { "/form show|submit|cancel|help [tag]", "-----------------------------------", - "Form configuration." + "Form configuration.", + "", "show - Show the current form.", "submit - Submit the current form.", "cancel - Cancel changes to the current form.", @@ -400,45 +434,43 @@ static struct cmd_t command_defs[] = { "/rooms [conference-service]", "---------------------------", "List the chat rooms available at the specified conference service", - "If no argument is supplied, the account preference 'muc.service' is used, which is 'conference.' by default.", "", - "Example : /rooms conference.jabber.org", - "Example : /rooms (if logged in as me@server.org, is equivalent to /rooms conference.server.org)", + "conference-service - The conference service to query.", + "", + "If no argument is supplied, the account preference 'muc.service' is used, 'conference.' by default.", NULL } } }, { "/bookmark", cmd_bookmark, parse_args, 0, 8, NULL, - { "/bookmark [list|add|update|remove|join] [room@server] [nick value] [password value] [autojoin on|off]", "Manage bookmarks.", - { "/bookmark [list|add|update|remove|join] [room@server] [nick value] [password value] [autojoin on|off]", - "---------------------------------------------------------------------------------------------------", - "Manage bookmarks.", - "list: List all bookmarks.", - "add: Add a bookmark for room@server with the following optional properties:", - " nick: Nickname used in the chat room", - " password: Password for private rooms, note this may be stored in plaintext on your server", - " autojoin: Whether to join the room automatically on login \"on\" or \"off\".", - "update: Update any of the above properties associated with the bookmark.", - "remove: Remove the bookmark for room@server.", - "join: Join room@server using the properties associated with the bookmark.", - "When in a chat room, the /bookmark command with no arguments will bookmark the current room with the current settings, and set autojoin to \"on\".", + { "/bookmark [command] [args..]", "Manage bookmarks.", + { "/bookmark [command] [args..]", + "----------------------------", + "Manage bookmarks and join bookmarked rooms.", + "", + "command - list|add|update|remove|join", + "", + "list - List all bookmarks.", + "add room@server [prop value..] - Add a bookmark for room@server with the following optional properties:", + " nick value - Nickname used in the chat room", + " password value - Password if required, may be stored in plaintext on your server", + " autojoin on|off - Whether to join the room automatically on login.", + "update room@server [prop value..] - Update any of the above properties associated with the bookmark.", + "remove room@server - Remove the bookmark for room@server.", + "join room@server - Join room using the properties associated with the bookmark.", + "", + "In a chat room, /bookmark with no arguments will bookmark the current room, setting autojoin to \"on\".", NULL } } }, { "/disco", cmd_disco, parse_args, 1, 2, NULL, - { "/disco command entity", "Service discovery.", - { "/disco command entity", + { "/disco info|items entity", "Service discovery.", + { "/disco info|items entity", "---------------------", "Find out information about an entities supported services.", - "Command may be one of:", - "info: List protocols and features supported by an entity.", - "items: List items associated with an entity.", "", - "The entity must be a Jabber ID.", - "", - "Example : /disco info myserver.org", - "Example : /disco items myserver.org", - "Example : /disco items conference.jabber.org", - "Example : /disco info myfriend@server.com/laptop", + "info - List protocols and features supported by an entity.", + "items - List items associated with an entity.", + "entity - Jabber ID.", NULL } } }, { "/nick", @@ -447,52 +479,49 @@ static struct cmd_t command_defs[] = { "/nick nickname", "--------------", "Change the name by which other members of a chat room see you.", - "This command is only valid when called within a chat room window.", "", - "Example : /nick kai hansen", - "Example : /nick bob", + "nickname - The new nickname.", NULL } } }, { "/win", cmd_win, parse_args, 1, 1, NULL, { "/win num", "View a window.", { "/win num", - "------------------", + "--------", "Show the contents of a specific window in the main window area.", + "", + "num - Window number to display.", NULL } } }, { "/wins", cmd_wins, parse_args, 0, 3, NULL, - { "/wins [tidy|prune|swap] [source] [target]", "List or tidy active windows.", - { "/wins [tidy|prune|swap] [source] [target]", - "-----------------------------------------", + { "/wins [tidy|prune|swap] [source target]", "List or tidy active windows.", + { "/wins [tidy|prune|swap] [source target]", + "---------------------------------------", + "Show a list of windows, or tidy or swap.", + "", + "tidy - Move windows so there are no gaps.", + "prune - Close all windows with no unread messages, and then tidy as above.", + "swap source target - Swap windows, target may be an empty position.", + "", "Passing no argument will list all currently active windows and information about their usage.", - "tidy : Shuffle windows so there are no gaps.", - "prune : Close all windows with no unread messages, and then tidy as above.", - "swap source target : Swap windows, target may be an empty position.", NULL } } }, { "/sub", cmd_sub, parse_args, 1, 2, NULL, - { "/sub command [jid]", "Manage subscriptions.", - { "/sub command [jid]", - "------------------", - "command : One of the following,", - "request : Send a subscription request to the user to be informed of their", - " : presence.", - "allow : Approve a contact's subscription reqeust to see your presence.", - "deny : Remove subscription for a contact, or deny a request", - "show : Show subscriprion status for a contact.", - "sent : Show all sent subscription requests pending a response.", - "received : Show all received subscription requests awaiting your response.", + { "/sub request|allow|deny|show|sent|received [jid]", "Manage subscriptions.", + { "/sub request|allow|deny|show|sent|received [jid]", + "------------------------------------------------", + "Manage subscriptions to contact presence.", "", - "The optional 'jid' parameter only applys to 'request', 'allow', 'deny' and 'show'", - "If it is omitted the contact of the current window is used.", + "request [jid] - Send a subscription request to the user.", + "allow [jid] - Approve a contact's subscription reqeust.", + "deny [jid] - Remove subscription for a contact, or deny a request", + "show [jid] - Show subscriprion status for a contact.", + "sent - Show all sent subscription requests pending a response.", + "received - Show all received subscription requests awaiting your response.", "", - "Example: /sub request myfriend@jabber.org", - "Example: /sub allow myfriend@jabber.org", - "Example: /sub request (whilst in chat with contact)", - "Example: /sub sent", + "If jid is omitted, the contact of the current window is used.", NULL } } }, { "/tiny", @@ -500,9 +529,9 @@ static struct cmd_t command_defs[] = { "/tiny url", "Send url as tinyurl in current chat.", { "/tiny url", "---------", - "Send the url as a tiny url.", + "Send url as tinyurl in current chat.", "", - "Example : /tiny http://www.profanity.im", + "url - The url to make tiny.", NULL } } }, { "/who", @@ -510,31 +539,30 @@ static struct cmd_t command_defs[] = { "/who [status|role|affiliation] [group]", "Show contacts/room occupants with chosen status, role or affiliation", { "/who [status|role|affiliation] [group]", "--------------------------------------", - "Normal usage:", - "Status may be one of - online, offline, away, dnd, xa, chat, available, unavailable, or any where:", - "online : Contacts that are online, chat, away, xa, dnd", - "available : Contacts that are available for chat - online, chat.", - "unavailable : Contacts that are not available for chat - offline, away, xa, dnd.", - "any : Contacts with any status (same as calling with no argument).", + "Show contacts/room occupants with chosen status, role or affiliation", "", - "The group argument filters the list by that group.", - "", - "In a chat room, a role or affiliation may also be supplied instead of status.", - "Roles: moderator, participant, visitor", - "Affiliations: owner, admin, member", + "status - online|offline|away|dnd|xa|chat|available|unavailable|any", + " online - Contacts that are online, chat, away, xa, dnd", + " available - Contacts that are available for chat - online, chat.", + " unavailable - Contacts that are not available for chat - offline, away, xa, dnd.", + " any - Contacts with any status (same as calling with no argument).", + "role - moderator|participant|visitor", + "affiliation - owner|admin|member", + "group - Filter the results by the specfied group.", NULL } } }, { "/close", cmd_close, parse_args, 0, 1, NULL, - { "/close [win|read|all]", "Close windows.", - { "/close [win|read|all]", + { "/close [num|read|all]", "Close windows.", + { "/close [num|read|all]", "---------------------", + "Close the current window, or a number of windows.", + "", + "num - Close the specified window.", + "all - Close all windows.", + "read - Close all windows that have no new messages.", + "", "Passing no argument will close the current window.", - "2,3,4,5,6,7,8,9 or 0 : Close the specified window.", - "all : Close all currently open windows.", - "read : Close all windows that have no new messages.", - "The console window cannot be closed.", - "If in a chat room, you will leave the room.", NULL } } }, { "/clear", @@ -557,8 +585,8 @@ static struct cmd_t command_defs[] = cmd_privileges, parse_args, 1, 1, &cons_privileges_setting, { "/privileges on|off", "Show occupant privileges in chat rooms.", { "/privileges on|off", - "---------------------------", - "If enabled the room roster will be broken down my role, and role information will be showin in the room.", + "------------------", + "If enabled the room occupants panel will be grouped by role, and role information will be shown in the room.", NULL } } }, { "/beep", @@ -576,7 +604,7 @@ static struct cmd_t command_defs[] = { "/presence on|off", "Show the contacts presence in the titlebar.", { "/presence on|off", "----------------", - "Switch display of the contacts presence on or off.", + "Switch display of the contacts presence in the titlebar on or off.", NULL } } }, { "/wrap", @@ -595,7 +623,7 @@ static struct cmd_t command_defs[] = "Configure time precision for the main window.", NULL } } }, - { "/inpblock", + { "/inpblock", // TODO review cmd_inpblock, parse_args, 2, 2, &cons_inpblock_setting, { "/inpblock timeout|dynamic [millis|on|off]", "Input blocking delay (dynamic or static).", { "/inpblock timeout|dynamic [millis|on|off]", From 0997bafeb99541fff67765506392209ef2ce1ef1 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 16 Feb 2015 22:52:18 +0000 Subject: [PATCH 088/252] Removed comment --- src/command/command.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/command/command.c b/src/command/command.c index 81633443..4411487d 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -428,7 +428,7 @@ static struct cmd_t command_defs[] = "help [tag] - Display help for form, or a specific field.", NULL } } }, - { "/rooms", // TODO help review + { "/rooms", cmd_rooms, parse_args, 0, 1, NULL, { "/rooms [conference-service]", "List chat rooms.", { "/rooms [conference-service]", From a1d14c4526a8d47adeef254cf0ae9142ae2b13b3 Mon Sep 17 00:00:00 2001 From: Christian Storm Date: Tue, 17 Feb 2015 10:52:37 +0100 Subject: [PATCH 089/252] Fixed spelling. --- src/chat_session.c | 2 +- src/command/command.c | 32 ++++++++++++++++---------------- src/config/accounts.c | 2 +- src/muc.c | 2 +- src/roster_list.c | 10 +++++----- src/tools/parser.c | 10 +++++----- src/ui/console.c | 2 +- src/ui/core.c | 8 ++++---- src/ui/statusbar.c | 4 ++-- src/ui/window.c | 2 +- src/xmpp/presence.c | 2 +- 11 files changed, 38 insertions(+), 38 deletions(-) diff --git a/src/chat_session.c b/src/chat_session.c index 555452cb..8ce2e437 100644 --- a/src/chat_session.c +++ b/src/chat_session.c @@ -141,7 +141,7 @@ chat_session_recipient_active(const char * const barejid, const char * const res // session exists with resource, update chat_states if (g_strcmp0(session->resource, resource) == 0) { session->send_states = send_states; - // session exists with differet resource and no override, replace + // session exists with different resource and no override, replace } else if (!session->resource_override) { _chat_session_new(barejid, resource, FALSE, send_states); } diff --git a/src/command/command.c b/src/command/command.c index 4411487d..944a9b8d 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -290,7 +290,7 @@ static struct cmd_t command_defs[] = "nick value - Nickname to use in the room", "password value - Password if the room requires it.", "", - "If no nickname is specfied the account preference 'muc.nick' will be used which by default is the localpart of your JID.", + "If no nickname is specified the account preference 'muc.nick' will be used which by default is the localpart of your JID.", "If the room doesn't exist, and the server allows it, a new one will be created.", NULL } } }, @@ -318,7 +318,7 @@ static struct cmd_t command_defs[] = { "/invites", "Show outstanding chat room invites.", { "/invites", "--------", - "Show all rooms that you have been invited to, and not accepted or declind.", + "Show all rooms that you have been invited to, and not accepted or declined.", NULL } } }, { "/decline", @@ -326,7 +326,7 @@ static struct cmd_t command_defs[] = { "/decline room", "Decline a chat room invite.", { "/decline room", "-------------", - "Decline a chat room ivivation.", + "Decline a chat room invitation.", "", "room - The room for the invite you wish to decline.", NULL } } }, @@ -515,9 +515,9 @@ static struct cmd_t command_defs[] = "Manage subscriptions to contact presence.", "", "request [jid] - Send a subscription request to the user.", - "allow [jid] - Approve a contact's subscription reqeust.", + "allow [jid] - Approve a contact's subscription request.", "deny [jid] - Remove subscription for a contact, or deny a request", - "show [jid] - Show subscriprion status for a contact.", + "show [jid] - Show subscription status for a contact.", "sent - Show all sent subscription requests pending a response.", "received - Show all received subscription requests awaiting your response.", "", @@ -548,7 +548,7 @@ static struct cmd_t command_defs[] = " any - Contacts with any status (same as calling with no argument).", "role - moderator|participant|visitor", "affiliation - owner|admin|member", - "group - Filter the results by the specfied group.", + "group - Filter the results by the specified group.", NULL } } }, { "/close", @@ -633,24 +633,24 @@ static struct cmd_t command_defs[] = " : Valid values are 1-1000.", "dynamic : Start with a 0 timeout and increase the value dynamically up to the specified 'timeout'.", " : on|off", - "A higher timeout will result in less CPU usage, but a noticable delay for response to input.", + "A higher timeout will result in less CPU usage, but a noticeable delay for response to input.", "A lower timeout will result in higher CPU usage, but faster response to input.", "Using the dynamic setting, higher CPU usage will occur during activity, but over time the CPU usage will decrease whilst there is no activity.", NULL } } }, { "/notify", cmd_notify, parse_args, 2, 3, &cons_notify_setting, - { "/notify [type value]|[type setting value]", "Control various desktop noficiations.", + { "/notify [type value]|[type setting value]", "Control various desktop notifications.", { "/notify [type value]|[type setting value]", "-----------------------------------------", "Settings for various desktop notifications where type is one of:", - "message : Notificaitons for regular messages.", + "message : Notifications for regular messages.", " : on|off", "message current : Whether messages in the current window trigger notifications.", " : on|off", "message text : Show message text in message notifications.", " : on|off", - "room : Notificaitons for chat room messages.", + "room : Notifications for chat room messages.", " : on|off|mention", "room current : Whether chat room messages in the current window trigger notifications.", " : on|off", @@ -661,7 +661,7 @@ static struct cmd_t command_defs[] = " : use 0 to disable.", "typing : Notifications when contacts are typing.", " : on|off", - "typing current : Whether typing notifications are triggerd for the current window.", + "typing current : Whether typing notifications are triggered for the current window.", " : on|off", "invite : Notifications for chat room invites.", " : on|off", @@ -742,7 +742,7 @@ static struct cmd_t command_defs[] = { "/mouse on|off", "-------------", "If set to 'on', profanity will handle mouse actions, which enables scrolling the main window with the mouse wheel.", - "To select text, use the shift key while selcting an area.", + "To select text, use the shift key while selecting an area.", "If set to 'off', profanity leaves mouse handling to the terminal implementation.", "This feature is experimental, certain mouse click events may occasionally freeze", "Profanity until a key is pressed or another mouse event is received", @@ -804,13 +804,13 @@ static struct cmd_t command_defs[] = "start [contact] - Start an OTR session with the contact, or the current recipient if in a chat window and no argument supplied.", "end - End the current OTR session,", "trust - Indicate that you have verified the contact's fingerprint.", - "untrust - Indicate the the contact's fingerprint is not verified,", + "untrust - Indicate the contact's fingerprint is not verified,", "log - How to log OTR messages, options are 'on', 'off' and 'redact', with redaction being the default.", "warn - Show when unencrypted messaging is being used in the title bar, options are 'on' and 'off' with 'on' being the default.", "libver - Show which version of the libotr library is being used.", "policy - manual, opportunistic or always.", "secret [secret]- Verify a contacts identity using a shared secret.", - "question [question] [answer] - Verify a contacts identity using a question and expected anwser, if the question has spaces, surround with double quotes.", + "question [question] [answer] - Verify a contacts identity using a question and expected answer, if the question has spaces, surround with double quotes.", "answer [answer] - Respond to a question answer verification request with your answer.", NULL } } }, @@ -876,9 +876,9 @@ static struct cmd_t command_defs[] = { "/ping", cmd_ping, parse_args, 0, 1, NULL, { "/ping [target]", "Send ping IQ request.", - { "/ping [rarget]", + { "/ping [target]", "--------------", - "Sends an IQ ping stanza to the specificed target.", + "Sends an IQ ping stanza to the specified target.", "If no target is supplied, your chat server will be used.", NULL } } }, diff --git a/src/config/accounts.c b/src/config/accounts.c index dd0d6eb4..6c04549c 100644 --- a/src/config/accounts.c +++ b/src/config/accounts.c @@ -828,7 +828,7 @@ _fix_legacy_accounts(const char * const account_name) _save_accounts(); } - // acounts with no muc service or nick + // accounts with no muc service or nick if (!g_key_file_has_key(accounts, account_name, "muc.service", NULL)) { gchar *account_jid = g_key_file_get_string(accounts, account_name, "jid", NULL); Jid *jidp = jid_create(account_jid); diff --git a/src/muc.c b/src/muc.c index 0d606873..ea4ae915 100644 --- a/src/muc.c +++ b/src/muc.c @@ -315,7 +315,7 @@ muc_nick_change_pending(const char * const room) } /* - * Change the current nuck name for the room, call once + * Change the current nick name for the room, call once * the service has responded */ void diff --git a/src/roster_list.c b/src/roster_list.c index 4ec5ea4f..b9a142cb 100644 --- a/src/roster_list.c +++ b/src/roster_list.c @@ -286,7 +286,7 @@ roster_get_contacts_by_presence(const char * const presence) } } - // resturn all contact structs + // return all contact structs return result; } @@ -303,7 +303,7 @@ roster_get_contacts(void) result = g_slist_insert_sorted(result, value, (GCompareFunc)_compare_contacts); } - // resturn all contact structs + // return all contact structs return result; } @@ -321,7 +321,7 @@ roster_get_contacts_online(void) result = g_slist_insert_sorted(result, value, (GCompareFunc)_compare_contacts); } - // resturn all contact structs + // return all contact structs return result; } @@ -371,7 +371,7 @@ roster_get_nogroup(void) } } - // resturn all contact structs + // return all contact structs return result; } @@ -395,7 +395,7 @@ roster_get_group(const char * const group) } } - // resturn all contact structs + // return all contact structs return result; } diff --git a/src/tools/parser.c b/src/tools/parser.c index 98fc21d4..1f8a5220 100644 --- a/src/tools/parser.c +++ b/src/tools/parser.c @@ -47,9 +47,9 @@ * * inp - The line of input * min - The minimum allowed number of arguments - * max - The maxmimum allowed number of arguments + * max - The maximum allowed number of arguments * - * Returns - An NULL terminated array of strings representing the aguments + * Returns - An NULL terminated array of strings representing the arguments * of the command, or NULL if the validation fails. * * E.g. the following input line: @@ -69,7 +69,7 @@ parse_args(const char * const inp, int min, int max, gboolean *result) return NULL; } - // copy and strip input of leading/trailing whitepsace + // copy and strip input of leading/trailing whitespace char *copy = strdup(inp); g_strstrip(copy); @@ -181,9 +181,9 @@ parse_args(const char * const inp, int min, int max, gboolean *result) * * inp - The line of input * min - The minimum allowed number of arguments - * max - The maxmimum allowed number of arguments + * max - The maximum allowed number of arguments * - * Returns - An NULL terminated array of strings representing the aguments + * Returns - An NULL terminated array of strings representing the arguments * of the command, or NULL if the validation fails. * * E.g. the following input line: diff --git a/src/ui/console.c b/src/ui/console.c index 01d1c73a..ef7df667 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -723,7 +723,7 @@ cons_show_account(ProfAccount *account) if (curr != NULL) { win_save_println(console, "Resources:"); - // sort in order of availabiltiy + // sort in order of availability while (curr != NULL) { Resource *resource = curr->data; ordered_resources = g_list_insert_sorted(ordered_resources, diff --git a/src/ui/core.c b/src/ui/core.c index fc6c0ed4..b5d32c73 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -1871,7 +1871,7 @@ ui_room_message(const char * const roomjid, const char * const nick, if (wins_is_current(window)) { status_bar_active(num); - // not currenlty on groupchat window + // not currently on groupchat window } else { status_bar_new(num); cons_show_incoming_message(nick, num); @@ -1955,7 +1955,7 @@ ui_room_requires_config(const char * const roomjid) if (wins_is_current(window)) { status_bar_active(num); - // not currenlty on groupchat window + // not currently on groupchat window } else { status_bar_new(num); } @@ -2096,7 +2096,7 @@ ui_room_subject(const char * const roomjid, const char * const nick, const char if (wins_is_current(window)) { status_bar_active(num); - // not currenlty on groupchat window + // not currently on groupchat window } else { status_bar_active(num); } @@ -2130,7 +2130,7 @@ ui_room_broadcast(const char * const roomjid, const char * const message) if (wins_is_current(window)) { status_bar_active(num); - // not currenlty on groupchat window + // not currently on groupchat window } else { status_bar_new(num); } diff --git a/src/ui/statusbar.c b/src/ui/statusbar.c index 58f3fc58..b9244fcd 100644 --- a/src/ui/statusbar.c +++ b/src/ui/statusbar.c @@ -192,7 +192,7 @@ status_bar_inactive(const int win) is_new[11] = TRUE; _mark_new(11); - // still have active winsows + // still have active windows } else if (g_hash_table_size(remaining_active) != 0) { is_active[11] = TRUE; is_new[11] = FALSE; @@ -241,7 +241,7 @@ status_bar_active(const int win) _mark_active(11); } - // visible winsow indicators + // visible window indicators } else { is_active[true_win] = TRUE; is_new[true_win] = FALSE; diff --git a/src/ui/window.c b/src/ui/window.c index 85cc875c..d683312b 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -690,7 +690,7 @@ win_show_info(ProfWin *window, PContact contact) if (resources != NULL) { win_save_print(window, '-', NULL, 0, 0, "", "Resources:"); - // sort in order of availabiltiy + // sort in order of availability GList *curr = resources; while (curr != NULL) { Resource *resource = curr->data; diff --git a/src/xmpp/presence.c b/src/xmpp/presence.c index a0d9e0f1..f4c45318 100644 --- a/src/xmpp/presence.c +++ b/src/xmpp/presence.c @@ -517,7 +517,7 @@ _handle_caps(char *jid, XMPPCaps *caps) } } - // unsupported hash, xep-0115, assoiciate with JID, no cache + // unsupported hash, xep-0115, associate with JID, no cache } else if (caps->hash) { log_info("Hash %s not supported: %s, sending service discovery request", caps->hash, jid); char *id = create_unique_id("caps"); From 3eeafa2277c6e3002d5f8cc1aa645701527942c8 Mon Sep 17 00:00:00 2001 From: Olivier Le Moal Date: Sat, 21 Feb 2015 22:22:21 +0100 Subject: [PATCH 090/252] fix segfault on self sent message carbon --- src/xmpp/message.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/xmpp/message.c b/src/xmpp/message.c index 4f341f6a..b264df54 100644 --- a/src/xmpp/message.c +++ b/src/xmpp/message.c @@ -434,6 +434,11 @@ _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, gchar *to = xmpp_stanza_get_attribute(message, STANZA_ATTR_TO); gchar *from = xmpp_stanza_get_attribute(message, STANZA_ATTR_FROM); + // happens when receive a carbon of a self sent message + if(to == NULL) { + to = from; + } + Jid *jid_from = jid_create(from); Jid *jid_to = jid_create(to); Jid *my_jid = jid_create(jabber_get_fulljid()); From c249a60cba286ccf9eff1610c30d2e211d723ea4 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 23 Feb 2015 00:15:33 +0000 Subject: [PATCH 091/252] Finished help tidy --- src/command/command.c | 602 +++++++++++++++++++++++------------------- 1 file changed, 327 insertions(+), 275 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index 4411487d..b6ac88e4 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -117,10 +117,14 @@ static struct cmd_t command_defs[] = "--------------------", "Help on using Profanity.", "", - "area - Summary help for commands in a certain area of functionality.", - "command - Full help for a specific command, for example '/help connect'.", + "area : Summary help for commands in a certain area of functionality.", + "command : Full help for a specific command, for example '/help connect'.", "", "Use with no arguments to see a list of areas.", + "", + "Example: /help commands", + "Example: /help presence", + "Example: /help who", NULL } } }, { "/about", @@ -138,12 +142,18 @@ static struct cmd_t command_defs[] = "----------------------------------------------", "Login to a chat service.", "", - "account - The local account you wish to connect with, or a JID if connecting for the first time.", - "server value - Supply a server if it is different to the domain part of your JID.", - "port value - The port to use if different to the default (5222, or 5223 for SSL).", + "account : The local account you wish to connect with, or a JID if connecting for the first time.", + "server value : Supply a server if it is different to the domain part of your JID.", + "port value : The port to use if different to the default (5222, or 5223 for SSL).", "", "If no account is specified, the default is used if one is configured.", "A local account is created with the JID as it's name if it doesn't already exist.", + "", + "Example: /connect", + "Example: /connect myuser@gmail.com", + "Example: /connect myuser@mycompany.com server talk.google.com", + "Example: /connect bob@someplace port 5678", + "Example: /connect me@chatty server chatty.com port 5443", NULL } } }, { "/disconnect", @@ -161,12 +171,17 @@ static struct cmd_t command_defs[] = "---------------------------", "Send a one to one chat message, or a private message to a chat room occupant.", "", - "contact - The contact's JID, or nickname if one has been set in your roster.", - "nick - A chat room occupant, to whom you wish to send a private message.", - "message - The message to send", + "contact : The contact's JID, or nickname if one has been set in your roster.", + "nick : A chat room occupant, to whom you wish to send a private message.", + "message : The message to send", "", "If the message is omitted, a new chat window will be opened without sending a message.", "Use quotes if the nickname includes spaces.", + "", + "Example: /msg myfriend@server.com Hey, here's a message!", + "Example: /msg otherfriend@server.com", + "Example: /msg Bob Here is a private message", + "Example: /msg \"My Friend\" Hi, how are you?", NULL } } }, { "/roster", @@ -178,23 +193,30 @@ static struct cmd_t command_defs[] = "", "command - online|show|hide|by|size|add|remove|nick|clearnick", "", - "online - Show all online contacts in your roster.", - "show - Show the roster panel.", - "show offline - Show offline contacts in the roster panel.", - "show resource - Show contact's connected resources in the roster panel.", - "hide - Hide the roster panel.", - "hide offline - Hide offline contacts in the roster panel.", - "hide resource - Hide contact's connected resources in the roster panel.", - "by group - Group contacts in the roster panel by roster group.", - "by presence - Group contacts in the roster panel by presence.", - "by none - No grouping in the roster panel.", - "size - Percentage of the screen taken up by the roster (1-99).", - "add jid [nick] - Add a new item to the roster.", - "remove jid - Removes an item from the roster.", - "nick jid nick - Change a contacts nickname.", - "clearnick jid - Removes the current nickname.", + "online : Show all online contacts in your roster.", + "show : Show the roster panel.", + "show offline : Show offline contacts in the roster panel.", + "show resource : Show contact's connected resources in the roster panel.", + "hide : Hide the roster panel.", + "hide offline : Hide offline contacts in the roster panel.", + "hide resource : Hide contact's connected resources in the roster panel.", + "by group : Group contacts in the roster panel by roster group.", + "by presence : Group contacts in the roster panel by presence.", + "by none : No grouping in the roster panel.", + "size : Percentage of the screen taken up by the roster (1-99).", + "add jid [nick] : Add a new item to the roster.", + "remove jid : Removes an item from the roster.", + "nick jid nick : Change a contacts nickname.", + "clearnick jid : Removes the current nickname.", "", "Passing no arguments lists all contacts in your roster.", + "", + "Example: /roster (show your roster)", + "Example: /roster add someone@contacts.org (add the contact)", + "Example: /roster add someone@contacts.org Buddy (add the contact with nickname 'Buddy')", + "Example: /roster remove someone@contacts.org (remove the contact)", + "Example: /roster nick myfriend@chat.org My Friend", + "Example: /roster clearnick kai@server.com (clears nickname)", NULL } } }, { "/group", @@ -204,11 +226,17 @@ static struct cmd_t command_defs[] = "------------------------------------------", "View, add to, and remove from roster groups.", "", - "show group - List all roster items a group.", - "add group contact - Added a contact to a group.", - "remove group contact - Remove a contact from a group.", + "show group : List all roster items a group.", + "add group contact : Added a contact to a group.", + "remove group contact : Remove a contact from a group.", "", "Passing no argument will list all roster groups.", + "", + "Example: /group", + "Example: /group show friends", + "Example: /group add friends newfriend@server.org", + "Example: /group add family Brother (using contacts nickname)", + "Example: /group remove colleagues boss@work.com", NULL } } }, { "/info", @@ -218,11 +246,14 @@ static struct cmd_t command_defs[] = "--------------------", "Show information about a contact, room, or room member.", "", - "contact - The contact you wish to view information about.", - "nick - When in a chat room, the occupant you wish to view information about.", + "contact : The contact you wish to view information about.", + "nick : When in a chat room, the occupant you wish to view information about.", "", "Passing no argument in a chat window will use the current recipient.", "Passing no argument in a chat room will display information about the room.", + "", + "Example: /info mybuddy@chat.server.org", + "Example: /info kai", NULL } } }, { "/caps", @@ -232,10 +263,14 @@ static struct cmd_t command_defs[] = "--------------------", "Find out a contacts, or room members client software capabilities.", "", - "fulljid - If in the console or a chat window, the full JID for which you wish to see capabilities.", - "nick - If in a chat room, nickname for which you wish to see capabilities.", + "fulljid : If in the console or a chat window, the full JID for which you wish to see capabilities.", + "nick : If in a chat room, nickname for which you wish to see capabilities.", "", "If in private chat initiated from a chat room, no parameter is required.", + "", + "Example: /caps mybuddy@chat.server.org/laptop (contact's laptop resource)", + "Example: /caps mybuddy@chat.server.org/phone (contact's phone resource)", + "Example: /caps bruce (room member)", NULL } } }, { "/software", @@ -245,11 +280,15 @@ static struct cmd_t command_defs[] = "------------------------", "Find out a contact, or room members software version information.", "", - "fulljid - If in the console or a chat window, the full JID for which you wish to see software information.", - "nick - If in a chat room, nickname for which you wish to see software information.", + "fulljid : If in the console or a chat window, the full JID for which you wish to see software information.", + "nick : If in a chat room, nickname for which you wish to see software information.", "", "If in private chat initiated from a chat room, no parameter is required.", "If the contact's software does not support software version requests, nothing will be displayed.", + "", + "Example: /software mybuddy@chat.server.org/laptop (contact's laptop resource)", + "Example: /software mybuddy@chat.server.org/phone (contact's phone resource)", + "Example: /software bruce (room member)", NULL } } }, { "/status", @@ -259,10 +298,13 @@ static struct cmd_t command_defs[] = "----------------------", "Find out a contact, or room members presence information.", "", - "contact - The contact who's presence you which to see.", - "nick - If in a chat room, the occupant who's presence you wish to see.", + "contact : The contact who's presence you which to see.", + "nick : If in a chat room, the occupant who's presence you wish to see.", "", "If in a chat window the parameter is not required, the current recipient will be used.", + "", + "Example: /status buddy@server.com", + "Example: /status jon", NULL } } }, { "/resource", @@ -272,10 +314,10 @@ static struct cmd_t command_defs[] = "------------------------------------------", "Override chat session resource, and manage resource display settings.", "", - "set resource - Set the resource to which messages will be sent.", - "off - Let the server choose which resource to route messages to.", - "title on|off - Show or hide the current resource in the titlebar.", - "message on|off - Show or hide the resource when showing an incoming message.", + "set resource : Set the resource to which messages will be sent.", + "off : Let the server choose which resource to route messages to.", + "title on|off : Show or hide the current resource in the titlebar.", + "message on|off : Show or hide the resource when showing an incoming message.", NULL } } }, { "/join", @@ -285,13 +327,18 @@ static struct cmd_t command_defs[] = "-------------------------------------------------", "Join a chat room at the conference server.", "", - "room - Bare room JID, the chat server is determined by the 'muc.service' account property, 'conference.' by default.", - "room@server - Full room JID.", - "nick value - Nickname to use in the room", - "password value - Password if the room requires it.", + "room : Bare room JID, the chat server is determined by the 'muc.service' account property, 'conference.' by default.", + "room@server : Full room JID.", + "nick value : Nickname to use in the room", + "password value : Password if the room requires it.", "", "If no nickname is specfied the account preference 'muc.nick' will be used which by default is the localpart of your JID.", "If the room doesn't exist, and the server allows it, a new one will be created.", + "", + "Example: /join jdev@conference.jabber.org", + "Example: /join jdev@conference.jabber.org nick mynick", + "Example: /join private@conference.jabber.org nick mynick password mypassword", + "Example: /join jdev (as user@jabber.org will join jdev@conference.jabber.org)", NULL } } }, { "/leave", @@ -309,8 +356,8 @@ static struct cmd_t command_defs[] = "-------------------------", "Send a direct invite to the current chat room.", "", - "contact - The contact you wish to invite", - "message - An optional message to send with the invite.", + "contact : The contact you wish to invite", + "message : An optional message to send with the invite.", NULL } } }, { "/invites", @@ -328,7 +375,7 @@ static struct cmd_t command_defs[] = "-------------", "Decline a chat room ivivation.", "", - "room - The room for the invite you wish to decline.", + "room : The room for the invite you wish to decline.", NULL } } }, { "/room", @@ -338,9 +385,9 @@ static struct cmd_t command_defs[] = "---------------------------", "Chat room configuration.", "", - "accept - Accept default room configuration.", - "destroy - Reject default room configuration.", - "config - Edit room configuration.", + "accept : Accept default room configuration.", + "destroy : Reject default room configuration.", + "config : Edit room configuration.", NULL } } }, { "/kick", @@ -350,8 +397,8 @@ static struct cmd_t command_defs[] = "-------------------", "Kick occupants from chat rooms.", "", - "nick - Nickname of the occupant to kick from the room.", - "reason - Optional reason for kicking the occupant.", + "nick : Nickname of the occupant to kick from the room.", + "reason : Optional reason for kicking the occupant.", NULL } } }, { "/ban", @@ -361,8 +408,8 @@ static struct cmd_t command_defs[] = "-----------------", "Ban users from chat rooms.", "", - "jid - Bare JID of the user to ban from the room.", - "reason - Optional reason for banning the user.", + "jid : Bare JID of the user to ban from the room.", + "reason : Optional reason for banning the user.", NULL } } }, { "/subject", @@ -372,8 +419,8 @@ static struct cmd_t command_defs[] = "----------------------------", "Set or clear room subject.", "", - "set subject - Set the room subject.", - "clear - Clear the room subject.", + "set subject : Set the room subject.", + "clear : Clear the room subject.", NULL } } }, { "/affiliation", @@ -383,8 +430,8 @@ static struct cmd_t command_defs[] = "--------------------------------------------------", "Manage room affiliations.", "", - "set affiliation jid [reason]- Set the affiliation of user with jid, with an optional reason.", - "list [affiliation] - List all users with the specified affiliation, or all if none specified.", + "set affiliation jid [reason]: Set the affiliation of user with jid, with an optional reason.", + "list [affiliation] : List all users with the specified affiliation, or all if none specified.", "", "The affiliation may be one of owner, admin, member, outcast or none.", NULL } } }, @@ -396,8 +443,8 @@ static struct cmd_t command_defs[] = "-------------------------------------", "Manage room roles.", "", - "set role nick [reason] - Set the role of occupant with nick, with an optional reason.", - "list [role] - List all occupants with the specified role, or all if none specified.", + "set role nick [reason] : Set the role of occupant with nick, with an optional reason.", + "list [role] : List all occupants with the specified role, or all if none specified.", "", "The role may be one of moderator, participant, visitor or none.", NULL } } }, @@ -409,10 +456,10 @@ static struct cmd_t command_defs[] = "-------------------------------------------------------", "Show or hide room occupants, and occupants panel display settings.", "", - "show - Show the occupants panel in chat rooms.", - "hide - Hide the occupants panel in chat rooms.", - "default show|hide - Whether occupants are shown by default in new rooms, 'show' or 'hide'", - "size percent - Percentage of the screen taken by the occupants list in rooms (1-99).", + "show : Show the occupants panel in chat rooms.", + "hide : Hide the occupants panel in chat rooms.", + "default show|hide : Whether occupants are shown by default in new rooms, 'show' or 'hide'", + "size percent : Percentage of the screen taken by the occupants list in rooms (1-99).", NULL } } }, { "/form", @@ -422,10 +469,10 @@ static struct cmd_t command_defs[] = "-----------------------------------", "Form configuration.", "", - "show - Show the current form.", - "submit - Submit the current form.", - "cancel - Cancel changes to the current form.", - "help [tag] - Display help for form, or a specific field.", + "show : Show the current form.", + "submit : Submit the current form.", + "cancel : Cancel changes to the current form.", + "help [tag] : Display help for form, or a specific field.", NULL } } }, { "/rooms", @@ -435,9 +482,12 @@ static struct cmd_t command_defs[] = "---------------------------", "List the chat rooms available at the specified conference service", "", - "conference-service - The conference service to query.", + "conference-service : The conference service to query.", "", "If no argument is supplied, the account preference 'muc.service' is used, 'conference.' by default.", + "", + "Example: /rooms conference.jabber.org", + "Example: /rooms (if logged in as me@server.org, is equivalent to /rooms conference.server.org)", NULL } } }, { "/bookmark", @@ -447,16 +497,16 @@ static struct cmd_t command_defs[] = "----------------------------", "Manage bookmarks and join bookmarked rooms.", "", - "command - list|add|update|remove|join", + "command : list|add|update|remove|join", "", - "list - List all bookmarks.", - "add room@server [prop value..] - Add a bookmark for room@server with the following optional properties:", - " nick value - Nickname used in the chat room", - " password value - Password if required, may be stored in plaintext on your server", - " autojoin on|off - Whether to join the room automatically on login.", - "update room@server [prop value..] - Update any of the above properties associated with the bookmark.", - "remove room@server - Remove the bookmark for room@server.", - "join room@server - Join room using the properties associated with the bookmark.", + "list : List all bookmarks.", + "add room@server [prop value..] : Add a bookmark for room@server with the following optional properties:", + " nick value : Nickname used in the chat room", + " password value : Password if required, may be stored in plaintext on your server", + " autojoin on|off : Whether to join the room automatically on login.", + "update room@server [prop value..] : Update any of the above properties associated with the bookmark.", + "remove room@server : Remove the bookmark for room@server.", + "join room@server : Join room using the properties associated with the bookmark.", "", "In a chat room, /bookmark with no arguments will bookmark the current room, setting autojoin to \"on\".", NULL } } }, @@ -468,9 +518,14 @@ static struct cmd_t command_defs[] = "---------------------", "Find out information about an entities supported services.", "", - "info - List protocols and features supported by an entity.", - "items - List items associated with an entity.", - "entity - Jabber ID.", + "info : List protocols and features supported by an entity.", + "items : List items associated with an entity.", + "entity : Jabber ID.", + "", + "Example: /disco info myserver.org", + "Example: /disco items myserver.org", + "Example: /disco items conference.jabber.org", + "Example: /disco info myfriend@server.com/laptop", NULL } } }, { "/nick", @@ -480,7 +535,10 @@ static struct cmd_t command_defs[] = "--------------", "Change the name by which other members of a chat room see you.", "", - "nickname - The new nickname.", + "nickname : The new nickname.", + "", + "Example: /nick kai hansen", + "Example: /nick bob", NULL } } }, { "/win", @@ -500,9 +558,9 @@ static struct cmd_t command_defs[] = "---------------------------------------", "Show a list of windows, or tidy or swap.", "", - "tidy - Move windows so there are no gaps.", - "prune - Close all windows with no unread messages, and then tidy as above.", - "swap source target - Swap windows, target may be an empty position.", + "tidy : Move windows so there are no gaps.", + "prune : Close all windows with no unread messages, and then tidy as above.", + "swap source target : Swap windows, target may be an empty position.", "", "Passing no argument will list all currently active windows and information about their usage.", NULL } } }, @@ -514,14 +572,19 @@ static struct cmd_t command_defs[] = "------------------------------------------------", "Manage subscriptions to contact presence.", "", - "request [jid] - Send a subscription request to the user.", - "allow [jid] - Approve a contact's subscription reqeust.", - "deny [jid] - Remove subscription for a contact, or deny a request", - "show [jid] - Show subscriprion status for a contact.", - "sent - Show all sent subscription requests pending a response.", - "received - Show all received subscription requests awaiting your response.", + "request [jid] : Send a subscription request to the user.", + "allow [jid] : Approve a contact's subscription reqeust.", + "deny [jid] : Remove subscription for a contact, or deny a request", + "show [jid] : Show subscriprion status for a contact.", + "sent : Show all sent subscription requests pending a response.", + "received : Show all received subscription requests awaiting your response.", "", "If jid is omitted, the contact of the current window is used.", + "", + "Example: /sub request myfriend@jabber.org", + "Example: /sub allow myfriend@jabber.org", + "Example: /sub request (whilst in chat with contact)", + "Example: /sub sent", NULL } } }, { "/tiny", @@ -531,7 +594,9 @@ static struct cmd_t command_defs[] = "---------", "Send url as tinyurl in current chat.", "", - "url - The url to make tiny.", + "url : The url to make tiny.", + "", + "Example: /tiny http://www.profanity.im", NULL } } }, { "/who", @@ -541,14 +606,14 @@ static struct cmd_t command_defs[] = "--------------------------------------", "Show contacts/room occupants with chosen status, role or affiliation", "", - "status - online|offline|away|dnd|xa|chat|available|unavailable|any", - " online - Contacts that are online, chat, away, xa, dnd", - " available - Contacts that are available for chat - online, chat.", - " unavailable - Contacts that are not available for chat - offline, away, xa, dnd.", - " any - Contacts with any status (same as calling with no argument).", - "role - moderator|participant|visitor", - "affiliation - owner|admin|member", - "group - Filter the results by the specfied group.", + "status : online|offline|away|dnd|xa|chat|available|unavailable|any", + " online : Contacts that are online, chat, away, xa, dnd", + " available : Contacts that are available for chat - online, chat.", + " unavailable : Contacts that are not available for chat - offline, away, xa, dnd.", + " any : Contacts with any status (same as calling with no argument).", + "role : moderator|participant|visitor", + "affiliation : owner|admin|member", + "group : Filter the results by the specfied group.", NULL } } }, { "/close", @@ -558,9 +623,9 @@ static struct cmd_t command_defs[] = "---------------------", "Close the current window, or a number of windows.", "", - "num - Close the specified window.", - "all - Close all windows.", - "read - Close all windows that have no new messages.", + "num : Close the specified window.", + "all : Close all windows.", + "read : Close all windows that have no new messages.", "", "Passing no argument will close the current window.", NULL } } }, @@ -623,19 +688,15 @@ static struct cmd_t command_defs[] = "Configure time precision for the main window.", NULL } } }, - { "/inpblock", // TODO review + { "/inpblock", cmd_inpblock, parse_args, 2, 2, &cons_inpblock_setting, - { "/inpblock timeout|dynamic [millis|on|off]", "Input blocking delay (dynamic or static).", + { "/inpblock timeout|dynamic [millis|on|off]", "Configure input blocking.", { "/inpblock timeout|dynamic [millis|on|off]", "-----------------------------------------", "How long to wait for input before checking for new messages or checking for state changes such as 'idle'.", - "timeout : Time to wait in milliseconds before reading input from the terminal buffer, defaults to 500.", - " : Valid values are 1-1000.", - "dynamic : Start with a 0 timeout and increase the value dynamically up to the specified 'timeout'.", - " : on|off", - "A higher timeout will result in less CPU usage, but a noticable delay for response to input.", - "A lower timeout will result in higher CPU usage, but faster response to input.", - "Using the dynamic setting, higher CPU usage will occur during activity, but over time the CPU usage will decrease whilst there is no activity.", + "", + "timeout millis : Time to wait (1-1000) in milliseconds before reading input from the terminal buffer, default: 1000.", + "dynamic on|off : Start with 0 millis and dynamically increase up to timeout when no activity, default: on.", NULL } } }, { "/notify", @@ -643,40 +704,29 @@ static struct cmd_t command_defs[] = { "/notify [type value]|[type setting value]", "Control various desktop noficiations.", { "/notify [type value]|[type setting value]", "-----------------------------------------", - "Settings for various desktop notifications where type is one of:", - "message : Notificaitons for regular messages.", - " : on|off", - "message current : Whether messages in the current window trigger notifications.", - " : on|off", - "message text : Show message text in message notifications.", - " : on|off", - "room : Notificaitons for chat room messages.", - " : on|off|mention", - "room current : Whether chat room messages in the current window trigger notifications.", - " : on|off", - "room text : Show message test in chat room message notifications.", - " : on|off", - "remind : Notification reminders of unread messages.", - " : where value is the reminder period in seconds,", - " : use 0 to disable.", - "typing : Notifications when contacts are typing.", - " : on|off", - "typing current : Whether typing notifications are triggerd for the current window.", - " : on|off", - "invite : Notifications for chat room invites.", - " : on|off", - "sub : Notifications for subscription requests.", - " : on|off", + "Settings for various kinds of desktop notifications.", "", - "Example : /notify message on (enable message notifications)", - "Example : /notify message text on (show message text in notifications)", - "Example : /notify room mention (enable chat room notifications only on mention)", - "Example : /notify room current off (disable room message notifications when window visible)", - "Example : /notify room text off (do not show message text in chat room notifications)", - "Example : /notify remind 10 (remind every 10 seconds)", - "Example : /notify remind 0 (switch off reminders)", - "Example : /notify typing on (enable typing notifications)", - "Example : /notify invite on (enable chat room invite notifications)", + "message on|off : Notificaitons for regular messages.", + "message current on|off : Whether messages in the current window trigger notifications.", + "message text on|off : Show message text in message notifications.", + "room on|off|mention : Notificaitons for chat room messages.", + "room current on|off : Whether chat room messages in the current window trigger notifications.", + "room text on|off : Show message text in chat room message notifications.", + "remind seconds : Notification reminder period for unread messages, use 0 to disable.", + "typing on|off : Notifications when contacts are typing.", + "typing current of|off : Whether typing notifications are triggerd for the current window.", + "invite on|off : Notifications for chat room invites.", + "sub on|off : Notifications for subscription requests.", + "", + "Example: /notify message on (enable message notifications)", + "Example: /notify message text on (show message text in notifications)", + "Example: /notify room mention (enable chat room notifications only on mention)", + "Example: /notify room current off (disable room message notifications when window visible)", + "Example: /notify room text off (do not show message text in chat room notifications)", + "Example: /notify remind 10 (remind every 10 seconds)", + "Example: /notify remind 0 (switch off reminders)", + "Example: /notify typing on (enable typing notifications)", + "Example: /notify invite on (enable chat room invite notifications)", NULL } } }, { "/flash", @@ -684,8 +734,7 @@ static struct cmd_t command_defs[] = { "/flash on|off", "Terminal flash on new messages.", { "/flash on|off", "-------------", - "Make the terminal flash when incoming messages are received.", - "The flash will only occur if you are not in the chat window associated with the user sending the message.", + "Make the terminal flash when incoming messages are received in another window.", "If the terminal doesn't support flashing, it may attempt to beep.", NULL } } }, @@ -714,7 +763,7 @@ static struct cmd_t command_defs[] = "The setting can be overridden by the -a (--account) command line option.", "", "Example: /autoconnect set jc@stuntteam.org (autoconnect with the specified account).", - "Example: /autoconnect off (disable autoconnect).", + "Example: /autoconnect off (disable autoconnect).", NULL } } }, { "/vercheck", @@ -722,18 +771,18 @@ static struct cmd_t command_defs[] = { "/vercheck [on|off]", "Check for a new release.", { "/vercheck [on|off]", "------------------", - "Without a parameter will check for a new release.", - "Switching on or off will enable/disable a version check when Profanity starts, and each time the /about command is run.", + "Enable/disable a version check when Profanity starts, and each time the /about command is run.", NULL } } }, { "/titlebar", cmd_titlebar, parse_args, 2, 2, &cons_titlebar_setting, { "/titlebar show|goodbye on|off", "Manage the terminal window title.", { "/titlebar show|goodbye on|off", - "---------------------", + "-----------------------------", "Show or hide a title and exit message in the terminal window title.", - "show - Show current logged in user, and unread messages in the title.", - "goodbye - Show a message in the title when exiting profanity.", + "", + "show : Show current logged in user, and unread messages in the title.", + "goodbye : Show a message in the title when exiting profanity.", NULL } } }, { "/mouse", @@ -741,12 +790,7 @@ static struct cmd_t command_defs[] = { "/mouse on|off", "Use profanity mouse handling.", { "/mouse on|off", "-------------", - "If set to 'on', profanity will handle mouse actions, which enables scrolling the main window with the mouse wheel.", - "To select text, use the shift key while selcting an area.", - "If set to 'off', profanity leaves mouse handling to the terminal implementation.", - "This feature is experimental, certain mouse click events may occasionally freeze", - "Profanity until a key is pressed or another mouse event is received", - "The default is 'off'.", + "This feature is experimental, default is 'off'.", NULL } } }, { "/alias", @@ -755,12 +799,17 @@ static struct cmd_t command_defs[] = { "/alias add|remove|list [name value]", "-----------------------------------", "Add, remove or show command aliases.", - "The alias will be available as a command, the leading '/' will be added if not supplied.", - "Example : /alias add friends /who online friends", - "Example : /alias add /q /quit", - "Example : /alias a /away \"I'm in a meeting.\"", - "Example : /alias remove q", - "Example : /alias list", + "", + "add name value : Add a new command alias.", + "remove name : Remove a command alias.", + "list : List all aliases.", + "", + "Example: /alias add friends /who online friends", + "Example: /alias add /q /quit", + "Example: /alias a /away \"I'm in a meeting.\"", + "Example: /alias remove q", + "Example: /alias list", + "", "The above aliases will be available as /friends and /a", NULL } } }, @@ -789,29 +838,30 @@ static struct cmd_t command_defs[] = { "/states on|off", "Send chat states during a chat session.", { "/states on|off", "--------------", - "Sending of chat state notifications during chat sessions.", - "Such as whether you have become inactive, or have closed the chat window.", + "Send chat state notifications during chat sessions.", NULL } } }, { "/otr", cmd_otr, parse_args, 1, 3, NULL, - { "/otr gen|myfp|theirfp|start|end|trust|untrust|log|warn|libver|policy|secret|question|answer", "Off The Record encryption commands.", - { "/otr gen|myfp|theirfp|start|end|trust|untrust|log|warn|libver|policy|secret|question|answer", - "-------------------------------------------------------------------------------------------", - "gen - Generate your private key.", - "myfp - Show your fingerprint.", - "theirfp - Show contacts fingerprint.", - "start [contact] - Start an OTR session with the contact, or the current recipient if in a chat window and no argument supplied.", - "end - End the current OTR session,", - "trust - Indicate that you have verified the contact's fingerprint.", - "untrust - Indicate the the contact's fingerprint is not verified,", - "log - How to log OTR messages, options are 'on', 'off' and 'redact', with redaction being the default.", - "warn - Show when unencrypted messaging is being used in the title bar, options are 'on' and 'off' with 'on' being the default.", - "libver - Show which version of the libotr library is being used.", - "policy - manual, opportunistic or always.", - "secret [secret]- Verify a contacts identity using a shared secret.", - "question [question] [answer] - Verify a contacts identity using a question and expected anwser, if the question has spaces, surround with double quotes.", - "answer [answer] - Respond to a question answer verification request with your answer.", + { "/otr command [args..]", "Off The Record encryption commands.", + { "/otr command [args..]", + "---------------------", + "Off The Record encryption commands.", + "", + "gen : Generate your private key.", + "myfp : Show your fingerprint.", + "theirfp : Show contacts fingerprint.", + "start [contact] : Start an OTR session with contact, or current recipient if omitted.", + "end : End the current OTR session,", + "trust : Indicate that you have verified the contact's fingerprint.", + "untrust : Indicate the the contact's fingerprint is not verified,", + "log on|off|redact : OTR message logging, default: redact.", + "warn on|off : Show in the titlebar when unencrypted messaging is being used.", + "libver : Show which version of the libotr library is being used.", + "policy manual|opportunistic|always : Set the global OTR policy.", + "secret [secret] : Verify a contacts identity using a shared secret.", + "question [question] [answer] : Verify a contacts identity using a question and expected anwser.", + "answer [answer] : Respond to a question answer verification request with your answer.", NULL } } }, { "/outtype", @@ -819,8 +869,7 @@ static struct cmd_t command_defs[] = { "/outtype on|off", "Send typing notification to recipient.", { "/outtype on|off", "---------------", - "Send an indication that you are typing to the chat recipient.", - "Chat states (/states) will be enabled if this setting is set.", + "Send typing notifications, chat states (/states) will be enabled if this setting is set.", NULL } } }, { "/gone", @@ -828,8 +877,7 @@ static struct cmd_t command_defs[] = { "/gone minutes", "Send 'gone' state to recipient after a period.", { "/gone minutes", "-------------", - "Send a 'gone' state to the recipient after the specified number of minutes." - "This indicates to the recipient's client that you have left the conversation.", + "Send a 'gone' state to the recipient after the specified number of minutes.", "A value of 0 will disable sending this chat state.", "Chat states (/states) will be enabled if this setting is set.", NULL } } }, @@ -845,14 +893,15 @@ static struct cmd_t command_defs[] = { "/log", cmd_log, parse_args, 1, 2, &cons_log_setting, - { "/log [property] [value]", "Manage system logging settings.", - { "/log [property] [value]", - "-----------------------", - "where : Show the current log file location.", - "Property may be one of:", - "rotate : Rotate log, accepts 'on' or 'off', defaults to 'on'.", - "maxsize : With rotate enabled, specifies the max log size, defaults to 1048580 (1MB).", - "shared : Share logs between all instances, accepts 'on' or 'off', defaults to 'on'.", + { "/log where|rotate|maxsize|shared [value]", "Manage system logging settings.", + { "/log where|rotate|maxsize|shared [value]", + "----------------------------------------", + "Manage profanity logging settings.", + "", + "where : Show the current log file location.", + "rotate on|off : Rotate log, default on.", + "maxsize bytes : With rotate enabled, specifies the max log size, defaults to 1048580 (1MB).", + "shared on|off : Share logs between all instances, default: on.", NULL } } }, { "/reconnect", @@ -879,23 +928,22 @@ static struct cmd_t command_defs[] = { "/ping [rarget]", "--------------", "Sends an IQ ping stanza to the specificed target.", - "If no target is supplied, your chat server will be used.", + "If no target is supplied, your chat server will be pinged.", NULL } } }, { "/autoaway", cmd_autoaway, parse_args_with_freetext, 2, 2, &cons_autoaway_setting, - { "/autoaway setting value", "Set auto idle/away properties.", - { "/autoaway setting value", - "-----------------------", - "'setting' may be one of 'mode', 'time', 'message' or 'check', with the following values:", + { "/autoaway mode|time|message|check value", "Set auto idle/away properties.", + { "/autoaway mode|time|message|check value", + "---------------------------------------", + "Manage autoway properties.", "", - "mode : idle - Sends idle time, whilst your status remains online.", - " away - Sends an away presence.", - " off - Disabled (default).", - "time : Number of minutes before the presence change is sent, the default is 15.", - "message : Optional message to send with the presence change.", - " : off - Disable message (default).", - "check : on|off, when enabled, checks for activity and sends online presence, default is 'on'.", + "mode idle : Sends idle time, status remains online.", + "mode away : Sends an away presence.", + "mode off : Disabled (default).", + "time minutes : Number of minutes before the presence change is sent, default: 15.", + "message text|off : Optional message to send with the presence change, default: off (disabled).", + "check on|off : When enabled, checks for activity and sends online presence, default: on.", "", "Example: /autoaway mode idle", "Example: /autoaway time 30", @@ -908,9 +956,11 @@ static struct cmd_t command_defs[] = { "/priority value", "Set priority for the current account.", { "/priority value", "---------------", - "Set priority for the current account, presence will be sent when calling this command.", - "See the /account command for more specific priority settings per presence status.", - "value : Number between -128 and 127. Default value is 0.", + "Set priority for the current account.", + "", + "value : Number between -128 and 127, default: 0.", + "", + "See the /account command for specific priority settings per presence status.", NULL } } }, { "/account", @@ -919,6 +969,7 @@ static struct cmd_t command_defs[] = { "/account [command] [account] [property] [value]", "-----------------------------------------------", "Commands for creating and managing accounts.", + "", "list : List all accounts.", "show account : Show information about an account.", "enable account : Enable the account, it will be used for autocomplete.", @@ -930,43 +981,38 @@ static struct cmd_t command_defs[] = "set account property value : Set 'property' of 'account' to 'value'.", "clear account property value : Clear 'property' of 'account'.", "", - "When connected, the /account command can be called with no arguments, to show current account settings.", + "Account properties.", "", - "The set command may use one of the following for 'property'.", - "jid : The Jabber ID of the account, the account name will be used if this property is not set.", - "server : The chat server, if different to the domainpart of the JID.", - "port : The port used for connecting if not the default (5222, or 5223 for SSL).", - "status : The presence status to use on login, use 'last' to use whatever your last status was.", - "online|chat|away", - "|xa|dnd : Priority for the specified presence.", - "resource : The resource to be used.", - "password : Password for the account, note this is currently stored in plaintext if set.", - "eval_password : Shell command evaluated to retrieve password for the account. Can be used to retrieve password from keyring.", - "muc : The default MUC chat service to use.", - "nick : The default nickname to use when joining chat rooms.", - "otr : Override global OTR policy for this account: manual, opportunistic or always.", + "jid : The Jabber ID of the account, account name will be used if not set.", + "server : The chat server, if different to the domainpart of the JID.", + "port : The port used for connecting if not the default (5222, or 5223 for SSL).", + "status : The presence status to use on login, use 'last' to use your last status before logging out.", + "online|chat|away|xa|dnd : Priority for the specified presence.", + "resource : The resource to be used.", + "password : Password for the account, note this is currently stored in plaintext if set.", + "eval_password : Shell command evaluated to retrieve password for the account. Can be used to retrieve password from keyring.", + "muc : The default MUC chat service to use.", + "nick : The default nickname to use when joining chat rooms.", + "otr : Override global OTR policy for this account: manual, opportunistic or always.", "", - "The clear command works for password, port and server", - "", - "Example : /account add work", - " : /account set work jid me@chatty", - " : /account set work server talk.chat.com", - " : /account set work port 5111", - " : /account set work resource desktop", - " : /account set work muc chatservice.mycompany.com", - " : /account set work nick dennis", - " : /account set work status dnd", - " : /account set work dnd -1", - " : /account set work online 10", - " : /account rename work gtalk", + "Example: /account add me", + "Example: /account set me jid me@chatty", + "Example: /account set me server talk.chat.com", + "Example: /account set me port 5111", + "Example: /account set me muc chatservice.mycompany.com", + "Example: /account set me nick dennis", + "Example: /account set me status dnd", + "Example: /account set me dnd -1", + "Example: /account rename me gtalk", NULL } } }, { "/prefs", cmd_prefs, parse_args, 0, 1, NULL, - { "/prefs [area]", "Show configuration.", - { "/prefs [area]", - "-------------", - "Area is one of:", + { "/prefs [ui|desktop|chat|log|conn|presence]", "Show configuration.", + { "/prefs [ui|desktop|chat|log|conn|presence]", + "------------------------------------------", + "Show preferences for different areas of functionality.", + "", "ui : User interface preferences.", "desktop : Desktop notification preferences.", "chat : Chat state preferences.", @@ -974,7 +1020,7 @@ static struct cmd_t command_defs[] = "conn : Connection handling preferences.", "presence : Chat presence preferences.", "", - "No argument shows all categories.", + "No argument shows all preferences.", NULL } } }, { "/theme", @@ -982,14 +1028,14 @@ static struct cmd_t command_defs[] = { "/theme list|set|colours [theme-name]", "Change colour theme.", { "/theme list|set|colours [theme-name]", "------------------------------------", - "Change the colour settings used.", + "Load a theme, includes colours and UI options.", "", "list : List all available themes.", - "set theme-name : Load the named theme.\"default\" will reset to the default colours.", + "set theme-name : Load the named theme. 'default' will reset to the default theme.", "colours : Show the colour values as rendered by the terminal.", "", - "Example : /theme list", - "Example : /theme set mycooltheme", + "Example: /theme list", + "Example: /theme set mycooltheme", NULL } } }, @@ -998,12 +1044,23 @@ static struct cmd_t command_defs[] = { "/statuses console|chat|muc setting", "Set preferences for presence change messages.", { "/statuses console|chat|muc setting", "----------------------------------", - "Configure how presence changes are displayed in various windows.", - "Settings:", - " all - Show all presence changes.", - " online - Show only online/offline changes.", - " none - Don't show any presence changes.", + "Configure which presence changes are displayed in various windows.", + "", + "console : Configure what is displayed in the console window.", + "chat : Configure what is displayed in chat windows.", + "muc : Configure what is displayed in chat room windows.", + "", + "Available options are:", + "", + "all : Show all presence changes.", + "online : Show only online/offline changes.", + "none : Don't show any presence changes.", + "", "The default is 'all' for all windows.", + "", + "Example: /statuses console none", + "Example: /statuses chat online", + "Example: /statuses muc all", NULL } } }, { "/xmlconsole", @@ -1016,57 +1073,52 @@ static struct cmd_t command_defs[] = { "/away", cmd_away, parse_args_with_freetext, 0, 1, NULL, - { "/away [msg]", "Set status to away.", - { "/away [msg]", - "-----------", + { "/away [message]", "Set status to away.", + { "/away [message]", + "---------------", "Set your status to 'away' with the optional message.", - "Your current status can be found in the top right of the screen.", "", - "Example : /away Gone for lunch", + "Example: /away Gone for lunch", NULL } } }, { "/chat", cmd_chat, parse_args_with_freetext, 0, 1, NULL, - { "/chat [msg]", "Set status to chat (available for chat).", - { "/chat [msg]", - "-----------", + { "/chat [message]", "Set status to chat (available for chat).", + { "/chat [message]", + "---------------", "Set your status to 'chat', meaning 'available for chat', with the optional message.", - "Your current status can be found in the top right of the screen.", "", - "Example : /chat Please talk to me!", + "Example: /chat Please talk to me!", NULL } } }, { "/dnd", cmd_dnd, parse_args_with_freetext, 0, 1, NULL, - { "/dnd [msg]", "Set status to dnd (do not disturb).", - { "/dnd [msg]", - "----------", + { "/dnd [message]", "Set status to dnd (do not disturb).", + { "/dnd [message]", + "--------------", "Set your status to 'dnd', meaning 'do not disturb', with the optional message.", - "Your current status can be found in the top right of the screen.", "", - "Example : /dnd I'm in the zone", + "Example: /dnd I'm in the zone", NULL } } }, { "/online", cmd_online, parse_args_with_freetext, 0, 1, NULL, - { "/online [msg]", "Set status to online.", - { "/online [msg]", - "-------------", + { "/online [message]", "Set status to online.", + { "/online [message]", + "-----------------", "Set your status to 'online' with the optional message.", - "Your current status can be found in the top right of the screen.", "", - "Example : /online Up the Irons!", + "Example: /online Up the Irons!", NULL } } }, { "/xa", cmd_xa, parse_args_with_freetext, 0, 1, NULL, - { "/xa [msg]", "Set status to xa (extended away).", - { "/xa [msg]", - "---------", + { "/xa [message]", "Set status to xa (extended away).", + { "/xa [message]", + "-------------", "Set your status to 'xa', meaning 'extended away', with the optional message.", - "Your current status can be found in the top right of the screen.", "", - "Example : /xa This meeting is going to be a long one", + "Example: /xa This meeting is going to be a long one", NULL } } }, }; From ba22baba90358ce755644b4478e506a88314f81d Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 23 Feb 2015 00:24:24 +0000 Subject: [PATCH 092/252] Updated .travis.yml to use cmocka-1.0.0 --- .travis.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index c87d68b7..534440d0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,15 +11,15 @@ install: - sudo make install - cd .. - rm -rf libstrophe - - wget https://open.cryptomilk.org/attachments/download/42/cmocka-0.4.1.tar.xz - - tar -xvf cmocka-0.4.1.tar.xz - - cd cmocka-0.4.1 + - wget https://cmocka.org/files/1.0/cmocka-1.0.0.tar.xz + - tar -xvf cmocka-1.0.0.tar.xz + - cd cmocka-1.0.0 - mkdir build - cd build - cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Debug .. - make - sudo make install - cd ../.. - - rm -rf cmocka-0.4.1 + - rm -rf cmocka-1.0.0 - ./bootstrap.sh script: ./configure && make && make check From cd084c7e46d40deee566e4aa5758c233d9f56632 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 23 Feb 2015 00:37:46 +0000 Subject: [PATCH 093/252] Updated CHANGELOG --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index 2d9970c7..4add51cf 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -15,3 +15,4 @@ - Lower CPU usage with dynamic input blocking timeout - Keychain/keyring integration using account eval_password property - Disable term window title by default +- Fixed remote code execution bug on OSX when desktop notifications configured to show message text From a2a187892b7bb0a343b8bbe3c46dee051d534bde Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 23 Feb 2015 23:12:44 +0000 Subject: [PATCH 094/252] Lowercase barejid before adding to roster --- src/xmpp/roster.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/xmpp/roster.c b/src/xmpp/roster.c index e6f4c2ca..1e943fb6 100644 --- a/src/xmpp/roster.c +++ b/src/xmpp/roster.c @@ -241,6 +241,7 @@ _roster_set_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, jid_destroy(my_jid); const char *barejid = xmpp_stanza_get_attribute(item, STANZA_ATTR_JID); + gchar *barejid_lower = g_utf8_strdown(barejid, -1); const char *name = xmpp_stanza_get_attribute(item, STANZA_ATTR_NAME); const char *sub = xmpp_stanza_get_attribute(item, STANZA_ATTR_SUBSCRIPTION); const char *ask = xmpp_stanza_get_attribute(item, STANZA_ATTR_ASK); @@ -254,12 +255,12 @@ _roster_set_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, if (g_strcmp0(sub, "remove") == 0) { // remove barejid and name if (name == NULL) { - name = barejid; + name = barejid_lower; } - roster_remove(name, barejid); + roster_remove(name, barejid_lower); - handle_roster_remove(barejid); + handle_roster_remove(barejid_lower); // otherwise update local roster } else { @@ -273,14 +274,14 @@ _roster_set_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, GSList *groups = _get_groups_from_item(item); // update the local roster - PContact contact = roster_get_contact(barejid); + PContact contact = roster_get_contact(barejid_lower); if (contact == NULL) { - gboolean added = roster_add(barejid, name, groups, sub, pending_out); + gboolean added = roster_add(barejid_lower, name, groups, sub, pending_out); if (added) { - handle_roster_add(barejid, name); + handle_roster_add(barejid_lower, name); } } else { - handle_roster_update(barejid, name, groups, sub, pending_out); + handle_roster_update(barejid_lower, name, groups, sub, pending_out); } } @@ -300,6 +301,7 @@ _roster_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, while (item != NULL) { const char *barejid = xmpp_stanza_get_attribute(item, STANZA_ATTR_JID); + gchar *barejid_lower = g_utf8_strdown(barejid, -1); const char *name = xmpp_stanza_get_attribute(item, STANZA_ATTR_NAME); const char *sub = xmpp_stanza_get_attribute(item, STANZA_ATTR_SUBSCRIPTION); @@ -316,10 +318,10 @@ _roster_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, GSList *groups = _get_groups_from_item(item); - gboolean added = roster_add(barejid, name, groups, sub, pending_out); + gboolean added = roster_add(barejid_lower, name, groups, sub, pending_out); if (!added) { - log_warning("Attempt to add contact twice: %s", barejid); + log_warning("Attempt to add contact twice: %s", barejid_lower); } item = xmpp_stanza_get_next(item); From b0176d050f9eb93101ac3e5775e43e881a0060fd Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 23 Feb 2015 23:30:13 +0000 Subject: [PATCH 095/252] Lowercase barejid before searching roster --- src/roster_list.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/roster_list.c b/src/roster_list.c index b9a142cb..ad1864f1 100644 --- a/src/roster_list.c +++ b/src/roster_list.c @@ -91,7 +91,7 @@ roster_update_presence(const char * const barejid, Resource *resource, assert(barejid != NULL); assert(resource != NULL); - PContact contact = g_hash_table_lookup(contacts, barejid); + PContact contact = roster_get_contact(barejid); if (contact == NULL) { return FALSE; } @@ -109,14 +109,18 @@ roster_update_presence(const char * const barejid, Resource *resource, PContact roster_get_contact(const char * const barejid) { - return g_hash_table_lookup(contacts, barejid); + gchar *barejidlower = g_utf8_strdown(barejid, -1); + PContact contact = g_hash_table_lookup(contacts, barejidlower); + g_free(barejidlower); + + return contact; } gboolean roster_contact_offline(const char * const barejid, const char * const resource, const char * const status) { - PContact contact = g_hash_table_lookup(contacts, barejid); + PContact contact = roster_get_contact(barejid); if (contact == NULL) { return FALSE; @@ -212,7 +216,7 @@ void roster_update(const char * const barejid, const char * const name, GSList *groups, const char * const subscription, gboolean pending_out) { - PContact contact = g_hash_table_lookup(contacts, barejid); + PContact contact = roster_get_contact(barejid); assert(contact != NULL); p_contact_set_subscription(contact, subscription); @@ -239,7 +243,7 @@ gboolean roster_add(const char * const barejid, const char * const name, GSList *groups, const char * const subscription, gboolean pending_out) { - PContact contact = g_hash_table_lookup(contacts, barejid); + PContact contact = roster_get_contact(barejid); if (contact != NULL) { return FALSE; } From 70b923a7fcc11011e536ffb741f6158798f2fb8e Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 23 Feb 2015 23:44:34 +0000 Subject: [PATCH 096/252] Lowercase barejid in Jid --- src/jid.c | 7 +++++-- src/xmpp/roster.c | 3 +++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/jid.c b/src/jid.c index d1c25ddb..e314b2cf 100644 --- a/src/jid.c +++ b/src/jid.c @@ -88,11 +88,12 @@ jid_create(const gchar * const str) if (slashp != NULL) { result->resourcepart = g_strdup(slashp + 1); result->domainpart = g_utf8_substring(domain_start, 0, g_utf8_pointer_to_offset(domain_start, slashp)); - result->barejid = g_utf8_substring(trimmed, 0, g_utf8_pointer_to_offset(trimmed, slashp)); + char *barejidraw = g_utf8_substring(trimmed, 0, g_utf8_pointer_to_offset(trimmed, slashp)); + result->barejid = g_utf8_strdown(barejidraw, -1); result->fulljid = g_strdup(trimmed); } else { result->domainpart = g_strdup(domain_start); - result->barejid = g_strdup(trimmed); + result->barejid = g_utf8_strdown(trimmed, -1); } if (result->domainpart == NULL) { @@ -144,7 +145,9 @@ jid_is_valid_room_form(Jid *jid) char * create_fulljid(const char * const barejid, const char * const resource) { + gchar *barejidlower = g_utf8_strdown(barejid, -1); GString *full_jid = g_string_new(barejid); + g_free(barejidlower); g_string_append(full_jid, "/"); g_string_append(full_jid, resource); diff --git a/src/xmpp/roster.c b/src/xmpp/roster.c index 1e943fb6..6de370aa 100644 --- a/src/xmpp/roster.c +++ b/src/xmpp/roster.c @@ -285,6 +285,8 @@ _roster_set_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, } } + g_free(barejid_lower); + return 1; } @@ -324,6 +326,7 @@ _roster_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, log_warning("Attempt to add contact twice: %s", barejid_lower); } + g_free(barejid_lower); item = xmpp_stanza_get_next(item); } From f5686cab1e5fbfc6bcfb2385792e8738a38a1890 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 23 Feb 2015 23:52:53 +0000 Subject: [PATCH 097/252] Fixed create_fulljid --- src/jid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/jid.c b/src/jid.c index e314b2cf..0a722b1e 100644 --- a/src/jid.c +++ b/src/jid.c @@ -146,7 +146,7 @@ char * create_fulljid(const char * const barejid, const char * const resource) { gchar *barejidlower = g_utf8_strdown(barejid, -1); - GString *full_jid = g_string_new(barejid); + GString *full_jid = g_string_new(barejidlower); g_free(barejidlower); g_string_append(full_jid, "/"); g_string_append(full_jid, resource); From 434fb1878bd3a387ef7b36c8e8dc124160d023ad Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 24 Feb 2015 21:42:43 +0000 Subject: [PATCH 098/252] Fixed /resource preference display --- src/ui/console.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ui/console.c b/src/ui/console.c index ef7df667..c5b743fa 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -857,9 +857,9 @@ cons_resource_setting(void) else cons_show("Resource title (/resource) : OFF"); if (prefs_get_boolean(PREF_RESOURCE_MESSAGE)) - cons_show("Message title (/resource) : ON"); + cons_show("Resource message (/resource) : ON"); else - cons_show("Message title (/resource) : OFF"); + cons_show("Resource message (/resource) : OFF"); } void From 84c02ffb72c2adae8d3a8b5231004b184c213d3e Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 24 Feb 2015 22:24:20 +0000 Subject: [PATCH 099/252] Added /roster by preference to UI preferences summary --- src/ui/console.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/ui/console.c b/src/ui/console.c index c5b743fa..194d7698 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -1003,6 +1003,9 @@ cons_roster_setting(void) else cons_show("Roster resource (/roster) : hide"); + char *by = prefs_get_string(PREF_ROSTER_BY); + cons_show("Roster by (/roster : %s", by); + int size = prefs_get_roster_size(); cons_show("Roster size (/roster) : %d", size); } From 68a8ab3401046d4e8b62a8e0081db2b156f0c5b1 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 24 Feb 2015 22:53:57 +0000 Subject: [PATCH 100/252] Updated default preferences --- src/config/preferences.c | 17 +++++++++++++---- src/ui/console.c | 2 +- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/config/preferences.c b/src/config/preferences.c index a1f82940..d5bd64d3 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -358,7 +358,7 @@ prefs_get_occupants_size(void) gint result = g_key_file_get_integer(prefs, PREF_GROUP_UI, "occupants.size", NULL); if (result > 99 || result < 1) { - return 20; + return 15; } else { return result; } @@ -377,7 +377,7 @@ prefs_get_roster_size(void) gint result = g_key_file_get_integer(prefs, PREF_GROUP_UI, "roster.size", NULL); if (result > 99 || result < 1) { - return 20; + return 25; } else { return result; } @@ -691,15 +691,24 @@ _get_default_boolean(preference_t pref) case PREF_AUTOAWAY_CHECK: case PREF_LOG_ROTATE: case PREF_LOG_SHARED: + case PREF_NOTIFY_MESSAGE: case PREF_NOTIFY_MESSAGE_CURRENT: case PREF_NOTIFY_ROOM_CURRENT: + case PREF_NOTIFY_TYPING: case PREF_NOTIFY_TYPING_CURRENT: + case PREF_NOTIFY_SUB: + case PREF_NOTIFY_INVITE: case PREF_SPLASH: case PREF_OCCUPANTS: case PREF_MUC_PRIVILEGES: case PREF_PRESENCE: case PREF_WRAP: case PREF_INPBLOCK_DYNAMIC: + case PREF_RESOURCE_TITLE: + case PREF_RESOURCE_MESSAGE: + case PREF_ROSTER: + case PREF_ROSTER_OFFLINE: + case PREF_ROSTER_RESOURCE: return TRUE; default: return FALSE; @@ -715,7 +724,7 @@ _get_default_string(preference_t pref) { case PREF_AUTOAWAY_MODE: case PREF_NOTIFY_ROOM: - return "off"; + return "on"; case PREF_OTR_LOG: return "redact"; case PREF_OTR_POLICY: @@ -725,7 +734,7 @@ _get_default_string(preference_t pref) case PREF_STATUSES_MUC: return "all"; case PREF_ROSTER_BY: - return "none"; + return "presence"; case PREF_TIME: return "seconds"; default: diff --git a/src/ui/console.c b/src/ui/console.c index 194d7698..8f1a1143 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -1004,7 +1004,7 @@ cons_roster_setting(void) cons_show("Roster resource (/roster) : hide"); char *by = prefs_get_string(PREF_ROSTER_BY); - cons_show("Roster by (/roster : %s", by); + cons_show("Roster by (/roster) : %s", by); int size = prefs_get_roster_size(); cons_show("Roster size (/roster) : %d", size); From 22daac5fe9a0b2121deca57ea42e4094b288fb8c Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 25 Feb 2015 00:01:41 +0000 Subject: [PATCH 101/252] Upgrade otr warn preference, added UI theme settings --- src/config/preferences.c | 30 ++++++------------------------ src/config/theme.c | 18 +++++++++++------- 2 files changed, 17 insertions(+), 31 deletions(-) diff --git a/src/config/preferences.c b/src/config/preferences.c index d5bd64d3..b29d7322 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -100,30 +100,12 @@ prefs_load(void) g_error_free(err); } - // move pre 0.4.1 OTR preferences to [otr] group + // move pre 0.4.6 OTR warn preferences to [ui] group err = NULL; - gboolean ui_otr_warn = g_key_file_get_boolean(prefs, PREF_GROUP_UI, "otr.warn", &err); + gboolean otr_warn = g_key_file_get_boolean(prefs, PREF_GROUP_OTR, "warn", &err); if (err == NULL) { - g_key_file_set_boolean(prefs, PREF_GROUP_OTR, _get_key(PREF_OTR_WARN), ui_otr_warn); - g_key_file_remove_key(prefs, PREF_GROUP_UI, "otr.warn", NULL); - } else { - g_error_free(err); - } - - err = NULL; - gchar *ui_otr_log = g_key_file_get_string(prefs, PREF_GROUP_LOGGING, "otr", &err); - if (err == NULL) { - g_key_file_set_string(prefs, PREF_GROUP_OTR, _get_key(PREF_OTR_LOG), ui_otr_log); - g_key_file_remove_key(prefs, PREF_GROUP_LOGGING, "otr", NULL); - } else { - g_error_free(err); - } - - err = NULL; - gchar *ui_otr_policy = g_key_file_get_string(prefs, "policy", "otr.policy", &err); - if (err == NULL) { - g_key_file_set_string(prefs, PREF_GROUP_OTR, _get_key(PREF_OTR_POLICY), ui_otr_policy); - g_key_file_remove_group(prefs, "policy", NULL); + g_key_file_set_boolean(prefs, PREF_GROUP_UI, _get_key(PREF_OTR_WARN), otr_warn); + g_key_file_remove_key(prefs, PREF_GROUP_OTR, "warn", NULL); } else { g_error_free(err); } @@ -531,6 +513,7 @@ _get_group(preference_t pref) case PREF_ROSTER_BY: case PREF_RESOURCE_TITLE: case PREF_RESOURCE_MESSAGE: + case PREF_OTR_WARN: case PREF_INPBLOCK_DYNAMIC: return PREF_GROUP_UI; case PREF_STATES: @@ -559,7 +542,6 @@ _get_group(preference_t pref) case PREF_CONNECT_ACCOUNT: case PREF_DEFAULT_ACCOUNT: return PREF_GROUP_CONNECTION; - case PREF_OTR_WARN: case PREF_OTR_LOG: case PREF_OTR_POLICY: return PREF_GROUP_OTR; @@ -648,7 +630,7 @@ _get_key(preference_t pref) case PREF_OTR_LOG: return "log"; case PREF_OTR_WARN: - return "warn"; + return "otr.warn"; case PREF_OTR_POLICY: return "policy"; case PREF_LOG_ROTATE: diff --git a/src/config/theme.c b/src/config/theme.c index e9389417..d2bf0a48 100644 --- a/src/config/theme.c +++ b/src/config/theme.c @@ -421,20 +421,20 @@ _set_boolean_preference(char *prefstr, preference_t pref) static void _load_preferences(void) { - _set_boolean_preference("intype", PREF_INTYPE); _set_boolean_preference("beep", PREF_BEEP); _set_boolean_preference("flash", PREF_FLASH); - _set_boolean_preference("privileges", PREF_MUC_PRIVILEGES); - _set_boolean_preference("presence", PREF_PRESENCE); + _set_boolean_preference("splash", PREF_SPLASH); _set_boolean_preference("wrap", PREF_WRAP); - _set_string_preference("time", PREF_TIME); - _set_string_preference("statuses.muc", PREF_STATUSES_MUC); + + _set_boolean_preference("resource.title", PREF_RESOURCE_TITLE); + _set_boolean_preference("resource.message", PREF_RESOURCE_MESSAGE); + _set_string_preference("statuses.console", PREF_STATUSES_CONSOLE); _set_string_preference("statuses.chat", PREF_STATUSES_CHAT); + _set_string_preference("statuses.muc", PREF_STATUSES_MUC); _set_boolean_preference("occupants", PREF_OCCUPANTS); - if (g_key_file_has_key(theme, "ui", "occupants.size", NULL)) { gint occupants_size = g_key_file_get_integer(theme, "ui", "occupants.size", NULL); prefs_set_occupants_size(occupants_size); @@ -444,12 +444,16 @@ _load_preferences(void) _set_boolean_preference("roster.offline", PREF_ROSTER_OFFLINE); _set_boolean_preference("roster.resource", PREF_ROSTER_RESOURCE); _set_string_preference("roster.by", PREF_ROSTER_BY); - if (g_key_file_has_key(theme, "ui", "roster.size", NULL)) { gint roster_size = g_key_file_get_integer(theme, "ui", "roster.size", NULL); prefs_set_roster_size(roster_size); } + _set_boolean_preference("privileges", PREF_MUC_PRIVILEGES); + + _set_boolean_preference("presence", PREF_PRESENCE); + _set_boolean_preference("intype", PREF_INTYPE); + _set_boolean_preference("otr.warn", PREF_OTR_WARN); } From d89112e13894d4d6a23846997ea7ef0c42674fe4 Mon Sep 17 00:00:00 2001 From: Olivier LE MOAL Date: Wed, 25 Feb 2015 10:10:30 +0100 Subject: [PATCH 102/252] Upgrade CMocka to 1.0.0 --- .travis.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index c87d68b7..534440d0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,15 +11,15 @@ install: - sudo make install - cd .. - rm -rf libstrophe - - wget https://open.cryptomilk.org/attachments/download/42/cmocka-0.4.1.tar.xz - - tar -xvf cmocka-0.4.1.tar.xz - - cd cmocka-0.4.1 + - wget https://cmocka.org/files/1.0/cmocka-1.0.0.tar.xz + - tar -xvf cmocka-1.0.0.tar.xz + - cd cmocka-1.0.0 - mkdir build - cd build - cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Debug .. - make - sudo make install - cd ../.. - - rm -rf cmocka-0.4.1 + - rm -rf cmocka-1.0.0 - ./bootstrap.sh script: ./configure && make && make check From cbdfc09a84ba80dce2199447b2b59f0d5866e3a4 Mon Sep 17 00:00:00 2001 From: James Booth Date: Thu, 26 Feb 2015 00:49:21 +0000 Subject: [PATCH 103/252] Renamed /theme set -> /theme load --- src/command/command.c | 20 ++++++++++---------- src/command/commands.c | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index f37ea461..d596c489 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -1025,17 +1025,17 @@ static struct cmd_t command_defs[] = { "/theme", cmd_theme, parse_args, 1, 2, &cons_theme_setting, - { "/theme list|set|colours [theme-name]", "Change colour theme.", - { "/theme list|set|colours [theme-name]", - "------------------------------------", + { "/theme list|load|colours [theme-name]", "Change colour theme.", + { "/theme list|load|colours [theme-name]", + "-------------------------------------", "Load a theme, includes colours and UI options.", "", - "list : List all available themes.", - "set theme-name : Load the named theme. 'default' will reset to the default theme.", - "colours : Show the colour values as rendered by the terminal.", + "list : List all available themes.", + "load theme-name : Load the named theme. 'default' will reset to the default theme.", + "colours : Show the colour values as rendered by the terminal.", "", "Example: /theme list", - "Example: /theme set mycooltheme", + "Example: /theme load mycooltheme", NULL } } }, @@ -1293,8 +1293,8 @@ cmd_init(void) autocomplete_add(autoconnect_ac, "off"); theme_ac = autocomplete_new(); + autocomplete_add(theme_ac, "load"); autocomplete_add(theme_ac, "list"); - autocomplete_add(theme_ac, "set"); autocomplete_add(theme_ac, "colours"); disco_ac = autocomplete_new(); @@ -2517,7 +2517,7 @@ static char * _theme_autocomplete(const char * const input) { char *result = NULL; - if ((strncmp(input, "/theme set ", 11) == 0) && (strlen(input) > 11)) { + if ((strncmp(input, "/theme load ", 12) == 0) && (strlen(input) > 12)) { if (theme_load_ac == NULL) { theme_load_ac = autocomplete_new(); GSList *themes = theme_list(); @@ -2529,7 +2529,7 @@ _theme_autocomplete(const char * const input) g_slist_free_full(themes, g_free); autocomplete_add(theme_load_ac, "default"); } - result = autocomplete_param_with_ac(input, "/theme set", theme_load_ac, TRUE); + result = autocomplete_param_with_ac(input, "/theme load", theme_load_ac, TRUE); if (result != NULL) { return result; } diff --git a/src/command/commands.c b/src/command/commands.c index 63cdedf7..18f8bf69 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -822,7 +822,7 @@ cmd_theme(gchar **args, struct cmd_help_t help) g_slist_free_full(themes, g_free); // load a theme - } else if (g_strcmp0(args[0], "set") == 0) { + } else if (g_strcmp0(args[0], "load") == 0) { if (args[1] == NULL) { cons_show("Usage: %s", help.usage); } else if (theme_load(args[1])) { From 30b5f112fd81890411d6fe52c1f442f4433e0d01 Mon Sep 17 00:00:00 2001 From: James Booth Date: Thu, 26 Feb 2015 23:23:15 +0000 Subject: [PATCH 104/252] Updated themes for release --- theme_template | 72 ++++++++++++++++++++++++++++++++++++++++ themes/advanced | 69 -------------------------------------- themes/aqua | 34 +++++++++++-------- themes/batman | 19 +++++++++-- themes/boothj5 | 75 ++++++++++++++++++++++-------------------- themes/complex | 22 +++++++++++++ themes/forest | 60 ++++++++++++++++----------------- themes/hacker | 58 ++++++++++++++++---------------- themes/headache | 39 ++++++++++++++-------- themes/joker | 53 ++++++++++++++++++----------- themes/minimal | 62 ---------------------------------- themes/mono | 58 ++++++++++++++++---------------- themes/orange | 37 ++++++++++++--------- themes/original | 60 ++++++++++++++++----------------- themes/original_bright | 58 ++++++++++++++++---------------- themes/shade | 41 +++++++++++++++-------- themes/simple | 65 ++++++------------------------------ themes/spawn | 54 ++++++++++++++++++------------ themes/whiteness | 43 +++++++++++++++--------- 19 files changed, 499 insertions(+), 480 deletions(-) create mode 100644 theme_template delete mode 100644 themes/advanced create mode 100644 themes/complex delete mode 100644 themes/minimal diff --git a/theme_template b/theme_template new file mode 100644 index 00000000..ece971a8 --- /dev/null +++ b/theme_template @@ -0,0 +1,72 @@ +[colours] +bkgnd= +titlebar= +titlebar.text= +titlebar.brackets= +titlebar.unencrypted= +titlebar.encrypted= +titlebar.untrusted= +titlebar.trusted= +titlebar.online= +titlebar.offline= +titlebar.away= +titlebar.chat= +titlebar.dnd= +titlebar.xa= +statusbar= +statusbar.text= +statusbar.brackets= +statusbar.active= +statusbar.new= +main.text= +main.text.me= +main.text.them= +main.splash= +main.time= +input.text= +subscribed= +unsubscribed= +otr.started.trusted= +otr.started.untrusted= +otr.ended= +otr.trusted= +otr.untrusted= +online= +away= +chat= +dnd= +xa= +offline= +incoming= +typing= +gone= +error= +roominfo= +roommention= +me= +them= +roster.header= +occupants.header= + +[ui] +beep= +flash= +splash= +wrap= +time= +privileges= +presence= +intype= +otr.warn= +resource.title= +resource.message= +statuses.console= +statuses.chat= +statuses.muc= +roster= +roster.offline= +roster.resource= +roster.by= +roster.size= +occupants= +occupants.size= \ No newline at end of file diff --git a/themes/advanced b/themes/advanced deleted file mode 100644 index a00948d8..00000000 --- a/themes/advanced +++ /dev/null @@ -1,69 +0,0 @@ -[colours] -bkgnd=default -titlebar=blue -statusbar=blue -titlebar.text=bold_white -titlebar.brackets=white -statusbar.text=bold_white -statusbar.brackets=white -statusbar.active=bold_cyan -statusbar.new=bold_green -main.text=white -main.text.me=cyan -main.text.them=bold_white -input.text=bold_green -main.time=yellow -main.splash=bold_red -online=bold_green -away=bold_cyan -chat=bold_white -dnd=magenta -xa=bold_blue -offline=red -typing=yellow -gone=red -error=red -incoming=bold_yellow -roominfo=yellow -roommention=bold_red -me=blue -them=bold_green -titlebar.unencrypted=bold_red -titlebar.encrypted=bold_white -titlebar.untrusted=bold_yellow -titlebar.trusted=bold_white -titlebar.online=bold_green -titlebar.offline=bold_red -titlebar.away=bold_cyan -titlebar.xa=bold_cyan -titlebar.dnd=bold_red -titlebar.chat=bold_green -otr.started.trusted=green -otr.started.untrusted=yellow -otr.ended=red -otr.trusted=green -otr.untrusted=yellow -roster.header=bold_yellow -occupants.header=bold_yellow - -[ui] -intype=true -beep=false -flash=false -privileges=true -presence=true -wrap=true -time=minutes -statuses.muc=off -statuses.chat=online -statuses.console=off -occupants=true -occupants.size=15 -roster=true -roster.size=25 -roster.offline=true -roster.resource=true -roster.by=presence -otr.warn=true - - diff --git a/themes/aqua b/themes/aqua index 7474d072..fe3fd56a 100644 --- a/themes/aqua +++ b/themes/aqua @@ -1,9 +1,19 @@ [colours] bkgnd=default titlebar=blue -statusbar=blue titlebar.text=bold_white titlebar.brackets=white +titlebar.unencrypted=cyan +titlebar.encrypted=white +titlebar.untrusted=cyan +titlebar.trusted=white +titlebar.online=bold_white +titlebar.offline=cyan +titlebar.away=white +titlebar.chat=bold_white +titlebar.dnd=cyan +titlebar.xa=bold_cyan +statusbar=blue statusbar.text=bold_white statusbar.brackets=white statusbar.active=cyan @@ -11,31 +21,29 @@ statusbar.new=white main.text=blue main.text.me=bold_cyan main.text.them=bold_white -input.text=white -main.time=cyan main.splash=bold_white +main.time=cyan +input.text=white +subscribed=bold_cyan +unsubscribed=blue +otr.started.trusted=white +otr.started.untrusted=cyan +otr.ended=cyan +otr.trusted=white +otr.untrusted=cyan online=bold_cyan away=bold_blue chat=white dnd=blue xa=cyan offline=bold_black +incoming=bold_cyan typing=cyan gone=blue error=bold_white -incoming=bold_cyan roominfo=white roommention=bold_blue me=cyan them=white -titlebar.unencrypted=cyan -titlebar.encrypted=white -titlebar.untrusted=cyan -titlebar.trusted=white -otr.started.trusted=white -otr.started.untrusted=cyan -otr.ended=cyan -otr.trusted=white -otr.untrusted=cyan roster.header=bold_white occupants.header=bold_white diff --git a/themes/batman b/themes/batman index fc8ce1be..358fc559 100644 --- a/themes/batman +++ b/themes/batman @@ -17,14 +17,13 @@ away=yellow chat=green dnd=green xa=yellow -offline=grey +offline=bold_black typing=cyan gone=red error=red incoming=yellow roominfo=green -roommention=cyan -me=black +me=black_bold them=yellow titlebar.unencrypted=red titlebar.encrypted=green @@ -35,3 +34,17 @@ otr.started.untrusted=red otr.ended=yellow otr.trusted=green otr.untrusted=red + +titlebar.online=magenta +titlebar.offline=black +titlebar.away=magenta +titlebar.chat=magenta +titlebar.dnd=magenta +titlebar.xa=magenta +main.text.me=white +main.text.them=white +subscribed=magenta +unsubscribed=black_bold +roommention=cyan +roster.header=yellow +occupants.header=yellow \ No newline at end of file diff --git a/themes/boothj5 b/themes/boothj5 index 3e086903..cd6379cd 100644 --- a/themes/boothj5 +++ b/themes/boothj5 @@ -1,33 +1,8 @@ [colours] bkgnd=default titlebar=blue -statusbar=blue titlebar.text=bold_white titlebar.brackets=white -statusbar.text=bold_white -statusbar.brackets=white -statusbar.active=bold_cyan -statusbar.new=bold_green -main.text=white -main.text.me=cyan -main.text.them=bold_white -input.text=bold_green -main.time=yellow -main.splash=bold_red -online=bold_green -away=bold_cyan -chat=bold_white -dnd=magenta -xa=bold_blue -offline=red -typing=yellow -gone=red -error=red -incoming=bold_yellow -roominfo=yellow -roommention=bold_red -me=blue -them=bold_green titlebar.unencrypted=bold_red titlebar.encrypted=bold_white titlebar.untrusted=bold_yellow @@ -38,32 +13,62 @@ titlebar.away=bold_cyan titlebar.xa=bold_cyan titlebar.dnd=bold_red titlebar.chat=bold_green +statusbar=blue +statusbar.text=bold_white +statusbar.brackets=white +statusbar.active=bold_cyan +statusbar.new=bold_green +main.text=white +main.text.me=cyan +main.text.them=bold_white +main.splash=bold_red +main.time=yellow +input.text=bold_green +subscribed=bold_green +unsubscribed=red otr.started.trusted=green otr.started.untrusted=yellow otr.ended=red otr.trusted=green otr.untrusted=yellow +online=bold_green +away=bold_cyan +chat=bold_white +dnd=magenta +xa=bold_blue +offline=red +incoming=bold_yellow +typing=yellow +gone=red +error=red +roominfo=yellow +roommention=bold_red +me=blue +them=bold_green roster.header=bold_yellow occupants.header=bold_yellow [ui] -intype=true beep=false flash=false +splash=true +wrap=true +time=seconds privileges=true presence=true -wrap=true -time=minutes -statuses.muc=none -statuses.chat=none -statuses.console=none -occupants=true -occupants.size=15 +intype=true +otr.warn=true +resource.title=true +resource.message=true +statuses.console=all +statuses.chat=all +statuses.muc=all roster=true -roster.size=25 roster.offline=true roster.resource=true roster.by=presence -otr.warn=true +roster.size=25 +occupants=true +occupants.size=15 diff --git a/themes/complex b/themes/complex new file mode 100644 index 00000000..a2695a1f --- /dev/null +++ b/themes/complex @@ -0,0 +1,22 @@ +[ui] +beep=false +flash=false +splash=true +wrap=true +time=seconds +resource.title=true +resource.message=true +statuses.console=all +statuses.chat=all +statuses.muc=all +occupants=true +occupants.size=15 +roster=true +roster.offline=true +roster.resource=true +roster.by=presence +roster.size=25 +privileges=true +presence=true +intype=true +otr.warn=true diff --git a/themes/forest b/themes/forest index fd170162..d04bc390 100644 --- a/themes/forest +++ b/themes/forest @@ -1,35 +1,8 @@ [colours] bkgnd=default titlebar=cyan -statusbar=green titlebar.text=black titlebar.brackets=black -statusbar.text=black -statusbar.brackets=black -statusbar.active=bold_green -statusbar.new=white -main.text=bold_cyan -main.text.me=yellow -main.text.them=green -input.text=bold_blue -main.time=bold_green -main.splash=bold_yellow -subscribed=green -unsubscribed=bold_black -online=green -away=blue -chat=green -dnd=bold_black -xa=blue -offline=bold_black -typing=yellow -gone=bold_black -error=bold_black -incoming=bold_yellow -roominfo=yellow -roommention=bold_cyan -me=blue -them=bold_blue titlebar.unencrypted=black titlebar.encrypted=white titlebar.untrusted=white @@ -37,13 +10,40 @@ titlebar.trusted=white titlebar.online=white titlebar.offline=white titlebar.away=white -titlebar.xa=white -titlebar.dnd=white titlebar.chat=white +titlebar.dnd=white +titlebar.xa=white +statusbar=green +statusbar.text=black +statusbar.brackets=black +statusbar.active=bold_green +statusbar.new=white +main.text=bold_cyan +main.text.me=yellow +main.text.them=green +main.splash=bold_yellow +main.time=bold_green +input.text=bold_blue +subscribed=green +unsubscribed=bold_black otr.started.trusted=green otr.started.untrusted=yellow otr.ended=red otr.trusted=green otr.untrusted=yellow +online=green +away=blue +chat=green +dnd=bold_black +xa=blue +offline=bold_black +incoming=bold_yellow +typing=yellow +gone=bold_black +error=bold_black +roominfo=yellow +roommention=bold_cyan +me=blue +them=bold_blue roster.header=bold_green -occupants.header=bold_green +occupants.header=bold_green \ No newline at end of file diff --git a/themes/hacker b/themes/hacker index 09928f61..a81a635c 100644 --- a/themes/hacker +++ b/themes/hacker @@ -1,33 +1,8 @@ [colours] bkgnd=default titlebar=green -statusbar=green titlebar.text=black titlebar.brackets=black -statusbar.text=black -statusbar.brackets=black -statusbar.active=black -statusbar.new=black -main.text=green -main.text.me=green -main.text.them=green -input.text=bold_green -main.time=bold_green -main.splash=bold_green -online=bold_green -away=green -chat=bold_green -dnd=green -xa=green -offline=green -typing=green -gone=green -error=bold_green -incoming=bold_green -roominfo=green -roommention=bold_green -me=green -them=bold_green titlebar.unencrypted=black titlebar.encrypted=black titlebar.untrusted=black @@ -35,13 +10,40 @@ titlebar.trusted=black titlebar.online=black titlebar.offline=black titlebar.away=black -titlebar.xa=black -titlebar.dnd=black titlebar.chat=black +titlebar.dnd=black +titlebar.xa=black +statusbar=green +statusbar.text=black +statusbar.brackets=black +statusbar.active=black +statusbar.new=black +main.text=green +main.text.me=green +main.text.them=green +main.splash=bold_green +main.time=bold_green +input.text=bold_green +subscribed=bold_green +unsubscribed=green otr.started.trusted=green otr.started.untrusted=green otr.ended=green otr.trusted=green otr.untrusted=green +online=bold_green +away=green +chat=bold_green +dnd=green +xa=green +offline=green +incoming=bold_green +typing=green +gone=green +error=bold_green +roominfo=green +roommention=bold_green +me=green +them=bold_green roster.header=bold_green -occupants.header=bold_green +occupants.header=bold_green \ No newline at end of file diff --git a/themes/headache b/themes/headache index ea5738ce..3a84d976 100644 --- a/themes/headache +++ b/themes/headache @@ -1,36 +1,49 @@ [colours] bkgnd=default titlebar=magenta -statusbar=default titlebar.text=white titlebar.brackets=white +titlebar.unencrypted=black +titlebar.encrypted=cyan +titlebar.untrusted=yellow +titlebar.trusted=cyan +titlebar.online=white +titlebar.offline=black +titlebar.away=white +titlebar.chat=white +titlebar.dnd=black +titlebar.xa=white +statusbar=default statusbar.text=white statusbar.brackets=red statusbar.active=cyan statusbar.new=white main.text=blue -input.text=yellow -main.time=green +main.text.me=white +main.text.them=bold_white main.splash=red +main.time=green +input.text=yellow +subscribed=bold_magenta +unsubscribed=bold_black +otr.started.trusted=cyan +otr.started.untrusted=yellow +otr.ended=blue +otr.trusted=cyan +otr.untrusted=yellow online=red away=cyan chat=green dnd=megenta xa=cyan offline=green +incoming=yellow typing=magenta gone=yellow error=red -incoming=yellow roominfo=white +roommention=bold_green me=white them=white -titlebar.unencrypted=black -titlebar.encrypted=cyan -titlebar.untrusted=yellow -titlebar.trusted=cyan -otr.started.trusted=cyan -otr.started.untrusted=yellow -otr.ended=blue -otr.trusted=cyan -otr.untrusted=yellow +roster.header=bold_cyan +occupants.header=bold_cyan \ No newline at end of file diff --git a/themes/joker b/themes/joker index 3c8adc39..a0986242 100644 --- a/themes/joker +++ b/themes/joker @@ -1,36 +1,49 @@ [colours] bkgnd=default titlebar=magenta -statusbar=magenta titlebar.text=white titlebar.brackets=cyan +titlebar.unencrypted=red +titlebar.encrypted=green +titlebar.untrusted=red +titlebar.trusted=green +titlebar.online=white +titlebar.offline=black +titlebar.away=white +titlebar.chat=white +titlebar.dnd=black +titlebar.xa=white +statusbar=magenta statusbar.text=green statusbar.brackets=cyan statusbar.active=green statusbar.new=white main.text=white -input.text=green -main.time=white +main.text.me=white +main.text.them=white main.splash=green -online=green -away=yellow -chat=green -dnd=green -xa=yellow -offline=grey -typing=green -gone=red -error=red -incoming=yellow -roominfo=green -me=magenta -them=green -titlebar.unencrypted=red -titlebar.encrypted=green -titlebar.untrusted=red -titlebar.trusted=green +main.time=white +input.text=green +subscribed=green +unsubscribed=white otr.started.trusted=green otr.started.untrusted=red otr.ended=yellow otr.trusted=green otr.untrusted=red +online=green +away=yellow +chat=green +dnd=green +xa=yellow +offline=bold_black +incoming=yellow +typing=green +gone=red +error=red +roominfo=green +roommention=green +me=magenta +them=green +roster.header=magenta +occupants.header=magenta \ No newline at end of file diff --git a/themes/minimal b/themes/minimal deleted file mode 100644 index cabf1887..00000000 --- a/themes/minimal +++ /dev/null @@ -1,62 +0,0 @@ -[colours] -bkgnd=default -titlebar=blue -statusbar=blue -titlebar.text=bold_white -titlebar.brackets=white -statusbar.text=bold_white -statusbar.brackets=white -statusbar.active=bold_cyan -statusbar.new=bold_green -main.text=white -main.text.me=cyan -main.text.them=bold_white -input.text=bold_green -main.time=yellow -main.splash=bold_red -online=bold_green -away=bold_cyan -chat=bold_white -dnd=magenta -xa=bold_blue -offline=red -typing=yellow -gone=red -error=red -incoming=bold_yellow -roominfo=yellow -roommention=bold_red -me=blue -them=bold_green -titlebar.unencrypted=bold_red -titlebar.encrypted=bold_white -titlebar.untrusted=bold_yellow -titlebar.trusted=bold_white -titlebar.online=bold_green -titlebar.offline=bold_red -titlebar.away=bold_cyan -titlebar.xa=bold_cyan -titlebar.dnd=bold_red -titlebar.chat=bold_green -otr.started.trusted=green -otr.started.untrusted=yellow -otr.ended=red -otr.trusted=green -otr.untrusted=yellow -roster.header=bold_yellow -occupants.header=bold_yellow - -[ui] -intype=true -beep=false -flash=false -privileges=false -presence=false -wrap=false -time=off -statuses.muc=all -statuses.chat=all -statuses.console=all -occupants=false -roster=false -otr.warn=false diff --git a/themes/mono b/themes/mono index 42beb174..779d04ff 100644 --- a/themes/mono +++ b/themes/mono @@ -1,33 +1,8 @@ [colours] bkgnd=default titlebar=white -statusbar=white titlebar.text=black titlebar.brackets=black -statusbar.text=black -statusbar.brackets=black -statusbar.active=black -statusbar.new=black -main.text=white -main.text.me=white -main.text.them=white -input.text=white -main.time=white -main.splash=white -online=white -away=white -chat=white -dnd=white -xa=white -offline=white -typing=white -gone=white -error=white -incoming=white -roominfo=white -roommention=white -me=white -them=white titlebar.unencrypted=black titlebar.encrypted=black titlebar.untrusted=black @@ -35,13 +10,40 @@ titlebar.trusted=black titlebar.online=black titlebar.offline=black titlebar.away=black -titlebar.xa=black -titlebar.dnd=black titlebar.chat=black +titlebar.dnd=black +titlebar.xa=black +statusbar=white +statusbar.text=black +statusbar.brackets=black +statusbar.active=black +statusbar.new=black +main.text=white +main.text.me=white +main.text.them=white +main.splash=white +main.time=white +input.text=white +subscribed=white +unsubscribed=white otr.started.trusted=white otr.started.untrusted=white otr.ended=white otr.trusted=white otr.untrusted=white +online=white +away=white +chat=white +dnd=white +xa=white +offline=white +incoming=white +typing=white +gone=white +error=white +roominfo=white +roommention=white +me=white +them=white roster.header=white -occupants.header=white +occupants.header=white \ No newline at end of file diff --git a/themes/orange b/themes/orange index cff5f58b..57df02fd 100644 --- a/themes/orange +++ b/themes/orange @@ -3,6 +3,16 @@ bkgnd=yellow titlebar=red titlebar.text=black titlebar.brackets=blue +titlebar.unencrypted=black +titlebar.encrypted=white +titlebar.untrusted=white +titlebar.trusted=green +titlebar.online=white +titlebar.offline=black +titlebar.away=white +titlebar.chat=white +titlebar.dnd=black +titlebar.xa=white statusbar=green statusbar.text=black statusbar.brackets=blue @@ -11,32 +21,29 @@ statusbar.new=white main.text=black main.text.me=black main.text.them=green -main.time=blue main.splash=blue +main.time=blue input.text=black subscribed=blue -unsubscribed=red +unsubscribed=white +otr.started.trusted=green +otr.started.untrusted=white +otr.ended=red +otr.trusted=green +otr.untrusted=white online=blue away=white chat=blue dnd=white xa=white offline=white +incoming=blue typing=black gone=green error=red -incoming=blue roominfo=blue -me=blue -them=green -titlebar.unencrypted=black -titlebar.encrypted=white -titlebar.untrusted=white -titlebar.trusted=green -otr.started.trusted=green -otr.started.untrusted=white -otr.ended=red -otr.trusted=green -otr.untrusted=white +roommention=blue +me=black +them=black roster.header=black -occupants.header=black +occupants.header=black \ No newline at end of file diff --git a/themes/original b/themes/original index db0818c5..33ae041b 100644 --- a/themes/original +++ b/themes/original @@ -1,35 +1,8 @@ [colours] bkgnd=default titlebar=blue -statusbar=blue titlebar.text=white titlebar.brackets=cyan -statusbar.text=white -statusbar.brackets=cyan -statusbar.active=cyan -statusbar.new=white -main.text=white -main.text.me=white -main.text.them=white -input.text=white -main.time=white -main.splash=cyan -subscribed=green -unsubscribed=red -online=green -away=cyan -chat=green -dnd=red -xa=cyan -offline=red -typing=yellow -gone=red -error=red -incoming=yellow -roominfo=yellow -roommention=yellow -me=yellow -them=green titlebar.unencrypted=red titlebar.encrypted=white titlebar.untrusted=yellow @@ -37,13 +10,40 @@ titlebar.trusted=white titlebar.online=white titlebar.offline=white titlebar.away=white -titlebar.xa=white -titlebar.dnd=white titlebar.chat=white +titlebar.dnd=white +titlebar.xa=white +statusbar=blue +statusbar.text=white +statusbar.brackets=cyan +statusbar.active=cyan +statusbar.new=white +main.text=white +main.text.me=white +main.text.them=white +main.splash=cyan +main.time=white +input.text=white +subscribed=green +unsubscribed=red otr.started.trusted=green otr.started.untrusted=yellow otr.ended=red otr.trusted=green otr.untrusted=yellow +online=green +away=cyan +chat=green +dnd=red +xa=cyan +offline=red +incoming=yellow +typing=yellow +gone=yellow +error=red +roominfo=yellow +roommention=yellow +me=yellow +them=green roster.header=yellow -occupants.header=yellow +occupants.header=yellow \ No newline at end of file diff --git a/themes/original_bright b/themes/original_bright index ffe0c12c..4ad4af17 100644 --- a/themes/original_bright +++ b/themes/original_bright @@ -1,35 +1,8 @@ [colours] bkgnd=default titlebar=blue -statusbar=blue titlebar.text=bold_white titlebar.brackets=bold_cyan -statusbar.text=bold_white -statusbar.brackets=bold_cyan -statusbar.active=bold_cyan -statusbar.new=bold_white -main.text=bold_white -main.text.me=bold_white -main.text.them=bold_white -input.text=bold_white -main.time=bold_white -main.splash=bold_cyan -subscribed=bold_green -unsubscribed=bold_red -online=bold_green -away=bold_cyan -chat=bold_green -dnd=bold_red -xa=bold_cyan -offline=bold_red -typing=bold_yellow -gone=bold_red -error=bold_red -incoming=bold_yellow -roominfo=bold_yellow -roommention=bold_yellow -me=bold_yellow -them=bold_green titlebar.unencrypted=bold_red titlebar.encrypted=bold_white titlebar.untrusted=bold_yellow @@ -37,13 +10,40 @@ titlebar.trusted=bold_white titlebar.online=bold_white titlebar.offline=bold_white titlebar.away=bold_white -titlebar.xa=bold_white -titlebar.dnd=bold_white titlebar.chat=bold_white +titlebar.dnd=bold_white +titlebar.xa=bold_white +statusbar=blue +statusbar.text=bold_white +statusbar.brackets=bold_cyan +statusbar.active=bold_cyan +statusbar.new=bold_white +main.text=bold_white +main.text.me=bold_white +main.text.them=bold_white +main.splash=bold_cyan +main.time=bold_white +input.text=bold_white +subscribed=bold_green +unsubscribed=bold_red otr.started.trusted=bold_green otr.started.untrusted=bold_yellow otr.ended=bold_red otr.trusted=bold_green otr.untrusted=bold_yellow +online=bold_green +away=bold_cyan +chat=bold_green +dnd=bold_red +xa=bold_cyan +offline=bold_red +incoming=bold_yellow +typing=bold_yellow +gone=bold_yellow +error=bold_red +roominfo=bold_yellow +roommention=bold_yellow +me=bold_yellow +them=bold_green roster.header=bold_yellow occupants.header=bold_yellow diff --git a/themes/shade b/themes/shade index 0b61a0f7..856b2fa4 100644 --- a/themes/shade +++ b/themes/shade @@ -1,36 +1,49 @@ [colours] bkgnd=default titlebar=default -statusbar=default titlebar.text=white titlebar.brackets=magenta +titlebar.unencrypted=red +titlebar.encrypted=green +titlebar.untrusted=red +titlebar.trusted=green +titlebar.online=green +titlebar.offline=red +titlebar.away=green +titlebar.chat=green +titlebar.dnd=red +titlebar.xa=green +statusbar=default statusbar.text=magenta statusbar.brackets=magenta statusbar.active=white statusbar.new=green main.text=white -input.text=white -main.time=magenta +main.text.me=white +main.text.them=white main.splash=magenta +main.time=magenta +input.text=white +subscribed=green +unsubscribed=yallow +otr.started.trusted=green +otr.started.untrusted=red +otr.ended=yellow +otr.trusted=green +otr.untrusted=red online=green away=yellow chat=green dnd=green xa=yellow offline=white +incoming=yellow typing=green gone=red error=red -incoming=yellow roominfo=green -me=black +roommention=green +me=bold_black them=magenta -titlebar.unencrypted=red -titlebar.encrypted=green -titlebar.untrusted=red -titlebar.trusted=green -otr.started.trusted=green -otr.started.untrusted=red -otr.ended=yellow -otr.trusted=green -otr.untrusted=red +roster.header=magenta +occupants.header=magenta \ No newline at end of file diff --git a/themes/simple b/themes/simple index 44c6977b..0b9baab5 100644 --- a/themes/simple +++ b/themes/simple @@ -1,67 +1,22 @@ -[colours] -bkgnd=default -titlebar=blue -statusbar=blue -titlebar.text=bold_white -titlebar.brackets=white -statusbar.text=bold_white -statusbar.brackets=white -statusbar.active=bold_cyan -statusbar.new=bold_green -main.text=white -main.text.me=cyan -main.text.them=bold_white -input.text=bold_green -main.time=yellow -main.splash=bold_red -online=bold_green -away=bold_cyan -chat=bold_white -dnd=magenta -xa=bold_blue -offline=red -typing=yellow -gone=red -error=red -incoming=bold_yellow -roominfo=yellow -roommention=bold_red -me=blue -them=bold_green -titlebar.unencrypted=bold_red -titlebar.encrypted=bold_white -titlebar.untrusted=bold_yellow -titlebar.trusted=bold_white -titlebar.online=bold_green -titlebar.offline=bold_red -titlebar.away=bold_cyan -titlebar.xa=bold_cyan -titlebar.dnd=bold_red -titlebar.chat=bold_green -otr.started.trusted=green -otr.started.untrusted=yellow -otr.ended=red -otr.trusted=green -otr.untrusted=yellow -roster.header=bold_yellow -occupants.header=bold_yellow - [ui] -intype=false beep=false flash=false -privileges=false -presence=false +splash=true wrap=true time=minutes -statuses.muc=off -statuses.chat=online -statuses.console=off +resource.title=false +resource.message=false +statuses.console=none +statuses.chat=none +statuses.muc=none occupants=true occupants.size=15 roster=true -roster.size=25 roster.offline=false roster.resource=false roster.by=presence +roster.size=25 +privileges=false +presence=false +intype=false otr.warn=false diff --git a/themes/spawn b/themes/spawn index 0b403905..44c9f098 100644 --- a/themes/spawn +++ b/themes/spawn @@ -1,37 +1,49 @@ [colours] bkgnd=default titlebar=red -statusbar=red titlebar.text=yellow titlebar.brackets=green +titlebar.unencrypted=red +titlebar.encrypted=green +titlebar.untrusted=red +titlebar.trusted=green +titlebar.online=green +titlebar.offline=red +titlebar.away=green +titlebar.chat=green +titlebar.dnd=red +titlebar.xa=green +statusbar=red statusbar.text=yellow statusbar.brackets=green statusbar.active=white statusbar.new=green main.text=white -input.text=green -main.time=red +main.text.me=white +main.text.them=white main.splash=red -online=green -away=yellow -chat=green -dnd=green -xa=yellow -offline=grey -typing=green -gone=red -error=red -incoming=yellow -roominfo=green -roommention=red -me=green -them=yellow -titlebar.unencrypted=red -titlebar.encrypted=green -titlebar.untrusted=red -titlebar.trusted=green +main.time=red +input.text=green +subscribed=green +unsubscribed=red otr.started.trusted=green otr.started.untrusted=red otr.ended=yellow otr.trusted=green otr.untrusted=red +online=green +away=yellow +chat=green +dnd=green +xa=yellow +offline=bold_black +incoming=yellow +typing=green +gone=red +error=red +roominfo=green +roommention=red +me=green +them=yellow +roster.header=white +occupants.header=white \ No newline at end of file diff --git a/themes/whiteness b/themes/whiteness index 597c9c83..c448fcfb 100644 --- a/themes/whiteness +++ b/themes/whiteness @@ -1,36 +1,49 @@ [colours] bkgnd=white titlebar=blue -statusbar=blue titlebar.text=white titlebar.brackets=white +titlebar.unencrypted=red +titlebar.encrypted=white +titlebar.untrusted=yellow +titlebar.trusted=white +titlebar.online=white +titlebar.offline=red +titlebar.away=white +titlebar.chat=white +titlebar.dnd=red +titlebar.xa=white +statusbar=blue statusbar.text=white statusbar.brackets=white statusbar.active=megenta statusbar.new=red main.text=black -input.text=black -main.time=black +main.text.me=black +main.text.them=black main.splash=black +main.time=black +input.text=black +subscribed=green +unsubscribed=red +otr.started.trusted=green +otr.started.untrusted=yellow +otr.ended=red +otr.trusted=green +otr.untrusted=yellow online=green away=cyan chat=green dnd=red xa=cyan offline=red +incoming=yellow typing=yellow gone=red error=red -incoming=yellow roominfo=yellow -me=yellow -them=green -titlebar.unencrypted=red -titlebar.encrypted=white -titlebar.untrusted=yellow -titlebar.trusted=white -otr.started.trusted=green -otr.started.untrusted=yellow -otr.ended=red -otr.trusted=green -otr.untrusted=yellow +roommention=yellow +me=black +them=black +roster.header=black +occupants.header=black \ No newline at end of file From 6be4b400b80d242538824d626297e1f70ed59b53 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 3 Mar 2015 22:10:01 +0000 Subject: [PATCH 105/252] Fixed swapping windows when in source win --- src/ui/windows.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/ui/windows.c b/src/ui/windows.c index dba5290c..b534e973 100644 --- a/src/ui/windows.c +++ b/src/ui/windows.c @@ -639,20 +639,21 @@ wins_swap(int source_win, int target_win) { ProfWin *source = g_hash_table_lookup(windows, GINT_TO_POINTER(source_win)); - if (source != NULL) { + if (source) { ProfWin *target = g_hash_table_lookup(windows, GINT_TO_POINTER(target_win)); // target window empty - if (target == NULL) { + if (!target) { g_hash_table_steal(windows, GINT_TO_POINTER(source_win)); - status_bar_inactive(source_win); g_hash_table_insert(windows, GINT_TO_POINTER(target_win), source); + status_bar_inactive(source_win); if (win_unread(source) > 0) { status_bar_new(target_win); } else { status_bar_active(target_win); } - if ((wins_get_current_num() == source_win) || (wins_get_current_num() == target_win)) { + if (wins_get_current_num() == source_win) { + wins_set_current_by_num(target_win); ui_switch_win(1); } return TRUE; From f80689dd3549920c444c9613b72f7fc5901a8c5e Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 3 Mar 2015 22:22:28 +0000 Subject: [PATCH 106/252] Set version to 0.4.6 --- configure.ac | 2 +- install-all.sh | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 7369f112..a9896555 100644 --- a/configure.ac +++ b/configure.ac @@ -20,7 +20,7 @@ AS_CASE([$host_os], [cygwin], [PLATFORM="cygwin"], [PLATFORM="nix"]) -PACKAGE_STATUS="development" +PACKAGE_STATUS="release" ### Get git branch and revision if in development if test "x$PACKAGE_STATUS" = xdevelopment; then diff --git a/install-all.sh b/install-all.sh index cc32d8fd..7970804b 100755 --- a/install-all.sh +++ b/install-all.sh @@ -74,6 +74,7 @@ install_lib_strophe() echo git clone git://github.com/strophe/libstrophe.git cd libstrophe + git checkout 0.8.7 ./bootstrap.sh ./configure --prefix=$1 make @@ -102,6 +103,7 @@ cyg_install_lib_strophe() echo git clone git://github.com/strophe/libstrophe.git cd libstrophe + git checkout 0.8.7 ./bootstrap.sh ./bootstrap.sh # second call seems to fix problem on cygwin ./configure --prefix=/usr From 0dee898c01c851deeda17602d809c02708483a14 Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 4 Mar 2015 00:45:42 +0000 Subject: [PATCH 107/252] Set version to 0.4.7 development --- configure.ac | 4 ++-- install-all.sh | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index a9896555..4665efb9 100644 --- a/configure.ac +++ b/configure.ac @@ -1,7 +1,7 @@ # -*- Autoconf -*- # Process this file with autoconf to produce a configure script. -AC_INIT([profanity], [0.4.6], [boothj5web@gmail.com]) +AC_INIT([profanity], [0.4.7], [boothj5web@gmail.com]) AC_CONFIG_MACRO_DIR([m4]) AC_CONFIG_SRCDIR([src/main.c]) AC_CONFIG_HEADERS([src/config.h]) @@ -20,7 +20,7 @@ AS_CASE([$host_os], [cygwin], [PLATFORM="cygwin"], [PLATFORM="nix"]) -PACKAGE_STATUS="release" +PACKAGE_STATUS="development" ### Get git branch and revision if in development if test "x$PACKAGE_STATUS" = xdevelopment; then diff --git a/install-all.sh b/install-all.sh index 7970804b..cc32d8fd 100755 --- a/install-all.sh +++ b/install-all.sh @@ -74,7 +74,6 @@ install_lib_strophe() echo git clone git://github.com/strophe/libstrophe.git cd libstrophe - git checkout 0.8.7 ./bootstrap.sh ./configure --prefix=$1 make @@ -103,7 +102,6 @@ cyg_install_lib_strophe() echo git clone git://github.com/strophe/libstrophe.git cd libstrophe - git checkout 0.8.7 ./bootstrap.sh ./bootstrap.sh # second call seems to fix problem on cygwin ./configure --prefix=/usr From 5e1ad0b0d215e11c330ba1e3687119304062d358 Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 4 Mar 2015 22:37:42 +0000 Subject: [PATCH 108/252] Added profanity.sh (OSX helper script for codelite) to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 37449348..ba909849 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ # *.[oa] # *~ profanity +profanity.sh *.o *.log *.swp From 7638f379cac3869abdd8530faa09cc7481e99ec6 Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 4 Mar 2015 23:32:47 +0000 Subject: [PATCH 109/252] Fixed tests for --disable-otr --- Makefile.am | 6 +++++- tests/testsuite.c | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Makefile.am b/Makefile.am index d9fa9729..809c3eea 100644 --- a/Makefile.am +++ b/Makefile.am @@ -44,6 +44,7 @@ tests_sources = \ src/roster_list.c src/roster_list.h \ src/xmpp/xmpp.h src/xmpp/form.c \ src/ui/ui.h \ + src/otr/otr.h \ src/command/command.h src/command/command.c \ src/command/commands.h src/command/commands.c \ src/tools/parser.c \ @@ -63,7 +64,6 @@ tests_sources = \ src/ui/titlebar.h src/ui/statusbar.h src/ui/inputwin.h \ src/server_events.c src/server_events.h \ tests/xmpp/stub_xmpp.c \ - tests/otr/stub_otr.c \ tests/ui/stub_ui.c \ tests/log/stub_log.c \ tests/config/stub_accounts.c \ @@ -104,6 +104,9 @@ otr3_sources = \ otr4_sources = \ src/otr/otrlib.h src/otr/otrlibv4.c src/otr/otr.h src/otr/otr.c +otr_test_sources = \ + tests/otr/stub_otr.c + themes_sources = themes/* script_sources = bootstrap.sh configure-debug install-all.sh @@ -111,6 +114,7 @@ script_sources = bootstrap.sh configure-debug install-all.sh man_sources = docs/profanity.1 if BUILD_OTR +tests_sources += $(otr_test_sources) if BUILD_OTR3 core_sources += $(otr3_sources) endif diff --git a/tests/testsuite.c b/tests/testsuite.c index ddfb45cd..645a1a40 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -346,9 +346,11 @@ int main(int argc, char* argv[]) { unit_test(cmd_account_set_eval_password_when_password_set), unit_test(cmd_account_set_muc_sets_muc), unit_test(cmd_account_set_nick_sets_nick), +#ifdef HAVE_LIBOTR unit_test(cmd_account_show_message_for_missing_otr_policy), unit_test(cmd_account_show_message_for_invalid_otr_policy), unit_test(cmd_account_set_otr_sets_otr), +#endif unit_test(cmd_account_set_status_shows_message_when_invalid_status), unit_test(cmd_account_set_status_sets_status_when_valid), unit_test(cmd_account_set_status_sets_status_when_last), From e361ea69221bded41784b9f4f1682a64baac13ac Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 8 Mar 2015 18:47:01 +0000 Subject: [PATCH 110/252] Added conditional OSX check for readline --- configure.ac | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/configure.ac b/configure.ac index c38c09c3..ec599f7c 100644 --- a/configure.ac +++ b/configure.ac @@ -135,8 +135,16 @@ PKG_CHECK_MODULES([glib], [glib-2.0 >= 2.26], [], [AC_MSG_ERROR([glib 2.26 or higher is required for profanity])]) PKG_CHECK_MODULES([curl], [libcurl], [], [AC_MSG_ERROR([libcurl is required for profanity])]) -AC_CHECK_LIB([readline], [main], [], - [AC_MSG_ERROR([libreadline is required for profanity])]) + +AS_IF([test "x$PLATFORM" != xosx], + [AC_CHECK_LIB([readline], [main], [], + [AC_MSG_ERROR([libreadline is required for profanity])])], + [AC_CHECK_FILE([/usr/local/opt/readline/lib], + [LIBS="-lreadline $LIBS" + AM_CPPFLAGS="-I/usr/local/opt/readline/include $AM_CPPFLAGS" + AM_LDFLAGS="-L/usr/local/opt/readline/lib $AM_LDFLAGS" + AC_SUBST(AM_LDFLAGS)], + [AC_MSG_ERROR([libreadline is required for profanity])])]) AS_IF([test "x$PLATFORM" = xosx], [LIBS="-lcurl $LIBS"]) @@ -236,13 +244,6 @@ AM_CPPFLAGS="$AM_CPPFLAGS $glib_CFLAGS $curl_CFLAGS $libnotify_CFLAGS" AM_CPPFLAGS="$AM_CPPFLAGS -DTHEMES_PATH=\"\\\"$THEMES_PATH\\\"\"" LIBS="$glib_LIBS $curl_LIBS $libnotify_LIBS $LIBS" -### Use brew installed gnu readline -AS_IF([test "x$PLATFORM" = xosx], [ - LIBS="-lreadline $LIBS" - AM_CPPFLAGS="-I/usr/local/opt/readline/include $AM_CPPFLAGS" - AM_LDFLAGS="-L/usr/local/opt/readline/lib $AM_LDFLAGS" - AC_SUBST(AM_LDFLAGS)]) - AC_SUBST(AM_CFLAGS) AC_SUBST(AM_CPPFLAGS) From e632f254d3d92d474a664f3bbaf0730032a949e3 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 8 Mar 2015 19:06:38 +0000 Subject: [PATCH 111/252] Added libreadline-dev to install-all.sh for ubuntu --- install-all.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install-all.sh b/install-all.sh index cc32d8fd..e3364ed9 100755 --- a/install-all.sh +++ b/install-all.sh @@ -24,7 +24,7 @@ debian_prepare() echo echo Profanity installer... installing dependencies echo - sudo apt-get -y install git automake autoconf libssl-dev libexpat1-dev libncursesw5-dev libglib2.0-dev libnotify-dev libcurl3-dev libxss-dev libotr5-dev libtool + sudo apt-get -y install git automake autoconf libssl-dev libexpat1-dev libncursesw5-dev libglib2.0-dev libnotify-dev libcurl3-dev libxss-dev libotr5-dev libreadline-dev libtool } From 84de10e7cd940bd0290099f666ceebb5599e87f2 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 8 Mar 2015 19:21:35 +0000 Subject: [PATCH 112/252] Added readline-devel to instal-all.sh for fedora --- install-all.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install-all.sh b/install-all.sh index e3364ed9..0f957dbc 100755 --- a/install-all.sh +++ b/install-all.sh @@ -36,7 +36,7 @@ fedora_prepare() ARCH=`arch` - sudo yum -y install gcc git autoconf automake openssl-devel.$ARCH expat-devel.$ARCH ncurses-devel.$ARCH glib2-devel.$ARCH libnotify-devel.$ARCH libcurl-devel.$ARCH libXScrnSaver-devel.$ARCH libotr3-devel.$ARCH libtool + sudo yum -y install gcc git autoconf automake openssl-devel.$ARCH expat-devel.$ARCH ncurses-devel.$ARCH glib2-devel.$ARCH libnotify-devel.$ARCH libcurl-devel.$ARCH libXScrnSaver-devel.$ARCH libotr3-devel.$ARCH readline-devel.$ARCH libtool } opensuse_prepare() From 8d968884051cec3c6fc4e6b678a3430d4b88daf2 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 8 Mar 2015 19:32:03 +0000 Subject: [PATCH 113/252] Added readline-devel to install-all.sh for opensuse --- install-all.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install-all.sh b/install-all.sh index 0f957dbc..8972bace 100755 --- a/install-all.sh +++ b/install-all.sh @@ -44,7 +44,7 @@ opensuse_prepare() echo echo Profanity installer...installing dependencies echo - sudo zypper -n in gcc git automake make autoconf libopenssl-devel expat libexpat-devel ncurses-devel glib2-devel libnotify-devel libcurl-devel libXScrnSaver-devel libotr-devel libtool + sudo zypper -n in gcc git automake make autoconf libopenssl-devel expat libexpat-devel ncurses-devel glib2-devel libnotify-devel libcurl-devel libXScrnSaver-devel libotr-devel readline-devel libtool } cygwin_prepare() From 232bf9b7fc80b0f2013359f002d38bc7a4d9c50f Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 8 Mar 2015 19:45:19 +0000 Subject: [PATCH 114/252] Added libreadline-devel to install-all.sh for cygwin --- install-all.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/install-all.sh b/install-all.sh index 8972bace..a054e166 100755 --- a/install-all.sh +++ b/install-all.sh @@ -60,9 +60,9 @@ cygwin_prepare() mv apt-cyg /usr/local/bin/ if [ -n "$CYG_MIRROR" ]; then - apt-cyg -m $CYG_MIRROR install git make gcc-core m4 automake autoconf pkg-config openssl-devel libexpat-devel zlib-devel libncursesw-devel libglib2.0-devel libcurl-devel libidn-devel libssh2-devel libkrb5-devel openldap-devel libgcrypt-devel libtool + apt-cyg -m $CYG_MIRROR install git make gcc-core m4 automake autoconf pkg-config openssl-devel libexpat-devel zlib-devel libncursesw-devel libglib2.0-devel libcurl-devel libidn-devel libssh2-devel libkrb5-devel openldap-devel libgcrypt-devel libreadline-devel libtool else - apt-cyg install git make gcc-core m4 automake autoconf pkg-config openssl-devel libexpat-devel zlib-devel libncursesw-devel libglib2.0-devel libcurl-devel libidn-devel libssh2-devel libkrb5-devel openldap-devel libgcrypt-devel libtool + apt-cyg install git make gcc-core m4 automake autoconf pkg-config openssl-devel libexpat-devel zlib-devel libncursesw-devel libglib2.0-devel libcurl-devel libidn-devel libssh2-devel libkrb5-devel openldap-devel libgcrypt-devel libreadline-devel libtool fi } From 88af6e34559efe93fa241323287631b015ef6f25 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 9 Mar 2015 21:52:09 +0000 Subject: [PATCH 115/252] Added connection check before sending carbons enable/disable IQ --- src/command/commands.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/command/commands.c b/src/command/commands.c index 4711c18e..2e466f61 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -3895,6 +3895,13 @@ cmd_history(gchar **args, struct cmd_help_t help) gboolean cmd_carbons(gchar **args, struct cmd_help_t help) { + jabber_conn_status_t conn_status = jabber_get_connection_status(); + + if (conn_status != JABBER_CONNECTED) { + cons_show("You are not currently connected."); + return TRUE; + } + gboolean result = _cmd_set_boolean_preference(args[0], help, "Carbons message", PREF_CARBONS); From 2c19fad6d63ca3d7ca3e59afd5b371892991411f Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 9 Mar 2015 21:53:29 +0000 Subject: [PATCH 116/252] Added /carbons autocompletion --- src/command/command.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/command/command.c b/src/command/command.c index 0a571d22..6502af75 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -2003,7 +2003,7 @@ _cmd_complete_parameters(const char * const input) // autocomplete boolean settings gchar *boolean_choices[] = { "/beep", "/intype", "/states", "/outtype", "/flash", "/splash", "/chlog", "/grlog", "/mouse", "/history", - "/vercheck", "/privileges", "/presence", "/wrap" }; + "/vercheck", "/privileges", "/presence", "/wrap", "/carbons" }; for (i = 0; i < ARRAY_SIZE(boolean_choices); i++) { result = autocomplete_param_with_func(input, boolean_choices[i], prefs_autocomplete_boolean_choice); From 3c1e8c4e154600b8b7aeb60bbf316e39a97ece27 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 9 Mar 2015 23:07:51 +0000 Subject: [PATCH 117/252] Added server error handling when setting /carbons preference --- src/command/commands.c | 2 +- src/server_events.c | 12 +++++ src/server_events.h | 2 + src/xmpp/iq.c | 103 ++++++++++++++++++++++++----------------- src/xmpp/stanza.c | 8 ++-- 5 files changed, 80 insertions(+), 47 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index 2e466f61..8c93b065 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -3903,7 +3903,7 @@ cmd_carbons(gchar **args, struct cmd_help_t help) } gboolean result = _cmd_set_boolean_preference(args[0], help, - "Carbons message", PREF_CARBONS); + "Message carbons preference", PREF_CARBONS); // enable carbons if (strcmp(args[0], "on") == 0) { diff --git a/src/server_events.c b/src/server_events.c index f6755d6a..e5602b87 100644 --- a/src/server_events.c +++ b/src/server_events.c @@ -177,6 +177,18 @@ handle_disco_info_error(const char * const from, const char * const error) } } +void +handle_enable_carbons_error(const char * const error) +{ + cons_show_error("Server error enabling message carbons: %s", error); +} + +void +handle_disable_carbons_error(const char * const error) +{ + cons_show_error("Server error disabling message carbons: %s", error); +} + void handle_room_info_error(const char * const room, const char * const error) { diff --git a/src/server_events.h b/src/server_events.h index 9f874ffa..042eb934 100644 --- a/src/server_events.h +++ b/src/server_events.h @@ -122,5 +122,7 @@ void handle_muc_occupant_online(const char * const room, const char * const nick void handle_roster_update(const char * const barejid, const char * const name, GSList *groups, const char * const subscription, gboolean pending_out); void handle_roster_received(void); +void handle_enable_carbons_error(const char * const error); +void handle_disable_carbons_error(const char * const error); #endif diff --git a/src/xmpp/iq.c b/src/xmpp/iq.c index 62193c74..028c586e 100644 --- a/src/xmpp/iq.c +++ b/src/xmpp/iq.c @@ -58,48 +58,29 @@ #define HANDLE(ns, type, func) xmpp_handler_add(conn, func, ns, STANZA_NAME_IQ, type, ctx) -static int _error_handler(xmpp_conn_t * const conn, - xmpp_stanza_t * const stanza, void * const userdata); -static int _ping_get_handler(xmpp_conn_t * const conn, - xmpp_stanza_t * const stanza, void * const userdata); -static int _version_get_handler(xmpp_conn_t * const conn, - xmpp_stanza_t * const stanza, void * const userdata); -static int _disco_info_get_handler(xmpp_conn_t * const conn, - xmpp_stanza_t * const stanza, void * const userdata); -static int _disco_info_response_handler(xmpp_conn_t * const conn, - xmpp_stanza_t * const stanza, void * const userdata); -static int _version_result_handler(xmpp_conn_t * const conn, - xmpp_stanza_t * const stanza, void * const userdata); -static int _disco_items_result_handler(xmpp_conn_t * const conn, - xmpp_stanza_t * const stanza, void * const userdata); -static int _disco_items_get_handler(xmpp_conn_t * const conn, - xmpp_stanza_t * const stanza, void * const userdata); -static int _destroy_room_result_handler(xmpp_conn_t * const conn, - xmpp_stanza_t * const stanza, void * const userdata); -static int _room_config_handler(xmpp_conn_t * const conn, - xmpp_stanza_t * const stanza, void * const userdata); -static int _room_config_submit_handler(xmpp_conn_t * const conn, - xmpp_stanza_t * const stanza, void * const userdata); -static int _room_affiliation_list_result_handler(xmpp_conn_t * const conn, - xmpp_stanza_t * const stanza, void * const userdata); -static int _room_affiliation_set_result_handler(xmpp_conn_t * const conn, - xmpp_stanza_t * const stanza, void * const userdata); -static int _room_role_set_result_handler(xmpp_conn_t * const conn, - xmpp_stanza_t * const stanza, void * const userdata); -static int _room_role_list_result_handler(xmpp_conn_t * const conn, - xmpp_stanza_t * const stanza, void * const userdata); -static int _room_kick_result_handler(xmpp_conn_t * const conn, - xmpp_stanza_t * const stanza, void * const userdata); -static int _manual_pong_handler(xmpp_conn_t *const conn, - xmpp_stanza_t * const stanza, void * const userdata); -static int _ping_timed_handler(xmpp_conn_t * const conn, - void * const userdata); -static int _caps_response_handler(xmpp_conn_t *const conn, - xmpp_stanza_t * const stanza, void * const userdata); -static int _caps_response_handler_for_jid(xmpp_conn_t *const conn, - xmpp_stanza_t * const stanza, void * const userdata); -static int _caps_response_handler_legacy(xmpp_conn_t *const conn, - xmpp_stanza_t * const stanza, void * const userdata); +static int _error_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata); +static int _ping_get_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata); +static int _version_get_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata); +static int _disco_info_get_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata); +static int _disco_info_response_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata); +static int _version_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata); +static int _disco_items_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata); +static int _disco_items_get_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata); +static int _destroy_room_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata); +static int _room_config_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata); +static int _room_config_submit_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata); +static int _room_affiliation_list_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata); +static int _room_affiliation_set_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata); +static int _room_role_set_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata); +static int _room_role_list_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata); +static int _room_kick_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata); +static int _enable_carbons_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata); +static int _disable_carbons_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata); +static int _manual_pong_handler(xmpp_conn_t *const conn, xmpp_stanza_t * const stanza, void * const userdata); +static int _ping_timed_handler(xmpp_conn_t * const conn, void * const userdata); +static int _caps_response_handler(xmpp_conn_t *const conn, xmpp_stanza_t * const stanza, void * const userdata); +static int _caps_response_handler_for_jid(xmpp_conn_t *const conn, xmpp_stanza_t * const stanza, void * const userdata); +static int _caps_response_handler_legacy(xmpp_conn_t *const conn, xmpp_stanza_t * const stanza, void * const userdata); void iq_add_handlers(void) @@ -158,6 +139,10 @@ iq_enable_carbons() xmpp_conn_t * const conn = connection_get_conn(); xmpp_ctx_t * const ctx = connection_get_ctx(); xmpp_stanza_t *iq = stanza_enable_carbons(ctx); + char *id = xmpp_stanza_get_id(iq); + + xmpp_id_handler_add(conn, _enable_carbons_handler, id, NULL); + xmpp_send(conn, iq); xmpp_stanza_release(iq); } @@ -168,6 +153,10 @@ iq_disable_carbons() xmpp_conn_t * const conn = connection_get_conn(); xmpp_ctx_t * const ctx = connection_get_ctx(); xmpp_stanza_t *iq = stanza_disable_carbons(ctx); + char *id = xmpp_stanza_get_id(iq); + + xmpp_id_handler_add(conn, _disable_carbons_handler, id, NULL); + xmpp_send(conn, iq); xmpp_stanza_release(iq); } @@ -734,6 +723,36 @@ _caps_response_handler_legacy(xmpp_conn_t *const conn, xmpp_stanza_t * const sta return 0; } +static int +_enable_carbons_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) +{ + char *type = xmpp_stanza_get_type(stanza); + if (g_strcmp0(type, "error") == 0) { + char *error_message = stanza_get_error_message(stanza); + handle_enable_carbons_error(error_message); + log_debug("Error enabling carbons: %s", error_message); + } else { + log_debug("Message carbons enabled."); + } + + return 0; +} + +static int +_disable_carbons_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) +{ + char *type = xmpp_stanza_get_type(stanza); + if (g_strcmp0(type, "error") == 0) { + char *error_message = stanza_get_error_message(stanza); + handle_disable_carbons_error(error_message); + log_debug("Error disabling carbons: %s", error_message); + } else { + log_debug("Message carbons disabled."); + } + + return 0; +} + static int _manual_pong_handler(xmpp_conn_t *const conn, xmpp_stanza_t * const stanza, void * const userdata) diff --git a/src/xmpp/stanza.c b/src/xmpp/stanza.c index f1aa9cf4..9b1431a9 100644 --- a/src/xmpp/stanza.c +++ b/src/xmpp/stanza.c @@ -201,10 +201,10 @@ stanza_create_bookmarks_pubsub_add(xmpp_ctx_t *ctx, const char * const jid, xmpp_stanza_t * stanza_enable_carbons(xmpp_ctx_t *ctx){ xmpp_stanza_t *iq = xmpp_stanza_new(ctx); - char *id = create_unique_id(NULL); + char *id = create_unique_id("carbons"); xmpp_stanza_set_name(iq, STANZA_NAME_IQ); - xmpp_stanza_set_type(iq, STANZA_TYPE_SET); + xmpp_stanza_set_type(iq, STANZA_TYPE_SET); xmpp_stanza_set_id(iq, id); free(id); @@ -220,10 +220,10 @@ stanza_enable_carbons(xmpp_ctx_t *ctx){ xmpp_stanza_t * stanza_disable_carbons(xmpp_ctx_t *ctx){ xmpp_stanza_t *iq = xmpp_stanza_new(ctx); - char *id = create_unique_id(NULL); + char *id = create_unique_id("carbons"); xmpp_stanza_set_name(iq, STANZA_NAME_IQ); - xmpp_stanza_set_type(iq, STANZA_TYPE_SET); + xmpp_stanza_set_type(iq, STANZA_TYPE_SET); xmpp_stanza_set_id(iq, id); free(id); From 2ff6873cf1ad4ca3c78947f5e3372d1da5a0b7d3 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 10 Mar 2015 21:16:34 +0000 Subject: [PATCH 118/252] Send private carbons element with message when encrypted --- src/command/command.c | 2 +- src/command/commands.c | 10 +++++----- src/otr/otr.c | 2 +- src/server_events.c | 4 ++-- src/xmpp/message.c | 40 ++++++++++++++++++++++++++++++++++------ src/xmpp/stanza.c | 10 +++++++++- src/xmpp/stanza.h | 2 +- src/xmpp/xmpp.h | 1 + tests/test_cmd_otr.c | 4 ++-- tests/xmpp/stub_xmpp.c | 6 ++++++ 10 files changed, 62 insertions(+), 19 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index 6502af75..6a5603ee 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -1928,7 +1928,7 @@ _cmd_execute_default(const char * inp) if (otr_is_secure(chatwin->barejid)) { char *encrypted = otr_encrypt_message(chatwin->barejid, inp); if (encrypted != NULL) { - message_send_chat(chatwin->barejid, encrypted); + message_send_chat_encrypted(chatwin->barejid, encrypted); otr_free_message(encrypted); if (prefs_get_boolean(PREF_CHLOG)) { const char *jid = jabber_get_fulljid(); diff --git a/src/command/commands.c b/src/command/commands.c index 8c93b065..2ca749fb 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -1265,7 +1265,7 @@ cmd_msg(gchar **args, struct cmd_help_t help) if (otr_is_secure(barejid)) { char *encrypted = otr_encrypt_message(barejid, msg); if (encrypted != NULL) { - message_send_chat(barejid, encrypted); + message_send_chat_encrypted(barejid, encrypted); otr_free_message(encrypted); ui_outgoing_chat_msg("me", barejid, msg); @@ -1294,7 +1294,7 @@ cmd_msg(gchar **args, struct cmd_help_t help) GString *otr_message = g_string_new(msg); g_string_append(otr_message, OTRL_MESSAGE_TAG_BASE); g_string_append(otr_message, OTRL_MESSAGE_TAG_V2); - message_send_chat(barejid, otr_message->str); + message_send_chat_encrypted(barejid, otr_message->str); g_string_free(otr_message, TRUE); } else { @@ -3073,7 +3073,7 @@ cmd_tiny(gchar **args, struct cmd_help_t help) if (otr_is_secure(chatwin->barejid)) { char *encrypted = otr_encrypt_message(chatwin->barejid, tiny); if (encrypted != NULL) { - message_send_chat(chatwin->barejid, encrypted); + message_send_chat_encrypted(chatwin->barejid, encrypted); otr_free_message(encrypted); if (prefs_get_boolean(PREF_CHLOG)) { const char *jid = jabber_get_fulljid(); @@ -4080,7 +4080,7 @@ cmd_otr(gchar **args, struct cmd_help_t help) ui_current_print_formatted_line('!', 0, "You have not generated or loaded a private key, use '/otr gen'"); } else if (!otr_is_secure(barejid)) { char *otr_query_message = otr_start_query(); - message_send_chat(barejid, otr_query_message); + message_send_chat_encrypted(barejid, otr_query_message); } else { ui_gone_secure(barejid, otr_is_trusted(barejid)); } @@ -4098,7 +4098,7 @@ cmd_otr(gchar **args, struct cmd_help_t help) } else { ProfChatWin *chatwin = ui_get_current_chat(); char *otr_query_message = otr_start_query(); - message_send_chat(chatwin->barejid, otr_query_message); + message_send_chat_encrypted(chatwin->barejid, otr_query_message); } } } diff --git a/src/otr/otr.c b/src/otr/otr.c index 7c500e71..d0515e97 100644 --- a/src/otr/otr.c +++ b/src/otr/otr.c @@ -110,7 +110,7 @@ static void cb_inject_message(void *opdata, const char *accountname, const char *protocol, const char *recipient, const char *message) { - message_send_chat(recipient, message); + message_send_chat_encrypted(recipient, message); } static void diff --git a/src/server_events.c b/src/server_events.c index e5602b87..b0a9b1e3 100644 --- a/src/server_events.c +++ b/src/server_events.c @@ -336,7 +336,7 @@ handle_incoming_message(char *barejid, char *resource, char *message) memmove(whitespace_base, whitespace_base+tag_length, tag_length); char *otr_query_message = otr_start_query(); cons_show("OTR Whitespace pattern detected. Attempting to start OTR session..."); - message_send_chat(barejid, otr_query_message); + message_send_chat_encrypted(barejid, otr_query_message); } } } @@ -350,7 +350,7 @@ handle_incoming_message(char *barejid, char *resource, char *message) if (policy == PROF_OTRPOLICY_ALWAYS && !was_decrypted && !whitespace_base) { char *otr_query_message = otr_start_query(); cons_show("Attempting to start OTR session..."); - message_send_chat(barejid, otr_query_message); + message_send_chat_encrypted(barejid, otr_query_message); } ui_incoming_msg(barejid, resource, newmessage, NULL); diff --git a/src/xmpp/message.c b/src/xmpp/message.c index df6afed6..ab7f52cd 100644 --- a/src/xmpp/message.c +++ b/src/xmpp/message.c @@ -93,14 +93,42 @@ message_send_chat(const char * const barejid, const char * const msg) state = STANZA_NAME_ACTIVE; } Jid *jidp = jid_create_from_bare_and_resource(session->barejid, session->resource); - message = stanza_create_message(ctx, jidp->fulljid, STANZA_TYPE_CHAT, msg, state); + message = stanza_create_message(ctx, jidp->fulljid, STANZA_TYPE_CHAT, msg, state, false); jid_destroy(jidp); } else { char *state = NULL; if (prefs_get_boolean(PREF_STATES)) { state = STANZA_NAME_ACTIVE; } - message = stanza_create_message(ctx, barejid, STANZA_TYPE_CHAT, msg, state); + message = stanza_create_message(ctx, barejid, STANZA_TYPE_CHAT, msg, state, false); + } + + xmpp_send(conn, message); + xmpp_stanza_release(message); +} + +void +message_send_chat_encrypted(const char * const barejid, const char * const msg) +{ + xmpp_stanza_t *message; + xmpp_conn_t * const conn = connection_get_conn(); + xmpp_ctx_t * const ctx = connection_get_ctx(); + + ChatSession *session = chat_session_get(barejid); + if (session) { + char *state = NULL; + if (prefs_get_boolean(PREF_STATES) && session->send_states) { + state = STANZA_NAME_ACTIVE; + } + Jid *jidp = jid_create_from_bare_and_resource(session->barejid, session->resource); + message = stanza_create_message(ctx, jidp->fulljid, STANZA_TYPE_CHAT, msg, state, true); + jid_destroy(jidp); + } else { + char *state = NULL; + if (prefs_get_boolean(PREF_STATES)) { + state = STANZA_NAME_ACTIVE; + } + message = stanza_create_message(ctx, barejid, STANZA_TYPE_CHAT, msg, state, true); } xmpp_send(conn, message); @@ -112,7 +140,7 @@ message_send_private(const char * const fulljid, const char * const msg) { xmpp_conn_t * const conn = connection_get_conn(); xmpp_ctx_t * const ctx = connection_get_ctx(); - xmpp_stanza_t *message = stanza_create_message(ctx, fulljid, STANZA_TYPE_CHAT, msg, NULL); + xmpp_stanza_t *message = stanza_create_message(ctx, fulljid, STANZA_TYPE_CHAT, msg, NULL, false); xmpp_send(conn, message); xmpp_stanza_release(message); @@ -123,7 +151,7 @@ message_send_groupchat(const char * const roomjid, const char * const msg) { xmpp_conn_t * const conn = connection_get_conn(); xmpp_ctx_t * const ctx = connection_get_ctx(); - xmpp_stanza_t *message = stanza_create_message(ctx, roomjid, STANZA_TYPE_GROUPCHAT, msg, NULL); + xmpp_stanza_t *message = stanza_create_message(ctx, roomjid, STANZA_TYPE_GROUPCHAT, msg, NULL, false); xmpp_send(conn, message); xmpp_stanza_release(message); @@ -424,7 +452,7 @@ _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, } // check if carbon message - xmpp_stanza_t *received = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_CARBONS); + xmpp_stanza_t *received = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_CARBONS); if(received != NULL){ xmpp_stanza_t *forwarded = xmpp_stanza_get_child_by_ns(received, STANZA_NS_FORWARD); xmpp_stanza_t *message = xmpp_stanza_get_child_by_name(forwarded, STANZA_NAME_MESSAGE); @@ -434,7 +462,7 @@ _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, gchar *to = xmpp_stanza_get_attribute(message, STANZA_ATTR_TO); gchar *from = xmpp_stanza_get_attribute(message, STANZA_ATTR_FROM); - // happens when receive a carbon of a self sent message + // happens when receive a carbon of a self sent message if(to == NULL) { to = from; } diff --git a/src/xmpp/stanza.c b/src/xmpp/stanza.c index 9b1431a9..e849ac97 100644 --- a/src/xmpp/stanza.c +++ b/src/xmpp/stanza.c @@ -284,7 +284,7 @@ stanza_create_room_subject_message(xmpp_ctx_t *ctx, const char * const room, con xmpp_stanza_t * stanza_create_message(xmpp_ctx_t *ctx, const char * const recipient, const char * const type, const char * const message, - const char * const state) + const char * const state, gboolean encrypted) { xmpp_stanza_t *msg, *body, *text; @@ -314,6 +314,14 @@ stanza_create_message(xmpp_ctx_t *ctx, const char * const recipient, xmpp_stanza_release(chat_state); } + if (encrypted) { + xmpp_stanza_t *private_carbon = xmpp_stanza_new(ctx); + xmpp_stanza_set_name(private_carbon, "private"); + xmpp_stanza_set_ns(private_carbon, STANZA_NS_CARBONS); + xmpp_stanza_add_child(msg, private_carbon); + xmpp_stanza_release(private_carbon); + } + return msg; } diff --git a/src/xmpp/stanza.h b/src/xmpp/stanza.h index 4291e1fd..365bed86 100644 --- a/src/xmpp/stanza.h +++ b/src/xmpp/stanza.h @@ -191,7 +191,7 @@ xmpp_stanza_t* stanza_create_chat_state(xmpp_ctx_t *ctx, xmpp_stanza_t* stanza_create_message(xmpp_ctx_t *ctx, const char * const recipient, const char * const type, - const char * const message, const char * const state); + const char * const message, const char * const state, gboolean encrypted); xmpp_stanza_t* stanza_create_room_join_presence(xmpp_ctx_t * const ctx, const char * const full_room_jid, const char * const passwd); diff --git a/src/xmpp/xmpp.h b/src/xmpp/xmpp.h index 724e11c4..e8e79ee9 100644 --- a/src/xmpp/xmpp.h +++ b/src/xmpp/xmpp.h @@ -146,6 +146,7 @@ GList * jabber_get_available_resources(void); // message functions void message_send_chat(const char * const barejid, const char * const msg); +void message_send_chat_encrypted(const char * const barejid, const char * const msg); void message_send_private(const char * const fulljid, const char * const msg); void message_send_groupchat(const char * const roomjid, const char * const msg); void message_send_groupchat_subject(const char * const roomjid, const char * const subject); diff --git a/tests/test_cmd_otr.c b/tests/test_cmd_otr.c index c6c6f7cf..dae17947 100644 --- a/tests/test_cmd_otr.c +++ b/tests/test_cmd_otr.c @@ -551,8 +551,8 @@ cmd_otr_start_sends_otr_query_message_to_current_recipeint(void **state) will_return(otr_key_loaded, TRUE); will_return(otr_start_query, query_message); - expect_string(message_send_chat, barejid, chatwin->barejid); - expect_string(message_send_chat, msg, query_message); + expect_string(message_send_chat_encrypted, barejid, chatwin->barejid); + expect_string(message_send_chat_encrypted, msg, query_message); gboolean result = cmd_otr(args, *help); assert_true(result); diff --git a/tests/xmpp/stub_xmpp.c b/tests/xmpp/stub_xmpp.c index dc9a258e..9ca0c2d4 100644 --- a/tests/xmpp/stub_xmpp.c +++ b/tests/xmpp/stub_xmpp.c @@ -64,6 +64,12 @@ void message_send_chat(const char * const barejid, const char * const msg) check_expected(msg); } +void message_send_chat_encrypted(const char * const barejid, const char * const msg) +{ + check_expected(barejid); + check_expected(msg); +} + void message_send_private(const char * const fulljid, const char * const msg) {} void message_send_groupchat(const char * const roomjid, const char * const msg) {} void message_send_groupchat_subject(const char * const roomjid, const char * const subject) {} From 0269129d17bf86f9db810a8a1720ff1d63ad336d Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 10 Mar 2015 21:24:38 +0000 Subject: [PATCH 119/252] Updated changelog --- CHANGELOG | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 4add51cf..10deba0b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,9 @@ +0.4.7 +===== + +- GNU Readline +- Message Carbons (xep-0280) + 0.4.6 ===== From e5bb12a0d6223e6c6297c1700914332942a4ca00 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 10 Mar 2015 23:35:08 +0000 Subject: [PATCH 120/252] Added /time statusbar preference --- src/command/command.c | 50 ++++++++++++++++++++++++++++++----- src/command/commands.c | 56 ++++++++++++++++++++++++++++------------ src/config/preferences.c | 5 ++++ src/config/preferences.h | 1 + src/config/theme.c | 1 + src/ui/console.c | 10 +++++++ src/ui/statusbar.c | 54 +++++++++++++++++++++++++++++--------- themes/boothj5 | 1 + themes/complex | 1 + themes/simple | 1 + 10 files changed, 144 insertions(+), 36 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index 6a5603ee..2186d224 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -102,6 +102,7 @@ static char * _role_autocomplete(const char * const input); static char * _resource_autocomplete(const char * const input); static char * _titlebar_autocomplete(const char * const input); static char * _inpblock_autocomplete(const char * const input); +static char * _time_autocomplete(const char * const input); GHashTable *commands = NULL; @@ -681,11 +682,18 @@ static struct cmd_t command_defs[] = NULL } } }, { "/time", - cmd_time, parse_args, 1, 1, &cons_time_setting, - { "/time minutes|seconds", "Time display.", - { "/time minutes|seconds", - "---------------------", - "Configure time precision for the main window.", + cmd_time, parse_args, 1, 2, &cons_time_setting, + { "/time setting|statusbar [setting]", "Time display.", + { "/time setting|statusbar [setting]", + "---------------------------------", + "Configure time display preferences.", + "", + "minutes : Use minutes precision in main window.", + "seconds : Use seconds precision in main window.", + "off : Do not show time in main window.", + "statusbar minutes : Show minutes precision in status bar.", + "statusbar seconds : Show seconds precision in status bar.", + "statusbar off : Do not show time in status bar.", NULL } } }, { "/inpblock", @@ -1180,6 +1188,7 @@ static Autocomplete form_field_multi_ac; static Autocomplete occupants_ac; static Autocomplete occupants_default_ac; static Autocomplete time_ac; +static Autocomplete time_statusbar_ac; static Autocomplete resource_ac; static Autocomplete inpblock_ac; @@ -1523,6 +1532,12 @@ cmd_init(void) autocomplete_add(time_ac, "minutes"); autocomplete_add(time_ac, "seconds"); autocomplete_add(time_ac, "off"); + autocomplete_add(time_ac, "statusbar"); + + time_statusbar_ac = autocomplete_new(); + autocomplete_add(time_statusbar_ac, "minutes"); + autocomplete_add(time_statusbar_ac, "seconds"); + autocomplete_add(time_statusbar_ac, "off"); resource_ac = autocomplete_new(); autocomplete_add(resource_ac, "set"); @@ -1587,6 +1602,7 @@ cmd_uninit(void) autocomplete_free(occupants_ac); autocomplete_free(occupants_default_ac); autocomplete_free(time_ac); + autocomplete_free(time_statusbar_ac); autocomplete_free(resource_ac); autocomplete_free(inpblock_ac); } @@ -1752,6 +1768,7 @@ cmd_reset_autocomplete() autocomplete_reset(occupants_ac); autocomplete_reset(occupants_default_ac); autocomplete_reset(time_ac); + autocomplete_reset(time_statusbar_ac); autocomplete_reset(resource_ac); autocomplete_reset(inpblock_ac); @@ -2067,8 +2084,8 @@ _cmd_complete_parameters(const char * const input) } } - gchar *cmds[] = { "/help", "/prefs", "/disco", "/close", "/wins", "/subject", "/room", "/time" }; - Autocomplete completers[] = { help_ac, prefs_ac, disco_ac, close_ac, wins_ac, subject_ac, room_ac, time_ac }; + gchar *cmds[] = { "/help", "/prefs", "/disco", "/close", "/wins", "/subject", "/room" }; + Autocomplete completers[] = { help_ac, prefs_ac, disco_ac, close_ac, wins_ac, subject_ac, room_ac }; for (i = 0; i < ARRAY_SIZE(cmds); i++) { result = autocomplete_param_with_ac(input, cmds[i], completers[i], TRUE); @@ -2103,6 +2120,7 @@ _cmd_complete_parameters(const char * const input) g_hash_table_insert(ac_funcs, "/resource", _resource_autocomplete); g_hash_table_insert(ac_funcs, "/titlebar", _titlebar_autocomplete); g_hash_table_insert(ac_funcs, "/inpblock", _inpblock_autocomplete); + g_hash_table_insert(ac_funcs, "/time", _time_autocomplete); int len = strlen(input); char parsed[len+1]; @@ -2739,6 +2757,24 @@ _occupants_autocomplete(const char * const input) return NULL; } +static char * +_time_autocomplete(const char * const input) +{ + char *found = NULL; + + found = autocomplete_param_with_ac(input, "/time statusbar", time_statusbar_ac, TRUE); + if (found != NULL) { + return found; + } + + found = autocomplete_param_with_ac(input, "/time", time_ac, TRUE); + if (found != NULL) { + return found; + } + + return NULL; +} + static char * _kick_autocomplete(const char * const input) { diff --git a/src/command/commands.c b/src/command/commands.c index 2ca749fb..1851a3f4 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -3270,24 +3270,46 @@ cmd_wrap(gchar **args, struct cmd_help_t help) gboolean cmd_time(gchar **args, struct cmd_help_t help) { - if (g_strcmp0(args[0], "minutes") == 0) { - prefs_set_string(PREF_TIME, "minutes"); - cons_show("Time precision set to minutes."); - wins_resize_all(); - return TRUE; - } else if (g_strcmp0(args[0], "seconds") == 0) { - prefs_set_string(PREF_TIME, "seconds"); - cons_show("Time precision set to seconds."); - wins_resize_all(); - return TRUE; - } else if (g_strcmp0(args[0], "off") == 0) { - prefs_set_string(PREF_TIME, "off"); - cons_show("Time display disabled."); - wins_resize_all(); - return TRUE; + if (g_strcmp0(args[0], "statusbar") == 0) { + if (g_strcmp0(args[1], "minutes") == 0) { + prefs_set_string(PREF_TIME_STATUSBAR, "minutes"); + cons_show("Status bar time precision set to minutes."); + ui_redraw(); + return TRUE; + } else if (g_strcmp0(args[1], "seconds") == 0) { + prefs_set_string(PREF_TIME_STATUSBAR, "seconds"); + cons_show("Status bar time precision set to seconds."); + ui_redraw(); + return TRUE; + } else if (g_strcmp0(args[1], "off") == 0) { + prefs_set_string(PREF_TIME_STATUSBAR, "off"); + cons_show("Status bar time display disabled."); + ui_redraw(); + return TRUE; + } else { + cons_show("Usage: %s", help.usage); + return TRUE; + } } else { - cons_show("Usage: %s", help.usage); - return TRUE; + if (g_strcmp0(args[0], "minutes") == 0) { + prefs_set_string(PREF_TIME, "minutes"); + cons_show("Time precision set to minutes."); + wins_resize_all(); + return TRUE; + } else if (g_strcmp0(args[0], "seconds") == 0) { + prefs_set_string(PREF_TIME, "seconds"); + cons_show("Time precision set to seconds."); + wins_resize_all(); + return TRUE; + } else if (g_strcmp0(args[0], "off") == 0) { + prefs_set_string(PREF_TIME, "off"); + cons_show("Time display disabled."); + wins_resize_all(); + return TRUE; + } else { + cons_show("Usage: %s", help.usage); + return TRUE; + } } } diff --git a/src/config/preferences.c b/src/config/preferences.c index eb610732..0dbfe3e3 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -507,6 +507,7 @@ _get_group(preference_t pref) case PREF_PRESENCE: case PREF_WRAP: case PREF_TIME: + case PREF_TIME_STATUSBAR: case PREF_ROSTER: case PREF_ROSTER_OFFLINE: case PREF_ROSTER_RESOURCE: @@ -646,6 +647,8 @@ _get_key(preference_t pref) return "wrap"; case PREF_TIME: return "time"; + case PREF_TIME_STATUSBAR: + return "time.statusbar"; case PREF_ROSTER: return "roster"; case PREF_ROSTER_OFFLINE: @@ -722,6 +725,8 @@ _get_default_string(preference_t pref) return "presence"; case PREF_TIME: return "seconds"; + case PREF_TIME_STATUSBAR: + return "minutes"; default: return NULL; } diff --git a/src/config/preferences.h b/src/config/preferences.h index 61a35c8a..7b29ae33 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -72,6 +72,7 @@ typedef enum { PREF_PRESENCE, PREF_WRAP, PREF_TIME, + PREF_TIME_STATUSBAR, PREF_STATUSES, PREF_STATUSES_CONSOLE, PREF_STATUSES_CHAT, diff --git a/src/config/theme.c b/src/config/theme.c index d2bf0a48..3aeadf40 100644 --- a/src/config/theme.c +++ b/src/config/theme.c @@ -426,6 +426,7 @@ _load_preferences(void) _set_boolean_preference("splash", PREF_SPLASH); _set_boolean_preference("wrap", PREF_WRAP); _set_string_preference("time", PREF_TIME); + _set_string_preference("time.statusbar", PREF_TIME_STATUSBAR); _set_boolean_preference("resource.title", PREF_RESOURCE_TITLE); _set_boolean_preference("resource.message", PREF_RESOURCE_MESSAGE); diff --git a/src/ui/console.c b/src/ui/console.c index 745a12ee..dc8a3c7b 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -934,6 +934,16 @@ cons_time_setting(void) cons_show("Time (/time) : seconds"); prefs_free_string(pref_time); + + char *pref_time_statusbar = prefs_get_string(PREF_TIME_STATUSBAR); + if (g_strcmp0(pref_time_statusbar, "minutes") == 0) + cons_show("Time statusbar (/time) : minutes"); + else if (g_strcmp0(pref_time_statusbar, "off") == 0) + cons_show("Time statusbar (/time) : OFF"); + else + cons_show("Time statusbar (/time) : seconds"); + + prefs_free_string(pref_time_statusbar); } void diff --git a/src/ui/statusbar.c b/src/ui/statusbar.c index b9244fcd..93eeaab0 100644 --- a/src/ui/statusbar.c +++ b/src/ui/statusbar.c @@ -48,6 +48,7 @@ #include "ui/ui.h" #include "ui/statusbar.h" #include "ui/inputwin.h" +#include "config/preferences.h" #define TIME_CHECK 60000000 @@ -127,7 +128,14 @@ status_bar_resize(void) wattroff(status_bar, bracket_attrs); if (message != NULL) { - mvwprintw(status_bar, 0, 10, message); + char *time_pref = prefs_get_string(PREF_TIME_STATUSBAR); + if (g_strcmp0(time_pref, "minutes") == 0) { + mvwprintw(status_bar, 0, 10, message); + } else if (g_strcmp0(time_pref, "seconds") == 0) { + mvwprintw(status_bar, 0, 13, message); + } else { + mvwprintw(status_bar, 0, 1, message); + } } if (last_time != NULL) { g_date_time_unref(last_time); @@ -293,7 +301,15 @@ status_bar_print_message(const char * const msg) free(message); } message = strdup(msg); - mvwprintw(status_bar, 0, 10, message); + + char *time_pref = prefs_get_string(PREF_TIME_STATUSBAR); + if (g_strcmp0(time_pref, "minutes") == 0) { + mvwprintw(status_bar, 0, 10, message); + } else if (g_strcmp0(time_pref, "seconds") == 0) { + mvwprintw(status_bar, 0, 13, message); + } else { + mvwprintw(status_bar, 0, 1, message); + } int cols = getmaxx(stdscr); int bracket_attrs = theme_attrs(THEME_STATUS_BRACKET); @@ -416,19 +432,33 @@ _status_bar_draw(void) g_date_time_unref(last_time); } last_time = g_date_time_new_now_local(); - gchar *date_fmt = g_date_time_format(last_time, "%H:%M"); - assert(date_fmt != NULL); int bracket_attrs = theme_attrs(THEME_STATUS_BRACKET); - wattron(status_bar, bracket_attrs); - mvwaddch(status_bar, 0, 1, '['); - wattroff(status_bar, bracket_attrs); - mvwprintw(status_bar, 0, 2, date_fmt); - wattron(status_bar, bracket_attrs); - mvwaddch(status_bar, 0, 7, ']'); - wattroff(status_bar, bracket_attrs); - g_free(date_fmt); + char *time_pref = prefs_get_string(PREF_TIME_STATUSBAR); + if (g_strcmp0(time_pref, "minutes") == 0) { + gchar *date_fmt = g_date_time_format(last_time, "%H:%M"); + assert(date_fmt != NULL); + wattron(status_bar, bracket_attrs); + mvwaddch(status_bar, 0, 1, '['); + wattroff(status_bar, bracket_attrs); + mvwprintw(status_bar, 0, 2, date_fmt); + wattron(status_bar, bracket_attrs); + mvwaddch(status_bar, 0, 7, ']'); + wattroff(status_bar, bracket_attrs); + g_free(date_fmt); + } else if (g_strcmp0(time_pref, "seconds") == 0) { + gchar *date_fmt = g_date_time_format(last_time, "%H:%M:%S"); + assert(date_fmt != NULL); + wattron(status_bar, bracket_attrs); + mvwaddch(status_bar, 0, 1, '['); + wattroff(status_bar, bracket_attrs); + mvwprintw(status_bar, 0, 2, date_fmt); + wattron(status_bar, bracket_attrs); + mvwaddch(status_bar, 0, 10, ']'); + wattroff(status_bar, bracket_attrs); + g_free(date_fmt); + } _update_win_statuses(); wnoutrefresh(status_bar); diff --git a/themes/boothj5 b/themes/boothj5 index cd6379cd..49231ab0 100644 --- a/themes/boothj5 +++ b/themes/boothj5 @@ -54,6 +54,7 @@ flash=false splash=true wrap=true time=seconds +time.statusbar=seconds privileges=true presence=true intype=true diff --git a/themes/complex b/themes/complex index a2695a1f..61f6a270 100644 --- a/themes/complex +++ b/themes/complex @@ -4,6 +4,7 @@ flash=false splash=true wrap=true time=seconds +time.statusbar=seconds resource.title=true resource.message=true statuses.console=all diff --git a/themes/simple b/themes/simple index 0b9baab5..2885db12 100644 --- a/themes/simple +++ b/themes/simple @@ -4,6 +4,7 @@ flash=false splash=true wrap=true time=minutes +time.statusbar=off resource.title=false resource.message=false statuses.console=none From 78becceedb19b1a793fcd3465363501f5468a83d Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 11 Mar 2015 23:18:28 +0000 Subject: [PATCH 121/252] Added basic delivery receipts --- src/config/preferences.c | 5 +- src/config/preferences.h | 1 + src/server_events.c | 6 +++ src/server_events.h | 1 + src/ui/core.c | 13 +++++ src/ui/ui.h | 1 + src/xmpp/message.c | 103 +++++++++++++++++++++++++++++++++------ src/xmpp/stanza.c | 55 ++++++++++++++------- src/xmpp/stanza.h | 8 ++- tests/ui/stub_ui.c | 2 + 10 files changed, 158 insertions(+), 37 deletions(-) diff --git a/src/config/preferences.c b/src/config/preferences.c index 0dbfe3e3..ce25ff9e 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -543,6 +543,7 @@ _get_group(preference_t pref) case PREF_CONNECT_ACCOUNT: case PREF_DEFAULT_ACCOUNT: case PREF_CARBONS: + case PREF_RECEIPTS: return PREF_GROUP_CONNECTION; case PREF_OTR_LOG: case PREF_OTR_POLICY: @@ -579,6 +580,8 @@ _get_key(preference_t pref) return "history"; case PREF_CARBONS: return "carbons"; + case PREF_RECEIPTS: + return "receipts"; case PREF_MOUSE: return "mouse"; case PREF_OCCUPANTS: @@ -730,4 +733,4 @@ _get_default_string(preference_t pref) default: return NULL; } -} +} \ No newline at end of file diff --git a/src/config/preferences.h b/src/config/preferences.h index 7b29ae33..b031e857 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -60,6 +60,7 @@ typedef enum { PREF_INTYPE, PREF_HISTORY, PREF_CARBONS, + PREF_RECEIPTS, PREF_MOUSE, PREF_OCCUPANTS, PREF_OCCUPANTS_SIZE, diff --git a/src/server_events.c b/src/server_events.c index b0a9b1e3..2509dd43 100644 --- a/src/server_events.c +++ b/src/server_events.c @@ -402,6 +402,12 @@ handle_delayed_message(char *barejid, char *message, GTimeVal tv_stamp) } } +void +handle_message_receipt(char *barejid, char *id) +{ + ui_message_receipt(barejid, id); +} + void handle_typing(char *barejid, char *resource) { diff --git a/src/server_events.h b/src/server_events.h index 042eb934..403c5bb5 100644 --- a/src/server_events.h +++ b/src/server_events.h @@ -79,6 +79,7 @@ void handle_inactive(char *barejid, char *resource); void handle_activity(char *barejid, char *resource, gboolean send_states); void handle_gone(const char * const barejid, const char * const resource); void handle_subscription(const char *from, jabber_subscr_t type); +void handle_message_receipt(char *barejid, char *id); void handle_contact_offline(char *contact, char *resource, char *status); void handle_contact_online(char *contact, Resource *resource, GDateTime *last_activity); diff --git a/src/ui/core.c b/src/ui/core.c index b9f526cc..48143f48 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -381,6 +381,19 @@ ui_get_current_chat(void) return wins_get_current_chat(); } +void +ui_message_receipt(const char * const barejid, const char * const id) +{ + ProfChatWin *chatwin = wins_get_chat(barejid); + if (chatwin) { + ProfWin *win = (ProfWin*) chatwin; + GString *message = g_string_new("Message received: "); + g_string_append(message, id); + win_save_println(win, message->str); + g_string_free(message, TRUE); + } +} + void ui_incoming_msg(const char * const barejid, const char * const resource, const char * const message, GTimeVal *tv_stamp) { diff --git a/src/ui/ui.h b/src/ui/ui.h index a0408503..b621a539 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -116,6 +116,7 @@ void ui_handle_stanza(const char * const msg); void ui_contact_typing(const char * const barejid, const char * const resource); void ui_incoming_msg(const char * const from, const char * const resource, const char * const message, GTimeVal *tv_stamp); void ui_incoming_private_msg(const char * const fulljid, const char * const message, GTimeVal *tv_stamp); +void ui_message_receipt(const char * const barejid, const char * const id); void ui_disconnected(void); void ui_recipient_gone(const char * const barejid, const char * const resource); diff --git a/src/xmpp/message.c b/src/xmpp/message.c index ab7f52cd..739a95e6 100644 --- a/src/xmpp/message.c +++ b/src/xmpp/message.c @@ -82,25 +82,35 @@ message_add_handlers(void) void message_send_chat(const char * const barejid, const char * const msg) { - xmpp_stanza_t *message; xmpp_conn_t * const conn = connection_get_conn(); xmpp_ctx_t * const ctx = connection_get_ctx(); ChatSession *session = chat_session_get(barejid); + char *state = NULL; + char *jid = NULL; if (session) { - char *state = NULL; if (prefs_get_boolean(PREF_STATES) && session->send_states) { state = STANZA_NAME_ACTIVE; } Jid *jidp = jid_create_from_bare_and_resource(session->barejid, session->resource); - message = stanza_create_message(ctx, jidp->fulljid, STANZA_TYPE_CHAT, msg, state, false); + jid = strdup(jidp->fulljid); jid_destroy(jidp); + } else { - char *state = NULL; if (prefs_get_boolean(PREF_STATES)) { state = STANZA_NAME_ACTIVE; } - message = stanza_create_message(ctx, barejid, STANZA_TYPE_CHAT, msg, state, false); + jid = strdup(barejid); + } + + xmpp_stanza_t *message = stanza_create_message(ctx, jid, STANZA_TYPE_CHAT, msg); + free(jid); + + if (state) { + stanza_attach_state(ctx, message, state); + } + if (prefs_get_boolean(PREF_RECEIPTS)) { + stanza_attach_receipt_request(ctx, message); } xmpp_send(conn, message); @@ -110,25 +120,35 @@ message_send_chat(const char * const barejid, const char * const msg) void message_send_chat_encrypted(const char * const barejid, const char * const msg) { - xmpp_stanza_t *message; xmpp_conn_t * const conn = connection_get_conn(); xmpp_ctx_t * const ctx = connection_get_ctx(); ChatSession *session = chat_session_get(barejid); + char *state = NULL; + char *jid = NULL; if (session) { - char *state = NULL; if (prefs_get_boolean(PREF_STATES) && session->send_states) { state = STANZA_NAME_ACTIVE; } Jid *jidp = jid_create_from_bare_and_resource(session->barejid, session->resource); - message = stanza_create_message(ctx, jidp->fulljid, STANZA_TYPE_CHAT, msg, state, true); + jid = strdup(jidp->fulljid); jid_destroy(jidp); } else { - char *state = NULL; if (prefs_get_boolean(PREF_STATES)) { state = STANZA_NAME_ACTIVE; } - message = stanza_create_message(ctx, barejid, STANZA_TYPE_CHAT, msg, state, true); + jid = strdup(barejid); + } + + xmpp_stanza_t *message = stanza_create_message(ctx, barejid, STANZA_TYPE_CHAT, msg); + free(jid); + + if (state) { + stanza_attach_state(ctx, message, state); + } + stanza_attach_carbons_private(ctx, message); + if (prefs_get_boolean(PREF_RECEIPTS)) { + stanza_attach_receipt_request(ctx, message); } xmpp_send(conn, message); @@ -140,7 +160,7 @@ message_send_private(const char * const fulljid, const char * const msg) { xmpp_conn_t * const conn = connection_get_conn(); xmpp_ctx_t * const ctx = connection_get_ctx(); - xmpp_stanza_t *message = stanza_create_message(ctx, fulljid, STANZA_TYPE_CHAT, msg, NULL, false); + xmpp_stanza_t *message = stanza_create_message(ctx, fulljid, STANZA_TYPE_CHAT, msg); xmpp_send(conn, message); xmpp_stanza_release(message); @@ -151,7 +171,7 @@ message_send_groupchat(const char * const roomjid, const char * const msg) { xmpp_conn_t * const conn = connection_get_conn(); xmpp_ctx_t * const ctx = connection_get_ctx(); - xmpp_stanza_t *message = stanza_create_message(ctx, roomjid, STANZA_TYPE_GROUPCHAT, msg, NULL, false); + xmpp_stanza_t *message = stanza_create_message(ctx, roomjid, STANZA_TYPE_GROUPCHAT, msg); xmpp_send(conn, message); xmpp_stanza_release(message); @@ -441,6 +461,29 @@ _groupchat_handler(xmpp_conn_t * const conn, return 1; } +void +_message_send_receipt(const char * const fulljid, const char * const message_id) +{ + xmpp_conn_t * const conn = connection_get_conn(); + xmpp_ctx_t * const ctx = connection_get_ctx(); + xmpp_stanza_t *message = xmpp_stanza_new(ctx); + char *id = create_unique_id("receipt"); + xmpp_stanza_set_name(message, STANZA_NAME_MESSAGE); + xmpp_stanza_set_id(message, id); + xmpp_stanza_set_attribute(message, STANZA_ATTR_TO, fulljid); + + xmpp_stanza_t *receipt = xmpp_stanza_new(ctx); + xmpp_stanza_set_name(receipt, "received"); + xmpp_stanza_set_ns(receipt, STANZA_NS_RECEIPTS); + xmpp_stanza_set_attribute(receipt, STANZA_ATTR_ID, message_id); + + xmpp_stanza_add_child(message, receipt); + xmpp_stanza_release(receipt); + + xmpp_send(conn, message); + xmpp_stanza_release(message); +} + static int _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) @@ -451,10 +494,28 @@ _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, return 1; } + // check if message receipt + xmpp_stanza_t *receipt = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_RECEIPTS); + if (receipt) { + char *name = xmpp_stanza_get_name(receipt); + if (g_strcmp0(name, "received") == 0) { + char *id = xmpp_stanza_get_attribute(receipt, STANZA_ATTR_ID); + if (id) { + char *fulljid = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); + if (fulljid) { + Jid *jidp = jid_create(fulljid); + handle_message_receipt(jidp->barejid, id); + jid_destroy(jidp); + } + + } + } + } + // check if carbon message - xmpp_stanza_t *received = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_CARBONS); - if(received != NULL){ - xmpp_stanza_t *forwarded = xmpp_stanza_get_child_by_ns(received, STANZA_NS_FORWARD); + xmpp_stanza_t *carbons = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_CARBONS); + if (carbons){ + xmpp_stanza_t *forwarded = xmpp_stanza_get_child_by_ns(carbons, STANZA_NS_FORWARD); xmpp_stanza_t *message = xmpp_stanza_get_child_by_name(forwarded, STANZA_NAME_MESSAGE); xmpp_ctx_t *ctx = connection_get_ctx(); @@ -535,6 +596,7 @@ _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, // determine if the notifications happened whilst offline GTimeVal tv_stamp; gboolean delayed = stanza_get_delay(stanza, &tv_stamp); + char *id = xmpp_stanza_get_id(stanza); // check for and deal with message xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_BODY); @@ -546,6 +608,15 @@ _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, } else { handle_incoming_message(jid->barejid, jid->resourcepart, message); } + if (id) { + xmpp_stanza_t *receipts = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_RECEIPTS); + if (receipts) { + char *receipts_name = xmpp_stanza_get_name(receipts); + if (g_strcmp0(receipts_name, "request") == 0) { + _message_send_receipt(jid->fulljid, id); + } + } + } xmpp_free(ctx, message); } } @@ -574,4 +645,4 @@ _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, jid_destroy(jid); return 1; } -} +} \ No newline at end of file diff --git a/src/xmpp/stanza.c b/src/xmpp/stanza.c index e849ac97..635f5678 100644 --- a/src/xmpp/stanza.c +++ b/src/xmpp/stanza.c @@ -281,10 +281,45 @@ stanza_create_room_subject_message(xmpp_ctx_t *ctx, const char * const room, con return msg; } +xmpp_stanza_t * +stanza_attach_state(xmpp_ctx_t *ctx, xmpp_stanza_t *stanza, const char * const state) +{ + xmpp_stanza_t *chat_state = xmpp_stanza_new(ctx); + xmpp_stanza_set_name(chat_state, state); + xmpp_stanza_set_ns(chat_state, STANZA_NS_CHATSTATES); + xmpp_stanza_add_child(stanza, chat_state); + xmpp_stanza_release(chat_state); + + return stanza; +} + +xmpp_stanza_t * +stanza_attach_carbons_private(xmpp_ctx_t *ctx, xmpp_stanza_t *stanza) +{ + xmpp_stanza_t *private_carbon = xmpp_stanza_new(ctx); + xmpp_stanza_set_name(private_carbon, "private"); + xmpp_stanza_set_ns(private_carbon, STANZA_NS_CARBONS); + xmpp_stanza_add_child(stanza, private_carbon); + xmpp_stanza_release(private_carbon); + + return stanza; +} + +xmpp_stanza_t * +stanza_attach_receipt_request(xmpp_ctx_t *ctx, xmpp_stanza_t *stanza) +{ + xmpp_stanza_t *receipet_request = xmpp_stanza_new(ctx); + xmpp_stanza_set_name(receipet_request, "request"); + xmpp_stanza_set_ns(receipet_request, STANZA_NS_RECEIPTS); + xmpp_stanza_add_child(stanza, receipet_request); + xmpp_stanza_release(receipet_request); + + return stanza; +} + xmpp_stanza_t * stanza_create_message(xmpp_ctx_t *ctx, const char * const recipient, - const char * const type, const char * const message, - const char * const state, gboolean encrypted) + const char * const type, const char * const message) { xmpp_stanza_t *msg, *body, *text; @@ -306,22 +341,6 @@ stanza_create_message(xmpp_ctx_t *ctx, const char * const recipient, xmpp_stanza_add_child(msg, body); xmpp_stanza_release(body); - if (state != NULL) { - xmpp_stanza_t *chat_state = xmpp_stanza_new(ctx); - xmpp_stanza_set_name(chat_state, state); - xmpp_stanza_set_ns(chat_state, STANZA_NS_CHATSTATES); - xmpp_stanza_add_child(msg, chat_state); - xmpp_stanza_release(chat_state); - } - - if (encrypted) { - xmpp_stanza_t *private_carbon = xmpp_stanza_new(ctx); - xmpp_stanza_set_name(private_carbon, "private"); - xmpp_stanza_set_ns(private_carbon, STANZA_NS_CARBONS); - xmpp_stanza_add_child(msg, private_carbon); - xmpp_stanza_release(private_carbon); - } - return msg; } diff --git a/src/xmpp/stanza.h b/src/xmpp/stanza.h index 365bed86..eca3bf8a 100644 --- a/src/xmpp/stanza.h +++ b/src/xmpp/stanza.h @@ -158,6 +158,7 @@ #define STANZA_NS_PUBSUB "http://jabber.org/protocol/pubsub" #define STANZA_NS_CARBONS "urn:xmpp:carbons:2" #define STANZA_NS_FORWARD "urn:xmpp:forward:0" +#define STANZA_NS_RECEIPTS "urn:xmpp:receipts" #define STANZA_DATAFORM_SOFTWARE "urn:xmpp:dataforms:softwareinfo" @@ -189,9 +190,12 @@ xmpp_stanza_t * stanza_disable_carbons(xmpp_ctx_t *ctx); xmpp_stanza_t* stanza_create_chat_state(xmpp_ctx_t *ctx, const char * const fulljid, const char * const state); +xmpp_stanza_t * stanza_attach_state(xmpp_ctx_t *ctx, xmpp_stanza_t *stanza, const char * const state); +xmpp_stanza_t * stanza_attach_carbons_private(xmpp_ctx_t *ctx, xmpp_stanza_t *stanza); +xmpp_stanza_t * stanza_attach_receipt_request(xmpp_ctx_t *ctx, xmpp_stanza_t *stanza); + xmpp_stanza_t* stanza_create_message(xmpp_ctx_t *ctx, - const char * const recipient, const char * const type, - const char * const message, const char * const state, gboolean encrypted); + const char * const recipient, const char * const type, const char * const message); xmpp_stanza_t* stanza_create_room_join_presence(xmpp_ctx_t * const ctx, const char * const full_room_jid, const char * const passwd); diff --git a/tests/ui/stub_ui.c b/tests/ui/stub_ui.c index 1a0f650d..55c67335 100644 --- a/tests/ui/stub_ui.c +++ b/tests/ui/stub_ui.c @@ -194,6 +194,8 @@ void ui_handle_stanza(const char * const msg) {} // ui events void ui_contact_typing(const char * const barejid, const char * const resource) {} void ui_incoming_msg(const char * const from, const char * const resource, const char * const message, GTimeVal *tv_stamp) {} +void ui_message_receipt(const char * const barejid, const char * const id) {} + void ui_incoming_private_msg(const char * const fulljid, const char * const message, GTimeVal *tv_stamp) {} void ui_disconnected(void) {} From 57c7564445bb9b3034be895a709d8ec777188a74 Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 11 Mar 2015 23:47:11 +0000 Subject: [PATCH 122/252] Show message received text for receipts --- src/command/command.c | 12 ++++++------ src/command/commands.c | 19 ++++++++++--------- src/server_events.c | 2 +- src/ui/core.c | 13 +++++++++++-- src/ui/ui.h | 2 +- src/xmpp/message.c | 22 ++++++++++++++++------ src/xmpp/stanza.c | 4 +--- src/xmpp/stanza.h | 2 +- src/xmpp/xmpp.h | 4 ++-- tests/ui/stub_ui.c | 2 +- tests/xmpp/stub_xmpp.c | 6 ++++-- 11 files changed, 54 insertions(+), 34 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index 2186d224..806a75f2 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -1945,7 +1945,7 @@ _cmd_execute_default(const char * inp) if (otr_is_secure(chatwin->barejid)) { char *encrypted = otr_encrypt_message(chatwin->barejid, inp); if (encrypted != NULL) { - message_send_chat_encrypted(chatwin->barejid, encrypted); + char *id = message_send_chat_encrypted(chatwin->barejid, encrypted); otr_free_message(encrypted); if (prefs_get_boolean(PREF_CHLOG)) { const char *jid = jabber_get_fulljid(); @@ -1960,12 +1960,12 @@ _cmd_execute_default(const char * inp) jid_destroy(jidp); } - ui_outgoing_chat_msg("me", chatwin->barejid, inp); + ui_outgoing_chat_msg("me", chatwin->barejid, inp, id); } else { cons_show_error("Failed to send message."); } } else { - message_send_chat(chatwin->barejid, inp); + char *id = message_send_chat(chatwin->barejid, inp); if (prefs_get_boolean(PREF_CHLOG)) { const char *jid = jabber_get_fulljid(); Jid *jidp = jid_create(jid); @@ -1973,10 +1973,10 @@ _cmd_execute_default(const char * inp) jid_destroy(jidp); } - ui_outgoing_chat_msg("me", chatwin->barejid, inp); + ui_outgoing_chat_msg("me", chatwin->barejid, inp, id); } #else - message_send_chat(chatwin->barejid, inp); + char *id = message_send_chat(chatwin->barejid, inp); if (prefs_get_boolean(PREF_CHLOG)) { const char *jid = jabber_get_fulljid(); Jid *jidp = jid_create(jid); @@ -1984,7 +1984,7 @@ _cmd_execute_default(const char * inp) jid_destroy(jidp); } - ui_outgoing_chat_msg("me", chatwin->barejid, inp); + ui_outgoing_chat_msg("me", chatwin->barejid, inp, id); #endif } break; diff --git a/src/command/commands.c b/src/command/commands.c index 1851a3f4..dd63b25f 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -1265,9 +1265,9 @@ cmd_msg(gchar **args, struct cmd_help_t help) if (otr_is_secure(barejid)) { char *encrypted = otr_encrypt_message(barejid, msg); if (encrypted != NULL) { - message_send_chat_encrypted(barejid, encrypted); + char *id = message_send_chat_encrypted(barejid, encrypted); otr_free_message(encrypted); - ui_outgoing_chat_msg("me", barejid, msg); + ui_outgoing_chat_msg("me", barejid, msg, id); if (((win_type == WIN_CHAT) || (win_type == WIN_CONSOLE)) && prefs_get_boolean(PREF_CHLOG)) { const char *jid = jabber_get_fulljid(); @@ -1286,6 +1286,7 @@ cmd_msg(gchar **args, struct cmd_help_t help) } } else { prof_otrpolicy_t policy = otr_get_policy(barejid); + char *id = NULL; if (policy == PROF_OTRPOLICY_ALWAYS) { cons_show_error("Failed to send message. Please check OTR policy"); @@ -1294,13 +1295,13 @@ cmd_msg(gchar **args, struct cmd_help_t help) GString *otr_message = g_string_new(msg); g_string_append(otr_message, OTRL_MESSAGE_TAG_BASE); g_string_append(otr_message, OTRL_MESSAGE_TAG_V2); - message_send_chat_encrypted(barejid, otr_message->str); + id = message_send_chat_encrypted(barejid, otr_message->str); g_string_free(otr_message, TRUE); } else { - message_send_chat(barejid, msg); + id = message_send_chat(barejid, msg); } - ui_outgoing_chat_msg("me", barejid, msg); + ui_outgoing_chat_msg("me", barejid, msg, id); if (((win_type == WIN_CHAT) || (win_type == WIN_CONSOLE)) && prefs_get_boolean(PREF_CHLOG)) { const char *jid = jabber_get_fulljid(); @@ -3073,7 +3074,7 @@ cmd_tiny(gchar **args, struct cmd_help_t help) if (otr_is_secure(chatwin->barejid)) { char *encrypted = otr_encrypt_message(chatwin->barejid, tiny); if (encrypted != NULL) { - message_send_chat_encrypted(chatwin->barejid, encrypted); + char *id = message_send_chat_encrypted(chatwin->barejid, encrypted); otr_free_message(encrypted); if (prefs_get_boolean(PREF_CHLOG)) { const char *jid = jabber_get_fulljid(); @@ -3088,12 +3089,12 @@ cmd_tiny(gchar **args, struct cmd_help_t help) jid_destroy(jidp); } - ui_outgoing_chat_msg("me", chatwin->barejid, tiny); + ui_outgoing_chat_msg("me", chatwin->barejid, tiny, id); } else { cons_show_error("Failed to send message."); } } else { - message_send_chat(chatwin->barejid, tiny); + char *id = message_send_chat(chatwin->barejid, tiny); if (prefs_get_boolean(PREF_CHLOG)) { const char *jid = jabber_get_fulljid(); Jid *jidp = jid_create(jid); @@ -3101,7 +3102,7 @@ cmd_tiny(gchar **args, struct cmd_help_t help) jid_destroy(jidp); } - ui_outgoing_chat_msg("me", chatwin->barejid, tiny); + ui_outgoing_chat_msg("me", chatwin->barejid, tiny, id); } #else message_send_chat(chatwin->barejid, tiny); diff --git a/src/server_events.c b/src/server_events.c index 2509dd43..3d14f0aa 100644 --- a/src/server_events.c +++ b/src/server_events.c @@ -310,7 +310,7 @@ handle_incoming_private_message(char *fulljid, char *message) void handle_carbon(char *barejid, char *message){ - ui_outgoing_chat_msg("me", barejid, message); + ui_outgoing_chat_msg("me", barejid, message, NULL); } void diff --git a/src/ui/core.c b/src/ui/core.c index 48143f48..f43fb2a4 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -1424,7 +1424,7 @@ ui_open_xmlconsole_win(void) void ui_outgoing_chat_msg(const char * const from, const char * const barejid, - const char * const message) + const char * const message, char *id) { PContact contact = roster_get_contact(barejid); ProfWin *window = (ProfWin*)wins_get_chat(barejid); @@ -1460,7 +1460,16 @@ ui_outgoing_chat_msg(const char * const from, const char * const barejid, ProfChatWin *chatwin = (ProfChatWin*)window; chat_state_active(chatwin->state); - win_save_print(window, '-', NULL, 0, THEME_TEXT_ME, from, message); + if (id) { + GString *message_with_id = g_string_new(id); + g_string_append(message_with_id, ": "); + g_string_append(message_with_id, message); + win_save_print(window, '-', NULL, 0, THEME_TEXT_ME, from, message_with_id->str); + g_string_free(message_with_id, TRUE); + free(id); + } else { + win_save_print(window, '-', NULL, 0, THEME_TEXT_ME, from, message); + } ui_switch_win(num); } diff --git a/src/ui/ui.h b/src/ui/ui.h index b621a539..a6428da3 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -122,7 +122,7 @@ void ui_disconnected(void); void ui_recipient_gone(const char * const barejid, const char * const resource); void ui_outgoing_chat_msg(const char * const from, const char * const barejid, - const char * const message); + const char * const message, char *id); void ui_outgoing_private_msg(const char * const from, const char * const fulljid, const char * const message); diff --git a/src/xmpp/message.c b/src/xmpp/message.c index 739a95e6..dea4f8d0 100644 --- a/src/xmpp/message.c +++ b/src/xmpp/message.c @@ -79,7 +79,7 @@ message_add_handlers(void) HANDLE(STANZA_NS_CAPTCHA, NULL, _captcha_handler); } -void +char * message_send_chat(const char * const barejid, const char * const msg) { xmpp_conn_t * const conn = connection_get_conn(); @@ -103,7 +103,8 @@ message_send_chat(const char * const barejid, const char * const msg) jid = strdup(barejid); } - xmpp_stanza_t *message = stanza_create_message(ctx, jid, STANZA_TYPE_CHAT, msg); + char *id = create_unique_id("msg"); + xmpp_stanza_t *message = stanza_create_message(ctx, id, jid, STANZA_TYPE_CHAT, msg); free(jid); if (state) { @@ -115,9 +116,11 @@ message_send_chat(const char * const barejid, const char * const msg) xmpp_send(conn, message); xmpp_stanza_release(message); + + return id; } -void +char * message_send_chat_encrypted(const char * const barejid, const char * const msg) { xmpp_conn_t * const conn = connection_get_conn(); @@ -140,7 +143,8 @@ message_send_chat_encrypted(const char * const barejid, const char * const msg) jid = strdup(barejid); } - xmpp_stanza_t *message = stanza_create_message(ctx, barejid, STANZA_TYPE_CHAT, msg); + char *id = create_unique_id("msg"); + xmpp_stanza_t *message = stanza_create_message(ctx, id, barejid, STANZA_TYPE_CHAT, msg); free(jid); if (state) { @@ -153,6 +157,8 @@ message_send_chat_encrypted(const char * const barejid, const char * const msg) xmpp_send(conn, message); xmpp_stanza_release(message); + + return id; } void @@ -160,7 +166,9 @@ message_send_private(const char * const fulljid, const char * const msg) { xmpp_conn_t * const conn = connection_get_conn(); xmpp_ctx_t * const ctx = connection_get_ctx(); - xmpp_stanza_t *message = stanza_create_message(ctx, fulljid, STANZA_TYPE_CHAT, msg); + char *id = create_unique_id("prv"); + xmpp_stanza_t *message = stanza_create_message(ctx, id, fulljid, STANZA_TYPE_CHAT, msg); + free(id); xmpp_send(conn, message); xmpp_stanza_release(message); @@ -171,7 +179,9 @@ message_send_groupchat(const char * const roomjid, const char * const msg) { xmpp_conn_t * const conn = connection_get_conn(); xmpp_ctx_t * const ctx = connection_get_ctx(); - xmpp_stanza_t *message = stanza_create_message(ctx, roomjid, STANZA_TYPE_GROUPCHAT, msg); + char *id = create_unique_id("muc"); + xmpp_stanza_t *message = stanza_create_message(ctx, id, roomjid, STANZA_TYPE_GROUPCHAT, msg); + free(id); xmpp_send(conn, message); xmpp_stanza_release(message); diff --git a/src/xmpp/stanza.c b/src/xmpp/stanza.c index 635f5678..0b291d2e 100644 --- a/src/xmpp/stanza.c +++ b/src/xmpp/stanza.c @@ -318,7 +318,7 @@ stanza_attach_receipt_request(xmpp_ctx_t *ctx, xmpp_stanza_t *stanza) } xmpp_stanza_t * -stanza_create_message(xmpp_ctx_t *ctx, const char * const recipient, +stanza_create_message(xmpp_ctx_t *ctx, char *id, const char * const recipient, const char * const type, const char * const message) { xmpp_stanza_t *msg, *body, *text; @@ -327,9 +327,7 @@ stanza_create_message(xmpp_ctx_t *ctx, const char * const recipient, xmpp_stanza_set_name(msg, STANZA_NAME_MESSAGE); xmpp_stanza_set_type(msg, type); xmpp_stanza_set_attribute(msg, STANZA_ATTR_TO, recipient); - char *id = create_unique_id(NULL); xmpp_stanza_set_id(msg, id); - free(id); body = xmpp_stanza_new(ctx); xmpp_stanza_set_name(body, STANZA_NAME_BODY); diff --git a/src/xmpp/stanza.h b/src/xmpp/stanza.h index eca3bf8a..50f3dbd0 100644 --- a/src/xmpp/stanza.h +++ b/src/xmpp/stanza.h @@ -194,7 +194,7 @@ xmpp_stanza_t * stanza_attach_state(xmpp_ctx_t *ctx, xmpp_stanza_t *stanza, cons xmpp_stanza_t * stanza_attach_carbons_private(xmpp_ctx_t *ctx, xmpp_stanza_t *stanza); xmpp_stanza_t * stanza_attach_receipt_request(xmpp_ctx_t *ctx, xmpp_stanza_t *stanza); -xmpp_stanza_t* stanza_create_message(xmpp_ctx_t *ctx, +xmpp_stanza_t* stanza_create_message(xmpp_ctx_t *ctx, char *id, const char * const recipient, const char * const type, const char * const message); xmpp_stanza_t* stanza_create_room_join_presence(xmpp_ctx_t * const ctx, diff --git a/src/xmpp/xmpp.h b/src/xmpp/xmpp.h index e8e79ee9..7deb71db 100644 --- a/src/xmpp/xmpp.h +++ b/src/xmpp/xmpp.h @@ -145,8 +145,8 @@ char* jabber_get_account_name(void); GList * jabber_get_available_resources(void); // message functions -void message_send_chat(const char * const barejid, const char * const msg); -void message_send_chat_encrypted(const char * const barejid, const char * const msg); +char* message_send_chat(const char * const barejid, const char * const msg); +char* message_send_chat_encrypted(const char * const barejid, const char * const msg); void message_send_private(const char * const fulljid, const char * const msg); void message_send_groupchat(const char * const roomjid, const char * const msg); void message_send_groupchat_subject(const char * const roomjid, const char * const subject); diff --git a/tests/ui/stub_ui.c b/tests/ui/stub_ui.c index 55c67335..4ae08ee7 100644 --- a/tests/ui/stub_ui.c +++ b/tests/ui/stub_ui.c @@ -202,7 +202,7 @@ void ui_disconnected(void) {} void ui_recipient_gone(const char * const barejid, const char * const resource) {} void ui_outgoing_chat_msg(const char * const from, const char * const barejid, - const char * const message) {} + const char * const message, char *id) {} void ui_outgoing_private_msg(const char * const from, const char * const fulljid, const char * const message) {} diff --git a/tests/xmpp/stub_xmpp.c b/tests/xmpp/stub_xmpp.c index 9ca0c2d4..53a01c95 100644 --- a/tests/xmpp/stub_xmpp.c +++ b/tests/xmpp/stub_xmpp.c @@ -58,16 +58,18 @@ GList * jabber_get_available_resources(void) } // message functions -void message_send_chat(const char * const barejid, const char * const msg) +char* message_send_chat(const char * const barejid, const char * const msg) { check_expected(barejid); check_expected(msg); + return NULL; } -void message_send_chat_encrypted(const char * const barejid, const char * const msg) +char* message_send_chat_encrypted(const char * const barejid, const char * const msg) { check_expected(barejid); check_expected(msg); + return NULL; } void message_send_private(const char * const fulljid, const char * const msg) {} From f4441ec64f71b684fed3bb842c6a0599132fd47a Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 14 Mar 2015 14:10:10 +0000 Subject: [PATCH 123/252] Renamed win_save_vprint -> win_vprint --- src/command/commands.c | 16 +-- src/ui/console.c | 80 +++++++------- src/ui/core.c | 236 ++++++++++++++++++++--------------------- src/ui/window.c | 64 +++++------ src/ui/window.h | 2 +- 5 files changed, 199 insertions(+), 199 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index dd63b25f..4e0bde2c 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -1312,8 +1312,8 @@ cmd_msg(gchar **args, struct cmd_help_t help) } return TRUE; #else - message_send_chat(barejid, msg); - ui_outgoing_chat_msg("me", barejid, msg); + char *id = message_send_chat(barejid, msg); + ui_outgoing_chat_msg("me", barejid, msg, id); if (((win_type == WIN_CHAT) || (win_type == WIN_CONSOLE)) && prefs_get_boolean(PREF_CHLOG)) { const char *jid = jabber_get_fulljid(); @@ -1722,7 +1722,7 @@ cmd_status(gchar **args, struct cmd_help_t help) if (occupant) { win_show_occupant(window, occupant); } else { - win_save_vprint(window, '-', NULL, 0, 0, "", "No such participant \"%s\" in room.", usr); + win_vprint(window, '-', NULL, 0, 0, "", "No such participant \"%s\" in room.", usr); } } else { ui_current_print_line("You must specify a nickname."); @@ -2449,7 +2449,7 @@ cmd_kick(gchar **args, struct cmd_help_t help) char *reason = args[1]; iq_room_kick_occupant(mucwin->roomjid, nick, reason); } else { - win_save_vprint((ProfWin*) mucwin, '!', NULL, 0, 0, "", "Occupant does not exist: %s", nick); + win_vprint((ProfWin*) mucwin, '!', NULL, 0, 0, "", "Occupant does not exist: %s", nick); } } else { cons_show("Usage: %s", help.usage); @@ -2508,8 +2508,8 @@ cmd_subject(gchar **args, struct cmd_help_t help) if (args[0] == NULL) { char *subject = muc_subject(mucwin->roomjid); if (subject) { - win_save_vprint(window, '!', NULL, NO_EOL, THEME_ROOMINFO, "", "Room subject: "); - win_save_vprint(window, '!', NULL, NO_DATE, 0, "", "%s", subject); + win_vprint(window, '!', NULL, NO_EOL, THEME_ROOMINFO, "", "Room subject: "); + win_vprint(window, '!', NULL, NO_DATE, 0, "", "%s", subject); } else { win_save_print(window, '!', NULL, 0, THEME_ROOMINFO, "", "Room has no subject"); } @@ -3105,7 +3105,7 @@ cmd_tiny(gchar **args, struct cmd_help_t help) ui_outgoing_chat_msg("me", chatwin->barejid, tiny, id); } #else - message_send_chat(chatwin->barejid, tiny); + char *id = message_send_chat(chatwin->barejid, tiny); if (prefs_get_boolean(PREF_CHLOG)) { const char *jid = jabber_get_fulljid(); Jid *jidp = jid_create(jid); @@ -3113,7 +3113,7 @@ cmd_tiny(gchar **args, struct cmd_help_t help) jid_destroy(jidp); } - ui_outgoing_chat_msg("me", chatwin->barejid, tiny); + ui_outgoing_chat_msg("me", chatwin->barejid, tiny, id); #endif } else if (win_type == WIN_PRIVATE) { ProfPrivateWin *privatewin = wins_get_current_private(); diff --git a/src/ui/console.c b/src/ui/console.c index dc8a3c7b..b7c86df2 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -136,7 +136,7 @@ cons_show_typing(const char * const barejid) display_usr = barejid; } - win_save_vprint(console, '-', NULL, 0, THEME_TYPING, "", "!! %s is typing a message...", display_usr); + win_vprint(console, '-', NULL, 0, THEME_TYPING, "", "!! %s is typing a message...", display_usr); cons_alert(); } @@ -149,7 +149,7 @@ cons_show_incoming_message(const char * const short_from, const int win_index) if (ui_index == 10) { ui_index = 0; } - win_save_vprint(console, '-', NULL, 0, THEME_INCOMING, "", "<< incoming from %s (%d)", short_from, ui_index); + win_vprint(console, '-', NULL, 0, THEME_INCOMING, "", "<< incoming from %s (%d)", short_from, ui_index); cons_alert(); } @@ -167,16 +167,16 @@ cons_about(void) if (strcmp(PACKAGE_STATUS, "development") == 0) { #ifdef HAVE_GIT_VERSION - win_save_vprint(console, '-', NULL, 0, 0, "", "Welcome to Profanity, version %sdev.%s.%s", PACKAGE_VERSION, PROF_GIT_BRANCH, PROF_GIT_REVISION); + win_vprint(console, '-', NULL, 0, 0, "", "Welcome to Profanity, version %sdev.%s.%s", PACKAGE_VERSION, PROF_GIT_BRANCH, PROF_GIT_REVISION); #else - win_save_vprint(console, '-', NULL, 0, 0, "", "Welcome to Profanity, version %sdev", PACKAGE_VERSION); + win_vprint(console, '-', NULL, 0, 0, "", "Welcome to Profanity, version %sdev", PACKAGE_VERSION); #endif } else { - win_save_vprint(console, '-', NULL, 0, 0, "", "Welcome to Profanity, version %s", PACKAGE_VERSION); + win_vprint(console, '-', NULL, 0, 0, "", "Welcome to Profanity, version %s", PACKAGE_VERSION); } } - win_save_vprint(console, '-', NULL, 0, 0, "", "Copyright (C) 2012 - 2015 James Booth <%s>.", PACKAGE_BUGREPORT); + win_vprint(console, '-', NULL, 0, 0, "", "Copyright (C) 2012 - 2015 James Booth <%s>.", PACKAGE_BUGREPORT); win_save_println(console, "License GPLv3+: GNU GPL version 3 or later "); win_save_println(console, ""); win_save_println(console, "This is free software; you are free to change and redistribute it."); @@ -205,7 +205,7 @@ cons_check_version(gboolean not_available_msg) if (relase_valid) { if (release_is_new(latest_release)) { - win_save_vprint(console, '-', NULL, 0, 0, "", "A new version of Profanity is available: %s", latest_release); + win_vprint(console, '-', NULL, 0, 0, "", "A new version of Profanity is available: %s", latest_release); win_save_println(console, "Check for details."); win_save_println(console, ""); } else { @@ -225,14 +225,14 @@ void cons_show_login_success(ProfAccount *account) { ProfWin *console = wins_get_console(); - win_save_vprint(console, '-', NULL, NO_EOL, 0, "", "%s logged in successfully, ", account->jid); + win_vprint(console, '-', NULL, NO_EOL, 0, "", "%s logged in successfully, ", account->jid); resource_presence_t presence = accounts_get_login_presence(account->name); const char *presence_str = string_from_resource_presence(presence); theme_item_t presence_colour = theme_main_presence_attrs(presence_str); - win_save_vprint(console, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", "%s", presence_str); - win_save_vprint(console, '-', NULL, NO_DATE | NO_EOL, 0, "", " (priority %d)", + win_vprint(console, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", "%s", presence_str); + win_vprint(console, '-', NULL, NO_DATE | NO_EOL, 0, "", " (priority %d)", accounts_get_priority_for_presence_type(account->name, presence)); win_save_print(console, '-', NULL, NO_DATE, 0, "", "."); cons_alert(); @@ -294,7 +294,7 @@ cons_show_caps(const char * const fulljid, resource_presence_t presence) const char *resource_presence = string_from_resource_presence(presence); theme_item_t presence_colour = theme_main_presence_attrs(resource_presence); - win_save_vprint(console, '-', NULL, NO_EOL, presence_colour, "", "%s", fulljid); + win_vprint(console, '-', NULL, NO_EOL, presence_colour, "", "%s", fulljid); win_save_print(console, '-', NULL, NO_DATE, 0, "", ":"); // show identity @@ -318,19 +318,19 @@ cons_show_caps(const char * const fulljid, resource_presence_t presence) win_save_newline(console); } if (caps->software != NULL) { - win_save_vprint(console, '-', NULL, NO_EOL, 0, "", "Software: %s", caps->software); + win_vprint(console, '-', NULL, NO_EOL, 0, "", "Software: %s", caps->software); } if (caps->software_version != NULL) { - win_save_vprint(console, '-', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->software_version); + win_vprint(console, '-', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->software_version); } if ((caps->software != NULL) || (caps->software_version != NULL)) { win_save_newline(console); } if (caps->os != NULL) { - win_save_vprint(console, '-', NULL, NO_EOL, 0, "", "OS: %s", caps->os); + win_vprint(console, '-', NULL, NO_EOL, 0, "", "OS: %s", caps->os); } if (caps->os_version != NULL) { - win_save_vprint(console, '-', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->os_version); + win_vprint(console, '-', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->os_version); } if ((caps->os != NULL) || (caps->os_version != NULL)) { win_save_newline(console); @@ -340,7 +340,7 @@ cons_show_caps(const char * const fulljid, resource_presence_t presence) win_save_println(console, "Features:"); GSList *feature = caps->features; while (feature != NULL) { - win_save_vprint(console, '-', NULL, 0, 0, "", " %s", feature->data); + win_vprint(console, '-', NULL, 0, 0, "", " %s", feature->data); feature = g_slist_next(feature); } } @@ -361,7 +361,7 @@ cons_show_software_version(const char * const jid, const char * const presence, if ((name != NULL) || (version != NULL) || (os != NULL)) { cons_show(""); theme_item_t presence_colour = theme_main_presence_attrs(presence); - win_save_vprint(console, '-', NULL, NO_EOL, presence_colour, "", "%s", jid); + win_vprint(console, '-', NULL, NO_EOL, presence_colour, "", "%s", jid); win_save_print(console, '-', NULL, NO_DATE, 0, "", ":"); } if (name != NULL) { @@ -426,9 +426,9 @@ cons_show_room_list(GSList *rooms, const char * const conference_node) cons_show("Chat rooms at %s:", conference_node); while (rooms != NULL) { DiscoItem *room = rooms->data; - win_save_vprint(console, '-', NULL, NO_EOL, 0, "", " %s", room->jid); + win_vprint(console, '-', NULL, NO_EOL, 0, "", " %s", room->jid); if (room->name != NULL) { - win_save_vprint(console, '-', NULL, NO_DATE | NO_EOL, 0, "", ", (%s)", room->name); + win_vprint(console, '-', NULL, NO_DATE | NO_EOL, 0, "", ", (%s)", room->name); } win_save_newline(console); rooms = g_slist_next(rooms); @@ -460,9 +460,9 @@ cons_show_bookmarks(const GList *list) if (muc_active(item->jid)) { presence_colour = THEME_ONLINE; } - win_save_vprint(console, '-', NULL, NO_EOL, presence_colour, "", " %s", item->jid); + win_vprint(console, '-', NULL, NO_EOL, presence_colour, "", " %s", item->jid); if (item->nick != NULL) { - win_save_vprint(console, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", "/%s", item->nick); + win_vprint(console, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", "/%s", item->nick); } if (item->autojoin) { win_save_print(console, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " (autojoin)"); @@ -474,7 +474,7 @@ cons_show_bookmarks(const GList *list) ProfWin *roomwin = (ProfWin*)wins_get_muc(item->jid); if (roomwin != NULL) { int num = wins_get_num(roomwin); - win_save_vprint(console, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " (%d)", num); + win_vprint(console, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " (%d)", num); } } win_save_newline(console); @@ -535,11 +535,11 @@ cons_show_disco_items(GSList *items, const char * const jid) cons_show("Service discovery items for %s:", jid); while (items != NULL) { DiscoItem *item = items->data; - win_save_vprint(console, '-', NULL, NO_EOL, 0, "", " %s", item->jid); + win_vprint(console, '-', NULL, NO_EOL, 0, "", " %s", item->jid); if (item->name != NULL) { - win_save_vprint(console, '-', NULL, NO_DATE | NO_EOL, 0, "", ", (%s)", item->name); + win_vprint(console, '-', NULL, NO_DATE | NO_EOL, 0, "", ", (%s)", item->name); } - win_save_vprint(console, '-', NULL, NO_DATE, 0, "", ""); + win_vprint(console, '-', NULL, NO_DATE, 0, "", ""); items = g_slist_next(items); } } else { @@ -614,7 +614,7 @@ cons_show_account_list(gchar **accounts) (g_strcmp0(jabber_get_account_name(), accounts[i]) == 0)) { resource_presence_t presence = accounts_get_last_presence(accounts[i]); theme_item_t presence_colour = theme_main_presence_attrs(string_from_resource_presence(presence)); - win_save_vprint(console, '-', NULL, 0, presence_colour, "", "%s", accounts[i]); + win_vprint(console, '-', NULL, 0, presence_colour, "", "%s", accounts[i]); } else { cons_show(accounts[i]); } @@ -739,12 +739,12 @@ cons_show_account(ProfAccount *account) Resource *resource = curr->data; const char *resource_presence = string_from_resource_presence(resource->presence); theme_item_t presence_colour = theme_main_presence_attrs(resource_presence); - win_save_vprint(console, '-', NULL, NO_EOL, presence_colour, "", " %s (%d), %s", resource->name, resource->priority, resource_presence); + win_vprint(console, '-', NULL, NO_EOL, presence_colour, "", " %s (%d), %s", resource->name, resource->priority, resource_presence); if (resource->status != NULL) { - win_save_vprint(console, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", resource->status); + win_vprint(console, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", resource->status); } - win_save_vprint(console, '-', NULL, NO_DATE, 0, "", ""); + win_vprint(console, '-', NULL, NO_DATE, 0, "", ""); Jid *jidp = jid_create_from_bare_and_resource(account->jid, resource->name); Capabilities *caps = caps_lookup(jidp->fulljid); jid_destroy(jidp); @@ -771,19 +771,19 @@ cons_show_account(ProfAccount *account) win_save_newline(console); } if (caps->software != NULL) { - win_save_vprint(console, '-', NULL, NO_EOL, 0, "", " Software: %s", caps->software); + win_vprint(console, '-', NULL, NO_EOL, 0, "", " Software: %s", caps->software); } if (caps->software_version != NULL) { - win_save_vprint(console, '-', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->software_version); + win_vprint(console, '-', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->software_version); } if ((caps->software != NULL) || (caps->software_version != NULL)) { win_save_newline(console); } if (caps->os != NULL) { - win_save_vprint(console, '-', NULL, NO_EOL, 0, "", " OS: %s", caps->os); + win_vprint(console, '-', NULL, NO_EOL, 0, "", " OS: %s", caps->os); } if (caps->os_version != NULL) { - win_save_vprint(console, '-', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->os_version); + win_vprint(console, '-', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->os_version); } if ((caps->os != NULL) || (caps->os_version != NULL)) { win_save_newline(console); @@ -1587,12 +1587,12 @@ _cons_splash_logo(void) if (strcmp(PACKAGE_STATUS, "development") == 0) { #ifdef HAVE_GIT_VERSION - win_save_vprint(console, '-', NULL, 0, 0, "", "Version %sdev.%s.%s", PACKAGE_VERSION, PROF_GIT_BRANCH, PROF_GIT_REVISION); + win_vprint(console, '-', NULL, 0, 0, "", "Version %sdev.%s.%s", PACKAGE_VERSION, PROF_GIT_BRANCH, PROF_GIT_REVISION); #else - win_save_vprint(console, '-', NULL, 0, 0, "", "Version %sdev", PACKAGE_VERSION); + win_vprint(console, '-', NULL, 0, 0, "", "Version %sdev", PACKAGE_VERSION); #endif } else { - win_save_vprint(console, '-', NULL, 0, 0, "", "Version %s", PACKAGE_VERSION); + win_vprint(console, '-', NULL, 0, 0, "", "Version %s", PACKAGE_VERSION); } } @@ -1619,7 +1619,7 @@ _show_roster_contacts(GSList *list, gboolean show_groups) } else { presence_colour = theme_main_presence_attrs("offline"); } - win_save_vprint(console, '-', NULL, NO_EOL, presence_colour, "", title->str); + win_vprint(console, '-', NULL, NO_EOL, presence_colour, "", title->str); g_string_free(title, TRUE); @@ -1639,9 +1639,9 @@ _show_roster_contacts(GSList *list, gboolean show_groups) } if (show_groups) { - win_save_vprint(console, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", "%s", sub->str); + win_vprint(console, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", "%s", sub->str); } else { - win_save_vprint(console, '-', NULL, NO_DATE, presence_colour, "", "%s", sub->str); + win_vprint(console, '-', NULL, NO_DATE, presence_colour, "", "%s", sub->str); } g_string_free(sub, TRUE); @@ -1657,7 +1657,7 @@ _show_roster_contacts(GSList *list, gboolean show_groups) } groups = g_slist_next(groups); } - win_save_vprint(console, '-', NULL, NO_DATE, 0, "", "%s", groups_str->str); + win_vprint(console, '-', NULL, NO_DATE, 0, "", "%s", groups_str->str); g_string_free(groups_str, TRUE); } else { win_save_print(console, '-', NULL, NO_DATE, 0, "", " "); diff --git a/src/ui/core.c b/src/ui/core.c index f43fb2a4..c5f7ea62 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -662,7 +662,7 @@ ui_handle_recipient_not_found(const char * const recipient, const char * const e ProfMucWin *mucwin = wins_get_muc(recipient); if (mucwin) { cons_show_error("Room %s not found: %s", recipient, err_msg); - win_save_vprint((ProfWin*) mucwin, '!', NULL, 0, THEME_ERROR, "", "Room %s not found: %s", recipient, err_msg); + win_vprint((ProfWin*) mucwin, '!', NULL, 0, THEME_ERROR, "", "Room %s not found: %s", recipient, err_msg); return; } } @@ -675,19 +675,19 @@ ui_handle_recipient_error(const char * const recipient, const char * const err_m ProfChatWin *chatwin = wins_get_chat(recipient); if (chatwin) { - win_save_vprint((ProfWin*)chatwin, '!', NULL, 0, THEME_ERROR, "", "Error from %s: %s", recipient, err_msg); + win_vprint((ProfWin*)chatwin, '!', NULL, 0, THEME_ERROR, "", "Error from %s: %s", recipient, err_msg); return; } ProfMucWin *mucwin = wins_get_muc(recipient); if (mucwin) { - win_save_vprint((ProfWin*)mucwin, '!', NULL, 0, THEME_ERROR, "", "Error from %s: %s", recipient, err_msg); + win_vprint((ProfWin*)mucwin, '!', NULL, 0, THEME_ERROR, "", "Error from %s: %s", recipient, err_msg); return; } ProfPrivateWin *privatewin = wins_get_private(recipient); if (privatewin) { - win_save_vprint((ProfWin*)privatewin, '!', NULL, 0, THEME_ERROR, "", "Error from %s: %s", recipient, err_msg); + win_vprint((ProfWin*)privatewin, '!', NULL, 0, THEME_ERROR, "", "Error from %s: %s", recipient, err_msg); return; } } @@ -1033,7 +1033,7 @@ ui_smp_recipient_initiated(const char * const barejid) { ProfChatWin *chatwin = wins_get_chat(barejid); if (chatwin) { - win_save_vprint((ProfWin*)chatwin, '!', NULL, 0, 0, "", "%s wants to authenticate your identity, use '/otr secret '.", barejid); + win_vprint((ProfWin*)chatwin, '!', NULL, 0, 0, "", "%s wants to authenticate your identity, use '/otr secret '.", barejid); } } @@ -1042,8 +1042,8 @@ ui_smp_recipient_initiated_q(const char * const barejid, const char *question) { ProfChatWin *chatwin = wins_get_chat(barejid); if (chatwin) { - win_save_vprint((ProfWin*)chatwin, '!', NULL, 0, 0, "", "%s wants to authenticate your identity with the following question:", barejid); - win_save_vprint((ProfWin*)chatwin, '!', NULL, 0, 0, "", " %s", question); + win_vprint((ProfWin*)chatwin, '!', NULL, 0, 0, "", "%s wants to authenticate your identity with the following question:", barejid); + win_vprint((ProfWin*)chatwin, '!', NULL, 0, 0, "", " %s", question); win_save_print((ProfWin*)chatwin, '!', NULL, 0, 0, "", "use '/otr answer '."); } } @@ -1053,7 +1053,7 @@ ui_smp_unsuccessful_sender(const char * const barejid) { ProfChatWin *chatwin = wins_get_chat(barejid); if (chatwin) { - win_save_vprint((ProfWin*)chatwin, '!', NULL, 0, 0, "", "Authentication failed, the secret you entered does not match the secret entered by %s.", barejid); + win_vprint((ProfWin*)chatwin, '!', NULL, 0, 0, "", "Authentication failed, the secret you entered does not match the secret entered by %s.", barejid); } } @@ -1062,7 +1062,7 @@ ui_smp_unsuccessful_receiver(const char * const barejid) { ProfChatWin *chatwin = wins_get_chat(barejid); if (chatwin) { - win_save_vprint((ProfWin*)chatwin, '!', NULL, 0, 0, "", "Authentication failed, the secret entered by %s does not match yours.", barejid); + win_vprint((ProfWin*)chatwin, '!', NULL, 0, 0, "", "Authentication failed, the secret entered by %s does not match yours.", barejid); } } @@ -1089,7 +1089,7 @@ ui_smp_answer_success(const char * const barejid) { ProfChatWin *chatwin = wins_get_chat(barejid); if (chatwin) { - win_save_vprint((ProfWin*)chatwin, '!', NULL, 0, 0, "", "%s successfully authenticated you.", barejid); + win_vprint((ProfWin*)chatwin, '!', NULL, 0, 0, "", "%s successfully authenticated you.", barejid); } } @@ -1098,7 +1098,7 @@ ui_smp_answer_failure(const char * const barejid) { ProfChatWin *chatwin = wins_get_chat(barejid); if (chatwin) { - win_save_vprint((ProfWin*)chatwin, '!', NULL, 0, 0, "", "%s failed to authenticate you.", barejid); + win_vprint((ProfWin*)chatwin, '!', NULL, 0, 0, "", "%s failed to authenticate you.", barejid); } } @@ -1107,7 +1107,7 @@ ui_otr_authenticating(const char * const barejid) { ProfChatWin *chatwin = wins_get_chat(barejid); if (chatwin) { - win_save_vprint((ProfWin*)chatwin, '!', NULL, 0, 0, "", "Authenticating %s...", barejid); + win_vprint((ProfWin*)chatwin, '!', NULL, 0, 0, "", "Authenticating %s...", barejid); } } @@ -1116,7 +1116,7 @@ ui_otr_authetication_waiting(const char * const barejid) { ProfChatWin *chatwin = wins_get_chat(barejid); if (chatwin) { - win_save_vprint((ProfWin*)chatwin, '!', NULL, 0, 0, "", "Awaiting authentication from %s...", barejid); + win_vprint((ProfWin*)chatwin, '!', NULL, 0, 0, "", "Awaiting authentication from %s...", barejid); } } @@ -1318,7 +1318,7 @@ ui_print_system_msg_from_recipient(const char * const barejid, const char *messa } } - win_save_vprint(window, '-', NULL, 0, 0, "", "*%s %s", barejid, message); + win_vprint(window, '-', NULL, 0, 0, "", "*%s %s", barejid, message); } void @@ -1350,7 +1350,7 @@ ui_recipient_gone(const char * const barejid, const char * const resource) display_usr = barejid; } - win_save_vprint((ProfWin*)chatwin, '!', NULL, 0, THEME_GONE, "", "<- %s has left the conversation.", display_usr); + win_vprint((ProfWin*)chatwin, '!', NULL, 0, THEME_GONE, "", "<- %s has left the conversation.", display_usr); } } } @@ -1506,15 +1506,15 @@ ui_room_join(const char * const roomjid, gboolean focus) } char *nick = muc_nick(roomjid); - win_save_vprint(window, '!', NULL, NO_EOL, THEME_ROOMINFO, "", "-> You have joined the room as %s", nick); + win_vprint(window, '!', NULL, NO_EOL, THEME_ROOMINFO, "", "-> You have joined the room as %s", nick); if (prefs_get_boolean(PREF_MUC_PRIVILEGES)) { char *role = muc_role_str(roomjid); char *affiliation = muc_affiliation_str(roomjid); if (role) { - win_save_vprint(window, '!', NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", role: %s", role); + win_vprint(window, '!', NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", role: %s", role); } if (affiliation) { - win_save_vprint(window, '!', NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", affiliation: %s", affiliation); + win_vprint(window, '!', NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", affiliation: %s", affiliation); } } win_save_print(window, '!', NULL, NO_DATE, THEME_ROOMINFO, "", ""); @@ -1527,7 +1527,7 @@ ui_room_join(const char * const roomjid, gboolean focus) status_bar_active(num); ProfWin *console = wins_get_console(); char *nick = muc_nick(roomjid); - win_save_vprint(console, '!', NULL, 0, THEME_TYPING, "", "-> Autojoined %s as %s (%d).", roomjid, nick, num); + win_vprint(console, '!', NULL, 0, THEME_TYPING, "", "-> Autojoined %s as %s (%d).", roomjid, nick, num); } } @@ -1545,12 +1545,12 @@ ui_room_role_change(const char * const roomjid, const char * const role, const c const char * const reason) { ProfWin *window = (ProfWin*)wins_get_muc(roomjid); - win_save_vprint(window, '!', NULL, NO_EOL, THEME_ROOMINFO, "", "Your role has been changed to: %s", role); + win_vprint(window, '!', NULL, NO_EOL, THEME_ROOMINFO, "", "Your role has been changed to: %s", role); if (actor) { - win_save_vprint(window, '!', NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", by: %s", actor); + win_vprint(window, '!', NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", by: %s", actor); } if (reason) { - win_save_vprint(window, '!', NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", reason: %s", reason); + win_vprint(window, '!', NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", reason: %s", reason); } win_save_print(window, '!', NULL, NO_DATE, THEME_ROOMINFO, "", ""); } @@ -1560,12 +1560,12 @@ ui_room_affiliation_change(const char * const roomjid, const char * const affili const char * const reason) { ProfWin *window = (ProfWin*)wins_get_muc(roomjid); - win_save_vprint(window, '!', NULL, NO_EOL, THEME_ROOMINFO, "", "Your affiliation has been changed to: %s", affiliation); + win_vprint(window, '!', NULL, NO_EOL, THEME_ROOMINFO, "", "Your affiliation has been changed to: %s", affiliation); if (actor) { - win_save_vprint(window, '!', NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", by: %s", actor); + win_vprint(window, '!', NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", by: %s", actor); } if (reason) { - win_save_vprint(window, '!', NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", reason: %s", reason); + win_vprint(window, '!', NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", reason: %s", reason); } win_save_print(window, '!', NULL, NO_DATE, THEME_ROOMINFO, "", ""); } @@ -1575,12 +1575,12 @@ ui_room_role_and_affiliation_change(const char * const roomjid, const char * con const char * const actor, const char * const reason) { ProfWin *window = (ProfWin*)wins_get_muc(roomjid); - win_save_vprint(window, '!', NULL, NO_EOL, THEME_ROOMINFO, "", "Your role and affiliation have been changed, role: %s, affiliation: %s", role, affiliation); + win_vprint(window, '!', NULL, NO_EOL, THEME_ROOMINFO, "", "Your role and affiliation have been changed, role: %s, affiliation: %s", role, affiliation); if (actor) { - win_save_vprint(window, '!', NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", by: %s", actor); + win_vprint(window, '!', NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", by: %s", actor); } if (reason) { - win_save_vprint(window, '!', NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", reason: %s", reason); + win_vprint(window, '!', NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", reason: %s", reason); } win_save_print(window, '!', NULL, NO_DATE, THEME_ROOMINFO, "", ""); } @@ -1591,12 +1591,12 @@ ui_room_occupant_role_change(const char * const roomjid, const char * const nick const char * const actor, const char * const reason) { ProfWin *window = (ProfWin*)wins_get_muc(roomjid); - win_save_vprint(window, '!', NULL, NO_EOL, THEME_ROOMINFO, "", "%s's role has been changed to: %s", nick, role); + win_vprint(window, '!', NULL, NO_EOL, THEME_ROOMINFO, "", "%s's role has been changed to: %s", nick, role); if (actor) { - win_save_vprint(window, '!', NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", by: %s", actor); + win_vprint(window, '!', NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", by: %s", actor); } if (reason) { - win_save_vprint(window, '!', NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", reason: %s", reason); + win_vprint(window, '!', NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", reason: %s", reason); } win_save_print(window, '!', NULL, NO_DATE, THEME_ROOMINFO, "", ""); } @@ -1606,12 +1606,12 @@ ui_room_occupant_affiliation_change(const char * const roomjid, const char * con const char * const actor, const char * const reason) { ProfWin *window = (ProfWin*)wins_get_muc(roomjid); - win_save_vprint(window, '!', NULL, NO_EOL, THEME_ROOMINFO, "", "%s's affiliation has been changed to: %s", nick, affiliation); + win_vprint(window, '!', NULL, NO_EOL, THEME_ROOMINFO, "", "%s's affiliation has been changed to: %s", nick, affiliation); if (actor) { - win_save_vprint(window, '!', NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", by: %s", actor); + win_vprint(window, '!', NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", by: %s", actor); } if (reason) { - win_save_vprint(window, '!', NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", reason: %s", reason); + win_vprint(window, '!', NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", reason: %s", reason); } win_save_print(window, '!', NULL, NO_DATE, THEME_ROOMINFO, "", ""); } @@ -1621,12 +1621,12 @@ ui_room_occupant_role_and_affiliation_change(const char * const roomjid, const c const char * const affiliation, const char * const actor, const char * const reason) { ProfWin *window = (ProfWin*)wins_get_muc(roomjid); - win_save_vprint(window, '!', NULL, NO_EOL, THEME_ROOMINFO, "", "%s's role and affiliation have been changed, role: %s, affiliation: %s", nick, role, affiliation); + win_vprint(window, '!', NULL, NO_EOL, THEME_ROOMINFO, "", "%s's role and affiliation have been changed, role: %s, affiliation: %s", nick, role, affiliation); if (actor) { - win_save_vprint(window, '!', NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", by: %s", actor); + win_vprint(window, '!', NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", by: %s", actor); } if (reason) { - win_save_vprint(window, '!', NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", reason: %s", reason); + win_vprint(window, '!', NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", reason: %s", reason); } win_save_print(window, '!', NULL, NO_DATE, THEME_ROOMINFO, "", ""); } @@ -1636,7 +1636,7 @@ ui_handle_room_info_error(const char * const roomjid, const char * const error) { ProfWin *window = (ProfWin*)wins_get_muc(roomjid); if (window) { - win_save_vprint(window, '!', NULL, 0, 0, "", "Room info request failed: %s", error); + win_vprint(window, '!', NULL, 0, 0, "", "Room info request failed: %s", error); win_save_print(window, '-', NULL, 0, 0, "", ""); } } @@ -1674,7 +1674,7 @@ ui_show_room_disco_info(const char * const roomjid, GSList *identities, GSList * win_save_print(window, '!', NULL, 0, 0, "", "Features:"); } while (features != NULL) { - win_save_vprint(window, '!', NULL, 0, 0, "", " %s", features->data); + win_vprint(window, '!', NULL, 0, 0, "", " %s", features->data); features = g_slist_next(features); } win_save_print(window, '-', NULL, 0, 0, "", ""); @@ -1693,14 +1693,14 @@ ui_room_roster(const char * const roomjid, GList *roster, const char * const pre if (presence == NULL) { win_save_print(window, '!', NULL, 0, THEME_ROOMINFO, "", "Room is empty."); } else { - win_save_vprint(window, '!', NULL, 0, THEME_ROOMINFO, "", "No occupants %s.", presence); + win_vprint(window, '!', NULL, 0, THEME_ROOMINFO, "", "No occupants %s.", presence); } } else { int length = g_list_length(roster); if (presence == NULL) { - win_save_vprint(window, '!', NULL, NO_EOL, THEME_ROOMINFO, "", "%d occupants: ", length); + win_vprint(window, '!', NULL, NO_EOL, THEME_ROOMINFO, "", "%d occupants: ", length); } else { - win_save_vprint(window, '!', NULL, NO_EOL, THEME_ROOMINFO, "", "%d %s: ", length, presence); + win_vprint(window, '!', NULL, NO_EOL, THEME_ROOMINFO, "", "%d %s: ", length, presence); } while (roster != NULL) { @@ -1708,7 +1708,7 @@ ui_room_roster(const char * const roomjid, GList *roster, const char * const pre const char *presence_str = string_from_resource_presence(occupant->presence); theme_item_t presence_colour = theme_main_presence_attrs(presence_str); - win_save_vprint(window, '!', NULL, NO_DATE | NO_EOL, presence_colour, "", "%s", occupant->nick); + win_vprint(window, '!', NULL, NO_DATE | NO_EOL, presence_colour, "", "%s", occupant->nick); if (roster->next != NULL) { win_save_print(window, '!', NULL, NO_DATE | NO_EOL, 0, "", ", "); @@ -1735,7 +1735,7 @@ ui_room_member_offline(const char * const roomjid, const char * const nick) if (window == NULL) { log_error("Received offline presence for room participant %s, but no window open for %s.", nick, roomjid); } else { - win_save_vprint(window, '!', NULL, 0, THEME_OFFLINE, "", "<- %s has left the room.", nick); + win_vprint(window, '!', NULL, 0, THEME_OFFLINE, "", "<- %s has left the room.", nick); } } @@ -1758,7 +1758,7 @@ ui_room_member_kicked(const char * const roomjid, const char * const nick, const g_string_append(message, reason); } - win_save_vprint(window, '!', NULL, 0, THEME_OFFLINE, "", "<- %s", message->str); + win_vprint(window, '!', NULL, 0, THEME_OFFLINE, "", "<- %s", message->str); g_string_free(message, TRUE); } } @@ -1782,7 +1782,7 @@ ui_room_member_banned(const char * const roomjid, const char * const nick, const g_string_append(message, reason); } - win_save_vprint(window, '!', NULL, 0, THEME_OFFLINE, "", "<- %s", message->str); + win_vprint(window, '!', NULL, 0, THEME_OFFLINE, "", "<- %s", message->str); g_string_free(message, TRUE); } } @@ -1795,13 +1795,13 @@ ui_room_member_online(const char * const roomjid, const char * const nick, const if (window == NULL) { log_error("Received online presence for room participant %s, but no window open for %s.", nick, roomjid); } else { - win_save_vprint(window, '!', NULL, NO_EOL, THEME_ONLINE, "", "-> %s has joined the room", nick); + win_vprint(window, '!', NULL, NO_EOL, THEME_ONLINE, "", "-> %s has joined the room", nick); if (prefs_get_boolean(PREF_MUC_PRIVILEGES)) { if (role) { - win_save_vprint(window, '!', NULL, NO_DATE | NO_EOL, THEME_ONLINE, "", ", role: %s", role); + win_vprint(window, '!', NULL, NO_DATE | NO_EOL, THEME_ONLINE, "", ", role: %s", role); } if (affiliation) { - win_save_vprint(window, '!', NULL, NO_DATE | NO_EOL, THEME_ONLINE, "", ", affiliation: %s", affiliation); + win_vprint(window, '!', NULL, NO_DATE | NO_EOL, THEME_ONLINE, "", ", affiliation: %s", affiliation); } } win_save_print(window, '!', NULL, NO_DATE, THEME_ROOMINFO, "", ""); @@ -1828,7 +1828,7 @@ ui_room_member_nick_change(const char * const roomjid, if (window == NULL) { log_error("Received nick change for room participant %s, but no window open for %s.", old_nick, roomjid); } else { - win_save_vprint(window, '!', NULL, 0, THEME_THEM, "", "** %s is now known as %s", old_nick, nick); + win_vprint(window, '!', NULL, 0, THEME_THEM, "", "** %s is now known as %s", old_nick, nick); } } @@ -1839,7 +1839,7 @@ ui_room_nick_change(const char * const roomjid, const char * const nick) if (window == NULL) { log_error("Received self nick change %s, but no window open for %s.", nick, roomjid); } else { - win_save_vprint(window, '!', NULL, 0, THEME_ME, "", "** You are now known as %s", nick); + win_vprint(window, '!', NULL, 0, THEME_ME, "", "** You are now known as %s", nick); } } @@ -1965,13 +1965,13 @@ ui_room_requires_config(const char * const roomjid) } win_save_print(window, '-', NULL, 0, 0, "", ""); - win_save_vprint(window, '!', NULL, 0, THEME_ROOMINFO, "", + win_vprint(window, '!', NULL, 0, THEME_ROOMINFO, "", "Room locked, requires configuration."); - win_save_vprint(window, '!', NULL, 0, THEME_ROOMINFO, "", + win_vprint(window, '!', NULL, 0, THEME_ROOMINFO, "", "Use '/room accept' to accept the defaults"); - win_save_vprint(window, '!', NULL, 0, THEME_ROOMINFO, "", + win_vprint(window, '!', NULL, 0, THEME_ROOMINFO, "", "Use '/room destroy' to cancel and destroy the room"); - win_save_vprint(window, '!', NULL, 0, THEME_ROOMINFO, "", + win_vprint(window, '!', NULL, 0, THEME_ROOMINFO, "", "Use '/room config' to edit the room configuration"); win_save_print(window, '-', NULL, 0, 0, "", ""); @@ -2022,16 +2022,16 @@ ui_room_destroyed(const char * const roomjid, const char * const reason, const c ProfWin *console = wins_get_console(); if (reason) { - win_save_vprint(console, '!', NULL, 0, THEME_TYPING, "", "<- Room destroyed: %s, reason: %s", roomjid, reason); + win_vprint(console, '!', NULL, 0, THEME_TYPING, "", "<- Room destroyed: %s, reason: %s", roomjid, reason); } else { - win_save_vprint(console, '!', NULL, 0, THEME_TYPING, "", "<- Room destroyed: %s", roomjid); + win_vprint(console, '!', NULL, 0, THEME_TYPING, "", "<- Room destroyed: %s", roomjid); } if (new_jid) { if (password) { - win_save_vprint(console, '!', NULL, 0, THEME_TYPING, "", "Replacement room: %s, password: %s", new_jid, password); + win_vprint(console, '!', NULL, 0, THEME_TYPING, "", "Replacement room: %s, password: %s", new_jid, password); } else { - win_save_vprint(console, '!', NULL, 0, THEME_TYPING, "", "Replacement room: %s", new_jid); + win_vprint(console, '!', NULL, 0, THEME_TYPING, "", "Replacement room: %s", new_jid); } } } @@ -2059,7 +2059,7 @@ ui_room_kicked(const char * const roomjid, const char * const actor, const char } ProfWin *console = wins_get_console(); - win_save_vprint(console, '!', NULL, 0, THEME_TYPING, "", "<- %s", message->str); + win_vprint(console, '!', NULL, 0, THEME_TYPING, "", "<- %s", message->str); g_string_free(message, TRUE); } } @@ -2086,7 +2086,7 @@ ui_room_banned(const char * const roomjid, const char * const actor, const char } ProfWin *console = wins_get_console(); - win_save_vprint(console, '!', NULL, 0, THEME_TYPING, "", "<- %s", message->str); + win_vprint(console, '!', NULL, 0, THEME_TYPING, "", "<- %s", message->str); g_string_free(message, TRUE); } } @@ -2102,17 +2102,17 @@ ui_room_subject(const char * const roomjid, const char * const nick, const char if (subject) { if (nick) { - win_save_vprint(window, '!', NULL, NO_EOL, THEME_ROOMINFO, "", "*%s has set the room subject: ", nick); - win_save_vprint(window, '!', NULL, NO_DATE, 0, "", "%s", subject); + win_vprint(window, '!', NULL, NO_EOL, THEME_ROOMINFO, "", "*%s has set the room subject: ", nick); + win_vprint(window, '!', NULL, NO_DATE, 0, "", "%s", subject); } else { - win_save_vprint(window, '!', NULL, NO_EOL, THEME_ROOMINFO, "", "Room subject: "); - win_save_vprint(window, '!', NULL, NO_DATE, 0, "", "%s", subject); + win_vprint(window, '!', NULL, NO_EOL, THEME_ROOMINFO, "", "Room subject: "); + win_vprint(window, '!', NULL, NO_DATE, 0, "", "%s", subject); } } else { if (nick) { - win_save_vprint(window, '!', NULL, 0, THEME_ROOMINFO, "", "*%s has cleared the room subject: ", nick); + win_vprint(window, '!', NULL, 0, THEME_ROOMINFO, "", "*%s has cleared the room subject: ", nick); } else { - win_save_vprint(window, '!', NULL, 0, THEME_ROOMINFO, "", "Room subject cleared"); + win_vprint(window, '!', NULL, 0, THEME_ROOMINFO, "", "Room subject cleared"); } } @@ -2134,7 +2134,7 @@ ui_handle_room_kick_error(const char * const roomjid, const char * const nick, c if (window == NULL) { log_error("Kick error received for %s, but no window open for %s.", nick, roomjid); } else { - win_save_vprint(window, '!', NULL, 0, THEME_ERROR, "", "Error kicking %s: %s", nick, error); + win_vprint(window, '!', NULL, 0, THEME_ERROR, "", "Error kicking %s: %s", nick, error); } } @@ -2147,8 +2147,8 @@ ui_room_broadcast(const char * const roomjid, const char * const message) } else { int num = wins_get_num(window); - win_save_vprint(window, '!', NULL, NO_EOL, THEME_ROOMINFO, "", "Room message: "); - win_save_vprint(window, '!', NULL, NO_DATE, 0, "", "%s", message); + win_vprint(window, '!', NULL, NO_EOL, THEME_ROOMINFO, "", "Room message: "); + win_vprint(window, '!', NULL, NO_DATE, 0, "", "%s", message); // currently in groupchat window if (wins_is_current(window)) { @@ -2167,7 +2167,7 @@ ui_handle_room_affiliation_list_error(const char * const roomjid, const char * c { ProfWin *window = (ProfWin*)wins_get_muc(roomjid); if (window) { - win_save_vprint(window, '!', NULL, 0, THEME_ERROR, "", "Error retrieving %s list: %s", affiliation, error); + win_vprint(window, '!', NULL, 0, THEME_ERROR, "", "Error retrieving %s list: %s", affiliation, error); } } @@ -2177,16 +2177,16 @@ ui_handle_room_affiliation_list(const char * const roomjid, const char * const a ProfWin *window = (ProfWin*)wins_get_muc(roomjid); if (window) { if (jids) { - win_save_vprint(window, '!', NULL, 0, 0, "", "Affiliation: %s", affiliation); + win_vprint(window, '!', NULL, 0, 0, "", "Affiliation: %s", affiliation); GSList *curr_jid = jids; while (curr_jid) { char *jid = curr_jid->data; - win_save_vprint(window, '!', NULL, 0, 0, "", " %s", jid); + win_vprint(window, '!', NULL, 0, 0, "", " %s", jid); curr_jid = g_slist_next(curr_jid); } win_save_print(window, '!', NULL, 0, 0, "", ""); } else { - win_save_vprint(window, '!', NULL, 0, 0, "", "No users found with affiliation: %s", affiliation); + win_vprint(window, '!', NULL, 0, 0, "", "No users found with affiliation: %s", affiliation); win_save_print(window, '!', NULL, 0, 0, "", ""); } } @@ -2197,7 +2197,7 @@ ui_handle_room_role_list_error(const char * const roomjid, const char * const ro { ProfWin *window = (ProfWin*)wins_get_muc(roomjid); if (window) { - win_save_vprint(window, '!', NULL, 0, THEME_ERROR, "", "Error retrieving %s list: %s", role, error); + win_vprint(window, '!', NULL, 0, THEME_ERROR, "", "Error retrieving %s list: %s", role, error); } } @@ -2207,25 +2207,25 @@ ui_handle_room_role_list(const char * const roomjid, const char * const role, GS ProfWin *window = (ProfWin*)wins_get_muc(roomjid); if (window) { if (nicks) { - win_save_vprint(window, '!', NULL, 0, 0, "", "Role: %s", role); + win_vprint(window, '!', NULL, 0, 0, "", "Role: %s", role); GSList *curr_nick = nicks; while (curr_nick) { char *nick = curr_nick->data; Occupant *occupant = muc_roster_item(roomjid, nick); if (occupant) { if (occupant->jid) { - win_save_vprint(window, '!', NULL, 0, 0, "", " %s (%s)", nick, occupant->jid); + win_vprint(window, '!', NULL, 0, 0, "", " %s (%s)", nick, occupant->jid); } else { - win_save_vprint(window, '!', NULL, 0, 0, "", " %s", nick); + win_vprint(window, '!', NULL, 0, 0, "", " %s", nick); } } else { - win_save_vprint(window, '!', NULL, 0, 0, "", " %s", nick); + win_vprint(window, '!', NULL, 0, 0, "", " %s", nick); } curr_nick = g_slist_next(curr_nick); } win_save_print(window, '!', NULL, 0, 0, "", ""); } else { - win_save_vprint(window, '!', NULL, 0, 0, "", "No occupants found with role: %s", role); + win_vprint(window, '!', NULL, 0, 0, "", "No occupants found with role: %s", role); win_save_print(window, '!', NULL, 0, 0, "", ""); } } @@ -2237,7 +2237,7 @@ ui_handle_room_affiliation_set_error(const char * const roomjid, const char * co { ProfWin *window = (ProfWin*)wins_get_muc(roomjid); if (window) { - win_save_vprint(window, '!', NULL, 0, THEME_ERROR, "", "Error setting %s affiliation for %s: %s", affiliation, jid, error); + win_vprint(window, '!', NULL, 0, THEME_ERROR, "", "Error setting %s affiliation for %s: %s", affiliation, jid, error); } } @@ -2247,7 +2247,7 @@ ui_handle_room_role_set_error(const char * const roomjid, const char * const nic { ProfWin *window = (ProfWin*)wins_get_muc(roomjid); if (window) { - win_save_vprint(window, '!', NULL, 0, THEME_ERROR, "", "Error setting %s role for %s: %s", role, nick, error); + win_vprint(window, '!', NULL, 0, THEME_ERROR, "", "Error setting %s role for %s: %s", role, nick, error); } } @@ -2410,9 +2410,9 @@ ui_show_room_info(ProfMucWin *mucwin) char *affiliation = muc_affiliation_str(mucwin->roomjid); ProfWin *window = (ProfWin*) mucwin; - win_save_vprint(window, '!', NULL, 0, 0, "", "Room: %s", mucwin->roomjid); - win_save_vprint(window, '!', NULL, 0, 0, "", "Affiliation: %s", affiliation); - win_save_vprint(window, '!', NULL, 0, 0, "", "Role: %s", role); + win_vprint(window, '!', NULL, 0, 0, "", "Room: %s", mucwin->roomjid); + win_vprint(window, '!', NULL, 0, 0, "", "Affiliation: %s", affiliation); + win_vprint(window, '!', NULL, 0, 0, "", "Role: %s", role); win_save_print(window, '-', NULL, 0, 0, "", ""); } @@ -2457,9 +2457,9 @@ ui_show_room_role_list(ProfMucWin *mucwin, muc_role_t role) Occupant *occupant = curr_occupant->data; if (occupant->role == role) { if (occupant->jid) { - win_save_vprint(window, '!', NULL, 0, 0, "", " %s (%s)", occupant->nick, occupant->jid); + win_vprint(window, '!', NULL, 0, 0, "", " %s (%s)", occupant->nick, occupant->jid); } else { - win_save_vprint(window, '!', NULL, 0, 0, "", " %s", occupant->nick); + win_vprint(window, '!', NULL, 0, 0, "", " %s", occupant->nick); } } @@ -2517,9 +2517,9 @@ ui_show_room_affiliation_list(ProfMucWin *mucwin, muc_affiliation_t affiliation) Occupant *occupant = curr_occupant->data; if (occupant->affiliation == affiliation) { if (occupant->jid) { - win_save_vprint(window, '!', NULL, 0, 0, "", " %s (%s)", occupant->nick, occupant->jid); + win_vprint(window, '!', NULL, 0, 0, "", " %s (%s)", occupant->nick, occupant->jid); } else { - win_save_vprint(window, '!', NULL, 0, 0, "", " %s", occupant->nick); + win_vprint(window, '!', NULL, 0, 0, "", " %s", occupant->nick); } } @@ -2533,8 +2533,8 @@ ui_show_room_affiliation_list(ProfMucWin *mucwin, muc_affiliation_t affiliation) static void _ui_handle_form_field(ProfWin *window, char *tag, FormField *field) { - win_save_vprint(window, '-', NULL, NO_EOL, THEME_AWAY, "", "[%s] ", tag); - win_save_vprint(window, '-', NULL, NO_EOL | NO_DATE, 0, "", "%s", field->label); + win_vprint(window, '-', NULL, NO_EOL, THEME_AWAY, "", "[%s] ", tag); + win_vprint(window, '-', NULL, NO_EOL | NO_DATE, 0, "", "%s", field->label); if (field->required) { win_save_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", " (required): "); } else { @@ -2576,7 +2576,7 @@ _ui_handle_form_field(ProfWin *window, char *tag, FormField *field) char *value = curr_value->data; GString *val_tag = g_string_new(""); g_string_printf(val_tag, "val%d", index++); - win_save_vprint(window, '-', NULL, 0, THEME_ONLINE, "", " [%s] %s", val_tag->str, value); + win_vprint(window, '-', NULL, 0, THEME_ONLINE, "", " [%s] %s", val_tag->str, value); g_string_free(val_tag, TRUE); curr_value = g_slist_next(curr_value); } @@ -2606,9 +2606,9 @@ _ui_handle_form_field(ProfWin *window, char *tag, FormField *field) while (curr_option != NULL) { FormOption *option = curr_option->data; if (g_strcmp0(option->value, value) == 0) { - win_save_vprint(window, '-', NULL, 0, THEME_ONLINE, "", " [%s] %s", option->value, option->label); + win_vprint(window, '-', NULL, 0, THEME_ONLINE, "", " [%s] %s", option->value, option->label); } else { - win_save_vprint(window, '-', NULL, 0, THEME_OFFLINE, "", " [%s] %s", option->value, option->label); + win_vprint(window, '-', NULL, 0, THEME_OFFLINE, "", " [%s] %s", option->value, option->label); } curr_option = g_slist_next(curr_option); } @@ -2622,9 +2622,9 @@ _ui_handle_form_field(ProfWin *window, char *tag, FormField *field) while (curr_option != NULL) { FormOption *option = curr_option->data; if (g_slist_find_custom(curr_value, option->value, (GCompareFunc)g_strcmp0) != NULL) { - win_save_vprint(window, '-', NULL, 0, THEME_ONLINE, "", " [%s] %s", option->value, option->label); + win_vprint(window, '-', NULL, 0, THEME_ONLINE, "", " [%s] %s", option->value, option->label); } else { - win_save_vprint(window, '-', NULL, 0, THEME_OFFLINE, "", " [%s] %s", option->value, option->label); + win_vprint(window, '-', NULL, 0, THEME_OFFLINE, "", " [%s] %s", option->value, option->label); } curr_option = g_slist_next(curr_option); } @@ -2643,7 +2643,7 @@ _ui_handle_form_field(ProfWin *window, char *tag, FormField *field) win_save_newline(window); while (curr_value != NULL) { char *value = curr_value->data; - win_save_vprint(window, '-', NULL, 0, THEME_ONLINE, "", " %s", value); + win_vprint(window, '-', NULL, 0, THEME_ONLINE, "", " %s", value); curr_value = g_slist_next(curr_value); } break; @@ -2669,7 +2669,7 @@ ui_show_form(ProfMucConfWin *confwin) win_save_print(window, '-', NULL, NO_EOL, 0, "", "Form title: "); win_save_print(window, '-', NULL, NO_DATE, 0, "", confwin->form->title); } else { - win_save_vprint(window, '-', NULL, 0, 0, "", "Configuration for room %s.", confwin->roomjid); + win_vprint(window, '-', NULL, 0, 0, "", "Configuration for room %s.", confwin->roomjid); } win_save_print(window, '-', NULL, 0, 0, "", ""); @@ -2795,21 +2795,21 @@ ui_handle_room_config_submit_result_error(const char * const roomjid, const char if (form_window) { if (message) { - win_save_vprint(form_window, '!', NULL, 0, THEME_ERROR, "", "Configuration error: %s", message); + win_vprint(form_window, '!', NULL, 0, THEME_ERROR, "", "Configuration error: %s", message); } else { win_save_print(form_window, '!', NULL, 0, THEME_ERROR, "", "Configuration error"); } } else if (muc_window) { if (message) { - win_save_vprint(muc_window, '!', NULL, 0, THEME_ERROR, "", "Configuration error: %s", message); + win_vprint(muc_window, '!', NULL, 0, THEME_ERROR, "", "Configuration error: %s", message); } else { win_save_print(muc_window, '!', NULL, 0, THEME_ERROR, "", "Configuration error"); } } else { if (message) { - win_save_vprint(console, '!', NULL, 0, THEME_ERROR, "", "Configuration error for %s: %s", roomjid, message); + win_vprint(console, '!', NULL, 0, THEME_ERROR, "", "Configuration error for %s: %s", roomjid, message); } else { - win_save_vprint(console, '!', NULL, 0, THEME_ERROR, "", "Configuration error for %s", roomjid); + win_vprint(console, '!', NULL, 0, THEME_ERROR, "", "Configuration error for %s", roomjid); } } } else { @@ -2830,9 +2830,9 @@ ui_show_form_field_help(ProfMucConfWin *confwin, char *tag) win_save_print(window, '-', NULL, NO_DATE, 0, "", ":"); } if (field->description != NULL) { - win_save_vprint(window, '-', NULL, 0, 0, "", " Description : %s", field->description); + win_vprint(window, '-', NULL, 0, 0, "", " Description : %s", field->description); } - win_save_vprint(window, '-', NULL, 0, 0, "", " Type : %s", field->type); + win_vprint(window, '-', NULL, 0, 0, "", " Type : %s", field->type); int num_values = 0; GSList *curr_option = NULL; @@ -2841,50 +2841,50 @@ ui_show_form_field_help(ProfMucConfWin *confwin, char *tag) switch (field->type_t) { case FIELD_TEXT_SINGLE: case FIELD_TEXT_PRIVATE: - win_save_vprint(window, '-', NULL, 0, 0, "", " Set : /%s ", tag); + win_vprint(window, '-', NULL, 0, 0, "", " Set : /%s ", tag); win_save_print(window, '-', NULL, 0, 0, "", " Where : is any text"); break; case FIELD_TEXT_MULTI: num_values = form_get_value_count(confwin->form, tag); - win_save_vprint(window, '-', NULL, 0, 0, "", " Add : /%s add ", tag); + win_vprint(window, '-', NULL, 0, 0, "", " Add : /%s add ", tag); win_save_print(window, '-', NULL, 0, 0, "", " Where : is any text"); if (num_values > 0) { - win_save_vprint(window, '-', NULL, 0, 0, "", " Remove : /%s remove ", tag); - win_save_vprint(window, '-', NULL, 0, 0, "", " Where : between 'val1' and 'val%d'", num_values); + win_vprint(window, '-', NULL, 0, 0, "", " Remove : /%s remove ", tag); + win_vprint(window, '-', NULL, 0, 0, "", " Where : between 'val1' and 'val%d'", num_values); } break; case FIELD_BOOLEAN: - win_save_vprint(window, '-', NULL, 0, 0, "", " Set : /%s ", tag); + win_vprint(window, '-', NULL, 0, 0, "", " Set : /%s ", tag); win_save_print(window, '-', NULL, 0, 0, "", " Where : is either 'on' or 'off'"); break; case FIELD_LIST_SINGLE: - win_save_vprint(window, '-', NULL, 0, 0, "", " Set : /%s ", tag); + win_vprint(window, '-', NULL, 0, 0, "", " Set : /%s ", tag); win_save_print(window, '-', NULL, 0, 0, "", " Where : is one of"); curr_option = field->options; while (curr_option != NULL) { option = curr_option->data; - win_save_vprint(window, '-', NULL, 0, 0, "", " %s", option->value); + win_vprint(window, '-', NULL, 0, 0, "", " %s", option->value); curr_option = g_slist_next(curr_option); } break; case FIELD_LIST_MULTI: - win_save_vprint(window, '-', NULL, 0, 0, "", " Add : /%s add ", tag); - win_save_vprint(window, '-', NULL, 0, 0, "", " Remove : /%s remove ", tag); + win_vprint(window, '-', NULL, 0, 0, "", " Add : /%s add ", tag); + win_vprint(window, '-', NULL, 0, 0, "", " Remove : /%s remove ", tag); win_save_print(window, '-', NULL, 0, 0, "", " Where : is one of"); curr_option = field->options; while (curr_option != NULL) { option = curr_option->data; - win_save_vprint(window, '-', NULL, 0, 0, "", " %s", option->value); + win_vprint(window, '-', NULL, 0, 0, "", " %s", option->value); curr_option = g_slist_next(curr_option); } break; case FIELD_JID_SINGLE: - win_save_vprint(window, '-', NULL, 0, 0, "", " Set : /%s ", tag); + win_vprint(window, '-', NULL, 0, 0, "", " Set : /%s ", tag); win_save_print(window, '-', NULL, 0, 0, "", " Where : is a valid Jabber ID"); break; case FIELD_JID_MULTI: - win_save_vprint(window, '-', NULL, 0, 0, "", " Add : /%s add ", tag); - win_save_vprint(window, '-', NULL, 0, 0, "", " Remove : /%s remove ", tag); + win_vprint(window, '-', NULL, 0, 0, "", " Add : /%s add ", tag); + win_vprint(window, '-', NULL, 0, 0, "", " Remove : /%s remove ", tag); win_save_print(window, '-', NULL, 0, 0, "", " Where : is a valid Jabber ID"); break; case FIELD_FIXED: @@ -2894,7 +2894,7 @@ ui_show_form_field_help(ProfMucConfWin *confwin, char *tag) break; } } else { - win_save_vprint(window, '-', NULL, 0, 0, "", "No such field %s", tag); + win_vprint(window, '-', NULL, 0, 0, "", "No such field %s", tag); } } diff --git a/src/ui/window.c b/src/ui/window.c index 96bfd546..6d3d5fc0 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -548,10 +548,10 @@ win_show_occupant(ProfWin *window, Occupant *occupant) theme_item_t presence_colour = theme_main_presence_attrs(presence_str); win_save_print(window, '-', NULL, NO_EOL, presence_colour, "", occupant->nick); - win_save_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " is %s", presence_str); + win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " is %s", presence_str); if (occupant->status) { - win_save_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", occupant->status); + win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", occupant->status); } win_save_print(window, '-', NULL, NO_DATE, presence_colour, "", ""); @@ -574,7 +574,7 @@ win_show_contact(ProfWin *window, PContact contact) win_save_print(window, '-', NULL, NO_EOL, presence_colour, "", barejid); } - win_save_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " is %s", presence); + win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " is %s", presence); if (last_activity != NULL) { GDateTime *now = g_date_time_new_now_local(); @@ -587,15 +587,15 @@ win_show_contact(ProfWin *window, PContact contact) int seconds = span / G_TIME_SPAN_SECOND; if (hours > 0) { - win_save_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", idle %dh%dm%ds", hours, minutes, seconds); + win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", idle %dh%dm%ds", hours, minutes, seconds); } else { - win_save_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", idle %dm%ds", minutes, seconds); + win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", idle %dm%ds", minutes, seconds); } } if (status != NULL) { - win_save_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", p_contact_status(contact)); + win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", p_contact_status(contact)); } win_save_print(window, '-', NULL, NO_DATE, presence_colour, "", ""); @@ -611,20 +611,20 @@ win_show_occupant_info(ProfWin *window, const char * const room, Occupant *occup theme_item_t presence_colour = theme_main_presence_attrs(presence_str); win_save_print(window, '!', NULL, NO_EOL, presence_colour, "", occupant->nick); - win_save_vprint(window, '!', NULL, NO_DATE | NO_EOL, presence_colour, "", " is %s", presence_str); + win_vprint(window, '!', NULL, NO_DATE | NO_EOL, presence_colour, "", " is %s", presence_str); if (occupant->status) { - win_save_vprint(window, '!', NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", occupant->status); + win_vprint(window, '!', NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", occupant->status); } win_save_newline(window); if (occupant->jid) { - win_save_vprint(window, '!', NULL, 0, 0, "", " Jid: %s", occupant->jid); + win_vprint(window, '!', NULL, 0, 0, "", " Jid: %s", occupant->jid); } - win_save_vprint(window, '!', NULL, 0, 0, "", " Affiliation: %s", occupant_affiliation); - win_save_vprint(window, '!', NULL, 0, 0, "", " Role: %s", occupant_role); + win_vprint(window, '!', NULL, 0, 0, "", " Affiliation: %s", occupant_affiliation); + win_vprint(window, '!', NULL, 0, 0, "", " Role: %s", occupant_role); Jid *jidp = jid_create_from_bare_and_resource(room, occupant->nick); Capabilities *caps = caps_lookup(jidp->fulljid); @@ -652,19 +652,19 @@ win_show_occupant_info(ProfWin *window, const char * const room, Occupant *occup win_save_newline(window); } if (caps->software != NULL) { - win_save_vprint(window, '!', NULL, NO_EOL, 0, "", " Software: %s", caps->software); + win_vprint(window, '!', NULL, NO_EOL, 0, "", " Software: %s", caps->software); } if (caps->software_version != NULL) { - win_save_vprint(window, '!', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->software_version); + win_vprint(window, '!', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->software_version); } if ((caps->software != NULL) || (caps->software_version != NULL)) { win_save_newline(window); } if (caps->os != NULL) { - win_save_vprint(window, '!', NULL, NO_EOL, 0, "", " OS: %s", caps->os); + win_vprint(window, '!', NULL, NO_EOL, 0, "", " OS: %s", caps->os); } if (caps->os_version != NULL) { - win_save_vprint(window, '!', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->os_version); + win_vprint(window, '!', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->os_version); } if ((caps->os != NULL) || (caps->os_version != NULL)) { win_save_newline(window); @@ -689,12 +689,12 @@ win_show_info(ProfWin *window, PContact contact) win_save_print(window, '-', NULL, 0, 0, "", ""); win_save_print(window, '-', NULL, NO_EOL, presence_colour, "", barejid); if (name != NULL) { - win_save_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " (%s)", name); + win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " (%s)", name); } win_save_print(window, '-', NULL, NO_DATE, 0, "", ":"); if (sub != NULL) { - win_save_vprint(window, '-', NULL, 0, 0, "", "Subscription: %s", sub); + win_vprint(window, '-', NULL, 0, 0, "", "Subscription: %s", sub); } if (last_activity != NULL) { @@ -708,10 +708,10 @@ win_show_info(ProfWin *window, PContact contact) int seconds = span / G_TIME_SPAN_SECOND; if (hours > 0) { - win_save_vprint(window, '-', NULL, 0, 0, "", "Last activity: %dh%dm%ds", hours, minutes, seconds); + win_vprint(window, '-', NULL, 0, 0, "", "Last activity: %dh%dm%ds", hours, minutes, seconds); } else { - win_save_vprint(window, '-', NULL, 0, 0, "", "Last activity: %dm%ds", minutes, seconds); + win_vprint(window, '-', NULL, 0, 0, "", "Last activity: %dm%ds", minutes, seconds); } g_date_time_unref(now); @@ -738,9 +738,9 @@ win_show_info(ProfWin *window, PContact contact) Resource *resource = curr->data; const char *resource_presence = string_from_resource_presence(resource->presence); theme_item_t presence_colour = theme_main_presence_attrs(resource_presence); - win_save_vprint(window, '-', NULL, NO_EOL, presence_colour, "", " %s (%d), %s", resource->name, resource->priority, resource_presence); + win_vprint(window, '-', NULL, NO_EOL, presence_colour, "", " %s (%d), %s", resource->name, resource->priority, resource_presence); if (resource->status != NULL) { - win_save_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", resource->status); + win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", resource->status); } win_save_newline(window); @@ -770,19 +770,19 @@ win_show_info(ProfWin *window, PContact contact) win_save_newline(window); } if (caps->software != NULL) { - win_save_vprint(window, '-', NULL, NO_EOL, 0, "", " Software: %s", caps->software); + win_vprint(window, '-', NULL, NO_EOL, 0, "", " Software: %s", caps->software); } if (caps->software_version != NULL) { - win_save_vprint(window, '-', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->software_version); + win_vprint(window, '-', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->software_version); } if ((caps->software != NULL) || (caps->software_version != NULL)) { win_save_newline(window); } if (caps->os != NULL) { - win_save_vprint(window, '-', NULL, NO_EOL, 0, "", " OS: %s", caps->os); + win_vprint(window, '-', NULL, NO_EOL, 0, "", " OS: %s", caps->os); } if (caps->os_version != NULL) { - win_save_vprint(window, '-', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->os_version); + win_vprint(window, '-', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->os_version); } if ((caps->os != NULL) || (caps->os_version != NULL)) { win_save_newline(window); @@ -812,12 +812,12 @@ win_show_status_string(ProfWin *window, const char * const from, } - win_save_vprint(window, '-', NULL, NO_EOL, presence_colour, "", "%s %s", pre, from); + win_vprint(window, '-', NULL, NO_EOL, presence_colour, "", "%s %s", pre, from); if (show != NULL) - win_save_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " is %s", show); + win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " is %s", show); else - win_save_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " is %s", default_show); + win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " is %s", default_show); if (last_activity != NULL) { GDateTime *now = g_date_time_new_now_local(); @@ -831,15 +831,15 @@ win_show_status_string(ProfWin *window, const char * const from, int seconds = span / G_TIME_SPAN_SECOND; if (hours > 0) { - win_save_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", idle %dh%dm%ds", hours, minutes, seconds); + win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", idle %dh%dm%ds", hours, minutes, seconds); } else { - win_save_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", idle %dm%ds", minutes, seconds); + win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", idle %dm%ds", minutes, seconds); } } if (status != NULL) - win_save_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", status); + win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", status); win_save_print(window, '-', NULL, NO_DATE, presence_colour, "", ""); @@ -862,7 +862,7 @@ win_print_incoming_message(ProfWin *window, GTimeVal *tv_stamp, } void -win_save_vprint(ProfWin *window, const char show_char, GTimeVal *tstamp, +win_vprint(ProfWin *window, const char show_char, GTimeVal *tstamp, int flags, theme_item_t theme_item, const char * const from, const char * const message, ...) { va_list arg; diff --git a/src/ui/window.h b/src/ui/window.h index d6e82340..c88a0926 100644 --- a/src/ui/window.h +++ b/src/ui/window.h @@ -168,7 +168,7 @@ void win_print_incoming_message(ProfWin *window, GTimeVal *tv_stamp, const char * const from, const char * const message); void win_show_info(ProfWin *window, PContact contact); void win_show_occupant_info(ProfWin *window, const char * const room, Occupant *occupant); -void win_save_vprint(ProfWin *window, const char show_char, GTimeVal *tstamp, int flags, theme_item_t theme_item, const char * const from, const char * const message, ...); +void win_vprint(ProfWin *window, const char show_char, GTimeVal *tstamp, int flags, theme_item_t theme_item, const char * const from, const char * const message, ...); void win_save_print(ProfWin *window, const char show_char, GTimeVal *tstamp, int flags, theme_item_t theme_item, const char * const from, const char * const message); void win_save_println(ProfWin *window, const char * const message); void win_save_newline(ProfWin *window); From e02dbe24da002ecb6b0b5b43399019b3ef5305e6 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 14 Mar 2015 14:12:32 +0000 Subject: [PATCH 124/252] Renamed win_save_print -> win_print --- src/command/commands.c | 10 +- src/ui/console.c | 92 +++++++++--------- src/ui/core.c | 210 ++++++++++++++++++++--------------------- src/ui/window.c | 58 ++++++------ src/ui/window.h | 2 +- src/ui/windows.c | 2 +- 6 files changed, 187 insertions(+), 187 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index 4e0bde2c..811cd85b 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -2511,7 +2511,7 @@ cmd_subject(gchar **args, struct cmd_help_t help) win_vprint(window, '!', NULL, NO_EOL, THEME_ROOMINFO, "", "Room subject: "); win_vprint(window, '!', NULL, NO_DATE, 0, "", "%s", subject); } else { - win_save_print(window, '!', NULL, 0, THEME_ROOMINFO, "", "Room has no subject"); + win_print(window, '!', NULL, 0, THEME_ROOMINFO, "", "Room has no subject"); } return TRUE; } @@ -2576,7 +2576,7 @@ cmd_affiliation(gchar **args, struct cmd_help_t help) iq_room_affiliation_list(mucwin->roomjid, "member"); iq_room_affiliation_list(mucwin->roomjid, "outcast"); } else if (g_strcmp0(affiliation, "none") == 0) { - win_save_print((ProfWin*) mucwin, '!', NULL, 0, 0, "", "Cannot list users with no affiliation."); + win_print((ProfWin*) mucwin, '!', NULL, 0, 0, "", "Cannot list users with no affiliation."); } else { iq_room_affiliation_list(mucwin->roomjid, affiliation); } @@ -2644,7 +2644,7 @@ cmd_role(gchar **args, struct cmd_help_t help) iq_room_role_list(mucwin->roomjid, "participant"); iq_room_role_list(mucwin->roomjid, "visitor"); } else if (g_strcmp0(role, "none") == 0) { - win_save_print((ProfWin*) mucwin, '!', NULL, 0, 0, "", "Cannot list users with no role."); + win_print((ProfWin*) mucwin, '!', NULL, 0, 0, "", "Cannot list users with no role."); } else { iq_room_role_list(mucwin->roomjid, role); } @@ -2707,12 +2707,12 @@ cmd_room(gchar **args, struct cmd_help_t help) if (g_strcmp0(args[0], "accept") == 0) { gboolean requires_config = muc_requires_config(mucwin->roomjid); if (!requires_config) { - win_save_print(window, '!', NULL, 0, THEME_ROOMINFO, "", "Current room does not require configuration."); + win_print(window, '!', NULL, 0, THEME_ROOMINFO, "", "Current room does not require configuration."); return TRUE; } else { iq_confirm_instant_room(mucwin->roomjid); muc_set_requires_config(mucwin->roomjid, FALSE); - win_save_print(window, '!', NULL, 0, THEME_ROOMINFO, "", "Room unlocked."); + win_print(window, '!', NULL, 0, THEME_ROOMINFO, "", "Room unlocked."); return TRUE; } } diff --git a/src/ui/console.c b/src/ui/console.c index b7c86df2..5e4bb6d8 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -67,14 +67,14 @@ void cons_show_time(void) { ProfWin *console = wins_get_console(); - win_save_print(console, '-', NULL, NO_EOL, 0, "", ""); + win_print(console, '-', NULL, NO_EOL, 0, "", ""); } void cons_show_word(const char * const word) { ProfWin *console = wins_get_console(); - win_save_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", word); + win_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", word); } void @@ -113,7 +113,7 @@ cons_show_error(const char * const msg, ...) va_start(arg, msg); GString *fmt_msg = g_string_new(NULL); g_string_vprintf(fmt_msg, msg, arg); - win_save_print(console, '-', NULL, 0, THEME_ERROR, "", fmt_msg->str); + win_print(console, '-', NULL, 0, THEME_ERROR, "", fmt_msg->str); g_string_free(fmt_msg, TRUE); va_end(arg); @@ -234,7 +234,7 @@ cons_show_login_success(ProfAccount *account) win_vprint(console, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", "%s", presence_str); win_vprint(console, '-', NULL, NO_DATE | NO_EOL, 0, "", " (priority %d)", accounts_get_priority_for_presence_type(account->name, presence)); - win_save_print(console, '-', NULL, NO_DATE, 0, "", "."); + win_print(console, '-', NULL, NO_DATE, 0, "", "."); cons_alert(); } @@ -295,25 +295,25 @@ cons_show_caps(const char * const fulljid, resource_presence_t presence) theme_item_t presence_colour = theme_main_presence_attrs(resource_presence); win_vprint(console, '-', NULL, NO_EOL, presence_colour, "", "%s", fulljid); - win_save_print(console, '-', NULL, NO_DATE, 0, "", ":"); + win_print(console, '-', NULL, NO_DATE, 0, "", ":"); // show identity if ((caps->category != NULL) || (caps->type != NULL) || (caps->name != NULL)) { - win_save_print(console, '-', NULL, NO_EOL, 0, "", "Identity: "); + win_print(console, '-', NULL, NO_EOL, 0, "", "Identity: "); if (caps->name != NULL) { - win_save_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->name); + win_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->name); if ((caps->category != NULL) || (caps->type != NULL)) { - win_save_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", " "); + win_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", " "); } } if (caps->type != NULL) { - win_save_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->type); + win_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->type); if (caps->category != NULL) { - win_save_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", " "); + win_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", " "); } } if (caps->category != NULL) { - win_save_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->category); + win_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->category); } win_save_newline(console); } @@ -362,7 +362,7 @@ cons_show_software_version(const char * const jid, const char * const presence, cons_show(""); theme_item_t presence_colour = theme_main_presence_attrs(presence); win_vprint(console, '-', NULL, NO_EOL, presence_colour, "", "%s", jid); - win_save_print(console, '-', NULL, NO_DATE, 0, "", ":"); + win_print(console, '-', NULL, NO_DATE, 0, "", ":"); } if (name != NULL) { cons_show("Name : %s", name); @@ -465,10 +465,10 @@ cons_show_bookmarks(const GList *list) win_vprint(console, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", "/%s", item->nick); } if (item->autojoin) { - win_save_print(console, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " (autojoin)"); + win_print(console, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " (autojoin)"); } if (item->password != NULL) { - win_save_print(console, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " (private)"); + win_print(console, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " (private)"); } if (muc_active(item->jid)) { ProfWin *roomwin = (ProfWin*)wins_get_muc(item->jid); @@ -752,21 +752,21 @@ cons_show_account(ProfAccount *account) if (caps != NULL) { // show identity if ((caps->category != NULL) || (caps->type != NULL) || (caps->name != NULL)) { - win_save_print(console, '-', NULL, NO_EOL, 0, "", " Identity: "); + win_print(console, '-', NULL, NO_EOL, 0, "", " Identity: "); if (caps->name != NULL) { - win_save_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->name); + win_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->name); if ((caps->category != NULL) || (caps->type != NULL)) { - win_save_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", " "); + win_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", " "); } } if (caps->type != NULL) { - win_save_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->type); + win_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->type); if (caps->category != NULL) { - win_save_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", " "); + win_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", " "); } } if (caps->category != NULL) { - win_save_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->category); + win_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->category); } win_save_newline(console); } @@ -1551,22 +1551,22 @@ cons_theme_colours(void) ProfWin *console = wins_get_console(); cons_show("Theme colours:"); - win_save_print(console, '-', NULL, NO_EOL, THEME_WHITE, "", " white "); - win_save_print(console, '-', NULL, NO_DATE, THEME_WHITE_BOLD, "", " bold_white"); - win_save_print(console, '-', NULL, NO_EOL, THEME_GREEN, "", " green "); - win_save_print(console, '-', NULL, NO_DATE, THEME_GREEN_BOLD, "", " bold_green"); - win_save_print(console, '-', NULL, NO_EOL, THEME_RED, "", " red "); - win_save_print(console, '-', NULL, NO_DATE, THEME_RED_BOLD, "", " bold_red"); - win_save_print(console, '-', NULL, NO_EOL, THEME_YELLOW, "", " yellow "); - win_save_print(console, '-', NULL, NO_DATE, THEME_YELLOW_BOLD, "", " bold_yellow"); - win_save_print(console, '-', NULL, NO_EOL, THEME_BLUE, "", " blue "); - win_save_print(console, '-', NULL, NO_DATE, THEME_BLUE_BOLD, "", " bold_blue"); - win_save_print(console, '-', NULL, NO_EOL, THEME_CYAN, "", " cyan "); - win_save_print(console, '-', NULL, NO_DATE, THEME_CYAN_BOLD, "", " bold_cyan"); - win_save_print(console, '-', NULL, NO_EOL, THEME_MAGENTA, "", " magenta "); - win_save_print(console, '-', NULL, NO_DATE, THEME_MAGENTA_BOLD, "", " bold_magenta"); - win_save_print(console, '-', NULL, NO_EOL, THEME_BLACK, "", " black "); - win_save_print(console, '-', NULL, NO_DATE, THEME_BLACK_BOLD, "", " bold_black"); + win_print(console, '-', NULL, NO_EOL, THEME_WHITE, "", " white "); + win_print(console, '-', NULL, NO_DATE, THEME_WHITE_BOLD, "", " bold_white"); + win_print(console, '-', NULL, NO_EOL, THEME_GREEN, "", " green "); + win_print(console, '-', NULL, NO_DATE, THEME_GREEN_BOLD, "", " bold_green"); + win_print(console, '-', NULL, NO_EOL, THEME_RED, "", " red "); + win_print(console, '-', NULL, NO_DATE, THEME_RED_BOLD, "", " bold_red"); + win_print(console, '-', NULL, NO_EOL, THEME_YELLOW, "", " yellow "); + win_print(console, '-', NULL, NO_DATE, THEME_YELLOW_BOLD, "", " bold_yellow"); + win_print(console, '-', NULL, NO_EOL, THEME_BLUE, "", " blue "); + win_print(console, '-', NULL, NO_DATE, THEME_BLUE_BOLD, "", " bold_blue"); + win_print(console, '-', NULL, NO_EOL, THEME_CYAN, "", " cyan "); + win_print(console, '-', NULL, NO_DATE, THEME_CYAN_BOLD, "", " bold_cyan"); + win_print(console, '-', NULL, NO_EOL, THEME_MAGENTA, "", " magenta "); + win_print(console, '-', NULL, NO_DATE, THEME_MAGENTA_BOLD, "", " bold_magenta"); + win_print(console, '-', NULL, NO_EOL, THEME_BLACK, "", " black "); + win_print(console, '-', NULL, NO_DATE, THEME_BLACK_BOLD, "", " bold_black"); cons_show(""); } @@ -1576,14 +1576,14 @@ _cons_splash_logo(void) ProfWin *console = wins_get_console(); win_save_println(console, "Welcome to"); - win_save_print(console, '-', NULL, 0, THEME_SPLASH, "", " ___ _ "); - win_save_print(console, '-', NULL, 0, THEME_SPLASH, "", " / __) (_)_ "); - win_save_print(console, '-', NULL, 0, THEME_SPLASH, "", " ____ ____ ___ | |__ ____ ____ _| |_ _ _ "); - win_save_print(console, '-', NULL, 0, THEME_SPLASH, "", "| _ \\ / ___) _ \\| __) _ | _ \\| | _) | | |"); - win_save_print(console, '-', NULL, 0, THEME_SPLASH, "", "| | | | | | |_| | | ( ( | | | | | | |_| |_| |"); - win_save_print(console, '-', NULL, 0, THEME_SPLASH, "", "| ||_/|_| \\___/|_| \\_||_|_| |_|_|\\___)__ |"); - win_save_print(console, '-', NULL, 0, THEME_SPLASH, "", "|_| (____/ "); - win_save_print(console, '-', NULL, 0, THEME_SPLASH, "", ""); + win_print(console, '-', NULL, 0, THEME_SPLASH, "", " ___ _ "); + win_print(console, '-', NULL, 0, THEME_SPLASH, "", " / __) (_)_ "); + win_print(console, '-', NULL, 0, THEME_SPLASH, "", " ____ ____ ___ | |__ ____ ____ _| |_ _ _ "); + win_print(console, '-', NULL, 0, THEME_SPLASH, "", "| _ \\ / ___) _ \\| __) _ | _ \\| | _) | | |"); + win_print(console, '-', NULL, 0, THEME_SPLASH, "", "| | | | | | |_| | | ( ( | | | | | | |_| |_| |"); + win_print(console, '-', NULL, 0, THEME_SPLASH, "", "| ||_/|_| \\___/|_| \\_||_|_| |_|_|\\___)__ |"); + win_print(console, '-', NULL, 0, THEME_SPLASH, "", "|_| (____/ "); + win_print(console, '-', NULL, 0, THEME_SPLASH, "", ""); if (strcmp(PACKAGE_STATUS, "development") == 0) { #ifdef HAVE_GIT_VERSION @@ -1623,7 +1623,7 @@ _show_roster_contacts(GSList *list, gboolean show_groups) g_string_free(title, TRUE); - win_save_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", " - "); + win_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", " - "); GString *sub = g_string_new(""); sub = g_string_append(sub, p_contact_subscription(contact)); if (p_contact_pending_out(contact)) { @@ -1660,7 +1660,7 @@ _show_roster_contacts(GSList *list, gboolean show_groups) win_vprint(console, '-', NULL, NO_DATE, 0, "", "%s", groups_str->str); g_string_free(groups_str, TRUE); } else { - win_save_print(console, '-', NULL, NO_DATE, 0, "", " "); + win_print(console, '-', NULL, NO_DATE, 0, "", " "); } } diff --git a/src/ui/core.c b/src/ui/core.c index c5f7ea62..dbc8b024 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -307,13 +307,13 @@ ui_handle_stanza(const char * const msg) ProfWin *window = (ProfWin*) xmlconsole; if (g_str_has_prefix(msg, "SENT:")) { - win_save_print(window, '-', NULL, 0, 0, "", "SENT:"); - win_save_print(window, '-', NULL, 0, THEME_ONLINE, "", &msg[6]); - win_save_print(window, '-', NULL, 0, THEME_ONLINE, "", ""); + win_print(window, '-', NULL, 0, 0, "", "SENT:"); + win_print(window, '-', NULL, 0, THEME_ONLINE, "", &msg[6]); + win_print(window, '-', NULL, 0, THEME_ONLINE, "", ""); } else if (g_str_has_prefix(msg, "RECV:")) { - win_save_print(window, '-', NULL, 0, 0, "", "RECV:"); - win_save_print(window, '-', NULL, 0, THEME_AWAY, "", &msg[6]); - win_save_print(window, '-', NULL, 0, THEME_AWAY, "", ""); + win_print(window, '-', NULL, 0, 0, "", "RECV:"); + win_print(window, '-', NULL, 0, THEME_AWAY, "", &msg[6]); + win_print(window, '-', NULL, 0, THEME_AWAY, "", ""); } } } @@ -992,9 +992,9 @@ ui_gone_secure(const char * const barejid, gboolean trusted) chatwin->is_otr = TRUE; chatwin->is_trusted = trusted; if (trusted) { - win_save_print(window, '!', NULL, 0, THEME_OTR_STARTED_TRUSTED, "", "OTR session started (trusted)."); + win_print(window, '!', NULL, 0, THEME_OTR_STARTED_TRUSTED, "", "OTR session started (trusted)."); } else { - win_save_print(window, '!', NULL, 0, THEME_OTR_STARTED_UNTRUSTED, "", "OTR session started (untrusted)."); + win_print(window, '!', NULL, 0, THEME_OTR_STARTED_UNTRUSTED, "", "OTR session started (untrusted)."); } if (wins_is_current(window)) { @@ -1021,7 +1021,7 @@ ui_gone_insecure(const char * const barejid) chatwin->is_trusted = FALSE; ProfWin *window = (ProfWin*)chatwin; - win_save_print(window, '!', NULL, 0, THEME_OTR_ENDED, "", "OTR session ended."); + win_print(window, '!', NULL, 0, THEME_OTR_ENDED, "", "OTR session ended."); if (wins_is_current(window)) { title_bar_switch(); } @@ -1044,7 +1044,7 @@ ui_smp_recipient_initiated_q(const char * const barejid, const char *question) if (chatwin) { win_vprint((ProfWin*)chatwin, '!', NULL, 0, 0, "", "%s wants to authenticate your identity with the following question:", barejid); win_vprint((ProfWin*)chatwin, '!', NULL, 0, 0, "", " %s", question); - win_save_print((ProfWin*)chatwin, '!', NULL, 0, 0, "", "use '/otr answer '."); + win_print((ProfWin*)chatwin, '!', NULL, 0, 0, "", "use '/otr answer '."); } } @@ -1071,7 +1071,7 @@ ui_smp_aborted(const char * const barejid) { ProfChatWin *chatwin = wins_get_chat(barejid); if (chatwin) { - win_save_print((ProfWin*)chatwin, '!', NULL, 0, 0, "", "SMP session aborted."); + win_print((ProfWin*)chatwin, '!', NULL, 0, 0, "", "SMP session aborted."); } } @@ -1080,7 +1080,7 @@ ui_smp_successful(const char * const barejid) { ProfChatWin *chatwin = wins_get_chat(barejid); if (chatwin) { - win_save_print((ProfWin*)chatwin, '!', NULL, 0, 0, "", "Authentication successful."); + win_print((ProfWin*)chatwin, '!', NULL, 0, 0, "", "Authentication successful."); } } @@ -1129,7 +1129,7 @@ ui_trust(const char * const barejid) chatwin->is_trusted = TRUE; ProfWin *window = (ProfWin*)chatwin; - win_save_print(window, '!', NULL, 0, THEME_OTR_TRUSTED, "", "OTR session trusted."); + win_print(window, '!', NULL, 0, THEME_OTR_TRUSTED, "", "OTR session trusted."); if (wins_is_current(window)) { title_bar_switch(); } @@ -1145,7 +1145,7 @@ ui_untrust(const char * const barejid) chatwin->is_trusted = FALSE; ProfWin *window = (ProfWin*)chatwin; - win_save_print(window, '!', NULL, 0, THEME_OTR_UNTRUSTED, "", "OTR session untrusted."); + win_print(window, '!', NULL, 0, THEME_OTR_UNTRUSTED, "", "OTR session untrusted."); if (wins_is_current(window)) { title_bar_switch(); } @@ -1286,7 +1286,7 @@ ui_current_print_formatted_line(const char show_char, int attrs, const char * co va_start(arg, msg); GString *fmt_msg = g_string_new(NULL); g_string_vprintf(fmt_msg, msg, arg); - win_save_print(current, show_char, NULL, 0, attrs, "", fmt_msg->str); + win_print(current, show_char, NULL, 0, attrs, "", fmt_msg->str); va_end(arg); g_string_free(fmt_msg, TRUE); } @@ -1295,7 +1295,7 @@ void ui_current_error_line(const char * const msg) { ProfWin *current = wins_get_current(); - win_save_print(current, '-', NULL, 0, THEME_ERROR, "", msg); + win_print(current, '-', NULL, 0, THEME_ERROR, "", msg); } void @@ -1464,11 +1464,11 @@ ui_outgoing_chat_msg(const char * const from, const char * const barejid, GString *message_with_id = g_string_new(id); g_string_append(message_with_id, ": "); g_string_append(message_with_id, message); - win_save_print(window, '-', NULL, 0, THEME_TEXT_ME, from, message_with_id->str); + win_print(window, '-', NULL, 0, THEME_TEXT_ME, from, message_with_id->str); g_string_free(message_with_id, TRUE); free(id); } else { - win_save_print(window, '-', NULL, 0, THEME_TEXT_ME, from, message); + win_print(window, '-', NULL, 0, THEME_TEXT_ME, from, message); } ui_switch_win(num); } @@ -1490,7 +1490,7 @@ ui_outgoing_private_msg(const char * const from, const char * const fulljid, num = wins_get_num(window); } - win_save_print(window, '-', NULL, 0, THEME_TEXT_ME, from, message); + win_print(window, '-', NULL, 0, THEME_TEXT_ME, from, message); ui_switch_win(num); } @@ -1517,7 +1517,7 @@ ui_room_join(const char * const roomjid, gboolean focus) win_vprint(window, '!', NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", affiliation: %s", affiliation); } } - win_save_print(window, '!', NULL, NO_DATE, THEME_ROOMINFO, "", ""); + win_print(window, '!', NULL, NO_DATE, THEME_ROOMINFO, "", ""); num = wins_get_num(window); @@ -1552,7 +1552,7 @@ ui_room_role_change(const char * const roomjid, const char * const role, const c if (reason) { win_vprint(window, '!', NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", reason: %s", reason); } - win_save_print(window, '!', NULL, NO_DATE, THEME_ROOMINFO, "", ""); + win_print(window, '!', NULL, NO_DATE, THEME_ROOMINFO, "", ""); } void @@ -1567,7 +1567,7 @@ ui_room_affiliation_change(const char * const roomjid, const char * const affili if (reason) { win_vprint(window, '!', NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", reason: %s", reason); } - win_save_print(window, '!', NULL, NO_DATE, THEME_ROOMINFO, "", ""); + win_print(window, '!', NULL, NO_DATE, THEME_ROOMINFO, "", ""); } void @@ -1582,7 +1582,7 @@ ui_room_role_and_affiliation_change(const char * const roomjid, const char * con if (reason) { win_vprint(window, '!', NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", reason: %s", reason); } - win_save_print(window, '!', NULL, NO_DATE, THEME_ROOMINFO, "", ""); + win_print(window, '!', NULL, NO_DATE, THEME_ROOMINFO, "", ""); } @@ -1598,7 +1598,7 @@ ui_room_occupant_role_change(const char * const roomjid, const char * const nick if (reason) { win_vprint(window, '!', NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", reason: %s", reason); } - win_save_print(window, '!', NULL, NO_DATE, THEME_ROOMINFO, "", ""); + win_print(window, '!', NULL, NO_DATE, THEME_ROOMINFO, "", ""); } void @@ -1613,7 +1613,7 @@ ui_room_occupant_affiliation_change(const char * const roomjid, const char * con if (reason) { win_vprint(window, '!', NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", reason: %s", reason); } - win_save_print(window, '!', NULL, NO_DATE, THEME_ROOMINFO, "", ""); + win_print(window, '!', NULL, NO_DATE, THEME_ROOMINFO, "", ""); } void @@ -1628,7 +1628,7 @@ ui_room_occupant_role_and_affiliation_change(const char * const roomjid, const c if (reason) { win_vprint(window, '!', NULL, NO_DATE | NO_EOL, THEME_ROOMINFO, "", ", reason: %s", reason); } - win_save_print(window, '!', NULL, NO_DATE, THEME_ROOMINFO, "", ""); + win_print(window, '!', NULL, NO_DATE, THEME_ROOMINFO, "", ""); } void @@ -1637,7 +1637,7 @@ ui_handle_room_info_error(const char * const roomjid, const char * const error) ProfWin *window = (ProfWin*)wins_get_muc(roomjid); if (window) { win_vprint(window, '!', NULL, 0, 0, "", "Room info request failed: %s", error); - win_save_print(window, '-', NULL, 0, 0, "", ""); + win_print(window, '-', NULL, 0, 0, "", ""); } } @@ -1649,7 +1649,7 @@ ui_show_room_disco_info(const char * const roomjid, GSList *identities, GSList * if (((identities != NULL) && (g_slist_length(identities) > 0)) || ((features != NULL) && (g_slist_length(features) > 0))) { if (identities != NULL) { - win_save_print(window, '!', NULL, 0, 0, "", "Identities:"); + win_print(window, '!', NULL, 0, 0, "", "Identities:"); } while (identities != NULL) { DiscoIdentity *identity = identities->data; // anme trpe, cat @@ -1665,19 +1665,19 @@ ui_show_room_disco_info(const char * const roomjid, GSList *identities, GSList * if (identity->category != NULL) { identity_str = g_string_append(identity_str, identity->category); } - win_save_print(window, '!', NULL, 0, 0, "", identity_str->str); + win_print(window, '!', NULL, 0, 0, "", identity_str->str); g_string_free(identity_str, TRUE); identities = g_slist_next(identities); } if (features != NULL) { - win_save_print(window, '!', NULL, 0, 0, "", "Features:"); + win_print(window, '!', NULL, 0, 0, "", "Features:"); } while (features != NULL) { win_vprint(window, '!', NULL, 0, 0, "", " %s", features->data); features = g_slist_next(features); } - win_save_print(window, '-', NULL, 0, 0, "", ""); + win_print(window, '-', NULL, 0, 0, "", ""); } } } @@ -1691,7 +1691,7 @@ ui_room_roster(const char * const roomjid, GList *roster, const char * const pre } else { if ((roster == NULL) || (g_list_length(roster) == 0)) { if (presence == NULL) { - win_save_print(window, '!', NULL, 0, THEME_ROOMINFO, "", "Room is empty."); + win_print(window, '!', NULL, 0, THEME_ROOMINFO, "", "Room is empty."); } else { win_vprint(window, '!', NULL, 0, THEME_ROOMINFO, "", "No occupants %s.", presence); } @@ -1711,12 +1711,12 @@ ui_room_roster(const char * const roomjid, GList *roster, const char * const pre win_vprint(window, '!', NULL, NO_DATE | NO_EOL, presence_colour, "", "%s", occupant->nick); if (roster->next != NULL) { - win_save_print(window, '!', NULL, NO_DATE | NO_EOL, 0, "", ", "); + win_print(window, '!', NULL, NO_DATE | NO_EOL, 0, "", ", "); } roster = g_list_next(roster); } - win_save_print(window, '!', NULL, NO_DATE, THEME_ONLINE, "", ""); + win_print(window, '!', NULL, NO_DATE, THEME_ONLINE, "", ""); } } @@ -1804,7 +1804,7 @@ ui_room_member_online(const char * const roomjid, const char * const nick, const win_vprint(window, '!', NULL, NO_DATE | NO_EOL, THEME_ONLINE, "", ", affiliation: %s", affiliation); } } - win_save_print(window, '!', NULL, NO_DATE, THEME_ROOMINFO, "", ""); + win_print(window, '!', NULL, NO_DATE, THEME_ROOMINFO, "", ""); } } @@ -1864,7 +1864,7 @@ ui_room_history(const char * const roomjid, const char * const nick, g_string_append(line, message); } - win_save_print(window, '-', &tv_stamp, NO_COLOUR_DATE, 0, "", line->str); + win_print(window, '-', &tv_stamp, NO_COLOUR_DATE, 0, "", line->str); g_string_free(line, TRUE); } } @@ -1883,12 +1883,12 @@ ui_room_message(const char * const roomjid, const char * const nick, if (g_strcmp0(nick, my_nick) != 0) { if (g_strrstr(message, my_nick) != NULL) { - win_save_print(window, '-', NULL, NO_ME, THEME_ROOMMENTION, nick, message); + win_print(window, '-', NULL, NO_ME, THEME_ROOMMENTION, nick, message); } else { - win_save_print(window, '-', NULL, NO_ME, THEME_TEXT_THEM, nick, message); + win_print(window, '-', NULL, NO_ME, THEME_TEXT_THEM, nick, message); } } else { - win_save_print(window, '-', NULL, 0, THEME_TEXT_ME, nick, message); + win_print(window, '-', NULL, 0, THEME_TEXT_ME, nick, message); } // currently in groupchat window @@ -1964,7 +1964,7 @@ ui_room_requires_config(const char * const roomjid) ui_index = 0; } - win_save_print(window, '-', NULL, 0, 0, "", ""); + win_print(window, '-', NULL, 0, 0, "", ""); win_vprint(window, '!', NULL, 0, THEME_ROOMINFO, "", "Room locked, requires configuration."); win_vprint(window, '!', NULL, 0, THEME_ROOMINFO, "", @@ -1973,7 +1973,7 @@ ui_room_requires_config(const char * const roomjid) "Use '/room destroy' to cancel and destroy the room"); win_vprint(window, '!', NULL, 0, THEME_ROOMINFO, "", "Use '/room config' to edit the room configuration"); - win_save_print(window, '-', NULL, 0, 0, "", ""); + win_print(window, '-', NULL, 0, 0, "", ""); // currently in groupchat window if (wins_is_current(window)) { @@ -2184,10 +2184,10 @@ ui_handle_room_affiliation_list(const char * const roomjid, const char * const a win_vprint(window, '!', NULL, 0, 0, "", " %s", jid); curr_jid = g_slist_next(curr_jid); } - win_save_print(window, '!', NULL, 0, 0, "", ""); + win_print(window, '!', NULL, 0, 0, "", ""); } else { win_vprint(window, '!', NULL, 0, 0, "", "No users found with affiliation: %s", affiliation); - win_save_print(window, '!', NULL, 0, 0, "", ""); + win_print(window, '!', NULL, 0, 0, "", ""); } } } @@ -2223,10 +2223,10 @@ ui_handle_room_role_list(const char * const roomjid, const char * const role, GS } curr_nick = g_slist_next(curr_nick); } - win_save_print(window, '!', NULL, 0, 0, "", ""); + win_print(window, '!', NULL, 0, 0, "", ""); } else { win_vprint(window, '!', NULL, 0, 0, "", "No occupants found with role: %s", role); - win_save_print(window, '!', NULL, 0, 0, "", ""); + win_print(window, '!', NULL, 0, 0, "", ""); } } } @@ -2413,7 +2413,7 @@ ui_show_room_info(ProfMucWin *mucwin) win_vprint(window, '!', NULL, 0, 0, "", "Room: %s", mucwin->roomjid); win_vprint(window, '!', NULL, 0, 0, "", "Affiliation: %s", affiliation); win_vprint(window, '!', NULL, 0, 0, "", "Role: %s", role); - win_save_print(window, '-', NULL, 0, 0, "", ""); + win_print(window, '-', NULL, 0, 0, "", ""); } void @@ -2425,28 +2425,28 @@ ui_show_room_role_list(ProfMucWin *mucwin, muc_role_t role) if (!occupants) { switch (role) { case MUC_ROLE_MODERATOR: - win_save_print(window, '!', NULL, 0, 0, "", "No moderators found."); + win_print(window, '!', NULL, 0, 0, "", "No moderators found."); break; case MUC_ROLE_PARTICIPANT: - win_save_print(window, '!', NULL, 0, 0, "", "No participants found."); + win_print(window, '!', NULL, 0, 0, "", "No participants found."); break; case MUC_ROLE_VISITOR: - win_save_print(window, '!', NULL, 0, 0, "", "No visitors found."); + win_print(window, '!', NULL, 0, 0, "", "No visitors found."); break; default: break; } - win_save_print(window, '-', NULL, 0, 0, "", ""); + win_print(window, '-', NULL, 0, 0, "", ""); } else { switch (role) { case MUC_ROLE_MODERATOR: - win_save_print(window, '!', NULL, 0, 0, "", "Moderators:"); + win_print(window, '!', NULL, 0, 0, "", "Moderators:"); break; case MUC_ROLE_PARTICIPANT: - win_save_print(window, '!', NULL, 0, 0, "", "Participants:"); + win_print(window, '!', NULL, 0, 0, "", "Participants:"); break; case MUC_ROLE_VISITOR: - win_save_print(window, '!', NULL, 0, 0, "", "Visitors:"); + win_print(window, '!', NULL, 0, 0, "", "Visitors:"); break; default: break; @@ -2466,7 +2466,7 @@ ui_show_room_role_list(ProfMucWin *mucwin, muc_role_t role) curr_occupant = g_slist_next(curr_occupant); } - win_save_print(window, '-', NULL, 0, 0, "", ""); + win_print(window, '-', NULL, 0, 0, "", ""); } } @@ -2479,34 +2479,34 @@ ui_show_room_affiliation_list(ProfMucWin *mucwin, muc_affiliation_t affiliation) if (!occupants) { switch (affiliation) { case MUC_AFFILIATION_OWNER: - win_save_print(window, '!', NULL, 0, 0, "", "No owners found."); + win_print(window, '!', NULL, 0, 0, "", "No owners found."); break; case MUC_AFFILIATION_ADMIN: - win_save_print(window, '!', NULL, 0, 0, "", "No admins found."); + win_print(window, '!', NULL, 0, 0, "", "No admins found."); break; case MUC_AFFILIATION_MEMBER: - win_save_print(window, '!', NULL, 0, 0, "", "No members found."); + win_print(window, '!', NULL, 0, 0, "", "No members found."); break; case MUC_AFFILIATION_OUTCAST: - win_save_print(window, '!', NULL, 0, 0, "", "No outcasts found."); + win_print(window, '!', NULL, 0, 0, "", "No outcasts found."); break; default: break; } - win_save_print(window, '-', NULL, 0, 0, "", ""); + win_print(window, '-', NULL, 0, 0, "", ""); } else { switch (affiliation) { case MUC_AFFILIATION_OWNER: - win_save_print(window, '!', NULL, 0, 0, "", "Owners:"); + win_print(window, '!', NULL, 0, 0, "", "Owners:"); break; case MUC_AFFILIATION_ADMIN: - win_save_print(window, '!', NULL, 0, 0, "", "Admins:"); + win_print(window, '!', NULL, 0, 0, "", "Admins:"); break; case MUC_AFFILIATION_MEMBER: - win_save_print(window, '!', NULL, 0, 0, "", "Members:"); + win_print(window, '!', NULL, 0, 0, "", "Members:"); break; case MUC_AFFILIATION_OUTCAST: - win_save_print(window, '!', NULL, 0, 0, "", "Outcasts:"); + win_print(window, '!', NULL, 0, 0, "", "Outcasts:"); break; default: break; @@ -2526,7 +2526,7 @@ ui_show_room_affiliation_list(ProfMucWin *mucwin, muc_affiliation_t affiliation) curr_occupant = g_slist_next(curr_occupant); } - win_save_print(window, '-', NULL, 0, 0, "", ""); + win_print(window, '-', NULL, 0, 0, "", ""); } } @@ -2536,9 +2536,9 @@ _ui_handle_form_field(ProfWin *window, char *tag, FormField *field) win_vprint(window, '-', NULL, NO_EOL, THEME_AWAY, "", "[%s] ", tag); win_vprint(window, '-', NULL, NO_EOL | NO_DATE, 0, "", "%s", field->label); if (field->required) { - win_save_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", " (required): "); + win_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", " (required): "); } else { - win_save_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", ": "); + win_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", ": "); } GSList *values = field->values; @@ -2552,9 +2552,9 @@ _ui_handle_form_field(ProfWin *window, char *tag, FormField *field) char *value = curr_value->data; if (value != NULL) { if (g_strcmp0(field->var, "muc#roomconfig_roomsecret") == 0) { - win_save_print(window, '-', NULL, NO_DATE | NO_EOL, THEME_ONLINE, "", "[hidden]"); + win_print(window, '-', NULL, NO_DATE | NO_EOL, THEME_ONLINE, "", "[hidden]"); } else { - win_save_print(window, '-', NULL, NO_DATE | NO_EOL, THEME_ONLINE, "", value); + win_print(window, '-', NULL, NO_DATE | NO_EOL, THEME_ONLINE, "", value); } } } @@ -2564,7 +2564,7 @@ _ui_handle_form_field(ProfWin *window, char *tag, FormField *field) if (curr_value != NULL) { char *value = curr_value->data; if (value != NULL) { - win_save_print(window, '-', NULL, NO_DATE | NO_EOL, THEME_ONLINE, "", "[hidden]"); + win_print(window, '-', NULL, NO_DATE | NO_EOL, THEME_ONLINE, "", "[hidden]"); } } win_save_newline(window); @@ -2583,16 +2583,16 @@ _ui_handle_form_field(ProfWin *window, char *tag, FormField *field) break; case FIELD_BOOLEAN: if (curr_value == NULL) { - win_save_print(window, '-', NULL, NO_DATE, THEME_OFFLINE, "", "FALSE"); + win_print(window, '-', NULL, NO_DATE, THEME_OFFLINE, "", "FALSE"); } else { char *value = curr_value->data; if (value == NULL) { - win_save_print(window, '-', NULL, NO_DATE, THEME_OFFLINE, "", "FALSE"); + win_print(window, '-', NULL, NO_DATE, THEME_OFFLINE, "", "FALSE"); } else { if (g_strcmp0(value, "0") == 0) { - win_save_print(window, '-', NULL, NO_DATE, THEME_OFFLINE, "", "FALSE"); + win_print(window, '-', NULL, NO_DATE, THEME_OFFLINE, "", "FALSE"); } else { - win_save_print(window, '-', NULL, NO_DATE, THEME_ONLINE, "", "TRUE"); + win_print(window, '-', NULL, NO_DATE, THEME_ONLINE, "", "TRUE"); } } } @@ -2634,7 +2634,7 @@ _ui_handle_form_field(ProfWin *window, char *tag, FormField *field) if (curr_value != NULL) { char *value = curr_value->data; if (value != NULL) { - win_save_print(window, '-', NULL, NO_DATE | NO_EOL, THEME_ONLINE, "", value); + win_print(window, '-', NULL, NO_DATE | NO_EOL, THEME_ONLINE, "", value); } } win_save_newline(window); @@ -2651,7 +2651,7 @@ _ui_handle_form_field(ProfWin *window, char *tag, FormField *field) if (curr_value != NULL) { char *value = curr_value->data; if (value != NULL) { - win_save_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", value); + win_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", value); } } win_save_newline(window); @@ -2666,12 +2666,12 @@ ui_show_form(ProfMucConfWin *confwin) { ProfWin *window = (ProfWin*) confwin; if (confwin->form->title != NULL) { - win_save_print(window, '-', NULL, NO_EOL, 0, "", "Form title: "); - win_save_print(window, '-', NULL, NO_DATE, 0, "", confwin->form->title); + win_print(window, '-', NULL, NO_EOL, 0, "", "Form title: "); + win_print(window, '-', NULL, NO_DATE, 0, "", confwin->form->title); } else { win_vprint(window, '-', NULL, 0, 0, "", "Configuration for room %s.", confwin->roomjid); } - win_save_print(window, '-', NULL, 0, 0, "", ""); + win_print(window, '-', NULL, 0, 0, "", ""); ui_show_form_help(confwin); @@ -2683,7 +2683,7 @@ ui_show_form(ProfMucConfWin *confwin) if ((g_strcmp0(field->type, "fixed") == 0) && field->values) { if (field->values) { char *value = field->values->data; - win_save_print(window, '-', NULL, 0, 0, "", value); + win_print(window, '-', NULL, 0, 0, "", value); } } else if (g_strcmp0(field->type, "hidden") != 0 && field->var) { char *tag = g_hash_table_lookup(confwin->form->var_to_tag, field->var); @@ -2714,11 +2714,11 @@ ui_handle_room_configuration(const char * const roomjid, DataForm *form) ui_show_form(confwin); - win_save_print(window, '-', NULL, 0, 0, "", ""); - win_save_print(window, '-', NULL, 0, 0, "", "Use '/form submit' to save changes."); - win_save_print(window, '-', NULL, 0, 0, "", "Use '/form cancel' to cancel changes."); - win_save_print(window, '-', NULL, 0, 0, "", "See '/form help' for more information."); - win_save_print(window, '-', NULL, 0, 0, "", ""); + win_print(window, '-', NULL, 0, 0, "", ""); + win_print(window, '-', NULL, 0, 0, "", "Use '/form submit' to save changes."); + win_print(window, '-', NULL, 0, 0, "", "Use '/form cancel' to cancel changes."); + win_print(window, '-', NULL, 0, 0, "", "See '/form help' for more information."); + win_print(window, '-', NULL, 0, 0, "", ""); } void @@ -2740,7 +2740,7 @@ ui_handle_room_configuration_form_error(const char * const roomjid, const char * g_string_append(message_str, message); } - win_save_print(window, '-', NULL, 0, THEME_ERROR, "", message_str->str); + win_print(window, '-', NULL, 0, THEME_ERROR, "", message_str->str); g_string_free(message_str, TRUE); } @@ -2768,7 +2768,7 @@ ui_handle_room_config_submit_result(const char * const roomjid) if (muc_window) { int num = wins_get_num(muc_window); ui_switch_win(num); - win_save_print(muc_window, '!', NULL, 0, THEME_ROOMINFO, "", "Room configuration successful"); + win_print(muc_window, '!', NULL, 0, THEME_ROOMINFO, "", "Room configuration successful"); } else { ui_switch_win(1); cons_show("Room configuration successful: %s", roomjid); @@ -2797,13 +2797,13 @@ ui_handle_room_config_submit_result_error(const char * const roomjid, const char if (message) { win_vprint(form_window, '!', NULL, 0, THEME_ERROR, "", "Configuration error: %s", message); } else { - win_save_print(form_window, '!', NULL, 0, THEME_ERROR, "", "Configuration error"); + win_print(form_window, '!', NULL, 0, THEME_ERROR, "", "Configuration error"); } } else if (muc_window) { if (message) { win_vprint(muc_window, '!', NULL, 0, THEME_ERROR, "", "Configuration error: %s", message); } else { - win_save_print(muc_window, '!', NULL, 0, THEME_ERROR, "", "Configuration error"); + win_print(muc_window, '!', NULL, 0, THEME_ERROR, "", "Configuration error"); } } else { if (message) { @@ -2813,7 +2813,7 @@ ui_handle_room_config_submit_result_error(const char * const roomjid, const char } } } else { - win_save_print(console, '!', NULL, 0, THEME_ERROR, "", "Configuration error"); + win_print(console, '!', NULL, 0, THEME_ERROR, "", "Configuration error"); } } @@ -2823,11 +2823,11 @@ ui_show_form_field_help(ProfMucConfWin *confwin, char *tag) ProfWin *window = (ProfWin*) confwin; FormField *field = form_get_field_by_tag(confwin->form, tag); if (field != NULL) { - win_save_print(window, '-', NULL, NO_EOL, 0, "", field->label); + win_print(window, '-', NULL, NO_EOL, 0, "", field->label); if (field->required) { - win_save_print(window, '-', NULL, NO_DATE, 0, "", " (Required):"); + win_print(window, '-', NULL, NO_DATE, 0, "", " (Required):"); } else { - win_save_print(window, '-', NULL, NO_DATE, 0, "", ":"); + win_print(window, '-', NULL, NO_DATE, 0, "", ":"); } if (field->description != NULL) { win_vprint(window, '-', NULL, 0, 0, "", " Description : %s", field->description); @@ -2842,12 +2842,12 @@ ui_show_form_field_help(ProfMucConfWin *confwin, char *tag) case FIELD_TEXT_SINGLE: case FIELD_TEXT_PRIVATE: win_vprint(window, '-', NULL, 0, 0, "", " Set : /%s ", tag); - win_save_print(window, '-', NULL, 0, 0, "", " Where : is any text"); + win_print(window, '-', NULL, 0, 0, "", " Where : is any text"); break; case FIELD_TEXT_MULTI: num_values = form_get_value_count(confwin->form, tag); win_vprint(window, '-', NULL, 0, 0, "", " Add : /%s add ", tag); - win_save_print(window, '-', NULL, 0, 0, "", " Where : is any text"); + win_print(window, '-', NULL, 0, 0, "", " Where : is any text"); if (num_values > 0) { win_vprint(window, '-', NULL, 0, 0, "", " Remove : /%s remove ", tag); win_vprint(window, '-', NULL, 0, 0, "", " Where : between 'val1' and 'val%d'", num_values); @@ -2855,11 +2855,11 @@ ui_show_form_field_help(ProfMucConfWin *confwin, char *tag) break; case FIELD_BOOLEAN: win_vprint(window, '-', NULL, 0, 0, "", " Set : /%s ", tag); - win_save_print(window, '-', NULL, 0, 0, "", " Where : is either 'on' or 'off'"); + win_print(window, '-', NULL, 0, 0, "", " Where : is either 'on' or 'off'"); break; case FIELD_LIST_SINGLE: win_vprint(window, '-', NULL, 0, 0, "", " Set : /%s ", tag); - win_save_print(window, '-', NULL, 0, 0, "", " Where : is one of"); + win_print(window, '-', NULL, 0, 0, "", " Where : is one of"); curr_option = field->options; while (curr_option != NULL) { option = curr_option->data; @@ -2870,7 +2870,7 @@ ui_show_form_field_help(ProfMucConfWin *confwin, char *tag) case FIELD_LIST_MULTI: win_vprint(window, '-', NULL, 0, 0, "", " Add : /%s add ", tag); win_vprint(window, '-', NULL, 0, 0, "", " Remove : /%s remove ", tag); - win_save_print(window, '-', NULL, 0, 0, "", " Where : is one of"); + win_print(window, '-', NULL, 0, 0, "", " Where : is one of"); curr_option = field->options; while (curr_option != NULL) { option = curr_option->data; @@ -2880,12 +2880,12 @@ ui_show_form_field_help(ProfMucConfWin *confwin, char *tag) break; case FIELD_JID_SINGLE: win_vprint(window, '-', NULL, 0, 0, "", " Set : /%s ", tag); - win_save_print(window, '-', NULL, 0, 0, "", " Where : is a valid Jabber ID"); + win_print(window, '-', NULL, 0, 0, "", " Where : is a valid Jabber ID"); break; case FIELD_JID_MULTI: win_vprint(window, '-', NULL, 0, 0, "", " Add : /%s add ", tag); win_vprint(window, '-', NULL, 0, 0, "", " Remove : /%s remove ", tag); - win_save_print(window, '-', NULL, 0, 0, "", " Where : is a valid Jabber ID"); + win_print(window, '-', NULL, 0, 0, "", " Where : is a valid Jabber ID"); break; case FIELD_FIXED: case FIELD_UNKNOWN: @@ -2903,9 +2903,9 @@ ui_show_form_help(ProfMucConfWin *confwin) { if (confwin->form->instructions != NULL) { ProfWin *window = (ProfWin*) confwin; - win_save_print(window, '-', NULL, 0, 0, "", "Supplied instructions:"); - win_save_print(window, '-', NULL, 0, 0, "", confwin->form->instructions); - win_save_print(window, '-', NULL, 0, 0, "", ""); + win_print(window, '-', NULL, 0, 0, "", "Supplied instructions:"); + win_print(window, '-', NULL, 0, 0, "", confwin->form->instructions); + win_print(window, '-', NULL, 0, 0, "", ""); } } @@ -2915,7 +2915,7 @@ ui_show_lines(ProfWin *window, const gchar** lines) if (lines != NULL) { int i; for (i = 0; lines[i] != NULL; i++) { - win_save_print(window, '-', NULL, 0, 0, "", lines[i]); + win_print(window, '-', NULL, 0, 0, "", lines[i]); } } } @@ -3006,11 +3006,11 @@ _win_show_history(int win_index, const char * const contact) GDateTime *time = g_date_time_new_local(2000, 1, 1, ihh, imm, iss); GTimeVal tv; g_date_time_to_timeval(time, &tv); - win_save_print(window, '-', &tv, NO_COLOUR_DATE, 0, "", curr->data+11); + win_print(window, '-', &tv, NO_COLOUR_DATE, 0, "", curr->data+11); g_date_time_unref(time); // header } else { - win_save_print(window, '-', NULL, 0, 0, "", curr->data); + win_print(window, '-', NULL, 0, 0, "", curr->data); } curr = g_slist_next(curr); } diff --git a/src/ui/window.c b/src/ui/window.c index 6d3d5fc0..08576f6b 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -547,14 +547,14 @@ win_show_occupant(ProfWin *window, Occupant *occupant) theme_item_t presence_colour = theme_main_presence_attrs(presence_str); - win_save_print(window, '-', NULL, NO_EOL, presence_colour, "", occupant->nick); + win_print(window, '-', NULL, NO_EOL, presence_colour, "", occupant->nick); win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " is %s", presence_str); if (occupant->status) { win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", occupant->status); } - win_save_print(window, '-', NULL, NO_DATE, presence_colour, "", ""); + win_print(window, '-', NULL, NO_DATE, presence_colour, "", ""); } void @@ -569,9 +569,9 @@ win_show_contact(ProfWin *window, PContact contact) theme_item_t presence_colour = theme_main_presence_attrs(presence); if (name != NULL) { - win_save_print(window, '-', NULL, NO_EOL, presence_colour, "", name); + win_print(window, '-', NULL, NO_EOL, presence_colour, "", name); } else { - win_save_print(window, '-', NULL, NO_EOL, presence_colour, "", barejid); + win_print(window, '-', NULL, NO_EOL, presence_colour, "", barejid); } win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " is %s", presence); @@ -598,7 +598,7 @@ win_show_contact(ProfWin *window, PContact contact) win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", p_contact_status(contact)); } - win_save_print(window, '-', NULL, NO_DATE, presence_colour, "", ""); + win_print(window, '-', NULL, NO_DATE, presence_colour, "", ""); } void @@ -610,7 +610,7 @@ win_show_occupant_info(ProfWin *window, const char * const room, Occupant *occup theme_item_t presence_colour = theme_main_presence_attrs(presence_str); - win_save_print(window, '!', NULL, NO_EOL, presence_colour, "", occupant->nick); + win_print(window, '!', NULL, NO_EOL, presence_colour, "", occupant->nick); win_vprint(window, '!', NULL, NO_DATE | NO_EOL, presence_colour, "", " is %s", presence_str); if (occupant->status) { @@ -633,21 +633,21 @@ win_show_occupant_info(ProfWin *window, const char * const room, Occupant *occup if (caps) { // show identity if ((caps->category != NULL) || (caps->type != NULL) || (caps->name != NULL)) { - win_save_print(window, '!', NULL, NO_EOL, 0, "", " Identity: "); + win_print(window, '!', NULL, NO_EOL, 0, "", " Identity: "); if (caps->name != NULL) { - win_save_print(window, '!', NULL, NO_DATE | NO_EOL, 0, "", caps->name); + win_print(window, '!', NULL, NO_DATE | NO_EOL, 0, "", caps->name); if ((caps->category != NULL) || (caps->type != NULL)) { - win_save_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", " "); + win_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", " "); } } if (caps->type != NULL) { - win_save_print(window, '!', NULL, NO_DATE | NO_EOL, 0, "", caps->type); + win_print(window, '!', NULL, NO_DATE | NO_EOL, 0, "", caps->type); if (caps->category != NULL) { - win_save_print(window, '!', NULL, NO_DATE | NO_EOL, 0, "", " "); + win_print(window, '!', NULL, NO_DATE | NO_EOL, 0, "", " "); } } if (caps->category != NULL) { - win_save_print(window, '!', NULL, NO_DATE | NO_EOL, 0, "", caps->category); + win_print(window, '!', NULL, NO_DATE | NO_EOL, 0, "", caps->category); } win_save_newline(window); } @@ -672,7 +672,7 @@ win_show_occupant_info(ProfWin *window, const char * const room, Occupant *occup caps_destroy(caps); } - win_save_print(window, '-', NULL, 0, 0, "", ""); + win_print(window, '-', NULL, 0, 0, "", ""); } void @@ -686,12 +686,12 @@ win_show_info(ProfWin *window, PContact contact) theme_item_t presence_colour = theme_main_presence_attrs(presence); - win_save_print(window, '-', NULL, 0, 0, "", ""); - win_save_print(window, '-', NULL, NO_EOL, presence_colour, "", barejid); + win_print(window, '-', NULL, 0, 0, "", ""); + win_print(window, '-', NULL, NO_EOL, presence_colour, "", barejid); if (name != NULL) { win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " (%s)", name); } - win_save_print(window, '-', NULL, NO_DATE, 0, "", ":"); + win_print(window, '-', NULL, NO_DATE, 0, "", ":"); if (sub != NULL) { win_vprint(window, '-', NULL, 0, 0, "", "Subscription: %s", sub); @@ -720,7 +720,7 @@ win_show_info(ProfWin *window, PContact contact) GList *resources = p_contact_get_available_resources(contact); GList *ordered_resources = NULL; if (resources != NULL) { - win_save_print(window, '-', NULL, 0, 0, "", "Resources:"); + win_print(window, '-', NULL, 0, 0, "", "Resources:"); // sort in order of availability GList *curr = resources; @@ -751,21 +751,21 @@ win_show_info(ProfWin *window, PContact contact) if (caps) { // show identity if ((caps->category != NULL) || (caps->type != NULL) || (caps->name != NULL)) { - win_save_print(window, '-', NULL, NO_EOL, 0, "", " Identity: "); + win_print(window, '-', NULL, NO_EOL, 0, "", " Identity: "); if (caps->name != NULL) { - win_save_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->name); + win_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->name); if ((caps->category != NULL) || (caps->type != NULL)) { - win_save_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", " "); + win_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", " "); } } if (caps->type != NULL) { - win_save_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->type); + win_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->type); if (caps->category != NULL) { - win_save_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", " "); + win_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", " "); } } if (caps->category != NULL) { - win_save_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->category); + win_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->category); } win_save_newline(window); } @@ -841,7 +841,7 @@ win_show_status_string(ProfWin *window, const char * const from, if (status != NULL) win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", status); - win_save_print(window, '-', NULL, NO_DATE, presence_colour, "", ""); + win_print(window, '-', NULL, NO_DATE, presence_colour, "", ""); } @@ -853,7 +853,7 @@ win_print_incoming_message(ProfWin *window, GTimeVal *tv_stamp, { case WIN_CHAT: case WIN_PRIVATE: - win_save_print(window, '-', tv_stamp, NO_ME, THEME_TEXT_THEM, from, message); + win_print(window, '-', tv_stamp, NO_ME, THEME_TEXT_THEM, from, message); break; default: assert(FALSE); @@ -869,12 +869,12 @@ win_vprint(ProfWin *window, const char show_char, GTimeVal *tstamp, va_start(arg, message); GString *fmt_msg = g_string_new(NULL); g_string_vprintf(fmt_msg, message, arg); - win_save_print(window, show_char, tstamp, flags, theme_item, from, fmt_msg->str); + win_print(window, show_char, tstamp, flags, theme_item, from, fmt_msg->str); g_string_free(fmt_msg, TRUE); } void -win_save_print(ProfWin *window, const char show_char, GTimeVal *tstamp, +win_print(ProfWin *window, const char show_char, GTimeVal *tstamp, int flags, theme_item_t theme_item, const char * const from, const char * const message) { GDateTime *time; @@ -894,13 +894,13 @@ win_save_print(ProfWin *window, const char show_char, GTimeVal *tstamp, void win_save_println(ProfWin *window, const char * const message) { - win_save_print(window, '-', NULL, 0, 0, "", message); + win_print(window, '-', NULL, 0, 0, "", message); } void win_save_newline(ProfWin *window) { - win_save_print(window, '-', NULL, NO_DATE, 0, "", ""); + win_print(window, '-', NULL, NO_DATE, 0, "", ""); } static void diff --git a/src/ui/window.h b/src/ui/window.h index c88a0926..49ce7d0e 100644 --- a/src/ui/window.h +++ b/src/ui/window.h @@ -169,7 +169,7 @@ void win_print_incoming_message(ProfWin *window, GTimeVal *tv_stamp, void win_show_info(ProfWin *window, PContact contact); void win_show_occupant_info(ProfWin *window, const char * const room, Occupant *occupant); void win_vprint(ProfWin *window, const char show_char, GTimeVal *tstamp, int flags, theme_item_t theme_item, const char * const from, const char * const message, ...); -void win_save_print(ProfWin *window, const char show_char, GTimeVal *tstamp, int flags, theme_item_t theme_item, const char * const from, const char * const message); +void win_print(ProfWin *window, const char show_char, GTimeVal *tstamp, int flags, theme_item_t theme_item, const char * const from, const char * const message); void win_save_println(ProfWin *window, const char * const message); void win_save_newline(ProfWin *window); void win_redraw(ProfWin *window); diff --git a/src/ui/windows.c b/src/ui/windows.c index b534e973..c9496ef6 100644 --- a/src/ui/windows.c +++ b/src/ui/windows.c @@ -622,7 +622,7 @@ wins_lost_connection(void) while (curr != NULL) { ProfWin *window = curr->data; if (window->type != WIN_CONSOLE) { - win_save_print(window, '-', NULL, 0, THEME_ERROR, "", "Lost connection."); + win_print(window, '-', NULL, 0, THEME_ERROR, "", "Lost connection."); // if current win, set current_win_dirty if (wins_is_current(window)) { From b84bddc46b2931f6ca5733c7a69f0f4006392513 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 14 Mar 2015 14:14:46 +0000 Subject: [PATCH 125/252] Renamed win_save_println -> win_println --- src/command/commands.c | 8 ++++---- src/ui/console.c | 34 +++++++++++++++++----------------- src/ui/core.c | 6 +++--- src/ui/window.c | 2 +- src/ui/window.h | 2 +- 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index 811cd85b..549a733d 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -1738,7 +1738,7 @@ cmd_status(gchar **args, struct cmd_help_t help) if (pcontact != NULL) { win_show_contact(window, pcontact); } else { - win_save_println(window, "Error getting contact info."); + win_println(window, "Error getting contact info."); } } break; @@ -1753,7 +1753,7 @@ cmd_status(gchar **args, struct cmd_help_t help) if (occupant) { win_show_occupant(window, occupant); } else { - win_save_println(window, "Error getting contact info."); + win_println(window, "Error getting contact info."); } jid_destroy(jid); } @@ -1819,7 +1819,7 @@ cmd_info(gchar **args, struct cmd_help_t help) if (pcontact != NULL) { win_show_info(window, pcontact); } else { - win_save_println(window, "Error getting contact info."); + win_println(window, "Error getting contact info."); } } break; @@ -1834,7 +1834,7 @@ cmd_info(gchar **args, struct cmd_help_t help) if (occupant) { win_show_occupant_info(window, jid->barejid, occupant); } else { - win_save_println(window, "Error getting contact info."); + win_println(window, "Error getting contact info."); } jid_destroy(jid); } diff --git a/src/ui/console.c b/src/ui/console.c index 5e4bb6d8..c4d698fb 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -86,7 +86,7 @@ cons_debug(const char * const msg, ...) va_start(arg, msg); GString *fmt_msg = g_string_new(NULL); g_string_vprintf(fmt_msg, msg, arg); - win_save_println(console, fmt_msg->str); + win_println(console, fmt_msg->str); g_string_free(fmt_msg, TRUE); va_end(arg); } @@ -100,7 +100,7 @@ cons_show(const char * const msg, ...) va_start(arg, msg); GString *fmt_msg = g_string_new(NULL); g_string_vprintf(fmt_msg, msg, arg); - win_save_println(console, fmt_msg->str); + win_println(console, fmt_msg->str); g_string_free(fmt_msg, TRUE); va_end(arg); } @@ -177,13 +177,13 @@ cons_about(void) } win_vprint(console, '-', NULL, 0, 0, "", "Copyright (C) 2012 - 2015 James Booth <%s>.", PACKAGE_BUGREPORT); - win_save_println(console, "License GPLv3+: GNU GPL version 3 or later "); - win_save_println(console, ""); - win_save_println(console, "This is free software; you are free to change and redistribute it."); - win_save_println(console, "There is NO WARRANTY, to the extent permitted by law."); - win_save_println(console, ""); - win_save_println(console, "Type '/help' to show complete help."); - win_save_println(console, ""); + win_println(console, "License GPLv3+: GNU GPL version 3 or later "); + win_println(console, ""); + win_println(console, "This is free software; you are free to change and redistribute it."); + win_println(console, "There is NO WARRANTY, to the extent permitted by law."); + win_println(console, ""); + win_println(console, "Type '/help' to show complete help."); + win_println(console, ""); if (prefs_get_boolean(PREF_VERCHECK)) { cons_check_version(FALSE); @@ -206,12 +206,12 @@ cons_check_version(gboolean not_available_msg) if (relase_valid) { if (release_is_new(latest_release)) { win_vprint(console, '-', NULL, 0, 0, "", "A new version of Profanity is available: %s", latest_release); - win_save_println(console, "Check for details."); - win_save_println(console, ""); + win_println(console, "Check for details."); + win_println(console, ""); } else { if (not_available_msg) { - win_save_println(console, "No new version available."); - win_save_println(console, ""); + win_println(console, "No new version available."); + win_println(console, ""); } } @@ -248,7 +248,7 @@ cons_show_wins(void) GSList *curr = window_strings; while (curr != NULL) { - win_save_println(console, curr->data); + win_println(console, curr->data); curr = g_slist_next(curr); } g_slist_free_full(window_strings, free); @@ -337,7 +337,7 @@ cons_show_caps(const char * const fulljid, resource_presence_t presence) } if (caps->features != NULL) { - win_save_println(console, "Features:"); + win_println(console, "Features:"); GSList *feature = caps->features; while (feature != NULL) { win_vprint(console, '-', NULL, 0, 0, "", " %s", feature->data); @@ -721,7 +721,7 @@ cons_show_account(ProfAccount *account) GList *curr = resources; if (curr != NULL) { - win_save_println(console, "Resources:"); + win_println(console, "Resources:"); // sort in order of availability while (curr != NULL) { @@ -1574,7 +1574,7 @@ static void _cons_splash_logo(void) { ProfWin *console = wins_get_console(); - win_save_println(console, "Welcome to"); + win_println(console, "Welcome to"); win_print(console, '-', NULL, 0, THEME_SPLASH, "", " ___ _ "); win_print(console, '-', NULL, 0, THEME_SPLASH, "", " / __) (_)_ "); diff --git a/src/ui/core.c b/src/ui/core.c index dbc8b024..a71fa9eb 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -389,7 +389,7 @@ ui_message_receipt(const char * const barejid, const char * const id) ProfWin *win = (ProfWin*) chatwin; GString *message = g_string_new("Message received: "); g_string_append(message, id); - win_save_println(win, message->str); + win_println(win, message->str); g_string_free(message, TRUE); } } @@ -1273,7 +1273,7 @@ ui_current_print_line(const char * const msg, ...) va_start(arg, msg); GString *fmt_msg = g_string_new(NULL); g_string_vprintf(fmt_msg, msg, arg); - win_save_println(window, fmt_msg->str); + win_println(window, fmt_msg->str); va_end(arg); g_string_free(fmt_msg, TRUE); } @@ -2699,7 +2699,7 @@ ui_show_form_field(ProfWin *window, DataForm *form, char *tag) { FormField *field = form_get_field_by_tag(form, tag); _ui_handle_form_field(window, tag, field); - win_save_println(window, ""); + win_println(window, ""); } void diff --git a/src/ui/window.c b/src/ui/window.c index 08576f6b..b3119b33 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -892,7 +892,7 @@ win_print(ProfWin *window, const char show_char, GTimeVal *tstamp, } void -win_save_println(ProfWin *window, const char * const message) +win_println(ProfWin *window, const char * const message) { win_print(window, '-', NULL, 0, 0, "", message); } diff --git a/src/ui/window.h b/src/ui/window.h index 49ce7d0e..9b376171 100644 --- a/src/ui/window.h +++ b/src/ui/window.h @@ -170,7 +170,7 @@ void win_show_info(ProfWin *window, PContact contact); void win_show_occupant_info(ProfWin *window, const char * const room, Occupant *occupant); void win_vprint(ProfWin *window, const char show_char, GTimeVal *tstamp, int flags, theme_item_t theme_item, const char * const from, const char * const message, ...); void win_print(ProfWin *window, const char show_char, GTimeVal *tstamp, int flags, theme_item_t theme_item, const char * const from, const char * const message); -void win_save_println(ProfWin *window, const char * const message); +void win_println(ProfWin *window, const char * const message); void win_save_newline(ProfWin *window); void win_redraw(ProfWin *window); void win_hide_subwin(ProfWin *window); From 6fd5b617ef9e3fc45cc5dbdaaff75516f920fdff Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 14 Mar 2015 14:16:50 +0000 Subject: [PATCH 126/252] Renamed win_save_newline -> win_newline --- src/ui/console.c | 16 ++++++++-------- src/ui/core.c | 16 ++++++++-------- src/ui/window.c | 18 +++++++++--------- src/ui/window.h | 2 +- 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/ui/console.c b/src/ui/console.c index c4d698fb..46cb00fb 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -315,7 +315,7 @@ cons_show_caps(const char * const fulljid, resource_presence_t presence) if (caps->category != NULL) { win_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->category); } - win_save_newline(console); + win_newline(console); } if (caps->software != NULL) { win_vprint(console, '-', NULL, NO_EOL, 0, "", "Software: %s", caps->software); @@ -324,7 +324,7 @@ cons_show_caps(const char * const fulljid, resource_presence_t presence) win_vprint(console, '-', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->software_version); } if ((caps->software != NULL) || (caps->software_version != NULL)) { - win_save_newline(console); + win_newline(console); } if (caps->os != NULL) { win_vprint(console, '-', NULL, NO_EOL, 0, "", "OS: %s", caps->os); @@ -333,7 +333,7 @@ cons_show_caps(const char * const fulljid, resource_presence_t presence) win_vprint(console, '-', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->os_version); } if ((caps->os != NULL) || (caps->os_version != NULL)) { - win_save_newline(console); + win_newline(console); } if (caps->features != NULL) { @@ -430,7 +430,7 @@ cons_show_room_list(GSList *rooms, const char * const conference_node) if (room->name != NULL) { win_vprint(console, '-', NULL, NO_DATE | NO_EOL, 0, "", ", (%s)", room->name); } - win_save_newline(console); + win_newline(console); rooms = g_slist_next(rooms); } } else { @@ -477,7 +477,7 @@ cons_show_bookmarks(const GList *list) win_vprint(console, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " (%d)", num); } } - win_save_newline(console); + win_newline(console); list = g_list_next(list); } } @@ -768,7 +768,7 @@ cons_show_account(ProfAccount *account) if (caps->category != NULL) { win_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->category); } - win_save_newline(console); + win_newline(console); } if (caps->software != NULL) { win_vprint(console, '-', NULL, NO_EOL, 0, "", " Software: %s", caps->software); @@ -777,7 +777,7 @@ cons_show_account(ProfAccount *account) win_vprint(console, '-', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->software_version); } if ((caps->software != NULL) || (caps->software_version != NULL)) { - win_save_newline(console); + win_newline(console); } if (caps->os != NULL) { win_vprint(console, '-', NULL, NO_EOL, 0, "", " OS: %s", caps->os); @@ -786,7 +786,7 @@ cons_show_account(ProfAccount *account) win_vprint(console, '-', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->os_version); } if ((caps->os != NULL) || (caps->os_version != NULL)) { - win_save_newline(console); + win_newline(console); } caps_destroy(caps); } diff --git a/src/ui/core.c b/src/ui/core.c index a71fa9eb..08cddcb9 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -2558,7 +2558,7 @@ _ui_handle_form_field(ProfWin *window, char *tag, FormField *field) } } } - win_save_newline(window); + win_newline(window); break; case FIELD_TEXT_PRIVATE: if (curr_value != NULL) { @@ -2567,10 +2567,10 @@ _ui_handle_form_field(ProfWin *window, char *tag, FormField *field) win_print(window, '-', NULL, NO_DATE | NO_EOL, THEME_ONLINE, "", "[hidden]"); } } - win_save_newline(window); + win_newline(window); break; case FIELD_TEXT_MULTI: - win_save_newline(window); + win_newline(window); int index = 1; while (curr_value != NULL) { char *value = curr_value->data; @@ -2599,7 +2599,7 @@ _ui_handle_form_field(ProfWin *window, char *tag, FormField *field) break; case FIELD_LIST_SINGLE: if (curr_value != NULL) { - win_save_newline(window); + win_newline(window); char *value = curr_value->data; GSList *options = field->options; GSList *curr_option = options; @@ -2616,7 +2616,7 @@ _ui_handle_form_field(ProfWin *window, char *tag, FormField *field) break; case FIELD_LIST_MULTI: if (curr_value != NULL) { - win_save_newline(window); + win_newline(window); GSList *options = field->options; GSList *curr_option = options; while (curr_option != NULL) { @@ -2637,10 +2637,10 @@ _ui_handle_form_field(ProfWin *window, char *tag, FormField *field) win_print(window, '-', NULL, NO_DATE | NO_EOL, THEME_ONLINE, "", value); } } - win_save_newline(window); + win_newline(window); break; case FIELD_JID_MULTI: - win_save_newline(window); + win_newline(window); while (curr_value != NULL) { char *value = curr_value->data; win_vprint(window, '-', NULL, 0, THEME_ONLINE, "", " %s", value); @@ -2654,7 +2654,7 @@ _ui_handle_form_field(ProfWin *window, char *tag, FormField *field) win_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", value); } } - win_save_newline(window); + win_newline(window); break; default: break; diff --git a/src/ui/window.c b/src/ui/window.c index b3119b33..d5b30228 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -617,7 +617,7 @@ win_show_occupant_info(ProfWin *window, const char * const room, Occupant *occup win_vprint(window, '!', NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", occupant->status); } - win_save_newline(window); + win_newline(window); if (occupant->jid) { win_vprint(window, '!', NULL, 0, 0, "", " Jid: %s", occupant->jid); @@ -649,7 +649,7 @@ win_show_occupant_info(ProfWin *window, const char * const room, Occupant *occup if (caps->category != NULL) { win_print(window, '!', NULL, NO_DATE | NO_EOL, 0, "", caps->category); } - win_save_newline(window); + win_newline(window); } if (caps->software != NULL) { win_vprint(window, '!', NULL, NO_EOL, 0, "", " Software: %s", caps->software); @@ -658,7 +658,7 @@ win_show_occupant_info(ProfWin *window, const char * const room, Occupant *occup win_vprint(window, '!', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->software_version); } if ((caps->software != NULL) || (caps->software_version != NULL)) { - win_save_newline(window); + win_newline(window); } if (caps->os != NULL) { win_vprint(window, '!', NULL, NO_EOL, 0, "", " OS: %s", caps->os); @@ -667,7 +667,7 @@ win_show_occupant_info(ProfWin *window, const char * const room, Occupant *occup win_vprint(window, '!', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->os_version); } if ((caps->os != NULL) || (caps->os_version != NULL)) { - win_save_newline(window); + win_newline(window); } caps_destroy(caps); } @@ -742,7 +742,7 @@ win_show_info(ProfWin *window, PContact contact) if (resource->status != NULL) { win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", resource->status); } - win_save_newline(window); + win_newline(window); Jid *jidp = jid_create_from_bare_and_resource(barejid, resource->name); Capabilities *caps = caps_lookup(jidp->fulljid); @@ -767,7 +767,7 @@ win_show_info(ProfWin *window, PContact contact) if (caps->category != NULL) { win_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->category); } - win_save_newline(window); + win_newline(window); } if (caps->software != NULL) { win_vprint(window, '-', NULL, NO_EOL, 0, "", " Software: %s", caps->software); @@ -776,7 +776,7 @@ win_show_info(ProfWin *window, PContact contact) win_vprint(window, '-', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->software_version); } if ((caps->software != NULL) || (caps->software_version != NULL)) { - win_save_newline(window); + win_newline(window); } if (caps->os != NULL) { win_vprint(window, '-', NULL, NO_EOL, 0, "", " OS: %s", caps->os); @@ -785,7 +785,7 @@ win_show_info(ProfWin *window, PContact contact) win_vprint(window, '-', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->os_version); } if ((caps->os != NULL) || (caps->os_version != NULL)) { - win_save_newline(window); + win_newline(window); } caps_destroy(caps); } @@ -898,7 +898,7 @@ win_println(ProfWin *window, const char * const message) } void -win_save_newline(ProfWin *window) +win_newline(ProfWin *window) { win_print(window, '-', NULL, NO_DATE, 0, "", ""); } diff --git a/src/ui/window.h b/src/ui/window.h index 9b376171..b16d2609 100644 --- a/src/ui/window.h +++ b/src/ui/window.h @@ -171,7 +171,7 @@ void win_show_occupant_info(ProfWin *window, const char * const room, Occupant * void win_vprint(ProfWin *window, const char show_char, GTimeVal *tstamp, int flags, theme_item_t theme_item, const char * const from, const char * const message, ...); void win_print(ProfWin *window, const char show_char, GTimeVal *tstamp, int flags, theme_item_t theme_item, const char * const from, const char * const message); void win_println(ProfWin *window, const char * const message); -void win_save_newline(ProfWin *window); +void win_newline(ProfWin *window); void win_redraw(ProfWin *window); void win_hide_subwin(ProfWin *window); void win_show_subwin(ProfWin *window); From bc6e32175d703e5cf7b4ed7638ee7b60c521c298 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 14 Mar 2015 14:50:45 +0000 Subject: [PATCH 127/252] Removed from argument from outgoing message functions --- src/command/command.c | 8 ++++---- src/command/commands.c | 16 ++++++++-------- src/server_events.c | 2 +- src/ui/core.c | 12 +++++------- src/ui/ui.h | 6 ++---- tests/ui/stub_ui.c | 6 ++---- 6 files changed, 22 insertions(+), 28 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index 806a75f2..0bca4212 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -1960,7 +1960,7 @@ _cmd_execute_default(const char * inp) jid_destroy(jidp); } - ui_outgoing_chat_msg("me", chatwin->barejid, inp, id); + ui_outgoing_chat_msg(chatwin->barejid, inp, id); } else { cons_show_error("Failed to send message."); } @@ -1973,7 +1973,7 @@ _cmd_execute_default(const char * inp) jid_destroy(jidp); } - ui_outgoing_chat_msg("me", chatwin->barejid, inp, id); + ui_outgoing_chat_msg(chatwin->barejid, inp, id); } #else char *id = message_send_chat(chatwin->barejid, inp); @@ -1984,7 +1984,7 @@ _cmd_execute_default(const char * inp) jid_destroy(jidp); } - ui_outgoing_chat_msg("me", chatwin->barejid, inp, id); + ui_outgoing_chat_msg(chatwin->barejid, inp, id); #endif } break; @@ -1995,7 +1995,7 @@ _cmd_execute_default(const char * inp) } else { ProfPrivateWin *privatewin = wins_get_current_private(); message_send_private(privatewin->fulljid, inp); - ui_outgoing_private_msg("me", privatewin->fulljid, inp); + ui_outgoing_private_msg(privatewin->fulljid, inp); } break; diff --git a/src/command/commands.c b/src/command/commands.c index 549a733d..8075e2c0 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -1240,7 +1240,7 @@ cmd_msg(gchar **args, struct cmd_help_t help) if (msg != NULL) { message_send_private(full_jid->str, msg); - ui_outgoing_private_msg("me", full_jid->str, msg); + ui_outgoing_private_msg(full_jid->str, msg); } else { ui_new_private_win(full_jid->str); } @@ -1267,7 +1267,7 @@ cmd_msg(gchar **args, struct cmd_help_t help) if (encrypted != NULL) { char *id = message_send_chat_encrypted(barejid, encrypted); otr_free_message(encrypted); - ui_outgoing_chat_msg("me", barejid, msg, id); + ui_outgoing_chat_msg(barejid, msg, id); if (((win_type == WIN_CHAT) || (win_type == WIN_CONSOLE)) && prefs_get_boolean(PREF_CHLOG)) { const char *jid = jabber_get_fulljid(); @@ -1301,7 +1301,7 @@ cmd_msg(gchar **args, struct cmd_help_t help) } else { id = message_send_chat(barejid, msg); } - ui_outgoing_chat_msg("me", barejid, msg, id); + ui_outgoing_chat_msg(barejid, msg, id); if (((win_type == WIN_CHAT) || (win_type == WIN_CONSOLE)) && prefs_get_boolean(PREF_CHLOG)) { const char *jid = jabber_get_fulljid(); @@ -1313,7 +1313,7 @@ cmd_msg(gchar **args, struct cmd_help_t help) return TRUE; #else char *id = message_send_chat(barejid, msg); - ui_outgoing_chat_msg("me", barejid, msg, id); + ui_outgoing_chat_msg(barejid, msg, id); if (((win_type == WIN_CHAT) || (win_type == WIN_CONSOLE)) && prefs_get_boolean(PREF_CHLOG)) { const char *jid = jabber_get_fulljid(); @@ -3089,7 +3089,7 @@ cmd_tiny(gchar **args, struct cmd_help_t help) jid_destroy(jidp); } - ui_outgoing_chat_msg("me", chatwin->barejid, tiny, id); + ui_outgoing_chat_msg(chatwin->barejid, tiny, id); } else { cons_show_error("Failed to send message."); } @@ -3102,7 +3102,7 @@ cmd_tiny(gchar **args, struct cmd_help_t help) jid_destroy(jidp); } - ui_outgoing_chat_msg("me", chatwin->barejid, tiny, id); + ui_outgoing_chat_msg(chatwin->barejid, tiny, id); } #else char *id = message_send_chat(chatwin->barejid, tiny); @@ -3113,12 +3113,12 @@ cmd_tiny(gchar **args, struct cmd_help_t help) jid_destroy(jidp); } - ui_outgoing_chat_msg("me", chatwin->barejid, tiny, id); + ui_outgoing_chat_msg(chatwin->barejid, tiny, id); #endif } else if (win_type == WIN_PRIVATE) { ProfPrivateWin *privatewin = wins_get_current_private(); message_send_private(privatewin->fulljid, tiny); - ui_outgoing_private_msg("me", privatewin->fulljid, tiny); + ui_outgoing_private_msg(privatewin->fulljid, tiny); } else if (win_type == WIN_MUC) { ProfMucWin *mucwin = wins_get_current_muc(); message_send_groupchat(mucwin->roomjid, tiny); diff --git a/src/server_events.c b/src/server_events.c index 3d14f0aa..d7504b64 100644 --- a/src/server_events.c +++ b/src/server_events.c @@ -310,7 +310,7 @@ handle_incoming_private_message(char *fulljid, char *message) void handle_carbon(char *barejid, char *message){ - ui_outgoing_chat_msg("me", barejid, message, NULL); + ui_outgoing_chat_msg(barejid, message, NULL); } void diff --git a/src/ui/core.c b/src/ui/core.c index 08cddcb9..be49ed29 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -1423,8 +1423,7 @@ ui_open_xmlconsole_win(void) } void -ui_outgoing_chat_msg(const char * const from, const char * const barejid, - const char * const message, char *id) +ui_outgoing_chat_msg(const char * const barejid, const char * const message, char *id) { PContact contact = roster_get_contact(barejid); ProfWin *window = (ProfWin*)wins_get_chat(barejid); @@ -1464,18 +1463,17 @@ ui_outgoing_chat_msg(const char * const from, const char * const barejid, GString *message_with_id = g_string_new(id); g_string_append(message_with_id, ": "); g_string_append(message_with_id, message); - win_print(window, '-', NULL, 0, THEME_TEXT_ME, from, message_with_id->str); + win_print(window, '-', NULL, 0, THEME_TEXT_ME, "me", message_with_id->str); g_string_free(message_with_id, TRUE); free(id); } else { - win_print(window, '-', NULL, 0, THEME_TEXT_ME, from, message); + win_print(window, '-', NULL, 0, THEME_TEXT_ME, "me", message); } ui_switch_win(num); } void -ui_outgoing_private_msg(const char * const from, const char * const fulljid, - const char * const message) +ui_outgoing_private_msg(const char * const fulljid, const char * const message) { ProfWin *window = (ProfWin*)wins_get_private(fulljid); int num = 0; @@ -1490,7 +1488,7 @@ ui_outgoing_private_msg(const char * const from, const char * const fulljid, num = wins_get_num(window); } - win_print(window, '-', NULL, 0, THEME_TEXT_ME, from, message); + win_print(window, '-', NULL, 0, THEME_TEXT_ME, "me", message); ui_switch_win(num); } diff --git a/src/ui/ui.h b/src/ui/ui.h index a6428da3..9c8b9b4d 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -121,10 +121,8 @@ void ui_message_receipt(const char * const barejid, const char * const id); void ui_disconnected(void); void ui_recipient_gone(const char * const barejid, const char * const resource); -void ui_outgoing_chat_msg(const char * const from, const char * const barejid, - const char * const message, char *id); -void ui_outgoing_private_msg(const char * const from, const char * const fulljid, - const char * const message); +void ui_outgoing_chat_msg(const char * const barejid, const char * const message, char *id); +void ui_outgoing_private_msg(const char * const fulljid, const char * const message); void ui_room_join(const char * const roomjid, gboolean focus); void ui_switch_to_room(const char * const roomjid); diff --git a/tests/ui/stub_ui.c b/tests/ui/stub_ui.c index 4ae08ee7..802286ba 100644 --- a/tests/ui/stub_ui.c +++ b/tests/ui/stub_ui.c @@ -201,10 +201,8 @@ void ui_incoming_private_msg(const char * const fulljid, const char * const mess void ui_disconnected(void) {} void ui_recipient_gone(const char * const barejid, const char * const resource) {} -void ui_outgoing_chat_msg(const char * const from, const char * const barejid, - const char * const message, char *id) {} -void ui_outgoing_private_msg(const char * const from, const char * const fulljid, - const char * const message) {} +void ui_outgoing_chat_msg(const char * const barejid, const char * const message, char *id) {} +void ui_outgoing_private_msg(const char * const fulljid, const char * const message) {} void ui_room_join(const char * const roomjid, gboolean focus) {} void ui_switch_to_room(const char * const roomjid) {} From 1014244408caa2d74278603dcbece7857e7f7d4b Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 14 Mar 2015 16:05:13 +0000 Subject: [PATCH 128/252] Use colouring for message receipts --- src/ui/buffer.c | 25 ++++++++++++++++++++- src/ui/buffer.h | 12 +++++++++- src/ui/core.c | 14 +++--------- src/ui/window.c | 58 +++++++++++++++++++++++++++++++++++++++++++------ src/ui/window.h | 3 +++ 5 files changed, 92 insertions(+), 20 deletions(-) diff --git a/src/ui/buffer.c b/src/ui/buffer.c index da505867..d16eec76 100644 --- a/src/ui/buffer.c +++ b/src/ui/buffer.c @@ -81,7 +81,7 @@ buffer_free(ProfBuff buffer) void buffer_push(ProfBuff buffer, const char show_char, GDateTime *time, - int flags, theme_item_t theme_item, const char * const from, const char * const message) + int flags, theme_item_t theme_item, const char * const from, const char * const message, DeliveryReceipt *receipt) { ProfBuffEntry *e = malloc(sizeof(struct prof_buff_entry_t)); e->show_char = show_char; @@ -90,6 +90,7 @@ buffer_push(ProfBuff buffer, const char show_char, GDateTime *time, e->time = time; e->from = strdup(from); e->message = strdup(message); + e->receipt = receipt; if (g_slist_length(buffer->entries) == BUFF_SIZE) { _free_entry(buffer->entries->data); @@ -99,6 +100,24 @@ buffer_push(ProfBuff buffer, const char show_char, GDateTime *time, buffer->entries = g_slist_append(buffer->entries, e); } +gboolean +buffer_mark_received(ProfBuff buffer, const char * const id) +{ + GSList *entries = buffer->entries; + while (entries) { + ProfBuffEntry *entry = entries->data; + if (entry->receipt) { + if (!entry->receipt->received) { + entry->receipt->received = TRUE; + return TRUE; + } + } + entries = g_slist_next(entries); + } + + return FALSE; +} + ProfBuffEntry* buffer_yield_entry(ProfBuff buffer, int entry) { @@ -113,4 +132,8 @@ _free_entry(ProfBuffEntry *entry) free(entry->from); g_date_time_unref(entry->time); free(entry); + if (entry->receipt) { + free(entry->receipt->id); + free(entry->receipt); + } } \ No newline at end of file diff --git a/src/ui/buffer.h b/src/ui/buffer.h index 5258b8c1..cad7eee0 100644 --- a/src/ui/buffer.h +++ b/src/ui/buffer.h @@ -40,6 +40,11 @@ #include +typedef struct delivery_receipt_t { + char *id; + gboolean received; +} DeliveryReceipt; + typedef struct prof_buff_entry_t { char show_char; GDateTime *time; @@ -47,13 +52,18 @@ typedef struct prof_buff_entry_t { theme_item_t theme_item; char *from; char *message; + DeliveryReceipt *receipt; } ProfBuffEntry; typedef struct prof_buff_t *ProfBuff; ProfBuff buffer_create(); void buffer_free(ProfBuff buffer); -void buffer_push(ProfBuff buffer, const char show_char, GDateTime *time, int flags, theme_item_t theme_item, const char * const from, const char * const message); +void buffer_push(ProfBuff buffer, const char show_char, GDateTime *time, int flags, theme_item_t theme_item, + const char * const from, const char * const message, DeliveryReceipt *receipt); int buffer_size(ProfBuff buffer); ProfBuffEntry* buffer_yield_entry(ProfBuff buffer, int entry); +gboolean buffer_mark_received(ProfBuff buffer, const char * const id); + + #endif diff --git a/src/ui/core.c b/src/ui/core.c index be49ed29..aa77e32e 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -387,10 +387,7 @@ ui_message_receipt(const char * const barejid, const char * const id) ProfChatWin *chatwin = wins_get_chat(barejid); if (chatwin) { ProfWin *win = (ProfWin*) chatwin; - GString *message = g_string_new("Message received: "); - g_string_append(message, id); - win_println(win, message->str); - g_string_free(message, TRUE); + win_mark_received(win, id); } } @@ -1459,13 +1456,8 @@ ui_outgoing_chat_msg(const char * const barejid, const char * const message, cha ProfChatWin *chatwin = (ProfChatWin*)window; chat_state_active(chatwin->state); - if (id) { - GString *message_with_id = g_string_new(id); - g_string_append(message_with_id, ": "); - g_string_append(message_with_id, message); - win_print(window, '-', NULL, 0, THEME_TEXT_ME, "me", message_with_id->str); - g_string_free(message_with_id, TRUE); - free(id); + if (prefs_get_boolean(PREF_RECEIPTS) && id) { + win_print_with_receipt(window, '-', NULL, 0, THEME_TEXT_ME, "me", message, id); } else { win_print(window, '-', NULL, 0, THEME_TEXT_ME, "me", message); } diff --git a/src/ui/window.c b/src/ui/window.c index d5b30228..81408403 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -59,7 +59,7 @@ #define CEILING(X) (X-(int)(X) > 0 ? (int)(X+1) : (int)(X)) static void _win_print(ProfWin *window, const char show_char, GDateTime *time, - int flags, theme_item_t theme_item, const char * const from, const char * const message); + int flags, theme_item_t theme_item, const char * const from, const char * const message, DeliveryReceipt *receipt); static void _win_print_wrapped(WINDOW *win, const char * const message); int @@ -885,12 +885,44 @@ win_print(ProfWin *window, const char show_char, GTimeVal *tstamp, time = g_date_time_new_from_timeval_utc(tstamp); } - buffer_push(window->layout->buffer, show_char, time, flags, theme_item, from, message); - _win_print(window, show_char, time, flags, theme_item, from, message); + buffer_push(window->layout->buffer, show_char, time, flags, theme_item, from, message, NULL); + _win_print(window, show_char, time, flags, theme_item, from, message, NULL); // TODO: cross-reference.. this should be replaced by a real event-based system ui_input_nonblocking(TRUE); } +void +win_print_with_receipt(ProfWin *window, const char show_char, GTimeVal *tstamp, + int flags, theme_item_t theme_item, const char * const from, const char * const message, char *id) +{ + GDateTime *time; + + if (tstamp == NULL) { + time = g_date_time_new_now_local(); + } else { + time = g_date_time_new_from_timeval_utc(tstamp); + } + + DeliveryReceipt *receipt = malloc(sizeof(struct delivery_receipt_t)); + receipt->id = strdup(id); + receipt->received = FALSE; + free(id); + + buffer_push(window->layout->buffer, show_char, time, flags, theme_item, from, message, receipt); + _win_print(window, show_char, time, flags, theme_item, from, message, receipt); + // TODO: cross-reference.. this should be replaced by a real event-based system + ui_input_nonblocking(TRUE); +} + +void +win_mark_received(ProfWin *window, const char * const id) +{ + gboolean received = buffer_mark_received(window->layout->buffer, id); + if (received) { + win_redraw(window); + } +} + void win_println(ProfWin *window, const char * const message) { @@ -905,7 +937,7 @@ win_newline(ProfWin *window) static void _win_print(ProfWin *window, const char show_char, GDateTime *time, - int flags, theme_item_t theme_item, const char * const from, const char * const message) + int flags, theme_item_t theme_item, const char * const from, const char * const message, DeliveryReceipt *receipt) { // flags : 1st bit = 0/1 - me/not me // 2nd bit = 0/1 - date/no date @@ -947,6 +979,10 @@ _win_print(ProfWin *window, const char show_char, GDateTime *time, colour = 0; } + if (receipt && !receipt->received) { + colour = theme_attrs(THEME_BLACK_BOLD); + } + wattron(window->layout->win, colour); if (strncmp(message, "/me ", 4) == 0) { wprintw(window->layout->win, "*%s ", from); @@ -959,7 +995,11 @@ _win_print(ProfWin *window, const char show_char, GDateTime *time, } if (!me_message) { - wattron(window->layout->win, theme_attrs(theme_item)); + if (receipt && !receipt->received) { + wattron(window->layout->win, theme_attrs(THEME_BLACK_BOLD)); + } else { + wattron(window->layout->win, theme_attrs(theme_item)); + } } if (prefs_get_boolean(PREF_WRAP)) { @@ -975,7 +1015,11 @@ _win_print(ProfWin *window, const char show_char, GDateTime *time, if (me_message) { wattroff(window->layout->win, colour); } else { - wattroff(window->layout->win, theme_attrs(theme_item)); + if (receipt && !receipt->received) { + wattroff(window->layout->win, theme_attrs(THEME_BLACK_BOLD)); + } else { + wattroff(window->layout->win, theme_attrs(theme_item)); + } } } @@ -1074,7 +1118,7 @@ win_redraw(ProfWin *window) for (i = 0; i < size; i++) { ProfBuffEntry *e = buffer_yield_entry(window->layout->buffer, i); - _win_print(window, e->show_char, e->time, e->flags, e->theme_item, e->from, e->message); + _win_print(window, e->show_char, e->time, e->flags, e->theme_item, e->from, e->message, e->receipt); } } diff --git a/src/ui/window.h b/src/ui/window.h index b16d2609..f525e5fa 100644 --- a/src/ui/window.h +++ b/src/ui/window.h @@ -170,6 +170,8 @@ void win_show_info(ProfWin *window, PContact contact); void win_show_occupant_info(ProfWin *window, const char * const room, Occupant *occupant); void win_vprint(ProfWin *window, const char show_char, GTimeVal *tstamp, int flags, theme_item_t theme_item, const char * const from, const char * const message, ...); void win_print(ProfWin *window, const char show_char, GTimeVal *tstamp, int flags, theme_item_t theme_item, const char * const from, const char * const message); +void win_print_with_receipt(ProfWin *window, const char show_char, GTimeVal *tstamp, int flags, + theme_item_t theme_item, const char * const from, const char * const message, char *id); void win_println(ProfWin *window, const char * const message); void win_newline(ProfWin *window); void win_redraw(ProfWin *window); @@ -179,6 +181,7 @@ int win_roster_cols(void); int win_occpuants_cols(void); void win_printline_nowrap(WINDOW *win, char *msg); void win_mouse(ProfWin *current, const wint_t ch, const int result); +void win_mark_received(ProfWin *window, const char * const id); int win_unread(ProfWin *window); gboolean win_has_active_subwin(ProfWin *window); From 2fc7937dcd6949bb322bbfdd33c903792324719b Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 14 Mar 2015 16:37:33 +0000 Subject: [PATCH 129/252] Fixed error with /otr start with carbons enabled --- src/xmpp/message.c | 73 ++++++++++++++++++++++++---------------------- 1 file changed, 38 insertions(+), 35 deletions(-) diff --git a/src/xmpp/message.c b/src/xmpp/message.c index ab7f52cd..c0c37f4d 100644 --- a/src/xmpp/message.c +++ b/src/xmpp/message.c @@ -452,46 +452,49 @@ _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, } // check if carbon message - xmpp_stanza_t *received = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_CARBONS); - if(received != NULL){ - xmpp_stanza_t *forwarded = xmpp_stanza_get_child_by_ns(received, STANZA_NS_FORWARD); - xmpp_stanza_t *message = xmpp_stanza_get_child_by_name(forwarded, STANZA_NAME_MESSAGE); + xmpp_stanza_t *carbons = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_CARBONS); + if(carbons) { + char *name = xmpp_stanza_get_name(carbons); + if (g_strcmp0(name, "received") == 0) { + xmpp_stanza_t *forwarded = xmpp_stanza_get_child_by_ns(carbons, STANZA_NS_FORWARD); + xmpp_stanza_t *message = xmpp_stanza_get_child_by_name(forwarded, STANZA_NAME_MESSAGE); - xmpp_ctx_t *ctx = connection_get_ctx(); + xmpp_ctx_t *ctx = connection_get_ctx(); - gchar *to = xmpp_stanza_get_attribute(message, STANZA_ATTR_TO); - gchar *from = xmpp_stanza_get_attribute(message, STANZA_ATTR_FROM); + gchar *to = xmpp_stanza_get_attribute(message, STANZA_ATTR_TO); + gchar *from = xmpp_stanza_get_attribute(message, STANZA_ATTR_FROM); - // happens when receive a carbon of a self sent message - if(to == NULL) { - to = from; - } - - Jid *jid_from = jid_create(from); - Jid *jid_to = jid_create(to); - Jid *my_jid = jid_create(jabber_get_fulljid()); - - // check for and deal with message - xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(message, STANZA_NAME_BODY); - if (body != NULL) { - char *message = xmpp_stanza_get_text(body); - if (message != NULL) { - // if we are the recipient, treat as standard incoming message - if(g_strcmp0(my_jid->barejid, jid_to->barejid) == 0){ - handle_incoming_message(jid_from->barejid, jid_from->resourcepart, message); - } - // else treat as a sent message - else{ - handle_carbon(jid_to->barejid, message); - } - xmpp_free(ctx, message); + // happens when receive a carbon of a self sent message + if(to == NULL) { + to = from; } - } - jid_destroy(jid_from); - jid_destroy(jid_to); - jid_destroy(my_jid); - return 1; + Jid *jid_from = jid_create(from); + Jid *jid_to = jid_create(to); + Jid *my_jid = jid_create(jabber_get_fulljid()); + + // check for and deal with message + xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(message, STANZA_NAME_BODY); + if (body != NULL) { + char *message = xmpp_stanza_get_text(body); + if (message != NULL) { + // if we are the recipient, treat as standard incoming message + if(g_strcmp0(my_jid->barejid, jid_to->barejid) == 0){ + handle_incoming_message(jid_from->barejid, jid_from->resourcepart, message); + } + // else treat as a sent message + else{ + handle_carbon(jid_to->barejid, message); + } + xmpp_free(ctx, message); + } + } + + jid_destroy(jid_from); + jid_destroy(jid_to); + jid_destroy(my_jid); + return 1; + } } // ignore handled namespaces From ede3368f7ad0f66928cdf506f3c51ffe64653a89 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 14 Mar 2015 16:44:21 +0000 Subject: [PATCH 130/252] Check for sent and received carbons --- src/xmpp/message.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/xmpp/message.c b/src/xmpp/message.c index c0c37f4d..a3da01ee 100644 --- a/src/xmpp/message.c +++ b/src/xmpp/message.c @@ -455,7 +455,7 @@ _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, xmpp_stanza_t *carbons = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_CARBONS); if(carbons) { char *name = xmpp_stanza_get_name(carbons); - if (g_strcmp0(name, "received") == 0) { + if ((g_strcmp0(name, "received") == 0) || (g_strcmp0(name, "sent")) == 0){ xmpp_stanza_t *forwarded = xmpp_stanza_get_child_by_ns(carbons, STANZA_NS_FORWARD); xmpp_stanza_t *message = xmpp_stanza_get_child_by_name(forwarded, STANZA_NAME_MESSAGE); From 385336c10b0026025d4cd3a32d0a9b1bc521469a Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 14 Mar 2015 22:59:49 +0000 Subject: [PATCH 131/252] Don't switch window on sent carbon --- src/server_events.c | 2 +- src/ui/core.c | 42 ++++++++++++++++++++++++++++++++++++++++++ src/ui/ui.h | 2 ++ tests/ui/stub_ui.c | 2 ++ 4 files changed, 47 insertions(+), 1 deletion(-) diff --git a/src/server_events.c b/src/server_events.c index b0a9b1e3..fc115d95 100644 --- a/src/server_events.c +++ b/src/server_events.c @@ -310,7 +310,7 @@ handle_incoming_private_message(char *fulljid, char *message) void handle_carbon(char *barejid, char *message){ - ui_outgoing_chat_msg("me", barejid, message); + ui_outgoing_chat_msg_carbon("me", barejid, message); } void diff --git a/src/ui/core.c b/src/ui/core.c index b9f526cc..967a379f 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -1451,6 +1451,48 @@ ui_outgoing_chat_msg(const char * const from, const char * const barejid, ui_switch_win(num); } +void +ui_outgoing_chat_msg_carbon(const char * const from, const char * const barejid, + const char * const message) +{ + PContact contact = roster_get_contact(barejid); + ProfWin *window = (ProfWin*)wins_get_chat(barejid); + int num = 0; + + // create new window + if (window == NULL) { + window = wins_new_chat(barejid); +#ifdef HAVE_LIBOTR + ProfChatWin *chatwin = (ProfChatWin*)window; + if (otr_is_secure(barejid)) { + chatwin->is_otr = TRUE; + } +#endif + num = wins_get_num(window); + + if (prefs_get_boolean(PREF_CHLOG) && prefs_get_boolean(PREF_HISTORY)) { + _win_show_history(num, barejid); + } + + if (contact != NULL) { + if (strcmp(p_contact_presence(contact), "offline") == 0) { + const char *show = p_contact_presence(contact); + const char *status = p_contact_status(contact); + win_show_status_string(window, barejid, show, status, NULL, "--", "offline"); + } + } + + // use existing window + } else { + num = wins_get_num(window); + } + ProfChatWin *chatwin = (ProfChatWin*)window; + chat_state_active(chatwin->state); + + win_save_print(window, '-', NULL, 0, THEME_TEXT_ME, from, message); + status_bar_active(num); +} + void ui_outgoing_private_msg(const char * const from, const char * const fulljid, const char * const message) diff --git a/src/ui/ui.h b/src/ui/ui.h index a0408503..c7ffda83 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -122,6 +122,8 @@ void ui_recipient_gone(const char * const barejid, const char * const resource); void ui_outgoing_chat_msg(const char * const from, const char * const barejid, const char * const message); +void ui_outgoing_chat_msg_carbon(const char * const from, const char * const barejid, + const char * const message); void ui_outgoing_private_msg(const char * const from, const char * const fulljid, const char * const message); diff --git a/tests/ui/stub_ui.c b/tests/ui/stub_ui.c index 1a0f650d..eb700856 100644 --- a/tests/ui/stub_ui.c +++ b/tests/ui/stub_ui.c @@ -201,6 +201,8 @@ void ui_recipient_gone(const char * const barejid, const char * const resource) void ui_outgoing_chat_msg(const char * const from, const char * const barejid, const char * const message) {} +void ui_outgoing_chat_msg_carbon(const char * const from, const char * const barejid, + const char * const message) {} void ui_outgoing_private_msg(const char * const from, const char * const fulljid, const char * const message) {} From 125719673b009b32ab0bc7223489589a44939d32 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 14 Mar 2015 23:25:20 +0000 Subject: [PATCH 132/252] Return after message receipt --- src/xmpp/message.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/xmpp/message.c b/src/xmpp/message.c index 5663dbfc..7986c668 100644 --- a/src/xmpp/message.c +++ b/src/xmpp/message.c @@ -516,8 +516,8 @@ _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, Jid *jidp = jid_create(fulljid); handle_message_receipt(jidp->barejid, id); jid_destroy(jidp); + return 1; } - } } } From 49022068efc35709db9c6bb7ca9c0c546db7673c Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 15 Mar 2015 01:26:09 +0000 Subject: [PATCH 133/252] Added OTR error messages --- src/otr/otrlibv4.c | 57 +++++++++++++++++++++++++++++++++++++++++----- src/ui/core.c | 11 +++++++++ src/ui/ui.h | 2 ++ 3 files changed, 64 insertions(+), 6 deletions(-) diff --git a/src/otr/otrlibv4.c b/src/otr/otrlibv4.c index e090ead4..713e51ab 100644 --- a/src/otr/otrlibv4.c +++ b/src/otr/otrlibv4.c @@ -113,12 +113,57 @@ cb_handle_msg_event(void *opdata, OtrlMessageEvent msg_event, ConnContext *context, const char *message, gcry_error_t err) { - if (err != 0) { - if (message != NULL) { - cons_show_error("%s", message); - } else { - cons_show_error("OTR error event with no message."); - } + GString *err_msg; + switch (msg_event) + { + case OTRL_MSGEVENT_ENCRYPTION_REQUIRED: + ui_handle_otr_error(context->username, "OTR: Policy requires encryption, but attempting to send an unencrypted message."); + break; + case OTRL_MSGEVENT_ENCRYPTION_ERROR: + ui_handle_otr_error(context->username, "OTR: Error occured while encrypting a message, message not sent."); + break; + case OTRL_MSGEVENT_CONNECTION_ENDED: + ui_handle_otr_error(context->username, "OTR: Message not sent because contact has ended the private conversation."); + break; + case OTRL_MSGEVENT_SETUP_ERROR: + ui_handle_otr_error(context->username, "OTR: A private conversation could not be set up."); + break; + case OTRL_MSGEVENT_MSG_REFLECTED: + ui_handle_otr_error(context->username, "OTR: Received our own OTR message."); + break; + case OTRL_MSGEVENT_MSG_RESENT: + ui_handle_otr_error(context->username, "OTR: The previous message was resent."); + break; + case OTRL_MSGEVENT_RCVDMSG_NOT_IN_PRIVATE: + ui_handle_otr_error(context->username, "OTR: Received an encrypted message but no private connection established."); + break; + case OTRL_MSGEVENT_RCVDMSG_UNREADABLE: + ui_handle_otr_error(context->username, "OTR: Cannot read the received message."); + break; + case OTRL_MSGEVENT_RCVDMSG_MALFORMED: + ui_handle_otr_error(context->username, "OTR: The message received contains malformed data."); + break; + case OTRL_MSGEVENT_RCVDMSG_GENERAL_ERR: + err_msg = g_string_new("OTR: Received error: "); + g_string_append(err_msg, message); + g_string_append(err_msg, "."); + ui_handle_otr_error(context->username, err_msg->str); + g_string_free(err_msg, TRUE); + break; + case OTRL_MSGEVENT_RCVDMSG_UNENCRYPTED: + err_msg = g_string_new("OTR: Received an unencrypted message: "); + g_string_append(err_msg, message); + ui_handle_otr_error(context->username, err_msg->str); + g_string_free(err_msg, TRUE); + break; + case OTRL_MSGEVENT_RCVDMSG_UNRECOGNIZED: + ui_handle_otr_error(context->username, "OTR: Cannot recognize the type of message received."); + break; + case OTRL_MSGEVENT_RCVDMSG_FOR_OTHER_INSTANCE: + ui_handle_otr_error(context->username, "OTR: Received and discarded a message intended for another instance."); + break; + default: + break; } } diff --git a/src/ui/core.c b/src/ui/core.c index 967a379f..3a65b270 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -1107,6 +1107,17 @@ ui_otr_authetication_waiting(const char * const barejid) } } +void +ui_handle_otr_error(const char * const barejid, const char * const message) +{ + ProfChatWin *chatwin = wins_get_chat(barejid); + if (chatwin) { + win_save_print((ProfWin*)chatwin, '!', NULL, 0, THEME_ERROR, "", message); + } else { + cons_show_error(message); + } +} + void ui_trust(const char * const barejid) { diff --git a/src/ui/ui.h b/src/ui/ui.h index c7ffda83..dfb8c0a9 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -82,6 +82,8 @@ void ui_smp_answer_failure(const char * const barejid); void ui_otr_authenticating(const char * const barejid); void ui_otr_authetication_waiting(const char * const recipient); +void ui_handle_otr_error(const char * const barejid, const char * const message); + unsigned long ui_get_idle_time(void); void ui_reset_idle_time(void); void ui_new_chat_win(const char * const barejid); From 448c91af61ab9269c9a862e73421721e73074aa7 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 15 Mar 2015 01:30:27 +0000 Subject: [PATCH 134/252] Fixed merge --- src/ui/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ui/core.c b/src/ui/core.c index 79a64931..c00c7838 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -1122,7 +1122,7 @@ ui_handle_otr_error(const char * const barejid, const char * const message) { ProfChatWin *chatwin = wins_get_chat(barejid); if (chatwin) { - win_save_print((ProfWin*)chatwin, '!', NULL, 0, THEME_ERROR, "", message); + win_print((ProfWin*)chatwin, '!', NULL, 0, THEME_ERROR, "", message); } else { cons_show_error(message); } From f0ffceefdd1b9ddb2cd63c2fa4fb6f15d7c0e635 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 15 Mar 2015 15:30:16 +0000 Subject: [PATCH 135/252] Added freebsd check for libnotify --- configure.ac | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index ec599f7c..0653ab68 100644 --- a/configure.ac +++ b/configure.ac @@ -149,7 +149,7 @@ AS_IF([test "x$PLATFORM" != xosx], AS_IF([test "x$PLATFORM" = xosx], [LIBS="-lcurl $LIBS"]) ### Check for desktop notification support -### Linux requires libnotify +### Linux/FreeBSD require libnotify ### Windows uses native OS calls ### OSX requires terminal-notifier @@ -162,7 +162,7 @@ AS_IF([test "x$PLATFORM" = xosx], [AC_MSG_ERROR([terminal-notifier not found, required for desktop notifications.])], [AC_MSG_NOTICE([Desktop notifications not supported.])])], [AC_DEFINE([HAVE_OSXNOTIFY], [1], [terminal notifier])])])], - [test "x$PLATFORM" = xnix], + [test "x$PLATFORM" = xnix -o "x$PLATFORM" = xfreebsd], [AS_IF([test "x$enable_notifications" != xno], [PKG_CHECK_MODULES([libnotify], [libnotify], [AC_DEFINE([HAVE_LIBNOTIFY], [1], [libnotify module])], From b21edfaa51e1a4e6cbfb22fa501a4c38bb4189b7 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 15 Mar 2015 19:35:25 +0000 Subject: [PATCH 136/252] Added receipt.sent theme setting --- src/config/theme.c | 128 +++++++++++++++++++++-------------------- src/config/theme.h | 1 + src/ui/window.c | 6 +- theme_template | 3 +- themes/aqua | 1 + themes/batman | 4 +- themes/boothj5 | 1 + themes/forest | 3 +- themes/hacker | 3 +- themes/headache | 3 +- themes/joker | 3 +- themes/mono | 3 +- themes/orange | 3 +- themes/original | 3 +- themes/original_bright | 1 + themes/shade | 3 +- themes/spawn | 3 +- themes/whiteness | 3 +- 18 files changed, 97 insertions(+), 78 deletions(-) diff --git a/src/config/theme.c b/src/config/theme.c index 3aeadf40..5b358ba3 100644 --- a/src/config/theme.c +++ b/src/config/theme.c @@ -121,6 +121,7 @@ static struct colours_t { NCURSES_COLOR_T otruntrusted; NCURSES_COLOR_T rosterheader; NCURSES_COLOR_T occupantsheader; + NCURSES_COLOR_T receiptsent; } colour_prefs; static NCURSES_COLOR_T _lookup_colour(const char * const colour); @@ -251,47 +252,48 @@ theme_init_colours(void) // chat init_pair(25, colour_prefs.me, colour_prefs.bkgnd); init_pair(26, colour_prefs.them, colour_prefs.bkgnd); + init_pair(27, colour_prefs.receiptsent, colour_prefs.bkgnd); // room chat - init_pair(27, colour_prefs.roominfo, colour_prefs.bkgnd); - init_pair(28, colour_prefs.roommention, colour_prefs.bkgnd); + init_pair(28, colour_prefs.roominfo, colour_prefs.bkgnd); + init_pair(29, colour_prefs.roommention, colour_prefs.bkgnd); // statuses - init_pair(29, colour_prefs.online, colour_prefs.bkgnd); - init_pair(30, colour_prefs.offline, colour_prefs.bkgnd); - init_pair(31, colour_prefs.away, colour_prefs.bkgnd); - init_pair(32, colour_prefs.chat, colour_prefs.bkgnd); - init_pair(33, colour_prefs.dnd, colour_prefs.bkgnd); - init_pair(34, colour_prefs.xa, colour_prefs.bkgnd); + init_pair(30, colour_prefs.online, colour_prefs.bkgnd); + init_pair(31, colour_prefs.offline, colour_prefs.bkgnd); + init_pair(32, colour_prefs.away, colour_prefs.bkgnd); + init_pair(33, colour_prefs.chat, colour_prefs.bkgnd); + init_pair(34, colour_prefs.dnd, colour_prefs.bkgnd); + init_pair(35, colour_prefs.xa, colour_prefs.bkgnd); // states - init_pair(35, colour_prefs.typing, colour_prefs.bkgnd); - init_pair(36, colour_prefs.gone, colour_prefs.bkgnd); + init_pair(36, colour_prefs.typing, colour_prefs.bkgnd); + init_pair(37, colour_prefs.gone, colour_prefs.bkgnd); // subscription status - init_pair(37, colour_prefs.subscribed, colour_prefs.bkgnd); - init_pair(38, colour_prefs.unsubscribed, colour_prefs.bkgnd); + init_pair(38, colour_prefs.subscribed, colour_prefs.bkgnd); + init_pair(39, colour_prefs.unsubscribed, colour_prefs.bkgnd); // otr messages - init_pair(39, colour_prefs.otrstartedtrusted, colour_prefs.bkgnd); - init_pair(40, colour_prefs.otrstarteduntrusted, colour_prefs.bkgnd); - init_pair(41, colour_prefs.otrended, colour_prefs.bkgnd); - init_pair(42, colour_prefs.otrtrusted, colour_prefs.bkgnd); - init_pair(43, colour_prefs.otruntrusted, colour_prefs.bkgnd); + init_pair(40, colour_prefs.otrstartedtrusted, colour_prefs.bkgnd); + init_pair(41, colour_prefs.otrstarteduntrusted, colour_prefs.bkgnd); + init_pair(42, colour_prefs.otrended, colour_prefs.bkgnd); + init_pair(43, colour_prefs.otrtrusted, colour_prefs.bkgnd); + init_pair(44, colour_prefs.otruntrusted, colour_prefs.bkgnd); // subwin headers - init_pair(44, colour_prefs.rosterheader, colour_prefs.bkgnd); - init_pair(45, colour_prefs.occupantsheader, colour_prefs.bkgnd); + init_pair(45, colour_prefs.rosterheader, colour_prefs.bkgnd); + init_pair(46, colour_prefs.occupantsheader, colour_prefs.bkgnd); // raw - init_pair(46, COLOR_WHITE, colour_prefs.bkgnd); - init_pair(47, COLOR_GREEN, colour_prefs.bkgnd); - init_pair(48, COLOR_RED, colour_prefs.bkgnd); - init_pair(49, COLOR_YELLOW, colour_prefs.bkgnd); - init_pair(50, COLOR_BLUE, colour_prefs.bkgnd); - init_pair(51, COLOR_CYAN, colour_prefs.bkgnd); - init_pair(52, COLOR_BLACK, colour_prefs.bkgnd); - init_pair(53, COLOR_MAGENTA, colour_prefs.bkgnd); + init_pair(47, COLOR_WHITE, colour_prefs.bkgnd); + init_pair(48, COLOR_GREEN, colour_prefs.bkgnd); + init_pair(49, COLOR_RED, colour_prefs.bkgnd); + init_pair(50, COLOR_YELLOW, colour_prefs.bkgnd); + init_pair(51, COLOR_BLUE, colour_prefs.bkgnd); + init_pair(52, COLOR_CYAN, colour_prefs.bkgnd); + init_pair(53, COLOR_BLACK, colour_prefs.bkgnd); + init_pair(54, COLOR_MAGENTA, colour_prefs.bkgnd); } static NCURSES_COLOR_T @@ -397,6 +399,7 @@ _load_colours(void) _set_colour("them", &colour_prefs.them, COLOR_GREEN, THEME_THEM); _set_colour("roster.header", &colour_prefs.rosterheader, COLOR_YELLOW, THEME_ROSTER_HEADER); _set_colour("occupants.header", &colour_prefs.occupantsheader, COLOR_YELLOW, THEME_OCCUPANTS_HEADER); + _set_colour("receipt.sent", &colour_prefs.receiptsent, COLOR_RED, THEME_RECEIPT_SENT); } static void @@ -564,41 +567,42 @@ theme_attrs(theme_item_t attrs) case THEME_STATUS_NEW: result = COLOR_PAIR(24); break; case THEME_ME: result = COLOR_PAIR(25); break; case THEME_THEM: result = COLOR_PAIR(26); break; - case THEME_ROOMINFO: result = COLOR_PAIR(27); break; - case THEME_ROOMMENTION: result = COLOR_PAIR(28); break; - case THEME_ONLINE: result = COLOR_PAIR(29); break; - case THEME_OFFLINE: result = COLOR_PAIR(30); break; - case THEME_AWAY: result = COLOR_PAIR(31); break; - case THEME_CHAT: result = COLOR_PAIR(32); break; - case THEME_DND: result = COLOR_PAIR(33); break; - case THEME_XA: result = COLOR_PAIR(34); break; - case THEME_TYPING: result = COLOR_PAIR(35); break; - case THEME_GONE: result = COLOR_PAIR(36); break; - case THEME_SUBSCRIBED: result = COLOR_PAIR(37); break; - case THEME_UNSUBSCRIBED: result = COLOR_PAIR(38); break; - case THEME_OTR_STARTED_TRUSTED: result = COLOR_PAIR(39); break; - case THEME_OTR_STARTED_UNTRUSTED: result = COLOR_PAIR(40); break; - case THEME_OTR_ENDED: result = COLOR_PAIR(41); break; - case THEME_OTR_TRUSTED: result = COLOR_PAIR(42); break; - case THEME_OTR_UNTRUSTED: result = COLOR_PAIR(43); break; - case THEME_ROSTER_HEADER: result = COLOR_PAIR(44); break; - case THEME_OCCUPANTS_HEADER: result = COLOR_PAIR(45); break; - case THEME_WHITE: result = COLOR_PAIR(46); break; - case THEME_WHITE_BOLD: result = COLOR_PAIR(46); break; - case THEME_GREEN: result = COLOR_PAIR(47); break; - case THEME_GREEN_BOLD: result = COLOR_PAIR(47); break; - case THEME_RED: result = COLOR_PAIR(48); break; - case THEME_RED_BOLD: result = COLOR_PAIR(48); break; - case THEME_YELLOW: result = COLOR_PAIR(49); break; - case THEME_YELLOW_BOLD: result = COLOR_PAIR(49); break; - case THEME_BLUE: result = COLOR_PAIR(50); break; - case THEME_BLUE_BOLD: result = COLOR_PAIR(50); break; - case THEME_CYAN: result = COLOR_PAIR(51); break; - case THEME_CYAN_BOLD: result = COLOR_PAIR(51); break; - case THEME_BLACK: result = COLOR_PAIR(52); break; - case THEME_BLACK_BOLD: result = COLOR_PAIR(52); break; - case THEME_MAGENTA: result = COLOR_PAIR(53); break; - case THEME_MAGENTA_BOLD: result = COLOR_PAIR(53); break; + case THEME_RECEIPT_SENT: result = COLOR_PAIR(27); break; + case THEME_ROOMINFO: result = COLOR_PAIR(28); break; + case THEME_ROOMMENTION: result = COLOR_PAIR(29); break; + case THEME_ONLINE: result = COLOR_PAIR(30); break; + case THEME_OFFLINE: result = COLOR_PAIR(31); break; + case THEME_AWAY: result = COLOR_PAIR(32); break; + case THEME_CHAT: result = COLOR_PAIR(33); break; + case THEME_DND: result = COLOR_PAIR(34); break; + case THEME_XA: result = COLOR_PAIR(35); break; + case THEME_TYPING: result = COLOR_PAIR(36); break; + case THEME_GONE: result = COLOR_PAIR(37); break; + case THEME_SUBSCRIBED: result = COLOR_PAIR(38); break; + case THEME_UNSUBSCRIBED: result = COLOR_PAIR(39); break; + case THEME_OTR_STARTED_TRUSTED: result = COLOR_PAIR(40); break; + case THEME_OTR_STARTED_UNTRUSTED: result = COLOR_PAIR(41); break; + case THEME_OTR_ENDED: result = COLOR_PAIR(42); break; + case THEME_OTR_TRUSTED: result = COLOR_PAIR(43); break; + case THEME_OTR_UNTRUSTED: result = COLOR_PAIR(44); break; + case THEME_ROSTER_HEADER: result = COLOR_PAIR(45); break; + case THEME_OCCUPANTS_HEADER: result = COLOR_PAIR(46); break; + case THEME_WHITE: result = COLOR_PAIR(47); break; + case THEME_WHITE_BOLD: result = COLOR_PAIR(47); break; + case THEME_GREEN: result = COLOR_PAIR(48); break; + case THEME_GREEN_BOLD: result = COLOR_PAIR(48); break; + case THEME_RED: result = COLOR_PAIR(49); break; + case THEME_RED_BOLD: result = COLOR_PAIR(49); break; + case THEME_YELLOW: result = COLOR_PAIR(50); break; + case THEME_YELLOW_BOLD: result = COLOR_PAIR(50); break; + case THEME_BLUE: result = COLOR_PAIR(51); break; + case THEME_BLUE_BOLD: result = COLOR_PAIR(51); break; + case THEME_CYAN: result = COLOR_PAIR(52); break; + case THEME_CYAN_BOLD: result = COLOR_PAIR(52); break; + case THEME_BLACK: result = COLOR_PAIR(53); break; + case THEME_BLACK_BOLD: result = COLOR_PAIR(53); break; + case THEME_MAGENTA: result = COLOR_PAIR(54); break; + case THEME_MAGENTA_BOLD: result = COLOR_PAIR(54); break; default: break; } diff --git a/src/config/theme.h b/src/config/theme.h index f2e38404..13099eb4 100644 --- a/src/config/theme.h +++ b/src/config/theme.h @@ -90,6 +90,7 @@ typedef enum { THEME_OTR_UNTRUSTED, THEME_OCCUPANTS_HEADER, THEME_ROSTER_HEADER, + THEME_RECEIPT_SENT, THEME_NONE, THEME_WHITE, THEME_WHITE_BOLD, diff --git a/src/ui/window.c b/src/ui/window.c index 81408403..4663089f 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -980,7 +980,7 @@ _win_print(ProfWin *window, const char show_char, GDateTime *time, } if (receipt && !receipt->received) { - colour = theme_attrs(THEME_BLACK_BOLD); + colour = theme_attrs(THEME_RECEIPT_SENT); } wattron(window->layout->win, colour); @@ -996,7 +996,7 @@ _win_print(ProfWin *window, const char show_char, GDateTime *time, if (!me_message) { if (receipt && !receipt->received) { - wattron(window->layout->win, theme_attrs(THEME_BLACK_BOLD)); + wattron(window->layout->win, theme_attrs(THEME_RECEIPT_SENT)); } else { wattron(window->layout->win, theme_attrs(theme_item)); } @@ -1016,7 +1016,7 @@ _win_print(ProfWin *window, const char show_char, GDateTime *time, wattroff(window->layout->win, colour); } else { if (receipt && !receipt->received) { - wattroff(window->layout->win, theme_attrs(THEME_BLACK_BOLD)); + wattroff(window->layout->win, theme_attrs(THEME_RECEIPT_SENT)); } else { wattroff(window->layout->win, theme_attrs(theme_item)); } diff --git a/theme_template b/theme_template index ece971a8..51e188da 100644 --- a/theme_template +++ b/theme_template @@ -47,6 +47,7 @@ me= them= roster.header= occupants.header= +receipt.sent= [ui] beep= @@ -69,4 +70,4 @@ roster.resource= roster.by= roster.size= occupants= -occupants.size= \ No newline at end of file +occupants.size= diff --git a/themes/aqua b/themes/aqua index fe3fd56a..11c250f4 100644 --- a/themes/aqua +++ b/themes/aqua @@ -47,3 +47,4 @@ me=cyan them=white roster.header=bold_white occupants.header=bold_white +receipt.sent=white diff --git a/themes/batman b/themes/batman index 358fc559..4d346ac1 100644 --- a/themes/batman +++ b/themes/batman @@ -34,7 +34,6 @@ otr.started.untrusted=red otr.ended=yellow otr.trusted=green otr.untrusted=red - titlebar.online=magenta titlebar.offline=black titlebar.away=magenta @@ -47,4 +46,5 @@ subscribed=magenta unsubscribed=black_bold roommention=cyan roster.header=yellow -occupants.header=yellow \ No newline at end of file +occupants.header=yellow +receipt.sent=red diff --git a/themes/boothj5 b/themes/boothj5 index 49231ab0..82e053ef 100644 --- a/themes/boothj5 +++ b/themes/boothj5 @@ -47,6 +47,7 @@ me=blue them=bold_green roster.header=bold_yellow occupants.header=bold_yellow +receipt.sent=bold_black [ui] beep=false diff --git a/themes/forest b/themes/forest index d04bc390..be3f3a82 100644 --- a/themes/forest +++ b/themes/forest @@ -46,4 +46,5 @@ roommention=bold_cyan me=blue them=bold_blue roster.header=bold_green -occupants.header=bold_green \ No newline at end of file +occupants.header=bold_green +receipt.sent=bold_black \ No newline at end of file diff --git a/themes/hacker b/themes/hacker index a81a635c..6486126f 100644 --- a/themes/hacker +++ b/themes/hacker @@ -46,4 +46,5 @@ roommention=bold_green me=green them=bold_green roster.header=bold_green -occupants.header=bold_green \ No newline at end of file +occupants.header=bold_green +receipt.sent=bold_black \ No newline at end of file diff --git a/themes/headache b/themes/headache index 3a84d976..5c06ca78 100644 --- a/themes/headache +++ b/themes/headache @@ -46,4 +46,5 @@ roommention=bold_green me=white them=white roster.header=bold_cyan -occupants.header=bold_cyan \ No newline at end of file +occupants.header=bold_cyan +receipt.sent=red \ No newline at end of file diff --git a/themes/joker b/themes/joker index a0986242..59e9ed94 100644 --- a/themes/joker +++ b/themes/joker @@ -46,4 +46,5 @@ roommention=green me=magenta them=green roster.header=magenta -occupants.header=magenta \ No newline at end of file +occupants.header=magenta +receipt.sent=red \ No newline at end of file diff --git a/themes/mono b/themes/mono index 779d04ff..8efd7369 100644 --- a/themes/mono +++ b/themes/mono @@ -46,4 +46,5 @@ roommention=white me=white them=white roster.header=white -occupants.header=white \ No newline at end of file +occupants.header=white +receipt.sent=white \ No newline at end of file diff --git a/themes/orange b/themes/orange index 57df02fd..5fc6ddf2 100644 --- a/themes/orange +++ b/themes/orange @@ -46,4 +46,5 @@ roommention=blue me=black them=black roster.header=black -occupants.header=black \ No newline at end of file +occupants.header=black +receipt.sent=red \ No newline at end of file diff --git a/themes/original b/themes/original index 33ae041b..d1c0b26a 100644 --- a/themes/original +++ b/themes/original @@ -46,4 +46,5 @@ roommention=yellow me=yellow them=green roster.header=yellow -occupants.header=yellow \ No newline at end of file +occupants.header=yellow +receipt.sent=red \ No newline at end of file diff --git a/themes/original_bright b/themes/original_bright index 4ad4af17..c584ff60 100644 --- a/themes/original_bright +++ b/themes/original_bright @@ -47,3 +47,4 @@ me=bold_yellow them=bold_green roster.header=bold_yellow occupants.header=bold_yellow +receipt.sent=bold_red diff --git a/themes/shade b/themes/shade index 856b2fa4..38d42860 100644 --- a/themes/shade +++ b/themes/shade @@ -46,4 +46,5 @@ roommention=green me=bold_black them=magenta roster.header=magenta -occupants.header=magenta \ No newline at end of file +occupants.header=magenta +receipt.sent=red \ No newline at end of file diff --git a/themes/spawn b/themes/spawn index 44c9f098..b32862d3 100644 --- a/themes/spawn +++ b/themes/spawn @@ -46,4 +46,5 @@ roommention=red me=green them=yellow roster.header=white -occupants.header=white \ No newline at end of file +occupants.header=white +receipt.sent=red \ No newline at end of file diff --git a/themes/whiteness b/themes/whiteness index c448fcfb..30b5e0e7 100644 --- a/themes/whiteness +++ b/themes/whiteness @@ -46,4 +46,5 @@ roommention=yellow me=black them=black roster.header=black -occupants.header=black \ No newline at end of file +occupants.header=black +receipt.sent=red \ No newline at end of file From 2762f18a3e4c4a73965d39cb2d2dbcdc81129b0c Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 15 Mar 2015 19:48:19 +0000 Subject: [PATCH 137/252] Added /receipts command --- src/command/command.c | 11 ++++++++++- src/command/commands.c | 7 +++++++ src/command/commands.h | 1 + src/ui/console.c | 9 +++++++++ src/ui/ui.h | 1 + tests/ui/stub_ui.c | 1 + 6 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/command/command.c b/src/command/command.c index 0bca4212..fe390fcb 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -921,6 +921,15 @@ static struct cmd_t command_defs[] = "The message carbons feature ensures that both sides of all conversations are shared with all the user's clients that implement this protocol.", NULL } } }, + { "/receipts", + cmd_receipts, parse_args, 1, 1, &cons_receipts_setting, + { "/reciepts on|off", "Message delivery receipts.", + { "/reciepts on|off", + "----------------", + "Enable or disable message delivery receipts.", + "The user interface will indicate when a message has been received.", + NULL } } }, + { "/reconnect", cmd_reconnect, parse_args, 1, 1, &cons_reconnect_setting, { "/reconnect seconds", "Set reconnect interval.", @@ -2020,7 +2029,7 @@ _cmd_complete_parameters(const char * const input) // autocomplete boolean settings gchar *boolean_choices[] = { "/beep", "/intype", "/states", "/outtype", "/flash", "/splash", "/chlog", "/grlog", "/mouse", "/history", - "/vercheck", "/privileges", "/presence", "/wrap", "/carbons" }; + "/vercheck", "/privileges", "/presence", "/wrap", "/carbons", "/receipts" }; for (i = 0; i < ARRAY_SIZE(boolean_choices); i++) { result = autocomplete_param_with_func(input, boolean_choices[i], prefs_autocomplete_boolean_choice); diff --git a/src/command/commands.c b/src/command/commands.c index 8075e2c0..528f44e2 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -3938,6 +3938,13 @@ cmd_carbons(gchar **args, struct cmd_help_t help) return result; } +gboolean +cmd_receipts(gchar **args, struct cmd_help_t help) +{ + return _cmd_set_boolean_preference(args[0], help, + "Message delivery receipts", PREF_RECEIPTS); +} + gboolean cmd_away(gchar **args, struct cmd_help_t help) { diff --git a/src/command/commands.h b/src/command/commands.h index bbf2ba8a..c74fb901 100644 --- a/src/command/commands.h +++ b/src/command/commands.h @@ -86,6 +86,7 @@ gboolean cmd_group(gchar **args, struct cmd_help_t help); gboolean cmd_help(gchar **args, struct cmd_help_t help); gboolean cmd_history(gchar **args, struct cmd_help_t help); gboolean cmd_carbons(gchar **args, struct cmd_help_t help); +gboolean cmd_receipts(gchar **args, struct cmd_help_t help); gboolean cmd_info(gchar **args, struct cmd_help_t help); gboolean cmd_intype(gchar **args, struct cmd_help_t help); gboolean cmd_invite(gchar **args, struct cmd_help_t help); diff --git a/src/ui/console.c b/src/ui/console.c index 46cb00fb..1c608dd9 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -1196,6 +1196,15 @@ cons_carbons_setting(void) cons_show("Message carbons (/carbons) : OFF"); } +void +cons_receipts_setting(void) +{ + if (prefs_get_boolean(PREF_RECEIPTS)) + cons_show("Message receipts (/reciepts) : ON"); + else + cons_show("Message receipts (/receipts) : OFF"); +} + void cons_show_chat_prefs(void) { diff --git a/src/ui/ui.h b/src/ui/ui.h index 1236b9d3..20685e92 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -318,6 +318,7 @@ void cons_intype_setting(void); void cons_gone_setting(void); void cons_history_setting(void); void cons_carbons_setting(void); +void cons_receipts_setting(void); void cons_log_setting(void); void cons_chlog_setting(void); void cons_grlog_setting(void); diff --git a/tests/ui/stub_ui.c b/tests/ui/stub_ui.c index 6b2698a2..3eeaa8ab 100644 --- a/tests/ui/stub_ui.c +++ b/tests/ui/stub_ui.c @@ -468,6 +468,7 @@ void cons_intype_setting(void) {} void cons_gone_setting(void) {} void cons_history_setting(void) {} void cons_carbons_setting(void) {} +void cons_receipts_setting(void) {} void cons_log_setting(void) {} void cons_chlog_setting(void) {} void cons_grlog_setting(void) {} From fae2717f27f4a45f03a50f2ccbf894e45af1cdce Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 15 Mar 2015 20:04:53 +0000 Subject: [PATCH 138/252] Tidied help --- src/command/command.c | 4 ++-- src/ui/console.c | 26 ++++++++++++++------------ 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index fe390fcb..5cf3f35d 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -923,8 +923,8 @@ static struct cmd_t command_defs[] = { "/receipts", cmd_receipts, parse_args, 1, 1, &cons_receipts_setting, - { "/reciepts on|off", "Message delivery receipts.", - { "/reciepts on|off", + { "/receipts on|off", "Message delivery receipts.", + { "/receipts on|off", "----------------", "Enable or disable message delivery receipts.", "The user interface will indicate when a message has been received.", diff --git a/src/ui/console.c b/src/ui/console.c index 1c608dd9..cd74f455 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -1142,27 +1142,27 @@ void cons_states_setting(void) { if (prefs_get_boolean(PREF_STATES)) - cons_show("Send chat states (/states) : ON"); + cons_show("Send chat states (/states) : ON"); else - cons_show("Send chat states (/states) : OFF"); + cons_show("Send chat states (/states) : OFF"); } void cons_outtype_setting(void) { if (prefs_get_boolean(PREF_OUTTYPE)) - cons_show("Send composing (/outtype) : ON"); + cons_show("Send composing (/outtype) : ON"); else - cons_show("Send composing (/outtype) : OFF"); + cons_show("Send composing (/outtype) : OFF"); } void cons_intype_setting(void) { if (prefs_get_boolean(PREF_INTYPE)) - cons_show("Show typing (/intype) : ON"); + cons_show("Show typing (/intype) : ON"); else - cons_show("Show typing (/intype) : OFF"); + cons_show("Show typing (/intype) : OFF"); } void @@ -1170,11 +1170,11 @@ cons_gone_setting(void) { gint gone_time = prefs_get_gone(); if (gone_time == 0) { - cons_show("Leave conversation (/gone) : OFF"); + cons_show("Leave conversation (/gone) : OFF"); } else if (gone_time == 1) { - cons_show("Leave conversation (/gone) : 1 minute"); + cons_show("Leave conversation (/gone) : 1 minute"); } else { - cons_show("Leave conversation (/gone) : %d minutes", gone_time); + cons_show("Leave conversation (/gone) : %d minutes", gone_time); } } @@ -1182,9 +1182,9 @@ void cons_history_setting(void) { if (prefs_get_boolean(PREF_HISTORY)) - cons_show("Chat history (/history) : ON"); + cons_show("Chat history (/history) : ON"); else - cons_show("Chat history (/history) : OFF"); + cons_show("Chat history (/history) : OFF"); } void @@ -1200,7 +1200,7 @@ void cons_receipts_setting(void) { if (prefs_get_boolean(PREF_RECEIPTS)) - cons_show("Message receipts (/reciepts) : ON"); + cons_show("Message receipts (/receipts) : ON"); else cons_show("Message receipts (/receipts) : OFF"); } @@ -1215,6 +1215,8 @@ cons_show_chat_prefs(void) cons_intype_setting(); cons_gone_setting(); cons_history_setting(); + cons_carbons_setting(); + cons_receipts_setting(); cons_alert(); } From 6f1119d225835e190bc1ec3e3b006a783aaa8c48 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 15 Mar 2015 20:28:09 +0000 Subject: [PATCH 139/252] Updated CHANGELOG --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index 10deba0b..7db3a45c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -3,6 +3,7 @@ - GNU Readline - Message Carbons (xep-0280) +- Message Delivery Receipts (xep-0184) 0.4.6 ===== From 8944a3b5bb1eece467870f90e434134e1a3fb23a Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 15 Mar 2015 23:18:50 +0000 Subject: [PATCH 140/252] Move common chat logging code to log.c --- src/command/command.c | 30 +------ src/command/commands.c | 180 ++++++++++++++++------------------------- src/log.c | 78 +++++++++++++++++- src/log.h | 10 ++- src/server_events.c | 33 +------- tests/log/stub_log.c | 10 ++- 6 files changed, 167 insertions(+), 174 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index 5cf3f35d..5a882a20 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -1956,43 +1956,19 @@ _cmd_execute_default(const char * inp) if (encrypted != NULL) { char *id = message_send_chat_encrypted(chatwin->barejid, encrypted); otr_free_message(encrypted); - if (prefs_get_boolean(PREF_CHLOG)) { - const char *jid = jabber_get_fulljid(); - Jid *jidp = jid_create(jid); - char *pref_otr_log = prefs_get_string(PREF_OTR_LOG); - if (strcmp(pref_otr_log, "on") == 0) { - chat_log_chat(jidp->barejid, chatwin->barejid, inp, PROF_OUT_LOG, NULL); - } else if (strcmp(pref_otr_log, "redact") == 0) { - chat_log_chat(jidp->barejid, chatwin->barejid, "[redacted]", PROF_OUT_LOG, NULL); - } - prefs_free_string(pref_otr_log); - jid_destroy(jidp); - } - + chat_log_otr_msg_out(chatwin->barejid, inp); ui_outgoing_chat_msg(chatwin->barejid, inp, id); } else { cons_show_error("Failed to send message."); } } else { char *id = message_send_chat(chatwin->barejid, inp); - if (prefs_get_boolean(PREF_CHLOG)) { - const char *jid = jabber_get_fulljid(); - Jid *jidp = jid_create(jid); - chat_log_chat(jidp->barejid, chatwin->barejid, inp, PROF_OUT_LOG, NULL); - jid_destroy(jidp); - } - + chat_log_msg_out(chatwin->barejid, inp); ui_outgoing_chat_msg(chatwin->barejid, inp, id); } #else char *id = message_send_chat(chatwin->barejid, inp); - if (prefs_get_boolean(PREF_CHLOG)) { - const char *jid = jabber_get_fulljid(); - Jid *jidp = jid_create(jid); - chat_log_chat(jidp->barejid, chatwin->barejid, inp, PROF_OUT_LOG, NULL); - jid_destroy(jidp); - } - + chat_log_msg_out(chatwin->barejid, inp); ui_outgoing_chat_msg(chatwin->barejid, inp, id); #endif } diff --git a/src/command/commands.c b/src/command/commands.c index 528f44e2..05d3ee53 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -1224,114 +1224,100 @@ cmd_msg(gchar **args, struct cmd_help_t help) char *msg = args[1]; jabber_conn_status_t conn_status = jabber_get_connection_status(); - win_type_t win_type = ui_current_win_type(); if (conn_status != JABBER_CONNECTED) { cons_show("You are not currently connected."); return TRUE; } - if (win_type == WIN_MUC) { - ProfMucWin *mucwin = wins_get_current_muc(); - if (muc_roster_contains_nick(mucwin->roomjid, usr)) { - GString *full_jid = g_string_new(mucwin->roomjid); - g_string_append(full_jid, "/"); - g_string_append(full_jid, usr); + win_type_t win_type = ui_current_win_type(); + + switch (win_type) { + case WIN_MUC: { + ProfMucWin *mucwin = wins_get_current_muc(); + if (muc_roster_contains_nick(mucwin->roomjid, usr)) { + GString *full_jid = g_string_new(mucwin->roomjid); + g_string_append(full_jid, "/"); + g_string_append(full_jid, usr); + + if (msg) { + message_send_private(full_jid->str, msg); + ui_outgoing_private_msg(full_jid->str, msg); + } else { + ui_new_private_win(full_jid->str); + } + + g_string_free(full_jid, TRUE); - if (msg != NULL) { - message_send_private(full_jid->str, msg); - ui_outgoing_private_msg(full_jid->str, msg); } else { - ui_new_private_win(full_jid->str); + ui_current_print_line("No such participant \"%s\" in room.", usr); } - g_string_free(full_jid, TRUE); - - } else { - ui_current_print_line("No such participant \"%s\" in room.", usr); + return TRUE; } + default: { + char *barejid = roster_barejid_from_name(usr); + if (barejid == NULL) { + barejid = usr; + } - return TRUE; - - } else { - // get barejid - char *barejid = roster_barejid_from_name(usr); - if (barejid == NULL) { - barejid = usr; - } - - if (msg != NULL) { + if (msg) { #ifdef HAVE_LIBOTR - if (otr_is_secure(barejid)) { - char *encrypted = otr_encrypt_message(barejid, msg); - if (encrypted != NULL) { - char *id = message_send_chat_encrypted(barejid, encrypted); - otr_free_message(encrypted); - ui_outgoing_chat_msg(barejid, msg, id); - - if (((win_type == WIN_CHAT) || (win_type == WIN_CONSOLE)) && prefs_get_boolean(PREF_CHLOG)) { - const char *jid = jabber_get_fulljid(); - Jid *jidp = jid_create(jid); - char *pref_otr_log = prefs_get_string(PREF_OTR_LOG); - if (strcmp(pref_otr_log, "on") == 0) { - chat_log_chat(jidp->barejid, barejid, msg, PROF_OUT_LOG, NULL); - } else if (strcmp(pref_otr_log, "redact") == 0) { - chat_log_chat(jidp->barejid, barejid, "[redacted]", PROF_OUT_LOG, NULL); + if (otr_is_secure(barejid)) { + char *encrypted = otr_encrypt_message(barejid, msg); + if (encrypted) { + char *id = message_send_chat_encrypted(barejid, encrypted); + otr_free_message(encrypted); + ui_outgoing_chat_msg(barejid, msg, id); + if (win_type == WIN_CHAT || win_type == WIN_CONSOLE) { + chat_log_otr_msg_out(barejid, msg); } - prefs_free_string(pref_otr_log); - jid_destroy(jidp); + } else { + cons_show_error("Failed to encrypt and send message,"); } } else { - cons_show_error("Failed to encrypt and send message,"); - } - } else { - prof_otrpolicy_t policy = otr_get_policy(barejid); - char *id = NULL; + prof_otrpolicy_t policy = otr_get_policy(barejid); + char *id = NULL; - if (policy == PROF_OTRPOLICY_ALWAYS) { - cons_show_error("Failed to send message. Please check OTR policy"); - return TRUE; - } else if (policy == PROF_OTRPOLICY_OPPORTUNISTIC) { - GString *otr_message = g_string_new(msg); - g_string_append(otr_message, OTRL_MESSAGE_TAG_BASE); - g_string_append(otr_message, OTRL_MESSAGE_TAG_V2); - id = message_send_chat_encrypted(barejid, otr_message->str); + if (policy == PROF_OTRPOLICY_ALWAYS) { + cons_show_error("Failed to send message. Please check OTR policy"); + return TRUE; + } else if (policy == PROF_OTRPOLICY_OPPORTUNISTIC) { + GString *otr_message = g_string_new(msg); + g_string_append(otr_message, OTRL_MESSAGE_TAG_BASE); + g_string_append(otr_message, OTRL_MESSAGE_TAG_V2); + id = message_send_chat_encrypted(barejid, otr_message->str); - g_string_free(otr_message, TRUE); - } else { - id = message_send_chat(barejid, msg); + g_string_free(otr_message, TRUE); + } else { + id = message_send_chat(barejid, msg); + } + ui_outgoing_chat_msg(barejid, msg, id); + + if (win_type == WIN_CHAT || win_type == WIN_CONSOLE) { + chat_log_msg_out(barejid, msg); + } } + return TRUE; +#else + char *id = message_send_chat(barejid, msg); ui_outgoing_chat_msg(barejid, msg, id); - if (((win_type == WIN_CHAT) || (win_type == WIN_CONSOLE)) && prefs_get_boolean(PREF_CHLOG)) { - const char *jid = jabber_get_fulljid(); - Jid *jidp = jid_create(jid); - chat_log_chat(jidp->barejid, barejid, msg, PROF_OUT_LOG, NULL); - jid_destroy(jidp); + if (win_type == WIN_CHAT || win_type == WIN_CONSOLE) { + chat_log_msg_out(barejid, msg); } - } - return TRUE; -#else - char *id = message_send_chat(barejid, msg); - ui_outgoing_chat_msg(barejid, msg, id); - - if (((win_type == WIN_CHAT) || (win_type == WIN_CONSOLE)) && prefs_get_boolean(PREF_CHLOG)) { - const char *jid = jabber_get_fulljid(); - Jid *jidp = jid_create(jid); - chat_log_chat(jidp->barejid, barejid, msg, PROF_OUT_LOG, NULL); - jid_destroy(jidp); - } - return TRUE; + return TRUE; #endif - } else { // msg == NULL - ui_new_chat_win(barejid); + } else { // msg == NULL + ui_new_chat_win(barejid); #ifdef HAVE_LIBOTR - if (otr_is_secure(barejid)) { - ui_gone_secure(barejid, otr_is_trusted(barejid)); - } + if (otr_is_secure(barejid)) { + ui_gone_secure(barejid, otr_is_trusted(barejid)); + } #endif - return TRUE; + return TRUE; + } } } } @@ -3076,43 +3062,19 @@ cmd_tiny(gchar **args, struct cmd_help_t help) if (encrypted != NULL) { char *id = message_send_chat_encrypted(chatwin->barejid, encrypted); otr_free_message(encrypted); - if (prefs_get_boolean(PREF_CHLOG)) { - const char *jid = jabber_get_fulljid(); - Jid *jidp = jid_create(jid); - char *pref_otr_log = prefs_get_string(PREF_OTR_LOG); - if (strcmp(pref_otr_log, "on") == 0) { - chat_log_chat(jidp->barejid, chatwin->barejid, tiny, PROF_OUT_LOG, NULL); - } else if (strcmp(pref_otr_log, "redact") == 0) { - chat_log_chat(jidp->barejid, chatwin->barejid, "[redacted]", PROF_OUT_LOG, NULL); - } - prefs_free_string(pref_otr_log); - jid_destroy(jidp); - } - + chat_log_otr_msg_out(chatwin->barejid, tiny); ui_outgoing_chat_msg(chatwin->barejid, tiny, id); } else { cons_show_error("Failed to send message."); } } else { char *id = message_send_chat(chatwin->barejid, tiny); - if (prefs_get_boolean(PREF_CHLOG)) { - const char *jid = jabber_get_fulljid(); - Jid *jidp = jid_create(jid); - chat_log_chat(jidp->barejid, chatwin->barejid, tiny, PROF_OUT_LOG, NULL); - jid_destroy(jidp); - } - + chat_log_msg_out(chatwin->barejid, tiny); ui_outgoing_chat_msg(chatwin->barejid, tiny, id); } #else char *id = message_send_chat(chatwin->barejid, tiny); - if (prefs_get_boolean(PREF_CHLOG)) { - const char *jid = jabber_get_fulljid(); - Jid *jidp = jid_create(jid); - chat_log_chat(jidp->barejid, chatwin->barejid, tiny, PROF_OUT_LOG, NULL); - jid_destroy(jidp); - } - + chat_log_msg_out(chatwin->barejid, tiny); ui_outgoing_chat_msg(chatwin->barejid, tiny, id); #endif } else if (win_type == WIN_PRIVATE) { diff --git a/src/log.c b/src/log.c index 004d4dcf..ac0dfd2e 100644 --- a/src/log.c +++ b/src/log.c @@ -46,6 +46,7 @@ #include "common.h" #include "config/preferences.h" +#include "xmpp/xmpp.h" #define PROF "prof" @@ -66,7 +67,7 @@ struct dated_chat_log { }; static gboolean _log_roll_needed(struct dated_chat_log *dated_log); -static struct dated_chat_log * _create_log(char *other, const char * const login); +static struct dated_chat_log * _create_log(const char * const other, const char * const login); static struct dated_chat_log * _create_groupchat_log(char *room, const char * const login); static void _free_chat_log(struct dated_chat_log *dated_log); static gboolean _key_equals(void *key1, void *key2); @@ -78,6 +79,8 @@ static gchar * _get_chatlog_dir(void); static gchar * _get_main_log_file(void); static void _rotate_log_file(void); static char* _log_string_from_level(log_level_t level); +static void _chat_log_chat(const char * const login, const char * const other, + const gchar * const msg, chat_log_direction_t direction, GTimeVal *tv_stamp); void log_debug(const char * const msg, ...) @@ -249,8 +252,75 @@ groupchat_log_init(void) } void -chat_log_chat(const gchar * const login, gchar *other, - const gchar * const msg, chat_log_direction_t direction, GTimeVal *tv_stamp) +chat_log_msg_out(const char * const barejid, const char * const msg) +{ + if (prefs_get_boolean(PREF_CHLOG)) { + const char *jid = jabber_get_fulljid(); + Jid *jidp = jid_create(jid); + _chat_log_chat(jidp->barejid, barejid, msg, PROF_OUT_LOG, NULL); + jid_destroy(jidp); + } +} + +void +chat_log_otr_msg_out(const char * const barejid, const char * const msg) +{ + if (prefs_get_boolean(PREF_CHLOG)) { + const char *jid = jabber_get_fulljid(); + Jid *jidp = jid_create(jid); + char *pref_otr_log = prefs_get_string(PREF_OTR_LOG); + if (strcmp(pref_otr_log, "on") == 0) { + _chat_log_chat(jidp->barejid, barejid, msg, PROF_OUT_LOG, NULL); + } else if (strcmp(pref_otr_log, "redact") == 0) { + _chat_log_chat(jidp->barejid, barejid, "[redacted]", PROF_OUT_LOG, NULL); + } + prefs_free_string(pref_otr_log); + jid_destroy(jidp); + } +} + +void +chat_log_otr_msg_in(const char * const barejid, const char * const msg, gboolean was_decrypted) +{ + if (prefs_get_boolean(PREF_CHLOG)) { + const char *jid = jabber_get_fulljid(); + Jid *jidp = jid_create(jid); + char *pref_otr_log = prefs_get_string(PREF_OTR_LOG); + if (!was_decrypted || (strcmp(pref_otr_log, "on") == 0)) { + _chat_log_chat(jidp->barejid, barejid, msg, PROF_IN_LOG, NULL); + } else if (strcmp(pref_otr_log, "redact") == 0) { + _chat_log_chat(jidp->barejid, barejid, "[redacted]", PROF_IN_LOG, NULL); + } + prefs_free_string(pref_otr_log); + jid_destroy(jidp); + } +} + +void +chat_log_msg_in(const char * const barejid, const char * const msg) +{ + if (prefs_get_boolean(PREF_CHLOG)) { + const char *jid = jabber_get_fulljid(); + Jid *jidp = jid_create(jid); + _chat_log_chat(jidp->barejid, barejid, msg, PROF_IN_LOG, NULL); + jid_destroy(jidp); + } +} + +void +chat_log_msg_in_delayed(const char * const barejid, const char * msg, GTimeVal *tv_stamp) +{ + if (prefs_get_boolean(PREF_CHLOG)) { + const char *jid = jabber_get_fulljid(); + Jid *jidp = jid_create(jid); + _chat_log_chat(jidp->barejid, barejid, msg, PROF_IN_LOG, tv_stamp); + jid_destroy(jidp); + } +} + +static void +_chat_log_chat(const char * const login, const char * const other, + const char * const msg, chat_log_direction_t direction, GTimeVal *tv_stamp) { struct dated_chat_log *dated_log = g_hash_table_lookup(logs, other); @@ -402,7 +472,7 @@ chat_log_close(void) } static struct dated_chat_log * -_create_log(char *other, const char * const login) +_create_log(const char * const other, const char * const login) { GDateTime *now = g_date_time_new_now_local(); char *filename = _get_log_filename(other, login, now, TRUE); diff --git a/src/log.h b/src/log.h index fdfd6caa..0689e2e6 100644 --- a/src/log.h +++ b/src/log.h @@ -64,8 +64,14 @@ void log_msg(log_level_t level, const char * const area, log_level_t log_level_from_string(char *log_level); void chat_log_init(void); -void chat_log_chat(const gchar * const login, gchar *other, - const gchar * const msg, chat_log_direction_t direction, GTimeVal *tv_stamp); + +void chat_log_msg_out(const char * const barejid, const char * const msg); +void chat_log_otr_msg_out(const char * const barejid, const char * const msg); + +void chat_log_msg_in(const char * const barejid, const char * const msg); +void chat_log_msg_in_delayed(const char * const barejid, const char * msg, GTimeVal *tv_stamp); +void chat_log_otr_msg_in(const char * const barejid, const char * const msg, gboolean was_decrypted); + void chat_log_close(void); GSList * chat_log_get_previous(const gchar * const login, const gchar * const recipient); diff --git a/src/server_events.c b/src/server_events.c index cf6ecb75..a97e0786 100644 --- a/src/server_events.c +++ b/src/server_events.c @@ -355,32 +355,11 @@ handle_incoming_message(char *barejid, char *resource, char *message) } ui_incoming_msg(barejid, resource, newmessage, NULL); - - if (prefs_get_boolean(PREF_CHLOG)) { - const char *jid = jabber_get_fulljid(); - Jid *jidp = jid_create(jid); - - char *pref_otr_log = prefs_get_string(PREF_OTR_LOG); - if (!was_decrypted || (strcmp(pref_otr_log, "on") == 0)) { - chat_log_chat(jidp->barejid, barejid, newmessage, PROF_IN_LOG, NULL); - } else if (strcmp(pref_otr_log, "redact") == 0) { - chat_log_chat(jidp->barejid, barejid, "[redacted]", PROF_IN_LOG, NULL); - } - prefs_free_string(pref_otr_log); - - jid_destroy(jidp); - } - + chat_log_otr_msg_in(barejid, newmessage, was_decrypted); otr_free_message(newmessage); #else ui_incoming_msg(barejid, resource, message, NULL); - - if (prefs_get_boolean(PREF_CHLOG)) { - const char *jid = jabber_get_fulljid(); - Jid *jidp = jid_create(jid); - chat_log_chat(jidp->barejid, barejid, message, PROF_IN_LOG, NULL); - jid_destroy(jidp); - } + chat_log_msg_in(barejid, message); #endif } @@ -394,13 +373,7 @@ void handle_delayed_message(char *barejid, char *message, GTimeVal tv_stamp) { ui_incoming_msg(barejid, NULL, message, &tv_stamp); - - if (prefs_get_boolean(PREF_CHLOG)) { - const char *jid = jabber_get_fulljid(); - Jid *jidp = jid_create(jid); - chat_log_chat(jidp->barejid, barejid, message, PROF_IN_LOG, &tv_stamp); - jid_destroy(jidp); - } + chat_log_msg_in_delayed(barejid, message, &tv_stamp); } void diff --git a/tests/log/stub_log.c b/tests/log/stub_log.c index 8ace164a..f88871a7 100644 --- a/tests/log/stub_log.c +++ b/tests/log/stub_log.c @@ -50,8 +50,14 @@ log_level_t log_level_from_string(char *log_level) } void chat_log_init(void) {} -void chat_log_chat(const gchar * const login, gchar *other, - const gchar * const msg, chat_log_direction_t direction, GTimeVal *tv_stamp) {} + +void chat_log_msg_out(const char * const barejid, const char * const msg) {} +void chat_log_otr_msg_out(const char * const barejid, const char * const msg) {} + +void chat_log_msg_in(const char * const barejid, const char * const msg) {} +void chat_log_msg_in_delayed(const char * const barejid, const char * msg, GTimeVal *tv_stamp) {} +void chat_log_otr_msg_in(const char * const barejid, const char * const msg, gboolean was_decrypted) {} + void chat_log_close(void) {} GSList * chat_log_get_previous(const gchar * const login, const gchar * const recipient) From eeabbc9bb3aaaafe34e05cafcc5e2d075196928f Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 15 Mar 2015 23:31:39 +0000 Subject: [PATCH 141/252] Fix for chat logging --- src/command/commands.c | 136 ++++++++++++++++++++--------------------- 1 file changed, 66 insertions(+), 70 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index 05d3ee53..3e5b6174 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -1224,100 +1224,96 @@ cmd_msg(gchar **args, struct cmd_help_t help) char *msg = args[1]; jabber_conn_status_t conn_status = jabber_get_connection_status(); + win_type_t win_type = ui_current_win_type(); if (conn_status != JABBER_CONNECTED) { cons_show("You are not currently connected."); return TRUE; } - win_type_t win_type = ui_current_win_type(); - - switch (win_type) { - case WIN_MUC: { - ProfMucWin *mucwin = wins_get_current_muc(); - if (muc_roster_contains_nick(mucwin->roomjid, usr)) { - GString *full_jid = g_string_new(mucwin->roomjid); - g_string_append(full_jid, "/"); - g_string_append(full_jid, usr); - - if (msg) { - message_send_private(full_jid->str, msg); - ui_outgoing_private_msg(full_jid->str, msg); - } else { - ui_new_private_win(full_jid->str); - } - - g_string_free(full_jid, TRUE); + if (win_type == WIN_MUC) { + ProfMucWin *mucwin = wins_get_current_muc(); + if (muc_roster_contains_nick(mucwin->roomjid, usr)) { + GString *full_jid = g_string_new(mucwin->roomjid); + g_string_append(full_jid, "/"); + g_string_append(full_jid, usr); + if (msg != NULL) { + message_send_private(full_jid->str, msg); + ui_outgoing_private_msg(full_jid->str, msg); } else { - ui_current_print_line("No such participant \"%s\" in room.", usr); + ui_new_private_win(full_jid->str); } - return TRUE; + g_string_free(full_jid, TRUE); + + } else { + ui_current_print_line("No such participant \"%s\" in room.", usr); } - default: { - char *barejid = roster_barejid_from_name(usr); - if (barejid == NULL) { - barejid = usr; - } - if (msg) { + return TRUE; + + } else { + // get barejid + char *barejid = roster_barejid_from_name(usr); + if (barejid == NULL) { + barejid = usr; + } + + if (msg != NULL) { #ifdef HAVE_LIBOTR - if (otr_is_secure(barejid)) { - char *encrypted = otr_encrypt_message(barejid, msg); - if (encrypted) { - char *id = message_send_chat_encrypted(barejid, encrypted); - otr_free_message(encrypted); - ui_outgoing_chat_msg(barejid, msg, id); - if (win_type == WIN_CHAT || win_type == WIN_CONSOLE) { - chat_log_otr_msg_out(barejid, msg); - } - } else { - cons_show_error("Failed to encrypt and send message,"); + if (otr_is_secure(barejid)) { + char *encrypted = otr_encrypt_message(barejid, msg); + if (encrypted != NULL) { + char *id = message_send_chat_encrypted(barejid, encrypted); + otr_free_message(encrypted); + ui_outgoing_chat_msg(barejid, msg, id); + if (win_type == WIN_CHAT || win_type == WIN_CONSOLE) { + chat_log_otr_msg_out(barejid, msg); } } else { - prof_otrpolicy_t policy = otr_get_policy(barejid); - char *id = NULL; - - if (policy == PROF_OTRPOLICY_ALWAYS) { - cons_show_error("Failed to send message. Please check OTR policy"); - return TRUE; - } else if (policy == PROF_OTRPOLICY_OPPORTUNISTIC) { - GString *otr_message = g_string_new(msg); - g_string_append(otr_message, OTRL_MESSAGE_TAG_BASE); - g_string_append(otr_message, OTRL_MESSAGE_TAG_V2); - id = message_send_chat_encrypted(barejid, otr_message->str); - - g_string_free(otr_message, TRUE); - } else { - id = message_send_chat(barejid, msg); - } - ui_outgoing_chat_msg(barejid, msg, id); - - if (win_type == WIN_CHAT || win_type == WIN_CONSOLE) { - chat_log_msg_out(barejid, msg); - } + cons_show_error("Failed to encrypt and send message,"); } - return TRUE; -#else - char *id = message_send_chat(barejid, msg); - ui_outgoing_chat_msg(barejid, msg, id); + } else { + prof_otrpolicy_t policy = otr_get_policy(barejid); + char *id = NULL; + if (policy == PROF_OTRPOLICY_ALWAYS) { + cons_show_error("Failed to send message. Please check OTR policy"); + return TRUE; + } else if (policy == PROF_OTRPOLICY_OPPORTUNISTIC) { + GString *otr_message = g_string_new(msg); + g_string_append(otr_message, OTRL_MESSAGE_TAG_BASE); + g_string_append(otr_message, OTRL_MESSAGE_TAG_V2); + id = message_send_chat_encrypted(barejid, otr_message->str); + + g_string_free(otr_message, TRUE); + } else { + id = message_send_chat(barejid, msg); + } + ui_outgoing_chat_msg(barejid, msg, id); if (win_type == WIN_CHAT || win_type == WIN_CONSOLE) { chat_log_msg_out(barejid, msg); } - return TRUE; + } + return TRUE; +#else + char *id = message_send_chat(barejid, msg); + ui_outgoing_chat_msg(barejid, msg, id); + if (win_type == WIN_CHAT || win_type == WIN_CONSOLE) { + chat_log_msg_out(barejid, msg); + } + return TRUE; #endif - } else { // msg == NULL - ui_new_chat_win(barejid); + } else { // msg == NULL + ui_new_chat_win(barejid); #ifdef HAVE_LIBOTR - if (otr_is_secure(barejid)) { - ui_gone_secure(barejid, otr_is_trusted(barejid)); - } -#endif - return TRUE; + if (otr_is_secure(barejid)) { + ui_gone_secure(barejid, otr_is_trusted(barejid)); } +#endif + return TRUE; } } } From 9bf5a683292931735fc5564550ee3b2dbca3b140 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 16 Mar 2015 00:03:07 +0000 Subject: [PATCH 142/252] Moved default and alias command execution --- src/command/command.c | 114 ++--------------------------------------- src/command/commands.c | 108 +++++++++++++++++++++++++++++++++++++- src/command/commands.h | 3 ++ 3 files changed, 113 insertions(+), 112 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index 5a882a20..0a4be511 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -71,8 +71,6 @@ typedef char*(*autocompleter)(char*, int*); static gboolean _cmd_execute(const char * const command, const char * const inp); -static gboolean _cmd_execute_default(const char * inp); -static gboolean _cmd_execute_alias(const char * const inp, gboolean *ran); static char * _cmd_complete_parameters(const char * const input); @@ -1829,7 +1827,7 @@ cmd_process_input(char *inp) // call a default handler if input didn't start with '/' } else { - result = _cmd_execute_default(inp); + result = cmd_execute_default(inp); } return result; @@ -1881,121 +1879,15 @@ _cmd_execute(const char * const command, const char * const inp) } } else { gboolean ran_alias = FALSE; - gboolean alias_result = _cmd_execute_alias(inp, &ran_alias); + gboolean alias_result = cmd_execute_alias(inp, &ran_alias); if (!ran_alias) { - return _cmd_execute_default(inp); + return cmd_execute_default(inp); } else { return alias_result; } } } -static gboolean -_cmd_execute_alias(const char * const inp, gboolean *ran) -{ - if (inp[0] != '/') { - ran = FALSE; - return TRUE; - } else { - char *alias = strdup(inp+1); - char *value = prefs_get_alias(alias); - free(alias); - if (value != NULL) { - *ran = TRUE; - return cmd_process_input(value); - } else { - *ran = FALSE; - return TRUE; - } - } -} - -static gboolean -_cmd_execute_default(const char * inp) -{ - jabber_conn_status_t status = jabber_get_connection_status(); - - // handle escaped commands - treat as normal message - if (g_str_has_prefix(inp, "//")) { - inp++; - - // handle unknown commands - } else if ((inp[0] == '/') && (!g_str_has_prefix(inp, "/me "))) { - cons_show("Unknown command: %s", inp); - cons_alert(); - return TRUE; - } - - win_type_t win_type = ui_current_win_type(); - switch (win_type) - { - case WIN_MUC: - if (status != JABBER_CONNECTED) { - ui_current_print_line("You are not currently connected."); - } else { - ProfMucWin *mucwin = wins_get_current_muc(); - message_send_groupchat(mucwin->roomjid, inp); - } - break; - - case WIN_CHAT: - if (status != JABBER_CONNECTED) { - ui_current_print_line("You are not currently connected."); - } else { - ProfWin *current = wins_get_current(); - ProfChatWin *chatwin = (ProfChatWin*)current; - assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK); -#ifdef HAVE_LIBOTR - prof_otrpolicy_t policy = otr_get_policy(chatwin->barejid); - if (policy == PROF_OTRPOLICY_ALWAYS && !otr_is_secure(chatwin->barejid)) { - cons_show_error("Failed to send message. Please check OTR policy"); - return TRUE; - } - if (otr_is_secure(chatwin->barejid)) { - char *encrypted = otr_encrypt_message(chatwin->barejid, inp); - if (encrypted != NULL) { - char *id = message_send_chat_encrypted(chatwin->barejid, encrypted); - otr_free_message(encrypted); - chat_log_otr_msg_out(chatwin->barejid, inp); - ui_outgoing_chat_msg(chatwin->barejid, inp, id); - } else { - cons_show_error("Failed to send message."); - } - } else { - char *id = message_send_chat(chatwin->barejid, inp); - chat_log_msg_out(chatwin->barejid, inp); - ui_outgoing_chat_msg(chatwin->barejid, inp, id); - } -#else - char *id = message_send_chat(chatwin->barejid, inp); - chat_log_msg_out(chatwin->barejid, inp); - ui_outgoing_chat_msg(chatwin->barejid, inp, id); -#endif - } - break; - - case WIN_PRIVATE: - if (status != JABBER_CONNECTED) { - ui_current_print_line("You are not currently connected."); - } else { - ProfPrivateWin *privatewin = wins_get_current_private(); - message_send_private(privatewin->fulljid, inp); - ui_outgoing_private_msg(privatewin->fulljid, inp); - } - break; - - case WIN_CONSOLE: - case WIN_XML: - cons_show("Unknown command: %s", inp); - break; - - default: - break; - } - - return TRUE; -} - static char * _cmd_complete_parameters(const char * const input) { diff --git a/src/command/commands.c b/src/command/commands.c index 3e5b6174..a2c574ec 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -80,6 +80,112 @@ static void _who_roster(gchar **args, struct cmd_help_t help); extern GHashTable *commands; +gboolean +cmd_execute_default(const char * inp) +{ + jabber_conn_status_t status = jabber_get_connection_status(); + + // handle escaped commands - treat as normal message + if (g_str_has_prefix(inp, "//")) { + inp++; + + // handle unknown commands + } else if ((inp[0] == '/') && (!g_str_has_prefix(inp, "/me "))) { + cons_show("Unknown command: %s", inp); + cons_alert(); + return TRUE; + } + + win_type_t win_type = ui_current_win_type(); + switch (win_type) + { + case WIN_MUC: + if (status != JABBER_CONNECTED) { + ui_current_print_line("You are not currently connected."); + } else { + ProfMucWin *mucwin = wins_get_current_muc(); + message_send_groupchat(mucwin->roomjid, inp); + } + break; + + case WIN_CHAT: + if (status != JABBER_CONNECTED) { + ui_current_print_line("You are not currently connected."); + } else { + ProfWin *current = wins_get_current(); + ProfChatWin *chatwin = (ProfChatWin*)current; + assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK); +#ifdef HAVE_LIBOTR + prof_otrpolicy_t policy = otr_get_policy(chatwin->barejid); + if (policy == PROF_OTRPOLICY_ALWAYS && !otr_is_secure(chatwin->barejid)) { + cons_show_error("Failed to send message. Please check OTR policy"); + return TRUE; + } + if (otr_is_secure(chatwin->barejid)) { + char *encrypted = otr_encrypt_message(chatwin->barejid, inp); + if (encrypted != NULL) { + char *id = message_send_chat_encrypted(chatwin->barejid, encrypted); + otr_free_message(encrypted); + chat_log_otr_msg_out(chatwin->barejid, inp); + ui_outgoing_chat_msg(chatwin->barejid, inp, id); + } else { + cons_show_error("Failed to send message."); + } + } else { + char *id = message_send_chat(chatwin->barejid, inp); + chat_log_msg_out(chatwin->barejid, inp); + ui_outgoing_chat_msg(chatwin->barejid, inp, id); + } +#else + char *id = message_send_chat(chatwin->barejid, inp); + chat_log_msg_out(chatwin->barejid, inp); + ui_outgoing_chat_msg(chatwin->barejid, inp, id); +#endif + } + break; + + case WIN_PRIVATE: + if (status != JABBER_CONNECTED) { + ui_current_print_line("You are not currently connected."); + } else { + ProfPrivateWin *privatewin = wins_get_current_private(); + message_send_private(privatewin->fulljid, inp); + ui_outgoing_private_msg(privatewin->fulljid, inp); + } + break; + + case WIN_CONSOLE: + case WIN_XML: + cons_show("Unknown command: %s", inp); + break; + + default: + break; + } + + return TRUE; +} + +gboolean +cmd_execute_alias(const char * const inp, gboolean *ran) +{ + if (inp[0] != '/') { + ran = FALSE; + return TRUE; + } else { + char *alias = strdup(inp+1); + char *value = prefs_get_alias(alias); + free(alias); + if (value != NULL) { + *ran = TRUE; + return cmd_process_input(value); + } else { + *ran = FALSE; + return TRUE; + } + } +} + gboolean cmd_connect(gchar **args, struct cmd_help_t help) { @@ -3057,9 +3163,9 @@ cmd_tiny(gchar **args, struct cmd_help_t help) char *encrypted = otr_encrypt_message(chatwin->barejid, tiny); if (encrypted != NULL) { char *id = message_send_chat_encrypted(chatwin->barejid, encrypted); - otr_free_message(encrypted); chat_log_otr_msg_out(chatwin->barejid, tiny); ui_outgoing_chat_msg(chatwin->barejid, tiny, id); + otr_free_message(encrypted); } else { cons_show_error("Failed to send message."); } diff --git a/src/command/commands.h b/src/command/commands.h index c74fb901..7b7e7c93 100644 --- a/src/command/commands.h +++ b/src/command/commands.h @@ -62,6 +62,9 @@ typedef struct cmd_t { CommandHelp help; } Command; +gboolean cmd_execute_alias(const char * const inp, gboolean *ran); +gboolean cmd_execute_default(const char * inp); + gboolean cmd_about(gchar **args, struct cmd_help_t help); gboolean cmd_account(gchar **args, struct cmd_help_t help); gboolean cmd_autoaway(gchar **args, struct cmd_help_t help); From 23ef3498b5b3b7377ca5995c68357b6bc62b0739 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 16 Mar 2015 01:03:20 +0000 Subject: [PATCH 143/252] Removed console dependency from strtoi --- src/command/commands.c | 192 +++++++++++++++++++++++++++-------------- 1 file changed, 126 insertions(+), 66 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index a2c574ec..400a7c8d 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -72,7 +72,7 @@ static void _update_presence(const resource_presence_t presence, const char * const show, gchar **args); static gboolean _cmd_set_boolean_preference(gchar *arg, struct cmd_help_t help, const char * const display, preference_t pref); -static int _strtoi(char *str, int *saveptr, int min, int max); +static gboolean _strtoi(char *str, int *saveptr, int min, int max, char **err_msg); static void _cmd_show_filtered_help(char *heading, gchar *cmd_filter[], int filter_size); static gint _compare_commands(Command *a, Command *b); static void _who_room(gchar **args, struct cmd_help_t help); @@ -212,9 +212,13 @@ cmd_connect(gchar **args, struct cmd_help_t help) int port = 0; if (g_hash_table_contains(options, "port")) { char *port_str = g_hash_table_lookup(options, "port"); - if (_strtoi(port_str, &port, 1, 65535) != 0) { - port = 0; + char *err_msg = NULL; + gboolean res = _strtoi(port_str, &port, 1, 65535, &err_msg); + if (!res) { + cons_show(err_msg); cons_show(""); + free(err_msg); + port = 0; return TRUE; } } @@ -464,8 +468,12 @@ cmd_account(gchar **args, struct cmd_help_t help) cons_show(""); } else if (strcmp(property, "port") == 0) { int port; - if (_strtoi(value, &port, 1, 65535) != 0) { + char *err_msg = NULL; + gboolean res = _strtoi(value, &port, 1, 65535, &err_msg); + if (!res) { + cons_show(err_msg); cons_show(""); + free(err_msg); return TRUE; } else { accounts_set_port(account_name, port); @@ -519,42 +527,46 @@ cmd_account(gchar **args, struct cmd_help_t help) } cons_show(""); } else if (valid_resource_presence_string(property)) { - int intval; - - if (_strtoi(value, &intval, -128, 127) == 0) { - resource_presence_t presence_type = resource_presence_from_string(property); - switch (presence_type) - { - case (RESOURCE_ONLINE): - accounts_set_priority_online(account_name, intval); - break; - case (RESOURCE_CHAT): - accounts_set_priority_chat(account_name, intval); - break; - case (RESOURCE_AWAY): - accounts_set_priority_away(account_name, intval); - break; - case (RESOURCE_XA): - accounts_set_priority_xa(account_name, intval); - break; - case (RESOURCE_DND): - accounts_set_priority_dnd(account_name, intval); - break; - } - - jabber_conn_status_t conn_status = jabber_get_connection_status(); - if (conn_status == JABBER_CONNECTED) { - char *connected_account = jabber_get_account_name(); - resource_presence_t last_presence = accounts_get_last_presence(connected_account); - - if (presence_type == last_presence) { - char *message = jabber_get_presence_message(); - presence_update(last_presence, message, 0); - } - } - cons_show("Updated %s priority for account %s: %s", property, account_name, value); - cons_show(""); + int intval; + char *err_msg = NULL; + gboolean res = _strtoi(value, &intval, -128, 127, &err_msg); + if (res) { + resource_presence_t presence_type = resource_presence_from_string(property); + switch (presence_type) + { + case (RESOURCE_ONLINE): + accounts_set_priority_online(account_name, intval); + break; + case (RESOURCE_CHAT): + accounts_set_priority_chat(account_name, intval); + break; + case (RESOURCE_AWAY): + accounts_set_priority_away(account_name, intval); + break; + case (RESOURCE_XA): + accounts_set_priority_xa(account_name, intval); + break; + case (RESOURCE_DND): + accounts_set_priority_dnd(account_name, intval); + break; } + + jabber_conn_status_t conn_status = jabber_get_connection_status(); + if (conn_status == JABBER_CONNECTED) { + char *connected_account = jabber_get_account_name(); + resource_presence_t last_presence = accounts_get_last_presence(connected_account); + + if (presence_type == last_presence) { + char *message = jabber_get_presence_message(); + presence_update(last_presence, message, 0); + } + } + cons_show("Updated %s priority for account %s: %s", property, account_name, value); + cons_show(""); + } else { + cons_show(err_msg); + free(err_msg); + } } else { cons_show("Invalid property: %s", property); cons_show(""); @@ -1557,11 +1569,14 @@ cmd_roster(gchar **args, struct cmd_help_t help) // set roster size } else if (g_strcmp0(args[0], "size") == 0) { - int intval = 0; if (!args[1]) { cons_show("Usage: %s", help.usage); return TRUE; - } else if (_strtoi(args[1], &intval, 1, 99) == 0) { + } + int intval = 0; + char *err_msg = NULL; + gboolean res = _strtoi(args[1], &intval, 1, 99, &err_msg); + if (res) { prefs_set_roster_size(intval); cons_show("Roster screen size set to: %d%%", intval); if (prefs_get_boolean(PREF_ROSTER)) { @@ -1569,6 +1584,8 @@ cmd_roster(gchar **args, struct cmd_help_t help) } return TRUE; } else { + cons_show(err_msg); + free(err_msg); return TRUE; } @@ -2836,15 +2853,23 @@ cmd_occupants(gchar **args, struct cmd_help_t help) } if (g_strcmp0(args[0], "size") == 0) { - int intval = 0; if (!args[1]) { cons_show("Usage: %s", help.usage); return TRUE; - } else if (_strtoi(args[1], &intval, 1, 99) == 0) { - prefs_set_occupants_size(intval); - cons_show("Occupants screen size set to: %d%%", intval); - wins_resize_all(); - return TRUE; + } else { + int intval = 0; + char *err_msg = NULL; + gboolean res = _strtoi(args[1], &intval, 1, 99, &err_msg); + if (res) { + prefs_set_occupants_size(intval); + cons_show("Occupants screen size set to: %d%%", intval); + wins_resize_all(); + return TRUE; + } else { + cons_show(err_msg); + free(err_msg); + return TRUE; + } } } @@ -3596,7 +3621,6 @@ cmd_inpblock(gchar **args, struct cmd_help_t help) { char *subcmd = args[0]; char *value = args[1]; - int intval; if (g_strcmp0(subcmd, "timeout") == 0) { if (value == NULL) { @@ -3604,10 +3628,16 @@ cmd_inpblock(gchar **args, struct cmd_help_t help) return TRUE; } - if (_strtoi(value, &intval, 1, 1000) == 0) { + int intval = 0; + char *err_msg = NULL; + gboolean res = _strtoi(value, &intval, 1, 1000, &err_msg); + if (res) { cons_show("Input blocking set to %d milliseconds.", intval); prefs_set_inpblock(intval); ui_input_nonblocking(FALSE); + } else { + cons_show(err_msg); + free(err_msg); } return TRUE; @@ -3637,16 +3667,22 @@ cmd_log(gchar **args, struct cmd_help_t help) { char *subcmd = args[0]; char *value = args[1]; - int intval; if (strcmp(subcmd, "maxsize") == 0) { if (value == NULL) { cons_show("Usage: %s", help.usage); return TRUE; } - if (_strtoi(value, &intval, PREFS_MIN_LOG_SIZE, INT_MAX) == 0) { + + int intval = 0; + char *err_msg = NULL; + gboolean res = _strtoi(value, &intval, PREFS_MIN_LOG_SIZE, INT_MAX, &err_msg); + if (res) { prefs_set_max_log_size(intval); cons_show("Log maxinum size set to %d bytes", intval); + } else { + cons_show(err_msg); + free(err_msg); } return TRUE; } @@ -3686,9 +3722,11 @@ gboolean cmd_reconnect(gchar **args, struct cmd_help_t help) { char *value = args[0]; - int intval; - if (_strtoi(value, &intval, 0, INT_MAX) == 0) { + int intval = 0; + char *err_msg = NULL; + gboolean res = _strtoi(value, &intval, 0, INT_MAX, &err_msg); + if (res) { prefs_set_reconnect(intval); if (intval == 0) { cons_show("Reconnect disabled.", intval); @@ -3696,7 +3734,9 @@ cmd_reconnect(gchar **args, struct cmd_help_t help) cons_show("Reconnect interval set to %d seconds.", intval); } } else { + cons_show(err_msg); cons_show("Usage: %s", help.usage); + free(err_msg); } return TRUE; @@ -3706,9 +3746,11 @@ gboolean cmd_autoping(gchar **args, struct cmd_help_t help) { char *value = args[0]; - int intval; - if (_strtoi(value, &intval, 0, INT_MAX) == 0) { + int intval = 0; + char *err_msg = NULL; + gboolean res = _strtoi(value, &intval, 0, INT_MAX, &err_msg); + if (res) { prefs_set_autoping(intval); iq_set_autoping(intval); if (intval == 0) { @@ -3717,7 +3759,9 @@ cmd_autoping(gchar **args, struct cmd_help_t help) cons_show("Autoping interval set to %d seconds.", intval); } } else { + cons_show(err_msg); cons_show("Usage: %s", help.usage); + free(err_msg); } return TRUE; @@ -3748,7 +3792,6 @@ cmd_autoaway(gchar **args, struct cmd_help_t help) { char *setting = args[0]; char *value = args[1]; - int minutesval; if ((strcmp(setting, "mode") != 0) && (strcmp(setting, "time") != 0) && (strcmp(setting, "message") != 0) && (strcmp(setting, "check") != 0)) { @@ -3769,9 +3812,15 @@ cmd_autoaway(gchar **args, struct cmd_help_t help) } if (strcmp(setting, "time") == 0) { - if (_strtoi(value, &minutesval, 1, INT_MAX) == 0) { + int minutesval = 0; + char *err_msg = NULL; + gboolean res = _strtoi(value, &minutesval, 1, INT_MAX, &err_msg); + if (res) { prefs_set_autoaway_time(minutesval); cons_show("Auto away time set to: %d minutes.", minutesval); + } else { + cons_show(err_msg); + free(err_msg); } return TRUE; @@ -3808,13 +3857,18 @@ cmd_priority(gchar **args, struct cmd_help_t help) } char *value = args[0]; - int intval; - if (_strtoi(value, &intval, -128, 127) == 0) { + int intval = 0; + char *err_msg = NULL; + gboolean res = _strtoi(value, &intval, -128, 127, &err_msg); + if (res) { accounts_set_priority_all(jabber_get_account_name(), intval); resource_presence_t last_presence = accounts_get_last_presence(jabber_get_account_name()); presence_update(last_presence, jabber_get_presence_message(), 0); cons_show("Priority set to %d.", intval); + } else { + cons_show(err_msg); + free(err_msg); } return TRUE; @@ -4358,8 +4412,8 @@ _cmd_set_boolean_preference(gchar *arg, struct cmd_help_t help, return TRUE; } -static int -_strtoi(char *str, int *saveptr, int min, int max) +static gboolean +_strtoi(char *str, int *saveptr, int min, int max, char **err_msg) { char *ptr; int val; @@ -4367,16 +4421,22 @@ _strtoi(char *str, int *saveptr, int min, int max) errno = 0; val = (int)strtol(str, &ptr, 0); if (errno != 0 || *str == '\0' || *ptr != '\0') { - cons_show("Could not convert \"%s\" to a number.", str); - return -1; + GString *err_str = g_string_new(""); + g_string_printf(err_str, "Could not convert \"%s\" to a number.", str); + *err_msg = err_str->str; + g_string_free(err_str, FALSE); + return FALSE; } else if (val < min || val > max) { - cons_show("Value %s out of range. Must be in %d..%d.", str, min, max); - return -1; + GString *err_str = g_string_new(""); + g_string_printf(err_str, "Value %s out of range. Must be in %d..%d.", str, min, max); + *err_msg = err_str->str; + g_string_free(err_str, FALSE); + return FALSE; } *saveptr = val; - return 0; + return TRUE; } static void From e7e1688d8aa3e7deaea7e15cad7c189a32c570e0 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 16 Mar 2015 01:06:40 +0000 Subject: [PATCH 144/252] Moved _strtoi to common, strtoi_range --- src/command/commands.c | 50 ++++++++++-------------------------------- src/common.c | 27 +++++++++++++++++++++++ src/common.h | 1 + 3 files changed, 39 insertions(+), 39 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index 400a7c8d..4919648a 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -72,7 +72,6 @@ static void _update_presence(const resource_presence_t presence, const char * const show, gchar **args); static gboolean _cmd_set_boolean_preference(gchar *arg, struct cmd_help_t help, const char * const display, preference_t pref); -static gboolean _strtoi(char *str, int *saveptr, int min, int max, char **err_msg); static void _cmd_show_filtered_help(char *heading, gchar *cmd_filter[], int filter_size); static gint _compare_commands(Command *a, Command *b); static void _who_room(gchar **args, struct cmd_help_t help); @@ -213,7 +212,7 @@ cmd_connect(gchar **args, struct cmd_help_t help) if (g_hash_table_contains(options, "port")) { char *port_str = g_hash_table_lookup(options, "port"); char *err_msg = NULL; - gboolean res = _strtoi(port_str, &port, 1, 65535, &err_msg); + gboolean res = strtoi_range(port_str, &port, 1, 65535, &err_msg); if (!res) { cons_show(err_msg); cons_show(""); @@ -469,7 +468,7 @@ cmd_account(gchar **args, struct cmd_help_t help) } else if (strcmp(property, "port") == 0) { int port; char *err_msg = NULL; - gboolean res = _strtoi(value, &port, 1, 65535, &err_msg); + gboolean res = strtoi_range(value, &port, 1, 65535, &err_msg); if (!res) { cons_show(err_msg); cons_show(""); @@ -529,7 +528,7 @@ cmd_account(gchar **args, struct cmd_help_t help) } else if (valid_resource_presence_string(property)) { int intval; char *err_msg = NULL; - gboolean res = _strtoi(value, &intval, -128, 127, &err_msg); + gboolean res = strtoi_range(value, &intval, -128, 127, &err_msg); if (res) { resource_presence_t presence_type = resource_presence_from_string(property); switch (presence_type) @@ -1575,7 +1574,7 @@ cmd_roster(gchar **args, struct cmd_help_t help) } int intval = 0; char *err_msg = NULL; - gboolean res = _strtoi(args[1], &intval, 1, 99, &err_msg); + gboolean res = strtoi_range(args[1], &intval, 1, 99, &err_msg); if (res) { prefs_set_roster_size(intval); cons_show("Roster screen size set to: %d%%", intval); @@ -2859,7 +2858,7 @@ cmd_occupants(gchar **args, struct cmd_help_t help) } else { int intval = 0; char *err_msg = NULL; - gboolean res = _strtoi(args[1], &intval, 1, 99, &err_msg); + gboolean res = strtoi_range(args[1], &intval, 1, 99, &err_msg); if (res) { prefs_set_occupants_size(intval); cons_show("Occupants screen size set to: %d%%", intval); @@ -3630,7 +3629,7 @@ cmd_inpblock(gchar **args, struct cmd_help_t help) int intval = 0; char *err_msg = NULL; - gboolean res = _strtoi(value, &intval, 1, 1000, &err_msg); + gboolean res = strtoi_range(value, &intval, 1, 1000, &err_msg); if (res) { cons_show("Input blocking set to %d milliseconds.", intval); prefs_set_inpblock(intval); @@ -3676,7 +3675,7 @@ cmd_log(gchar **args, struct cmd_help_t help) int intval = 0; char *err_msg = NULL; - gboolean res = _strtoi(value, &intval, PREFS_MIN_LOG_SIZE, INT_MAX, &err_msg); + gboolean res = strtoi_range(value, &intval, PREFS_MIN_LOG_SIZE, INT_MAX, &err_msg); if (res) { prefs_set_max_log_size(intval); cons_show("Log maxinum size set to %d bytes", intval); @@ -3725,7 +3724,7 @@ cmd_reconnect(gchar **args, struct cmd_help_t help) int intval = 0; char *err_msg = NULL; - gboolean res = _strtoi(value, &intval, 0, INT_MAX, &err_msg); + gboolean res = strtoi_range(value, &intval, 0, INT_MAX, &err_msg); if (res) { prefs_set_reconnect(intval); if (intval == 0) { @@ -3749,7 +3748,7 @@ cmd_autoping(gchar **args, struct cmd_help_t help) int intval = 0; char *err_msg = NULL; - gboolean res = _strtoi(value, &intval, 0, INT_MAX, &err_msg); + gboolean res = strtoi_range(value, &intval, 0, INT_MAX, &err_msg); if (res) { prefs_set_autoping(intval); iq_set_autoping(intval); @@ -3814,7 +3813,7 @@ cmd_autoaway(gchar **args, struct cmd_help_t help) if (strcmp(setting, "time") == 0) { int minutesval = 0; char *err_msg = NULL; - gboolean res = _strtoi(value, &minutesval, 1, INT_MAX, &err_msg); + gboolean res = strtoi_range(value, &minutesval, 1, INT_MAX, &err_msg); if (res) { prefs_set_autoaway_time(minutesval); cons_show("Auto away time set to: %d minutes.", minutesval); @@ -3860,7 +3859,7 @@ cmd_priority(gchar **args, struct cmd_help_t help) int intval = 0; char *err_msg = NULL; - gboolean res = _strtoi(value, &intval, -128, 127, &err_msg); + gboolean res = strtoi_range(value, &intval, -128, 127, &err_msg); if (res) { accounts_set_priority_all(jabber_get_account_name(), intval); resource_presence_t last_presence = accounts_get_last_presence(jabber_get_account_name()); @@ -4412,33 +4411,6 @@ _cmd_set_boolean_preference(gchar *arg, struct cmd_help_t help, return TRUE; } -static gboolean -_strtoi(char *str, int *saveptr, int min, int max, char **err_msg) -{ - char *ptr; - int val; - - errno = 0; - val = (int)strtol(str, &ptr, 0); - if (errno != 0 || *str == '\0' || *ptr != '\0') { - GString *err_str = g_string_new(""); - g_string_printf(err_str, "Could not convert \"%s\" to a number.", str); - *err_msg = err_str->str; - g_string_free(err_str, FALSE); - return FALSE; - } else if (val < min || val > max) { - GString *err_str = g_string_new(""); - g_string_printf(err_str, "Value %s out of range. Must be in %d..%d.", str, min, max); - *err_msg = err_str->str; - g_string_free(err_str, FALSE); - return FALSE; - } - - *saveptr = val; - - return TRUE; -} - static void _cmd_show_filtered_help(char *heading, gchar *cmd_filter[], int filter_size) { diff --git a/src/common.c b/src/common.c index 47598ddd..653be720 100644 --- a/src/common.c +++ b/src/common.c @@ -202,6 +202,33 @@ str_contains(const char str[], int size, char ch) return 0; } +gboolean +strtoi_range(char *str, int *saveptr, int min, int max, char **err_msg) +{ + char *ptr; + int val; + + errno = 0; + val = (int)strtol(str, &ptr, 0); + if (errno != 0 || *str == '\0' || *ptr != '\0') { + GString *err_str = g_string_new(""); + g_string_printf(err_str, "Could not convert \"%s\" to a number.", str); + *err_msg = err_str->str; + g_string_free(err_str, FALSE); + return FALSE; + } else if (val < min || val > max) { + GString *err_str = g_string_new(""); + g_string_printf(err_str, "Value %s out of range. Must be in %d..%d.", str, min, max); + *err_msg = err_str->str; + g_string_free(err_str, FALSE); + return FALSE; + } + + *saveptr = val; + + return TRUE; +} + int utf8_display_len(const char * const str) { diff --git a/src/common.h b/src/common.h index d64ea33a..9521a701 100644 --- a/src/common.h +++ b/src/common.h @@ -111,6 +111,7 @@ gboolean mkdir_recursive(const char *dir); char * str_replace(const char *string, const char *substr, const char *replacement); int str_contains(const char str[], int size, char ch); +gboolean strtoi_range(char *str, int *saveptr, int min, int max, char **err_msg); int utf8_display_len(const char * const str); gboolean utf8_is_printable(const wint_t ch); char * prof_getline(FILE *stream); From 981618b7da2d151d51987c3942e959d6838b08ae Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 16 Mar 2015 01:29:03 +0000 Subject: [PATCH 145/252] Added static functions to commands.c for sending messages --- src/command/commands.c | 65 +++++++++++++++++++++++------------------- src/ui/window.c | 1 - 2 files changed, 35 insertions(+), 31 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index 4919648a..c53782c7 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -76,6 +76,8 @@ static void _cmd_show_filtered_help(char *heading, gchar *cmd_filter[], int filt static gint _compare_commands(Command *a, Command *b); static void _who_room(gchar **args, struct cmd_help_t help); static void _who_roster(gchar **args, struct cmd_help_t help); +static void _send_chat_message(const char * const barejid, const char * const message); +static void _send_otr_chat_message(const char * const barejid, const char * const message); extern GHashTable *commands; @@ -121,24 +123,12 @@ cmd_execute_default(const char * inp) return TRUE; } if (otr_is_secure(chatwin->barejid)) { - char *encrypted = otr_encrypt_message(chatwin->barejid, inp); - if (encrypted != NULL) { - char *id = message_send_chat_encrypted(chatwin->barejid, encrypted); - otr_free_message(encrypted); - chat_log_otr_msg_out(chatwin->barejid, inp); - ui_outgoing_chat_msg(chatwin->barejid, inp, id); - } else { - cons_show_error("Failed to send message."); - } + _send_otr_chat_message(chatwin->barejid, inp); } else { - char *id = message_send_chat(chatwin->barejid, inp); - chat_log_msg_out(chatwin->barejid, inp); - ui_outgoing_chat_msg(chatwin->barejid, inp, id); + _send_chat_message(chatwin->barejid, inp); } #else - char *id = message_send_chat(chatwin->barejid, inp); - chat_log_msg_out(chatwin->barejid, inp); - ui_outgoing_chat_msg(chatwin->barejid, inp, id); + _send_chat_message(chatwin->barejid, inp); #endif } break; @@ -1388,6 +1378,7 @@ cmd_msg(gchar **args, struct cmd_help_t help) if (win_type == WIN_CHAT || win_type == WIN_CONSOLE) { chat_log_otr_msg_out(barejid, msg); } + free(id); } else { cons_show_error("Failed to encrypt and send message,"); } @@ -1412,6 +1403,7 @@ cmd_msg(gchar **args, struct cmd_help_t help) if (win_type == WIN_CHAT || win_type == WIN_CONSOLE) { chat_log_msg_out(barejid, msg); } + free(id); } return TRUE; #else @@ -1420,6 +1412,7 @@ cmd_msg(gchar **args, struct cmd_help_t help) if (win_type == WIN_CHAT || win_type == WIN_CONSOLE) { chat_log_msg_out(barejid, msg); } + free(id); return TRUE; #endif @@ -3184,24 +3177,12 @@ cmd_tiny(gchar **args, struct cmd_help_t help) ProfChatWin *chatwin = wins_get_current_chat(); #ifdef HAVE_LIBOTR if (otr_is_secure(chatwin->barejid)) { - char *encrypted = otr_encrypt_message(chatwin->barejid, tiny); - if (encrypted != NULL) { - char *id = message_send_chat_encrypted(chatwin->barejid, encrypted); - chat_log_otr_msg_out(chatwin->barejid, tiny); - ui_outgoing_chat_msg(chatwin->barejid, tiny, id); - otr_free_message(encrypted); - } else { - cons_show_error("Failed to send message."); - } + _send_otr_chat_message(chatwin->barejid, tiny); } else { - char *id = message_send_chat(chatwin->barejid, tiny); - chat_log_msg_out(chatwin->barejid, tiny); - ui_outgoing_chat_msg(chatwin->barejid, tiny, id); + _send_chat_message(chatwin->barejid, tiny); } #else - char *id = message_send_chat(chatwin->barejid, tiny); - chat_log_msg_out(chatwin->barejid, tiny); - ui_outgoing_chat_msg(chatwin->barejid, tiny, id); + _send_chat_message(chatwin->barejid, tiny); #endif } else if (win_type == WIN_PRIVATE) { ProfPrivateWin *privatewin = wins_get_current_private(); @@ -4455,3 +4436,27 @@ gint _compare_commands(Command *a, Command *b) return result; } + +static void +_send_chat_message(const char * const barejid, const char * const message) +{ + char *id = message_send_chat(barejid, message); + chat_log_msg_out(barejid, message); + ui_outgoing_chat_msg(barejid, message, id); + free(id); +} + +static void +_send_otr_chat_message(const char * const barejid, const char * const message) +{ + char *encrypted = otr_encrypt_message(barejid, message); + if (encrypted != NULL) { + char *id = message_send_chat_encrypted(barejid, encrypted); + chat_log_otr_msg_out(barejid, message); + ui_outgoing_chat_msg(barejid, message, id); + otr_free_message(encrypted); + free(id); + } else { + cons_show_error("Failed to encrypt and send message."); + } +} \ No newline at end of file diff --git a/src/ui/window.c b/src/ui/window.c index 4663089f..2a1b1a7b 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -906,7 +906,6 @@ win_print_with_receipt(ProfWin *window, const char show_char, GTimeVal *tstamp, DeliveryReceipt *receipt = malloc(sizeof(struct delivery_receipt_t)); receipt->id = strdup(id); receipt->received = FALSE; - free(id); buffer_push(window->layout->buffer, show_char, time, flags, theme_item, from, message, receipt); _win_print(window, show_char, time, flags, theme_item, from, message, receipt); From d50754aac69cccf653d8c5599d5ae1d1938944b9 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 16 Mar 2015 01:39:43 +0000 Subject: [PATCH 146/252] Removed window checks before logging in cmd_msg --- src/command/commands.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index c53782c7..07c869b8 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -1375,9 +1375,7 @@ cmd_msg(gchar **args, struct cmd_help_t help) char *id = message_send_chat_encrypted(barejid, encrypted); otr_free_message(encrypted); ui_outgoing_chat_msg(barejid, msg, id); - if (win_type == WIN_CHAT || win_type == WIN_CONSOLE) { - chat_log_otr_msg_out(barejid, msg); - } + chat_log_otr_msg_out(barejid, msg); free(id); } else { cons_show_error("Failed to encrypt and send message,"); @@ -1400,18 +1398,14 @@ cmd_msg(gchar **args, struct cmd_help_t help) id = message_send_chat(barejid, msg); } ui_outgoing_chat_msg(barejid, msg, id); - if (win_type == WIN_CHAT || win_type == WIN_CONSOLE) { - chat_log_msg_out(barejid, msg); - } + chat_log_msg_out(barejid, msg); free(id); } return TRUE; #else char *id = message_send_chat(barejid, msg); ui_outgoing_chat_msg(barejid, msg, id); - if (win_type == WIN_CHAT || win_type == WIN_CONSOLE) { - chat_log_msg_out(barejid, msg); - } + chat_log_msg_out(barejid, msg); free(id); return TRUE; #endif From ec57c72fb4ecf7266f16bcb53e260e0c83685c32 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 16 Mar 2015 01:48:12 +0000 Subject: [PATCH 147/252] Use static functions in cmd_msg --- src/command/commands.c | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index 07c869b8..1ecaeb6a 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -1370,20 +1370,9 @@ cmd_msg(gchar **args, struct cmd_help_t help) if (msg != NULL) { #ifdef HAVE_LIBOTR if (otr_is_secure(barejid)) { - char *encrypted = otr_encrypt_message(barejid, msg); - if (encrypted != NULL) { - char *id = message_send_chat_encrypted(barejid, encrypted); - otr_free_message(encrypted); - ui_outgoing_chat_msg(barejid, msg, id); - chat_log_otr_msg_out(barejid, msg); - free(id); - } else { - cons_show_error("Failed to encrypt and send message,"); - } + _send_otr_chat_message(barejid, msg); } else { prof_otrpolicy_t policy = otr_get_policy(barejid); - char *id = NULL; - if (policy == PROF_OTRPOLICY_ALWAYS) { cons_show_error("Failed to send message. Please check OTR policy"); return TRUE; @@ -1391,22 +1380,20 @@ cmd_msg(gchar **args, struct cmd_help_t help) GString *otr_message = g_string_new(msg); g_string_append(otr_message, OTRL_MESSAGE_TAG_BASE); g_string_append(otr_message, OTRL_MESSAGE_TAG_V2); - id = message_send_chat_encrypted(barejid, otr_message->str); + + char *id = message_send_chat_encrypted(barejid, otr_message->str); + ui_outgoing_chat_msg(barejid, msg, id); + chat_log_msg_out(barejid, msg); + free(id); g_string_free(otr_message, TRUE); } else { - id = message_send_chat(barejid, msg); + _send_chat_message(barejid, msg); } - ui_outgoing_chat_msg(barejid, msg, id); - chat_log_msg_out(barejid, msg); - free(id); } return TRUE; #else - char *id = message_send_chat(barejid, msg); - ui_outgoing_chat_msg(barejid, msg, id); - chat_log_msg_out(barejid, msg); - free(id); + _send_chat_message(barejid, msg); return TRUE; #endif From 11966d39b074e0bff4228067055807274d5d4834 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 16 Mar 2015 21:41:35 +0000 Subject: [PATCH 148/252] Added otr_tag_message, removed commands.c dependency on libotr --- src/command/commands.c | 13 +++---------- src/otr/otr.c | 12 ++++++++++++ src/otr/otr.h | 2 ++ tests/otr/stub_otr.c | 7 ++++++- 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index 1ecaeb6a..ef912d88 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -39,9 +39,6 @@ #include #include #include -#ifdef HAVE_LIBOTR -#include -#endif #include "chat_session.h" #include "command/commands.h" @@ -1377,16 +1374,12 @@ cmd_msg(gchar **args, struct cmd_help_t help) cons_show_error("Failed to send message. Please check OTR policy"); return TRUE; } else if (policy == PROF_OTRPOLICY_OPPORTUNISTIC) { - GString *otr_message = g_string_new(msg); - g_string_append(otr_message, OTRL_MESSAGE_TAG_BASE); - g_string_append(otr_message, OTRL_MESSAGE_TAG_V2); - - char *id = message_send_chat_encrypted(barejid, otr_message->str); + char *otr_tagged_msg = otr_tag_message(msg); + char *id = message_send_chat_encrypted(barejid, otr_tagged_msg); ui_outgoing_chat_msg(barejid, msg, id); chat_log_msg_out(barejid, msg); free(id); - - g_string_free(otr_message, TRUE); + free(otr_tagged_msg); } else { _send_chat_message(barejid, msg); } diff --git a/src/otr/otr.c b/src/otr/otr.c index d0515e97..9dcff1f9 100644 --- a/src/otr/otr.c +++ b/src/otr/otr.c @@ -365,6 +365,18 @@ otr_key_loaded(void) return data_loaded; } +char * +otr_tag_message(const char * const msg) +{ + GString *otr_message = g_string_new(msg); + g_string_append(otr_message, OTRL_MESSAGE_TAG_BASE); + g_string_append(otr_message, OTRL_MESSAGE_TAG_V2); + char *result = otr_message->str; + g_string_free(otr_message, FALSE); + + return result; +} + gboolean otr_is_secure(const char * const recipient) { diff --git a/src/otr/otr.h b/src/otr/otr.h index 58d5c04b..91445a5c 100644 --- a/src/otr/otr.h +++ b/src/otr/otr.h @@ -58,6 +58,8 @@ void otr_poll(void); void otr_on_connect(ProfAccount *account); void otr_keygen(ProfAccount *account); +char* otr_tag_message(const char * const msg); + gboolean otr_key_loaded(void); gboolean otr_is_secure(const char * const recipient); diff --git a/tests/otr/stub_otr.c b/tests/otr/stub_otr.c index 82994034..7a0122b6 100644 --- a/tests/otr/stub_otr.c +++ b/tests/otr/stub_otr.c @@ -52,6 +52,11 @@ gboolean otr_key_loaded(void) return (gboolean)mock(); } +char* otr_tag_message(const char * const msg) +{ + return NULL; +} + gboolean otr_is_secure(const char * const recipient) { return FALSE; @@ -98,4 +103,4 @@ void otr_free_message(char *message) {} prof_otrpolicy_t otr_get_policy(const char * const recipient) { return PROF_OTRPOLICY_MANUAL; -} \ No newline at end of file +} From 848baa95a2bb74f85ab5c5442d89e5098060ae5a Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 16 Mar 2015 21:59:11 +0000 Subject: [PATCH 149/252] Added static function for sending otr tagged messages --- src/command/commands.c | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index ef912d88..e4717bff 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -75,6 +75,7 @@ static void _who_room(gchar **args, struct cmd_help_t help); static void _who_roster(gchar **args, struct cmd_help_t help); static void _send_chat_message(const char * const barejid, const char * const message); static void _send_otr_chat_message(const char * const barejid, const char * const message); +static void _send_otr_tagged_chat_message(const char * const barejid, const char * const message); extern GHashTable *commands; @@ -1358,31 +1359,22 @@ cmd_msg(gchar **args, struct cmd_help_t help) return TRUE; } else { - // get barejid char *barejid = roster_barejid_from_name(usr); if (barejid == NULL) { barejid = usr; } - if (msg != NULL) { + if (msg) { #ifdef HAVE_LIBOTR + prof_otrpolicy_t policy = otr_get_policy(barejid); if (otr_is_secure(barejid)) { _send_otr_chat_message(barejid, msg); + } else if (policy == PROF_OTRPOLICY_ALWAYS) { + cons_show_error("Failed to send message. Please check OTR policy"); + } else if (policy == PROF_OTRPOLICY_OPPORTUNISTIC) { + _send_otr_tagged_chat_message(barejid, msg); } else { - prof_otrpolicy_t policy = otr_get_policy(barejid); - if (policy == PROF_OTRPOLICY_ALWAYS) { - cons_show_error("Failed to send message. Please check OTR policy"); - return TRUE; - } else if (policy == PROF_OTRPOLICY_OPPORTUNISTIC) { - char *otr_tagged_msg = otr_tag_message(msg); - char *id = message_send_chat_encrypted(barejid, otr_tagged_msg); - ui_outgoing_chat_msg(barejid, msg, id); - chat_log_msg_out(barejid, msg); - free(id); - free(otr_tagged_msg); - } else { - _send_chat_message(barejid, msg); - } + _send_chat_message(barejid, msg); } return TRUE; #else @@ -1390,7 +1382,7 @@ cmd_msg(gchar **args, struct cmd_help_t help) return TRUE; #endif - } else { // msg == NULL + } else { ui_new_chat_win(barejid); #ifdef HAVE_LIBOTR if (otr_is_secure(barejid)) { @@ -4433,4 +4425,15 @@ _send_otr_chat_message(const char * const barejid, const char * const message) } else { cons_show_error("Failed to encrypt and send message."); } +} + +static void +_send_otr_tagged_chat_message(const char * const barejid, const char * const message) +{ + char *otr_tagged_msg = otr_tag_message(message); + char *id = message_send_chat_encrypted(barejid, otr_tagged_msg); + ui_outgoing_chat_msg(barejid, message, id); + chat_log_msg_out(barejid, message); + free(id); + free(otr_tagged_msg); } \ No newline at end of file From 311b64a379a7af82b09ec4424246b892cedcfeb9 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 16 Mar 2015 23:03:31 +0000 Subject: [PATCH 150/252] Tidy cmd_tiny --- src/command/commands.c | 85 ++++++++++++++++++++++++------------------ 1 file changed, 48 insertions(+), 37 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index e4717bff..1a55765e 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -3125,47 +3125,58 @@ gboolean cmd_tiny(gchar **args, struct cmd_help_t help) { char *url = args[0]; - win_type_t win_type = ui_current_win_type(); + ProfWin *current = wins_get_current(); + + if (current->type != WIN_CHAT && current->type != WIN_MUC && current->type != WIN_PRIVATE) { + cons_show("/tiny can only be used in chat windows"); + return TRUE; + } if (!tinyurl_valid(url)) { - GString *error = g_string_new("/tiny, badly formed URL: "); - g_string_append(error, url); - cons_show_error(error->str); - if (win_type != WIN_CONSOLE) { - ui_current_error_line(error->str); - } - g_string_free(error, TRUE); - } else if (win_type != WIN_CONSOLE) { - char *tiny = tinyurl_get(url); - - if (tiny != NULL) { - if (win_type == WIN_CHAT) { - ProfChatWin *chatwin = wins_get_current_chat(); -#ifdef HAVE_LIBOTR - if (otr_is_secure(chatwin->barejid)) { - _send_otr_chat_message(chatwin->barejid, tiny); - } else { - _send_chat_message(chatwin->barejid, tiny); - } -#else - _send_chat_message(chatwin->barejid, tiny); -#endif - } else if (win_type == WIN_PRIVATE) { - ProfPrivateWin *privatewin = wins_get_current_private(); - message_send_private(privatewin->fulljid, tiny); - ui_outgoing_private_msg(privatewin->fulljid, tiny); - } else if (win_type == WIN_MUC) { - ProfMucWin *mucwin = wins_get_current_muc(); - message_send_groupchat(mucwin->roomjid, tiny); - } - free(tiny); - } else { - cons_show_error("Couldn't get tinyurl."); - } - } else { - cons_show("/tiny can only be used in chat windows"); + win_vprint(current, '-', NULL, 0, THEME_ERROR, "", "/tiny, badly formed URL: %s", url); + return TRUE; } + char *tiny = tinyurl_get(url); + if (!tiny) { + win_print(current, '-', NULL, 0, THEME_ERROR, "", "Couldn't create tinyurl."); + return TRUE; + } + + switch (current->type){ + case WIN_CHAT: + { + ProfChatWin *chatwin = wins_get_current_chat(); +#ifdef HAVE_LIBOTR + if (otr_is_secure(chatwin->barejid)) { + _send_otr_chat_message(chatwin->barejid, tiny); + } else { + _send_chat_message(chatwin->barejid, tiny); + } +#else + _send_chat_message(chatwin->barejid, tiny); +#endif + break; + } + case WIN_PRIVATE: + { + ProfPrivateWin *privatewin = wins_get_current_private(); + message_send_private(privatewin->fulljid, tiny); + ui_outgoing_private_msg(privatewin->fulljid, tiny); + break; + } + case WIN_MUC: + { + ProfMucWin *mucwin = wins_get_current_muc(); + message_send_groupchat(mucwin->roomjid, tiny); + break; + } + default: + break; + } + + free(tiny); + return TRUE; } From d6977e31cd933917c748983caaa511e8b12cbb02 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 17 Mar 2015 20:42:21 +0000 Subject: [PATCH 151/252] Fix buffer entry free --- src/ui/buffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ui/buffer.c b/src/ui/buffer.c index d16eec76..40a994f1 100644 --- a/src/ui/buffer.c +++ b/src/ui/buffer.c @@ -131,9 +131,9 @@ _free_entry(ProfBuffEntry *entry) free(entry->message); free(entry->from); g_date_time_unref(entry->time); - free(entry); if (entry->receipt) { free(entry->receipt->id); free(entry->receipt); } + free(entry); } \ No newline at end of file From e7e94eed7fb1bfd87c13a6d5a2a98ed9f110e89e Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 18 Mar 2015 21:30:43 +0000 Subject: [PATCH 152/252] Added keybindings for rxvt --- src/ui/inputwin.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index dbf1d7f0..f55be0f1 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -370,19 +370,26 @@ _inp_rl_startup_hook(void) rl_bind_keyseq("\\e[20~", _inp_rl_win9_handler); rl_bind_keyseq("\\e[21~", _inp_rl_win0_handler); -#ifdef PLATFORM_OSX rl_bind_keyseq("\\e[1;9D", _inp_rl_altleft_handler); - rl_bind_keyseq("\\e[1;9C", _inp_rl_altright_handler); - rl_bind_keyseq("\\e\\e[5~", _inp_rl_altpageup_handler); - rl_bind_keyseq("\\e\\e[6~", _inp_rl_altpagedown_handler); -#else rl_bind_keyseq("\\e[1;3D", _inp_rl_altleft_handler); + rl_bind_keyseq("\\e\\e[D", _inp_rl_altleft_handler); + + rl_bind_keyseq("\\e[1;9C", _inp_rl_altright_handler); rl_bind_keyseq("\\e[1;3C", _inp_rl_altright_handler); + rl_bind_keyseq("\\e\\e[C", _inp_rl_altright_handler); + + rl_bind_keyseq("\\e\\e[5~", _inp_rl_altpageup_handler); rl_bind_keyseq("\\e[5;3~", _inp_rl_altpageup_handler); + rl_bind_keyseq("\\e\\eOy", _inp_rl_altpageup_handler); + + rl_bind_keyseq("\\e\\e[6~", _inp_rl_altpagedown_handler); rl_bind_keyseq("\\e[6;3~", _inp_rl_altpagedown_handler); -#endif + rl_bind_keyseq("\\e\\eOs", _inp_rl_altpagedown_handler); + rl_bind_keyseq("\\e[5~", _inp_rl_pageup_handler); + rl_bind_keyseq("\\eOy", _inp_rl_pageup_handler); rl_bind_keyseq("\\e[6~", _inp_rl_pagedown_handler); + rl_bind_keyseq("\\eOs", _inp_rl_pagedown_handler); rl_bind_key('\t', _inp_rl_tab_handler); rl_bind_key(CTRL('L'), _inp_rl_clear_handler); From f1f047889eed360a0c91be4fcabd24199089c02a Mon Sep 17 00:00:00 2001 From: James Booth Date: Thu, 19 Mar 2015 22:57:51 +0000 Subject: [PATCH 153/252] Added individual options to send and request delivery receipts --- src/command/command.c | 48 ++++++++++++++++++++++++++++++++++------ src/command/commands.c | 12 ++++++++-- src/config/preferences.c | 9 +++++--- src/config/preferences.h | 3 ++- src/ui/buffer.c | 2 +- src/ui/console.c | 12 +++++++--- src/ui/core.c | 2 +- src/xmpp/message.c | 6 ++--- 8 files changed, 73 insertions(+), 21 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index 0a4be511..e165254e 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -101,6 +101,7 @@ static char * _resource_autocomplete(const char * const input); static char * _titlebar_autocomplete(const char * const input); static char * _inpblock_autocomplete(const char * const input); static char * _time_autocomplete(const char * const input); +static char * _receipts_autocomplete(const char * const input); GHashTable *commands = NULL; @@ -920,12 +921,14 @@ static struct cmd_t command_defs[] = NULL } } }, { "/receipts", - cmd_receipts, parse_args, 1, 1, &cons_receipts_setting, - { "/receipts on|off", "Message delivery receipts.", - { "/receipts on|off", - "----------------", - "Enable or disable message delivery receipts.", - "The user interface will indicate when a message has been received.", + cmd_receipts, parse_args, 2, 2, &cons_receipts_setting, + { "/receipts send|request on|off", "Message delivery receipts.", + { "/receipts send|request on|off", + "-----------------------------", + "Enable or disable message delivery receipts. The interface will indicate when a message has been received.", + "", + "send on|off : Enable or disable sending of delivery receipts.", + "request on|off : Enable or disable sending of delivery receipt requests.", NULL } } }, { "/reconnect", @@ -1198,6 +1201,7 @@ static Autocomplete time_ac; static Autocomplete time_statusbar_ac; static Autocomplete resource_ac; static Autocomplete inpblock_ac; +static Autocomplete receipts_ac; /* * Initialise command autocompleter and history @@ -1555,6 +1559,10 @@ cmd_init(void) inpblock_ac = autocomplete_new(); autocomplete_add(inpblock_ac, "timeout"); autocomplete_add(inpblock_ac, "dynamic"); + + receipts_ac = autocomplete_new(); + autocomplete_add(receipts_ac, "send"); + autocomplete_add(receipts_ac, "request"); } void @@ -1612,6 +1620,7 @@ cmd_uninit(void) autocomplete_free(time_statusbar_ac); autocomplete_free(resource_ac); autocomplete_free(inpblock_ac); + autocomplete_free(receipts_ac); } gboolean @@ -1778,6 +1787,7 @@ cmd_reset_autocomplete() autocomplete_reset(time_statusbar_ac); autocomplete_reset(resource_ac); autocomplete_reset(inpblock_ac); + autocomplete_reset(receipts_ac); if (ui_current_win_type() == WIN_CHAT) { ProfChatWin *chatwin = wins_get_current_chat(); @@ -1897,7 +1907,7 @@ _cmd_complete_parameters(const char * const input) // autocomplete boolean settings gchar *boolean_choices[] = { "/beep", "/intype", "/states", "/outtype", "/flash", "/splash", "/chlog", "/grlog", "/mouse", "/history", - "/vercheck", "/privileges", "/presence", "/wrap", "/carbons", "/receipts" }; + "/vercheck", "/privileges", "/presence", "/wrap", "/carbons" }; for (i = 0; i < ARRAY_SIZE(boolean_choices); i++) { result = autocomplete_param_with_func(input, boolean_choices[i], prefs_autocomplete_boolean_choice); @@ -1998,6 +2008,7 @@ _cmd_complete_parameters(const char * const input) g_hash_table_insert(ac_funcs, "/titlebar", _titlebar_autocomplete); g_hash_table_insert(ac_funcs, "/inpblock", _inpblock_autocomplete); g_hash_table_insert(ac_funcs, "/time", _time_autocomplete); + g_hash_table_insert(ac_funcs, "/receipts", _receipts_autocomplete); int len = strlen(input); char parsed[len+1]; @@ -2814,6 +2825,29 @@ _statuses_autocomplete(const char * const input) return NULL; } +static char * +_receipts_autocomplete(const char * const input) +{ + char *result = NULL; + + result = autocomplete_param_with_func(input, "/receipts send", prefs_autocomplete_boolean_choice); + if (result != NULL) { + return result; + } + + result = autocomplete_param_with_func(input, "/receipts request", prefs_autocomplete_boolean_choice); + if (result != NULL) { + return result; + } + + result = autocomplete_param_with_ac(input, "/receipts", receipts_ac, TRUE); + if (result != NULL) { + return result; + } + + return NULL; +} + static char * _alias_autocomplete(const char * const input) { diff --git a/src/command/commands.c b/src/command/commands.c index 1a55765e..86285a46 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -4016,8 +4016,16 @@ cmd_carbons(gchar **args, struct cmd_help_t help) gboolean cmd_receipts(gchar **args, struct cmd_help_t help) { - return _cmd_set_boolean_preference(args[0], help, - "Message delivery receipts", PREF_RECEIPTS); + if (g_strcmp0(args[0], "send") == 0) { + return _cmd_set_boolean_preference(args[1], help, + "Send delivery receipts", PREF_RECEIPTS_SEND); + } else if (g_strcmp0(args[0], "request") == 0) { + return _cmd_set_boolean_preference(args[1], help, + "Request delivery receipets", PREF_RECEIPTS_REQUEST); + } else { + cons_show("Usage: %s", help.usage); + return TRUE; + } } gboolean diff --git a/src/config/preferences.c b/src/config/preferences.c index ce25ff9e..fdaae11f 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -543,7 +543,8 @@ _get_group(preference_t pref) case PREF_CONNECT_ACCOUNT: case PREF_DEFAULT_ACCOUNT: case PREF_CARBONS: - case PREF_RECEIPTS: + case PREF_RECEIPTS_SEND: + case PREF_RECEIPTS_REQUEST: return PREF_GROUP_CONNECTION; case PREF_OTR_LOG: case PREF_OTR_POLICY: @@ -580,8 +581,10 @@ _get_key(preference_t pref) return "history"; case PREF_CARBONS: return "carbons"; - case PREF_RECEIPTS: - return "receipts"; + case PREF_RECEIPTS_SEND: + return "receipts.send"; + case PREF_RECEIPTS_REQUEST: + return "receipts.request"; case PREF_MOUSE: return "mouse"; case PREF_OCCUPANTS: diff --git a/src/config/preferences.h b/src/config/preferences.h index b031e857..a9413886 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -60,7 +60,8 @@ typedef enum { PREF_INTYPE, PREF_HISTORY, PREF_CARBONS, - PREF_RECEIPTS, + PREF_RECEIPTS_SEND, + PREF_RECEIPTS_REQUEST, PREF_MOUSE, PREF_OCCUPANTS, PREF_OCCUPANTS_SIZE, diff --git a/src/ui/buffer.c b/src/ui/buffer.c index 40a994f1..0848b60f 100644 --- a/src/ui/buffer.c +++ b/src/ui/buffer.c @@ -106,7 +106,7 @@ buffer_mark_received(ProfBuff buffer, const char * const id) GSList *entries = buffer->entries; while (entries) { ProfBuffEntry *entry = entries->data; - if (entry->receipt) { + if (entry->receipt && g_strcmp0(entry->receipt->id, id) == 0) { if (!entry->receipt->received) { entry->receipt->received = TRUE; return TRUE; diff --git a/src/ui/console.c b/src/ui/console.c index cd74f455..328f59aa 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -1199,10 +1199,16 @@ cons_carbons_setting(void) void cons_receipts_setting(void) { - if (prefs_get_boolean(PREF_RECEIPTS)) - cons_show("Message receipts (/receipts) : ON"); + if (prefs_get_boolean(PREF_RECEIPTS_REQUEST)) + cons_show("Request receipts (/receipts) : ON"); else - cons_show("Message receipts (/receipts) : OFF"); + cons_show("Request receipts (/receipts) : OFF"); + + if (prefs_get_boolean(PREF_RECEIPTS_SEND)) + cons_show("Send receipts (/receipts) : ON"); + else + cons_show("Send receipts (/receipts) : OFF"); + } void diff --git a/src/ui/core.c b/src/ui/core.c index c00c7838..acb9e550 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -1467,7 +1467,7 @@ ui_outgoing_chat_msg(const char * const barejid, const char * const message, cha ProfChatWin *chatwin = (ProfChatWin*)window; chat_state_active(chatwin->state); - if (prefs_get_boolean(PREF_RECEIPTS) && id) { + if (prefs_get_boolean(PREF_RECEIPTS_REQUEST) && id) { win_print_with_receipt(window, '-', NULL, 0, THEME_TEXT_ME, "me", message, id); } else { win_print(window, '-', NULL, 0, THEME_TEXT_ME, "me", message); diff --git a/src/xmpp/message.c b/src/xmpp/message.c index 7986c668..e6927f76 100644 --- a/src/xmpp/message.c +++ b/src/xmpp/message.c @@ -110,7 +110,7 @@ message_send_chat(const char * const barejid, const char * const msg) if (state) { stanza_attach_state(ctx, message, state); } - if (prefs_get_boolean(PREF_RECEIPTS)) { + if (prefs_get_boolean(PREF_RECEIPTS_REQUEST)) { stanza_attach_receipt_request(ctx, message); } @@ -151,7 +151,7 @@ message_send_chat_encrypted(const char * const barejid, const char * const msg) stanza_attach_state(ctx, message, state); } stanza_attach_carbons_private(ctx, message); - if (prefs_get_boolean(PREF_RECEIPTS)) { + if (prefs_get_boolean(PREF_RECEIPTS_REQUEST)) { stanza_attach_receipt_request(ctx, message); } @@ -621,7 +621,7 @@ _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, } else { handle_incoming_message(jid->barejid, jid->resourcepart, message); } - if (id) { + if (id && prefs_get_boolean(PREF_RECEIPTS_SEND)) { xmpp_stanza_t *receipts = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_RECEIPTS); if (receipts) { char *receipts_name = xmpp_stanza_get_name(receipts); From fac2b2cf665e72f0f7fe66232952401274d51ee7 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 28 Mar 2015 22:51:41 +0000 Subject: [PATCH 154/252] Added check members only room to send mediated invites --- src/muc.c | 14 ++++++++++++++ src/muc.h | 8 ++++++++ src/server_events.c | 3 +++ src/xmpp/message.c | 11 ++++++++++- src/xmpp/stanza.c | 40 ++++++++++++++++++++++++++++++++++++++++ src/xmpp/stanza.h | 2 ++ 6 files changed, 77 insertions(+), 1 deletion(-) diff --git a/src/muc.c b/src/muc.c index ea4ae915..1c5e1825 100644 --- a/src/muc.c +++ b/src/muc.c @@ -62,6 +62,7 @@ typedef struct _muc_room_t { Autocomplete jid_ac; GHashTable *nick_changes; gboolean roster_received; + muc_member_type_t member_type; } ChatRoom; GHashTable *rooms = NULL; @@ -177,6 +178,7 @@ muc_join(const char * const room, const char * const nick, new_room->roster_received = FALSE; new_room->pending_nick_change = FALSE; new_room->autojoin = autojoin; + new_room->member_type = MUC_MEMBER_TYPE_UNKNOWN; g_hash_table_insert(rooms, strdup(room), new_room); } @@ -763,6 +765,18 @@ muc_set_affiliation(const char * const room, const char * const affiliation) } } +muc_member_type_t +muc_member_type(const char * const room) +{ + ChatRoom *chat_room = g_hash_table_lookup(rooms, room); + if (chat_room) { + return chat_room->member_type; + } else { + return MUC_MEMBER_TYPE_UNKNOWN; + } +} + + static void _free_room(ChatRoom *room) { diff --git a/src/muc.h b/src/muc.h index 16f217d0..60cf7108 100644 --- a/src/muc.h +++ b/src/muc.h @@ -56,6 +56,12 @@ typedef enum { MUC_AFFILIATION_OWNER } muc_affiliation_t; +typedef enum { + MUC_MEMBER_TYPE_UNKNOWN, + MUC_MEMBER_TYPE_PUBLIC, + MUC_MEMBER_TYPE_MEMBERS_ONLY +} muc_member_type_t; + typedef struct _muc_occupant_t { char *nick; char *jid; @@ -134,4 +140,6 @@ void muc_set_affiliation(const char * const room, const char * const affiliation char *muc_role_str(const char * const room); char *muc_affiliation_str(const char * const room); +muc_member_type_t muc_member_type(const char * const room); + #endif diff --git a/src/server_events.c b/src/server_events.c index a97e0786..f9f5afe4 100644 --- a/src/server_events.c +++ b/src/server_events.c @@ -697,6 +697,9 @@ handle_muc_self_online(const char * const room, const char * const nick, gboolea } else { ui_room_join(room, TRUE); } + + // TODO send disco info request to room + muc_invites_remove(room); muc_roster_set_complete(room); diff --git a/src/xmpp/message.c b/src/xmpp/message.c index e6927f76..1bb3bcdc 100644 --- a/src/xmpp/message.c +++ b/src/xmpp/message.c @@ -204,7 +204,16 @@ message_send_invite(const char * const roomjid, const char * const contact, { xmpp_conn_t * const conn = connection_get_conn(); xmpp_ctx_t * const ctx = connection_get_ctx(); - xmpp_stanza_t *stanza = stanza_create_invite(ctx, roomjid, contact, reason); + xmpp_stanza_t *stanza; + + muc_member_type_t member_type = muc_member_type(roomjid); + if (member_type == MUC_MEMBER_TYPE_PUBLIC) { + log_debug("Sending direct invite to %s, for %s", contact, roomjid); + stanza = stanza_create_invite(ctx, roomjid, contact, reason); + } else { + log_debug("Sending mediated invite to %s, for %s", contact, roomjid); + stanza = stanza_create_mediated_invite(ctx, roomjid, contact, reason); + } xmpp_send(conn, stanza); xmpp_stanza_release(stanza); diff --git a/src/xmpp/stanza.c b/src/xmpp/stanza.c index 0b291d2e..03567e31 100644 --- a/src/xmpp/stanza.c +++ b/src/xmpp/stanza.c @@ -440,6 +440,46 @@ stanza_create_invite(xmpp_ctx_t *ctx, const char * const room, return message; } +xmpp_stanza_t * +stanza_create_mediated_invite(xmpp_ctx_t *ctx, const char * const room, + const char * const contact, const char * const reason) +{ + xmpp_stanza_t *message, *x, *invite; + + message = xmpp_stanza_new(ctx); + xmpp_stanza_set_name(message, STANZA_NAME_MESSAGE); + xmpp_stanza_set_attribute(message, STANZA_ATTR_TO, room); + char *id = create_unique_id(NULL); + xmpp_stanza_set_id(message, id); + free(id); + + x = xmpp_stanza_new(ctx); + xmpp_stanza_set_name(x, STANZA_NAME_X); + xmpp_stanza_set_ns(x, STANZA_NS_MUC_USER); + + invite = xmpp_stanza_new(ctx); + xmpp_stanza_set_name(invite, STANZA_NAME_INVITE); + xmpp_stanza_set_attribute(invite, STANZA_ATTR_TO, contact); + + if (reason != NULL) { + xmpp_stanza_t *reason_st = xmpp_stanza_new(ctx); + xmpp_stanza_set_name(reason_st, STANZA_NAME_REASON); + xmpp_stanza_t *reason_txt = xmpp_stanza_new(ctx); + xmpp_stanza_set_text(reason_txt, reason); + xmpp_stanza_add_child(reason_st, reason_txt); + xmpp_stanza_release(reason_txt); + xmpp_stanza_add_child(invite, reason_st); + xmpp_stanza_release(reason_st); + } + + xmpp_stanza_add_child(x, invite); + xmpp_stanza_release(invite); + xmpp_stanza_add_child(message, x); + xmpp_stanza_release(x); + + return message; +} + xmpp_stanza_t * stanza_create_room_join_presence(xmpp_ctx_t * const ctx, const char * const full_room_jid, const char * const passwd) diff --git a/src/xmpp/stanza.h b/src/xmpp/stanza.h index 50f3dbd0..744bd7fb 100644 --- a/src/xmpp/stanza.h +++ b/src/xmpp/stanza.h @@ -215,6 +215,8 @@ xmpp_stanza_t* stanza_create_disco_info_iq(xmpp_ctx_t *ctx, const char * const i xmpp_stanza_t* stanza_create_invite(xmpp_ctx_t *ctx, const char * const room, const char * const contact, const char * const reason); +xmpp_stanza_t* stanza_create_mediated_invite(xmpp_ctx_t *ctx, const char * const room, + const char * const contact, const char * const reason); gboolean stanza_contains_chat_state(xmpp_stanza_t *stanza); From 24a45e5292b1aaf0977d2af801827f5738a6b9c1 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 29 Mar 2015 00:21:18 +0000 Subject: [PATCH 155/252] Set members only property when getting room features --- src/muc.c | 13 +++++++++++++ src/muc.h | 2 ++ src/server_events.c | 2 ++ src/xmpp/iq.c | 9 +++++++-- src/xmpp/xmpp.h | 2 +- tests/xmpp/stub_xmpp.c | 2 +- 6 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/muc.c b/src/muc.c index 1c5e1825..ae48d66b 100644 --- a/src/muc.c +++ b/src/muc.c @@ -210,6 +210,19 @@ muc_set_requires_config(const char * const room, gboolean val) } } +void +muc_set_features(const char * const room, GSList *features) +{ + ChatRoom *chat_room = g_hash_table_lookup(rooms, room); + if (chat_room && features) { + if (g_slist_find_custom(features, "muc_membersonly", (GCompareFunc)g_strcmp0)) { + chat_room->member_type = MUC_MEMBER_TYPE_MEMBERS_ONLY; + } else { + chat_room->member_type = MUC_MEMBER_TYPE_PUBLIC; + } + } +} + /* * Returns TRUE if the user is currently in the room */ diff --git a/src/muc.h b/src/muc.h index 60cf7108..2c7b3e7e 100644 --- a/src/muc.h +++ b/src/muc.h @@ -82,6 +82,8 @@ gboolean muc_autojoin(const char * const room); GList* muc_rooms(void); +void muc_set_features(const char * const room, GSList *features); + char* muc_nick(const char * const room); char* muc_password(const char * const room); diff --git a/src/server_events.c b/src/server_events.c index f9f5afe4..882c308c 100644 --- a/src/server_events.c +++ b/src/server_events.c @@ -164,6 +164,7 @@ handle_disco_info(const char *from, GSList *identities, GSList *features) void handle_room_disco_info(const char * const room, GSList *identities, GSList *features) { + muc_set_features(room, features); ui_show_room_disco_info(room, identities, features); } @@ -699,6 +700,7 @@ handle_muc_self_online(const char * const room, const char * const nick, gboolea } // TODO send disco info request to room + iq_room_info_request(room); muc_invites_remove(room); muc_roster_set_complete(room); diff --git a/src/xmpp/iq.c b/src/xmpp/iq.c index 028c586e..573a50ef 100644 --- a/src/xmpp/iq.c +++ b/src/xmpp/iq.c @@ -178,14 +178,14 @@ iq_disco_info_request(gchar *jid) } void -iq_room_info_request(gchar *room) +iq_room_info_request(const char * const room) { xmpp_conn_t * const conn = connection_get_conn(); xmpp_ctx_t * const ctx = connection_get_ctx(); char *id = create_unique_id("room_disco_info"); xmpp_stanza_t *iq = stanza_create_disco_info_iq(ctx, id, room, NULL); - xmpp_id_handler_add(conn, _disco_info_response_handler, id, room); + xmpp_id_handler_add(conn, _disco_info_response_handler, id, strdup(room)); free(id); @@ -1362,6 +1362,7 @@ _disco_info_response_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const sta char *error_message = stanza_get_error_message(stanza); if (room) { handle_room_info_error(room, error_message); + free(room); } else { handle_disco_info_error(from, error_message); } @@ -1422,6 +1423,10 @@ _disco_info_response_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const sta g_slist_free_full(features, free); g_slist_free_full(identities, (GDestroyNotify)_identity_destroy); } + + if (room) { + free(room); + } return 1; } diff --git a/src/xmpp/xmpp.h b/src/xmpp/xmpp.h index 7deb71db..af9e30cc 100644 --- a/src/xmpp/xmpp.h +++ b/src/xmpp/xmpp.h @@ -192,7 +192,7 @@ void iq_send_caps_request_for_jid(const char * const to, const char * const id, const char * const node, const char * const ver); void iq_send_caps_request_legacy(const char * const to, const char * const id, const char * const node, const char * const ver); -void iq_room_info_request(gchar *room); +void iq_room_info_request(const char * const room); void iq_room_affiliation_list(const char * const room, char *affiliation); void iq_room_affiliation_set(const char * const room, const char * const jid, char *affiliation, const char * const reason); diff --git a/tests/xmpp/stub_xmpp.c b/tests/xmpp/stub_xmpp.c index 53a01c95..21c9862d 100644 --- a/tests/xmpp/stub_xmpp.c +++ b/tests/xmpp/stub_xmpp.c @@ -151,7 +151,7 @@ void iq_send_caps_request_for_jid(const char * const to, const char * const id, const char * const node, const char * const ver) {} void iq_send_caps_request_legacy(const char * const to, const char * const id, const char * const node, const char * const ver) {} -void iq_room_info_request(gchar *room) {} +void iq_room_info_request(const char * const room) {} void iq_room_affiliation_list(const char * const room, char *affiliation) {} void iq_room_affiliation_set(const char * const room, const char * const jid, char *affiliation, const char * const reason) {} From 714faeb2e6330a65de6eddbff48a12a6e6f00abc Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 29 Mar 2015 00:55:33 +0000 Subject: [PATCH 156/252] Add callback data to room disco info response handler --- src/command/commands.c | 2 +- src/server_events.c | 9 +-- src/server_events.h | 2 +- src/xmpp/iq.c | 121 ++++++++++++++++++++++++++++++++--------- src/xmpp/xmpp.h | 2 +- tests/xmpp/stub_xmpp.c | 2 +- 6 files changed, 103 insertions(+), 35 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index 86285a46..76da2a93 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -1867,7 +1867,7 @@ cmd_info(gchar **args, struct cmd_help_t help) } } else { ProfMucWin *mucwin = wins_get_current_muc(); - iq_room_info_request(mucwin->roomjid); + iq_room_info_request(mucwin->roomjid, TRUE); ui_show_room_info(mucwin); return TRUE; } diff --git a/src/server_events.c b/src/server_events.c index 882c308c..bab6cb13 100644 --- a/src/server_events.c +++ b/src/server_events.c @@ -162,10 +162,12 @@ handle_disco_info(const char *from, GSList *identities, GSList *features) } void -handle_room_disco_info(const char * const room, GSList *identities, GSList *features) +handle_room_disco_info(const char * const room, GSList *identities, GSList *features, gboolean display) { muc_set_features(room, features); - ui_show_room_disco_info(room, identities, features); + if (display) { + ui_show_room_disco_info(room, identities, features); + } } void @@ -699,8 +701,7 @@ handle_muc_self_online(const char * const room, const char * const nick, gboolea ui_room_join(room, TRUE); } - // TODO send disco info request to room - iq_room_info_request(room); + iq_room_info_request(room, FALSE); muc_invites_remove(room); muc_roster_set_complete(room); diff --git a/src/server_events.h b/src/server_events.h index 403c5bb5..b03e11be 100644 --- a/src/server_events.h +++ b/src/server_events.h @@ -58,7 +58,7 @@ void handle_room_message(const char * const room_jid, const char * const nick, const char * const message); void handle_room_join_error(const char * const room, const char * const err); void handle_room_info_error(const char * const room, const char * const error); -void handle_room_disco_info(const char * const room, GSList *identities, GSList *features); +void handle_room_disco_info(const char * const room, GSList *identities, GSList *features, gboolean display); void handle_room_affiliation_list_result_error(const char * const room, const char * const affiliation, const char * const error); void handle_room_affiliation_list(const char * const room, const char * const affiliation, GSList *jids); diff --git a/src/xmpp/iq.c b/src/xmpp/iq.c index 573a50ef..2cbed0dd 100644 --- a/src/xmpp/iq.c +++ b/src/xmpp/iq.c @@ -58,11 +58,17 @@ #define HANDLE(ns, type, func) xmpp_handler_add(conn, func, ns, STANZA_NAME_IQ, type, ctx) +typedef struct p_room_info_data_t { + char *room; + gboolean display; +} ProfRoomInfoData; + static int _error_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata); static int _ping_get_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata); static int _version_get_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata); static int _disco_info_get_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata); static int _disco_info_response_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata); +static int _room_info_response_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata); static int _version_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata); static int _disco_items_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata); static int _disco_items_get_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata); @@ -178,14 +184,18 @@ iq_disco_info_request(gchar *jid) } void -iq_room_info_request(const char * const room) +iq_room_info_request(const char * const room, gboolean display_result) { xmpp_conn_t * const conn = connection_get_conn(); xmpp_ctx_t * const ctx = connection_get_ctx(); char *id = create_unique_id("room_disco_info"); xmpp_stanza_t *iq = stanza_create_disco_info_iq(ctx, id, room, NULL); - xmpp_id_handler_add(conn, _disco_info_response_handler, id, strdup(room)); + ProfRoomInfoData *cb_data = malloc(sizeof(ProfRoomInfoData)); + cb_data->room = strdup(room); + cb_data->display = display_result; + + xmpp_id_handler_add(conn, _room_info_response_handler, id, cb_data); free(id); @@ -1337,6 +1347,82 @@ _item_destroy(DiscoItem *item) } } +static int +_room_info_response_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, + void * const userdata) +{ + const char *type = xmpp_stanza_get_type(stanza); + ProfRoomInfoData *cb_data = (ProfRoomInfoData *)userdata; + log_info("Received diso#info response for room: %s", cb_data->room); + + // handle error responses + if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) { + if (cb_data->display) { + char *error_message = stanza_get_error_message(stanza); + handle_room_info_error(cb_data->room, error_message); + free(error_message); + } + free(cb_data->room); + free(cb_data); + return 0; + } + + xmpp_stanza_t *query = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_QUERY); + + if (query != NULL) { + xmpp_stanza_t *child = xmpp_stanza_get_children(query); + GSList *identities = NULL; + GSList *features = NULL; + while (child != NULL) { + const char *stanza_name = xmpp_stanza_get_name(child); + if (g_strcmp0(stanza_name, STANZA_NAME_FEATURE) == 0) { + const char *var = xmpp_stanza_get_attribute(child, STANZA_ATTR_VAR); + if (var != NULL) { + features = g_slist_append(features, strdup(var)); + } + } else if (g_strcmp0(stanza_name, STANZA_NAME_IDENTITY) == 0) { + const char *name = xmpp_stanza_get_attribute(child, STANZA_ATTR_NAME); + const char *type = xmpp_stanza_get_attribute(child, STANZA_ATTR_TYPE); + const char *category = xmpp_stanza_get_attribute(child, STANZA_ATTR_CATEGORY); + + if ((name != NULL) || (category != NULL) || (type != NULL)) { + DiscoIdentity *identity = malloc(sizeof(struct disco_identity_t)); + + if (name != NULL) { + identity->name = strdup(name); + } else { + identity->name = NULL; + } + if (category != NULL) { + identity->category = strdup(category); + } else { + identity->category = NULL; + } + if (type != NULL) { + identity->type = strdup(type); + } else { + identity->type = NULL; + } + + identities = g_slist_append(identities, identity); + } + } + + child = xmpp_stanza_get_next(child); + } + + handle_room_disco_info(cb_data->room, identities, features, cb_data->display); + + g_slist_free_full(features, free); + g_slist_free_full(identities, (GDestroyNotify)_identity_destroy); + } + + free(cb_data->room); + free(cb_data); + + return 0; +} + static int _disco_info_response_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) @@ -1344,28 +1430,16 @@ _disco_info_response_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const sta const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); const char *type = xmpp_stanza_get_type(stanza); - char *room = NULL; - if (userdata) { - room = (char *) userdata; - log_info("Received diso#info response for room: %s", room); + if (from) { + log_info("Received diso#info response from: %s", from); } else { - room = NULL; - if (from) { - log_info("Received diso#info response from: %s", from); - } else { - log_info("Received diso#info response"); - } + log_info("Received diso#info response"); } // handle error responses if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) { char *error_message = stanza_get_error_message(stanza); - if (room) { - handle_room_info_error(room, error_message); - free(room); - } else { - handle_disco_info_error(from, error_message); - } + handle_disco_info_error(from, error_message); free(error_message); return 0; } @@ -1414,20 +1488,13 @@ _disco_info_response_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const sta child = xmpp_stanza_get_next(child); } - if (room) { - handle_room_disco_info(room, identities, features); - } else { - handle_disco_info(from, identities, features); - } + handle_disco_info(from, identities, features); g_slist_free_full(features, free); g_slist_free_full(identities, (GDestroyNotify)_identity_destroy); } - if (room) { - free(room); - } - return 1; + return 0; } static int diff --git a/src/xmpp/xmpp.h b/src/xmpp/xmpp.h index af9e30cc..1dc0c131 100644 --- a/src/xmpp/xmpp.h +++ b/src/xmpp/xmpp.h @@ -192,7 +192,7 @@ void iq_send_caps_request_for_jid(const char * const to, const char * const id, const char * const node, const char * const ver); void iq_send_caps_request_legacy(const char * const to, const char * const id, const char * const node, const char * const ver); -void iq_room_info_request(const char * const room); +void iq_room_info_request(const char * const room, gboolean display_result); void iq_room_affiliation_list(const char * const room, char *affiliation); void iq_room_affiliation_set(const char * const room, const char * const jid, char *affiliation, const char * const reason); diff --git a/tests/xmpp/stub_xmpp.c b/tests/xmpp/stub_xmpp.c index 21c9862d..1e57f7a8 100644 --- a/tests/xmpp/stub_xmpp.c +++ b/tests/xmpp/stub_xmpp.c @@ -151,7 +151,7 @@ void iq_send_caps_request_for_jid(const char * const to, const char * const id, const char * const node, const char * const ver) {} void iq_send_caps_request_legacy(const char * const to, const char * const id, const char * const node, const char * const ver) {} -void iq_room_info_request(const char * const room) {} +void iq_room_info_request(const char * const room, gboolean display) {} void iq_room_affiliation_list(const char * const room, char *affiliation) {} void iq_room_affiliation_set(const char * const room, const char * const jid, char *affiliation, const char * const reason) {} From 1917d4c095d3df705a79a92078bef060d50b6947 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 29 Mar 2015 02:46:59 +0100 Subject: [PATCH 157/252] Added password to direct invites --- src/xmpp/message.c | 4 +++- src/xmpp/stanza.c | 7 +++++-- src/xmpp/stanza.h | 3 ++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/xmpp/message.c b/src/xmpp/message.c index 1bb3bcdc..bdbd5907 100644 --- a/src/xmpp/message.c +++ b/src/xmpp/message.c @@ -206,10 +206,12 @@ message_send_invite(const char * const roomjid, const char * const contact, xmpp_ctx_t * const ctx = connection_get_ctx(); xmpp_stanza_t *stanza; + muc_member_type_t member_type = muc_member_type(roomjid); if (member_type == MUC_MEMBER_TYPE_PUBLIC) { log_debug("Sending direct invite to %s, for %s", contact, roomjid); - stanza = stanza_create_invite(ctx, roomjid, contact, reason); + char *password = muc_password(roomjid); + stanza = stanza_create_invite(ctx, roomjid, contact, reason, password); } else { log_debug("Sending mediated invite to %s, for %s", contact, roomjid); stanza = stanza_create_mediated_invite(ctx, roomjid, contact, reason); diff --git a/src/xmpp/stanza.c b/src/xmpp/stanza.c index 03567e31..84dcb797 100644 --- a/src/xmpp/stanza.c +++ b/src/xmpp/stanza.c @@ -414,7 +414,7 @@ stanza_create_roster_set(xmpp_ctx_t *ctx, const char * const id, xmpp_stanza_t * stanza_create_invite(xmpp_ctx_t *ctx, const char * const room, - const char * const contact, const char * const reason) + const char * const contact, const char * const reason, const char * const password) { xmpp_stanza_t *message, *x; @@ -430,9 +430,12 @@ stanza_create_invite(xmpp_ctx_t *ctx, const char * const room, xmpp_stanza_set_ns(x, STANZA_NS_CONFERENCE); xmpp_stanza_set_attribute(x, STANZA_ATTR_JID, room); - if (reason != NULL) { + if (reason) { xmpp_stanza_set_attribute(x, STANZA_ATTR_REASON, reason); } + if (password) { + xmpp_stanza_set_attribute(x, STANZA_ATTR_PASSWORD, password); + } xmpp_stanza_add_child(message, x); xmpp_stanza_release(x); diff --git a/src/xmpp/stanza.h b/src/xmpp/stanza.h index 744bd7fb..89dbda57 100644 --- a/src/xmpp/stanza.h +++ b/src/xmpp/stanza.h @@ -135,6 +135,7 @@ #define STANZA_ATTR_CATEGORY "category" #define STANZA_ATTR_REASON "reason" #define STANZA_ATTR_AUTOJOIN "autojoin" +#define STANZA_ATTR_PASSWORD "password" #define STANZA_TEXT_AWAY "away" #define STANZA_TEXT_DND "dnd" @@ -214,7 +215,7 @@ xmpp_stanza_t* stanza_create_disco_info_iq(xmpp_ctx_t *ctx, const char * const i const char * const to, const char * const node); xmpp_stanza_t* stanza_create_invite(xmpp_ctx_t *ctx, const char * const room, - const char * const contact, const char * const reason); + const char * const contact, const char * const reason, const char * const password); xmpp_stanza_t* stanza_create_mediated_invite(xmpp_ctx_t *ctx, const char * const room, const char * const contact, const char * const reason); From 71c2be599b54fb3cf7beb2a0855ad2a9d1bf6a0b Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 29 Mar 2015 03:16:41 +0100 Subject: [PATCH 158/252] Use password for chat room invites --- src/command/commands.c | 7 ++++++- src/muc.c | 17 ++++++++++++++++- src/muc.h | 3 ++- src/server_events.c | 4 ++-- src/server_events.h | 2 +- src/xmpp/message.c | 17 +++++++++++++---- tests/test_muc.c | 14 +++++++------- 7 files changed, 47 insertions(+), 17 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index 76da2a93..2699924b 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -2118,10 +2118,15 @@ cmd_join(gchar **args, struct cmd_help_t help) options_destroy(options); // In the case that a nick wasn't provided by the optional args... - if (nick == NULL) { + if (!nick) { nick = account->muc_nick; } + // When no password, check for invite with password + if (!passwd) { + passwd = muc_invite_password(room); + } + if (!muc_active(room)) { presence_join_room(room, nick, passwd); muc_join(room, nick, passwd, FALSE); diff --git a/src/muc.c b/src/muc.c index ae48d66b..6fd09de3 100644 --- a/src/muc.c +++ b/src/muc.c @@ -66,6 +66,7 @@ typedef struct _muc_room_t { } ChatRoom; GHashTable *rooms = NULL; +GHashTable *invite_passwords = NULL; Autocomplete invite_ac; static void _free_room(ChatRoom *room); @@ -83,6 +84,7 @@ muc_init(void) { invite_ac = autocomplete_new(); rooms = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify)_free_room); + invite_passwords = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); } void @@ -90,19 +92,25 @@ muc_close(void) { autocomplete_free(invite_ac); g_hash_table_destroy(rooms); + g_hash_table_destroy(invite_passwords); rooms = NULL; + invite_passwords = NULL; } void -muc_invites_add(const char * const room) +muc_invites_add(const char * const room, const char * const password) { autocomplete_add(invite_ac, room); + if (password) { + g_hash_table_replace(invite_passwords, strdup(room), strdup(password)); + } } void muc_invites_remove(const char * const room) { autocomplete_remove(invite_ac, room); + g_hash_table_remove(invite_passwords, room); } gint @@ -117,6 +125,12 @@ muc_invites(void) return autocomplete_create_list(invite_ac); } +char * +muc_invite_password(const char * const room) +{ + return g_hash_table_lookup(invite_passwords, room); +} + gboolean muc_invites_contain(const char * const room) { @@ -151,6 +165,7 @@ void muc_invites_clear(void) { autocomplete_clear(invite_ac); + g_hash_table_remove_all(invite_passwords); } void diff --git a/src/muc.h b/src/muc.h index 2c7b3e7e..cdaa10bd 100644 --- a/src/muc.h +++ b/src/muc.h @@ -116,7 +116,7 @@ GSList * muc_occupants_by_affiliation(const char * const room, muc_affiliation_t void muc_occupant_nick_change_start(const char * const room, const char * const new_nick, const char * const old_nick); char* muc_roster_nick_change_complete(const char * const room, const char * const nick); -void muc_invites_add(const char * const room); +void muc_invites_add(const char * const room, const char * const password); void muc_invites_remove(const char * const room); gint muc_invites_count(void); GSList* muc_invites(void); @@ -124,6 +124,7 @@ gboolean muc_invites_contain(const char * const room); void muc_invites_reset_ac(void); char* muc_invites_find(const char * const search_str); void muc_invites_clear(void); +char* muc_invite_password(const char * const room); void muc_set_subject(const char * const room, const char * const subject); char* muc_subject(const char * const room); diff --git a/src/server_events.c b/src/server_events.c index bab6cb13..fe942680 100644 --- a/src/server_events.c +++ b/src/server_events.c @@ -257,11 +257,11 @@ handle_disco_items(GSList *items, const char *jid) void handle_room_invite(jabber_invite_t invite_type, const char * const invitor, const char * const room, - const char * const reason) + const char * const reason, const char * const password) { if (!muc_active(room) && !muc_invites_contain(room)) { cons_show_room_invite(invitor, room, reason); - muc_invites_add(room); + muc_invites_add(room, password); } } diff --git a/src/server_events.h b/src/server_events.h index b03e11be..85d75ac3 100644 --- a/src/server_events.h +++ b/src/server_events.h @@ -48,7 +48,7 @@ void handle_room_list(GSList *rooms, const char *conference_node); void handle_disco_items(GSList *items, const char *jid); void handle_room_invite(jabber_invite_t invite_type, const char * const invitor, const char * const room, - const char * const reason); + const char * const reason, const char * const password); void handle_room_broadcast(const char *const room_jid, const char * const message); void handle_room_subject(const char * const room, const char * const nick, const char * const subject); diff --git a/src/xmpp/message.c b/src/xmpp/message.c index bdbd5907..02c748d9 100644 --- a/src/xmpp/message.c +++ b/src/xmpp/message.c @@ -340,11 +340,18 @@ _muc_user_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, reason = xmpp_stanza_get_text(reason_st); } - handle_room_invite(INVITE_MEDIATED, invitor, room, reason); + char *password = NULL; + xmpp_stanza_t *password_st = xmpp_stanza_get_child_by_name(xns_muc_user, STANZA_NAME_PASSWORD); + password = xmpp_stanza_get_text(password_st); + + handle_room_invite(INVITE_MEDIATED, invitor, room, reason, password); jid_destroy(jidp); - if (reason != NULL) { + if (reason) { xmpp_free(ctx, reason); } + if (password) { + xmpp_free(ctx, password); + } } return 1; @@ -359,13 +366,14 @@ _conference_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, char *room = NULL; char *invitor = NULL; char *reason = NULL; + char *password = NULL; if (from == NULL) { log_warning("Message received with no from attribute, ignoring"); return 1; } - // XEP-0429 + // XEP-0249 room = xmpp_stanza_get_attribute(xns_conference, STANZA_ATTR_JID); if (room == NULL) { return 1; @@ -378,8 +386,9 @@ _conference_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, invitor = jidp->barejid; reason = xmpp_stanza_get_attribute(xns_conference, STANZA_ATTR_REASON); + password = xmpp_stanza_get_attribute(xns_conference, STANZA_ATTR_PASSWORD); - handle_room_invite(INVITE_DIRECT, invitor, room, reason); + handle_room_invite(INVITE_DIRECT, invitor, room, reason, password); jid_destroy(jidp); diff --git a/tests/test_muc.c b/tests/test_muc.c index 5566c17e..e3b7f9b0 100644 --- a/tests/test_muc.c +++ b/tests/test_muc.c @@ -19,7 +19,7 @@ void muc_after_test(void **state) void test_muc_invites_add(void **state) { char *room = "room@conf.server"; - muc_invites_add(room); + muc_invites_add(room, NULL); gboolean invite_exists = muc_invites_contain(room); @@ -29,7 +29,7 @@ void test_muc_invites_add(void **state) void test_muc_remove_invite(void **state) { char *room = "room@conf.server"; - muc_invites_add(room); + muc_invites_add(room, NULL); muc_invites_remove(room); gboolean invite_exists = muc_invites_contain(room); @@ -46,11 +46,11 @@ void test_muc_invites_count_0(void **state) void test_muc_invites_count_5(void **state) { - muc_invites_add("room1@conf.server"); - muc_invites_add("room2@conf.server"); - muc_invites_add("room3@conf.server"); - muc_invites_add("room4@conf.server"); - muc_invites_add("room5@conf.server"); + muc_invites_add("room1@conf.server", NULL); + muc_invites_add("room2@conf.server", NULL); + muc_invites_add("room3@conf.server", NULL); + muc_invites_add("room4@conf.server", NULL); + muc_invites_add("room5@conf.server", NULL); int invite_count = muc_invites_count(); From f18759192c1dd82385cfbc3edabea3e9a920e23c Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 11 Apr 2015 21:42:58 +0100 Subject: [PATCH 159/252] Updated CHANGELOG --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index 7db3a45c..519660db 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -4,6 +4,7 @@ - GNU Readline - Message Carbons (xep-0280) - Message Delivery Receipts (xep-0184) +- MUC Mediated Invitation support 0.4.6 ===== From a2ccd896465982bd6059ae7770532417b1062bdb Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 11 Apr 2015 23:37:52 +0100 Subject: [PATCH 160/252] Autogenerate room name with UUID for /join with no args --- configure.ac | 3 +++ src/command/command.c | 13 +++++++------ src/command/commands.c | 21 +++++++++++++++++++-- src/xmpp/message.c | 4 +++- tests/test_cmd_join.c | 17 ----------------- tests/test_cmd_join.h | 1 - tests/testsuite.c | 1 - 7 files changed, 32 insertions(+), 28 deletions(-) diff --git a/configure.ac b/configure.ac index 0653ab68..1e2c6173 100644 --- a/configure.ac +++ b/configure.ac @@ -146,6 +146,9 @@ AS_IF([test "x$PLATFORM" != xosx], AC_SUBST(AM_LDFLAGS)], [AC_MSG_ERROR([libreadline is required for profanity])])]) +AC_CHECK_LIB([uuid], [uuid_generate], [], + [AC_MSG_ERROR([libuuid is required for profanity])]) + AS_IF([test "x$PLATFORM" = xosx], [LIBS="-lcurl $LIBS"]) ### Check for desktop notification support diff --git a/src/command/command.c b/src/command/command.c index e165254e..d9b6a6e0 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -321,20 +321,21 @@ static struct cmd_t command_defs[] = NULL } } }, { "/join", - cmd_join, parse_args, 1, 5, NULL, - { "/join room[@server] [nick value] [password value]", "Join a chat room.", - { "/join room[@server] [nick value] [password value]", - "-------------------------------------------------", + cmd_join, parse_args, 0, 5, NULL, + { "/join [room] [nick value] [password value]", "Join a chat room.", + { "/join [room] [nick value] [password value]", + "-----------------------------------------", "Join a chat room at the conference server.", "", - "room : Bare room JID, the chat server is determined by the 'muc.service' account property, 'conference.' by default.", - "room@server : Full room JID.", + "room : Bare room JID (the chat server is determined by the 'muc.service' account property) or full room jid." "nick value : Nickname to use in the room", "password value : Password if the room requires it.", "", + "If no room is supplied, a generated name will be used with the format private-chat-[UUID].", "If no nickname is specified the account preference 'muc.nick' will be used which by default is the localpart of your JID.", "If the room doesn't exist, and the server allows it, a new one will be created.", "", + "Example: /join", "Example: /join jdev@conference.jabber.org", "Example: /join jdev@conference.jabber.org nick mynick", "Example: /join private@conference.jabber.org nick mynick password mypassword", diff --git a/src/command/commands.c b/src/command/commands.c index 2699924b..79bc54af 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -38,6 +38,7 @@ #include #include #include +#include #include #include "chat_session.h" @@ -2070,8 +2071,24 @@ cmd_join(gchar **args, struct cmd_help_t help) } if (args[0] == NULL) { - cons_show("Usage: %s", help.usage); - cons_show(""); + uuid_t uuid; + uuid_generate(uuid); + char *uuid_str = malloc(sizeof(char) * 37); + uuid_unparse_lower(uuid, uuid_str); + + char *account_name = jabber_get_account_name(); + ProfAccount *account = accounts_get_account(account_name); + + GString *room_str = g_string_new(""); + g_string_append_printf(room_str, "private-chat-%s@%s", uuid_str, account->muc_service); + + presence_join_room(room_str->str, account->muc_nick, NULL); + muc_join(room_str->str, account->muc_nick, NULL, FALSE); + + g_string_free(room_str, TRUE); + free(uuid_str); + account_free(account); + return TRUE; } diff --git a/src/xmpp/message.c b/src/xmpp/message.c index 02c748d9..323c653c 100644 --- a/src/xmpp/message.c +++ b/src/xmpp/message.c @@ -342,7 +342,9 @@ _muc_user_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, char *password = NULL; xmpp_stanza_t *password_st = xmpp_stanza_get_child_by_name(xns_muc_user, STANZA_NAME_PASSWORD); - password = xmpp_stanza_get_text(password_st); + if (password_st) { + password = xmpp_stanza_get_text(password_st); + } handle_room_invite(INVITE_MEDIATED, invitor, room, reason, password); jid_destroy(jidp); diff --git a/tests/test_cmd_join.c b/tests/test_cmd_join.c index 10ffa547..19824b3a 100644 --- a/tests/test_cmd_join.c +++ b/tests/test_cmd_join.c @@ -50,23 +50,6 @@ void cmd_join_shows_message_when_undefined(void **state) test_with_connection_status(JABBER_UNDEFINED); } -void cmd_join_shows_usage_when_no_args(void **state) -{ - CommandHelp *help = malloc(sizeof(CommandHelp)); - help->usage = "some usage"; - gchar *args[] = { NULL }; - - will_return(jabber_get_connection_status, JABBER_CONNECTED); - - expect_cons_show("Usage: some usage"); - expect_cons_show(""); - - gboolean result = cmd_join(args, *help); - assert_true(result); - - free(help); -} - void cmd_join_shows_error_message_when_invalid_room_jid(void **state) { CommandHelp *help = malloc(sizeof(CommandHelp)); diff --git a/tests/test_cmd_join.h b/tests/test_cmd_join.h index 812aee87..a96fa435 100644 --- a/tests/test_cmd_join.h +++ b/tests/test_cmd_join.h @@ -2,7 +2,6 @@ void cmd_join_shows_message_when_disconnecting(void **state); void cmd_join_shows_message_when_connecting(void **state); void cmd_join_shows_message_when_disconnected(void **state); void cmd_join_shows_message_when_undefined(void **state); -void cmd_join_shows_usage_when_no_args(void **state); void cmd_join_shows_error_message_when_invalid_room_jid(void **state); void cmd_join_uses_account_mucservice_when_no_service_specified(void **state); void cmd_join_uses_supplied_nick(void **state); diff --git a/tests/testsuite.c b/tests/testsuite.c index 78d7b570..15682d1f 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -563,7 +563,6 @@ int main(int argc, char* argv[]) { unit_test(cmd_join_shows_message_when_connecting), unit_test(cmd_join_shows_message_when_disconnected), unit_test(cmd_join_shows_message_when_undefined), - unit_test(cmd_join_shows_usage_when_no_args), unit_test(cmd_join_shows_error_message_when_invalid_room_jid), unit_test(cmd_join_uses_account_mucservice_when_no_service_specified), unit_test(cmd_join_uses_supplied_nick), From a8669bb2bd9ff5dd011fea1b92f733e00cb52570 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 12 Apr 2015 00:01:59 +0100 Subject: [PATCH 161/252] Updated travis build to include uuid-dev dependency --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 534440d0..e546d8b3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: c install: - sudo apt-get update - - sudo apt-get -y install libssl-dev libexpat1-dev libncursesw5-dev libglib2.0-dev libnotify-dev libcurl3-dev libxss-dev libotr2-dev + - sudo apt-get -y install libssl-dev libexpat1-dev libncursesw5-dev libglib2.0-dev libnotify-dev libcurl3-dev libxss-dev libotr2-dev uuid-dev - git clone git://github.com/strophe/libstrophe.git - cd libstrophe - mkdir m4 From 57dc5f14efec19c9532c2ec9a8742e90e4c964d2 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 12 Apr 2015 02:14:37 +0100 Subject: [PATCH 162/252] Added option to show jids in occupants panel --- src/command/command.c | 45 +++++++++++++++++++++++++++++++++------- src/command/commands.c | 34 +++++++++++++++++++++++------- src/config/preferences.c | 3 +++ src/config/preferences.h | 1 + src/config/theme.c | 1 + src/ui/console.c | 5 +++++ src/ui/core.c | 9 ++++++++ src/ui/occupantswin.c | 17 ++++++++++----- src/ui/ui.h | 1 + src/ui/window.c | 5 +++++ src/ui/window.h | 1 + src/ui/windows.c | 8 ++++++- tests/ui/stub_ui.c | 1 + theme_template | 1 + themes/boothj5 | 3 +-- themes/complex | 1 + 16 files changed, 113 insertions(+), 23 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index d9b6a6e0..fca25690 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -451,16 +451,19 @@ static struct cmd_t command_defs[] = NULL } } }, { "/occupants", - cmd_occupants, parse_args, 1, 2, cons_occupants_setting, - { "/occupants show|hide|default|size [show|hide] [percent]", "Show or hide room occupants.", - { "/occupants show|hide|default|size [show|hide] [percent]", - "-------------------------------------------------------", + cmd_occupants, parse_args, 1, 3, cons_occupants_setting, + { "/occupants show|hide|default|size [jid|show|hide|percent] [jid]", "Show or hide room occupants.", + { "/occupants show|hide|default|size [jid|show|hide|percent] [jid]", + "---------------------------------------------------------------", "Show or hide room occupants, and occupants panel display settings.", "", - "show : Show the occupants panel in chat rooms.", - "hide : Hide the occupants panel in chat rooms.", - "default show|hide : Whether occupants are shown by default in new rooms, 'show' or 'hide'", - "size percent : Percentage of the screen taken by the occupants list in rooms (1-99).", + "show : Show the occupants panel in current room.", + "hide : Hide the occupants panel in current room.", + "show jid : Show jid in the occupants panel in current room.", + "hide jid : Hide jid in the occupants panel in current room.", + "default show|hide : Whether occupants are shown by default in new rooms.", + "default show|hide jid : Whether occupants jids are shown by default in new rooms.", + "size percent : Percentage of the screen taken by the occupants list in rooms (1-99).", NULL } } }, { "/form", @@ -1198,6 +1201,7 @@ static Autocomplete form_ac; static Autocomplete form_field_multi_ac; static Autocomplete occupants_ac; static Autocomplete occupants_default_ac; +static Autocomplete occupants_show_ac; static Autocomplete time_ac; static Autocomplete time_statusbar_ac; static Autocomplete resource_ac; @@ -1540,6 +1544,9 @@ cmd_init(void) autocomplete_add(occupants_default_ac, "show"); autocomplete_add(occupants_default_ac, "hide"); + occupants_show_ac = autocomplete_new(); + autocomplete_add(occupants_show_ac, "jid"); + time_ac = autocomplete_new(); autocomplete_add(time_ac, "minutes"); autocomplete_add(time_ac, "seconds"); @@ -1617,6 +1624,7 @@ cmd_uninit(void) autocomplete_free(form_field_multi_ac); autocomplete_free(occupants_ac); autocomplete_free(occupants_default_ac); + autocomplete_free(occupants_show_ac); autocomplete_free(time_ac); autocomplete_free(time_statusbar_ac); autocomplete_free(resource_ac); @@ -1784,6 +1792,7 @@ cmd_reset_autocomplete() autocomplete_reset(form_field_multi_ac); autocomplete_reset(occupants_ac); autocomplete_reset(occupants_default_ac); + autocomplete_reset(occupants_show_ac); autocomplete_reset(time_ac); autocomplete_reset(time_statusbar_ac); autocomplete_reset(resource_ac); @@ -2633,11 +2642,31 @@ _occupants_autocomplete(const char * const input) { char *found = NULL; + found = autocomplete_param_with_ac(input, "/occupants default show", occupants_show_ac, TRUE); + if (found != NULL) { + return found; + } + + found = autocomplete_param_with_ac(input, "/occupants default hide", occupants_show_ac, TRUE); + if (found != NULL) { + return found; + } + found = autocomplete_param_with_ac(input, "/occupants default", occupants_default_ac, TRUE); if (found != NULL) { return found; } + found = autocomplete_param_with_ac(input, "/occupants show", occupants_show_ac, TRUE); + if (found != NULL) { + return found; + } + + found = autocomplete_param_with_ac(input, "/occupants hide", occupants_show_ac, TRUE); + if (found != NULL) { + return found; + } + found = autocomplete_param_with_ac(input, "/occupants", occupants_ac, TRUE); if (found != NULL) { return found; diff --git a/src/command/commands.c b/src/command/commands.c index 79bc54af..29ae6614 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -2855,12 +2855,22 @@ cmd_occupants(gchar **args, struct cmd_help_t help) if (g_strcmp0(args[0], "default") == 0) { if (g_strcmp0(args[1], "show") == 0) { - cons_show("Occupant list enabled."); - prefs_set_boolean(PREF_OCCUPANTS, TRUE); + if (g_strcmp0(args[2], "jid") == 0) { + cons_show("Occupant jids enabled."); + prefs_set_boolean(PREF_OCCUPANTS_JID, TRUE); + } else { + cons_show("Occupant list enabled."); + prefs_set_boolean(PREF_OCCUPANTS, TRUE); + } return TRUE; } else if (g_strcmp0(args[1], "hide") == 0) { - cons_show("Occupant list disabled."); - prefs_set_boolean(PREF_OCCUPANTS, FALSE); + if (g_strcmp0(args[2], "jid") == 0) { + cons_show("Occupant jids disabled."); + prefs_set_boolean(PREF_OCCUPANTS_JID, FALSE); + } else { + cons_show("Occupant list disabled."); + prefs_set_boolean(PREF_OCCUPANTS, FALSE); + } return TRUE; } else { cons_show("Usage: %s", help.usage); @@ -2870,16 +2880,26 @@ cmd_occupants(gchar **args, struct cmd_help_t help) win_type_t win_type = ui_current_win_type(); if (win_type != WIN_MUC) { - cons_show("Cannot show/hide occupant list when not in chat room."); + cons_show("Cannot apply setting when not in chat room."); return TRUE; } ProfMucWin *mucwin = wins_get_current_muc(); if (g_strcmp0(args[0], "show") == 0) { - ui_room_show_occupants(mucwin->roomjid); + if (g_strcmp0(args[1], "jid") == 0) { + mucwin->showjid = TRUE; + ui_room_update_occupants(mucwin->roomjid); + } else { + ui_room_show_occupants(mucwin->roomjid); + } } else if (g_strcmp0(args[0], "hide") == 0) { - ui_room_hide_occupants(mucwin->roomjid); + if (g_strcmp0(args[1], "jid") == 0) { + mucwin->showjid = FALSE; + ui_room_update_occupants(mucwin->roomjid); + } else { + ui_room_hide_occupants(mucwin->roomjid); + } } else { cons_show("Usage: %s", help.usage); } diff --git a/src/config/preferences.c b/src/config/preferences.c index fdaae11f..3ca3a721 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -499,6 +499,7 @@ _get_group(preference_t pref) case PREF_HISTORY: case PREF_MOUSE: case PREF_OCCUPANTS: + case PREF_OCCUPANTS_JID: case PREF_STATUSES: case PREF_STATUSES_CONSOLE: case PREF_STATUSES_CHAT: @@ -589,6 +590,8 @@ _get_key(preference_t pref) return "mouse"; case PREF_OCCUPANTS: return "occupants"; + case PREF_OCCUPANTS_JID: + return "occupants.jid"; case PREF_MUC_PRIVILEGES: return "privileges"; case PREF_STATUSES: diff --git a/src/config/preferences.h b/src/config/preferences.h index a9413886..4455eca1 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -65,6 +65,7 @@ typedef enum { PREF_MOUSE, PREF_OCCUPANTS, PREF_OCCUPANTS_SIZE, + PREF_OCCUPANTS_JID, PREF_ROSTER, PREF_ROSTER_SIZE, PREF_ROSTER_OFFLINE, diff --git a/src/config/theme.c b/src/config/theme.c index 5b358ba3..1ee9836b 100644 --- a/src/config/theme.c +++ b/src/config/theme.c @@ -439,6 +439,7 @@ _load_preferences(void) _set_string_preference("statuses.muc", PREF_STATUSES_MUC); _set_boolean_preference("occupants", PREF_OCCUPANTS); + _set_boolean_preference("occupants.jid", PREF_OCCUPANTS_JID); if (g_key_file_has_key(theme, "ui", "occupants.size", NULL)) { gint occupants_size = g_key_file_get_integer(theme, "ui", "occupants.size", NULL); prefs_set_occupants_size(occupants_size); diff --git a/src/ui/console.c b/src/ui/console.c index 328f59aa..8dfd473f 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -906,6 +906,11 @@ cons_occupants_setting(void) else cons_show("Occupants (/occupants) : hide"); + if (prefs_get_boolean(PREF_OCCUPANTS_JID)) + cons_show("Occupant jids (/occupants) : show"); + else + cons_show("Occupant jids (/occupants) : hide"); + int size = prefs_get_occupants_size(); cons_show("Occupants size (/occupants) : %d", size); } diff --git a/src/ui/core.c b/src/ui/core.c index acb9e550..e1df5edf 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -2962,6 +2962,15 @@ ui_show_lines(ProfWin *window, const gchar** lines) } } +void +ui_room_update_occupants(const char * const roomjid) +{ + ProfWin *window = (ProfWin*)wins_get_muc(roomjid); + if (window && win_has_active_subwin(window)) { + occupantswin_occupants(roomjid); + } +} + void ui_room_show_occupants(const char * const roomjid) { diff --git a/src/ui/occupantswin.c b/src/ui/occupantswin.c index d865eeed..bba9d0b9 100644 --- a/src/ui/occupantswin.c +++ b/src/ui/occupantswin.c @@ -40,7 +40,7 @@ #include "config/preferences.h" static void -_occuptantswin_occupant(ProfLayoutSplit *layout, Occupant *occupant) +_occuptantswin_occupant(ProfLayoutSplit *layout, Occupant *occupant, gboolean showjid) { const char *presence_str = string_from_resource_presence(occupant->presence); theme_item_t presence_colour = theme_main_presence_attrs(presence_str); @@ -51,6 +51,13 @@ _occuptantswin_occupant(ProfLayoutSplit *layout, Occupant *occupant) win_printline_nowrap(layout->subwin, msg->str); g_string_free(msg, TRUE); + if (showjid && occupant->jid) { + GString *msg = g_string_new(" "); + g_string_append(msg, occupant->jid); + win_printline_nowrap(layout->subwin, msg->str); + g_string_free(msg, TRUE); + } + wattroff(layout->subwin, theme_attrs(presence_colour)); } @@ -74,7 +81,7 @@ occupantswin_occupants(const char * const roomjid) while (roster_curr) { Occupant *occupant = roster_curr->data; if (occupant->role == MUC_ROLE_MODERATOR) { - _occuptantswin_occupant(layout, occupant); + _occuptantswin_occupant(layout, occupant, mucwin->showjid); } roster_curr = g_list_next(roster_curr); } @@ -86,7 +93,7 @@ occupantswin_occupants(const char * const roomjid) while (roster_curr) { Occupant *occupant = roster_curr->data; if (occupant->role == MUC_ROLE_PARTICIPANT) { - _occuptantswin_occupant(layout, occupant); + _occuptantswin_occupant(layout, occupant, mucwin->showjid); } roster_curr = g_list_next(roster_curr); } @@ -98,7 +105,7 @@ occupantswin_occupants(const char * const roomjid) while (roster_curr) { Occupant *occupant = roster_curr->data; if (occupant->role == MUC_ROLE_VISITOR) { - _occuptantswin_occupant(layout, occupant); + _occuptantswin_occupant(layout, occupant, mucwin->showjid); } roster_curr = g_list_next(roster_curr); } @@ -109,7 +116,7 @@ occupantswin_occupants(const char * const roomjid) GList *roster_curr = occupants; while (roster_curr) { Occupant *occupant = roster_curr->data; - _occuptantswin_occupant(layout, occupant); + _occuptantswin_occupant(layout, occupant, mucwin->showjid); roster_curr = g_list_next(roster_curr); } } diff --git a/src/ui/ui.h b/src/ui/ui.h index 20685e92..fc1485ff 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -174,6 +174,7 @@ void ui_room_member_nick_change(const char * const roomjid, void ui_room_nick_change(const char * const roomjid, const char * const nick); void ui_room_member_presence(const char * const roomjid, const char * const nick, const char * const show, const char * const status); +void ui_room_update_occupants(const char * const roomjid); void ui_room_show_occupants(const char * const roomjid); void ui_room_hide_occupants(const char * const roomjid); void ui_show_roster(void); diff --git a/src/ui/window.c b/src/ui/window.c index 2a1b1a7b..ab894d07 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -177,6 +177,11 @@ win_create_muc(const char * const roomjid) new_win->roomjid = strdup(roomjid); new_win->unread = 0; + if (prefs_get_boolean(PREF_OCCUPANTS_JID)) { + new_win->showjid = TRUE; + } else { + new_win->showjid = FALSE; + } new_win->memcheck = PROFMUCWIN_MEMCHECK; diff --git a/src/ui/window.h b/src/ui/window.h index f525e5fa..650df67f 100644 --- a/src/ui/window.h +++ b/src/ui/window.h @@ -124,6 +124,7 @@ typedef struct prof_muc_win_t { ProfWin window; char *roomjid; int unread; + gboolean showjid; unsigned long memcheck; } ProfMucWin; diff --git a/src/ui/windows.c b/src/ui/windows.c index c9496ef6..993a51c1 100644 --- a/src/ui/windows.c +++ b/src/ui/windows.c @@ -497,7 +497,13 @@ wins_resize_all(void) } wresize(layout->base.win, PAD_SIZE, cols - subwin_cols); wresize(layout->subwin, PAD_SIZE, subwin_cols); - rosterwin_roster(); + if (window->type == WIN_CONSOLE) { + rosterwin_roster(); + } else if (window->type == WIN_MUC) { + ProfMucWin *mucwin = (ProfMucWin *)window; + assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK); + occupantswin_occupants(mucwin->roomjid); + } } else { wresize(layout->base.win, PAD_SIZE, cols); } diff --git a/tests/ui/stub_ui.c b/tests/ui/stub_ui.c index 3eeaa8ab..d7fdeb0a 100644 --- a/tests/ui/stub_ui.c +++ b/tests/ui/stub_ui.c @@ -252,6 +252,7 @@ void ui_room_member_nick_change(const char * const roomjid, void ui_room_nick_change(const char * const roomjid, const char * const nick) {} void ui_room_member_presence(const char * const roomjid, const char * const nick, const char * const show, const char * const status) {} +void ui_room_update_occupants(const char * const roomjid) {} void ui_room_show_occupants(const char * const roomjid) {} void ui_room_hide_occupants(const char * const roomjid) {} void ui_show_roster(void) {} diff --git a/theme_template b/theme_template index 51e188da..c088e181 100644 --- a/theme_template +++ b/theme_template @@ -71,3 +71,4 @@ roster.by= roster.size= occupants= occupants.size= +occupants.jid= diff --git a/themes/boothj5 b/themes/boothj5 index 82e053ef..9ed3fe69 100644 --- a/themes/boothj5 +++ b/themes/boothj5 @@ -72,5 +72,4 @@ roster.by=presence roster.size=25 occupants=true occupants.size=15 - - +occupants.jid=true diff --git a/themes/complex b/themes/complex index 61f6a270..a5510baa 100644 --- a/themes/complex +++ b/themes/complex @@ -12,6 +12,7 @@ statuses.chat=all statuses.muc=all occupants=true occupants.size=15 +occupants.jid=true roster=true roster.offline=true roster.resource=true From 424f52c3fa0665babd9550cff75e7384ae3a369c Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 19 Apr 2015 16:54:16 +0100 Subject: [PATCH 163/252] Moved server_events to event/ --- Makefile.am | 4 ++-- src/{ => event}/server_events.c | 0 src/{ => event}/server_events.h | 0 src/xmpp/bookmark.c | 2 +- src/xmpp/connection.c | 4 ++-- src/xmpp/iq.c | 2 +- src/xmpp/message.c | 2 +- src/xmpp/presence.c | 2 +- src/xmpp/roster.c | 2 +- tests/test_server_events.c | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) rename src/{ => event}/server_events.c (100%) rename src/{ => event}/server_events.h (100%) diff --git a/Makefile.am b/Makefile.am index cd708a13..c5449a2b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -13,7 +13,7 @@ core_sources = \ src/xmpp/roster.c src/xmpp/roster.h \ src/xmpp/bookmark.c src/xmpp/bookmark.h \ src/xmpp/form.c src/xmpp/form.h \ - src/server_events.c src/server_events.h \ + src/event/server_events.c src/event/server_events.h \ src/ui/ui.h src/ui/window.c src/ui/window.h src/ui/core.c \ src/ui/titlebar.c src/ui/statusbar.c src/ui/inputwin.c \ src/ui/titlebar.h src/ui/statusbar.h src/ui/inputwin.h \ @@ -60,7 +60,7 @@ tests_sources = \ src/ui/buffer.c \ src/ui/titlebar.c src/ui/statusbar.c src/ui/inputwin.c \ src/ui/titlebar.h src/ui/statusbar.h src/ui/inputwin.h \ - src/server_events.c src/server_events.h \ + src/event/server_events.c src/event/server_events.h \ tests/xmpp/stub_xmpp.c \ tests/ui/stub_ui.c \ tests/log/stub_log.c \ diff --git a/src/server_events.c b/src/event/server_events.c similarity index 100% rename from src/server_events.c rename to src/event/server_events.c diff --git a/src/server_events.h b/src/event/server_events.h similarity index 100% rename from src/server_events.h rename to src/event/server_events.h diff --git a/src/xmpp/bookmark.c b/src/xmpp/bookmark.c index 1cf11f93..9e7bf62b 100644 --- a/src/xmpp/bookmark.c +++ b/src/xmpp/bookmark.c @@ -42,7 +42,7 @@ #include "common.h" #include "log.h" #include "muc.h" -#include "server_events.h" +#include "event/server_events.h" #include "xmpp/connection.h" #include "xmpp/stanza.h" #include "xmpp/xmpp.h" diff --git a/src/xmpp/connection.c b/src/xmpp/connection.c index d6a492ab..c51652fa 100644 --- a/src/xmpp/connection.c +++ b/src/xmpp/connection.c @@ -45,7 +45,7 @@ #include "log.h" #include "muc.h" #include "profanity.h" -#include "server_events.h" +#include "event/server_events.h" #include "xmpp/bookmark.h" #include "xmpp/capabilities.h" #include "xmpp/connection.h" @@ -470,7 +470,7 @@ _connection_handler(xmpp_conn_t * const conn, if (prefs_get_boolean(PREF_CARBONS)){ iq_enable_carbons(); } - + jabber_conn.conn_status = JABBER_CONNECTED; if (prefs_get_reconnect() != 0) { diff --git a/src/xmpp/iq.c b/src/xmpp/iq.c index 2cbed0dd..adee07b8 100644 --- a/src/xmpp/iq.c +++ b/src/xmpp/iq.c @@ -48,7 +48,7 @@ #include "muc.h" #include "profanity.h" #include "config/preferences.h" -#include "server_events.h" +#include "event/server_events.h" #include "xmpp/capabilities.h" #include "xmpp/connection.h" #include "xmpp/stanza.h" diff --git a/src/xmpp/message.c b/src/xmpp/message.c index 323c653c..ac20cbaf 100644 --- a/src/xmpp/message.c +++ b/src/xmpp/message.c @@ -42,7 +42,7 @@ #include "log.h" #include "muc.h" #include "profanity.h" -#include "server_events.h" +#include "event/server_events.h" #include "xmpp/connection.h" #include "xmpp/message.h" #include "xmpp/roster.h" diff --git a/src/xmpp/presence.c b/src/xmpp/presence.c index f4c45318..2be9780a 100644 --- a/src/xmpp/presence.c +++ b/src/xmpp/presence.c @@ -44,7 +44,7 @@ #include "log.h" #include "muc.h" #include "profanity.h" -#include "server_events.h" +#include "event/server_events.h" #include "xmpp/capabilities.h" #include "xmpp/connection.h" #include "xmpp/stanza.h" diff --git a/src/xmpp/roster.c b/src/xmpp/roster.c index 6de370aa..2e9d461b 100644 --- a/src/xmpp/roster.c +++ b/src/xmpp/roster.c @@ -41,7 +41,7 @@ #include "log.h" #include "profanity.h" -#include "server_events.h" +#include "event/server_events.h" #include "tools/autocomplete.h" #include "xmpp/connection.h" #include "xmpp/roster.h" diff --git a/tests/test_server_events.c b/tests/test_server_events.c index ce54b4f2..5df7c243 100644 --- a/tests/test_server_events.c +++ b/tests/test_server_events.c @@ -6,7 +6,7 @@ #include #include -#include "server_events.h" +#include "event/server_events.h" #include "roster_list.h" #include "chat_session.h" #include "config/preferences.h" From e688dd7d289a3d26c9e1dc340f9cbb24e526a9bd Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 19 Apr 2015 17:29:54 +0100 Subject: [PATCH 164/252] Renamed server event functions --- src/event/server_events.c | 130 ++++++++++++++++++------------------- src/event/server_events.h | 130 ++++++++++++++++++------------------- src/xmpp/connection.c | 10 +-- src/xmpp/iq.c | 56 ++++++++-------- src/xmpp/message.c | 42 ++++++------ src/xmpp/presence.c | 34 +++++----- src/xmpp/roster.c | 12 ++-- tests/test_server_events.c | 28 ++++---- 8 files changed, 221 insertions(+), 221 deletions(-) diff --git a/src/event/server_events.c b/src/event/server_events.c index fe942680..bd4634e5 100644 --- a/src/event/server_events.c +++ b/src/event/server_events.c @@ -52,7 +52,7 @@ #include "ui/ui.h" void -handle_room_join_error(const char * const room, const char * const err) +srv_room_join_error(const char * const room, const char * const err) { if (muc_active(room)) { muc_leave(room); @@ -62,7 +62,7 @@ handle_room_join_error(const char * const room, const char * const err) // handle presence stanza errors void -handle_presence_error(const char *from, const char * const type, +srv_presence_error(const char *from, const char * const type, const char *err_msg) { // handle error from recipient @@ -77,7 +77,7 @@ handle_presence_error(const char *from, const char * const type, // handle message stanza errors void -handle_message_error(const char * const jid, const char * const type, +srv_message_error(const char * const jid, const char * const type, const char * const err_msg) { // handle errors from no recipient @@ -97,7 +97,7 @@ handle_message_error(const char * const jid, const char * const type, } void -handle_login_account_success(char *account_name) +srv_login_account_success(char *account_name) { ProfAccount *account = accounts_get_account(account_name); @@ -124,7 +124,7 @@ handle_login_account_success(char *account_name) } void -handle_roster_received(void) +srv_roster_received(void) { if (prefs_get_boolean(PREF_ROSTER)) { ui_show_roster(); @@ -132,7 +132,7 @@ handle_roster_received(void) } void -handle_lost_connection(void) +srv_lost_connection(void) { cons_show_error("Lost connection."); roster_clear(); @@ -142,27 +142,27 @@ handle_lost_connection(void) } void -handle_failed_login(void) +srv_failed_login(void) { cons_show_error("Login failed."); log_info("Login failed"); } void -handle_software_version_result(const char * const jid, const char * const presence, +srv_software_version_result(const char * const jid, const char * const presence, const char * const name, const char * const version, const char * const os) { cons_show_software_version(jid, presence, name, version, os); } void -handle_disco_info(const char *from, GSList *identities, GSList *features) +srv_disco_info(const char *from, GSList *identities, GSList *features) { cons_show_disco_info(from, identities, features); } void -handle_room_disco_info(const char * const room, GSList *identities, GSList *features, gboolean display) +srv_room_disco_info(const char * const room, GSList *identities, GSList *features, gboolean display) { muc_set_features(room, features); if (display) { @@ -171,7 +171,7 @@ handle_room_disco_info(const char * const room, GSList *identities, GSList *feat } void -handle_disco_info_error(const char * const from, const char * const error) +srv_disco_info_error(const char * const from, const char * const error) { if (from) { cons_show_error("Service discovery failed for %s: %s", from, error); @@ -181,31 +181,31 @@ handle_disco_info_error(const char * const from, const char * const error) } void -handle_enable_carbons_error(const char * const error) +srv_enable_carbons_error(const char * const error) { cons_show_error("Server error enabling message carbons: %s", error); } void -handle_disable_carbons_error(const char * const error) +srv_disable_carbons_error(const char * const error) { cons_show_error("Server error disabling message carbons: %s", error); } void -handle_room_info_error(const char * const room, const char * const error) +srv_room_info_error(const char * const room, const char * const error) { ui_handle_room_info_error(room, error); } void -handle_room_list(GSList *rooms, const char *conference_node) +srv_room_list(GSList *rooms, const char *conference_node) { cons_show_room_list(rooms, conference_node); } void -handle_room_affiliation_list_result_error(const char * const room, const char * const affiliation, +srv_room_affiliation_list_result_error(const char * const room, const char * const affiliation, const char * const error) { log_debug("Error retrieving %s list for room %s: %s", affiliation, room, error); @@ -213,14 +213,14 @@ handle_room_affiliation_list_result_error(const char * const room, const char * } void -handle_room_affiliation_list(const char * const room, const char * const affiliation, GSList *jids) +srv_room_affiliation_list(const char * const room, const char * const affiliation, GSList *jids) { muc_jid_autocomplete_add_all(room, jids); ui_handle_room_affiliation_list(room, affiliation, jids); } void -handle_room_role_set_error(const char * const room, const char * const nick, const char * const role, +srv_room_role_set_error(const char * const room, const char * const nick, const char * const role, const char * const error) { log_debug("Error setting role %s list for room %s, user %s: %s", role, room, nick, error); @@ -228,20 +228,20 @@ handle_room_role_set_error(const char * const room, const char * const nick, con } void -handle_room_role_list_result_error(const char * const room, const char * const role, const char * const error) +srv_room_role_list_result_error(const char * const room, const char * const role, const char * const error) { log_debug("Error retrieving %s list for room %s: %s", role, room, error); ui_handle_room_role_list_error(room, role, error); } void -handle_room_role_list(const char * const room, const char * const role, GSList *nicks) +srv_room_role_list(const char * const room, const char * const role, GSList *nicks) { ui_handle_room_role_list(room, role, nicks); } void -handle_room_affiliation_set_error(const char * const room, const char * const jid, const char * const affiliation, +srv_room_affiliation_set_error(const char * const room, const char * const jid, const char * const affiliation, const char * const error) { log_debug("Error setting affiliation %s list for room %s, user %s: %s", affiliation, room, jid, error); @@ -249,13 +249,13 @@ handle_room_affiliation_set_error(const char * const room, const char * const ji } void -handle_disco_items(GSList *items, const char *jid) +srv_disco_items(GSList *items, const char *jid) { cons_show_disco_items(items, jid); } void -handle_room_invite(jabber_invite_t invite_type, +srv_room_invite(jabber_invite_t invite_type, const char * const invitor, const char * const room, const char * const reason, const char * const password) { @@ -266,7 +266,7 @@ handle_room_invite(jabber_invite_t invite_type, } void -handle_room_broadcast(const char *const room_jid, +srv_room_broadcast(const char *const room_jid, const char * const message) { if (muc_roster_complete(room_jid)) { @@ -277,7 +277,7 @@ handle_room_broadcast(const char *const room_jid, } void -handle_room_subject(const char * const room, const char * const nick, const char * const subject) +srv_room_subject(const char * const room, const char * const nick, const char * const subject) { muc_set_subject(room, subject); if (muc_roster_complete(room)) { @@ -286,14 +286,14 @@ handle_room_subject(const char * const room, const char * const nick, const char } void -handle_room_history(const char * const room_jid, const char * const nick, +srv_room_history(const char * const room_jid, const char * const nick, GTimeVal tv_stamp, const char * const message) { ui_room_history(room_jid, nick, tv_stamp, message); } void -handle_room_message(const char * const room_jid, const char * const nick, +srv_room_message(const char * const room_jid, const char * const nick, const char * const message) { ui_room_message(room_jid, nick, message); @@ -306,19 +306,19 @@ handle_room_message(const char * const room_jid, const char * const nick, } void -handle_incoming_private_message(char *fulljid, char *message) +srv_incoming_private_message(char *fulljid, char *message) { ui_incoming_private_msg(fulljid, message, NULL); } void -handle_carbon(char *barejid, char *message) +srv_carbon(char *barejid, char *message) { ui_outgoing_chat_msg_carbon(barejid, message); } void -handle_incoming_message(char *barejid, char *resource, char *message) +srv_incoming_message(char *barejid, char *resource, char *message) { #ifdef HAVE_LIBOTR gboolean was_decrypted = FALSE; @@ -367,26 +367,26 @@ handle_incoming_message(char *barejid, char *resource, char *message) } void -handle_delayed_private_message(char *fulljid, char *message, GTimeVal tv_stamp) +srv_delayed_private_message(char *fulljid, char *message, GTimeVal tv_stamp) { ui_incoming_private_msg(fulljid, message, &tv_stamp); } void -handle_delayed_message(char *barejid, char *message, GTimeVal tv_stamp) +srv_delayed_message(char *barejid, char *message, GTimeVal tv_stamp) { ui_incoming_msg(barejid, NULL, message, &tv_stamp); chat_log_msg_in_delayed(barejid, message, &tv_stamp); } void -handle_message_receipt(char *barejid, char *id) +srv_message_receipt(char *barejid, char *id) { ui_message_receipt(barejid, id); } void -handle_typing(char *barejid, char *resource) +srv_typing(char *barejid, char *resource) { ui_contact_typing(barejid, resource); if (ui_chat_win_exists(barejid)) { @@ -395,7 +395,7 @@ handle_typing(char *barejid, char *resource) } void -handle_paused(char *barejid, char *resource) +srv_paused(char *barejid, char *resource) { if (ui_chat_win_exists(barejid)) { chat_session_recipient_paused(barejid, resource); @@ -403,7 +403,7 @@ handle_paused(char *barejid, char *resource) } void -handle_inactive(char *barejid, char *resource) +srv_inactive(char *barejid, char *resource) { if (ui_chat_win_exists(barejid)) { chat_session_recipient_inactive(barejid, resource); @@ -411,7 +411,7 @@ handle_inactive(char *barejid, char *resource) } void -handle_gone(const char * const barejid, const char * const resource) +srv_gone(const char * const barejid, const char * const resource) { ui_recipient_gone(barejid, resource); if (ui_chat_win_exists(barejid)) { @@ -420,7 +420,7 @@ handle_gone(const char * const barejid, const char * const resource) } void -handle_activity(const char * const barejid, const char * const resource, gboolean send_states) +srv_activity(const char * const barejid, const char * const resource, gboolean send_states) { if (ui_chat_win_exists(barejid)) { chat_session_recipient_active(barejid, resource, send_states); @@ -428,7 +428,7 @@ handle_activity(const char * const barejid, const char * const resource, gboolea } void -handle_subscription(const char *barejid, jabber_subscr_t type) +srv_subscription(const char *barejid, jabber_subscr_t type) { switch (type) { case PRESENCE_SUBSCRIBE: @@ -457,7 +457,7 @@ handle_subscription(const char *barejid, jabber_subscr_t type) } void -handle_contact_offline(char *barejid, char *resource, char *status) +srv_contact_offline(char *barejid, char *resource, char *status) { gboolean updated = roster_contact_offline(barejid, resource, status); @@ -470,7 +470,7 @@ handle_contact_offline(char *barejid, char *resource, char *status) } void -handle_contact_online(char *barejid, Resource *resource, +srv_contact_online(char *barejid, Resource *resource, GDateTime *last_activity) { gboolean updated = roster_update_presence(barejid, resource, last_activity); @@ -513,21 +513,21 @@ handle_contact_online(char *barejid, Resource *resource, } void -handle_leave_room(const char * const room) +srv_leave_room(const char * const room) { muc_leave(room); ui_leave_room(room); } void -handle_room_destroy(const char * const room) +srv_room_destroy(const char * const room) { muc_leave(room); ui_room_destroy(room); } void -handle_room_destroyed(const char * const room, const char * const new_jid, const char * const password, +srv_room_destroyed(const char * const room, const char * const new_jid, const char * const password, const char * const reason) { muc_leave(room); @@ -535,51 +535,51 @@ handle_room_destroyed(const char * const room, const char * const new_jid, const } void -handle_room_kicked(const char * const room, const char * const actor, const char * const reason) +srv_room_kicked(const char * const room, const char * const actor, const char * const reason) { muc_leave(room); ui_room_kicked(room, actor, reason); } void -handle_room_banned(const char * const room, const char * const actor, const char * const reason) +srv_room_banned(const char * const room, const char * const actor, const char * const reason) { muc_leave(room); ui_room_banned(room, actor, reason); } void -handle_room_configure(const char * const room, DataForm *form) +srv_room_configure(const char * const room, DataForm *form) { ui_handle_room_configuration(room, form); } void -handle_room_configuration_form_error(const char * const room, const char * const message) +srv_room_configuration_form_error(const char * const room, const char * const message) { ui_handle_room_configuration_form_error(room, message); } void -handle_room_config_submit_result(const char * const room) +srv_room_config_submit_result(const char * const room) { ui_handle_room_config_submit_result(room); } void -handle_room_config_submit_result_error(const char * const room, const char * const message) +srv_room_config_submit_result_error(const char * const room, const char * const message) { ui_handle_room_config_submit_result_error(room, message); } void -handle_room_kick_result_error(const char * const room, const char * const nick, const char * const error) +srv_room_kick_result_error(const char * const room, const char * const nick, const char * const error) { ui_handle_room_kick_error(room, nick, error); } void -handle_room_occupant_offline(const char * const room, const char * const nick, +srv_room_occupant_offline(const char * const room, const char * const nick, const char * const show, const char * const status) { muc_roster_remove(room, nick); @@ -593,7 +593,7 @@ handle_room_occupant_offline(const char * const room, const char * const nick, } void -handle_room_occupent_kicked(const char * const room, const char * const nick, const char * const actor, +srv_room_occupent_kicked(const char * const room, const char * const nick, const char * const actor, const char * const reason) { muc_roster_remove(room, nick); @@ -602,7 +602,7 @@ handle_room_occupent_kicked(const char * const room, const char * const nick, co } void -handle_room_occupent_banned(const char * const room, const char * const nick, const char * const actor, +srv_room_occupent_banned(const char * const room, const char * const nick, const char * const actor, const char * const reason) { muc_roster_remove(room, nick); @@ -611,33 +611,33 @@ handle_room_occupent_banned(const char * const room, const char * const nick, co } void -handle_group_add(const char * const contact, +srv_group_add(const char * const contact, const char * const group) { ui_group_added(contact, group); } void -handle_group_remove(const char * const contact, +srv_group_remove(const char * const contact, const char * const group) { ui_group_removed(contact, group); } void -handle_roster_remove(const char * const barejid) +srv_roster_remove(const char * const barejid) { ui_roster_remove(barejid); } void -handle_roster_add(const char * const barejid, const char * const name) +srv_roster_add(const char * const barejid, const char * const name) { ui_roster_add(barejid, name); } void -handle_roster_update(const char * const barejid, const char * const name, +srv_roster_update(const char * const barejid, const char * const name, GSList *groups, const char * const subscription, gboolean pending_out) { roster_update(barejid, name, groups, subscription, pending_out); @@ -645,20 +645,20 @@ handle_roster_update(const char * const barejid, const char * const name, } void -handle_autoping_cancel(void) +srv_autoping_cancel(void) { prefs_set_autoping(0); cons_show_error("Server ping not supported, autoping disabled."); } void -handle_xmpp_stanza(const char * const msg) +srv_xmpp_stanza(const char * const msg) { ui_handle_stanza(msg); } void -handle_ping_result(const char * const from, int millis) +srv_ping_result(const char * const from, int millis) { if (from == NULL) { cons_show("Ping response from server: %dms.", millis); @@ -668,7 +668,7 @@ handle_ping_result(const char * const from, int millis) } void -handle_ping_error_result(const char * const from, const char * const error) +srv_ping_error_result(const char * const from, const char * const error) { if (error == NULL) { cons_show_error("Error returned from pinging %s.", from); @@ -678,7 +678,7 @@ handle_ping_error_result(const char * const from, const char * const error) } void -handle_muc_self_online(const char * const room, const char * const nick, gboolean config_required, +srv_muc_self_online(const char * const room, const char * const nick, gboolean config_required, const char * const role, const char * const affiliation, const char * const actor, const char * const reason, const char * const jid, const char * const show, const char * const status) { @@ -755,7 +755,7 @@ handle_muc_self_online(const char * const room, const char * const nick, gboolea } void -handle_muc_occupant_online(const char * const room, const char * const nick, const char * const jid, +srv_muc_occupant_online(const char * const room, const char * const nick, const char * const jid, const char * const role, const char * const affiliation, const char * const actor, const char * const reason, const char * const show, const char * const status) { diff --git a/src/event/server_events.h b/src/event/server_events.h index 85d75ac3..acba1391 100644 --- a/src/event/server_events.h +++ b/src/event/server_events.h @@ -37,93 +37,93 @@ #include "xmpp/xmpp.h" -void handle_login_account_success(char *account_name); -void handle_lost_connection(void); -void handle_failed_login(void); -void handle_software_version_result(const char * const jid, const char * const presence, +void srv_login_account_success(char *account_name); +void srv_lost_connection(void); +void srv_failed_login(void); +void srv_software_version_result(const char * const jid, const char * const presence, const char * const name, const char * const version, const char * const os); -void handle_disco_info(const char *from, GSList *identities, GSList *features); -void handle_disco_info_error(const char * const from, const char * const error); -void handle_room_list(GSList *rooms, const char *conference_node); -void handle_disco_items(GSList *items, const char *jid); -void handle_room_invite(jabber_invite_t invite_type, +void srv_disco_info(const char *from, GSList *identities, GSList *features); +void srv_disco_info_error(const char * const from, const char * const error); +void srv_room_list(GSList *rooms, const char *conference_node); +void srv_disco_items(GSList *items, const char *jid); +void srv_room_invite(jabber_invite_t invite_type, const char * const invitor, const char * const room, const char * const reason, const char * const password); -void handle_room_broadcast(const char *const room_jid, +void srv_room_broadcast(const char *const room_jid, const char * const message); -void handle_room_subject(const char * const room, const char * const nick, const char * const subject); -void handle_room_history(const char * const room_jid, const char * const nick, +void srv_room_subject(const char * const room, const char * const nick, const char * const subject); +void srv_room_history(const char * const room_jid, const char * const nick, GTimeVal tv_stamp, const char * const message); -void handle_room_message(const char * const room_jid, const char * const nick, +void srv_room_message(const char * const room_jid, const char * const nick, const char * const message); -void handle_room_join_error(const char * const room, const char * const err); -void handle_room_info_error(const char * const room, const char * const error); -void handle_room_disco_info(const char * const room, GSList *identities, GSList *features, gboolean display); -void handle_room_affiliation_list_result_error(const char * const room, const char * const affiliation, +void srv_room_join_error(const char * const room, const char * const err); +void srv_room_info_error(const char * const room, const char * const error); +void srv_room_disco_info(const char * const room, GSList *identities, GSList *features, gboolean display); +void srv_room_affiliation_list_result_error(const char * const room, const char * const affiliation, const char * const error); -void handle_room_affiliation_list(const char * const room, const char * const affiliation, GSList *jids); -void handle_room_affiliation_set_error(const char * const room, const char * const jid, const char * const affiliation, +void srv_room_affiliation_list(const char * const room, const char * const affiliation, GSList *jids); +void srv_room_affiliation_set_error(const char * const room, const char * const jid, const char * const affiliation, const char * const error); -void handle_room_role_list_result_error(const char * const from, const char * const role, const char * const error); -void handle_room_role_list(const char * const from, const char * const role, GSList *nicks); -void handle_room_role_set_error(const char * const room, const char * const nick, const char * const role, +void srv_room_role_list_result_error(const char * const from, const char * const role, const char * const error); +void srv_room_role_list(const char * const from, const char * const role, GSList *nicks); +void srv_room_role_set_error(const char * const room, const char * const nick, const char * const role, const char * const error); -void handle_room_kick_result_error(const char * const room, const char * const nick, const char * const error); -void handle_incoming_message(char *barejid, char *resource, char *message); -void handle_incoming_private_message(char *fulljid, char *message); -void handle_delayed_message(char *fulljid, char *message, GTimeVal tv_stamp); -void handle_delayed_private_message(char *fulljid, char *message, GTimeVal tv_stamp); -void handle_typing(char *barejid, char *resource); -void handle_paused(char *barejid, char *resource); -void handle_inactive(char *barejid, char *resource); -void handle_activity(char *barejid, char *resource, gboolean send_states); -void handle_gone(const char * const barejid, const char * const resource); -void handle_subscription(const char *from, jabber_subscr_t type); -void handle_message_receipt(char *barejid, char *id); -void handle_contact_offline(char *contact, char *resource, char *status); -void handle_contact_online(char *contact, Resource *resource, +void srv_room_kick_result_error(const char * const room, const char * const nick, const char * const error); +void srv_incoming_message(char *barejid, char *resource, char *message); +void srv_incoming_private_message(char *fulljid, char *message); +void srv_delayed_message(char *fulljid, char *message, GTimeVal tv_stamp); +void srv_delayed_private_message(char *fulljid, char *message, GTimeVal tv_stamp); +void srv_typing(char *barejid, char *resource); +void srv_paused(char *barejid, char *resource); +void srv_inactive(char *barejid, char *resource); +void srv_activity(char *barejid, char *resource, gboolean send_states); +void srv_gone(const char * const barejid, const char * const resource); +void srv_subscription(const char *from, jabber_subscr_t type); +void srv_message_receipt(char *barejid, char *id); +void srv_contact_offline(char *contact, char *resource, char *status); +void srv_contact_online(char *contact, Resource *resource, GDateTime *last_activity); -void handle_leave_room(const char * const room); -void handle_room_destroy(const char * const room); -void handle_room_occupant_offline(const char * const room, const char * const nick, +void srv_leave_room(const char * const room); +void srv_room_destroy(const char * const room); +void srv_room_occupant_offline(const char * const room, const char * const nick, const char * const show, const char * const status); -void handle_room_destroyed(const char * const room, const char * const new_jid, const char * const password, +void srv_room_destroyed(const char * const room, const char * const new_jid, const char * const password, const char * const reason); -void handle_room_kicked(const char * const room, const char * const actor, const char * const reason); -void handle_room_occupent_kicked(const char * const room, const char * const nick, const char * const actor, +void srv_room_kicked(const char * const room, const char * const actor, const char * const reason); +void srv_room_occupent_kicked(const char * const room, const char * const nick, const char * const actor, const char * const reason); -void handle_room_banned(const char * const room, const char * const actor, const char * const reason); -void handle_room_occupent_banned(const char * const room, const char * const nick, const char * const actor, +void srv_room_banned(const char * const room, const char * const actor, const char * const reason); +void srv_room_occupent_banned(const char * const room, const char * const nick, const char * const actor, const char * const reason); -void handle_group_add(const char * const contact, +void srv_group_add(const char * const contact, const char * const group); -void handle_group_remove(const char * const contact, +void srv_group_remove(const char * const contact, const char * const group); -void handle_roster_remove(const char * const barejid); -void handle_roster_add(const char * const barejid, const char * const name); -void handle_autoping_cancel(void); -void handle_carbon(char *barejid, char *message); -void handle_message_error(const char * const from, const char * const type, +void srv_roster_remove(const char * const barejid); +void srv_roster_add(const char * const barejid, const char * const name); +void srv_autoping_cancel(void); +void srv_carbon(char *barejid, char *message); +void srv_message_error(const char * const from, const char * const type, const char * const err_msg); -void handle_presence_error(const char *from, const char * const type, +void srv_presence_error(const char *from, const char * const type, const char *err_msg); -void handle_xmpp_stanza(const char * const msg); -void handle_ping_result(const char * const from, int millis); -void handle_ping_error_result(const char * const from, const char * const error); -void handle_room_configure(const char * const room, DataForm *form); -void handle_room_configuration_form_error(const char * const from, const char * const message); -void handle_room_config_submit_result(const char * const room); -void handle_room_config_submit_result_error(const char * const room, const char * const message); -void handle_muc_self_online(const char * const room, const char * const nick, gboolean config_required, +void srv_xmpp_stanza(const char * const msg); +void srv_ping_result(const char * const from, int millis); +void srv_ping_error_result(const char * const from, const char * const error); +void srv_room_configure(const char * const room, DataForm *form); +void srv_room_configuration_form_error(const char * const from, const char * const message); +void srv_room_config_submit_result(const char * const room); +void srv_room_config_submit_result_error(const char * const room, const char * const message); +void srv_muc_self_online(const char * const room, const char * const nick, gboolean config_required, const char * const role, const char * const affiliation, const char * const actor, const char * const reason, const char * const jid, const char * const show, const char * const status); -void handle_muc_occupant_online(const char * const room, const char * const nick, const char * const jid, +void srv_muc_occupant_online(const char * const room, const char * const nick, const char * const jid, const char * const role, const char * const affiliation, const char * const actor, const char * const reason, const char * const show_str, const char * const status_str); -void handle_roster_update(const char * const barejid, const char * const name, +void srv_roster_update(const char * const barejid, const char * const name, GSList *groups, const char * const subscription, gboolean pending_out); -void handle_roster_received(void); -void handle_enable_carbons_error(const char * const error); -void handle_disable_carbons_error(const char * const error); +void srv_roster_received(void); +void srv_enable_carbons_error(const char * const error); +void srv_disable_carbons_error(const char * const error); #endif diff --git a/src/xmpp/connection.c b/src/xmpp/connection.c index c51652fa..295c8f2f 100644 --- a/src/xmpp/connection.c +++ b/src/xmpp/connection.c @@ -438,7 +438,7 @@ _connection_handler(xmpp_conn_t * const conn, // logged in with account if (saved_account.name != NULL) { log_debug("Connection handler: logged in with account name: %s", saved_account.name); - handle_login_account_success(saved_account.name); + srv_login_account_success(saved_account.name); // logged in without account, use details to create new account } else { @@ -446,7 +446,7 @@ _connection_handler(xmpp_conn_t * const conn, accounts_add(saved_details.name, saved_details.altdomain, saved_details.port); accounts_set_jid(saved_details.name, saved_details.jid); - handle_login_account_success(saved_details.name); + srv_login_account_success(saved_details.name); saved_account.name = strdup(saved_details.name); saved_account.passwd = strdup(saved_details.passwd); @@ -486,7 +486,7 @@ _connection_handler(xmpp_conn_t * const conn, // lost connection for unknown reason if (jabber_conn.conn_status == JABBER_CONNECTED) { log_debug("Connection handler: Lost connection for unknown reason"); - handle_lost_connection(); + srv_lost_connection(); if (prefs_get_reconnect() != 0) { assert(reconnect_timer == NULL); reconnect_timer = g_timer_new(); @@ -503,7 +503,7 @@ _connection_handler(xmpp_conn_t * const conn, log_debug("Connection handler: Login failed"); if (reconnect_timer == NULL) { log_debug("Connection handler: No reconnect timer"); - handle_failed_login(); + srv_failed_login(); _connection_free_saved_account(); _connection_free_saved_details(); _connection_free_session_data(); @@ -563,7 +563,7 @@ _xmpp_file_logger(void * const userdata, const xmpp_log_level_t level, log_level_t prof_level = _get_log_level(level); log_msg(prof_level, area, msg); if ((g_strcmp0(area, "xmpp") == 0) || (g_strcmp0(area, "conn")) == 0) { - handle_xmpp_stanza(msg); + srv_xmpp_stanza(msg); } } diff --git a/src/xmpp/iq.c b/src/xmpp/iq.c index adee07b8..71876cdc 100644 --- a/src/xmpp/iq.c +++ b/src/xmpp/iq.c @@ -515,7 +515,7 @@ _pong_handler(xmpp_conn_t *const conn, xmpp_stanza_t * const stanza, if (errtype != NULL) { if (strcmp(errtype, "cancel") == 0) { log_warning("Server ping (id=%s) error type 'cancel', disabling autoping.", id); - handle_autoping_cancel(); + srv_autoping_cancel(); xmpp_timed_handler_delete(conn, _ping_timed_handler); } } @@ -739,7 +739,7 @@ _enable_carbons_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, char *type = xmpp_stanza_get_type(stanza); if (g_strcmp0(type, "error") == 0) { char *error_message = stanza_get_error_message(stanza); - handle_enable_carbons_error(error_message); + srv_enable_carbons_error(error_message); log_debug("Error enabling carbons: %s", error_message); } else { log_debug("Message carbons enabled."); @@ -754,7 +754,7 @@ _disable_carbons_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, char *type = xmpp_stanza_get_type(stanza); if (g_strcmp0(type, "error") == 0) { char *error_message = stanza_get_error_message(stanza); - handle_disable_carbons_error(error_message); + srv_disable_carbons_error(error_message); log_debug("Error disabling carbons: %s", error_message); } else { log_debug("Message carbons disabled."); @@ -774,7 +774,7 @@ _manual_pong_handler(xmpp_conn_t *const conn, xmpp_stanza_t * const stanza, // handle error responses if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) { char *error_message = stanza_get_error_message(stanza); - handle_ping_error_result(from, error_message); + srv_ping_error_result(from, error_message); free(error_message); g_date_time_unref(sent); return 0; @@ -788,7 +788,7 @@ _manual_pong_handler(xmpp_conn_t *const conn, xmpp_stanza_t * const stanza, g_date_time_unref(sent); g_date_time_unref(now); - handle_ping_result(from, elapsed_millis); + srv_ping_result(from, elapsed_millis); return 0; } @@ -865,7 +865,7 @@ _version_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, presence = string_from_resource_presence(resource->presence); } - handle_software_version_result(jid, presence, name_str, version_str, os_str); + srv_software_version_result(jid, presence, name_str, version_str, os_str); jid_destroy(jidp); @@ -1062,7 +1062,7 @@ _destroy_room_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const sta if (from == NULL) { log_error("No from attribute for IQ destroy room result"); } else { - handle_room_destroy(from); + srv_room_destroy(from); } return 0; @@ -1085,40 +1085,40 @@ _room_config_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, // handle error responses if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) { char *error_message = stanza_get_error_message(stanza); - handle_room_configuration_form_error(from, error_message); + srv_room_configuration_form_error(from, error_message); free(error_message); return 0; } if (from == NULL) { log_warning("No from attribute for IQ config request result"); - handle_room_configuration_form_error(from, "No from attribute for room cofig response."); + srv_room_configuration_form_error(from, "No from attribute for room cofig response."); return 0; } xmpp_stanza_t *query = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_QUERY); if (query == NULL) { log_warning("No query element found parsing room config response"); - handle_room_configuration_form_error(from, "No query element found parsing room config response"); + srv_room_configuration_form_error(from, "No query element found parsing room config response"); return 0; } xmpp_stanza_t *x = xmpp_stanza_get_child_by_ns(query, STANZA_NS_DATA); if (x == NULL) { log_warning("No x element found with %s namespace parsing room config response", STANZA_NS_DATA); - handle_room_configuration_form_error(from, "No form configuration options available"); + srv_room_configuration_form_error(from, "No form configuration options available"); return 0; } char *form_type = xmpp_stanza_get_attribute(x, STANZA_ATTR_TYPE); if (g_strcmp0(form_type, "form") != 0) { log_warning("x element not of type 'form' parsing room config response"); - handle_room_configuration_form_error(from, "Form not of type 'form' parsing room config response."); + srv_room_configuration_form_error(from, "Form not of type 'form' parsing room config response."); return 0; } DataForm *form = form_create(x); - handle_room_configure(from, form); + srv_room_configure(from, form); return 0; } @@ -1140,7 +1140,7 @@ static int _room_affiliation_set_result_handler(xmpp_conn_t * const conn, xmpp_s // handle error responses if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) { char *error_message = stanza_get_error_message(stanza); - handle_room_affiliation_set_error(from, affiliation_set->item, affiliation_set->privilege, error_message); + srv_room_affiliation_set_error(from, affiliation_set->item, affiliation_set->privilege, error_message); free(error_message); } @@ -1168,7 +1168,7 @@ static int _room_role_set_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t // handle error responses if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) { char *error_message = stanza_get_error_message(stanza); - handle_room_role_set_error(from, role_set->item, role_set->privilege, error_message); + srv_room_role_set_error(from, role_set->item, role_set->privilege, error_message); free(error_message); } @@ -1196,7 +1196,7 @@ _room_affiliation_list_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * // handle error responses if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) { char *error_message = stanza_get_error_message(stanza); - handle_room_affiliation_list_result_error(from, affiliation, error_message); + srv_room_affiliation_list_result_error(from, affiliation, error_message); free(error_message); free(affiliation); return 0; @@ -1218,7 +1218,7 @@ _room_affiliation_list_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * } } - handle_room_affiliation_list(from, affiliation, jids); + srv_room_affiliation_list(from, affiliation, jids); free(affiliation); g_slist_free(jids); @@ -1242,7 +1242,7 @@ _room_role_list_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const s // handle error responses if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) { char *error_message = stanza_get_error_message(stanza); - handle_room_role_list_result_error(from, role, error_message); + srv_room_role_list_result_error(from, role, error_message); free(error_message); free(role); return 0; @@ -1264,7 +1264,7 @@ _room_role_list_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const s } } - handle_room_role_list(from, role, nicks); + srv_room_role_list(from, role, nicks); free(role); g_slist_free(nicks); @@ -1288,12 +1288,12 @@ _room_config_submit_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stan // handle error responses if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) { char *error_message = stanza_get_error_message(stanza); - handle_room_config_submit_result_error(from, error_message); + srv_room_config_submit_result_error(from, error_message); free(error_message); return 0; } - handle_room_config_submit_result(from); + srv_room_config_submit_result(from); return 0; } @@ -1315,7 +1315,7 @@ _room_kick_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza // handle error responses if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) { char *error_message = stanza_get_error_message(stanza); - handle_room_kick_result_error(from, nick, error_message); + srv_room_kick_result_error(from, nick, error_message); free(error_message); free(nick); return 0; @@ -1359,7 +1359,7 @@ _room_info_response_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stan if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) { if (cb_data->display) { char *error_message = stanza_get_error_message(stanza); - handle_room_info_error(cb_data->room, error_message); + srv_room_info_error(cb_data->room, error_message); free(error_message); } free(cb_data->room); @@ -1411,7 +1411,7 @@ _room_info_response_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stan child = xmpp_stanza_get_next(child); } - handle_room_disco_info(cb_data->room, identities, features, cb_data->display); + srv_room_disco_info(cb_data->room, identities, features, cb_data->display); g_slist_free_full(features, free); g_slist_free_full(identities, (GDestroyNotify)_identity_destroy); @@ -1439,7 +1439,7 @@ _disco_info_response_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const sta // handle error responses if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) { char *error_message = stanza_get_error_message(stanza); - handle_disco_info_error(from, error_message); + srv_disco_info_error(from, error_message); free(error_message); return 0; } @@ -1488,7 +1488,7 @@ _disco_info_response_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const sta child = xmpp_stanza_get_next(child); } - handle_disco_info(from, identities, features); + srv_disco_info(from, identities, features); g_slist_free_full(features, free); g_slist_free_full(identities, (GDestroyNotify)_identity_destroy); @@ -1536,9 +1536,9 @@ _disco_items_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stan } if (g_strcmp0(id, "confreq") == 0) { - handle_room_list(items, from); + srv_room_list(items, from); } else if (g_strcmp0(id, "discoitemsreq") == 0) { - handle_disco_items(items, from); + srv_disco_items(items, from); } g_slist_free_full(items, (GDestroyNotify)_item_destroy); diff --git a/src/xmpp/message.c b/src/xmpp/message.c index ac20cbaf..8febbe11 100644 --- a/src/xmpp/message.c +++ b/src/xmpp/message.c @@ -299,7 +299,7 @@ _message_error_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, g_string_free(log_msg, TRUE); - handle_message_error(jid, type, err_msg); + srv_message_error(jid, type, err_msg); free(err_msg); @@ -346,7 +346,7 @@ _muc_user_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, password = xmpp_stanza_get_text(password_st); } - handle_room_invite(INVITE_MEDIATED, invitor, room, reason, password); + srv_room_invite(INVITE_MEDIATED, invitor, room, reason, password); jid_destroy(jidp); if (reason) { xmpp_free(ctx, reason); @@ -390,7 +390,7 @@ _conference_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, reason = xmpp_stanza_get_attribute(xns_conference, STANZA_ATTR_REASON); password = xmpp_stanza_get_attribute(xns_conference, STANZA_ATTR_PASSWORD); - handle_room_invite(INVITE_DIRECT, invitor, room, reason, password); + srv_room_invite(INVITE_DIRECT, invitor, room, reason, password); jid_destroy(jidp); @@ -414,7 +414,7 @@ _captcha_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, if (body != NULL) { char *message = xmpp_stanza_get_text(body); if (message != NULL) { - handle_room_broadcast(from, message); + srv_room_broadcast(from, message); xmpp_free(ctx, message); } } @@ -435,7 +435,7 @@ _groupchat_handler(xmpp_conn_t * const conn, xmpp_stanza_t *subject = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_SUBJECT); if (subject != NULL) { message = xmpp_stanza_get_text(subject); - handle_room_subject(jid->barejid, jid->resourcepart, message); + srv_room_subject(jid->barejid, jid->resourcepart, message); xmpp_free(ctx, message); jid_destroy(jid); @@ -448,7 +448,7 @@ _groupchat_handler(xmpp_conn_t * const conn, if (body != NULL) { message = xmpp_stanza_get_text(body); if (message != NULL) { - handle_room_broadcast(room_jid, message); + srv_room_broadcast(room_jid, message); xmpp_free(ctx, message); } } @@ -480,9 +480,9 @@ _groupchat_handler(xmpp_conn_t * const conn, message = xmpp_stanza_get_text(body); if (message != NULL) { if (delayed) { - handle_room_history(jid->barejid, jid->resourcepart, tv_stamp, message); + srv_room_history(jid->barejid, jid->resourcepart, tv_stamp, message); } else { - handle_room_message(jid->barejid, jid->resourcepart, message); + srv_room_message(jid->barejid, jid->resourcepart, message); } xmpp_free(ctx, message); } @@ -536,7 +536,7 @@ _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, char *fulljid = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); if (fulljid) { Jid *jidp = jid_create(fulljid); - handle_message_receipt(jidp->barejid, id); + srv_message_receipt(jidp->barejid, id); jid_destroy(jidp); return 1; } @@ -573,11 +573,11 @@ _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, if (message != NULL) { // if we are the recipient, treat as standard incoming message if(g_strcmp0(my_jid->barejid, jid_to->barejid) == 0){ - handle_incoming_message(jid_from->barejid, jid_from->resourcepart, message); + srv_incoming_message(jid_from->barejid, jid_from->resourcepart, message); } // else treat as a sent message else{ - handle_carbon(jid_to->barejid, message); + srv_carbon(jid_to->barejid, message); } xmpp_free(ctx, message); } @@ -615,9 +615,9 @@ _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, char *message = xmpp_stanza_get_text(body); if (message != NULL) { if (delayed) { - handle_delayed_private_message(jid->str, message, tv_stamp); + srv_delayed_private_message(jid->str, message, tv_stamp); } else { - handle_incoming_private_message(jid->str, message); + srv_incoming_private_message(jid->str, message); } xmpp_free(ctx, message); } @@ -639,9 +639,9 @@ _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, char *message = xmpp_stanza_get_text(body); if (message != NULL) { if (delayed) { - handle_delayed_message(jid->barejid, message, tv_stamp); + srv_delayed_message(jid->barejid, message, tv_stamp); } else { - handle_incoming_message(jid->barejid, jid->resourcepart, message); + srv_incoming_message(jid->barejid, jid->resourcepart, message); } if (id && prefs_get_boolean(PREF_RECEIPTS_SEND)) { xmpp_stanza_t *receipts = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_RECEIPTS); @@ -663,17 +663,17 @@ _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, gboolean paused = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_PAUSED) != NULL; gboolean inactive = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_INACTIVE) != NULL; if (gone) { - handle_gone(jid->barejid, jid->resourcepart); + srv_gone(jid->barejid, jid->resourcepart); } else if (typing) { - handle_typing(jid->barejid, jid->resourcepart); + srv_typing(jid->barejid, jid->resourcepart); } else if (paused) { - handle_paused(jid->barejid, jid->resourcepart); + srv_paused(jid->barejid, jid->resourcepart); } else if (inactive) { - handle_inactive(jid->barejid, jid->resourcepart); + srv_inactive(jid->barejid, jid->resourcepart); } else if (stanza_contains_chat_state(stanza)) { - handle_activity(jid->barejid, jid->resourcepart, TRUE); + srv_activity(jid->barejid, jid->resourcepart, TRUE); } else { - handle_activity(jid->barejid, jid->resourcepart, FALSE); + srv_activity(jid->barejid, jid->resourcepart, FALSE); } } diff --git a/src/xmpp/presence.c b/src/xmpp/presence.c index 2be9780a..403ddc4e 100644 --- a/src/xmpp/presence.c +++ b/src/xmpp/presence.c @@ -372,7 +372,7 @@ _presence_error_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, } log_info("Error joining room: %s, reason: %s", fulljid->barejid, error_cond); - handle_room_join_error(fulljid->barejid, error_cond); + srv_room_join_error(fulljid->barejid, error_cond); jid_destroy(fulljid); return 1; } @@ -400,7 +400,7 @@ _presence_error_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, g_string_free(log_msg, TRUE); - handle_presence_error(from, type, err_msg); + srv_presence_error(from, type, err_msg); free(err_msg); @@ -416,7 +416,7 @@ _unsubscribed_handler(xmpp_conn_t * const conn, Jid *from_jid = jid_create(from); log_debug("Unsubscribed presence handler fired for %s", from); - handle_subscription(from_jid->barejid, PRESENCE_UNSUBSCRIBED); + srv_subscription(from_jid->barejid, PRESENCE_UNSUBSCRIBED); autocomplete_remove(sub_requests_ac, from_jid->barejid); jid_destroy(from_jid); @@ -432,7 +432,7 @@ _subscribed_handler(xmpp_conn_t * const conn, Jid *from_jid = jid_create(from); log_debug("Subscribed presence handler fired for %s", from); - handle_subscription(from_jid->barejid, PRESENCE_SUBSCRIBED); + srv_subscription(from_jid->barejid, PRESENCE_SUBSCRIBED); autocomplete_remove(sub_requests_ac, from_jid->barejid); jid_destroy(from_jid); @@ -452,7 +452,7 @@ _subscribe_handler(xmpp_conn_t * const conn, return 1; } - handle_subscription(from_jid->barejid, PRESENCE_SUBSCRIBE); + srv_subscription(from_jid->barejid, PRESENCE_SUBSCRIBE); autocomplete_add(sub_requests_ac, from_jid->barejid); jid_destroy(from_jid); @@ -480,11 +480,11 @@ _unavailable_handler(xmpp_conn_t * const conn, if (strcmp(my_jid->barejid, from_jid->barejid) !=0) { if (from_jid->resourcepart != NULL) { - handle_contact_offline(from_jid->barejid, from_jid->resourcepart, status_str); + srv_contact_offline(from_jid->barejid, from_jid->resourcepart, status_str); // hack for servers that do not send full jid with unavailable presence } else { - handle_contact_offline(from_jid->barejid, "__prof_default", status_str); + srv_contact_offline(from_jid->barejid, "__prof_default", status_str); } } else { if (from_jid->resourcepart != NULL) { @@ -596,7 +596,7 @@ _available_handler(xmpp_conn_t * const conn, if (g_strcmp0(xmpp_presence->jid->barejid, my_jid->barejid) == 0) { connection_add_available_resource(resource); } else { - handle_contact_online(xmpp_presence->jid->barejid, resource, xmpp_presence->last_activity); + srv_contact_online(xmpp_presence->jid->barejid, resource, xmpp_presence->last_activity); } jid_destroy(my_jid); @@ -682,7 +682,7 @@ _muc_user_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * char *new_jid = stanza_get_muc_destroy_alternative_room(stanza); char *password = stanza_get_muc_destroy_alternative_password(stanza); char *reason = stanza_get_muc_destroy_reason(stanza); - handle_room_destroyed(room, new_jid, password, reason); + srv_room_destroyed(room, new_jid, password, reason); free(password); free(reason); @@ -690,19 +690,19 @@ _muc_user_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * } else if (g_slist_find_custom(status_codes, "307", (GCompareFunc)g_strcmp0) != NULL) { char *actor = stanza_get_actor(stanza); char *reason = stanza_get_reason(stanza); - handle_room_kicked(room, actor, reason); + srv_room_kicked(room, actor, reason); free(reason); // banned from room } else if (g_slist_find_custom(status_codes, "301", (GCompareFunc)g_strcmp0) != NULL) { char *actor = stanza_get_actor(stanza); char *reason = stanza_get_reason(stanza); - handle_room_banned(room, actor, reason); + srv_room_banned(room, actor, reason); free(reason); // normal exit } else { - handle_leave_room(room); + srv_leave_room(room); } g_slist_free_full(status_codes, free); @@ -713,7 +713,7 @@ _muc_user_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * gboolean config_required = stanza_muc_requires_config(stanza); char *actor = stanza_get_actor(stanza); char *reason = stanza_get_reason(stanza); - handle_muc_self_online(room, nick, config_required, role, affiliation, actor, reason, jid, show_str, status_str); + srv_muc_self_online(room, nick, config_required, role, affiliation, actor, reason, jid, show_str, status_str); } // handle presence from room members @@ -735,19 +735,19 @@ _muc_user_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * if (g_slist_find_custom(status_codes, "307", (GCompareFunc)g_strcmp0) != NULL) { char *actor = stanza_get_actor(stanza); char *reason = stanza_get_reason(stanza); - handle_room_occupent_kicked(room, nick, actor, reason); + srv_room_occupent_kicked(room, nick, actor, reason); free(reason); // banned from room } else if (g_slist_find_custom(status_codes, "301", (GCompareFunc)g_strcmp0) != NULL) { char *actor = stanza_get_actor(stanza); char *reason = stanza_get_reason(stanza); - handle_room_occupent_banned(room, nick, actor, reason); + srv_room_occupent_banned(room, nick, actor, reason); free(reason); // normal exit } else { - handle_room_occupant_offline(room, nick, "offline", status_str); + srv_room_occupant_offline(room, nick, "offline", status_str); } g_slist_free_full(status_codes, free); @@ -765,7 +765,7 @@ _muc_user_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * char *actor = stanza_get_actor(stanza); char *reason = stanza_get_reason(stanza); - handle_muc_occupant_online(room, nick, jid, role, affiliation, actor, reason, show_str, status_str); + srv_muc_occupant_online(room, nick, jid, role, affiliation, actor, reason, show_str, status_str); } } diff --git a/src/xmpp/roster.c b/src/xmpp/roster.c index 2e9d461b..51880d77 100644 --- a/src/xmpp/roster.c +++ b/src/xmpp/roster.c @@ -163,7 +163,7 @@ _group_add_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, { if (userdata != NULL) { GroupData *data = userdata; - handle_group_add(data->name, data->group); + srv_group_add(data->name, data->group); free(data->name); free(data->group); free(userdata); @@ -210,7 +210,7 @@ _group_remove_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, { if (userdata != NULL) { GroupData *data = userdata; - handle_group_remove(data->name, data->group); + srv_group_remove(data->name, data->group); free(data->name); free(data->group); free(userdata); @@ -260,7 +260,7 @@ _roster_set_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, roster_remove(name, barejid_lower); - handle_roster_remove(barejid_lower); + srv_roster_remove(barejid_lower); // otherwise update local roster } else { @@ -278,10 +278,10 @@ _roster_set_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, if (contact == NULL) { gboolean added = roster_add(barejid_lower, name, groups, sub, pending_out); if (added) { - handle_roster_add(barejid_lower, name); + srv_roster_add(barejid_lower, name); } } else { - handle_roster_update(barejid_lower, name, groups, sub, pending_out); + srv_roster_update(barejid_lower, name, groups, sub, pending_out); } } @@ -330,7 +330,7 @@ _roster_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, item = xmpp_stanza_get_next(item); } - handle_roster_received(); + srv_roster_received(); resource_presence_t conn_presence = accounts_get_login_presence(jabber_get_account_name()); presence_update(conn_presence, NULL, 0); diff --git a/tests/test_server_events.c b/tests/test_server_events.c index 5df7c243..29290203 100644 --- a/tests/test_server_events.c +++ b/tests/test_server_events.c @@ -21,7 +21,7 @@ void console_doesnt_show_online_presence_when_set_none(void **state) roster_add("test1@server", "bob", NULL, "both", FALSE); Resource *resource = resource_new("resource", RESOURCE_ONLINE, NULL, 10); - handle_contact_online("test1@server", resource, NULL); + srv_contact_online("test1@server", resource, NULL); roster_clear(); } @@ -38,7 +38,7 @@ void console_shows_online_presence_when_set_online(void **state) expect_memory(cons_show_contact_online, resource, resource, sizeof(resource)); expect_value(cons_show_contact_online, last_activity, NULL); - handle_contact_online("test1@server", resource, NULL); + srv_contact_online("test1@server", resource, NULL); roster_clear(); } @@ -55,7 +55,7 @@ void console_shows_online_presence_when_set_all(void **state) expect_memory(cons_show_contact_online, resource, resource, sizeof(resource)); expect_value(cons_show_contact_online, last_activity, NULL); - handle_contact_online("test1@server", resource, NULL); + srv_contact_online("test1@server", resource, NULL); roster_clear(); } @@ -67,7 +67,7 @@ void console_doesnt_show_dnd_presence_when_set_none(void **state) roster_add("test1@server", "bob", NULL, "both", FALSE); Resource *resource = resource_new("resource", RESOURCE_DND, NULL, 10); - handle_contact_online("test1@server", resource, NULL); + srv_contact_online("test1@server", resource, NULL); roster_clear(); } @@ -79,7 +79,7 @@ void console_doesnt_show_dnd_presence_when_set_online(void **state) roster_add("test1@server", "bob", NULL, "both", FALSE); Resource *resource = resource_new("resource", RESOURCE_DND, NULL, 10); - handle_contact_online("test1@server", resource, NULL); + srv_contact_online("test1@server", resource, NULL); roster_clear(); } @@ -96,7 +96,7 @@ void console_shows_dnd_presence_when_set_all(void **state) expect_memory(cons_show_contact_online, resource, resource, sizeof(resource)); expect_value(cons_show_contact_online, last_activity, NULL); - handle_contact_online("test1@server", resource, NULL); + srv_contact_online("test1@server", resource, NULL); roster_clear(); } @@ -109,7 +109,7 @@ void handle_message_error_when_no_recipient(void **state) expect_string(ui_handle_error, err_msg, err_msg); - handle_message_error(from, type, err_msg); + srv_message_error(from, type, err_msg); } void handle_message_error_when_recipient_cancel(void **state) @@ -121,7 +121,7 @@ void handle_message_error_when_recipient_cancel(void **state) prefs_set_boolean(PREF_STATES, FALSE); chat_sessions_init(); - handle_message_error(from, type, err_msg); + srv_message_error(from, type, err_msg); } void handle_message_error_when_recipient_cancel_disables_chat_session(void **state) @@ -135,7 +135,7 @@ void handle_message_error_when_recipient_cancel_disables_chat_session(void **sta chat_sessions_init(); chat_session_recipient_active(barejid, resource, FALSE); - handle_message_error(barejid, type, err_msg); + srv_message_error(barejid, type, err_msg); ChatSession *session = chat_session_get(barejid); assert_null(session); @@ -151,7 +151,7 @@ void handle_message_error_when_recipient_and_no_type(void **state) expect_string(ui_handle_recipient_error, recipient, from); expect_string(ui_handle_recipient_error, err_msg, err_msg); - handle_message_error(from, type, err_msg); + srv_message_error(from, type, err_msg); } void handle_presence_error_when_no_recipient(void **state) @@ -162,7 +162,7 @@ void handle_presence_error_when_no_recipient(void **state) expect_string(ui_handle_error, err_msg, err_msg); - handle_presence_error(from, type, err_msg); + srv_presence_error(from, type, err_msg); } void handle_presence_error_when_from_recipient(void **state) @@ -174,7 +174,7 @@ void handle_presence_error_when_from_recipient(void **state) expect_string(ui_handle_recipient_error, recipient, from); expect_string(ui_handle_recipient_error, err_msg, err_msg); - handle_presence_error(from, type, err_msg); + srv_presence_error(from, type, err_msg); } void handle_offline_removes_chat_session(void **state) @@ -187,7 +187,7 @@ void handle_offline_removes_chat_session(void **state) Resource *resourcep = resource_new(resource, RESOURCE_ONLINE, NULL, 10); roster_update_presence(barejid, resourcep, NULL); chat_session_recipient_active(barejid, resource, FALSE); - handle_contact_offline(barejid, resource, NULL); + srv_contact_offline(barejid, resource, NULL); ChatSession *session = chat_session_get(barejid); assert_null(session); @@ -203,7 +203,7 @@ void lost_connection_clears_chat_sessions(void **state) chat_session_recipient_active("steve@server.org", "mobile", FALSE); expect_any_cons_show_error(); - handle_lost_connection(); + srv_lost_connection(); ChatSession *session1 = chat_session_get("bob@server.org"); ChatSession *session2 = chat_session_get("steve@server.org"); From 32da6548da7bc9941b2ff64924223d67cdb0b063 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 19 Apr 2015 19:40:15 +0100 Subject: [PATCH 165/252] Added client_events module, reuse message sending code for all commands --- Makefile.am | 2 + src/command/commands.c | 81 ++---------------------------------- src/event/client_events.c | 86 +++++++++++++++++++++++++++++++++++++++ src/event/client_events.h | 40 ++++++++++++++++++ 4 files changed, 132 insertions(+), 77 deletions(-) create mode 100644 src/event/client_events.c create mode 100644 src/event/client_events.h diff --git a/Makefile.am b/Makefile.am index c5449a2b..6566cdfa 100644 --- a/Makefile.am +++ b/Makefile.am @@ -14,6 +14,7 @@ core_sources = \ src/xmpp/bookmark.c src/xmpp/bookmark.h \ src/xmpp/form.c src/xmpp/form.h \ src/event/server_events.c src/event/server_events.h \ + src/event/client_events.c src/event/client_events.h \ src/ui/ui.h src/ui/window.c src/ui/window.h src/ui/core.c \ src/ui/titlebar.c src/ui/statusbar.c src/ui/inputwin.c \ src/ui/titlebar.h src/ui/statusbar.h src/ui/inputwin.h \ @@ -61,6 +62,7 @@ tests_sources = \ src/ui/titlebar.c src/ui/statusbar.c src/ui/inputwin.c \ src/ui/titlebar.h src/ui/statusbar.h src/ui/inputwin.h \ src/event/server_events.c src/event/server_events.h \ + src/event/client_events.c src/event/client_events.h \ tests/xmpp/stub_xmpp.c \ tests/ui/stub_ui.c \ tests/log/stub_log.c \ diff --git a/src/command/commands.c b/src/command/commands.c index 29ae6614..1ee305e3 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -65,6 +65,7 @@ #include "xmpp/bookmark.h" #include "ui/ui.h" #include "ui/windows.h" +#include "event/client_events.h" static void _update_presence(const resource_presence_t presence, const char * const show, gchar **args); @@ -74,9 +75,6 @@ static void _cmd_show_filtered_help(char *heading, gchar *cmd_filter[], int filt static gint _compare_commands(Command *a, Command *b); static void _who_room(gchar **args, struct cmd_help_t help); static void _who_roster(gchar **args, struct cmd_help_t help); -static void _send_chat_message(const char * const barejid, const char * const message); -static void _send_otr_chat_message(const char * const barejid, const char * const message); -static void _send_otr_tagged_chat_message(const char * const barejid, const char * const message); extern GHashTable *commands; @@ -115,20 +113,7 @@ cmd_execute_default(const char * inp) ProfWin *current = wins_get_current(); ProfChatWin *chatwin = (ProfChatWin*)current; assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK); -#ifdef HAVE_LIBOTR - prof_otrpolicy_t policy = otr_get_policy(chatwin->barejid); - if (policy == PROF_OTRPOLICY_ALWAYS && !otr_is_secure(chatwin->barejid)) { - cons_show_error("Failed to send message. Please check OTR policy"); - return TRUE; - } - if (otr_is_secure(chatwin->barejid)) { - _send_otr_chat_message(chatwin->barejid, inp); - } else { - _send_chat_message(chatwin->barejid, inp); - } -#else - _send_chat_message(chatwin->barejid, inp); -#endif + client_msg_send(chatwin->barejid, inp); } break; @@ -1366,23 +1351,8 @@ cmd_msg(gchar **args, struct cmd_help_t help) } if (msg) { -#ifdef HAVE_LIBOTR - prof_otrpolicy_t policy = otr_get_policy(barejid); - if (otr_is_secure(barejid)) { - _send_otr_chat_message(barejid, msg); - } else if (policy == PROF_OTRPOLICY_ALWAYS) { - cons_show_error("Failed to send message. Please check OTR policy"); - } else if (policy == PROF_OTRPOLICY_OPPORTUNISTIC) { - _send_otr_tagged_chat_message(barejid, msg); - } else { - _send_chat_message(barejid, msg); - } + client_msg_send(barejid, msg); return TRUE; -#else - _send_chat_message(barejid, msg); - return TRUE; -#endif - } else { ui_new_chat_win(barejid); #ifdef HAVE_LIBOTR @@ -3189,15 +3159,7 @@ cmd_tiny(gchar **args, struct cmd_help_t help) case WIN_CHAT: { ProfChatWin *chatwin = wins_get_current_chat(); -#ifdef HAVE_LIBOTR - if (otr_is_secure(chatwin->barejid)) { - _send_otr_chat_message(chatwin->barejid, tiny); - } else { - _send_chat_message(chatwin->barejid, tiny); - } -#else - _send_chat_message(chatwin->barejid, tiny); -#endif + client_msg_send(chatwin->barejid, tiny); break; } case WIN_PRIVATE: @@ -4462,39 +4424,4 @@ gint _compare_commands(Command *a, Command *b) g_free(key_b); return result; -} - -static void -_send_chat_message(const char * const barejid, const char * const message) -{ - char *id = message_send_chat(barejid, message); - chat_log_msg_out(barejid, message); - ui_outgoing_chat_msg(barejid, message, id); - free(id); -} - -static void -_send_otr_chat_message(const char * const barejid, const char * const message) -{ - char *encrypted = otr_encrypt_message(barejid, message); - if (encrypted != NULL) { - char *id = message_send_chat_encrypted(barejid, encrypted); - chat_log_otr_msg_out(barejid, message); - ui_outgoing_chat_msg(barejid, message, id); - otr_free_message(encrypted); - free(id); - } else { - cons_show_error("Failed to encrypt and send message."); - } -} - -static void -_send_otr_tagged_chat_message(const char * const barejid, const char * const message) -{ - char *otr_tagged_msg = otr_tag_message(message); - char *id = message_send_chat_encrypted(barejid, otr_tagged_msg); - ui_outgoing_chat_msg(barejid, message, id); - chat_log_msg_out(barejid, message); - free(id); - free(otr_tagged_msg); } \ No newline at end of file diff --git a/src/event/client_events.c b/src/event/client_events.c new file mode 100644 index 00000000..48225078 --- /dev/null +++ b/src/event/client_events.c @@ -0,0 +1,86 @@ +/* + * client_events.c + * + * Copyright (C) 2012 - 2015 James Booth + * + * This file is part of Profanity. + * + * Profanity is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Profanity is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Profanity. If not, see . + * + * In addition, as a special exception, the copyright holders give permission to + * link the code of portions of this program with the OpenSSL library under + * certain conditions as described in each individual source file, and + * distribute linked combinations including the two. + * + * You must obey the GNU General Public License in all respects for all of the + * code used other than OpenSSL. If you modify file(s) with this exception, you + * may extend this exception to your version of the file(s), but you are not + * obligated to do so. If you do not wish to do so, delete this exception + * statement from your version. If you delete this exception statement from all + * source files in the program, then also delete it here. + * + */ + +#include + +#include "config.h" +#include "log.h" +#include "ui/ui.h" +#include "xmpp/xmpp.h" +#ifdef HAVE_LIBOTR +#include "otr/otr.h" +#endif + +void +client_msg_send(const char * const barejid, const char * const msg) +{ + char *id = NULL; + +#ifdef HAVE_LIBOTR + prof_otrpolicy_t policy = otr_get_policy(barejid); + + if (otr_is_secure(barejid)) { + char *encrypted = otr_encrypt_message(barejid, msg); + if (encrypted != NULL) { + id = message_send_chat_encrypted(barejid, encrypted); + chat_log_otr_msg_out(barejid, msg); + ui_outgoing_chat_msg(barejid, msg, id); + otr_free_message(encrypted); + } else { + cons_show_error("Failed to encrypt and send message."); + } + + } else if (policy == PROF_OTRPOLICY_ALWAYS) { + cons_show_error("Failed to send message. Please check OTR policy"); + + } else if (policy == PROF_OTRPOLICY_OPPORTUNISTIC) { + char *otr_tagged_msg = otr_tag_message(msg); + id = message_send_chat_encrypted(barejid, otr_tagged_msg); + ui_outgoing_chat_msg(barejid, msg, id); + chat_log_msg_out(barejid, msg); + free(otr_tagged_msg); + + } else { + id = message_send_chat(barejid, msg); + ui_outgoing_chat_msg(barejid, msg, id); + chat_log_msg_out(barejid, msg); + } +#else + id = message_send_chat(barejid, msg); + chat_log_msg_out(barejid, msg); + ui_outgoing_chat_msg(barejid, msg, id); +#endif + + free(id); +} \ No newline at end of file diff --git a/src/event/client_events.h b/src/event/client_events.h new file mode 100644 index 00000000..922b89d1 --- /dev/null +++ b/src/event/client_events.h @@ -0,0 +1,40 @@ +/* + * client_events.h + * + * Copyright (C) 2012 - 2015 James Booth + * + * This file is part of Profanity. + * + * Profanity is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Profanity is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Profanity. If not, see . + * + * In addition, as a special exception, the copyright holders give permission to + * link the code of portions of this program with the OpenSSL library under + * certain conditions as described in each individual source file, and + * distribute linked combinations including the two. + * + * You must obey the GNU General Public License in all respects for all of the + * code used other than OpenSSL. If you modify file(s) with this exception, you + * may extend this exception to your version of the file(s), but you are not + * obligated to do so. If you do not wish to do so, delete this exception + * statement from your version. If you delete this exception statement from all + * source files in the program, then also delete it here. + * + */ + +#ifndef CLIENT_EVENTS_H +#define CLIENT_EVENTS_H + +void client_msg_send(const char * const barejid, const char * const msg); + +#endif \ No newline at end of file From a4f9661da2b9328b51a81272aecf91129f97cc72 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 19 Apr 2015 21:03:20 +0100 Subject: [PATCH 166/252] Removed unused otr check --- src/ui/core.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/ui/core.c b/src/ui/core.c index e1df5edf..9f8ac806 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -417,11 +417,6 @@ ui_incoming_msg(const char * const barejid, const char * const resource, const c if (chatwin == NULL) { ProfWin *window = wins_new_chat(barejid); chatwin = (ProfChatWin*)window; -#ifdef HAVE_LIBOTR - if (otr_is_secure(barejid)) { - chatwin->is_otr = TRUE; - } -#endif win_created = TRUE; } From 53f2a4a35c287b755eff7e723928f56c9bf220d2 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 21 Apr 2015 21:57:39 +0100 Subject: [PATCH 167/252] Moved all message sending to client events module --- src/command/commands.c | 90 ++++++++++++++++++--------------------- src/event/client_events.c | 15 ++++++- src/event/client_events.h | 4 +- 3 files changed, 58 insertions(+), 51 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index 1ee305e3..0febccd8 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -81,8 +81,6 @@ extern GHashTable *commands; gboolean cmd_execute_default(const char * inp) { - jabber_conn_status_t status = jabber_get_connection_status(); - // handle escaped commands - treat as normal message if (g_str_has_prefix(inp, "//")) { inp++; @@ -94,46 +92,40 @@ cmd_execute_default(const char * inp) return TRUE; } - win_type_t win_type = ui_current_win_type(); - switch (win_type) + // handle non commands in non chat windows + ProfWin *current = wins_get_current(); + if (current->type != WIN_CHAT && current->type != WIN_MUC && current->type != WIN_PRIVATE) { + cons_show("Unknown command: %s", inp); + return TRUE; + } + + jabber_conn_status_t status = jabber_get_connection_status(); + if (status != JABBER_CONNECTED) { + ui_current_print_line("You are not currently connected."); + return TRUE; + } + + switch (current->type) { + case WIN_CHAT: { - case WIN_MUC: - if (status != JABBER_CONNECTED) { - ui_current_print_line("You are not currently connected."); - } else { - ProfMucWin *mucwin = wins_get_current_muc(); - message_send_groupchat(mucwin->roomjid, inp); - } - break; - - case WIN_CHAT: - if (status != JABBER_CONNECTED) { - ui_current_print_line("You are not currently connected."); - } else { - ProfWin *current = wins_get_current(); - ProfChatWin *chatwin = (ProfChatWin*)current; - assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK); - client_msg_send(chatwin->barejid, inp); - } - break; - - case WIN_PRIVATE: - if (status != JABBER_CONNECTED) { - ui_current_print_line("You are not currently connected."); - } else { - ProfPrivateWin *privatewin = wins_get_current_private(); - message_send_private(privatewin->fulljid, inp); - ui_outgoing_private_msg(privatewin->fulljid, inp); - } - break; - - case WIN_CONSOLE: - case WIN_XML: - cons_show("Unknown command: %s", inp); - break; - - default: - break; + ProfChatWin *chatwin = wins_get_current_chat(); + client_send_msg(chatwin->barejid, inp); + break; + } + case WIN_PRIVATE: + { + ProfPrivateWin *privatewin = wins_get_current_private(); + client_send_priv_msg(privatewin->fulljid, inp); + break; + } + case WIN_MUC: + { + ProfMucWin *mucwin = wins_get_current_muc(); + client_send_muc_msg(mucwin->roomjid, inp); + break; + } + default: + break; } return TRUE; @@ -1322,6 +1314,7 @@ cmd_msg(gchar **args, struct cmd_help_t help) return TRUE; } + // send private message when in MUC room if (win_type == WIN_MUC) { ProfMucWin *mucwin = wins_get_current_muc(); if (muc_roster_contains_nick(mucwin->roomjid, usr)) { @@ -1329,9 +1322,8 @@ cmd_msg(gchar **args, struct cmd_help_t help) g_string_append(full_jid, "/"); g_string_append(full_jid, usr); - if (msg != NULL) { - message_send_private(full_jid->str, msg); - ui_outgoing_private_msg(full_jid->str, msg); + if (msg) { + client_send_priv_msg(full_jid->str, msg); } else { ui_new_private_win(full_jid->str); } @@ -1344,6 +1336,7 @@ cmd_msg(gchar **args, struct cmd_help_t help) return TRUE; + // send chat message } else { char *barejid = roster_barejid_from_name(usr); if (barejid == NULL) { @@ -1351,7 +1344,7 @@ cmd_msg(gchar **args, struct cmd_help_t help) } if (msg) { - client_msg_send(barejid, msg); + client_send_msg(barejid, msg); return TRUE; } else { ui_new_chat_win(barejid); @@ -3159,20 +3152,19 @@ cmd_tiny(gchar **args, struct cmd_help_t help) case WIN_CHAT: { ProfChatWin *chatwin = wins_get_current_chat(); - client_msg_send(chatwin->barejid, tiny); + client_send_msg(chatwin->barejid, tiny); break; } case WIN_PRIVATE: { ProfPrivateWin *privatewin = wins_get_current_private(); - message_send_private(privatewin->fulljid, tiny); - ui_outgoing_private_msg(privatewin->fulljid, tiny); + client_send_priv_msg(privatewin->fulljid, tiny); break; } case WIN_MUC: { ProfMucWin *mucwin = wins_get_current_muc(); - message_send_groupchat(mucwin->roomjid, tiny); + client_send_muc_msg(mucwin->roomjid, tiny); break; } default: diff --git a/src/event/client_events.c b/src/event/client_events.c index 48225078..615010e5 100644 --- a/src/event/client_events.c +++ b/src/event/client_events.c @@ -43,7 +43,7 @@ #endif void -client_msg_send(const char * const barejid, const char * const msg) +client_send_msg(const char * const barejid, const char * const msg) { char *id = NULL; @@ -83,4 +83,17 @@ client_msg_send(const char * const barejid, const char * const msg) #endif free(id); +} + +void +client_send_muc_msg(const char * const roomjid, const char * const msg) +{ + message_send_groupchat(roomjid, msg); +} + +void +client_send_priv_msg(const char * const fulljid, const char * const msg) +{ + message_send_private(fulljid, msg); + ui_outgoing_private_msg(fulljid, msg); } \ No newline at end of file diff --git a/src/event/client_events.h b/src/event/client_events.h index 922b89d1..e0ae3959 100644 --- a/src/event/client_events.h +++ b/src/event/client_events.h @@ -35,6 +35,8 @@ #ifndef CLIENT_EVENTS_H #define CLIENT_EVENTS_H -void client_msg_send(const char * const barejid, const char * const msg); +void client_send_msg(const char * const barejid, const char * const msg); +void client_send_muc_msg(const char * const roomjid, const char * const msg); +void client_send_priv_msg(const char * const fulljid, const char * const msg); #endif \ No newline at end of file From 88739d5c59022b4d1f1b67da3128cb4a3266ecf9 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 21 Apr 2015 23:28:52 +0100 Subject: [PATCH 168/252] Moved new chat win events to client events module --- src/command/commands.c | 21 +++++++--- src/event/client_events.c | 13 ++++++ src/event/client_events.h | 3 ++ src/ui/core.c | 86 +++++++++++++++++++-------------------- src/ui/inputwin.c | 20 ++++----- src/ui/ui.h | 5 ++- src/ui/windows.c | 6 +-- tests/test_cmd_win.c | 8 ++-- tests/ui/stub_ui.c | 13 +++++- 9 files changed, 105 insertions(+), 70 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index 0febccd8..713cd0ef 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -738,7 +738,7 @@ gboolean cmd_win(gchar **args, struct cmd_help_t help) { int num = atoi(args[0]); - gboolean switched = ui_switch_win(num); + gboolean switched = ui_switch_win_num(num); if (switched == FALSE) { cons_show("Window %d does not exist.", num); } @@ -1347,7 +1347,13 @@ cmd_msg(gchar **args, struct cmd_help_t help) client_send_msg(barejid, msg); return TRUE; } else { - ui_new_chat_win(barejid); + ProfWin *window = (ProfWin*)wins_get_chat(barejid); + if (window) { + client_focus_win(window); + } else { + client_new_chat_win(barejid); + } + #ifdef HAVE_LIBOTR if (otr_is_secure(barejid)) { ui_gone_secure(barejid, otr_is_trusted(barejid)); @@ -2467,7 +2473,7 @@ cmd_form(gchar **args, struct cmd_help_t help) current = wins_get_console(); } int num = wins_get_num(current); - ui_switch_win(num); + ui_switch_win_num(num); } return TRUE; @@ -2775,7 +2781,7 @@ cmd_room(gchar **args, struct cmd_help_t help) if (confwin != NULL) { num = wins_get_num(window); - ui_switch_win(num); + ui_switch_win_num(num); } else { iq_request_room_config_form(mucwin->roomjid); } @@ -4180,7 +4186,12 @@ cmd_otr(gchar **args, struct cmd_help_t help) barejid = contact; } - ui_new_chat_win(barejid); + ProfWin *window = (ProfWin*)wins_get_chat(barejid); + if (window) { + client_focus_win(window); + } else { + client_new_chat_win(barejid); + } if (ui_current_win_is_otr()) { ui_current_print_formatted_line('!', 0, "You are already in an OTR session."); diff --git a/src/event/client_events.c b/src/event/client_events.c index 615010e5..c580f700 100644 --- a/src/event/client_events.c +++ b/src/event/client_events.c @@ -96,4 +96,17 @@ client_send_priv_msg(const char * const fulljid, const char * const msg) { message_send_private(fulljid, msg); ui_outgoing_private_msg(fulljid, msg); +} + +void +client_focus_win(ProfWin *win) +{ + ui_switch_win(win); +} + +void +client_new_chat_win(const char * const barejid) +{ + ProfWin *win = ui_new_chat_win(barejid); + ui_switch_win(win); } \ No newline at end of file diff --git a/src/event/client_events.h b/src/event/client_events.h index e0ae3959..41764e73 100644 --- a/src/event/client_events.h +++ b/src/event/client_events.h @@ -39,4 +39,7 @@ void client_send_msg(const char * const barejid, const char * const msg); void client_send_muc_msg(const char * const roomjid, const char * const msg); void client_send_priv_msg(const char * const fulljid, const char * const msg); +void client_focus_win(ProfWin *win); +void client_new_chat_win(const char * const barejid); + #endif \ No newline at end of file diff --git a/src/ui/core.c b/src/ui/core.c index 9f8ac806..78faff18 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -878,7 +878,14 @@ ui_win_has_unsaved_form(int num) } gboolean -ui_switch_win(const int i) +ui_switch_win(ProfWin *win) +{ + int num = wins_get_num(win); + return ui_switch_win_num(num); +} + +gboolean +ui_switch_win_num(const int i) { if (ui_win_exists(i)) { ProfWin *old_current = wins_get_current(); @@ -1358,6 +1365,30 @@ ui_recipient_gone(const char * const barejid, const char * const resource) } } +ProfWin* +ui_new_chat_win(const char * const barejid) +{ + ProfWin* window = wins_new_chat(barejid); + + int num = wins_get_num(window); + + if (prefs_get_boolean(PREF_CHLOG) && prefs_get_boolean(PREF_HISTORY)) { + _win_show_history(num, barejid); + } + + // if the contact is offline, show a message + PContact contact = roster_get_contact(barejid); + if (contact != NULL) { + if (strcmp(p_contact_presence(contact), "offline") == 0) { + const char * const show = p_contact_presence(contact); + const char * const status = p_contact_status(contact); + win_show_status_string(window, barejid, show, status, NULL, "--", "offline"); + } + } + + return window; +} + void ui_new_private_win(const char * const fulljid) { @@ -1372,39 +1403,7 @@ ui_new_private_win(const char * const fulljid) num = wins_get_num(window); } - ui_switch_win(num); -} - -void -ui_new_chat_win(const char * const barejid) -{ - ProfWin *window = (ProfWin*)wins_get_chat(barejid); - int num = 0; - - // create new window - if (window == NULL) { - window = wins_new_chat(barejid); - - num = wins_get_num(window); - - if (prefs_get_boolean(PREF_CHLOG) && prefs_get_boolean(PREF_HISTORY)) { - _win_show_history(num, barejid); - } - - // if the contact is offline, show a message - PContact contact = roster_get_contact(barejid); - if (contact != NULL) { - if (strcmp(p_contact_presence(contact), "offline") == 0) { - const char * const show = p_contact_presence(contact); - const char * const status = p_contact_status(contact); - win_show_status_string(window, barejid, show, status, NULL, "--", "offline"); - } - } - } else { - num = wins_get_num(window); - } - - ui_switch_win(num); + ui_switch_win_num(num); } void @@ -1412,7 +1411,7 @@ ui_create_xmlconsole_win(void) { ProfWin *window = wins_new_xmlconsole(); int num = wins_get_num(window); - ui_switch_win(num); + ui_switch_win_num(num); } void @@ -1421,7 +1420,7 @@ ui_open_xmlconsole_win(void) ProfXMLWin *xmlwin = wins_get_xmlconsole(); if (xmlwin != NULL) { int num = wins_get_num((ProfWin*)xmlwin); - ui_switch_win(num); + ui_switch_win_num(num); } } @@ -1467,7 +1466,7 @@ ui_outgoing_chat_msg(const char * const barejid, const char * const message, cha } else { win_print(window, '-', NULL, 0, THEME_TEXT_ME, "me", message); } - ui_switch_win(num); + ui_switch_win_num(num); } void @@ -1528,7 +1527,7 @@ ui_outgoing_private_msg(const char * const fulljid, const char * const message) } win_print(window, '-', NULL, 0, THEME_TEXT_ME, "me", message); - ui_switch_win(num); + ui_switch_win_num(num); } void @@ -1559,7 +1558,7 @@ ui_room_join(const char * const roomjid, gboolean focus) num = wins_get_num(window); if (focus) { - ui_switch_win(num); + ui_switch_win_num(num); } else { status_bar_active(num); ProfWin *console = wins_get_console(); @@ -1573,8 +1572,7 @@ ui_switch_to_room(const char * const roomjid) { ProfWin *window = (ProfWin*)wins_get_muc(roomjid); int num = wins_get_num(window); - num = wins_get_num(window); - ui_switch_win(num); + ui_switch_win_num(num); } void @@ -2747,7 +2745,7 @@ ui_handle_room_configuration(const char * const roomjid, DataForm *form) assert(confwin->memcheck == PROFCONFWIN_MEMCHECK); int num = wins_get_num(window); - ui_switch_win(num); + ui_switch_win_num(num); ui_show_form(confwin); @@ -2804,10 +2802,10 @@ ui_handle_room_config_submit_result(const char * const roomjid) if (muc_window) { int num = wins_get_num(muc_window); - ui_switch_win(num); + ui_switch_win_num(num); win_print(muc_window, '!', NULL, 0, THEME_ROOMINFO, "", "Room configuration successful"); } else { - ui_switch_win(1); + ui_switch_win_num(1); cons_show("Room configuration successful: %s", roomjid); } } else { diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index f55be0f1..935fd4ce 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -452,70 +452,70 @@ _inp_rl_tab_handler(int count, int key) static int _inp_rl_win1_handler(int count, int key) { - ui_switch_win(1); + ui_switch_win_num(1); return 0; } static int _inp_rl_win2_handler(int count, int key) { - ui_switch_win(2); + ui_switch_win_num(2); return 0; } static int _inp_rl_win3_handler(int count, int key) { - ui_switch_win(3); + ui_switch_win_num(3); return 0; } static int _inp_rl_win4_handler(int count, int key) { - ui_switch_win(4); + ui_switch_win_num(4); return 0; } static int _inp_rl_win5_handler(int count, int key) { - ui_switch_win(5); + ui_switch_win_num(5); return 0; } static int _inp_rl_win6_handler(int count, int key) { - ui_switch_win(6); + ui_switch_win_num(6); return 0; } static int _inp_rl_win7_handler(int count, int key) { - ui_switch_win(7); + ui_switch_win_num(7); return 0; } static int _inp_rl_win8_handler(int count, int key) { - ui_switch_win(8); + ui_switch_win_num(8); return 0; } static int _inp_rl_win9_handler(int count, int key) { - ui_switch_win(9); + ui_switch_win_num(9); return 0; } static int _inp_rl_win0_handler(int count, int key) { - ui_switch_win(0); + ui_switch_win_num(0); return 0; } diff --git a/src/ui/ui.h b/src/ui/ui.h index fc1485ff..d5e9c28c 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -59,7 +59,8 @@ void ui_close(void); void ui_redraw(void); void ui_resize(void); GSList* ui_get_chat_recipients(void); -gboolean ui_switch_win(const int i); +gboolean ui_switch_win_num(const int i); +gboolean ui_switch_win(ProfWin *win); void ui_next_win(void); void ui_previous_win(void); void ui_sigwinch_handler(int sig); @@ -86,8 +87,8 @@ void ui_handle_otr_error(const char * const barejid, const char * const message) unsigned long ui_get_idle_time(void); void ui_reset_idle_time(void); -void ui_new_chat_win(const char * const barejid); void ui_new_private_win(const char * const fulljid); +ProfWin* ui_new_chat_win(const char * const barejid); void ui_print_system_msg_from_recipient(const char * const barejid, const char *message); gint ui_unread(void); void ui_close_connected_win(int index); diff --git a/src/ui/windows.c b/src/ui/windows.c index 993a51c1..269bea1d 100644 --- a/src/ui/windows.c +++ b/src/ui/windows.c @@ -660,7 +660,7 @@ wins_swap(int source_win, int target_win) } if (wins_get_current_num() == source_win) { wins_set_current_by_num(target_win); - ui_switch_win(1); + ui_switch_win_num(1); } return TRUE; @@ -681,7 +681,7 @@ wins_swap(int source_win, int target_win) status_bar_active(source_win); } if ((wins_get_current_num() == source_win) || (wins_get_current_num() == target_win)) { - ui_switch_win(1); + ui_switch_win_num(1); } return TRUE; } @@ -740,7 +740,7 @@ wins_tidy(void) windows = new_windows; current = 1; - ui_switch_win(1); + ui_switch_win_num(1); g_list_free(keys); return TRUE; } else { diff --git a/tests/test_cmd_win.c b/tests/test_cmd_win.c index bc19ebf3..7ad01c49 100644 --- a/tests/test_cmd_win.c +++ b/tests/test_cmd_win.c @@ -15,8 +15,8 @@ void cmd_win_shows_message_when_win_doesnt_exist(void **state) CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "3", NULL }; - expect_value(ui_switch_win, i, 3); - will_return(ui_switch_win, FALSE); + expect_value(ui_switch_win_num, i, 3); + will_return(ui_switch_win_num, FALSE); expect_cons_show("Window 3 does not exist."); @@ -31,8 +31,8 @@ void cmd_win_switches_to_given_win_when_exists(void **state) CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "12", NULL }; - expect_value(ui_switch_win, i, 12); - will_return(ui_switch_win, TRUE); + expect_value(ui_switch_win_num, i, 12); + will_return(ui_switch_win_num, TRUE); gboolean result = cmd_win(args, *help); assert_true(result); diff --git a/tests/ui/stub_ui.c b/tests/ui/stub_ui.c index d7fdeb0a..54faa50a 100644 --- a/tests/ui/stub_ui.c +++ b/tests/ui/stub_ui.c @@ -64,7 +64,12 @@ GSList* ui_get_chat_recipients(void) return NULL; } -gboolean ui_switch_win(const int i) +gboolean ui_switch_win(ProfWin *win) +{ + return FALSE; +} + +gboolean ui_switch_win_num(const int i) { check_expected(i); return (gboolean)mock(); @@ -99,8 +104,12 @@ unsigned long ui_get_idle_time(void) } void ui_reset_idle_time(void) {} -void ui_new_chat_win(const char * const barejid) {} void ui_new_private_win(const char * const fulljid) {} +ProfWin* ui_new_chat_win(const char * const barejid) +{ + return NULL; +} + void ui_print_system_msg_from_recipient(const char * const barejid, const char *message) {} gint ui_unread(void) { From 1c47b57e195609511c3acd52a6d5e46e8288edca Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 21 Apr 2015 23:45:03 +0100 Subject: [PATCH 169/252] Tidy execute alias code --- src/command/commands.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index 713cd0ef..529a1019 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -137,18 +137,18 @@ cmd_execute_alias(const char * const inp, gboolean *ran) if (inp[0] != '/') { ran = FALSE; return TRUE; - } else { - char *alias = strdup(inp+1); - char *value = prefs_get_alias(alias); - free(alias); - if (value != NULL) { - *ran = TRUE; - return cmd_process_input(value); - } else { - *ran = FALSE; - return TRUE; - } } + + char *alias = strdup(inp+1); + char *value = prefs_get_alias(alias); + free(alias); + if (value) { + *ran = TRUE; + return cmd_process_input(value); + } + + *ran = FALSE; + return TRUE; } gboolean From ba286c54ef69f9adde8bd8aa4d54857dee5414cb Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 22 Apr 2015 00:29:37 +0100 Subject: [PATCH 170/252] Moved login events to client events module --- src/command/commands.c | 176 +++++++++++++++----------------------- src/event/client_events.c | 62 ++++++++++++++ src/event/client_events.h | 3 + 3 files changed, 132 insertions(+), 109 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index 529a1019..9ca70ef0 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -154,120 +154,78 @@ cmd_execute_alias(const char * const inp, gboolean *ran) gboolean cmd_connect(gchar **args, struct cmd_help_t help) { - gboolean result = FALSE; - jabber_conn_status_t conn_status = jabber_get_connection_status(); - if ((conn_status != JABBER_DISCONNECTED) && (conn_status != JABBER_STARTED)) { cons_show("You are either connected already, or a login is in process."); - result = TRUE; - } else { - gchar *opt_keys[] = { "server", "port", NULL }; - gboolean parsed; - - GHashTable *options = parse_options(&args[args[0] ? 1 : 0], opt_keys, &parsed); - if (!parsed) { - cons_show("Usage: %s", help.usage); - cons_show(""); - return TRUE; - } - - char *altdomain = g_hash_table_lookup(options, "server"); - - int port = 0; - if (g_hash_table_contains(options, "port")) { - char *port_str = g_hash_table_lookup(options, "port"); - char *err_msg = NULL; - gboolean res = strtoi_range(port_str, &port, 1, 65535, &err_msg); - if (!res) { - cons_show(err_msg); - cons_show(""); - free(err_msg); - port = 0; - return TRUE; - } - } - - char *user = args[0]; - char *def = prefs_get_string(PREF_DEFAULT_ACCOUNT); - if(!user){ - if(def){ - user = def; - cons_show("Using default account %s.", user); - } else { - cons_show("No default account."); - g_free(def); - return TRUE; - } - } - - char *lower = g_utf8_strdown(user, -1); - char *jid; - g_free(def); - def = NULL; - - ProfAccount *account = accounts_get_account(lower); - if (account != NULL) { - jid = account_create_full_jid(account); - if(account->eval_password){ - // Evaluate as shell command to retrieve password - GString *cmd = g_string_append(g_string_new(account->eval_password), " 2>/dev/null"); - FILE *stream = popen(cmd->str, "r"); - g_string_free(cmd, TRUE); - if(stream){ - // Limit to READ_BUF_SIZE bytes to prevent overflows in the case of a poorly chosen command - account->password = g_malloc(READ_BUF_SIZE); - if(!account->password){ - log_error("Failed to allocate enough memory to read eval_password output"); - cons_show("Error evaluating password, see logs for details."); - return TRUE; - } - account->password = fgets(account->password, READ_BUF_SIZE, stream); - pclose(stream); - if(!account->password){ - log_error("No result from eval_password."); - cons_show("Error evaluating password, see logs for details."); - return TRUE; - } - // strip trailing newline - if (g_str_has_suffix(account->password, "\n")) { - account->password[strlen(account->password)-1] = '\0'; - } - } else { - log_error("popen failed when running eval_password."); - cons_show("Error evaluating password, see logs for details."); - return TRUE; - } - } else if (!account->password) { - account->password = ui_ask_password(); - } - cons_show("Connecting with account %s as %s", account->name, jid); - if(g_hash_table_contains(options, "port") || g_hash_table_contains(options, "server")) - cons_show("Ignoring extra connect options. Please set them with /account set"); - conn_status = jabber_connect_with_account(account); - account_free(account); - } else { - char *passwd = ui_ask_password(); - jid = strdup(lower); - cons_show("Connecting as %s", jid); - conn_status = jabber_connect_with_details(jid, passwd, altdomain, port); - free(passwd); - } - g_free(lower); - - if (conn_status == JABBER_DISCONNECTED) { - cons_show_error("Connection attempt for %s failed.", jid); - log_info("Connection attempt for %s failed", jid); - } - - options_destroy(options); - - free(jid); - - result = TRUE; + return TRUE; } - return result; + gchar *opt_keys[] = { "server", "port", NULL }; + gboolean parsed; + + GHashTable *options = parse_options(&args[args[0] ? 1 : 0], opt_keys, &parsed); + if (!parsed) { + cons_show("Usage: %s", help.usage); + cons_show(""); + return TRUE; + } + + char *altdomain = g_hash_table_lookup(options, "server"); + + int port = 0; + if (g_hash_table_contains(options, "port")) { + char *port_str = g_hash_table_lookup(options, "port"); + char *err_msg = NULL; + gboolean res = strtoi_range(port_str, &port, 1, 65535, &err_msg); + if (!res) { + cons_show(err_msg); + cons_show(""); + free(err_msg); + port = 0; + return TRUE; + } + } + + char *user = args[0]; + char *def = prefs_get_string(PREF_DEFAULT_ACCOUNT); + if (!user) { + if (def) { + user = def; + cons_show("Using default account %s.", user); + } else { + cons_show("No default account."); + g_free(def); + return TRUE; + } + } + + char *lower = g_utf8_strdown(user, -1); + char *jid; + g_free(def); + + ProfAccount *account = accounts_get_account(lower); + if (account) { + jid = account_create_full_jid(account); + gboolean res = client_connect_account(account, &conn_status); + if (!res) { + g_free(lower); + return TRUE; + } + } else { + jid = strdup(lower); + conn_status = client_connect_jid(jid, altdomain, port); + } + + if (conn_status == JABBER_DISCONNECTED) { + cons_show_error("Connection attempt for %s failed.", jid); + log_info("Connection attempt for %s failed", jid); + } + + options_destroy(options); + g_free(lower); + free(jid); + + return TRUE; } gboolean diff --git a/src/event/client_events.c b/src/event/client_events.c index c580f700..08c422c4 100644 --- a/src/event/client_events.c +++ b/src/event/client_events.c @@ -42,6 +42,68 @@ #include "otr/otr.h" #endif +jabber_conn_status_t +client_connect_jid(const char * const jid, const char * const altdomain, const int port) +{ + cons_show("Connecting as %s", jid); + char *passwd = ui_ask_password(); + jabber_conn_status_t conn_status = jabber_connect_with_details(jid, passwd, altdomain, port); + free(passwd); + + return conn_status; +} + +gboolean +client_connect_account(ProfAccount *account, jabber_conn_status_t *conn_status) +{ + if (account->eval_password) { + + // Evaluate as shell command to retrieve password + GString *cmd = g_string_new(""); + g_string_append_printf(cmd, "%s 2>/dev/null", account->eval_password); + + FILE *stream = popen(cmd->str, "r"); + g_string_free(cmd, TRUE); + if (stream) { + // Limit to READ_BUF_SIZE bytes to prevent overflows in the case of a poorly chosen command + account->password = g_malloc(READ_BUF_SIZE); + if (!account->password) { + log_error("Failed to allocate enough memory to read eval_password output"); + cons_show("Error evaluating password, see logs for details."); + return FALSE; + } + account->password = fgets(account->password, READ_BUF_SIZE, stream); + pclose(stream); + if (!account->password) { + log_error("No result from eval_password."); + cons_show("Error evaluating password, see logs for details."); + return FALSE; + } + + // strip trailing newline + if (g_str_has_suffix(account->password, "\n")) { + account->password[strlen(account->password)-1] = '\0'; + } + } else { + log_error("popen failed when running eval_password."); + cons_show("Error evaluating password, see logs for details."); + return FALSE; + } + + } else if (!account->password) { + account->password = ui_ask_password(); + } + + char *jid = account_create_full_jid(account); + cons_show("Connecting with account %s as %s", account->name, jid); + free(jid); + + *conn_status = jabber_connect_with_account(account); + account_free(account); + + return TRUE; +} + void client_send_msg(const char * const barejid, const char * const msg) { diff --git a/src/event/client_events.h b/src/event/client_events.h index 41764e73..156c66a3 100644 --- a/src/event/client_events.h +++ b/src/event/client_events.h @@ -35,6 +35,9 @@ #ifndef CLIENT_EVENTS_H #define CLIENT_EVENTS_H +jabber_conn_status_t client_connect_jid(const char * const jid, const char * const altdomain, const int port); +gboolean client_connect_account(ProfAccount *account, jabber_conn_status_t *conn_status); + void client_send_msg(const char * const barejid, const char * const msg); void client_send_muc_msg(const char * const roomjid, const char * const msg); void client_send_priv_msg(const char * const fulljid, const char * const msg); From bc9e6b79cdc246f7e97f6ddff7ea81474a698b05 Mon Sep 17 00:00:00 2001 From: James Booth Date: Thu, 23 Apr 2015 21:56:48 +0100 Subject: [PATCH 171/252] Tidied account login --- src/command/commands.c | 37 +++++++++++++++++++++----- src/config/account.c | 40 ++++++++++++++++++++++++++++ src/config/account.h | 3 +-- src/event/client_events.c | 55 ++++----------------------------------- src/event/client_events.h | 4 +-- 5 files changed, 79 insertions(+), 60 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index 9ca70ef0..2d9e1dfc 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -203,17 +203,42 @@ cmd_connect(gchar **args, struct cmd_help_t help) char *jid; g_free(def); + // connect with account ProfAccount *account = accounts_get_account(lower); if (account) { - jid = account_create_full_jid(account); - gboolean res = client_connect_account(account, &conn_status); - if (!res) { - g_free(lower); - return TRUE; + // use password if set + if (account->password) { + conn_status = client_connect_account(account); + + // use eval_password if set + } else if (account->eval_password) { + gboolean res = account_eval_password(account); + if (res) { + conn_status = client_connect_account(account); + free(account->password); + account->password = NULL; + } else { + cons_show("Error evaluating password, see logs for details."); + g_free(lower); + return TRUE; + } + + // no account password setting, prompt + } else { + account->password = ui_ask_password(); + conn_status = client_connect_account(account); + free(account->password); + account->password = NULL; } + + jid = account_create_full_jid(account); + + // connect with JID } else { jid = strdup(lower); - conn_status = client_connect_jid(jid, altdomain, port); + char *passwd = ui_ask_password(); + conn_status = client_connect_jid(jid, passwd, altdomain, port); + free(passwd); } if (conn_status == JABBER_DISCONNECTED) { diff --git a/src/config/account.c b/src/config/account.c index 3896286b..749eb885 100644 --- a/src/config/account.c +++ b/src/config/account.c @@ -34,12 +34,14 @@ #include #include +#include #include #include "jid.h" #include "config/account.h" #include "common.h" +#include "log.h" ProfAccount* account_new(const gchar * const name, const gchar * const jid, @@ -155,6 +157,44 @@ account_create_full_jid(ProfAccount *account) } } +gboolean +account_eval_password(ProfAccount *account) +{ + assert(account != NULL); + assert(account->eval_password != NULL); + + // Evaluate as shell command to retrieve password + GString *cmd = g_string_new(""); + g_string_append_printf(cmd, "%s 2>/dev/null", account->eval_password); + + FILE *stream = popen(cmd->str, "r"); + g_string_free(cmd, TRUE); + if (stream) { + // Limit to READ_BUF_SIZE bytes to prevent overflows in the case of a poorly chosen command + account->password = g_malloc(READ_BUF_SIZE); + if (!account->password) { + log_error("Failed to allocate enough memory to read eval_password output"); + return FALSE; + } + account->password = fgets(account->password, READ_BUF_SIZE, stream); + pclose(stream); + if (!account->password) { + log_error("No result from eval_password."); + return FALSE; + } + + // strip trailing newline + if (g_str_has_suffix(account->password, "\n")) { + account->password[strlen(account->password)-1] = '\0'; + } + } else { + log_error("popen failed when running eval_password."); + return FALSE; + } + + return TRUE; +} + void account_free(ProfAccount *account) { diff --git a/src/config/account.h b/src/config/account.h index c237a19e..218f8ce7 100644 --- a/src/config/account.h +++ b/src/config/account.h @@ -69,9 +69,8 @@ ProfAccount* account_new(const gchar * const name, const gchar * const jid, const gchar * const muc_service, const gchar * const muc_nick, const gchar * const otr_policy, GList *otr_manual, GList *otr_opportunistic, GList *otr_always); - char* account_create_full_jid(ProfAccount *account); - +gboolean account_eval_password(ProfAccount *account); void account_free(ProfAccount *account); #endif diff --git a/src/event/client_events.c b/src/event/client_events.c index 08c422c4..2a1d349a 100644 --- a/src/event/client_events.c +++ b/src/event/client_events.c @@ -43,65 +43,20 @@ #endif jabber_conn_status_t -client_connect_jid(const char * const jid, const char * const altdomain, const int port) +client_connect_jid(const char * const jid, const char * const passwd, const char * const altdomain, const int port) { cons_show("Connecting as %s", jid); - char *passwd = ui_ask_password(); - jabber_conn_status_t conn_status = jabber_connect_with_details(jid, passwd, altdomain, port); - free(passwd); - - return conn_status; + return jabber_connect_with_details(jid, passwd, altdomain, port); } -gboolean -client_connect_account(ProfAccount *account, jabber_conn_status_t *conn_status) +jabber_conn_status_t +client_connect_account(ProfAccount *account) { - if (account->eval_password) { - - // Evaluate as shell command to retrieve password - GString *cmd = g_string_new(""); - g_string_append_printf(cmd, "%s 2>/dev/null", account->eval_password); - - FILE *stream = popen(cmd->str, "r"); - g_string_free(cmd, TRUE); - if (stream) { - // Limit to READ_BUF_SIZE bytes to prevent overflows in the case of a poorly chosen command - account->password = g_malloc(READ_BUF_SIZE); - if (!account->password) { - log_error("Failed to allocate enough memory to read eval_password output"); - cons_show("Error evaluating password, see logs for details."); - return FALSE; - } - account->password = fgets(account->password, READ_BUF_SIZE, stream); - pclose(stream); - if (!account->password) { - log_error("No result from eval_password."); - cons_show("Error evaluating password, see logs for details."); - return FALSE; - } - - // strip trailing newline - if (g_str_has_suffix(account->password, "\n")) { - account->password[strlen(account->password)-1] = '\0'; - } - } else { - log_error("popen failed when running eval_password."); - cons_show("Error evaluating password, see logs for details."); - return FALSE; - } - - } else if (!account->password) { - account->password = ui_ask_password(); - } - char *jid = account_create_full_jid(account); cons_show("Connecting with account %s as %s", account->name, jid); free(jid); - *conn_status = jabber_connect_with_account(account); - account_free(account); - - return TRUE; + return jabber_connect_with_account(account); } void diff --git a/src/event/client_events.h b/src/event/client_events.h index 156c66a3..efa535c9 100644 --- a/src/event/client_events.h +++ b/src/event/client_events.h @@ -35,8 +35,8 @@ #ifndef CLIENT_EVENTS_H #define CLIENT_EVENTS_H -jabber_conn_status_t client_connect_jid(const char * const jid, const char * const altdomain, const int port); -gboolean client_connect_account(ProfAccount *account, jabber_conn_status_t *conn_status); +jabber_conn_status_t client_connect_jid(const char * const jid, const char * const passwd, const char * const altdomain, const int port); +jabber_conn_status_t client_connect_account(ProfAccount *account); void client_send_msg(const char * const barejid, const char * const msg); void client_send_muc_msg(const char * const roomjid, const char * const msg); From f219302f069e1db38ae656f1d8cca931756f388c Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 27 Apr 2015 22:34:06 +0100 Subject: [PATCH 172/252] Renamed incoming otr message --- src/event/server_events.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/event/server_events.c b/src/event/server_events.c index bd4634e5..cc76ed17 100644 --- a/src/event/server_events.c +++ b/src/event/server_events.c @@ -322,7 +322,7 @@ srv_incoming_message(char *barejid, char *resource, char *message) { #ifdef HAVE_LIBOTR gboolean was_decrypted = FALSE; - char *newmessage; + char *otr_message; prof_otrpolicy_t policy = otr_get_policy(barejid); char *whitespace_base = strstr(message,OTRL_MESSAGE_TAG_BASE); @@ -344,10 +344,10 @@ srv_incoming_message(char *barejid, char *resource, char *message) } } } - newmessage = otr_decrypt_message(barejid, message, &was_decrypted); + otr_message = otr_decrypt_message(barejid, message, &was_decrypted); // internal OTR message - if (newmessage == NULL) { + if (otr_message == NULL) { return; } @@ -357,9 +357,9 @@ srv_incoming_message(char *barejid, char *resource, char *message) message_send_chat_encrypted(barejid, otr_query_message); } - ui_incoming_msg(barejid, resource, newmessage, NULL); - chat_log_otr_msg_in(barejid, newmessage, was_decrypted); - otr_free_message(newmessage); + ui_incoming_msg(barejid, resource, otr_message, NULL); + chat_log_otr_msg_in(barejid, otr_message, was_decrypted); + otr_free_message(otr_message); #else ui_incoming_msg(barejid, resource, message, NULL); chat_log_msg_in(barejid, message); From eb177ccbefe24732dc1c0a127d1720f1809e53e5 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 27 Apr 2015 23:17:38 +0100 Subject: [PATCH 173/252] Removed server_events dependency on libotr headers --- src/event/server_events.c | 41 +----------------------------------- src/otr/otr.c | 44 +++++++++++++++++++++++++++++++++++++++ src/otr/otr.h | 1 + tests/otr/stub_otr.c | 3 ++- 4 files changed, 48 insertions(+), 41 deletions(-) diff --git a/src/event/server_events.c b/src/event/server_events.c index cc76ed17..514835ba 100644 --- a/src/event/server_events.c +++ b/src/event/server_events.c @@ -46,7 +46,6 @@ #ifdef HAVE_LIBOTR #include "otr/otr.h" -#include #endif #include "ui/ui.h" @@ -321,45 +320,7 @@ void srv_incoming_message(char *barejid, char *resource, char *message) { #ifdef HAVE_LIBOTR - gboolean was_decrypted = FALSE; - char *otr_message; - - prof_otrpolicy_t policy = otr_get_policy(barejid); - char *whitespace_base = strstr(message,OTRL_MESSAGE_TAG_BASE); - - //check for OTR whitespace (opportunistic or always) - if (policy == PROF_OTRPOLICY_OPPORTUNISTIC || policy == PROF_OTRPOLICY_ALWAYS) { - if (whitespace_base) { - if (strstr(message, OTRL_MESSAGE_TAG_V2) || strstr(message, OTRL_MESSAGE_TAG_V1)) { - // Remove whitespace pattern for proper display in UI - // Handle both BASE+TAGV1/2(16+8) and BASE+TAGV1+TAGV2(16+8+8) - int tag_length = 24; - if (strstr(message, OTRL_MESSAGE_TAG_V2) && strstr(message, OTRL_MESSAGE_TAG_V1)) { - tag_length = 32; - } - memmove(whitespace_base, whitespace_base+tag_length, tag_length); - char *otr_query_message = otr_start_query(); - cons_show("OTR Whitespace pattern detected. Attempting to start OTR session..."); - message_send_chat_encrypted(barejid, otr_query_message); - } - } - } - otr_message = otr_decrypt_message(barejid, message, &was_decrypted); - - // internal OTR message - if (otr_message == NULL) { - return; - } - - if (policy == PROF_OTRPOLICY_ALWAYS && !was_decrypted && !whitespace_base) { - char *otr_query_message = otr_start_query(); - cons_show("Attempting to start OTR session..."); - message_send_chat_encrypted(barejid, otr_query_message); - } - - ui_incoming_msg(barejid, resource, otr_message, NULL); - chat_log_otr_msg_in(barejid, otr_message, was_decrypted); - otr_free_message(otr_message); + otr_on_message_recv(barejid, resource, message); #else ui_incoming_msg(barejid, resource, message, NULL); chat_log_msg_in(barejid, message); diff --git a/src/otr/otr.c b/src/otr/otr.c index 9dcff1f9..70bf9761 100644 --- a/src/otr/otr.c +++ b/src/otr/otr.c @@ -269,6 +269,50 @@ otr_on_connect(ProfAccount *account) return; } +void +otr_on_message_recv(const char * const barejid, const char * const resource, const char * const message) +{ + gboolean was_decrypted = FALSE; + char *decrypted; + + prof_otrpolicy_t policy = otr_get_policy(barejid); + char *whitespace_base = strstr(message, OTRL_MESSAGE_TAG_BASE); + + //check for OTR whitespace (opportunistic or always) + if (policy == PROF_OTRPOLICY_OPPORTUNISTIC || policy == PROF_OTRPOLICY_ALWAYS) { + if (whitespace_base) { + if (strstr(message, OTRL_MESSAGE_TAG_V2) || strstr(message, OTRL_MESSAGE_TAG_V1)) { + // Remove whitespace pattern for proper display in UI + // Handle both BASE+TAGV1/2(16+8) and BASE+TAGV1+TAGV2(16+8+8) + int tag_length = 24; + if (strstr(message, OTRL_MESSAGE_TAG_V2) && strstr(message, OTRL_MESSAGE_TAG_V1)) { + tag_length = 32; + } + memmove(whitespace_base, whitespace_base+tag_length, tag_length); + char *otr_query_message = otr_start_query(); + cons_show("OTR Whitespace pattern detected. Attempting to start OTR session..."); + message_send_chat_encrypted(barejid, otr_query_message); + } + } + } + decrypted = otr_decrypt_message(barejid, message, &was_decrypted); + + // internal OTR message + if (decrypted == NULL) { + return; + } + + if (policy == PROF_OTRPOLICY_ALWAYS && !was_decrypted && !whitespace_base) { + char *otr_query_message = otr_start_query(); + cons_show("Attempting to start OTR session..."); + message_send_chat_encrypted(barejid, otr_query_message); + } + + ui_incoming_msg(barejid, resource, decrypted, NULL); + chat_log_otr_msg_in(barejid, decrypted, was_decrypted); + otr_free_message(decrypted); +} + void otr_keygen(ProfAccount *account) { diff --git a/src/otr/otr.h b/src/otr/otr.h index 91445a5c..8eb322ed 100644 --- a/src/otr/otr.h +++ b/src/otr/otr.h @@ -56,6 +56,7 @@ char* otr_libotr_version(void); char* otr_start_query(void); void otr_poll(void); void otr_on_connect(ProfAccount *account); +void otr_on_message_recv(const char * const barejid, const char * const resource, const char * const message); void otr_keygen(ProfAccount *account); char* otr_tag_message(const char * const msg); diff --git a/tests/otr/stub_otr.c b/tests/otr/stub_otr.c index 7a0122b6..8e0a5d75 100644 --- a/tests/otr/stub_otr.c +++ b/tests/otr/stub_otr.c @@ -41,6 +41,7 @@ char* otr_start_query(void) void otr_poll(void) {} void otr_on_connect(ProfAccount *account) {} +void otr_on_message_recv(const char * const barejid, const char * const resource, const char * const message) {} void otr_keygen(ProfAccount *account) { @@ -53,7 +54,7 @@ gboolean otr_key_loaded(void) } char* otr_tag_message(const char * const msg) -{ +{ return NULL; } From 70d1756a1cf380a75d4e4191670787e5dc6bf182 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 27 Apr 2015 23:30:33 +0100 Subject: [PATCH 174/252] Moved otr message send event to otr module --- src/event/client_events.c | 36 +++--------------------------------- src/otr/otr.c | 37 +++++++++++++++++++++++++++++++++++++ src/otr/otr.h | 3 +++ tests/otr/stub_otr.c | 1 + 4 files changed, 44 insertions(+), 33 deletions(-) diff --git a/src/event/client_events.c b/src/event/client_events.c index 2a1d349a..2aa66d08 100644 --- a/src/event/client_events.c +++ b/src/event/client_events.c @@ -62,44 +62,14 @@ client_connect_account(ProfAccount *account) void client_send_msg(const char * const barejid, const char * const msg) { - char *id = NULL; - #ifdef HAVE_LIBOTR - prof_otrpolicy_t policy = otr_get_policy(barejid); - - if (otr_is_secure(barejid)) { - char *encrypted = otr_encrypt_message(barejid, msg); - if (encrypted != NULL) { - id = message_send_chat_encrypted(barejid, encrypted); - chat_log_otr_msg_out(barejid, msg); - ui_outgoing_chat_msg(barejid, msg, id); - otr_free_message(encrypted); - } else { - cons_show_error("Failed to encrypt and send message."); - } - - } else if (policy == PROF_OTRPOLICY_ALWAYS) { - cons_show_error("Failed to send message. Please check OTR policy"); - - } else if (policy == PROF_OTRPOLICY_OPPORTUNISTIC) { - char *otr_tagged_msg = otr_tag_message(msg); - id = message_send_chat_encrypted(barejid, otr_tagged_msg); - ui_outgoing_chat_msg(barejid, msg, id); - chat_log_msg_out(barejid, msg); - free(otr_tagged_msg); - - } else { - id = message_send_chat(barejid, msg); - ui_outgoing_chat_msg(barejid, msg, id); - chat_log_msg_out(barejid, msg); - } + otr_on_message_send(barejid, msg); #else - id = message_send_chat(barejid, msg); + char *id = message_send_chat(barejid, msg); chat_log_msg_out(barejid, msg); ui_outgoing_chat_msg(barejid, msg, id); -#endif - free(id); +#endif } void diff --git a/src/otr/otr.c b/src/otr/otr.c index 70bf9761..c8518c70 100644 --- a/src/otr/otr.c +++ b/src/otr/otr.c @@ -313,6 +313,43 @@ otr_on_message_recv(const char * const barejid, const char * const resource, con otr_free_message(decrypted); } +void +otr_on_message_send(const char * const barejid, const char * const message) +{ + char *id = NULL; + + prof_otrpolicy_t policy = otr_get_policy(barejid); + + if (otr_is_secure(barejid)) { + char *encrypted = otr_encrypt_message(barejid, message); + if (encrypted != NULL) { + id = message_send_chat_encrypted(barejid, encrypted); + chat_log_otr_msg_out(barejid, message); + ui_outgoing_chat_msg(barejid, message, id); + otr_free_message(encrypted); + } else { + cons_show_error("Failed to encrypt and send message."); + } + + } else if (policy == PROF_OTRPOLICY_ALWAYS) { + cons_show_error("Failed to send message. Please check OTR policy"); + + } else if (policy == PROF_OTRPOLICY_OPPORTUNISTIC) { + char *otr_tagged_msg = otr_tag_message(message); + id = message_send_chat_encrypted(barejid, otr_tagged_msg); + ui_outgoing_chat_msg(barejid, message, id); + chat_log_msg_out(barejid, message); + free(otr_tagged_msg); + + } else { + id = message_send_chat(barejid, message); + ui_outgoing_chat_msg(barejid, message, id); + chat_log_msg_out(barejid, message); + } + + free(id); +} + void otr_keygen(ProfAccount *account) { diff --git a/src/otr/otr.h b/src/otr/otr.h index 8eb322ed..8e1d22df 100644 --- a/src/otr/otr.h +++ b/src/otr/otr.h @@ -56,7 +56,10 @@ char* otr_libotr_version(void); char* otr_start_query(void); void otr_poll(void); void otr_on_connect(ProfAccount *account); + void otr_on_message_recv(const char * const barejid, const char * const resource, const char * const message); +void otr_on_message_send(const char * const barejid, const char * const message); + void otr_keygen(ProfAccount *account); char* otr_tag_message(const char * const msg); diff --git a/tests/otr/stub_otr.c b/tests/otr/stub_otr.c index 8e0a5d75..eb676877 100644 --- a/tests/otr/stub_otr.c +++ b/tests/otr/stub_otr.c @@ -42,6 +42,7 @@ char* otr_start_query(void) void otr_poll(void) {} void otr_on_connect(ProfAccount *account) {} void otr_on_message_recv(const char * const barejid, const char * const resource, const char * const message) {} +void otr_on_message_send(const char * const barejid, const char * const message) {} void otr_keygen(ProfAccount *account) { From 403e9b47fe985cb7b1e1644bf8d3bfb0cc4eb829 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 28 Apr 2015 23:00:06 +0100 Subject: [PATCH 175/252] Removed commented code --- src/ui/core.c | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/src/ui/core.c b/src/ui/core.c index 78faff18..698b4e98 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -3002,32 +3002,6 @@ ui_hide_roster(void) } } -//static void -//_win_handle_switch(const wint_t ch) -//{ -// if (ch == KEY_F(1)) { -// ui_switch_win(1); -// } else if (ch == KEY_F(2)) { -// ui_switch_win(2); -// } else if (ch == KEY_F(3)) { -// ui_switch_win(3); -// } else if (ch == KEY_F(4)) { -// ui_switch_win(4); -// } else if (ch == KEY_F(5)) { -// ui_switch_win(5); -// } else if (ch == KEY_F(6)) { -// ui_switch_win(6); -// } else if (ch == KEY_F(7)) { -// ui_switch_win(7); -// } else if (ch == KEY_F(8)) { -// ui_switch_win(8); -// } else if (ch == KEY_F(9)) { -// ui_switch_win(9); -// } else if (ch == KEY_F(10)) { -// ui_switch_win(0); -// } -//} -// static void _win_show_history(int win_index, const char * const contact) { From 8aba52f4fe20a126c59322fe8e6ab7479ab83633 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 28 Apr 2015 23:38:56 +0100 Subject: [PATCH 176/252] Renamed event functions --- src/command/commands.c | 32 ++++----- src/event/client_events.c | 14 ++-- src/event/client_events.h | 14 ++-- src/event/server_events.c | 130 ++++++++++++++++++------------------- src/event/server_events.h | 130 ++++++++++++++++++------------------- src/xmpp/connection.c | 10 +-- src/xmpp/iq.c | 56 ++++++++-------- src/xmpp/message.c | 42 ++++++------ src/xmpp/presence.c | 34 +++++----- src/xmpp/roster.c | 12 ++-- tests/test_server_events.c | 28 ++++---- 11 files changed, 251 insertions(+), 251 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index 2d9e1dfc..9eaa6e9b 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -109,19 +109,19 @@ cmd_execute_default(const char * inp) case WIN_CHAT: { ProfChatWin *chatwin = wins_get_current_chat(); - client_send_msg(chatwin->barejid, inp); + cl_ev_send_msg(chatwin->barejid, inp); break; } case WIN_PRIVATE: { ProfPrivateWin *privatewin = wins_get_current_private(); - client_send_priv_msg(privatewin->fulljid, inp); + cl_ev_send_priv_msg(privatewin->fulljid, inp); break; } case WIN_MUC: { ProfMucWin *mucwin = wins_get_current_muc(); - client_send_muc_msg(mucwin->roomjid, inp); + cl_ev_send_muc_msg(mucwin->roomjid, inp); break; } default: @@ -208,13 +208,13 @@ cmd_connect(gchar **args, struct cmd_help_t help) if (account) { // use password if set if (account->password) { - conn_status = client_connect_account(account); + conn_status = cl_ev_connect_account(account); // use eval_password if set } else if (account->eval_password) { gboolean res = account_eval_password(account); if (res) { - conn_status = client_connect_account(account); + conn_status = cl_ev_connect_account(account); free(account->password); account->password = NULL; } else { @@ -226,7 +226,7 @@ cmd_connect(gchar **args, struct cmd_help_t help) // no account password setting, prompt } else { account->password = ui_ask_password(); - conn_status = client_connect_account(account); + conn_status = cl_ev_connect_account(account); free(account->password); account->password = NULL; } @@ -237,7 +237,7 @@ cmd_connect(gchar **args, struct cmd_help_t help) } else { jid = strdup(lower); char *passwd = ui_ask_password(); - conn_status = client_connect_jid(jid, passwd, altdomain, port); + conn_status = cl_ev_connect_jid(jid, passwd, altdomain, port); free(passwd); } @@ -1306,7 +1306,7 @@ cmd_msg(gchar **args, struct cmd_help_t help) g_string_append(full_jid, usr); if (msg) { - client_send_priv_msg(full_jid->str, msg); + cl_ev_send_priv_msg(full_jid->str, msg); } else { ui_new_private_win(full_jid->str); } @@ -1327,14 +1327,14 @@ cmd_msg(gchar **args, struct cmd_help_t help) } if (msg) { - client_send_msg(barejid, msg); + cl_ev_send_msg(barejid, msg); return TRUE; } else { ProfWin *window = (ProfWin*)wins_get_chat(barejid); if (window) { - client_focus_win(window); + ui_ev_focus_win(window); } else { - client_new_chat_win(barejid); + ui_ev_new_chat_win(barejid); } #ifdef HAVE_LIBOTR @@ -3141,19 +3141,19 @@ cmd_tiny(gchar **args, struct cmd_help_t help) case WIN_CHAT: { ProfChatWin *chatwin = wins_get_current_chat(); - client_send_msg(chatwin->barejid, tiny); + cl_ev_send_msg(chatwin->barejid, tiny); break; } case WIN_PRIVATE: { ProfPrivateWin *privatewin = wins_get_current_private(); - client_send_priv_msg(privatewin->fulljid, tiny); + cl_ev_send_priv_msg(privatewin->fulljid, tiny); break; } case WIN_MUC: { ProfMucWin *mucwin = wins_get_current_muc(); - client_send_muc_msg(mucwin->roomjid, tiny); + cl_ev_send_muc_msg(mucwin->roomjid, tiny); break; } default: @@ -4171,9 +4171,9 @@ cmd_otr(gchar **args, struct cmd_help_t help) ProfWin *window = (ProfWin*)wins_get_chat(barejid); if (window) { - client_focus_win(window); + ui_ev_focus_win(window); } else { - client_new_chat_win(barejid); + ui_ev_new_chat_win(barejid); } if (ui_current_win_is_otr()) { diff --git a/src/event/client_events.c b/src/event/client_events.c index 2aa66d08..6ee3c832 100644 --- a/src/event/client_events.c +++ b/src/event/client_events.c @@ -43,14 +43,14 @@ #endif jabber_conn_status_t -client_connect_jid(const char * const jid, const char * const passwd, const char * const altdomain, const int port) +cl_ev_connect_jid(const char * const jid, const char * const passwd, const char * const altdomain, const int port) { cons_show("Connecting as %s", jid); return jabber_connect_with_details(jid, passwd, altdomain, port); } jabber_conn_status_t -client_connect_account(ProfAccount *account) +cl_ev_connect_account(ProfAccount *account) { char *jid = account_create_full_jid(account); cons_show("Connecting with account %s as %s", account->name, jid); @@ -60,7 +60,7 @@ client_connect_account(ProfAccount *account) } void -client_send_msg(const char * const barejid, const char * const msg) +cl_ev_send_msg(const char * const barejid, const char * const msg) { #ifdef HAVE_LIBOTR otr_on_message_send(barejid, msg); @@ -73,26 +73,26 @@ client_send_msg(const char * const barejid, const char * const msg) } void -client_send_muc_msg(const char * const roomjid, const char * const msg) +cl_ev_send_muc_msg(const char * const roomjid, const char * const msg) { message_send_groupchat(roomjid, msg); } void -client_send_priv_msg(const char * const fulljid, const char * const msg) +cl_ev_send_priv_msg(const char * const fulljid, const char * const msg) { message_send_private(fulljid, msg); ui_outgoing_private_msg(fulljid, msg); } void -client_focus_win(ProfWin *win) +ui_ev_focus_win(ProfWin *win) { ui_switch_win(win); } void -client_new_chat_win(const char * const barejid) +ui_ev_new_chat_win(const char * const barejid) { ProfWin *win = ui_new_chat_win(barejid); ui_switch_win(win); diff --git a/src/event/client_events.h b/src/event/client_events.h index efa535c9..55f2b477 100644 --- a/src/event/client_events.h +++ b/src/event/client_events.h @@ -35,14 +35,14 @@ #ifndef CLIENT_EVENTS_H #define CLIENT_EVENTS_H -jabber_conn_status_t client_connect_jid(const char * const jid, const char * const passwd, const char * const altdomain, const int port); -jabber_conn_status_t client_connect_account(ProfAccount *account); +jabber_conn_status_t cl_ev_connect_jid(const char * const jid, const char * const passwd, const char * const altdomain, const int port); +jabber_conn_status_t cl_ev_connect_account(ProfAccount *account); -void client_send_msg(const char * const barejid, const char * const msg); -void client_send_muc_msg(const char * const roomjid, const char * const msg); -void client_send_priv_msg(const char * const fulljid, const char * const msg); +void cl_ev_send_msg(const char * const barejid, const char * const msg); +void cl_ev_send_muc_msg(const char * const roomjid, const char * const msg); +void cl_ev_send_priv_msg(const char * const fulljid, const char * const msg); -void client_focus_win(ProfWin *win); -void client_new_chat_win(const char * const barejid); +void ui_ev_focus_win(ProfWin *win); +void ui_ev_new_chat_win(const char * const barejid); #endif \ No newline at end of file diff --git a/src/event/server_events.c b/src/event/server_events.c index 514835ba..56d5b11f 100644 --- a/src/event/server_events.c +++ b/src/event/server_events.c @@ -51,7 +51,7 @@ #include "ui/ui.h" void -srv_room_join_error(const char * const room, const char * const err) +sv_ev_room_join_error(const char * const room, const char * const err) { if (muc_active(room)) { muc_leave(room); @@ -61,7 +61,7 @@ srv_room_join_error(const char * const room, const char * const err) // handle presence stanza errors void -srv_presence_error(const char *from, const char * const type, +sv_ev_presence_error(const char *from, const char * const type, const char *err_msg) { // handle error from recipient @@ -76,7 +76,7 @@ srv_presence_error(const char *from, const char * const type, // handle message stanza errors void -srv_message_error(const char * const jid, const char * const type, +sv_ev_message_error(const char * const jid, const char * const type, const char * const err_msg) { // handle errors from no recipient @@ -96,7 +96,7 @@ srv_message_error(const char * const jid, const char * const type, } void -srv_login_account_success(char *account_name) +sv_ev_login_account_success(char *account_name) { ProfAccount *account = accounts_get_account(account_name); @@ -123,7 +123,7 @@ srv_login_account_success(char *account_name) } void -srv_roster_received(void) +sv_ev_roster_received(void) { if (prefs_get_boolean(PREF_ROSTER)) { ui_show_roster(); @@ -131,7 +131,7 @@ srv_roster_received(void) } void -srv_lost_connection(void) +sv_ev_lost_connection(void) { cons_show_error("Lost connection."); roster_clear(); @@ -141,27 +141,27 @@ srv_lost_connection(void) } void -srv_failed_login(void) +sv_ev_failed_login(void) { cons_show_error("Login failed."); log_info("Login failed"); } void -srv_software_version_result(const char * const jid, const char * const presence, +sv_ev_software_version_result(const char * const jid, const char * const presence, const char * const name, const char * const version, const char * const os) { cons_show_software_version(jid, presence, name, version, os); } void -srv_disco_info(const char *from, GSList *identities, GSList *features) +sv_ev_disco_info(const char *from, GSList *identities, GSList *features) { cons_show_disco_info(from, identities, features); } void -srv_room_disco_info(const char * const room, GSList *identities, GSList *features, gboolean display) +sv_ev_room_disco_info(const char * const room, GSList *identities, GSList *features, gboolean display) { muc_set_features(room, features); if (display) { @@ -170,7 +170,7 @@ srv_room_disco_info(const char * const room, GSList *identities, GSList *feature } void -srv_disco_info_error(const char * const from, const char * const error) +sv_ev_disco_info_error(const char * const from, const char * const error) { if (from) { cons_show_error("Service discovery failed for %s: %s", from, error); @@ -180,31 +180,31 @@ srv_disco_info_error(const char * const from, const char * const error) } void -srv_enable_carbons_error(const char * const error) +sv_ev_enable_carbons_error(const char * const error) { cons_show_error("Server error enabling message carbons: %s", error); } void -srv_disable_carbons_error(const char * const error) +sv_ev_disable_carbons_error(const char * const error) { cons_show_error("Server error disabling message carbons: %s", error); } void -srv_room_info_error(const char * const room, const char * const error) +sv_ev_room_info_error(const char * const room, const char * const error) { ui_handle_room_info_error(room, error); } void -srv_room_list(GSList *rooms, const char *conference_node) +sv_ev_room_list(GSList *rooms, const char *conference_node) { cons_show_room_list(rooms, conference_node); } void -srv_room_affiliation_list_result_error(const char * const room, const char * const affiliation, +sv_ev_room_affiliation_list_result_error(const char * const room, const char * const affiliation, const char * const error) { log_debug("Error retrieving %s list for room %s: %s", affiliation, room, error); @@ -212,14 +212,14 @@ srv_room_affiliation_list_result_error(const char * const room, const char * con } void -srv_room_affiliation_list(const char * const room, const char * const affiliation, GSList *jids) +sv_ev_room_affiliation_list(const char * const room, const char * const affiliation, GSList *jids) { muc_jid_autocomplete_add_all(room, jids); ui_handle_room_affiliation_list(room, affiliation, jids); } void -srv_room_role_set_error(const char * const room, const char * const nick, const char * const role, +sv_ev_room_role_set_error(const char * const room, const char * const nick, const char * const role, const char * const error) { log_debug("Error setting role %s list for room %s, user %s: %s", role, room, nick, error); @@ -227,20 +227,20 @@ srv_room_role_set_error(const char * const room, const char * const nick, const } void -srv_room_role_list_result_error(const char * const room, const char * const role, const char * const error) +sv_ev_room_role_list_result_error(const char * const room, const char * const role, const char * const error) { log_debug("Error retrieving %s list for room %s: %s", role, room, error); ui_handle_room_role_list_error(room, role, error); } void -srv_room_role_list(const char * const room, const char * const role, GSList *nicks) +sv_ev_room_role_list(const char * const room, const char * const role, GSList *nicks) { ui_handle_room_role_list(room, role, nicks); } void -srv_room_affiliation_set_error(const char * const room, const char * const jid, const char * const affiliation, +sv_ev_room_affiliation_set_error(const char * const room, const char * const jid, const char * const affiliation, const char * const error) { log_debug("Error setting affiliation %s list for room %s, user %s: %s", affiliation, room, jid, error); @@ -248,13 +248,13 @@ srv_room_affiliation_set_error(const char * const room, const char * const jid, } void -srv_disco_items(GSList *items, const char *jid) +sv_ev_disco_items(GSList *items, const char *jid) { cons_show_disco_items(items, jid); } void -srv_room_invite(jabber_invite_t invite_type, +sv_ev_room_invite(jabber_invite_t invite_type, const char * const invitor, const char * const room, const char * const reason, const char * const password) { @@ -265,7 +265,7 @@ srv_room_invite(jabber_invite_t invite_type, } void -srv_room_broadcast(const char *const room_jid, +sv_ev_room_broadcast(const char *const room_jid, const char * const message) { if (muc_roster_complete(room_jid)) { @@ -276,7 +276,7 @@ srv_room_broadcast(const char *const room_jid, } void -srv_room_subject(const char * const room, const char * const nick, const char * const subject) +sv_ev_room_subject(const char * const room, const char * const nick, const char * const subject) { muc_set_subject(room, subject); if (muc_roster_complete(room)) { @@ -285,14 +285,14 @@ srv_room_subject(const char * const room, const char * const nick, const char * } void -srv_room_history(const char * const room_jid, const char * const nick, +sv_ev_room_history(const char * const room_jid, const char * const nick, GTimeVal tv_stamp, const char * const message) { ui_room_history(room_jid, nick, tv_stamp, message); } void -srv_room_message(const char * const room_jid, const char * const nick, +sv_ev_room_message(const char * const room_jid, const char * const nick, const char * const message) { ui_room_message(room_jid, nick, message); @@ -305,19 +305,19 @@ srv_room_message(const char * const room_jid, const char * const nick, } void -srv_incoming_private_message(char *fulljid, char *message) +sv_ev_incoming_private_message(char *fulljid, char *message) { ui_incoming_private_msg(fulljid, message, NULL); } void -srv_carbon(char *barejid, char *message) +sv_ev_carbon(char *barejid, char *message) { ui_outgoing_chat_msg_carbon(barejid, message); } void -srv_incoming_message(char *barejid, char *resource, char *message) +sv_ev_incoming_message(char *barejid, char *resource, char *message) { #ifdef HAVE_LIBOTR otr_on_message_recv(barejid, resource, message); @@ -328,26 +328,26 @@ srv_incoming_message(char *barejid, char *resource, char *message) } void -srv_delayed_private_message(char *fulljid, char *message, GTimeVal tv_stamp) +sv_ev_delayed_private_message(char *fulljid, char *message, GTimeVal tv_stamp) { ui_incoming_private_msg(fulljid, message, &tv_stamp); } void -srv_delayed_message(char *barejid, char *message, GTimeVal tv_stamp) +sv_ev_delayed_message(char *barejid, char *message, GTimeVal tv_stamp) { ui_incoming_msg(barejid, NULL, message, &tv_stamp); chat_log_msg_in_delayed(barejid, message, &tv_stamp); } void -srv_message_receipt(char *barejid, char *id) +sv_ev_message_receipt(char *barejid, char *id) { ui_message_receipt(barejid, id); } void -srv_typing(char *barejid, char *resource) +sv_ev_typing(char *barejid, char *resource) { ui_contact_typing(barejid, resource); if (ui_chat_win_exists(barejid)) { @@ -356,7 +356,7 @@ srv_typing(char *barejid, char *resource) } void -srv_paused(char *barejid, char *resource) +sv_ev_paused(char *barejid, char *resource) { if (ui_chat_win_exists(barejid)) { chat_session_recipient_paused(barejid, resource); @@ -364,7 +364,7 @@ srv_paused(char *barejid, char *resource) } void -srv_inactive(char *barejid, char *resource) +sv_ev_inactive(char *barejid, char *resource) { if (ui_chat_win_exists(barejid)) { chat_session_recipient_inactive(barejid, resource); @@ -372,7 +372,7 @@ srv_inactive(char *barejid, char *resource) } void -srv_gone(const char * const barejid, const char * const resource) +sv_ev_gone(const char * const barejid, const char * const resource) { ui_recipient_gone(barejid, resource); if (ui_chat_win_exists(barejid)) { @@ -381,7 +381,7 @@ srv_gone(const char * const barejid, const char * const resource) } void -srv_activity(const char * const barejid, const char * const resource, gboolean send_states) +sv_ev_activity(const char * const barejid, const char * const resource, gboolean send_states) { if (ui_chat_win_exists(barejid)) { chat_session_recipient_active(barejid, resource, send_states); @@ -389,7 +389,7 @@ srv_activity(const char * const barejid, const char * const resource, gboolean s } void -srv_subscription(const char *barejid, jabber_subscr_t type) +sv_ev_subscription(const char *barejid, jabber_subscr_t type) { switch (type) { case PRESENCE_SUBSCRIBE: @@ -418,7 +418,7 @@ srv_subscription(const char *barejid, jabber_subscr_t type) } void -srv_contact_offline(char *barejid, char *resource, char *status) +sv_ev_contact_offline(char *barejid, char *resource, char *status) { gboolean updated = roster_contact_offline(barejid, resource, status); @@ -431,7 +431,7 @@ srv_contact_offline(char *barejid, char *resource, char *status) } void -srv_contact_online(char *barejid, Resource *resource, +sv_ev_contact_online(char *barejid, Resource *resource, GDateTime *last_activity) { gboolean updated = roster_update_presence(barejid, resource, last_activity); @@ -474,21 +474,21 @@ srv_contact_online(char *barejid, Resource *resource, } void -srv_leave_room(const char * const room) +sv_ev_leave_room(const char * const room) { muc_leave(room); ui_leave_room(room); } void -srv_room_destroy(const char * const room) +sv_ev_room_destroy(const char * const room) { muc_leave(room); ui_room_destroy(room); } void -srv_room_destroyed(const char * const room, const char * const new_jid, const char * const password, +sv_ev_room_destroyed(const char * const room, const char * const new_jid, const char * const password, const char * const reason) { muc_leave(room); @@ -496,51 +496,51 @@ srv_room_destroyed(const char * const room, const char * const new_jid, const ch } void -srv_room_kicked(const char * const room, const char * const actor, const char * const reason) +sv_ev_room_kicked(const char * const room, const char * const actor, const char * const reason) { muc_leave(room); ui_room_kicked(room, actor, reason); } void -srv_room_banned(const char * const room, const char * const actor, const char * const reason) +sv_ev_room_banned(const char * const room, const char * const actor, const char * const reason) { muc_leave(room); ui_room_banned(room, actor, reason); } void -srv_room_configure(const char * const room, DataForm *form) +sv_ev_room_configure(const char * const room, DataForm *form) { ui_handle_room_configuration(room, form); } void -srv_room_configuration_form_error(const char * const room, const char * const message) +sv_ev_room_configuration_form_error(const char * const room, const char * const message) { ui_handle_room_configuration_form_error(room, message); } void -srv_room_config_submit_result(const char * const room) +sv_ev_room_config_submit_result(const char * const room) { ui_handle_room_config_submit_result(room); } void -srv_room_config_submit_result_error(const char * const room, const char * const message) +sv_ev_room_config_submit_result_error(const char * const room, const char * const message) { ui_handle_room_config_submit_result_error(room, message); } void -srv_room_kick_result_error(const char * const room, const char * const nick, const char * const error) +sv_ev_room_kick_result_error(const char * const room, const char * const nick, const char * const error) { ui_handle_room_kick_error(room, nick, error); } void -srv_room_occupant_offline(const char * const room, const char * const nick, +sv_ev_room_occupant_offline(const char * const room, const char * const nick, const char * const show, const char * const status) { muc_roster_remove(room, nick); @@ -554,7 +554,7 @@ srv_room_occupant_offline(const char * const room, const char * const nick, } void -srv_room_occupent_kicked(const char * const room, const char * const nick, const char * const actor, +sv_ev_room_occupent_kicked(const char * const room, const char * const nick, const char * const actor, const char * const reason) { muc_roster_remove(room, nick); @@ -563,7 +563,7 @@ srv_room_occupent_kicked(const char * const room, const char * const nick, const } void -srv_room_occupent_banned(const char * const room, const char * const nick, const char * const actor, +sv_ev_room_occupent_banned(const char * const room, const char * const nick, const char * const actor, const char * const reason) { muc_roster_remove(room, nick); @@ -572,33 +572,33 @@ srv_room_occupent_banned(const char * const room, const char * const nick, const } void -srv_group_add(const char * const contact, +sv_ev_group_add(const char * const contact, const char * const group) { ui_group_added(contact, group); } void -srv_group_remove(const char * const contact, +sv_ev_group_remove(const char * const contact, const char * const group) { ui_group_removed(contact, group); } void -srv_roster_remove(const char * const barejid) +sv_ev_roster_remove(const char * const barejid) { ui_roster_remove(barejid); } void -srv_roster_add(const char * const barejid, const char * const name) +sv_ev_roster_add(const char * const barejid, const char * const name) { ui_roster_add(barejid, name); } void -srv_roster_update(const char * const barejid, const char * const name, +sv_ev_roster_update(const char * const barejid, const char * const name, GSList *groups, const char * const subscription, gboolean pending_out) { roster_update(barejid, name, groups, subscription, pending_out); @@ -606,20 +606,20 @@ srv_roster_update(const char * const barejid, const char * const name, } void -srv_autoping_cancel(void) +sv_ev_autoping_cancel(void) { prefs_set_autoping(0); cons_show_error("Server ping not supported, autoping disabled."); } void -srv_xmpp_stanza(const char * const msg) +sv_ev_xmpp_stanza(const char * const msg) { ui_handle_stanza(msg); } void -srv_ping_result(const char * const from, int millis) +sv_ev_ping_result(const char * const from, int millis) { if (from == NULL) { cons_show("Ping response from server: %dms.", millis); @@ -629,7 +629,7 @@ srv_ping_result(const char * const from, int millis) } void -srv_ping_error_result(const char * const from, const char * const error) +sv_ev_ping_error_result(const char * const from, const char * const error) { if (error == NULL) { cons_show_error("Error returned from pinging %s.", from); @@ -639,7 +639,7 @@ srv_ping_error_result(const char * const from, const char * const error) } void -srv_muc_self_online(const char * const room, const char * const nick, gboolean config_required, +sv_ev_muc_self_online(const char * const room, const char * const nick, gboolean config_required, const char * const role, const char * const affiliation, const char * const actor, const char * const reason, const char * const jid, const char * const show, const char * const status) { @@ -716,7 +716,7 @@ srv_muc_self_online(const char * const room, const char * const nick, gboolean c } void -srv_muc_occupant_online(const char * const room, const char * const nick, const char * const jid, +sv_ev_muc_occupant_online(const char * const room, const char * const nick, const char * const jid, const char * const role, const char * const affiliation, const char * const actor, const char * const reason, const char * const show, const char * const status) { diff --git a/src/event/server_events.h b/src/event/server_events.h index acba1391..daf885b3 100644 --- a/src/event/server_events.h +++ b/src/event/server_events.h @@ -37,93 +37,93 @@ #include "xmpp/xmpp.h" -void srv_login_account_success(char *account_name); -void srv_lost_connection(void); -void srv_failed_login(void); -void srv_software_version_result(const char * const jid, const char * const presence, +void sv_ev_login_account_success(char *account_name); +void sv_ev_lost_connection(void); +void sv_ev_failed_login(void); +void sv_ev_software_version_result(const char * const jid, const char * const presence, const char * const name, const char * const version, const char * const os); -void srv_disco_info(const char *from, GSList *identities, GSList *features); -void srv_disco_info_error(const char * const from, const char * const error); -void srv_room_list(GSList *rooms, const char *conference_node); -void srv_disco_items(GSList *items, const char *jid); -void srv_room_invite(jabber_invite_t invite_type, +void sv_ev_disco_info(const char *from, GSList *identities, GSList *features); +void sv_ev_disco_info_error(const char * const from, const char * const error); +void sv_ev_room_list(GSList *rooms, const char *conference_node); +void sv_ev_disco_items(GSList *items, const char *jid); +void sv_ev_room_invite(jabber_invite_t invite_type, const char * const invitor, const char * const room, const char * const reason, const char * const password); -void srv_room_broadcast(const char *const room_jid, +void sv_ev_room_broadcast(const char *const room_jid, const char * const message); -void srv_room_subject(const char * const room, const char * const nick, const char * const subject); -void srv_room_history(const char * const room_jid, const char * const nick, +void sv_ev_room_subject(const char * const room, const char * const nick, const char * const subject); +void sv_ev_room_history(const char * const room_jid, const char * const nick, GTimeVal tv_stamp, const char * const message); -void srv_room_message(const char * const room_jid, const char * const nick, +void sv_ev_room_message(const char * const room_jid, const char * const nick, const char * const message); -void srv_room_join_error(const char * const room, const char * const err); -void srv_room_info_error(const char * const room, const char * const error); -void srv_room_disco_info(const char * const room, GSList *identities, GSList *features, gboolean display); -void srv_room_affiliation_list_result_error(const char * const room, const char * const affiliation, +void sv_ev_room_join_error(const char * const room, const char * const err); +void sv_ev_room_info_error(const char * const room, const char * const error); +void sv_ev_room_disco_info(const char * const room, GSList *identities, GSList *features, gboolean display); +void sv_ev_room_affiliation_list_result_error(const char * const room, const char * const affiliation, const char * const error); -void srv_room_affiliation_list(const char * const room, const char * const affiliation, GSList *jids); -void srv_room_affiliation_set_error(const char * const room, const char * const jid, const char * const affiliation, +void sv_ev_room_affiliation_list(const char * const room, const char * const affiliation, GSList *jids); +void sv_ev_room_affiliation_set_error(const char * const room, const char * const jid, const char * const affiliation, const char * const error); -void srv_room_role_list_result_error(const char * const from, const char * const role, const char * const error); -void srv_room_role_list(const char * const from, const char * const role, GSList *nicks); -void srv_room_role_set_error(const char * const room, const char * const nick, const char * const role, +void sv_ev_room_role_list_result_error(const char * const from, const char * const role, const char * const error); +void sv_ev_room_role_list(const char * const from, const char * const role, GSList *nicks); +void sv_ev_room_role_set_error(const char * const room, const char * const nick, const char * const role, const char * const error); -void srv_room_kick_result_error(const char * const room, const char * const nick, const char * const error); -void srv_incoming_message(char *barejid, char *resource, char *message); -void srv_incoming_private_message(char *fulljid, char *message); -void srv_delayed_message(char *fulljid, char *message, GTimeVal tv_stamp); -void srv_delayed_private_message(char *fulljid, char *message, GTimeVal tv_stamp); -void srv_typing(char *barejid, char *resource); -void srv_paused(char *barejid, char *resource); -void srv_inactive(char *barejid, char *resource); -void srv_activity(char *barejid, char *resource, gboolean send_states); -void srv_gone(const char * const barejid, const char * const resource); -void srv_subscription(const char *from, jabber_subscr_t type); -void srv_message_receipt(char *barejid, char *id); -void srv_contact_offline(char *contact, char *resource, char *status); -void srv_contact_online(char *contact, Resource *resource, +void sv_ev_room_kick_result_error(const char * const room, const char * const nick, const char * const error); +void sv_ev_incoming_message(char *barejid, char *resource, char *message); +void sv_ev_incoming_private_message(char *fulljid, char *message); +void sv_ev_delayed_message(char *fulljid, char *message, GTimeVal tv_stamp); +void sv_ev_delayed_private_message(char *fulljid, char *message, GTimeVal tv_stamp); +void sv_ev_typing(char *barejid, char *resource); +void sv_ev_paused(char *barejid, char *resource); +void sv_ev_inactive(char *barejid, char *resource); +void sv_ev_activity(char *barejid, char *resource, gboolean send_states); +void sv_ev_gone(const char * const barejid, const char * const resource); +void sv_ev_subscription(const char *from, jabber_subscr_t type); +void sv_ev_message_receipt(char *barejid, char *id); +void sv_ev_contact_offline(char *contact, char *resource, char *status); +void sv_ev_contact_online(char *contact, Resource *resource, GDateTime *last_activity); -void srv_leave_room(const char * const room); -void srv_room_destroy(const char * const room); -void srv_room_occupant_offline(const char * const room, const char * const nick, +void sv_ev_leave_room(const char * const room); +void sv_ev_room_destroy(const char * const room); +void sv_ev_room_occupant_offline(const char * const room, const char * const nick, const char * const show, const char * const status); -void srv_room_destroyed(const char * const room, const char * const new_jid, const char * const password, +void sv_ev_room_destroyed(const char * const room, const char * const new_jid, const char * const password, const char * const reason); -void srv_room_kicked(const char * const room, const char * const actor, const char * const reason); -void srv_room_occupent_kicked(const char * const room, const char * const nick, const char * const actor, +void sv_ev_room_kicked(const char * const room, const char * const actor, const char * const reason); +void sv_ev_room_occupent_kicked(const char * const room, const char * const nick, const char * const actor, const char * const reason); -void srv_room_banned(const char * const room, const char * const actor, const char * const reason); -void srv_room_occupent_banned(const char * const room, const char * const nick, const char * const actor, +void sv_ev_room_banned(const char * const room, const char * const actor, const char * const reason); +void sv_ev_room_occupent_banned(const char * const room, const char * const nick, const char * const actor, const char * const reason); -void srv_group_add(const char * const contact, +void sv_ev_group_add(const char * const contact, const char * const group); -void srv_group_remove(const char * const contact, +void sv_ev_group_remove(const char * const contact, const char * const group); -void srv_roster_remove(const char * const barejid); -void srv_roster_add(const char * const barejid, const char * const name); -void srv_autoping_cancel(void); -void srv_carbon(char *barejid, char *message); -void srv_message_error(const char * const from, const char * const type, +void sv_ev_roster_remove(const char * const barejid); +void sv_ev_roster_add(const char * const barejid, const char * const name); +void sv_ev_autoping_cancel(void); +void sv_ev_carbon(char *barejid, char *message); +void sv_ev_message_error(const char * const from, const char * const type, const char * const err_msg); -void srv_presence_error(const char *from, const char * const type, +void sv_ev_presence_error(const char *from, const char * const type, const char *err_msg); -void srv_xmpp_stanza(const char * const msg); -void srv_ping_result(const char * const from, int millis); -void srv_ping_error_result(const char * const from, const char * const error); -void srv_room_configure(const char * const room, DataForm *form); -void srv_room_configuration_form_error(const char * const from, const char * const message); -void srv_room_config_submit_result(const char * const room); -void srv_room_config_submit_result_error(const char * const room, const char * const message); -void srv_muc_self_online(const char * const room, const char * const nick, gboolean config_required, +void sv_ev_xmpp_stanza(const char * const msg); +void sv_ev_ping_result(const char * const from, int millis); +void sv_ev_ping_error_result(const char * const from, const char * const error); +void sv_ev_room_configure(const char * const room, DataForm *form); +void sv_ev_room_configuration_form_error(const char * const from, const char * const message); +void sv_ev_room_config_submit_result(const char * const room); +void sv_ev_room_config_submit_result_error(const char * const room, const char * const message); +void sv_ev_muc_self_online(const char * const room, const char * const nick, gboolean config_required, const char * const role, const char * const affiliation, const char * const actor, const char * const reason, const char * const jid, const char * const show, const char * const status); -void srv_muc_occupant_online(const char * const room, const char * const nick, const char * const jid, +void sv_ev_muc_occupant_online(const char * const room, const char * const nick, const char * const jid, const char * const role, const char * const affiliation, const char * const actor, const char * const reason, const char * const show_str, const char * const status_str); -void srv_roster_update(const char * const barejid, const char * const name, +void sv_ev_roster_update(const char * const barejid, const char * const name, GSList *groups, const char * const subscription, gboolean pending_out); -void srv_roster_received(void); -void srv_enable_carbons_error(const char * const error); -void srv_disable_carbons_error(const char * const error); +void sv_ev_roster_received(void); +void sv_ev_enable_carbons_error(const char * const error); +void sv_ev_disable_carbons_error(const char * const error); #endif diff --git a/src/xmpp/connection.c b/src/xmpp/connection.c index 295c8f2f..f2596f14 100644 --- a/src/xmpp/connection.c +++ b/src/xmpp/connection.c @@ -438,7 +438,7 @@ _connection_handler(xmpp_conn_t * const conn, // logged in with account if (saved_account.name != NULL) { log_debug("Connection handler: logged in with account name: %s", saved_account.name); - srv_login_account_success(saved_account.name); + sv_ev_login_account_success(saved_account.name); // logged in without account, use details to create new account } else { @@ -446,7 +446,7 @@ _connection_handler(xmpp_conn_t * const conn, accounts_add(saved_details.name, saved_details.altdomain, saved_details.port); accounts_set_jid(saved_details.name, saved_details.jid); - srv_login_account_success(saved_details.name); + sv_ev_login_account_success(saved_details.name); saved_account.name = strdup(saved_details.name); saved_account.passwd = strdup(saved_details.passwd); @@ -486,7 +486,7 @@ _connection_handler(xmpp_conn_t * const conn, // lost connection for unknown reason if (jabber_conn.conn_status == JABBER_CONNECTED) { log_debug("Connection handler: Lost connection for unknown reason"); - srv_lost_connection(); + sv_ev_lost_connection(); if (prefs_get_reconnect() != 0) { assert(reconnect_timer == NULL); reconnect_timer = g_timer_new(); @@ -503,7 +503,7 @@ _connection_handler(xmpp_conn_t * const conn, log_debug("Connection handler: Login failed"); if (reconnect_timer == NULL) { log_debug("Connection handler: No reconnect timer"); - srv_failed_login(); + sv_ev_failed_login(); _connection_free_saved_account(); _connection_free_saved_details(); _connection_free_session_data(); @@ -563,7 +563,7 @@ _xmpp_file_logger(void * const userdata, const xmpp_log_level_t level, log_level_t prof_level = _get_log_level(level); log_msg(prof_level, area, msg); if ((g_strcmp0(area, "xmpp") == 0) || (g_strcmp0(area, "conn")) == 0) { - srv_xmpp_stanza(msg); + sv_ev_xmpp_stanza(msg); } } diff --git a/src/xmpp/iq.c b/src/xmpp/iq.c index 71876cdc..75286bf8 100644 --- a/src/xmpp/iq.c +++ b/src/xmpp/iq.c @@ -515,7 +515,7 @@ _pong_handler(xmpp_conn_t *const conn, xmpp_stanza_t * const stanza, if (errtype != NULL) { if (strcmp(errtype, "cancel") == 0) { log_warning("Server ping (id=%s) error type 'cancel', disabling autoping.", id); - srv_autoping_cancel(); + sv_ev_autoping_cancel(); xmpp_timed_handler_delete(conn, _ping_timed_handler); } } @@ -739,7 +739,7 @@ _enable_carbons_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, char *type = xmpp_stanza_get_type(stanza); if (g_strcmp0(type, "error") == 0) { char *error_message = stanza_get_error_message(stanza); - srv_enable_carbons_error(error_message); + sv_ev_enable_carbons_error(error_message); log_debug("Error enabling carbons: %s", error_message); } else { log_debug("Message carbons enabled."); @@ -754,7 +754,7 @@ _disable_carbons_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, char *type = xmpp_stanza_get_type(stanza); if (g_strcmp0(type, "error") == 0) { char *error_message = stanza_get_error_message(stanza); - srv_disable_carbons_error(error_message); + sv_ev_disable_carbons_error(error_message); log_debug("Error disabling carbons: %s", error_message); } else { log_debug("Message carbons disabled."); @@ -774,7 +774,7 @@ _manual_pong_handler(xmpp_conn_t *const conn, xmpp_stanza_t * const stanza, // handle error responses if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) { char *error_message = stanza_get_error_message(stanza); - srv_ping_error_result(from, error_message); + sv_ev_ping_error_result(from, error_message); free(error_message); g_date_time_unref(sent); return 0; @@ -788,7 +788,7 @@ _manual_pong_handler(xmpp_conn_t *const conn, xmpp_stanza_t * const stanza, g_date_time_unref(sent); g_date_time_unref(now); - srv_ping_result(from, elapsed_millis); + sv_ev_ping_result(from, elapsed_millis); return 0; } @@ -865,7 +865,7 @@ _version_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, presence = string_from_resource_presence(resource->presence); } - srv_software_version_result(jid, presence, name_str, version_str, os_str); + sv_ev_software_version_result(jid, presence, name_str, version_str, os_str); jid_destroy(jidp); @@ -1062,7 +1062,7 @@ _destroy_room_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const sta if (from == NULL) { log_error("No from attribute for IQ destroy room result"); } else { - srv_room_destroy(from); + sv_ev_room_destroy(from); } return 0; @@ -1085,40 +1085,40 @@ _room_config_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, // handle error responses if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) { char *error_message = stanza_get_error_message(stanza); - srv_room_configuration_form_error(from, error_message); + sv_ev_room_configuration_form_error(from, error_message); free(error_message); return 0; } if (from == NULL) { log_warning("No from attribute for IQ config request result"); - srv_room_configuration_form_error(from, "No from attribute for room cofig response."); + sv_ev_room_configuration_form_error(from, "No from attribute for room cofig response."); return 0; } xmpp_stanza_t *query = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_QUERY); if (query == NULL) { log_warning("No query element found parsing room config response"); - srv_room_configuration_form_error(from, "No query element found parsing room config response"); + sv_ev_room_configuration_form_error(from, "No query element found parsing room config response"); return 0; } xmpp_stanza_t *x = xmpp_stanza_get_child_by_ns(query, STANZA_NS_DATA); if (x == NULL) { log_warning("No x element found with %s namespace parsing room config response", STANZA_NS_DATA); - srv_room_configuration_form_error(from, "No form configuration options available"); + sv_ev_room_configuration_form_error(from, "No form configuration options available"); return 0; } char *form_type = xmpp_stanza_get_attribute(x, STANZA_ATTR_TYPE); if (g_strcmp0(form_type, "form") != 0) { log_warning("x element not of type 'form' parsing room config response"); - srv_room_configuration_form_error(from, "Form not of type 'form' parsing room config response."); + sv_ev_room_configuration_form_error(from, "Form not of type 'form' parsing room config response."); return 0; } DataForm *form = form_create(x); - srv_room_configure(from, form); + sv_ev_room_configure(from, form); return 0; } @@ -1140,7 +1140,7 @@ static int _room_affiliation_set_result_handler(xmpp_conn_t * const conn, xmpp_s // handle error responses if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) { char *error_message = stanza_get_error_message(stanza); - srv_room_affiliation_set_error(from, affiliation_set->item, affiliation_set->privilege, error_message); + sv_ev_room_affiliation_set_error(from, affiliation_set->item, affiliation_set->privilege, error_message); free(error_message); } @@ -1168,7 +1168,7 @@ static int _room_role_set_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t // handle error responses if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) { char *error_message = stanza_get_error_message(stanza); - srv_room_role_set_error(from, role_set->item, role_set->privilege, error_message); + sv_ev_room_role_set_error(from, role_set->item, role_set->privilege, error_message); free(error_message); } @@ -1196,7 +1196,7 @@ _room_affiliation_list_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * // handle error responses if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) { char *error_message = stanza_get_error_message(stanza); - srv_room_affiliation_list_result_error(from, affiliation, error_message); + sv_ev_room_affiliation_list_result_error(from, affiliation, error_message); free(error_message); free(affiliation); return 0; @@ -1218,7 +1218,7 @@ _room_affiliation_list_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * } } - srv_room_affiliation_list(from, affiliation, jids); + sv_ev_room_affiliation_list(from, affiliation, jids); free(affiliation); g_slist_free(jids); @@ -1242,7 +1242,7 @@ _room_role_list_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const s // handle error responses if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) { char *error_message = stanza_get_error_message(stanza); - srv_room_role_list_result_error(from, role, error_message); + sv_ev_room_role_list_result_error(from, role, error_message); free(error_message); free(role); return 0; @@ -1264,7 +1264,7 @@ _room_role_list_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const s } } - srv_room_role_list(from, role, nicks); + sv_ev_room_role_list(from, role, nicks); free(role); g_slist_free(nicks); @@ -1288,12 +1288,12 @@ _room_config_submit_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stan // handle error responses if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) { char *error_message = stanza_get_error_message(stanza); - srv_room_config_submit_result_error(from, error_message); + sv_ev_room_config_submit_result_error(from, error_message); free(error_message); return 0; } - srv_room_config_submit_result(from); + sv_ev_room_config_submit_result(from); return 0; } @@ -1315,7 +1315,7 @@ _room_kick_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza // handle error responses if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) { char *error_message = stanza_get_error_message(stanza); - srv_room_kick_result_error(from, nick, error_message); + sv_ev_room_kick_result_error(from, nick, error_message); free(error_message); free(nick); return 0; @@ -1359,7 +1359,7 @@ _room_info_response_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stan if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) { if (cb_data->display) { char *error_message = stanza_get_error_message(stanza); - srv_room_info_error(cb_data->room, error_message); + sv_ev_room_info_error(cb_data->room, error_message); free(error_message); } free(cb_data->room); @@ -1411,7 +1411,7 @@ _room_info_response_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stan child = xmpp_stanza_get_next(child); } - srv_room_disco_info(cb_data->room, identities, features, cb_data->display); + sv_ev_room_disco_info(cb_data->room, identities, features, cb_data->display); g_slist_free_full(features, free); g_slist_free_full(identities, (GDestroyNotify)_identity_destroy); @@ -1439,7 +1439,7 @@ _disco_info_response_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const sta // handle error responses if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) { char *error_message = stanza_get_error_message(stanza); - srv_disco_info_error(from, error_message); + sv_ev_disco_info_error(from, error_message); free(error_message); return 0; } @@ -1488,7 +1488,7 @@ _disco_info_response_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const sta child = xmpp_stanza_get_next(child); } - srv_disco_info(from, identities, features); + sv_ev_disco_info(from, identities, features); g_slist_free_full(features, free); g_slist_free_full(identities, (GDestroyNotify)_identity_destroy); @@ -1536,9 +1536,9 @@ _disco_items_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stan } if (g_strcmp0(id, "confreq") == 0) { - srv_room_list(items, from); + sv_ev_room_list(items, from); } else if (g_strcmp0(id, "discoitemsreq") == 0) { - srv_disco_items(items, from); + sv_ev_disco_items(items, from); } g_slist_free_full(items, (GDestroyNotify)_item_destroy); diff --git a/src/xmpp/message.c b/src/xmpp/message.c index 8febbe11..c9464e2f 100644 --- a/src/xmpp/message.c +++ b/src/xmpp/message.c @@ -299,7 +299,7 @@ _message_error_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, g_string_free(log_msg, TRUE); - srv_message_error(jid, type, err_msg); + sv_ev_message_error(jid, type, err_msg); free(err_msg); @@ -346,7 +346,7 @@ _muc_user_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, password = xmpp_stanza_get_text(password_st); } - srv_room_invite(INVITE_MEDIATED, invitor, room, reason, password); + sv_ev_room_invite(INVITE_MEDIATED, invitor, room, reason, password); jid_destroy(jidp); if (reason) { xmpp_free(ctx, reason); @@ -390,7 +390,7 @@ _conference_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, reason = xmpp_stanza_get_attribute(xns_conference, STANZA_ATTR_REASON); password = xmpp_stanza_get_attribute(xns_conference, STANZA_ATTR_PASSWORD); - srv_room_invite(INVITE_DIRECT, invitor, room, reason, password); + sv_ev_room_invite(INVITE_DIRECT, invitor, room, reason, password); jid_destroy(jidp); @@ -414,7 +414,7 @@ _captcha_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, if (body != NULL) { char *message = xmpp_stanza_get_text(body); if (message != NULL) { - srv_room_broadcast(from, message); + sv_ev_room_broadcast(from, message); xmpp_free(ctx, message); } } @@ -435,7 +435,7 @@ _groupchat_handler(xmpp_conn_t * const conn, xmpp_stanza_t *subject = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_SUBJECT); if (subject != NULL) { message = xmpp_stanza_get_text(subject); - srv_room_subject(jid->barejid, jid->resourcepart, message); + sv_ev_room_subject(jid->barejid, jid->resourcepart, message); xmpp_free(ctx, message); jid_destroy(jid); @@ -448,7 +448,7 @@ _groupchat_handler(xmpp_conn_t * const conn, if (body != NULL) { message = xmpp_stanza_get_text(body); if (message != NULL) { - srv_room_broadcast(room_jid, message); + sv_ev_room_broadcast(room_jid, message); xmpp_free(ctx, message); } } @@ -480,9 +480,9 @@ _groupchat_handler(xmpp_conn_t * const conn, message = xmpp_stanza_get_text(body); if (message != NULL) { if (delayed) { - srv_room_history(jid->barejid, jid->resourcepart, tv_stamp, message); + sv_ev_room_history(jid->barejid, jid->resourcepart, tv_stamp, message); } else { - srv_room_message(jid->barejid, jid->resourcepart, message); + sv_ev_room_message(jid->barejid, jid->resourcepart, message); } xmpp_free(ctx, message); } @@ -536,7 +536,7 @@ _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, char *fulljid = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); if (fulljid) { Jid *jidp = jid_create(fulljid); - srv_message_receipt(jidp->barejid, id); + sv_ev_message_receipt(jidp->barejid, id); jid_destroy(jidp); return 1; } @@ -573,11 +573,11 @@ _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, if (message != NULL) { // if we are the recipient, treat as standard incoming message if(g_strcmp0(my_jid->barejid, jid_to->barejid) == 0){ - srv_incoming_message(jid_from->barejid, jid_from->resourcepart, message); + sv_ev_incoming_message(jid_from->barejid, jid_from->resourcepart, message); } // else treat as a sent message else{ - srv_carbon(jid_to->barejid, message); + sv_ev_carbon(jid_to->barejid, message); } xmpp_free(ctx, message); } @@ -615,9 +615,9 @@ _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, char *message = xmpp_stanza_get_text(body); if (message != NULL) { if (delayed) { - srv_delayed_private_message(jid->str, message, tv_stamp); + sv_ev_delayed_private_message(jid->str, message, tv_stamp); } else { - srv_incoming_private_message(jid->str, message); + sv_ev_incoming_private_message(jid->str, message); } xmpp_free(ctx, message); } @@ -639,9 +639,9 @@ _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, char *message = xmpp_stanza_get_text(body); if (message != NULL) { if (delayed) { - srv_delayed_message(jid->barejid, message, tv_stamp); + sv_ev_delayed_message(jid->barejid, message, tv_stamp); } else { - srv_incoming_message(jid->barejid, jid->resourcepart, message); + sv_ev_incoming_message(jid->barejid, jid->resourcepart, message); } if (id && prefs_get_boolean(PREF_RECEIPTS_SEND)) { xmpp_stanza_t *receipts = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_RECEIPTS); @@ -663,17 +663,17 @@ _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, gboolean paused = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_PAUSED) != NULL; gboolean inactive = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_INACTIVE) != NULL; if (gone) { - srv_gone(jid->barejid, jid->resourcepart); + sv_ev_gone(jid->barejid, jid->resourcepart); } else if (typing) { - srv_typing(jid->barejid, jid->resourcepart); + sv_ev_typing(jid->barejid, jid->resourcepart); } else if (paused) { - srv_paused(jid->barejid, jid->resourcepart); + sv_ev_paused(jid->barejid, jid->resourcepart); } else if (inactive) { - srv_inactive(jid->barejid, jid->resourcepart); + sv_ev_inactive(jid->barejid, jid->resourcepart); } else if (stanza_contains_chat_state(stanza)) { - srv_activity(jid->barejid, jid->resourcepart, TRUE); + sv_ev_activity(jid->barejid, jid->resourcepart, TRUE); } else { - srv_activity(jid->barejid, jid->resourcepart, FALSE); + sv_ev_activity(jid->barejid, jid->resourcepart, FALSE); } } diff --git a/src/xmpp/presence.c b/src/xmpp/presence.c index 403ddc4e..123717cc 100644 --- a/src/xmpp/presence.c +++ b/src/xmpp/presence.c @@ -372,7 +372,7 @@ _presence_error_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, } log_info("Error joining room: %s, reason: %s", fulljid->barejid, error_cond); - srv_room_join_error(fulljid->barejid, error_cond); + sv_ev_room_join_error(fulljid->barejid, error_cond); jid_destroy(fulljid); return 1; } @@ -400,7 +400,7 @@ _presence_error_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, g_string_free(log_msg, TRUE); - srv_presence_error(from, type, err_msg); + sv_ev_presence_error(from, type, err_msg); free(err_msg); @@ -416,7 +416,7 @@ _unsubscribed_handler(xmpp_conn_t * const conn, Jid *from_jid = jid_create(from); log_debug("Unsubscribed presence handler fired for %s", from); - srv_subscription(from_jid->barejid, PRESENCE_UNSUBSCRIBED); + sv_ev_subscription(from_jid->barejid, PRESENCE_UNSUBSCRIBED); autocomplete_remove(sub_requests_ac, from_jid->barejid); jid_destroy(from_jid); @@ -432,7 +432,7 @@ _subscribed_handler(xmpp_conn_t * const conn, Jid *from_jid = jid_create(from); log_debug("Subscribed presence handler fired for %s", from); - srv_subscription(from_jid->barejid, PRESENCE_SUBSCRIBED); + sv_ev_subscription(from_jid->barejid, PRESENCE_SUBSCRIBED); autocomplete_remove(sub_requests_ac, from_jid->barejid); jid_destroy(from_jid); @@ -452,7 +452,7 @@ _subscribe_handler(xmpp_conn_t * const conn, return 1; } - srv_subscription(from_jid->barejid, PRESENCE_SUBSCRIBE); + sv_ev_subscription(from_jid->barejid, PRESENCE_SUBSCRIBE); autocomplete_add(sub_requests_ac, from_jid->barejid); jid_destroy(from_jid); @@ -480,11 +480,11 @@ _unavailable_handler(xmpp_conn_t * const conn, if (strcmp(my_jid->barejid, from_jid->barejid) !=0) { if (from_jid->resourcepart != NULL) { - srv_contact_offline(from_jid->barejid, from_jid->resourcepart, status_str); + sv_ev_contact_offline(from_jid->barejid, from_jid->resourcepart, status_str); // hack for servers that do not send full jid with unavailable presence } else { - srv_contact_offline(from_jid->barejid, "__prof_default", status_str); + sv_ev_contact_offline(from_jid->barejid, "__prof_default", status_str); } } else { if (from_jid->resourcepart != NULL) { @@ -596,7 +596,7 @@ _available_handler(xmpp_conn_t * const conn, if (g_strcmp0(xmpp_presence->jid->barejid, my_jid->barejid) == 0) { connection_add_available_resource(resource); } else { - srv_contact_online(xmpp_presence->jid->barejid, resource, xmpp_presence->last_activity); + sv_ev_contact_online(xmpp_presence->jid->barejid, resource, xmpp_presence->last_activity); } jid_destroy(my_jid); @@ -682,7 +682,7 @@ _muc_user_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * char *new_jid = stanza_get_muc_destroy_alternative_room(stanza); char *password = stanza_get_muc_destroy_alternative_password(stanza); char *reason = stanza_get_muc_destroy_reason(stanza); - srv_room_destroyed(room, new_jid, password, reason); + sv_ev_room_destroyed(room, new_jid, password, reason); free(password); free(reason); @@ -690,19 +690,19 @@ _muc_user_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * } else if (g_slist_find_custom(status_codes, "307", (GCompareFunc)g_strcmp0) != NULL) { char *actor = stanza_get_actor(stanza); char *reason = stanza_get_reason(stanza); - srv_room_kicked(room, actor, reason); + sv_ev_room_kicked(room, actor, reason); free(reason); // banned from room } else if (g_slist_find_custom(status_codes, "301", (GCompareFunc)g_strcmp0) != NULL) { char *actor = stanza_get_actor(stanza); char *reason = stanza_get_reason(stanza); - srv_room_banned(room, actor, reason); + sv_ev_room_banned(room, actor, reason); free(reason); // normal exit } else { - srv_leave_room(room); + sv_ev_leave_room(room); } g_slist_free_full(status_codes, free); @@ -713,7 +713,7 @@ _muc_user_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * gboolean config_required = stanza_muc_requires_config(stanza); char *actor = stanza_get_actor(stanza); char *reason = stanza_get_reason(stanza); - srv_muc_self_online(room, nick, config_required, role, affiliation, actor, reason, jid, show_str, status_str); + sv_ev_muc_self_online(room, nick, config_required, role, affiliation, actor, reason, jid, show_str, status_str); } // handle presence from room members @@ -735,19 +735,19 @@ _muc_user_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * if (g_slist_find_custom(status_codes, "307", (GCompareFunc)g_strcmp0) != NULL) { char *actor = stanza_get_actor(stanza); char *reason = stanza_get_reason(stanza); - srv_room_occupent_kicked(room, nick, actor, reason); + sv_ev_room_occupent_kicked(room, nick, actor, reason); free(reason); // banned from room } else if (g_slist_find_custom(status_codes, "301", (GCompareFunc)g_strcmp0) != NULL) { char *actor = stanza_get_actor(stanza); char *reason = stanza_get_reason(stanza); - srv_room_occupent_banned(room, nick, actor, reason); + sv_ev_room_occupent_banned(room, nick, actor, reason); free(reason); // normal exit } else { - srv_room_occupant_offline(room, nick, "offline", status_str); + sv_ev_room_occupant_offline(room, nick, "offline", status_str); } g_slist_free_full(status_codes, free); @@ -765,7 +765,7 @@ _muc_user_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * char *actor = stanza_get_actor(stanza); char *reason = stanza_get_reason(stanza); - srv_muc_occupant_online(room, nick, jid, role, affiliation, actor, reason, show_str, status_str); + sv_ev_muc_occupant_online(room, nick, jid, role, affiliation, actor, reason, show_str, status_str); } } diff --git a/src/xmpp/roster.c b/src/xmpp/roster.c index 51880d77..91330f1b 100644 --- a/src/xmpp/roster.c +++ b/src/xmpp/roster.c @@ -163,7 +163,7 @@ _group_add_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, { if (userdata != NULL) { GroupData *data = userdata; - srv_group_add(data->name, data->group); + sv_ev_group_add(data->name, data->group); free(data->name); free(data->group); free(userdata); @@ -210,7 +210,7 @@ _group_remove_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, { if (userdata != NULL) { GroupData *data = userdata; - srv_group_remove(data->name, data->group); + sv_ev_group_remove(data->name, data->group); free(data->name); free(data->group); free(userdata); @@ -260,7 +260,7 @@ _roster_set_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, roster_remove(name, barejid_lower); - srv_roster_remove(barejid_lower); + sv_ev_roster_remove(barejid_lower); // otherwise update local roster } else { @@ -278,10 +278,10 @@ _roster_set_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, if (contact == NULL) { gboolean added = roster_add(barejid_lower, name, groups, sub, pending_out); if (added) { - srv_roster_add(barejid_lower, name); + sv_ev_roster_add(barejid_lower, name); } } else { - srv_roster_update(barejid_lower, name, groups, sub, pending_out); + sv_ev_roster_update(barejid_lower, name, groups, sub, pending_out); } } @@ -330,7 +330,7 @@ _roster_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, item = xmpp_stanza_get_next(item); } - srv_roster_received(); + sv_ev_roster_received(); resource_presence_t conn_presence = accounts_get_login_presence(jabber_get_account_name()); presence_update(conn_presence, NULL, 0); diff --git a/tests/test_server_events.c b/tests/test_server_events.c index 29290203..ffff74f9 100644 --- a/tests/test_server_events.c +++ b/tests/test_server_events.c @@ -21,7 +21,7 @@ void console_doesnt_show_online_presence_when_set_none(void **state) roster_add("test1@server", "bob", NULL, "both", FALSE); Resource *resource = resource_new("resource", RESOURCE_ONLINE, NULL, 10); - srv_contact_online("test1@server", resource, NULL); + sv_ev_contact_online("test1@server", resource, NULL); roster_clear(); } @@ -38,7 +38,7 @@ void console_shows_online_presence_when_set_online(void **state) expect_memory(cons_show_contact_online, resource, resource, sizeof(resource)); expect_value(cons_show_contact_online, last_activity, NULL); - srv_contact_online("test1@server", resource, NULL); + sv_ev_contact_online("test1@server", resource, NULL); roster_clear(); } @@ -55,7 +55,7 @@ void console_shows_online_presence_when_set_all(void **state) expect_memory(cons_show_contact_online, resource, resource, sizeof(resource)); expect_value(cons_show_contact_online, last_activity, NULL); - srv_contact_online("test1@server", resource, NULL); + sv_ev_contact_online("test1@server", resource, NULL); roster_clear(); } @@ -67,7 +67,7 @@ void console_doesnt_show_dnd_presence_when_set_none(void **state) roster_add("test1@server", "bob", NULL, "both", FALSE); Resource *resource = resource_new("resource", RESOURCE_DND, NULL, 10); - srv_contact_online("test1@server", resource, NULL); + sv_ev_contact_online("test1@server", resource, NULL); roster_clear(); } @@ -79,7 +79,7 @@ void console_doesnt_show_dnd_presence_when_set_online(void **state) roster_add("test1@server", "bob", NULL, "both", FALSE); Resource *resource = resource_new("resource", RESOURCE_DND, NULL, 10); - srv_contact_online("test1@server", resource, NULL); + sv_ev_contact_online("test1@server", resource, NULL); roster_clear(); } @@ -96,7 +96,7 @@ void console_shows_dnd_presence_when_set_all(void **state) expect_memory(cons_show_contact_online, resource, resource, sizeof(resource)); expect_value(cons_show_contact_online, last_activity, NULL); - srv_contact_online("test1@server", resource, NULL); + sv_ev_contact_online("test1@server", resource, NULL); roster_clear(); } @@ -109,7 +109,7 @@ void handle_message_error_when_no_recipient(void **state) expect_string(ui_handle_error, err_msg, err_msg); - srv_message_error(from, type, err_msg); + sv_ev_message_error(from, type, err_msg); } void handle_message_error_when_recipient_cancel(void **state) @@ -121,7 +121,7 @@ void handle_message_error_when_recipient_cancel(void **state) prefs_set_boolean(PREF_STATES, FALSE); chat_sessions_init(); - srv_message_error(from, type, err_msg); + sv_ev_message_error(from, type, err_msg); } void handle_message_error_when_recipient_cancel_disables_chat_session(void **state) @@ -135,7 +135,7 @@ void handle_message_error_when_recipient_cancel_disables_chat_session(void **sta chat_sessions_init(); chat_session_recipient_active(barejid, resource, FALSE); - srv_message_error(barejid, type, err_msg); + sv_ev_message_error(barejid, type, err_msg); ChatSession *session = chat_session_get(barejid); assert_null(session); @@ -151,7 +151,7 @@ void handle_message_error_when_recipient_and_no_type(void **state) expect_string(ui_handle_recipient_error, recipient, from); expect_string(ui_handle_recipient_error, err_msg, err_msg); - srv_message_error(from, type, err_msg); + sv_ev_message_error(from, type, err_msg); } void handle_presence_error_when_no_recipient(void **state) @@ -162,7 +162,7 @@ void handle_presence_error_when_no_recipient(void **state) expect_string(ui_handle_error, err_msg, err_msg); - srv_presence_error(from, type, err_msg); + sv_ev_presence_error(from, type, err_msg); } void handle_presence_error_when_from_recipient(void **state) @@ -174,7 +174,7 @@ void handle_presence_error_when_from_recipient(void **state) expect_string(ui_handle_recipient_error, recipient, from); expect_string(ui_handle_recipient_error, err_msg, err_msg); - srv_presence_error(from, type, err_msg); + sv_ev_presence_error(from, type, err_msg); } void handle_offline_removes_chat_session(void **state) @@ -187,7 +187,7 @@ void handle_offline_removes_chat_session(void **state) Resource *resourcep = resource_new(resource, RESOURCE_ONLINE, NULL, 10); roster_update_presence(barejid, resourcep, NULL); chat_session_recipient_active(barejid, resource, FALSE); - srv_contact_offline(barejid, resource, NULL); + sv_ev_contact_offline(barejid, resource, NULL); ChatSession *session = chat_session_get(barejid); assert_null(session); @@ -203,7 +203,7 @@ void lost_connection_clears_chat_sessions(void **state) chat_session_recipient_active("steve@server.org", "mobile", FALSE); expect_any_cons_show_error(); - srv_lost_connection(); + sv_ev_lost_connection(); ChatSession *session1 = chat_session_get("bob@server.org"); ChatSession *session2 = chat_session_get("steve@server.org"); From d3698e6bee7985cd1707ec7b50fe61a5bf0c2829 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 28 Apr 2015 23:53:37 +0100 Subject: [PATCH 177/252] Added ui events module --- Makefile.am | 2 ++ src/command/commands.c | 1 + src/event/client_events.c | 13 ----------- src/event/client_events.h | 3 --- src/event/ui_events.c | 48 +++++++++++++++++++++++++++++++++++++++ src/event/ui_events.h | 41 +++++++++++++++++++++++++++++++++ 6 files changed, 92 insertions(+), 16 deletions(-) create mode 100644 src/event/ui_events.c create mode 100644 src/event/ui_events.h diff --git a/Makefile.am b/Makefile.am index 6566cdfa..55631477 100644 --- a/Makefile.am +++ b/Makefile.am @@ -15,6 +15,7 @@ core_sources = \ src/xmpp/form.c src/xmpp/form.h \ src/event/server_events.c src/event/server_events.h \ src/event/client_events.c src/event/client_events.h \ + src/event/ui_events.c src/event/ui_events.h \ src/ui/ui.h src/ui/window.c src/ui/window.h src/ui/core.c \ src/ui/titlebar.c src/ui/statusbar.c src/ui/inputwin.c \ src/ui/titlebar.h src/ui/statusbar.h src/ui/inputwin.h \ @@ -63,6 +64,7 @@ tests_sources = \ src/ui/titlebar.h src/ui/statusbar.h src/ui/inputwin.h \ src/event/server_events.c src/event/server_events.h \ src/event/client_events.c src/event/client_events.h \ + src/event/ui_events.c src/event/ui_events.h \ tests/xmpp/stub_xmpp.c \ tests/ui/stub_ui.c \ tests/log/stub_log.c \ diff --git a/src/command/commands.c b/src/command/commands.c index 9eaa6e9b..44069693 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -66,6 +66,7 @@ #include "ui/ui.h" #include "ui/windows.h" #include "event/client_events.h" +#include "event/ui_events.h" static void _update_presence(const resource_presence_t presence, const char * const show, gchar **args); diff --git a/src/event/client_events.c b/src/event/client_events.c index 6ee3c832..70de5f6c 100644 --- a/src/event/client_events.c +++ b/src/event/client_events.c @@ -83,17 +83,4 @@ cl_ev_send_priv_msg(const char * const fulljid, const char * const msg) { message_send_private(fulljid, msg); ui_outgoing_private_msg(fulljid, msg); -} - -void -ui_ev_focus_win(ProfWin *win) -{ - ui_switch_win(win); -} - -void -ui_ev_new_chat_win(const char * const barejid) -{ - ProfWin *win = ui_new_chat_win(barejid); - ui_switch_win(win); } \ No newline at end of file diff --git a/src/event/client_events.h b/src/event/client_events.h index 55f2b477..fcf26523 100644 --- a/src/event/client_events.h +++ b/src/event/client_events.h @@ -42,7 +42,4 @@ void cl_ev_send_msg(const char * const barejid, const char * const msg); void cl_ev_send_muc_msg(const char * const roomjid, const char * const msg); void cl_ev_send_priv_msg(const char * const fulljid, const char * const msg); -void ui_ev_focus_win(ProfWin *win); -void ui_ev_new_chat_win(const char * const barejid); - #endif \ No newline at end of file diff --git a/src/event/ui_events.c b/src/event/ui_events.c new file mode 100644 index 00000000..c079c0e6 --- /dev/null +++ b/src/event/ui_events.c @@ -0,0 +1,48 @@ +/* + * ui_events.c + * + * Copyright (C) 2012 - 2015 James Booth + * + * This file is part of Profanity. + * + * Profanity is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Profanity is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Profanity. If not, see . + * + * In addition, as a special exception, the copyright holders give permission to + * link the code of portions of this program with the OpenSSL library under + * certain conditions as described in each individual source file, and + * distribute linked combinations including the two. + * + * You must obey the GNU General Public License in all respects for all of the + * code used other than OpenSSL. If you modify file(s) with this exception, you + * may extend this exception to your version of the file(s), but you are not + * obligated to do so. If you do not wish to do so, delete this exception + * statement from your version. If you delete this exception statement from all + * source files in the program, then also delete it here. + * + */ + +#include "ui/ui.h" + +void +ui_ev_focus_win(ProfWin *win) +{ + ui_switch_win(win); +} + +void +ui_ev_new_chat_win(const char * const barejid) +{ + ProfWin *win = ui_new_chat_win(barejid); + ui_switch_win(win); +} \ No newline at end of file diff --git a/src/event/ui_events.h b/src/event/ui_events.h new file mode 100644 index 00000000..77017d2c --- /dev/null +++ b/src/event/ui_events.h @@ -0,0 +1,41 @@ +/* + * ui_events.h + * + * Copyright (C) 2012 - 2015 James Booth + * + * This file is part of Profanity. + * + * Profanity is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Profanity is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Profanity. If not, see . + * + * In addition, as a special exception, the copyright holders give permission to + * link the code of portions of this program with the OpenSSL library under + * certain conditions as described in each individual source file, and + * distribute linked combinations including the two. + * + * You must obey the GNU General Public License in all respects for all of the + * code used other than OpenSSL. If you modify file(s) with this exception, you + * may extend this exception to your version of the file(s), but you are not + * obligated to do so. If you do not wish to do so, delete this exception + * statement from your version. If you delete this exception statement from all + * source files in the program, then also delete it here. + * + */ + +#ifndef UI_EVENTS_H +#define UI_EVENTS_H + +void ui_ev_focus_win(ProfWin *win); +void ui_ev_new_chat_win(const char * const barejid); + +#endif \ No newline at end of file From 0296a603908eb5cbf52bd66d837a928924fed46f Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 29 Apr 2015 21:19:20 +0100 Subject: [PATCH 178/252] _win_show_history takes ProfChatWin as first arg --- src/ui/core.c | 119 +++++++++++++++++++++++--------------------------- 1 file changed, 54 insertions(+), 65 deletions(-) diff --git a/src/ui/core.c b/src/ui/core.c index 698b4e98..ff429e33 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -88,7 +88,7 @@ static Display *display; static GTimer *ui_idle_time; //static void _win_handle_switch(const wint_t ch); -static void _win_show_history(int win_index, const char * const contact); +static void _win_show_history(ProfChatWin *chatwin, const char * const contact); static void _ui_draw_term_title(void); void @@ -441,7 +441,7 @@ ui_incoming_msg(const char * const barejid, const char * const resource, const c chatwin->unread++; if (prefs_get_boolean(PREF_CHLOG) && prefs_get_boolean(PREF_HISTORY)) { - _win_show_history(num, barejid); + _win_show_history(chatwin, barejid); } // show users status first, when receiving message via delayed delivery @@ -501,19 +501,14 @@ ui_incoming_private_msg(const char * const fulljid, const char * const message, // not currently viewing chat window with sender } else { + privatewin->unread++; status_bar_new(num); cons_show_incoming_message(display_from, num); + win_print_incoming_message(window, tv_stamp, display_from, message); if (prefs_get_boolean(PREF_FLASH)) { flash(); } - - privatewin->unread++; - if (prefs_get_boolean(PREF_CHLOG) && prefs_get_boolean(PREF_HISTORY)) { - _win_show_history(num, fulljid); - } - - win_print_incoming_message(window, tv_stamp, display_from, message); } int ui_index = num; @@ -1365,30 +1360,6 @@ ui_recipient_gone(const char * const barejid, const char * const resource) } } -ProfWin* -ui_new_chat_win(const char * const barejid) -{ - ProfWin* window = wins_new_chat(barejid); - - int num = wins_get_num(window); - - if (prefs_get_boolean(PREF_CHLOG) && prefs_get_boolean(PREF_HISTORY)) { - _win_show_history(num, barejid); - } - - // if the contact is offline, show a message - PContact contact = roster_get_contact(barejid); - if (contact != NULL) { - if (strcmp(p_contact_presence(contact), "offline") == 0) { - const char * const show = p_contact_presence(contact); - const char * const status = p_contact_status(contact); - win_show_status_string(window, barejid, show, status, NULL, "--", "offline"); - } - } - - return window; -} - void ui_new_private_win(const char * const fulljid) { @@ -1424,6 +1395,29 @@ ui_open_xmlconsole_win(void) } } +ProfWin* +ui_new_chat_win(const char * const barejid) +{ + ProfWin *window = wins_new_chat(barejid); + ProfChatWin *chatwin = (ProfChatWin *)window; + + if (prefs_get_boolean(PREF_CHLOG) && prefs_get_boolean(PREF_HISTORY)) { + _win_show_history(chatwin, barejid); + } + + // if the contact is offline, show a message + PContact contact = roster_get_contact(barejid); + if (contact != NULL) { + if (strcmp(p_contact_presence(contact), "offline") == 0) { + const char * const show = p_contact_presence(contact); + const char * const status = p_contact_status(contact); + win_show_status_string(window, barejid, show, status, NULL, "--", "offline"); + } + } + + return window; +} + void ui_outgoing_chat_msg(const char * const barejid, const char * const message, char *id) { @@ -1443,7 +1437,7 @@ ui_outgoing_chat_msg(const char * const barejid, const char * const message, cha num = wins_get_num(window); if (prefs_get_boolean(PREF_CHLOG) && prefs_get_boolean(PREF_HISTORY)) { - _win_show_history(num, barejid); + _win_show_history(chatwin, barejid); } if (contact != NULL) { @@ -1488,7 +1482,7 @@ ui_outgoing_chat_msg_carbon(const char * const barejid, const char * const messa num = wins_get_num(window); if (prefs_get_boolean(PREF_CHLOG) && prefs_get_boolean(PREF_HISTORY)) { - _win_show_history(num, barejid); + _win_show_history(chatwin, barejid); } if (contact != NULL) { @@ -3003,39 +2997,34 @@ ui_hide_roster(void) } static void -_win_show_history(int win_index, const char * const contact) +_win_show_history(ProfChatWin *chatwin, const char * const contact) { - ProfWin *window = wins_get_by_num(win_index); - if (window->type == WIN_CHAT) { - ProfChatWin *chatwin = (ProfChatWin*) window; - assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK); - if (!chatwin->history_shown) { - Jid *jid = jid_create(jabber_get_fulljid()); - GSList *history = chat_log_get_previous(jid->barejid, contact); - jid_destroy(jid); - GSList *curr = history; - while (curr != NULL) { - char *line = curr->data; - // entry - if (line[2] == ':') { - char hh[3]; memcpy(hh, &line[0], 2); hh[2] = '\0'; int ihh = atoi(hh); - char mm[3]; memcpy(mm, &line[3], 2); mm[2] = '\0'; int imm = atoi(mm); - char ss[3]; memcpy(ss, &line[6], 2); ss[2] = '\0'; int iss = atoi(ss); - GDateTime *time = g_date_time_new_local(2000, 1, 1, ihh, imm, iss); - GTimeVal tv; - g_date_time_to_timeval(time, &tv); - win_print(window, '-', &tv, NO_COLOUR_DATE, 0, "", curr->data+11); - g_date_time_unref(time); - // header - } else { - win_print(window, '-', NULL, 0, 0, "", curr->data); - } - curr = g_slist_next(curr); + if (!chatwin->history_shown) { + Jid *jid = jid_create(jabber_get_fulljid()); + GSList *history = chat_log_get_previous(jid->barejid, contact); + jid_destroy(jid); + GSList *curr = history; + while (curr != NULL) { + char *line = curr->data; + // entry + if (line[2] == ':') { + char hh[3]; memcpy(hh, &line[0], 2); hh[2] = '\0'; int ihh = atoi(hh); + char mm[3]; memcpy(mm, &line[3], 2); mm[2] = '\0'; int imm = atoi(mm); + char ss[3]; memcpy(ss, &line[6], 2); ss[2] = '\0'; int iss = atoi(ss); + GDateTime *time = g_date_time_new_local(2000, 1, 1, ihh, imm, iss); + GTimeVal tv; + g_date_time_to_timeval(time, &tv); + win_print((ProfWin*)chatwin, '-', &tv, NO_COLOUR_DATE, 0, "", curr->data+11); + g_date_time_unref(time); + // header + } else { + win_print((ProfWin*)chatwin, '-', NULL, 0, 0, "", curr->data); } - chatwin->history_shown = TRUE; - - g_slist_free_full(history, free); + curr = g_slist_next(curr); } + chatwin->history_shown = TRUE; + + g_slist_free_full(history, free); } } From 15b34692fdd7cd6c2d377bc0daa2b8002cc318f3 Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 29 Apr 2015 21:42:29 +0100 Subject: [PATCH 179/252] Reuse ui_new_chat_win --- src/ui/core.c | 72 ++++++++++++--------------------------------------- 1 file changed, 17 insertions(+), 55 deletions(-) diff --git a/src/ui/core.c b/src/ui/core.c index ff429e33..a4ed45f3 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -1401,13 +1401,19 @@ ui_new_chat_win(const char * const barejid) ProfWin *window = wins_new_chat(barejid); ProfChatWin *chatwin = (ProfChatWin *)window; +#ifdef HAVE_LIBOTR + if (otr_is_secure(barejid)) { + chatwin->is_otr = TRUE; + } +#endif + if (prefs_get_boolean(PREF_CHLOG) && prefs_get_boolean(PREF_HISTORY)) { _win_show_history(chatwin, barejid); } // if the contact is offline, show a message PContact contact = roster_get_contact(barejid); - if (contact != NULL) { + if (contact) { if (strcmp(p_contact_presence(contact), "offline") == 0) { const char * const show = p_contact_presence(contact); const char * const status = p_contact_status(contact); @@ -1421,37 +1427,13 @@ ui_new_chat_win(const char * const barejid) void ui_outgoing_chat_msg(const char * const barejid, const char * const message, char *id) { - PContact contact = roster_get_contact(barejid); ProfWin *window = (ProfWin*)wins_get_chat(barejid); - int num = 0; // create new window - if (window == NULL) { - window = wins_new_chat(barejid); -#ifdef HAVE_LIBOTR - ProfChatWin *chatwin = (ProfChatWin*)window; - if (otr_is_secure(barejid)) { - chatwin->is_otr = TRUE; - } -#endif - num = wins_get_num(window); - - if (prefs_get_boolean(PREF_CHLOG) && prefs_get_boolean(PREF_HISTORY)) { - _win_show_history(chatwin, barejid); - } - - if (contact != NULL) { - if (strcmp(p_contact_presence(contact), "offline") == 0) { - const char *show = p_contact_presence(contact); - const char *status = p_contact_status(contact); - win_show_status_string(window, barejid, show, status, NULL, "--", "offline"); - } - } - - // use existing window - } else { - num = wins_get_num(window); + if (!window) { + window = ui_new_chat_win(barejid); } + ProfChatWin *chatwin = (ProfChatWin*)window; chat_state_active(chatwin->state); @@ -1460,47 +1442,27 @@ ui_outgoing_chat_msg(const char * const barejid, const char * const message, cha } else { win_print(window, '-', NULL, 0, THEME_TEXT_ME, "me", message); } + + int num = wins_get_num(window); ui_switch_win_num(num); } void ui_outgoing_chat_msg_carbon(const char * const barejid, const char * const message) { - PContact contact = roster_get_contact(barejid); ProfWin *window = (ProfWin*)wins_get_chat(barejid); - int num = 0; // create new window - if (window == NULL) { - window = wins_new_chat(barejid); -#ifdef HAVE_LIBOTR - ProfChatWin *chatwin = (ProfChatWin*)window; - if (otr_is_secure(barejid)) { - chatwin->is_otr = TRUE; - } -#endif - num = wins_get_num(window); - - if (prefs_get_boolean(PREF_CHLOG) && prefs_get_boolean(PREF_HISTORY)) { - _win_show_history(chatwin, barejid); - } - - if (contact != NULL) { - if (strcmp(p_contact_presence(contact), "offline") == 0) { - const char *show = p_contact_presence(contact); - const char *status = p_contact_status(contact); - win_show_status_string(window, barejid, show, status, NULL, "--", "offline"); - } - } - - // use existing window - } else { - num = wins_get_num(window); + if (!window) { + window = ui_new_chat_win(barejid); } + ProfChatWin *chatwin = (ProfChatWin*)window; chat_state_active(chatwin->state); win_print(window, '-', NULL, 0, THEME_TEXT_ME, "me", message); + + int num = wins_get_num(window); status_bar_active(num); } From 8de308c96af476de607d7ba5ecee5dc7c990ffc5 Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 29 Apr 2015 21:55:09 +0100 Subject: [PATCH 180/252] Changed message when sending non encrypted message with OTR policy always --- src/otr/otr.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/otr/otr.c b/src/otr/otr.c index c8518c70..7507cd56 100644 --- a/src/otr/otr.c +++ b/src/otr/otr.c @@ -322,7 +322,7 @@ otr_on_message_send(const char * const barejid, const char * const message) if (otr_is_secure(barejid)) { char *encrypted = otr_encrypt_message(barejid, message); - if (encrypted != NULL) { + if (encrypted) { id = message_send_chat_encrypted(barejid, encrypted); chat_log_otr_msg_out(barejid, message); ui_outgoing_chat_msg(barejid, message, id); @@ -332,7 +332,7 @@ otr_on_message_send(const char * const barejid, const char * const message) } } else if (policy == PROF_OTRPOLICY_ALWAYS) { - cons_show_error("Failed to send message. Please check OTR policy"); + cons_show_error("Failed to send message. OTR policy set to: always"); } else if (policy == PROF_OTRPOLICY_OPPORTUNISTIC) { char *otr_tagged_msg = otr_tag_message(message); From 0df8b8beff8aeeae072beee8fc3ed69f9d132fb2 Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 29 Apr 2015 22:10:32 +0100 Subject: [PATCH 181/252] Return new window on new chat win event --- src/command/commands.c | 14 ++++++-------- src/event/ui_events.c | 5 ++--- src/event/ui_events.h | 2 +- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index 44069693..f583fa44 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -1332,11 +1332,10 @@ cmd_msg(gchar **args, struct cmd_help_t help) return TRUE; } else { ProfWin *window = (ProfWin*)wins_get_chat(barejid); - if (window) { - ui_ev_focus_win(window); - } else { - ui_ev_new_chat_win(barejid); + if (!window) { + window = ui_ev_new_chat_win(barejid); } + ui_ev_focus_win(window); #ifdef HAVE_LIBOTR if (otr_is_secure(barejid)) { @@ -4171,11 +4170,10 @@ cmd_otr(gchar **args, struct cmd_help_t help) } ProfWin *window = (ProfWin*)wins_get_chat(barejid); - if (window) { - ui_ev_focus_win(window); - } else { - ui_ev_new_chat_win(barejid); + if (!window) { + window = ui_ev_new_chat_win(barejid); } + ui_ev_focus_win(window); if (ui_current_win_is_otr()) { ui_current_print_formatted_line('!', 0, "You are already in an OTR session."); diff --git a/src/event/ui_events.c b/src/event/ui_events.c index c079c0e6..5e16cc43 100644 --- a/src/event/ui_events.c +++ b/src/event/ui_events.c @@ -40,9 +40,8 @@ ui_ev_focus_win(ProfWin *win) ui_switch_win(win); } -void +ProfWin* ui_ev_new_chat_win(const char * const barejid) { - ProfWin *win = ui_new_chat_win(barejid); - ui_switch_win(win); + return ui_new_chat_win(barejid); } \ No newline at end of file diff --git a/src/event/ui_events.h b/src/event/ui_events.h index 77017d2c..9e2dc7ee 100644 --- a/src/event/ui_events.h +++ b/src/event/ui_events.h @@ -36,6 +36,6 @@ #define UI_EVENTS_H void ui_ev_focus_win(ProfWin *win); -void ui_ev_new_chat_win(const char * const barejid); +ProfWin* ui_ev_new_chat_win(const char * const barejid); #endif \ No newline at end of file From 665c34414d7534016fb8136cffbadd35793dec7b Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 29 Apr 2015 22:59:44 +0100 Subject: [PATCH 182/252] Return result on OTR message sending --- src/command/commands.c | 32 ++++++++++++++++---------------- src/event/client_events.c | 18 +++++++++++++----- src/event/client_events.h | 2 +- src/event/ui_events.c | 2 +- src/event/ui_events.h | 2 +- src/otr/otr.c | 18 +++++++++++++++--- src/otr/otr.h | 10 +++++++++- src/ui/core.c | 26 +++++++------------------- src/ui/ui.h | 2 +- tests/otr/stub_otr.c | 11 ++++++++++- tests/ui/stub_ui.c | 2 +- 11 files changed, 75 insertions(+), 50 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index f583fa44..3ef37fc1 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -110,7 +110,7 @@ cmd_execute_default(const char * inp) case WIN_CHAT: { ProfChatWin *chatwin = wins_get_current_chat(); - cl_ev_send_msg(chatwin->barejid, inp); + cl_ev_send_msg(chatwin, inp); break; } case WIN_PRIVATE: @@ -1327,23 +1327,23 @@ cmd_msg(gchar **args, struct cmd_help_t help) barejid = usr; } - if (msg) { - cl_ev_send_msg(barejid, msg); - return TRUE; - } else { - ProfWin *window = (ProfWin*)wins_get_chat(barejid); - if (!window) { - window = ui_ev_new_chat_win(barejid); - } - ui_ev_focus_win(window); + ProfChatWin *chatwin = wins_get_chat(barejid); + if (!chatwin) { + chatwin = ui_ev_new_chat_win(barejid); + } + ui_ev_focus_win((ProfWin*)chatwin); + if (msg) { + cl_ev_send_msg(chatwin, msg); + } else { #ifdef HAVE_LIBOTR if (otr_is_secure(barejid)) { ui_gone_secure(barejid, otr_is_trusted(barejid)); } #endif - return TRUE; } + + return TRUE; } } @@ -3141,7 +3141,7 @@ cmd_tiny(gchar **args, struct cmd_help_t help) case WIN_CHAT: { ProfChatWin *chatwin = wins_get_current_chat(); - cl_ev_send_msg(chatwin->barejid, tiny); + cl_ev_send_msg(chatwin, tiny); break; } case WIN_PRIVATE: @@ -4169,11 +4169,11 @@ cmd_otr(gchar **args, struct cmd_help_t help) barejid = contact; } - ProfWin *window = (ProfWin*)wins_get_chat(barejid); - if (!window) { - window = ui_ev_new_chat_win(barejid); + ProfChatWin *chatwin = wins_get_chat(barejid); + if (!chatwin) { + chatwin = ui_ev_new_chat_win(barejid); } - ui_ev_focus_win(window); + ui_ev_focus_win((ProfWin*)chatwin); if (ui_current_win_is_otr()) { ui_current_print_formatted_line('!', 0, "You are already in an OTR session."); diff --git a/src/event/client_events.c b/src/event/client_events.c index 70de5f6c..af8b833c 100644 --- a/src/event/client_events.c +++ b/src/event/client_events.c @@ -37,6 +37,7 @@ #include "config.h" #include "log.h" #include "ui/ui.h" +#include "ui/windows.h" #include "xmpp/xmpp.h" #ifdef HAVE_LIBOTR #include "otr/otr.h" @@ -60,14 +61,21 @@ cl_ev_connect_account(ProfAccount *account) } void -cl_ev_send_msg(const char * const barejid, const char * const msg) +cl_ev_send_msg(ProfChatWin *chatwin, const char * const msg) { + chat_state_active(chatwin->state); + #ifdef HAVE_LIBOTR - otr_on_message_send(barejid, msg); + prof_otrsendres_t res = otr_on_message_send(chatwin->barejid, msg); + if (res != PROF_OTRSUCCESS) { + char *errmsg = otr_senderror_str(res); + // TODO reference passed window + ui_current_error_line(errmsg); + } #else - char *id = message_send_chat(barejid, msg); - chat_log_msg_out(barejid, msg); - ui_outgoing_chat_msg(barejid, msg, id); + char *id = message_send_chat(chatwin->barejid, msg); + chat_log_msg_out(chatwin->barejid, msg); + ui_outgoing_chat_msg(chatwin->barejid, msg, id); free(id); #endif } diff --git a/src/event/client_events.h b/src/event/client_events.h index fcf26523..c074b230 100644 --- a/src/event/client_events.h +++ b/src/event/client_events.h @@ -38,7 +38,7 @@ jabber_conn_status_t cl_ev_connect_jid(const char * const jid, const char * const passwd, const char * const altdomain, const int port); jabber_conn_status_t cl_ev_connect_account(ProfAccount *account); -void cl_ev_send_msg(const char * const barejid, const char * const msg); +void cl_ev_send_msg(ProfChatWin *chatwin, const char * const msg); void cl_ev_send_muc_msg(const char * const roomjid, const char * const msg); void cl_ev_send_priv_msg(const char * const fulljid, const char * const msg); diff --git a/src/event/ui_events.c b/src/event/ui_events.c index 5e16cc43..2ad7562d 100644 --- a/src/event/ui_events.c +++ b/src/event/ui_events.c @@ -40,7 +40,7 @@ ui_ev_focus_win(ProfWin *win) ui_switch_win(win); } -ProfWin* +ProfChatWin* ui_ev_new_chat_win(const char * const barejid) { return ui_new_chat_win(barejid); diff --git a/src/event/ui_events.h b/src/event/ui_events.h index 9e2dc7ee..b7075e61 100644 --- a/src/event/ui_events.h +++ b/src/event/ui_events.h @@ -36,6 +36,6 @@ #define UI_EVENTS_H void ui_ev_focus_win(ProfWin *win); -ProfWin* ui_ev_new_chat_win(const char * const barejid); +ProfChatWin* ui_ev_new_chat_win(const char * const barejid); #endif \ No newline at end of file diff --git a/src/otr/otr.c b/src/otr/otr.c index 7507cd56..46ad491c 100644 --- a/src/otr/otr.c +++ b/src/otr/otr.c @@ -313,7 +313,7 @@ otr_on_message_recv(const char * const barejid, const char * const resource, con otr_free_message(decrypted); } -void +prof_otrsendres_t otr_on_message_send(const char * const barejid, const char * const message) { char *id = NULL; @@ -328,11 +328,11 @@ otr_on_message_send(const char * const barejid, const char * const message) ui_outgoing_chat_msg(barejid, message, id); otr_free_message(encrypted); } else { - cons_show_error("Failed to encrypt and send message."); + return PROF_OTRENCFAIL; } } else if (policy == PROF_OTRPOLICY_ALWAYS) { - cons_show_error("Failed to send message. OTR policy set to: always"); + return PROF_OTRPOLICYFAIL; } else if (policy == PROF_OTRPOLICY_OPPORTUNISTIC) { char *otr_tagged_msg = otr_tag_message(message); @@ -348,6 +348,8 @@ otr_on_message_send(const char * const barejid, const char * const message) } free(id); + + return PROF_OTRSUCCESS; } void @@ -741,6 +743,16 @@ otr_decrypt_message(const char * const from, const char * const message, gboolea } } +char* +otr_senderror_str(prof_otrsendres_t res) +{ + switch (res) { + case PROF_OTRENCFAIL: return "Failed to encrypt and send message."; + case PROF_OTRPOLICYFAIL: return "Failed to send message. OTR policy set to: always"; + default: return "Unknown OTR error."; + } +} + void otr_free_message(char *message) { diff --git a/src/otr/otr.h b/src/otr/otr.h index 8e1d22df..6f1103df 100644 --- a/src/otr/otr.h +++ b/src/otr/otr.h @@ -46,6 +46,12 @@ typedef enum { PROF_OTRPOLICY_ALWAYS } prof_otrpolicy_t; +typedef enum { + PROF_OTRENCFAIL, + PROF_OTRPOLICYFAIL, + PROF_OTRSUCCESS +} prof_otrsendres_t; + OtrlUserState otr_userstate(void); OtrlMessageAppOps* otr_messageops(void); GHashTable* otr_smpinitators(void); @@ -58,7 +64,7 @@ void otr_poll(void); void otr_on_connect(ProfAccount *account); void otr_on_message_recv(const char * const barejid, const char * const resource, const char * const message); -void otr_on_message_send(const char * const barejid, const char * const message); +prof_otrsendres_t otr_on_message_send(const char * const barejid, const char * const message); void otr_keygen(ProfAccount *account); @@ -88,4 +94,6 @@ void otr_free_message(char *message); prof_otrpolicy_t otr_get_policy(const char * const recipient); +char* otr_senderror_str(prof_otrsendres_t res); + #endif diff --git a/src/ui/core.c b/src/ui/core.c index a4ed45f3..40f9dbbf 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -1395,7 +1395,7 @@ ui_open_xmlconsole_win(void) } } -ProfWin* +ProfChatWin* ui_new_chat_win(const char * const barejid) { ProfWin *window = wins_new_chat(barejid); @@ -1421,7 +1421,7 @@ ui_new_chat_win(const char * const barejid) } } - return window; + return chatwin; } void @@ -1429,40 +1429,28 @@ ui_outgoing_chat_msg(const char * const barejid, const char * const message, cha { ProfWin *window = (ProfWin*)wins_get_chat(barejid); - // create new window - if (!window) { - window = ui_new_chat_win(barejid); - } - - ProfChatWin *chatwin = (ProfChatWin*)window; - chat_state_active(chatwin->state); - if (prefs_get_boolean(PREF_RECEIPTS_REQUEST) && id) { win_print_with_receipt(window, '-', NULL, 0, THEME_TEXT_ME, "me", message, id); } else { win_print(window, '-', NULL, 0, THEME_TEXT_ME, "me", message); } - - int num = wins_get_num(window); - ui_switch_win_num(num); } void ui_outgoing_chat_msg_carbon(const char * const barejid, const char * const message) { - ProfWin *window = (ProfWin*)wins_get_chat(barejid); + ProfChatWin *chatwin = wins_get_chat(barejid); // create new window - if (!window) { - window = ui_new_chat_win(barejid); + if (!chatwin) { + chatwin = ui_new_chat_win(barejid); } - ProfChatWin *chatwin = (ProfChatWin*)window; chat_state_active(chatwin->state); - win_print(window, '-', NULL, 0, THEME_TEXT_ME, "me", message); + win_print((ProfWin*)chatwin, '-', NULL, 0, THEME_TEXT_ME, "me", message); - int num = wins_get_num(window); + int num = wins_get_num((ProfWin*)chatwin); status_bar_active(num); } diff --git a/src/ui/ui.h b/src/ui/ui.h index d5e9c28c..11457988 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -88,7 +88,7 @@ void ui_handle_otr_error(const char * const barejid, const char * const message) unsigned long ui_get_idle_time(void); void ui_reset_idle_time(void); void ui_new_private_win(const char * const fulljid); -ProfWin* ui_new_chat_win(const char * const barejid); +ProfChatWin* ui_new_chat_win(const char * const barejid); void ui_print_system_msg_from_recipient(const char * const barejid, const char *message); gint ui_unread(void); void ui_close_connected_win(int index); diff --git a/tests/otr/stub_otr.c b/tests/otr/stub_otr.c index eb676877..9815957f 100644 --- a/tests/otr/stub_otr.c +++ b/tests/otr/stub_otr.c @@ -42,7 +42,10 @@ char* otr_start_query(void) void otr_poll(void) {} void otr_on_connect(ProfAccount *account) {} void otr_on_message_recv(const char * const barejid, const char * const resource, const char * const message) {} -void otr_on_message_send(const char * const barejid, const char * const message) {} +prof_otrsendres_t otr_on_message_send(const char * const barejid, const char * const message) +{ + return PROF_OTRSUCCESS; +} void otr_keygen(ProfAccount *account) { @@ -106,3 +109,9 @@ prof_otrpolicy_t otr_get_policy(const char * const recipient) { return PROF_OTRPOLICY_MANUAL; } + +char* otr_senderror_str(prof_otrsendres_t res) +{ + return NULL; +} + diff --git a/tests/ui/stub_ui.c b/tests/ui/stub_ui.c index 54faa50a..70be97ef 100644 --- a/tests/ui/stub_ui.c +++ b/tests/ui/stub_ui.c @@ -105,7 +105,7 @@ unsigned long ui_get_idle_time(void) void ui_reset_idle_time(void) {} void ui_new_private_win(const char * const fulljid) {} -ProfWin* ui_new_chat_win(const char * const barejid) +ProfChatWin* ui_new_chat_win(const char * const barejid) { return NULL; } From 2e75e5446060f64759dcc73c2f0a4967024f1627 Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 29 Apr 2015 23:16:28 +0100 Subject: [PATCH 183/252] Added ui_win_error_line() --- src/event/client_events.c | 3 +-- src/ui/core.c | 6 ++++++ src/ui/ui.h | 1 + tests/ui/stub_ui.c | 2 ++ 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/event/client_events.c b/src/event/client_events.c index af8b833c..f3c67f63 100644 --- a/src/event/client_events.c +++ b/src/event/client_events.c @@ -69,8 +69,7 @@ cl_ev_send_msg(ProfChatWin *chatwin, const char * const msg) prof_otrsendres_t res = otr_on_message_send(chatwin->barejid, msg); if (res != PROF_OTRSUCCESS) { char *errmsg = otr_senderror_str(res); - // TODO reference passed window - ui_current_error_line(errmsg); + ui_win_error_line((ProfWin*)chatwin, errmsg); } #else char *id = message_send_chat(chatwin->barejid, msg); diff --git a/src/ui/core.c b/src/ui/core.c index 40f9dbbf..b985e52b 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -1296,6 +1296,12 @@ ui_current_print_formatted_line(const char show_char, int attrs, const char * co g_string_free(fmt_msg, TRUE); } +void +ui_win_error_line(ProfWin *window, const char * const msg) +{ + win_print(window, '-', NULL, 0, THEME_ERROR, "", msg); +} + void ui_current_error_line(const char * const msg) { diff --git a/src/ui/ui.h b/src/ui/ui.h index 11457988..e98a105e 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -106,6 +106,7 @@ ProfChatWin *ui_get_current_chat(void); void ui_current_print_line(const char * const msg, ...); void ui_current_print_formatted_line(const char show_char, int attrs, const char * const msg, ...); void ui_current_error_line(const char * const msg); +void ui_win_error_line(ProfWin *window, const char * const msg); win_type_t ui_win_type(int index); void ui_close_win(int index); diff --git a/tests/ui/stub_ui.c b/tests/ui/stub_ui.c index 70be97ef..faea7dd3 100644 --- a/tests/ui/stub_ui.c +++ b/tests/ui/stub_ui.c @@ -171,6 +171,8 @@ void ui_current_print_formatted_line(const char show_char, int attrs, const char } void ui_current_error_line(const char * const msg) {} +void ui_win_error_line(ProfWin *window, const char * const msg) {} + win_type_t ui_win_type(int index) { From 0a6b76d6d36455a118d95b2815f1ab5f16707bff Mon Sep 17 00:00:00 2001 From: James Booth Date: Thu, 30 Apr 2015 21:23:43 +0100 Subject: [PATCH 184/252] Removed some ui functions, inlined --- src/command/commands.c | 22 +++++++++++----------- src/ui/core.c | 16 ++-------------- src/ui/ui.h | 2 -- tests/ui/stub_ui.c | 9 --------- 4 files changed, 13 insertions(+), 36 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index 3ef37fc1..f85af612 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -1331,7 +1331,9 @@ cmd_msg(gchar **args, struct cmd_help_t help) if (!chatwin) { chatwin = ui_ev_new_chat_win(barejid); } - ui_ev_focus_win((ProfWin*)chatwin); + if (!wins_is_current((ProfWin*)chatwin)) { + ui_ev_focus_win((ProfWin*)chatwin); + } if (msg) { cl_ev_send_msg(chatwin, msg); @@ -3180,7 +3182,7 @@ cmd_close(gchar **args, struct cmd_help_t help) int count = 0; if (args[0] == NULL) { - index = ui_current_win_index(); + index = wins_get_current_num(); } else if (strcmp(args[0], "all") == 0) { count = ui_close_all_wins(); if (count == 0) { @@ -3215,19 +3217,15 @@ cmd_close(gchar **args, struct cmd_help_t help) return TRUE; } - if (!ui_win_exists(index)) { + ProfWin *window = wins_get_by_num(index); + if (!window) { cons_show("Window is not open."); return TRUE; } // check for unsaved form if (ui_win_has_unsaved_form(index)) { - ProfWin *window = wins_get_current(); - if (wins_is_current(window)) { - ui_current_print_line("You have unsaved changes, use /form submit or /form cancel"); - } else { - cons_show("Cannot close form window with unsaved changes, use /form submit or /form cancel"); - } + ui_current_print_line("You have unsaved changes, use /form submit or /form cancel"); return TRUE; } @@ -3248,7 +3246,7 @@ cmd_leave(gchar **args, struct cmd_help_t help) { jabber_conn_status_t conn_status = jabber_get_connection_status(); win_type_t win_type = ui_current_win_type(); - int index = ui_current_win_index(); + int index = wins_get_current_num(); if (win_type != WIN_MUC) { cons_show("You can only use the /leave command in a chat room."); @@ -4173,7 +4171,9 @@ cmd_otr(gchar **args, struct cmd_help_t help) if (!chatwin) { chatwin = ui_ev_new_chat_win(barejid); } - ui_ev_focus_win((ProfWin*)chatwin); + if (!wins_is_current((ProfWin*)chatwin)) { + ui_ev_focus_win((ProfWin*)chatwin); + } if (ui_current_win_is_otr()) { ui_current_print_formatted_line('!', 0, "You are already in an OTR session."); diff --git a/src/ui/core.c b/src/ui/core.c index b985e52b..59144223 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -281,13 +281,6 @@ ui_load_colours(void) } } -gboolean -ui_win_exists(int index) -{ - ProfWin *window = wins_get_by_num(index); - return (window != NULL); -} - gboolean ui_xmlconsole_exists(void) { @@ -882,7 +875,8 @@ ui_switch_win(ProfWin *win) gboolean ui_switch_win_num(const int i) { - if (ui_win_exists(i)) { + ProfWin *window = wins_get_by_num(i); + if (window) { ProfWin *old_current = wins_get_current(); if (old_current->type == WIN_MUC_CONFIG) { ProfMucConfWin *confwin = (ProfMucConfWin*)old_current; @@ -1257,12 +1251,6 @@ ui_current_win_is_otr(void) } } -int -ui_current_win_index(void) -{ - return wins_get_current_num(); -} - win_type_t ui_win_type(int index) { diff --git a/src/ui/ui.h b/src/ui/ui.h index e98a105e..e42505bc 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -98,7 +98,6 @@ int ui_close_read_wins(void); // current window actions void ui_clear_current(void); win_type_t ui_current_win_type(void); -int ui_current_win_index(void); gboolean ui_current_win_is_otr(void); ProfChatWin *ui_get_current_chat(void); @@ -110,7 +109,6 @@ void ui_win_error_line(ProfWin *window, const char * const msg); win_type_t ui_win_type(int index); void ui_close_win(int index); -gboolean ui_win_exists(int index); int ui_win_unread(int index); char * ui_ask_password(void); diff --git a/tests/ui/stub_ui.c b/tests/ui/stub_ui.c index faea7dd3..16933e5d 100644 --- a/tests/ui/stub_ui.c +++ b/tests/ui/stub_ui.c @@ -135,11 +135,6 @@ win_type_t ui_current_win_type(void) return (win_type_t)mock(); } -int ui_current_win_index(void) -{ - return 0; -} - gboolean ui_current_win_is_otr(void) { return (gboolean)mock(); @@ -180,10 +175,6 @@ win_type_t ui_win_type(int index) } void ui_close_win(int index) {} -gboolean ui_win_exists(int index) -{ - return FALSE; -} int ui_win_unread(int index) { From 20555fcb3646d789206ede9a95881fed75fbc0b9 Mon Sep 17 00:00:00 2001 From: James Booth Date: Thu, 30 Apr 2015 21:27:44 +0100 Subject: [PATCH 185/252] Added assert to ui_switch_win --- src/ui/core.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ui/core.c b/src/ui/core.c index 59144223..d4bac9b3 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -868,6 +868,7 @@ ui_win_has_unsaved_form(int num) gboolean ui_switch_win(ProfWin *win) { + assert(win != NULL); int num = wins_get_num(win); return ui_switch_win_num(num); } From d68fb25ddef2f30c9d17991aa5d1d0e2a36d8386 Mon Sep 17 00:00:00 2001 From: James Booth Date: Thu, 30 Apr 2015 22:09:39 +0100 Subject: [PATCH 186/252] Removed ui_win_switch_num --- Makefile.am | 1 - src/command/commands.c | 24 +++++---- src/ui/core.c | 113 ++++++++++++++--------------------------- src/ui/inputwin.c | 32 ++++++++---- src/ui/ui.h | 3 +- src/ui/windows.c | 8 +-- tests/test_cmd_win.c | 41 --------------- tests/test_cmd_win.h | 2 - tests/testsuite.c | 4 -- tests/ui/stub_ui.c | 12 +---- 10 files changed, 81 insertions(+), 159 deletions(-) delete mode 100644 tests/test_cmd_win.c delete mode 100644 tests/test_cmd_win.h diff --git a/Makefile.am b/Makefile.am index 55631477..372b60f3 100644 --- a/Makefile.am +++ b/Makefile.am @@ -80,7 +80,6 @@ tests_sources = \ tests/test_cmd_roster.c tests/test_cmd_roster.h \ tests/test_cmd_statuses.c tests/test_cmd_statuses.h \ tests/test_cmd_sub.c tests/test_cmd_sub.h \ - tests/test_cmd_win.c tests/test_cmd_win.h \ tests/test_cmd_disconnect.c tests/test_cmd_disconnect.h \ tests/test_common.c tests/test_common.h \ tests/test_contact.c tests/test_contact.h \ diff --git a/src/command/commands.c b/src/command/commands.c index f85af612..ad8c276c 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -722,10 +722,16 @@ gboolean cmd_win(gchar **args, struct cmd_help_t help) { int num = atoi(args[0]); - gboolean switched = ui_switch_win_num(num); - if (switched == FALSE) { + + ProfWin *window = wins_get_by_num(num); + if (!window) { cons_show("Window %d does not exist.", num); + } else { + if (!wins_is_current(window)) { + ui_ev_focus_win(window); + } } + return TRUE; } @@ -2453,12 +2459,11 @@ cmd_form(gchar **args, struct cmd_help_t help) cmd_autocomplete_remove_form_fields(confwin->form); } wins_close_current(); - ProfWin *current = (ProfWin*)wins_get_muc(confwin->roomjid); - if (current == NULL) { - current = wins_get_console(); + ProfWin *new_current = (ProfWin*)wins_get_muc(confwin->roomjid); + if (!new_current) { + new_current = wins_get_console(); } - int num = wins_get_num(current); - ui_switch_win_num(num); + ui_ev_focus_win(new_current); } return TRUE; @@ -2764,9 +2769,8 @@ cmd_room(gchar **args, struct cmd_help_t help) if (g_strcmp0(args[0], "config") == 0) { ProfMucConfWin *confwin = wins_get_muc_conf(mucwin->roomjid); - if (confwin != NULL) { - num = wins_get_num(window); - ui_switch_win_num(num); + if (confwin) { + ui_ev_focus_win((ProfWin*)confwin); } else { iq_request_room_config_form(mucwin->roomjid); } diff --git a/src/ui/core.c b/src/ui/core.c index d4bac9b3..22cf1168 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -865,46 +865,32 @@ ui_win_has_unsaved_form(int num) } } -gboolean -ui_switch_win(ProfWin *win) +void +ui_switch_win(ProfWin *window) { - assert(win != NULL); - int num = wins_get_num(win); - return ui_switch_win_num(num); -} + assert(window != NULL); -gboolean -ui_switch_win_num(const int i) -{ - ProfWin *window = wins_get_by_num(i); - if (window) { - ProfWin *old_current = wins_get_current(); - if (old_current->type == WIN_MUC_CONFIG) { - ProfMucConfWin *confwin = (ProfMucConfWin*)old_current; - cmd_autocomplete_remove_form_fields(confwin->form); - } - - ProfWin *new_current = wins_get_by_num(i); - if (new_current->type == WIN_MUC_CONFIG) { - ProfMucConfWin *confwin = (ProfMucConfWin*)new_current; - cmd_autocomplete_add_form_fields(confwin->form); - } - - wins_set_current_by_num(i); - - if (i == 1) { - title_bar_console(); - status_bar_current(1); - status_bar_active(1); - } else { - title_bar_switch(); - status_bar_current(i); - status_bar_active(i); - } - return TRUE; - } else { - return FALSE; + ProfWin *old_current = wins_get_current(); + if (old_current->type == WIN_MUC_CONFIG) { + ProfMucConfWin *confwin = (ProfMucConfWin*)old_current; + cmd_autocomplete_remove_form_fields(confwin->form); } + + if (window->type == WIN_MUC_CONFIG) { + ProfMucConfWin *confwin = (ProfMucConfWin*)window; + cmd_autocomplete_add_form_fields(confwin->form); + } + + int i = wins_get_num(window); + wins_set_current_by_num(i); + + if (i == 1) { + title_bar_console(); + } else { + title_bar_switch(); + } + status_bar_current(i); + status_bar_active(i); } void @@ -1359,34 +1345,25 @@ void ui_new_private_win(const char * const fulljid) { ProfWin *window = (ProfWin*)wins_get_private(fulljid); - int num = 0; - - // create new window - if (window == NULL) { + if (!window) { window = wins_new_private(fulljid); - num = wins_get_num(window); - } else { - num = wins_get_num(window); } - - ui_switch_win_num(num); + ui_switch_win(window); } void ui_create_xmlconsole_win(void) { ProfWin *window = wins_new_xmlconsole(); - int num = wins_get_num(window); - ui_switch_win_num(num); + ui_switch_win(window); } void ui_open_xmlconsole_win(void) { ProfXMLWin *xmlwin = wins_get_xmlconsole(); - if (xmlwin != NULL) { - int num = wins_get_num((ProfWin*)xmlwin); - ui_switch_win_num(num); + if (xmlwin) { + ui_switch_win((ProfWin*)xmlwin); } } @@ -1453,30 +1430,19 @@ void ui_outgoing_private_msg(const char * const fulljid, const char * const message) { ProfWin *window = (ProfWin*)wins_get_private(fulljid); - int num = 0; - - // create new window - if (window == NULL) { + if (!window) { window = wins_new_private(fulljid); - num = wins_get_num(window); - - // use existing window - } else { - num = wins_get_num(window); } win_print(window, '-', NULL, 0, THEME_TEXT_ME, "me", message); - ui_switch_win_num(num); + ui_switch_win(window); } void ui_room_join(const char * const roomjid, gboolean focus) { ProfWin *window = (ProfWin*)wins_get_muc(roomjid); - int num = 0; - - // create new window - if (window == NULL) { + if (!window) { window = wins_new_muc(roomjid); } @@ -1494,11 +1460,11 @@ ui_room_join(const char * const roomjid, gboolean focus) } win_print(window, '!', NULL, NO_DATE, THEME_ROOMINFO, "", ""); - num = wins_get_num(window); if (focus) { - ui_switch_win_num(num); + ui_switch_win(window); } else { + int num = wins_get_num(window); status_bar_active(num); ProfWin *console = wins_get_console(); char *nick = muc_nick(roomjid); @@ -1510,8 +1476,7 @@ void ui_switch_to_room(const char * const roomjid) { ProfWin *window = (ProfWin*)wins_get_muc(roomjid); - int num = wins_get_num(window); - ui_switch_win_num(num); + ui_switch_win(window); } void @@ -2683,9 +2648,7 @@ ui_handle_room_configuration(const char * const roomjid, DataForm *form) ProfMucConfWin *confwin = (ProfMucConfWin*)window; assert(confwin->memcheck == PROFCONFWIN_MEMCHECK); - int num = wins_get_num(window); - ui_switch_win_num(num); - + ui_switch_win(window); ui_show_form(confwin); win_print(window, '-', NULL, 0, 0, "", ""); @@ -2740,11 +2703,11 @@ ui_handle_room_config_submit_result(const char * const roomjid) } if (muc_window) { - int num = wins_get_num(muc_window); - ui_switch_win_num(num); + ui_switch_win((ProfWin*)muc_window); win_print(muc_window, '!', NULL, 0, THEME_ROOMINFO, "", "Room configuration successful"); } else { - ui_switch_win_num(1); + ProfWin *console = wins_get_console(); + ui_switch_win(console); cons_show("Room configuration successful: %s", roomjid); } } else { diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index 935fd4ce..6cfbde47 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -63,6 +63,7 @@ #include "ui/statusbar.h" #include "ui/inputwin.h" #include "ui/windows.h" +#include "event/ui_events.h" #include "xmpp/xmpp.h" static WINDOW *inp_win; @@ -449,73 +450,84 @@ _inp_rl_tab_handler(int count, int key) return 0; } +static void +_go_to_win(int i) +{ + ProfWin *window = wins_get_by_num(i); + if (window) { + if (!wins_is_current(window)) { + ui_ev_focus_win(window); + } + } +} + static int _inp_rl_win1_handler(int count, int key) { - ui_switch_win_num(1); + _go_to_win(1); return 0; } static int _inp_rl_win2_handler(int count, int key) { - ui_switch_win_num(2); + _go_to_win(2); return 0; } static int _inp_rl_win3_handler(int count, int key) { - ui_switch_win_num(3); + _go_to_win(3); return 0; } static int _inp_rl_win4_handler(int count, int key) { - ui_switch_win_num(4); + _go_to_win(4); return 0; } static int _inp_rl_win5_handler(int count, int key) { - ui_switch_win_num(5); + _go_to_win(5); return 0; } static int _inp_rl_win6_handler(int count, int key) { - ui_switch_win_num(6); + _go_to_win(6); return 0; } static int _inp_rl_win7_handler(int count, int key) { - ui_switch_win_num(7); + _go_to_win(7); return 0; } static int _inp_rl_win8_handler(int count, int key) { - ui_switch_win_num(8); + _go_to_win(8); return 0; } static int _inp_rl_win9_handler(int count, int key) { - ui_switch_win_num(9); + _go_to_win(9); return 0; } static int _inp_rl_win0_handler(int count, int key) { - ui_switch_win_num(0); + _go_to_win(0); return 0; } diff --git a/src/ui/ui.h b/src/ui/ui.h index e42505bc..529e0f92 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -59,8 +59,7 @@ void ui_close(void); void ui_redraw(void); void ui_resize(void); GSList* ui_get_chat_recipients(void); -gboolean ui_switch_win_num(const int i); -gboolean ui_switch_win(ProfWin *win); +void ui_switch_win(ProfWin *window); void ui_next_win(void); void ui_previous_win(void); void ui_sigwinch_handler(int sig); diff --git a/src/ui/windows.c b/src/ui/windows.c index 269bea1d..4cc0fef7 100644 --- a/src/ui/windows.c +++ b/src/ui/windows.c @@ -644,6 +644,7 @@ gboolean wins_swap(int source_win, int target_win) { ProfWin *source = g_hash_table_lookup(windows, GINT_TO_POINTER(source_win)); + ProfWin *console = wins_get_console(); if (source) { ProfWin *target = g_hash_table_lookup(windows, GINT_TO_POINTER(target_win)); @@ -660,7 +661,7 @@ wins_swap(int source_win, int target_win) } if (wins_get_current_num() == source_win) { wins_set_current_by_num(target_win); - ui_switch_win_num(1); + ui_switch_win(console); } return TRUE; @@ -681,7 +682,7 @@ wins_swap(int source_win, int target_win) status_bar_active(source_win); } if ((wins_get_current_num() == source_win) || (wins_get_current_num() == target_win)) { - ui_switch_win_num(1); + ui_switch_win(console); } return TRUE; } @@ -740,7 +741,8 @@ wins_tidy(void) windows = new_windows; current = 1; - ui_switch_win_num(1); + ProfWin *console = wins_get_console(); + ui_switch_win(console); g_list_free(keys); return TRUE; } else { diff --git a/tests/test_cmd_win.c b/tests/test_cmd_win.c deleted file mode 100644 index 7ad01c49..00000000 --- a/tests/test_cmd_win.c +++ /dev/null @@ -1,41 +0,0 @@ -#include -#include -#include -#include -#include -#include - -#include "ui/ui.h" -#include "ui/stub_ui.h" - -#include "command/commands.h" - -void cmd_win_shows_message_when_win_doesnt_exist(void **state) -{ - CommandHelp *help = malloc(sizeof(CommandHelp)); - gchar *args[] = { "3", NULL }; - - expect_value(ui_switch_win_num, i, 3); - will_return(ui_switch_win_num, FALSE); - - expect_cons_show("Window 3 does not exist."); - - gboolean result = cmd_win(args, *help); - assert_true(result); - - free(help); -} - -void cmd_win_switches_to_given_win_when_exists(void **state) -{ - CommandHelp *help = malloc(sizeof(CommandHelp)); - gchar *args[] = { "12", NULL }; - - expect_value(ui_switch_win_num, i, 12); - will_return(ui_switch_win_num, TRUE); - - gboolean result = cmd_win(args, *help); - assert_true(result); - - free(help); -} diff --git a/tests/test_cmd_win.h b/tests/test_cmd_win.h deleted file mode 100644 index a0f61a6b..00000000 --- a/tests/test_cmd_win.h +++ /dev/null @@ -1,2 +0,0 @@ -void cmd_win_shows_message_when_win_doesnt_exist(void **state); -void cmd_win_switches_to_given_win_when_exists(void **state); diff --git a/tests/testsuite.c b/tests/testsuite.c index 15682d1f..b4ce1c0a 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -31,7 +31,6 @@ #include "test_cmd_join.h" #include "test_muc.h" #include "test_cmd_roster.h" -#include "test_cmd_win.h" #include "test_cmd_disconnect.h" #include "test_form.h" @@ -586,9 +585,6 @@ int main(int argc, char* argv[]) { unit_test(cmd_roster_clearnick_shows_message_when_no_contact_exists), unit_test(cmd_roster_clearnick_sends_name_change_request_with_empty_nick), - unit_test(cmd_win_shows_message_when_win_doesnt_exist), - unit_test(cmd_win_switches_to_given_win_when_exists), - unit_test(get_form_type_field_returns_null_no_fields), unit_test(get_form_type_field_returns_null_when_not_present), unit_test(get_form_type_field_returns_value_when_present), diff --git a/tests/ui/stub_ui.c b/tests/ui/stub_ui.c index 16933e5d..1f812781 100644 --- a/tests/ui/stub_ui.c +++ b/tests/ui/stub_ui.c @@ -64,17 +64,7 @@ GSList* ui_get_chat_recipients(void) return NULL; } -gboolean ui_switch_win(ProfWin *win) -{ - return FALSE; -} - -gboolean ui_switch_win_num(const int i) -{ - check_expected(i); - return (gboolean)mock(); - return FALSE; -} +void ui_switch_win(ProfWin *win) {} void ui_next_win(void) {} void ui_previous_win(void) {} From e11e55e31abced2f4e7fa332298485562adaf1ef Mon Sep 17 00:00:00 2001 From: James Booth Date: Thu, 30 Apr 2015 22:43:08 +0100 Subject: [PATCH 187/252] Move current win check to event, removed next and prev win functions --- src/command/commands.c | 12 ++----- src/event/ui_events.c | 5 ++- src/ui/core.c | 77 ++++++------------------------------------ src/ui/inputwin.c | 14 +++++--- src/ui/ui.h | 2 -- src/ui/windows.c | 7 ++-- tests/ui/stub_ui.c | 3 -- 7 files changed, 30 insertions(+), 90 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index ad8c276c..62dcb927 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -727,9 +727,7 @@ cmd_win(gchar **args, struct cmd_help_t help) if (!window) { cons_show("Window %d does not exist.", num); } else { - if (!wins_is_current(window)) { - ui_ev_focus_win(window); - } + ui_ev_focus_win(window); } return TRUE; @@ -1337,9 +1335,7 @@ cmd_msg(gchar **args, struct cmd_help_t help) if (!chatwin) { chatwin = ui_ev_new_chat_win(barejid); } - if (!wins_is_current((ProfWin*)chatwin)) { - ui_ev_focus_win((ProfWin*)chatwin); - } + ui_ev_focus_win((ProfWin*)chatwin); if (msg) { cl_ev_send_msg(chatwin, msg); @@ -4175,9 +4171,7 @@ cmd_otr(gchar **args, struct cmd_help_t help) if (!chatwin) { chatwin = ui_ev_new_chat_win(barejid); } - if (!wins_is_current((ProfWin*)chatwin)) { - ui_ev_focus_win((ProfWin*)chatwin); - } + ui_ev_focus_win((ProfWin*)chatwin); if (ui_current_win_is_otr()) { ui_current_print_formatted_line('!', 0, "You are already in an OTR session."); diff --git a/src/event/ui_events.c b/src/event/ui_events.c index 2ad7562d..bebffc07 100644 --- a/src/event/ui_events.c +++ b/src/event/ui_events.c @@ -33,11 +33,14 @@ */ #include "ui/ui.h" +#include "ui/windows.h" void ui_ev_focus_win(ProfWin *win) { - ui_switch_win(win); + if (!wins_is_current(win)) { + ui_switch_win(win); + } } ProfChatWin* diff --git a/src/ui/core.c b/src/ui/core.c index 22cf1168..946e3eaf 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -74,6 +74,7 @@ #include "ui/window.h" #include "ui/windows.h" #include "xmpp/xmpp.h" +#include "event/ui_events.h" static char *win_title; @@ -893,64 +894,6 @@ ui_switch_win(ProfWin *window) status_bar_active(i); } -void -ui_previous_win(void) -{ - ProfWin *old_current = wins_get_current(); - if (old_current->type == WIN_MUC_CONFIG) { - ProfMucConfWin *confwin = (ProfMucConfWin*)old_current; - cmd_autocomplete_remove_form_fields(confwin->form); - } - - ProfWin *new_current = wins_get_previous(); - if (new_current->type == WIN_MUC_CONFIG) { - ProfMucConfWin *confwin = (ProfMucConfWin*)new_current; - cmd_autocomplete_add_form_fields(confwin->form); - } - - int i = wins_get_num(new_current); - wins_set_current_by_num(i); - - if (i == 1) { - title_bar_console(); - status_bar_current(1); - status_bar_active(1); - } else { - title_bar_switch(); - status_bar_current(i); - status_bar_active(i); - } -} - -void -ui_next_win(void) -{ - ProfWin *old_current = wins_get_current(); - if (old_current->type == WIN_MUC_CONFIG) { - ProfMucConfWin *confwin = (ProfMucConfWin*)old_current; - cmd_autocomplete_remove_form_fields(confwin->form); - } - - ProfWin *new_current = wins_get_next(); - if (new_current->type == WIN_MUC_CONFIG) { - ProfMucConfWin *confwin = (ProfMucConfWin*)new_current; - cmd_autocomplete_add_form_fields(confwin->form); - } - - int i = wins_get_num(new_current); - wins_set_current_by_num(i); - - if (i == 1) { - title_bar_console(); - status_bar_current(1); - status_bar_active(1); - } else { - title_bar_switch(); - status_bar_current(i); - status_bar_active(i); - } -} - void ui_gone_secure(const char * const barejid, gboolean trusted) { @@ -1348,14 +1291,14 @@ ui_new_private_win(const char * const fulljid) if (!window) { window = wins_new_private(fulljid); } - ui_switch_win(window); + ui_ev_focus_win(window); } void ui_create_xmlconsole_win(void) { ProfWin *window = wins_new_xmlconsole(); - ui_switch_win(window); + ui_ev_focus_win(window); } void @@ -1363,7 +1306,7 @@ ui_open_xmlconsole_win(void) { ProfXMLWin *xmlwin = wins_get_xmlconsole(); if (xmlwin) { - ui_switch_win((ProfWin*)xmlwin); + ui_ev_focus_win((ProfWin*)xmlwin); } } @@ -1435,7 +1378,7 @@ ui_outgoing_private_msg(const char * const fulljid, const char * const message) } win_print(window, '-', NULL, 0, THEME_TEXT_ME, "me", message); - ui_switch_win(window); + ui_ev_focus_win(window); } void @@ -1462,7 +1405,7 @@ ui_room_join(const char * const roomjid, gboolean focus) if (focus) { - ui_switch_win(window); + ui_ev_focus_win(window); } else { int num = wins_get_num(window); status_bar_active(num); @@ -1476,7 +1419,7 @@ void ui_switch_to_room(const char * const roomjid) { ProfWin *window = (ProfWin*)wins_get_muc(roomjid); - ui_switch_win(window); + ui_ev_focus_win(window); } void @@ -2648,7 +2591,7 @@ ui_handle_room_configuration(const char * const roomjid, DataForm *form) ProfMucConfWin *confwin = (ProfMucConfWin*)window; assert(confwin->memcheck == PROFCONFWIN_MEMCHECK); - ui_switch_win(window); + ui_ev_focus_win(window); ui_show_form(confwin); win_print(window, '-', NULL, 0, 0, "", ""); @@ -2703,11 +2646,11 @@ ui_handle_room_config_submit_result(const char * const roomjid) } if (muc_window) { - ui_switch_win((ProfWin*)muc_window); + ui_ev_focus_win((ProfWin*)muc_window); win_print(muc_window, '!', NULL, 0, THEME_ROOMINFO, "", "Room configuration successful"); } else { ProfWin *console = wins_get_console(); - ui_switch_win(console); + ui_ev_focus_win(console); cons_show("Room configuration successful: %s", roomjid); } } else { diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index 6cfbde47..caea8ea9 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -455,9 +455,7 @@ _go_to_win(int i) { ProfWin *window = wins_get_by_num(i); if (window) { - if (!wins_is_current(window)) { - ui_ev_focus_win(window); - } + ui_ev_focus_win(window); } } @@ -534,14 +532,20 @@ _inp_rl_win0_handler(int count, int key) static int _inp_rl_altleft_handler(int count, int key) { - ui_previous_win(); + ProfWin *window = wins_get_previous(); + if (window) { + ui_ev_focus_win(window); + } return 0; } static int _inp_rl_altright_handler(int count, int key) { - ui_next_win(); + ProfWin *window = wins_get_next(); + if (window) { + ui_ev_focus_win(window); + } return 0; } diff --git a/src/ui/ui.h b/src/ui/ui.h index 529e0f92..6d85c9e8 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -60,8 +60,6 @@ void ui_redraw(void); void ui_resize(void); GSList* ui_get_chat_recipients(void); void ui_switch_win(ProfWin *window); -void ui_next_win(void); -void ui_previous_win(void); void ui_sigwinch_handler(int sig); void ui_gone_secure(const char * const barejid, gboolean trusted); diff --git a/src/ui/windows.c b/src/ui/windows.c index 4cc0fef7..7a86403b 100644 --- a/src/ui/windows.c +++ b/src/ui/windows.c @@ -53,6 +53,7 @@ #include "ui/statusbar.h" #include "ui/window.h" #include "ui/windows.h" +#include "event/ui_events.h" static GHashTable *windows; static int current; @@ -661,7 +662,7 @@ wins_swap(int source_win, int target_win) } if (wins_get_current_num() == source_win) { wins_set_current_by_num(target_win); - ui_switch_win(console); + ui_ev_focus_win(console); } return TRUE; @@ -682,7 +683,7 @@ wins_swap(int source_win, int target_win) status_bar_active(source_win); } if ((wins_get_current_num() == source_win) || (wins_get_current_num() == target_win)) { - ui_switch_win(console); + ui_ev_focus_win(console); } return TRUE; } @@ -742,7 +743,7 @@ wins_tidy(void) windows = new_windows; current = 1; ProfWin *console = wins_get_console(); - ui_switch_win(console); + ui_ev_focus_win(console); g_list_free(keys); return TRUE; } else { diff --git a/tests/ui/stub_ui.c b/tests/ui/stub_ui.c index 1f812781..cee81872 100644 --- a/tests/ui/stub_ui.c +++ b/tests/ui/stub_ui.c @@ -66,9 +66,6 @@ GSList* ui_get_chat_recipients(void) void ui_switch_win(ProfWin *win) {} -void ui_next_win(void) {} -void ui_previous_win(void) {} - void ui_gone_secure(const char * const barejid, gboolean trusted) {} void ui_gone_insecure(const char * const barejid) {} void ui_trust(const char * const barejid) {} From 01181780801a46ecc6996be5b75b2245c1c1b953 Mon Sep 17 00:00:00 2001 From: James Booth Date: Fri, 1 May 2015 00:55:40 +0100 Subject: [PATCH 188/252] Removed server event delegation functions --- src/event/server_events.c | 234 ------------------------------------- src/event/server_events.h | 38 ------ src/xmpp/iq.c | 77 +++++++----- src/xmpp/message.c | 12 +- src/xmpp/presence.c | 12 +- src/xmpp/roster.c | 11 +- tests/test_server_events.c | 76 ------------ tests/testsuite.c | 10 -- 8 files changed, 76 insertions(+), 394 deletions(-) diff --git a/src/event/server_events.c b/src/event/server_events.c index 56d5b11f..0e07e170 100644 --- a/src/event/server_events.c +++ b/src/event/server_events.c @@ -50,51 +50,6 @@ #include "ui/ui.h" -void -sv_ev_room_join_error(const char * const room, const char * const err) -{ - if (muc_active(room)) { - muc_leave(room); - } - ui_handle_room_join_error(room, err); -} - -// handle presence stanza errors -void -sv_ev_presence_error(const char *from, const char * const type, - const char *err_msg) -{ - // handle error from recipient - if (from != NULL) { - ui_handle_recipient_error(from, err_msg); - - // handle errors from no recipient - } else { - ui_handle_error(err_msg); - } -} - -// handle message stanza errors -void -sv_ev_message_error(const char * const jid, const char * const type, - const char * const err_msg) -{ - // handle errors from no recipient - if (jid == NULL) { - ui_handle_error(err_msg); - - // handle recipient not found ('from' contains a value and type is 'cancel') - } else if (type != NULL && (strcmp(type, "cancel") == 0)) { - log_info("Recipient %s not found: %s", jid, err_msg); - Jid *jidp = jid_create(jid); - chat_session_remove(jidp->barejid); - - // handle any other error from recipient - } else { - ui_handle_recipient_error(jid, err_msg); - } -} - void sv_ev_login_account_success(char *account_name) { @@ -147,112 +102,6 @@ sv_ev_failed_login(void) log_info("Login failed"); } -void -sv_ev_software_version_result(const char * const jid, const char * const presence, - const char * const name, const char * const version, const char * const os) -{ - cons_show_software_version(jid, presence, name, version, os); -} - -void -sv_ev_disco_info(const char *from, GSList *identities, GSList *features) -{ - cons_show_disco_info(from, identities, features); -} - -void -sv_ev_room_disco_info(const char * const room, GSList *identities, GSList *features, gboolean display) -{ - muc_set_features(room, features); - if (display) { - ui_show_room_disco_info(room, identities, features); - } -} - -void -sv_ev_disco_info_error(const char * const from, const char * const error) -{ - if (from) { - cons_show_error("Service discovery failed for %s: %s", from, error); - } else { - cons_show_error("Service discovery failed: %s", error); - } -} - -void -sv_ev_enable_carbons_error(const char * const error) -{ - cons_show_error("Server error enabling message carbons: %s", error); -} - -void -sv_ev_disable_carbons_error(const char * const error) -{ - cons_show_error("Server error disabling message carbons: %s", error); -} - -void -sv_ev_room_info_error(const char * const room, const char * const error) -{ - ui_handle_room_info_error(room, error); -} - -void -sv_ev_room_list(GSList *rooms, const char *conference_node) -{ - cons_show_room_list(rooms, conference_node); -} - -void -sv_ev_room_affiliation_list_result_error(const char * const room, const char * const affiliation, - const char * const error) -{ - log_debug("Error retrieving %s list for room %s: %s", affiliation, room, error); - ui_handle_room_affiliation_list_error(room, affiliation, error); -} - -void -sv_ev_room_affiliation_list(const char * const room, const char * const affiliation, GSList *jids) -{ - muc_jid_autocomplete_add_all(room, jids); - ui_handle_room_affiliation_list(room, affiliation, jids); -} - -void -sv_ev_room_role_set_error(const char * const room, const char * const nick, const char * const role, - const char * const error) -{ - log_debug("Error setting role %s list for room %s, user %s: %s", role, room, nick, error); - ui_handle_room_role_set_error(room, nick, role, error); -} - -void -sv_ev_room_role_list_result_error(const char * const room, const char * const role, const char * const error) -{ - log_debug("Error retrieving %s list for room %s: %s", role, room, error); - ui_handle_room_role_list_error(room, role, error); -} - -void -sv_ev_room_role_list(const char * const room, const char * const role, GSList *nicks) -{ - ui_handle_room_role_list(room, role, nicks); -} - -void -sv_ev_room_affiliation_set_error(const char * const room, const char * const jid, const char * const affiliation, - const char * const error) -{ - log_debug("Error setting affiliation %s list for room %s, user %s: %s", affiliation, room, jid, error); - ui_handle_room_affiliation_set_error(room, jid, affiliation, error); -} - -void -sv_ev_disco_items(GSList *items, const char *jid) -{ - cons_show_disco_items(items, jid); -} - void sv_ev_room_invite(jabber_invite_t invite_type, const char * const invitor, const char * const room, @@ -509,36 +358,6 @@ sv_ev_room_banned(const char * const room, const char * const actor, const char ui_room_banned(room, actor, reason); } -void -sv_ev_room_configure(const char * const room, DataForm *form) -{ - ui_handle_room_configuration(room, form); -} - -void -sv_ev_room_configuration_form_error(const char * const room, const char * const message) -{ - ui_handle_room_configuration_form_error(room, message); -} - -void -sv_ev_room_config_submit_result(const char * const room) -{ - ui_handle_room_config_submit_result(room); -} - -void -sv_ev_room_config_submit_result_error(const char * const room, const char * const message) -{ - ui_handle_room_config_submit_result_error(room, message); -} - -void -sv_ev_room_kick_result_error(const char * const room, const char * const nick, const char * const error) -{ - ui_handle_room_kick_error(room, nick, error); -} - void sv_ev_room_occupant_offline(const char * const room, const char * const nick, const char * const show, const char * const status) @@ -571,32 +390,6 @@ sv_ev_room_occupent_banned(const char * const room, const char * const nick, con occupantswin_occupants(room); } -void -sv_ev_group_add(const char * const contact, - const char * const group) -{ - ui_group_added(contact, group); -} - -void -sv_ev_group_remove(const char * const contact, - const char * const group) -{ - ui_group_removed(contact, group); -} - -void -sv_ev_roster_remove(const char * const barejid) -{ - ui_roster_remove(barejid); -} - -void -sv_ev_roster_add(const char * const barejid, const char * const name) -{ - ui_roster_add(barejid, name); -} - void sv_ev_roster_update(const char * const barejid, const char * const name, GSList *groups, const char * const subscription, gboolean pending_out) @@ -605,39 +398,12 @@ sv_ev_roster_update(const char * const barejid, const char * const name, rosterwin_roster(); } -void -sv_ev_autoping_cancel(void) -{ - prefs_set_autoping(0); - cons_show_error("Server ping not supported, autoping disabled."); -} - void sv_ev_xmpp_stanza(const char * const msg) { ui_handle_stanza(msg); } -void -sv_ev_ping_result(const char * const from, int millis) -{ - if (from == NULL) { - cons_show("Ping response from server: %dms.", millis); - } else { - cons_show("Ping response from %s: %dms.", from, millis); - } -} - -void -sv_ev_ping_error_result(const char * const from, const char * const error) -{ - if (error == NULL) { - cons_show_error("Error returned from pinging %s.", from); - } else { - cons_show_error("Error returned from pinging %s: %s.", from, error); - } -} - void sv_ev_muc_self_online(const char * const room, const char * const nick, gboolean config_required, const char * const role, const char * const affiliation, const char * const actor, const char * const reason, diff --git a/src/event/server_events.h b/src/event/server_events.h index daf885b3..c7cc9697 100644 --- a/src/event/server_events.h +++ b/src/event/server_events.h @@ -40,12 +40,6 @@ void sv_ev_login_account_success(char *account_name); void sv_ev_lost_connection(void); void sv_ev_failed_login(void); -void sv_ev_software_version_result(const char * const jid, const char * const presence, - const char * const name, const char * const version, const char * const os); -void sv_ev_disco_info(const char *from, GSList *identities, GSList *features); -void sv_ev_disco_info_error(const char * const from, const char * const error); -void sv_ev_room_list(GSList *rooms, const char *conference_node); -void sv_ev_disco_items(GSList *items, const char *jid); void sv_ev_room_invite(jabber_invite_t invite_type, const char * const invitor, const char * const room, const char * const reason, const char * const password); @@ -56,19 +50,6 @@ void sv_ev_room_history(const char * const room_jid, const char * const nick, GTimeVal tv_stamp, const char * const message); void sv_ev_room_message(const char * const room_jid, const char * const nick, const char * const message); -void sv_ev_room_join_error(const char * const room, const char * const err); -void sv_ev_room_info_error(const char * const room, const char * const error); -void sv_ev_room_disco_info(const char * const room, GSList *identities, GSList *features, gboolean display); -void sv_ev_room_affiliation_list_result_error(const char * const room, const char * const affiliation, - const char * const error); -void sv_ev_room_affiliation_list(const char * const room, const char * const affiliation, GSList *jids); -void sv_ev_room_affiliation_set_error(const char * const room, const char * const jid, const char * const affiliation, - const char * const error); -void sv_ev_room_role_list_result_error(const char * const from, const char * const role, const char * const error); -void sv_ev_room_role_list(const char * const from, const char * const role, GSList *nicks); -void sv_ev_room_role_set_error(const char * const room, const char * const nick, const char * const role, - const char * const error); -void sv_ev_room_kick_result_error(const char * const room, const char * const nick, const char * const error); void sv_ev_incoming_message(char *barejid, char *resource, char *message); void sv_ev_incoming_private_message(char *fulljid, char *message); void sv_ev_delayed_message(char *fulljid, char *message, GTimeVal tv_stamp); @@ -95,25 +76,8 @@ void sv_ev_room_occupent_kicked(const char * const room, const char * const nick void sv_ev_room_banned(const char * const room, const char * const actor, const char * const reason); void sv_ev_room_occupent_banned(const char * const room, const char * const nick, const char * const actor, const char * const reason); -void sv_ev_group_add(const char * const contact, - const char * const group); -void sv_ev_group_remove(const char * const contact, - const char * const group); -void sv_ev_roster_remove(const char * const barejid); -void sv_ev_roster_add(const char * const barejid, const char * const name); -void sv_ev_autoping_cancel(void); void sv_ev_carbon(char *barejid, char *message); -void sv_ev_message_error(const char * const from, const char * const type, - const char * const err_msg); -void sv_ev_presence_error(const char *from, const char * const type, - const char *err_msg); void sv_ev_xmpp_stanza(const char * const msg); -void sv_ev_ping_result(const char * const from, int millis); -void sv_ev_ping_error_result(const char * const from, const char * const error); -void sv_ev_room_configure(const char * const room, DataForm *form); -void sv_ev_room_configuration_form_error(const char * const from, const char * const message); -void sv_ev_room_config_submit_result(const char * const room); -void sv_ev_room_config_submit_result_error(const char * const room, const char * const message); void sv_ev_muc_self_online(const char * const room, const char * const nick, gboolean config_required, const char * const role, const char * const affiliation, const char * const actor, const char * const reason, const char * const jid, const char * const show, const char * const status); @@ -123,7 +87,5 @@ void sv_ev_muc_occupant_online(const char * const room, const char * const nick, void sv_ev_roster_update(const char * const barejid, const char * const name, GSList *groups, const char * const subscription, gboolean pending_out); void sv_ev_roster_received(void); -void sv_ev_enable_carbons_error(const char * const error); -void sv_ev_disable_carbons_error(const char * const error); #endif diff --git a/src/xmpp/iq.c b/src/xmpp/iq.c index 75286bf8..1a0f64a9 100644 --- a/src/xmpp/iq.c +++ b/src/xmpp/iq.c @@ -47,6 +47,7 @@ #include "log.h" #include "muc.h" #include "profanity.h" +#include "ui/ui.h" #include "config/preferences.h" #include "event/server_events.h" #include "xmpp/capabilities.h" @@ -515,7 +516,8 @@ _pong_handler(xmpp_conn_t *const conn, xmpp_stanza_t * const stanza, if (errtype != NULL) { if (strcmp(errtype, "cancel") == 0) { log_warning("Server ping (id=%s) error type 'cancel', disabling autoping.", id); - sv_ev_autoping_cancel(); + prefs_set_autoping(0); + cons_show_error("Server ping not supported, autoping disabled."); xmpp_timed_handler_delete(conn, _ping_timed_handler); } } @@ -739,7 +741,7 @@ _enable_carbons_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, char *type = xmpp_stanza_get_type(stanza); if (g_strcmp0(type, "error") == 0) { char *error_message = stanza_get_error_message(stanza); - sv_ev_enable_carbons_error(error_message); + cons_show_error("Server error enabling message carbons: %s", error_message); log_debug("Error enabling carbons: %s", error_message); } else { log_debug("Message carbons enabled."); @@ -754,7 +756,7 @@ _disable_carbons_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, char *type = xmpp_stanza_get_type(stanza); if (g_strcmp0(type, "error") == 0) { char *error_message = stanza_get_error_message(stanza); - sv_ev_disable_carbons_error(error_message); + cons_show_error("Server error disabling message carbons: %s", error_message); log_debug("Error disabling carbons: %s", error_message); } else { log_debug("Message carbons disabled."); @@ -774,7 +776,12 @@ _manual_pong_handler(xmpp_conn_t *const conn, xmpp_stanza_t * const stanza, // handle error responses if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) { char *error_message = stanza_get_error_message(stanza); - sv_ev_ping_error_result(from, error_message); + if (!error_message) { + cons_show_error("Error returned from pinging %s.", from); + } else { + cons_show_error("Error returned from pinging %s: %s.", from, error_message); + } + free(error_message); g_date_time_unref(sent); return 0; @@ -788,7 +795,11 @@ _manual_pong_handler(xmpp_conn_t *const conn, xmpp_stanza_t * const stanza, g_date_time_unref(sent); g_date_time_unref(now); - sv_ev_ping_result(from, elapsed_millis); + if (from == NULL) { + cons_show("Ping response from server: %dms.", elapsed_millis); + } else { + cons_show("Ping response from %s: %dms.", from, elapsed_millis); + } return 0; } @@ -865,7 +876,7 @@ _version_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, presence = string_from_resource_presence(resource->presence); } - sv_ev_software_version_result(jid, presence, name_str, version_str, os_str); + cons_show_software_version(jid, presence, name_str, version_str, os_str); jid_destroy(jidp); @@ -1085,40 +1096,40 @@ _room_config_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, // handle error responses if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) { char *error_message = stanza_get_error_message(stanza); - sv_ev_room_configuration_form_error(from, error_message); + ui_handle_room_configuration_form_error(from, error_message); free(error_message); return 0; } if (from == NULL) { log_warning("No from attribute for IQ config request result"); - sv_ev_room_configuration_form_error(from, "No from attribute for room cofig response."); + ui_handle_room_configuration_form_error(from, "No from attribute for room cofig response."); return 0; } xmpp_stanza_t *query = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_QUERY); if (query == NULL) { log_warning("No query element found parsing room config response"); - sv_ev_room_configuration_form_error(from, "No query element found parsing room config response"); + ui_handle_room_configuration_form_error(from, "No query element found parsing room config response"); return 0; } xmpp_stanza_t *x = xmpp_stanza_get_child_by_ns(query, STANZA_NS_DATA); if (x == NULL) { log_warning("No x element found with %s namespace parsing room config response", STANZA_NS_DATA); - sv_ev_room_configuration_form_error(from, "No form configuration options available"); + ui_handle_room_configuration_form_error(from, "No form configuration options available"); return 0; } char *form_type = xmpp_stanza_get_attribute(x, STANZA_ATTR_TYPE); if (g_strcmp0(form_type, "form") != 0) { log_warning("x element not of type 'form' parsing room config response"); - sv_ev_room_configuration_form_error(from, "Form not of type 'form' parsing room config response."); + ui_handle_room_configuration_form_error(from, "Form not of type 'form' parsing room config response."); return 0; } DataForm *form = form_create(x); - sv_ev_room_configure(from, form); + ui_handle_room_configuration(from, form); return 0; } @@ -1140,7 +1151,8 @@ static int _room_affiliation_set_result_handler(xmpp_conn_t * const conn, xmpp_s // handle error responses if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) { char *error_message = stanza_get_error_message(stanza); - sv_ev_room_affiliation_set_error(from, affiliation_set->item, affiliation_set->privilege, error_message); + log_debug("Error setting affiliation %s list for room %s, user %s: %s", affiliation_set->privilege, from, affiliation_set->item, error_message); + ui_handle_room_affiliation_set_error(from, affiliation_set->item, affiliation_set->privilege, error_message); free(error_message); } @@ -1168,7 +1180,8 @@ static int _room_role_set_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t // handle error responses if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) { char *error_message = stanza_get_error_message(stanza); - sv_ev_room_role_set_error(from, role_set->item, role_set->privilege, error_message); + log_debug("Error setting role %s list for room %s, user %s: %s", role_set->privilege, from, role_set->item, error_message); + ui_handle_room_role_set_error(from, role_set->item, role_set->privilege, error_message); free(error_message); } @@ -1196,7 +1209,8 @@ _room_affiliation_list_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * // handle error responses if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) { char *error_message = stanza_get_error_message(stanza); - sv_ev_room_affiliation_list_result_error(from, affiliation, error_message); + log_debug("Error retrieving %s list for room %s: %s", affiliation, from, error_message); + ui_handle_room_affiliation_list_error(from, affiliation, error_message); free(error_message); free(affiliation); return 0; @@ -1218,7 +1232,8 @@ _room_affiliation_list_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * } } - sv_ev_room_affiliation_list(from, affiliation, jids); + muc_jid_autocomplete_add_all(from, jids); + ui_handle_room_affiliation_list(from, affiliation, jids); free(affiliation); g_slist_free(jids); @@ -1242,7 +1257,8 @@ _room_role_list_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const s // handle error responses if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) { char *error_message = stanza_get_error_message(stanza); - sv_ev_room_role_list_result_error(from, role, error_message); + log_debug("Error retrieving %s list for room %s: %s", role, from, error_message); + ui_handle_room_role_list_error(from, role, error_message); free(error_message); free(role); return 0; @@ -1264,7 +1280,7 @@ _room_role_list_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const s } } - sv_ev_room_role_list(from, role, nicks); + ui_handle_room_role_list(from, role, nicks); free(role); g_slist_free(nicks); @@ -1288,12 +1304,12 @@ _room_config_submit_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stan // handle error responses if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) { char *error_message = stanza_get_error_message(stanza); - sv_ev_room_config_submit_result_error(from, error_message); + ui_handle_room_config_submit_result_error(from, error_message); free(error_message); return 0; } - sv_ev_room_config_submit_result(from); + ui_handle_room_config_submit_result(from); return 0; } @@ -1315,7 +1331,7 @@ _room_kick_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza // handle error responses if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) { char *error_message = stanza_get_error_message(stanza); - sv_ev_room_kick_result_error(from, nick, error_message); + ui_handle_room_kick_error(from, nick, error_message); free(error_message); free(nick); return 0; @@ -1359,7 +1375,7 @@ _room_info_response_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stan if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) { if (cb_data->display) { char *error_message = stanza_get_error_message(stanza); - sv_ev_room_info_error(cb_data->room, error_message); + ui_handle_room_info_error(cb_data->room, error_message); free(error_message); } free(cb_data->room); @@ -1411,7 +1427,10 @@ _room_info_response_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stan child = xmpp_stanza_get_next(child); } - sv_ev_room_disco_info(cb_data->room, identities, features, cb_data->display); + muc_set_features(cb_data->room, features); + if (cb_data->display) { + ui_show_room_disco_info(cb_data->room, identities, features); + } g_slist_free_full(features, free); g_slist_free_full(identities, (GDestroyNotify)_identity_destroy); @@ -1439,7 +1458,11 @@ _disco_info_response_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const sta // handle error responses if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) { char *error_message = stanza_get_error_message(stanza); - sv_ev_disco_info_error(from, error_message); + if (from) { + cons_show_error("Service discovery failed for %s: %s", from, error_message); + } else { + cons_show_error("Service discovery failed: %s", error_message); + } free(error_message); return 0; } @@ -1488,7 +1511,7 @@ _disco_info_response_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const sta child = xmpp_stanza_get_next(child); } - sv_ev_disco_info(from, identities, features); + cons_show_disco_info(from, identities, features); g_slist_free_full(features, free); g_slist_free_full(identities, (GDestroyNotify)_identity_destroy); @@ -1536,9 +1559,9 @@ _disco_items_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stan } if (g_strcmp0(id, "confreq") == 0) { - sv_ev_room_list(items, from); + cons_show_room_list(items, from); } else if (g_strcmp0(id, "discoitemsreq") == 0) { - sv_ev_disco_items(items, from); + cons_show_disco_items(items, from); } g_slist_free_full(items, (GDestroyNotify)_item_destroy); diff --git a/src/xmpp/message.c b/src/xmpp/message.c index c9464e2f..57d99919 100644 --- a/src/xmpp/message.c +++ b/src/xmpp/message.c @@ -42,6 +42,7 @@ #include "log.h" #include "muc.h" #include "profanity.h" +#include "ui/ui.h" #include "event/server_events.h" #include "xmpp/connection.h" #include "xmpp/message.h" @@ -299,7 +300,16 @@ _message_error_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, g_string_free(log_msg, TRUE); - sv_ev_message_error(jid, type, err_msg); + if (!jid) { + ui_handle_error(err_msg); + } else if (type && (strcmp(type, "cancel") == 0)) { + log_info("Recipient %s not found: %s", jid, err_msg); + Jid *jidp = jid_create(jid); + chat_session_remove(jidp->barejid); + jid_destroy(jidp); + } else { + ui_handle_recipient_error(jid, err_msg); + } free(err_msg); diff --git a/src/xmpp/presence.c b/src/xmpp/presence.c index 123717cc..0c6702b3 100644 --- a/src/xmpp/presence.c +++ b/src/xmpp/presence.c @@ -44,6 +44,7 @@ #include "log.h" #include "muc.h" #include "profanity.h" +#include "ui/ui.h" #include "event/server_events.h" #include "xmpp/capabilities.h" #include "xmpp/connection.h" @@ -372,7 +373,10 @@ _presence_error_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, } log_info("Error joining room: %s, reason: %s", fulljid->barejid, error_cond); - sv_ev_room_join_error(fulljid->barejid, error_cond); + if (muc_active(fulljid->barejid)) { + muc_leave(fulljid->barejid); + } + ui_handle_room_join_error(fulljid->barejid, error_cond); jid_destroy(fulljid); return 1; } @@ -400,7 +404,11 @@ _presence_error_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, g_string_free(log_msg, TRUE); - sv_ev_presence_error(from, type, err_msg); + if (from != NULL) { + ui_handle_recipient_error(from, err_msg); + } else { + ui_handle_error(err_msg); + } free(err_msg); diff --git a/src/xmpp/roster.c b/src/xmpp/roster.c index 91330f1b..84561ecf 100644 --- a/src/xmpp/roster.c +++ b/src/xmpp/roster.c @@ -41,6 +41,7 @@ #include "log.h" #include "profanity.h" +#include "ui/ui.h" #include "event/server_events.h" #include "tools/autocomplete.h" #include "xmpp/connection.h" @@ -163,7 +164,7 @@ _group_add_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, { if (userdata != NULL) { GroupData *data = userdata; - sv_ev_group_add(data->name, data->group); + ui_group_added(data->name, data->group); free(data->name); free(data->group); free(userdata); @@ -210,7 +211,7 @@ _group_remove_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, { if (userdata != NULL) { GroupData *data = userdata; - sv_ev_group_remove(data->name, data->group); + ui_group_removed(data->name, data->group); free(data->name); free(data->group); free(userdata); @@ -257,10 +258,8 @@ _roster_set_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, if (name == NULL) { name = barejid_lower; } - roster_remove(name, barejid_lower); - - sv_ev_roster_remove(barejid_lower); + ui_roster_remove(barejid_lower); // otherwise update local roster } else { @@ -278,7 +277,7 @@ _roster_set_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, if (contact == NULL) { gboolean added = roster_add(barejid_lower, name, groups, sub, pending_out); if (added) { - sv_ev_roster_add(barejid_lower, name); + ui_roster_add(barejid_lower, name); } } else { sv_ev_roster_update(barejid_lower, name, groups, sub, pending_out); diff --git a/tests/test_server_events.c b/tests/test_server_events.c index ffff74f9..d87dc217 100644 --- a/tests/test_server_events.c +++ b/tests/test_server_events.c @@ -101,82 +101,6 @@ void console_shows_dnd_presence_when_set_all(void **state) roster_clear(); } -void handle_message_error_when_no_recipient(void **state) -{ - char *err_msg = "Some error."; - char *from = NULL; - char *type = "cancel"; - - expect_string(ui_handle_error, err_msg, err_msg); - - sv_ev_message_error(from, type, err_msg); -} - -void handle_message_error_when_recipient_cancel(void **state) -{ - char *err_msg = "Some error."; - char *from = "bob@server.com"; - char *type = "cancel"; - - prefs_set_boolean(PREF_STATES, FALSE); - chat_sessions_init(); - - sv_ev_message_error(from, type, err_msg); -} - -void handle_message_error_when_recipient_cancel_disables_chat_session(void **state) -{ - char *err_msg = "Some error."; - char *barejid = "bob@server.com"; - char *resource = "resource"; - char *type = "cancel"; - - prefs_set_boolean(PREF_STATES, TRUE); - chat_sessions_init(); - chat_session_recipient_active(barejid, resource, FALSE); - - sv_ev_message_error(barejid, type, err_msg); - ChatSession *session = chat_session_get(barejid); - - assert_null(session); - chat_sessions_clear(); -} - -void handle_message_error_when_recipient_and_no_type(void **state) -{ - char *err_msg = "Some error."; - char *from = "bob@server.com"; - char *type = NULL; - - expect_string(ui_handle_recipient_error, recipient, from); - expect_string(ui_handle_recipient_error, err_msg, err_msg); - - sv_ev_message_error(from, type, err_msg); -} - -void handle_presence_error_when_no_recipient(void **state) -{ - char *err_msg = "Some error."; - char *from = NULL; - char *type = NULL; - - expect_string(ui_handle_error, err_msg, err_msg); - - sv_ev_presence_error(from, type, err_msg); -} - -void handle_presence_error_when_from_recipient(void **state) -{ - char *err_msg = "Some error."; - char *from = "bob@server.com"; - char *type = NULL; - - expect_string(ui_handle_recipient_error, recipient, from); - expect_string(ui_handle_recipient_error, err_msg, err_msg); - - sv_ev_presence_error(from, type, err_msg); -} - void handle_offline_removes_chat_session(void **state) { chat_sessions_init(); diff --git a/tests/testsuite.c b/tests/testsuite.c index b4ce1c0a..91fd54e3 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -443,16 +443,6 @@ int main(int argc, char* argv[]) { unit_test_setup_teardown(console_shows_dnd_presence_when_set_all, load_preferences, close_preferences), - unit_test(handle_message_error_when_no_recipient), - unit_test_setup_teardown(handle_message_error_when_recipient_cancel, - load_preferences, - close_preferences), - unit_test_setup_teardown(handle_message_error_when_recipient_cancel_disables_chat_session, - load_preferences, - close_preferences), - unit_test(handle_message_error_when_recipient_and_no_type), - unit_test(handle_presence_error_when_no_recipient), - unit_test(handle_presence_error_when_from_recipient), unit_test(handle_offline_removes_chat_session), unit_test(lost_connection_clears_chat_sessions), From be4ee40ed4566680b15385f6fc736402612e8812 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 2 May 2015 23:23:12 +0100 Subject: [PATCH 189/252] Pass ProfChatWin to otr_on_message_send --- src/event/client_events.c | 6 +---- src/otr/otr.c | 46 +++++++++++++++------------------------ src/otr/otr.h | 11 ++-------- tests/otr/stub_otr.c | 11 +--------- 4 files changed, 22 insertions(+), 52 deletions(-) diff --git a/src/event/client_events.c b/src/event/client_events.c index f3c67f63..ea327ca1 100644 --- a/src/event/client_events.c +++ b/src/event/client_events.c @@ -66,11 +66,7 @@ cl_ev_send_msg(ProfChatWin *chatwin, const char * const msg) chat_state_active(chatwin->state); #ifdef HAVE_LIBOTR - prof_otrsendres_t res = otr_on_message_send(chatwin->barejid, msg); - if (res != PROF_OTRSUCCESS) { - char *errmsg = otr_senderror_str(res); - ui_win_error_line((ProfWin*)chatwin, errmsg); - } + otr_on_message_send(chatwin, msg); #else char *id = message_send_chat(chatwin->barejid, msg); chat_log_msg_out(chatwin->barejid, msg); diff --git a/src/otr/otr.c b/src/otr/otr.c index 46ad491c..ae8ed006 100644 --- a/src/otr/otr.c +++ b/src/otr/otr.c @@ -313,43 +313,43 @@ otr_on_message_recv(const char * const barejid, const char * const resource, con otr_free_message(decrypted); } -prof_otrsendres_t -otr_on_message_send(const char * const barejid, const char * const message) +void +otr_on_message_send(ProfChatWin *chatwin, const char * const message) { char *id = NULL; - prof_otrpolicy_t policy = otr_get_policy(barejid); + prof_otrpolicy_t policy = otr_get_policy(chatwin->barejid); - if (otr_is_secure(barejid)) { - char *encrypted = otr_encrypt_message(barejid, message); + if (otr_is_secure(chatwin->barejid)) { + char *encrypted = otr_encrypt_message(chatwin->barejid, message); if (encrypted) { - id = message_send_chat_encrypted(barejid, encrypted); - chat_log_otr_msg_out(barejid, message); - ui_outgoing_chat_msg(barejid, message, id); + id = message_send_chat_encrypted(chatwin->barejid, encrypted); + chat_log_otr_msg_out(chatwin->barejid, message); + ui_outgoing_chat_msg(chatwin->barejid, message, id); otr_free_message(encrypted); } else { - return PROF_OTRENCFAIL; + ui_win_error_line((ProfWin*)chatwin, "Failed to encrypt and send message."); + return; } } else if (policy == PROF_OTRPOLICY_ALWAYS) { - return PROF_OTRPOLICYFAIL; + ui_win_error_line((ProfWin*)chatwin, "Failed to send message. OTR policy set to: always"); + return; } else if (policy == PROF_OTRPOLICY_OPPORTUNISTIC) { char *otr_tagged_msg = otr_tag_message(message); - id = message_send_chat_encrypted(barejid, otr_tagged_msg); - ui_outgoing_chat_msg(barejid, message, id); - chat_log_msg_out(barejid, message); + id = message_send_chat_encrypted(chatwin->barejid, otr_tagged_msg); + ui_outgoing_chat_msg(chatwin->barejid, message, id); + chat_log_msg_out(chatwin->barejid, message); free(otr_tagged_msg); } else { - id = message_send_chat(barejid, message); - ui_outgoing_chat_msg(barejid, message, id); - chat_log_msg_out(barejid, message); + id = message_send_chat(chatwin->barejid, message); + ui_outgoing_chat_msg(chatwin->barejid, message, id); + chat_log_msg_out(chatwin->barejid, message); } free(id); - - return PROF_OTRSUCCESS; } void @@ -743,16 +743,6 @@ otr_decrypt_message(const char * const from, const char * const message, gboolea } } -char* -otr_senderror_str(prof_otrsendres_t res) -{ - switch (res) { - case PROF_OTRENCFAIL: return "Failed to encrypt and send message."; - case PROF_OTRPOLICYFAIL: return "Failed to send message. OTR policy set to: always"; - default: return "Unknown OTR error."; - } -} - void otr_free_message(char *message) { diff --git a/src/otr/otr.h b/src/otr/otr.h index 6f1103df..e020c0c8 100644 --- a/src/otr/otr.h +++ b/src/otr/otr.h @@ -39,6 +39,7 @@ #include #include "config/accounts.h" +#include "ui/window.h" typedef enum { PROF_OTRPOLICY_MANUAL, @@ -46,12 +47,6 @@ typedef enum { PROF_OTRPOLICY_ALWAYS } prof_otrpolicy_t; -typedef enum { - PROF_OTRENCFAIL, - PROF_OTRPOLICYFAIL, - PROF_OTRSUCCESS -} prof_otrsendres_t; - OtrlUserState otr_userstate(void); OtrlMessageAppOps* otr_messageops(void); GHashTable* otr_smpinitators(void); @@ -64,7 +59,7 @@ void otr_poll(void); void otr_on_connect(ProfAccount *account); void otr_on_message_recv(const char * const barejid, const char * const resource, const char * const message); -prof_otrsendres_t otr_on_message_send(const char * const barejid, const char * const message); +void otr_on_message_send(ProfChatWin *chatwin, const char * const message); void otr_keygen(ProfAccount *account); @@ -94,6 +89,4 @@ void otr_free_message(char *message); prof_otrpolicy_t otr_get_policy(const char * const recipient); -char* otr_senderror_str(prof_otrsendres_t res); - #endif diff --git a/tests/otr/stub_otr.c b/tests/otr/stub_otr.c index 9815957f..482f0a7f 100644 --- a/tests/otr/stub_otr.c +++ b/tests/otr/stub_otr.c @@ -42,10 +42,7 @@ char* otr_start_query(void) void otr_poll(void) {} void otr_on_connect(ProfAccount *account) {} void otr_on_message_recv(const char * const barejid, const char * const resource, const char * const message) {} -prof_otrsendres_t otr_on_message_send(const char * const barejid, const char * const message) -{ - return PROF_OTRSUCCESS; -} +void otr_on_message_send(ProfChatWin *chatwin, const char * const message) {} void otr_keygen(ProfAccount *account) { @@ -109,9 +106,3 @@ prof_otrpolicy_t otr_get_policy(const char * const recipient) { return PROF_OTRPOLICY_MANUAL; } - -char* otr_senderror_str(prof_otrsendres_t res) -{ - return NULL; -} - From ddc64755a0c89cad6041ff7fbf91ba1b2ae4a818 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 2 May 2015 23:40:14 +0100 Subject: [PATCH 190/252] Tidy message.c --- src/xmpp/message.c | 130 +++++++++++++++++++++------------------------ 1 file changed, 62 insertions(+), 68 deletions(-) diff --git a/src/xmpp/message.c b/src/xmpp/message.c index 57d99919..334e0ec7 100644 --- a/src/xmpp/message.c +++ b/src/xmpp/message.c @@ -53,18 +53,12 @@ #define HANDLE(ns, type, func) xmpp_handler_add(conn, func, ns, STANZA_NAME_MESSAGE, type, ctx) -static int _groupchat_handler(xmpp_conn_t * const conn, - xmpp_stanza_t * const stanza, void * const userdata); -static int _chat_handler(xmpp_conn_t * const conn, - xmpp_stanza_t * const stanza, void * const userdata); -static int _muc_user_handler(xmpp_conn_t * const conn, - xmpp_stanza_t * const stanza, void * const userdata); -static int _conference_handler(xmpp_conn_t * const conn, - xmpp_stanza_t * const stanza, void * const userdata); -static int _captcha_handler(xmpp_conn_t * const conn, - xmpp_stanza_t * const stanza, void * const userdata); -static int _message_error_handler(xmpp_conn_t * const conn, - xmpp_stanza_t * const stanza, void * const userdata); +static int _groupchat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata); +static int _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata); +static int _muc_user_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata); +static int _conference_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata); +static int _captcha_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata); +static int _message_error_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata); void message_add_handlers(void) @@ -273,7 +267,7 @@ _message_error_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, char *jid = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); xmpp_stanza_t *error_stanza = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_ERROR); char *type = NULL; - if (error_stanza != NULL) { + if (error_stanza) { type = xmpp_stanza_get_attribute(error_stanza, STANZA_ATTR_TYPE); } @@ -281,15 +275,15 @@ _message_error_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, char *err_msg = stanza_get_error_message(stanza); GString *log_msg = g_string_new("message stanza error received"); - if (id != NULL) { + if (id) { g_string_append(log_msg, " id="); g_string_append(log_msg, id); } - if (jid != NULL) { + if (jid) { g_string_append(log_msg, " from="); g_string_append(log_msg, jid); } - if (type != NULL) { + if (type) { g_string_append(log_msg, " type="); g_string_append(log_msg, type); } @@ -324,46 +318,48 @@ _muc_user_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, xmpp_stanza_t *xns_muc_user = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_MUC_USER); char *room = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); - if (room == NULL) { + if (!room) { log_warning("Message received with no from attribute, ignoring"); return 1; } // XEP-0045 xmpp_stanza_t *invite = xmpp_stanza_get_child_by_name(xns_muc_user, STANZA_NAME_INVITE); - if (invite != NULL) { - char *invitor_jid = xmpp_stanza_get_attribute(invite, STANZA_ATTR_FROM); - if (invitor_jid == NULL) { - log_warning("Chat room invite received with no from attribute"); - return 1; - } + if (!invite) { + return 1; + } - Jid *jidp = jid_create(invitor_jid); - if (jidp == NULL) { - return 1; - } - char *invitor = jidp->barejid; + char *invitor_jid = xmpp_stanza_get_attribute(invite, STANZA_ATTR_FROM); + if (!invitor_jid) { + log_warning("Chat room invite received with no from attribute"); + return 1; + } - char *reason = NULL; - xmpp_stanza_t *reason_st = xmpp_stanza_get_child_by_name(invite, STANZA_NAME_REASON); - if (reason_st != NULL) { - reason = xmpp_stanza_get_text(reason_st); - } + Jid *jidp = jid_create(invitor_jid); + if (!jidp) { + return 1; + } + char *invitor = jidp->barejid; - char *password = NULL; - xmpp_stanza_t *password_st = xmpp_stanza_get_child_by_name(xns_muc_user, STANZA_NAME_PASSWORD); - if (password_st) { - password = xmpp_stanza_get_text(password_st); - } + char *reason = NULL; + xmpp_stanza_t *reason_st = xmpp_stanza_get_child_by_name(invite, STANZA_NAME_REASON); + if (reason_st) { + reason = xmpp_stanza_get_text(reason_st); + } - sv_ev_room_invite(INVITE_MEDIATED, invitor, room, reason, password); - jid_destroy(jidp); - if (reason) { - xmpp_free(ctx, reason); - } - if (password) { - xmpp_free(ctx, password); - } + char *password = NULL; + xmpp_stanza_t *password_st = xmpp_stanza_get_child_by_name(xns_muc_user, STANZA_NAME_PASSWORD); + if (password_st) { + password = xmpp_stanza_get_text(password_st); + } + + sv_ev_room_invite(INVITE_MEDIATED, invitor, room, reason, password); + jid_destroy(jidp); + if (reason) { + xmpp_free(ctx, reason); + } + if (password) { + xmpp_free(ctx, password); } return 1; @@ -380,19 +376,19 @@ _conference_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, char *reason = NULL; char *password = NULL; - if (from == NULL) { + if (!from) { log_warning("Message received with no from attribute, ignoring"); return 1; } // XEP-0249 room = xmpp_stanza_get_attribute(xns_conference, STANZA_ATTR_JID); - if (room == NULL) { + if (!room) { return 1; } Jid *jidp = jid_create(from); - if (jidp == NULL) { + if (!jidp) { return 1; } invitor = jidp->barejid; @@ -414,16 +410,16 @@ _captcha_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, xmpp_ctx_t *ctx = connection_get_ctx(); char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); - if (from == NULL) { + if (!from) { log_warning("Message received with no from attribute, ignoring"); return 1; } // XEP-0158 xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_BODY); - if (body != NULL) { + if (body) { char *message = xmpp_stanza_get_text(body); - if (message != NULL) { + if (message) { sv_ev_room_broadcast(from, message); xmpp_free(ctx, message); } @@ -443,7 +439,7 @@ _groupchat_handler(xmpp_conn_t * const conn, // handle room subject xmpp_stanza_t *subject = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_SUBJECT); - if (subject != NULL) { + if (subject) { message = xmpp_stanza_get_text(subject); sv_ev_room_subject(jid->barejid, jid->resourcepart, message); xmpp_free(ctx, message); @@ -453,11 +449,11 @@ _groupchat_handler(xmpp_conn_t * const conn, } // handle room broadcasts - if (jid->resourcepart == NULL) { + if (!jid->resourcepart) { xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_BODY); - if (body != NULL) { + if (body) { message = xmpp_stanza_get_text(body); - if (message != NULL) { + if (message) { sv_ev_room_broadcast(room_jid, message); xmpp_free(ctx, message); } @@ -486,9 +482,9 @@ _groupchat_handler(xmpp_conn_t * const conn, xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_BODY); // check for and deal with message - if (body != NULL) { + if (body) { message = xmpp_stanza_get_text(body); - if (message != NULL) { + if (message) { if (delayed) { sv_ev_room_history(jid->barejid, jid->resourcepart, tv_stamp, message); } else { @@ -556,7 +552,7 @@ _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, // check if carbon message xmpp_stanza_t *carbons = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_CARBONS); - if(carbons) { + if (carbons) { char *name = xmpp_stanza_get_name(carbons); if ((g_strcmp0(name, "received") == 0) || (g_strcmp0(name, "sent")) == 0){ xmpp_stanza_t *forwarded = xmpp_stanza_get_child_by_ns(carbons, STANZA_NS_FORWARD); @@ -568,9 +564,7 @@ _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, gchar *from = xmpp_stanza_get_attribute(message, STANZA_ATTR_FROM); // happens when receive a carbon of a self sent message - if(to == NULL) { - to = from; - } + if (!to) to = from; Jid *jid_from = jid_create(from); Jid *jid_to = jid_create(to); @@ -578,9 +572,9 @@ _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, // check for and deal with message xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(message, STANZA_NAME_BODY); - if (body != NULL) { + if (body) { char *message = xmpp_stanza_get_text(body); - if (message != NULL) { + if (message) { // if we are the recipient, treat as standard incoming message if(g_strcmp0(my_jid->barejid, jid_to->barejid) == 0){ sv_ev_incoming_message(jid_from->barejid, jid_from->resourcepart, message); @@ -621,9 +615,9 @@ _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, // check for and deal with message xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_BODY); - if (body != NULL) { + if (body) { char *message = xmpp_stanza_get_text(body); - if (message != NULL) { + if (message) { if (delayed) { sv_ev_delayed_private_message(jid->str, message, tv_stamp); } else { @@ -645,9 +639,9 @@ _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, // check for and deal with message xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_BODY); - if (body != NULL) { + if (body) { char *message = xmpp_stanza_get_text(body); - if (message != NULL) { + if (message) { if (delayed) { sv_ev_delayed_message(jid->barejid, message, tv_stamp); } else { From 5a90e2862e3d11ec86a34b990be7b87a03c7f01f Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 3 May 2015 00:05:47 +0100 Subject: [PATCH 191/252] Extracted receipt received handler --- src/xmpp/message.c | 64 ++++++++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 30 deletions(-) diff --git a/src/xmpp/message.c b/src/xmpp/message.c index 334e0ec7..67a1103d 100644 --- a/src/xmpp/message.c +++ b/src/xmpp/message.c @@ -59,6 +59,7 @@ static int _muc_user_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const sta static int _conference_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata); static int _captcha_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata); static int _message_error_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata); +static int _receipt_received_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata); void message_add_handlers(void) @@ -72,6 +73,7 @@ message_add_handlers(void) HANDLE(STANZA_NS_MUC_USER, NULL, _muc_user_handler); HANDLE(STANZA_NS_CONFERENCE, NULL, _conference_handler); HANDLE(STANZA_NS_CAPTCHA, NULL, _captcha_handler); + HANDLE(STANZA_NS_RECEIPTS, NULL, _receipt_received_handler); } char * @@ -260,8 +262,7 @@ message_send_gone(const char * const jid) } static int -_message_error_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, - void * const userdata) +_message_error_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { char *id = xmpp_stanza_get_id(stanza); char *jid = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); @@ -311,8 +312,7 @@ _message_error_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, } static int -_muc_user_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, - void * const userdata) +_muc_user_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { xmpp_ctx_t *ctx = connection_get_ctx(); xmpp_stanza_t *xns_muc_user = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_MUC_USER); @@ -366,8 +366,7 @@ _muc_user_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, } static int -_conference_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, - void * const userdata) +_conference_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { xmpp_stanza_t *xns_conference = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_CONFERENCE); char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); @@ -404,8 +403,7 @@ _conference_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, } static int -_captcha_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, - void * const userdata) +_captcha_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { xmpp_ctx_t *ctx = connection_get_ctx(); char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); @@ -429,8 +427,7 @@ _captcha_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, } static int -_groupchat_handler(xmpp_conn_t * const conn, - xmpp_stanza_t * const stanza, void * const userdata) +_groupchat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { xmpp_ctx_t *ctx = connection_get_ctx(); char *message = NULL; @@ -523,8 +520,33 @@ _message_send_receipt(const char * const fulljid, const char * const message_id) } static int -_chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, - void * const userdata) +_receipt_received_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) +{ + xmpp_stanza_t *receipt = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_RECEIPTS); + char *name = xmpp_stanza_get_name(receipt); + if (g_strcmp0(name, "received") != 0) { + return 1; + } + + char *id = xmpp_stanza_get_attribute(receipt, STANZA_ATTR_ID); + if (!id) { + return 1; + } + + char *fulljid = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); + if (!fulljid) { + return 1; + } + + Jid *jidp = jid_create(fulljid); + sv_ev_message_receipt(jidp->barejid, id); + jid_destroy(jidp); + + return 1; +} + +static int +_chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { // ignore if type not chat or absent char *type = xmpp_stanza_get_type(stanza); @@ -532,24 +554,6 @@ _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, return 1; } - // check if message receipt - xmpp_stanza_t *receipt = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_RECEIPTS); - if (receipt) { - char *name = xmpp_stanza_get_name(receipt); - if (g_strcmp0(name, "received") == 0) { - char *id = xmpp_stanza_get_attribute(receipt, STANZA_ATTR_ID); - if (id) { - char *fulljid = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); - if (fulljid) { - Jid *jidp = jid_create(fulljid); - sv_ev_message_receipt(jidp->barejid, id); - jid_destroy(jidp); - return 1; - } - } - } - } - // check if carbon message xmpp_stanza_t *carbons = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_CARBONS); if (carbons) { From 236c854419d893c4dd0326afc9c9eabcbfe8dd0b Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 3 May 2015 00:35:31 +0100 Subject: [PATCH 192/252] Tidy message.c --- src/xmpp/message.c | 90 +++++++++++++++++++++++++--------------------- 1 file changed, 50 insertions(+), 40 deletions(-) diff --git a/src/xmpp/message.c b/src/xmpp/message.c index 67a1103d..26c266cd 100644 --- a/src/xmpp/message.c +++ b/src/xmpp/message.c @@ -369,34 +369,28 @@ static int _conference_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { xmpp_stanza_t *xns_conference = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_CONFERENCE); - char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); - char *room = NULL; - char *invitor = NULL; - char *reason = NULL; - char *password = NULL; + char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); if (!from) { log_warning("Message received with no from attribute, ignoring"); return 1; } - // XEP-0249 - room = xmpp_stanza_get_attribute(xns_conference, STANZA_ATTR_JID); - if (!room) { - return 1; - } - Jid *jidp = jid_create(from); if (!jidp) { return 1; } - invitor = jidp->barejid; - reason = xmpp_stanza_get_attribute(xns_conference, STANZA_ATTR_REASON); - password = xmpp_stanza_get_attribute(xns_conference, STANZA_ATTR_PASSWORD); + // XEP-0249 + char *room = xmpp_stanza_get_attribute(xns_conference, STANZA_ATTR_JID); + if (!room) { + return 1; + } - sv_ev_room_invite(INVITE_DIRECT, invitor, room, reason, password); + char *reason = xmpp_stanza_get_attribute(xns_conference, STANZA_ATTR_REASON); + char *password = xmpp_stanza_get_attribute(xns_conference, STANZA_ATTR_PASSWORD); + sv_ev_room_invite(INVITE_DIRECT, jidp->barejid, room, reason, password); jid_destroy(jidp); return 1; @@ -415,14 +409,18 @@ _captcha_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * // XEP-0158 xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_BODY); - if (body) { - char *message = xmpp_stanza_get_text(body); - if (message) { - sv_ev_room_broadcast(from, message); - xmpp_free(ctx, message); - } + if (!body) { + return 1; } + char *message = xmpp_stanza_get_text(body); + if (!message) { + return 1; + } + + sv_ev_room_broadcast(from, message); + xmpp_free(ctx, message); + return 1; } @@ -448,14 +446,20 @@ _groupchat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void // handle room broadcasts if (!jid->resourcepart) { xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_BODY); - if (body) { - message = xmpp_stanza_get_text(body); - if (message) { - sv_ev_room_broadcast(room_jid, message); - xmpp_free(ctx, message); - } + if (!body) { + jid_destroy(jid); + return 1; } + message = xmpp_stanza_get_text(body); + if (!message) { + jid_destroy(jid); + return 1; + } + + sv_ev_room_broadcast(room_jid, message); + xmpp_free(ctx, message); + jid_destroy(jid); return 1; } @@ -473,24 +477,30 @@ _groupchat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void return 1; } - // determine if the notifications happened whilst offline - GTimeVal tv_stamp; - gboolean delayed = stanza_get_delay(stanza, &tv_stamp); xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_BODY); // check for and deal with message - if (body) { - message = xmpp_stanza_get_text(body); - if (message) { - if (delayed) { - sv_ev_room_history(jid->barejid, jid->resourcepart, tv_stamp, message); - } else { - sv_ev_room_message(jid->barejid, jid->resourcepart, message); - } - xmpp_free(ctx, message); - } + if (!body) { + jid_destroy(jid); + return 1; } + message = xmpp_stanza_get_text(body); + if (!message) { + jid_destroy(jid); + return 1; + } + + // determine if the notifications happened whilst offline + GTimeVal tv_stamp; + gboolean delayed = stanza_get_delay(stanza, &tv_stamp); + if (delayed) { + sv_ev_room_history(jid->barejid, jid->resourcepart, tv_stamp, message); + } else { + sv_ev_room_message(jid->barejid, jid->resourcepart, message); + } + + xmpp_free(ctx, message); jid_destroy(jid); return 1; From 530c060d2aa578bfbb9969ba6e56340830138dfc Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 3 May 2015 01:25:33 +0100 Subject: [PATCH 193/252] Extract private message hanlding in message.c --- src/event/server_events.c | 4 +- src/event/server_events.h | 4 +- src/xmpp/message.c | 155 ++++++++++++++++++++------------------ 3 files changed, 84 insertions(+), 79 deletions(-) diff --git a/src/event/server_events.c b/src/event/server_events.c index 0e07e170..03d53901 100644 --- a/src/event/server_events.c +++ b/src/event/server_events.c @@ -154,7 +154,7 @@ sv_ev_room_message(const char * const room_jid, const char * const nick, } void -sv_ev_incoming_private_message(char *fulljid, char *message) +sv_ev_incoming_private_message(const char * const fulljid, char *message) { ui_incoming_private_msg(fulljid, message, NULL); } @@ -177,7 +177,7 @@ sv_ev_incoming_message(char *barejid, char *resource, char *message) } void -sv_ev_delayed_private_message(char *fulljid, char *message, GTimeVal tv_stamp) +sv_ev_delayed_private_message(const char * const fulljid, char *message, GTimeVal tv_stamp) { ui_incoming_private_msg(fulljid, message, &tv_stamp); } diff --git a/src/event/server_events.h b/src/event/server_events.h index c7cc9697..46d485da 100644 --- a/src/event/server_events.h +++ b/src/event/server_events.h @@ -51,9 +51,9 @@ void sv_ev_room_history(const char * const room_jid, const char * const nick, void sv_ev_room_message(const char * const room_jid, const char * const nick, const char * const message); void sv_ev_incoming_message(char *barejid, char *resource, char *message); -void sv_ev_incoming_private_message(char *fulljid, char *message); +void sv_ev_incoming_private_message(const char * const fulljid, char *message); void sv_ev_delayed_message(char *fulljid, char *message, GTimeVal tv_stamp); -void sv_ev_delayed_private_message(char *fulljid, char *message, GTimeVal tv_stamp); +void sv_ev_delayed_private_message(const char * const fulljid, char *message, GTimeVal tv_stamp); void sv_ev_typing(char *barejid, char *resource); void sv_ev_paused(char *barejid, char *resource); void sv_ev_inactive(char *barejid, char *resource); diff --git a/src/xmpp/message.c b/src/xmpp/message.c index 26c266cd..0ceec4cf 100644 --- a/src/xmpp/message.c +++ b/src/xmpp/message.c @@ -555,6 +555,30 @@ _receipt_received_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza return 1; } +void _private_chat_handler(xmpp_stanza_t * const stanza, const char * const fulljid) +{ + xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_BODY); + if (!body) { + return; + } + + char *message = xmpp_stanza_get_text(body); + if (!message) { + return; + } + + GTimeVal tv_stamp; + gboolean delayed = stanza_get_delay(stanza, &tv_stamp); + if (delayed) { + sv_ev_delayed_private_message(fulljid, message, tv_stamp); + } else { + sv_ev_incoming_private_message(fulljid, message); + } + + xmpp_ctx_t *ctx = connection_get_ctx(); + xmpp_free(ctx, message); +} + static int _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { @@ -616,86 +640,67 @@ _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * con return 1; } - xmpp_ctx_t *ctx = connection_get_ctx(); gchar *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); - Jid *jid = jid_create(from); // private message from chat room use full jid (room/nick) if (muc_active(jid->barejid)) { - // determine if the notifications happened whilst offline - GTimeVal tv_stamp; - gboolean delayed = stanza_get_delay(stanza, &tv_stamp); - - // check for and deal with message - xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_BODY); - if (body) { - char *message = xmpp_stanza_get_text(body); - if (message) { - if (delayed) { - sv_ev_delayed_private_message(jid->str, message, tv_stamp); - } else { - sv_ev_incoming_private_message(jid->str, message); - } - xmpp_free(ctx, message); - } - } - - jid_destroy(jid); - return 1; - - // standard chat message, use jid without resource - } else { - // determine if the notifications happened whilst offline - GTimeVal tv_stamp; - gboolean delayed = stanza_get_delay(stanza, &tv_stamp); - char *id = xmpp_stanza_get_id(stanza); - - // check for and deal with message - xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_BODY); - if (body) { - char *message = xmpp_stanza_get_text(body); - if (message) { - if (delayed) { - sv_ev_delayed_message(jid->barejid, message, tv_stamp); - } else { - sv_ev_incoming_message(jid->barejid, jid->resourcepart, message); - } - if (id && prefs_get_boolean(PREF_RECEIPTS_SEND)) { - xmpp_stanza_t *receipts = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_RECEIPTS); - if (receipts) { - char *receipts_name = xmpp_stanza_get_name(receipts); - if (g_strcmp0(receipts_name, "request") == 0) { - _message_send_receipt(jid->fulljid, id); - } - } - } - xmpp_free(ctx, message); - } - } - - // handle chat sessions and states - if (!delayed && jid->resourcepart) { - gboolean gone = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_GONE) != NULL; - gboolean typing = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_COMPOSING) != NULL; - gboolean paused = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_PAUSED) != NULL; - gboolean inactive = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_INACTIVE) != NULL; - if (gone) { - sv_ev_gone(jid->barejid, jid->resourcepart); - } else if (typing) { - sv_ev_typing(jid->barejid, jid->resourcepart); - } else if (paused) { - sv_ev_paused(jid->barejid, jid->resourcepart); - } else if (inactive) { - sv_ev_inactive(jid->barejid, jid->resourcepart); - } else if (stanza_contains_chat_state(stanza)) { - sv_ev_activity(jid->barejid, jid->resourcepart, TRUE); - } else { - sv_ev_activity(jid->barejid, jid->resourcepart, FALSE); - } - } - - jid_destroy(jid); + _private_chat_handler(stanza, jid->fulljid); return 1; } + + // standard chat message, use jid without resource + GTimeVal tv_stamp; + gboolean delayed = stanza_get_delay(stanza, &tv_stamp); + + xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_BODY); + if (body) { + char *message = xmpp_stanza_get_text(body); + if (message) { + if (delayed) { + sv_ev_delayed_message(jid->barejid, message, tv_stamp); + } else { + sv_ev_incoming_message(jid->barejid, jid->resourcepart, message); + } + + // send receipt if configured + char *id = xmpp_stanza_get_id(stanza); + if (id && prefs_get_boolean(PREF_RECEIPTS_SEND)) { + xmpp_stanza_t *receipts = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_RECEIPTS); + if (receipts) { + char *receipts_name = xmpp_stanza_get_name(receipts); + if (g_strcmp0(receipts_name, "request") == 0) { + _message_send_receipt(jid->fulljid, id); + } + } + } + + xmpp_ctx_t *ctx = connection_get_ctx(); + xmpp_free(ctx, message); + } + } + + // handle chat sessions and states + if (!delayed && jid->resourcepart) { + gboolean gone = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_GONE) != NULL; + gboolean typing = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_COMPOSING) != NULL; + gboolean paused = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_PAUSED) != NULL; + gboolean inactive = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_INACTIVE) != NULL; + if (gone) { + sv_ev_gone(jid->barejid, jid->resourcepart); + } else if (typing) { + sv_ev_typing(jid->barejid, jid->resourcepart); + } else if (paused) { + sv_ev_paused(jid->barejid, jid->resourcepart); + } else if (inactive) { + sv_ev_inactive(jid->barejid, jid->resourcepart); + } else if (stanza_contains_chat_state(stanza)) { + sv_ev_activity(jid->barejid, jid->resourcepart, TRUE); + } else { + sv_ev_activity(jid->barejid, jid->resourcepart, FALSE); + } + } + + jid_destroy(jid); + return 1; } From f25f90b38bfa72960f0290231696073966f58c69 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 3 May 2015 01:48:12 +0100 Subject: [PATCH 194/252] Extracted receipt request processing in message.c --- src/xmpp/message.c | 43 +++++++++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/src/xmpp/message.c b/src/xmpp/message.c index 0ceec4cf..85106132 100644 --- a/src/xmpp/message.c +++ b/src/xmpp/message.c @@ -555,7 +555,36 @@ _receipt_received_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza return 1; } -void _private_chat_handler(xmpp_stanza_t * const stanza, const char * const fulljid) +void +_receipt_request_handler(xmpp_stanza_t * const stanza) +{ + if (!prefs_get_boolean(PREF_RECEIPTS_SEND)) { + return; + } + + char *id = xmpp_stanza_get_id(stanza); + if (!id) { + return; + } + + xmpp_stanza_t *receipts = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_RECEIPTS); + if (!receipts) { + return; + } + + char *receipts_name = xmpp_stanza_get_name(receipts); + if (g_strcmp0(receipts_name, "request") != 0) { + return; + } + + gchar *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); + Jid *jid = jid_create(from); + _message_send_receipt(jid->fulljid, id); + jid_destroy(jid); +} + +void +_private_chat_handler(xmpp_stanza_t * const stanza, const char * const fulljid) { xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_BODY); if (!body) { @@ -663,17 +692,7 @@ _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * con sv_ev_incoming_message(jid->barejid, jid->resourcepart, message); } - // send receipt if configured - char *id = xmpp_stanza_get_id(stanza); - if (id && prefs_get_boolean(PREF_RECEIPTS_SEND)) { - xmpp_stanza_t *receipts = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_RECEIPTS); - if (receipts) { - char *receipts_name = xmpp_stanza_get_name(receipts); - if (g_strcmp0(receipts_name, "request") == 0) { - _message_send_receipt(jid->fulljid, id); - } - } - } + _receipt_request_handler(stanza); xmpp_ctx_t *ctx = connection_get_ctx(); xmpp_free(ctx, message); From 4e1c2a4f64fd3ed97b9200472f9f627cf16728d4 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 3 May 2015 02:04:04 +0100 Subject: [PATCH 195/252] Show resource in status bar --- src/ui/core.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/ui/core.c b/src/ui/core.c index 946e3eaf..9deca664 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -618,7 +618,12 @@ ui_handle_login_account_success(ProfAccount *account) contact_presence_t contact_presence = contact_presence_from_resource_presence(resource_presence); cons_show_login_success(account); title_bar_set_presence(contact_presence); - status_bar_print_message(account->jid); + + GString *fulljid = g_string_new(account->jid); + g_string_append(fulljid, "/"); + g_string_append(fulljid, account->resource); + status_bar_print_message(fulljid->str); + g_string_free(fulljid, TRUE); status_bar_update_virtual(); } From ff867e7f2bdfbd8856bd2a010e9d19b9a429a239 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 3 May 2015 02:34:58 +0100 Subject: [PATCH 196/252] Added carbons handler --- src/xmpp/message.c | 104 ++++++++++++++++++++++----------------------- 1 file changed, 52 insertions(+), 52 deletions(-) diff --git a/src/xmpp/message.c b/src/xmpp/message.c index 85106132..8ff4e85f 100644 --- a/src/xmpp/message.c +++ b/src/xmpp/message.c @@ -60,6 +60,7 @@ static int _conference_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const s static int _captcha_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata); static int _message_error_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata); static int _receipt_received_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata); +static int _carbons_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata); void message_add_handlers(void) @@ -74,6 +75,7 @@ message_add_handlers(void) HANDLE(STANZA_NS_CONFERENCE, NULL, _conference_handler); HANDLE(STANZA_NS_CAPTCHA, NULL, _captcha_handler); HANDLE(STANZA_NS_RECEIPTS, NULL, _receipt_received_handler); + HANDLE(STANZA_NS_CARBONS, NULL, _carbons_handler); } char * @@ -529,6 +531,48 @@ _message_send_receipt(const char * const fulljid, const char * const message_id) xmpp_stanza_release(message); } +static int +_carbons_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) +{ + xmpp_stanza_t *carbons = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_CARBONS); + char *name = xmpp_stanza_get_name(carbons); + if ((g_strcmp0(name, "received") == 0) || (g_strcmp0(name, "sent")) == 0){ + xmpp_stanza_t *forwarded = xmpp_stanza_get_child_by_ns(carbons, STANZA_NS_FORWARD); + xmpp_stanza_t *message = xmpp_stanza_get_child_by_name(forwarded, STANZA_NAME_MESSAGE); + + gchar *to = xmpp_stanza_get_attribute(message, STANZA_ATTR_TO); + gchar *from = xmpp_stanza_get_attribute(message, STANZA_ATTR_FROM); + + // carbon of a self sent message + if (!to) to = from; + + Jid *jid_from = jid_create(from); + Jid *jid_to = jid_create(to); + Jid *my_jid = jid_create(jabber_get_fulljid()); + + xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(message, STANZA_NAME_BODY); + if (body) { + char *message = xmpp_stanza_get_text(body); + if (message) { + if (g_strcmp0(my_jid->barejid, jid_to->barejid) == 0) { + sv_ev_incoming_message(jid_from->barejid, jid_from->resourcepart, message); + } else { + sv_ev_carbon(jid_to->barejid, message); + } + + xmpp_ctx_t *ctx = connection_get_ctx(); + xmpp_free(ctx, message); + } + } + + jid_destroy(jid_from); + jid_destroy(jid_to); + jid_destroy(my_jid); + } + + return 1; +} + static int _receipt_received_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { @@ -611,61 +655,18 @@ _private_chat_handler(xmpp_stanza_t * const stanza, const char * const fulljid) static int _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { - // ignore if type not chat or absent - char *type = xmpp_stanza_get_type(stanza); - if (!(g_strcmp0(type, "chat") == 0 || type == NULL)) { - return 1; - } - - // check if carbon message - xmpp_stanza_t *carbons = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_CARBONS); - if (carbons) { - char *name = xmpp_stanza_get_name(carbons); - if ((g_strcmp0(name, "received") == 0) || (g_strcmp0(name, "sent")) == 0){ - xmpp_stanza_t *forwarded = xmpp_stanza_get_child_by_ns(carbons, STANZA_NS_FORWARD); - xmpp_stanza_t *message = xmpp_stanza_get_child_by_name(forwarded, STANZA_NAME_MESSAGE); - - xmpp_ctx_t *ctx = connection_get_ctx(); - - gchar *to = xmpp_stanza_get_attribute(message, STANZA_ATTR_TO); - gchar *from = xmpp_stanza_get_attribute(message, STANZA_ATTR_FROM); - - // happens when receive a carbon of a self sent message - if (!to) to = from; - - Jid *jid_from = jid_create(from); - Jid *jid_to = jid_create(to); - Jid *my_jid = jid_create(jabber_get_fulljid()); - - // check for and deal with message - xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(message, STANZA_NAME_BODY); - if (body) { - char *message = xmpp_stanza_get_text(body); - if (message) { - // if we are the recipient, treat as standard incoming message - if(g_strcmp0(my_jid->barejid, jid_to->barejid) == 0){ - sv_ev_incoming_message(jid_from->barejid, jid_from->resourcepart, message); - } - // else treat as a sent message - else{ - sv_ev_carbon(jid_to->barejid, message); - } - xmpp_free(ctx, message); - } - } - - jid_destroy(jid_from); - jid_destroy(jid_to); - jid_destroy(my_jid); - return 1; - } - } - // ignore handled namespaces xmpp_stanza_t *conf = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_CONFERENCE); xmpp_stanza_t *mucuser = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_MUC_USER); xmpp_stanza_t *captcha = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_CAPTCHA); - if (conf || mucuser || captcha) { + xmpp_stanza_t *carbons = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_CARBONS); + if (conf || mucuser || captcha || carbons) { + return 1; + } + + // ignore if type not chat or absent + char *type = xmpp_stanza_get_type(stanza); + if (!(g_strcmp0(type, "chat") == 0 || type == NULL)) { return 1; } @@ -678,7 +679,6 @@ _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * con return 1; } - // standard chat message, use jid without resource GTimeVal tv_stamp; gboolean delayed = stanza_get_delay(stanza, &tv_stamp); From c3d2a7e9377c9d16f1ee4ea57c6e0c1f78b5ac6e Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 3 May 2015 23:38:46 +0100 Subject: [PATCH 197/252] Added roster list function to get display name for messages --- src/roster_list.c | 28 ++++++++++++++++++++++++++++ src/roster_list.h | 1 + src/ui/core.c | 32 ++++++++------------------------ 3 files changed, 37 insertions(+), 24 deletions(-) diff --git a/src/roster_list.c b/src/roster_list.c index ad1864f1..a320ab2b 100644 --- a/src/roster_list.c +++ b/src/roster_list.c @@ -42,6 +42,7 @@ #include "contact.h" #include "jid.h" #include "tools/autocomplete.h" +#include "config/preferences.h" // nicknames static Autocomplete name_ac; @@ -116,6 +117,33 @@ roster_get_contact(const char * const barejid) return contact; } +char * +roster_get_msg_display_name(const char * const barejid, const char * const resource) +{ + GString *result = g_string_new(""); + + PContact contact = roster_get_contact(barejid); + if (contact != NULL) { + if (p_contact_name(contact) != NULL) { + g_string_append(result, p_contact_name(contact)); + } else { + g_string_append(result, barejid); + } + } else { + g_string_append(result, barejid); + } + + if (resource && prefs_get_boolean(PREF_RESOURCE_MESSAGE)) { + g_string_append(result, "/"); + g_string_append(result, resource); + } + + char *result_str = result->str; + g_string_free(result, FALSE); + + return result_str; +} + gboolean roster_contact_offline(const char * const barejid, const char * const resource, const char * const status) diff --git a/src/roster_list.h b/src/roster_list.h index 6c66d142..4417c763 100644 --- a/src/roster_list.h +++ b/src/roster_list.h @@ -67,5 +67,6 @@ char * roster_group_autocomplete(const char * const search_str); char * roster_barejid_autocomplete(const char * const search_str); GSList * roster_get_contacts_by_presence(const char * const presence); GSList * roster_get_nogroup(void); +char * roster_get_msg_display_name(const char * const barejid, const char * const resource); #endif diff --git a/src/ui/core.c b/src/ui/core.c index 9deca664..fb1a4219 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -389,23 +389,6 @@ void ui_incoming_msg(const char * const barejid, const char * const resource, const char * const message, GTimeVal *tv_stamp) { gboolean win_created = FALSE; - GString *user = g_string_new(""); - - PContact contact = roster_get_contact(barejid); - if (contact != NULL) { - if (p_contact_name(contact) != NULL) { - g_string_append(user, p_contact_name(contact)); - } else { - g_string_append(user, barejid); - } - } else { - g_string_append(user, barejid); - } - - if (resource && prefs_get_boolean(PREF_RESOURCE_MESSAGE)) { - g_string_append(user, "/"); - g_string_append(user, resource); - } ProfChatWin *chatwin = wins_get_chat(barejid); if (chatwin == NULL) { @@ -415,19 +398,20 @@ ui_incoming_msg(const char * const barejid, const char * const resource, const c } ProfWin *window = (ProfWin*) chatwin; - int num = wins_get_num(window); + char *display_name = roster_get_msg_display_name(barejid, resource); + // currently viewing chat window with sender if (wins_is_current(window)) { - win_print_incoming_message(window, tv_stamp, user->str, message); + win_print_incoming_message(window, tv_stamp, display_name, message); title_bar_set_typing(FALSE); status_bar_active(num); // not currently viewing chat window with sender } else { status_bar_new(num); - cons_show_incoming_message(user->str, num); + cons_show_incoming_message(display_name, num); if (prefs_get_boolean(PREF_FLASH)) { flash(); @@ -446,7 +430,7 @@ ui_incoming_msg(const char * const barejid, const char * const resource, const c } } - win_print_incoming_message(window, tv_stamp, user->str, message); + win_print_incoming_message(window, tv_stamp, display_name, message); } int ui_index = num; @@ -462,14 +446,14 @@ ui_incoming_msg(const char * const barejid, const char * const resource, const c gboolean is_current = wins_is_current(window); if ( !is_current || (is_current && prefs_get_boolean(PREF_NOTIFY_MESSAGE_CURRENT)) ) { if (prefs_get_boolean(PREF_NOTIFY_MESSAGE_TEXT)) { - notify_message(user->str, ui_index, message); + notify_message(display_name, ui_index, message); } else { - notify_message(user->str, ui_index, NULL); + notify_message(display_name, ui_index, NULL); } } } - g_string_free(user, TRUE); + free(display_name); } void From ef54ff305eb4d5f971547721e20a8347f6ee7770 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 00:55:43 +0100 Subject: [PATCH 198/252] ui_outgoing_chat_msg now takes ProfChatWin as argument --- src/event/client_events.c | 2 +- src/otr/otr.c | 6 +++--- src/ui/core.c | 16 +++++++--------- src/ui/ui.h | 2 +- tests/ui/stub_ui.c | 2 +- 5 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/event/client_events.c b/src/event/client_events.c index ea327ca1..9f1acca4 100644 --- a/src/event/client_events.c +++ b/src/event/client_events.c @@ -70,7 +70,7 @@ cl_ev_send_msg(ProfChatWin *chatwin, const char * const msg) #else char *id = message_send_chat(chatwin->barejid, msg); chat_log_msg_out(chatwin->barejid, msg); - ui_outgoing_chat_msg(chatwin->barejid, msg, id); + ui_outgoing_chat_msg(chatwin, msg, id); free(id); #endif } diff --git a/src/otr/otr.c b/src/otr/otr.c index ae8ed006..fbc26eb8 100644 --- a/src/otr/otr.c +++ b/src/otr/otr.c @@ -325,7 +325,7 @@ otr_on_message_send(ProfChatWin *chatwin, const char * const message) if (encrypted) { id = message_send_chat_encrypted(chatwin->barejid, encrypted); chat_log_otr_msg_out(chatwin->barejid, message); - ui_outgoing_chat_msg(chatwin->barejid, message, id); + ui_outgoing_chat_msg(chatwin, message, id); otr_free_message(encrypted); } else { ui_win_error_line((ProfWin*)chatwin, "Failed to encrypt and send message."); @@ -339,13 +339,13 @@ otr_on_message_send(ProfChatWin *chatwin, const char * const message) } else if (policy == PROF_OTRPOLICY_OPPORTUNISTIC) { char *otr_tagged_msg = otr_tag_message(message); id = message_send_chat_encrypted(chatwin->barejid, otr_tagged_msg); - ui_outgoing_chat_msg(chatwin->barejid, message, id); + ui_outgoing_chat_msg(chatwin, message, id); chat_log_msg_out(chatwin->barejid, message); free(otr_tagged_msg); } else { id = message_send_chat(chatwin->barejid, message); - ui_outgoing_chat_msg(chatwin->barejid, message, id); + ui_outgoing_chat_msg(chatwin, message, id); chat_log_msg_out(chatwin->barejid, message); } diff --git a/src/ui/core.c b/src/ui/core.c index fb1a4219..b4cef52d 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -433,15 +433,15 @@ ui_incoming_msg(const char * const barejid, const char * const resource, const c win_print_incoming_message(window, tv_stamp, display_name, message); } + if (prefs_get_boolean(PREF_BEEP)) { + beep(); + } + int ui_index = num; if (ui_index == 10) { ui_index = 0; } - if (prefs_get_boolean(PREF_BEEP)) { - beep(); - } - if (prefs_get_boolean(PREF_NOTIFY_MESSAGE)) { gboolean is_current = wins_is_current(window); if ( !is_current || (is_current && prefs_get_boolean(PREF_NOTIFY_MESSAGE_CURRENT)) ) { @@ -1329,14 +1329,12 @@ ui_new_chat_win(const char * const barejid) } void -ui_outgoing_chat_msg(const char * const barejid, const char * const message, char *id) +ui_outgoing_chat_msg(ProfChatWin *chatwin, const char * const message, char *id) { - ProfWin *window = (ProfWin*)wins_get_chat(barejid); - if (prefs_get_boolean(PREF_RECEIPTS_REQUEST) && id) { - win_print_with_receipt(window, '-', NULL, 0, THEME_TEXT_ME, "me", message, id); + win_print_with_receipt((ProfWin*)chatwin, '-', NULL, 0, THEME_TEXT_ME, "me", message, id); } else { - win_print(window, '-', NULL, 0, THEME_TEXT_ME, "me", message); + win_print((ProfWin*)chatwin, '-', NULL, 0, THEME_TEXT_ME, "me", message); } } diff --git a/src/ui/ui.h b/src/ui/ui.h index 6d85c9e8..212ed451 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -120,7 +120,7 @@ void ui_message_receipt(const char * const barejid, const char * const id); void ui_disconnected(void); void ui_recipient_gone(const char * const barejid, const char * const resource); -void ui_outgoing_chat_msg(const char * const barejid, const char * const message, char *id); +void ui_outgoing_chat_msg(ProfChatWin *chatwin, const char * const message, char *id); void ui_outgoing_chat_msg_carbon(const char * const barejid, const char * const message); void ui_outgoing_private_msg(const char * const fulljid, const char * const message); diff --git a/tests/ui/stub_ui.c b/tests/ui/stub_ui.c index cee81872..ac5fe7c9 100644 --- a/tests/ui/stub_ui.c +++ b/tests/ui/stub_ui.c @@ -190,7 +190,7 @@ void ui_incoming_private_msg(const char * const fulljid, const char * const mess void ui_disconnected(void) {} void ui_recipient_gone(const char * const barejid, const char * const resource) {} -void ui_outgoing_chat_msg(const char * const barejid, const char * const message, char *id) {} +void ui_outgoing_chat_msg(ProfChatWin *chatwin, const char * const message, char *id) {} void ui_outgoing_chat_msg_carbon(const char * const barejid, const char * const message) {} void ui_outgoing_private_msg(const char * const fulljid, const char * const message) {} From b1dd1e2726892ac8152ba4b8f880f693c113a6e9 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 01:06:12 +0100 Subject: [PATCH 199/252] cl_ev_send_muc_msg takes ProfMucWin as arg --- src/command/commands.c | 4 ++-- src/event/client_events.c | 4 ++-- src/event/client_events.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index 62dcb927..21acc413 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -122,7 +122,7 @@ cmd_execute_default(const char * inp) case WIN_MUC: { ProfMucWin *mucwin = wins_get_current_muc(); - cl_ev_send_muc_msg(mucwin->roomjid, inp); + cl_ev_send_muc_msg(mucwin, inp); break; } default: @@ -3155,7 +3155,7 @@ cmd_tiny(gchar **args, struct cmd_help_t help) case WIN_MUC: { ProfMucWin *mucwin = wins_get_current_muc(); - cl_ev_send_muc_msg(mucwin->roomjid, tiny); + cl_ev_send_muc_msg(mucwin, tiny); break; } default: diff --git a/src/event/client_events.c b/src/event/client_events.c index 9f1acca4..167dfac7 100644 --- a/src/event/client_events.c +++ b/src/event/client_events.c @@ -76,9 +76,9 @@ cl_ev_send_msg(ProfChatWin *chatwin, const char * const msg) } void -cl_ev_send_muc_msg(const char * const roomjid, const char * const msg) +cl_ev_send_muc_msg(ProfMucWin *mucwin, const char * const msg) { - message_send_groupchat(roomjid, msg); + message_send_groupchat(mucwin->roomjid, msg); } void diff --git a/src/event/client_events.h b/src/event/client_events.h index c074b230..3685cb2d 100644 --- a/src/event/client_events.h +++ b/src/event/client_events.h @@ -39,7 +39,7 @@ jabber_conn_status_t cl_ev_connect_jid(const char * const jid, const char * cons jabber_conn_status_t cl_ev_connect_account(ProfAccount *account); void cl_ev_send_msg(ProfChatWin *chatwin, const char * const msg); -void cl_ev_send_muc_msg(const char * const roomjid, const char * const msg); +void cl_ev_send_muc_msg(ProfMucWin *mucwin, const char * const msg); void cl_ev_send_priv_msg(const char * const fulljid, const char * const msg); #endif \ No newline at end of file From c8eaaa0ce918064a4009f706baac4a975999fc3f Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 01:31:27 +0100 Subject: [PATCH 200/252] Added ui_ev_new_private_win to ui events --- src/command/commands.c | 14 +++++++++----- src/event/client_events.c | 6 +++--- src/event/client_events.h | 2 +- src/event/ui_events.c | 6 ++++++ src/event/ui_events.h | 1 + src/ui/core.c | 19 +++++-------------- src/ui/ui.h | 4 ++-- tests/ui/stub_ui.c | 8 ++++++-- 8 files changed, 33 insertions(+), 27 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index 21acc413..dfabc4f0 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -116,7 +116,7 @@ cmd_execute_default(const char * inp) case WIN_PRIVATE: { ProfPrivateWin *privatewin = wins_get_current_private(); - cl_ev_send_priv_msg(privatewin->fulljid, inp); + cl_ev_send_priv_msg(privatewin, inp); break; } case WIN_MUC: @@ -1310,10 +1310,14 @@ cmd_msg(gchar **args, struct cmd_help_t help) g_string_append(full_jid, "/"); g_string_append(full_jid, usr); + ProfPrivateWin *privwin = wins_get_private(full_jid->str); + if (!privwin) { + privwin = ui_ev_new_private_win(full_jid->str); + } + ui_ev_focus_win((ProfWin*)privwin); + if (msg) { - cl_ev_send_priv_msg(full_jid->str, msg); - } else { - ui_new_private_win(full_jid->str); + cl_ev_send_priv_msg(privwin, msg); } g_string_free(full_jid, TRUE); @@ -3149,7 +3153,7 @@ cmd_tiny(gchar **args, struct cmd_help_t help) case WIN_PRIVATE: { ProfPrivateWin *privatewin = wins_get_current_private(); - cl_ev_send_priv_msg(privatewin->fulljid, tiny); + cl_ev_send_priv_msg(privatewin, tiny); break; } case WIN_MUC: diff --git a/src/event/client_events.c b/src/event/client_events.c index 167dfac7..db8f6497 100644 --- a/src/event/client_events.c +++ b/src/event/client_events.c @@ -82,8 +82,8 @@ cl_ev_send_muc_msg(ProfMucWin *mucwin, const char * const msg) } void -cl_ev_send_priv_msg(const char * const fulljid, const char * const msg) +cl_ev_send_priv_msg(ProfPrivateWin *privwin, const char * const msg) { - message_send_private(fulljid, msg); - ui_outgoing_private_msg(fulljid, msg); + message_send_private(privwin->fulljid, msg); + ui_outgoing_private_msg(privwin, msg); } \ No newline at end of file diff --git a/src/event/client_events.h b/src/event/client_events.h index 3685cb2d..a7ecc583 100644 --- a/src/event/client_events.h +++ b/src/event/client_events.h @@ -40,6 +40,6 @@ jabber_conn_status_t cl_ev_connect_account(ProfAccount *account); void cl_ev_send_msg(ProfChatWin *chatwin, const char * const msg); void cl_ev_send_muc_msg(ProfMucWin *mucwin, const char * const msg); -void cl_ev_send_priv_msg(const char * const fulljid, const char * const msg); +void cl_ev_send_priv_msg(ProfPrivateWin *privwin, const char * const msg); #endif \ No newline at end of file diff --git a/src/event/ui_events.c b/src/event/ui_events.c index bebffc07..ff1d7273 100644 --- a/src/event/ui_events.c +++ b/src/event/ui_events.c @@ -47,4 +47,10 @@ ProfChatWin* ui_ev_new_chat_win(const char * const barejid) { return ui_new_chat_win(barejid); +} + +ProfPrivateWin* +ui_ev_new_private_win(const char * const fulljid) +{ + return ui_new_private_win(fulljid); } \ No newline at end of file diff --git a/src/event/ui_events.h b/src/event/ui_events.h index b7075e61..3f7fed02 100644 --- a/src/event/ui_events.h +++ b/src/event/ui_events.h @@ -37,5 +37,6 @@ void ui_ev_focus_win(ProfWin *win); ProfChatWin* ui_ev_new_chat_win(const char * const barejid); +ProfPrivateWin* ui_ev_new_private_win(const char * const fulljid); #endif \ No newline at end of file diff --git a/src/ui/core.c b/src/ui/core.c index b4cef52d..8c4d4644 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -1273,14 +1273,11 @@ ui_recipient_gone(const char * const barejid, const char * const resource) } } -void +ProfPrivateWin* ui_new_private_win(const char * const fulljid) { - ProfWin *window = (ProfWin*)wins_get_private(fulljid); - if (!window) { - window = wins_new_private(fulljid); - } - ui_ev_focus_win(window); + ProfWin *window = wins_new_private(fulljid); + return (ProfPrivateWin*)window; } void @@ -1357,15 +1354,9 @@ ui_outgoing_chat_msg_carbon(const char * const barejid, const char * const messa } void -ui_outgoing_private_msg(const char * const fulljid, const char * const message) +ui_outgoing_private_msg(ProfPrivateWin *privwin, const char * const message) { - ProfWin *window = (ProfWin*)wins_get_private(fulljid); - if (!window) { - window = wins_new_private(fulljid); - } - - win_print(window, '-', NULL, 0, THEME_TEXT_ME, "me", message); - ui_ev_focus_win(window); + win_print((ProfWin*)privwin, '-', NULL, 0, THEME_TEXT_ME, "me", message); } void diff --git a/src/ui/ui.h b/src/ui/ui.h index 212ed451..c98d45e8 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -84,7 +84,7 @@ void ui_handle_otr_error(const char * const barejid, const char * const message) unsigned long ui_get_idle_time(void); void ui_reset_idle_time(void); -void ui_new_private_win(const char * const fulljid); +ProfPrivateWin* ui_new_private_win(const char * const fulljid); ProfChatWin* ui_new_chat_win(const char * const barejid); void ui_print_system_msg_from_recipient(const char * const barejid, const char *message); gint ui_unread(void); @@ -122,7 +122,7 @@ void ui_recipient_gone(const char * const barejid, const char * const resource); void ui_outgoing_chat_msg(ProfChatWin *chatwin, const char * const message, char *id); void ui_outgoing_chat_msg_carbon(const char * const barejid, const char * const message); -void ui_outgoing_private_msg(const char * const fulljid, const char * const message); +void ui_outgoing_private_msg(ProfPrivateWin *privwin, const char * const message); void ui_room_join(const char * const roomjid, gboolean focus); void ui_switch_to_room(const char * const roomjid); diff --git a/tests/ui/stub_ui.c b/tests/ui/stub_ui.c index ac5fe7c9..c23723e1 100644 --- a/tests/ui/stub_ui.c +++ b/tests/ui/stub_ui.c @@ -91,7 +91,11 @@ unsigned long ui_get_idle_time(void) } void ui_reset_idle_time(void) {} -void ui_new_private_win(const char * const fulljid) {} +ProfPrivateWin* ui_new_private_win(const char * const fulljid) +{ + return NULL; +} + ProfChatWin* ui_new_chat_win(const char * const barejid) { return NULL; @@ -192,7 +196,7 @@ void ui_recipient_gone(const char * const barejid, const char * const resource) void ui_outgoing_chat_msg(ProfChatWin *chatwin, const char * const message, char *id) {} void ui_outgoing_chat_msg_carbon(const char * const barejid, const char * const message) {} -void ui_outgoing_private_msg(const char * const fulljid, const char * const message) {} +void ui_outgoing_private_msg(ProfPrivateWin *privwin, const char * const message) {} void ui_room_join(const char * const roomjid, gboolean focus) {} void ui_switch_to_room(const char * const roomjid) {} From ac940c2c8a3716c2b340da7e625cfb10f68c4575 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 21:18:53 +0100 Subject: [PATCH 201/252] Revert "Added carbons handler" This reverts commit ff867e7f2bdfbd8856bd2a010e9d19b9a429a239. --- src/xmpp/message.c | 104 ++++++++++++++++++++++----------------------- 1 file changed, 52 insertions(+), 52 deletions(-) diff --git a/src/xmpp/message.c b/src/xmpp/message.c index 8ff4e85f..85106132 100644 --- a/src/xmpp/message.c +++ b/src/xmpp/message.c @@ -60,7 +60,6 @@ static int _conference_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const s static int _captcha_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata); static int _message_error_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata); static int _receipt_received_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata); -static int _carbons_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata); void message_add_handlers(void) @@ -75,7 +74,6 @@ message_add_handlers(void) HANDLE(STANZA_NS_CONFERENCE, NULL, _conference_handler); HANDLE(STANZA_NS_CAPTCHA, NULL, _captcha_handler); HANDLE(STANZA_NS_RECEIPTS, NULL, _receipt_received_handler); - HANDLE(STANZA_NS_CARBONS, NULL, _carbons_handler); } char * @@ -531,48 +529,6 @@ _message_send_receipt(const char * const fulljid, const char * const message_id) xmpp_stanza_release(message); } -static int -_carbons_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) -{ - xmpp_stanza_t *carbons = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_CARBONS); - char *name = xmpp_stanza_get_name(carbons); - if ((g_strcmp0(name, "received") == 0) || (g_strcmp0(name, "sent")) == 0){ - xmpp_stanza_t *forwarded = xmpp_stanza_get_child_by_ns(carbons, STANZA_NS_FORWARD); - xmpp_stanza_t *message = xmpp_stanza_get_child_by_name(forwarded, STANZA_NAME_MESSAGE); - - gchar *to = xmpp_stanza_get_attribute(message, STANZA_ATTR_TO); - gchar *from = xmpp_stanza_get_attribute(message, STANZA_ATTR_FROM); - - // carbon of a self sent message - if (!to) to = from; - - Jid *jid_from = jid_create(from); - Jid *jid_to = jid_create(to); - Jid *my_jid = jid_create(jabber_get_fulljid()); - - xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(message, STANZA_NAME_BODY); - if (body) { - char *message = xmpp_stanza_get_text(body); - if (message) { - if (g_strcmp0(my_jid->barejid, jid_to->barejid) == 0) { - sv_ev_incoming_message(jid_from->barejid, jid_from->resourcepart, message); - } else { - sv_ev_carbon(jid_to->barejid, message); - } - - xmpp_ctx_t *ctx = connection_get_ctx(); - xmpp_free(ctx, message); - } - } - - jid_destroy(jid_from); - jid_destroy(jid_to); - jid_destroy(my_jid); - } - - return 1; -} - static int _receipt_received_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { @@ -655,18 +611,61 @@ _private_chat_handler(xmpp_stanza_t * const stanza, const char * const fulljid) static int _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { + // ignore if type not chat or absent + char *type = xmpp_stanza_get_type(stanza); + if (!(g_strcmp0(type, "chat") == 0 || type == NULL)) { + return 1; + } + + // check if carbon message + xmpp_stanza_t *carbons = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_CARBONS); + if (carbons) { + char *name = xmpp_stanza_get_name(carbons); + if ((g_strcmp0(name, "received") == 0) || (g_strcmp0(name, "sent")) == 0){ + xmpp_stanza_t *forwarded = xmpp_stanza_get_child_by_ns(carbons, STANZA_NS_FORWARD); + xmpp_stanza_t *message = xmpp_stanza_get_child_by_name(forwarded, STANZA_NAME_MESSAGE); + + xmpp_ctx_t *ctx = connection_get_ctx(); + + gchar *to = xmpp_stanza_get_attribute(message, STANZA_ATTR_TO); + gchar *from = xmpp_stanza_get_attribute(message, STANZA_ATTR_FROM); + + // happens when receive a carbon of a self sent message + if (!to) to = from; + + Jid *jid_from = jid_create(from); + Jid *jid_to = jid_create(to); + Jid *my_jid = jid_create(jabber_get_fulljid()); + + // check for and deal with message + xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(message, STANZA_NAME_BODY); + if (body) { + char *message = xmpp_stanza_get_text(body); + if (message) { + // if we are the recipient, treat as standard incoming message + if(g_strcmp0(my_jid->barejid, jid_to->barejid) == 0){ + sv_ev_incoming_message(jid_from->barejid, jid_from->resourcepart, message); + } + // else treat as a sent message + else{ + sv_ev_carbon(jid_to->barejid, message); + } + xmpp_free(ctx, message); + } + } + + jid_destroy(jid_from); + jid_destroy(jid_to); + jid_destroy(my_jid); + return 1; + } + } + // ignore handled namespaces xmpp_stanza_t *conf = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_CONFERENCE); xmpp_stanza_t *mucuser = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_MUC_USER); xmpp_stanza_t *captcha = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_CAPTCHA); - xmpp_stanza_t *carbons = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_CARBONS); - if (conf || mucuser || captcha || carbons) { - return 1; - } - - // ignore if type not chat or absent - char *type = xmpp_stanza_get_type(stanza); - if (!(g_strcmp0(type, "chat") == 0 || type == NULL)) { + if (conf || mucuser || captcha) { return 1; } @@ -679,6 +678,7 @@ _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * con return 1; } + // standard chat message, use jid without resource GTimeVal tv_stamp; gboolean delayed = stanza_get_delay(stanza, &tv_stamp); From a0c872edf85d98d237200ada08a97705a1e18e7f Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 21:31:05 +0100 Subject: [PATCH 202/252] Extracted carbons handling --- src/xmpp/message.c | 96 ++++++++++++++++++++++++++-------------------- 1 file changed, 55 insertions(+), 41 deletions(-) diff --git a/src/xmpp/message.c b/src/xmpp/message.c index 85106132..bc702199 100644 --- a/src/xmpp/message.c +++ b/src/xmpp/message.c @@ -608,6 +608,58 @@ _private_chat_handler(xmpp_stanza_t * const stanza, const char * const fulljid) xmpp_free(ctx, message); } +static gboolean +_handle_carbons(xmpp_stanza_t * const stanza) +{ + xmpp_stanza_t *carbons = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_CARBONS); + if (!carbons) { + return FALSE; + } + + char *name = xmpp_stanza_get_name(carbons); + if ((g_strcmp0(name, "received") == 0) || (g_strcmp0(name, "sent")) == 0) { + xmpp_stanza_t *forwarded = xmpp_stanza_get_child_by_ns(carbons, STANZA_NS_FORWARD); + xmpp_stanza_t *message = xmpp_stanza_get_child_by_name(forwarded, STANZA_NAME_MESSAGE); + + xmpp_ctx_t *ctx = connection_get_ctx(); + + gchar *to = xmpp_stanza_get_attribute(message, STANZA_ATTR_TO); + gchar *from = xmpp_stanza_get_attribute(message, STANZA_ATTR_FROM); + + // happens when receive a carbon of a self sent message + if (!to) to = from; + + Jid *jid_from = jid_create(from); + Jid *jid_to = jid_create(to); + Jid *my_jid = jid_create(jabber_get_fulljid()); + + // check for and deal with message + xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(message, STANZA_NAME_BODY); + if (body) { + char *message = xmpp_stanza_get_text(body); + if (message) { + // if we are the recipient, treat as standard incoming message + if(g_strcmp0(my_jid->barejid, jid_to->barejid) == 0){ + sv_ev_incoming_message(jid_from->barejid, jid_from->resourcepart, message); + } + // else treat as a sent message + else{ + sv_ev_carbon(jid_to->barejid, message); + } + xmpp_free(ctx, message); + } + } + + jid_destroy(jid_from); + jid_destroy(jid_to); + jid_destroy(my_jid); + + return TRUE; + } + + return FALSE; +} + static int _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { @@ -618,47 +670,9 @@ _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * con } // check if carbon message - xmpp_stanza_t *carbons = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_CARBONS); - if (carbons) { - char *name = xmpp_stanza_get_name(carbons); - if ((g_strcmp0(name, "received") == 0) || (g_strcmp0(name, "sent")) == 0){ - xmpp_stanza_t *forwarded = xmpp_stanza_get_child_by_ns(carbons, STANZA_NS_FORWARD); - xmpp_stanza_t *message = xmpp_stanza_get_child_by_name(forwarded, STANZA_NAME_MESSAGE); - - xmpp_ctx_t *ctx = connection_get_ctx(); - - gchar *to = xmpp_stanza_get_attribute(message, STANZA_ATTR_TO); - gchar *from = xmpp_stanza_get_attribute(message, STANZA_ATTR_FROM); - - // happens when receive a carbon of a self sent message - if (!to) to = from; - - Jid *jid_from = jid_create(from); - Jid *jid_to = jid_create(to); - Jid *my_jid = jid_create(jabber_get_fulljid()); - - // check for and deal with message - xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(message, STANZA_NAME_BODY); - if (body) { - char *message = xmpp_stanza_get_text(body); - if (message) { - // if we are the recipient, treat as standard incoming message - if(g_strcmp0(my_jid->barejid, jid_to->barejid) == 0){ - sv_ev_incoming_message(jid_from->barejid, jid_from->resourcepart, message); - } - // else treat as a sent message - else{ - sv_ev_carbon(jid_to->barejid, message); - } - xmpp_free(ctx, message); - } - } - - jid_destroy(jid_from); - jid_destroy(jid_to); - jid_destroy(my_jid); - return 1; - } + gboolean res = _handle_carbons(stanza); + if (res) { + return 1; } // ignore handled namespaces From 8ccbeade44f7929d7ec77b2f0a6198bd95432f0f Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 21:38:19 +0100 Subject: [PATCH 203/252] Added enc_mode to ProfChatWin --- src/ui/core.c | 14 +++++++------- src/ui/titlebar.c | 2 +- src/ui/window.c | 2 +- src/ui/window.h | 7 ++++++- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/ui/core.c b/src/ui/core.c index 8c4d4644..e75d5432 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -714,7 +714,7 @@ ui_close_connected_win(int index) ProfChatWin *chatwin = (ProfChatWin*) window; assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK); #ifdef HAVE_LIBOTR - if (chatwin->is_otr) { + if (chatwin->enc_mode == PROF_ENC_OTR) { otr_end_session(chatwin->barejid); } #endif @@ -896,7 +896,7 @@ ui_gone_secure(const char * const barejid, gboolean trusted) chatwin = (ProfChatWin*)window; } - chatwin->is_otr = TRUE; + chatwin->enc_mode = PROF_ENC_OTR; chatwin->is_trusted = trusted; if (trusted) { win_print(window, '!', NULL, 0, THEME_OTR_STARTED_TRUSTED, "", "OTR session started (trusted)."); @@ -924,7 +924,7 @@ ui_gone_insecure(const char * const barejid) { ProfChatWin *chatwin = wins_get_chat(barejid); if (chatwin) { - chatwin->is_otr = FALSE; + chatwin->enc_mode = PROF_ENC_NONE; chatwin->is_trusted = FALSE; ProfWin *window = (ProfWin*)chatwin; @@ -1043,7 +1043,7 @@ ui_trust(const char * const barejid) { ProfChatWin *chatwin = wins_get_chat(barejid); if (chatwin) { - chatwin->is_otr = TRUE; + chatwin->enc_mode = PROF_ENC_OTR; chatwin->is_trusted = TRUE; ProfWin *window = (ProfWin*)chatwin; @@ -1059,7 +1059,7 @@ ui_untrust(const char * const barejid) { ProfChatWin *chatwin = wins_get_chat(barejid); if (chatwin) { - chatwin->is_otr = TRUE; + chatwin->enc_mode = PROF_ENC_OTR; chatwin->is_trusted = FALSE; ProfWin *window = (ProfWin*)chatwin; @@ -1164,7 +1164,7 @@ ui_current_win_is_otr(void) if (current->type == WIN_CHAT) { ProfChatWin *chatwin = (ProfChatWin*)current; assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK); - return chatwin->is_otr; + return chatwin->enc_mode == PROF_ENC_OTR; } else { return FALSE; } @@ -1304,7 +1304,7 @@ ui_new_chat_win(const char * const barejid) #ifdef HAVE_LIBOTR if (otr_is_secure(barejid)) { - chatwin->is_otr = TRUE; + chatwin->enc_mode = PROF_ENC_OTR; } #endif diff --git a/src/ui/titlebar.c b/src/ui/titlebar.c index 7b80c889..08c9a8e6 100644 --- a/src/ui/titlebar.c +++ b/src/ui/titlebar.c @@ -252,7 +252,7 @@ _show_privacy(ProfChatWin *chatwin) { int bracket_attrs = theme_attrs(THEME_TITLE_BRACKET); - if (!chatwin->is_otr) { + if (chatwin->enc_mode == PROF_ENC_NONE) { if (prefs_get_boolean(PREF_OTR_WARN)) { int unencrypted_attrs = theme_attrs(THEME_TITLE_UNENCRYPTED); wprintw(win, " "); diff --git a/src/ui/window.c b/src/ui/window.c index ab894d07..60c71802 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -134,7 +134,7 @@ win_create_chat(const char * const barejid) new_win->barejid = strdup(barejid); new_win->resource_override = NULL; - new_win->is_otr = FALSE; + new_win->enc_mode = PROF_ENC_NONE; new_win->is_trusted = FALSE; new_win->history_shown = FALSE; new_win->unread = 0; diff --git a/src/ui/window.h b/src/ui/window.h index 650df67f..d5e57971 100644 --- a/src/ui/window.h +++ b/src/ui/window.h @@ -99,6 +99,11 @@ typedef enum { WIN_XML } win_type_t; +typedef enum { + PROF_ENC_NONE, + PROF_ENC_OTR +} prof_enc_t; + typedef struct prof_win_t { win_type_t type; ProfLayout *layout; @@ -113,7 +118,7 @@ typedef struct prof_chat_win_t { char *barejid; int unread; ChatState *state; - gboolean is_otr; + prof_enc_t enc_mode; gboolean is_trusted; char *resource_override; gboolean history_shown; From 2b3cc65b52ecc9de54c6d4974f8253ce1fbcf3bd Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 22:16:39 +0100 Subject: [PATCH 204/252] Use null check convention in command.c --- src/command/command.c | 220 +++++++++++++++++++++--------------------- 1 file changed, 110 insertions(+), 110 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index fca25690..04bb6603 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -1247,7 +1247,7 @@ cmd_init(void) // load aliases GList *aliases = prefs_get_aliases(); GList *curr = aliases; - while (curr != NULL) { + while (curr) { ProfAlias *alias = curr->data; GString *ac_alias = g_string_new("/"); g_string_append(ac_alias, alias->name); @@ -1645,7 +1645,7 @@ cmd_exists(char *cmd) void cmd_autocomplete_add(char *value) { - if (commands_ac != NULL) { + if (commands_ac) { autocomplete_add(commands_ac, value); } } @@ -1687,7 +1687,7 @@ cmd_autocomplete_remove_form_fields(DataForm *form) void cmd_autocomplete_remove(char *value) { - if (commands_ac != NULL) { + if (commands_ac) { autocomplete_remove(commands_ac, value); } } @@ -1695,7 +1695,7 @@ cmd_autocomplete_remove(char *value) void cmd_alias_add(char *value) { - if (aliases_ac != NULL) { + if (aliases_ac) { autocomplete_add(aliases_ac, value); } } @@ -1703,7 +1703,7 @@ cmd_alias_add(char *value) void cmd_alias_remove(char *value) { - if (aliases_ac != NULL) { + if (aliases_ac) { autocomplete_remove(aliases_ac, value); } } @@ -1716,7 +1716,7 @@ cmd_autocomplete(const char * const input) if ((strncmp(input, "/", 1) == 0) && (!str_contains(input, strlen(input), ' '))) { char *found = NULL; found = autocomplete_complete(commands_ac, input, TRUE); - if (found != NULL) { + if (found) { return found; } @@ -1756,7 +1756,7 @@ cmd_reset_autocomplete() autocomplete_reset(autoaway_mode_ac); autocomplete_reset(autoconnect_ac); autocomplete_reset(theme_ac); - if (theme_load_ac != NULL) { + if (theme_load_ac) { autocomplete_free(theme_load_ac); theme_load_ac = NULL; } @@ -1887,7 +1887,7 @@ _cmd_execute(const char * const command, const char * const inp) Command *cmd = g_hash_table_lookup(commands, command); gboolean result = FALSE; - if (cmd != NULL) { + if (cmd) { gchar **args = cmd->parser(inp, cmd->min_args, cmd->max_args, &result); if (result == FALSE) { ui_invalid_command_usage(cmd->help.usage, cmd->setting_func); @@ -2034,7 +2034,7 @@ _cmd_complete_parameters(const char * const input) parsed[i] = '\0'; char * (*ac_func)(const char * const) = g_hash_table_lookup(ac_funcs, parsed); - if (ac_func != NULL) { + if (ac_func) { result = ac_func(input); if (result) { g_hash_table_destroy(ac_funcs); @@ -2058,15 +2058,15 @@ _sub_autocomplete(const char * const input) { char *result = NULL; result = autocomplete_param_with_func(input, "/sub allow", presence_sub_request_find); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_with_func(input, "/sub deny", presence_sub_request_find); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_with_ac(input, "/sub", sub_ac, TRUE); - if (result != NULL) { + if (result) { return result; } @@ -2081,7 +2081,7 @@ _who_autocomplete(const char * const input) if (win_type == WIN_MUC) { result = autocomplete_param_with_ac(input, "/who", who_room_ac, TRUE); - if (result != NULL) { + if (result) { return result; } } else { @@ -2092,13 +2092,13 @@ _who_autocomplete(const char * const input) for (i = 0; i < ARRAY_SIZE(group_commands); i++) { result = autocomplete_param_with_func(input, group_commands[i], roster_group_autocomplete); - if (result != NULL) { + if (result) { return result; } } result = autocomplete_param_with_ac(input, "/who", who_roster_ac, TRUE); - if (result != NULL) { + if (result) { return result; } } @@ -2111,31 +2111,31 @@ _roster_autocomplete(const char * const input) { char *result = NULL; result = autocomplete_param_with_func(input, "/roster nick", roster_barejid_autocomplete); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_with_func(input, "/roster clearnick", roster_barejid_autocomplete); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_with_func(input, "/roster remove", roster_barejid_autocomplete); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_with_ac(input, "/roster show", roster_option_ac, TRUE); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_with_ac(input, "/roster hide", roster_option_ac, TRUE); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_with_ac(input, "/roster by", roster_by_ac, TRUE); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_with_ac(input, "/roster", roster_ac, TRUE); - if (result != NULL) { + if (result) { return result; } @@ -2147,28 +2147,28 @@ _group_autocomplete(const char * const input) { char *result = NULL; result = autocomplete_param_with_func(input, "/group show", roster_group_autocomplete); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_no_with_func(input, "/group add", 4, roster_contact_autocomplete); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_no_with_func(input, "/group remove", 4, roster_contact_autocomplete); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_with_func(input, "/group add", roster_group_autocomplete); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_with_func(input, "/group remove", roster_group_autocomplete); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_with_ac(input, "/group", group_ac, TRUE); - if (result != NULL) { + if (result) { return result; } @@ -2229,7 +2229,7 @@ _bookmark_autocomplete(const char * const input) found = autocomplete_param_with_ac(input, beginning->str, bookmark_property_ac, TRUE); } g_string_free(beginning, TRUE); - if (found != NULL) { + if (found) { g_strfreev(args); return found; } @@ -2238,15 +2238,15 @@ _bookmark_autocomplete(const char * const input) g_strfreev(args); found = autocomplete_param_with_func(input, "/bookmark remove", bookmark_find); - if (found != NULL) { + if (found) { return found; } found = autocomplete_param_with_func(input, "/bookmark join", bookmark_find); - if (found != NULL) { + if (found) { return found; } found = autocomplete_param_with_func(input, "/bookmark update", bookmark_find); - if (found != NULL) { + if (found) { return found; } @@ -2261,42 +2261,42 @@ _notify_autocomplete(const char * const input) char *result = NULL; result = autocomplete_param_with_func(input, "/notify room current", prefs_autocomplete_boolean_choice); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_with_func(input, "/notify message current", prefs_autocomplete_boolean_choice); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_with_func(input, "/notify typing current", prefs_autocomplete_boolean_choice); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_with_func(input, "/notify room text", prefs_autocomplete_boolean_choice); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_with_func(input, "/notify message text", prefs_autocomplete_boolean_choice); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_with_ac(input, "/notify room", notify_room_ac, TRUE); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_with_ac(input, "/notify message", notify_message_ac, TRUE); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_with_ac(input, "/notify typing", notify_typing_ac, TRUE); - if (result != NULL) { + if (result) { return result; } @@ -2304,13 +2304,13 @@ _notify_autocomplete(const char * const input) for (i = 0; i < ARRAY_SIZE(boolean_choices); i++) { result = autocomplete_param_with_func(input, boolean_choices[i], prefs_autocomplete_boolean_choice); - if (result != NULL) { + if (result) { return result; } } result = autocomplete_param_with_ac(input, "/notify", notify_ac, TRUE); - if (result != NULL) { + if (result) { return result; } @@ -2323,16 +2323,16 @@ _autoaway_autocomplete(const char * const input) char *result = NULL; result = autocomplete_param_with_ac(input, "/autoaway mode", autoaway_mode_ac, TRUE); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_with_func(input, "/autoaway check", prefs_autocomplete_boolean_choice); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_with_ac(input, "/autoaway", autoaway_ac, TRUE); - if (result != NULL) { + if (result) { return result; } @@ -2346,16 +2346,16 @@ _log_autocomplete(const char * const input) result = autocomplete_param_with_func(input, "/log rotate", prefs_autocomplete_boolean_choice); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_with_func(input, "/log shared", prefs_autocomplete_boolean_choice); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_with_ac(input, "/log", log_ac, TRUE); - if (result != NULL) { + if (result) { return result; } @@ -2368,12 +2368,12 @@ _autoconnect_autocomplete(const char * const input) char *result = NULL; result = autocomplete_param_with_func(input, "/autoconnect set", accounts_find_enabled); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_with_ac(input, "/autoconnect", autoconnect_ac, TRUE); - if (result != NULL) { + if (result) { return result; } @@ -2386,12 +2386,12 @@ _otr_autocomplete(const char * const input) char *found = NULL; found = autocomplete_param_with_func(input, "/otr start", roster_contact_autocomplete); - if (found != NULL) { + if (found) { return found; } found = autocomplete_param_with_ac(input, "/otr log", otr_log_ac, TRUE); - if (found != NULL) { + if (found) { return found; } @@ -2406,7 +2406,7 @@ _otr_autocomplete(const char * const input) found = autocomplete_param_with_func(input, beginning->str, roster_contact_autocomplete); g_string_free(beginning, TRUE); - if (found != NULL) { + if (found) { g_strfreev(args); return found; } @@ -2415,18 +2415,18 @@ _otr_autocomplete(const char * const input) g_strfreev(args); found = autocomplete_param_with_ac(input, "/otr policy", otr_policy_ac, TRUE); - if (found != NULL) { + if (found) { return found; } found = autocomplete_param_with_func(input, "/otr warn", prefs_autocomplete_boolean_choice); - if (found != NULL) { + if (found) { return found; } found = autocomplete_param_with_ac(input, "/otr", otr_ac, TRUE); - if (found != NULL) { + if (found) { return found; } @@ -2442,7 +2442,7 @@ _theme_autocomplete(const char * const input) theme_load_ac = autocomplete_new(); GSList *themes = theme_list(); GSList *curr = themes; - while (curr != NULL) { + while (curr) { autocomplete_add(theme_load_ac, curr->data); curr = g_slist_next(curr); } @@ -2450,12 +2450,12 @@ _theme_autocomplete(const char * const input) autocomplete_add(theme_load_ac, "default"); } result = autocomplete_param_with_ac(input, "/theme load", theme_load_ac, TRUE); - if (result != NULL) { + if (result) { return result; } } result = autocomplete_param_with_ac(input, "/theme", theme_ac, TRUE); - if (result != NULL) { + if (result) { return result; } @@ -2474,24 +2474,24 @@ _resource_autocomplete(const char * const input) if (contact) { Autocomplete ac = p_contact_resource_ac(contact); found = autocomplete_param_with_ac(input, "/resource set", ac, FALSE); - if (found != NULL) { + if (found) { return found; } } } found = autocomplete_param_with_func(input, "/resource title", prefs_autocomplete_boolean_choice); - if (found != NULL) { + if (found) { return found; } found = autocomplete_param_with_func(input, "/resource message", prefs_autocomplete_boolean_choice); - if (found != NULL) { + if (found) { return found; } found = autocomplete_param_with_ac(input, "/resource", resource_ac, FALSE); - if (found != NULL) { + if (found) { return found; } @@ -2504,17 +2504,17 @@ _titlebar_autocomplete(const char * const input) char *found = NULL; found = autocomplete_param_with_func(input, "/titlebar show", prefs_autocomplete_boolean_choice); - if (found != NULL) { + if (found) { return found; } found = autocomplete_param_with_func(input, "/titlebar goodbye", prefs_autocomplete_boolean_choice); - if (found != NULL) { + if (found) { return found; } found = autocomplete_param_with_ac(input, "/titlebar", titlebar_ac, FALSE); - if (found != NULL) { + if (found) { return found; } @@ -2527,12 +2527,12 @@ _inpblock_autocomplete(const char * const input) char *found = NULL; found = autocomplete_param_with_func(input, "/inpblock dynamic", prefs_autocomplete_boolean_choice); - if (found != NULL) { + if (found) { return found; } found = autocomplete_param_with_ac(input, "/inpblock", inpblock_ac, FALSE); - if (found != NULL) { + if (found) { return found; } @@ -2553,13 +2553,13 @@ _form_autocomplete(const char * const input) DataForm *form = confwin->form; if (form) { found = autocomplete_param_with_ac(input, "/form help", form->tag_ac, TRUE); - if (found != NULL) { + if (found) { return found; } } found = autocomplete_param_with_ac(input, "/form", form_ac, TRUE); - if (found != NULL) { + if (found) { return found; } @@ -2643,32 +2643,32 @@ _occupants_autocomplete(const char * const input) char *found = NULL; found = autocomplete_param_with_ac(input, "/occupants default show", occupants_show_ac, TRUE); - if (found != NULL) { + if (found) { return found; } found = autocomplete_param_with_ac(input, "/occupants default hide", occupants_show_ac, TRUE); - if (found != NULL) { + if (found) { return found; } found = autocomplete_param_with_ac(input, "/occupants default", occupants_default_ac, TRUE); - if (found != NULL) { + if (found) { return found; } found = autocomplete_param_with_ac(input, "/occupants show", occupants_show_ac, TRUE); - if (found != NULL) { + if (found) { return found; } found = autocomplete_param_with_ac(input, "/occupants hide", occupants_show_ac, TRUE); - if (found != NULL) { + if (found) { return found; } found = autocomplete_param_with_ac(input, "/occupants", occupants_ac, TRUE); - if (found != NULL) { + if (found) { return found; } @@ -2681,12 +2681,12 @@ _time_autocomplete(const char * const input) char *found = NULL; found = autocomplete_param_with_ac(input, "/time statusbar", time_statusbar_ac, TRUE); - if (found != NULL) { + if (found) { return found; } found = autocomplete_param_with_ac(input, "/time", time_ac, TRUE); - if (found != NULL) { + if (found) { return found; } @@ -2702,9 +2702,9 @@ _kick_autocomplete(const char * const input) ProfMucWin *mucwin = wins_get_current_muc(); Autocomplete nick_ac = muc_roster_ac(mucwin->roomjid); - if (nick_ac != NULL) { + if (nick_ac) { result = autocomplete_param_with_ac(input, "/kick", nick_ac, TRUE); - if (result != NULL) { + if (result) { return result; } } @@ -2722,9 +2722,9 @@ _ban_autocomplete(const char * const input) ProfMucWin *mucwin = wins_get_current_muc(); Autocomplete jid_ac = muc_roster_jid_ac(mucwin->roomjid); - if (jid_ac != NULL) { + if (jid_ac) { result = autocomplete_param_with_ac(input, "/ban", jid_ac, TRUE); - if (result != NULL) { + if (result) { return result; } } @@ -2753,7 +2753,7 @@ _affiliation_autocomplete(const char * const input) result = autocomplete_param_with_ac(input, beginning->str, jid_ac, TRUE); g_string_free(beginning, TRUE); - if (result != NULL) { + if (result) { g_strfreev(args); return result; } @@ -2763,17 +2763,17 @@ _affiliation_autocomplete(const char * const input) } result = autocomplete_param_with_ac(input, "/affiliation set", affiliation_ac, TRUE); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_with_ac(input, "/affiliation list", affiliation_ac, TRUE); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_with_ac(input, "/affiliation", privilege_cmd_ac, TRUE); - if (result != NULL) { + if (result) { return result; } @@ -2800,7 +2800,7 @@ _role_autocomplete(const char * const input) result = autocomplete_param_with_ac(input, beginning->str, nick_ac, TRUE); g_string_free(beginning, TRUE); - if (result != NULL) { + if (result) { g_strfreev(args); return result; } @@ -2810,17 +2810,17 @@ _role_autocomplete(const char * const input) } result = autocomplete_param_with_ac(input, "/role set", role_ac, TRUE); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_with_ac(input, "/role list", role_ac, TRUE); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_with_ac(input, "/role", privilege_cmd_ac, TRUE); - if (result != NULL) { + if (result) { return result; } @@ -2833,22 +2833,22 @@ _statuses_autocomplete(const char * const input) char *result = NULL; result = autocomplete_param_with_ac(input, "/statuses console", statuses_setting_ac, TRUE); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_with_ac(input, "/statuses chat", statuses_setting_ac, TRUE); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_with_ac(input, "/statuses muc", statuses_setting_ac, TRUE); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_with_ac(input, "/statuses", statuses_ac, TRUE); - if (result != NULL) { + if (result) { return result; } @@ -2861,17 +2861,17 @@ _receipts_autocomplete(const char * const input) char *result = NULL; result = autocomplete_param_with_func(input, "/receipts send", prefs_autocomplete_boolean_choice); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_with_func(input, "/receipts request", prefs_autocomplete_boolean_choice); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_with_ac(input, "/receipts", receipts_ac, TRUE); - if (result != NULL) { + if (result) { return result; } @@ -2884,12 +2884,12 @@ _alias_autocomplete(const char * const input) char *result = NULL; result = autocomplete_param_with_ac(input, "/alias remove", aliases_ac, TRUE); - if (result != NULL) { + if (result) { return result; } result = autocomplete_param_with_ac(input, "/alias", alias_ac, TRUE); - if (result != NULL) { + if (result) { return result; } @@ -2907,7 +2907,7 @@ _connect_autocomplete(const char * const input) if ((strncmp(input, "/connect", 8) == 0) && (result == TRUE)) { GString *beginning = g_string_new("/connect "); g_string_append(beginning, args[0]); - if (args[1] != NULL && args[2] != NULL) { + if (args[1] && args[2]) { g_string_append(beginning, " "); g_string_append(beginning, args[1]); g_string_append(beginning, " "); @@ -2915,7 +2915,7 @@ _connect_autocomplete(const char * const input) } found = autocomplete_param_with_ac(input, beginning->str, connect_property_ac, TRUE); g_string_free(beginning, TRUE); - if (found != NULL) { + if (found) { g_strfreev(args); return found; } @@ -2924,7 +2924,7 @@ _connect_autocomplete(const char * const input) g_strfreev(args); found = autocomplete_param_with_func(input, "/connect", accounts_find_enabled); - if (found != NULL) { + if (found) { return found; } @@ -2938,7 +2938,7 @@ _join_autocomplete(const char * const input) gboolean result = FALSE; found = autocomplete_param_with_func(input, "/join", bookmark_find); - if (found != NULL) { + if (found) { return found; } @@ -2947,7 +2947,7 @@ _join_autocomplete(const char * const input) if ((strncmp(input, "/join", 5) == 0) && (result == TRUE)) { GString *beginning = g_string_new("/join "); g_string_append(beginning, args[0]); - if (args[1] != NULL && args[2] != NULL) { + if (args[1] && args[2]) { g_string_append(beginning, " "); g_string_append(beginning, args[1]); g_string_append(beginning, " "); @@ -2955,7 +2955,7 @@ _join_autocomplete(const char * const input) } found = autocomplete_param_with_ac(input, beginning->str, join_property_ac, TRUE); g_string_free(beginning, TRUE); - if (found != NULL) { + if (found) { g_strfreev(args); return found; } @@ -2982,14 +2982,14 @@ _account_autocomplete(const char * const input) g_string_append(beginning, args[2]); found = autocomplete_param_with_ac(input, beginning->str, otr_policy_ac, TRUE); g_string_free(beginning, TRUE); - if (found != NULL) { + if (found) { g_strfreev(args); return found; } } else { found = autocomplete_param_with_ac(input, beginning->str, account_set_ac, TRUE); g_string_free(beginning, TRUE); - if (found != NULL) { + if (found) { g_strfreev(args); return found; } @@ -3001,7 +3001,7 @@ _account_autocomplete(const char * const input) g_string_append(beginning, args[1]); found = autocomplete_param_with_ac(input, beginning->str, account_clear_ac, TRUE); g_string_free(beginning, TRUE); - if (found != NULL) { + if (found) { g_strfreev(args); return found; } @@ -3021,7 +3021,7 @@ _account_autocomplete(const char * const input) for (i = 0; i < ARRAY_SIZE(account_choice); i++) { found = autocomplete_param_with_func(input, account_choice[i], accounts_find_all); - if (found != NULL) { + if (found) { return found; } } @@ -3066,7 +3066,7 @@ command_docgen(void) fputs("

Details:

\n", main_fragment); fputs("

", main_fragment);
         int i = 2;
-        while (pcmd->help.long_help[i] != NULL) {
+        while (pcmd->help.long_help[i]) {
             fprintf(main_fragment, "%s\n", pcmd->help.long_help[i++]);
         }
         fputs("

\n
back to top


\n", main_fragment); From 4acf853b1c66a9fbc4b80d75144ea7dd01b6471d Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 22:23:59 +0100 Subject: [PATCH 205/252] Use null check convention in commands.c --- src/command/commands.c | 100 ++++++++++++++++++++--------------------- 1 file changed, 50 insertions(+), 50 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index dfabc4f0..3d7dcc67 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -404,7 +404,7 @@ cmd_account(gchar **args, struct cmd_help_t help) } else { accounts_set_jid(account_name, jid->barejid); cons_show("Updated jid for account %s: %s", account_name, jid->barejid); - if (jid->resourcepart != NULL) { + if (jid->resourcepart) { accounts_set_resource(account_name, jid->resourcepart); cons_show("Updated resource for account %s: %s", account_name, jid->resourcepart); } @@ -434,7 +434,7 @@ cmd_account(gchar **args, struct cmd_help_t help) cons_show("Updated resource for account %s: %s", account_name, value); cons_show(""); } else if (strcmp(property, "password") == 0) { - if(accounts_get_account(account_name)->eval_password != NULL) { + if(accounts_get_account(account_name)->eval_password) { cons_show("Cannot set password when eval_password is set."); } else { accounts_set_password(account_name, value); @@ -442,7 +442,7 @@ cmd_account(gchar **args, struct cmd_help_t help) cons_show(""); } } else if (strcmp(property, "eval_password") == 0) { - if(accounts_get_account(account_name)->password != NULL) { + if(accounts_get_account(account_name)->password) { cons_show("Cannot set eval_password when password is set."); } else { accounts_set_eval_password(account_name, value); @@ -755,7 +755,7 @@ cmd_help(gchar **args, struct cmd_help_t help) } GList *curr = ordered_commands; - while (curr != NULL) { + while (curr) { Command *cmd = curr->data; cons_show("%-12s: %s", cmd->cmd, cmd->help.short_help); curr = g_list_next(curr); @@ -817,12 +817,12 @@ cmd_help(gchar **args, struct cmd_help_t help) const gchar **help_text = NULL; Command *command = g_hash_table_lookup(commands, cmd_with_slash); - if (command != NULL) { + if (command) { help_text = command->help.long_help; } cons_show(""); - if (help_text != NULL) { + if (help_text) { ProfWin *console = wins_get_console(); ui_show_lines(console, help_text); } else { @@ -928,13 +928,13 @@ cmd_theme(gchar **args, struct cmd_help_t help) static void _who_room(gchar **args, struct cmd_help_t help) { - if ((g_strv_length(args) == 2) && (args[1] != NULL)) { + if ((g_strv_length(args) == 2) && args[1]) { cons_show("Argument group is not applicable to chat rooms."); return; } // bad arg - if (args[0] != NULL && + if (args[0] && (g_strcmp0(args[0], "online") != 0) && (g_strcmp0(args[0], "available") != 0) && (g_strcmp0(args[0], "unavailable") != 0) && @@ -978,7 +978,7 @@ _who_room(gchar **args, struct cmd_help_t help) } else if (strcmp("available", presence) == 0) { GList *filtered = NULL; - while (occupants != NULL) { + while (occupants) { Occupant *occupant = occupants->data; if (muc_occupant_available(occupant)) { filtered = g_list_append(filtered, occupant); @@ -992,7 +992,7 @@ _who_room(gchar **args, struct cmd_help_t help) } else if (strcmp("unavailable", presence) == 0) { GList *filtered = NULL; - while (occupants != NULL) { + while (occupants) { Occupant *occupant = occupants->data; if (!muc_occupant_available(occupant)) { filtered = g_list_append(filtered, occupant); @@ -1006,7 +1006,7 @@ _who_room(gchar **args, struct cmd_help_t help) } else { GList *filtered = NULL; - while (occupants != NULL) { + while (occupants) { Occupant *occupant = occupants->data; const char *presence_str = string_from_resource_presence(occupant->presence); if (strcmp(presence_str, presence) == 0) { @@ -1060,7 +1060,7 @@ _who_roster(gchar **args, struct cmd_help_t help) char *presence = args[0]; // bad arg - if ((presence != NULL) + if (presence && (strcmp(presence, "online") != 0) && (strcmp(presence, "available") != 0) && (strcmp(presence, "unavailable") != 0) @@ -1075,13 +1075,13 @@ _who_roster(gchar **args, struct cmd_help_t help) } char *group = NULL; - if ((g_strv_length(args) == 2) && (args[1] != NULL)) { + if ((g_strv_length(args) == 2) && args[1]) { group = args[1]; } cons_show(""); GSList *list = NULL; - if (group != NULL) { + if (group) { list = roster_get_group(group); if (list == NULL) { cons_show("No such group: %s.", group); @@ -1097,7 +1097,7 @@ _who_roster(gchar **args, struct cmd_help_t help) // no arg, show all contacts if ((presence == NULL) || (g_strcmp0(presence, "any") == 0)) { - if (group != NULL) { + if (group) { if (list == NULL) { cons_show("No contacts in group %s.", group); } else { @@ -1118,7 +1118,7 @@ _who_roster(gchar **args, struct cmd_help_t help) GSList *filtered = NULL; GSList *curr = list; - while (curr != NULL) { + while (curr) { PContact contact = curr->data; if (p_contact_is_available(contact)) { filtered = g_slist_append(filtered, contact); @@ -1126,7 +1126,7 @@ _who_roster(gchar **args, struct cmd_help_t help) curr = g_slist_next(curr); } - if (group != NULL) { + if (group) { if (filtered == NULL) { cons_show("No contacts in group %s are %s.", group, presence); } else { @@ -1148,7 +1148,7 @@ _who_roster(gchar **args, struct cmd_help_t help) GSList *filtered = NULL; GSList *curr = list; - while (curr != NULL) { + while (curr) { PContact contact = curr->data; if (!p_contact_is_available(contact)) { filtered = g_slist_append(filtered, contact); @@ -1156,7 +1156,7 @@ _who_roster(gchar **args, struct cmd_help_t help) curr = g_slist_next(curr); } - if (group != NULL) { + if (group) { if (filtered == NULL) { cons_show("No contacts in group %s are %s.", group, presence); } else { @@ -1178,7 +1178,7 @@ _who_roster(gchar **args, struct cmd_help_t help) GSList *filtered = NULL; GSList *curr = list; - while (curr != NULL) { + while (curr) { PContact contact = curr->data; if (p_contact_has_available_resource(contact)) { filtered = g_slist_append(filtered, contact); @@ -1186,7 +1186,7 @@ _who_roster(gchar **args, struct cmd_help_t help) curr = g_slist_next(curr); } - if (group != NULL) { + if (group) { if (filtered == NULL) { cons_show("No contacts in group %s are %s.", group, presence); } else { @@ -1208,7 +1208,7 @@ _who_roster(gchar **args, struct cmd_help_t help) GSList *filtered = NULL; GSList *curr = list; - while (curr != NULL) { + while (curr) { PContact contact = curr->data; if (!p_contact_has_available_resource(contact)) { filtered = g_slist_append(filtered, contact); @@ -1216,7 +1216,7 @@ _who_roster(gchar **args, struct cmd_help_t help) curr = g_slist_next(curr); } - if (group != NULL) { + if (group) { if (filtered == NULL) { cons_show("No contacts in group %s are %s.", group, presence); } else { @@ -1238,7 +1238,7 @@ _who_roster(gchar **args, struct cmd_help_t help) GSList *filtered = NULL; GSList *curr = list; - while (curr != NULL) { + while (curr) { PContact contact = curr->data; if (strcmp(p_contact_presence(contact), presence) == 0) { filtered = g_slist_append(filtered, contact); @@ -1246,7 +1246,7 @@ _who_roster(gchar **args, struct cmd_help_t help) curr = g_slist_next(curr); } - if (group != NULL) { + if (group) { if (filtered == NULL) { cons_show("No contacts in group %s are %s.", group, presence); } else { @@ -1369,9 +1369,9 @@ cmd_group(gchar **args, struct cmd_help_t help) if (args[0] == NULL) { GSList *groups = roster_get_groups(); GSList *curr = groups; - if (curr != NULL) { + if (curr) { cons_show("Groups:"); - while (curr != NULL) { + while (curr) { cons_show(" %s", curr->data); curr = g_slist_next(curr); } @@ -1739,7 +1739,7 @@ cmd_status(gchar **args, struct cmd_help_t help) switch (win_type) { case WIN_MUC: - if (usr != NULL) { + if (usr) { ProfMucWin *mucwin = wins_get_current_muc(); ProfWin *window = (ProfWin*) mucwin; Occupant *occupant = muc_roster_item(mucwin->roomjid, usr); @@ -1753,13 +1753,13 @@ cmd_status(gchar **args, struct cmd_help_t help) } break; case WIN_CHAT: - if (usr != NULL) { + if (usr) { ui_current_print_line("No parameter required when in chat."); } else { ProfChatWin *chatwin = wins_get_current_chat(); ProfWin *window = (ProfWin*) chatwin; PContact pcontact = roster_get_contact(chatwin->barejid); - if (pcontact != NULL) { + if (pcontact) { win_show_contact(window, pcontact); } else { win_println(window, "Error getting contact info."); @@ -1767,7 +1767,7 @@ cmd_status(gchar **args, struct cmd_help_t help) } break; case WIN_PRIVATE: - if (usr != NULL) { + if (usr) { ui_current_print_line("No parameter required when in chat."); } else { ProfPrivateWin *privatewin = wins_get_current_private(); @@ -1783,7 +1783,7 @@ cmd_status(gchar **args, struct cmd_help_t help) } break; case WIN_CONSOLE: - if (usr != NULL) { + if (usr) { char *usr_jid = roster_barejid_from_name(usr); if (usr_jid == NULL) { usr_jid = usr; @@ -1840,7 +1840,7 @@ cmd_info(gchar **args, struct cmd_help_t help) ProfChatWin *chatwin = wins_get_current_chat(); ProfWin *window = (ProfWin*) chatwin; PContact pcontact = roster_get_contact(chatwin->barejid); - if (pcontact != NULL) { + if (pcontact) { win_show_info(window, pcontact); } else { win_println(window, "Error getting contact info."); @@ -1870,7 +1870,7 @@ cmd_info(gchar **args, struct cmd_help_t help) usr_jid = usr; } pcontact = roster_get_contact(usr_jid); - if (pcontact != NULL) { + if (pcontact) { cons_show_info(pcontact); } else { cons_show("No such contact \"%s\" in roster.", usr); @@ -1902,7 +1902,7 @@ cmd_caps(gchar **args, struct cmd_help_t help) switch (win_type) { case WIN_MUC: - if (args[0] != NULL) { + if (args[0]) { ProfMucWin *mucwin = wins_get_current_muc(); occupant = muc_roster_item(mucwin->roomjid, args[0]); if (occupant) { @@ -1918,7 +1918,7 @@ cmd_caps(gchar **args, struct cmd_help_t help) break; case WIN_CHAT: case WIN_CONSOLE: - if (args[0] != NULL) { + if (args[0]) { Jid *jid = jid_create(args[0]); if (jid->fulljid == NULL) { @@ -1942,7 +1942,7 @@ cmd_caps(gchar **args, struct cmd_help_t help) } break; case WIN_PRIVATE: - if (args[0] != NULL) { + if (args[0]) { cons_show("No parameter needed to /caps when in private chat."); } else { ProfPrivateWin *privatewin = wins_get_current_private(); @@ -1977,7 +1977,7 @@ cmd_software(gchar **args, struct cmd_help_t help) switch (win_type) { case WIN_MUC: - if (args[0] != NULL) { + if (args[0]) { ProfMucWin *mucwin = wins_get_current_muc(); occupant = muc_roster_item(mucwin->roomjid, args[0]); if (occupant) { @@ -1993,7 +1993,7 @@ cmd_software(gchar **args, struct cmd_help_t help) break; case WIN_CHAT: case WIN_CONSOLE: - if (args[0] != NULL) { + if (args[0]) { Jid *jid = jid_create(args[0]); if (jid == NULL || jid->fulljid == NULL) { @@ -2007,7 +2007,7 @@ cmd_software(gchar **args, struct cmd_help_t help) } break; case WIN_PRIVATE: - if (args[0] != NULL) { + if (args[0]) { cons_show("No parameter needed to /software when in private chat."); } else { ProfPrivateWin *privatewin = wins_get_current_private(); @@ -2067,7 +2067,7 @@ cmd_join(gchar **args, struct cmd_help_t help) ProfAccount *account = accounts_get_account(account_name); // full room jid supplied (room@server) - if (room_arg->localpart != NULL) { + if (room_arg->localpart) { room = args[0]; // server not supplied (room), use account preference @@ -2142,7 +2142,7 @@ cmd_invite(gchar **args, struct cmd_help_t help) ProfMucWin *mucwin = wins_get_current_muc(); message_send_invite(mucwin->roomjid, usr_jid, reason); - if (reason != NULL) { + if (reason) { cons_show("Room invite sent, contact: %s, room: %s, reason: \"%s\".", contact, mucwin->roomjid, reason); } else { @@ -2427,7 +2427,7 @@ cmd_form(gchar **args, struct cmd_help_t help) if (g_strcmp0(args[0], "help") == 0) { char *tag = args[1]; - if (tag != NULL) { + if (tag) { ui_show_form_field_help(confwin, tag); } else { ui_show_form_help(confwin); @@ -2435,7 +2435,7 @@ cmd_form(gchar **args, struct cmd_help_t help) const gchar **help_text = NULL; Command *command = g_hash_table_lookup(commands, "/form"); - if (command != NULL) { + if (command) { help_text = command->help.long_help; } @@ -2601,7 +2601,7 @@ cmd_affiliation(gchar **args, struct cmd_help_t help) } char *affiliation = args[1]; - if ((affiliation != NULL) && + if (affiliation && (g_strcmp0(affiliation, "owner") != 0) && (g_strcmp0(affiliation, "admin") != 0) && (g_strcmp0(affiliation, "member") != 0) && @@ -2671,7 +2671,7 @@ cmd_role(gchar **args, struct cmd_help_t help) } char *role = args[1]; - if ((role != NULL ) && + if (role && (g_strcmp0(role, "visitor") != 0) && (g_strcmp0(role, "participant") != 0) && (g_strcmp0(role, "moderator") != 0) && @@ -2961,7 +2961,7 @@ cmd_bookmark(gchar **args, struct cmd_help_t help) char *password = g_hash_table_lookup(options, "password"); char *autojoin = g_hash_table_lookup(options, "autojoin"); - if (autojoin != NULL) { + if (autojoin) { if ((strcmp(autojoin, "on") != 0) && (strcmp(autojoin, "off") != 0)) { cons_show("Usage: %s", help.usage); cons_show(""); @@ -3009,7 +3009,7 @@ cmd_disco(gchar **args, struct cmd_help_t help) } GString *jid = g_string_new(""); - if (args[1] != NULL) { + if (args[1]) { jid = g_string_append(jid, args[1]); } else { Jid *jidp = jid_create(jabber_get_fulljid()); @@ -4164,7 +4164,7 @@ cmd_otr(gchar **args, struct cmd_help_t help) return TRUE; } else if (strcmp(args[0], "start") == 0) { - if (args[1] != NULL) { + if (args[1]) { char *contact = args[1]; char *barejid = roster_barejid_from_name(contact); if (barejid == NULL) { @@ -4383,7 +4383,7 @@ _cmd_show_filtered_help(char *heading, gchar *cmd_filter[], int filter_size) } GList *curr = ordered_commands; - while (curr != NULL) { + while (curr) { Command *cmd = curr->data; cons_show("%-12s: %s", cmd->cmd, cmd->help.short_help); curr = g_list_next(curr); From 47549452f178a9a81a5481e87d8004ce6010e3c1 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 22:29:51 +0100 Subject: [PATCH 206/252] Use null check convention in account.c --- src/config/account.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/config/account.c b/src/config/account.c index 749eb885..857d049b 100644 --- a/src/config/account.c +++ b/src/config/account.c @@ -57,19 +57,19 @@ account_new(const gchar * const name, const gchar * const jid, new_account->name = strdup(name); - if (jid != NULL) { + if (jid) { new_account->jid = strdup(jid); } else { new_account->jid = strdup(name); } - if (password != NULL) { + if (password) { new_account->password = strdup(password); } else { new_account->password = NULL; } - if (eval_password != NULL) { + if (eval_password) { new_account->eval_password = strdup(eval_password); } else { new_account->eval_password = NULL; @@ -77,13 +77,13 @@ account_new(const gchar * const name, const gchar * const jid, new_account->enabled = enabled; - if (server != NULL) { + if (server) { new_account->server = strdup(server); } else { new_account->server = NULL; } - if (resource != NULL) { + if (resource) { new_account->resource = strdup(resource); } else { new_account->resource = NULL; @@ -134,7 +134,7 @@ account_new(const gchar * const name, const gchar * const jid, new_account->muc_nick = strdup(muc_nick); } - if (otr_policy != NULL) { + if (otr_policy) { new_account->otr_policy = strdup(otr_policy); } else { new_account->otr_policy = NULL; @@ -150,7 +150,7 @@ account_new(const gchar * const name, const gchar * const jid, char * account_create_full_jid(ProfAccount *account) { - if (account->resource != NULL) { + if (account->resource) { return create_fulljid(account->jid, account->resource); } else { return strdup(account->jid); @@ -198,7 +198,7 @@ account_eval_password(ProfAccount *account) void account_free(ProfAccount *account) { - if (account != NULL) { + if (account) { free(account->name); free(account->jid); free(account->password); From a293045d855ab04aa9beff7924e1f5ec2d0403fc Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 22:32:42 +0100 Subject: [PATCH 207/252] Use null check convention in accounts.c --- src/config/accounts.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/config/accounts.c b/src/config/accounts.c index 6c04549c..d68f3a55 100644 --- a/src/config/accounts.c +++ b/src/config/accounts.c @@ -147,9 +147,9 @@ accounts_add(const char *account_name, const char *altdomain, const int port) const char *barejid = account_name; const char *resource = "profanity"; Jid *jid = jid_create(account_name); - if (jid != NULL) { + if (jid) { barejid = jid->barejid; - if (jid->resourcepart != NULL) { + if (jid->resourcepart) { resource = jid->resourcepart; } } @@ -159,7 +159,7 @@ accounts_add(const char *account_name, const char *altdomain, const int port) g_key_file_set_boolean(accounts, account_name, "enabled", TRUE); g_key_file_set_string(accounts, account_name, "jid", barejid); g_key_file_set_string(accounts, account_name, "resource", resource); - if (altdomain != NULL) { + if (altdomain) { g_key_file_set_string(accounts, account_name, "server", altdomain); } if (port != 0) { @@ -252,7 +252,7 @@ accounts_get_account(const char * const name) gsize length; GList *otr_manual = NULL; gchar **manual = g_key_file_get_string_list(accounts, name, "otr.manual", &length, NULL); - if (manual != NULL) { + if (manual) { int i = 0; for (i = 0; i < length; i++) { otr_manual = g_list_append(otr_manual, strdup(manual[i])); @@ -262,7 +262,7 @@ accounts_get_account(const char * const name) GList *otr_opportunistic = NULL; gchar **opportunistic = g_key_file_get_string_list(accounts, name, "otr.opportunistic", &length, NULL); - if (opportunistic != NULL) { + if (opportunistic) { int i = 0; for (i = 0; i < length; i++) { otr_opportunistic = g_list_append(otr_opportunistic, strdup(opportunistic[i])); @@ -272,7 +272,7 @@ accounts_get_account(const char * const name) GList *otr_always = NULL; gchar **always = g_key_file_get_string_list(accounts, name, "otr.always", &length, NULL); - if (always != NULL) { + if (always) { int i = 0; for (i = 0; i < length; i++) { otr_always = g_list_append(otr_always, strdup(always[i])); @@ -356,7 +356,7 @@ accounts_rename(const char * const account_name, const char * const new_name) int i; for (i = 0; i < ARRAY_SIZE(string_keys); i++) { char *value = g_key_file_get_string(accounts, account_name, string_keys[i], NULL); - if (value != NULL) { + if (value) { g_key_file_set_string(accounts, new_name, string_keys[i], value); g_free(value); } @@ -386,10 +386,10 @@ void accounts_set_jid(const char * const account_name, const char * const value) { Jid *jid = jid_create(value); - if (jid != NULL) { + if (jid) { if (accounts_account_exists(account_name)) { g_key_file_set_string(accounts, account_name, "jid", jid->barejid); - if (jid->resourcepart != NULL) { + if (jid->resourcepart) { g_key_file_set_string(accounts, account_name, "resource", jid->resourcepart); } @@ -509,7 +509,7 @@ accounts_add_otr_policy(const char * const account_name, const char * const cont GList *glist = NULL; // list found - if (list != NULL) { + if (list) { int i = 0; for (i = 0; i < length; i++) { // item already in list, exit function @@ -529,7 +529,7 @@ accounts_add_otr_policy(const char * const account_name, const char * const cont const gchar* new_list[g_list_length(glist)+1]; GList *curr = glist; i = 0; - while (curr != NULL) { + while (curr) { new_list[i++] = strdup(curr->data); curr = g_list_next(curr); } @@ -572,7 +572,7 @@ _remove_from_list(GKeyFile *accounts, const char * const account_name, const cha gsize length; gchar **list = g_key_file_get_string_list(accounts, account_name, key, &length, NULL); - if (list != NULL) { + if (list) { int i = 0; GList *glist = NULL; gboolean deleted = FALSE; @@ -595,7 +595,7 @@ _remove_from_list(GKeyFile *accounts, const char * const account_name, const cha const gchar* new_list[g_list_length(glist)+1]; GList *curr = glist; i = 0; - while (curr != NULL) { + while (curr) { new_list[i++] = strdup(curr->data); curr = g_list_next(curr); } @@ -766,7 +766,7 @@ accounts_get_last_presence(const char * const account_name) result = RESOURCE_ONLINE; } - if (setting != NULL) { + if (setting) { g_free(setting); } return result; @@ -796,7 +796,7 @@ accounts_get_login_presence(const char * const account_name) result = RESOURCE_ONLINE; } - if (setting != NULL) { + if (setting) { g_free(setting); } return result; @@ -809,9 +809,9 @@ _fix_legacy_accounts(const char * const account_name) const char *barejid = account_name; const char *resource = "profanity"; Jid *jid = jid_create(account_name); - if (jid != NULL) { + if (jid) { barejid = jid->barejid; - if (jid->resourcepart != NULL) { + if (jid->resourcepart) { resource = jid->resourcepart; } } From b093b99c15c109eb56f0386f8add5529b5e76a4c Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 22:33:19 +0100 Subject: [PATCH 208/252] Use null check convention in preferences.c --- src/config/preferences.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/config/preferences.c b/src/config/preferences.c index 3ca3a721..59a6a7ca 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -95,7 +95,7 @@ prefs_load(void) err = NULL; log_maxsize = g_key_file_get_integer(prefs, PREF_GROUP_LOGGING, "maxsize", &err); - if (err != NULL) { + if (err) { log_maxsize = 0; g_error_free(err); } @@ -180,7 +180,7 @@ prefs_get_string(preference_t pref) char *result = g_key_file_get_string(prefs, group, key, NULL); if (result == NULL) { - if (def != NULL) { + if (def) { return strdup(def); } else { return NULL; @@ -193,7 +193,7 @@ prefs_get_string(preference_t pref) void prefs_free_string(char *pref) { - if (pref != NULL) { + if (pref) { free(pref); } pref = NULL; @@ -419,7 +419,7 @@ prefs_get_aliases(void) char *name = keys[i]; char *value = g_key_file_get_string(prefs, PREF_GROUP_ALIAS, name, NULL); - if (value != NULL) { + if (value) { ProfAlias *alias = malloc(sizeof(struct prof_alias_t)); alias->name = strdup(name); alias->value = strdup(value); From 4ba33005d0e5333ff15d9af40663741f6884c649 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 22:33:55 +0100 Subject: [PATCH 209/252] Use null check convention in theme.c --- src/config/theme.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/config/theme.c b/src/config/theme.c index 1ee9836b..f73dee19 100644 --- a/src/config/theme.c +++ b/src/config/theme.c @@ -160,7 +160,7 @@ _theme_load_file(const char * const theme_name) { // use default theme if (theme_name == NULL || strcmp(theme_name, "default") == 0) { - if (theme != NULL) { + if (theme) { g_key_file_free(theme); } theme = g_key_file_new(); @@ -173,12 +173,12 @@ _theme_load_file(const char * const theme_name) return FALSE; } - if (theme_loc != NULL) { + if (theme_loc) { g_string_free(theme_loc, TRUE); } theme_loc = new_theme_file; log_info("Loading theme \"%s\"", theme_name); - if (theme != NULL) { + if (theme) { g_key_file_free(theme); } theme = g_key_file_new(); @@ -205,10 +205,10 @@ theme_list(void) void theme_close(void) { - if (theme != NULL) { + if (theme) { g_key_file_free(theme); } - if (theme_loc != NULL) { + if (theme_loc) { g_string_free(theme_loc, TRUE); } if (bold_items) { @@ -476,9 +476,9 @@ void _theme_list_dir(const gchar * const dir, GSList **result) { GDir *themes = g_dir_open(dir, 0, NULL); - if (themes != NULL) { + if (themes) { const gchar *theme = g_dir_read_name(themes); - while (theme != NULL) { + while (theme) { *result = g_slist_append(*result, strdup(theme)); theme = g_dir_read_name(themes); } @@ -492,7 +492,7 @@ _theme_find(const char * const theme_name) GString *path = NULL; gchar *themes_dir = _get_themes_dir(); - if (themes_dir != NULL) { + if (themes_dir) { path = g_string_new(themes_dir); g_free(themes_dir); g_string_append(path, "/"); From 4dc90334728b61f02ac3ee3508a663ae227b9fab Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 22:51:15 +0100 Subject: [PATCH 210/252] Use null check convention in server_events.c --- src/event/server_events.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/event/server_events.c b/src/event/server_events.c index 03d53901..e409e06a 100644 --- a/src/event/server_events.c +++ b/src/event/server_events.c @@ -63,9 +63,9 @@ sv_ev_login_account_success(char *account_name) // attempt to rejoin rooms with passwords GList *curr = muc_rooms(); - while (curr != NULL) { + while (curr) { char *password = muc_password(curr->data); - if (password != NULL) { + if (password) { char *nick = muc_nick(curr->data); presence_join_room(curr->data, nick, password); } @@ -271,7 +271,7 @@ sv_ev_contact_offline(char *barejid, char *resource, char *status) { gboolean updated = roster_contact_offline(barejid, resource, status); - if (resource != NULL && updated) { + if (resource && updated) { ui_contact_offline(barejid, resource, status); } @@ -289,7 +289,7 @@ sv_ev_contact_online(char *barejid, Resource *resource, char *show_console = prefs_get_string(PREF_STATUSES_CONSOLE); char *show_chat_win = prefs_get_string(PREF_STATUSES_CHAT); PContact contact = roster_get_contact(barejid); - if (p_contact_subscription(contact) != NULL) { + if (p_contact_subscription(contact)) { if (strcmp(p_contact_subscription(contact), "none") != 0) { // show in console if "all" @@ -441,14 +441,14 @@ sv_ev_muc_self_online(const char * const room, const char * const nick, gboolean } char *subject = muc_subject(room); - if (subject != NULL) { + if (subject) { ui_room_subject(room, NULL, subject); } GList *pending_broadcasts = muc_pending_broadcasts(room); - if (pending_broadcasts != NULL) { + if (pending_broadcasts) { GList *curr = pending_broadcasts; - while (curr != NULL) { + while (curr) { ui_room_broadcast(room, curr->data); curr = g_list_next(curr); } From a979d23e10a5ad2ee25dab12c1fbbb66b5362a6e Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 22:52:48 +0100 Subject: [PATCH 211/252] Use null check convention in otr.c --- src/otr/otr.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/otr/otr.c b/src/otr/otr.c index fbc26eb8..e568af56 100644 --- a/src/otr/otr.c +++ b/src/otr/otr.c @@ -179,7 +179,7 @@ otr_init(void) void otr_shutdown(void) { - if (jid != NULL) { + if (jid) { free(jid); } } @@ -193,7 +193,7 @@ otr_poll(void) void otr_on_connect(ProfAccount *account) { - if (jid != NULL) { + if (jid) { free(jid); } jid = strdup(account->jid); @@ -360,7 +360,7 @@ otr_keygen(ProfAccount *account) return; } - if (jid != NULL) { + if (jid) { free(jid); } jid = strdup(account->jid); @@ -516,7 +516,7 @@ otr_trust(const char * const recipient) } if (context->active_fingerprint) { - if (context->active_fingerprint->trust != NULL) { + if (context->active_fingerprint->trust) { free(context->active_fingerprint->trust); } context->active_fingerprint->trust = strdup("trusted"); @@ -540,7 +540,7 @@ otr_untrust(const char * const recipient) } if (context->active_fingerprint) { - if (context->active_fingerprint->trust != NULL) { + if (context->active_fingerprint->trust) { free(context->active_fingerprint->trust); } context->active_fingerprint->trust = NULL; @@ -629,7 +629,7 @@ otr_get_their_fingerprint(const char * const recipient) { ConnContext *context = otrlib_context_find(user_state, recipient, jid); - if (context != NULL) { + if (context) { Fingerprint *fingerprint = context->active_fingerprint; char readable[45]; otrl_privkey_hash_to_human(readable, fingerprint->fingerprint); @@ -658,7 +658,7 @@ otr_get_policy(const char * const recipient) } // check default account setting - if (account->otr_policy != NULL) { + if (account->otr_policy) { prof_otrpolicy_t result; if (g_strcmp0(account->otr_policy, "manual") == 0) { result = PROF_OTRPOLICY_MANUAL; @@ -720,7 +720,7 @@ otr_decrypt_message(const char * const from, const char * const message, gboolea OtrlTLV *tlv = otrl_tlv_find(tlvs, OTRL_TLV_DISCONNECTED); if (tlv) { - if (context != NULL) { + if (context) { otrl_context_force_plaintext(context); ui_gone_insecure(from); } @@ -732,7 +732,7 @@ otr_decrypt_message(const char * const from, const char * const message, gboolea return NULL; // message was decrypted, return to user - } else if (decrypted != NULL) { + } else if (decrypted) { *was_decrypted = TRUE; return decrypted; From 2426a7fcfcfa2ee4e5ab0f9300e7d5296170f893 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 22:55:04 +0100 Subject: [PATCH 212/252] Use null check convention in otrlibv3.c --- src/otr/otrlibv3.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/otr/otrlibv3.c b/src/otr/otrlibv3.c index 77b0ee77..0b81796c 100644 --- a/src/otr/otrlibv3.c +++ b/src/otr/otrlibv3.c @@ -87,7 +87,7 @@ otrlib_end_session(OtrlUserState user_state, const char * const recipient, char ConnContext *context = otrl_context_find(user_state, recipient, jid, "xmpp", 0, NULL, NULL, NULL); - if (context != NULL) { + if (context) { otrl_message_disconnect(user_state, ops, NULL, jid, "xmpp", recipient); } } @@ -171,7 +171,7 @@ otrlib_handle_tlvs(OtrlUserState user_state, OtrlMessageAppOps *ops, ConnContext } else { context->smstate->nextExpected = OTRL_SMP_EXPECT1; if (context->smstate->received_question == 0) { - if ((context->active_fingerprint->trust != NULL) && (context->active_fingerprint->trust[0] != '\0')) { + if (context->active_fingerprint->trust && (context->active_fingerprint->trust[0] != '\0')) { ui_smp_successful(context->username); ui_trust(context->username); } else { @@ -193,7 +193,7 @@ otrlib_handle_tlvs(OtrlUserState user_state, OtrlMessageAppOps *ops, ConnContext otrl_message_abort_smp(user_state, ops, NULL, context); } else { context->smstate->nextExpected = OTRL_SMP_EXPECT1; - if ((context->active_fingerprint->trust != NULL) && (context->active_fingerprint->trust[0] != '\0')) { + if (context->active_fingerprint->trust && (context->active_fingerprint->trust[0] != '\0')) { ui_smp_successful(context->username); ui_trust(context->username); } else { From fa2e33e11d45e3df363da2c4ca3b2a6137f955df Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 22:55:28 +0100 Subject: [PATCH 213/252] Use null check convention in otrlibv4.c --- src/otr/otrlibv4.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/otr/otrlibv4.c b/src/otr/otrlibv4.c index 713e51ab..fc1f5285 100644 --- a/src/otr/otrlibv4.c +++ b/src/otr/otrlibv4.c @@ -253,7 +253,7 @@ otrlib_end_session(OtrlUserState user_state, const char * const recipient, char ConnContext *context = otrl_context_find(user_state, recipient, jid, "xmpp", OTRL_INSTAG_MASTER, 0, NULL, NULL, NULL); - if (context != NULL) { + if (context) { otrl_message_disconnect(user_state, ops, NULL, jid, "xmpp", recipient, 0); } } From fe216b4e9777abe658c6a24e5c5faf5247e4b74d Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 22:57:19 +0100 Subject: [PATCH 214/252] Use null check convention in parser.c --- src/tools/parser.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/tools/parser.c b/src/tools/parser.c index 1f8a5220..d3a23264 100644 --- a/src/tools/parser.c +++ b/src/tools/parser.c @@ -156,7 +156,7 @@ parse_args(const char * const inp, int min, int max, gboolean *result) token = g_slist_next(token); int arg_count = 0; - while (token != NULL) { + while (token) { args[arg_count++] = strdup(token->data); token = g_slist_next(token); } @@ -303,7 +303,7 @@ parse_args_with_freetext(const char * const inp, int min, int max, gboolean *res token = g_slist_next(token); int arg_count = 0; - while (token != NULL) { + while (token) { args[arg_count++] = strdup(token->data); token = g_slist_next(token); } @@ -419,7 +419,7 @@ parse_options(gchar **args, gchar **opt_keys, gboolean *res) } // check if duplicate - if (g_list_find_custom(found_keys, args[curr], (GCompareFunc)g_strcmp0) != NULL) { + if (g_list_find_custom(found_keys, args[curr], (GCompareFunc)g_strcmp0)) { *res = FALSE; g_list_free(keys); return options; @@ -450,7 +450,7 @@ parse_options(gchar **args, gchar **opt_keys, gboolean *res) void options_destroy(GHashTable *options) { - if (options != NULL) { + if (options) { g_hash_table_destroy(options); } } From 09e1e7618e08a406dae31e55fddbd30975b4b354 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 22:57:49 +0100 Subject: [PATCH 215/252] Use null check convention in tinyurl.c --- src/tools/tinyurl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/tinyurl.c b/src/tools/tinyurl.c index 34e8967a..92ff97b8 100644 --- a/src/tools/tinyurl.c +++ b/src/tools/tinyurl.c @@ -74,7 +74,7 @@ tinyurl_get(char *url) g_string_free(full_url, TRUE); - if (output.buffer != NULL) { + if (output.buffer) { output.buffer[output.size++] = '\0'; return output.buffer; } else { From 2e2b3f9403f1935447d1363873d6519db6c8d537 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 23:02:57 +0100 Subject: [PATCH 216/252] Use null check convention in console.c --- src/ui/console.c | 160 +++++++++++++++++++++++------------------------ 1 file changed, 80 insertions(+), 80 deletions(-) diff --git a/src/ui/console.c b/src/ui/console.c index 8dfd473f..a41ccad6 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -126,8 +126,8 @@ cons_show_typing(const char * const barejid) ProfWin *console = wins_get_console(); const char * display_usr = NULL; PContact contact = roster_get_contact(barejid); - if (contact != NULL) { - if (p_contact_name(contact) != NULL) { + if (contact) { + if (p_contact_name(contact)) { display_usr = p_contact_name(contact); } else { display_usr = barejid; @@ -200,7 +200,7 @@ cons_check_version(gboolean not_available_msg) ProfWin *console = wins_get_console(); char *latest_release = release_get_latest(); - if (latest_release != NULL) { + if (latest_release) { gboolean relase_valid = g_regex_match_simple("^\\d+\\.\\d+\\.\\d+$", latest_release, 0, 0); if (relase_valid) { @@ -247,7 +247,7 @@ cons_show_wins(void) GSList *window_strings = wins_create_summary(); GSList *curr = window_strings; - while (curr != NULL) { + while (curr) { win_println(console, curr->data); curr = g_slist_next(curr); } @@ -265,7 +265,7 @@ cons_show_room_invites(GSList *invites) cons_show("No outstanding chat room invites."); } else { cons_show("Chat room invites, use /join or /decline commands:"); - while (invites != NULL) { + while (invites) { cons_show(" %s", invites->data); invites = g_slist_next(invites); } @@ -298,48 +298,48 @@ cons_show_caps(const char * const fulljid, resource_presence_t presence) win_print(console, '-', NULL, NO_DATE, 0, "", ":"); // show identity - if ((caps->category != NULL) || (caps->type != NULL) || (caps->name != NULL)) { + if (caps->category || caps->type || caps->name) { win_print(console, '-', NULL, NO_EOL, 0, "", "Identity: "); - if (caps->name != NULL) { + if (caps->name) { win_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->name); - if ((caps->category != NULL) || (caps->type != NULL)) { + if (caps->category || caps->type) { win_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", " "); } } - if (caps->type != NULL) { + if (caps->type) { win_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->type); - if (caps->category != NULL) { + if (caps->category) { win_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", " "); } } - if (caps->category != NULL) { + if (caps->category) { win_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->category); } win_newline(console); } - if (caps->software != NULL) { + if (caps->software) { win_vprint(console, '-', NULL, NO_EOL, 0, "", "Software: %s", caps->software); } - if (caps->software_version != NULL) { + if (caps->software_version) { win_vprint(console, '-', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->software_version); } - if ((caps->software != NULL) || (caps->software_version != NULL)) { + if (caps->software || caps->software_version) { win_newline(console); } - if (caps->os != NULL) { + if (caps->os) { win_vprint(console, '-', NULL, NO_EOL, 0, "", "OS: %s", caps->os); } - if (caps->os_version != NULL) { + if (caps->os_version) { win_vprint(console, '-', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->os_version); } - if ((caps->os != NULL) || (caps->os_version != NULL)) { + if (caps->os || caps->os_version) { win_newline(console); } - if (caps->features != NULL) { + if (caps->features) { win_println(console, "Features:"); GSList *feature = caps->features; - while (feature != NULL) { + while (feature) { win_vprint(console, '-', NULL, 0, 0, "", " %s", feature->data); feature = g_slist_next(feature); } @@ -358,19 +358,19 @@ cons_show_software_version(const char * const jid, const char * const presence, const char * const name, const char * const version, const char * const os) { ProfWin *console = wins_get_console(); - if ((name != NULL) || (version != NULL) || (os != NULL)) { + if (name || version || os) { cons_show(""); theme_item_t presence_colour = theme_main_presence_attrs(presence); win_vprint(console, '-', NULL, NO_EOL, presence_colour, "", "%s", jid); win_print(console, '-', NULL, NO_DATE, 0, "", ":"); } - if (name != NULL) { + if (name) { cons_show("Name : %s", name); } - if (version != NULL) { + if (version) { cons_show("Version : %s", version); } - if (os != NULL) { + if (os) { cons_show("OS : %s", os); } @@ -386,7 +386,7 @@ cons_show_received_subs(void) } else { cons_show("Outstanding subscription requests from:", g_slist_length(received)); - while (received != NULL) { + while (received) { cons_show(" %s", received->data); received = g_slist_next(received); } @@ -404,7 +404,7 @@ cons_show_sent_subs(void) PContact contact = NULL; cons_show("Awaiting subscription responses from:"); GSList *curr = contacts; - while (curr != NULL) { + while (curr) { contact = (PContact) curr->data; if (p_contact_pending_out(contact)) { cons_show(" %s", p_contact_barejid(contact)); @@ -422,12 +422,12 @@ void cons_show_room_list(GSList *rooms, const char * const conference_node) { ProfWin *console = wins_get_console(); - if ((rooms != NULL) && (g_slist_length(rooms) > 0)) { + if (rooms && (g_slist_length(rooms) > 0)) { cons_show("Chat rooms at %s:", conference_node); - while (rooms != NULL) { + while (rooms) { DiscoItem *room = rooms->data; win_vprint(console, '-', NULL, NO_EOL, 0, "", " %s", room->jid); - if (room->name != NULL) { + if (room->name) { win_vprint(console, '-', NULL, NO_DATE | NO_EOL, 0, "", ", (%s)", room->name); } win_newline(console); @@ -452,7 +452,7 @@ cons_show_bookmarks(const GList *list) cons_show(""); cons_show("Bookmarks:"); - while (list != NULL) { + while (list) { Bookmark *item = list->data; theme_item_t presence_colour = THEME_TEXT; @@ -461,18 +461,18 @@ cons_show_bookmarks(const GList *list) presence_colour = THEME_ONLINE; } win_vprint(console, '-', NULL, NO_EOL, presence_colour, "", " %s", item->jid); - if (item->nick != NULL) { + if (item->nick) { win_vprint(console, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", "/%s", item->nick); } if (item->autojoin) { win_print(console, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " (autojoin)"); } - if (item->password != NULL) { + if (item->password) { win_print(console, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " (private)"); } if (muc_active(item->jid)) { ProfWin *roomwin = (ProfWin*)wins_get_muc(item->jid); - if (roomwin != NULL) { + if (roomwin) { int num = wins_get_num(roomwin); win_vprint(console, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " (%d)", num); } @@ -487,26 +487,26 @@ cons_show_bookmarks(const GList *list) void cons_show_disco_info(const char *jid, GSList *identities, GSList *features) { - if (((identities != NULL) && (g_slist_length(identities) > 0)) || - ((features != NULL) && (g_slist_length(features) > 0))) { + if ((identities && (g_slist_length(identities) > 0)) || + (features && (g_slist_length(features) > 0))) { cons_show(""); cons_show("Service disovery info for %s", jid); - if (identities != NULL) { + if (identities) { cons_show(" Identities"); } - while (identities != NULL) { + while (identities) { DiscoIdentity *identity = identities->data; // anme trpe, cat GString *identity_str = g_string_new(" "); - if (identity->name != NULL) { + if (identity->name) { identity_str = g_string_append(identity_str, identity->name); identity_str = g_string_append(identity_str, " "); } - if (identity->type != NULL) { + if (identity->type) { identity_str = g_string_append(identity_str, identity->type); identity_str = g_string_append(identity_str, " "); } - if (identity->category != NULL) { + if (identity->category) { identity_str = g_string_append(identity_str, identity->category); } cons_show(identity_str->str); @@ -514,10 +514,10 @@ cons_show_disco_info(const char *jid, GSList *identities, GSList *features) identities = g_slist_next(identities); } - if (features != NULL) { + if (features) { cons_show(" Features:"); } - while (features != NULL) { + while (features) { cons_show(" %s", features->data); features = g_slist_next(features); } @@ -530,13 +530,13 @@ void cons_show_disco_items(GSList *items, const char * const jid) { ProfWin *console = wins_get_console(); - if ((items != NULL) && (g_slist_length(items) > 0)) { + if (items && (g_slist_length(items) > 0)) { cons_show(""); cons_show("Service discovery items for %s:", jid); - while (items != NULL) { + while (items) { DiscoItem *item = items->data; win_vprint(console, '-', NULL, NO_EOL, 0, "", " %s", item->jid); - if (item->name != NULL) { + if (item->name) { win_vprint(console, '-', NULL, NO_DATE | NO_EOL, 0, "", ", (%s)", item->name); } win_vprint(console, '-', NULL, NO_DATE, 0, "", ""); @@ -556,7 +556,7 @@ cons_show_status(const char * const barejid) ProfWin *console = wins_get_console(); PContact pcontact = roster_get_contact(barejid); - if (pcontact != NULL) { + if (pcontact) { win_show_contact(console, pcontact); } else { cons_show("No such contact \"%s\" in roster.", barejid); @@ -571,8 +571,8 @@ cons_show_room_invite(const char * const invitor, const char * const room, { char *display_from = NULL; PContact contact = roster_get_contact(invitor); - if (contact != NULL) { - if (p_contact_name(contact) != NULL) { + if (contact) { + if (p_contact_name(contact)) { display_from = strdup(p_contact_name(contact)); } else { display_from = strdup(invitor); @@ -586,7 +586,7 @@ cons_show_room_invite(const char * const invitor, const char * const room, cons_show(" From : %s", display_from); cons_show(" Room : %s", room); - if (reason != NULL) { + if (reason) { cons_show(" Message: %s", reason); } @@ -673,9 +673,9 @@ cons_show_account(ProfAccount *account) if (g_list_length(account->otr_manual) > 0) { GString *manual = g_string_new("OTR manual : "); GList *curr = account->otr_manual; - while (curr != NULL) { + while (curr) { g_string_append(manual, curr->data); - if (curr->next != NULL) { + if (curr->next) { g_string_append(manual, ", "); } curr = curr->next; @@ -686,9 +686,9 @@ cons_show_account(ProfAccount *account) if (g_list_length(account->otr_opportunistic) > 0) { GString *opportunistic = g_string_new("OTR opportunistic : "); GList *curr = account->otr_opportunistic; - while (curr != NULL) { + while (curr) { g_string_append(opportunistic, curr->data); - if (curr->next != NULL) { + if (curr->next) { g_string_append(opportunistic, ", "); } curr = curr->next; @@ -699,9 +699,9 @@ cons_show_account(ProfAccount *account) if (g_list_length(account->otr_always) > 0) { GString *always = g_string_new("OTR always : "); GList *curr = account->otr_always; - while (curr != NULL) { + while (curr) { g_string_append(always, curr->data); - if (curr->next != NULL) { + if (curr->next) { g_string_append(always, ", "); } curr = curr->next; @@ -720,11 +720,11 @@ cons_show_account(ProfAccount *account) GList *ordered_resources = NULL; GList *curr = resources; - if (curr != NULL) { + if (curr) { win_println(console, "Resources:"); // sort in order of availability - while (curr != NULL) { + while (curr) { Resource *resource = curr->data; ordered_resources = g_list_insert_sorted(ordered_resources, resource, (GCompareFunc)resource_compare_availability); @@ -735,13 +735,13 @@ cons_show_account(ProfAccount *account) g_list_free(resources); curr = ordered_resources; - while (curr != NULL) { + while (curr) { Resource *resource = curr->data; const char *resource_presence = string_from_resource_presence(resource->presence); theme_item_t presence_colour = theme_main_presence_attrs(resource_presence); win_vprint(console, '-', NULL, NO_EOL, presence_colour, "", " %s (%d), %s", resource->name, resource->priority, resource_presence); - if (resource->status != NULL) { + if (resource->status) { win_vprint(console, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", resource->status); } win_vprint(console, '-', NULL, NO_DATE, 0, "", ""); @@ -749,43 +749,43 @@ cons_show_account(ProfAccount *account) Capabilities *caps = caps_lookup(jidp->fulljid); jid_destroy(jidp); - if (caps != NULL) { + if (caps) { // show identity - if ((caps->category != NULL) || (caps->type != NULL) || (caps->name != NULL)) { + if (caps->category || caps->type || caps->name) { win_print(console, '-', NULL, NO_EOL, 0, "", " Identity: "); - if (caps->name != NULL) { + if (caps->name) { win_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->name); - if ((caps->category != NULL) || (caps->type != NULL)) { + if (caps->category || caps->type) { win_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", " "); } } - if (caps->type != NULL) { + if (caps->type) { win_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->type); - if (caps->category != NULL) { + if (caps->category) { win_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", " "); } } - if (caps->category != NULL) { + if (caps->category) { win_print(console, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->category); } win_newline(console); } - if (caps->software != NULL) { + if (caps->software) { win_vprint(console, '-', NULL, NO_EOL, 0, "", " Software: %s", caps->software); } - if (caps->software_version != NULL) { + if (caps->software_version) { win_vprint(console, '-', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->software_version); } - if ((caps->software != NULL) || (caps->software_version != NULL)) { + if (caps->software || caps->software_version) { win_newline(console); } - if (caps->os != NULL) { + if (caps->os) { win_vprint(console, '-', NULL, NO_EOL, 0, "", " OS: %s", caps->os); } - if (caps->os_version != NULL) { + if (caps->os_version) { win_vprint(console, '-', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->os_version); } - if ((caps->os != NULL) || (caps->os_version != NULL)) { + if (caps->os || caps->os_version) { win_newline(console); } caps_destroy(caps); @@ -808,10 +808,10 @@ cons_show_aliases(GList *aliases) } GList *curr = aliases; - if (curr != NULL) { + if (curr) { cons_show("Command aliases:"); } - while (curr != NULL) { + while (curr) { ProfAlias *alias = curr->data; cons_show(" /%s -> %s", alias->name, alias->value); curr = g_list_next(curr); @@ -919,7 +919,7 @@ void cons_autoconnect_setting(void) { char *pref_connect_account = prefs_get_string(PREF_CONNECT_ACCOUNT); - if (pref_connect_account != NULL) + if (pref_connect_account) cons_show("Autoconnect (/autoconnect) : %s", pref_connect_account); else cons_show("Autoconnect (/autoconnect) : OFF"); @@ -1412,7 +1412,7 @@ cons_show_themes(GSList *themes) cons_show("No available themes."); } else { cons_show("Available themes:"); - while (themes != NULL) { + while (themes) { cons_show(themes->data); themes = g_slist_next(themes); } @@ -1484,7 +1484,7 @@ cons_show_roster_group(const char * const group, GSList *list) { cons_show(""); - if (list != NULL) { + if (list) { cons_show("%s:", group); } else { cons_show("No group named %s exists.", group); @@ -1628,7 +1628,7 @@ _show_roster_contacts(GSList *list, gboolean show_groups) PContact contact = curr->data; GString *title = g_string_new(" "); title = g_string_append(title, p_contact_barejid(contact)); - if (p_contact_name(contact) != NULL) { + if (p_contact_name(contact)) { title = g_string_append(title, " ("); title = g_string_append(title, p_contact_name(contact)); title = g_string_append(title, ")"); @@ -1670,11 +1670,11 @@ _show_roster_contacts(GSList *list, gboolean show_groups) if (show_groups) { GSList *groups = p_contact_groups(contact); - if (groups != NULL) { + if (groups) { GString *groups_str = g_string_new(" - "); - while (groups != NULL) { + while (groups) { g_string_append(groups_str, groups->data); - if (g_slist_next(groups) != NULL) { + if (g_slist_next(groups)) { g_string_append(groups_str, ", "); } groups = g_slist_next(groups); From aefe458b600b72cc6d292aa177dde18b024ef1a3 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 23:05:52 +0100 Subject: [PATCH 217/252] Use null check convention in core.c --- src/ui/core.c | 124 +++++++++++++++++++++++++------------------------- 1 file changed, 62 insertions(+), 62 deletions(-) diff --git a/src/ui/core.c b/src/ui/core.c index e75d5432..06dd84e3 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -168,13 +168,13 @@ ui_get_idle_time(void) // if compiled with libxss, get the x sessions idle time #ifdef HAVE_LIBXSS XScreenSaverInfo *info = XScreenSaverAllocInfo(); - if (info != NULL && display != NULL) { + if (info && display) { XScreenSaverQueryInfo(display, DefaultRootWindow(display), info); unsigned long result = info->idle; XFree(info); return result; } - if (info != NULL) { + if (info) { XFree(info); } // if no libxss or xss idle time failed, use profanity idle time @@ -352,7 +352,7 @@ ui_contact_typing(const char * const barejid, const char * const resource) if ( !is_current || (is_current && prefs_get_boolean(PREF_NOTIFY_TYPING_CURRENT)) ) { PContact contact = roster_get_contact(barejid); char const *display_usr = NULL; - if (p_contact_name(contact) != NULL) { + if (p_contact_name(contact)) { display_usr = p_contact_name(contact); } else { display_usr = barejid; @@ -423,9 +423,9 @@ ui_incoming_msg(const char * const barejid, const char * const resource, const c } // show users status first, when receiving message via delayed delivery - if ((tv_stamp != NULL) && (win_created)) { + if (tv_stamp && (win_created)) { PContact pcontact = roster_get_contact(barejid); - if (pcontact != NULL) { + if (pcontact) { win_show_contact(window, pcontact); } } @@ -515,7 +515,7 @@ ui_incoming_private_msg(const char * const fulljid, const char * const message, void ui_roster_add(const char * const barejid, const char * const name) { - if (name != NULL) { + if (name) { cons_show("Roster item added: %s (%s)", barejid, name); } else { cons_show("Roster item added: %s", barejid); @@ -562,7 +562,7 @@ void ui_auto_away(void) { char *pref_autoaway_message = prefs_get_string(PREF_AUTOAWAY_MESSAGE); - if (pref_autoaway_message != NULL) { + if (pref_autoaway_message) { int pri = accounts_get_priority_for_presence_type(jabber_get_account_name(), RESOURCE_AWAY); @@ -618,7 +618,7 @@ ui_update_presence(const resource_presence_t resource_presence, contact_presence_t contact_presence = contact_presence_from_resource_presence(resource_presence); title_bar_set_presence(contact_presence); gint priority = accounts_get_priority_for_presence_type(jabber_get_account_name(), resource_presence); - if (message != NULL) { + if (message) { cons_show("Status set to %s (priority %d), \"%s\".", show, priority, message); } else { cons_show("Status set to %s (priority %d).", show, priority); @@ -676,7 +676,7 @@ ui_handle_error(const char * const err_msg) void ui_invalid_command_usage(const char * const usage, void (*setting_func)(void)) { - if (setting_func != NULL) { + if (setting_func) { cons_show(""); (*setting_func)(); cons_show("Usage: %s", usage); @@ -733,7 +733,7 @@ ui_close_all_wins(void) GList *win_nums = wins_get_nums(); GList *curr = win_nums; - while (curr != NULL) { + while (curr) { int num = GPOINTER_TO_INT(curr->data); if ((num != 1) && (!ui_win_has_unsaved_form(num))) { if (conn_status == JABBER_CONNECTED) { @@ -760,7 +760,7 @@ ui_close_read_wins(void) GList *win_nums = wins_get_nums(); GList *curr = win_nums; - while (curr != NULL) { + while (curr) { int num = GPOINTER_TO_INT(curr->data); if ((num != 1) && (ui_win_unread(num) == 0) && (!ui_win_has_unsaved_form(num))) { if (conn_status == JABBER_CONNECTED) { @@ -784,7 +784,7 @@ ui_redraw_all_room_rosters(void) GList *win_nums = wins_get_nums(); GList *curr = win_nums; - while (curr != NULL) { + while (curr) { int num = GPOINTER_TO_INT(curr->data); ProfWin *window = wins_get_by_num(num); if (window->type == WIN_MUC && win_has_active_subwin(window)) { @@ -805,7 +805,7 @@ ui_hide_all_room_rosters(void) GList *win_nums = wins_get_nums(); GList *curr = win_nums; - while (curr != NULL) { + while (curr) { int num = GPOINTER_TO_INT(curr->data); ProfWin *window = wins_get_by_num(num); if (window->type == WIN_MUC && win_has_active_subwin(window)) { @@ -826,7 +826,7 @@ ui_show_all_room_rosters(void) GList *win_nums = wins_get_nums(); GList *curr = win_nums; - while (curr != NULL) { + while (curr) { int num = GPOINTER_TO_INT(curr->data); ProfWin *window = wins_get_by_num(num); if (window->type == WIN_MUC && !win_has_active_subwin(window)) { @@ -1112,12 +1112,12 @@ ui_prune_wins(void) gboolean pruned = FALSE; GSList *wins = wins_get_prune_wins(); - if (wins != NULL) { + if (wins) { pruned = TRUE; } GSList *curr = wins; - while (curr != NULL) { + while (curr) { ProfWin *window = curr->data; if (window->type == WIN_CHAT) { if (conn_status == JABBER_CONNECTED) { @@ -1132,7 +1132,7 @@ ui_prune_wins(void) curr = g_slist_next(curr); } - if (wins != NULL) { + if (wins) { g_slist_free(wins); } @@ -1226,7 +1226,7 @@ ui_print_system_msg_from_recipient(const char * const barejid, const char *messa if (window == NULL) { int num = 0; window = wins_new_chat(barejid); - if (window != NULL) { + if (window) { num = wins_get_num(window); status_bar_active(num); } else { @@ -1258,8 +1258,8 @@ ui_recipient_gone(const char * const barejid, const char * const resource) if (show_message) { const char * display_usr = NULL; PContact contact = roster_get_contact(barejid); - if (contact != NULL) { - if (p_contact_name(contact) != NULL) { + if (contact) { + if (p_contact_name(contact)) { display_usr = p_contact_name(contact); } else { display_usr = barejid; @@ -1506,23 +1506,23 @@ ui_show_room_disco_info(const char * const roomjid, GSList *identities, GSList * { ProfWin *window = (ProfWin*)wins_get_muc(roomjid); if (window) { - if (((identities != NULL) && (g_slist_length(identities) > 0)) || - ((features != NULL) && (g_slist_length(features) > 0))) { - if (identities != NULL) { + if ((identities && (g_slist_length(identities) > 0)) || + (features && (g_slist_length(features) > 0))) { + if (identities) { win_print(window, '!', NULL, 0, 0, "", "Identities:"); } - while (identities != NULL) { + while (identities) { DiscoIdentity *identity = identities->data; // anme trpe, cat GString *identity_str = g_string_new(" "); - if (identity->name != NULL) { + if (identity->name) { identity_str = g_string_append(identity_str, identity->name); identity_str = g_string_append(identity_str, " "); } - if (identity->type != NULL) { + if (identity->type) { identity_str = g_string_append(identity_str, identity->type); identity_str = g_string_append(identity_str, " "); } - if (identity->category != NULL) { + if (identity->category) { identity_str = g_string_append(identity_str, identity->category); } win_print(window, '!', NULL, 0, 0, "", identity_str->str); @@ -1530,10 +1530,10 @@ ui_show_room_disco_info(const char * const roomjid, GSList *identities, GSList * identities = g_slist_next(identities); } - if (features != NULL) { + if (features) { win_print(window, '!', NULL, 0, 0, "", "Features:"); } - while (features != NULL) { + while (features) { win_vprint(window, '!', NULL, 0, 0, "", " %s", features->data); features = g_slist_next(features); } @@ -1563,14 +1563,14 @@ ui_room_roster(const char * const roomjid, GList *roster, const char * const pre win_vprint(window, '!', NULL, NO_EOL, THEME_ROOMINFO, "", "%d %s: ", length, presence); } - while (roster != NULL) { + while (roster) { Occupant *occupant = roster->data; const char *presence_str = string_from_resource_presence(occupant->presence); theme_item_t presence_colour = theme_main_presence_attrs(presence_str); win_vprint(window, '!', NULL, NO_DATE | NO_EOL, presence_colour, "", "%s", occupant->nick); - if (roster->next != NULL) { + if (roster->next) { win_print(window, '!', NULL, NO_DATE | NO_EOL, 0, "", ", "); } @@ -1742,7 +1742,7 @@ ui_room_message(const char * const roomjid, const char * const nick, char *my_nick = muc_nick(roomjid); if (g_strcmp0(nick, my_nick) != 0) { - if (g_strrstr(message, my_nick) != NULL) { + if (g_strrstr(message, my_nick)) { win_print(window, '-', NULL, NO_ME, THEME_ROOMMENTION, nick, message); } else { win_print(window, '-', NULL, NO_ME, THEME_TEXT_THEM, nick, message); @@ -1787,7 +1787,7 @@ ui_room_message(const char * const roomjid, const char * const nick, if (g_strcmp0(room_setting, "mention") == 0) { char *message_lower = g_utf8_strdown(message, -1); char *nick_lower = g_utf8_strdown(nick, -1); - if (g_strrstr(message_lower, nick_lower) != NULL) { + if (g_strrstr(message_lower, nick_lower)) { notify = TRUE; } g_free(message_lower); @@ -2121,7 +2121,7 @@ int ui_win_unread(int index) { ProfWin *window = wins_get_by_num(index); - if (window != NULL) { + if (window) { return win_unread(window); } else { return 0; @@ -2144,7 +2144,7 @@ ui_chat_win_contact_online(PContact contact, Resource *resource, GDateTime *last const char *barejid = p_contact_barejid(contact); ProfWin *window = (ProfWin*)wins_get_chat(barejid); - if (window != NULL) { + if (window) { win_show_status_string(window, display_str, show, resource->status, last_activity, "++", "online"); @@ -2160,7 +2160,7 @@ ui_chat_win_contact_offline(PContact contact, char *resource, char *status) const char *barejid = p_contact_barejid(contact); ProfWin *window = (ProfWin*)wins_get_chat(barejid); - if (window != NULL) { + if (window) { win_show_status_string(window, display_str, "offline", status, NULL, "--", "offline"); } @@ -2175,7 +2175,7 @@ ui_contact_offline(char *barejid, char *resource, char *status) char *show_chat_win = prefs_get_string(PREF_STATUSES_CHAT); Jid *jid = jid_create_from_bare_and_resource(barejid, resource); PContact contact = roster_get_contact(barejid); - if (p_contact_subscription(contact) != NULL) { + if (p_contact_subscription(contact)) { if (strcmp(p_contact_subscription(contact), "none") != 0) { // show in console if "all" @@ -2256,7 +2256,7 @@ _ui_draw_term_title(void) if (res == -1) { log_error("Error writing terminal window title."); } - if (win_title != NULL) { + if (win_title) { free(win_title); } win_title = strdup(new_win_title); @@ -2408,9 +2408,9 @@ _ui_handle_form_field(ProfWin *window, char *tag, FormField *field) case FIELD_HIDDEN: break; case FIELD_TEXT_SINGLE: - if (curr_value != NULL) { + if (curr_value) { char *value = curr_value->data; - if (value != NULL) { + if (value) { if (g_strcmp0(field->var, "muc#roomconfig_roomsecret") == 0) { win_print(window, '-', NULL, NO_DATE | NO_EOL, THEME_ONLINE, "", "[hidden]"); } else { @@ -2421,9 +2421,9 @@ _ui_handle_form_field(ProfWin *window, char *tag, FormField *field) win_newline(window); break; case FIELD_TEXT_PRIVATE: - if (curr_value != NULL) { + if (curr_value) { char *value = curr_value->data; - if (value != NULL) { + if (value) { win_print(window, '-', NULL, NO_DATE | NO_EOL, THEME_ONLINE, "", "[hidden]"); } } @@ -2432,7 +2432,7 @@ _ui_handle_form_field(ProfWin *window, char *tag, FormField *field) case FIELD_TEXT_MULTI: win_newline(window); int index = 1; - while (curr_value != NULL) { + while (curr_value) { char *value = curr_value->data; GString *val_tag = g_string_new(""); g_string_printf(val_tag, "val%d", index++); @@ -2458,12 +2458,12 @@ _ui_handle_form_field(ProfWin *window, char *tag, FormField *field) } break; case FIELD_LIST_SINGLE: - if (curr_value != NULL) { + if (curr_value) { win_newline(window); char *value = curr_value->data; GSList *options = field->options; GSList *curr_option = options; - while (curr_option != NULL) { + while (curr_option) { FormOption *option = curr_option->data; if (g_strcmp0(option->value, value) == 0) { win_vprint(window, '-', NULL, 0, THEME_ONLINE, "", " [%s] %s", option->value, option->label); @@ -2475,13 +2475,13 @@ _ui_handle_form_field(ProfWin *window, char *tag, FormField *field) } break; case FIELD_LIST_MULTI: - if (curr_value != NULL) { + if (curr_value) { win_newline(window); GSList *options = field->options; GSList *curr_option = options; - while (curr_option != NULL) { + while (curr_option) { FormOption *option = curr_option->data; - if (g_slist_find_custom(curr_value, option->value, (GCompareFunc)g_strcmp0) != NULL) { + if (g_slist_find_custom(curr_value, option->value, (GCompareFunc)g_strcmp0)) { win_vprint(window, '-', NULL, 0, THEME_ONLINE, "", " [%s] %s", option->value, option->label); } else { win_vprint(window, '-', NULL, 0, THEME_OFFLINE, "", " [%s] %s", option->value, option->label); @@ -2491,9 +2491,9 @@ _ui_handle_form_field(ProfWin *window, char *tag, FormField *field) } break; case FIELD_JID_SINGLE: - if (curr_value != NULL) { + if (curr_value) { char *value = curr_value->data; - if (value != NULL) { + if (value) { win_print(window, '-', NULL, NO_DATE | NO_EOL, THEME_ONLINE, "", value); } } @@ -2501,16 +2501,16 @@ _ui_handle_form_field(ProfWin *window, char *tag, FormField *field) break; case FIELD_JID_MULTI: win_newline(window); - while (curr_value != NULL) { + while (curr_value) { char *value = curr_value->data; win_vprint(window, '-', NULL, 0, THEME_ONLINE, "", " %s", value); curr_value = g_slist_next(curr_value); } break; case FIELD_FIXED: - if (curr_value != NULL) { + if (curr_value) { char *value = curr_value->data; - if (value != NULL) { + if (value) { win_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", value); } } @@ -2525,7 +2525,7 @@ void ui_show_form(ProfMucConfWin *confwin) { ProfWin *window = (ProfWin*) confwin; - if (confwin->form->title != NULL) { + if (confwin->form->title) { win_print(window, '-', NULL, NO_EOL, 0, "", "Form title: "); win_print(window, '-', NULL, NO_DATE, 0, "", confwin->form->title); } else { @@ -2537,7 +2537,7 @@ ui_show_form(ProfMucConfWin *confwin) GSList *fields = confwin->form->fields; GSList *curr_field = fields; - while (curr_field != NULL) { + while (curr_field) { FormField *field = curr_field->data; if ((g_strcmp0(field->type, "fixed") == 0) && field->values) { @@ -2680,14 +2680,14 @@ ui_show_form_field_help(ProfMucConfWin *confwin, char *tag) { ProfWin *window = (ProfWin*) confwin; FormField *field = form_get_field_by_tag(confwin->form, tag); - if (field != NULL) { + if (field) { win_print(window, '-', NULL, NO_EOL, 0, "", field->label); if (field->required) { win_print(window, '-', NULL, NO_DATE, 0, "", " (Required):"); } else { win_print(window, '-', NULL, NO_DATE, 0, "", ":"); } - if (field->description != NULL) { + if (field->description) { win_vprint(window, '-', NULL, 0, 0, "", " Description : %s", field->description); } win_vprint(window, '-', NULL, 0, 0, "", " Type : %s", field->type); @@ -2719,7 +2719,7 @@ ui_show_form_field_help(ProfMucConfWin *confwin, char *tag) win_vprint(window, '-', NULL, 0, 0, "", " Set : /%s ", tag); win_print(window, '-', NULL, 0, 0, "", " Where : is one of"); curr_option = field->options; - while (curr_option != NULL) { + while (curr_option) { option = curr_option->data; win_vprint(window, '-', NULL, 0, 0, "", " %s", option->value); curr_option = g_slist_next(curr_option); @@ -2730,7 +2730,7 @@ ui_show_form_field_help(ProfMucConfWin *confwin, char *tag) win_vprint(window, '-', NULL, 0, 0, "", " Remove : /%s remove ", tag); win_print(window, '-', NULL, 0, 0, "", " Where : is one of"); curr_option = field->options; - while (curr_option != NULL) { + while (curr_option) { option = curr_option->data; win_vprint(window, '-', NULL, 0, 0, "", " %s", option->value); curr_option = g_slist_next(curr_option); @@ -2759,7 +2759,7 @@ ui_show_form_field_help(ProfMucConfWin *confwin, char *tag) void ui_show_form_help(ProfMucConfWin *confwin) { - if (confwin->form->instructions != NULL) { + if (confwin->form->instructions) { ProfWin *window = (ProfWin*) confwin; win_print(window, '-', NULL, 0, 0, "", "Supplied instructions:"); win_print(window, '-', NULL, 0, 0, "", confwin->form->instructions); @@ -2770,7 +2770,7 @@ ui_show_form_help(ProfMucConfWin *confwin) void ui_show_lines(ProfWin *window, const gchar** lines) { - if (lines != NULL) { + if (lines) { int i; for (i = 0; lines[i] != NULL; i++) { win_print(window, '-', NULL, 0, 0, "", lines[i]); @@ -2833,7 +2833,7 @@ _win_show_history(ProfChatWin *chatwin, const char * const contact) GSList *history = chat_log_get_previous(jid->barejid, contact); jid_destroy(jid); GSList *curr = history; - while (curr != NULL) { + while (curr) { char *line = curr->data; // entry if (line[2] == ':') { From dda812cd3efbf4029ece7705f4d912ce6d52ea90 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 23:06:35 +0100 Subject: [PATCH 218/252] Use null check convention in notifier.c --- src/ui/notifier.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ui/notifier.c b/src/ui/notifier.c index e8bc61e3..d3389bc5 100644 --- a/src/ui/notifier.c +++ b/src/ui/notifier.c @@ -89,7 +89,7 @@ notify_invite(const char * const from, const char * const room, g_string_append(message, from); g_string_append(message, "\nto: "); g_string_append(message, room); - if (reason != NULL) { + if (reason) { g_string_append_printf(message, "\n\"%s\"", reason); } @@ -103,7 +103,7 @@ notify_message(const char * const handle, int win, const char * const text) { GString *message = g_string_new(""); g_string_append_printf(message, "%s (win %d)", handle, win); - if (text != NULL) { + if (text) { g_string_append_printf(message, "\n%s", text); } @@ -117,7 +117,7 @@ notify_room_message(const char * const handle, const char * const room, int win, { GString *message = g_string_new(""); g_string_append_printf(message, "%s in %s (win %d)", handle, room, win); - if (text != NULL) { + if (text) { g_string_append_printf(message, "\n%s", text); } @@ -274,7 +274,7 @@ _notify(const char * const message, int timeout, app_id = "com.googlecode.iterm2"; } - if (app_id != NULL) { + if (app_id) { g_string_append(notify_command, " -sender "); g_string_append(notify_command, app_id); } From bf5646aee31864945c767eeb676c0de84756051a Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 23:07:36 +0100 Subject: [PATCH 219/252] Use null check convention in statusbar.c --- src/ui/statusbar.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/ui/statusbar.c b/src/ui/statusbar.c index 93eeaab0..581e63df 100644 --- a/src/ui/statusbar.c +++ b/src/ui/statusbar.c @@ -95,7 +95,7 @@ create_status_bar(void) mvwprintw(status_bar, 0, cols - 34 + ((current - 1) * 3), bracket); wattroff(status_bar, bracket_attrs); - if (last_time != NULL) { + if (last_time) { g_date_time_unref(last_time); } last_time = g_date_time_new_now_local(); @@ -127,7 +127,7 @@ status_bar_resize(void) mvwprintw(status_bar, 0, cols - 34 + ((current - 1) * 3), bracket); wattroff(status_bar, bracket_attrs); - if (message != NULL) { + if (message) { char *time_pref = prefs_get_string(PREF_TIME_STATUSBAR); if (g_strcmp0(time_pref, "minutes") == 0) { mvwprintw(status_bar, 0, 10, message); @@ -137,7 +137,7 @@ status_bar_resize(void) mvwprintw(status_bar, 0, 1, message); } } - if (last_time != NULL) { + if (last_time) { g_date_time_unref(last_time); } last_time = g_date_time_new_now_local(); @@ -297,7 +297,7 @@ status_bar_print_message(const char * const msg) { werase(status_bar); - if (message != NULL) { + if (message) { free(message); } message = strdup(msg); @@ -325,7 +325,7 @@ status_bar_print_message(const char * const msg) void status_bar_clear(void) { - if (message != NULL) { + if (message) { free(message); message = NULL; } @@ -346,7 +346,7 @@ status_bar_clear(void) void status_bar_clear_message(void) { - if (message != NULL) { + if (message) { free(message); message = NULL; } @@ -428,7 +428,7 @@ _mark_inactive(int num) static void _status_bar_draw(void) { - if (last_time != NULL) { + if (last_time) { g_date_time_unref(last_time); } last_time = g_date_time_new_now_local(); From dd386b4a4ed6cb732bd4aaf88131748d3697b441 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 23:08:09 +0100 Subject: [PATCH 220/252] Use null check convention in titlebar.c --- src/ui/titlebar.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ui/titlebar.c b/src/ui/titlebar.c index 08c9a8e6..9bb84f9d 100644 --- a/src/ui/titlebar.c +++ b/src/ui/titlebar.c @@ -80,7 +80,7 @@ title_bar_update_virtual(void) { ProfWin *window = wins_get_current(); if (window->type != WIN_CONSOLE) { - if (typing_elapsed != NULL) { + if (typing_elapsed) { gdouble seconds = g_timer_elapsed(typing_elapsed, NULL); if (seconds >= 10) { @@ -128,7 +128,7 @@ title_bar_set_presence(contact_presence_t presence) void title_bar_switch(void) { - if (typing_elapsed != NULL) { + if (typing_elapsed) { g_timer_destroy(typing_elapsed); typing_elapsed = NULL; typing = FALSE; @@ -141,7 +141,7 @@ void title_bar_set_typing(gboolean is_typing) { if (is_typing) { - if (typing_elapsed != NULL) { + if (typing_elapsed) { g_timer_start(typing_elapsed); } else { typing_elapsed = g_timer_new(); From c19a05ca0943477bf600b91e644526810492b477 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 23:11:32 +0100 Subject: [PATCH 221/252] Use null check convention in window.c --- src/ui/window.c | 76 ++++++++++++++++++++++++------------------------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/src/ui/window.c b/src/ui/window.c index 60c71802..9752ffda 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -573,7 +573,7 @@ win_show_contact(ProfWin *window, PContact contact) theme_item_t presence_colour = theme_main_presence_attrs(presence); - if (name != NULL) { + if (name) { win_print(window, '-', NULL, NO_EOL, presence_colour, "", name); } else { win_print(window, '-', NULL, NO_EOL, presence_colour, "", barejid); @@ -581,7 +581,7 @@ win_show_contact(ProfWin *window, PContact contact) win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " is %s", presence); - if (last_activity != NULL) { + if (last_activity) { GDateTime *now = g_date_time_new_now_local(); GTimeSpan span = g_date_time_difference(now, last_activity); @@ -599,7 +599,7 @@ win_show_contact(ProfWin *window, PContact contact) } } - if (status != NULL) { + if (status) { win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", p_contact_status(contact)); } @@ -637,41 +637,41 @@ win_show_occupant_info(ProfWin *window, const char * const room, Occupant *occup if (caps) { // show identity - if ((caps->category != NULL) || (caps->type != NULL) || (caps->name != NULL)) { + if (caps->category || caps->type || caps->name) { win_print(window, '!', NULL, NO_EOL, 0, "", " Identity: "); - if (caps->name != NULL) { + if (caps->name) { win_print(window, '!', NULL, NO_DATE | NO_EOL, 0, "", caps->name); - if ((caps->category != NULL) || (caps->type != NULL)) { + if (caps->category || caps->type) { win_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", " "); } } - if (caps->type != NULL) { + if (caps->type) { win_print(window, '!', NULL, NO_DATE | NO_EOL, 0, "", caps->type); - if (caps->category != NULL) { + if (caps->category) { win_print(window, '!', NULL, NO_DATE | NO_EOL, 0, "", " "); } } - if (caps->category != NULL) { + if (caps->category) { win_print(window, '!', NULL, NO_DATE | NO_EOL, 0, "", caps->category); } win_newline(window); } - if (caps->software != NULL) { + if (caps->software) { win_vprint(window, '!', NULL, NO_EOL, 0, "", " Software: %s", caps->software); } - if (caps->software_version != NULL) { + if (caps->software_version) { win_vprint(window, '!', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->software_version); } - if ((caps->software != NULL) || (caps->software_version != NULL)) { + if (caps->software || caps->software_version) { win_newline(window); } - if (caps->os != NULL) { + if (caps->os) { win_vprint(window, '!', NULL, NO_EOL, 0, "", " OS: %s", caps->os); } - if (caps->os_version != NULL) { + if (caps->os_version) { win_vprint(window, '!', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->os_version); } - if ((caps->os != NULL) || (caps->os_version != NULL)) { + if (caps->os || caps->os_version) { win_newline(window); } caps_destroy(caps); @@ -693,16 +693,16 @@ win_show_info(ProfWin *window, PContact contact) win_print(window, '-', NULL, 0, 0, "", ""); win_print(window, '-', NULL, NO_EOL, presence_colour, "", barejid); - if (name != NULL) { + if (name) { win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " (%s)", name); } win_print(window, '-', NULL, NO_DATE, 0, "", ":"); - if (sub != NULL) { + if (sub) { win_vprint(window, '-', NULL, 0, 0, "", "Subscription: %s", sub); } - if (last_activity != NULL) { + if (last_activity) { GDateTime *now = g_date_time_new_now_local(); GTimeSpan span = g_date_time_difference(now, last_activity); @@ -724,12 +724,12 @@ win_show_info(ProfWin *window, PContact contact) GList *resources = p_contact_get_available_resources(contact); GList *ordered_resources = NULL; - if (resources != NULL) { + if (resources) { win_print(window, '-', NULL, 0, 0, "", "Resources:"); // sort in order of availability GList *curr = resources; - while (curr != NULL) { + while (curr) { Resource *resource = curr->data; ordered_resources = g_list_insert_sorted(ordered_resources, resource, (GCompareFunc)resource_compare_availability); @@ -739,12 +739,12 @@ win_show_info(ProfWin *window, PContact contact) g_list_free(resources); GList *curr = ordered_resources; - while (curr != NULL) { + while (curr) { Resource *resource = curr->data; const char *resource_presence = string_from_resource_presence(resource->presence); theme_item_t presence_colour = theme_main_presence_attrs(resource_presence); win_vprint(window, '-', NULL, NO_EOL, presence_colour, "", " %s (%d), %s", resource->name, resource->priority, resource_presence); - if (resource->status != NULL) { + if (resource->status) { win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", resource->status); } win_newline(window); @@ -755,41 +755,41 @@ win_show_info(ProfWin *window, PContact contact) if (caps) { // show identity - if ((caps->category != NULL) || (caps->type != NULL) || (caps->name != NULL)) { + if (caps->category || caps->type || caps->name) { win_print(window, '-', NULL, NO_EOL, 0, "", " Identity: "); - if (caps->name != NULL) { + if (caps->name) { win_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->name); - if ((caps->category != NULL) || (caps->type != NULL)) { + if (caps->category || caps->type) { win_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", " "); } } - if (caps->type != NULL) { + if (caps->type) { win_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->type); - if (caps->category != NULL) { + if (caps->category) { win_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", " "); } } - if (caps->category != NULL) { + if (caps->category) { win_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", caps->category); } win_newline(window); } - if (caps->software != NULL) { + if (caps->software) { win_vprint(window, '-', NULL, NO_EOL, 0, "", " Software: %s", caps->software); } - if (caps->software_version != NULL) { + if (caps->software_version) { win_vprint(window, '-', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->software_version); } - if ((caps->software != NULL) || (caps->software_version != NULL)) { + if (caps->software || caps->software_version) { win_newline(window); } - if (caps->os != NULL) { + if (caps->os) { win_vprint(window, '-', NULL, NO_EOL, 0, "", " OS: %s", caps->os); } - if (caps->os_version != NULL) { + if (caps->os_version) { win_vprint(window, '-', NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->os_version); } - if ((caps->os != NULL) || (caps->os_version != NULL)) { + if (caps->os || caps->os_version) { win_newline(window); } caps_destroy(caps); @@ -808,7 +808,7 @@ win_show_status_string(ProfWin *window, const char * const from, { theme_item_t presence_colour; - if (show != NULL) { + if (show) { presence_colour = theme_main_presence_attrs(show); } else if (strcmp(default_show, "online") == 0) { presence_colour = THEME_ONLINE; @@ -819,12 +819,12 @@ win_show_status_string(ProfWin *window, const char * const from, win_vprint(window, '-', NULL, NO_EOL, presence_colour, "", "%s %s", pre, from); - if (show != NULL) + if (show) win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " is %s", show); else win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", " is %s", default_show); - if (last_activity != NULL) { + if (last_activity) { GDateTime *now = g_date_time_new_now_local(); GTimeSpan span = g_date_time_difference(now, last_activity); g_date_time_unref(now); @@ -843,7 +843,7 @@ win_show_status_string(ProfWin *window, const char * const from, } } - if (status != NULL) + if (status) win_vprint(window, '-', NULL, NO_DATE | NO_EOL, presence_colour, "", ", \"%s\"", status); win_print(window, '-', NULL, NO_DATE, presence_colour, "", ""); From a71d1dab6a6a8b4bb16363d3b59d126e6e7988f7 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 23:12:55 +0100 Subject: [PATCH 222/252] Use null check convention in windows.c --- src/ui/windows.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/ui/windows.c b/src/ui/windows.c index 7a86403b..2334efc8 100644 --- a/src/ui/windows.c +++ b/src/ui/windows.c @@ -84,7 +84,7 @@ wins_get_chat(const char * const barejid) GList *values = g_hash_table_get_values(windows); GList *curr = values; - while (curr != NULL) { + while (curr) { ProfWin *window = curr->data; if (window->type == WIN_CHAT) { ProfChatWin *chatwin = (ProfChatWin*)window; @@ -106,7 +106,7 @@ wins_get_muc_conf(const char * const roomjid) GList *values = g_hash_table_get_values(windows); GList *curr = values; - while (curr != NULL) { + while (curr) { ProfWin *window = curr->data; if (window->type == WIN_MUC_CONFIG) { ProfMucConfWin *confwin = (ProfMucConfWin*)window; @@ -128,7 +128,7 @@ wins_get_muc(const char * const roomjid) GList *values = g_hash_table_get_values(windows); GList *curr = values; - while (curr != NULL) { + while (curr) { ProfWin *window = curr->data; if (window->type == WIN_MUC) { ProfMucWin *mucwin = (ProfMucWin*)window; @@ -150,7 +150,7 @@ wins_get_private(const char * const fulljid) GList *values = g_hash_table_get_values(windows); GList *curr = values; - while (curr != NULL) { + while (curr) { ProfWin *window = curr->data; if (window->type == WIN_PRIVATE) { ProfPrivateWin *privatewin = (ProfPrivateWin*)window; @@ -169,7 +169,7 @@ wins_get_private(const char * const fulljid) ProfWin * wins_get_current(void) { - if (windows != NULL) { + if (windows) { return g_hash_table_lookup(windows, GINT_TO_POINTER(current)); } else { return NULL; @@ -286,7 +286,7 @@ wins_get_next(void) GList *curr = keys; // find our place in the list - while (curr != NULL) { + while (curr) { if (current == GPOINTER_TO_INT(curr->data)) { break; } @@ -295,7 +295,7 @@ wins_get_next(void) // if there is a next window return it curr = g_list_next(curr); - if (curr != NULL) { + if (curr) { int next = GPOINTER_TO_INT(curr->data); g_list_free(keys); return wins_get_by_num(next); @@ -315,7 +315,7 @@ wins_get_previous(void) GList *curr = keys; // find our place in the list - while (curr != NULL) { + while (curr) { if (current == GPOINTER_TO_INT(curr->data)) { break; } @@ -324,7 +324,7 @@ wins_get_previous(void) // if there is a previous window return it curr = g_list_previous(curr); - if (curr != NULL) { + if (curr) { int previous = GPOINTER_TO_INT(curr->data); g_list_free(keys); return wins_get_by_num(previous); @@ -342,7 +342,7 @@ wins_get_num(ProfWin *window) GList *keys = g_hash_table_get_keys(windows); GList *curr = keys; - while (curr != NULL) { + while (curr) { gconstpointer num_p = curr->data; ProfWin *curr_win = g_hash_table_lookup(windows, num_p); if (curr_win == window) { @@ -468,7 +468,7 @@ wins_get_total_unread(void) GList *values = g_hash_table_get_values(windows); GList *curr = values; - while (curr != NULL) { + while (curr) { ProfWin *window = curr->data; result += win_unread(window); curr = g_list_next(curr); @@ -484,7 +484,7 @@ wins_resize_all(void) GList *values = g_hash_table_get_values(windows); GList *curr = values; - while (curr != NULL) { + while (curr) { ProfWin *window = curr->data; int subwin_cols = 0; @@ -564,7 +564,7 @@ wins_get_xmlconsole(void) GList *values = g_hash_table_get_values(windows); GList *curr = values; - while (curr != NULL) { + while (curr) { ProfWin *window = curr->data; if (window->type == WIN_XML) { ProfXMLWin *xmlwin = (ProfXMLWin*)window; @@ -586,7 +586,7 @@ wins_get_chat_recipients(void) GList *values = g_hash_table_get_values(windows); GList *curr = values; - while (curr != NULL) { + while (curr) { ProfWin *window = curr->data; if (window->type == WIN_CHAT) { ProfChatWin *chatwin = (ProfChatWin*)window; @@ -605,7 +605,7 @@ wins_get_prune_wins(void) GList *values = g_hash_table_get_values(windows); GList *curr = values; - while (curr != NULL) { + while (curr) { ProfWin *window = curr->data; if (win_unread(window) == 0 && window->type != WIN_MUC && @@ -626,7 +626,7 @@ wins_lost_connection(void) GList *values = g_hash_table_get_values(windows); GList *curr = values; - while (curr != NULL) { + while (curr) { ProfWin *window = curr->data; if (window->type != WIN_CONSOLE) { win_print(window, '-', NULL, 0, THEME_ERROR, "", "Lost connection."); @@ -719,7 +719,7 @@ wins_tidy(void) int num = 1; GList *curr = keys; - while (curr != NULL) { + while (curr) { ProfWin *window = g_hash_table_lookup(windows, curr->data); if (num == 10) { g_hash_table_insert(new_windows, GINT_TO_POINTER(0), window); @@ -761,7 +761,7 @@ wins_create_summary(void) keys = g_list_sort(keys, cmp_win_num); GList *curr = keys; - while (curr != NULL) { + while (curr) { ProfWin *window = g_hash_table_lookup(windows, curr->data); int ui_index = GPOINTER_TO_INT(curr->data); From 398eac4ed6d204cbf8b059a00c08b9ca121cf544 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 23:14:18 +0100 Subject: [PATCH 223/252] Use null check convention in bookmark.c --- src/xmpp/bookmark.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/xmpp/bookmark.c b/src/xmpp/bookmark.c index 9e7bf62b..68e66569 100644 --- a/src/xmpp/bookmark.c +++ b/src/xmpp/bookmark.c @@ -74,7 +74,7 @@ bookmark_request(void) autocomplete_free(bookmark_ac); bookmark_ac = autocomplete_new(); - if (bookmark_list != NULL) { + if (bookmark_list) { g_list_free_full(bookmark_list, _bookmark_item_destroy); bookmark_list = NULL; } @@ -96,12 +96,12 @@ bookmark_add(const char *jid, const char *nick, const char *password, const char } else { Bookmark *item = malloc(sizeof(*item)); item->jid = strdup(jid); - if (nick != NULL) { + if (nick) { item->nick = strdup(nick); } else { item->nick = NULL; } - if (password != NULL) { + if (password) { item->password = strdup(password); } else { item->password = NULL; @@ -136,15 +136,15 @@ bookmark_update(const char *jid, const char *nick, const char *password, const c return FALSE; } else { Bookmark *bm = found->data; - if (nick != NULL) { + if (nick) { free(bm->nick); bm->nick = strdup(nick); } - if (password != NULL) { + if (password) { free(bm->password); bm->password = strdup(password); } - if (autojoin_str != NULL) { + if (autojoin_str) { if (g_strcmp0(autojoin_str, "on") == 0) { bm->autojoin = TRUE; } else if (g_strcmp0(autojoin_str, "off") == 0) { @@ -228,7 +228,7 @@ bookmark_find(const char * const search_str) void bookmark_autocomplete_reset(void) { - if (bookmark_ac != NULL) { + if (bookmark_ac) { autocomplete_reset(bookmark_ac); } } @@ -413,14 +413,14 @@ _send_bookmarks(void) xmpp_stanza_set_ns(storage, "storage:bookmarks"); GList *curr = bookmark_list; - while (curr != NULL) { + while (curr) { Bookmark *bookmark = curr->data; xmpp_stanza_t *conference = xmpp_stanza_new(ctx); xmpp_stanza_set_name(conference, STANZA_NAME_CONFERENCE); xmpp_stanza_set_attribute(conference, STANZA_ATTR_JID, bookmark->jid); Jid *jidp = jid_create(bookmark->jid); - if (jidp->localpart != NULL) { + if (jidp->localpart) { xmpp_stanza_set_attribute(conference, STANZA_ATTR_NAME, jidp->localpart); } jid_destroy(jidp); @@ -431,7 +431,7 @@ _send_bookmarks(void) xmpp_stanza_set_attribute(conference, STANZA_ATTR_AUTOJOIN, "false"); } - if (bookmark->nick != NULL) { + if (bookmark->nick) { xmpp_stanza_t *nick_st = xmpp_stanza_new(ctx); xmpp_stanza_set_name(nick_st, STANZA_NAME_NICK); xmpp_stanza_t *nick_text = xmpp_stanza_new(ctx); @@ -443,7 +443,7 @@ _send_bookmarks(void) xmpp_stanza_release(nick_st); } - if (bookmark->password != NULL) { + if (bookmark->password) { xmpp_stanza_t *password_st = xmpp_stanza_new(ctx); xmpp_stanza_set_name(password_st, STANZA_NAME_PASSWORD); xmpp_stanza_t *password_text = xmpp_stanza_new(ctx); From 067ad7fa2cb4354531c2bc9b51c97af48c17d92f Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 23:15:15 +0100 Subject: [PATCH 224/252] Use null check convention in capabilities.c --- src/xmpp/capabilities.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/xmpp/capabilities.c b/src/xmpp/capabilities.c index 54144330..56475da1 100644 --- a/src/xmpp/capabilities.c +++ b/src/xmpp/capabilities.c @@ -203,7 +203,7 @@ _caps_by_ver(const char * const ver) gsize features_len = 0; gchar **features = g_key_file_get_string_list(cache, ver, "features", &features_len, NULL); - if (features != NULL && features_len > 0) { + if (features && features_len > 0) { GSList *features_list = NULL; int i; for (i = 0; i < features_len; i++) { @@ -395,16 +395,16 @@ caps_create(xmpp_stanza_t *query) GSList *features = NULL; xmpp_stanza_t *softwareinfo = xmpp_stanza_get_child_by_ns(query, STANZA_NS_DATA); - if (softwareinfo != NULL) { + if (softwareinfo) { DataForm *form = form_create(softwareinfo); FormField *formField = NULL; char *form_type = form_get_form_type_field(form); if (g_strcmp0(form_type, STANZA_DATAFORM_SOFTWARE) == 0) { GSList *field = form->fields; - while (field != NULL) { + while (field) { formField = field->data; - if (formField->values != NULL) { + if (formField->values) { if (strcmp(formField->var, "software") == 0) { software = strdup(formField->values->data); } else if (strcmp(formField->var, "software_version") == 0) { @@ -424,7 +424,7 @@ caps_create(xmpp_stanza_t *query) xmpp_stanza_t *child = xmpp_stanza_get_children(query); GSList *identity_stanzas = NULL; - while (child != NULL) { + while (child) { if (g_strcmp0(xmpp_stanza_get_name(child), "feature") == 0) { features = g_slist_append(features, strdup(xmpp_stanza_get_attribute(child, "var"))); } @@ -490,42 +490,42 @@ caps_create(xmpp_stanza_t *query) Capabilities *new_caps = malloc(sizeof(struct capabilities_t)); - if (category != NULL) { + if (category) { new_caps->category = strdup(category); } else { new_caps->category = NULL; } - if (type != NULL) { + if (type) { new_caps->type = strdup(type); } else { new_caps->type = NULL; } - if (name != NULL) { + if (name) { new_caps->name = strdup(name); } else { new_caps->name = NULL; } - if (software != NULL) { + if (software) { new_caps->software = software; } else { new_caps->software = NULL; } - if (software_version != NULL) { + if (software_version) { new_caps->software_version = software_version; } else { new_caps->software_version = NULL; } - if (os != NULL) { + if (os) { new_caps->os = os; } else { new_caps->os = NULL; } - if (os_version != NULL) { + if (os_version) { new_caps->os_version = os_version; } else { new_caps->os_version = NULL; } - if (features != NULL) { + if (features) { new_caps->features = features; } else { new_caps->features = NULL; @@ -635,7 +635,7 @@ caps_close(void) void caps_destroy(Capabilities *caps) { - if (caps != NULL) { + if (caps) { free(caps->category); free(caps->type); free(caps->name); @@ -643,7 +643,7 @@ caps_destroy(Capabilities *caps) free(caps->software_version); free(caps->os); free(caps->os_version); - if (caps->features != NULL) { + if (caps->features) { g_slist_free_full(caps->features, free); } free(caps); From af75bc4be67422b7523707ec56db4a9cde59429b Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 23:16:44 +0100 Subject: [PATCH 225/252] Use null check convention in connection.c --- src/xmpp/connection.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/xmpp/connection.c b/src/xmpp/connection.c index f2596f14..70d49b7c 100644 --- a/src/xmpp/connection.c +++ b/src/xmpp/connection.c @@ -129,11 +129,11 @@ jabber_connect_with_account(const ProfAccount * const account) log_info("Connecting using account: %s", account->name); // save account name and password for reconnect - if (saved_account.name != NULL) { + if (saved_account.name) { free(saved_account.name); } saved_account.name = strdup(account->name); - if (saved_account.passwd != NULL) { + if (saved_account.passwd) { free(saved_account.passwd); } saved_account.passwd = strdup(account->password); @@ -157,7 +157,7 @@ jabber_connect_with_details(const char * const jid, // save details for reconnect, remember name for account creating on success saved_details.name = strdup(jid); saved_details.passwd = strdup(passwd); - if (altdomain != NULL) { + if (altdomain) { saved_details.altdomain = strdup(altdomain); } else { saved_details.altdomain = NULL; @@ -199,11 +199,11 @@ jabber_disconnect(void) _connection_free_saved_account(); _connection_free_saved_details(); _connection_free_session_data(); - if (jabber_conn.conn != NULL) { + if (jabber_conn.conn) { xmpp_conn_release(jabber_conn.conn); jabber_conn.conn = NULL; } - if (jabber_conn.ctx != NULL) { + if (jabber_conn.ctx) { xmpp_ctx_free(jabber_conn.ctx); jabber_conn.ctx = NULL; } @@ -238,7 +238,7 @@ jabber_process_events(void) break; case JABBER_DISCONNECTED: reconnect_sec = prefs_get_reconnect(); - if ((reconnect_sec != 0) && (reconnect_timer != NULL)) { + if ((reconnect_sec != 0) && reconnect_timer) { int elapsed_sec = g_timer_elapsed(reconnect_timer, NULL); if (elapsed_sec > reconnect_sec) { _jabber_reconnect(); @@ -302,7 +302,7 @@ void connection_set_presence_message(const char * const message) { FREE_SET_NULL(jabber_conn.presence_message); - if (message != NULL) { + if (message) { jabber_conn.presence_message = strdup(message); } } @@ -371,15 +371,15 @@ _jabber_connect(const char * const fulljid, const char * const passwd, jid_destroy(jid); log_info("Connecting as %s", fulljid); - if (jabber_conn.log != NULL) { + if (jabber_conn.log) { free(jabber_conn.log); } jabber_conn.log = _xmpp_get_file_logger(); - if (jabber_conn.conn != NULL) { + if (jabber_conn.conn) { xmpp_conn_release(jabber_conn.conn); } - if (jabber_conn.ctx != NULL) { + if (jabber_conn.ctx) { xmpp_ctx_free(jabber_conn.ctx); } jabber_conn.ctx = xmpp_ctx_new(NULL, jabber_conn.log); @@ -436,7 +436,7 @@ _connection_handler(xmpp_conn_t * const conn, log_debug("Connection handler: XMPP_CONN_CONNECT"); // logged in with account - if (saved_account.name != NULL) { + if (saved_account.name) { log_debug("Connection handler: logged in with account name: %s", saved_account.name); sv_ev_login_account_success(saved_account.name); @@ -474,7 +474,7 @@ _connection_handler(xmpp_conn_t * const conn, jabber_conn.conn_status = JABBER_CONNECTED; if (prefs_get_reconnect() != 0) { - if (reconnect_timer != NULL) { + if (reconnect_timer) { g_timer_destroy(reconnect_timer); reconnect_timer = NULL; } From cbcf476a7c63642d0b520460eb94064dd27b4b97 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 23:17:18 +0100 Subject: [PATCH 226/252] Use null check convention in form.c --- src/xmpp/form.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/xmpp/form.c b/src/xmpp/form.c index 02d26ba0..e6213b64 100644 --- a/src/xmpp/form.c +++ b/src/xmpp/form.c @@ -211,7 +211,7 @@ form_create(xmpp_stanza_t * const form_stanza) field->var = _get_attr(field_stanza, "var"); - if (field->type_t != FIELD_HIDDEN && field->var != NULL) { + if (field->type_t != FIELD_HIDDEN && field->var) { GString *tag = g_string_new(""); g_string_printf(tag, "field%d", tag_num++); g_hash_table_insert(form->var_to_tag, strdup(field->var), strdup(tag->str)); From 8e2578459e29a26b53cb05df2305052c6f8064b0 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 23:19:10 +0100 Subject: [PATCH 227/252] Use null check convention in iq.c --- src/xmpp/iq.c | 96 +++++++++++++++++++++++++-------------------------- 1 file changed, 48 insertions(+), 48 deletions(-) diff --git a/src/xmpp/iq.c b/src/xmpp/iq.c index 1a0f64a9..18abad36 100644 --- a/src/xmpp/iq.c +++ b/src/xmpp/iq.c @@ -476,7 +476,7 @@ _error_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID); char *error_msg = stanza_get_error_message(stanza); - if (id != NULL) { + if (id) { log_debug("IQ error handler fired, id: %s, error: %s", id, error_msg); log_error("IQ error received, id: %s, error: %s", id, error_msg); } else { @@ -496,13 +496,13 @@ _pong_handler(xmpp_conn_t *const conn, xmpp_stanza_t * const stanza, char *id = xmpp_stanza_get_id(stanza); char *type = xmpp_stanza_get_type(stanza); - if (id != NULL) { + if (id) { log_debug("IQ pong handler fired, id: %s.", id); } else { log_debug("IQ pong handler fired."); } - if (id != NULL && type != NULL) { + if (id && type) { // show warning if error if (strcmp(type, STANZA_TYPE_ERROR) == 0) { char *error_msg = stanza_get_error_message(stanza); @@ -511,9 +511,9 @@ _pong_handler(xmpp_conn_t *const conn, xmpp_stanza_t * const stanza, // turn off autoping if error type is 'cancel' xmpp_stanza_t *error = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_ERROR); - if (error != NULL) { + if (error) { char *errtype = xmpp_stanza_get_type(error); - if (errtype != NULL) { + if (errtype) { if (strcmp(errtype, "cancel") == 0) { log_warning("Server ping (id=%s) error type 'cancel', disabling autoping.", id); prefs_set_autoping(0); @@ -830,7 +830,7 @@ _version_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, { char *id = xmpp_stanza_get_id(stanza); - if (id != NULL) { + if (id) { log_debug("IQ version result handler fired, id: %s.", id); } else { log_debug("IQ version result handler fired."); @@ -855,13 +855,13 @@ _version_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, xmpp_stanza_t *version = xmpp_stanza_get_child_by_name(query, "version"); xmpp_stanza_t *os = xmpp_stanza_get_child_by_name(query, "os"); - if (name != NULL) { + if (name) { name_str = xmpp_stanza_get_text(name); } - if (version != NULL) { + if (version) { version_str = xmpp_stanza_get_text(version); } - if (os != NULL) { + if (os) { os_str = xmpp_stanza_get_text(os); } @@ -892,7 +892,7 @@ _ping_get_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, const char *to = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_TO); const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); - if (id != NULL) { + if (id) { log_debug("IQ ping get handler fired, id: %s.", id); } else { log_debug("IQ ping get handler fired."); @@ -908,7 +908,7 @@ _ping_get_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, xmpp_stanza_set_attribute(pong, STANZA_ATTR_FROM, to); xmpp_stanza_set_attribute(pong, STANZA_ATTR_TYPE, STANZA_TYPE_RESULT); - if (id != NULL) { + if (id) { xmpp_stanza_set_attribute(pong, STANZA_ATTR_ID, id); } @@ -926,16 +926,16 @@ _version_get_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID); const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); - if (id != NULL) { + if (id) { log_debug("IQ version get handler fired, id: %s.", id); } else { log_debug("IQ version get handler fired."); } - if (from != NULL) { + if (from) { xmpp_stanza_t *response = xmpp_stanza_new(ctx); xmpp_stanza_set_name(response, STANZA_NAME_IQ); - if (id != NULL) { + if (id) { xmpp_stanza_set_id(response, id); } xmpp_stanza_set_attribute(response, STANZA_ATTR_TO, from); @@ -994,13 +994,13 @@ _disco_items_get_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID); const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); - if (id != NULL) { + if (id) { log_debug("IQ disco items get handler fired, id: %s.", id); } else { log_debug("IQ disco items get handler fired."); } - if (from != NULL) { + if (from) { xmpp_stanza_t *response = xmpp_stanza_new(ctx); xmpp_stanza_set_name(response, STANZA_NAME_IQ); xmpp_stanza_set_id(response, xmpp_stanza_get_id(stanza)); @@ -1031,20 +1031,20 @@ _disco_info_get_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID); - if (id != NULL) { + if (id) { log_debug("IQ disco info get handler fired, id: %s.", id); } else { log_debug("IQ disco info get handler fired."); } - if (from != NULL) { + if (from) { xmpp_stanza_t *response = xmpp_stanza_new(ctx); xmpp_stanza_set_name(response, STANZA_NAME_IQ); xmpp_stanza_set_id(response, xmpp_stanza_get_id(stanza)); xmpp_stanza_set_attribute(response, STANZA_ATTR_TO, from); xmpp_stanza_set_type(response, STANZA_TYPE_RESULT); xmpp_stanza_t *query = caps_create_query_response_stanza(ctx); - if (node_str != NULL) { + if (node_str) { xmpp_stanza_set_attribute(query, STANZA_ATTR_NODE, node_str); } xmpp_stanza_add_child(response, query); @@ -1063,7 +1063,7 @@ _destroy_room_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const sta { const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID); - if (id != NULL) { + if (id) { log_debug("IQ destroy room result handler fired, id: %s.", id); } else { log_debug("IQ destroy room result handler fired."); @@ -1087,7 +1087,7 @@ _room_config_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, const char *type = xmpp_stanza_get_type(stanza); const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); - if (id != NULL) { + if (id) { log_debug("IQ room config handler fired, id: %s.", id); } else { log_debug("IQ room config handler fired."); @@ -1142,7 +1142,7 @@ static int _room_affiliation_set_result_handler(xmpp_conn_t * const conn, xmpp_s const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); struct privilege_set_t *affiliation_set = (struct privilege_set_t *)userdata; - if (id != NULL) { + if (id) { log_debug("IQ affiliation set handler fired, id: %s.", id); } else { log_debug("IQ affiliation set handler fired."); @@ -1171,7 +1171,7 @@ static int _room_role_set_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); struct privilege_set_t *role_set = (struct privilege_set_t *)userdata; - if (id != NULL) { + if (id) { log_debug("IQ role set handler fired, id: %s.", id); } else { log_debug("IQ role set handler fired."); @@ -1200,7 +1200,7 @@ _room_affiliation_list_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); char *affiliation = (char *)userdata; - if (id != NULL) { + if (id) { log_debug("IQ affiliation list result handler fired, id: %s.", id); } else { log_debug("IQ affiliation list result handler fired."); @@ -1248,7 +1248,7 @@ _room_role_list_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const s const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); char *role = (char *)userdata; - if (id != NULL) { + if (id) { log_debug("IQ role list result handler fired, id: %s.", id); } else { log_debug("IQ role list result handler fired."); @@ -1295,7 +1295,7 @@ _room_config_submit_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stan const char *type = xmpp_stanza_get_type(stanza); const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); - if (id != NULL) { + if (id) { log_debug("IQ room config submit handler fired, id: %s.", id); } else { log_debug("IQ room config submit handler fired."); @@ -1322,7 +1322,7 @@ _room_kick_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); char *nick = (char *)userdata; - if (id != NULL) { + if (id) { log_debug("IQ kick result handler fired, id: %s.", id); } else { log_debug("IQ kick result handler fired."); @@ -1345,7 +1345,7 @@ _room_kick_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza static void _identity_destroy(DiscoIdentity *identity) { - if (identity != NULL) { + if (identity) { free(identity->name); free(identity->type); free(identity->category); @@ -1356,7 +1356,7 @@ _identity_destroy(DiscoIdentity *identity) static void _item_destroy(DiscoItem *item) { - if (item != NULL) { + if (item) { free(item->jid); free(item->name); free(item); @@ -1385,15 +1385,15 @@ _room_info_response_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stan xmpp_stanza_t *query = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_QUERY); - if (query != NULL) { + if (query) { xmpp_stanza_t *child = xmpp_stanza_get_children(query); GSList *identities = NULL; GSList *features = NULL; - while (child != NULL) { + while (child) { const char *stanza_name = xmpp_stanza_get_name(child); if (g_strcmp0(stanza_name, STANZA_NAME_FEATURE) == 0) { const char *var = xmpp_stanza_get_attribute(child, STANZA_ATTR_VAR); - if (var != NULL) { + if (var) { features = g_slist_append(features, strdup(var)); } } else if (g_strcmp0(stanza_name, STANZA_NAME_IDENTITY) == 0) { @@ -1401,20 +1401,20 @@ _room_info_response_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stan const char *type = xmpp_stanza_get_attribute(child, STANZA_ATTR_TYPE); const char *category = xmpp_stanza_get_attribute(child, STANZA_ATTR_CATEGORY); - if ((name != NULL) || (category != NULL) || (type != NULL)) { + if (name || category || type) { DiscoIdentity *identity = malloc(sizeof(struct disco_identity_t)); - if (name != NULL) { + if (name) { identity->name = strdup(name); } else { identity->name = NULL; } - if (category != NULL) { + if (category) { identity->category = strdup(category); } else { identity->category = NULL; } - if (type != NULL) { + if (type) { identity->type = strdup(type); } else { identity->type = NULL; @@ -1469,15 +1469,15 @@ _disco_info_response_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const sta xmpp_stanza_t *query = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_QUERY); - if (query != NULL) { + if (query) { xmpp_stanza_t *child = xmpp_stanza_get_children(query); GSList *identities = NULL; GSList *features = NULL; - while (child != NULL) { + while (child) { const char *stanza_name = xmpp_stanza_get_name(child); if (g_strcmp0(stanza_name, STANZA_NAME_FEATURE) == 0) { const char *var = xmpp_stanza_get_attribute(child, STANZA_ATTR_VAR); - if (var != NULL) { + if (var) { features = g_slist_append(features, strdup(var)); } } else if (g_strcmp0(stanza_name, STANZA_NAME_IDENTITY) == 0) { @@ -1485,20 +1485,20 @@ _disco_info_response_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const sta const char *type = xmpp_stanza_get_attribute(child, STANZA_ATTR_TYPE); const char *category = xmpp_stanza_get_attribute(child, STANZA_ATTR_CATEGORY); - if ((name != NULL) || (category != NULL) || (type != NULL)) { + if (name || category || type) { DiscoIdentity *identity = malloc(sizeof(struct disco_identity_t)); - if (name != NULL) { + if (name) { identity->name = strdup(name); } else { identity->name = NULL; } - if (category != NULL) { + if (category) { identity->category = strdup(category); } else { identity->category = NULL; } - if (type != NULL) { + if (type) { identity->type = strdup(type); } else { identity->type = NULL; @@ -1534,17 +1534,17 @@ _disco_items_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stan log_debug("Response to query: %s", id); xmpp_stanza_t *query = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_QUERY); - if (query != NULL) { + if (query) { xmpp_stanza_t *child = xmpp_stanza_get_children(query); - while (child != NULL) { + while (child) { const char *stanza_name = xmpp_stanza_get_name(child); - if ((stanza_name != NULL) && (g_strcmp0(stanza_name, STANZA_NAME_ITEM) == 0)) { + if (stanza_name && (g_strcmp0(stanza_name, STANZA_NAME_ITEM) == 0)) { const char *item_jid = xmpp_stanza_get_attribute(child, STANZA_ATTR_JID); - if (item_jid != NULL) { + if (item_jid) { DiscoItem *item = malloc(sizeof(struct disco_item_t)); item->jid = strdup(item_jid); const char *item_name = xmpp_stanza_get_attribute(child, STANZA_ATTR_NAME); - if (item_name != NULL) { + if (item_name) { item->name = strdup(item_name); } else { item->name = NULL; From 8e64323503078ec8d24e4c5ce12ab22be097acfe Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 23:21:06 +0100 Subject: [PATCH 228/252] Use null check convention in presence.c --- src/xmpp/presence.c | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/xmpp/presence.c b/src/xmpp/presence.c index 0c6702b3..efb2e32d 100644 --- a/src/xmpp/presence.c +++ b/src/xmpp/presence.c @@ -171,7 +171,7 @@ presence_sub_request_exists(const char * const bare_jid) GSList *requests_p = autocomplete_create_list(sub_requests_ac); GSList *requests = requests_p; - while (requests != NULL) { + while (requests) { if (strcmp(requests->data, bare_jid) == 0) { result = TRUE; break; @@ -179,7 +179,7 @@ presence_sub_request_exists(const char * const bare_jid) requests = g_slist_next(requests); } - if (requests_p != NULL) { + if (requests_p) { g_slist_free_full(requests_p, free); } @@ -201,7 +201,7 @@ presence_update(const resource_presence_t presence_type, const char * const msg, return; } - if (msg != NULL) { + if (msg) { log_debug("Updating presence: %s, \"%s\"", string_from_resource_presence(presence_type), msg); } else { @@ -246,11 +246,11 @@ _send_room_presence(xmpp_conn_t *conn, xmpp_stanza_t *presence) GList *rooms_p = muc_rooms(); GList *rooms = rooms_p; - while (rooms != NULL) { + while (rooms) { const char *room = rooms->data; const char *nick = muc_nick(room); - if (nick != NULL) { + if (nick) { char *full_room_jid = create_fulljid(room, nick); xmpp_stanza_set_attribute(presence, STANZA_ATTR_TO, full_room_jid); @@ -262,7 +262,7 @@ _send_room_presence(xmpp_conn_t *conn, xmpp_stanza_t *presence) rooms = g_list_next(rooms); } - if (rooms_p != NULL) { + if (rooms_p) { g_list_free(rooms_p); } } @@ -334,7 +334,7 @@ presence_leave_chat_room(const char * const room_jid) xmpp_conn_t *conn = connection_get_conn(); char *nick = muc_nick(room_jid); - if (nick != NULL) { + if (nick) { xmpp_stanza_t *presence = stanza_create_room_leave_presence(ctx, room_jid, nick); xmpp_send(conn, presence); @@ -351,11 +351,11 @@ _presence_error_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, xmpp_stanza_t *error_stanza = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_ERROR); xmpp_stanza_t *x = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_X); char *xmlns = NULL; - if (x != NULL) { + if (x) { xmlns = xmpp_stanza_get_ns(x); } char *type = NULL; - if (error_stanza != NULL) { + if (error_stanza) { type = xmpp_stanza_get_attribute(error_stanza, STANZA_ATTR_TYPE); } @@ -365,7 +365,7 @@ _presence_error_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, char *error_cond = NULL; xmpp_stanza_t *reason_st = xmpp_stanza_get_child_by_ns(error_stanza, STANZA_NS_STANZAS); - if (reason_st != NULL) { + if (reason_st) { error_cond = xmpp_stanza_get_name(reason_st); } if (error_cond == NULL) { @@ -385,15 +385,15 @@ _presence_error_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, char *err_msg = stanza_get_error_message(stanza); GString *log_msg = g_string_new("presence stanza error received"); - if (id != NULL) { + if (id) { g_string_append(log_msg, " id="); g_string_append(log_msg, id); } - if (from != NULL) { + if (from) { g_string_append(log_msg, " from="); g_string_append(log_msg, from); } - if (type != NULL) { + if (type) { g_string_append(log_msg, " type="); g_string_append(log_msg, type); } @@ -404,7 +404,7 @@ _presence_error_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, g_string_free(log_msg, TRUE); - if (from != NULL) { + if (from) { ui_handle_recipient_error(from, err_msg); } else { ui_handle_error(err_msg); @@ -487,7 +487,7 @@ _unavailable_handler(xmpp_conn_t * const conn, char *status_str = stanza_get_status(stanza, NULL); if (strcmp(my_jid->barejid, from_jid->barejid) !=0) { - if (from_jid->resourcepart != NULL) { + if (from_jid->resourcepart) { sv_ev_contact_offline(from_jid->barejid, from_jid->resourcepart, status_str); // hack for servers that do not send full jid with unavailable presence @@ -495,7 +495,7 @@ _unavailable_handler(xmpp_conn_t * const conn, sv_ev_contact_offline(from_jid->barejid, "__prof_default", status_str); } } else { - if (from_jid->resourcepart != NULL) { + if (from_jid->resourcepart) { connection_remove_available_resource(from_jid->resourcepart); } } @@ -619,7 +619,7 @@ _send_caps_request(char *node, char *caps_key, char *id, char *from) xmpp_ctx_t *ctx = connection_get_ctx(); xmpp_conn_t *conn = connection_get_conn(); - if (node != NULL) { + if (node) { log_debug("Node string: %s.", node); if (!caps_contains(caps_key)) { log_debug("Capabilities not cached for '%s', sending discovery IQ.", from); @@ -695,14 +695,14 @@ _muc_user_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * free(reason); // kicked from room - } else if (g_slist_find_custom(status_codes, "307", (GCompareFunc)g_strcmp0) != NULL) { + } else if (g_slist_find_custom(status_codes, "307", (GCompareFunc)g_strcmp0)) { char *actor = stanza_get_actor(stanza); char *reason = stanza_get_reason(stanza); sv_ev_room_kicked(room, actor, reason); free(reason); // banned from room - } else if (g_slist_find_custom(status_codes, "301", (GCompareFunc)g_strcmp0) != NULL) { + } else if (g_slist_find_custom(status_codes, "301", (GCompareFunc)g_strcmp0)) { char *actor = stanza_get_actor(stanza); char *reason = stanza_get_reason(stanza); sv_ev_room_banned(room, actor, reason); @@ -740,14 +740,14 @@ _muc_user_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * GSList *status_codes = stanza_get_status_codes_by_ns(stanza, STANZA_NS_MUC_USER); // kicked from room - if (g_slist_find_custom(status_codes, "307", (GCompareFunc)g_strcmp0) != NULL) { + if (g_slist_find_custom(status_codes, "307", (GCompareFunc)g_strcmp0)) { char *actor = stanza_get_actor(stanza); char *reason = stanza_get_reason(stanza); sv_ev_room_occupent_kicked(room, nick, actor, reason); free(reason); // banned from room - } else if (g_slist_find_custom(status_codes, "301", (GCompareFunc)g_strcmp0) != NULL) { + } else if (g_slist_find_custom(status_codes, "301", (GCompareFunc)g_strcmp0)) { char *actor = stanza_get_actor(stanza); char *reason = stanza_get_reason(stanza); sv_ev_room_occupent_banned(room, nick, actor, reason); From defa955ae022e691c12908a624170444eabd236f Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 23:22:06 +0100 Subject: [PATCH 229/252] Use null check convention in roster.c --- src/xmpp/roster.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/xmpp/roster.c b/src/xmpp/roster.c index 84561ecf..71396c4d 100644 --- a/src/xmpp/roster.c +++ b/src/xmpp/roster.c @@ -132,7 +132,7 @@ roster_send_add_to_group(const char * const group, PContact contact) { GSList *groups = p_contact_groups(contact); GSList *new_groups = NULL; - while (groups != NULL) { + while (groups) { new_groups = g_slist_append(new_groups, strdup(groups->data)); groups = g_slist_next(groups); } @@ -142,7 +142,7 @@ roster_send_add_to_group(const char * const group, PContact contact) char *unique_id = create_unique_id(NULL); GroupData *data = malloc(sizeof(GroupData)); data->group = strdup(group); - if (p_contact_name(contact) != NULL) { + if (p_contact_name(contact)) { data->name = strdup(p_contact_name(contact)); } else { data->name = strdup(p_contact_barejid(contact)); @@ -162,7 +162,7 @@ static int _group_add_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { - if (userdata != NULL) { + if (userdata) { GroupData *data = userdata; ui_group_added(data->name, data->group); free(data->name); @@ -177,7 +177,7 @@ roster_send_remove_from_group(const char * const group, PContact contact) { GSList *groups = p_contact_groups(contact); GSList *new_groups = NULL; - while (groups != NULL) { + while (groups) { if (strcmp(groups->data, group) != 0) { new_groups = g_slist_append(new_groups, strdup(groups->data)); } @@ -191,7 +191,7 @@ roster_send_remove_from_group(const char * const group, PContact contact) char *unique_id = create_unique_id(NULL); GroupData *data = malloc(sizeof(GroupData)); data->group = strdup(group); - if (p_contact_name(contact) != NULL) { + if (p_contact_name(contact)) { data->name = strdup(p_contact_name(contact)); } else { data->name = strdup(p_contact_barejid(contact)); @@ -209,7 +209,7 @@ static int _group_remove_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { - if (userdata != NULL) { + if (userdata) { GroupData *data = userdata; ui_group_removed(data->name, data->group); free(data->name); @@ -235,7 +235,7 @@ _roster_set_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, // if from attribute exists and it is not current users barejid, ignore push Jid *my_jid = jid_create(jabber_get_fulljid()); const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); - if ((from != NULL) && (strcmp(from, my_jid->barejid) != 0)) { + if (from && (strcmp(from, my_jid->barejid) != 0)) { jid_destroy(my_jid); return 1; } @@ -266,7 +266,7 @@ _roster_set_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, // check for pending out subscriptions gboolean pending_out = FALSE; - if ((ask != NULL) && (strcmp(ask, "subscribe") == 0)) { + if (ask && (strcmp(ask, "subscribe") == 0)) { pending_out = TRUE; } @@ -300,7 +300,7 @@ _roster_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, xmpp_stanza_t *query = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_QUERY); xmpp_stanza_t *item = xmpp_stanza_get_children(query); - while (item != NULL) { + while (item) { const char *barejid = xmpp_stanza_get_attribute(item, STANZA_ATTR_JID); gchar *barejid_lower = g_utf8_strdown(barejid, -1); const char *name = xmpp_stanza_get_attribute(item, STANZA_ATTR_NAME); @@ -344,10 +344,10 @@ _get_groups_from_item(xmpp_stanza_t *item) GSList *groups = NULL; xmpp_stanza_t *group_element = xmpp_stanza_get_children(item); - while (group_element != NULL) { + while (group_element) { if (strcmp(xmpp_stanza_get_name(group_element), STANZA_NAME_GROUP) == 0) { char *groupname = xmpp_stanza_get_text(group_element); - if (groupname != NULL) { + if (groupname) { groups = g_slist_append(groups, groupname); } } From c487fe5f77e6bc0f11b63714d14e62e986eaa3ee Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 23:23:55 +0100 Subject: [PATCH 230/252] Use null check convention in stanza.c --- src/xmpp/stanza.c | 64 +++++++++++++++++++++++------------------------ 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/src/xmpp/stanza.c b/src/xmpp/stanza.c index 84dcb797..1f25239b 100644 --- a/src/xmpp/stanza.c +++ b/src/xmpp/stanza.c @@ -141,7 +141,7 @@ stanza_create_bookmarks_pubsub_add(xmpp_ctx_t *ctx, const char * const jid, xmpp_stanza_set_attribute(conference, STANZA_ATTR_AUTOJOIN, "false"); } - if (nick != NULL) { + if (nick) { xmpp_stanza_t *nick_st = xmpp_stanza_new(ctx); xmpp_stanza_set_name(nick_st, STANZA_NAME_NICK); xmpp_stanza_set_text(nick_st, nick); @@ -374,7 +374,7 @@ stanza_create_roster_set(xmpp_ctx_t *ctx, const char * const id, xmpp_stanza_t *iq = xmpp_stanza_new(ctx); xmpp_stanza_set_name(iq, STANZA_NAME_IQ); xmpp_stanza_set_type(iq, STANZA_TYPE_SET); - if (id != NULL) { + if (id) { xmpp_stanza_set_id(iq, id); } @@ -386,13 +386,13 @@ stanza_create_roster_set(xmpp_ctx_t *ctx, const char * const id, xmpp_stanza_set_name(item, STANZA_NAME_ITEM); xmpp_stanza_set_attribute(item, STANZA_ATTR_JID, jid); - if (handle != NULL) { + if (handle) { xmpp_stanza_set_attribute(item, STANZA_ATTR_NAME, handle); } else { xmpp_stanza_set_attribute(item, STANZA_ATTR_NAME, ""); } - while (groups != NULL) { + while (groups) { xmpp_stanza_t *group = xmpp_stanza_new(ctx); xmpp_stanza_t *groupname = xmpp_stanza_new(ctx); xmpp_stanza_set_name(group, STANZA_NAME_GROUP); @@ -464,7 +464,7 @@ stanza_create_mediated_invite(xmpp_ctx_t *ctx, const char * const room, xmpp_stanza_set_name(invite, STANZA_NAME_INVITE); xmpp_stanza_set_attribute(invite, STANZA_ATTR_TO, contact); - if (reason != NULL) { + if (reason) { xmpp_stanza_t *reason_st = xmpp_stanza_new(ctx); xmpp_stanza_set_name(reason_st, STANZA_NAME_REASON); xmpp_stanza_t *reason_txt = xmpp_stanza_new(ctx); @@ -499,7 +499,7 @@ stanza_create_room_join_presence(xmpp_ctx_t * const ctx, xmpp_stanza_set_ns(x, STANZA_NS_MUC); // if a password was given - if (passwd != NULL) { + if (passwd) { xmpp_stanza_t *pass = xmpp_stanza_new(ctx); xmpp_stanza_set_name(pass, "password"); xmpp_stanza_t *text = xmpp_stanza_new(ctx); @@ -893,7 +893,7 @@ stanza_create_disco_info_iq(xmpp_ctx_t *ctx, const char * const id, const char * xmpp_stanza_t *query = xmpp_stanza_new(ctx); xmpp_stanza_set_name(query, STANZA_NAME_QUERY); xmpp_stanza_set_ns(query, XMPP_NS_DISCO_INFO); - if (node != NULL) { + if (node) { xmpp_stanza_set_attribute(query, STANZA_ATTR_NODE, node); } @@ -964,7 +964,7 @@ stanza_create_ping_iq(xmpp_ctx_t *ctx, const char * const target) xmpp_stanza_t *iq = xmpp_stanza_new(ctx); xmpp_stanza_set_name(iq, STANZA_NAME_IQ); xmpp_stanza_set_type(iq, STANZA_TYPE_GET); - if (target != NULL) { + if (target) { xmpp_stanza_set_attribute(iq, STANZA_ATTR_TO, target); } char *id = create_unique_id("ping"); @@ -987,11 +987,11 @@ stanza_get_delay(xmpp_stanza_t * const stanza, GTimeVal *tv_stamp) { // first check for XEP-0203 delayed delivery xmpp_stanza_t *delay = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_DELAY); - if (delay != NULL) { + if (delay) { char *xmlns = xmpp_stanza_get_attribute(delay, STANZA_ATTR_XMLNS); - if ((xmlns != NULL) && (strcmp(xmlns, "urn:xmpp:delay") == 0)) { + if (xmlns && (strcmp(xmlns, "urn:xmpp:delay") == 0)) { char *stamp = xmpp_stanza_get_attribute(delay, STANZA_ATTR_STAMP); - if ((stamp != NULL) && (g_time_val_from_iso8601(stamp, tv_stamp))) { + if (stamp && (g_time_val_from_iso8601(stamp, tv_stamp))) { return TRUE; } } @@ -1000,11 +1000,11 @@ stanza_get_delay(xmpp_stanza_t * const stanza, GTimeVal *tv_stamp) // otherwise check for XEP-0091 legacy delayed delivery // stanp format : CCYYMMDDThh:mm:ss xmpp_stanza_t *x = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_X); - if (x != NULL) { + if (x) { char *xmlns = xmpp_stanza_get_attribute(x, STANZA_ATTR_XMLNS); - if ((xmlns != NULL) && (strcmp(xmlns, "jabber:x:delay") == 0)) { + if (xmlns && (strcmp(xmlns, "jabber:x:delay") == 0)) { char *stamp = xmpp_stanza_get_attribute(x, STANZA_ATTR_STAMP); - if ((stamp != NULL) && (g_time_val_from_iso8601(stamp, tv_stamp))) { + if (stamp && (g_time_val_from_iso8601(stamp, tv_stamp))) { return TRUE; } } @@ -1020,17 +1020,17 @@ stanza_get_status(xmpp_stanza_t *stanza, char *def) xmpp_stanza_t *status = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_STATUS); - if (status != NULL) { + if (status) { // xmpp_free and free may be different functions so convert all to // libc malloc char *s1, *s2 = NULL; s1 = xmpp_stanza_get_text(status); - if (s1 != NULL) { + if (s1) { s2 = strdup(s1); xmpp_free(ctx, s1); } return s2; - } else if (def != NULL) { + } else if (def) { return strdup(def); } else { return NULL; @@ -1044,17 +1044,17 @@ stanza_get_show(xmpp_stanza_t *stanza, char *def) xmpp_stanza_t *show = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_SHOW); - if (show != NULL) { + if (show) { // xmpp_free and free may be different functions so convert all to // libc malloc char *s1, *s2 = NULL; s1 = xmpp_stanza_get_text(show); - if (s1 != NULL) { + if (s1) { s2 = strdup(s1); xmpp_free(ctx, s1); } return s2; - } else if (def != NULL) { + } else if (def) { return strdup(def); } else { return NULL; @@ -1090,7 +1090,7 @@ stanza_muc_requires_config(xmpp_stanza_t * const stanza) // muc user namespaced x element xmpp_stanza_t *x = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_MUC_USER); - if (x != NULL) { + if (x) { // check for item element with owner affiliation xmpp_stanza_t *item = xmpp_stanza_get_child_by_name(x, "item"); @@ -1104,7 +1104,7 @@ stanza_muc_requires_config(xmpp_stanza_t * const stanza) // check for status code 201 xmpp_stanza_t *x_children = xmpp_stanza_get_children(x); - while (x_children != NULL) { + while (x_children) { if (g_strcmp0(xmpp_stanza_get_name(x_children), STANZA_NAME_STATUS) == 0) { char *code = xmpp_stanza_get_attribute(x_children, STANZA_ATTR_CODE); if (g_strcmp0(code, "201") == 0) { @@ -1346,11 +1346,11 @@ stanza_is_room_nick_change(xmpp_stanza_t * const stanza) // muc user namespaced x element xmpp_stanza_t *x = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_MUC_USER); - if (x != NULL) { + if (x) { // check for status child element with 303 code xmpp_stanza_t *x_children = xmpp_stanza_get_children(x); - while (x_children != NULL) { + while (x_children) { if (g_strcmp0(xmpp_stanza_get_name(x_children), STANZA_NAME_STATUS) == 0) { char *code = xmpp_stanza_get_attribute(x_children, STANZA_ATTR_CODE); if (g_strcmp0(code, "303") == 0) { @@ -1374,7 +1374,7 @@ stanza_get_new_nick(xmpp_stanza_t * const stanza) xmpp_stanza_t *x = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_X); xmpp_stanza_t *x_children = xmpp_stanza_get_children(x); - while (x_children != NULL) { + while (x_children) { if (strcmp(xmpp_stanza_get_name(x_children), STANZA_NAME_ITEM) == 0) { char *nick = xmpp_stanza_get_attribute(x_children, STANZA_ATTR_NICK); if (nick) { @@ -1488,9 +1488,9 @@ stanza_get_error_message(xmpp_stanza_t *stanza) xmpp_stanza_t *text_stanza = xmpp_stanza_get_child_by_name(error_stanza, STANZA_NAME_TEXT); // check for text - if (text_stanza != NULL) { + if (text_stanza) { gchar *err_msg = xmpp_stanza_get_text(text_stanza); - if (err_msg != NULL) { + if (err_msg) { char *result = strdup(err_msg); xmpp_free(ctx, err_msg); return result; @@ -1525,7 +1525,7 @@ stanza_get_error_message(xmpp_stanza_t *stanza) int i; for (i = 0; i < ARRAY_SIZE(defined_conditions); i++) { xmpp_stanza_t *cond_stanza = xmpp_stanza_get_child_by_name(error_stanza, defined_conditions[i]); - if (cond_stanza != NULL) { + if (cond_stanza) { char *result = strdup(xmpp_stanza_get_name(cond_stanza)); return result; } @@ -1562,7 +1562,7 @@ void stanza_attach_show(xmpp_ctx_t * const ctx, xmpp_stanza_t * const presence, const char * const show) { - if (show != NULL) { + if (show) { xmpp_stanza_t *show_stanza = xmpp_stanza_new(ctx); xmpp_stanza_set_name(show_stanza, STANZA_NAME_SHOW); xmpp_stanza_t *text = xmpp_stanza_new(ctx); @@ -1578,7 +1578,7 @@ void stanza_attach_status(xmpp_ctx_t * const ctx, xmpp_stanza_t * const presence, const char * const status) { - if (status != NULL) { + if (status) { xmpp_stanza_t *status_stanza = xmpp_stanza_new(ctx); xmpp_stanza_set_name(status_stanza, STANZA_NAME_STATUS); xmpp_stanza_t *text = xmpp_stanza_new(ctx); @@ -1725,9 +1725,9 @@ stanza_parse_presence(xmpp_stanza_t *stanza, int *err) result->priority = 0; xmpp_stanza_t *priority_stanza = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_PRIORITY); - if (priority_stanza != NULL) { + if (priority_stanza) { char *priority_str = xmpp_stanza_get_text(priority_stanza); - if (priority_str != NULL) { + if (priority_str) { result->priority = atoi(priority_str); } free(priority_str); From 49e450767db2c9d025fe124b824226849bb2bea1 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 23:24:37 +0100 Subject: [PATCH 231/252] Use null check convention in chat_session.c --- src/chat_session.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/chat_session.c b/src/chat_session.c index 8ce2e437..2758d603 100644 --- a/src/chat_session.c +++ b/src/chat_session.c @@ -64,7 +64,7 @@ _chat_session_new(const char * const barejid, const char * const resource, static void _chat_session_free(ChatSession *session) { - if (session != NULL) { + if (session) { free(session->barejid); free(session->resource); free(session); @@ -81,7 +81,7 @@ chat_sessions_init(void) void chat_sessions_clear(void) { - if (sessions != NULL) + if (sessions) g_hash_table_remove_all(sessions); } From 1d002e5bdc4347502bd4b87e147f54e322944250 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 23:26:08 +0100 Subject: [PATCH 232/252] Use null check convention in common.c --- src/common.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/common.c b/src/common.c index 653be720..772e24d3 100644 --- a/src/common.c +++ b/src/common.c @@ -287,7 +287,7 @@ prof_getline(FILE *stream) result = (char *)realloc(s, s_size + buf_size); if (result == NULL) { - if (s != NULL) { + if (s) { free(s); s = NULL; } @@ -325,7 +325,7 @@ release_get_latest() curl_easy_perform(handle); curl_easy_cleanup(handle); - if (output.buffer != NULL) { + if (output.buffer) { output.buffer[output.size++] = '\0'; return output.buffer; } else { @@ -432,10 +432,10 @@ gchar * xdg_get_config_home(void) { gchar *xdg_config_home = getenv("XDG_CONFIG_HOME"); - if (xdg_config_home != NULL) + if (xdg_config_home) g_strstrip(xdg_config_home); - if ((xdg_config_home != NULL) && (strcmp(xdg_config_home, "") != 0)) { + if (xdg_config_home && (strcmp(xdg_config_home, "") != 0)) { return strdup(xdg_config_home); } else { GString *default_path = g_string_new(getenv("HOME")); @@ -451,10 +451,10 @@ gchar * xdg_get_data_home(void) { gchar *xdg_data_home = getenv("XDG_DATA_HOME"); - if (xdg_data_home != NULL) + if (xdg_data_home) g_strstrip(xdg_data_home); - if ((xdg_data_home != NULL) && (strcmp(xdg_data_home, "") != 0)) { + if (xdg_data_home && (strcmp(xdg_data_home, "") != 0)) { return strdup(xdg_data_home); } else { GString *default_path = g_string_new(getenv("HOME")); @@ -474,7 +474,7 @@ create_unique_id(char *prefix) GString *result_str = g_string_new(""); unique_id++; - if (prefix != NULL) { + if (prefix) { g_string_printf(result_str, "prof_%s_%lu", prefix, unique_id); } else { g_string_printf(result_str, "prof_%lu", unique_id); @@ -543,7 +543,7 @@ get_next_available_win_num(GList *used) curr = sorted; // skip console curr = g_list_next(curr); - while (curr != NULL) { + while (curr) { int curr_num = GPOINTER_TO_INT(curr->data); if (((last_num != 9) && ((last_num + 1) != curr_num)) || @@ -622,14 +622,14 @@ strip_arg_quotes(const char * const input) char *unquoted = strdup(input); // Remove starting quote if it exists - if(strchr(unquoted, '"') != NULL) { + if(strchr(unquoted, '"')) { if(strchr(unquoted, ' ') + 1 == strchr(unquoted, '"')) { memmove(strchr(unquoted, '"'), strchr(unquoted, '"')+1, strchr(unquoted, '\0') - strchr(unquoted, '"')); } } // Remove ending quote if it exists - if(strchr(unquoted, '"') != NULL) { + if(strchr(unquoted, '"')) { if(strchr(unquoted, '\0') - 1 == strchr(unquoted, '"')) { memmove(strchr(unquoted, '"'), strchr(unquoted, '"')+1, strchr(unquoted, '\0') - strchr(unquoted, '"')); } From 1bfaa49fb3cd61878c85eb5bfad202a798fb8b0a Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 23:26:57 +0100 Subject: [PATCH 233/252] Use null check convention in contact.c --- src/contact.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/contact.c b/src/contact.c index cd7d5d9d..993ede7c 100644 --- a/src/contact.c +++ b/src/contact.c @@ -63,7 +63,7 @@ p_contact_new(const char * const barejid, const char * const name, PContact contact = malloc(sizeof(struct p_contact_t)); contact->barejid = strdup(barejid); - if (name != NULL) { + if (name) { contact->name = strdup(name); } else { contact->name = NULL; @@ -71,12 +71,12 @@ p_contact_new(const char * const barejid, const char * const name, contact->groups = groups; - if (subscription != NULL) + if (subscription) contact->subscription = strdup(subscription); else contact->subscription = strdup("none"); - if (offline_message != NULL) + if (offline_message) contact->offline_message = strdup(offline_message); else contact->offline_message = NULL; @@ -96,7 +96,7 @@ void p_contact_set_name(const PContact contact, const char * const name) { FREE_SET_NULL(contact->name); - if (name != NULL) { + if (name) { contact->name = strdup(name); } } @@ -104,7 +104,7 @@ p_contact_set_name(const PContact contact, const char * const name) void p_contact_set_groups(const PContact contact, GSList *groups) { - if (contact->groups != NULL) { + if (contact->groups) { g_slist_free_full(contact->groups, g_free); contact->groups = NULL; } @@ -116,7 +116,7 @@ gboolean p_contact_in_group(const PContact contact, const char * const group) { GSList *groups = contact->groups; - while (groups != NULL) { + while (groups) { if (strcmp(groups->data, group) == 0) { return TRUE; } @@ -144,17 +144,17 @@ p_contact_remove_resource(PContact contact, const char * const resource) void p_contact_free(PContact contact) { - if (contact != NULL) { + if (contact) { free(contact->barejid); free(contact->name); free(contact->subscription); free(contact->offline_message); - if (contact->groups != NULL) { + if (contact->groups) { g_slist_free_full(contact->groups, g_free); } - if (contact->last_activity != NULL) { + if (contact->last_activity) { g_date_time_unref(contact->last_activity); } @@ -179,7 +179,7 @@ p_contact_name(const PContact contact) const char * p_contact_name_or_jid(const PContact contact) { - if (contact->name != NULL) { + if (contact->name) { return contact->name; } else { return contact->barejid; @@ -247,7 +247,7 @@ _get_most_available_resource(PContact contact) Resource *current = curr->data; Resource *highest = current; curr = g_list_next(curr); - while (curr != NULL) { + while (curr) { current = curr->data; // priority is same as current highest, choose presence @@ -388,7 +388,7 @@ void p_contact_set_subscription(const PContact contact, const char * const subscription) { FREE_SET_NULL(contact->subscription); - if (subscription != NULL) { + if (subscription) { contact->subscription = strdup(subscription); } } @@ -402,12 +402,12 @@ p_contact_set_pending_out(const PContact contact, gboolean pending_out) void p_contact_set_last_activity(const PContact contact, GDateTime *last_activity) { - if (contact->last_activity != NULL) { + if (contact->last_activity) { g_date_time_unref(contact->last_activity); contact->last_activity = NULL; } - if (last_activity != NULL) { + if (last_activity) { contact->last_activity = g_date_time_ref(last_activity); } } From 4c78534be0e78be94bc7cd23ec1e2f644ebbd27f Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 23:27:41 +0100 Subject: [PATCH 234/252] Use null check convention in jid.c --- src/jid.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/jid.c b/src/jid.c index 0a722b1e..baeeb279 100644 --- a/src/jid.c +++ b/src/jid.c @@ -80,12 +80,12 @@ jid_create(const gchar * const str) gchar *domain_start = trimmed; - if (atp != NULL) { + if (atp) { result->localpart = g_utf8_substring(trimmed, 0, g_utf8_pointer_to_offset(trimmed, atp)); domain_start = atp + 1; } - if (slashp != NULL) { + if (slashp) { result->resourcepart = g_strdup(slashp + 1); result->domainpart = g_utf8_substring(domain_start, 0, g_utf8_pointer_to_offset(domain_start, slashp)); char *barejidraw = g_utf8_substring(trimmed, 0, g_utf8_pointer_to_offset(trimmed, slashp)); @@ -120,7 +120,7 @@ jid_create_from_bare_and_resource(const char * const room, const char * const ni void jid_destroy(Jid *jid) { - if (jid != NULL) { + if (jid) { g_free(jid->str); g_free(jid->localpart); g_free(jid->domainpart); @@ -169,8 +169,8 @@ get_nick_from_full_jid(const char * const full_room_jid) char **tokens = g_strsplit(full_room_jid, "/", 0); char *nick_part = NULL; - if (tokens != NULL) { - if (tokens[0] != NULL && tokens[1] != NULL) { + if (tokens) { + if (tokens[0] && tokens[1]) { nick_part = strdup(tokens[1]); } From 41724218c0ca8be94906001f22c87af423e8540c Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 23:28:34 +0100 Subject: [PATCH 235/252] Use null check convention in log.c --- src/log.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/log.c b/src/log.c index ac0dfd2e..a7727e8b 100644 --- a/src/log.c +++ b/src/log.c @@ -166,7 +166,7 @@ log_close(void) { g_string_free(mainlogfile, TRUE); g_time_zone_unref(tz); - if (logp != NULL) { + if (logp) { fclose(logp); } } @@ -174,7 +174,7 @@ log_close(void) void log_msg(log_level_t level, const char * const area, const char * const msg) { - if (level >= level_filter && logp != NULL) { + if (level >= level_filter && logp) { dt = g_date_time_new_now(tz); char *level_str = _log_string_from_level(level); @@ -347,7 +347,7 @@ _chat_log_chat(const char * const login, const char * const other, FILE *logp = fopen(dated_log->filename, "a"); g_chmod(dated_log->filename, S_IRUSR | S_IWUSR); - if (logp != NULL) { + if (logp) { if (direction == PROF_IN_LOG) { if (strncmp(msg, "/me ", 4) == 0) { fprintf(logp, "%s - *%s %s\n", date_fmt, other, msg + 4); @@ -396,7 +396,7 @@ groupchat_log_chat(const gchar * const login, const gchar * const room, FILE *logp = fopen(dated_log->filename, "a"); g_chmod(dated_log->filename, S_IRUSR | S_IWUSR); - if (logp != NULL) { + if (logp) { if (strncmp(msg, "/me ", 4) == 0) { fprintf(logp, "%s - *%s %s\n", date_fmt, nick, msg + 4); } else { @@ -433,7 +433,7 @@ chat_log_get_previous(const gchar * const login, const gchar * const recipient) char *filename = _get_log_filename(recipient, login, log_date, FALSE); FILE *logp = fopen(filename, "r"); - if (logp != NULL) { + if (logp) { GString *header = g_string_new(""); g_string_append_printf(header, "%d/%d/%d:", g_date_time_get_day_of_month(log_date), @@ -518,12 +518,12 @@ _log_roll_needed(struct dated_chat_log *dated_log) static void _free_chat_log(struct dated_chat_log *dated_log) { - if (dated_log != NULL) { - if (dated_log->filename != NULL) { + if (dated_log) { + if (dated_log->filename) { g_free(dated_log->filename); dated_log->filename = NULL; } - if (dated_log->date != NULL) { + if (dated_log->date) { g_date_time_unref(dated_log->date); dated_log->date = NULL; } From 0930f0f688bc9784b66f8531c4337eaa1106b92a Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 23:29:24 +0100 Subject: [PATCH 236/252] Use null check convention in profanity.c --- src/profanity.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/profanity.c b/src/profanity.c index 6a2966dd..4330b718 100644 --- a/src/profanity.c +++ b/src/profanity.c @@ -112,14 +112,14 @@ prof_handle_idle(void) GSList *recipients = ui_get_chat_recipients(); GSList *curr = recipients; - while (curr != NULL) { + while (curr) { char *barejid = curr->data; ProfChatWin *chatwin = wins_get_chat(barejid); chat_state_handle_idle(chatwin->barejid, chatwin->state); curr = g_slist_next(curr); } - if (recipients != NULL) { + if (recipients) { g_slist_free(recipients); } } From 59788752c7269ef30f25e35bf7fdecb2db3fb2b9 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 23:29:53 +0100 Subject: [PATCH 237/252] Use null check convention in resource.c --- src/resource.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/resource.c b/src/resource.c index 620dd38d..1598c7b2 100644 --- a/src/resource.c +++ b/src/resource.c @@ -46,7 +46,7 @@ Resource * resource_new(const char * const name, resource_presence_t presence, Resource *new_resource = malloc(sizeof(struct resource_t)); new_resource->name = strdup(name); new_resource->presence = presence; - if (status != NULL) { + if (status) { new_resource->status = strdup(status); } else { new_resource->status = NULL; @@ -88,7 +88,7 @@ resource_compare_availability(Resource *first, Resource *second) void resource_destroy(Resource *resource) { - if (resource != NULL) { + if (resource) { free(resource->name); free(resource->status); free(resource); From 6f3750c6aa1ba72378ac004e6abceb19ed1ddecb Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 23:31:05 +0100 Subject: [PATCH 238/252] Use null check convention in roster_list.c --- src/roster_list.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/roster_list.c b/src/roster_list.c index a320ab2b..d5e1c4a0 100644 --- a/src/roster_list.c +++ b/src/roster_list.c @@ -123,8 +123,8 @@ roster_get_msg_display_name(const char * const barejid, const char * const resou GString *result = g_string_new(""); PContact contact = roster_get_contact(barejid); - if (contact != NULL) { - if (p_contact_name(contact) != NULL) { + if (contact) { + if (p_contact_name(contact)) { g_string_append(result, p_contact_name(contact)); } else { g_string_append(result, barejid); @@ -206,7 +206,7 @@ roster_change_name(PContact contact, const char * const new_name) const char *current_name = NULL; const char *barejid = p_contact_barejid(contact); - if (p_contact_name(contact) != NULL) { + if (p_contact_name(contact)) { current_name = strdup(p_contact_name(contact)); } @@ -223,9 +223,9 @@ roster_remove(const char * const name, const char * const barejid) // remove each fulljid PContact contact = roster_get_contact(barejid); - if (contact != NULL) { + if (contact) { GList *resources = p_contact_get_available_resources(contact); - while (resources != NULL) { + while (resources) { GString *fulljid = g_string_new(strdup(barejid)); g_string_append(fulljid, "/"); g_string_append(fulljid, resources->data); @@ -252,7 +252,7 @@ roster_update(const char * const barejid, const char * const name, const char * const new_name = name; const char * current_name = NULL; - if (p_contact_name(contact) != NULL) { + if (p_contact_name(contact)) { current_name = strdup(p_contact_name(contact)); } @@ -261,7 +261,7 @@ roster_update(const char * const barejid, const char * const name, _replace_name(current_name, new_name, barejid); // add groups - while (groups != NULL) { + while (groups) { autocomplete_add(groups_ac, groups->data); groups = g_slist_next(groups); } @@ -272,7 +272,7 @@ roster_add(const char * const barejid, const char * const name, GSList *groups, const char * const subscription, gboolean pending_out) { PContact contact = roster_get_contact(barejid); - if (contact != NULL) { + if (contact) { return FALSE; } @@ -280,7 +280,7 @@ roster_add(const char * const barejid, const char * const name, GSList *groups, pending_out); // add groups - while (groups != NULL) { + while (groups) { autocomplete_add(groups_ac, groups->data); groups = g_slist_next(groups); } @@ -418,7 +418,7 @@ roster_get_group(const char * const group) g_hash_table_iter_init(&iter, contacts); while (g_hash_table_iter_next(&iter, &key, &value)) { GSList *groups = p_contact_groups(value); - while (groups != NULL) { + while (groups) { if (strcmp(groups->data, group) == 0) { result = g_slist_insert_sorted(result, value, (GCompareFunc)_compare_contacts); break; @@ -477,12 +477,12 @@ _replace_name(const char * const current_name, const char * const new_name, const char * const barejid) { // current handle exists already - if (current_name != NULL) { + if (current_name) { autocomplete_remove(name_ac, current_name); g_hash_table_remove(name_to_barejid, current_name); _add_name_and_barejid(new_name, barejid); // no current handle - } else if (new_name != NULL) { + } else if (new_name) { autocomplete_remove(name_ac, barejid); g_hash_table_remove(name_to_barejid, barejid); _add_name_and_barejid(new_name, barejid); @@ -492,7 +492,7 @@ _replace_name(const char * const current_name, const char * const new_name, static void _add_name_and_barejid(const char * const name, const char * const barejid) { - if (name != NULL) { + if (name) { autocomplete_add(name_ac, name); g_hash_table_insert(name_to_barejid, strdup(name), strdup(barejid)); } else { @@ -507,12 +507,12 @@ gint _compare_contacts(PContact a, PContact b) const char * utf8_str_a = NULL; const char * utf8_str_b = NULL; - if (p_contact_name(a) != NULL) { + if (p_contact_name(a)) { utf8_str_a = p_contact_name(a); } else { utf8_str_a = p_contact_barejid(a); } - if (p_contact_name(b) != NULL) { + if (p_contact_name(b)) { utf8_str_b = p_contact_name(b); } else { utf8_str_b = p_contact_barejid(b); From d52f86ef0fe6a7e88c218df5b9802d7901704c57 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 5 May 2015 00:13:41 +0100 Subject: [PATCH 239/252] Tidied form field autocompleters --- src/command/command.c | 48 +++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index 04bb6603..bd0d741c 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -1653,35 +1653,39 @@ cmd_autocomplete_add(char *value) void cmd_autocomplete_add_form_fields(DataForm *form) { - if (form) { - GSList *fields = autocomplete_create_list(form->tag_ac); - GSList *curr_field = fields; - while (curr_field) { - GString *field_str = g_string_new("/"); - g_string_append(field_str, curr_field->data); - cmd_autocomplete_add(field_str->str); - g_string_free(field_str, TRUE); - curr_field = g_slist_next(curr_field); - } - g_slist_free_full(fields, free); + if (form == NULL) { + return; } + + GSList *fields = autocomplete_create_list(form->tag_ac); + GSList *curr_field = fields; + while (curr_field) { + GString *field_str = g_string_new("/"); + g_string_append(field_str, curr_field->data); + cmd_autocomplete_add(field_str->str); + g_string_free(field_str, TRUE); + curr_field = g_slist_next(curr_field); + } + g_slist_free_full(fields, free); } void cmd_autocomplete_remove_form_fields(DataForm *form) { - if (form) { - GSList *fields = autocomplete_create_list(form->tag_ac); - GSList *curr_field = fields; - while (curr_field) { - GString *field_str = g_string_new("/"); - g_string_append(field_str, curr_field->data); - cmd_autocomplete_remove(field_str->str); - g_string_free(field_str, TRUE); - curr_field = g_slist_next(curr_field); - } - g_slist_free_full(fields, free); + if (form == NULL) { + return; } + + GSList *fields = autocomplete_create_list(form->tag_ac); + GSList *curr_field = fields; + while (curr_field) { + GString *field_str = g_string_new("/"); + g_string_append(field_str, curr_field->data); + cmd_autocomplete_remove(field_str->str); + g_string_free(field_str, TRUE); + curr_field = g_slist_next(curr_field); + } + g_slist_free_full(fields, free); } void From 5067e565e32e8035c109718e78cd11299973fb26 Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 6 May 2015 22:02:50 +0100 Subject: [PATCH 240/252] Set ui nonblocking on presence updates Speeds up joining rooms, and connecting. --- src/xmpp/presence.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/xmpp/presence.c b/src/xmpp/presence.c index efb2e32d..45513ac8 100644 --- a/src/xmpp/presence.c +++ b/src/xmpp/presence.c @@ -472,6 +472,8 @@ static int _unavailable_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { + ui_input_nonblocking(TRUE); + const char *jid = xmpp_conn_get_jid(conn); char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); log_debug("Unavailable presence handler fired for %s", from); @@ -547,6 +549,8 @@ static int _available_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { + ui_input_nonblocking(TRUE); + // handler still fires if error if (g_strcmp0(xmpp_stanza_get_type(stanza), STANZA_TYPE_ERROR) == 0) { return 1; @@ -637,6 +641,8 @@ _send_caps_request(char *node, char *caps_key, char *id, char *from) static int _muc_user_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { + ui_input_nonblocking(TRUE); + char *type = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_TYPE); char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); From ca3f7412f58aeb601404417f27dd98e0ffbb2b40 Mon Sep 17 00:00:00 2001 From: James Booth Date: Thu, 7 May 2015 00:16:22 +0100 Subject: [PATCH 241/252] Optimised contact comparisons, create utf8 collate key once --- src/contact.c | 21 +++++++++++++++++++++ src/contact.h | 2 ++ src/roster_list.c | 20 +++++++------------- 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/src/contact.c b/src/contact.c index 993ede7c..713af955 100644 --- a/src/contact.c +++ b/src/contact.c @@ -45,7 +45,9 @@ struct p_contact_t { char *barejid; + gchar *barejid_collate_key; char *name; + gchar *name_collate_key; GSList *groups; char *subscription; char *offline_message; @@ -62,11 +64,14 @@ p_contact_new(const char * const barejid, const char * const name, { PContact contact = malloc(sizeof(struct p_contact_t)); contact->barejid = strdup(barejid); + contact->barejid_collate_key = g_utf8_collate_key(contact->barejid, -1); if (name) { contact->name = strdup(name); + contact->name_collate_key = g_utf8_collate_key(contact->name, -1); } else { contact->name = NULL; + contact->name_collate_key = NULL; } contact->groups = groups; @@ -96,8 +101,10 @@ void p_contact_set_name(const PContact contact, const char * const name) { FREE_SET_NULL(contact->name); + FREE_SET_NULL(contact->name_collate_key); if (name) { contact->name = strdup(name); + contact->name_collate_key = g_utf8_collate_key(contact->name, -1); } } @@ -146,7 +153,9 @@ p_contact_free(PContact contact) { if (contact) { free(contact->barejid); + free(contact->barejid_collate_key); free(contact->name); + free(contact->name_collate_key); free(contact->subscription); free(contact->offline_message); @@ -170,12 +179,24 @@ p_contact_barejid(const PContact contact) return contact->barejid; } +const char * +p_contact_barejid_collate_key(const PContact contact) +{ + return contact->barejid_collate_key; +} + const char * p_contact_name(const PContact contact) { return contact->name; } +const char * +p_contact_name_collate_key(const PContact contact) +{ + return contact->name_collate_key; +} + const char * p_contact_name_or_jid(const PContact contact) { diff --git a/src/contact.h b/src/contact.h index a08aef43..343b230f 100644 --- a/src/contact.h +++ b/src/contact.h @@ -47,7 +47,9 @@ void p_contact_add_resource(PContact contact, Resource *resource); gboolean p_contact_remove_resource(PContact contact, const char * const resource); void p_contact_free(PContact contact); const char* p_contact_barejid(PContact contact); +const char* p_contact_barejid_collate_key(PContact contact); const char* p_contact_name(PContact contact); +const char* p_contact_name_collate_key(PContact contact); const char* p_contact_name_or_jid(const PContact contact); const char* p_contact_presence(PContact contact); const char* p_contact_status(PContact contact); diff --git a/src/roster_list.c b/src/roster_list.c index d5e1c4a0..2d9df860 100644 --- a/src/roster_list.c +++ b/src/roster_list.c @@ -507,24 +507,18 @@ gint _compare_contacts(PContact a, PContact b) const char * utf8_str_a = NULL; const char * utf8_str_b = NULL; - if (p_contact_name(a)) { - utf8_str_a = p_contact_name(a); + if (p_contact_name_collate_key(a)) { + utf8_str_a = p_contact_name_collate_key(a); } else { - utf8_str_a = p_contact_barejid(a); + utf8_str_a = p_contact_barejid_collate_key(a); } - if (p_contact_name(b)) { - utf8_str_b = p_contact_name(b); + if (p_contact_name_collate_key(b)) { + utf8_str_b = p_contact_name_collate_key(b); } else { - utf8_str_b = p_contact_barejid(b); + utf8_str_b = p_contact_barejid_collate_key(b); } - gchar *key_a = g_utf8_collate_key(utf8_str_a, -1); - gchar *key_b = g_utf8_collate_key(utf8_str_b, -1); - - gint result = g_strcmp0(key_a, key_b); - - g_free(key_a); - g_free(key_b); + gint result = g_strcmp0(utf8_str_a, utf8_str_b); return result; } From 6fd9b179a08126deb20d6efedac3089e9bf432cb Mon Sep 17 00:00:00 2001 From: James Booth Date: Thu, 7 May 2015 00:26:24 +0100 Subject: [PATCH 242/252] Optimised occupant comparisons, create utf8 collate key once --- src/muc.c | 15 ++++++--------- src/muc.h | 1 + 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/muc.c b/src/muc.c index 6fd09de3..d283b55e 100644 --- a/src/muc.c +++ b/src/muc.c @@ -832,16 +832,10 @@ _free_room(ChatRoom *room) static gint _compare_occupants(Occupant *a, Occupant *b) { - const char * utf8_str_a = a->nick; - const char * utf8_str_b = b->nick; + const char * utf8_str_a = a->nick_collate_key; + const char * utf8_str_b = b->nick_collate_key; - gchar *key_a = g_utf8_collate_key(utf8_str_a, -1); - gchar *key_b = g_utf8_collate_key(utf8_str_b, -1); - - gint result = g_strcmp0(key_a, key_b); - - g_free(key_a); - g_free(key_b); + gint result = g_strcmp0(utf8_str_a, utf8_str_b); return result; } @@ -947,8 +941,10 @@ _muc_occupant_new(const char *const nick, const char * const jid, muc_role_t rol if (nick) { occupant->nick = strdup(nick); + occupant->nick_collate_key = g_utf8_collate_key(occupant->nick, -1); } else { occupant->nick = NULL; + occupant->nick_collate_key = NULL; } if (jid) { @@ -976,6 +972,7 @@ _occupant_free(Occupant *occupant) { if (occupant) { free(occupant->nick); + free(occupant->nick_collate_key); free(occupant->jid); free(occupant->status); free(occupant); diff --git a/src/muc.h b/src/muc.h index cdaa10bd..ad96f3d9 100644 --- a/src/muc.h +++ b/src/muc.h @@ -64,6 +64,7 @@ typedef enum { typedef struct _muc_occupant_t { char *nick; + gchar *nick_collate_key; char *jid; muc_role_t role; muc_affiliation_t affiliation; From a2c62117322eea58c17231c27c5ee3b41900ea81 Mon Sep 17 00:00:00 2001 From: James Booth Date: Thu, 7 May 2015 22:05:36 +0100 Subject: [PATCH 243/252] Added ui_contact_online --- src/event/server_events.c | 34 ++---------------- src/ui/core.c | 36 +++++++++++++++++++ src/ui/ui.h | 1 + tests/test_server_events.c | 72 ++++++++++---------------------------- tests/testsuite.c | 9 ----- tests/ui/stub_ui.c | 7 ++++ 6 files changed, 64 insertions(+), 95 deletions(-) diff --git a/src/event/server_events.c b/src/event/server_events.c index e409e06a..e2e910a3 100644 --- a/src/event/server_events.c +++ b/src/event/server_events.c @@ -280,42 +280,12 @@ sv_ev_contact_offline(char *barejid, char *resource, char *status) } void -sv_ev_contact_online(char *barejid, Resource *resource, - GDateTime *last_activity) +sv_ev_contact_online(char *barejid, Resource *resource, GDateTime *last_activity) { gboolean updated = roster_update_presence(barejid, resource, last_activity); if (updated) { - char *show_console = prefs_get_string(PREF_STATUSES_CONSOLE); - char *show_chat_win = prefs_get_string(PREF_STATUSES_CHAT); - PContact contact = roster_get_contact(barejid); - if (p_contact_subscription(contact)) { - if (strcmp(p_contact_subscription(contact), "none") != 0) { - - // show in console if "all" - if (g_strcmp0(show_console, "all") == 0) { - cons_show_contact_online(contact, resource, last_activity); - - // show in console of "online" and presence online - } else if (g_strcmp0(show_console, "online") == 0 && - resource->presence == RESOURCE_ONLINE) { - cons_show_contact_online(contact, resource, last_activity); - - } - - // show in chat win if "all" - if (g_strcmp0(show_chat_win, "all") == 0) { - ui_chat_win_contact_online(contact, resource, last_activity); - - // show in char win if "online" and presence online - } else if (g_strcmp0(show_chat_win, "online") == 0 && - resource->presence == RESOURCE_ONLINE) { - ui_chat_win_contact_online(contact, resource, last_activity); - } - } - } - prefs_free_string(show_console); - prefs_free_string(show_chat_win); + ui_contact_online(barejid, resource, last_activity); } rosterwin_roster(); diff --git a/src/ui/core.c b/src/ui/core.c index 06dd84e3..cb295244 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -319,6 +319,42 @@ ui_chat_win_exists(const char * const barejid) return (chatwin != NULL); } +void +ui_contact_online(char *barejid, Resource *resource, GDateTime *last_activity) +{ + char *show_console = prefs_get_string(PREF_STATUSES_CONSOLE); + char *show_chat_win = prefs_get_string(PREF_STATUSES_CHAT); + PContact contact = roster_get_contact(barejid); + + // show nothing + if (g_strcmp0(p_contact_subscription(contact), "none") == 0) { + free(show_console); + free(show_chat_win); + return; + } + + // show in console if "all" + if (g_strcmp0(show_console, "all") == 0) { + cons_show_contact_online(contact, resource, last_activity); + + // show in console of "online" and presence online + } else if (g_strcmp0(show_console, "online") == 0 && resource->presence == RESOURCE_ONLINE) { + cons_show_contact_online(contact, resource, last_activity); + } + + // show in chat win if "all" + if (g_strcmp0(show_chat_win, "all") == 0) { + ui_chat_win_contact_online(contact, resource, last_activity); + + // show in char win if "online" and presence online + } else if (g_strcmp0(show_chat_win, "online") == 0 && resource->presence == RESOURCE_ONLINE) { + ui_chat_win_contact_online(contact, resource, last_activity); + } + + free(show_console); + free(show_chat_win); +} + void ui_contact_typing(const char * const barejid, const char * const resource) { diff --git a/src/ui/ui.h b/src/ui/ui.h index c98d45e8..48b8d393 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -112,6 +112,7 @@ char * ui_ask_password(void); void ui_handle_stanza(const char * const msg); // ui events +void ui_contact_online(char *barejid, Resource *resource, GDateTime *last_activity); void ui_contact_typing(const char * const barejid, const char * const resource); void ui_incoming_msg(const char * const from, const char * const resource, const char * const message, GTimeVal *tv_stamp); void ui_incoming_private_msg(const char * const fulljid, const char * const message, GTimeVal *tv_stamp); diff --git a/tests/test_server_events.c b/tests/test_server_events.c index d87dc217..58489807 100644 --- a/tests/test_server_events.c +++ b/tests/test_server_events.c @@ -14,31 +14,19 @@ #include "ui/stub_ui.h" #include "muc.h" -void console_doesnt_show_online_presence_when_set_none(void **state) -{ - prefs_set_string(PREF_STATUSES_CONSOLE, "none"); - roster_init(); - roster_add("test1@server", "bob", NULL, "both", FALSE); - Resource *resource = resource_new("resource", RESOURCE_ONLINE, NULL, 10); - - sv_ev_contact_online("test1@server", resource, NULL); - - roster_clear(); -} - void console_shows_online_presence_when_set_online(void **state) { prefs_set_string(PREF_STATUSES_CONSOLE, "online"); roster_init(); - roster_add("test1@server", "bob", NULL, "both", FALSE); + char *barejid = "test1@server"; + roster_add(barejid, "bob", NULL, "both", FALSE); Resource *resource = resource_new("resource", RESOURCE_ONLINE, NULL, 10); - PContact contact = roster_get_contact("test1@server"); - expect_memory(cons_show_contact_online, contact, contact, sizeof(contact)); - expect_memory(cons_show_contact_online, resource, resource, sizeof(resource)); - expect_value(cons_show_contact_online, last_activity, NULL); + expect_memory(ui_contact_online, barejid, barejid, sizeof(barejid)); + expect_memory(ui_contact_online, resource, resource, sizeof(resource)); + expect_value(ui_contact_online, last_activity, NULL); - sv_ev_contact_online("test1@server", resource, NULL); + sv_ev_contact_online(barejid, resource, NULL); roster_clear(); } @@ -47,39 +35,15 @@ void console_shows_online_presence_when_set_all(void **state) { prefs_set_string(PREF_STATUSES_CONSOLE, "all"); roster_init(); - roster_add("test1@server", "bob", NULL, "both", FALSE); + char *barejid = "test1@server"; + roster_add(barejid, "bob", NULL, "both", FALSE); Resource *resource = resource_new("resource", RESOURCE_ONLINE, NULL, 10); - PContact contact = roster_get_contact("test1@server"); - expect_memory(cons_show_contact_online, contact, contact, sizeof(contact)); - expect_memory(cons_show_contact_online, resource, resource, sizeof(resource)); - expect_value(cons_show_contact_online, last_activity, NULL); + expect_memory(ui_contact_online, barejid, barejid, sizeof(barejid)); + expect_memory(ui_contact_online, resource, resource, sizeof(resource)); + expect_value(ui_contact_online, last_activity, NULL); - sv_ev_contact_online("test1@server", resource, NULL); - - roster_clear(); -} - -void console_doesnt_show_dnd_presence_when_set_none(void **state) -{ - prefs_set_string(PREF_STATUSES_CONSOLE, "none"); - roster_init(); - roster_add("test1@server", "bob", NULL, "both", FALSE); - Resource *resource = resource_new("resource", RESOURCE_DND, NULL, 10); - - sv_ev_contact_online("test1@server", resource, NULL); - - roster_clear(); -} - -void console_doesnt_show_dnd_presence_when_set_online(void **state) -{ - prefs_set_string(PREF_STATUSES_CONSOLE, "online"); - roster_init(); - roster_add("test1@server", "bob", NULL, "both", FALSE); - Resource *resource = resource_new("resource", RESOURCE_DND, NULL, 10); - - sv_ev_contact_online("test1@server", resource, NULL); + sv_ev_contact_online(barejid, resource, NULL); roster_clear(); } @@ -88,15 +52,15 @@ void console_shows_dnd_presence_when_set_all(void **state) { prefs_set_string(PREF_STATUSES_CONSOLE, "all"); roster_init(); - roster_add("test1@server", "bob", NULL, "both", FALSE); + char *barejid = "test1@server"; + roster_add(barejid, "bob", NULL, "both", FALSE); Resource *resource = resource_new("resource", RESOURCE_ONLINE, NULL, 10); - PContact contact = roster_get_contact("test1@server"); - expect_memory(cons_show_contact_online, contact, contact, sizeof(contact)); - expect_memory(cons_show_contact_online, resource, resource, sizeof(resource)); - expect_value(cons_show_contact_online, last_activity, NULL); + expect_memory(ui_contact_online, barejid, barejid, sizeof(barejid)); + expect_memory(ui_contact_online, resource, resource, sizeof(resource)); + expect_value(ui_contact_online, last_activity, NULL); - sv_ev_contact_online("test1@server", resource, NULL); + sv_ev_contact_online(barejid, resource, NULL); roster_clear(); } diff --git a/tests/testsuite.c b/tests/testsuite.c index 91fd54e3..3f860178 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -425,21 +425,12 @@ int main(int argc, char* argv[]) { load_preferences, close_preferences), - unit_test_setup_teardown(console_doesnt_show_online_presence_when_set_none, - load_preferences, - close_preferences), unit_test_setup_teardown(console_shows_online_presence_when_set_online, load_preferences, close_preferences), unit_test_setup_teardown(console_shows_online_presence_when_set_all, load_preferences, close_preferences), - unit_test_setup_teardown(console_doesnt_show_dnd_presence_when_set_none, - load_preferences, - close_preferences), - unit_test_setup_teardown(console_doesnt_show_dnd_presence_when_set_online, - load_preferences, - close_preferences), unit_test_setup_teardown(console_shows_dnd_presence_when_set_all, load_preferences, close_preferences), diff --git a/tests/ui/stub_ui.c b/tests/ui/stub_ui.c index c23723e1..f3c5831f 100644 --- a/tests/ui/stub_ui.c +++ b/tests/ui/stub_ui.c @@ -185,6 +185,13 @@ char * ui_ask_password(void) void ui_handle_stanza(const char * const msg) {} // ui events +void ui_contact_online(char *barejid, Resource *resource, GDateTime *last_activity) +{ + check_expected(barejid); + check_expected(resource); + check_expected(last_activity); +} + void ui_contact_typing(const char * const barejid, const char * const resource) {} void ui_incoming_msg(const char * const from, const char * const resource, const char * const message, GTimeVal *tv_stamp) {} void ui_message_receipt(const char * const barejid, const char * const id) {} From f69ccbf0cc94c44ee806d745ddc57adbaa007a20 Mon Sep 17 00:00:00 2001 From: James Booth Date: Thu, 7 May 2015 22:51:35 +0100 Subject: [PATCH 244/252] Tidied _roster_result_handler --- src/xmpp/roster.c | 64 +++++++++++++++++++++++------------------------ 1 file changed, 31 insertions(+), 33 deletions(-) diff --git a/src/xmpp/roster.c b/src/xmpp/roster.c index 71396c4d..2f2bc77f 100644 --- a/src/xmpp/roster.c +++ b/src/xmpp/roster.c @@ -290,51 +290,49 @@ _roster_set_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, } static int -_roster_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, - void * const userdata) +_roster_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID); + if (g_strcmp0(id, "roster") != 0) { + return 1; + } + // handle initial roster response - if (g_strcmp0(id, "roster") == 0) { - xmpp_stanza_t *query = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_QUERY); - xmpp_stanza_t *item = xmpp_stanza_get_children(query); + xmpp_stanza_t *query = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_QUERY); + xmpp_stanza_t *item = xmpp_stanza_get_children(query); - while (item) { - const char *barejid = xmpp_stanza_get_attribute(item, STANZA_ATTR_JID); - gchar *barejid_lower = g_utf8_strdown(barejid, -1); - const char *name = xmpp_stanza_get_attribute(item, STANZA_ATTR_NAME); - const char *sub = xmpp_stanza_get_attribute(item, STANZA_ATTR_SUBSCRIPTION); + while (item) { + const char *barejid = xmpp_stanza_get_attribute(item, STANZA_ATTR_JID); + gchar *barejid_lower = g_utf8_strdown(barejid, -1); + const char *name = xmpp_stanza_get_attribute(item, STANZA_ATTR_NAME); + const char *sub = xmpp_stanza_get_attribute(item, STANZA_ATTR_SUBSCRIPTION); - // do not set nickname to empty string, set to NULL instead - if (name && (strlen(name) == 0)) { - name = NULL; - } + // do not set nickname to empty string, set to NULL instead + if (name && (strlen(name) == 0)) name = NULL; - gboolean pending_out = FALSE; - const char *ask = xmpp_stanza_get_attribute(item, STANZA_ATTR_ASK); - if (g_strcmp0(ask, "subscribe") == 0) { - pending_out = TRUE; - } - - GSList *groups = _get_groups_from_item(item); - - gboolean added = roster_add(barejid_lower, name, groups, sub, pending_out); - - if (!added) { - log_warning("Attempt to add contact twice: %s", barejid_lower); - } - - g_free(barejid_lower); - item = xmpp_stanza_get_next(item); + gboolean pending_out = FALSE; + const char *ask = xmpp_stanza_get_attribute(item, STANZA_ATTR_ASK); + if (g_strcmp0(ask, "subscribe") == 0) { + pending_out = TRUE; } - sv_ev_roster_received(); + GSList *groups = _get_groups_from_item(item); - resource_presence_t conn_presence = accounts_get_login_presence(jabber_get_account_name()); - presence_update(conn_presence, NULL, 0); + gboolean added = roster_add(barejid_lower, name, groups, sub, pending_out); + if (!added) { + log_warning("Attempt to add contact twice: %s", barejid_lower); + } + + g_free(barejid_lower); + item = xmpp_stanza_get_next(item); } + sv_ev_roster_received(); + + resource_presence_t conn_presence = accounts_get_login_presence(jabber_get_account_name()); + presence_update(conn_presence, NULL, 0); + return 1; } From 56cbce2ff3d1d1de4f3cd1661a719773c0c915f0 Mon Sep 17 00:00:00 2001 From: James Booth Date: Thu, 7 May 2015 23:12:49 +0100 Subject: [PATCH 245/252] Renamed presence_update -> presence_send --- src/command/commands.c | 6 +++--- src/profanity.c | 8 ++++---- src/xmpp/presence.c | 13 ++++--------- src/xmpp/roster.c | 2 +- src/xmpp/xmpp.h | 2 +- tests/test_cmd_account.c | 6 +++--- tests/xmpp/stub_xmpp.c | 2 +- 7 files changed, 17 insertions(+), 22 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index 3d7dcc67..4608b7de 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -507,7 +507,7 @@ cmd_account(gchar **args, struct cmd_help_t help) if (presence_type == last_presence) { char *message = jabber_get_presence_message(); - presence_update(last_presence, message, 0); + presence_send(last_presence, message, 0); } } cons_show("Updated %s priority for account %s: %s", property, account_name, value); @@ -3808,7 +3808,7 @@ cmd_priority(gchar **args, struct cmd_help_t help) if (res) { accounts_set_priority_all(jabber_get_account_name(), intval); resource_presence_t last_presence = accounts_get_last_presence(jabber_get_account_name()); - presence_update(last_presence, jabber_get_presence_message(), 0); + presence_send(last_presence, jabber_get_presence_message(), 0); cons_show("Priority set to %d.", intval); } else { cons_show(err_msg); @@ -4330,7 +4330,7 @@ _update_presence(const resource_presence_t resource_presence, if (conn_status != JABBER_CONNECTED) { cons_show("You are not currently connected."); } else { - presence_update(resource_presence, msg, 0); + presence_send(resource_presence, msg, 0); ui_update_presence(resource_presence, msg, show); } } diff --git a/src/profanity.c b/src/profanity.c index 4330b718..2472006c 100644 --- a/src/profanity.c +++ b/src/profanity.c @@ -172,12 +172,12 @@ _check_autoaway() // handle away mode if (strcmp(pref_autoaway_mode, "away") == 0) { - presence_update(RESOURCE_AWAY, pref_autoaway_message, 0); + presence_send(RESOURCE_AWAY, pref_autoaway_message, 0); ui_auto_away(); // handle idle mode } else if (strcmp(pref_autoaway_mode, "idle") == 0) { - presence_update(RESOURCE_ONLINE, pref_autoaway_message, idle_ms / 1000); + presence_send(RESOURCE_ONLINE, pref_autoaway_message, idle_ms / 1000); } prefs_free_string(pref_autoaway_message); @@ -191,10 +191,10 @@ _check_autoaway() // handle check if (prefs_get_boolean(PREF_AUTOAWAY_CHECK)) { if (strcmp(pref_autoaway_mode, "away") == 0) { - presence_update(RESOURCE_ONLINE, NULL, 0); + presence_send(RESOURCE_ONLINE, NULL, 0); ui_end_auto_away(); } else if (strcmp(pref_autoaway_mode, "idle") == 0) { - presence_update(RESOURCE_ONLINE, NULL, 0); + presence_send(RESOURCE_ONLINE, NULL, 0); ui_titlebar_presence(CONTACT_ONLINE); } } diff --git a/src/xmpp/presence.c b/src/xmpp/presence.c index 45513ac8..e46730e3 100644 --- a/src/xmpp/presence.c +++ b/src/xmpp/presence.c @@ -193,8 +193,7 @@ presence_reset_sub_request_search(void) } void -presence_update(const resource_presence_t presence_type, const char * const msg, - const int idle) +presence_send(const resource_presence_t presence_type, const char * const msg, const int idle) { if (jabber_get_connection_status() != JABBER_CONNECTED) { log_warning("Error setting presence, not connected."); @@ -202,18 +201,14 @@ presence_update(const resource_presence_t presence_type, const char * const msg, } if (msg) { - log_debug("Updating presence: %s, \"%s\"", - string_from_resource_presence(presence_type), msg); + log_debug("Updating presence: %s, \"%s\"", string_from_resource_presence(presence_type), msg); } else { - log_debug("Updating presence: %s", - string_from_resource_presence(presence_type)); + log_debug("Updating presence: %s", string_from_resource_presence(presence_type)); } xmpp_ctx_t * const ctx = connection_get_ctx(); xmpp_conn_t * const conn = connection_get_conn(); - const int pri = - accounts_get_priority_for_presence_type(jabber_get_account_name(), - presence_type); + const int pri = accounts_get_priority_for_presence_type(jabber_get_account_name(), presence_type); const char *show = stanza_get_presence_string_from_type(presence_type); connection_set_presence_message(msg); diff --git a/src/xmpp/roster.c b/src/xmpp/roster.c index 2f2bc77f..9ee4ec86 100644 --- a/src/xmpp/roster.c +++ b/src/xmpp/roster.c @@ -331,7 +331,7 @@ _roster_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, v sv_ev_roster_received(); resource_presence_t conn_presence = accounts_get_login_presence(jabber_get_account_name()); - presence_update(conn_presence, NULL, 0); + presence_send(conn_presence, NULL, 0); return 1; } diff --git a/src/xmpp/xmpp.h b/src/xmpp/xmpp.h index 1dc0c131..398c9f46 100644 --- a/src/xmpp/xmpp.h +++ b/src/xmpp/xmpp.h @@ -168,7 +168,7 @@ char * presence_sub_request_find(const char * const search_str); void presence_join_room(char *room, char *nick, char * passwd); void presence_change_room_nick(const char * const room, const char * const nick); void presence_leave_chat_room(const char * const room_jid); -void presence_update(resource_presence_t status, const char * const msg, +void presence_send(resource_presence_t status, const char * const msg, int idle); gboolean presence_sub_request_exists(const char * const bare_jid); diff --git a/tests/test_cmd_account.c b/tests/test_cmd_account.c index d02fc5ba..bddc4c6d 100644 --- a/tests/test_cmd_account.c +++ b/tests/test_cmd_account.c @@ -941,9 +941,9 @@ void cmd_account_set_priority_updates_presence_when_account_connected_with_prese will_return(jabber_get_presence_message, "Free to chat"); - expect_value(presence_update, status, RESOURCE_ONLINE); - expect_string(presence_update, msg, "Free to chat"); - expect_value(presence_update, idle, 0); + expect_value(presence_send, status, RESOURCE_ONLINE); + expect_string(presence_send, msg, "Free to chat"); + expect_value(presence_send, idle, 0); expect_cons_show("Updated online priority for account a_account: 10"); expect_cons_show(""); diff --git a/tests/xmpp/stub_xmpp.c b/tests/xmpp/stub_xmpp.c index 1e57f7a8..cc9580bf 100644 --- a/tests/xmpp/stub_xmpp.c +++ b/tests/xmpp/stub_xmpp.c @@ -114,7 +114,7 @@ void presence_join_room(char *room, char *nick, char * passwd) void presence_change_room_nick(const char * const room, const char * const nick) {} void presence_leave_chat_room(const char * const room_jid) {} -void presence_update(resource_presence_t status, const char * const msg, int idle) +void presence_send(resource_presence_t status, const char * const msg, int idle) { check_expected(status); check_expected(msg); From d853284f92fb93067b724446f256cefcccd4b67c Mon Sep 17 00:00:00 2001 From: James Booth Date: Thu, 7 May 2015 23:21:48 +0100 Subject: [PATCH 246/252] Added cl_ev_presence_send --- src/command/commands.c | 6 +++--- src/event/client_events.c | 6 ++++++ src/event/client_events.h | 2 ++ src/profanity.c | 9 +++++---- src/xmpp/roster.c | 3 ++- 5 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index 4608b7de..0c341880 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -507,7 +507,7 @@ cmd_account(gchar **args, struct cmd_help_t help) if (presence_type == last_presence) { char *message = jabber_get_presence_message(); - presence_send(last_presence, message, 0); + cl_ev_presence_send(last_presence, message, 0); } } cons_show("Updated %s priority for account %s: %s", property, account_name, value); @@ -3808,7 +3808,7 @@ cmd_priority(gchar **args, struct cmd_help_t help) if (res) { accounts_set_priority_all(jabber_get_account_name(), intval); resource_presence_t last_presence = accounts_get_last_presence(jabber_get_account_name()); - presence_send(last_presence, jabber_get_presence_message(), 0); + cl_ev_presence_send(last_presence, jabber_get_presence_message(), 0); cons_show("Priority set to %d.", intval); } else { cons_show(err_msg); @@ -4330,7 +4330,7 @@ _update_presence(const resource_presence_t resource_presence, if (conn_status != JABBER_CONNECTED) { cons_show("You are not currently connected."); } else { - presence_send(resource_presence, msg, 0); + cl_ev_presence_send(resource_presence, msg, 0); ui_update_presence(resource_presence, msg, show); } } diff --git a/src/event/client_events.c b/src/event/client_events.c index db8f6497..f0f763a6 100644 --- a/src/event/client_events.c +++ b/src/event/client_events.c @@ -60,6 +60,12 @@ cl_ev_connect_account(ProfAccount *account) return jabber_connect_with_account(account); } +void +cl_ev_presence_send(const resource_presence_t presence_type, const char * const msg, const int idle) +{ + presence_send(presence_type, msg, idle); +} + void cl_ev_send_msg(ProfChatWin *chatwin, const char * const msg) { diff --git a/src/event/client_events.h b/src/event/client_events.h index a7ecc583..207299c5 100644 --- a/src/event/client_events.h +++ b/src/event/client_events.h @@ -38,6 +38,8 @@ jabber_conn_status_t cl_ev_connect_jid(const char * const jid, const char * const passwd, const char * const altdomain, const int port); jabber_conn_status_t cl_ev_connect_account(ProfAccount *account); +void cl_ev_presence_send(const resource_presence_t presence_type, const char * const msg, const int idle); + void cl_ev_send_msg(ProfChatWin *chatwin, const char * const msg); void cl_ev_send_muc_msg(ProfMucWin *mucwin, const char * const msg); void cl_ev_send_priv_msg(ProfPrivateWin *privwin, const char * const msg); diff --git a/src/profanity.c b/src/profanity.c index 2472006c..55a73430 100644 --- a/src/profanity.c +++ b/src/profanity.c @@ -63,6 +63,7 @@ #include "xmpp/xmpp.h" #include "ui/ui.h" #include "ui/windows.h" +#include "event/client_events.h" static void _check_autoaway(void); static void _init(const int disable_tls, char *log_level); @@ -172,12 +173,12 @@ _check_autoaway() // handle away mode if (strcmp(pref_autoaway_mode, "away") == 0) { - presence_send(RESOURCE_AWAY, pref_autoaway_message, 0); + cl_ev_presence_send(RESOURCE_AWAY, pref_autoaway_message, 0); ui_auto_away(); // handle idle mode } else if (strcmp(pref_autoaway_mode, "idle") == 0) { - presence_send(RESOURCE_ONLINE, pref_autoaway_message, idle_ms / 1000); + cl_ev_presence_send(RESOURCE_ONLINE, pref_autoaway_message, idle_ms / 1000); } prefs_free_string(pref_autoaway_message); @@ -191,10 +192,10 @@ _check_autoaway() // handle check if (prefs_get_boolean(PREF_AUTOAWAY_CHECK)) { if (strcmp(pref_autoaway_mode, "away") == 0) { - presence_send(RESOURCE_ONLINE, NULL, 0); + cl_ev_presence_send(RESOURCE_ONLINE, NULL, 0); ui_end_auto_away(); } else if (strcmp(pref_autoaway_mode, "idle") == 0) { - presence_send(RESOURCE_ONLINE, NULL, 0); + cl_ev_presence_send(RESOURCE_ONLINE, NULL, 0); ui_titlebar_presence(CONTACT_ONLINE); } } diff --git a/src/xmpp/roster.c b/src/xmpp/roster.c index 9ee4ec86..5c9fa5d4 100644 --- a/src/xmpp/roster.c +++ b/src/xmpp/roster.c @@ -43,6 +43,7 @@ #include "profanity.h" #include "ui/ui.h" #include "event/server_events.h" +#include "event/client_events.h" #include "tools/autocomplete.h" #include "xmpp/connection.h" #include "xmpp/roster.h" @@ -331,7 +332,7 @@ _roster_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, v sv_ev_roster_received(); resource_presence_t conn_presence = accounts_get_login_presence(jabber_get_account_name()); - presence_send(conn_presence, NULL, 0); + cl_ev_presence_send(conn_presence, NULL, 0); return 1; } From aaad3ff90903e05f075076dc87b4ec9e66b4a773 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 10 May 2015 01:03:34 +0100 Subject: [PATCH 247/252] Moved logic to notify_message --- src/ui/core.c | 28 ++-------------------------- src/ui/notifier.c | 26 +++++++++++++++++--------- src/ui/ui.h | 2 +- tests/ui/stub_ui.c | 2 +- 4 files changed, 21 insertions(+), 37 deletions(-) diff --git a/src/ui/core.c b/src/ui/core.c index cb295244..36b73f33 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -473,20 +473,8 @@ ui_incoming_msg(const char * const barejid, const char * const resource, const c beep(); } - int ui_index = num; - if (ui_index == 10) { - ui_index = 0; - } - if (prefs_get_boolean(PREF_NOTIFY_MESSAGE)) { - gboolean is_current = wins_is_current(window); - if ( !is_current || (is_current && prefs_get_boolean(PREF_NOTIFY_MESSAGE_CURRENT)) ) { - if (prefs_get_boolean(PREF_NOTIFY_MESSAGE_TEXT)) { - notify_message(display_name, ui_index, message); - } else { - notify_message(display_name, ui_index, NULL); - } - } + notify_message(window, display_name, message); } free(display_name); @@ -525,24 +513,12 @@ ui_incoming_private_msg(const char * const fulljid, const char * const message, } } - int ui_index = num; - if (ui_index == 10) { - ui_index = 0; - } - if (prefs_get_boolean(PREF_BEEP)) { beep(); } if (prefs_get_boolean(PREF_NOTIFY_MESSAGE)) { - gboolean is_current = wins_is_current(window); - if ( !is_current || (is_current && prefs_get_boolean(PREF_NOTIFY_MESSAGE_CURRENT)) ) { - if (prefs_get_boolean(PREF_NOTIFY_MESSAGE_TEXT)) { - notify_message(display_from, ui_index, message); - } else { - notify_message(display_from, ui_index, NULL); - } - } + notify_message(window, display_from, message); } free(display_from); diff --git a/src/ui/notifier.c b/src/ui/notifier.c index d3389bc5..76290daf 100644 --- a/src/ui/notifier.c +++ b/src/ui/notifier.c @@ -48,10 +48,10 @@ #include "log.h" #include "muc.h" #include "ui/ui.h" +#include "ui/windows.h" #include "config/preferences.h" -static void _notify(const char * const message, int timeout, - const char * const category); +static void _notify(const char * const message, int timeout, const char * const category); static GTimer *remind_timer; @@ -99,17 +99,25 @@ notify_invite(const char * const from, const char * const room, } void -notify_message(const char * const handle, int win, const char * const text) +notify_message(ProfWin *window, const char * const name, const char * const text) { - GString *message = g_string_new(""); - g_string_append_printf(message, "%s (win %d)", handle, win); - if (text) { - g_string_append_printf(message, "\n%s", text); + int num = wins_get_num(window); + if (num == 10) { + num = 0; } - _notify(message->str, 10000, "incoming message"); + gboolean is_current = wins_is_current(window); + if (!is_current || (is_current && prefs_get_boolean(PREF_NOTIFY_MESSAGE_CURRENT)) ) { + GString *message = g_string_new(""); + g_string_append_printf(message, "%s (win %d)", name, num); - g_string_free(message, TRUE); + if (prefs_get_boolean(PREF_NOTIFY_MESSAGE_TEXT) && text) { + g_string_append_printf(message, "\n%s", text); + } + + _notify(message->str, 10000, "incoming message"); + g_string_free(message, TRUE); + } } void diff --git a/src/ui/ui.h b/src/ui/ui.h index 48b8d393..0ee21be4 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -342,7 +342,7 @@ void notifier_initialise(void); void notifier_uninit(void); void notify_typing(const char * const handle); -void notify_message(const char * const handle, int win, const char * const text); +void notify_message(ProfWin *window, const char * const name, const char * const text); void notify_room_message(const char * const handle, const char * const room, int win, const char * const text); void notify_remind(void); diff --git a/tests/ui/stub_ui.c b/tests/ui/stub_ui.c index f3c5831f..52c38570 100644 --- a/tests/ui/stub_ui.c +++ b/tests/ui/stub_ui.c @@ -500,7 +500,7 @@ void occupantswin_occupants(const char * const room) {} void notifier_uninit(void) {} void notify_typing(const char * const handle) {} -void notify_message(const char * const handle, int win, const char * const text) {} +void notify_message(ProfWin *window, const char * const name, const char * const text) {} void notify_room_message(const char * const handle, const char * const room, int win, const char * const text) {} void notify_remind(void) {} From aeffca496c338e91cacb4af1ebf0d8ca3160bf31 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 10 May 2015 01:44:34 +0100 Subject: [PATCH 248/252] Tidy ui_room_message --- src/ui/core.c | 136 +++++++++++++++++++++++++------------------------- 1 file changed, 69 insertions(+), 67 deletions(-) diff --git a/src/ui/core.c b/src/ui/core.c index 36b73f33..2c797271 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -1748,77 +1748,79 @@ ui_room_message(const char * const roomjid, const char * const nick, ProfMucWin *mucwin = wins_get_muc(roomjid); if (mucwin == NULL) { log_error("Room message received from %s, but no window open for %s", nick, roomjid); + return; + } + + ProfWin *window = (ProfWin*) mucwin; + int num = wins_get_num(window); + char *my_nick = muc_nick(roomjid); + + if (g_strcmp0(nick, my_nick) != 0) { + if (g_strrstr(message, my_nick)) { + win_print(window, '-', NULL, NO_ME, THEME_ROOMMENTION, nick, message); + } else { + win_print(window, '-', NULL, NO_ME, THEME_TEXT_THEM, nick, message); + } } else { - ProfWin *window = (ProfWin*) mucwin; - int num = wins_get_num(window); - char *my_nick = muc_nick(roomjid); + win_print(window, '-', NULL, 0, THEME_TEXT_ME, nick, message); + } - if (g_strcmp0(nick, my_nick) != 0) { - if (g_strrstr(message, my_nick)) { - win_print(window, '-', NULL, NO_ME, THEME_ROOMMENTION, nick, message); + // currently in groupchat window + if (wins_is_current(window)) { + status_bar_active(num); + + // not currently on groupchat window + } else { + status_bar_new(num); + cons_show_incoming_message(nick, num); + + if (prefs_get_boolean(PREF_FLASH) && (strcmp(nick, my_nick) != 0)) { + flash(); + } + + mucwin->unread++; + } + + int ui_index = num; + if (ui_index == 10) { + ui_index = 0; + } + + // don't notify self messages + if (strcmp(nick, my_nick) == 0) { + return; + } + + if (prefs_get_boolean(PREF_BEEP)) { + beep(); + } + + gboolean notify = FALSE; + char *room_setting = prefs_get_string(PREF_NOTIFY_ROOM); + if (g_strcmp0(room_setting, "on") == 0) { + notify = TRUE; + } + if (g_strcmp0(room_setting, "mention") == 0) { + char *message_lower = g_utf8_strdown(message, -1); + char *nick_lower = g_utf8_strdown(nick, -1); + if (g_strrstr(message_lower, nick_lower)) { + notify = TRUE; + } + g_free(message_lower); + g_free(nick_lower); + } + prefs_free_string(room_setting); + + if (notify) { + gboolean is_current = wins_is_current(window); + if ( !is_current || (is_current && prefs_get_boolean(PREF_NOTIFY_ROOM_CURRENT)) ) { + Jid *jidp = jid_create(roomjid); + if (prefs_get_boolean(PREF_NOTIFY_ROOM_TEXT)) { + notify_room_message(nick, jidp->localpart, ui_index, message); } else { - win_print(window, '-', NULL, NO_ME, THEME_TEXT_THEM, nick, message); - } - } else { - win_print(window, '-', NULL, 0, THEME_TEXT_ME, nick, message); - } - - // currently in groupchat window - if (wins_is_current(window)) { - status_bar_active(num); - - // not currently on groupchat window - } else { - status_bar_new(num); - cons_show_incoming_message(nick, num); - - if (strcmp(nick, my_nick) != 0) { - if (prefs_get_boolean(PREF_FLASH)) { - flash(); - } - } - - mucwin->unread++; - } - - int ui_index = num; - if (ui_index == 10) { - ui_index = 0; - } - - if (strcmp(nick, muc_nick(roomjid)) != 0) { - if (prefs_get_boolean(PREF_BEEP)) { - beep(); - } - - gboolean notify = FALSE; - char *room_setting = prefs_get_string(PREF_NOTIFY_ROOM); - if (g_strcmp0(room_setting, "on") == 0) { - notify = TRUE; - } - if (g_strcmp0(room_setting, "mention") == 0) { - char *message_lower = g_utf8_strdown(message, -1); - char *nick_lower = g_utf8_strdown(nick, -1); - if (g_strrstr(message_lower, nick_lower)) { - notify = TRUE; - } - g_free(message_lower); - g_free(nick_lower); - } - prefs_free_string(room_setting); - - if (notify) { - gboolean is_current = wins_is_current(window); - if ( !is_current || (is_current && prefs_get_boolean(PREF_NOTIFY_ROOM_CURRENT)) ) { - Jid *jidp = jid_create(roomjid); - if (prefs_get_boolean(PREF_NOTIFY_ROOM_TEXT)) { - notify_room_message(nick, jidp->localpart, ui_index, message); - } else { - notify_room_message(nick, jidp->localpart, ui_index, NULL); - } - jid_destroy(jidp); - } + notify_room_message(nick, jidp->localpart, ui_index, NULL); } + jid_destroy(jidp); } } } From 882ca85aca1a7887dcf571385a16be70679d2387 Mon Sep 17 00:00:00 2001 From: Adam Ehlers Nyholm Thomsen Date: Sun, 17 May 2015 13:29:08 +0200 Subject: [PATCH 249/252] allow enabling / disabling carbons without being connected. --- src/command/commands.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index 0c341880..b942acd4 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -3980,23 +3980,21 @@ cmd_history(gchar **args, struct cmd_help_t help) gboolean cmd_carbons(gchar **args, struct cmd_help_t help) { - jabber_conn_status_t conn_status = jabber_get_connection_status(); - - if (conn_status != JABBER_CONNECTED) { - cons_show("You are not currently connected."); - return TRUE; - } - gboolean result = _cmd_set_boolean_preference(args[0], help, "Message carbons preference", PREF_CARBONS); - // enable carbons - if (strcmp(args[0], "on") == 0) { - iq_enable_carbons(); - } - else if (strcmp(args[0], "off") == 0){ - iq_disable_carbons(); + jabber_conn_status_t conn_status = jabber_get_connection_status(); + + if (conn_status == JABBER_CONNECTED) { + // enable carbons + if (strcmp(args[0], "on") == 0) { + iq_enable_carbons(); + } + else if (strcmp(args[0], "off") == 0){ + iq_disable_carbons(); + } } + return result; } @@ -4411,4 +4409,4 @@ gint _compare_commands(Command *a, Command *b) g_free(key_b); return result; -} \ No newline at end of file +} From 7eab35f353118d9ec8aca730adb7e105aae0fbfe Mon Sep 17 00:00:00 2001 From: Pete Maynard Date: Mon, 18 May 2015 14:15:02 +0100 Subject: [PATCH 250/252] Udpate installer.sh for Debain to unclude uuid-dev --- install-all.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install-all.sh b/install-all.sh index a054e166..af59fa0b 100755 --- a/install-all.sh +++ b/install-all.sh @@ -24,7 +24,7 @@ debian_prepare() echo echo Profanity installer... installing dependencies echo - sudo apt-get -y install git automake autoconf libssl-dev libexpat1-dev libncursesw5-dev libglib2.0-dev libnotify-dev libcurl3-dev libxss-dev libotr5-dev libreadline-dev libtool + sudo apt-get -y install git automake autoconf libssl-dev libexpat1-dev libncursesw5-dev libglib2.0-dev libnotify-dev libcurl3-dev libxss-dev libotr5-dev libreadline-dev libtool uuid-dev } From e5c14b9b8030c381439bfb26f609660bc08e38a8 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 19 May 2015 22:42:16 +0100 Subject: [PATCH 251/252] Added uuid dependency to install-all.sh, opensuse, fedora and cygwin --- install-all.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/install-all.sh b/install-all.sh index af59fa0b..4ffc5999 100755 --- a/install-all.sh +++ b/install-all.sh @@ -36,7 +36,7 @@ fedora_prepare() ARCH=`arch` - sudo yum -y install gcc git autoconf automake openssl-devel.$ARCH expat-devel.$ARCH ncurses-devel.$ARCH glib2-devel.$ARCH libnotify-devel.$ARCH libcurl-devel.$ARCH libXScrnSaver-devel.$ARCH libotr3-devel.$ARCH readline-devel.$ARCH libtool + sudo yum -y install gcc git autoconf automake openssl-devel.$ARCH expat-devel.$ARCH ncurses-devel.$ARCH glib2-devel.$ARCH libnotify-devel.$ARCH libcurl-devel.$ARCH libXScrnSaver-devel.$ARCH libotr3-devel.$ARCH readline-devel.$ARCH libtool uuid-devel.$ARCH } opensuse_prepare() @@ -44,7 +44,7 @@ opensuse_prepare() echo echo Profanity installer...installing dependencies echo - sudo zypper -n in gcc git automake make autoconf libopenssl-devel expat libexpat-devel ncurses-devel glib2-devel libnotify-devel libcurl-devel libXScrnSaver-devel libotr-devel readline-devel libtool + sudo zypper -n in gcc git automake make autoconf libopenssl-devel expat libexpat-devel ncurses-devel glib2-devel libnotify-devel libcurl-devel libXScrnSaver-devel libotr-devel readline-devel libtool libuuid-devel } cygwin_prepare() @@ -60,9 +60,9 @@ cygwin_prepare() mv apt-cyg /usr/local/bin/ if [ -n "$CYG_MIRROR" ]; then - apt-cyg -m $CYG_MIRROR install git make gcc-core m4 automake autoconf pkg-config openssl-devel libexpat-devel zlib-devel libncursesw-devel libglib2.0-devel libcurl-devel libidn-devel libssh2-devel libkrb5-devel openldap-devel libgcrypt-devel libreadline-devel libtool + apt-cyg -m $CYG_MIRROR install git make gcc-core m4 automake autoconf pkg-config openssl-devel libexpat-devel zlib-devel libncursesw-devel libglib2.0-devel libcurl-devel libidn-devel libssh2-devel libkrb5-devel openldap-devel libgcrypt-devel libreadline-devel libtool libuuid-devel else - apt-cyg install git make gcc-core m4 automake autoconf pkg-config openssl-devel libexpat-devel zlib-devel libncursesw-devel libglib2.0-devel libcurl-devel libidn-devel libssh2-devel libkrb5-devel openldap-devel libgcrypt-devel libreadline-devel libtool + apt-cyg install git make gcc-core m4 automake autoconf pkg-config openssl-devel libexpat-devel zlib-devel libncursesw-devel libglib2.0-devel libcurl-devel libidn-devel libssh2-devel libkrb5-devel openldap-devel libgcrypt-devel libreadline-devel libtool libuuid-devel fi } From 304e08a9c0bfa27ed84dc1ff0a2e2d32b36529f8 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 25 May 2015 21:16:10 +0100 Subject: [PATCH 252/252] Added jid to OTR errors in console --- src/ui/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ui/core.c b/src/ui/core.c index 2c797271..e7059ef0 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -1046,7 +1046,7 @@ ui_handle_otr_error(const char * const barejid, const char * const message) if (chatwin) { win_print((ProfWin*)chatwin, '!', NULL, 0, THEME_ERROR, "", message); } else { - cons_show_error(message); + cons_show_error("%s - %s", barejid, message); } }