summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xMakefile4
-rwxr-xr-xvchat-client.c54
-rwxr-xr-xvchat-commands.c106
-rwxr-xr-xvchat-config.h6
-rwxr-xr-xvchat-protocol.c140
-rwxr-xr-xvchat-ui.c284
-rwxr-xr-xvchat-user.c82
-rwxr-xr-xvchat.h124
8 files changed, 374 insertions, 426 deletions
diff --git a/Makefile b/Makefile
index 216f161..9e19425 100755
--- a/Makefile
+++ b/Makefile
@@ -14,6 +14,8 @@ CFLAGS = -Wall -Os
14 14
15CFLAGS += $(OLDREADLINE) 15CFLAGS += $(OLDREADLINE)
16 16
17CFLAGS += -I../readline-5.0 -I../ncurses-5.4/include/
18
17## you might need one or more of these: 19## you might need one or more of these:
18#CFLAGS += -I/usr/local/ssl/include -L/usr/local/ssl/lib 20#CFLAGS += -I/usr/local/ssl/include -L/usr/local/ssl/lib
19#CFLAGS += -I/usr/local/include -L/usr/local/lib 21#CFLAGS += -I/usr/local/include -L/usr/local/lib
@@ -29,7 +31,7 @@ CFLAGS += $(OLDREADLINE)
29## the install prefix best is /usr/local 31## the install prefix best is /usr/local
30PREFIX=/usr/local 32PREFIX=/usr/local
31 33
32LIBS = -lreadline -lncurses -lssl -lcrypto 34LIBS = ../readline-5.0/libreadline.a ../ncurses-5.4/lib/libncurses.a -lssl -lcrypto
33OBJS = vchat-client.o vchat-ui.o vchat-protocol.o vchat-user.o vchat-commands.o 35OBJS = vchat-client.o vchat-ui.o vchat-protocol.o vchat-user.o vchat-commands.o
34 36
35 37
diff --git a/vchat-client.c b/vchat-client.c
index d7d1998..2d50932 100755
--- a/vchat-client.c
+++ b/vchat-client.c
@@ -32,7 +32,7 @@
32#include "vchat.h" 32#include "vchat.h"
33 33
34/* version of this module */ 34/* version of this module */
35unsigned char *vchat_cl_version = "$Id$"; 35char *vchat_cl_version = "$Id$";
36 36
37/* externally used variables */ 37/* externally used variables */
38/* we're logged in */ 38/* we're logged in */
@@ -40,7 +40,7 @@ unsigned int loggedin = 0;
40/* we run as long as this is true */ 40/* we run as long as this is true */
41unsigned int status = 1; 41unsigned int status = 1;
42/* error string to show after exit */ 42/* error string to show after exit */
43unsigned char errstr[ERRSTRSIZE] = "\0"; 43char errstr[ERRSTRSIZE] = "\0";
44 44
45/* locally global variables */ 45/* locally global variables */
46/* our list of filedescriptors */ 46/* our list of filedescriptors */
@@ -52,12 +52,12 @@ static fd_set masterfds;
52/* servers filedescriptor from vchat-protocol.c */ 52/* servers filedescriptor from vchat-protocol.c */
53extern int serverfd; 53extern int serverfd;
54 54
55void setnoption (unsigned char *, unsigned char *); 55void setnoption (char *, char *);
56 56
57static void parsecfg(unsigned char *line) { 57static void parsecfg(char *line) {
58 int bytes; 58 int bytes;
59 unsigned char *param=line; 59 char *param=line;
60 unsigned char *value=NULL; 60 char *value=NULL;
61 61
62 /* handle quotes value is empty, so wecan use it */ 62 /* handle quotes value is empty, so wecan use it */
63 value = strchr(line,'#'); 63 value = strchr(line,'#');
@@ -101,9 +101,9 @@ static void parsecfg(unsigned char *line) {
101 setnoption(param,value); 101 setnoption(param,value);
102} 102}
103 103
104static void parseformats(unsigned char *line) { 104static void parseformats(char *line) {
105 int i; 105 int i;
106 unsigned char *tmp = NULL; 106 char *tmp = NULL;
107 107
108 /* read a format line from file, syntax is 108 /* read a format line from file, syntax is
109 FS_XXX = "formatstring" 109 FS_XXX = "formatstring"
@@ -117,7 +117,7 @@ static void parseformats(unsigned char *line) {
117 for (i = 0; formatstrings[i].formatstr; i++) 117 for (i = 0; formatstrings[i].formatstr; i++)
118 if (!strncasecmp(formatstrings[i].idstring, line, strlen( formatstrings[i].idstring) )) 118 if (!strncasecmp(formatstrings[i].idstring, line, strlen( formatstrings[i].idstring) ))
119 { 119 {
120 unsigned char *tail = line + strlen( formatstrings[i].idstring); 120 char *tail = line + strlen( formatstrings[i].idstring);
121 while( *tail==' ' || *tail=='\t') tail++; /* and skip whitespaces */ 121 while( *tail==' ' || *tail=='\t') tail++; /* and skip whitespaces */
122 122
123 if( *tail++ == '=' ) 123 if( *tail++ == '=' )
@@ -145,7 +145,7 @@ static void parseformats(unsigned char *line) {
145 } 145 }
146 } 146 }
147 147
148 if ( stringends && ( (tmp = (unsigned char *)malloc( 1 + j )) != NULL ) ) 148 if ( stringends && ( (tmp = (char *)malloc( 1 + j )) != NULL ) )
149 { 149 {
150 memcpy( tmp, tmpstr, k); 150 memcpy( tmp, tmpstr, k);
151 tmp[k-1]=0; 151 tmp[k-1]=0;
@@ -158,21 +158,21 @@ static void parseformats(unsigned char *line) {
158} 158}
159 159
160/* UNUSED uncomment if needed 160/* UNUSED uncomment if needed
161static void parseknownhosts(unsigned char *line) { 161static void parseknownhosts(char *line) {
162} 162}
163*/ 163*/
164 164
165/* load config file */ 165/* load config file */
166static void 166static void
167loadcfg (unsigned char *file,void (*lineparser) (unsigned char *)) 167loadcfg (char *file,void (*lineparser) (char *))
168{ 168{
169 int fd; 169 int fd;
170 int bytes,bufoff=0; 170 int bytes,bufoff=0;
171 unsigned char *tmp = NULL; 171 char *tmp = NULL;
172#define BUFSIZE 4096 172#define BUFSIZE 4096
173 unsigned char buf[BUFSIZE]; /* data buffer */ 173 char buf[BUFSIZE]; /* data buffer */
174 unsigned char *ltmp = buf; 174 char *ltmp = buf;
175 unsigned char *tildex = NULL; 175 char *tildex = NULL;
176 buf[BUFSIZE-1] = '\0'; /* sanity stop */ 176 buf[BUFSIZE-1] = '\0'; /* sanity stop */
177 177
178 if (!file) return; 178 if (!file) return;
@@ -226,19 +226,19 @@ loadcfg (unsigned char *file,void (*lineparser) (unsigned char *))
226} 226}
227 227
228void 228void
229loadconfig (unsigned char *file) 229loadconfig (char *file)
230{ 230{
231 loadcfg(file,parsecfg); 231 loadcfg(file,parsecfg);
232} 232}
233 233
234void 234void
235loadformats (unsigned char *file) 235loadformats (char *file)
236{ 236{
237 loadcfg(file,parseformats); 237 loadcfg(file,parseformats);
238} 238}
239 239
240/* get-format-string */ 240/* get-format-string */
241unsigned char * 241char *
242getformatstr (formtstr id) 242getformatstr (formtstr id)
243{ 243{
244 int i; 244 int i;
@@ -248,7 +248,7 @@ getformatstr (formtstr id)
248} 248}
249 249
250/* get-string-option, fetches *char-value of variable named by option */ 250/* get-string-option, fetches *char-value of variable named by option */
251unsigned char * 251char *
252getstroption (confopt option) 252getstroption (confopt option)
253{ 253{
254 int i; 254 int i;
@@ -267,7 +267,7 @@ getstroption (confopt option)
267 267
268/* set-string-option, puts *char-value to variable named by option */ 268/* set-string-option, puts *char-value to variable named by option */
269void 269void
270setstroption (confopt option, unsigned char *string) 270setstroption (confopt option, char *string)
271{ 271{
272 int i; 272 int i;
273#ifdef DEBUG 273#ifdef DEBUG
@@ -288,7 +288,7 @@ setstroption (confopt option, unsigned char *string)
288 288
289/* set-named-option, puts string to variable named by name */ 289/* set-named-option, puts string to variable named by name */
290void 290void
291setnoption (unsigned char *name, unsigned char *string) 291setnoption (char *name, char *string)
292{ 292{
293 int i; 293 int i;
294#ifdef DEBUG 294#ifdef DEBUG
@@ -450,8 +450,8 @@ eventloop (void)
450 } 450 }
451} 451}
452 452
453void usage(unsigned char *name) { 453void usage( char *name) {
454 printf ("usage: %s [-C config-file] [-F formats] [-l] [-z] [-s host] [-p port] [-c channel] [-n nickname] [-k] [-K] [-L logfile]\n",name); 454 printf ("usage: %s [-C config-file] [-F formats] [-l] [-z] [-s host] [-p port] [-c channel] [-n nickname]\n",name);
455 puts (" -C load a second config-file, overriding the first one"); 455 puts (" -C load a second config-file, overriding the first one");
456 puts (" -F load format strings (skins) from this file"); 456 puts (" -F load format strings (skins) from this file");
457 puts (" -l local connect (no SSL + connects localhost:2323)"); 457 puts (" -l local connect (no SSL + connects localhost:2323)");
@@ -464,9 +464,6 @@ void usage(unsigned char *name) {
464 else 464 else
465 puts (" -n set nickname"); 465 puts (" -n set nickname");
466 printf (" -f set from (default \"%s\")\n",getstroption(CF_FROM)); 466 printf (" -f set from (default \"%s\")\n",getstroption(CF_FROM));
467 puts (" -k keep autolog");
468 puts (" -K don't keep autolog");
469 printf (" -L use this file as logfile (default \"%s\")\n",getstroption(CF_LOGFILE));
470 puts (" -h gives this help"); 467 puts (" -h gives this help");
471} 468}
472 469
@@ -502,9 +499,6 @@ main (int argc, char **argv)
502 case 'c': setintoption(CF_CHANNEL,strtol(optarg,NULL,10)); break; 499 case 'c': setintoption(CF_CHANNEL,strtol(optarg,NULL,10)); break;
503 case 'n': setstroption(CF_NICK,optarg); break; 500 case 'n': setstroption(CF_NICK,optarg); break;
504 case 'f': setstroption(CF_FROM,optarg); break; 501 case 'f': setstroption(CF_FROM,optarg); break;
505 case 'k': setintoption(CF_KEEPLOG,1); break;
506 case 'K': setintoption(CF_KEEPLOG,0); break;
507 case 'L': setstroption(CF_LOGFILE,optarg); break;
508 case 'h': usage(argv[0]); exit(0); break; 502 case 'h': usage(argv[0]); exit(0); break;
509 default : usage(argv[0]); exit(1); 503 default : usage(argv[0]); exit(1);
510 } 504 }
diff --git a/vchat-commands.c b/vchat-commands.c
index 5f54733..5dc7b4f 100755
--- a/vchat-commands.c
+++ b/vchat-commands.c
@@ -25,7 +25,7 @@
25#include "vchat-help.h" 25#include "vchat-help.h"
26 26
27/* version of this module */ 27/* version of this module */
28unsigned char *vchat_cm_version = "$Id$"; 28char *vchat_cm_version = "$Id$";
29 29
30/* our "/command " table */ 30/* our "/command " table */
31enum { 31enum {
@@ -38,29 +38,30 @@ COMMAND_HELP,
38COMMAND_KEYS, 38COMMAND_KEYS,
39COMMAND_QUIT, 39COMMAND_QUIT,
40COMMAND_USER, 40COMMAND_USER,
41COMMAND_LOG,
42COMMAND_FLT, 41COMMAND_FLT,
43COMMAND_PM, 42COMMAND_PM,
44COMMAND_ACTION, 43COMMAND_ACTION,
45COMMAND_PMSHORT, 44COMMAND_PMSHORT,
45COMMAND_QUERY,
46COMMAND_QUITSHORT,
46COMMAND_PLAIN, 47COMMAND_PLAIN,
47COMMAND_NONE 48COMMAND_NONE
48}; 49};
49 50
50static void command_quit ( unsigned char *tail); 51static void command_quit ( char *tail);
51static void command_user ( unsigned char *tail); 52static void command_user ( char *tail);
52static void command_pm ( unsigned char *tail); 53static void command_pm ( char *tail);
53static void command_action ( unsigned char *tail); 54static void command_action ( char *tail);
54static void command_help ( unsigned char *tail); 55static void command_help ( char *tail);
55static void command_flt ( unsigned char *tail); 56static void command_flt ( char *tail);
56static void command_lsflt ( unsigned char *tail); 57static void command_lsflt ( char *tail);
57static void command_clflt ( unsigned char *tail); 58static void command_clflt ( char *tail);
58static void command_rmflt ( unsigned char *tail); 59static void command_rmflt ( char *tail);
59 void command_version ( unsigned char *tail); 60 void command_version ( char *tail);
60static void command_none ( unsigned char *line); 61static void command_none ( char *line);
61static void command_log ( unsigned char *tail); 62static void command_query ( char *tail);
62 63
63static void output_default ( unsigned char *tail); 64static void output_default ( char *tail);
64 65
65/* commandentry defined in vchat.h */ 66/* commandentry defined in vchat.h */
66 67
@@ -73,20 +74,21 @@ commandtable[] = {
73{ COMMAND_HELP, "HELP", 4, command_help, SHORT_HELPTEXT_HELP, LONG_HELPTEXT_HELP }, 74{ COMMAND_HELP, "HELP", 4, command_help, SHORT_HELPTEXT_HELP, LONG_HELPTEXT_HELP },
74{ COMMAND_FILTERS, "FILTERS", 7, command_help, SHORT_HELPTEXT_FILTERS, LONG_HELPTEXT_FILTERS }, 75{ COMMAND_FILTERS, "FILTERS", 7, command_help, SHORT_HELPTEXT_FILTERS, LONG_HELPTEXT_FILTERS },
75{ COMMAND_KEYS, "KEYS", 4, command_help, SHORT_HELPTEXT_KEYS, LONG_HELPTEXT_KEYS }, 76{ COMMAND_KEYS, "KEYS", 4, command_help, SHORT_HELPTEXT_KEYS, LONG_HELPTEXT_KEYS },
77{ COMMAND_QUERY, "QUERY", 5, command_query, NULL, NULL },
76{ COMMAND_QUIT, "QUIT", 4, command_quit, SHORT_HELPTEXT_QUIT, LONG_HELPTEXT_QUIT }, 78{ COMMAND_QUIT, "QUIT", 4, command_quit, SHORT_HELPTEXT_QUIT, LONG_HELPTEXT_QUIT },
77{ COMMAND_USER, "USER", 4, command_user, SHORT_HELPTEXT_USER, LONG_HELPTEXT_USER }, 79{ COMMAND_USER, "USER", 4, command_user, SHORT_HELPTEXT_USER, LONG_HELPTEXT_USER },
78{ COMMAND_FLT, "FLT", 3, command_flt, NULL, LONG_HELPTEXT_FLT }, 80{ COMMAND_FLT, "FLT", 3, command_flt, NULL, LONG_HELPTEXT_FLT },
79{ COMMAND_LOG, "LOG", 3, command_log, NULL, NULL },
80{ COMMAND_PM, "MSG", 3, command_pm, SHORT_HELPTEXT_MSG, LONG_HELPTEXT_MSG }, 81{ COMMAND_PM, "MSG", 3, command_pm, SHORT_HELPTEXT_MSG, LONG_HELPTEXT_MSG },
81{ COMMAND_ACTION, "ME", 2, command_action, SHORT_HELPTEXT_ME, LONG_HELPTEXT_ME }, 82{ COMMAND_ACTION, "ME", 2, command_action, SHORT_HELPTEXT_ME, LONG_HELPTEXT_ME },
82{ COMMAND_PMSHORT, "M", 1, command_pm, NULL, SHORT_HELPTEXT_MSG }, 83{ COMMAND_PMSHORT, "M", 1, command_pm, NULL, SHORT_HELPTEXT_MSG },
84{ COMMAND_QUITSHORT,"Q", 1, command_quit, SHORT_HELPTEXT_QUIT, LONG_HELPTEXT_QUIT },
83{ COMMAND_PLAIN, "/", 1, output_default, NULL, NULL }, 85{ COMMAND_PLAIN, "/", 1, output_default, NULL, NULL },
84{ COMMAND_NONE, "", 0, command_none, NULL, NULL } 86{ COMMAND_NONE, "", 0, command_none, NULL, NULL }
85}; 87};
86 88
87/* parse "/command" */ 89/* parse "/command" */
88static int 90static int
89translatecommand( unsigned char **cmd) 91translatecommand( char **cmd)
90{ 92{
91 int result; 93 int result;
92 int cut = 0; 94 int cut = 0;
@@ -120,7 +122,7 @@ translatecommand( unsigned char **cmd)
120 122
121/* handle thought */ 123/* handle thought */
122static void 124static void
123dothink( unsigned char *tail, char nice ) 125dothink( char *tail, char nice )
124{ 126{
125 while( *tail == ' ' ) tail++; 127 while( *tail == ' ' ) tail++;
126 128
@@ -136,7 +138,7 @@ dothink( unsigned char *tail, char nice )
136 138
137/* handle action */ 139/* handle action */
138static void 140static void
139doaction( unsigned char *tail ) 141doaction( char *tail )
140{ 142{
141 while( *tail == ' ' ) tail++; 143 while( *tail == ' ' ) tail++;
142 144
@@ -156,8 +158,8 @@ doaction( unsigned char *tail )
156 158
157/* handle private message outgoing */ 159/* handle private message outgoing */
158static void 160static void
159privatemessagetx ( unsigned char *tail ) { 161privatemessagetx ( char *tail ) {
160 unsigned char *mesg; 162 char *mesg;
161 163
162 /* find nick */ 164 /* find nick */
163 while( *tail==' ') tail++; 165 while( *tail==' ') tail++;
@@ -191,7 +193,7 @@ privatemessagetx ( unsigned char *tail ) {
191 193
192/* handle line entered by user */ 194/* handle line entered by user */
193void 195void
194handleline (unsigned char *line) 196handleline (char *line)
195{ 197{
196#ifdef DEBUG 198#ifdef DEBUG
197 /* debugging? log users input! */ 199 /* debugging? log users input! */
@@ -245,7 +247,7 @@ handleline (unsigned char *line)
245} 247}
246 248
247static void 249static void
248output_default( unsigned char *line ) { 250output_default(char *line ) {
249 /* prepare for output on display */ 251 /* prepare for output on display */
250 snprintf (tmpstr, TMPSTRSIZE, getformatstr(FS_TXPUBMSG), nick, line); 252 snprintf (tmpstr, TMPSTRSIZE, getformatstr(FS_TXPUBMSG), nick, line);
251 253
@@ -258,11 +260,11 @@ output_default( unsigned char *line ) {
258 260
259/* handle a "/user " request */ 261/* handle a "/user " request */
260static void 262static void
261command_user( unsigned char *tail) 263command_user(char *tail)
262{ 264{
263 while( *tail == ' ') tail++; 265 while( *tail == ' ') tail++;
264 if( *tail ) { 266 if( *tail ) {
265 unsigned char * out = ul_matchuser( tail); 267 char * out = ul_matchuser( tail);
266 if( *out ) { 268 if( *out ) {
267 snprintf( tmpstr, TMPSTRSIZE, getformatstr(FS_USMATCH), tail, out); 269 snprintf( tmpstr, TMPSTRSIZE, getformatstr(FS_USMATCH), tail, out);
268 } else { 270 } else {
@@ -276,14 +278,14 @@ command_user( unsigned char *tail)
276 278
277/* handle a "/msg " request */ 279/* handle a "/msg " request */
278static void 280static void
279command_pm (unsigned char *tail) 281command_pm (char *tail)
280{ 282{
281 privatemessagetx( tail ); 283 privatemessagetx( tail );
282} 284}
283 285
284/* handle a help request */ 286/* handle a help request */
285static void 287static void
286command_help (unsigned char *line) { 288command_help (char *line) {
287 flushout( ); 289 flushout( );
288 while( *line==' ') line++; 290 while( *line==' ') line++;
289 if( *line ) { /* Get help on command */ 291 if( *line ) { /* Get help on command */
@@ -297,7 +299,7 @@ command_help (unsigned char *line) {
297 line = commandtable[i].help; 299 line = commandtable[i].help;
298 if( line ) { 300 if( line ) {
299 while( *line ) { 301 while( *line ) {
300 unsigned char *tmp = tmpstr; 302 char *tmp = tmpstr;
301 while( *line && (*line != '\n') ) 303 while( *line && (*line != '\n') )
302 *tmp++ = *line++; 304 *tmp++ = *line++;
303 *tmp = '\0'; if( *line == '\n') line++; 305 *tmp = '\0'; if( *line == '\n') line++;
@@ -319,15 +321,15 @@ command_help (unsigned char *line) {
319 321
320/* handle an unknown command */ 322/* handle an unknown command */
321static void 323static void
322command_none( unsigned char *line) { 324command_none(char *line) {
323 snprintf(tmpstr, TMPSTRSIZE, " Unknown client command: %s ", line); 325 snprintf(tmpstr, TMPSTRSIZE, " Unknown client command: %s ", line);
324 msgout(tmpstr); 326 msgout(tmpstr);
325} 327}
326 328
327/* handle a "/flt " request */ 329/* handle a "/flt " request */
328static void 330static void
329command_flt( unsigned char *tail){ 331command_flt(char *tail){
330 unsigned char colour; 332 char colour;
331 while(*tail==' ') tail++; 333 while(*tail==' ') tail++;
332 colour = *tail++; 334 colour = *tail++;
333 while( colour && *tail == ' ') tail++; 335 while( colour && *tail == ' ') tail++;
@@ -338,34 +340,34 @@ command_flt( unsigned char *tail){
338 340
339/* handle a "/clflt " request */ 341/* handle a "/clflt " request */
340static void 342static void
341command_clflt ( unsigned char *tail) { 343command_clflt (char *tail) {
342 while( *tail == ' ') tail++; 344 while( *tail == ' ') tail++;
343 clearfilters( *tail ); 345 clearfilters( *tail );
344} 346}
345 347
346/* handle a "/rmflt " request */ 348/* handle a "/rmflt " request */
347static void 349static void
348command_rmflt ( unsigned char *tail) { 350command_rmflt (char *tail) {
349 while( *tail == ' ') tail++; 351 while( *tail == ' ') tail++;
350 removefilter( tail ); 352 removefilter( tail );
351} 353}
352 354
353/* list filters */ 355/* list filters */
354static void 356static void
355command_lsflt ( unsigned char *tail) { 357command_lsflt (char *tail) {
356 listfilters(); 358 listfilters();
357} 359}
358 360
359/* handle a "/me " action */ 361/* handle a "/me " action */
360static void 362static void
361command_action( unsigned char *tail) 363command_action(char *tail)
362{ 364{
363 doaction( tail); 365 doaction( tail);
364} 366}
365 367
366/* handle a "/quit " exit */ 368/* handle a "/quit " exit */
367static void 369static void
368command_quit ( unsigned char *tail) 370command_quit(char *tail)
369{ 371{
370 /* send users message to server */ 372 /* send users message to server */
371 snprintf (tmpstr, TMPSTRSIZE, ".x %s", tail); 373 snprintf (tmpstr, TMPSTRSIZE, ".x %s", tail);
@@ -377,7 +379,7 @@ command_quit ( unsigned char *tail)
377 379
378/* print out version */ 380/* print out version */
379void 381void
380command_version( unsigned char *tail) 382command_version(char *tail)
381{ 383{
382 /* output internal versions of all modules */ 384 /* output internal versions of all modules */
383 flushout(); 385 flushout();
@@ -389,24 +391,20 @@ command_version( unsigned char *tail)
389 showout(); 391 showout();
390} 392}
391 393
392/* Undocumented feature */ 394/* start or end a query */
393void 395void
394command_log ( unsigned char *tail) 396command_query(char *tail)
395{ 397{
396 /* log to file */ 398 char *msg;
397 FILE *logfile = NULL; 399 while( *tail == ' ') tail++;
398 while( *tail == ' ' ) 400
399 tail++; 401 // Check, if a message is to be sent in first query
400 if( (logfile = fopen( tail, "w")) ) { 402 // Note: this is safe, since readline chops trailing spaces
401 if( *tail == '_' ) { 403 if((msg = strchr(tail, ' '))) {
402 writelog_i(logfile); 404 privatemessagetx( tail );
403 } else { 405 *msg = 0;
404 writelog(logfile);
405 }
406 fclose( logfile );
407 msgout(" Log written. ");
408 } else {
409 snprintf(tmpstr, TMPSTRSIZE, " Can't open file: %s ", tail);
410 msgout(tmpstr);
411 } 406 }
407
408 // Do the ui stuff for query
409 handlequery( tail );
412} 410}
diff --git a/vchat-config.h b/vchat-config.h
index 008a940..ce9c72d 100755
--- a/vchat-config.h
+++ b/vchat-config.h
@@ -23,8 +23,8 @@
23#endif 23#endif
24 24
25/* configuration array with structure as defined in vchat.h */ 25/* configuration array with structure as defined in vchat.h */
26extern int usessl; 26extern unsigned int usessl;
27extern int usetime; 27extern unsigned int usetime;
28extern unsigned int hscroll; 28extern unsigned int hscroll;
29 29
30static volatile configoption configoptions[] = { 30static volatile configoption configoptions[] = {
@@ -38,7 +38,6 @@ static volatile configoption configoptions[] = {
38 {CF_CERTFILE, CO_STR, "certfile", "~/.vchat/cert", NULL, { NULL } }, 38 {CF_CERTFILE, CO_STR, "certfile", "~/.vchat/cert", NULL, { NULL } },
39 {CF_KEYFILE, CO_STR, "keyfile", "~/.vchat/key", NULL, { NULL } }, 39 {CF_KEYFILE, CO_STR, "keyfile", "~/.vchat/key", NULL, { NULL } },
40 {CF_FORMFILE, CO_STR, "formatfile", "~/.vchat/formats", NULL, { NULL } }, 40 {CF_FORMFILE, CO_STR, "formatfile", "~/.vchat/formats", NULL, { NULL } },
41 {CF_LOGFILE, CO_STR, "logfile", "~/.vchat/log", NULL, { NULL } },
42 {CF_ENCODING, CO_STR, "encoding", NULL, NULL, { .pstr = &encoding }}, 41 {CF_ENCODING, CO_STR, "encoding", NULL, NULL, { .pstr = &encoding }},
43 {CF_USESSL, CO_INT, "usessl", (char *) 1, (char *)-1, { .pint = &usessl } }, 42 {CF_USESSL, CO_INT, "usessl", (char *) 1, (char *)-1, { .pint = &usessl } },
44 {CF_USECERT, CO_INT, "usecert", (char *) 1, (char *)-1, { NULL } }, 43 {CF_USECERT, CO_INT, "usecert", (char *) 1, (char *)-1, { NULL } },
@@ -51,7 +50,6 @@ static volatile configoption configoptions[] = {
51 {CF_SCROLLBACK, CO_INT, "scrollback", (char *) 8192, (char *)-1, { NULL } }, 50 {CF_SCROLLBACK, CO_INT, "scrollback", (char *) 8192, (char *)-1, { NULL } },
52 {CF_SCROLLBPRIVT,CO_INT, "privscrollt",(char *) 0, (char *)-1, { NULL } }, 51 {CF_SCROLLBPRIVT,CO_INT, "privscrollt",(char *) 0, (char *)-1, { NULL } },
53 {CF_SCROLLBACKT, CO_INT, "scrolltime", (char *) 86400, (char *)-1, { NULL } }, 52 {CF_SCROLLBACKT, CO_INT, "scrolltime", (char *) 86400, (char *)-1, { NULL } },
54 {CF_KEEPLOG, CO_INT, "keeplog", (char *) 0, (char *)-1, { NULL } },
55 {CF_BELLPRIV, CO_INT, "bellonpm", (char *) 0, (char *)-1, { NULL } }, 53 {CF_BELLPRIV, CO_INT, "bellonpm", (char *) 0, (char *)-1, { NULL } },
56 {CF_NIL, CO_NIL, NULL, NULL, NULL, { NULL } }, 54 {CF_NIL, CO_NIL, NULL, NULL, NULL, { NULL } },
57}; 55};
diff --git a/vchat-protocol.c b/vchat-protocol.c
index 7c91638..5554796 100755
--- a/vchat-protocol.c
+++ b/vchat-protocol.c
@@ -35,7 +35,7 @@
35#include "vchat.h" 35#include "vchat.h"
36 36
37/* version of this module */ 37/* version of this module */
38unsigned char *vchat_io_version = "$Id$"; 38char *vchat_io_version = "$Id$";
39 39
40/* externally used variables */ 40/* externally used variables */
41int serverfd = -1; 41int serverfd = -1;
@@ -49,28 +49,28 @@ static SSL *sslconn = NULL;
49 * but by the library. we use it to set the accepted list of ciphers */ 49 * but by the library. we use it to set the accepted list of ciphers */
50STACK_OF(SSL_CIPHER) * ssl_create_cipher_list (const SSL_METHOD * meth, STACK_OF (SSL_CIPHER) ** pref, STACK_OF (SSL_CIPHER) ** sorted, const unsigned char *rule_str); 50STACK_OF(SSL_CIPHER) * ssl_create_cipher_list (const SSL_METHOD * meth, STACK_OF (SSL_CIPHER) ** pref, STACK_OF (SSL_CIPHER) ** sorted, const unsigned char *rule_str);
51 51
52static unsigned char *sslpubkey = NULL; /* servers public key extracted from X.509 certificate */ 52static char *sslpubkey = NULL; /* servers public key extracted from X.509 certificate */
53static int sslpubkeybits = 0; /* length of server public key */ 53static int sslpubkeybits = 0; /* length of server public key */
54 54
55/* declaration of local helper functions */ 55/* declaration of local helper functions */
56static void usersignon (unsigned char *); 56static void usersignon (char *);
57static void usersignoff (unsigned char *); 57static void usersignoff (char *);
58static void usernickchange (unsigned char *); 58static void usernickchange (char *);
59static void userjoin (unsigned char *); 59static void userjoin (char *);
60static void userleave (unsigned char *); 60static void userleave (char *);
61static void receivenicks (unsigned char *message); 61static void receivenicks (char *message);
62static void justloggedin (unsigned char *message); 62static void justloggedin (char *message);
63static void nickerr (unsigned char *message); 63static void nickerr (char *message);
64static void login (unsigned char *message); 64static void login (char *message);
65static void anonlogin (unsigned char *message); 65static void anonlogin (char *message);
66static void topicinfo (unsigned char *message); 66static void topicinfo (char *message);
67static void pubaction (unsigned char *message); 67static void pubaction (char *message);
68static void pubthoughts (unsigned char *message); 68static void pubthoughts (char *message);
69static void serverlogin (unsigned char *message); 69static void serverlogin (char *message);
70static void idleprompt (unsigned char *message); 70static void idleprompt (char *message);
71static void topicchange (unsigned char *message); 71static void topicchange (char *message);
72static void pmnotsent (unsigned char *message); 72static void pmnotsent (char *message);
73static int getportnum(unsigned char *port); 73static int getportnum (char *port);
74 74
75/* declaration of server message array */ 75/* declaration of server message array */
76#include "vchat-messages.h" 76#include "vchat-messages.h"
@@ -80,21 +80,21 @@ static int getportnum(unsigned char *port);
80extern int status; 80extern int status;
81 81
82int usessl = 1; 82int usessl = 1;
83unsigned char *encoding; 83char *encoding;
84 84
85/* connects to server */ 85/* connects to server */
86int 86int
87vcconnect (unsigned char *server, unsigned char *port) 87vcconnect (char *server, char *port)
88{ 88{
89 /* used for tilde expansion of cert & key filenames */ 89 /* used for tilde expansion of cert & key filenames */
90 unsigned char *tildex = NULL; 90 char *tildex = NULL;
91 /* buffer for X.509 subject of server certificate */ 91 /* buffer for X.509 subject of server certificate */
92 unsigned char subjbuf[256]; 92 char subjbuf[256];
93 /* variables used to split the subject */ 93 /* variables used to split the subject */
94 unsigned char *subjv = NULL; 94 char *subjv = NULL;
95 unsigned char *subjn = NULL; 95 char *subjn = NULL;
96 unsigned char *subjc = NULL; 96 char *subjc = NULL;
97 unsigned char *subjh = NULL; 97 char *subjh = NULL;
98 /* pointer to key in certificate */ 98 /* pointer to key in certificate */
99 EVP_PKEY *certpubkey = NULL; 99 EVP_PKEY *certpubkey = NULL;
100 /* temporary result */ 100 /* temporary result */
@@ -109,7 +109,7 @@ vcconnect (unsigned char *server, unsigned char *port)
109 SSL_METHOD *sslmeth = NULL; 109 SSL_METHOD *sslmeth = NULL;
110 110
111 /* pointer to tilde-expanded certificate/keyfile-names */ 111 /* pointer to tilde-expanded certificate/keyfile-names */
112 unsigned char *certfile = NULL, *keyfile = NULL; 112 char *certfile = NULL, *keyfile = NULL;
113 113
114 /* variable for verify return */ 114 /* variable for verify return */
115 long verify; 115 long verify;
@@ -154,7 +154,7 @@ vcconnect (unsigned char *server, unsigned char *port)
154 SSL_CTX_set_default_passwd_cb (sslctx, passprompt); 154 SSL_CTX_set_default_passwd_cb (sslctx, passprompt);
155 155
156 /* set our list of accepted ciphers */ 156 /* set our list of accepted ciphers */
157 ssl_create_cipher_list (sslctx->method, &(sslctx->cipher_list), &(sslctx->cipher_list_by_id), getstroption (CF_CIPHERSUITE)); 157 ssl_create_cipher_list (sslctx->method, &(sslctx->cipher_list), &(sslctx->cipher_list_by_id), (unsigned char*)getstroption (CF_CIPHERSUITE));
158 158
159 /* get name of certificate file */ 159 /* get name of certificate file */
160 certfile = getstroption (CF_CERTFILE); 160 certfile = getstroption (CF_CERTFILE);
@@ -366,7 +366,7 @@ vcdisconnect ()
366} 366}
367 367
368/* lookup a port number by service string */ 368/* lookup a port number by service string */
369static int getportnum (unsigned char *port) 369static int getportnum (char *port)
370{ 370{
371 char *endpt = NULL; 371 char *endpt = NULL;
372 struct servent *service = getservbyname(port, "tcp"); 372 struct servent *service = getservbyname(port, "tcp");
@@ -382,7 +382,7 @@ static int getportnum (unsigned char *port)
382/* handle a pm not sent error 382/* handle a pm not sent error
383 * format: 412 %s */ 383 * format: 412 %s */
384static void 384static void
385pmnotsent (unsigned char *message) 385pmnotsent (char *message)
386{ 386{
387 while(*message && *message!=' ') message++; 387 while(*message && *message!=' ') message++;
388 snprintf(tmpstr,TMPSTRSIZE,getformatstr(FS_ERR),message+1); 388 snprintf(tmpstr,TMPSTRSIZE,getformatstr(FS_ERR),message+1);
@@ -395,9 +395,9 @@ pmnotsent (unsigned char *message)
395 * vars: %s nick 395 * vars: %s nick
396 * %s action */ 396 * %s action */
397static void 397static void
398pubaction (unsigned char *message) 398pubaction (char *message)
399{ 399{
400 unsigned char *nick = NULL, *action = NULL; 400 char *nick = NULL, *action = NULL;
401 nick = strchr (message, ' '); 401 nick = strchr (message, ' ');
402 nick[0] = '\0'; 402 nick[0] = '\0';
403 nick++; 403 nick++;
@@ -415,9 +415,9 @@ pubaction (unsigned char *message)
415 * vars: %s nick 415 * vars: %s nick
416 * %s thought */ 416 * %s thought */
417static void 417static void
418pubthoughts (unsigned char *message) 418pubthoughts (char *message)
419{ 419{
420 unsigned char *nick = NULL, *thoughts = NULL; 420 char *nick = NULL, *thoughts = NULL;
421 nick = strchr (message, ' '); 421 nick = strchr (message, ' ');
422 nick[0] = '\0'; 422 nick[0] = '\0';
423 nick++; 423 nick++;
@@ -432,7 +432,7 @@ pubthoughts (unsigned char *message)
432 432
433/* parse and handle server logon */ 433/* parse and handle server logon */
434static void 434static void
435serverlogin (unsigned char *message) 435serverlogin (char *message)
436{ 436{
437#ifndef NO_LOCALE 437#ifndef NO_LOCALE
438 int utf8=!strcmp(nl_langinfo(CODESET), "UTF-8"); 438 int utf8=!strcmp(nl_langinfo(CODESET), "UTF-8");
@@ -444,9 +444,9 @@ serverlogin (unsigned char *message)
444 * format: 305 444 * format: 305
445 * vars: %s message */ 445 * vars: %s message */
446static void 446static void
447idleprompt (unsigned char *message) 447idleprompt (char *message)
448{ 448{
449 unsigned char *msg = NULL; 449 char *msg = NULL;
450 msg = strchr (message, ' '); 450 msg = strchr (message, ' ');
451 msg[0] = '\0'; 451 msg[0] = '\0';
452 msg++; 452 msg++;
@@ -460,9 +460,9 @@ idleprompt (unsigned char *message)
460 * vars: %d chan - channel number 460 * vars: %d chan - channel number
461 * %s topic - topic */ 461 * %s topic - topic */
462static void 462static void
463topicinfo (unsigned char *message) 463topicinfo (char *message)
464{ 464{
465 unsigned char *channel = NULL, *topic = NULL; 465 char *channel = NULL, *topic = NULL;
466 int tmpchan = 0; 466 int tmpchan = 0;
467 467
468 /* search start of channel number */ 468 /* search start of channel number */
@@ -499,9 +499,9 @@ topicinfo (unsigned char *message)
499 * vars: %s nick 499 * vars: %s nick
500 * %s topic */ 500 * %s topic */
501static void 501static void
502topicchange (unsigned char *message) 502topicchange (char *message)
503{ 503{
504 unsigned char *nick = NULL, *topic = NULL; 504 char *nick = NULL, *topic = NULL;
505 int len; 505 int len;
506 506
507 /* search start of nickname */ 507 /* search start of nickname */
@@ -537,9 +537,9 @@ topicchange (unsigned char *message)
537 * vars: %s str1 - nick used to login 537 * vars: %s str1 - nick used to login
538 * %s str2 - servers message */ 538 * %s str2 - servers message */
539static void 539static void
540justloggedin (unsigned char *message) 540justloggedin (char *message)
541{ 541{
542 unsigned char *str1 = NULL, *str2 = NULL; 542 char *str1 = NULL, *str2 = NULL;
543 /* search start of nickname */ 543 /* search start of nickname */
544 str1 = strchr (message, ' '); 544 str1 = strchr (message, ' ');
545 str1++; 545 str1++;
@@ -590,7 +590,7 @@ ownleave (int channel)
590 590
591/* this user changes his nick */ 591/* this user changes his nick */
592void 592void
593ownnickchange (unsigned char *newnick) 593ownnickchange (char *newnick)
594{ 594{
595 /* free old nick, store copy of new nick */ 595 /* free old nick, store copy of new nick */
596 setstroption(CF_NICK,newnick); 596 setstroption(CF_NICK,newnick);
@@ -606,9 +606,9 @@ ownnickchange (unsigned char *newnick)
606 * 415 %s 606 * 415 %s
607 * vars: %s - server message */ 607 * vars: %s - server message */
608static void 608static void
609nickerr (unsigned char *message) 609nickerr (char *message)
610{ 610{
611 unsigned char *helpkiller = NULL; 611 char *helpkiller = NULL;
612 /* mutate message for output */ 612 /* mutate message for output */
613 message[2] = '!'; 613 message[2] = '!';
614 /* help information found? remove it. */ 614 /* help information found? remove it. */
@@ -639,9 +639,9 @@ nickerr (unsigned char *message)
639 * vars: %s - this users registered nick 639 * vars: %s - this users registered nick
640 * %s msg - server message */ 640 * %s msg - server message */
641static void 641static void
642login (unsigned char *message) 642login (char *message)
643{ 643{
644 unsigned char *msg = NULL; 644 char *msg = NULL;
645 645
646 /* mutate message for output */ 646 /* mutate message for output */
647 message[2] = '*'; 647 message[2] = '*';
@@ -675,7 +675,7 @@ login (unsigned char *message)
675 * format: 121 %s 675 * format: 121 %s
676 * vars: %s - server message */ 676 * vars: %s - server message */
677static void 677static void
678anonlogin (unsigned char *message) 678anonlogin (char *message)
679{ 679{
680 /* mutate message for output */ 680 /* mutate message for output */
681 message[2] = '*'; 681 message[2] = '*';
@@ -695,11 +695,11 @@ anonlogin (unsigned char *message)
695 * format: 119 %s .. 695 * format: 119 %s ..
696 * vars: %s nick - a users nick */ 696 * vars: %s nick - a users nick */
697static void 697static void
698receivenicks (unsigned char *message) 698receivenicks (char *message)
699{ 699{
700 unsigned char *str1 = NULL, *str2 = NULL; 700 char *str1 = NULL, *str2 = NULL;
701 int mychan = 0; 701 int mychan = 0;
702 void (*ul_myfunc)(unsigned char*,int); 702 void (*ul_myfunc)(char*,int);
703 703
704 /* show message to user */ 704 /* show message to user */
705 snprintf (tmpstr, TMPSTRSIZE, getformatstr(FS_USONLINE), &message[4]); 705 snprintf (tmpstr, TMPSTRSIZE, getformatstr(FS_USONLINE), &message[4]);
@@ -745,9 +745,9 @@ receivenicks (unsigned char *message)
745 * vars: %s nick - who logged on 745 * vars: %s nick - who logged on
746 * %s msg - servers message */ 746 * %s msg - servers message */
747static void 747static void
748usersignon (unsigned char *message) 748usersignon (char *message)
749{ 749{
750 unsigned char *nick = NULL, *msg = NULL; 750 char *nick = NULL, *msg = NULL;
751 /* search start of nickname */ 751 /* search start of nickname */
752 nick = strchr (message, ' '); 752 nick = strchr (message, ' ');
753 nick++; 753 nick++;
@@ -770,9 +770,9 @@ usersignon (unsigned char *message)
770 * vars: %s nick - who logged off 770 * vars: %s nick - who logged off
771 * %s msg - servers message */ 771 * %s msg - servers message */
772static void 772static void
773usersignoff (unsigned char *message) 773usersignoff (char *message)
774{ 774{
775 unsigned char *nick = NULL, *msg = NULL; 775 char *nick = NULL, *msg = NULL;
776 /* search start of nickname */ 776 /* search start of nickname */
777 nick = strchr (message, ' '); 777 nick = strchr (message, ' ');
778 nick++; 778 nick++;
@@ -796,9 +796,9 @@ usersignoff (unsigned char *message)
796 * %s msg - servers message 796 * %s msg - servers message
797 * %d chan - channel joined */ 797 * %d chan - channel joined */
798static void 798static void
799userjoin (unsigned char *message) 799userjoin (char *message)
800{ 800{
801 unsigned char *nick = NULL, *msg = NULL, *channel = NULL; 801 char *nick = NULL, *msg = NULL, *channel = NULL;
802 int chan = 0; 802 int chan = 0;
803 803
804 /* search start of nickname */ 804 /* search start of nickname */
@@ -832,9 +832,9 @@ userjoin (unsigned char *message)
832 * %s msg - servers message 832 * %s msg - servers message
833 * %d chan - channel joined */ 833 * %d chan - channel joined */
834static void 834static void
835userleave (unsigned char *message) 835userleave (char *message)
836{ 836{
837 unsigned char *nick = NULL, *msg = NULL, *channel = NULL; 837 char *nick = NULL, *msg = NULL, *channel = NULL;
838 int chan = 0; 838 int chan = 0;
839 839
840 /* search start of nickname */ 840 /* search start of nickname */
@@ -868,9 +868,9 @@ userleave (unsigned char *message)
868 * %s newnick - users new nick 868 * %s newnick - users new nick
869 * %s msg - server message */ 869 * %s msg - server message */
870static void 870static void
871usernickchange (unsigned char *message) 871usernickchange (char *message)
872{ 872{
873 unsigned char *oldnick = NULL, *newnick = NULL, *msg = NULL; 873 char *oldnick = NULL, *newnick = NULL, *msg = NULL;
874 874
875 /* search start of old nickname */ 875 /* search start of old nickname */
876 oldnick = strchr (message, ' '); 876 oldnick = strchr (message, ' ');
@@ -896,9 +896,9 @@ usernickchange (unsigned char *message)
896 896
897/* handle received message from server */ 897/* handle received message from server */
898static void 898static void
899parsemsg (unsigned char *message) 899parsemsg (char *message)
900{ 900{
901 unsigned char *str1, *str2; 901 char *str1, *str2;
902 int i; 902 int i;
903 /* message to short or starts with '<'? must be channel */ 903 /* message to short or starts with '<'? must be channel */
904 if (message[0] == '<') 904 if (message[0] == '<')
@@ -1014,10 +1014,10 @@ void
1014networkinput (void) 1014networkinput (void)
1015{ 1015{
1016 int bytes; 1016 int bytes;
1017 unsigned char *tmp = NULL; 1017 char *tmp = NULL;
1018#define BUFSIZE 4096 1018#define BUFSIZE 4096
1019 unsigned char buf[BUFSIZE]; /* data buffer */ 1019 char buf[BUFSIZE]; /* data buffer */
1020 unsigned char *ltmp = buf; 1020 char *ltmp = buf;
1021 buf[BUFSIZE-1] = '\0'; /* sanity stop */ 1021 buf[BUFSIZE-1] = '\0'; /* sanity stop */
1022 1022
1023 /* check if we use ssl or if we don't and receive data at offset */ 1023 /* check if we use ssl or if we don't and receive data at offset */
@@ -1085,7 +1085,7 @@ networkinput (void)
1085} 1085}
1086 1086
1087void 1087void
1088networkoutput (unsigned char *msg) 1088networkoutput (char *msg)
1089{ 1089{
1090#ifdef DEBUG 1090#ifdef DEBUG
1091 /* debugging? log network output! */ 1091 /* debugging? log network output! */
diff --git a/vchat-ui.c b/vchat-ui.c
index 9378e0d..bd1cbe0 100755
--- a/vchat-ui.c
+++ b/vchat-ui.c
@@ -30,13 +30,13 @@
30#include "vchat.h" 30#include "vchat.h"
31 31
32/* version of this module */ 32/* version of this module */
33unsigned char *vchat_ui_version = "$Id$"; 33char *vchat_ui_version = "$Id$";
34 34
35/* externally used variables */ 35/* externally used variables */
36/* current string in topic window */ 36/* current string in topic window */
37unsigned char topicstr[TOPICSTRSIZE] = "[] VChat 0.16"; 37char topicstr[TOPICSTRSIZE] = "[] VChat 0.16";
38/* current string in console window */ 38/* current string in console window */
39unsigned char consolestr[CONSOLESTRSIZE] = "[ Get help: .h for server /h for client commands"; 39char consolestr[CONSOLESTRSIZE] = "[ Get help: .h for server /h for client commands";
40 40
41static unsigned int ui_init = 0; 41static unsigned int ui_init = 0;
42 42
@@ -48,8 +48,6 @@ static WINDOW *channel = NULL;
48static WINDOW *private = NULL; 48static WINDOW *private = NULL;
49static WINDOW *output = NULL; 49static WINDOW *output = NULL;
50 50
51static FILE *vchat_logfile = NULL;
52
53/* our screen dimensions */ 51/* our screen dimensions */
54static int screensx = 0; 52static int screensx = 0;
55static int screensy = 0; 53static int screensy = 0;
@@ -68,12 +66,13 @@ static int privheight_desired = 0;
68static int privwinhidden = 0; 66static int privwinhidden = 0;
69int usetime = 1; 67int usetime = 1;
70int outputcountdown = 0; 68int outputcountdown = 0;
69char *querypartner = NULL;
71 70
72struct sb_entry { 71struct sb_entry {
73 int id; 72 int id;
74 time_t when; 73 time_t when;
75 int stamp; 74 int stamp;
76 unsigned char *what; 75 char *what;
77 struct sb_entry *link; 76 struct sb_entry *link;
78}; 77};
79 78
@@ -93,9 +92,9 @@ static int sb_win = 0; /* 0 for pub, 1 for priv */
93 92
94/* struct to keep filter list */ 93/* struct to keep filter list */
95struct filt { 94struct filt {
96 unsigned char colour; 95 char colour;
97 unsigned int id; 96 unsigned int id;
98 unsigned char *text; 97 char *text;
99 regex_t regex; 98 regex_t regex;
100 struct filt *next; 99 struct filt *next;
101}; 100};
@@ -119,7 +118,7 @@ static void resize_output (void);
119static int getsbeheight (struct sb_entry *entry, const int xwidth, int needstime ); 118static int getsbeheight (struct sb_entry *entry, const int xwidth, int needstime );
120static int getsbdataheight (struct sb_data *data, const int xwidth, int needstime ); 119static int getsbdataheight (struct sb_data *data, const int xwidth, int needstime );
121/* CURRENTLY UNUSED 120/* CURRENTLY UNUSED
122static void writecolorized (WINDOW *win, unsigned char *string); 121static void writecolorized (WINDOW *win, char *string);
123*/ 122*/
124 123
125enum { 124enum {
@@ -129,10 +128,20 @@ enum {
129 RMFILTER_KEEPANDSTOP 128 RMFILTER_KEEPANDSTOP
130}; 129};
131 130
131/* */
132static void
133togglequery() {
134 if( querypartner && private ) {
135 { struct sb_data *tmp = sb_pub; sb_pub = sb_priv; sb_priv = tmp; }
136 { WINDOW *tmp= private; private = channel; channel = tmp; }
137 }
138}
139
132/* readlines callback when a line is completed */ 140/* readlines callback when a line is completed */
133static void 141static void
134linecomplete (unsigned char *line) 142linecomplete (char *line)
135{ 143{
144 char *c;
136 int i; 145 int i;
137 146
138 /* send linefeed, return pointer, reset cursors */ 147 /* send linefeed, return pointer, reset cursors */
@@ -157,6 +166,10 @@ linecomplete (unsigned char *line)
157 handleline (line); 166 handleline (line);
158 free (line); 167 free (line);
159 168
169 /* If in query mode, feed query prefix */
170 if (( c = querypartner ))
171 while( *c ) rl_stuff_char( *c++ );
172
160 /* wipe input line and reset cursor */ 173 /* wipe input line and reset cursor */
161 wmove (input, 0, 0); 174 wmove (input, 0, 0);
162 for (i = 0; i < input->_maxx; i++) 175 for (i = 0; i < input->_maxx; i++)
@@ -212,8 +225,8 @@ userinput (void)
212} 225}
213 226
214static int 227static int
215calcdrawcus (unsigned char * const str) { 228calcdrawcus (char * const str) {
216 unsigned char *tmp = str; 229 char *tmp = str;
217 int zero = 0; 230 int zero = 0;
218 while( *tmp && (*tmp!=' ') && (*tmp!='\n')) { if(*tmp==1) zero+=2; tmp++; } 231 while( *tmp && (*tmp!=' ') && (*tmp!='\n')) { if(*tmp==1) zero+=2; tmp++; }
219 return (tmp - str) - zero; 232 return (tmp - str) - zero;
@@ -240,7 +253,7 @@ sb_clear ( struct sb_data **sb ) {
240}*/ 253}*/
241 254
242static struct sb_entry* 255static struct sb_entry*
243sb_add (struct sb_data *sb, unsigned char *line, time_t when) { 256sb_add (struct sb_data *sb, char *line, time_t when) {
244 struct sb_entry *newone = malloc (sizeof(struct sb_entry)); 257 struct sb_entry *newone = malloc (sizeof(struct sb_entry));
245 if( newone ) { 258 if( newone ) {
246 if( sb->count == sb->scroll ) sb->scroll++; 259 if( sb->count == sb->scroll ) sb->scroll++;
@@ -282,7 +295,7 @@ void showout (void)
282 resize(0); 295 resize(0);
283} 296}
284 297
285void writeout (unsigned char *str) 298void writeout (char *str)
286{ 299{
287 int i; 300 int i;
288 sb_add(sb_out,str,time(NULL)); 301 sb_add(sb_out,str,time(NULL));
@@ -290,43 +303,47 @@ void writeout (unsigned char *str)
290 if( i > outputwidth_desired ) outputwidth_desired = i; 303 if( i > outputwidth_desired ) outputwidth_desired = i;
291} 304}
292 305
293int writechan (unsigned char *str) { 306int writechan (char *str) {
294 struct sb_entry *tmp; 307 struct sb_entry *tmp;
295 int i = 0; 308 int i = 0;
296 time_t now = time(NULL); 309 time_t now = time(NULL);
297 tmp = sb_add(sb_pub,str,now); 310 tmp = sb_add(sb_pub,str,now);
298 311
299 if( getintoption( CF_KEEPLOG ) && vchat_logfile )
300 fprintf( vchat_logfile, "%016llX0%s\n", (signed long long)now, str);
301
302 if ( (sb_pub->scroll == sb_pub->count) && ((filtertype == 0) || ( testfilter(tmp)))) { 312 if ( (sb_pub->scroll == sb_pub->count) && ((filtertype == 0) || ( testfilter(tmp)))) {
303 i = writescr(channel, tmp); 313 i = writescr(channel, tmp);
304 wnoutrefresh(channel); 314 wnoutrefresh(channel);
305 } 315 }
306 consoleline(NULL); 316
317 if( querypartner && private )
318 topicline(NULL);
319 else
320 consoleline(NULL);
321
307 return i; 322 return i;
308} 323}
309 324
310int writecf (formtstr id,unsigned char *str) { 325int writecf (formtstr id, char *str) {
311 struct sb_entry *tmp; 326 struct sb_entry *tmp;
312 int i = 0; 327 int i = 0;
313 time_t now = time(NULL); 328 time_t now = time(NULL);
314 snprintf(tmpstr,TMPSTRSIZE,getformatstr(id),str); 329 snprintf(tmpstr,TMPSTRSIZE,getformatstr(id),str);
315 tmp = sb_add(sb_pub,tmpstr,now); 330 tmp = sb_add(sb_pub,tmpstr,now);
316 331
317 if( getintoption( CF_KEEPLOG ) && vchat_logfile )
318 fprintf( vchat_logfile, "%016llX0%s\n", (unsigned long long)now, tmpstr);
319
320 if ( (sb_pub->scroll == sb_pub->count) && 332 if ( (sb_pub->scroll == sb_pub->count) &&
321 ((filtertype == 0) || ( testfilter(tmp)))) { 333 ((filtertype == 0) || ( testfilter(tmp)))) {
322 i = writescr(channel, tmp); 334 i = writescr(channel, tmp);
323 wnoutrefresh(channel); 335 wnoutrefresh(channel);
324 } 336 }
325 consoleline(NULL); 337
338 if( querypartner && private )
339 topicline(NULL);
340 else
341 consoleline(NULL);
342
326 return i; 343 return i;
327} 344}
328 345
329int writepriv (unsigned char *str, int maybeep) { 346int writepriv (char *str, int maybeep) {
330 int i = 0; 347 int i = 0;
331 if (private) { 348 if (private) {
332 349
@@ -334,10 +351,6 @@ int writepriv (unsigned char *str, int maybeep) {
334 struct sb_entry *tmp; 351 struct sb_entry *tmp;
335 tmp = sb_add(sb_priv,str,now); 352 tmp = sb_add(sb_priv,str,now);
336 353
337 if( getintoption( CF_KEEPLOG ) && vchat_logfile ) {
338 fprintf( vchat_logfile, "%016llX1%s\n", (unsigned long long)now, str);
339 }
340
341 if ( !privwinhidden && (sb_priv->scroll == sb_priv->count) && 354 if ( !privwinhidden && (sb_priv->scroll == sb_priv->count) &&
342 ((filtertype == 0) || ( testfilter(tmp)))) { 355 ((filtertype == 0) || ( testfilter(tmp)))) {
343 i = writescr(private, tmp); 356 i = writescr(private, tmp);
@@ -350,7 +363,12 @@ int writepriv (unsigned char *str, int maybeep) {
350 resize(0); 363 resize(0);
351 } 364 }
352 wnoutrefresh(private); 365 wnoutrefresh(private);
353 topicline(NULL); 366
367 if( querypartner && private )
368 consoleline(NULL);
369 else
370 topicline(NULL);
371
354 } else 372 } else
355 i = writechan( str ); 373 i = writechan( str );
356 374
@@ -388,13 +406,13 @@ static int attributes[] = { A_ALTCHARSET, A_BOLD, 0, A_DIM, 0, 0, 0, 0, A_INVIS,
388 0, 0, 1, 0, 0 }; 406 0, 0, 1, 0, 0 };
389 407
390static void 408static void
391docolorize (unsigned char colour, ncurs_attr *attr, ncurs_attr orgattr) { 409docolorize (char colour, ncurs_attr *attr, ncurs_attr orgattr) {
392 if( colour== '0') { 410 if( colour== '0') {
393 *attr = orgattr; 411 *attr = orgattr;
394 } else if( ( colour > '0') && ( colour <= '9')) { 412 } else if( ( colour > '0') && ( colour <= '9')) {
395 BCOLR_SET( attr, colour - '0' ); 413 BCOLR_SET( attr, colour - '0' );
396 } else { 414 } else {
397 unsigned char upc = colour & ( 0x20 ^ 0xff ); /* colour AND NOT 0x20 */ 415 char upc = colour & ( 0x20 ^ 0xff ); /* colour AND NOT 0x20 */
398 attr_t newattr; 416 attr_t newattr;
399 if( ( upc >= 'A') && ( upc<='Z' ) && ( newattr = attributes[upc - 'A']) ) 417 if( ( upc >= 'A') && ( upc<='Z' ) && ( newattr = attributes[upc - 'A']) )
400 attr->attr = ( colour & 0x20 ) ? attr->attr | newattr : attr->attr & ~newattr; 418 attr->attr = ( colour & 0x20 ) ? attr->attr | newattr : attr->attr & ~newattr;
@@ -404,13 +422,13 @@ docolorize (unsigned char colour, ncurs_attr *attr, ncurs_attr orgattr) {
404/* draw arbitrary strings */ 422/* draw arbitrary strings */
405static int 423static int
406writescr ( WINDOW *win, struct sb_entry *entry ) { 424writescr ( WINDOW *win, struct sb_entry *entry ) {
407 unsigned char tmp [64]; 425 char tmp [64];
408 int charcount = 0; 426 int charcount = 0;
409 int i; 427 int i;
410 int textlen = strlen( entry->what ); 428 int textlen = strlen( entry->what );
411 int timelen = ((win == channel)||(win == private)) && usetime ? 429 int timelen = ((win == channel)||(win == private)) && usetime ?
412 (int)strftime(tmp,64,getformatstr(FS_TIME),localtime(&entry->when)) : 0; 430 (int)strftime(tmp,64,getformatstr(FS_TIME),localtime(&entry->when)) : 0;
413 unsigned char textbuffer[ textlen+timelen+1 ]; 431 char textbuffer[ textlen+timelen+1 ];
414 ncurs_attr attrbuffer[ textlen+timelen+1 ]; 432 ncurs_attr attrbuffer[ textlen+timelen+1 ];
415 ncurs_attr orgattr; 433 ncurs_attr orgattr;
416 434
@@ -446,9 +464,9 @@ writescr ( WINDOW *win, struct sb_entry *entry ) {
446 464
447 /* hilite */ 465 /* hilite */
448 if((win == channel)||(win == private)) { /* do not higlight bars */ 466 if((win == channel)||(win == private)) { /* do not higlight bars */
449 filt *flt = filterlist; 467 filt *flt = filterlist;
450 unsigned char *instr = textbuffer; 468 char *instr = textbuffer;
451 regmatch_t match; 469 regmatch_t match;
452 int j; 470 int j;
453 471
454 while( flt ) { 472 while( flt ) {
@@ -494,87 +512,6 @@ writescr ( WINDOW *win, struct sb_entry *entry ) {
494} 512}
495 513
496static void 514static void
497writelog_processentry ( FILE *file, struct sb_entry* entry )
498{
499 char *outtmp;
500 int outoff = 0;
501 if( usetime ) {
502 outtmp = tmpstr+64;
503 strftime(outtmp,64,getformatstr(FS_TIME),localtime(&entry->when));
504 while(*outtmp)
505 if( *outtmp > 1 )
506 tmpstr[outoff++] = *(outtmp++);
507 else
508 if( *(++outtmp))
509 outtmp++;
510 }
511
512 outtmp = entry->what;
513 while(*outtmp)
514 while(*outtmp && ( outoff < TMPSTRSIZE-1) ) {
515 if( *outtmp > 1 )
516 tmpstr[outoff++] = *(outtmp++);
517 else
518 if( *(++outtmp))
519 outtmp++;
520 tmpstr[outoff]=0; outoff = 0;
521 fputs( tmpstr, file );
522 }
523
524 fputc( '\n', file);
525}
526
527void
528writelog_i ( FILE *file)
529{
530 if( !private ) {
531 writelog( file);
532 } else {
533 struct sb_entry *now1= sb_pub->last, *prev1 = NULL, *tmp;
534 struct sb_entry *now2= sb_priv->last, *prev2 = NULL;
535 fputs( "Interleaved messages:\n\n", file);
536 while( now1 || now2 ) {
537 int process;
538 if( now1 && now2 ) {
539 process = ( now1->when < now2->when ) ? 1 : 2;
540 } else {
541 process = now1 ? 1 : 2;
542 }
543
544 if( process == 1 ) {
545 writelog_processentry( file, now1 );
546 tmp = now1; now1 = (struct sb_entry*)((unsigned long)now1->link ^ (unsigned long)prev1); prev1 = tmp;
547 } else {
548 writelog_processentry( file, now2 );
549 tmp = now2; now2 = (struct sb_entry*)((unsigned long)now2->link ^ (unsigned long)prev2); prev2 = tmp;
550 }
551 }
552 }
553}
554
555void
556writelog ( FILE *file )
557{
558 if( sb_pub->last ) {
559 struct sb_entry *now = sb_pub->last, *prev = NULL, *tmp;
560 fputs( "Public messages:\n\n", file);
561 while( now ) {
562 writelog_processentry( file, now );
563 tmp = now; now = (struct sb_entry*)((unsigned long)now->link ^ (unsigned long)prev); prev = tmp;
564 }
565 putc( '\n', file );
566 }
567 if( private && sb_priv->last ) {
568 struct sb_entry *now = sb_priv->last, *prev = NULL, *tmp;
569 fputs( "Private messages:\n\n", file);
570 while( now ) {
571 writelog_processentry( file, now );
572 tmp = now; now = (struct sb_entry*)((unsigned long)now->link ^ (unsigned long)prev); prev = tmp;
573 }
574 }
575}
576
577static void
578resize_output ( ) 515resize_output ( )
579{ 516{
580 int outputwidth = (outputwidth_desired + 7 > screensx) ? screensx - 7 : outputwidth_desired; 517 int outputwidth = (outputwidth_desired + 7 > screensx) ? screensx - 7 : outputwidth_desired;
@@ -587,7 +524,9 @@ resize_output ( )
587} 524}
588 525
589static void 526static void
590doscroll( int up ) { 527doscroll ( int up ) {
528 togglequery();
529 {
591 WINDOW *destwin = (sb_win && private) ? private : channel; 530 WINDOW *destwin = (sb_win && private) ? private : channel;
592 struct sb_data *sb = (sb_win && private) ? sb_priv : sb_pub; 531 struct sb_data *sb = (sb_win && private) ? sb_priv : sb_pub;
593 struct sb_entry *now = sb->entries, *prev = NULL, *tmp; 532 struct sb_entry *now = sb->entries, *prev = NULL, *tmp;
@@ -617,7 +556,14 @@ doscroll( int up ) {
617 556
618 drawwin(destwin, sb); 557 drawwin(destwin, sb);
619 wnoutrefresh(destwin); 558 wnoutrefresh(destwin);
620 if( sb_win && private ) topicline(NULL); else consoleline(NULL); 559
560 togglequery();
561
562 if( private && (destwin == channel) )
563 topicline( NULL);
564 else
565 consoleline( NULL);
566 }
621} 567}
622 568
623 569
@@ -634,7 +580,7 @@ scrolldown (void)
634} 580}
635 581
636void 582void
637scrollwin (vod) 583scrollwin (void)
638{ 584{
639 if (!sb_win && private && !privwinhidden) sb_win = 1; 585 if (!sb_win && private && !privwinhidden) sb_win = 1;
640 else sb_win = 0; 586 else sb_win = 0;
@@ -643,7 +589,7 @@ scrollwin (vod)
643} 589}
644 590
645void 591void
646growprivwin (vod) { 592growprivwin (void) {
647 if( private ) { 593 if( private ) {
648 if( privwinhidden) 594 if( privwinhidden)
649 privwinhidden = 0; 595 privwinhidden = 0;
@@ -653,7 +599,7 @@ growprivwin (vod) {
653 } 599 }
654} 600}
655 601
656void toggleprivwin (vod) { 602void toggleprivwin (void) {
657 if( outputshown ) { 603 if( outputshown ) {
658 outputshown = 0; 604 outputshown = 0;
659 resize(0); 605 resize(0);
@@ -674,7 +620,7 @@ void toggleprivwin (vod) {
674} 620}
675 621
676void 622void
677shrinkprivwin (vod) { 623shrinkprivwin (void) {
678 if( private && !privwinhidden ) { 624 if( private && !privwinhidden ) {
679 if( --privheight_desired < 1) privheight_desired = 1; 625 if( --privheight_desired < 1) privheight_desired = 1;
680 if( privheight_desired > screensy - 5) privheight_desired = screensy - 5; 626 if( privheight_desired > screensy - 5) privheight_desired = screensy - 5;
@@ -778,7 +724,7 @@ forceredraw (void)
778 if(console) wclear(console); 724 if(console) wclear(console);
779 if(topic) wclear(topic); 725 if(topic) wclear(topic);
780 if(private) wclear(private); 726 if(private) wclear(private);
781 if(channel) wclear( channel ); 727 if(channel) wclear(channel );
782 if(output) wclear(output); 728 if(output) wclear(output);
783 if(input) wclear(input); 729 if(input) wclear(input);
784 resize(0); 730 resize(0);
@@ -828,6 +774,8 @@ resize (int signal)
828 * Arrange windows on screen 774 * Arrange windows on screen
829 *****/ 775 *****/
830 776
777 togglequery();
778
831 /* console and input are always there and always 1 line tall */ 779 /* console and input are always there and always 1 line tall */
832 wresize(console,1,screensx); 780 wresize(console,1,screensx);
833 wresize(input,1,screensx); 781 wresize(input,1,screensx);
@@ -882,6 +830,8 @@ resize (int signal)
882 if(private && !privwinhidden ) 830 if(private && !privwinhidden )
883 wnoutrefresh(private); 831 wnoutrefresh(private);
884 832
833 togglequery();
834
885 /* Resize and draw our message window, render topic and 835 /* Resize and draw our message window, render topic and
886 console line */ 836 console line */
887 if(outputshown) resize_output(); 837 if(outputshown) resize_output();
@@ -1277,34 +1227,6 @@ initui (void)
1277 showout( ); 1227 showout( );
1278*/ 1228*/
1279 1229
1280 if( getintoption( CF_KEEPLOG ) ) {
1281 unsigned char *logfile = getstroption( CF_LOGFILE );
1282 if( logfile && *logfile ) {
1283 if( *logfile == '~' )
1284 logfile = tilde_expand( logfile );
1285 vchat_logfile = fopen( logfile, "r+" );
1286 if( vchat_logfile ) {
1287 time_t now;
1288 long long now_;
1289 char dst;
1290 int lenstr;
1291 while( !feof( vchat_logfile)) {
1292 if( (fscanf( vchat_logfile, "%016llX%c", (unsigned long long*)&now_, &dst)) &&
1293 ((dst == '0') || (dst == '1')))
1294 {
1295 now = (time_t)now_;
1296 if(fgets(tmpstr, TMPSTRSIZE, vchat_logfile)) {
1297 lenstr = strlen( tmpstr );
1298 tmpstr[lenstr-1] = '\0';
1299 sb_add( dst == '0' ? sb_pub : sb_priv, tmpstr, now);
1300 }
1301 } else
1302 while( !feof( vchat_logfile) && ( fgetc( vchat_logfile ) != '\n'));
1303 }
1304 }
1305 }
1306 }
1307
1308 resize(0); 1230 resize(0);
1309} 1231}
1310 1232
@@ -1314,7 +1236,7 @@ initui (void)
1314 Enable, when needed 1236 Enable, when needed
1315 1237
1316static void 1238static void
1317writecolorized( WINDOW *win, unsigned char *string) { 1239writecolorized( WINDOW *win, char *string) {
1318 ncurs_attr old_att, new_att; 1240 ncurs_attr old_att, new_att;
1319 int i; 1241 int i;
1320 1242
@@ -1333,12 +1255,14 @@ writecolorized( WINDOW *win, unsigned char *string) {
1333 1255
1334/* render consoleline to screen */ 1256/* render consoleline to screen */
1335void 1257void
1336consoleline (unsigned char *message) 1258consoleline (char *message)
1337{ 1259{
1338 /* clear console, set string (or default), redraw display */ 1260 /* clear console, set string (or default), redraw display */
1339 int i; 1261 int i;
1340 ncurs_attr old_att, new_att; 1262 ncurs_attr old_att, new_att;
1341 1263
1264 togglequery();
1265
1342 memset( &new_att, 0, sizeof(new_att)); 1266 memset( &new_att, 0, sizeof(new_att));
1343 BCOLR_SET( (&new_att), 8 ); 1267 BCOLR_SET( (&new_att), 8 );
1344 wmove (console, 0, 0); 1268 wmove (console, 0, 0);
@@ -1370,13 +1294,15 @@ consoleline (unsigned char *message)
1370 redrawwin(output); 1294 redrawwin(output);
1371 wnoutrefresh(output); 1295 wnoutrefresh(output);
1372 } 1296 }
1297
1298 togglequery();
1373 wnoutrefresh(input); 1299 wnoutrefresh(input);
1374 doupdate(); 1300 doupdate();
1375} 1301}
1376 1302
1377/* render topicline to screen */ 1303/* render topicline to screen */
1378void 1304void
1379topicline (unsigned char *message) 1305topicline (char *message)
1380{ 1306{
1381 int i; 1307 int i;
1382 ncurs_attr old_att, new_att; 1308 ncurs_attr old_att, new_att;
@@ -1384,6 +1310,8 @@ topicline (unsigned char *message)
1384 if( !topic ) 1310 if( !topic )
1385 return; 1311 return;
1386 1312
1313 togglequery();
1314
1387 memset( &new_att, 0, sizeof(new_att)); 1315 memset( &new_att, 0, sizeof(new_att));
1388 BCOLR_SET( (&new_att), 8 ); 1316 BCOLR_SET( (&new_att), 8 );
1389 1317
@@ -1409,6 +1337,8 @@ topicline (unsigned char *message)
1409 redrawwin(output); 1337 redrawwin(output);
1410 wnoutrefresh(output); 1338 wnoutrefresh(output);
1411 } 1339 }
1340
1341 togglequery();
1412 wnoutrefresh(input); 1342 wnoutrefresh(input);
1413 doupdate(); 1343 doupdate();
1414} 1344}
@@ -1421,8 +1351,6 @@ exitui (void)
1421 rl_callback_handler_remove (); 1351 rl_callback_handler_remove ();
1422 endwin (); 1352 endwin ();
1423 ui_init = 0; 1353 ui_init = 0;
1424 if( vchat_logfile )
1425 fclose( vchat_logfile );
1426 } 1354 }
1427} 1355}
1428 1356
@@ -1465,7 +1393,7 @@ static void
1465vcnredraw (void) 1393vcnredraw (void)
1466{ 1394{
1467 int i; 1395 int i;
1468 unsigned char *passbof="-*-*-*-*-*-*-"; 1396 char *passbof="-*-*-*-*-*-*-";
1469 1397
1470 /* wipe input line and reset cursor */ 1398 /* wipe input line and reset cursor */
1471 wmove(input, 0, 0); 1399 wmove(input, 0, 0);
@@ -1486,7 +1414,7 @@ int
1486passprompt (char *buf, int size, int rwflag, void *userdata) 1414passprompt (char *buf, int size, int rwflag, void *userdata)
1487{ 1415{
1488 int i; 1416 int i;
1489 unsigned char *passphrase = NULL; 1417 char *passphrase = NULL;
1490 1418
1491 /* use special non-revealing redraw function */ 1419 /* use special non-revealing redraw function */
1492 /* FIXME: passphrase isn't protected against e.g. swapping */ 1420 /* FIXME: passphrase isn't protected against e.g. swapping */
@@ -1619,7 +1547,7 @@ clearfilters( char colour ) {
1619 1547
1620/* removes filter pattern */ 1548/* removes filter pattern */
1621void 1549void
1622removefilter( unsigned char *tail ) { 1550removefilter( char *tail ) {
1623 int rmv = 0, val; 1551 int rmv = 0, val;
1624 char* end; 1552 char* end;
1625 1553
@@ -1627,8 +1555,8 @@ removefilter( unsigned char *tail ) {
1627 1555
1628 rmv = removefromfilterlist( test_simplerm, (void *)tail, 0 ); 1556 rmv = removefromfilterlist( test_simplerm, (void *)tail, 0 );
1629 if(!rmv) { 1557 if(!rmv) {
1630 val = strtol((char*)tail, &end, 10); 1558 val = strtol(tail, &end, 10);
1631 if( (tail != (unsigned char*)end) && (!*end) ) 1559 if( (tail != end) && (!*end) )
1632 rmv = removefromfilterlist( test_numericrm, (void *)val, 0); 1560 rmv = removefromfilterlist( test_numericrm, (void *)val, 0);
1633 } 1561 }
1634 1562
@@ -1646,7 +1574,7 @@ static unsigned int uniqueidpool = 1;
1646 1574
1647/* returns unique id for filter pattern or 0 for failure */ 1575/* returns unique id for filter pattern or 0 for failure */
1648unsigned int 1576unsigned int
1649addfilter( char colour, unsigned char *regex ) { 1577addfilter( char colour, char *regex ) {
1650 filt *newflt = malloc( sizeof(filt)), **flt = &filterlist; 1578 filt *newflt = malloc( sizeof(filt)), **flt = &filterlist;
1651 1579
1652 if( !newflt ) return 0; 1580 if( !newflt ) return 0;
@@ -1753,3 +1681,31 @@ listfilters( void ) {
1753 } 1681 }
1754 showout(); 1682 showout();
1755} 1683}
1684
1685void
1686handlequery( char *tail ) {
1687 if( *tail ) {
1688 // ".m %s " -> string + 4
1689 if( querypartner && private ) {
1690 WINDOW *tmp= private; private = channel; channel = tmp;
1691 }
1692 querypartner = (char *)realloc( querypartner, 5 + strlen( tail ));
1693 if( querypartner ) {
1694 snprintf( querypartner, 5 + strlen( tail ), ".m %s ", tail );
1695 if( private ) {
1696 WINDOW *tmp= private; private = channel; channel = tmp;
1697 }
1698 }
1699 resize( 0 );
1700 } else {
1701 // QUERY ends
1702 if( querypartner ) {
1703 free( querypartner );
1704 querypartner = NULL;
1705 if( private ) {
1706 WINDOW *tmp= private; private = channel; channel = tmp;
1707 }
1708 resize( 0 );
1709 }
1710 }
1711}
diff --git a/vchat-user.c b/vchat-user.c
index 1e14112..65b32b7 100755
--- a/vchat-user.c
+++ b/vchat-user.c
@@ -26,20 +26,20 @@
26 26
27struct user 27struct user
28{ 28{
29 unsigned char *nick; /* nick of user */ 29 char *nick; /* nick of user */
30 int chan; /* channel user is on */ 30 int chan; /* channel user is on */
31 int chan_valid; /* are we sure he is? */ 31 int chan_valid; /* are we sure he is? */
32 int client_pv; /* client protocol version */ 32 int client_pv; /* client protocol version */
33 int messaged; /* did we message with this user? */ 33 int messaged; /* did we message with this user? */
34 struct user *next; /* next user in linked list */ 34 struct user *next;/* next user in linked list */
35}; 35};
36 36
37/* version of this module */ 37/* version of this module */
38unsigned char *vchat_us_version = "$Id$"; 38char *vchat_us_version = "$Id$";
39 39
40/* externally used variables */ 40/* externally used variables */
41/* current nick */ 41/* current nick */
42unsigned char *nick = NULL; 42char *nick = NULL;
43/* current channel */ 43/* current channel */
44int chan = 0; 44int chan = 0;
45/* userlist */ 45/* userlist */
@@ -47,7 +47,7 @@ user *nicks = NULL;
47 47
48/* add user to userlist */ 48/* add user to userlist */
49void 49void
50ul_add (unsigned char *name, int ignored) 50ul_add (char *name, int ignored)
51{ 51{
52 user *tmp = NULL; 52 user *tmp = NULL;
53 53
@@ -100,7 +100,7 @@ ul_add (unsigned char *name, int ignored)
100 100
101/* delete user from userlist */ 101/* delete user from userlist */
102void 102void
103ul_del (unsigned char *name, int ignored) 103ul_del (char *name, int ignored)
104{ 104{
105 user *tmp = NULL, *ltmp = NULL; 105 user *tmp = NULL, *ltmp = NULL;
106 106
@@ -143,7 +143,7 @@ ul_del (unsigned char *name, int ignored)
143 143
144/* let user join a channel */ 144/* let user join a channel */
145void 145void
146ul_join (unsigned char *name, int channel) 146ul_join (char *name, int channel)
147{ 147{
148 /* is it this client? handle and return */ 148 /* is it this client? handle and return */
149 if (nick && !strcmp (nick, name)) 149 if (nick && !strcmp (nick, name))
@@ -157,7 +157,7 @@ ul_join (unsigned char *name, int channel)
157} 157}
158 158
159user * 159user *
160ul_finduser (unsigned char *name) { 160ul_finduser (char *name) {
161 user *tmp = nicks; 161 user *tmp = nicks;
162 snprintf( tmpstr, TMPSTRSIZE, "%s:", name); 162 snprintf( tmpstr, TMPSTRSIZE, "%s:", name);
163 163
@@ -175,11 +175,11 @@ ul_finduser (unsigned char *name) {
175 return NULL; 175 return NULL;
176} 176}
177 177
178unsigned char * 178char *
179ul_matchuser( unsigned char *regex) { 179ul_matchuser( char *regex) {
180 user *tmp = nicks; 180 user *tmp = nicks;
181 unsigned char *dest = tmpstr; 181 char *dest = tmpstr;
182 regex_t preg; 182 regex_t preg;
183 183
184 *dest = 0; 184 *dest = 0;
185 if( !regcomp( &preg, regex, REG_ICASE | REG_EXTENDED | REG_NEWLINE)) { 185 if( !regcomp( &preg, regex, REG_ICASE | REG_EXTENDED | REG_NEWLINE)) {
@@ -212,7 +212,7 @@ ul_usertofront( user *who ) {
212} 212}
213 213
214void 214void
215ul_msgto (unsigned char *name) { 215ul_msgto (char *name) {
216 user *tmp = ul_finduser(name); 216 user *tmp = ul_finduser(name);
217 217
218 if (tmp) { 218 if (tmp) {
@@ -222,7 +222,7 @@ ul_msgto (unsigned char *name) {
222} 222}
223 223
224void 224void
225ul_msgfrom (unsigned char *name) { 225ul_msgfrom (char *name) {
226 user *tmp = ul_finduser(name); 226 user *tmp = ul_finduser(name);
227 227
228 if (tmp) { 228 if (tmp) {
@@ -233,7 +233,7 @@ ul_msgfrom (unsigned char *name) {
233 233
234/* set channel of user */ 234/* set channel of user */
235void 235void
236ul_moveuser (unsigned char *name, int channel) { 236ul_moveuser (char *name, int channel) {
237 user *tmp = ul_finduser(name); 237 user *tmp = ul_finduser(name);
238 238
239 if (tmp) { 239 if (tmp) {
@@ -248,7 +248,7 @@ ul_moveuser (unsigned char *name, int channel) {
248 248
249/* let user leave a channel */ 249/* let user leave a channel */
250void 250void
251ul_leave (unsigned char *name, int channel) 251ul_leave (char *name, int channel)
252{ 252{
253 user *tmp = ul_finduser(name); 253 user *tmp = ul_finduser(name);
254 /* is it this client? handle and return */ 254 /* is it this client? handle and return */
@@ -271,7 +271,7 @@ ul_leave (unsigned char *name, int channel)
271 271
272/* let user change nick */ 272/* let user change nick */
273void 273void
274ul_nickchange (unsigned char *oldnick, unsigned char *newnick) 274ul_nickchange (char *oldnick, char *newnick)
275{ 275{
276 user *tmp = ul_finduser(oldnick); 276 user *tmp = ul_finduser(oldnick);
277 /* is it this client? handle and return */ 277 /* is it this client? handle and return */
@@ -314,19 +314,19 @@ ul_clear (void)
314#endif 314#endif
315} 315}
316 316
317int ulnc_casenick(user *tmp, const unsigned char *text, int len, int value) { 317int ulnc_casenick(user *tmp, const char *text, int len, int value) {
318 return (!strncmp(tmp->nick, text, len)); 318 return (!strncmp(tmp->nick, text, len));
319} 319}
320 320
321int ulnc_ncasenick(user *tmp, const unsigned char *text, int len, int value) { 321int ulnc_ncasenick(user *tmp, const char *text, int len, int value) {
322 return (!strncasecmp(tmp->nick, text, len)); 322 return (!strncasecmp(tmp->nick, text, len));
323} 323}
324 324
325unsigned char * 325char *
326ulnc_complete (const unsigned char *text, int state, int value, int (*checkfn)(user *,const unsigned char *,int,int)) { 326ulnc_complete (const char *text, int state, int value, int (*checkfn)(user *,const char *,int,int)) {
327 static int len; 327 static int len;
328 static user *tmp; 328 static user *tmp;
329 unsigned char *name; 329 char *name;
330 330
331 /* first round? reset pointers! */ 331 /* first round? reset pointers! */
332 if (!state) 332 if (!state)
@@ -355,11 +355,11 @@ ulnc_complete (const unsigned char *text, int state, int value, int (*checkfn)(u
355} 355}
356 356
357/* nick completion functions for readline in vchat-ui.c */ 357/* nick completion functions for readline in vchat-ui.c */
358unsigned char * 358char *
359ul_nickcomp (const unsigned char *text, int state) 359ul_nickcomp (const char *text, int state)
360{ 360{
361 int ncasemode = 1; 361 int ncasemode = 1;
362 unsigned char *name = NULL; 362 char *name = NULL;
363 if (!state) ncasemode = 0; 363 if (!state) ncasemode = 0;
364 if (!ncasemode) { 364 if (!ncasemode) {
365 name = ulnc_complete(text,state,0,ulnc_casenick); 365 name = ulnc_complete(text,state,0,ulnc_casenick);
@@ -373,20 +373,20 @@ ul_nickcomp (const unsigned char *text, int state)
373 return NULL; 373 return NULL;
374} 374}
375 375
376int ulnc_casenickc(user *tmp, const unsigned char *text, int len, int value) { 376int ulnc_casenickc(user *tmp, const char *text, int len, int value) {
377 return (!strncmp(tmp->nick, text, len) && (tmp->chan_valid) && (tmp->chan == value)); 377 return (!strncmp(tmp->nick, text, len) && (tmp->chan_valid) && (tmp->chan == value));
378} 378}
379 379
380int ulnc_ncasenickc(user *tmp, const unsigned char *text, int len, int value) { 380int ulnc_ncasenickc(user *tmp, const char *text, int len, int value) {
381 return (!strncasecmp(tmp->nick, text, len) && (tmp->chan_valid) && (tmp->chan == value)); 381 return (!strncasecmp(tmp->nick, text, len) && (tmp->chan_valid) && (tmp->chan == value));
382} 382}
383 383
384/* nick completion for channel, used by vchat-ui.c */ 384/* nick completion for channel, used by vchat-ui.c */
385unsigned char * 385char *
386ul_cnickcomp (const unsigned char *text, int state) 386ul_cnickcomp (const char *text, int state)
387{ 387{
388 int ncasemode = 1; 388 int ncasemode = 1;
389 static unsigned char *name = NULL; 389 static char *name = NULL;
390 390
391 if (!state) ncasemode = 0; 391 if (!state) ncasemode = 0;
392 if (!ncasemode) { 392 if (!ncasemode) {
@@ -402,20 +402,20 @@ ul_cnickcomp (const unsigned char *text, int state)
402 return NULL; 402 return NULL;
403} 403}
404 404
405int ulnc_casenickm(user *tmp, const unsigned char *text, int len, int value) { 405int ulnc_casenickm(user *tmp, const char *text, int len, int value) {
406 return (!strncmp(tmp->nick, text, len) && (tmp->messaged)); 406 return (!strncmp(tmp->nick, text, len) && (tmp->messaged));
407} 407}
408 408
409int ulnc_ncasenickm(user *tmp, const unsigned char *text, int len, int value) { 409int ulnc_ncasenickm(user *tmp, const char *text, int len, int value) {
410 return (!strncasecmp(tmp->nick, text, len) && (tmp->messaged)); 410 return (!strncasecmp(tmp->nick, text, len) && (tmp->messaged));
411} 411}
412 412
413/* nick completion for channel, used by vchat-ui.c */ 413/* nick completion for channel, used by vchat-ui.c */
414unsigned char * 414char *
415ul_mnickcomp (const unsigned char *text, int state) 415ul_mnickcomp (const char *text, int state)
416{ 416{
417 int ncasemode = 1; 417 int ncasemode = 1;
418 static unsigned char *name = NULL; 418 static char *name = NULL;
419 419
420 if (!state) ncasemode = 0; 420 if (!state) ncasemode = 0;
421 if (!ncasemode) { 421 if (!ncasemode) {
diff --git a/vchat.h b/vchat.h
index 33c378b..60d485d 100755
--- a/vchat.h
+++ b/vchat.h
@@ -26,20 +26,20 @@ typedef enum { SM_IGNORE, SM_INFO, SM_USERINFO, SM_CHANNEL, SM_ERROR } smtype;
26/* servermessage structure */ 26/* servermessage structure */
27struct servermessage 27struct servermessage
28{ 28{
29 unsigned char id[4]; /* three-character message id */ 29 char id[4]; /* three-character message id */
30 smtype type; /* message type */ 30 smtype type; /* message type */
31 void (*funct) (unsigned char *); /* function used by client */ 31 void (*funct) (char *); /* function used by client */
32 void (*hook) (unsigned char *); /* function hook for scripting */ 32 void (*hook) (char *); /* function hook for scripting */
33}; 33};
34typedef struct servermessage servermessage; 34typedef struct servermessage servermessage;
35 35
36/* configuration types and variable numbers */ 36/* configuration types and variable numbers */
37typedef enum { CO_NIL, CO_STR, CO_INT } conftype; 37typedef enum { CO_NIL, CO_STR, CO_INT } conftype;
38typedef enum { CF_NIL, CF_NICK, CF_FROM, CF_SERVERHOST, CF_SERVERPORT, 38typedef enum { CF_NIL, CF_NICK, CF_FROM, CF_SERVERHOST, CF_SERVERPORT,
39CF_CIPHERSUITE, CF_CONFIGFILE, CF_CERTFILE, CF_KEYFILE, CF_FORMFILE, CF_LOGFILE, 39CF_CIPHERSUITE, CF_CONFIGFILE, CF_CERTFILE, CF_KEYFILE, CF_FORMFILE,
40CF_USESSL, CF_USECERT, CF_PRIVHEIGHT, CF_HSCROLL, CF_CHANNEL, CF_USETIME, 40CF_USESSL, CF_USECERT, CF_PRIVHEIGHT, CF_HSCROLL, CF_CHANNEL, CF_USETIME,
41CF_USETOPIC, CF_SCROLLBPRIV, CF_SCROLLBACK, CF_SCROLLBPRIVT, CF_SCROLLBACKT, 41CF_USETOPIC, CF_SCROLLBPRIV, CF_SCROLLBACK, CF_SCROLLBPRIVT, CF_SCROLLBACKT,
42CF_KEEPLOG, CF_ENCODING, CF_BELLPRIV } confopt; 42CF_ENCODING, CF_BELLPRIV } confopt;
43 43
44/* format strings */ 44/* format strings */
45typedef enum { FS_PLAIN, FS_CHAN, FS_PRIV, FS_SERV, FS_GLOB, FS_DBG, FS_ERR, 45typedef enum { FS_PLAIN, FS_CHAN, FS_PRIV, FS_SERV, FS_GLOB, FS_DBG, FS_ERR,
@@ -54,14 +54,14 @@ FS_SBINF, FS_MISSTYPED, FS_UNKNCMD, FS_BADREGEX, FS_ERR_STRING } formtstr;
54/* configoption structure */ 54/* configoption structure */
55struct configoption 55struct configoption
56{ 56{
57 confopt id; 57 confopt id;
58 conftype type; 58 conftype type;
59 unsigned char *varname; 59 char *varname;
60 unsigned char *defaultvalue; 60 char *defaultvalue;
61 unsigned char *value; 61 char *value;
62 union { 62 union {
63 unsigned char **pstr; 63 char **pstr;
64 int *pint; 64 unsigned int *pint;
65 } localvar; 65 } localvar;
66}; 66};
67 67
@@ -71,74 +71,74 @@ typedef struct configoption configoption;
71struct formatstring 71struct formatstring
72{ 72{
73 formtstr id; 73 formtstr id;
74 unsigned char *idstring; 74 char *idstring;
75 unsigned char *formatstr; 75 char *formatstr;
76}; 76};
77typedef struct formatstring formatstring; 77typedef struct formatstring formatstring;
78 78
79/* static tmpstr in all modules */ 79/* static tmpstr in all modules */
80#define TMPSTRSIZE 1024 80#define TMPSTRSIZE 1024
81static unsigned char tmpstr[TMPSTRSIZE]; 81static char tmpstr[TMPSTRSIZE];
82 82
83extern unsigned char *nick; 83extern char *nick;
84extern int chan; 84extern int chan;
85 85
86extern unsigned int loggedin; 86extern unsigned int loggedin;
87 87
88/* vchat-client.c */ 88/* vchat-client.c */
89#define ERRSTRSIZE 1024 89#define ERRSTRSIZE 1024
90extern unsigned char errstr[]; 90extern char errstr[];
91extern unsigned char *vchat_cl_version; 91extern char *vchat_cl_version;
92void cleanup(int signal); 92void cleanup(int signal);
93 93
94/* configuration helper funktions from vchat-client.c */ 94/* configuration helper funktions from vchat-client.c */
95unsigned char *getformatstr (formtstr id); 95char *getformatstr (formtstr id);
96unsigned char *getstroption (confopt option); 96char *getstroption (confopt option);
97void setstroption (confopt option, unsigned char *string); 97void setstroption (confopt option, char *string);
98int getintoption (confopt option); 98int getintoption (confopt option);
99void setintoption (confopt option, int value); 99void setintoption (confopt option, int value);
100 100
101/* vchat-user.c */ 101/* vchat-user.c */
102extern unsigned char *vchat_us_version; 102extern char *vchat_us_version;
103 103
104/* add / delete user */ 104/* add / delete user */
105void ul_add (unsigned char *nick, int ignored); 105void ul_add (char *nick, int ignored);
106void ul_del (unsigned char *nick, int ignored); 106void ul_del (char *nick, int ignored);
107 107
108/* clear userlist */ 108/* clear userlist */
109void ul_clear (); 109void ul_clear ();
110 110
111/* channel join / leave */ 111/* channel join / leave */
112void ul_join (unsigned char *nick, int channel); 112void ul_join (char *nick, int channel);
113void ul_leave (unsigned char *nick, int channel); 113void ul_leave (char *nick, int channel);
114 114
115/* nickchange */ 115/* nickchange */
116void ul_nickchange (unsigned char *oldnick, unsigned char *newnick); 116void ul_nickchange (char *oldnick, char *newnick);
117 117
118/* place user in channel */ 118/* place user in channel */
119void ul_moveuser (unsigned char *nick, int channel); 119void ul_moveuser (char *nick, int channel);
120 120
121/* message nick completion */ 121/* message nick completion */
122void ul_msgto (unsigned char *nick); 122void ul_msgto (char *nick);
123void ul_msgfrom (unsigned char *nick); 123void ul_msgfrom (char *nick);
124 124
125/* nick-completion for vchat-ui.c */ 125/* nick-completion for vchat-ui.c */
126unsigned char *ul_nickcomp (const unsigned char *text, int state); 126char *ul_nickcomp (const char *text, int state);
127unsigned char *ul_cnickcomp (const unsigned char *text, int state); 127char *ul_cnickcomp (const char *text, int state);
128unsigned char *ul_mnickcomp (const unsigned char *text, int state); 128char *ul_mnickcomp (const char *text, int state);
129 129
130/* try to find user by substring */ 130/* try to find user by substring */
131unsigned char *ul_matchuser ( unsigned char *substr); 131char *ul_matchuser (char *substr);
132 132
133/* vchat-ui.c */ 133/* vchat-ui.c */
134extern unsigned char *vchat_ui_version; 134extern char *vchat_ui_version;
135 135
136/* topic and console strings */ 136/* topic and console strings */
137#define TOPICSTRSIZE 1024 137#define TOPICSTRSIZE 1024
138#define CONSOLESTRSIZE 1024 138#define CONSOLESTRSIZE 1024
139extern unsigned char topicstr[]; 139extern char topicstr[];
140extern unsigned char consolestr[]; 140extern char consolestr[];
141extern unsigned char *encoding; 141extern char *encoding;
142 142
143/* init / exit functions */ 143/* init / exit functions */
144void initui (void); 144void initui (void);
@@ -148,22 +148,20 @@ void exitui (void);
148void userinput (void); 148void userinput (void);
149 149
150/* display various messages */ 150/* display various messages */
151int writechan (unsigned char *str); 151int writechan (char *str);
152int writepriv (unsigned char *str, int maybeep ); 152int writepriv (char *str, int maybeep );
153void writeout (unsigned char *str); 153void writeout (char *str);
154void showout (void); 154void showout (void);
155void flushout (void); 155void flushout (void);
156#define msgout(STR) {flushout();writeout(STR);showout();} 156#define msgout(STR) {flushout();writeout(STR);showout();}
157void hideout (void); 157void hideout (void);
158int writecf (formtstr id, unsigned char *str); 158int writecf (formtstr id, char *str);
159void writelog (FILE *file);
160void writelog_i(FILE *file);
161 159
162extern int outputcountdown; 160extern int outputcountdown;
163 161
164/* update console / topic window */ 162/* update console / topic window */
165void consoleline (unsigned char *); 163void consoleline (char *);
166void topicline (unsigned char *); 164void topicline (char *);
167 165
168/* prompt for nick or password */ 166/* prompt for nick or password */
169void nickprompt (void); 167void nickprompt (void);
@@ -172,40 +170,42 @@ int passprompt (char *buf, int size, int rwflag, void *userdata);
172/* filter functions */ 170/* filter functions */
173void refilterscrollback( void); 171void refilterscrollback( void);
174 172
175unsigned int addfilter ( char colour, unsigned char *regex ); 173unsigned int addfilter ( char colour, char *regex );
176void removefilter ( unsigned char *line ); 174void removefilter ( char *line );
177void listfilters ( void ); 175void listfilters ( void );
178void clearfilters ( char colour ); 176void clearfilters ( char colour );
179 177
178void handlequery ( char *line );
179
180/* vchat-protocol.c */ 180/* vchat-protocol.c */
181extern unsigned char *vchat_io_version; 181extern char *vchat_io_version;
182 182
183/* connect/disconnect */ 183/* connect/disconnect */
184int vcconnect (unsigned char *server, unsigned char *port); 184int vcconnect (char *server, char *port);
185void vcdisconnect (); 185void vcdisconnect ();
186 186
187/* network I/O */ 187/* network I/O */
188void networkinput (void); 188void networkinput (void);
189void networkoutput (unsigned char *); 189void networkoutput (char *);
190 190
191/* helpers for vchat-user.c */ 191/* helpers for vchat-user.c */
192void ownjoin (int channel); 192void ownjoin (int channel);
193void ownleave (int channel); 193void ownleave (int channel);
194void ownnickchange (unsigned char *newnick); 194void ownnickchange (char *newnick);
195 195
196/* vchat-commands.c */ 196/* vchat-commands.c */
197extern unsigned char *vchat_cm_version; 197extern char *vchat_cm_version;
198void command_version ( unsigned char *tail); 198void command_version ( char *tail);
199 199
200/* user input */ 200/* user input */
201void handleline (unsigned char *); 201void handleline (char *);
202 202
203/* struct for defining "/command" handlers */ 203/* struct for defining "/command" handlers */
204typedef struct { 204typedef struct {
205 int number; 205 int number;
206 unsigned char name[8]; 206 char name[8];
207 int len; 207 int len;
208 void (*handler)(unsigned char *); 208 void (*handler)(char *);
209 unsigned char *short_help; 209 char *short_help;
210 unsigned char *help; 210 char *help;
211} commandentry; 211} commandentry;