Mercurial > hg > nnchat
annotate main.c @ 602:4bae14092b78
Add parameters (unused for now) for proxy password etc. in case SOCKS 5
support is ever added.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 20 May 2014 01:04:30 +0300 |
parents | e661d7654e23 |
children | 0a30bf8db004 |
rev | line source |
---|---|
41 | 1 /* |
2 * NNChat - Custom chat client for NewbieNudes.com chatrooms | |
39 | 3 * Written by Matti 'ccr' Hämäläinen |
598 | 4 * (C) Copyright 2008-2014 Tecnic Software productions (TNSP) |
39 | 5 */ |
413 | 6 #include "util.h" |
7 #include "network.h" | |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
464
diff
changeset
|
8 #include "ui.h" |
0 | 9 #include "th_args.h" |
133 | 10 #include "th_config.h" |
415 | 11 #include <errno.h> |
555 | 12 #include <unistd.h> |
13 #include <fcntl.h> | |
64
6a3a917303e4
Some random cleanups, bring back WinSock support.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
14 #ifdef __WIN32 |
154
e8f67e344aaf
Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
15 #include <shlwapi.h> |
533
52c56ada3816
Fix Win32/MinGW cross-compilation target to work with Debian's gcc-mingw-w64
Matti Hamalainen <ccr@tnsp.org>
parents:
532
diff
changeset
|
16 #include <shfolder.h> |
52c56ada3816
Fix Win32/MinGW cross-compilation target to work with Debian's gcc-mingw-w64
Matti Hamalainen <ccr@tnsp.org>
parents:
532
diff
changeset
|
17 #define srandom srand |
52c56ada3816
Fix Win32/MinGW cross-compilation target to work with Debian's gcc-mingw-w64
Matti Hamalainen <ccr@tnsp.org>
parents:
532
diff
changeset
|
18 #define random rand |
128
713879a7ca10
Wait for forked processes, to prevent a zombie apocalypse.
Matti Hamalainen <ccr@tnsp.org>
parents:
125
diff
changeset
|
19 #else |
713879a7ca10
Wait for forked processes, to prevent a zombie apocalypse.
Matti Hamalainen <ccr@tnsp.org>
parents:
125
diff
changeset
|
20 #include <sys/wait.h> |
545
895ede06ff11
Implement default log file directory.
Matti Hamalainen <ccr@tnsp.org>
parents:
544
diff
changeset
|
21 #include <sys/stat.h> |
895ede06ff11
Implement default log file directory.
Matti Hamalainen <ccr@tnsp.org>
parents:
544
diff
changeset
|
22 #include <sys/types.h> |
68
3ab7751fdad1
MingW compatibility, with one ugly kludge.
Matti Hamalainen <ccr@tnsp.org>
parents:
67
diff
changeset
|
23 #endif |
0 | 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" |
545
895ede06ff11
Implement default log file directory.
Matti Hamalainen <ccr@tnsp.org>
parents:
544
diff
changeset
|
27 #define SET_LOG_DIR "NNChat Log Files" |
541
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
28 #define SET_DIR_SEPARATOR '\\' |
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" |
545
895ede06ff11
Implement default log file directory.
Matti Hamalainen <ccr@tnsp.org>
parents:
544
diff
changeset
|
31 #define SET_LOG_DIR "nnlogs" |
541
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
32 #define SET_DIR_SEPARATOR '/' |
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 |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
35 #define SET_PROFILE_PREFIX "http://www.newbienudes.com/profile/%s/" |
409
4556174b5be8
Make nickname autocomplete separator configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
408
diff
changeset
|
36 #define SET_NICK_SEPARATOR ':' |
4556174b5be8
Make nickname autocomplete separator configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
408
diff
changeset
|
37 |
588
573a3ad30938
Bump up the command history size.
Matti Hamalainen <ccr@tnsp.org>
parents:
586
diff
changeset
|
38 #define SET_MAX_HISTORY (64) // Command history length |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
39 #define SET_KEEPALIVE (15*60) // Ping/keepalive period in seconds |
0 | 40 |
49
0bcc38910a77
Simple ringbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
41 |
592
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
42 typedef struct |
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
43 { |
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
44 char *name; |
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
45 int port; |
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
46 char *desc; |
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
47 } nn_room_data_t; |
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
48 |
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
49 static const nn_room_data_t nn_room_data[] = |
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
50 { |
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
51 { "main" , 8005, "Main room" }, |
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
52 { "pit" , 8003, "Passion Pit" }, |
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
53 }; |
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
54 |
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
55 static const int nn_room_data_n = sizeof(nn_room_data) / sizeof(nn_room_data[0]); |
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
56 |
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
57 |
0 | 58 /* Options |
59 */ | |
352
b54c8545dcb0
Overhaul network code a bit, add initial implementation of SOCKS4/4A proxy support -- which may not work yet, it is untested.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
60 int optPort = 8005, |
b54c8545dcb0
Overhaul network code a bit, add initial implementation of SOCKS4/4A proxy support -- which may not work yet, it is untested.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
61 optProxyPort = 1080, |
b54c8545dcb0
Overhaul network code a bit, add initial implementation of SOCKS4/4A proxy support -- which may not work yet, it is untested.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
62 optProxyType = NN_PROXY_NONE; |
207
e0c085426b91
Change default user color to black (#000000).
Matti Hamalainen <ccr@tnsp.org>
parents:
206
diff
changeset
|
63 int optUserColor = 0x000000; |
96
7c9538e71c89
Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
64 char *optServer = "chat.newbienudes.com", |
352
b54c8545dcb0
Overhaul network code a bit, add initial implementation of SOCKS4/4A proxy support -- which may not work yet, it is untested.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
65 *optProxyServer = NULL, |
602
4bae14092b78
Add parameters (unused for now) for proxy password etc. in case SOCKS 5
Matti Hamalainen <ccr@tnsp.org>
parents:
601
diff
changeset
|
66 *optProxyUserID = NULL, |
4bae14092b78
Add parameters (unused for now) for proxy password etc. in case SOCKS 5
Matti Hamalainen <ccr@tnsp.org>
parents:
601
diff
changeset
|
67 *optProxyPassword = NULL, |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
68 *optUserName = NULL, |
198
21a37995c3fb
Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents:
197
diff
changeset
|
69 *optUserNameCmd = NULL, |
21a37995c3fb
Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents:
197
diff
changeset
|
70 *optUserNameEnc = NULL, |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
71 *optPassword = NULL, |
198
21a37995c3fb
Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents:
197
diff
changeset
|
72 *optPasswordCmd = NULL, |
541
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
73 *optLogPath = NULL, |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
74 *optLogExtension = ".log", |
409
4556174b5be8
Make nickname autocomplete separator configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
408
diff
changeset
|
75 *optSite = "NN", |
4556174b5be8
Make nickname autocomplete separator configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
408
diff
changeset
|
76 *optNickSepStr = NULL; |
4556174b5be8
Make nickname autocomplete separator configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
408
diff
changeset
|
77 char optNickSep; |
552 | 78 BOOL optDaemon = FALSE, |
79 setIgnoreMode = FALSE, | |
519
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
80 optDebug = FALSE, |
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
81 optLogEnable = FALSE, |
554
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
82 optLogDaily = FALSE, |
519
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
83 optOnlyFriendPrv = FALSE; |
140
2d2ef5bbcc11
Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents:
139
diff
changeset
|
84 |
265
b9c650db8a6a
Rename variable nnIgnoreList to setIgnoreList.
Matti Hamalainen <ccr@tnsp.org>
parents:
264
diff
changeset
|
85 qlist_t *setIgnoreList = NULL, |
519
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
86 *setFriendList = 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
|
87 *setIdleMessages = NULL; |
140
2d2ef5bbcc11
Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents:
139
diff
changeset
|
88 nn_userhash_t *nnUsers = NULL; |
137
fad8c31e41e6
Move browser code around a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
89 char *setConfigFile = NULL, |
fad8c31e41e6
Move browser code around a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
90 *setBrowser = NULL; |
561
1ff9e85a1fcc
Rework the configuration file loading and saving to use the I/O context and new th-config API.
Matti Hamalainen <ccr@tnsp.org>
parents:
560
diff
changeset
|
91 th_cfgitem_t *cfg = NULL; |
89
c2d916b340bf
Change some typedef names; Add struct for user list handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
92 |
513 | 93 nn_editbuf_t *editHistBuf[SET_MAX_HISTORY+2]; |
94 int editHistPos = 0, | |
95 editHistMax = 0; | |
273 | 96 |
97 /* Logging mode flags | |
98 */ | |
391 | 99 enum |
100 { | |
553
b464409fa643
Make LOG_* flags enum more readable and extendable by using hexadecimal values.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
101 LOG_FILE = 0x0001, |
b464409fa643
Make LOG_* flags enum more readable and extendable by using hexadecimal values.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
102 LOG_WINDOW = 0x0002, |
b464409fa643
Make LOG_* flags enum more readable and extendable by using hexadecimal values.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
103 LOG_STAMP = 0x0004, |
b464409fa643
Make LOG_* flags enum more readable and extendable by using hexadecimal values.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
104 LOG_FILE2 = 0x0008, |
554
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
105 LOG_RECURSIVE = 0x0010, |
273 | 106 }; |
107 | |
108 | |
0 | 109 /* Arguments |
110 */ | |
391 | 111 optarg_t optList[] = |
112 { | |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
113 { 0, '?', "help", "Show this help", OPT_NONE }, |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
114 { 1, 'v', "verbose", "Be more verbose", OPT_NONE }, |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
115 { 2, 'p', "port", "Connect to port", OPT_ARGREQ }, |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
116 { 3, 's', "server", "Server to connect to", OPT_ARGREQ }, |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
117 { 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
|
118 { 6, 'D', "daemon", "A pseudo-daemon mode for logging", OPT_NONE }, |
352
b54c8545dcb0
Overhaul network code a bit, add initial implementation of SOCKS4/4A proxy support -- which may not work yet, it is untested.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
119 { 7, 'f', "force-site", "Force 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
|
120 { 8, 'd', "debug", "Enable various debug features", OPT_NONE }, |
391 | 121 |
352
b54c8545dcb0
Overhaul network code a bit, add initial implementation of SOCKS4/4A proxy support -- which may not work yet, it is untested.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
122 {10, '4', "socks4", "SOCKS4 proxy server", OPT_ARGREQ }, |
b54c8545dcb0
Overhaul network code a bit, add initial implementation of SOCKS4/4A proxy support -- which may not work yet, it is untested.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
123 {11, 'A', "socks4a", "SOCKS4A proxy server", OPT_ARGREQ }, |
b54c8545dcb0
Overhaul network code a bit, add initial implementation of SOCKS4/4A proxy support -- which may not work yet, it is untested.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
124 {12, 'P', "proxy-port", "Proxy port (default: 1080)", OPT_ARGREQ }, |
592
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
125 |
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
126 {13, 'r', "room", "Connect to room (main, pit)", OPT_ARGREQ }, |
0 | 127 }; |
128 | |
43
40ba8cdcf03a
Cleanups, added a silly morse code conversion mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
129 const int optListN = (sizeof(optList) / sizeof(optList[0])); |
0 | 130 |
131 | |
258 | 132 void argShowHelp(void) |
68
3ab7751fdad1
MingW compatibility, with one ugly kludge.
Matti Hamalainen <ccr@tnsp.org>
parents:
67
diff
changeset
|
133 { |
592
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
134 int i; |
381
7c28f38cb6dd
Update to use new th-libs from the subrepo.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
135 th_print_banner(stdout, th_prog_name, |
391 | 136 "[options] <username> <password>"); |
137 | |
381
7c28f38cb6dd
Update to use new th-libs from the subrepo.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
138 th_args_help(stdout, optList, optListN); |
592
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
139 |
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
140 printf("Supported rooms (for option '-r'):\n"); |
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
141 for (i = 0; i < nn_room_data_n; i++) |
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
142 { |
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
143 printf(" %s - %s (port %d)\n", |
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
144 nn_room_data[i].name, |
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
145 nn_room_data[i].desc, |
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
146 nn_room_data[i].port); |
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
147 } |
68
3ab7751fdad1
MingW compatibility, with one ugly kludge.
Matti Hamalainen <ccr@tnsp.org>
parents:
67
diff
changeset
|
148 } |
3ab7751fdad1
MingW compatibility, with one ugly kludge.
Matti Hamalainen <ccr@tnsp.org>
parents:
67
diff
changeset
|
149 |
3ab7751fdad1
MingW compatibility, with one ugly kludge.
Matti Hamalainen <ccr@tnsp.org>
parents:
67
diff
changeset
|
150 |
0 | 151 BOOL argHandleOpt(const int optN, char *optArg, char *currArg) |
152 { | |
391 | 153 switch (optN) |
154 { | |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
155 case 0: |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
156 argShowHelp(); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
157 exit(0); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
158 break; |
0 | 159 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
160 case 1: |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
161 th_verbosityLevel++; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
162 break; |
391 | 163 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
164 case 2: |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
165 optPort = atoi(optArg); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
166 break; |
0 | 167 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
168 case 3: |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
169 optServer = optArg; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
170 break; |
391 | 171 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
172 case 4: |
391 | 173 if ((optUserColor = th_get_hex_triplet(optArg)) < 0) |
174 { | |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
175 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
|
176 optArg); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
177 return FALSE; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
178 } |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
179 THMSG(1, "Using color #%06x\n", optUserColor); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
180 break; |
0 | 181 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
182 case 7: |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
183 optSite = optArg; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
184 break; |
33
e49ea6febfeb
Cleanups. Added option to specify/fake "site" where logging in from.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
185 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
186 case 6: |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
187 optDaemon = TRUE; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
188 THMSG(1, "Running in pseudo-daemon mode.\n"); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
189 break; |
21 | 190 |
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
|
191 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
|
192 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
|
193 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
|
194 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
|
195 |
352
b54c8545dcb0
Overhaul network code a bit, add initial implementation of SOCKS4/4A proxy support -- which may not work yet, it is untested.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
196 |
b54c8545dcb0
Overhaul network code a bit, add initial implementation of SOCKS4/4A proxy support -- which may not work yet, it is untested.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
197 case 10: |
b54c8545dcb0
Overhaul network code a bit, add initial implementation of SOCKS4/4A proxy support -- which may not work yet, it is untested.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
198 optProxyServer = optArg; |
b54c8545dcb0
Overhaul network code a bit, add initial implementation of SOCKS4/4A proxy support -- which may not work yet, it is untested.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
199 optProxyType = NN_PROXY_SOCKS4; |
b54c8545dcb0
Overhaul network code a bit, add initial implementation of SOCKS4/4A proxy support -- which may not work yet, it is untested.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
200 break; |
b54c8545dcb0
Overhaul network code a bit, add initial implementation of SOCKS4/4A proxy support -- which may not work yet, it is untested.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
201 |
b54c8545dcb0
Overhaul network code a bit, add initial implementation of SOCKS4/4A proxy support -- which may not work yet, it is untested.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
202 case 11: |
b54c8545dcb0
Overhaul network code a bit, add initial implementation of SOCKS4/4A proxy support -- which may not work yet, it is untested.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
203 optProxyServer = optArg; |
b54c8545dcb0
Overhaul network code a bit, add initial implementation of SOCKS4/4A proxy support -- which may not work yet, it is untested.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
204 optProxyType = NN_PROXY_SOCKS4A; |
b54c8545dcb0
Overhaul network code a bit, add initial implementation of SOCKS4/4A proxy support -- which may not work yet, it is untested.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
205 break; |
b54c8545dcb0
Overhaul network code a bit, add initial implementation of SOCKS4/4A proxy support -- which may not work yet, it is untested.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
206 |
b54c8545dcb0
Overhaul network code a bit, add initial implementation of SOCKS4/4A proxy support -- which may not work yet, it is untested.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
207 case 12: |
590
2a6b512ee5a1
Proxy port commandline option was not working correctly (set wrong variable), fixed.
Matti Hamalainen <ccr@tnsp.org>
parents:
588
diff
changeset
|
208 optProxyPort = atoi(optArg); |
352
b54c8545dcb0
Overhaul network code a bit, add initial implementation of SOCKS4/4A proxy support -- which may not work yet, it is untested.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
209 break; |
b54c8545dcb0
Overhaul network code a bit, add initial implementation of SOCKS4/4A proxy support -- which may not work yet, it is untested.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
210 |
592
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
211 case 13: |
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
212 { |
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
213 int i; |
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
214 for (i = 0; i < nn_room_data_n; i++) |
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
215 if (!strcasecmp(nn_room_data[i].name, optArg)) |
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
216 { |
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
217 optPort = nn_room_data[i].port; |
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
218 return TRUE; |
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
219 } |
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
220 |
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
221 THERR("Unsupported room '%s'.\n", optArg); |
594
463210f14158
Oops, we didn't error out when the room name was non-existent for -r option.
Matti Hamalainen <ccr@tnsp.org>
parents:
593
diff
changeset
|
222 return FALSE; |
592
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
223 } |
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
224 break; |
352
b54c8545dcb0
Overhaul network code a bit, add initial implementation of SOCKS4/4A proxy support -- which may not work yet, it is untested.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
225 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
226 default: |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
227 THERR("Unknown option '%s'.\n", currArg); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
228 return FALSE; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
229 } |
391 | 230 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
231 return TRUE; |
0 | 232 } |
233 | |
234 | |
235 BOOL argHandleFile(char *currArg) | |
236 { | |
198
21a37995c3fb
Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents:
197
diff
changeset
|
237 if (!optUserNameCmd) |
21a37995c3fb
Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents:
197
diff
changeset
|
238 optUserNameCmd = currArg; |
21a37995c3fb
Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents:
197
diff
changeset
|
239 else if (!optPasswordCmd) |
21a37995c3fb
Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents:
197
diff
changeset
|
240 optPasswordCmd = currArg; |
391 | 241 else |
242 { | |
198
21a37995c3fb
Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents:
197
diff
changeset
|
243 THERR("Username '%s' already specified on commandline!\n", optUserNameCmd); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
244 return FALSE; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
245 } |
391 | 246 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
247 return TRUE; |
0 | 248 } |
249 | |
460 | 250 |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
251 int printFile(FILE *outFile, const char *fmt) |
0 | 252 { |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
253 const char *s = fmt; |
391 | 254 |
255 while (*s) | |
256 { | |
257 if (*s == '½') | |
258 { | |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
259 s++; |
391 | 260 if (*s == '½') |
261 { | |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
262 fputc((unsigned char) *s, outFile); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
263 s++; |
391 | 264 } |
265 else | |
266 { | |
74 | 267 while (*s && isdigit((int) *s)) s++; |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
268 if (*s != '½') return -1; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
269 s++; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
270 } |
391 | 271 } |
272 else | |
273 { | |
191
4007b9ac7cde
Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents:
190
diff
changeset
|
274 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
|
275 fputc(' ', outFile); |
4007b9ac7cde
Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents:
190
diff
changeset
|
276 else |
4007b9ac7cde
Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents:
190
diff
changeset
|
277 fputc((unsigned char) *s, outFile); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
278 s++; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
279 } |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
280 } |
391 | 281 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
282 return 0; |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
283 } |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
284 |
542
d8184a3c241f
Clean up window logging logic a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
541
diff
changeset
|
285 void printMsgFile(nn_window_t *win, int flags, const char *stamp, const char *msg) |
d8184a3c241f
Clean up window logging logic a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
541
diff
changeset
|
286 { |
d8184a3c241f
Clean up window logging logic a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
541
diff
changeset
|
287 if (win != NULL && win->logFile != NULL) |
d8184a3c241f
Clean up window logging logic a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
541
diff
changeset
|
288 { |
d8184a3c241f
Clean up window logging logic a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
541
diff
changeset
|
289 if (flags & LOG_STAMP) printFile(win->logFile, stamp); |
d8184a3c241f
Clean up window logging logic a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
541
diff
changeset
|
290 printFile(win->logFile, msg); |
d8184a3c241f
Clean up window logging logic a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
541
diff
changeset
|
291 fflush(win->logFile); |
d8184a3c241f
Clean up window logging logic a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
541
diff
changeset
|
292 } |
d8184a3c241f
Clean up window logging logic a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
541
diff
changeset
|
293 } |
d8184a3c241f
Clean up window logging logic a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
541
diff
changeset
|
294 |
554
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
295 |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
296 void printMsgF(nn_window_t *win, int flags, const char *fmt, ...); |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
297 BOOL nn_log_reopen(nn_window_t *win); |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
298 |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
299 |
563
c3e4e8f3c658
Refactor message/error/etc printing functions to be a bit more sane.
Matti Hamalainen <ccr@tnsp.org>
parents:
561
diff
changeset
|
300 void printMsgConst(nn_window_t *win, int flags, const char *msg) |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
301 { |
563
c3e4e8f3c658
Refactor message/error/etc printing functions to be a bit more sane.
Matti Hamalainen <ccr@tnsp.org>
parents:
561
diff
changeset
|
302 char tmpStr[128]; |
554
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
303 nn_window_t *tmpwin = (win != NULL) ? win : nnwin_main_window(); |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
304 |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
305 // Only the main window |
576
414d11df07ce
Gracefully handle error situations when the main UI has not yet been
Matti Hamalainen <ccr@tnsp.org>
parents:
573
diff
changeset
|
306 if (win == NULL && tmpwin != NULL && (flags & LOG_RECURSIVE) == 0) |
554
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
307 { |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
308 time_t currTime = time(NULL); |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
309 struct tm *currTm, *prevTm; |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
310 |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
311 if ((currTm = localtime(&currTime)) != NULL && |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
312 currTm->tm_hour == 0 && |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
313 (prevTm = localtime(&tmpwin->logPrevMsgTime)) != NULL && |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
314 prevTm->tm_hour == 23) |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
315 { |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
316 str_get_timestamp(tmpStr, sizeof(tmpStr), "%d %b %Y"); |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
317 printMsgF(win, LOG_RECURSIVE, "Day changed to %s.\n", tmpStr); |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
318 nn_log_reopen(tmpwin); |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
319 } |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
320 |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
321 tmpwin->logPrevMsgTime = currTime; |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
322 } |
391 | 323 |
520 | 324 if (flags & LOG_STAMP) |
325 { | |
326 str_get_timestamp(tmpStr, sizeof(tmpStr), "½17½[½11½%H:%M:%S½17½]½0½ "); | |
327 } | |
391 | 328 |
542
d8184a3c241f
Clean up window logging logic a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
541
diff
changeset
|
329 if (flags & LOG_FILE) |
391 | 330 { |
563
c3e4e8f3c658
Refactor message/error/etc printing functions to be a bit more sane.
Matti Hamalainen <ccr@tnsp.org>
parents:
561
diff
changeset
|
331 printMsgFile(win != NULL ? win : nnwin_main_window(), flags, tmpStr, msg); |
544
e30fa8592a48
Possibly fix logging after latest changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
542
diff
changeset
|
332 } |
542
d8184a3c241f
Clean up window logging logic a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
541
diff
changeset
|
333 |
544
e30fa8592a48
Possibly fix logging after latest changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
542
diff
changeset
|
334 if (flags & LOG_FILE2) |
e30fa8592a48
Possibly fix logging after latest changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
542
diff
changeset
|
335 { |
563
c3e4e8f3c658
Refactor message/error/etc printing functions to be a bit more sane.
Matti Hamalainen <ccr@tnsp.org>
parents:
561
diff
changeset
|
336 printMsgFile(nnwin_main_window(), flags, tmpStr, msg); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
337 } |
391 | 338 |
339 if (!optDaemon && (flags & LOG_WINDOW)) | |
340 { | |
554
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
341 if (flags & LOG_STAMP) nnwin_print(tmpwin, tmpStr); |
563
c3e4e8f3c658
Refactor message/error/etc printing functions to be a bit more sane.
Matti Hamalainen <ccr@tnsp.org>
parents:
561
diff
changeset
|
342 nnwin_print(tmpwin, msg); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
343 } |
563
c3e4e8f3c658
Refactor message/error/etc printing functions to be a bit more sane.
Matti Hamalainen <ccr@tnsp.org>
parents:
561
diff
changeset
|
344 } |
391 | 345 |
563
c3e4e8f3c658
Refactor message/error/etc printing functions to be a bit more sane.
Matti Hamalainen <ccr@tnsp.org>
parents:
561
diff
changeset
|
346 void printMsgV(nn_window_t *win, int flags, const char *fmt, va_list ap) |
c3e4e8f3c658
Refactor message/error/etc printing functions to be a bit more sane.
Matti Hamalainen <ccr@tnsp.org>
parents:
561
diff
changeset
|
347 { |
c3e4e8f3c658
Refactor message/error/etc printing functions to be a bit more sane.
Matti Hamalainen <ccr@tnsp.org>
parents:
561
diff
changeset
|
348 char *buf = th_strdup_vprintf(fmt, ap); |
c3e4e8f3c658
Refactor message/error/etc printing functions to be a bit more sane.
Matti Hamalainen <ccr@tnsp.org>
parents:
561
diff
changeset
|
349 printMsgConst(win, flags, buf); |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
350 th_free(buf); |
0 | 351 } |
352 | |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
353 void printMsg(nn_window_t *win, const char *fmt, ...) |
100
ed4067c10a8a
Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
354 { |
ed4067c10a8a
Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
355 va_list ap; |
391 | 356 |
100
ed4067c10a8a
Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
357 va_start(ap, fmt); |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
358 printMsgV(win, LOG_STAMP | LOG_WINDOW | LOG_FILE, fmt, ap); |
103
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
359 va_end(ap); |
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
360 } |
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
361 |
322
b9c15c57dc8f
Clean up message functions, add new printMsgQ() helper function for messages that should not
Matti Hamalainen <ccr@tnsp.org>
parents:
321
diff
changeset
|
362 void printMsgF(nn_window_t *win, int flags, const char *fmt, ...) |
103
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
363 { |
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
364 va_list ap; |
391 | 365 |
103
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
366 va_start(ap, fmt); |
322
b9c15c57dc8f
Clean up message functions, add new printMsgQ() helper function for messages that should not
Matti Hamalainen <ccr@tnsp.org>
parents:
321
diff
changeset
|
367 printMsgV(win, flags | LOG_STAMP, fmt, ap); |
103
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
368 va_end(ap); |
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
369 } |
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
370 |
322
b9c15c57dc8f
Clean up message functions, add new printMsgQ() helper function for messages that should not
Matti Hamalainen <ccr@tnsp.org>
parents:
321
diff
changeset
|
371 void printMsgQ(nn_window_t *win, const char *fmt, ...) |
103
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
372 { |
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
373 va_list ap; |
391 | 374 |
103
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
375 va_start(ap, fmt); |
322
b9c15c57dc8f
Clean up message functions, add new printMsgQ() helper function for messages that should not
Matti Hamalainen <ccr@tnsp.org>
parents:
321
diff
changeset
|
376 printMsgV(win, LOG_STAMP | LOG_WINDOW, fmt, ap); |
100
ed4067c10a8a
Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
377 va_end(ap); |
ed4067c10a8a
Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
378 } |
ed4067c10a8a
Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
379 |
0 | 380 |
223
03af28fb1c38
Show error messages printed out to stderr only after the program has quit.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
381 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
|
382 |
563
c3e4e8f3c658
Refactor message/error/etc printing functions to be a bit more sane.
Matti Hamalainen <ccr@tnsp.org>
parents:
561
diff
changeset
|
383 void errorMsgConst(const char *msg) |
96
7c9538e71c89
Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
384 { |
563
c3e4e8f3c658
Refactor message/error/etc printing functions to be a bit more sane.
Matti Hamalainen <ccr@tnsp.org>
parents:
561
diff
changeset
|
385 printMsgConst(NULL, LOG_STAMP | LOG_WINDOW | LOG_FILE, msg); |
391 | 386 |
387 if (errorMessages != NULL) | |
388 { | |
563
c3e4e8f3c658
Refactor message/error/etc printing functions to be a bit more sane.
Matti Hamalainen <ccr@tnsp.org>
parents:
561
diff
changeset
|
389 // XXX Yes, this is lazy. |
c3e4e8f3c658
Refactor message/error/etc printing functions to be a bit more sane.
Matti Hamalainen <ccr@tnsp.org>
parents:
561
diff
changeset
|
390 char *tmp = th_strdup_printf("%s%s", errorMessages, msg); |
223
03af28fb1c38
Show error messages printed out to stderr only after the program has quit.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
391 th_free(errorMessages); |
563
c3e4e8f3c658
Refactor message/error/etc printing functions to be a bit more sane.
Matti Hamalainen <ccr@tnsp.org>
parents:
561
diff
changeset
|
392 errorMessages = tmp; |
391 | 393 } |
394 else | |
563
c3e4e8f3c658
Refactor message/error/etc printing functions to be a bit more sane.
Matti Hamalainen <ccr@tnsp.org>
parents:
561
diff
changeset
|
395 errorMessages = th_strdup(msg); |
c3e4e8f3c658
Refactor message/error/etc printing functions to be a bit more sane.
Matti Hamalainen <ccr@tnsp.org>
parents:
561
diff
changeset
|
396 } |
c3e4e8f3c658
Refactor message/error/etc printing functions to be a bit more sane.
Matti Hamalainen <ccr@tnsp.org>
parents:
561
diff
changeset
|
397 |
c3e4e8f3c658
Refactor message/error/etc printing functions to be a bit more sane.
Matti Hamalainen <ccr@tnsp.org>
parents:
561
diff
changeset
|
398 |
c3e4e8f3c658
Refactor message/error/etc printing functions to be a bit more sane.
Matti Hamalainen <ccr@tnsp.org>
parents:
561
diff
changeset
|
399 void errorMsgV(const char *fmt, va_list ap) |
c3e4e8f3c658
Refactor message/error/etc printing functions to be a bit more sane.
Matti Hamalainen <ccr@tnsp.org>
parents:
561
diff
changeset
|
400 { |
c3e4e8f3c658
Refactor message/error/etc printing functions to be a bit more sane.
Matti Hamalainen <ccr@tnsp.org>
parents:
561
diff
changeset
|
401 char *msg = th_strdup_vprintf(fmt, ap); |
c3e4e8f3c658
Refactor message/error/etc printing functions to be a bit more sane.
Matti Hamalainen <ccr@tnsp.org>
parents:
561
diff
changeset
|
402 errorMsgConst(msg); |
c3e4e8f3c658
Refactor message/error/etc printing functions to be a bit more sane.
Matti Hamalainen <ccr@tnsp.org>
parents:
561
diff
changeset
|
403 th_free(msg); |
96
7c9538e71c89
Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
404 } |
7c9538e71c89
Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
405 |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
464
diff
changeset
|
406 |
236
71fa0364c058
Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
407 void errorMsg(const char *fmt, ...) |
71fa0364c058
Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
408 { |
71fa0364c058
Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
409 va_list ap; |
71fa0364c058
Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
410 |
71fa0364c058
Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
411 va_start(ap, fmt); |
71fa0364c058
Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
412 errorMsgV(fmt, ap); |
71fa0364c058
Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
413 va_end(ap); |
71fa0364c058
Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
414 } |
71fa0364c058
Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
415 |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
464
diff
changeset
|
416 |
513 | 417 void debugMsg(const char *fmt, ...) |
418 { | |
419 if (optDebug) | |
420 { | |
421 va_list ap; | |
422 | |
423 va_start(ap, fmt); | |
544
e30fa8592a48
Possibly fix logging after latest changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
542
diff
changeset
|
424 printMsgV(NULL, LOG_FILE | LOG_WINDOW, fmt, ap); |
513 | 425 va_end(ap); |
426 } | |
427 } | |
428 | |
429 | |
564
6e5789cbb4d4
Change network layer error/info message passing API to pass direct strings
Matti Hamalainen <ccr@tnsp.org>
parents:
563
diff
changeset
|
430 void nn_network_errfunc(struct _nn_conn_t *conn, const char *msg) |
236
71fa0364c058
Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
431 { |
262
6d48fc4fd421
Shut up some trivial warnings.
Matti Hamalainen <ccr@tnsp.org>
parents:
258
diff
changeset
|
432 (void) conn; |
564
6e5789cbb4d4
Change network layer error/info message passing API to pass direct strings
Matti Hamalainen <ccr@tnsp.org>
parents:
563
diff
changeset
|
433 errorMsg("%s", msg); |
236
71fa0364c058
Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
434 } |
71fa0364c058
Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
435 |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
464
diff
changeset
|
436 |
564
6e5789cbb4d4
Change network layer error/info message passing API to pass direct strings
Matti Hamalainen <ccr@tnsp.org>
parents:
563
diff
changeset
|
437 void nn_network_msgfunc(struct _nn_conn_t *conn, const char *msg) |
236
71fa0364c058
Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
438 { |
262
6d48fc4fd421
Shut up some trivial warnings.
Matti Hamalainen <ccr@tnsp.org>
parents:
258
diff
changeset
|
439 (void) conn; |
564
6e5789cbb4d4
Change network layer error/info message passing API to pass direct strings
Matti Hamalainen <ccr@tnsp.org>
parents:
563
diff
changeset
|
440 printMsgConst(NULL, LOG_STAMP | LOG_WINDOW | LOG_FILE, msg); |
236
71fa0364c058
Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
441 } |
71fa0364c058
Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
442 |
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
|
443 |
565
de1af9652fef
Update to conform to changes in th-libs ioctx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
564
diff
changeset
|
444 void nn_ioctx_errfunc(th_ioctx_t *ctx, int err, const char *msg) |
de1af9652fef
Update to conform to changes in th-libs ioctx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
564
diff
changeset
|
445 { |
de1af9652fef
Update to conform to changes in th-libs ioctx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
564
diff
changeset
|
446 (void) err; |
582
8a0c2eb25b35
Adjust certain error message formats slightly.
Matti Hamalainen <ccr@tnsp.org>
parents:
581
diff
changeset
|
447 errorMsg("[%s:%d] %s", |
565
de1af9652fef
Update to conform to changes in th-libs ioctx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
564
diff
changeset
|
448 ctx->filename, ctx->line, msg); |
de1af9652fef
Update to conform to changes in th-libs ioctx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
564
diff
changeset
|
449 } |
de1af9652fef
Update to conform to changes in th-libs ioctx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
564
diff
changeset
|
450 |
de1af9652fef
Update to conform to changes in th-libs ioctx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
564
diff
changeset
|
451 |
de1af9652fef
Update to conform to changes in th-libs ioctx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
564
diff
changeset
|
452 void nn_ioctx_msgfunc(th_ioctx_t *ctx, const char *msg) |
de1af9652fef
Update to conform to changes in th-libs ioctx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
564
diff
changeset
|
453 { |
de1af9652fef
Update to conform to changes in th-libs ioctx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
564
diff
changeset
|
454 (void) ctx; |
de1af9652fef
Update to conform to changes in th-libs ioctx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
564
diff
changeset
|
455 printMsgConst(NULL, LOG_STAMP | LOG_WINDOW | LOG_FILE, msg); |
de1af9652fef
Update to conform to changes in th-libs ioctx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
564
diff
changeset
|
456 } |
de1af9652fef
Update to conform to changes in th-libs ioctx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
564
diff
changeset
|
457 |
de1af9652fef
Update to conform to changes in th-libs ioctx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
564
diff
changeset
|
458 |
519
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
459 BOOL checkNameList(qlist_t *list, const char *name) |
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
|
460 { |
519
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
461 qlist_t *node; |
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
462 |
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
463 for (node = list; node != NULL; node = node->next) |
391 | 464 { |
372
b9f0bdad6285
Use th_strcasecmp() and th_strncasecmp().
Matti Hamalainen <ccr@tnsp.org>
parents:
369
diff
changeset
|
465 if (th_strcasecmp(name, (char *) node->data) == 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
|
466 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
|
467 } |
519
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
468 |
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
|
469 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
|
470 } |
801ac37321f6
Sanitize ignore handling; Also action messages and PRVs were not being properly ignored, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
471 |
801ac37321f6
Sanitize ignore handling; Also action messages and PRVs were not being properly ignored, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
472 |
416 | 473 int nnproto_parse_user(nn_conn_t *conn) |
0 | 474 { |
229
08d4355d6fc9
Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
228
diff
changeset
|
475 BOOL isMine, isIgnored = FALSE; |
417
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
476 char *name, *msg, *t; |
391 | 477 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
478 // Find start of the message |
417
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
479 name = conn->ptr; |
430
aaadf6cea6be
Better handling of some messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
429
diff
changeset
|
480 t = nn_conn_buf_strstr(conn, "</USER>"); |
417
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
481 if (!t) return 1; |
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
482 *t = 0; |
391 | 483 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
484 // Find end of the message |
430
aaadf6cea6be
Better handling of some messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
429
diff
changeset
|
485 t = nn_conn_buf_strstr(conn, "<MESSAGE>"); |
aaadf6cea6be
Better handling of some messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
429
diff
changeset
|
486 if (!t) return 2; |
aaadf6cea6be
Better handling of some messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
429
diff
changeset
|
487 msg = conn->ptr; |
aaadf6cea6be
Better handling of some messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
429
diff
changeset
|
488 |
417
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
489 t = nn_conn_buf_strstr(conn, "</MESSAGE>"); |
229
08d4355d6fc9
Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
228
diff
changeset
|
490 if (!t) return 3; |
08d4355d6fc9
Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
228
diff
changeset
|
491 *t = 0; |
391 | 492 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
493 // Decode message string |
417
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
494 msg = nn_decode_str1(msg); |
481 | 495 if (!msg) |
496 { | |
497 errorMsg("Decode/malloc failure @ nnproto_parse_user()\n"); | |
498 return -1; | |
499 } | |
391 | 500 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
501 // Decode username |
417
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
502 name = nn_decode_str1(name); |
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
503 if (!name) |
391 | 504 { |
481 | 505 errorMsg("Decode/malloc failure @ nnproto_parse_user()\n"); |
417
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
506 th_free(msg); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
507 return -2; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
508 } |
229
08d4355d6fc9
Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
228
diff
changeset
|
509 |
08d4355d6fc9
Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
228
diff
changeset
|
510 /* 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
|
511 * that it is not our OWN username! |
08d4355d6fc9
Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
228
diff
changeset
|
512 */ |
417
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
513 isMine = strcmp(name, optUserName) == 0; |
519
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
514 isIgnored = setIgnoreMode && !isMine && checkNameList(setIgnoreList, name); |
108
f323b137ca08
Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents:
107
diff
changeset
|
515 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
516 // Is it a special control message? |
417
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
517 if (*msg == '/') |
391 | 518 { |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
519 // Ignore room join/leave messages |
417
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
520 if (!optDebug && (strstr(msg, "left the room") || strstr(msg, "joined the room from"))) |
229
08d4355d6fc9
Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
228
diff
changeset
|
521 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
|
522 |
417
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
523 t = nn_strip_tags(msg + 1); |
391 | 524 if (!strncmp(t, "BPRV ", 5)) |
525 { | |
417
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
526 char *in_name, *tmp, *in_msg, *h; |
293 | 527 nn_window_t *win; |
528 h = nn_decode_str2(t + 1); | |
391 | 529 |
418 | 530 // Check type of |
531 if ((isMine = strncmp(t, "BPRV from ", 10)) == 0) | |
417
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
532 in_name = nn_decode_str2(t + 10); |
391 | 533 else |
417
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
534 in_name = nn_decode_str2(t + 8); |
291
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
535 |
417
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
536 for (tmp = in_name; *tmp && *tmp != ':'; tmp++); |
291
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
537 if (tmp[0] != 0 && tmp[1] == ' ') |
417
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
538 in_msg = tmp + 2; |
291
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
539 else |
417
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
540 in_msg = ""; |
291
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
541 *tmp = 0; |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
542 |
519
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
543 if (!optOnlyFriendPrv || !checkNameList(setFriendList, in_name)) |
391 | 544 { |
519
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
545 isIgnored = setIgnoreMode && checkNameList(setIgnoreList, in_name); |
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
546 win = nnwin_find(in_name); |
388
f45673fe6b23
Log private messages always in the PRV format.
Matti Hamalainen <ccr@tnsp.org>
parents:
385
diff
changeset
|
547 |
519
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
548 if (win != NULL) |
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
549 { |
544
e30fa8592a48
Possibly fix logging after latest changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
542
diff
changeset
|
550 printMsgF(win, isIgnored ? LOG_FILE : (LOG_FILE | LOG_WINDOW), |
519
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
551 "½5½<½%d½%s½5½>½0½ %s\n", |
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
552 isMine ? 14 : 15, isMine ? optUserName : in_name, in_msg); |
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
553 |
544
e30fa8592a48
Possibly fix logging after latest changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
542
diff
changeset
|
554 printMsgF(NULL, LOG_FILE2, "½11½%s½0½\n", h); |
519
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
555 } |
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
556 else |
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
557 { |
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
558 printMsgF(NULL, isIgnored ? LOG_FILE : (LOG_WINDOW | LOG_FILE), |
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
559 "½11½%s½0½\n", h); |
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
560 } |
391 | 561 } |
519
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
562 |
417
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
563 th_free(in_name); |
293 | 564 th_free(h); |
391 | 565 } |
566 else | |
567 { | |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
568 // It's an action (/me) |
291
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
569 char *h = nn_decode_str2(t); |
322
b9c15c57dc8f
Clean up message functions, add new printMsgQ() helper function for messages that should not
Matti Hamalainen <ccr@tnsp.org>
parents:
321
diff
changeset
|
570 printMsgF(NULL, isIgnored ? LOG_FILE : (LOG_WINDOW | LOG_FILE), |
b9c15c57dc8f
Clean up message functions, add new printMsgQ() helper function for messages that should not
Matti Hamalainen <ccr@tnsp.org>
parents:
321
diff
changeset
|
571 "½9½* %s½0½\n", h); |
291
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
572 th_free(h); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
573 } |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
574 th_free(t); |
391 | 575 } |
576 else | |
577 { | |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
578 // It's a normal message |
291
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
579 char *h; |
530
f0bca971170b
Change coloring to use friend list as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
526
diff
changeset
|
580 int colorNick, colorText; |
417
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
581 t = nn_strip_tags(msg); |
97
218efd2f0641
Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
582 h = nn_decode_str2(t); |
530
f0bca971170b
Change coloring to use friend list as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
526
diff
changeset
|
583 if (isMine) |
f0bca971170b
Change coloring to use friend list as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
526
diff
changeset
|
584 { |
f0bca971170b
Change coloring to use friend list as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
526
diff
changeset
|
585 colorNick = 14; |
f0bca971170b
Change coloring to use friend list as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
526
diff
changeset
|
586 colorText = 0; |
f0bca971170b
Change coloring to use friend list as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
526
diff
changeset
|
587 } |
f0bca971170b
Change coloring to use friend list as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
526
diff
changeset
|
588 else |
f0bca971170b
Change coloring to use friend list as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
526
diff
changeset
|
589 { |
f0bca971170b
Change coloring to use friend list as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
526
diff
changeset
|
590 if (checkNameList(setFriendList, name)) |
f0bca971170b
Change coloring to use friend list as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
526
diff
changeset
|
591 { |
535
379e361f1144
Fix various segfault issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
533
diff
changeset
|
592 colorNick = 11; |
379e361f1144
Fix various segfault issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
533
diff
changeset
|
593 colorText = 0; |
530
f0bca971170b
Change coloring to use friend list as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
526
diff
changeset
|
594 } |
f0bca971170b
Change coloring to use friend list as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
526
diff
changeset
|
595 else |
f0bca971170b
Change coloring to use friend list as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
526
diff
changeset
|
596 { |
f0bca971170b
Change coloring to use friend list as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
526
diff
changeset
|
597 colorNick = 15; |
f0bca971170b
Change coloring to use friend list as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
526
diff
changeset
|
598 colorText = 0; |
f0bca971170b
Change coloring to use friend list as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
526
diff
changeset
|
599 } |
f0bca971170b
Change coloring to use friend list as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
526
diff
changeset
|
600 } |
f0bca971170b
Change coloring to use friend list as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
526
diff
changeset
|
601 |
322
b9c15c57dc8f
Clean up message functions, add new printMsgQ() helper function for messages that should not
Matti Hamalainen <ccr@tnsp.org>
parents:
321
diff
changeset
|
602 printMsgF(NULL, isIgnored ? LOG_FILE : (LOG_WINDOW | LOG_FILE), |
530
f0bca971170b
Change coloring to use friend list as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
526
diff
changeset
|
603 "½5½<½%d½%s½5½>½%d½ %s½0½\n", colorNick, name, colorText, h); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
604 th_free(h); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
605 th_free(t); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
606 } |
108
f323b137ca08
Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents:
107
diff
changeset
|
607 |
229
08d4355d6fc9
Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
228
diff
changeset
|
608 done: |
417
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
609 th_free(msg); |
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
610 th_free(name); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
611 return 0; |
0 | 612 } |
613 | |
614 | |
416 | 615 int nnproto_parse_login(nn_conn_t *conn) |
0 | 616 { |
156
0a9fe14882dc
Introduce utility function getTimeStamp() and use it to lessen code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
155
diff
changeset
|
617 char tmpStr[256]; |
403
7bec02f382fb
Refactor the connection and protocol handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
402
diff
changeset
|
618 str_get_timestamp(tmpStr, sizeof(tmpStr), "%c"); |
391 | 619 |
403
7bec02f382fb
Refactor the connection and protocol handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
402
diff
changeset
|
620 if (!nn_conn_buf_strcmp(conn, "FAILURE>")) |
391 | 621 { |
430
aaadf6cea6be
Better handling of some messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
429
diff
changeset
|
622 nn_conn_buf_strstr(conn, "</LOGIN_FAILURE>"); |
437
8e9690a3f973
Fix parsing of LOGIN_{SUCCESS,FAILURE} packets.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
623 nn_conn_buf_strstr(conn, "</USER>"); |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
624 printMsg(NULL, "½1½Login failure½0½ - ½3½%s½0½\n", tmpStr); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
625 return -2; |
391 | 626 } |
403
7bec02f382fb
Refactor the connection and protocol handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
402
diff
changeset
|
627 else if (!nn_conn_buf_strcmp(conn, "SUCCESS>")) |
391 | 628 { |
430
aaadf6cea6be
Better handling of some messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
429
diff
changeset
|
629 nn_conn_buf_strstr(conn, "</LOGIN_SUCCESS>"); |
437
8e9690a3f973
Fix parsing of LOGIN_{SUCCESS,FAILURE} packets.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
630 nn_conn_buf_strstr(conn, "</USER>"); |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
631 printMsg(NULL, "½2½Login success½0½ - ½3½%s½0½\n", tmpStr); |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
632 nn_conn_send_msg(conn, optUserNameEnc, "%2FRequestUserList"); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
633 return 0; |
391 | 634 } |
635 else | |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
636 return 1; |
0 | 637 } |
638 | |
639 | |
416 | 640 int nnproto_parse_add_user(nn_conn_t *conn) |
0 | 641 { |
403
7bec02f382fb
Refactor the connection and protocol handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
402
diff
changeset
|
642 char *p, *s, *str = conn->ptr; |
297
d34910f1b1e1
Print messages about user leaving or joining the chat in the specific buffer, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
643 nn_window_t *win; |
0 | 644 |
403
7bec02f382fb
Refactor the connection and protocol handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
402
diff
changeset
|
645 s = nn_conn_buf_strstr(conn, "</ADD_USER>"); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
646 if (!s) return 1; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
647 *s = 0; |
391 | 648 |
97
218efd2f0641
Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
649 p = nn_dbldecode_str(str); |
481 | 650 if (!p) |
651 { | |
652 errorMsg("Decode/malloc failure @ nnproto_parse_add_user()\n"); | |
653 return -1; | |
654 } | |
103
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
655 |
422 | 656 win = nnwin_find(p); |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
657 nn_userhash_insert(nnUsers, nn_username_encode(p)); |
103
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
658 |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
659 printMsg(NULL, "! ½3½%s½0½ ½2½ADDED.½0½\n", p); |
297
d34910f1b1e1
Print messages about user leaving or joining the chat in the specific buffer, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
660 if (win != NULL) |
d34910f1b1e1
Print messages about user leaving or joining the chat in the specific buffer, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
661 printMsg(win, "! ½3½%s½0½ ½2½joined the chat.½0½\n", p); |
d34910f1b1e1
Print messages about user leaving or joining the chat in the specific buffer, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
662 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
663 th_free(p); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
664 return 0; |
0 | 665 } |
666 | |
667 | |
416 | 668 int nnproto_parse_delete_user(nn_conn_t *conn) |
0 | 669 { |
403
7bec02f382fb
Refactor the connection and protocol handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
402
diff
changeset
|
670 char *p, *s, *str = conn->ptr; |
297
d34910f1b1e1
Print messages about user leaving or joining the chat in the specific buffer, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
671 nn_window_t *win; |
0 | 672 |
403
7bec02f382fb
Refactor the connection and protocol handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
402
diff
changeset
|
673 s = nn_conn_buf_strstr(conn, "</DELETE_USER>"); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
674 if (!s) return 1; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
675 *s = 0; |
391 | 676 |
97
218efd2f0641
Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
677 p = nn_dbldecode_str(str); |
481 | 678 if (!p) |
679 { | |
680 errorMsg("Decode/malloc failure @ nnproto_parse_delete_user()\n"); | |
681 return -1; | |
682 } | |
103
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
683 |
422 | 684 win = nnwin_find(p); |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
685 nn_userhash_delete(nnUsers, nn_username_encode(p)); |
107
8037a3a7e491
Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
104
diff
changeset
|
686 |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
687 printMsg(NULL, "! ½3½%s½0½ ½1½DELETED.½0½\n", p); |
297
d34910f1b1e1
Print messages about user leaving or joining the chat in the specific buffer, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
688 if (win != NULL) |
d34910f1b1e1
Print messages about user leaving or joining the chat in the specific buffer, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
689 printMsg(win, "! ½3½%s½0½ ½1½left the chat.½0½\n", p); |
391 | 690 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
691 th_free(p); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
692 return 0; |
0 | 693 } |
694 | |
695 | |
416 | 696 int nnproto_parse_num_clients(nn_conn_t *conn) |
0 | 697 { |
403
7bec02f382fb
Refactor the connection and protocol handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
402
diff
changeset
|
698 nn_conn_buf_strstr(conn, "</NUMCLIENTS>"); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
699 return 0; |
0 | 700 } |
701 | |
702 | |
416 | 703 int nnproto_parse_boot(nn_conn_t *conn) |
96
7c9538e71c89
Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
704 { |
391 | 705 (void) conn; |
96
7c9538e71c89
Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
706 errorMsg("Booted by server.\n"); |
7c9538e71c89
Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
707 return -1; |
7c9538e71c89
Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
708 } |
7c9538e71c89
Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
709 |
7c9538e71c89
Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
710 |
391 | 711 typedef struct |
712 { | |
443 | 713 char *name; |
431
a9b20b31cae1
More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
430
diff
changeset
|
714 size_t len; |
403
7bec02f382fb
Refactor the connection and protocol handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
402
diff
changeset
|
715 int (*handler)(nn_conn_t *); |
7bec02f382fb
Refactor the connection and protocol handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
402
diff
changeset
|
716 } nn_protocolcmd_t; |
0 | 717 |
718 | |
403
7bec02f382fb
Refactor the connection and protocol handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
402
diff
changeset
|
719 static nn_protocolcmd_t protoCmds[] = |
391 | 720 { |
431
a9b20b31cae1
More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
430
diff
changeset
|
721 { "<USER>", 0, nnproto_parse_user }, |
a9b20b31cae1
More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
430
diff
changeset
|
722 { "<LOGIN_", 0, nnproto_parse_login }, |
a9b20b31cae1
More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
430
diff
changeset
|
723 { "<DELETE_USER>", 0, nnproto_parse_delete_user }, |
a9b20b31cae1
More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
430
diff
changeset
|
724 { "<ADD_USER>", 0, nnproto_parse_add_user }, |
a9b20b31cae1
More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
430
diff
changeset
|
725 { "<NUMCLIENTS>", 0, nnproto_parse_num_clients }, |
a9b20b31cae1
More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
430
diff
changeset
|
726 { "<BOOT />", 0, nnproto_parse_boot }, |
0 | 727 }; |
728 | |
108
f323b137ca08
Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents:
107
diff
changeset
|
729 static const int nprotoCmds = sizeof(protoCmds) / sizeof(protoCmds[0]); |
0 | 730 |
731 | |
403
7bec02f382fb
Refactor the connection and protocol handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
402
diff
changeset
|
732 int nn_parse_protocol(nn_conn_t *conn) |
0 | 733 { |
130
352ec3c300e4
A different initialization.
Matti Hamalainen <ccr@tnsp.org>
parents:
129
diff
changeset
|
734 static BOOL protoCmdsInit = FALSE; |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
735 int i; |
130
352ec3c300e4
A different initialization.
Matti Hamalainen <ccr@tnsp.org>
parents:
129
diff
changeset
|
736 |
391 | 737 if (!protoCmdsInit) |
738 { | |
130
352ec3c300e4
A different initialization.
Matti Hamalainen <ccr@tnsp.org>
parents:
129
diff
changeset
|
739 for (i = 0; i < nprotoCmds; i++) |
443 | 740 protoCmds[i].len = strlen(protoCmds[i].name); |
403
7bec02f382fb
Refactor the connection and protocol handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
402
diff
changeset
|
741 |
130
352ec3c300e4
A different initialization.
Matti Hamalainen <ccr@tnsp.org>
parents:
129
diff
changeset
|
742 protoCmdsInit = TRUE; |
352ec3c300e4
A different initialization.
Matti Hamalainen <ccr@tnsp.org>
parents:
129
diff
changeset
|
743 } |
391 | 744 |
745 for (i = 0; i < nprotoCmds; i++) | |
746 { | |
443 | 747 if (!nn_conn_buf_strncmp(conn, protoCmds[i].name, protoCmds[i].len)) |
403
7bec02f382fb
Refactor the connection and protocol handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
402
diff
changeset
|
748 return protoCmds[i].handler(conn); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
749 } |
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
|
750 |
391 | 751 if (optDebug) |
752 { | |
403
7bec02f382fb
Refactor the connection and protocol handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
402
diff
changeset
|
753 printMsg(NULL, "Unknown protocmd: \"%s\"\n", conn->ptr); |
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
|
754 return 0; |
391 | 755 } |
756 else | |
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
|
757 return 1; |
0 | 758 } |
759 | |
402
563a70e8a303
Oops, these functions were moved/renamed and were left out from a previous commit. :|
Matti Hamalainen <ccr@tnsp.org>
parents:
401
diff
changeset
|
760 |
474
4ddc3d87242e
Refactor web-browser launching into nn_open_uri().
Matti Hamalainen <ccr@tnsp.org>
parents:
473
diff
changeset
|
761 int nn_open_uri(const char *uri) |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
762 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
763 #ifdef __WIN32 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
764 HINSTANCE status; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
765 |
442 | 766 status = ShellExecute(NULL, "open", uri, NULL, NULL, SW_SHOWNA); |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
767 if (status <= (HINSTANCE) 32) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
768 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
769 printMsgQ(currWin, "Could not launch default web browser: %d\n", status); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
770 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
771 #else |
474
4ddc3d87242e
Refactor web-browser launching into nn_open_uri().
Matti Hamalainen <ccr@tnsp.org>
parents:
473
diff
changeset
|
772 int status; |
4ddc3d87242e
Refactor web-browser launching into nn_open_uri().
Matti Hamalainen <ccr@tnsp.org>
parents:
473
diff
changeset
|
773 int fds[2]; |
4ddc3d87242e
Refactor web-browser launching into nn_open_uri().
Matti Hamalainen <ccr@tnsp.org>
parents:
473
diff
changeset
|
774 pid_t pid; |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
775 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
776 if (pipe(fds) == -1) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
777 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
778 int ret = errno; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
779 printMsgQ(currWin, "Could not open process communication pipe! (%d, %s)\n", ret, strerror(ret)); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
780 return 0; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
781 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
782 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
783 if ((pid = fork()) < 0) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
784 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
785 printMsgQ(currWin, "Could not create sub-process!\n"); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
786 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
787 else if (pid == 0) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
788 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
789 dup2(fds[1], STDOUT_FILENO); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
790 dup2(fds[0], STDERR_FILENO); |
474
4ddc3d87242e
Refactor web-browser launching into nn_open_uri().
Matti Hamalainen <ccr@tnsp.org>
parents:
473
diff
changeset
|
791 char *url = th_strdup_printf("openurl(%s,new-tab)", uri); |
478
4dca76db9e1f
Fix opening of browser windows on UNIX.
Matti Hamalainen <ccr@tnsp.org>
parents:
474
diff
changeset
|
792 execlp(setBrowser, setBrowser, "-remote", url, (void *)NULL); |
474
4ddc3d87242e
Refactor web-browser launching into nn_open_uri().
Matti Hamalainen <ccr@tnsp.org>
parents:
473
diff
changeset
|
793 th_free(url); |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
794 _exit(errno); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
795 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
796 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
797 wait(&status); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
798 #endif |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
799 |
474
4ddc3d87242e
Refactor web-browser launching into nn_open_uri().
Matti Hamalainen <ccr@tnsp.org>
parents:
473
diff
changeset
|
800 return 0; |
4ddc3d87242e
Refactor web-browser launching into nn_open_uri().
Matti Hamalainen <ccr@tnsp.org>
parents:
473
diff
changeset
|
801 } |
4ddc3d87242e
Refactor web-browser launching into nn_open_uri().
Matti Hamalainen <ccr@tnsp.org>
parents:
473
diff
changeset
|
802 |
516 | 803 |
474
4ddc3d87242e
Refactor web-browser launching into nn_open_uri().
Matti Hamalainen <ccr@tnsp.org>
parents:
473
diff
changeset
|
804 int nncmd_open_profile(nn_conn_t *conn, char *name) |
4ddc3d87242e
Refactor web-browser launching into nn_open_uri().
Matti Hamalainen <ccr@tnsp.org>
parents:
473
diff
changeset
|
805 { |
4ddc3d87242e
Refactor web-browser launching into nn_open_uri().
Matti Hamalainen <ccr@tnsp.org>
parents:
473
diff
changeset
|
806 char *enc_name = nn_encode_str1(name); |
4ddc3d87242e
Refactor web-browser launching into nn_open_uri().
Matti Hamalainen <ccr@tnsp.org>
parents:
473
diff
changeset
|
807 char *uri = th_strdup_printf(SET_PROFILE_PREFIX, name); |
4ddc3d87242e
Refactor web-browser launching into nn_open_uri().
Matti Hamalainen <ccr@tnsp.org>
parents:
473
diff
changeset
|
808 (void) conn; |
4ddc3d87242e
Refactor web-browser launching into nn_open_uri().
Matti Hamalainen <ccr@tnsp.org>
parents:
473
diff
changeset
|
809 |
4ddc3d87242e
Refactor web-browser launching into nn_open_uri().
Matti Hamalainen <ccr@tnsp.org>
parents:
473
diff
changeset
|
810 printMsg(currWin, "Opening profile for: '%s'\n", name); |
4ddc3d87242e
Refactor web-browser launching into nn_open_uri().
Matti Hamalainen <ccr@tnsp.org>
parents:
473
diff
changeset
|
811 |
4ddc3d87242e
Refactor web-browser launching into nn_open_uri().
Matti Hamalainen <ccr@tnsp.org>
parents:
473
diff
changeset
|
812 nn_open_uri(uri); |
4ddc3d87242e
Refactor web-browser launching into nn_open_uri().
Matti Hamalainen <ccr@tnsp.org>
parents:
473
diff
changeset
|
813 |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
814 th_free(uri); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
815 th_free(enc_name); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
816 return 0; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
817 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
818 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
819 |
519
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
820 int nncmd_change_list(nn_conn_t *conn, const char *listname, qlist_t **list, const char *name) |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
821 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
822 (void) conn; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
823 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
824 if (name[0]) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
825 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
826 // Add or remove someone to/from ignore |
519
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
827 qlist_t *user = th_llist_find_func(*list, name, str_compare); |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
828 if (user != NULL) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
829 { |
519
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
830 printMsgQ(currWin, "Removed user '%s' from %s list.\n", name, listname); |
531 | 831 th_llist_delete_node(list, user); |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
832 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
833 else |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
834 { |
519
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
835 printMsgQ(currWin, "Added '%s' to %s list.\n", name, listname); |
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
836 th_llist_append(list, th_strdup(name)); |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
837 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
838 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
839 else |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
840 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
841 // Just list whomever is in ignore now |
519
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
842 qlist_t *user = *list; |
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
843 size_t nuser = th_llist_length(*list); |
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
844 char *result = th_strdup_printf("Users on %s list (%d): ", listname, nuser); |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
845 while (user != NULL) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
846 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
847 if (user->data != NULL) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
848 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
849 th_pstr_printf(&result, "%s'%s'", result, (char *) user->data); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
850 if (--nuser > 0) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
851 th_pstr_printf(&result, "%s, ", result); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
852 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
853 user = user->next; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
854 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
855 printMsgQ(currWin, "%s\n", result); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
856 th_free(result); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
857 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
858 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
859 return 0; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
860 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
861 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
862 |
519
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
863 int nncmd_ignore(nn_conn_t *conn, char *name) |
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
864 { |
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
865 return nncmd_change_list(conn, "ignore", &setIgnoreList, name); |
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
866 } |
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
867 |
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
868 |
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
869 int nncmd_friend(nn_conn_t *conn, char *name) |
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
870 { |
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
871 return nncmd_change_list(conn, "friend", &setFriendList, name); |
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
872 } |
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
873 |
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
874 |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
875 int nncmd_set_color(nn_conn_t *conn, char *arg) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
876 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
877 int val; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
878 (void) conn; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
879 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
880 if ((val = th_get_hex_triplet(arg)) < 0) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
881 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
882 printMsgQ(currWin, "Invalid color value '%s'\n", arg); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
883 return 1; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
884 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
885 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
886 optUserColor = val; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
887 printMsgQ(currWin, "Setting color to #%06x\n", optUserColor); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
888 nn_conn_send_msg_v(conn, optUserNameEnc, "%%2FSetFontColor%%20%%2Dcolor%%20%06X", optUserColor); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
889 return 0; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
890 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
891 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
892 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
893 int nncmd_open_query(nn_conn_t *conn, char *name) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
894 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
895 (void) conn; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
896 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
897 if (name[0]) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
898 { |
446
3396acd40147
Rename and remove some functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
899 nn_user_t *user = nn_userhash_find(nnUsers, nn_username_encode(name)); |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
900 if (user != NULL) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
901 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
902 name = nn_username_decode(th_strdup(user->name)); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
903 printMsgQ(currWin, "Opening PRV query for '%s'.\n", name); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
904 if (nnwin_open(name, TRUE)) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
905 printMsgQ(currWin, "In PRV query with '%s'.\n", name); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
906 th_free(name); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
907 return 0; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
908 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
909 else |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
910 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
911 printMsgQ(currWin, "Could not find username '%s'.\n", name); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
912 return 1; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
913 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
914 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
915 else |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
916 { |
472 | 917 printMsgQ(currWin, |
918 "Usage: /query username\n" | |
919 "To close a PRV query, use /close [username]\n" | |
920 "/close without username will close the current PRV window, if any.\n"); | |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
921 return 1; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
922 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
923 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
924 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
925 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
926 int nncmd_close_query(nn_conn_t *conn, char *name) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
927 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
928 (void) conn; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
929 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
930 if (name[0]) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
931 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
932 nn_window_t *win = nnwin_find(name); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
933 if (win != NULL) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
934 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
935 nnwin_close(win); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
936 printMsgQ(currWin, "Closed PRV query to '%s'.\n", name); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
937 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
938 else |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
939 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
940 printMsgQ(currWin, "No PRV query by name '%s'.\n", name); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
941 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
942 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
943 else |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
944 { |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
464
diff
changeset
|
945 if (currWin != nnwin_main_window()) |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
946 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
947 nnwin_close(currWin); |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
464
diff
changeset
|
948 currWin = nnwin_main_window(); |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
949 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
950 else |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
951 { |
472 | 952 printMsgQ(currWin, |
953 "Usage: /close [username]\n" | |
954 "/close without username will close the current PRV window. if any.\n"); | |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
955 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
956 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
957 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
958 return 0; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
959 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
960 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
961 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
962 int nncmd_window_info(nn_conn_t *conn, char *arg) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
963 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
964 (void) conn; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
965 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
966 if (arg[0]) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
967 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
968 int val = atoi(arg); |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
464
diff
changeset
|
969 nn_window_t *win = nnwin_get(val); |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
464
diff
changeset
|
970 if (win != NULL) |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
464
diff
changeset
|
971 currWin = win; |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
972 else |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
973 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
974 printMsgQ(currWin, "Invalid window number '%s'\n", arg); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
975 return 1; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
976 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
977 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
978 else |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
979 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
980 printMsgQ(currWin, "Window : #%d\n", currWin->num); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
981 printMsgQ(currWin, "ID : %s\n", currWin->id); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
982 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
983 return 0; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
984 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
985 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
986 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
987 int nncmd_list_all_users(nn_conn_t *conn, char *buf) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
988 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
989 (void) buf; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
990 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
991 // Alias /listallusers |
425 | 992 return nn_conn_send_msg(conn, optUserNameEnc, "%2Flistallusers"); |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
993 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
994 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
995 |
486
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
996 #define NAME_NUM_PER_LINE 3 |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
997 #define NAME_ENTRY_SIZE 64 |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
998 #define NAME_ENTRY_WIDTH 22 |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
999 |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1000 typedef struct |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1001 { |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1002 char buf[(NAME_NUM_PER_LINE * NAME_ENTRY_SIZE) + 16]; |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1003 size_t offs; |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1004 int i, total; |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1005 } nncmd_namedata_t; |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1006 |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1007 |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1008 static int nncmd_names_do(const nn_user_t *user, void *data) |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1009 { |
486
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1010 nncmd_namedata_t *d = data; |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1011 char name[NAME_ENTRY_SIZE]; |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1012 size_t len; |
538
ffacb78d9b9f
Add colorization of usernames on userlist based on friend/ignore status.
Matti Hamalainen <ccr@tnsp.org>
parents:
536
diff
changeset
|
1013 int color; |
486
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1014 |
538
ffacb78d9b9f
Add colorization of usernames on userlist based on friend/ignore status.
Matti Hamalainen <ccr@tnsp.org>
parents:
536
diff
changeset
|
1015 if (checkNameList(setFriendList, user->name)) |
ffacb78d9b9f
Add colorization of usernames on userlist based on friend/ignore status.
Matti Hamalainen <ccr@tnsp.org>
parents:
536
diff
changeset
|
1016 color = 11; |
ffacb78d9b9f
Add colorization of usernames on userlist based on friend/ignore status.
Matti Hamalainen <ccr@tnsp.org>
parents:
536
diff
changeset
|
1017 else |
ffacb78d9b9f
Add colorization of usernames on userlist based on friend/ignore status.
Matti Hamalainen <ccr@tnsp.org>
parents:
536
diff
changeset
|
1018 if (checkNameList(setIgnoreList, user->name)) |
ffacb78d9b9f
Add colorization of usernames on userlist based on friend/ignore status.
Matti Hamalainen <ccr@tnsp.org>
parents:
536
diff
changeset
|
1019 color = 1; |
ffacb78d9b9f
Add colorization of usernames on userlist based on friend/ignore status.
Matti Hamalainen <ccr@tnsp.org>
parents:
536
diff
changeset
|
1020 else |
ffacb78d9b9f
Add colorization of usernames on userlist based on friend/ignore status.
Matti Hamalainen <ccr@tnsp.org>
parents:
536
diff
changeset
|
1021 color = 3; |
ffacb78d9b9f
Add colorization of usernames on userlist based on friend/ignore status.
Matti Hamalainen <ccr@tnsp.org>
parents:
536
diff
changeset
|
1022 |
ffacb78d9b9f
Add colorization of usernames on userlist based on friend/ignore status.
Matti Hamalainen <ccr@tnsp.org>
parents:
536
diff
changeset
|
1023 snprintf(name, sizeof(name), "[½%d½%-20s½0½] ", color, user->name); |
486
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1024 |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1025 d->total++; |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1026 if (d->i >= NAME_NUM_PER_LINE) |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1027 { |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1028 printMsgQ(currWin, "%s\n", d->buf); |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1029 d->i = 0; |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1030 d->offs = 0; |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1031 } |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1032 |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1033 len = strlen(name); |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1034 memcpy(d->buf + d->offs, name, len + 1); |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1035 d->offs += len; |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1036 d->i++; |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1037 |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1038 return 0; |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1039 } |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1040 |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1041 |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1042 int nncmd_names(nn_conn_t *conn, char *arg) |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1043 { |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1044 nncmd_namedata_t data; |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1045 (void) conn; |
486
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1046 (void) arg; |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1047 |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1048 printMsgQ(currWin, "Users:\n"); |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1049 data.i = data.total = 0; |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1050 data.offs = 0; |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1051 |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1052 nn_userhash_foreach(nnUsers, nncmd_names_do, &data); |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1053 |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1054 if (data.i > 0) |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1055 { |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1056 printMsgQ(currWin, "%s\n", data.buf); |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1057 } |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1058 |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1059 printMsgQ(currWin, "%d users total.\n", data.total); |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1060 return 0; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1061 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1062 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1063 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1064 int nncmd_save_config(nn_conn_t *conn, char *buf) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1065 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1066 (void) conn; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1067 (void) buf; |
561
1ff9e85a1fcc
Rework the configuration file loading and saving to use the I/O context and new th-config API.
Matti Hamalainen <ccr@tnsp.org>
parents:
560
diff
changeset
|
1068 th_ioctx_t ctx; |
556
9b72d0060b85
Create configuration and log files with reduced permissions (rw for user
Matti Hamalainen <ccr@tnsp.org>
parents:
555
diff
changeset
|
1069 #ifndef __WIN32 |
9b72d0060b85
Create configuration and log files with reduced permissions (rw for user
Matti Hamalainen <ccr@tnsp.org>
parents:
555
diff
changeset
|
1070 int cfgfd = -1; |
9b72d0060b85
Create configuration and log files with reduced permissions (rw for user
Matti Hamalainen <ccr@tnsp.org>
parents:
555
diff
changeset
|
1071 #endif |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1072 |
565
de1af9652fef
Update to conform to changes in th-libs ioctx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
564
diff
changeset
|
1073 if (!th_ioctx_init(&ctx, setConfigFile, nn_ioctx_errfunc, nn_ioctx_msgfunc)) |
561
1ff9e85a1fcc
Rework the configuration file loading and saving to use the I/O context and new th-config API.
Matti Hamalainen <ccr@tnsp.org>
parents:
560
diff
changeset
|
1074 { |
1ff9e85a1fcc
Rework the configuration file loading and saving to use the I/O context and new th-config API.
Matti Hamalainen <ccr@tnsp.org>
parents:
560
diff
changeset
|
1075 printMsgQ(currWin, "Could not initialize I/O context for configuration file writing!\n"); |
1ff9e85a1fcc
Rework the configuration file loading and saving to use the I/O context and new th-config API.
Matti Hamalainen <ccr@tnsp.org>
parents:
560
diff
changeset
|
1076 goto error; |
1ff9e85a1fcc
Rework the configuration file loading and saving to use the I/O context and new th-config API.
Matti Hamalainen <ccr@tnsp.org>
parents:
560
diff
changeset
|
1077 } |
1ff9e85a1fcc
Rework the configuration file loading and saving to use the I/O context and new th-config API.
Matti Hamalainen <ccr@tnsp.org>
parents:
560
diff
changeset
|
1078 |
556
9b72d0060b85
Create configuration and log files with reduced permissions (rw for user
Matti Hamalainen <ccr@tnsp.org>
parents:
555
diff
changeset
|
1079 #ifdef __WIN32 |
561
1ff9e85a1fcc
Rework the configuration file loading and saving to use the I/O context and new th-config API.
Matti Hamalainen <ccr@tnsp.org>
parents:
560
diff
changeset
|
1080 if ((ctx.fp = fopen(setConfigFile, "w")) == NULL) |
556
9b72d0060b85
Create configuration and log files with reduced permissions (rw for user
Matti Hamalainen <ccr@tnsp.org>
parents:
555
diff
changeset
|
1081 #else |
577
06675b69ca6c
Add O_TRUNC to configuration file saving flags.
Matti Hamalainen <ccr@tnsp.org>
parents:
576
diff
changeset
|
1082 if ((cfgfd = open(setConfigFile, O_CREAT | O_TRUNC | O_WRONLY, S_IRUSR | S_IWUSR)) == -1 || |
561
1ff9e85a1fcc
Rework the configuration file loading and saving to use the I/O context and new th-config API.
Matti Hamalainen <ccr@tnsp.org>
parents:
560
diff
changeset
|
1083 (ctx.fp = fdopen(cfgfd, "w")) == NULL) |
556
9b72d0060b85
Create configuration and log files with reduced permissions (rw for user
Matti Hamalainen <ccr@tnsp.org>
parents:
555
diff
changeset
|
1084 #endif |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1085 { |
556
9b72d0060b85
Create configuration and log files with reduced permissions (rw for user
Matti Hamalainen <ccr@tnsp.org>
parents:
555
diff
changeset
|
1086 printMsgQ(currWin, "Could not create configuration to file '%s', %d: %s\n", |
9b72d0060b85
Create configuration and log files with reduced permissions (rw for user
Matti Hamalainen <ccr@tnsp.org>
parents:
555
diff
changeset
|
1087 setConfigFile, errno, strerror(errno)); |
9b72d0060b85
Create configuration and log files with reduced permissions (rw for user
Matti Hamalainen <ccr@tnsp.org>
parents:
555
diff
changeset
|
1088 goto error; |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1089 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1090 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1091 printMsgQ(currWin, "Configuration saved in file '%s', res=%d\n", |
561
1ff9e85a1fcc
Rework the configuration file loading and saving to use the I/O context and new th-config API.
Matti Hamalainen <ccr@tnsp.org>
parents:
560
diff
changeset
|
1092 setConfigFile, th_cfg_write(&ctx, cfg)); |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1093 |
556
9b72d0060b85
Create configuration and log files with reduced permissions (rw for user
Matti Hamalainen <ccr@tnsp.org>
parents:
555
diff
changeset
|
1094 error: |
561
1ff9e85a1fcc
Rework the configuration file loading and saving to use the I/O context and new th-config API.
Matti Hamalainen <ccr@tnsp.org>
parents:
560
diff
changeset
|
1095 th_ioctx_close(&ctx); |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1096 return 0; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1097 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1098 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1099 |
573 | 1100 int nncmd_quit(nn_conn_t *conn, char *buf) |
1101 { | |
1102 (void) conn; | |
1103 (void) buf; | |
1104 | |
1105 appQuitFlag = TRUE; | |
1106 return 0; | |
1107 } | |
1108 | |
1109 | |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1110 enum |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1111 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1112 CMDARG_NONE, |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1113 CMDARG_STRING, |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1114 CMDARG_OPTIONAL, |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1115 CMDARG_NICK, |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1116 }; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1117 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1118 typedef struct |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1119 { |
443 | 1120 char *name; |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1121 int flags; |
431
a9b20b31cae1
More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
430
diff
changeset
|
1122 size_t len; |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1123 int (*handler)(nn_conn_t *, char *buf); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1124 } nn_usercmd_t; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1125 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1126 |
450
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1127 static nn_usercmd_t userCmdsTable[] = |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1128 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1129 // Server side commands, we just implement completion |
450
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1130 { "/me", CMDARG_STRING, 0, NULL }, |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1131 { "/status", CMDARG_STRING, 0, NULL }, |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1132 { "/list", CMDARG_NONE, 0, nncmd_list_all_users }, |
518 | 1133 { "/prvon", CMDARG_NONE, 0, NULL }, |
1134 { "/prvoff", CMDARG_NONE, 0, NULL }, | |
601
e661d7654e23
Add /mute to 'supported' passthrough commands.
Matti Hamalainen <ccr@tnsp.org>
parents:
599
diff
changeset
|
1135 { "/mute", CMDARG_STRING, 0, NULL }, |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1136 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1137 // List internal username list |
450
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1138 { "/who", CMDARG_NONE, 0, nncmd_names }, |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1139 { "/names", CMDARG_NONE, 0, nncmd_names }, |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1140 |
450
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1141 { "/w", CMDARG_NICK, 0, nncmd_open_profile }, |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1142 { "/profile", CMDARG_NICK, 0, nncmd_open_profile }, |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1143 |
450
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1144 { "/query", CMDARG_NICK, 0, nncmd_open_query }, |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1145 { "/close", CMDARG_OPTIONAL, 0, nncmd_close_query }, |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1146 { "/win", CMDARG_OPTIONAL, 0, nncmd_window_info }, |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1147 |
497 | 1148 { "/ignore", CMDARG_OPTIONAL, 0, nncmd_ignore }, |
519
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
1149 { "/friend", CMDARG_OPTIONAL, 0, nncmd_friend }, |
450
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1150 { "/color", CMDARG_STRING, 0, nncmd_set_color }, |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1151 { "/save", CMDARG_NONE, 0, nncmd_save_config }, |
573 | 1152 |
1153 { "/quit", CMDARG_NONE, 0, nncmd_quit }, | |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1154 }; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1155 |
450
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1156 static qlist_t *userCmds = NULL; |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1157 |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1158 |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1159 void nn_usercmd_init() |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1160 { |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1161 size_t i; |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1162 for (i = 0; i < sizeof(userCmdsTable) / sizeof(userCmdsTable[0]); i++) |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1163 { |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1164 th_llist_append(&userCmds, &userCmdsTable[i]); |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1165 userCmdsTable[i].len = strlen(userCmdsTable[i].name); |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1166 } |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1167 } |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1168 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1169 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1170 int nn_handle_command(nn_conn_t *conn, char *buf) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1171 { |
450
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1172 qlist_t *curr; |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1173 |
450
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1174 for (curr = userCmds; curr != NULL; curr = curr->next) |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1175 { |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1176 nn_usercmd_t *cmd = curr->data; |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1177 |
450
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1178 if (!th_strncasecmp(buf, cmd->name, cmd->len)) |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1179 { |
457 | 1180 char *nbuf; |
1181 if (buf[cmd->len] != 0 && !th_isspace(buf[cmd->len])) | |
1182 continue; | |
1183 | |
1184 nbuf = str_trim_left(buf + cmd->len); | |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1185 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1186 switch (cmd->flags) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1187 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1188 case CMDARG_NICK: |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1189 case CMDARG_STRING: |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1190 if (!nbuf[0]) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1191 { |
450
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1192 printMsgQ(currWin, "Command %s requires an argument.\n", cmd->name); |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1193 return 1; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1194 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1195 break; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1196 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1197 case CMDARG_NONE: |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1198 if (nbuf[0]) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1199 { |
450
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1200 printMsgQ(currWin, "Command %s does not take arguments.\n", cmd->name); |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1201 return 1; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1202 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1203 break; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1204 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1205 case CMDARG_OPTIONAL: |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1206 break; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1207 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1208 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1209 // Check if there is a handler function |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1210 if (cmd->handler) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1211 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1212 // Internal commands have a handler |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1213 return cmd->handler(conn, nbuf); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1214 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1215 else |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1216 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1217 // Server-side commands are just pass-through here |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1218 char *tmp = nn_dblencode_str(buf); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1219 BOOL result; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1220 if (tmp == NULL) return -2; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1221 result = nn_conn_send_msg(conn, optUserNameEnc, tmp); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1222 th_free(tmp); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1223 return result ? 0 : -1; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1224 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1225 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1226 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1227 |
444 | 1228 printMsgQ(currWin, "Unknown command: %s\n", buf); |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1229 return 1; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1230 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1231 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1232 |
450
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1233 static nn_usercmd_t *nn_usercmd_match_do(qlist_t *list, const char *pattern, size_t len) |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1234 { |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1235 qlist_t *node; |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1236 for (node = list; node != NULL; node = node->next) |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1237 { |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1238 nn_usercmd_t *cmd = node->data; |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1239 if (len <= strlen(cmd->name) && th_strncasecmp(cmd->name, pattern, len) == 0) |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1240 return cmd; |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1241 } |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1242 return NULL; |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1243 } |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1244 |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1245 |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1246 nn_usercmd_t *nn_usercmd_match(qlist_t *list, const char *pattern, const char *current, BOOL again) |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1247 { |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1248 nn_usercmd_t *curr; |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1249 size_t len; |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1250 |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1251 if (list == NULL || pattern == NULL) return NULL; |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1252 |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1253 len = strlen(pattern); |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1254 |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1255 if (current != NULL) |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1256 { |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1257 qlist_t *node; |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1258 for (node = list; node != NULL; node = node->next) |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1259 { |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1260 curr = node->data; |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1261 if (th_strcasecmp(curr->name, current) == 0) |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1262 { |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1263 if (again) |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1264 return curr; |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1265 |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1266 if ((curr = nn_usercmd_match_do(node->next, pattern, len)) != NULL) |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1267 return curr; |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1268 } |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1269 } |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1270 } |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1271 |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1272 if ((curr = nn_usercmd_match_do(list, pattern, len)) != NULL) |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1273 return curr; |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1274 |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1275 return NULL; |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1276 } |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1277 |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1278 |
410
7ea78f4a4d23
Rename input handling main function.
Matti Hamalainen <ccr@tnsp.org>
parents:
409
diff
changeset
|
1279 int nn_handle_input(nn_conn_t *conn, char *buf, size_t bufLen) |
0 | 1280 { |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1281 BOOL result; |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1282 char *tmp; |
391 | 1283 |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1284 // Trim right side |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1285 while (bufLen > 0 && th_isspace(buf[bufLen - 1])) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1286 buf[--bufLen] = 0; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1287 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1288 if (buf[0] == 0) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1289 return 1; |
258 | 1290 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
1291 // Decode completed usernames |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
1292 nn_username_decode(buf); |
391 | 1293 |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1294 // Check for commands |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1295 if (buf[0] == '/') |
426 | 1296 return nn_handle_command(conn, buf); |
133 | 1297 |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1298 // If current window is not the main room window, send private |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
464
diff
changeset
|
1299 if (currWin != nnwin_main_window()) |
391 | 1300 { |
1301 if (currWin->id != NULL) | |
1302 { | |
431
a9b20b31cae1
More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
430
diff
changeset
|
1303 char *msg = th_strdup_printf("/prv -to %s -msg %s", currWin->id, buf); |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1304 if (msg == NULL) return -3; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1305 tmp = nn_dblencode_str(msg); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1306 if (tmp == NULL) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1307 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1308 th_free(msg); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1309 return -2; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1310 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1311 result = nn_conn_send_msg(conn, optUserNameEnc, tmp); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1312 th_free(tmp); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1313 th_free(msg); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1314 return result ? 0 : -1; |
391 | 1315 } |
1316 else | |
1317 { | |
322
b9c15c57dc8f
Clean up message functions, add new printMsgQ() helper function for messages that should not
Matti Hamalainen <ccr@tnsp.org>
parents:
321
diff
changeset
|
1318 printMsgQ(NULL, "No target set, exiting prv mode.\n"); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1319 return 1; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1320 } |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1321 } |
291
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
1322 |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1323 // Send double-encoded message |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1324 tmp = nn_dblencode_str(buf); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1325 if (tmp == NULL) return -2; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1326 result = nn_conn_send_msg(conn, optUserNameEnc, tmp); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1327 th_free(tmp); |
103
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
1328 return result ? 0 : -1; |
0 | 1329 } |
1330 | |
405 | 1331 |
449
7d9fa9f7caf1
Rename tab completion functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
448
diff
changeset
|
1332 static void nn_tabcomplete_replace(nn_editbuf_t *buf, size_t *pi, const size_t startPos, const size_t endPos, char *c) |
447
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1333 { |
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1334 size_t i; |
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1335 |
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1336 for (i = startPos; i <= endPos; i++) |
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1337 nn_editbuf_delete(buf, startPos); |
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1338 |
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1339 for (i = startPos; *c; i++, c++) |
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1340 nn_editbuf_insert(buf, i, *c); |
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1341 |
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1342 *pi = i; |
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1343 } |
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1344 |
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1345 |
449
7d9fa9f7caf1
Rename tab completion functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
448
diff
changeset
|
1346 static void nn_tabcomplete_finish(nn_editbuf_t *buf, char **previous, const size_t startPos, const char *name) |
447
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1347 { |
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1348 nn_editbuf_setpos(buf, startPos + 1 + strlen(name)); |
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1349 th_free(*previous); |
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1350 *previous = th_strdup(name); |
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1351 } |
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1352 |
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1353 |
449
7d9fa9f7caf1
Rename tab completion functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
448
diff
changeset
|
1354 BOOL nn_tabcomplete_buffer(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
|
1355 { |
189
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1356 static char *previous = NULL, *pattern = NULL; |
451 | 1357 char *str = buf->data; |
429
2ac24f1e241b
Start working on command completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
427
diff
changeset
|
1358 BOOL again = FALSE, hasSeparator = FALSE, |
447
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1359 hasSpace, newPattern = FALSE, isCommand; |
431
a9b20b31cae1
More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
430
diff
changeset
|
1360 size_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
|
1361 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
1362 // previous word |
391 | 1363 if (startPos >= 2 && str[startPos - 1] == ' ' && str[startPos - 2] != ' ') |
1364 { | |
113
2a53156e7e12
Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents:
112
diff
changeset
|
1365 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
|
1366 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
|
1367 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
|
1368 } |
391 | 1369 else |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
1370 // middle of a word, new pattern |
404
d11a68f214eb
Fix indentation after astyle reindent.
Matti Hamalainen <ccr@tnsp.org>
parents:
403
diff
changeset
|
1371 if (startPos < buf->len && str[startPos] != ' ') |
d11a68f214eb
Fix indentation after astyle reindent.
Matti Hamalainen <ccr@tnsp.org>
parents:
403
diff
changeset
|
1372 { |
d11a68f214eb
Fix indentation after astyle reindent.
Matti Hamalainen <ccr@tnsp.org>
parents:
403
diff
changeset
|
1373 endPos = startPos; |
d11a68f214eb
Fix indentation after astyle reindent.
Matti Hamalainen <ccr@tnsp.org>
parents:
403
diff
changeset
|
1374 while (startPos > 0 && str[startPos - 1] != ' ') startPos--; |
d11a68f214eb
Fix indentation after astyle reindent.
Matti Hamalainen <ccr@tnsp.org>
parents:
403
diff
changeset
|
1375 while (endPos < buf->len - 1 && str[endPos + 1] != ' ') endPos++; |
d11a68f214eb
Fix indentation after astyle reindent.
Matti Hamalainen <ccr@tnsp.org>
parents:
403
diff
changeset
|
1376 newPattern = TRUE; |
d11a68f214eb
Fix indentation after astyle reindent.
Matti Hamalainen <ccr@tnsp.org>
parents:
403
diff
changeset
|
1377 } |
d11a68f214eb
Fix indentation after astyle reindent.
Matti Hamalainen <ccr@tnsp.org>
parents:
403
diff
changeset
|
1378 else |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
1379 // previous word, new pattern |
404
d11a68f214eb
Fix indentation after astyle reindent.
Matti Hamalainen <ccr@tnsp.org>
parents:
403
diff
changeset
|
1380 if (startPos >= 1 && str[startPos - 1] != ' ') |
d11a68f214eb
Fix indentation after astyle reindent.
Matti Hamalainen <ccr@tnsp.org>
parents:
403
diff
changeset
|
1381 { |
d11a68f214eb
Fix indentation after astyle reindent.
Matti Hamalainen <ccr@tnsp.org>
parents:
403
diff
changeset
|
1382 startPos -= 1; |
d11a68f214eb
Fix indentation after astyle reindent.
Matti Hamalainen <ccr@tnsp.org>
parents:
403
diff
changeset
|
1383 endPos = startPos; |
d11a68f214eb
Fix indentation after astyle reindent.
Matti Hamalainen <ccr@tnsp.org>
parents:
403
diff
changeset
|
1384 while (startPos > 0 && str[startPos - 1] != ' ') startPos--; |
d11a68f214eb
Fix indentation after astyle reindent.
Matti Hamalainen <ccr@tnsp.org>
parents:
403
diff
changeset
|
1385 newPattern = TRUE; |
d11a68f214eb
Fix indentation after astyle reindent.
Matti Hamalainen <ccr@tnsp.org>
parents:
403
diff
changeset
|
1386 } |
d11a68f214eb
Fix indentation after astyle reindent.
Matti Hamalainen <ccr@tnsp.org>
parents:
403
diff
changeset
|
1387 else |
d11a68f214eb
Fix indentation after astyle reindent.
Matti Hamalainen <ccr@tnsp.org>
parents:
403
diff
changeset
|
1388 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
|
1389 |
429
2ac24f1e241b
Start working on command completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
427
diff
changeset
|
1390 // Check if this is a command completion |
2ac24f1e241b
Start working on command completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
427
diff
changeset
|
1391 isCommand = (str[0] == '/' && startPos == 0); |
2ac24f1e241b
Start working on command completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
427
diff
changeset
|
1392 |
2ac24f1e241b
Start working on command completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
427
diff
changeset
|
1393 if (!isCommand && str[endPos] == optNickSep) |
391 | 1394 { |
189
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1395 endPos--; |
391 | 1396 if (startPos > 0) |
113
2a53156e7e12
Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents:
112
diff
changeset
|
1397 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
|
1398 hasSeparator = TRUE; |
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1399 } |
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1400 |
451 | 1401 hasSpace = (buf->pos > 0 && str[buf->pos - 1] == ' ') || |
447
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1402 (buf->pos <= buf->len && str[buf->pos] == ' '); |
391 | 1403 |
1404 if (newPattern) | |
1405 { | |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
1406 // 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
|
1407 char *npattern = nn_editbuf_get_string(buf, startPos, endPos); |
372
b9f0bdad6285
Use th_strcasecmp() and th_strncasecmp().
Matti Hamalainen <ccr@tnsp.org>
parents:
369
diff
changeset
|
1408 if (pattern && npattern && th_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
|
1409 again = TRUE; |
391 | 1410 |
189
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1411 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
|
1412 pattern = npattern; |
391 | 1413 |
1414 if (!again) | |
1415 { | |
116
741e45592522
Add simple "prediction" into tab-completion based on previously gotten last
Matti Hamalainen <ccr@tnsp.org>
parents:
115
diff
changeset
|
1416 th_free(previous); |
741e45592522
Add simple "prediction" into tab-completion based on previously gotten last
Matti Hamalainen <ccr@tnsp.org>
parents:
115
diff
changeset
|
1417 previous = NULL; |
741e45592522
Add simple "prediction" into tab-completion based on previously gotten last
Matti Hamalainen <ccr@tnsp.org>
parents:
115
diff
changeset
|
1418 } |
189
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1419 } |
116
741e45592522
Add simple "prediction" into tab-completion based on previously gotten last
Matti Hamalainen <ccr@tnsp.org>
parents:
115
diff
changeset
|
1420 |
429
2ac24f1e241b
Start working on command completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
427
diff
changeset
|
1421 if (!pattern) |
2ac24f1e241b
Start working on command completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
427
diff
changeset
|
1422 return FALSE; |
2ac24f1e241b
Start working on command completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
427
diff
changeset
|
1423 |
2ac24f1e241b
Start working on command completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
427
diff
changeset
|
1424 if (isCommand) |
2ac24f1e241b
Start working on command completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
427
diff
changeset
|
1425 { |
450
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1426 nn_usercmd_t *cmd = nn_usercmd_match(userCmds, pattern, previous, again); |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1427 if (cmd) |
429
2ac24f1e241b
Start working on command completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
427
diff
changeset
|
1428 { |
450
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1429 size_t i; |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1430 nn_tabcomplete_replace(buf, &i, startPos, endPos, cmd->name); |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1431 |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1432 if (!hasSpace) |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1433 nn_editbuf_insert(buf, i++, ' '); |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1434 |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1435 nn_tabcomplete_finish(buf, &previous, startPos, cmd->name); |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1436 return TRUE; |
429
2ac24f1e241b
Start working on command completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
427
diff
changeset
|
1437 } |
2ac24f1e241b
Start working on command completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
427
diff
changeset
|
1438 } |
2ac24f1e241b
Start working on command completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
427
diff
changeset
|
1439 else |
391 | 1440 { |
446
3396acd40147
Rename and remove some functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
1441 nn_user_t *user = nn_userhash_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
|
1442 |
391 | 1443 if (user) |
1444 { | |
431
a9b20b31cae1
More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
430
diff
changeset
|
1445 size_t i; |
449
7d9fa9f7caf1
Rename tab completion functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
448
diff
changeset
|
1446 nn_tabcomplete_replace(buf, &i, startPos, endPos, user->name); |
107
8037a3a7e491
Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
104
diff
changeset
|
1447 |
391 | 1448 if (!hasSeparator && startPos == 0) |
1449 { | |
189
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1450 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
|
1451 startPos++; |
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1452 } |
447
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1453 else |
189
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1454 if (hasSeparator) |
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1455 startPos++; |
447
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1456 |
189
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1457 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
|
1458 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
|
1459 |
449
7d9fa9f7caf1
Rename tab completion functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
448
diff
changeset
|
1460 nn_tabcomplete_finish(buf, &previous, startPos, 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
|
1461 return TRUE; |
107
8037a3a7e491
Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
104
diff
changeset
|
1462 } |
8037a3a7e491
Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
104
diff
changeset
|
1463 } |
391 | 1464 |
113
2a53156e7e12
Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents:
112
diff
changeset
|
1465 return FALSE; |
103
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
1466 } |
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
1467 |
405 | 1468 |
513 | 1469 BOOL processUserInput(int c, nn_editbuf_t *editBuf, nn_editstate_t *editState) |
1470 { | |
1471 // Chat window switching via Meta/Esc-[1..9] | |
1472 if (c >= 0x5001 && c <= 0x5009) | |
1473 { | |
1474 nn_window_t *win = nnwin_get(c - 0x5000); | |
1475 if (win != NULL) | |
1476 { | |
1477 currWin = win; | |
1478 editState->update = TRUE; | |
1479 } | |
1480 } | |
1481 else | |
1482 switch (c) | |
1483 { | |
1484 case KEY_ENTER: | |
1485 // Call the user input handler | |
1486 if (editBuf->len > 0) | |
1487 { | |
1488 int result; | |
1489 | |
1490 if (editHistMax > 0) | |
1491 { | |
1492 nn_editbuf_free(editHistBuf[SET_MAX_HISTORY+1]); | |
1493 editHistBuf[SET_MAX_HISTORY+1] = NULL; | |
1494 memmove(&editHistBuf[2], &editHistBuf[1], | |
1495 editHistMax * sizeof(editHistBuf[0])); | |
1496 } | |
1497 | |
1498 editHistPos = 0; | |
1499 editHistBuf[1] = nn_editbuf_copy(editBuf); | |
1500 if (editHistMax < SET_MAX_HISTORY) | |
1501 editHistMax++; | |
1502 | |
1503 result = nn_handle_input(editState->conn, editBuf->data, editBuf->len); | |
1504 | |
1505 nn_editbuf_clear(editBuf); | |
1506 | |
1507 if (result < 0) | |
1508 { | |
1509 errorMsg("Fatal error handling user input: %s\n", editBuf->data); | |
1510 editState->isError = TRUE; | |
1511 } | |
1512 else | |
1513 { | |
1514 // Update time value of last sent message for unidle timeouts | |
1515 editState->prevKeepAlive = time(NULL); | |
1516 } | |
1517 } | |
1518 break; | |
1519 | |
1520 case KEY_NPAGE: | |
1521 case KEY_PPAGE: | |
1522 // Page Up / Page Down | |
1523 if (currWin != NULL) | |
1524 { | |
1525 int oldPos = currWin->pos, page = (scrHeight - 4) / 3; | |
1526 | |
1527 currWin->pos += (c == KEY_NPAGE) ? - page : page; | |
1528 | |
1529 if (currWin->pos >= currWin->data->n - page) | |
1530 currWin->pos = currWin->data->n - page; | |
1531 if (currWin->pos < 0) | |
1532 currWin->pos = 0; | |
1533 | |
1534 if (oldPos != currWin->pos) | |
1535 editState->update = TRUE; | |
1536 } | |
1537 break; | |
1538 | |
1539 case KEY_UP: // Backwards in input history | |
1540 if (editHistPos == 0) | |
1541 { | |
1542 nn_editbuf_free(editHistBuf[0]); | |
1543 editHistBuf[0] = nn_editbuf_copy(editBuf); | |
1544 } | |
1545 if (editHistPos < editHistMax) | |
1546 { | |
1547 editHistPos++; | |
1548 nn_editbuf_free(editBuf); | |
1549 editBuf = nn_editbuf_copy(editHistBuf[editHistPos]); | |
1550 } | |
1551 break; | |
1552 | |
1553 case KEY_DOWN: // Forwards in input history | |
1554 if (editHistPos > 0) | |
1555 { | |
1556 editHistPos--; | |
1557 nn_editbuf_free(editBuf); | |
1558 editBuf = nn_editbuf_copy(editHistBuf[editHistPos]); | |
1559 } | |
1560 break; | |
1561 | |
1562 case KEY_F(5): // F5 = Ignore mode | |
515 | 1563 setIgnoreMode = !setIgnoreMode; |
513 | 1564 printMsgQ(currWin, "Ignore mode = %s\n", setIgnoreMode ? "ON" : "OFF"); |
1565 break; | |
1566 | |
519
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
1567 case KEY_F(6): // F6 = Ignore mode |
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
1568 optOnlyFriendPrv = !optOnlyFriendPrv; |
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
1569 printMsgQ(currWin, "Only friends allowed to PRV you = %s\n", optOnlyFriendPrv ? "ON" : "OFF"); |
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
1570 break; |
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
1571 |
513 | 1572 case KEY_F(9): // F9 = Quit |
1573 printMsg(currWin, "Quitting per user request (%d/0x%x).\n", c, c); | |
571
3ae357fd34bb
Rename quit-related internal variables.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
1574 appQuitFlag = TRUE; |
513 | 1575 break; |
1576 | |
1577 case 0x09: // Tab = complete username or command | |
1578 nn_tabcomplete_buffer(editBuf); | |
1579 break; | |
1580 | |
1581 default: | |
1582 return FALSE; | |
1583 } | |
1584 | |
1585 return TRUE; | |
1586 } | |
1587 | |
1588 | |
1589 BOOL processUserPrompt(int c, nn_editbuf_t *editBuf, nn_editstate_t *editState) | |
1590 { | |
1591 (void) editBuf; | |
1592 | |
1593 switch (c) | |
1594 { | |
1595 case KEY_ENTER: | |
1596 editState->done = TRUE; | |
1597 break; | |
526
ba5807ebff88
Make it possible to quit when entering username/passwd.
Matti Hamalainen <ccr@tnsp.org>
parents:
521
diff
changeset
|
1598 |
ba5807ebff88
Make it possible to quit when entering username/passwd.
Matti Hamalainen <ccr@tnsp.org>
parents:
521
diff
changeset
|
1599 case KEY_F(9): // F9 = Quit |
ba5807ebff88
Make it possible to quit when entering username/passwd.
Matti Hamalainen <ccr@tnsp.org>
parents:
521
diff
changeset
|
1600 printMsg(currWin, "Quitting per user request (%d/0x%x).\n", c, c); |
571
3ae357fd34bb
Rename quit-related internal variables.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
1601 appQuitFlag = TRUE; |
526
ba5807ebff88
Make it possible to quit when entering username/passwd.
Matti Hamalainen <ccr@tnsp.org>
parents:
521
diff
changeset
|
1602 break; |
513 | 1603 |
1604 default: | |
1605 return FALSE; | |
1606 } | |
1607 | |
1608 return TRUE; | |
1609 } | |
1610 | |
1611 | |
1612 void updateUserPrompt(nn_editbuf_t *editBuf, nn_editstate_t *editState) | |
1613 { | |
1614 nnwin_update(editState->update, editState->mask, editBuf, optUserName, optUserColor); | |
1615 } | |
1616 | |
1617 | |
535
379e361f1144
Fix various segfault issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
533
diff
changeset
|
1618 void clearEditState(nn_editstate_t *st) |
379e361f1144
Fix various segfault issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
533
diff
changeset
|
1619 { |
379e361f1144
Fix various segfault issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
533
diff
changeset
|
1620 memset(st, 0, sizeof(nn_editstate_t)); |
379e361f1144
Fix various segfault issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
533
diff
changeset
|
1621 st->insertMode = TRUE; |
379e361f1144
Fix various segfault issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
533
diff
changeset
|
1622 st->debugMsg = debugMsg; |
379e361f1144
Fix various segfault issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
533
diff
changeset
|
1623 } |
379e361f1144
Fix various segfault issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
533
diff
changeset
|
1624 |
541
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1625 |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1626 BOOL nn_log_open(nn_window_t *win) |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1627 { |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1628 char *path = NULL; |
556
9b72d0060b85
Create configuration and log files with reduced permissions (rw for user
Matti Hamalainen <ccr@tnsp.org>
parents:
555
diff
changeset
|
1629 #ifndef __WIN32 |
9b72d0060b85
Create configuration and log files with reduced permissions (rw for user
Matti Hamalainen <ccr@tnsp.org>
parents:
555
diff
changeset
|
1630 int logFd = -1; |
9b72d0060b85
Create configuration and log files with reduced permissions (rw for user
Matti Hamalainen <ccr@tnsp.org>
parents:
555
diff
changeset
|
1631 #endif |
541
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1632 |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1633 if (!optLogEnable) |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1634 return FALSE; |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1635 |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1636 if (optLogPath != NULL) |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1637 { |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1638 char *lt = strrchr(optLogPath, SET_DIR_SEPARATOR); |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1639 if (lt == NULL || lt[1] != 0) |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1640 path = th_strdup_printf("%s%c", optLogPath, SET_DIR_SEPARATOR); |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1641 else |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1642 path = th_strdup(optLogPath); |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1643 } |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1644 |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1645 if (win->id == NULL) |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1646 { |
554
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
1647 // Main window log (aka room log) |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
1648 if (optLogDaily) |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
1649 { |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
1650 char stamp[64]; |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
1651 str_get_timestamp(stamp, sizeof(stamp), "%Y-%m-%d"); |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
1652 win->logFilename = th_strdup_printf("%sroom_%d-%s%s", |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
1653 path != NULL ? path : "", optPort, |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
1654 stamp, optLogExtension); |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
1655 } |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
1656 else |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
1657 { |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
1658 win->logFilename = th_strdup_printf("%sroom_%d%s", |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
1659 path != NULL ? path : "", optPort, optLogExtension); |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
1660 } |
541
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1661 } |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1662 else |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1663 { |
552 | 1664 // PRV chat log |
541
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1665 size_t pos; |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1666 char *cleaned; |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1667 |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1668 if ((cleaned = th_strdup(win->id)) == NULL) |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1669 return FALSE; |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1670 |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1671 for (pos = 0; cleaned[pos] != 0; pos++) |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1672 { |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1673 if (!isalnum(cleaned[pos])) |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1674 cleaned[pos] = '_'; |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1675 } |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1676 |
551
89fafb218396
Fix situations where the log path is unset.
Matti Hamalainen <ccr@tnsp.org>
parents:
550
diff
changeset
|
1677 win->logFilename = th_strdup_printf("%s%s%s", |
89fafb218396
Fix situations where the log path is unset.
Matti Hamalainen <ccr@tnsp.org>
parents:
550
diff
changeset
|
1678 path != NULL ? path : "", cleaned, optLogExtension); |
89fafb218396
Fix situations where the log path is unset.
Matti Hamalainen <ccr@tnsp.org>
parents:
550
diff
changeset
|
1679 |
541
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1680 th_free(cleaned); |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1681 } |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1682 |
552 | 1683 // Try to open the file for appending |
541
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1684 if (win->logFilename == NULL) |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1685 goto error; |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1686 |
556
9b72d0060b85
Create configuration and log files with reduced permissions (rw for user
Matti Hamalainen <ccr@tnsp.org>
parents:
555
diff
changeset
|
1687 #ifdef __WIN32 |
541
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1688 if ((win->logFile = fopen(win->logFilename, "a")) == NULL) |
556
9b72d0060b85
Create configuration and log files with reduced permissions (rw for user
Matti Hamalainen <ccr@tnsp.org>
parents:
555
diff
changeset
|
1689 #else |
9b72d0060b85
Create configuration and log files with reduced permissions (rw for user
Matti Hamalainen <ccr@tnsp.org>
parents:
555
diff
changeset
|
1690 if ((logFd = open(win->logFilename, O_CREAT | O_APPEND | O_WRONLY, S_IRUSR | S_IWUSR)) == -1 || |
9b72d0060b85
Create configuration and log files with reduced permissions (rw for user
Matti Hamalainen <ccr@tnsp.org>
parents:
555
diff
changeset
|
1691 (win->logFile = fdopen(logFd, "a")) == NULL) |
9b72d0060b85
Create configuration and log files with reduced permissions (rw for user
Matti Hamalainen <ccr@tnsp.org>
parents:
555
diff
changeset
|
1692 #endif |
541
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1693 { |
556
9b72d0060b85
Create configuration and log files with reduced permissions (rw for user
Matti Hamalainen <ccr@tnsp.org>
parents:
555
diff
changeset
|
1694 errorMsg("Could not open logfile '%s' for appending, %d: %s\n", |
9b72d0060b85
Create configuration and log files with reduced permissions (rw for user
Matti Hamalainen <ccr@tnsp.org>
parents:
555
diff
changeset
|
1695 win->logFilename, errno, strerror(errno)); |
541
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1696 goto error; |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1697 } |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1698 |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1699 printMsg(win, "Logging to '%s'.\n", win->logFilename); |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1700 |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1701 th_free(path); |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1702 return TRUE; |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1703 |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1704 error: |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1705 th_free(path); |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1706 th_free(win->logFilename); |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1707 win->logFilename = NULL; |
556
9b72d0060b85
Create configuration and log files with reduced permissions (rw for user
Matti Hamalainen <ccr@tnsp.org>
parents:
555
diff
changeset
|
1708 if (win->logFile != NULL) |
9b72d0060b85
Create configuration and log files with reduced permissions (rw for user
Matti Hamalainen <ccr@tnsp.org>
parents:
555
diff
changeset
|
1709 fclose(win->logFile); |
9b72d0060b85
Create configuration and log files with reduced permissions (rw for user
Matti Hamalainen <ccr@tnsp.org>
parents:
555
diff
changeset
|
1710 #ifndef __WIN32 |
9b72d0060b85
Create configuration and log files with reduced permissions (rw for user
Matti Hamalainen <ccr@tnsp.org>
parents:
555
diff
changeset
|
1711 else |
9b72d0060b85
Create configuration and log files with reduced permissions (rw for user
Matti Hamalainen <ccr@tnsp.org>
parents:
555
diff
changeset
|
1712 if (logFd >= 0) |
9b72d0060b85
Create configuration and log files with reduced permissions (rw for user
Matti Hamalainen <ccr@tnsp.org>
parents:
555
diff
changeset
|
1713 close(logFd); |
9b72d0060b85
Create configuration and log files with reduced permissions (rw for user
Matti Hamalainen <ccr@tnsp.org>
parents:
555
diff
changeset
|
1714 #endif |
541
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1715 return FALSE; |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1716 } |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1717 |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1718 |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1719 void nn_log_close(nn_window_t *win) |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1720 { |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1721 if (win->logFile != NULL) |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1722 fclose(win->logFile); |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1723 win->logFile = NULL; |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1724 |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1725 th_free(win->logFilename); |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1726 win->logFilename = NULL; |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1727 } |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1728 |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1729 |
554
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
1730 BOOL nn_log_reopen(nn_window_t *win) |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
1731 { |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
1732 nn_log_close(win); |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
1733 return nn_log_open(win); |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
1734 } |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
1735 |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
1736 |
548
28688eb812de
Add helper functions for checking if target path is writable, readable or directory and creating directory structures recursively.
Matti Hamalainen <ccr@tnsp.org>
parents:
546
diff
changeset
|
1737 BOOL nn_stat_path(const char *path, BOOL *isDirectory, BOOL *isWritable, BOOL *isReadable) |
28688eb812de
Add helper functions for checking if target path is writable, readable or directory and creating directory structures recursively.
Matti Hamalainen <ccr@tnsp.org>
parents:
546
diff
changeset
|
1738 { |
28688eb812de
Add helper functions for checking if target path is writable, readable or directory and creating directory structures recursively.
Matti Hamalainen <ccr@tnsp.org>
parents:
546
diff
changeset
|
1739 #ifdef __WIN32 |
28688eb812de
Add helper functions for checking if target path is writable, readable or directory and creating directory structures recursively.
Matti Hamalainen <ccr@tnsp.org>
parents:
546
diff
changeset
|
1740 DWORD attr = GetFileAttributes(path); |
28688eb812de
Add helper functions for checking if target path is writable, readable or directory and creating directory structures recursively.
Matti Hamalainen <ccr@tnsp.org>
parents:
546
diff
changeset
|
1741 |
557
02244c553741
Fix Win32 side of log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
556
diff
changeset
|
1742 *isDirectory = (attr & FILE_ATTRIBUTE_DIRECTORY) != 0; |
02244c553741
Fix Win32 side of log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
556
diff
changeset
|
1743 *isWritable = (attr & FILE_ATTRIBUTE_READONLY) == 0; |
548
28688eb812de
Add helper functions for checking if target path is writable, readable or directory and creating directory structures recursively.
Matti Hamalainen <ccr@tnsp.org>
parents:
546
diff
changeset
|
1744 *isReadable = TRUE; |
28688eb812de
Add helper functions for checking if target path is writable, readable or directory and creating directory structures recursively.
Matti Hamalainen <ccr@tnsp.org>
parents:
546
diff
changeset
|
1745 #else |
28688eb812de
Add helper functions for checking if target path is writable, readable or directory and creating directory structures recursively.
Matti Hamalainen <ccr@tnsp.org>
parents:
546
diff
changeset
|
1746 uid_t id = geteuid(); |
28688eb812de
Add helper functions for checking if target path is writable, readable or directory and creating directory structures recursively.
Matti Hamalainen <ccr@tnsp.org>
parents:
546
diff
changeset
|
1747 struct stat sb; |
28688eb812de
Add helper functions for checking if target path is writable, readable or directory and creating directory structures recursively.
Matti Hamalainen <ccr@tnsp.org>
parents:
546
diff
changeset
|
1748 if (stat(path, &sb) < 0) |
28688eb812de
Add helper functions for checking if target path is writable, readable or directory and creating directory structures recursively.
Matti Hamalainen <ccr@tnsp.org>
parents:
546
diff
changeset
|
1749 return FALSE; |
28688eb812de
Add helper functions for checking if target path is writable, readable or directory and creating directory structures recursively.
Matti Hamalainen <ccr@tnsp.org>
parents:
546
diff
changeset
|
1750 |
28688eb812de
Add helper functions for checking if target path is writable, readable or directory and creating directory structures recursively.
Matti Hamalainen <ccr@tnsp.org>
parents:
546
diff
changeset
|
1751 *isDirectory = (S_ISDIR(sb.st_mode)); |
28688eb812de
Add helper functions for checking if target path is writable, readable or directory and creating directory structures recursively.
Matti Hamalainen <ccr@tnsp.org>
parents:
546
diff
changeset
|
1752 *isWritable = (id == sb.st_uid && (sb.st_mode & S_IWUSR)); |
28688eb812de
Add helper functions for checking if target path is writable, readable or directory and creating directory structures recursively.
Matti Hamalainen <ccr@tnsp.org>
parents:
546
diff
changeset
|
1753 *isReadable = (id == sb.st_uid && (sb.st_mode & S_IRUSR)); |
28688eb812de
Add helper functions for checking if target path is writable, readable or directory and creating directory structures recursively.
Matti Hamalainen <ccr@tnsp.org>
parents:
546
diff
changeset
|
1754 #endif |
557
02244c553741
Fix Win32 side of log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
556
diff
changeset
|
1755 |
560
1b2d434a651b
Comment out a debug message.
Matti Hamalainen <ccr@tnsp.org>
parents:
558
diff
changeset
|
1756 // THERR("'%s': dir=%d, wr=%d, rd=%d\n", path, *isDirectory, *isWritable, *isReadable); |
548
28688eb812de
Add helper functions for checking if target path is writable, readable or directory and creating directory structures recursively.
Matti Hamalainen <ccr@tnsp.org>
parents:
546
diff
changeset
|
1757 return TRUE; |
28688eb812de
Add helper functions for checking if target path is writable, readable or directory and creating directory structures recursively.
Matti Hamalainen <ccr@tnsp.org>
parents:
546
diff
changeset
|
1758 } |
28688eb812de
Add helper functions for checking if target path is writable, readable or directory and creating directory structures recursively.
Matti Hamalainen <ccr@tnsp.org>
parents:
546
diff
changeset
|
1759 |
28688eb812de
Add helper functions for checking if target path is writable, readable or directory and creating directory structures recursively.
Matti Hamalainen <ccr@tnsp.org>
parents:
546
diff
changeset
|
1760 |
550
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1761 BOOL nn_mkdir_rec(const char *cpath) |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1762 { |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1763 char save, *path = th_strdup(cpath); |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1764 size_t start = 0, end; |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1765 BOOL res = FALSE, exists, isDir, isWritable, isReadable; |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1766 |
557
02244c553741
Fix Win32 side of log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
556
diff
changeset
|
1767 THMSG(0, "Creating directory %s\n", cpath); |
550
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1768 do |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1769 { |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1770 for (save = 0, end = start; path[end] != 0; end++) |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1771 if (path[end] == SET_DIR_SEPARATOR) |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1772 { |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1773 save = path[end]; |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1774 path[end] = 0; |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1775 break; |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1776 } |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1777 |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1778 |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1779 if (path[start] != 0) |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1780 { |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1781 exists = nn_stat_path(path, &isDir, &isWritable, &isReadable); |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1782 if (exists && !isDir) |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1783 goto error; |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1784 |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1785 if (!exists) |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1786 { |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1787 #ifdef __WIN32 |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1788 if (!CreateDirectory(path, NULL)) |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1789 goto error; |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1790 #else |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1791 if (mkdir(path, 0x1c9) < 0) |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1792 goto error; |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1793 #endif |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1794 } |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1795 } |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1796 |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1797 path[end] = save; |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1798 start = end + 1; |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1799 } while (save != 0); |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1800 |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1801 res = TRUE; |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1802 |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1803 error: |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1804 th_free(path); |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1805 return res; |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1806 } |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1807 |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1808 |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1809 |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1810 |
0 | 1811 int main(int argc, char *argv[]) |
1812 { | |
513 | 1813 char *tmpStr; |
1814 int index, updateCount = 0; | |
1815 BOOL argsOK, colorSet = FALSE; | |
168
2e4850ece456
Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
165
diff
changeset
|
1816 nn_conn_t *conn = NULL; |
2e4850ece456
Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
165
diff
changeset
|
1817 nn_editbuf_t *editBuf = nn_editbuf_new(NN_TMPBUF_SIZE); |
513 | 1818 nn_editstate_t editState; |
561
1ff9e85a1fcc
Rework the configuration file loading and saving to use the I/O context and new th-config API.
Matti Hamalainen <ccr@tnsp.org>
parents:
560
diff
changeset
|
1819 th_cfgitem_t *tmpcfg; |
432
966c521e0954
Rename user home directory variable.
Matti Hamalainen <ccr@tnsp.org>
parents:
431
diff
changeset
|
1820 char *setHomeDir = NULL; |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
1821 |
513 | 1822 memset(editHistBuf, 0, sizeof(editHistBuf)); |
535
379e361f1144
Fix various segfault issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
533
diff
changeset
|
1823 clearEditState(&editState); |
391 | 1824 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
1825 // 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
|
1826 th_init("NNChat", "Newbie Nudes chat client", NN_VERSION, |
598 | 1827 "Written and designed by Anonymous Finnish Guy (C) 2008-2014", |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1828 "This software is freeware, use and distribute as you wish."); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1829 th_verbosityLevel = 0; |
133 | 1830 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
1831 // Read configuration file |
148 | 1832 tmpcfg = NULL; |
133 | 1833 th_cfg_add_comment(&tmpcfg, "General settings"); |
1834 th_cfg_add_string(&tmpcfg, "username", &optUserName, NULL); | |
1835 th_cfg_add_string(&tmpcfg, "password", &optPassword, NULL); | |
409
4556174b5be8
Make nickname autocomplete separator configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
408
diff
changeset
|
1836 |
150
db5e7a1f1eb3
Add comment in config file about format of user color setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
149
diff
changeset
|
1837 th_cfg_add_comment(&tmpcfg, "Default color as a hex-triplet"); |
133 | 1838 th_cfg_add_hexvalue(&tmpcfg, "color", &optUserColor, optUserColor); |
391 | 1839 |
149
a4d6707161a7
Add config file option for default setting of ignore mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
1840 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
|
1841 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
|
1842 th_cfg_add_comment(&tmpcfg, "People to be ignored when ignore mode is enabled"); |
265
b9c650db8a6a
Rename variable nnIgnoreList to setIgnoreList.
Matti Hamalainen <ccr@tnsp.org>
parents:
264
diff
changeset
|
1843 th_cfg_add_string_list(&tmpcfg, "ignore_list", &setIgnoreList); |
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
|
1844 |
519
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
1845 th_cfg_add_comment(&tmpcfg, "Allow only defined friends to private to you"); |
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
1846 th_cfg_add_bool(&tmpcfg, "prv_friends", &optOnlyFriendPrv, optOnlyFriendPrv); |
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
1847 th_cfg_add_comment(&tmpcfg, "List of your friends"); |
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
1848 th_cfg_add_string_list(&tmpcfg, "friend_list", &setFriendList); |
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
1849 |
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
|
1850 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
|
1851 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
|
1852 |
409
4556174b5be8
Make nickname autocomplete separator configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
408
diff
changeset
|
1853 th_cfg_add_comment(&tmpcfg, "Character used as nickname auto-completion separator (default is ':')"); |
4556174b5be8
Make nickname autocomplete separator configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
408
diff
changeset
|
1854 th_cfg_add_string(&tmpcfg, "nick_separator", &optNickSepStr, NULL); |
4556174b5be8
Make nickname autocomplete separator configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
408
diff
changeset
|
1855 |
133 | 1856 th_cfg_add_section(&cfg, "general", tmpcfg); |
1857 | |
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
|
1858 |
133 | 1859 tmpcfg = NULL; |
1860 th_cfg_add_comment(&tmpcfg, "Chat server hostname or IP address"); | |
1861 th_cfg_add_string(&tmpcfg, "host", &optServer, optServer); | |
593
00f476c65e1b
Remove port descriptions from configuration.
Matti Hamalainen <ccr@tnsp.org>
parents:
592
diff
changeset
|
1862 |
00f476c65e1b
Remove port descriptions from configuration.
Matti Hamalainen <ccr@tnsp.org>
parents:
592
diff
changeset
|
1863 th_cfg_add_comment(&tmpcfg, "Default port to connect"); |
133 | 1864 th_cfg_add_int(&tmpcfg, "port", &optPort, optPort); |
1865 th_cfg_add_section(&cfg, "server", tmpcfg); | |
1866 | |
239
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
1867 tmpcfg = NULL; |
369
461a6befb7c3
Oops, the proxy type was accidentally called "port" in the configuration file, as was the actual port setting. Fixed.
Matti Hamalainen <ccr@tnsp.org>
parents:
360
diff
changeset
|
1868 th_cfg_add_comment(&tmpcfg, "Proxy server type (0 = none, 1 = SOCKS 4, 2 = SOCKS 4a)"); |
461a6befb7c3
Oops, the proxy type was accidentally called "port" in the configuration file, as was the actual port setting. Fixed.
Matti Hamalainen <ccr@tnsp.org>
parents:
360
diff
changeset
|
1869 th_cfg_add_int(&tmpcfg, "type", &optProxyType, optProxyType); |
353
83ae825bb8c1
Add configuration section for proxy settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
352
diff
changeset
|
1870 th_cfg_add_comment(&tmpcfg, "Proxy server host name"); |
83ae825bb8c1
Add configuration section for proxy settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
352
diff
changeset
|
1871 th_cfg_add_string(&tmpcfg, "host", &optProxyServer, optProxyServer); |
83ae825bb8c1
Add configuration section for proxy settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
352
diff
changeset
|
1872 th_cfg_add_comment(&tmpcfg, "Proxy port, 1080 is the standard SOCKS port"); |
83ae825bb8c1
Add configuration section for proxy settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
352
diff
changeset
|
1873 th_cfg_add_int(&tmpcfg, "port", &optProxyPort, optProxyPort); |
602
4bae14092b78
Add parameters (unused for now) for proxy password etc. in case SOCKS 5
Matti Hamalainen <ccr@tnsp.org>
parents:
601
diff
changeset
|
1874 th_cfg_add_comment(&tmpcfg, "Proxy user ID"); |
4bae14092b78
Add parameters (unused for now) for proxy password etc. in case SOCKS 5
Matti Hamalainen <ccr@tnsp.org>
parents:
601
diff
changeset
|
1875 th_cfg_add_string(&tmpcfg, "userid", &optProxyUserID, optProxyUserID); |
4bae14092b78
Add parameters (unused for now) for proxy password etc. in case SOCKS 5
Matti Hamalainen <ccr@tnsp.org>
parents:
601
diff
changeset
|
1876 // th_cfg_add_comment(&tmpcfg, "Proxy password (only available for SOCKS 5)"); |
4bae14092b78
Add parameters (unused for now) for proxy password etc. in case SOCKS 5
Matti Hamalainen <ccr@tnsp.org>
parents:
601
diff
changeset
|
1877 // th_cfg_add_string(&tmpcfg, "password", &optProxyPassword, optProxyPassword); |
353
83ae825bb8c1
Add configuration section for proxy settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
352
diff
changeset
|
1878 th_cfg_add_section(&cfg, "proxy", tmpcfg); |
83ae825bb8c1
Add configuration section for proxy settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
352
diff
changeset
|
1879 |
541
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1880 |
353
83ae825bb8c1
Add configuration section for proxy settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
352
diff
changeset
|
1881 tmpcfg = NULL; |
239
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
1882 th_cfg_add_comment(&tmpcfg, "Enable logging"); |
247 | 1883 th_cfg_add_bool(&tmpcfg, "enable", &optLogEnable, optLogEnable); |
554
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
1884 |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
1885 th_cfg_add_comment(&tmpcfg, "Use daily logfiles for room logs"); |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
1886 th_cfg_add_bool(&tmpcfg, "daily", &optLogDaily, optLogDaily); |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
1887 |
541
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1888 th_cfg_add_comment(&tmpcfg, "Log files path"); |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1889 th_cfg_add_string(&tmpcfg, "path", &optLogPath, optLogPath); |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1890 |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1891 th_cfg_add_comment(&tmpcfg, "Log filename extension"); |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1892 th_cfg_add_string(&tmpcfg, "extension", &optLogExtension, optLogExtension); |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1893 |
247 | 1894 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
|
1895 |
512 | 1896 // Get home directory path |
154
e8f67e344aaf
Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
1897 #ifdef __WIN32 |
e8f67e344aaf
Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
1898 { |
391 | 1899 char tmpPath[MAX_PATH]; |
1900 if (SHGetFolderPath(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, tmpPath) == S_OK) | |
432
966c521e0954
Rename user home directory variable.
Matti Hamalainen <ccr@tnsp.org>
parents:
431
diff
changeset
|
1901 setHomeDir = th_strdup(tmpPath); |
197
e0ec2280a778
Implement browser launching on Windows via ShellExecute().
Matti Hamalainen <ccr@tnsp.org>
parents:
196
diff
changeset
|
1902 |
391 | 1903 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
|
1904 } |
e8f67e344aaf
Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
1905 #else |
512 | 1906 { |
1907 char *xdgConfigDir = getenv("XDG_CONFIG_HOME"), | |
1908 *userHomeDir = getenv("HOME"); | |
546 | 1909 |
512 | 1910 #ifdef USE_XDG |
546 | 1911 // If XDG is enabled, try the environment variable first |
512 | 1912 if (xdgConfigDir != NULL) |
1913 setHomeDir = th_strdup(xdgConfigDir); | |
1914 else | |
546 | 1915 // Nope, try the obvious alternative |
512 | 1916 setHomeDir = th_strdup_printf("%s/.config", userHomeDir); |
1917 #else | |
1918 setHomeDir = th_strdup(userHomeDir); | |
1919 #endif | |
1920 } | |
154
e8f67e344aaf
Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
1921 #endif |
391 | 1922 |
432
966c521e0954
Rename user home directory variable.
Matti Hamalainen <ccr@tnsp.org>
parents:
431
diff
changeset
|
1923 if (setHomeDir != NULL) |
391 | 1924 { |
561
1ff9e85a1fcc
Rework the configuration file loading and saving to use the I/O context and new th-config API.
Matti Hamalainen <ccr@tnsp.org>
parents:
560
diff
changeset
|
1925 th_ioctx_t ctx; |
541
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1926 setConfigFile = th_strdup_printf("%s%c%s", setHomeDir, SET_DIR_SEPARATOR, SET_CONFIG_FILE); |
154
e8f67e344aaf
Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
1927 |
e8f67e344aaf
Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
1928 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
|
1929 |
565
de1af9652fef
Update to conform to changes in th-libs ioctx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
564
diff
changeset
|
1930 if (th_ioctx_open(&ctx, setConfigFile, "r", nn_ioctx_errfunc, nn_ioctx_msgfunc)) |
391 | 1931 { |
561
1ff9e85a1fcc
Rework the configuration file loading and saving to use the I/O context and new th-config API.
Matti Hamalainen <ccr@tnsp.org>
parents:
560
diff
changeset
|
1932 th_cfg_read(&ctx, cfg); |
1ff9e85a1fcc
Rework the configuration file loading and saving to use the I/O context and new th-config API.
Matti Hamalainen <ccr@tnsp.org>
parents:
560
diff
changeset
|
1933 th_ioctx_close(&ctx); |
315
864e6e52ed69
Fix a filehandle leak when reading in configuration file.
Matti Hamalainen <ccr@tnsp.org>
parents:
314
diff
changeset
|
1934 } |
133 | 1935 } |
196
edd5ce3e5399
Add simplistic username/password requester if none given on commandline or config file.
Matti Hamalainen <ccr@tnsp.org>
parents:
195
diff
changeset
|
1936 |
546 | 1937 optNickSep = optNickSepStr ? optNickSepStr[0] : SET_NICK_SEPARATOR; |
409
4556174b5be8
Make nickname autocomplete separator configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
408
diff
changeset
|
1938 |
137
fad8c31e41e6
Move browser code around a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
1939 setBrowser = getenv("BROWSER"); |
fad8c31e41e6
Move browser code around a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
1940 if (setBrowser == NULL) |
fad8c31e41e6
Move browser code around a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
1941 setBrowser = "firefox"; |
391 | 1942 |
545
895ede06ff11
Implement default log file directory.
Matti Hamalainen <ccr@tnsp.org>
parents:
544
diff
changeset
|
1943 if (optLogPath == NULL) |
895ede06ff11
Implement default log file directory.
Matti Hamalainen <ccr@tnsp.org>
parents:
544
diff
changeset
|
1944 { |
895ede06ff11
Implement default log file directory.
Matti Hamalainen <ccr@tnsp.org>
parents:
544
diff
changeset
|
1945 optLogPath = th_strdup_printf("%s%c%s%c", |
895ede06ff11
Implement default log file directory.
Matti Hamalainen <ccr@tnsp.org>
parents:
544
diff
changeset
|
1946 setHomeDir, SET_DIR_SEPARATOR, SET_LOG_DIR, SET_DIR_SEPARATOR); |
895ede06ff11
Implement default log file directory.
Matti Hamalainen <ccr@tnsp.org>
parents:
544
diff
changeset
|
1947 } |
895ede06ff11
Implement default log file directory.
Matti Hamalainen <ccr@tnsp.org>
parents:
544
diff
changeset
|
1948 |
558
e32881ece842
Only try to create log directories if logging is enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
557
diff
changeset
|
1949 if (optLogEnable) |
550
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1950 { |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1951 BOOL isDir, isWritable, isReadable; |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1952 if (nn_stat_path(optLogPath, &isDir, &isWritable, &isReadable)) |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1953 { |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1954 if (!isDir) |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1955 { |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1956 THERR("The log file path '%s' is not a directory.\n", |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1957 optLogPath); |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1958 goto err_exit; |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1959 } |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1960 else |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1961 if (!isWritable) |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1962 { |
557
02244c553741
Fix Win32 side of log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
556
diff
changeset
|
1963 #ifdef __WIN32 |
02244c553741
Fix Win32 side of log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
556
diff
changeset
|
1964 if (!nn_mkdir_rec(optLogPath)) |
02244c553741
Fix Win32 side of log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
556
diff
changeset
|
1965 { |
02244c553741
Fix Win32 side of log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
556
diff
changeset
|
1966 THERR("Could not create log file directory '%s'.\n", |
02244c553741
Fix Win32 side of log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
556
diff
changeset
|
1967 optLogPath); |
02244c553741
Fix Win32 side of log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
556
diff
changeset
|
1968 goto err_exit; |
02244c553741
Fix Win32 side of log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
556
diff
changeset
|
1969 } |
02244c553741
Fix Win32 side of log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
556
diff
changeset
|
1970 #else |
550
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1971 THERR("The log file path '%s' is not writable.\n", |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1972 optLogPath); |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1973 goto err_exit; |
557
02244c553741
Fix Win32 side of log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
556
diff
changeset
|
1974 #endif |
550
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1975 } |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1976 } |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1977 else |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1978 if (!nn_mkdir_rec(optLogPath)) |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1979 { |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1980 THERR("Could not create log file directory '%s'.\n", |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1981 optLogPath); |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1982 goto err_exit; |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1983 } |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1984 } |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
1985 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
1986 // Parse command line arguments |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1987 argsOK = th_args_process(argc, argv, optList, optListN, |
391 | 1988 argHandleOpt, argHandleFile, FALSE); |
26
b84fc46c6035
Improved color hex triplet parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
1989 |
391 | 1990 if (optUserNameCmd != NULL) |
1991 { | |
513 | 1992 THMSG(1, "Username set on commandline.\n"); |
198
21a37995c3fb
Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents:
197
diff
changeset
|
1993 optUserName = optUserNameCmd; |
21a37995c3fb
Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents:
197
diff
changeset
|
1994 optPassword = optPasswordCmd; |
21a37995c3fb
Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents:
197
diff
changeset
|
1995 } |
21a37995c3fb
Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents:
197
diff
changeset
|
1996 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1997 if (!argsOK) |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1998 return -2; |
64
6a3a917303e4
Some random cleanups, bring back WinSock support.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
1999 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
2000 // Allocate userhash |
391 | 2001 if ((nnUsers = nn_userhash_new()) == NULL) |
2002 { | |
103
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
2003 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
|
2004 return -105; |
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
2005 } |
64
6a3a917303e4
Some random cleanups, bring back WinSock support.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
2006 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
2007 // If no idle messages are set, add default |
391 | 2008 if (setIdleMessages == NULL) |
2009 { | |
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
|
2010 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
|
2011 } |
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
|
2012 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
2013 // Initialize network |
391 | 2014 if (!nn_network_init()) |
2015 { | |
91
acfc4b4bc180
Create network initialization functions in libnnchat and move Win32/WinSock code there.
Matti Hamalainen <ccr@tnsp.org>
parents:
90
diff
changeset
|
2016 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
|
2017 goto err_exit; |
391 | 2018 } |
68
3ab7751fdad1
MingW compatibility, with one ugly kludge.
Matti Hamalainen <ccr@tnsp.org>
parents:
67
diff
changeset
|
2019 |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
464
diff
changeset
|
2020 // Initialize curses windowing |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
464
diff
changeset
|
2021 if (!optDaemon && !nnwin_init(SET_DELAY)) |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
464
diff
changeset
|
2022 goto err_exit; |
391 | 2023 |
549
dd7b58eca06d
Use the helper functions for creating log file directory automatically.
Matti Hamalainen <ccr@tnsp.org>
parents:
548
diff
changeset
|
2024 |
571
3ae357fd34bb
Rename quit-related internal variables.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
2025 if (appCursesInit) |
501
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
497
diff
changeset
|
2026 { |
536
15e447d6a2a6
Fix to conform to th-libs changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
535
diff
changeset
|
2027 printMsg(NULL, "%s v%s - %s\n", th_prog_name, th_prog_version, th_prog_desc); |
513 | 2028 printMsg(NULL, "%s\n", th_prog_author); |
2029 printMsg(NULL, "%s\n", th_prog_license); | |
2030 | |
2031 nnwin_update(TRUE, FALSE, NULL, optUserName, optUserColor); | |
268
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
2032 |
513 | 2033 // Check if we have username and password |
2034 if (optUserName == NULL || optPassword == NULL) | |
2035 { | |
2036 printMsg(NULL, "Please enter your NN login credentials.\n"); | |
2037 printMsg(NULL, "You can avoid doing this every time by issuing '/save' after logging in.\n"); | |
2038 | |
2039 printMsg(NULL, "Enter your NN username ...\n"); | |
2040 optUserName = nnwin_prompt_requester(FALSE, &editState, processUserPrompt, updateUserPrompt); | |
571
3ae357fd34bb
Rename quit-related internal variables.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
2041 if (appQuitFlag) |
526
ba5807ebff88
Make it possible to quit when entering username/passwd.
Matti Hamalainen <ccr@tnsp.org>
parents:
521
diff
changeset
|
2042 goto err_exit; |
513 | 2043 |
2044 editState.mask = TRUE; | |
2045 printMsg(NULL, "Enter your NN password ...\n"); | |
2046 optPassword = nnwin_prompt_requester(TRUE, &editState, processUserPrompt, updateUserPrompt); | |
2047 editState.mask = FALSE; | |
571
3ae357fd34bb
Rename quit-related internal variables.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
2048 if (appQuitFlag) |
526
ba5807ebff88
Make it possible to quit when entering username/passwd.
Matti Hamalainen <ccr@tnsp.org>
parents:
521
diff
changeset
|
2049 goto err_exit; |
513 | 2050 } |
268
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
2051 } |
391 | 2052 |
2053 if (optUserName == NULL || optPassword == NULL) | |
2054 { | |
268
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
2055 errorMsg("Username and/or password not specified.\n"); |
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
2056 goto err_exit; |
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
2057 } |
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
2058 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
2059 // Create a connection |
564
6e5789cbb4d4
Change network layer error/info message passing API to pass direct strings
Matti Hamalainen <ccr@tnsp.org>
parents:
563
diff
changeset
|
2060 conn = nn_conn_new(nn_network_errfunc, nn_network_msgfunc); |
391 | 2061 if (conn == NULL) |
2062 { | |
354
c01e42fc9adb
More work on SOCKS proxy support, should work now.
Matti Hamalainen <ccr@tnsp.org>
parents:
353
diff
changeset
|
2063 errorMsg("Could not create connection structure.\n"); |
c01e42fc9adb
More work on SOCKS proxy support, should work now.
Matti Hamalainen <ccr@tnsp.org>
parents:
353
diff
changeset
|
2064 goto err_exit; |
c01e42fc9adb
More work on SOCKS proxy support, should work now.
Matti Hamalainen <ccr@tnsp.org>
parents:
353
diff
changeset
|
2065 } |
513 | 2066 |
2067 editState.conn = conn; | |
354
c01e42fc9adb
More work on SOCKS proxy support, should work now.
Matti Hamalainen <ccr@tnsp.org>
parents:
353
diff
changeset
|
2068 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
2069 // Are we using a proxy? |
391 | 2070 if (optProxyType != NN_PROXY_NONE && optProxyServer != NULL) |
2071 { | |
602
4bae14092b78
Add parameters (unused for now) for proxy password etc. in case SOCKS 5
Matti Hamalainen <ccr@tnsp.org>
parents:
601
diff
changeset
|
2072 if (optProxyUserID == NULL) |
4bae14092b78
Add parameters (unused for now) for proxy password etc. in case SOCKS 5
Matti Hamalainen <ccr@tnsp.org>
parents:
601
diff
changeset
|
2073 optProxyUserID = "James Bond"; |
4bae14092b78
Add parameters (unused for now) for proxy password etc. in case SOCKS 5
Matti Hamalainen <ccr@tnsp.org>
parents:
601
diff
changeset
|
2074 |
4bae14092b78
Add parameters (unused for now) for proxy password etc. in case SOCKS 5
Matti Hamalainen <ccr@tnsp.org>
parents:
601
diff
changeset
|
2075 if (nn_conn_set_proxy(conn, optProxyType, optProxyPort, optProxyServer, |
4bae14092b78
Add parameters (unused for now) for proxy password etc. in case SOCKS 5
Matti Hamalainen <ccr@tnsp.org>
parents:
601
diff
changeset
|
2076 optProxyUserID, optProxyPassword) != 0) |
391 | 2077 { |
354
c01e42fc9adb
More work on SOCKS proxy support, should work now.
Matti Hamalainen <ccr@tnsp.org>
parents:
353
diff
changeset
|
2078 errorMsg("Error setting proxy information.\n"); |
352
b54c8545dcb0
Overhaul network code a bit, add initial implementation of SOCKS4/4A proxy support -- which may not work yet, it is untested.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
2079 goto err_exit; |
b54c8545dcb0
Overhaul network code a bit, add initial implementation of SOCKS4/4A proxy support -- which may not work yet, it is untested.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
2080 } |
b54c8545dcb0
Overhaul network code a bit, add initial implementation of SOCKS4/4A proxy support -- which may not work yet, it is untested.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
2081 } |
391 | 2082 |
456
bb65460c7aa2
Clean up some initialization messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
451
diff
changeset
|
2083 // Okay, try to resolve the hostname |
354
c01e42fc9adb
More work on SOCKS proxy support, should work now.
Matti Hamalainen <ccr@tnsp.org>
parents:
353
diff
changeset
|
2084 conn->host = th_strdup(optServer); |
c01e42fc9adb
More work on SOCKS proxy support, should work now.
Matti Hamalainen <ccr@tnsp.org>
parents:
353
diff
changeset
|
2085 conn->hst = nn_resolve_host(conn, optServer); |
391 | 2086 if (conn->hst == NULL) |
268
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
2087 goto err_exit; |
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
2088 |
329
c0988ab45afd
#ifdef out the policy probe.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
2089 #ifdef FINAL_BUILD |
268
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
2090 /* To emulate the official client, we first make a request for |
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
2091 * policy file, even though we don't use it for anything... |
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
2092 */ |
391 | 2093 if (nn_conn_open(conn, 843, NULL) != 0) |
2094 { | |
268
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
2095 errorMsg("Policy file request connection setup failed!\n"); |
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
2096 goto err_exit; |
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
2097 } |
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
2098 |
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
2099 tmpStr = "<policy-file-request/>"; |
391 | 2100 if (nn_conn_send_buf(conn, tmpStr, strlen(tmpStr) + 1) == FALSE) |
2101 { | |
268
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
2102 errorMsg("Failed to send policy file request.\n"); |
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
2103 goto err_exit; |
391 | 2104 } |
2105 else | |
2106 { | |
268
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
2107 int cres = nn_conn_pull(conn); |
391 | 2108 if (cres == 0) |
2109 { | |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
2110 printMsg(currWin, "Probe got: %s\n", conn->buf); |
391 | 2111 } |
2112 else | |
2113 { | |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
2114 printMsg(currWin, "Could not get policy probe.\n"); |
268
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
2115 } |
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
2116 } |
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
2117 nn_conn_close(conn); |
329
c0988ab45afd
#ifdef out the policy probe.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
2118 #endif |
268
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
2119 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
2120 // Okay, now do the proper connection ... |
391 | 2121 if (nn_conn_open(conn, optPort, NULL) != 0) |
2122 { | |
268
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
2123 errorMsg("Main connection setup failed!\n"); |
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
2124 goto err_exit; |
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
2125 } |
391 | 2126 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
2127 // Send login command |
268
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
2128 optUserNameEnc = nn_dblencode_str(optUserName); |
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
2129 tmpStr = nn_dblencode_str(optSite); |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
2130 nn_conn_send_msg_v(conn, optUserNameEnc, "%%2Flogin%%20%%2Dsite%%20%s%%20%%2Dpassword%%20%s", tmpStr, optPassword); |
268
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
2131 th_free(tmpStr); |
391 | 2132 |
450
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
2133 // Initialize user commands |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
2134 nn_usercmd_init(); |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
2135 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
2136 // Initialize random numbers |
513 | 2137 editState.prevKeepAlive = time(NULL); |
2138 srandom((int) editState.prevKeepAlive); | |
100
ed4067c10a8a
Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
2139 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
2140 // Enter mainloop |
360
b465a17ffa47
Finally fix handling of long packets.
Matti Hamalainen <ccr@tnsp.org>
parents:
359
diff
changeset
|
2141 nn_conn_reset(conn); |
571
3ae357fd34bb
Rename quit-related internal variables.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
2142 while (!editState.isError && !appQuitFlag) |
391 | 2143 { |
445
7e46f2f0ba34
Cleanup packet retrying a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
444
diff
changeset
|
2144 int retries = 3, cres; |
584
6d23385c0643
Prevent spurious screen updates.
Matti Hamalainen <ccr@tnsp.org>
parents:
582
diff
changeset
|
2145 editState.update = FALSE; |
445
7e46f2f0ba34
Cleanup packet retrying a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
444
diff
changeset
|
2146 |
7e46f2f0ba34
Cleanup packet retrying a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
444
diff
changeset
|
2147 packet_retry: |
7e46f2f0ba34
Cleanup packet retrying a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
444
diff
changeset
|
2148 cres = nn_conn_pull(conn); |
439
70ea06294f3f
Possibly fix packet handling after the whole mess of refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents:
437
diff
changeset
|
2149 if (cres == 0) |
70ea06294f3f
Possibly fix packet handling after the whole mess of refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents:
437
diff
changeset
|
2150 { |
70ea06294f3f
Possibly fix packet handling after the whole mess of refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents:
437
diff
changeset
|
2151 while (conn->ptr < conn->in_ptr && |
70ea06294f3f
Possibly fix packet handling after the whole mess of refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents:
437
diff
changeset
|
2152 *(conn->in_ptr - 1) == 0 && |
513 | 2153 retries > 0 && !editState.isError) |
391 | 2154 { |
439
70ea06294f3f
Possibly fix packet handling after the whole mess of refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents:
437
diff
changeset
|
2155 // nn_conn_dump_buffer(stderr, conn); |
403
7bec02f382fb
Refactor the connection and protocol handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
402
diff
changeset
|
2156 int result = nn_parse_protocol(conn); |
436 | 2157 if (result == 0) |
2158 { | |
2159 nn_conn_buf_skip(conn, 1); | |
2160 } | |
2161 else | |
385 | 2162 if (result > 0) |
2163 { | |
445
7e46f2f0ba34
Cleanup packet retrying a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
444
diff
changeset
|
2164 // Retry if possible |
439
70ea06294f3f
Possibly fix packet handling after the whole mess of refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents:
437
diff
changeset
|
2165 if (--retries > 0) |
445
7e46f2f0ba34
Cleanup packet retrying a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
444
diff
changeset
|
2166 goto packet_retry; |
7e46f2f0ba34
Cleanup packet retrying a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
444
diff
changeset
|
2167 |
7e46f2f0ba34
Cleanup packet retrying a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
444
diff
changeset
|
2168 // Couldn't handle the message for some reason |
7e46f2f0ba34
Cleanup packet retrying a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
444
diff
changeset
|
2169 printMsg(currWin, "Could not handle: %s\n", conn->ptr); |
7e46f2f0ba34
Cleanup packet retrying a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
444
diff
changeset
|
2170 nn_conn_buf_skip(conn, strlen(conn->ptr) + 1); |
385 | 2171 } |
436 | 2172 else |
513 | 2173 editState.isError = TRUE; |
403
7bec02f382fb
Refactor the connection and protocol handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
402
diff
changeset
|
2174 } |
7bec02f382fb
Refactor the connection and protocol handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
402
diff
changeset
|
2175 } |
439
70ea06294f3f
Possibly fix packet handling after the whole mess of refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents:
437
diff
changeset
|
2176 else |
70ea06294f3f
Possibly fix packet handling after the whole mess of refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents:
437
diff
changeset
|
2177 if (cres < 0 || !nn_conn_check(conn)) |
513 | 2178 editState.isError = TRUE; |
168
2e4850ece456
Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
165
diff
changeset
|
2179 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
2180 // Handle user input |
586
7c593c9303e8
Add another tiny screen update flush check.
Matti Hamalainen <ccr@tnsp.org>
parents:
584
diff
changeset
|
2181 BOOL flushed = FALSE; |
571
3ae357fd34bb
Rename quit-related internal variables.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
2182 if (appCursesInit) |
391 | 2183 { |
513 | 2184 nnwin_input_process(editBuf, &editState, processUserInput); |
2185 nnwin_update(editState.update, editState.mask, editBuf, optUserName, optUserColor); | |
586
7c593c9303e8
Add another tiny screen update flush check.
Matti Hamalainen <ccr@tnsp.org>
parents:
584
diff
changeset
|
2186 flushed = TRUE; |
513 | 2187 } |
391 | 2188 |
2189 if (++updateCount > 10) | |
2190 { | |
96
7c9538e71c89
Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
2191 time_t tmpTime = time(NULL); |
513 | 2192 if (tmpTime - editState.prevKeepAlive > SET_KEEPALIVE) |
391 | 2193 { |
435
708a15fdf791
Fix a type / conversion related warning.
Matti Hamalainen <ccr@tnsp.org>
parents:
432
diff
changeset
|
2194 size_t n = ((size_t) random()) % th_llist_length(setIdleMessages); |
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
|
2195 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
|
2196 nn_conn_send_msg(conn, optUserNameEnc, node->data); |
513 | 2197 editState.prevKeepAlive = tmpTime; |
96
7c9538e71c89
Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
2198 } |
391 | 2199 |
2200 if (!colorSet) | |
2201 { | |
96
7c9538e71c89
Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
2202 colorSet = TRUE; |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
2203 nn_conn_send_msg_v(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
|
2204 } |
513 | 2205 |
586
7c593c9303e8
Add another tiny screen update flush check.
Matti Hamalainen <ccr@tnsp.org>
parents:
584
diff
changeset
|
2206 if (appCursesInit && !flushed) |
513 | 2207 { |
2208 nnwin_update(FALSE, editState.mask, editBuf, optUserName, optUserColor); | |
2209 } | |
391 | 2210 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
2211 updateCount = 0; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
2212 } |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
2213 } |
391 | 2214 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
2215 // 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
|
2216 err_exit: |
532
cfab338d3c9e
Stop to show errors when exiting even when not running on Win32.
Matti Hamalainen <ccr@tnsp.org>
parents:
531
diff
changeset
|
2217 if (errorMessages || editState.isError) |
521 | 2218 { |
2219 char *tmp; | |
2220 printMsg(NULL, "Press enter to exit.\n"); | |
535
379e361f1144
Fix various segfault issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
533
diff
changeset
|
2221 clearEditState(&editState); |
521 | 2222 tmp = nnwin_prompt_requester(FALSE, &editState, processUserPrompt, updateUserPrompt); |
2223 th_free(tmp); | |
2224 } | |
2225 | |
316
1065115665bd
Plug some more minor memory leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
315
diff
changeset
|
2226 th_cfg_free(cfg); |
432
966c521e0954
Rename user home directory variable.
Matti Hamalainen <ccr@tnsp.org>
parents:
431
diff
changeset
|
2227 th_free(setHomeDir); |
316
1065115665bd
Plug some more minor memory leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
315
diff
changeset
|
2228 th_llist_free_func(setIdleMessages, th_free); |
103
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
2229 nn_userhash_free(nnUsers); |
97
218efd2f0641
Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
2230 nn_editbuf_free(editBuf); |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
2231 |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
464
diff
changeset
|
2232 for (index = 0; index <= SET_MAX_HISTORY; index++) |
513 | 2233 nn_editbuf_free(editHistBuf[index]); |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
2234 |
489
ba48840b8525
Move network initialization/shutdown flag checking to network module.
Matti Hamalainen <ccr@tnsp.org>
parents:
486
diff
changeset
|
2235 nnwin_shutdown(); |
391 | 2236 |
268
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
2237 #ifndef __WIN32 |
223
03af28fb1c38
Show error messages printed out to stderr only after the program has quit.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
2238 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
|
2239 THERR("%s", errorMessages); |
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
|
2240 #endif |
391 | 2241 |
198
21a37995c3fb
Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents:
197
diff
changeset
|
2242 th_free(optUserNameEnc); |
168
2e4850ece456
Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
165
diff
changeset
|
2243 nn_conn_close(conn); |
489
ba48840b8525
Move network initialization/shutdown flag checking to network module.
Matti Hamalainen <ccr@tnsp.org>
parents:
486
diff
changeset
|
2244 nn_network_close(); |
68
3ab7751fdad1
MingW compatibility, with one ugly kludge.
Matti Hamalainen <ccr@tnsp.org>
parents:
67
diff
changeset
|
2245 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
2246 THMSG(1, "Connection terminated.\n"); |
391 | 2247 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
2248 return 0; |
0 | 2249 } |