summaryrefslogtreecommitdiff
path: root/vchat-client.c
diff options
context:
space:
mode:
authorDirk Engling <erdgeist@erdgeist.org>2022-05-16 15:53:39 +0200
committerDirk Engling <erdgeist@erdgeist.org>2022-05-16 15:53:39 +0200
commitd1ac67f6d73f24a165ccc008440bb8b208ae140f (patch)
tree0da0184ec2273ffa6f642ab06e776fcdda9f4ac3 /vchat-client.c
parent43b74147212ddc5e619ac17dd1b5967b6b293d8a (diff)
Decouple IO openssl's BIO abstraction and split connection and tls handling to allow for other TLS libs
Diffstat (limited to 'vchat-client.c')
-rwxr-xr-xvchat-client.c46
1 files changed, 14 insertions, 32 deletions
diff --git a/vchat-client.c b/vchat-client.c
index 0e480be..d6a3db3 100755
--- a/vchat-client.c
+++ b/vchat-client.c
@@ -29,6 +29,7 @@
29#include <locale.h> 29#include <locale.h>
30 30
31#include "vchat.h" 31#include "vchat.h"
32#include "vchat-connection.h"
32#include "vchat-user.h" 33#include "vchat-user.h"
33 34
34/* version of this module */ 35/* version of this module */
@@ -43,7 +44,6 @@ int status = 1;
43int ownquit = 0; 44int ownquit = 0;
44/* we set this, we DONT want to quit */ 45/* we set this, we DONT want to quit */
45int wantreconnect = 0; 46int wantreconnect = 0;
46unsigned int want_tcp_keepalive = 0;
47 47
48static int reconnect_delay = 6; 48static int reconnect_delay = 6;
49static time_t reconnect_time = 0; 49static time_t reconnect_time = 0;
@@ -51,17 +51,10 @@ static time_t reconnect_time = 0;
51/* error string to show after exit */ 51/* error string to show after exit */
52char errstr[ERRSTRSIZE] = "\0"; 52char errstr[ERRSTRSIZE] = "\0";
53 53
54/* locally global variables */
55/* our list of filedescriptors */
56static fd_set masterfds;
57
58/* declaration of configuration array */ 54/* declaration of configuration array */
59#include "vchat-config.h" 55#include "vchat-config.h"
60 56
61/* servers filedescriptor from vchat-protocol.c */ 57void setnoption (const char *, char *);
62extern int serverfd;
63
64void setnoption (char *, char *);
65 58
66static void parsecfg(char *line) { 59static void parsecfg(char *line) {
67 int bytes; 60 int bytes;
@@ -264,7 +257,7 @@ setstroption (confopt option, char *string)
264 257
265/* set-named-option, puts string to variable named by name */ 258/* set-named-option, puts string to variable named by name */
266void 259void
267setnoption (char *name, char *string) 260setnoption (const char *name, char *string)
268{ 261{
269 int i; 262 int i;
270#ifdef DEBUG 263#ifdef DEBUG
@@ -354,11 +347,8 @@ cleanup (int signal)
354 exitui (); 347 exitui ();
355 /* clear userlist */ 348 /* clear userlist */
356 ul_clear (); 349 ul_clear ();
357 /* close server connection */ 350 vc_disconnect();
358 if (serverfd > 0) { 351
359 close (serverfd);
360 serverfd = -1;
361 }
362 /* inform user if we where killed by signal */ 352 /* inform user if we where killed by signal */
363 if (signal > 1) 353 if (signal > 1)
364 { 354 {
@@ -394,12 +384,9 @@ void calleverysecond( void ) {
394void 384void
395eventloop (void) 385eventloop (void)
396{ 386{
397 /* get fresh copy of filedescriptor list */ 387 int poll_result = vc_poll( 1 /* second timeout */ );
398 fd_set readfds = masterfds;
399 struct timeval tv = { 1, 0};
400 388
401 switch (select (serverfd + 2, &readfds, NULL, NULL, &tv)) 389 switch (poll_result) {
402 {
403 case -1: 390 case -1:
404 /* EINTR is most likely a SIGWINCH - ignore for now */ 391 /* EINTR is most likely a SIGWINCH - ignore for now */
405 if (errno != EINTR) 392 if (errno != EINTR)
@@ -411,19 +398,19 @@ eventloop (void)
411 writecf (FS_ERR,tmpstr); 398 writecf (FS_ERR,tmpstr);
412 /* see this as an error condition and bail out */ 399 /* see this as an error condition and bail out */
413 status = 0; 400 status = 0;
414 } 401 }
415 break; 402 break;
416 case 0: 403 case 0:
417 /* time out reached */ 404 /* time out reached */
418 calleverysecond(); 405 calleverysecond();
419 break; 406 break;
420 default: 407 default:
421 /* something to read from user & we're logged in or have a cert? */ 408 /* something to read from user & we're logged in or have a cert? */
422 if (FD_ISSET (0, &readfds) ) 409 if (poll_result & 1)
423 userinput (); 410 userinput ();
424 411
425 /* something to read from server? */ 412 /* something to read from server? */
426 if (serverfd!=-1 && FD_ISSET (serverfd, &readfds)) 413 if (poll_result & 2)
427 networkinput (); 414 networkinput ();
428 break; 415 break;
429 } 416 }
@@ -511,12 +498,8 @@ main (int argc, char **argv)
511 initui (); 498 initui ();
512 499
513 while( status ) { 500 while( status ) {
514 /* add stdin to masterfds */
515 FD_ZERO (&masterfds);
516 FD_SET (0, &masterfds);
517
518 /* attempt connection */ 501 /* attempt connection */
519 if (vcconnect (getstroption(CF_SERVERHOST), getstroption(CF_SERVERPORT))) { 502 if (vc_connect (getstroption(CF_SERVERHOST), getstroption(CF_SERVERPORT))) {
520 snprintf (tmpstr, TMPSTRSIZE, "Could not connect to server, %s.", strerror(errno)); 503 snprintf (tmpstr, TMPSTRSIZE, "Could not connect to server, %s.", strerror(errno));
521 strncpy(errstr,tmpstr,TMPSTRSIZE-2); 504 strncpy(errstr,tmpstr,TMPSTRSIZE-2);
522 errstr[TMPSTRSIZE-2] = '\0'; 505 errstr[TMPSTRSIZE-2] = '\0';
@@ -531,8 +514,7 @@ main (int argc, char **argv)
531 } else 514 } else
532 status = 0; 515 status = 0;
533 } else { 516 } else {
534 /* add serverfd to masterfds, reset reconnect delay */ 517 /* reset reconnect delay */
535 FD_SET (serverfd, &masterfds);
536 reconnect_delay = 6; 518 reconnect_delay = 6;
537 reconnect_time = 0; 519 reconnect_time = 0;
538 } 520 }
@@ -541,7 +523,7 @@ main (int argc, char **argv)
541 eventloop (); 523 eventloop ();
542 524
543 /* sanely close connection to server */ 525 /* sanely close connection to server */
544 vcdisconnect (); 526 vc_disconnect ();
545 527
546 if( !ownquit && ( getintoption( CF_AUTORECONN ) || wantreconnect ) ) 528 if( !ownquit && ( getintoption( CF_AUTORECONN ) || wantreconnect ) )
547 status = 1; 529 status = 1;