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