annotate nnchat.c @ 264:4c1c18a388d9

Add configuration setting and functionality for random "keepalive" messages to avoid idle timeout kicks from chat.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 03 Jun 2011 11:18:19 +0300
parents 8a0f7446318e
children b9c650db8a6a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
41
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
1 /*
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
2 * NNChat - Custom chat client for NewbieNudes.com chatrooms
39
Matti Hamalainen <ccr@tnsp.org>
parents: 36
diff changeset
3 * Written by Matti 'ccr' Hämäläinen
237
52a2f06fd41c Update copyright years.
Matti Hamalainen <ccr@tnsp.org>
parents: 236
diff changeset
4 * (C) Copyright 2008-2011 Tecnic Software productions (TNSP)
39
Matti Hamalainen <ccr@tnsp.org>
parents: 36
diff changeset
5 */
62
ff5d74f0d428 Moved some functions to "libnnchat".
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
6 #include "libnnchat.h"
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 #include <stdlib.h>
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 #include "th_args.h"
133
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
9 #include "th_config.h"
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10 #include <string.h>
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11 #include <errno.h>
64
6a3a917303e4 Some random cleanups, bring back WinSock support.
Matti Hamalainen <ccr@tnsp.org>
parents: 63
diff changeset
12 #ifdef __WIN32
68
3ab7751fdad1 MingW compatibility, with one ugly kludge.
Matti Hamalainen <ccr@tnsp.org>
parents: 67
diff changeset
13 /* Undefine because both windows.h and curses.h #define it */
3ab7751fdad1 MingW compatibility, with one ugly kludge.
Matti Hamalainen <ccr@tnsp.org>
parents: 67
diff changeset
14 #undef MOUSE_MOVED
154
e8f67e344aaf Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
15 #include <shlwapi.h>
128
713879a7ca10 Wait for forked processes, to prevent a zombie apocalypse.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
16 #else
713879a7ca10 Wait for forked processes, to prevent a zombie apocalypse.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
17 #include <sys/wait.h>
68
3ab7751fdad1 MingW compatibility, with one ugly kludge.
Matti Hamalainen <ccr@tnsp.org>
parents: 67
diff changeset
18 #endif
217
7ba4e371e9a6 Add Makefile for OpenBSD, and specific #ifdef'd includes for the platform.
Matti Hamalainen <ccr@tnsp.org>
parents: 216
diff changeset
19 #ifdef HAVE_NCURSES_H
7ba4e371e9a6 Add Makefile for OpenBSD, and specific #ifdef'd includes for the platform.
Matti Hamalainen <ccr@tnsp.org>
parents: 216
diff changeset
20 #include <ncurses.h>
7ba4e371e9a6 Add Makefile for OpenBSD, and specific #ifdef'd includes for the platform.
Matti Hamalainen <ccr@tnsp.org>
parents: 216
diff changeset
21 #else
64
6a3a917303e4 Some random cleanups, bring back WinSock support.
Matti Hamalainen <ccr@tnsp.org>
parents: 63
diff changeset
22 #include <curses.h>
217
7ba4e371e9a6 Add Makefile for OpenBSD, and specific #ifdef'd includes for the platform.
Matti Hamalainen <ccr@tnsp.org>
parents: 216
diff changeset
23 #endif
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24
139
c39399725f7b Define some platform-specific constants.
Matti Hamalainen <ccr@tnsp.org>
parents: 137
diff changeset
25 #ifdef __WIN32
160
d3c78f2ef77b Rename configuration file for Windows.
Matti Hamalainen <ccr@tnsp.org>
parents: 156
diff changeset
26 #define SET_CONFIG_FILE "nnchat.txt"
139
c39399725f7b Define some platform-specific constants.
Matti Hamalainen <ccr@tnsp.org>
parents: 137
diff changeset
27 #define SET_DIR_SEPARATOR "\\"
210
4554f9abc686 Change timeout() value for PDCurses/Windows to 0 to improve responsivity.
Matti Hamalainen <ccr@tnsp.org>
parents: 209
diff changeset
28 #define SET_DELAY (0)
139
c39399725f7b Define some platform-specific constants.
Matti Hamalainen <ccr@tnsp.org>
parents: 137
diff changeset
29 #else
c39399725f7b Define some platform-specific constants.
Matti Hamalainen <ccr@tnsp.org>
parents: 137
diff changeset
30 #define SET_CONFIG_FILE ".nnchat"
c39399725f7b Define some platform-specific constants.
Matti Hamalainen <ccr@tnsp.org>
parents: 137
diff changeset
31 #define SET_DIR_SEPARATOR "/"
228
744c277b57cf Change timeout delay to lower value.
Matti Hamalainen <ccr@tnsp.org>
parents: 226
diff changeset
32 #define SET_DELAY (5)
139
c39399725f7b Define some platform-specific constants.
Matti Hamalainen <ccr@tnsp.org>
parents: 137
diff changeset
33 #endif
49
0bcc38910a77 Simple ringbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
34
230
b64500bb7fbe Some yet-unused backbuffer related code.
Matti Hamalainen <ccr@tnsp.org>
parents: 229
diff changeset
35 /* Define the weak "encryption" key used for locally stored passwords.
b64500bb7fbe Some yet-unused backbuffer related code.
Matti Hamalainen <ccr@tnsp.org>
parents: 229
diff changeset
36 * This has no other purpose than to obfuscate keys in configuration
b64500bb7fbe Some yet-unused backbuffer related code.
Matti Hamalainen <ccr@tnsp.org>
parents: 229
diff changeset
37 * file(s) from casual observers. In NO WAY this can be seen as a
b64500bb7fbe Some yet-unused backbuffer related code.
Matti Hamalainen <ccr@tnsp.org>
parents: 229
diff changeset
38 * true security measure!
b64500bb7fbe Some yet-unused backbuffer related code.
Matti Hamalainen <ccr@tnsp.org>
parents: 229
diff changeset
39 */
b64500bb7fbe Some yet-unused backbuffer related code.
Matti Hamalainen <ccr@tnsp.org>
parents: 229
diff changeset
40 #define SET_ENC_KEY "1a#!sCbZxcGj0a04hBz&S"
b64500bb7fbe Some yet-unused backbuffer related code.
Matti Hamalainen <ccr@tnsp.org>
parents: 229
diff changeset
41
b64500bb7fbe Some yet-unused backbuffer related code.
Matti Hamalainen <ccr@tnsp.org>
parents: 229
diff changeset
42 #define SET_BACKBUF_LEN (512) /* Backbuffer size (in lines) */
141
cce05daf6f01 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
43 #define SET_MAX_HISTORY (16) /* Command history length */
96
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
44 #define SET_KEEPALIVE (15*60) /* Ping/keepalive period in seconds */
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45
49
0bcc38910a77 Simple ringbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
46
264
4c1c18a388d9 Add configuration setting and functionality for random "keepalive" messages to avoid idle timeout kicks from chat.
Matti Hamalainen <ccr@tnsp.org>
parents: 258
diff changeset
47
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48 /* Options
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49 */
254
269135d58acd Change default port to 8005 (new main room).
Matti Hamalainen <ccr@tnsp.org>
parents: 252
diff changeset
50 int optPort = 8005;
207
e0c085426b91 Change default user color to black (#000000).
Matti Hamalainen <ccr@tnsp.org>
parents: 206
diff changeset
51 int optUserColor = 0x000000;
96
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
52 char *optServer = "chat.newbienudes.com",
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
53 *optUserName = NULL,
198
21a37995c3fb Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents: 197
diff changeset
54 *optUserNameCmd = NULL,
21a37995c3fb Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents: 197
diff changeset
55 *optUserNameEnc = NULL,
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
56 *optPassword = NULL,
198
21a37995c3fb Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents: 197
diff changeset
57 *optPasswordCmd = NULL,
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
58 *optLogFilename = NULL,
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
59 *setTarget = NULL,
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
60 *optSite = "NN";
116
741e45592522 Add simple "prediction" into tab-completion based on previously gotten last
Matti Hamalainen <ccr@tnsp.org>
parents: 115
diff changeset
61 char optNickSep = ':';
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
62 BOOL optDaemon = FALSE;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
63 FILE *optLogFile = NULL;
28
512775f6b081 A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
64 WINDOW *mainWin = NULL,
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
65 *statusWin = NULL,
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
66 *editWin = NULL;
59
d57a8acf92bf Remove morse code mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
67 BOOL setPrvMode = FALSE;
258
8a0f7446318e General cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 254
diff changeset
68 BOOL setIgnoreMode = FALSE;
162
e59cec397811 Add a debug mode option (commandline) and enable certain features when we are in debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
69 BOOL optDebug = FALSE;
242
cb86d7543be2 Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
70 BOOL optLogEnable = FALSE;
140
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
71
264
4c1c18a388d9 Add configuration setting and functionality for random "keepalive" messages to avoid idle timeout kicks from chat.
Matti Hamalainen <ccr@tnsp.org>
parents: 258
diff changeset
72 qlist_t *nnIgnoreList = NULL,
4c1c18a388d9 Add configuration setting and functionality for random "keepalive" messages to avoid idle timeout kicks from chat.
Matti Hamalainen <ccr@tnsp.org>
parents: 258
diff changeset
73 *setIdleMessages = NULL;
140
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
74 nn_userhash_t *nnUsers = NULL;
137
fad8c31e41e6 Move browser code around a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
75 char *setConfigFile = NULL,
fad8c31e41e6 Move browser code around a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
76 *setBrowser = NULL;
133
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
77 cfgitem_t *cfg = NULL;
230
b64500bb7fbe Some yet-unused backbuffer related code.
Matti Hamalainen <ccr@tnsp.org>
parents: 229
diff changeset
78 nn_ringbuf_t *backBuf = NULL;
89
c2d916b340bf Change some typedef names; Add struct for user list handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
79
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80 /* Arguments
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81 */
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82 optarg_t optList[] = {
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
83 { 0, '?', "help", "Show this help", OPT_NONE },
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
84 { 1, 'v', "verbose", "Be more verbose", OPT_NONE },
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
85 { 2, 'p', "port", "Connect to port", OPT_ARGREQ },
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
86 { 3, 's', "server", "Server to connect to", OPT_ARGREQ },
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
87 { 4, 'C', "color", "Initial color in RGB hex 000000", OPT_ARGREQ },
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
88 { 5, 'l', "logfile", "Log filename", OPT_ARGREQ },
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
89 { 6, 'D', "daemon", "A pseudo-daemon mode for logging", OPT_NONE },
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
90 { 7, 'S', "site", "Site (default: NN)", OPT_ARGREQ },
162
e59cec397811 Add a debug mode option (commandline) and enable certain features when we are in debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
91 { 8, 'd', "debug", "Enable various debug features", OPT_NONE },
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92 };
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93
43
40ba8cdcf03a Cleanups, added a silly morse code conversion mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
94 const int optListN = (sizeof(optList) / sizeof(optList[0]));
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
95
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96
258
8a0f7446318e General cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 254
diff changeset
97 void argShowHelp(void)
68
3ab7751fdad1 MingW compatibility, with one ugly kludge.
Matti Hamalainen <ccr@tnsp.org>
parents: 67
diff changeset
98 {
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
99 th_args_help(stdout, optList, optListN, th_prog_name,
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
100 "[options] <username> <password>");
68
3ab7751fdad1 MingW compatibility, with one ugly kludge.
Matti Hamalainen <ccr@tnsp.org>
parents: 67
diff changeset
101 }
3ab7751fdad1 MingW compatibility, with one ugly kludge.
Matti Hamalainen <ccr@tnsp.org>
parents: 67
diff changeset
102
3ab7751fdad1 MingW compatibility, with one ugly kludge.
Matti Hamalainen <ccr@tnsp.org>
parents: 67
diff changeset
103
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
104 BOOL argHandleOpt(const int optN, char *optArg, char *currArg)
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
105 {
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
106 switch (optN) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
107 case 0:
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
108 argShowHelp();
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
109 exit(0);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
110 break;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
111
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
112 case 1:
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
113 th_verbosityLevel++;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
114 break;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
115
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
116 case 2:
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
117 optPort = atoi(optArg);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
118 break;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
119
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
120 case 3:
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
121 optServer = optArg;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
122 break;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
123
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
124 case 4:
132
10daf4660cae Use th_get_hex_triplet().
Matti Hamalainen <ccr@tnsp.org>
parents: 130
diff changeset
125 if ((optUserColor = th_get_hex_triplet(optArg)) < 0) {
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
126 THERR("Invalid color argument '%s', should be a RGB hex triplet '000000'.\n",
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
127 optArg);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
128 return FALSE;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
129 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
130 THMSG(1, "Using color #%06x\n", optUserColor);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
131 break;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
132
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
133 case 5:
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
134 optLogFilename = optArg;
242
cb86d7543be2 Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
135 optLogEnable = TRUE;
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
136 break;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
137
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
138 case 7:
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
139 optSite = optArg;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
140 break;
33
e49ea6febfeb Cleanups. Added option to specify/fake "site" where logging in from.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
141
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
142 case 6:
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
143 optDaemon = TRUE;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
144 THMSG(1, "Running in pseudo-daemon mode.\n");
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
145 break;
21
29098addfa65 Added a "daemon" mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
146
162
e59cec397811 Add a debug mode option (commandline) and enable certain features when we are in debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
147 case 8:
e59cec397811 Add a debug mode option (commandline) and enable certain features when we are in debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
148 optDebug = TRUE;
e59cec397811 Add a debug mode option (commandline) and enable certain features when we are in debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
149 THMSG(1, "Debug mode enabled.\n");
e59cec397811 Add a debug mode option (commandline) and enable certain features when we are in debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
150 break;
e59cec397811 Add a debug mode option (commandline) and enable certain features when we are in debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
151
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
152 default:
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
153 THERR("Unknown option '%s'.\n", currArg);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
154 return FALSE;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
155 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
156
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
157 return TRUE;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
158 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
159
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
160
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
161 BOOL argHandleFile(char *currArg)
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
162 {
198
21a37995c3fb Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents: 197
diff changeset
163 if (!optUserNameCmd)
21a37995c3fb Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents: 197
diff changeset
164 optUserNameCmd = currArg;
21a37995c3fb Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents: 197
diff changeset
165 else if (!optPasswordCmd)
21a37995c3fb Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents: 197
diff changeset
166 optPasswordCmd = currArg;
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
167 else {
198
21a37995c3fb Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents: 197
diff changeset
168 THERR("Username '%s' already specified on commandline!\n", optUserNameCmd);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
169 return FALSE;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
170 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
171
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
172 return TRUE;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
173 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
174
156
0a9fe14882dc Introduce utility function getTimeStamp() and use it to lessen code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 155
diff changeset
175 BOOL getTimeStamp(char *str, size_t len, const char *fmt)
0a9fe14882dc Introduce utility function getTimeStamp() and use it to lessen code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 155
diff changeset
176 {
0a9fe14882dc Introduce utility function getTimeStamp() and use it to lessen code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 155
diff changeset
177 time_t stamp = time(NULL);
0a9fe14882dc Introduce utility function getTimeStamp() and use it to lessen code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 155
diff changeset
178 struct tm *stamp_tm;
0a9fe14882dc Introduce utility function getTimeStamp() and use it to lessen code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 155
diff changeset
179 if ((stamp_tm = localtime(&stamp)) != NULL) {
0a9fe14882dc Introduce utility function getTimeStamp() and use it to lessen code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 155
diff changeset
180 strftime(str, len, fmt, stamp_tm);
0a9fe14882dc Introduce utility function getTimeStamp() and use it to lessen code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 155
diff changeset
181 return TRUE;
0a9fe14882dc Introduce utility function getTimeStamp() and use it to lessen code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 155
diff changeset
182 } else {
0a9fe14882dc Introduce utility function getTimeStamp() and use it to lessen code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 155
diff changeset
183 str[0] = 0;
0a9fe14882dc Introduce utility function getTimeStamp() and use it to lessen code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 155
diff changeset
184 return FALSE;
0a9fe14882dc Introduce utility function getTimeStamp() and use it to lessen code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 155
diff changeset
185 }
0a9fe14882dc Introduce utility function getTimeStamp() and use it to lessen code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 155
diff changeset
186 }
49
0bcc38910a77 Simple ringbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
187
226
f25d47398326 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 225
diff changeset
188
191
4007b9ac7cde Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents: 190
diff changeset
189 char *encodeUsername(char *str)
4007b9ac7cde Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents: 190
diff changeset
190 {
4007b9ac7cde Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents: 190
diff changeset
191 unsigned char *c = (unsigned char *) str;
4007b9ac7cde Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents: 190
diff changeset
192 if (str == NULL) return NULL;
4007b9ac7cde Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents: 190
diff changeset
193 for (; *c ; c++)
4007b9ac7cde Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents: 190
diff changeset
194 if (*c == ' ') *c = 255;
4007b9ac7cde Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents: 190
diff changeset
195 return str;
4007b9ac7cde Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents: 190
diff changeset
196 }
4007b9ac7cde Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents: 190
diff changeset
197
258
8a0f7446318e General cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 254
diff changeset
198
191
4007b9ac7cde Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents: 190
diff changeset
199 char *decodeUsername(char *str)
4007b9ac7cde Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents: 190
diff changeset
200 {
4007b9ac7cde Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents: 190
diff changeset
201 unsigned char *c = (unsigned char *) str;
4007b9ac7cde Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents: 190
diff changeset
202 if (str == NULL) return NULL;
4007b9ac7cde Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents: 190
diff changeset
203 for (; *c ; c++)
4007b9ac7cde Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents: 190
diff changeset
204 if (*c == 255) *c = ' ';
4007b9ac7cde Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents: 190
diff changeset
205 return str;
4007b9ac7cde Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents: 190
diff changeset
206 }
4007b9ac7cde Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents: 190
diff changeset
207
258
8a0f7446318e General cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 254
diff changeset
208
30
Matti Hamalainen <ccr@tnsp.org>
parents: 29
diff changeset
209 void updateStatus(BOOL insertMode)
28
512775f6b081 A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
210 {
156
0a9fe14882dc Introduce utility function getTimeStamp() and use it to lessen code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 155
diff changeset
211 char tmpStr[128];
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
212
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
213 if (statusWin == NULL) return;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
214
156
0a9fe14882dc Introduce utility function getTimeStamp() and use it to lessen code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 155
diff changeset
215 getTimeStamp(tmpStr, sizeof(tmpStr), "%H:%M:%S");
110
8af4072dc31a Fix Win32/MinGW/PDcurses issues.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
216
119
4bc63a535acb Fix some PDCurses incompatibilities and remove some Win32/PDCurses specific hacks.
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
217 wbkgdset(statusWin, COLOR_PAIR(10));
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
218 werase(statusWin);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
219
119
4bc63a535acb Fix some PDCurses incompatibilities and remove some Win32/PDCurses specific hacks.
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
220 wattrset(statusWin, A_BOLD | COLOR_PAIR(11));
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
221 mvwaddstr(statusWin, 0, 1, tmpStr);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
222
119
4bc63a535acb Fix some PDCurses incompatibilities and remove some Win32/PDCurses specific hacks.
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
223 wattrset(statusWin, A_BOLD | COLOR_PAIR(13));
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
224 waddstr(statusWin, " | ");
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
225 wattrset(statusWin, A_BOLD | COLOR_PAIR(16));
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
226 waddstr(statusWin, optUserName);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
227 wattrset(statusWin, A_BOLD | COLOR_PAIR(13));
29
a27ef0e359b9 Make statusline more informative.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
228
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
229 waddstr(statusWin, " | ");
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
230 wattrset(statusWin, A_BOLD | COLOR_PAIR(11));
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
231 waddstr(statusWin, insertMode ? "INS" : "DEL");
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
232
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
233 wattrset(statusWin, A_BOLD | COLOR_PAIR(13));
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
234 waddstr(statusWin, " | Prv: ");
28
512775f6b081 A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
235
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
236 wattrset(statusWin, A_BOLD | COLOR_PAIR(11));
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
237 waddstr(statusWin, setTarget != NULL ? setTarget : "-");
29
a27ef0e359b9 Make statusline more informative.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
238
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
239 wattrset(statusWin, A_BOLD | COLOR_PAIR(13));
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
240 waddstr(statusWin, " | P/C: ");
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
241 wattrset(statusWin, A_BOLD | COLOR_PAIR(11));
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
242 snprintf(tmpStr, sizeof(tmpStr), "%d / #%06x", optPort, optUserColor);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
243 waddstr(statusWin, tmpStr);
29
a27ef0e359b9 Make statusline more informative.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
244
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
245 wrefresh(statusWin);
28
512775f6b081 A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
246 }
512775f6b081 A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
247
161
6dd282b5f431 Constify.
Matti Hamalainen <ccr@tnsp.org>
parents: 160
diff changeset
248 void printEditBuf(const char *str, nn_editbuf_t *buf)
28
512775f6b081 A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
249 {
191
4007b9ac7cde Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents: 190
diff changeset
250 char *tmp;
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
251 if (statusWin == NULL || buf == NULL) return;
32
67ec4073e38c Check for NULL pointers (fixes "daemon" mode)
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
252
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
253 buf->data[buf->len] = 0;
191
4007b9ac7cde Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents: 190
diff changeset
254 tmp = decodeUsername(th_strdup(buf->data));
4007b9ac7cde Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents: 190
diff changeset
255
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
256 werase(editWin);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
257
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
258 wattrset(editWin, A_BOLD);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
259 mvwaddstr(editWin, 0, 0, str);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
260 waddstr(editWin, "> ");
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
261 wattrset(editWin, A_NORMAL);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
262
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
263 if (buf->pos < buf->len) {
191
4007b9ac7cde Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents: 190
diff changeset
264 waddnstr(editWin, tmp, buf->pos);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
265 wattrset(editWin, A_REVERSE);
191
4007b9ac7cde Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents: 190
diff changeset
266 waddch(editWin, tmp[buf->pos]);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
267 wattrset(editWin, A_NORMAL);
191
4007b9ac7cde Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents: 190
diff changeset
268 waddnstr(editWin, tmp + buf->pos + 1, buf->len - buf->pos - 1);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
269 } else {
191
4007b9ac7cde Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents: 190
diff changeset
270 waddnstr(editWin, tmp, buf->len);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
271 wattrset(editWin, A_REVERSE);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
272 waddch(editWin, ' ');
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
273 wattrset(editWin, A_NORMAL);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
274 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
275 wrefresh(editWin);
191
4007b9ac7cde Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents: 190
diff changeset
276 th_free(tmp);
28
512775f6b081 A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
277 }
512775f6b081 A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
278
226
f25d47398326 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 225
diff changeset
279
28
512775f6b081 A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
280 int printWin(WINDOW *win, const char *fmt)
512775f6b081 A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
281 {
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
282 const char *s = fmt;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
283 int col = 0;
141
cce05daf6f01 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
284
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
285 while (*s) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
286 if (*s == '½') {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
287 int val = 0;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
288 s++;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
289 if (*s == '½') {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
290 waddch(win, ((unsigned char) *s) | col);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
291 s++;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
292 } else {
110
8af4072dc31a Fix Win32/MinGW/PDcurses issues.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
293 while (*s >= '0' && *s <= '9') {
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
294 val *= 10;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
295 val += (*s - '0');
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
296 s++;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
297 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
298 if (*s != '½') return -1;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
299 s++;
191
4007b9ac7cde Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents: 190
diff changeset
300
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
301 if (val < 9) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
302 col = A_DIM | COLOR_PAIR(val);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
303 } else if (val < 30) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
304 col = A_BOLD | COLOR_PAIR(val - 9);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
305 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
306 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
307 } else {
191
4007b9ac7cde Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents: 190
diff changeset
308 if ((unsigned char) *s == 255)
4007b9ac7cde Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents: 190
diff changeset
309 waddch(win, ((unsigned char) ' ') | col);
4007b9ac7cde Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents: 190
diff changeset
310 else
110
8af4072dc31a Fix Win32/MinGW/PDcurses issues.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
311 if (*s != '\r')
121
dad765129133 Remove #ifdef __WIN32 around non-win32 specific code.
Matti Hamalainen <ccr@tnsp.org>
parents: 120
diff changeset
312 waddch(win, ((unsigned char) *s) | col);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
313 s++;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
314 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
315 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
316 return 0;
28
512775f6b081 A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
317 }
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
318
62
ff5d74f0d428 Moved some functions to "libnnchat".
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
319
28
512775f6b081 A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
320 int printFile(FILE *outFile, const char *fmt)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
321 {
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
322 const char *s = fmt;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
323
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
324 while (*s) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
325 if (*s == '½') {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
326 s++;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
327 if (*s == '½') {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
328 fputc((unsigned char) *s, outFile);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
329 s++;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
330 } else {
74
98004129202a Portability fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
331 while (*s && isdigit((int) *s)) s++;
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
332 if (*s != '½') return -1;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
333 s++;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
334 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
335 } else {
191
4007b9ac7cde Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents: 190
diff changeset
336 if ((unsigned char) *s == 255)
4007b9ac7cde Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents: 190
diff changeset
337 fputc(' ', outFile);
4007b9ac7cde Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents: 190
diff changeset
338 else
4007b9ac7cde Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents: 190
diff changeset
339 fputc((unsigned char) *s, outFile);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
340 s++;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
341 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
342 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
343
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
344 return 0;
28
512775f6b081 A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
345 }
512775f6b081 A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
346
62
ff5d74f0d428 Moved some functions to "libnnchat".
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
347
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
348 void printMsgV(BOOL addStamp, BOOL logOnly, const char *fmt, va_list ap)
28
512775f6b081 A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
349 {
156
0a9fe14882dc Introduce utility function getTimeStamp() and use it to lessen code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 155
diff changeset
350 char tmpStr[128], buf[8192];
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
351
156
0a9fe14882dc Introduce utility function getTimeStamp() and use it to lessen code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 155
diff changeset
352 getTimeStamp(tmpStr, sizeof(tmpStr), "½17½[½11½%H:%M:%S½17½]½0½ ");
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
353
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
354 vsnprintf(buf, sizeof(buf), fmt, ap);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
355
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
356 if (optLogFile) {
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
357 if (addStamp) printFile(optLogFile, tmpStr);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
358 printFile(optLogFile, buf);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
359 fflush(optLogFile);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
360 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
361
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
362 if (!optDaemon && !logOnly) {
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
363 if (addStamp) printWin(mainWin, tmpStr);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
364 printWin(mainWin, buf);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
365 wrefresh(mainWin);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
366 }
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
367 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
368
100
ed4067c10a8a Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
369 void printMsg(const char *fmt, ...)
ed4067c10a8a Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
370 {
ed4067c10a8a Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
371 va_list ap;
ed4067c10a8a Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
372
ed4067c10a8a Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
373 va_start(ap, fmt);
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
374 printMsgV(TRUE, FALSE, fmt, ap);
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
375 va_end(ap);
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
376 }
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
377
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
378 void printMsgC(const char *fmt, ...)
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
379 {
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
380 va_list ap;
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
381
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
382 va_start(ap, fmt);
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
383 printMsgV(FALSE, FALSE, fmt, ap);
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
384 va_end(ap);
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
385 }
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
386
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
387 void printMsgQ(BOOL logOnly, const char *fmt, ...)
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
388 {
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
389 va_list ap;
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
390
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
391 va_start(ap, fmt);
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
392 printMsgV(TRUE, logOnly, fmt, ap);
100
ed4067c10a8a Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
393 va_end(ap);
ed4067c10a8a Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
394 }
ed4067c10a8a Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
395
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
396
223
03af28fb1c38 Show error messages printed out to stderr only after the program has quit.
Matti Hamalainen <ccr@tnsp.org>
parents: 222
diff changeset
397 char *errorMessages = NULL;
03af28fb1c38 Show error messages printed out to stderr only after the program has quit.
Matti Hamalainen <ccr@tnsp.org>
parents: 222
diff changeset
398
236
71fa0364c058 Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
399 void errorMsgV(const char *fmt, va_list ap)
96
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
400 {
223
03af28fb1c38 Show error messages printed out to stderr only after the program has quit.
Matti Hamalainen <ccr@tnsp.org>
parents: 222
diff changeset
401 char *tmp;
236
71fa0364c058 Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
402 va_list ap2;
96
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
403
236
71fa0364c058 Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
404 va_copy(ap2, ap);
71fa0364c058 Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
405 printMsgV(TRUE, FALSE, fmt, ap);
96
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
406
223
03af28fb1c38 Show error messages printed out to stderr only after the program has quit.
Matti Hamalainen <ccr@tnsp.org>
parents: 222
diff changeset
407 tmp = th_strdup_vprintf(fmt, ap2);
03af28fb1c38 Show error messages printed out to stderr only after the program has quit.
Matti Hamalainen <ccr@tnsp.org>
parents: 222
diff changeset
408
03af28fb1c38 Show error messages printed out to stderr only after the program has quit.
Matti Hamalainen <ccr@tnsp.org>
parents: 222
diff changeset
409 if (errorMessages != NULL) {
03af28fb1c38 Show error messages printed out to stderr only after the program has quit.
Matti Hamalainen <ccr@tnsp.org>
parents: 222
diff changeset
410 char *tmp2 = th_strdup_printf("%s%s", errorMessages, tmp);
03af28fb1c38 Show error messages printed out to stderr only after the program has quit.
Matti Hamalainen <ccr@tnsp.org>
parents: 222
diff changeset
411 th_free(errorMessages);
03af28fb1c38 Show error messages printed out to stderr only after the program has quit.
Matti Hamalainen <ccr@tnsp.org>
parents: 222
diff changeset
412 th_free(tmp);
03af28fb1c38 Show error messages printed out to stderr only after the program has quit.
Matti Hamalainen <ccr@tnsp.org>
parents: 222
diff changeset
413 errorMessages = tmp2;
03af28fb1c38 Show error messages printed out to stderr only after the program has quit.
Matti Hamalainen <ccr@tnsp.org>
parents: 222
diff changeset
414 } else
03af28fb1c38 Show error messages printed out to stderr only after the program has quit.
Matti Hamalainen <ccr@tnsp.org>
parents: 222
diff changeset
415 errorMessages = tmp;
96
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
416 }
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
417
236
71fa0364c058 Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
418 void errorMsg(const char *fmt, ...)
71fa0364c058 Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
419 {
71fa0364c058 Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
420 va_list ap;
71fa0364c058 Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
421
71fa0364c058 Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
422 va_start(ap, fmt);
71fa0364c058 Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
423 errorMsgV(fmt, ap);
71fa0364c058 Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
424 va_end(ap);
71fa0364c058 Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
425 }
71fa0364c058 Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
426
71fa0364c058 Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
427 void errorFunc(struct _nn_conn_t *conn, const char *fmt, va_list ap)
71fa0364c058 Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
428 {
71fa0364c058 Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
429 errorMsgV(fmt, ap);
71fa0364c058 Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
430 }
71fa0364c058 Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
431
71fa0364c058 Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
432 void messageFunc(struct _nn_conn_t *conn, const char *fmt, va_list ap)
71fa0364c058 Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
433 {
71fa0364c058 Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
434 printMsgV(TRUE, FALSE, fmt, ap);
71fa0364c058 Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
435 }
71fa0364c058 Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
436
225
801ac37321f6 Sanitize ignore handling; Also action messages and PRVs were not being properly ignored, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
437
801ac37321f6 Sanitize ignore handling; Also action messages and PRVs were not being properly ignored, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
438 BOOL checkIgnoreList(const char *name)
801ac37321f6 Sanitize ignore handling; Also action messages and PRVs were not being properly ignored, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
439 {
801ac37321f6 Sanitize ignore handling; Also action messages and PRVs were not being properly ignored, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
440 qlist_t *node = nnIgnoreList;
801ac37321f6 Sanitize ignore handling; Also action messages and PRVs were not being properly ignored, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
441 while (node != NULL) {
801ac37321f6 Sanitize ignore handling; Also action messages and PRVs were not being properly ignored, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
442 if (strcasecmp(name, (char *) node->data) == 0)
801ac37321f6 Sanitize ignore handling; Also action messages and PRVs were not being properly ignored, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
443 return TRUE;
801ac37321f6 Sanitize ignore handling; Also action messages and PRVs were not being properly ignored, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
444 node = node->next;
801ac37321f6 Sanitize ignore handling; Also action messages and PRVs were not being properly ignored, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
445 }
801ac37321f6 Sanitize ignore handling; Also action messages and PRVs were not being properly ignored, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
446 return FALSE;
801ac37321f6 Sanitize ignore handling; Also action messages and PRVs were not being properly ignored, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
447 }
801ac37321f6 Sanitize ignore handling; Also action messages and PRVs were not being properly ignored, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
448
801ac37321f6 Sanitize ignore handling; Also action messages and PRVs were not being properly ignored, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
449
168
2e4850ece456 Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 165
diff changeset
450 int handleUser(nn_conn_t *conn, const char *str)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
451 {
108
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
452 const char *msg = "</USER><MESSAGE>", *p = str;
229
08d4355d6fc9 Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents: 228
diff changeset
453 BOOL isMine, isIgnored = FALSE;
08d4355d6fc9 Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents: 228
diff changeset
454 char *s, *t, *h, *userName;
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
455
168
2e4850ece456 Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 165
diff changeset
456 (void) conn;
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
457
229
08d4355d6fc9 Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents: 228
diff changeset
458 /* Find start of the message */
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
459 s = strstr(str, msg);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
460 if (!s) return 1;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
461 *s = 0;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
462 s += strlen(msg);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
463
229
08d4355d6fc9 Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents: 228
diff changeset
464 /* Find end of the message */
08d4355d6fc9 Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents: 228
diff changeset
465 t = strstr(s, "</MESSAGE>");
08d4355d6fc9 Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents: 228
diff changeset
466 if (!t) return 3;
08d4355d6fc9 Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents: 228
diff changeset
467 *t = 0;
08d4355d6fc9 Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents: 228
diff changeset
468
08d4355d6fc9 Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents: 228
diff changeset
469 /* Decode message string */
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
470 s = nn_decode_str1(s);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
471 if (!s) return -1;
229
08d4355d6fc9 Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents: 228
diff changeset
472
08d4355d6fc9 Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents: 228
diff changeset
473 /* Decode username */
225
801ac37321f6 Sanitize ignore handling; Also action messages and PRVs were not being properly ignored, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
474 userName = nn_decode_str1(p);
801ac37321f6 Sanitize ignore handling; Also action messages and PRVs were not being properly ignored, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
475 if (!userName) {
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
476 th_free(s);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
477 return -2;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
478 }
229
08d4355d6fc9 Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents: 228
diff changeset
479
08d4355d6fc9 Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents: 228
diff changeset
480 /* Check if the username is on our ignore list and
08d4355d6fc9 Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents: 228
diff changeset
481 * that it is not our OWN username!
08d4355d6fc9 Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents: 228
diff changeset
482 */
225
801ac37321f6 Sanitize ignore handling; Also action messages and PRVs were not being properly ignored, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
483 isMine = strcmp(userName, optUserName) == 0;
258
8a0f7446318e General cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 254
diff changeset
484 isIgnored = setIgnoreMode && !isMine && checkIgnoreList(userName);
108
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
485
229
08d4355d6fc9 Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents: 228
diff changeset
486 /* Is it a special control message? */
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
487 if (*s == '/') {
108
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
488 /* Ignore room join/leave messages */
162
e59cec397811 Add a debug mode option (commandline) and enable certain features when we are in debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
489 if (!optDebug && (strstr(s, "left the room") || strstr(s, "joined the room from")))
229
08d4355d6fc9 Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents: 228
diff changeset
490 goto done;
108
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
491
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
492 t = nn_strip_tags(s + 1);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
493 if (!strncmp(t, "BPRV", 4)) {
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
494 h = nn_decode_str2(t + 1);
225
801ac37321f6 Sanitize ignore handling; Also action messages and PRVs were not being properly ignored, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
495 if (!isIgnored && setTarget == NULL && !strncmp(h, "PRV from ", 9)) {
229
08d4355d6fc9 Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents: 228
diff changeset
496 char *q;
08d4355d6fc9 Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents: 228
diff changeset
497 setTarget = th_strdup(h + 9);
08d4355d6fc9 Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents: 228
diff changeset
498 for (q = setTarget; *q && *q != ':'; q++);
08d4355d6fc9 Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents: 228
diff changeset
499 *q = 0;
225
801ac37321f6 Sanitize ignore handling; Also action messages and PRVs were not being properly ignored, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
500 printMsg("PRV target autoset to '%s'\n", setTarget);
188
6b399b7ce40b Automatically grab PRV target from incoming PRV if target not already set.
Matti Hamalainen <ccr@tnsp.org>
parents: 187
diff changeset
501 }
225
801ac37321f6 Sanitize ignore handling; Also action messages and PRVs were not being properly ignored, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
502 printMsgQ(isIgnored, "½11½%s½0½\n", h);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
503 } else {
229
08d4355d6fc9 Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents: 228
diff changeset
504 /* It's an action (/me) */
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
505 h = nn_decode_str2(t);
225
801ac37321f6 Sanitize ignore handling; Also action messages and PRVs were not being properly ignored, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
506 printMsgQ(isIgnored, "½9½* %s½0½\n", h);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
507 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
508 th_free(h);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
509 th_free(t);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
510 } else {
229
08d4355d6fc9 Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents: 228
diff changeset
511 /* It's a normal message */
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
512 t = nn_strip_tags(s);
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
513 h = nn_decode_str2(t);
225
801ac37321f6 Sanitize ignore handling; Also action messages and PRVs were not being properly ignored, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
514 printMsgQ(isIgnored, "½5½<½%d½%s½5½>½0½ %s\n", isMine ? 14 : 15, userName, h);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
515 th_free(h);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
516 th_free(t);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
517 }
108
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
518
229
08d4355d6fc9 Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents: 228
diff changeset
519 done:
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
520 th_free(s);
225
801ac37321f6 Sanitize ignore handling; Also action messages and PRVs were not being properly ignored, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
521 th_free(userName);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
522 return 0;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
523 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
524
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
525
168
2e4850ece456 Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 165
diff changeset
526 int handleLogin(nn_conn_t *conn, const char *str)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
527 {
156
0a9fe14882dc Introduce utility function getTimeStamp() and use it to lessen code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 155
diff changeset
528 char tmpStr[256];
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
529
156
0a9fe14882dc Introduce utility function getTimeStamp() and use it to lessen code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 155
diff changeset
530 getTimeStamp(tmpStr, sizeof(tmpStr), "%c");
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
531
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
532 if (!strncmp(str, "FAILURE", 7)) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
533 printMsg("½1½Login failure½0½ - ½3½%s½0½\n", tmpStr);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
534 return -2;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
535 } else if (!strncmp(str, "SUCCESS", 7)) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
536 printMsg("½2½Login success½0½ - ½3½%s½0½\n", tmpStr);
198
21a37995c3fb Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents: 197
diff changeset
537 nn_conn_send_msg(conn, optUserNameEnc, "%%2FRequestUserList");
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
538 return 0;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
539 } else
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
540 return 1;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
541 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
542
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
543
168
2e4850ece456 Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 165
diff changeset
544 int handleAddUser(nn_conn_t *conn, const char *str)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
545 {
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
546 char *p, *s = strstr(str, "</ADD_USER>");
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
547
168
2e4850ece456 Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 165
diff changeset
548 (void) conn;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
549
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
550 if (!s) return 1;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
551 *s = 0;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
552
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
553 p = nn_dbldecode_str(str);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
554 if (!p) return -1;
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
555
191
4007b9ac7cde Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents: 190
diff changeset
556 nn_userhash_insert(nnUsers, encodeUsername(p));
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
557
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
558 printMsg("! ½3½%s½0½ ½2½ADDED.½0½\n", p);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
559 th_free(p);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
560 return 0;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
561 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
562
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
563
168
2e4850ece456 Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 165
diff changeset
564 int handleDeleteUser(nn_conn_t *conn, const char *str)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
565 {
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
566 char *p, *s = strstr(str, "</DELETE_USER>");
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
567
168
2e4850ece456 Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 165
diff changeset
568 (void) conn;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
569
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
570 if (!s) return 1;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
571 *s = 0;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
572
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
573 p = nn_dbldecode_str(str);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
574 if (!p) return -1;
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
575
191
4007b9ac7cde Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents: 190
diff changeset
576 nn_userhash_delete(nnUsers, encodeUsername(p));
107
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
577
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
578 printMsg("! ½3½%s½0½ ½1½DELETED.½0½\n", p);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
579 th_free(p);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
580 return 0;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
581 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
582
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
583
168
2e4850ece456 Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 165
diff changeset
584 int handleFoo(nn_conn_t *conn, const char *str)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
585 {
168
2e4850ece456 Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 165
diff changeset
586 (void) conn; (void) str;
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
587
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
588 return 0;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
589 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
590
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
591
168
2e4850ece456 Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 165
diff changeset
592 int handleBoot(nn_conn_t *conn, const char *str)
96
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
593 {
168
2e4850ece456 Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 165
diff changeset
594 (void) conn; (void) str;
96
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
595 errorMsg("Booted by server.\n");
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
596 return -1;
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
597 }
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
598
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
599
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
600 typedef struct {
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
601 char *cmd;
129
4235ff4ced04 "Optimize" protocol handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 128
diff changeset
602 ssize_t len;
168
2e4850ece456 Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 165
diff changeset
603 int (*handler)(nn_conn_t *, const char *);
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
604 } protocmd_t;
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
605
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
606
129
4235ff4ced04 "Optimize" protocol handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 128
diff changeset
607 static protocmd_t protoCmds[] = {
4235ff4ced04 "Optimize" protocol handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 128
diff changeset
608 { "<USER>", -1, handleUser },
4235ff4ced04 "Optimize" protocol handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 128
diff changeset
609 { "<LOGIN_", -1, handleLogin },
4235ff4ced04 "Optimize" protocol handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 128
diff changeset
610 { "<DELETE_USER>", -1, handleDeleteUser },
4235ff4ced04 "Optimize" protocol handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 128
diff changeset
611 { "<ADD_USER>", -1, handleAddUser },
4235ff4ced04 "Optimize" protocol handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 128
diff changeset
612 { "<NUMCLIENTS>", -1, handleFoo },
4235ff4ced04 "Optimize" protocol handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 128
diff changeset
613 { "<BOOT />", -1, handleBoot },
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
614 };
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
615
108
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
616 static const int nprotoCmds = sizeof(protoCmds) / sizeof(protoCmds[0]);
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
617
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
618
168
2e4850ece456 Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 165
diff changeset
619 int handleProtocol(nn_conn_t *conn, const char *buf, const ssize_t bufLen)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
620 {
130
352ec3c300e4 A different initialization.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
621 static BOOL protoCmdsInit = FALSE;
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
622 int i;
130
352ec3c300e4 A different initialization.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
623
352ec3c300e4 A different initialization.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
624 if (!protoCmdsInit) {
352ec3c300e4 A different initialization.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
625 for (i = 0; i < nprotoCmds; i++)
352ec3c300e4 A different initialization.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
626 protoCmds[i].len = strlen(protoCmds[i].cmd);
352ec3c300e4 A different initialization.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
627 protoCmdsInit = TRUE;
352ec3c300e4 A different initialization.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
628 }
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
629
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
630 for (i = 0; i < nprotoCmds; i++) {
129
4235ff4ced04 "Optimize" protocol handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 128
diff changeset
631 ssize_t cmdLen = protoCmds[i].len;
4235ff4ced04 "Optimize" protocol handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 128
diff changeset
632 if (cmdLen < bufLen && !strncmp(buf, protoCmds[i].cmd, cmdLen))
168
2e4850ece456 Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 165
diff changeset
633 return protoCmds[i].handler(conn, buf + cmdLen);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
634 }
162
e59cec397811 Add a debug mode option (commandline) and enable certain features when we are in debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
635
e59cec397811 Add a debug mode option (commandline) and enable certain features when we are in debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
636 if (optDebug) {
e59cec397811 Add a debug mode option (commandline) and enable certain features when we are in debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
637 printMsg("Unknown protocmd: \"%s\"\n", buf);
e59cec397811 Add a debug mode option (commandline) and enable certain features when we are in debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
638 return 0;
e59cec397811 Add a debug mode option (commandline) and enable certain features when we are in debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
639 } else
e59cec397811 Add a debug mode option (commandline) and enable certain features when we are in debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
640 return 1;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
641 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
642
125
d03ebefb92a6 Improve internal command handling, use fork() and execlp() instead of system() for opening profiles into external browser's tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 123
diff changeset
643 char * trimLeft(char *buf)
d03ebefb92a6 Improve internal command handling, use fork() and execlp() instead of system() for opening profiles into external browser's tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 123
diff changeset
644 {
202
4b93442bd411 Silence a warning under Solaris and few other systems by using th_isspace() wrapper instead of isspace().
Matti Hamalainen <ccr@tnsp.org>
parents: 198
diff changeset
645 while (*buf != 0 && th_isspace(*buf)) buf++;
125
d03ebefb92a6 Improve internal command handling, use fork() and execlp() instead of system() for opening profiles into external browser's tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 123
diff changeset
646 return buf;
d03ebefb92a6 Improve internal command handling, use fork() and execlp() instead of system() for opening profiles into external browser's tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 123
diff changeset
647 }
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
648
140
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
649 int compareUsername(const void *s1, const void *s2)
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
650 {
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
651 return strcasecmp((char *) s1, (char *) s2);
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
652 }
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
653
168
2e4850ece456 Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 165
diff changeset
654 int handleUserInput(nn_conn_t *conn, char *buf, size_t bufLen)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
655 {
78
745f670068dc Add functions to simplify code.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
656 char *tmpStr, tmpBuf[4096];
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
657 BOOL result;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
658
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
659 /* Trim right */
112
c4865ac2386c Fix right-side trimming of command line.
Matti Hamalainen <ccr@tnsp.org>
parents: 111
diff changeset
660 bufLen--;
c4865ac2386c Fix right-side trimming of command line.
Matti Hamalainen <ccr@tnsp.org>
parents: 111
diff changeset
661 buf[bufLen--] = 0;
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
662 while (bufLen > 0 && (buf[bufLen] == '\n' || buf[bufLen] == '\r' || th_isspace(buf[bufLen])))
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
663 buf[bufLen--] = 0;
258
8a0f7446318e General cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 254
diff changeset
664
8a0f7446318e General cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 254
diff changeset
665 /* Decode completed usernames */
191
4007b9ac7cde Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents: 190
diff changeset
666 decodeUsername(buf);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
667
109
1323a7f88c21 Fix /w -command and add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
668 /* Check for special user commands */
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
669 if (*buf == 0) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
670 return 1;
258
8a0f7446318e General cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 254
diff changeset
671 }
8a0f7446318e General cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 254
diff changeset
672 else if (!strncasecmp(buf, "/color ", 7)) {
109
1323a7f88c21 Fix /w -command and add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
673 /* Change color */
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
674 int tmpInt;
132
10daf4660cae Use th_get_hex_triplet().
Matti Hamalainen <ccr@tnsp.org>
parents: 130
diff changeset
675 if ((tmpInt = th_get_hex_triplet(trimLeft(buf + 7))) < 0) {
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
676 printMsg("Invalid color value '%s'\n", buf+7);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
677 return 1;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
678 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
679 optUserColor = tmpInt;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
680 printMsg("Setting color to #%06x\n", optUserColor);
198
21a37995c3fb Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents: 197
diff changeset
681 nn_conn_send_msg(conn, optUserNameEnc, "%%2FSetFontColor%%20%%2Dcolor%%20%06X", optUserColor);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
682 return 0;
258
8a0f7446318e General cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 254
diff changeset
683 }
8a0f7446318e General cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 254
diff changeset
684 else if (!strncasecmp(buf, "/ignore", 7)) {
140
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
685 char *name = trimLeft(buf + 7);
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
686 if (strlen(name) > 0) {
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
687 /* Add or remove someone to/from ignore */
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
688 qlist_t *user = th_llist_find_func(nnIgnoreList, name, compareUsername);
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
689 if (user != NULL) {
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
690 printMsg("Removed user '%s' from ignore.\n", name);
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
691 th_llist_delete_node(&nnIgnoreList, user);
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
692 } else {
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
693 printMsg("Now ignoring '%s'.\n", name);
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
694 th_llist_append(&nnIgnoreList, th_strdup(name));
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
695 }
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
696 } else {
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
697 /* Just list whomever is in ignore now */
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
698 qlist_t *user = nnIgnoreList;
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
699 ssize_t nuser = th_llist_length(nnIgnoreList);
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
700 printMsg("Users ignored (%d): ", nuser);
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
701 while (user != NULL) {
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
702 if (user->data != NULL) {
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
703 printMsgC("'%s'", (char *) user->data);
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
704 if (--nuser > 0)
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
705 printMsgC(", ");
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
706 }
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
707 user = user->next;
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
708 }
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
709 printMsgC("\n");
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
710 }
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
711 return 0;
258
8a0f7446318e General cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 254
diff changeset
712 }
8a0f7446318e General cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 254
diff changeset
713 else if (!strncasecmp(buf, "/save", 5)) {
133
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
714 /* Save configuration */
143
5babbff7ca26 Rename some variables, cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 142
diff changeset
715 FILE *cfgfile = fopen(setConfigFile, "w");
5babbff7ca26 Rename some variables, cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 142
diff changeset
716 if (cfgfile == NULL) {
5babbff7ca26 Rename some variables, cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 142
diff changeset
717 printMsg("Could not create configuration to file '%s': %s\n", setConfigFile,
5babbff7ca26 Rename some variables, cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 142
diff changeset
718 strerror(errno));
133
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
719 return 0;
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
720 }
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
721 printMsg("Configuration saved in file '%s', res=%d\n",
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
722 setConfigFile,
143
5babbff7ca26 Rename some variables, cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 142
diff changeset
723 th_cfg_write(cfgfile, setConfigFile, cfg));
133
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
724
143
5babbff7ca26 Rename some variables, cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 142
diff changeset
725 fclose(cfgfile);
133
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
726 return 0;
258
8a0f7446318e General cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 254
diff changeset
727 }
8a0f7446318e General cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 254
diff changeset
728 else if (!strncasecmp(buf, "/w ", 3)) {
109
1323a7f88c21 Fix /w -command and add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
729 /* Open given username's profile via firefox in a new tab */
137
fad8c31e41e6 Move browser code around a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
730 char *name = trimLeft(buf + 3);
114
256cca8cc086 Support $BROWSER environment variable setting.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
731
125
d03ebefb92a6 Improve internal command handling, use fork() and execlp() instead of system() for opening profiles into external browser's tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 123
diff changeset
732 printMsg("Opening profile for: '%s'\n", name);
d03ebefb92a6 Improve internal command handling, use fork() and execlp() instead of system() for opening profiles into external browser's tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 123
diff changeset
733
108
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
734 tmpStr = nn_encode_str1(name);
197
e0ec2280a778 Implement browser launching on Windows via ShellExecute().
Matti Hamalainen <ccr@tnsp.org>
parents: 196
diff changeset
735 #ifdef __WIN32
e0ec2280a778 Implement browser launching on Windows via ShellExecute().
Matti Hamalainen <ccr@tnsp.org>
parents: 196
diff changeset
736 {
218
0e60593006c9 Change ShellExecute return value's variable type to HINSTANCE as it should be.
Matti Hamalainen <ccr@tnsp.org>
parents: 217
diff changeset
737 HINSTANCE status;
197
e0ec2280a778 Implement browser launching on Windows via ShellExecute().
Matti Hamalainen <ccr@tnsp.org>
parents: 196
diff changeset
738 snprintf(tmpBuf, sizeof(tmpBuf), "http://www.newbienudes.com/profile/%s/", tmpStr);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
739 th_free(tmpStr);
197
e0ec2280a778 Implement browser launching on Windows via ShellExecute().
Matti Hamalainen <ccr@tnsp.org>
parents: 196
diff changeset
740 status = ShellExecute(NULL, "open", tmpBuf, NULL, NULL, SW_SHOWNA);
e0ec2280a778 Implement browser launching on Windows via ShellExecute().
Matti Hamalainen <ccr@tnsp.org>
parents: 196
diff changeset
741 if (status <= 32)
e0ec2280a778 Implement browser launching on Windows via ShellExecute().
Matti Hamalainen <ccr@tnsp.org>
parents: 196
diff changeset
742 printMsg("Could not launch default web browser: %d\n", status);
e0ec2280a778 Implement browser launching on Windows via ShellExecute().
Matti Hamalainen <ccr@tnsp.org>
parents: 196
diff changeset
743 }
128
713879a7ca10 Wait for forked processes, to prevent a zombie apocalypse.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
744 #else
713879a7ca10 Wait for forked processes, to prevent a zombie apocalypse.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
745 {
713879a7ca10 Wait for forked processes, to prevent a zombie apocalypse.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
746 int status;
233
6b1c67274f6c Use a pipe to redirect executed browser's stderr and stdout when opening profiles.
Matti Hamalainen <ccr@tnsp.org>
parents: 232
diff changeset
747 int fds[2];
128
713879a7ca10 Wait for forked processes, to prevent a zombie apocalypse.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
748 pid_t pid;
197
e0ec2280a778 Implement browser launching on Windows via ShellExecute().
Matti Hamalainen <ccr@tnsp.org>
parents: 196
diff changeset
749 snprintf(tmpBuf, sizeof(tmpBuf), "openurl(http://www.newbienudes.com/profile/%s/,new-tab)", tmpStr);
e0ec2280a778 Implement browser launching on Windows via ShellExecute().
Matti Hamalainen <ccr@tnsp.org>
parents: 196
diff changeset
750 th_free(tmpStr);
e0ec2280a778 Implement browser launching on Windows via ShellExecute().
Matti Hamalainen <ccr@tnsp.org>
parents: 196
diff changeset
751
233
6b1c67274f6c Use a pipe to redirect executed browser's stderr and stdout when opening profiles.
Matti Hamalainen <ccr@tnsp.org>
parents: 232
diff changeset
752 if (pipe(fds) == -1) {
6b1c67274f6c Use a pipe to redirect executed browser's stderr and stdout when opening profiles.
Matti Hamalainen <ccr@tnsp.org>
parents: 232
diff changeset
753 int ret = errno;
6b1c67274f6c Use a pipe to redirect executed browser's stderr and stdout when opening profiles.
Matti Hamalainen <ccr@tnsp.org>
parents: 232
diff changeset
754 printMsg("Could not open process communication pipe! (%d, %s)\n", ret, strerror(ret));
6b1c67274f6c Use a pipe to redirect executed browser's stderr and stdout when opening profiles.
Matti Hamalainen <ccr@tnsp.org>
parents: 232
diff changeset
755 return 0;
6b1c67274f6c Use a pipe to redirect executed browser's stderr and stdout when opening profiles.
Matti Hamalainen <ccr@tnsp.org>
parents: 232
diff changeset
756 }
6b1c67274f6c Use a pipe to redirect executed browser's stderr and stdout when opening profiles.
Matti Hamalainen <ccr@tnsp.org>
parents: 232
diff changeset
757
125
d03ebefb92a6 Improve internal command handling, use fork() and execlp() instead of system() for opening profiles into external browser's tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 123
diff changeset
758 if ((pid = fork()) < 0) {
d03ebefb92a6 Improve internal command handling, use fork() and execlp() instead of system() for opening profiles into external browser's tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 123
diff changeset
759 printMsg("Could not create sub-process!\n");
d03ebefb92a6 Improve internal command handling, use fork() and execlp() instead of system() for opening profiles into external browser's tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 123
diff changeset
760 } else if (pid == 0) {
233
6b1c67274f6c Use a pipe to redirect executed browser's stderr and stdout when opening profiles.
Matti Hamalainen <ccr@tnsp.org>
parents: 232
diff changeset
761 dup2(fds[1], STDOUT_FILENO);
6b1c67274f6c Use a pipe to redirect executed browser's stderr and stdout when opening profiles.
Matti Hamalainen <ccr@tnsp.org>
parents: 232
diff changeset
762 dup2(fds[0], STDERR_FILENO);
216
3ccfe8902fd5 Use (void *) typecast for execlp() sentinel to avoid a warning under OpenBSD.
Matti Hamalainen <ccr@tnsp.org>
parents: 211
diff changeset
763 execlp(setBrowser, setBrowser, "-remote", tmpBuf, (void *)NULL);
128
713879a7ca10 Wait for forked processes, to prevent a zombie apocalypse.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
764 _exit(errno);
125
d03ebefb92a6 Improve internal command handling, use fork() and execlp() instead of system() for opening profiles into external browser's tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 123
diff changeset
765 }
128
713879a7ca10 Wait for forked processes, to prevent a zombie apocalypse.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
766
713879a7ca10 Wait for forked processes, to prevent a zombie apocalypse.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
767 wait(&status);
713879a7ca10 Wait for forked processes, to prevent a zombie apocalypse.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
768 }
713879a7ca10 Wait for forked processes, to prevent a zombie apocalypse.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
769 #endif
109
1323a7f88c21 Fix /w -command and add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
770 return 0;
258
8a0f7446318e General cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 254
diff changeset
771 }
8a0f7446318e General cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 254
diff changeset
772 else if (!strncasecmp(buf, "/to", 3)) {
183
209546c5b7d0 Improve /to command a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 181
diff changeset
773 char *name = trimLeft(buf + 3);
109
1323a7f88c21 Fix /w -command and add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
774 /* Set private messaging target */
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
775 th_free(setTarget);
183
209546c5b7d0 Improve /to command a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 181
diff changeset
776 if (strlen(name) > 0) {
209546c5b7d0 Improve /to command a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 181
diff changeset
777 setTarget = th_strdup(trimLeft(buf + 3));
209546c5b7d0 Improve /to command a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 181
diff changeset
778 printMsg("Set prv target to '%s'\n", setTarget);
209546c5b7d0 Improve /to command a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 181
diff changeset
779 } else {
209546c5b7d0 Improve /to command a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 181
diff changeset
780 setTarget = NULL;
209546c5b7d0 Improve /to command a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 181
diff changeset
781 printMsg("Cleared prv target.\n");
209546c5b7d0 Improve /to command a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 181
diff changeset
782 }
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
783 return 0;
258
8a0f7446318e General cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 254
diff changeset
784 }
8a0f7446318e General cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 254
diff changeset
785 else if (!strncasecmp(buf, "/who", 4)) {
109
1323a7f88c21 Fix /w -command and add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
786 /* Alias /who to /listallusers */
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
787 snprintf(tmpBuf, sizeof(tmpBuf), "/listallusers");
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
788 buf = tmpBuf;
258
8a0f7446318e General cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 254
diff changeset
789 }
8a0f7446318e General cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 254
diff changeset
790 else if (setPrvMode) {
109
1323a7f88c21 Fix /w -command and add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
791 /* Private chat mode, send as PRV */
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
792 if (setTarget != NULL) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
793 snprintf(tmpBuf, sizeof(tmpBuf), "/prv -to %s -msg %s", setTarget, buf);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
794 buf = tmpBuf;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
795 } else {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
796 printMsg("No target set, exiting prv mode.\n");
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
797 setPrvMode = FALSE;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
798 return 1;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
799 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
800 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
801
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
802 /* Send double-encoded */
191
4007b9ac7cde Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents: 190
diff changeset
803 tmpStr = nn_dblencode_str(decodeUsername(buf));
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
804 if (tmpStr == 0) return -2;
198
21a37995c3fb Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents: 197
diff changeset
805 result = nn_conn_send_msg(conn, optUserNameEnc, "%s", tmpStr);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
806 th_free(tmpStr);
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
807
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
808 return result ? 0 : -1;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
809 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
810
155
0720ca51673e Plug some minor "memory leaks" related to curses.
Matti Hamalainen <ccr@tnsp.org>
parents: 154
diff changeset
811 void closeWindows(void)
0720ca51673e Plug some minor "memory leaks" related to curses.
Matti Hamalainen <ccr@tnsp.org>
parents: 154
diff changeset
812 {
0720ca51673e Plug some minor "memory leaks" related to curses.
Matti Hamalainen <ccr@tnsp.org>
parents: 154
diff changeset
813 if (mainWin) delwin(mainWin);
0720ca51673e Plug some minor "memory leaks" related to curses.
Matti Hamalainen <ccr@tnsp.org>
parents: 154
diff changeset
814 if (statusWin) delwin(statusWin);
0720ca51673e Plug some minor "memory leaks" related to curses.
Matti Hamalainen <ccr@tnsp.org>
parents: 154
diff changeset
815 if (editWin) delwin(editWin);
0720ca51673e Plug some minor "memory leaks" related to curses.
Matti Hamalainen <ccr@tnsp.org>
parents: 154
diff changeset
816 }
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
817
46
65b1ac6a1e2e Support for resizing the terminal on fly. Not perfect, but works.
Matti Hamalainen <ccr@tnsp.org>
parents: 45
diff changeset
818 BOOL initializeWindows(void)
65b1ac6a1e2e Support for resizing the terminal on fly. Not perfect, but works.
Matti Hamalainen <ccr@tnsp.org>
parents: 45
diff changeset
819 {
118
9e7f52878725 Use getmaxyx() instead of LINES and COLS globals as recommended by curses programming guidelines.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
820 int w, h;
9e7f52878725 Use getmaxyx() instead of LINES and COLS globals as recommended by curses programming guidelines.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
821
9e7f52878725 Use getmaxyx() instead of LINES and COLS globals as recommended by curses programming guidelines.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
822 getmaxyx(stdscr, h, w);
9e7f52878725 Use getmaxyx() instead of LINES and COLS globals as recommended by curses programming guidelines.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
823
155
0720ca51673e Plug some minor "memory leaks" related to curses.
Matti Hamalainen <ccr@tnsp.org>
parents: 154
diff changeset
824 closeWindows();
118
9e7f52878725 Use getmaxyx() instead of LINES and COLS globals as recommended by curses programming guidelines.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
825
209
e1bfd5227a24 Use curses subwin(stdscr, ...) instead of newwin().
Matti Hamalainen <ccr@tnsp.org>
parents: 208
diff changeset
826 mainWin = subwin(stdscr, h - 4, w, 0, 0);
e1bfd5227a24 Use curses subwin(stdscr, ...) instead of newwin().
Matti Hamalainen <ccr@tnsp.org>
parents: 208
diff changeset
827 statusWin = subwin(stdscr, 1, w, h - 4, 0);
e1bfd5227a24 Use curses subwin(stdscr, ...) instead of newwin().
Matti Hamalainen <ccr@tnsp.org>
parents: 208
diff changeset
828 editWin = subwin(stdscr, 3, w, h - 3, 0);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
829
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
830 if (mainWin == NULL || statusWin == NULL || editWin == NULL) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
831 THERR("Could not create ncurses windows!\n");
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
832 return FALSE;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
833 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
834 scrollok(mainWin, 1);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
835
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
836 return TRUE;
46
65b1ac6a1e2e Support for resizing the terminal on fly. Not perfect, but works.
Matti Hamalainen <ccr@tnsp.org>
parents: 45
diff changeset
837 }
65b1ac6a1e2e Support for resizing the terminal on fly. Not perfect, but works.
Matti Hamalainen <ccr@tnsp.org>
parents: 45
diff changeset
838
179
8c493b5671bd Add separate updateWindows() function.
Matti Hamalainen <ccr@tnsp.org>
parents: 175
diff changeset
839 void updateWindows(void)
8c493b5671bd Add separate updateWindows() function.
Matti Hamalainen <ccr@tnsp.org>
parents: 175
diff changeset
840 {
8c493b5671bd Add separate updateWindows() function.
Matti Hamalainen <ccr@tnsp.org>
parents: 175
diff changeset
841 if (mainWin) redrawwin(mainWin);
8c493b5671bd Add separate updateWindows() function.
Matti Hamalainen <ccr@tnsp.org>
parents: 175
diff changeset
842 if (statusWin) redrawwin(statusWin);
8c493b5671bd Add separate updateWindows() function.
Matti Hamalainen <ccr@tnsp.org>
parents: 175
diff changeset
843 if (editWin) redrawwin(editWin);
8c493b5671bd Add separate updateWindows() function.
Matti Hamalainen <ccr@tnsp.org>
parents: 175
diff changeset
844 }
113
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
845
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
846 BOOL performTabCompletion(nn_editbuf_t *buf)
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
847 {
189
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
848 static char *previous = NULL, *pattern = NULL;
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
849 BOOL again = FALSE, hasSeparator = FALSE, newPattern = FALSE, hasSpace = FALSE;
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
850 char *str = buf->data;
113
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
851 int mode = 0;
189
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
852 ssize_t endPos, startPos = buf->pos;
107
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
853
189
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
854 /* previous word */
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
855 if (startPos >= 2 && str[startPos - 1] == ' ' && str[startPos - 2] != ' ') {
113
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
856 startPos -= 2;
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
857 endPos = startPos;
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
858 while (startPos > 0 && str[startPos - 1] != ' ') startPos--;
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
859 mode = 1;
107
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
860 } else
189
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
861 /* middle of a word, new pattern */
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
862 if (startPos < buf->len && str[startPos] != ' ') {
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
863 endPos = startPos;
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
864 while (startPos > 0 && str[startPos - 1] != ' ') startPos--;
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
865 while (endPos < buf->len - 1 && str[endPos + 1] != ' ') endPos++;
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
866 newPattern = TRUE;
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
867 mode = 2;
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
868 } else
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
869 /* previous word, new pattern */
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
870 if (startPos >= 1 && str[startPos - 1] != ' ') {
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
871 startPos -= 1;
113
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
872 endPos = startPos;
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
873 while (startPos > 0 && str[startPos - 1] != ' ') startPos--;
189
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
874 newPattern = TRUE;
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
875 mode = 3;
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
876 } else {
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
877 if (optDebug)
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
878 printMsg("no mode\n");
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
879 return FALSE;
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
880 }
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
881
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
882 if (str[endPos] == optNickSep) {
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
883 endPos--;
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
884 if (startPos > 0) {
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
885 if (optDebug)
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
886 printMsg("str[endPos] == optNickSep && startPos > 0 (%d)\n", startPos);
113
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
887 return FALSE;
189
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
888 }
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
889 hasSeparator = TRUE;
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
890 }
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
891
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
892 if (buf->pos > 0 && str[buf->pos - 1] == ' ')
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
893 hasSpace = TRUE;
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
894 if (buf->pos <= buf->len && str[buf->pos] == ' ')
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
895 hasSpace = TRUE;
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
896
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
897 if (newPattern) {
116
741e45592522 Add simple "prediction" into tab-completion based on previously gotten last
Matti Hamalainen <ccr@tnsp.org>
parents: 115
diff changeset
898 /* Get pattern, check if it matches previous pattern and set 'again' flag */
189
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
899 char *npattern = nn_editbuf_get_string(buf, startPos, endPos);
165
f2f0b6f9281b Dont set 'again' flag in tab completion function if the new and old pattern do not match exactly (apart from case).
Matti Hamalainen <ccr@tnsp.org>
parents: 163
diff changeset
900 if (pattern && npattern && strcasecmp(npattern, pattern) == 0)
116
741e45592522 Add simple "prediction" into tab-completion based on previously gotten last
Matti Hamalainen <ccr@tnsp.org>
parents: 115
diff changeset
901 again = TRUE;
189
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
902
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
903 th_free(pattern);
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
904 pattern = npattern;
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
905
116
741e45592522 Add simple "prediction" into tab-completion based on previously gotten last
Matti Hamalainen <ccr@tnsp.org>
parents: 115
diff changeset
906 if (!again) {
741e45592522 Add simple "prediction" into tab-completion based on previously gotten last
Matti Hamalainen <ccr@tnsp.org>
parents: 115
diff changeset
907 th_free(previous);
741e45592522 Add simple "prediction" into tab-completion based on previously gotten last
Matti Hamalainen <ccr@tnsp.org>
parents: 115
diff changeset
908 previous = NULL;
741e45592522 Add simple "prediction" into tab-completion based on previously gotten last
Matti Hamalainen <ccr@tnsp.org>
parents: 115
diff changeset
909 }
189
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
910 }
116
741e45592522 Add simple "prediction" into tab-completion based on previously gotten last
Matti Hamalainen <ccr@tnsp.org>
parents: 115
diff changeset
911
189
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
912 if (optDebug) {
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
913 printMsg("sPos=%d, ePos=%d <-> bPos=%d, bufLen=%d : pat='%s' (again=%s, hassep=%s, hasspc=%s, newpat=%s, mode=%d)\n",
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
914 startPos, endPos, buf->pos, buf->len, pattern,
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
915 again ? "yes" : "no",
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
916 hasSeparator ? "yes" : "no",
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
917 hasSpace ? "yes" : "no",
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
918 newPattern ? "yes" : "no", mode);
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
919 }
107
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
920
113
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
921 if (pattern) {
116
741e45592522 Add simple "prediction" into tab-completion based on previously gotten last
Matti Hamalainen <ccr@tnsp.org>
parents: 115
diff changeset
922 nn_user_t *user = nn_user_match(nnUsers, pattern, previous, again);
107
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
923
108
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
924 if (user) {
107
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
925 int i;
108
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
926 char *c = user->name;
162
e59cec397811 Add a debug mode option (commandline) and enable certain features when we are in debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
927 if (optDebug)
163
cc1cc49d26f0 Make tab username completion debug messages clearer.
Matti Hamalainen <ccr@tnsp.org>
parents: 162
diff changeset
928 printMsg("match='%s' / prev='%s'\n", user->name, previous);
107
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
929
113
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
930 for (i = startPos; i <= endPos; i++)
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
931 nn_editbuf_delete(buf, startPos);
107
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
932
113
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
933 for (i = startPos; *c; i++, c++)
107
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
934 nn_editbuf_insert(buf, i, *c);
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
935
189
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
936 if (!hasSeparator && startPos == 0) {
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
937 nn_editbuf_insert(buf, i++, optNickSep);
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
938 startPos++;
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
939 }
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
940 if (hasSeparator)
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
941 startPos++;
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
942 if (!hasSpace)
113
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
943 nn_editbuf_insert(buf, i++, ' ');
189
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
944
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
945 nn_editbuf_setpos(buf, startPos + 1 + strlen(user->name));
107
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
946
108
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
947 th_free(previous);
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
948 previous = th_strdup(user->name);
113
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
949
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
950 return TRUE;
107
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
951 }
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
952 }
113
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
953
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
954 return FALSE;
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
955 }
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
956
252
dcf78e2c458c Improve log filename format parsing; Add special casing for handling of function keys for certain terminal types.
Matti Hamalainen <ccr@tnsp.org>
parents: 247
diff changeset
957 #define VPUTCH(CH) th_vputch(&bufData, &bufSize, &bufLen, CH)
242
cb86d7543be2 Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
958 #define VPUTS(STR) th_vputs(&bufData, &bufSize, &bufLen, STR)
cb86d7543be2 Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
959
239
b7e7ed741a18 Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
960 char *logParseFilename(const char *fmt, int id)
b7e7ed741a18 Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
961 {
252
dcf78e2c458c Improve log filename format parsing; Add special casing for handling of function keys for certain terminal types.
Matti Hamalainen <ccr@tnsp.org>
parents: 247
diff changeset
962 size_t bufSize = strlen(fmt) + TH_BUFGROW, bufLen = 0;
dcf78e2c458c Improve log filename format parsing; Add special casing for handling of function keys for certain terminal types.
Matti Hamalainen <ccr@tnsp.org>
parents: 247
diff changeset
963 char *bufData = th_malloc(bufSize);
dcf78e2c458c Improve log filename format parsing; Add special casing for handling of function keys for certain terminal types.
Matti Hamalainen <ccr@tnsp.org>
parents: 247
diff changeset
964 char tmpBuf[32];
239
b7e7ed741a18 Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
965 const char *s = fmt;
b7e7ed741a18 Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
966
b7e7ed741a18 Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
967 while (*s) {
b7e7ed741a18 Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
968 if (*s == '%') {
b7e7ed741a18 Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
969 s++;
b7e7ed741a18 Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
970 switch (*s) {
b7e7ed741a18 Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
971 case 'i':
b7e7ed741a18 Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
972 snprintf(tmpBuf, sizeof(tmpBuf), "%05d", id);
b7e7ed741a18 Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
973 VPUTS(tmpBuf);
b7e7ed741a18 Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
974 break;
252
dcf78e2c458c Improve log filename format parsing; Add special casing for handling of function keys for certain terminal types.
Matti Hamalainen <ccr@tnsp.org>
parents: 247
diff changeset
975
dcf78e2c458c Improve log filename format parsing; Add special casing for handling of function keys for certain terminal types.
Matti Hamalainen <ccr@tnsp.org>
parents: 247
diff changeset
976 case 'd':
dcf78e2c458c Improve log filename format parsing; Add special casing for handling of function keys for certain terminal types.
Matti Hamalainen <ccr@tnsp.org>
parents: 247
diff changeset
977 snprintf(tmpBuf, sizeof(tmpBuf), "%d", id);
dcf78e2c458c Improve log filename format parsing; Add special casing for handling of function keys for certain terminal types.
Matti Hamalainen <ccr@tnsp.org>
parents: 247
diff changeset
978 VPUTS(tmpBuf);
dcf78e2c458c Improve log filename format parsing; Add special casing for handling of function keys for certain terminal types.
Matti Hamalainen <ccr@tnsp.org>
parents: 247
diff changeset
979 break;
dcf78e2c458c Improve log filename format parsing; Add special casing for handling of function keys for certain terminal types.
Matti Hamalainen <ccr@tnsp.org>
parents: 247
diff changeset
980
239
b7e7ed741a18 Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
981 case '%':
242
cb86d7543be2 Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
982 VPUTCH('%');
239
b7e7ed741a18 Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
983 break;
b7e7ed741a18 Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
984 }
242
cb86d7543be2 Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
985 s++;
cb86d7543be2 Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
986 } else {
cb86d7543be2 Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
987 VPUTCH(*s);
cb86d7543be2 Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
988 s++;
239
b7e7ed741a18 Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
989 }
b7e7ed741a18 Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
990 }
242
cb86d7543be2 Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
991
cb86d7543be2 Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
992 VPUTCH(0);
cb86d7543be2 Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
993 return bufData;
239
b7e7ed741a18 Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
994 }
b7e7ed741a18 Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
995
b7e7ed741a18 Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
996
b7e7ed741a18 Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
997 BOOL logFileOpen(void)
b7e7ed741a18 Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
998 {
b7e7ed741a18 Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
999 char *filename;
b7e7ed741a18 Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
1000
242
cb86d7543be2 Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
1001 if (optLogFilename == NULL || !optLogEnable)
239
b7e7ed741a18 Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
1002 return FALSE;
b7e7ed741a18 Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
1003
242
cb86d7543be2 Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
1004 filename = logParseFilename(optLogFilename, optPort);
239
b7e7ed741a18 Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
1005
b7e7ed741a18 Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
1006 if ((optLogFile = fopen(filename, "a")) == NULL) {
242
cb86d7543be2 Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
1007 errorMsg("Could not open logfile '%s' for appending!\n", filename);
239
b7e7ed741a18 Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
1008 th_free(filename);
b7e7ed741a18 Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
1009 return FALSE;
b7e7ed741a18 Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
1010 }
242
cb86d7543be2 Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
1011
cb86d7543be2 Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
1012 th_free(filename);
cb86d7543be2 Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
1013
239
b7e7ed741a18 Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
1014 return TRUE;
b7e7ed741a18 Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
1015 }
b7e7ed741a18 Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
1016
242
cb86d7543be2 Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
1017 void logFileClose(void)
239
b7e7ed741a18 Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
1018 {
242
cb86d7543be2 Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
1019 if (optLogFile) {
cb86d7543be2 Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
1020 fclose(optLogFile);
cb86d7543be2 Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
1021 optLogFile = NULL;
cb86d7543be2 Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
1022 }
239
b7e7ed741a18 Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
1023 }
b7e7ed741a18 Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
1024
211
c40329e95445 Trim both left and right side of username+password prompt input. Also allow empty passwords, to be able to use guest accounts.
Matti Hamalainen <ccr@tnsp.org>
parents: 210
diff changeset
1025 char *promptRequester(const char *info, BOOL allowEmpty)
196
edd5ce3e5399 Add simplistic username/password requester if none given on commandline or config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 195
diff changeset
1026 {
211
c40329e95445 Trim both left and right side of username+password prompt input. Also allow empty passwords, to be able to use guest accounts.
Matti Hamalainen <ccr@tnsp.org>
parents: 210
diff changeset
1027 char tmpBuf[512], *ptr;
c40329e95445 Trim both left and right side of username+password prompt input. Also allow empty passwords, to be able to use guest accounts.
Matti Hamalainen <ccr@tnsp.org>
parents: 210
diff changeset
1028 ssize_t pos;
196
edd5ce3e5399 Add simplistic username/password requester if none given on commandline or config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 195
diff changeset
1029
edd5ce3e5399 Add simplistic username/password requester if none given on commandline or config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 195
diff changeset
1030 fputs(info, stdout);
edd5ce3e5399 Add simplistic username/password requester if none given on commandline or config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 195
diff changeset
1031 fgets(tmpBuf, sizeof(tmpBuf), stdin);
197
e0ec2280a778 Implement browser launching on Windows via ShellExecute().
Matti Hamalainen <ccr@tnsp.org>
parents: 196
diff changeset
1032
211
c40329e95445 Trim both left and right side of username+password prompt input. Also allow empty passwords, to be able to use guest accounts.
Matti Hamalainen <ccr@tnsp.org>
parents: 210
diff changeset
1033 for (pos = strlen(tmpBuf) - 1; pos > 0 && (tmpBuf[pos] == '\n' || tmpBuf[pos] == '\r' || th_isspace(tmpBuf[pos])); pos--)
c40329e95445 Trim both left and right side of username+password prompt input. Also allow empty passwords, to be able to use guest accounts.
Matti Hamalainen <ccr@tnsp.org>
parents: 210
diff changeset
1034 tmpBuf[pos] = 0;
196
edd5ce3e5399 Add simplistic username/password requester if none given on commandline or config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 195
diff changeset
1035
211
c40329e95445 Trim both left and right side of username+password prompt input. Also allow empty passwords, to be able to use guest accounts.
Matti Hamalainen <ccr@tnsp.org>
parents: 210
diff changeset
1036 ptr = trimLeft(tmpBuf);
c40329e95445 Trim both left and right side of username+password prompt input. Also allow empty passwords, to be able to use guest accounts.
Matti Hamalainen <ccr@tnsp.org>
parents: 210
diff changeset
1037
c40329e95445 Trim both left and right side of username+password prompt input. Also allow empty passwords, to be able to use guest accounts.
Matti Hamalainen <ccr@tnsp.org>
parents: 210
diff changeset
1038 if (allowEmpty || strlen(ptr) > 0)
c40329e95445 Trim both left and right side of username+password prompt input. Also allow empty passwords, to be able to use guest accounts.
Matti Hamalainen <ccr@tnsp.org>
parents: 210
diff changeset
1039 return th_strdup(ptr);
196
edd5ce3e5399 Add simplistic username/password requester if none given on commandline or config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 195
diff changeset
1040 else
edd5ce3e5399 Add simplistic username/password requester if none given on commandline or config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 195
diff changeset
1041 return NULL;
edd5ce3e5399 Add simplistic username/password requester if none given on commandline or config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 195
diff changeset
1042 }
168
2e4850ece456 Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 165
diff changeset
1043
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1044 int main(int argc, char *argv[])
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1045 {
168
2e4850ece456 Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 165
diff changeset
1046 nn_conn_t *conn = NULL;
2e4850ece456 Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 165
diff changeset
1047 int curVis = ERR, updateCount = 0;
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1048 struct hostent *tmpHost;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1049 BOOL argsOK, isError = FALSE,
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1050 exitProg = FALSE,
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1051 colorSet = FALSE,
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1052 cursesInit = FALSE,
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1053 networkInit = FALSE,
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1054 insertMode = TRUE;
96
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
1055 time_t prevTime;
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1056 char *tmpStr;
168
2e4850ece456 Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 165
diff changeset
1057 nn_editbuf_t *editBuf = nn_editbuf_new(NN_TMPBUF_SIZE);
89
c2d916b340bf Change some typedef names; Add struct for user list handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
1058 nn_editbuf_t *histBuf[SET_MAX_HISTORY+2];
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1059 int histPos = 0, histMax = 0;
221
f6160051b72e Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 218
diff changeset
1060 BOOL firstUpdate = TRUE;
154
e8f67e344aaf Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
1061
e8f67e344aaf Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
1062 cfgitem_t *tmpcfg;
e8f67e344aaf Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
1063 char *homeDir = NULL;
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1064
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1065 memset(histBuf, 0, sizeof(histBuf));
230
b64500bb7fbe Some yet-unused backbuffer related code.
Matti Hamalainen <ccr@tnsp.org>
parents: 229
diff changeset
1066 backBuf = nn_ringbuf_new(SET_BACKBUF_LEN);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1067
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1068 /* Initialize */
195
829457be9eea Build system changes to support (in a big kludgy manner) icon and version information resource generation for Win32 binaries.
Matti Hamalainen <ccr@tnsp.org>
parents: 191
diff changeset
1069 th_init("NNChat", "Newbie Nudes chat client", NN_VERSION,
237
52a2f06fd41c Update copyright years.
Matti Hamalainen <ccr@tnsp.org>
parents: 236
diff changeset
1070 "Written and designed by Anonymous Finnish Guy (C) 2008-2011",
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1071 "This software is freeware, use and distribute as you wish.");
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1072 th_verbosityLevel = 0;
133
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
1073
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
1074 /* Read config */
148
9da39d090ef1 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 147
diff changeset
1075 tmpcfg = NULL;
133
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
1076 th_cfg_add_comment(&tmpcfg, "General settings");
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
1077 th_cfg_add_string(&tmpcfg, "username", &optUserName, NULL);
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
1078 th_cfg_add_string(&tmpcfg, "password", &optPassword, NULL);
150
db5e7a1f1eb3 Add comment in config file about format of user color setting.
Matti Hamalainen <ccr@tnsp.org>
parents: 149
diff changeset
1079 th_cfg_add_comment(&tmpcfg, "Default color as a hex-triplet");
133
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
1080 th_cfg_add_hexvalue(&tmpcfg, "color", &optUserColor, optUserColor);
149
a4d6707161a7 Add config file option for default setting of ignore mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
1081
a4d6707161a7 Add config file option for default setting of ignore mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
1082 th_cfg_add_comment(&tmpcfg, "Default setting of ignore mode");
151
303db1141147 Oops, should be th_cfg_add_bool() instead of th_cfg_add_boolean()
Matti Hamalainen <ccr@tnsp.org>
parents: 150
diff changeset
1083 th_cfg_add_bool(&tmpcfg, "ignore", &setIgnoreMode, setIgnoreMode);
149
a4d6707161a7 Add config file option for default setting of ignore mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
1084 th_cfg_add_comment(&tmpcfg, "People to be ignored when ignore mode is enabled");
a4d6707161a7 Add config file option for default setting of ignore mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
1085 th_cfg_add_string_list(&tmpcfg, "ignore_list", &nnIgnoreList);
264
4c1c18a388d9 Add configuration setting and functionality for random "keepalive" messages to avoid idle timeout kicks from chat.
Matti Hamalainen <ccr@tnsp.org>
parents: 258
diff changeset
1086
4c1c18a388d9 Add configuration setting and functionality for random "keepalive" messages to avoid idle timeout kicks from chat.
Matti Hamalainen <ccr@tnsp.org>
parents: 258
diff changeset
1087 th_cfg_add_comment(&tmpcfg, "Random messages for idle timeout protection. If none are set, plain '.' is used.");
4c1c18a388d9 Add configuration setting and functionality for random "keepalive" messages to avoid idle timeout kicks from chat.
Matti Hamalainen <ccr@tnsp.org>
parents: 258
diff changeset
1088 th_cfg_add_string_list(&tmpcfg, "idle_messages", &setIdleMessages);
4c1c18a388d9 Add configuration setting and functionality for random "keepalive" messages to avoid idle timeout kicks from chat.
Matti Hamalainen <ccr@tnsp.org>
parents: 258
diff changeset
1089
133
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
1090 th_cfg_add_section(&cfg, "general", tmpcfg);
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
1091
264
4c1c18a388d9 Add configuration setting and functionality for random "keepalive" messages to avoid idle timeout kicks from chat.
Matti Hamalainen <ccr@tnsp.org>
parents: 258
diff changeset
1092
133
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
1093 tmpcfg = NULL;
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
1094 th_cfg_add_comment(&tmpcfg, "Chat server hostname or IP address");
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
1095 th_cfg_add_string(&tmpcfg, "host", &optServer, optServer);
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
1096 th_cfg_add_comment(&tmpcfg, "Default port to connect to (8002 = public room, 8003 = passion pit, 8005 = members only)");
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
1097 th_cfg_add_int(&tmpcfg, "port", &optPort, optPort);
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
1098 th_cfg_add_section(&cfg, "server", tmpcfg);
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
1099
239
b7e7ed741a18 Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
1100 tmpcfg = NULL;
b7e7ed741a18 Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
1101 th_cfg_add_comment(&tmpcfg, "Enable logging");
247
fce4e2e31d69 Add the config section ...
Matti Hamalainen <ccr@tnsp.org>
parents: 242
diff changeset
1102 th_cfg_add_bool(&tmpcfg, "enable", &optLogEnable, optLogEnable);
242
cb86d7543be2 Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
1103 th_cfg_add_comment(&tmpcfg, "Log filename format");
247
fce4e2e31d69 Add the config section ...
Matti Hamalainen <ccr@tnsp.org>
parents: 242
diff changeset
1104 th_cfg_add_string(&tmpcfg, "filename", &optLogFilename, optLogFilename);
fce4e2e31d69 Add the config section ...
Matti Hamalainen <ccr@tnsp.org>
parents: 242
diff changeset
1105 th_cfg_add_section(&cfg, "logging", tmpcfg);
239
b7e7ed741a18 Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
1106
154
e8f67e344aaf Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
1107 #ifdef __WIN32
e8f67e344aaf Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
1108 {
e8f67e344aaf Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
1109 char tmpPath[MAX_PATH];
e8f67e344aaf Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
1110 if (SHGetFolderPath(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, tmpPath) == S_OK)
e8f67e344aaf Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
1111 homeDir = th_strdup(tmpPath);
197
e0ec2280a778 Implement browser launching on Windows via ShellExecute().
Matti Hamalainen <ccr@tnsp.org>
parents: 196
diff changeset
1112
e0ec2280a778 Implement browser launching on Windows via ShellExecute().
Matti Hamalainen <ccr@tnsp.org>
parents: 196
diff changeset
1113 CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
154
e8f67e344aaf Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
1114 }
e8f67e344aaf Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
1115 #else
172
ffba05eb578c Make a copy of getenv("HOME") result instead of using it directly.
Matti Hamalainen <ccr@tnsp.org>
parents: 171
diff changeset
1116 homeDir = th_strdup(getenv("HOME"));
154
e8f67e344aaf Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
1117 #endif
e8f67e344aaf Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
1118
e8f67e344aaf Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
1119 if (homeDir != NULL) {
e8f67e344aaf Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
1120 FILE *cfgfile;
e8f67e344aaf Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
1121 setConfigFile = th_strdup_printf("%s" SET_DIR_SEPARATOR "%s", homeDir, SET_CONFIG_FILE);
e8f67e344aaf Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
1122
e8f67e344aaf Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
1123 THMSG(0, "Reading configuration from '%s'.\n", setConfigFile);
e8f67e344aaf Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
1124
e8f67e344aaf Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
1125 if ((cfgfile = fopen(setConfigFile, "r")) != NULL)
e8f67e344aaf Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
1126 th_cfg_read(cfgfile, setConfigFile, cfg);
133
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
1127 }
196
edd5ce3e5399 Add simplistic username/password requester if none given on commandline or config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 195
diff changeset
1128
137
fad8c31e41e6 Move browser code around a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
1129 setBrowser = getenv("BROWSER");
fad8c31e41e6 Move browser code around a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
1130 if (setBrowser == NULL)
fad8c31e41e6 Move browser code around a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
1131 setBrowser = "firefox";
fad8c31e41e6 Move browser code around a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
1132
153
f1684884fd56 Comment cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 151
diff changeset
1133 /* Parse command line arguments */
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1134 argsOK = th_args_process(argc, argv, optList, optListN,
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1135 argHandleOpt, argHandleFile, FALSE);
26
b84fc46c6035 Improved color hex triplet parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
1136
198
21a37995c3fb Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents: 197
diff changeset
1137 if (optUserNameCmd != NULL) {
21a37995c3fb Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents: 197
diff changeset
1138 optUserName = optUserNameCmd;
21a37995c3fb Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents: 197
diff changeset
1139 optPassword = optPasswordCmd;
21a37995c3fb Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents: 197
diff changeset
1140 }
21a37995c3fb Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents: 197
diff changeset
1141
153
f1684884fd56 Comment cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 151
diff changeset
1142 /* Check if we have username and password */
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1143 if (optUserName == NULL || optPassword == NULL) {
196
edd5ce3e5399 Add simplistic username/password requester if none given on commandline or config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 195
diff changeset
1144 printf("\nYou can avoid this prompt by issuing '/save' after logging in.\n\n");
211
c40329e95445 Trim both left and right side of username+password prompt input. Also allow empty passwords, to be able to use guest accounts.
Matti Hamalainen <ccr@tnsp.org>
parents: 210
diff changeset
1145 optUserName = promptRequester("NN username: ", FALSE);
c40329e95445 Trim both left and right side of username+password prompt input. Also allow empty passwords, to be able to use guest accounts.
Matti Hamalainen <ccr@tnsp.org>
parents: 210
diff changeset
1146 optPassword = promptRequester("NN password: ", TRUE);
196
edd5ce3e5399 Add simplistic username/password requester if none given on commandline or config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 195
diff changeset
1147 if (optUserName == NULL || optPassword == NULL) {
edd5ce3e5399 Add simplistic username/password requester if none given on commandline or config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 195
diff changeset
1148 THERR("User/pass not specified, get some --help\n");
edd5ce3e5399 Add simplistic username/password requester if none given on commandline or config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 195
diff changeset
1149 return -1;
edd5ce3e5399 Add simplistic username/password requester if none given on commandline or config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 195
diff changeset
1150 }
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1151 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1152
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1153 if (!argsOK)
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1154 return -2;
64
6a3a917303e4 Some random cleanups, bring back WinSock support.
Matti Hamalainen <ccr@tnsp.org>
parents: 63
diff changeset
1155
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1156 /* Allocate userhash */
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1157 if ((nnUsers = nn_userhash_new()) == NULL) {
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1158 THERR("Could not allocate userhash. Fatal error.\n");
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1159 return -105;
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1160 }
64
6a3a917303e4 Some random cleanups, bring back WinSock support.
Matti Hamalainen <ccr@tnsp.org>
parents: 63
diff changeset
1161
264
4c1c18a388d9 Add configuration setting and functionality for random "keepalive" messages to avoid idle timeout kicks from chat.
Matti Hamalainen <ccr@tnsp.org>
parents: 258
diff changeset
1162 /* If no idle messages are set, add default */
4c1c18a388d9 Add configuration setting and functionality for random "keepalive" messages to avoid idle timeout kicks from chat.
Matti Hamalainen <ccr@tnsp.org>
parents: 258
diff changeset
1163 if (setIdleMessages == NULL) {
4c1c18a388d9 Add configuration setting and functionality for random "keepalive" messages to avoid idle timeout kicks from chat.
Matti Hamalainen <ccr@tnsp.org>
parents: 258
diff changeset
1164 th_llist_append(&setIdleMessages, th_strdup("."));
4c1c18a388d9 Add configuration setting and functionality for random "keepalive" messages to avoid idle timeout kicks from chat.
Matti Hamalainen <ccr@tnsp.org>
parents: 258
diff changeset
1165 }
4c1c18a388d9 Add configuration setting and functionality for random "keepalive" messages to avoid idle timeout kicks from chat.
Matti Hamalainen <ccr@tnsp.org>
parents: 258
diff changeset
1166
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1167 /* Open logfile */
242
cb86d7543be2 Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
1168 logFileOpen();
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1169
264
4c1c18a388d9 Add configuration setting and functionality for random "keepalive" messages to avoid idle timeout kicks from chat.
Matti Hamalainen <ccr@tnsp.org>
parents: 258
diff changeset
1170 /* Initialize network */
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1171 if (!nn_network_init()) {
91
acfc4b4bc180 Create network initialization functions in libnnchat and move Win32/WinSock code there.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
1172 THERR("Could not initialize network subsystem.\n");
acfc4b4bc180 Create network initialization functions in libnnchat and move Win32/WinSock code there.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
1173 goto err_exit;
acfc4b4bc180 Create network initialization functions in libnnchat and move Win32/WinSock code there.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
1174 } else
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1175 networkInit = TRUE;
68
3ab7751fdad1 MingW compatibility, with one ugly kludge.
Matti Hamalainen <ccr@tnsp.org>
parents: 67
diff changeset
1176
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1177 /* Okay ... */
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1178 THMSG(1, "Trying to resolve host '%s' ...\n", optServer);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1179 tmpHost = gethostbyname(optServer);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1180 if (tmpHost == NULL) {
174
f5518f10dd1a Don't use hstrerror(), but strerror() instead.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
1181 THERR("Could not resolve hostname: %s.\n", strerror(h_errno));
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1182 goto err_exit;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1183 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1184 THMSG(2, "True hostname: %s\n", tmpHost->h_name);
26
b84fc46c6035 Improved color hex triplet parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
1185
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1186 /* To emulate the official client, we first make a request for
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1187 * policy file, even though we don't use it for anything...
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1188 */
170
8d4cdbeae606 Clean up connection forming.
Matti Hamalainen <ccr@tnsp.org>
parents: 168
diff changeset
1189 conn = nn_conn_open((struct in_addr *) tmpHost->h_addr, 843);
8d4cdbeae606 Clean up connection forming.
Matti Hamalainen <ccr@tnsp.org>
parents: 168
diff changeset
1190 if (!nn_conn_check(conn)) {
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1191 THERR("Policy file request connection setup failed!\n");
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1192 goto err_exit;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1193 }
168
2e4850ece456 Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 165
diff changeset
1194
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1195 tmpStr = "<policy-file-request/>";
168
2e4850ece456 Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 165
diff changeset
1196 if (nn_conn_send_buf(conn, tmpStr, strlen(tmpStr) + 1) == FALSE) {
96
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
1197 THERR("Failed to send policy file request.\n");
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1198 goto err_exit;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1199 } else {
168
2e4850ece456 Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 165
diff changeset
1200 int cres = nn_conn_pull(conn);
2e4850ece456 Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 165
diff changeset
1201 if (cres == 0) {
2e4850ece456 Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 165
diff changeset
1202 THMSG(2, "Probe got: %s\n", conn->buf);
2e4850ece456 Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 165
diff changeset
1203 } else {
2e4850ece456 Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 165
diff changeset
1204 THMSG(2, "Could not get policy probe.\n");
2e4850ece456 Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 165
diff changeset
1205 }
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1206 }
168
2e4850ece456 Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 165
diff changeset
1207 nn_conn_close(conn);
26
b84fc46c6035 Improved color hex triplet parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
1208
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1209 /* Okay, now do the proper connection ... */
170
8d4cdbeae606 Clean up connection forming.
Matti Hamalainen <ccr@tnsp.org>
parents: 168
diff changeset
1210 conn = nn_conn_open((struct in_addr *) tmpHost->h_addr, optPort);
8d4cdbeae606 Clean up connection forming.
Matti Hamalainen <ccr@tnsp.org>
parents: 168
diff changeset
1211 if (!nn_conn_check(conn)) {
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1212 THERR("Main connection setup failed!\n");
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1213 goto err_exit;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1214 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1215
236
71fa0364c058 Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
1216 conn->errfunc = errorFunc;
71fa0364c058 Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
1217 conn->msgfunc = messageFunc;
71fa0364c058 Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
1218
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1219 THMSG(1, "Connected, logging in as '%s', site '%s'.\n", optUserName, optSite);
198
21a37995c3fb Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents: 197
diff changeset
1220 optUserNameEnc = nn_dblencode_str(optUserName);
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1221 tmpStr = nn_dblencode_str(optSite);
198
21a37995c3fb Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents: 197
diff changeset
1222 nn_conn_send_msg(conn, optUserNameEnc, "%%2Flogin%%20%%2Dsite%%20%s%%20%%2Dpassword%%20%s", tmpStr, optPassword);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1223 th_free(tmpStr);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1224
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1225 /* Initialize NCurses */
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1226 if (!optDaemon) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1227 if (LINES < 0 || LINES > 1000) LINES = 24;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1228 if (COLS < 0 || COLS > 1000) COLS = 80;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1229 initscr();
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1230 raw();
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1231 keypad(stdscr, TRUE);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1232 noecho();
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1233 meta(stdscr, TRUE);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1234 timeout(SET_DELAY);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1235 curVis = curs_set(0);
110
8af4072dc31a Fix Win32/MinGW/PDcurses issues.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
1236
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1237 if (has_colors()) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1238 start_color();
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1239
185
73bdf1ede348 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 184
diff changeset
1240 init_pair( 1, COLOR_RED, COLOR_BLACK);
73bdf1ede348 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 184
diff changeset
1241 init_pair( 2, COLOR_GREEN, COLOR_BLACK);
73bdf1ede348 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 184
diff changeset
1242 init_pair( 3, COLOR_YELLOW, COLOR_BLACK);
73bdf1ede348 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 184
diff changeset
1243 init_pair( 4, COLOR_BLUE, COLOR_BLACK);
73bdf1ede348 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 184
diff changeset
1244 init_pair( 5, COLOR_MAGENTA, COLOR_BLACK);
73bdf1ede348 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 184
diff changeset
1245 init_pair( 6, COLOR_CYAN, COLOR_BLACK);
73bdf1ede348 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 184
diff changeset
1246 init_pair( 7, COLOR_WHITE, COLOR_BLACK);
73bdf1ede348 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 184
diff changeset
1247 init_pair( 8, COLOR_BLACK, COLOR_BLACK);
28
512775f6b081 A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
1248
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1249 init_pair(10, COLOR_BLACK, COLOR_RED);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1250 init_pair(11, COLOR_WHITE, COLOR_RED);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1251 init_pair(12, COLOR_GREEN, COLOR_RED);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1252 init_pair(13, COLOR_YELLOW, COLOR_RED);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1253 init_pair(14, COLOR_BLUE, COLOR_RED);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1254 init_pair(15, COLOR_MAGENTA, COLOR_RED);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1255 init_pair(16, COLOR_CYAN, COLOR_RED);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1256 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1257
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1258 cursesInit = TRUE;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1259
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1260 if (!initializeWindows())
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1261 goto err_exit;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1262
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1263 nn_editbuf_clear(editBuf);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1264 printEditBuf("", editBuf);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1265 updateStatus(insertMode);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1266 }
100
ed4067c10a8a Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
1267
264
4c1c18a388d9 Add configuration setting and functionality for random "keepalive" messages to avoid idle timeout kicks from chat.
Matti Hamalainen <ccr@tnsp.org>
parents: 258
diff changeset
1268 /* Initialize random numbers */
96
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
1269 prevTime = time(NULL);
264
4c1c18a388d9 Add configuration setting and functionality for random "keepalive" messages to avoid idle timeout kicks from chat.
Matti Hamalainen <ccr@tnsp.org>
parents: 258
diff changeset
1270 srandom((int) prevTime);
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1271
264
4c1c18a388d9 Add configuration setting and functionality for random "keepalive" messages to avoid idle timeout kicks from chat.
Matti Hamalainen <ccr@tnsp.org>
parents: 258
diff changeset
1272 /* Enter mainloop */
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1273 while (!isError && !exitProg) {
168
2e4850ece456 Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 165
diff changeset
1274 int cres = nn_conn_pull(conn);
2e4850ece456 Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 165
diff changeset
1275 if (cres == 0) {
2e4850ece456 Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 165
diff changeset
1276 do {
2e4850ece456 Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 165
diff changeset
1277 size_t bufLen = strlen(conn->ptr) + 1;
2e4850ece456 Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 165
diff changeset
1278 int result = handleProtocol(conn, conn->ptr, bufLen);
2e4850ece456 Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 165
diff changeset
1279
2e4850ece456 Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 165
diff changeset
1280 if (result > 0) {
2e4850ece456 Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 165
diff changeset
1281 /* Couldn't handle the message for some reason */
2e4850ece456 Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 165
diff changeset
1282 printMsg("Could not handle: %s\n", conn->ptr);
2e4850ece456 Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 165
diff changeset
1283 } else if (result < 0) {
2e4850ece456 Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 165
diff changeset
1284 /* Fatal error, quit */
2e4850ece456 Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 165
diff changeset
1285 errorMsg("Fatal error with message: %s\n", conn->ptr);
2e4850ece456 Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 165
diff changeset
1286 isError = TRUE;
2e4850ece456 Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 165
diff changeset
1287 }
2e4850ece456 Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 165
diff changeset
1288
2e4850ece456 Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 165
diff changeset
1289 conn->got -= bufLen;
2e4850ece456 Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 165
diff changeset
1290 conn->ptr += bufLen;
2e4850ece456 Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 165
diff changeset
1291 } while (conn->got > 0 && !isError);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1292 }
168
2e4850ece456 Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 165
diff changeset
1293 if (!nn_conn_check(conn))
2e4850ece456 Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 165
diff changeset
1294 isError = TRUE;
2e4850ece456 Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 165
diff changeset
1295
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1296 /* Handle user input */
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1297 if (!optDaemon) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1298 int c, cnt = 0;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1299 BOOL update = FALSE;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1300
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1301 /* Handle several buffered keypresses at once */
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1302 do {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1303 c = wgetch(stdscr);
77
e8c9d7d13866 Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
1304 if (c == 0x1b) {
e8c9d7d13866 Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
1305 c = wgetch(stdscr);
e8c9d7d13866 Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
1306 if (c == 'O') {
e8c9d7d13866 Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
1307 c = wgetch(stdscr);
e8c9d7d13866 Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
1308 switch (c) {
e8c9d7d13866 Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
1309 case 'd': c = 0x204; break;
e8c9d7d13866 Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
1310 case 'c': c = 0x206; break;
e8c9d7d13866 Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
1311 default:
e8c9d7d13866 Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
1312 printMsg("Unhandled ESC-O key sequence 0x%02x\n", c);
e8c9d7d13866 Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
1313 break;
e8c9d7d13866 Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
1314 }
206
af32c038cf1e Add some hardcoded translations for certain terminal keycodes that NCurses 4.x on Solaris didn't handle .. urgh.
Matti Hamalainen <ccr@tnsp.org>
parents: 203
diff changeset
1315 } else
af32c038cf1e Add some hardcoded translations for certain terminal keycodes that NCurses 4.x on Solaris didn't handle .. urgh.
Matti Hamalainen <ccr@tnsp.org>
parents: 203
diff changeset
1316 if (c == '[') {
af32c038cf1e Add some hardcoded translations for certain terminal keycodes that NCurses 4.x on Solaris didn't handle .. urgh.
Matti Hamalainen <ccr@tnsp.org>
parents: 203
diff changeset
1317 c = wgetch(stdscr);
af32c038cf1e Add some hardcoded translations for certain terminal keycodes that NCurses 4.x on Solaris didn't handle .. urgh.
Matti Hamalainen <ccr@tnsp.org>
parents: 203
diff changeset
1318 switch (c) {
252
dcf78e2c458c Improve log filename format parsing; Add special casing for handling of function keys for certain terminal types.
Matti Hamalainen <ccr@tnsp.org>
parents: 247
diff changeset
1319 case 0x31:
dcf78e2c458c Improve log filename format parsing; Add special casing for handling of function keys for certain terminal types.
Matti Hamalainen <ccr@tnsp.org>
parents: 247
diff changeset
1320 c = wgetch(stdscr);
dcf78e2c458c Improve log filename format parsing; Add special casing for handling of function keys for certain terminal types.
Matti Hamalainen <ccr@tnsp.org>
parents: 247
diff changeset
1321 if (c >= 0x31 && c <= 0x39)
dcf78e2c458c Improve log filename format parsing; Add special casing for handling of function keys for certain terminal types.
Matti Hamalainen <ccr@tnsp.org>
parents: 247
diff changeset
1322 c = KEY_F(c - 0x30);
dcf78e2c458c Improve log filename format parsing; Add special casing for handling of function keys for certain terminal types.
Matti Hamalainen <ccr@tnsp.org>
parents: 247
diff changeset
1323 else
dcf78e2c458c Improve log filename format parsing; Add special casing for handling of function keys for certain terminal types.
Matti Hamalainen <ccr@tnsp.org>
parents: 247
diff changeset
1324 c = ERR;
dcf78e2c458c Improve log filename format parsing; Add special casing for handling of function keys for certain terminal types.
Matti Hamalainen <ccr@tnsp.org>
parents: 247
diff changeset
1325 break;
dcf78e2c458c Improve log filename format parsing; Add special casing for handling of function keys for certain terminal types.
Matti Hamalainen <ccr@tnsp.org>
parents: 247
diff changeset
1326
206
af32c038cf1e Add some hardcoded translations for certain terminal keycodes that NCurses 4.x on Solaris didn't handle .. urgh.
Matti Hamalainen <ccr@tnsp.org>
parents: 203
diff changeset
1327 case 0x32: c = KEY_IC; break;
af32c038cf1e Add some hardcoded translations for certain terminal keycodes that NCurses 4.x on Solaris didn't handle .. urgh.
Matti Hamalainen <ccr@tnsp.org>
parents: 203
diff changeset
1328 case 0x33: c = KEY_DC; break;
af32c038cf1e Add some hardcoded translations for certain terminal keycodes that NCurses 4.x on Solaris didn't handle .. urgh.
Matti Hamalainen <ccr@tnsp.org>
parents: 203
diff changeset
1329
af32c038cf1e Add some hardcoded translations for certain terminal keycodes that NCurses 4.x on Solaris didn't handle .. urgh.
Matti Hamalainen <ccr@tnsp.org>
parents: 203
diff changeset
1330 case 0x35: c = KEY_PPAGE; break;
af32c038cf1e Add some hardcoded translations for certain terminal keycodes that NCurses 4.x on Solaris didn't handle .. urgh.
Matti Hamalainen <ccr@tnsp.org>
parents: 203
diff changeset
1331 case 0x36: c = KEY_NPAGE; break;
af32c038cf1e Add some hardcoded translations for certain terminal keycodes that NCurses 4.x on Solaris didn't handle .. urgh.
Matti Hamalainen <ccr@tnsp.org>
parents: 203
diff changeset
1332
af32c038cf1e Add some hardcoded translations for certain terminal keycodes that NCurses 4.x on Solaris didn't handle .. urgh.
Matti Hamalainen <ccr@tnsp.org>
parents: 203
diff changeset
1333 case 0x37: c = KEY_HOME; break;
af32c038cf1e Add some hardcoded translations for certain terminal keycodes that NCurses 4.x on Solaris didn't handle .. urgh.
Matti Hamalainen <ccr@tnsp.org>
parents: 203
diff changeset
1334 case 0x38: c = KEY_END; break;
af32c038cf1e Add some hardcoded translations for certain terminal keycodes that NCurses 4.x on Solaris didn't handle .. urgh.
Matti Hamalainen <ccr@tnsp.org>
parents: 203
diff changeset
1335
af32c038cf1e Add some hardcoded translations for certain terminal keycodes that NCurses 4.x on Solaris didn't handle .. urgh.
Matti Hamalainen <ccr@tnsp.org>
parents: 203
diff changeset
1336 default:
af32c038cf1e Add some hardcoded translations for certain terminal keycodes that NCurses 4.x on Solaris didn't handle .. urgh.
Matti Hamalainen <ccr@tnsp.org>
parents: 203
diff changeset
1337 printMsg("Unhandled ESC-[*~ key sequence 0x%02x\n", c);
af32c038cf1e Add some hardcoded translations for certain terminal keycodes that NCurses 4.x on Solaris didn't handle .. urgh.
Matti Hamalainen <ccr@tnsp.org>
parents: 203
diff changeset
1338 c = ERR;
af32c038cf1e Add some hardcoded translations for certain terminal keycodes that NCurses 4.x on Solaris didn't handle .. urgh.
Matti Hamalainen <ccr@tnsp.org>
parents: 203
diff changeset
1339 break;
af32c038cf1e Add some hardcoded translations for certain terminal keycodes that NCurses 4.x on Solaris didn't handle .. urgh.
Matti Hamalainen <ccr@tnsp.org>
parents: 203
diff changeset
1340 }
af32c038cf1e Add some hardcoded translations for certain terminal keycodes that NCurses 4.x on Solaris didn't handle .. urgh.
Matti Hamalainen <ccr@tnsp.org>
parents: 203
diff changeset
1341 /* Get the trailing ~ */
af32c038cf1e Add some hardcoded translations for certain terminal keycodes that NCurses 4.x on Solaris didn't handle .. urgh.
Matti Hamalainen <ccr@tnsp.org>
parents: 203
diff changeset
1342 if (c != ERR)
af32c038cf1e Add some hardcoded translations for certain terminal keycodes that NCurses 4.x on Solaris didn't handle .. urgh.
Matti Hamalainen <ccr@tnsp.org>
parents: 203
diff changeset
1343 wgetch(stdscr);
77
e8c9d7d13866 Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
1344 } else {
e8c9d7d13866 Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
1345 printMsg("Unhandled ESC key sequence 0x%02x\n", c);
e8c9d7d13866 Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
1346 continue;
e8c9d7d13866 Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
1347 }
e8c9d7d13866 Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
1348 }
e8c9d7d13866 Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
1349
119
4bc63a535acb Fix some PDCurses incompatibilities and remove some Win32/PDCurses specific hacks.
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
1350
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1351 switch (c) {
74
98004129202a Portability fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
1352 #ifdef KEY_RESIZE
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1353 case KEY_RESIZE:
119
4bc63a535acb Fix some PDCurses incompatibilities and remove some Win32/PDCurses specific hacks.
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
1354 resize_term(0, 0);
4bc63a535acb Fix some PDCurses incompatibilities and remove some Win32/PDCurses specific hacks.
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
1355 erase();
134
f367fc14021a Use resize_term() and erase() on resize event also with ncurses and not only with PDcurses.
Matti Hamalainen <ccr@tnsp.org>
parents: 133
diff changeset
1356 #ifdef PDCURSES
119
4bc63a535acb Fix some PDCurses incompatibilities and remove some Win32/PDCurses specific hacks.
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
1357 timeout(SET_DELAY);
4bc63a535acb Fix some PDCurses incompatibilities and remove some Win32/PDCurses specific hacks.
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
1358 #endif
4bc63a535acb Fix some PDCurses incompatibilities and remove some Win32/PDCurses specific hacks.
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
1359
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1360 if (!initializeWindows()) {
119
4bc63a535acb Fix some PDCurses incompatibilities and remove some Win32/PDCurses specific hacks.
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
1361 errorMsg("Error resizing curses windows\n");
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1362 isError = TRUE;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1363 }
119
4bc63a535acb Fix some PDCurses incompatibilities and remove some Win32/PDCurses specific hacks.
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
1364 update = TRUE;
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1365 break;
74
98004129202a Portability fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
1366 #endif
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1367
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1368 case KEY_ENTER:
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1369 case '\n':
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1370 case '\r':
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1371 /* Call the user input handler */
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1372 if (editBuf->len > 0) {
168
2e4850ece456 Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 165
diff changeset
1373 int result;
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1374
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1375 if (histMax > 0) {
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1376 nn_editbuf_free(histBuf[SET_MAX_HISTORY+1]);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1377 histBuf[SET_MAX_HISTORY+1] = NULL;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1378 memmove(&histBuf[2], &histBuf[1], histMax * sizeof(histBuf[0]));
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1379 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1380
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1381 histPos = 0;
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1382 histBuf[1] = nn_editbuf_copy(editBuf);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1383 if (histMax < SET_MAX_HISTORY) histMax++;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1384
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1385 nn_editbuf_insert(editBuf, editBuf->len, 0);
168
2e4850ece456 Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 165
diff changeset
1386 result = handleUserInput(conn, editBuf->data, editBuf->len);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1387
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1388 nn_editbuf_clear(editBuf);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1389
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1390 if (result < 0) {
96
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
1391 errorMsg("Fatal error handling user input: %s\n", editBuf->data);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1392 isError = TRUE;
264
4c1c18a388d9 Add configuration setting and functionality for random "keepalive" messages to avoid idle timeout kicks from chat.
Matti Hamalainen <ccr@tnsp.org>
parents: 258
diff changeset
1393 } else {
4c1c18a388d9 Add configuration setting and functionality for random "keepalive" messages to avoid idle timeout kicks from chat.
Matti Hamalainen <ccr@tnsp.org>
parents: 258
diff changeset
1394 /* Update time value of last sent message for unidle timeouts */
4c1c18a388d9 Add configuration setting and functionality for random "keepalive" messages to avoid idle timeout kicks from chat.
Matti Hamalainen <ccr@tnsp.org>
parents: 258
diff changeset
1395 prevTime = time(NULL);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1396 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1397
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1398 update = TRUE;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1399 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1400 break;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1401
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1402 case KEY_UP: /* Backwards in input history */
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1403 if (histPos == 0) {
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1404 nn_editbuf_free(histBuf[0]);
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1405 histBuf[0] = nn_editbuf_copy(editBuf);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1406 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1407 if (histPos < histMax) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1408 histPos++;
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1409 nn_editbuf_free(editBuf);
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1410 editBuf = nn_editbuf_copy(histBuf[histPos]);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1411 update = TRUE;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1412 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1413 break;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1414
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1415 case KEY_DOWN: /* Forwards in input history */
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1416 if (histPos > 0) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1417 histPos--;
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1418 nn_editbuf_free(editBuf);
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1419 editBuf = nn_editbuf_copy(histBuf[histPos]);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1420 update = TRUE;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1421 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1422 break;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1423
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1424 case 0x204: /* ctrl+left arrow = Skip words left */
232
3140ea43d4a3 Handle certain terminals differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 230
diff changeset
1425 case 0x20b:
74
98004129202a Portability fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
1426 while (editBuf->pos > 0 && isspace((int) editBuf->data[editBuf->pos - 1]))
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1427 editBuf->pos--;
74
98004129202a Portability fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
1428 while (editBuf->pos > 0 && !isspace((int) editBuf->data[editBuf->pos - 1]))
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1429 editBuf->pos--;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1430 update = TRUE;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1431 break;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1432
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1433 case 0x206: /* ctrl+right arrow = Skip words right */
232
3140ea43d4a3 Handle certain terminals differently.
Matti Hamalainen <ccr@tnsp.org>
parents: 230
diff changeset
1434 case 0x210:
74
98004129202a Portability fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
1435 while (editBuf->pos < editBuf->len && isspace((int) editBuf->data[editBuf->pos]))
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1436 editBuf->pos++;
74
98004129202a Portability fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
1437 while (editBuf->pos < editBuf->len && !isspace((int) editBuf->data[editBuf->pos]))
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1438 editBuf->pos++;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1439 if (editBuf->pos > editBuf->len)
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1440 editBuf->pos = editBuf->len;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1441 update = TRUE;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1442 break;
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1443
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1444 case KEY_HOME: nn_editbuf_setpos(editBuf, 0); update = TRUE; break;
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1445 case KEY_END: nn_editbuf_setpos(editBuf, editBuf->len); update = TRUE; break;
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1446 case KEY_LEFT: nn_editbuf_setpos(editBuf, editBuf->pos - 1); update = TRUE; break;
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1447 case KEY_RIGHT: nn_editbuf_setpos(editBuf, editBuf->pos + 1); update = TRUE; break;
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1448
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1449 case KEY_BACKSPACE:
73
c56e766acce1 Support keycode 0x08 as backspace for Win32 compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
1450 case 0x08:
206
af32c038cf1e Add some hardcoded translations for certain terminal keycodes that NCurses 4.x on Solaris didn't handle .. urgh.
Matti Hamalainen <ccr@tnsp.org>
parents: 203
diff changeset
1451 case 0x7f:
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1452 nn_editbuf_delete(editBuf, editBuf->pos - 1);
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1453 nn_editbuf_setpos(editBuf, editBuf->pos - 1);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1454 update = TRUE;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1455 break;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1456
122
e564dd9df07c Change some key defines.
Matti Hamalainen <ccr@tnsp.org>
parents: 121
diff changeset
1457 case KEY_DC: /* Delete character */
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1458 nn_editbuf_delete(editBuf, editBuf->pos);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1459 update = TRUE;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1460 break;
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1461
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1462
175
86904a43c339 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
1463 case KEY_IC: /* Ins = Toggle insert / overwrite mode */
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1464 insertMode = !insertMode;
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1465 update = TRUE;
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1466 break;
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1467
208
6c5d136b6e6a Use curses KEY_F(n) macros for defining function keys instead of hardcoded values.
Matti Hamalainen <ccr@tnsp.org>
parents: 207
diff changeset
1468 case KEY_F(2): /* F2 = Clear editbuffer */
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1469 nn_editbuf_clear(editBuf);
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1470 update = TRUE;
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1471 break;
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1472
208
6c5d136b6e6a Use curses KEY_F(n) macros for defining function keys instead of hardcoded values.
Matti Hamalainen <ccr@tnsp.org>
parents: 207
diff changeset
1473 case KEY_F(5): /* F5 = Ignore mode */
149
a4d6707161a7 Add config file option for default setting of ignore mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
1474 setIgnoreMode = !setIgnoreMode;
a4d6707161a7 Add config file option for default setting of ignore mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
1475 printMsg("Ignore mode = %s\n", setIgnoreMode ? "ON" : "OFF");
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1476 break;
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1477
208
6c5d136b6e6a Use curses KEY_F(n) macros for defining function keys instead of hardcoded values.
Matti Hamalainen <ccr@tnsp.org>
parents: 207
diff changeset
1478 case KEY_F(7): /* F7 = Clear PRV target */
187
c73003485c2d F7 to clear current PRV target.
Matti Hamalainen <ccr@tnsp.org>
parents: 186
diff changeset
1479 if (setTarget) {
c73003485c2d F7 to clear current PRV target.
Matti Hamalainen <ccr@tnsp.org>
parents: 186
diff changeset
1480 printMsg("Cleared PRV target.\n");
c73003485c2d F7 to clear current PRV target.
Matti Hamalainen <ccr@tnsp.org>
parents: 186
diff changeset
1481 setPrvMode = FALSE;
c73003485c2d F7 to clear current PRV target.
Matti Hamalainen <ccr@tnsp.org>
parents: 186
diff changeset
1482 th_free(setTarget);
c73003485c2d F7 to clear current PRV target.
Matti Hamalainen <ccr@tnsp.org>
parents: 186
diff changeset
1483 setTarget = NULL;
c73003485c2d F7 to clear current PRV target.
Matti Hamalainen <ccr@tnsp.org>
parents: 186
diff changeset
1484 update = TRUE;
c73003485c2d F7 to clear current PRV target.
Matti Hamalainen <ccr@tnsp.org>
parents: 186
diff changeset
1485 }
c73003485c2d F7 to clear current PRV target.
Matti Hamalainen <ccr@tnsp.org>
parents: 186
diff changeset
1486 break;
c73003485c2d F7 to clear current PRV target.
Matti Hamalainen <ccr@tnsp.org>
parents: 186
diff changeset
1487
208
6c5d136b6e6a Use curses KEY_F(n) macros for defining function keys instead of hardcoded values.
Matti Hamalainen <ccr@tnsp.org>
parents: 207
diff changeset
1488 case KEY_F(8): /* F8 = switch between PRV */
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1489 if (setPrvMode)
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1490 setPrvMode = FALSE;
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1491 else {
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1492 if (setTarget != NULL)
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1493 setPrvMode = TRUE;
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1494 }
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1495 update = TRUE;
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1496 break;
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1497
203
e7538539de7f Make ^C equivalent of quit (F9).
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
1498 case 0x03: /* ^C = quit */
208
6c5d136b6e6a Use curses KEY_F(n) macros for defining function keys instead of hardcoded values.
Matti Hamalainen <ccr@tnsp.org>
parents: 207
diff changeset
1499 case KEY_F(9): /* F9 = Quit */
175
86904a43c339 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
1500 printMsg("Quitting per user request.\n");
86904a43c339 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
1501 exitProg = TRUE;
86904a43c339 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
1502 break;
86904a43c339 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
1503
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1504 case 0x09: /* Tab = complete username */
107
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
1505 performTabCompletion(editBuf);
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
1506 update = TRUE;
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1507 break;
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1508
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1509 case 0x0c: /* Ctrl + L */
179
8c493b5671bd Add separate updateWindows() function.
Matti Hamalainen <ccr@tnsp.org>
parents: 175
diff changeset
1510 updateWindows();
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1511 break;
122
e564dd9df07c Change some key defines.
Matti Hamalainen <ccr@tnsp.org>
parents: 121
diff changeset
1512
e564dd9df07c Change some key defines.
Matti Hamalainen <ccr@tnsp.org>
parents: 121
diff changeset
1513 case KEY_NPAGE:
e564dd9df07c Change some key defines.
Matti Hamalainen <ccr@tnsp.org>
parents: 121
diff changeset
1514 case KEY_PPAGE:
230
b64500bb7fbe Some yet-unused backbuffer related code.
Matti Hamalainen <ccr@tnsp.org>
parents: 229
diff changeset
1515 #if 0
b64500bb7fbe Some yet-unused backbuffer related code.
Matti Hamalainen <ccr@tnsp.org>
parents: 229
diff changeset
1516 {
b64500bb7fbe Some yet-unused backbuffer related code.
Matti Hamalainen <ccr@tnsp.org>
parents: 229
diff changeset
1517 int nlines, ncol, old;
b64500bb7fbe Some yet-unused backbuffer related code.
Matti Hamalainen <ccr@tnsp.org>
parents: 229
diff changeset
1518 getmaxyx(mainWin, nlines, ncol);
b64500bb7fbe Some yet-unused backbuffer related code.
Matti Hamalainen <ccr@tnsp.org>
parents: 229
diff changeset
1519 nlines /= 2;
b64500bb7fbe Some yet-unused backbuffer related code.
Matti Hamalainen <ccr@tnsp.org>
parents: 229
diff changeset
1520 old = backBufPos;
b64500bb7fbe Some yet-unused backbuffer related code.
Matti Hamalainen <ccr@tnsp.org>
parents: 229
diff changeset
1521
b64500bb7fbe Some yet-unused backbuffer related code.
Matti Hamalainen <ccr@tnsp.org>
parents: 229
diff changeset
1522 if (c == KEY_NPAGE)
b64500bb7fbe Some yet-unused backbuffer related code.
Matti Hamalainen <ccr@tnsp.org>
parents: 229
diff changeset
1523 backBufPos = (backBufPos > nlines) ? backBufPos - nlines : 0;
b64500bb7fbe Some yet-unused backbuffer related code.
Matti Hamalainen <ccr@tnsp.org>
parents: 229
diff changeset
1524 else
b64500bb7fbe Some yet-unused backbuffer related code.
Matti Hamalainen <ccr@tnsp.org>
parents: 229
diff changeset
1525 backBufPos = (backBufPos < );
b64500bb7fbe Some yet-unused backbuffer related code.
Matti Hamalainen <ccr@tnsp.org>
parents: 229
diff changeset
1526
b64500bb7fbe Some yet-unused backbuffer related code.
Matti Hamalainen <ccr@tnsp.org>
parents: 229
diff changeset
1527 if (old != backBufPos)
b64500bb7fbe Some yet-unused backbuffer related code.
Matti Hamalainen <ccr@tnsp.org>
parents: 229
diff changeset
1528 updateMain();
b64500bb7fbe Some yet-unused backbuffer related code.
Matti Hamalainen <ccr@tnsp.org>
parents: 229
diff changeset
1529 }
b64500bb7fbe Some yet-unused backbuffer related code.
Matti Hamalainen <ccr@tnsp.org>
parents: 229
diff changeset
1530 #endif
122
e564dd9df07c Change some key defines.
Matti Hamalainen <ccr@tnsp.org>
parents: 121
diff changeset
1531 break;
e564dd9df07c Change some key defines.
Matti Hamalainen <ccr@tnsp.org>
parents: 121
diff changeset
1532
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1533 case ERR:
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1534 /* Ignore */
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1535 break;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1536
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1537 default:
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1538 if (isprint(c) || c == 0xe4 || c == 0xf6 || c == 0xc4 || c == 0xd6) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1539 if (insertMode)
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1540 nn_editbuf_insert(editBuf, editBuf->pos, c);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1541 else
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1542 nn_editbuf_write(editBuf, editBuf->pos, c);
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1543 nn_editbuf_setpos(editBuf, editBuf->pos + 1);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1544 update = TRUE;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1545 } else {
77
e8c9d7d13866 Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
1546 printMsg("Unhandled key: 0x%02x\n", c);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1547 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1548 break;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1549 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1550 } while (c != ERR && !exitProg && ++cnt < 10);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1551
221
f6160051b72e Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 218
diff changeset
1552 if (update || firstUpdate) {
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1553 /* Update edit line */
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1554 printEditBuf(setPrvMode ? setTarget : "", editBuf);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1555 updateStatus(insertMode);
221
f6160051b72e Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 218
diff changeset
1556 firstUpdate = FALSE; /* a nasty hack ... */
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1557 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1558 } /* !optDaemon */
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1559
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1560 if (++updateCount > 10) {
96
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
1561 time_t tmpTime = time(NULL);
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
1562 if (tmpTime - prevTime > SET_KEEPALIVE) {
264
4c1c18a388d9 Add configuration setting and functionality for random "keepalive" messages to avoid idle timeout kicks from chat.
Matti Hamalainen <ccr@tnsp.org>
parents: 258
diff changeset
1563 int n = random() % th_llist_length(setIdleMessages);
4c1c18a388d9 Add configuration setting and functionality for random "keepalive" messages to avoid idle timeout kicks from chat.
Matti Hamalainen <ccr@tnsp.org>
parents: 258
diff changeset
1564 qlist_t *node = th_llist_get_nth(setIdleMessages, n);
4c1c18a388d9 Add configuration setting and functionality for random "keepalive" messages to avoid idle timeout kicks from chat.
Matti Hamalainen <ccr@tnsp.org>
parents: 258
diff changeset
1565 nn_conn_send_msg(conn, optUserNameEnc, node->data);
96
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
1566 prevTime = tmpTime;
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
1567 }
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
1568
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
1569 if (!colorSet) {
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
1570 colorSet = TRUE;
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
1571 printMsg("%s v%s - %s\n", th_prog_name, th_prog_version, th_prog_fullname);
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
1572 printMsg("%s\n", th_prog_author);
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
1573 printMsg("%s\n", th_prog_license);
198
21a37995c3fb Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents: 197
diff changeset
1574 nn_conn_send_msg(conn, optUserNameEnc, "%%2FSetFontColor%%20%%2Dcolor%%20%06X", optUserColor);
96
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
1575 }
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
1576
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1577 updateStatus(insertMode);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1578 updateCount = 0;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1579 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1580
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1581 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1582
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1583 /* Shutdown */
13
86fe5f0d1a85 Cleanups; Added probing connection (requesting some policy crap) to emulate the official client.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1584 err_exit:
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1585 nn_userhash_free(nnUsers);
230
b64500bb7fbe Some yet-unused backbuffer related code.
Matti Hamalainen <ccr@tnsp.org>
parents: 229
diff changeset
1586 nn_ringbuf_free(backBuf);
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1587 nn_editbuf_free(editBuf);
75
abbdd101b267 Free some memory.
Matti Hamalainen <ccr@tnsp.org>
parents: 74
diff changeset
1588 for (histPos = 0; histPos <= SET_MAX_HISTORY; histPos++)
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1589 nn_editbuf_free(histBuf[histPos]);
75
abbdd101b267 Free some memory.
Matti Hamalainen <ccr@tnsp.org>
parents: 74
diff changeset
1590
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1591 if (cursesInit) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1592 if (curVis != ERR)
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1593 curs_set(curVis);
155
0720ca51673e Plug some minor "memory leaks" related to curses.
Matti Hamalainen <ccr@tnsp.org>
parents: 154
diff changeset
1594 closeWindows();
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1595 endwin();
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1596 THMSG(1, "NCurses deinitialized.\n");
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1597 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1598
223
03af28fb1c38 Show error messages printed out to stderr only after the program has quit.
Matti Hamalainen <ccr@tnsp.org>
parents: 222
diff changeset
1599 if (errorMessages)
03af28fb1c38 Show error messages printed out to stderr only after the program has quit.
Matti Hamalainen <ccr@tnsp.org>
parents: 222
diff changeset
1600 THERR("%s", errorMessages);
03af28fb1c38 Show error messages printed out to stderr only after the program has quit.
Matti Hamalainen <ccr@tnsp.org>
parents: 222
diff changeset
1601
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1602 if (isError) {
222
a1fefbce0b7a Add a simple 'press enter to continue' for Windows port, when an error occurs so the user can see it before the application closes.
Matti Hamalainen <ccr@tnsp.org>
parents: 221
diff changeset
1603 #ifdef __WIN32
a1fefbce0b7a Add a simple 'press enter to continue' for Windows port, when an error occurs so the user can see it before the application closes.
Matti Hamalainen <ccr@tnsp.org>
parents: 221
diff changeset
1604 char *tmp = promptRequester("Press enter to quit.\n", FALSE);
a1fefbce0b7a Add a simple 'press enter to continue' for Windows port, when an error occurs so the user can see it before the application closes.
Matti Hamalainen <ccr@tnsp.org>
parents: 221
diff changeset
1605 th_free(tmp);
a1fefbce0b7a Add a simple 'press enter to continue' for Windows port, when an error occurs so the user can see it before the application closes.
Matti Hamalainen <ccr@tnsp.org>
parents: 221
diff changeset
1606 #else
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1607 THMSG(1, "Error exit.\n");
222
a1fefbce0b7a Add a simple 'press enter to continue' for Windows port, when an error occurs so the user can see it before the application closes.
Matti Hamalainen <ccr@tnsp.org>
parents: 221
diff changeset
1608 #endif
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1609 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1610
198
21a37995c3fb Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents: 197
diff changeset
1611 th_free(optUserNameEnc);
10
53e127854dca WinSock support fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
1612
168
2e4850ece456 Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 165
diff changeset
1613 nn_conn_close(conn);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1614
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1615 if (networkInit)
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1616 nn_network_close();
68
3ab7751fdad1 MingW compatibility, with one ugly kludge.
Matti Hamalainen <ccr@tnsp.org>
parents: 67
diff changeset
1617
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1618 THMSG(1, "Connection terminated.\n");
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1619
242
cb86d7543be2 Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
1620 logFileClose();
133
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
1621
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1622 return 0;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1623 }