From e137c1011b212ec7d7b26d0cd7290549d2d5eb6c Mon Sep 17 00:00:00 2001 From: glengray Date: Mon, 12 Nov 2001 17:35:43 +0000 Subject: [PATCH] Added the client_function timeout to the code. Also noticed a BIG bug in the screen_set code, the strcmp's never worked, they where no longer checking the results == 0. --- server/client_functions.c | 40 ++++++++++++++++++++++++++++----------- server/main.c | 34 +++++++++++++++++++++++++++++++++ server/screen.c | 2 ++ server/screen.h | 1 + 4 files changed, 66 insertions(+), 11 deletions(-) diff --git a/server/client_functions.c b/server/client_functions.c index fe5c68d..e25f894 100644 --- a/server/client_functions.c +++ b/server/client_functions.c @@ -589,9 +589,9 @@ screen_set_func (client * c, int argc, char **argv) p = argv[i]; if (*p == '-') p++; - + // Handle the "name" parameter - if (strcmp (p, "name")) { + if (strcmp (p, "name") == 0) { if (argc > i + 1) { i++; debug ("screen_set: name=\"%s\"\n", argv[i]); @@ -606,7 +606,7 @@ screen_set_func (client * c, int argc, char **argv) } } // Handle the "priority" parameter - else if (strcmp (p, "priority")) { + else if (strcmp (p, "priority") == 0) { if (argc > i + 1) { i++; debug ("screen_set: priority=\"%s\"\n", argv[i]); @@ -621,7 +621,7 @@ screen_set_func (client * c, int argc, char **argv) } } // Handle the "duration" parameter - else if (strcmp (p, "duration")) { + else if (strcmp (p, "duration") == 0) { if (argc > i + 1) { i++; debug ("screen_set: duration=\"%s\"\n", argv[i]); @@ -636,7 +636,7 @@ screen_set_func (client * c, int argc, char **argv) } } // Handle the "heartbeat" parameter - else if (strcmp (p, "heartbeat")) { + else if (strcmp (p, "heartbeat") == 0) { if (argc > i + 1) { i++; debug ("screen_set: heartbeat=\"%s\"\n", argv[i]); @@ -662,7 +662,7 @@ screen_set_func (client * c, int argc, char **argv) } } // Handle the "wid" parameter - else if (strcmp (p, "wid")) { + else if (strcmp (p, "wid") == 0) { if (argc > i + 1) { i++; debug ("screen_set: wid=\"%s\"\n", argv[i]); @@ -675,9 +675,10 @@ screen_set_func (client * c, int argc, char **argv) } else { sock_send_string (c->sock, "huh? -wid requires a parameter\n"); } + } // Handle the "hgt" parameter - else if (strcmp (p, "hgt")) { + else if (strcmp (p, "hgt") == 0) { if (argc > i + 1) { i++; debug ("screen_set: hgt=\"%s\"\n", argv[i]); @@ -690,11 +691,28 @@ screen_set_func (client * c, int argc, char **argv) } else { sock_send_string (c->sock, "huh? -hgt requires a parameter\n"); } - } else { - sock_send_string (c->sock, "huh? invalid parameter\n"); } - } // done checking argv - + // Handle the "timeout" parameter + else if (strcmp (p, "timeout") == 0) { + if (argc > i + 1) { + i++; + syslog(LOG_NOTICE, "Setting timeout."); + debug ("screen_set: timeout=\"%s\"\n", argv[i]); + // set the duration... + number = atoi (argv[i]); + // Add the timeout value (count of TIME_UNITS) + // to struct, TIME_UNIT is 1/8th of a second + if (number > 0) { + s->timeout = number; + syslog(LOG_NOTICE, "Timeout set."); + } + sock_send_string(c->sock, "success\n"); + } else { + sock_send_string (c->sock, "huh? -timeout requires a parameter\n"); + } + } + else sock_send_string (c->sock, "huh? invalid parameter\n"); + }// done checking argv return 0; } diff --git a/server/main.c b/server/main.c index 521137f..86ed799 100644 --- a/server/main.c +++ b/server/main.c @@ -565,6 +565,8 @@ void do_mainloop () { screen *s = NULL; + char *message=NULL; + //char buf[64]; // FIXME: s should still be null from initialization.... what's happening here?! @@ -616,6 +618,38 @@ do_mainloop () no_screen_screen (timer); usleep (TIME_UNIT); + + //Check to see if the screen has a timeout value, if it does + //decrese it and then check to see if it has excpired. + //Remove if expired. + if((message = malloc(256)) == NULL) + syslog(LOG_NOTICE, "Error allocating message string"); + else { + snprintf(message, 256, "Screen->%s has timeout->%d", s->name, s->timeout); + syslog(LOG_NOTICE, message); + free(message); + } + if (s && s->timeout != -1) { + + --(s->timeout); + if((message = malloc(256)) == NULL) + syslog(LOG_NOTICE, "Error allocating message string"); + else { + snprintf(message, 256, "Timeout matches check, has timeout->%d", s->name, s->timeout); + syslog(LOG_NOTICE, message); + free(message); + } + if (s->timeout <= 0) { + screen_remove (s->parent, s->id); + if((message = malloc(256)) == NULL) + syslog(LOG_NOTICE, "Error allocating message string"); + else { + snprintf(message, 256, "Removing screen %s which has timeout->%d", s->name, s->timeout); + syslog(LOG_NOTICE, message); + free(message); + } + } + } } // Quit! diff --git a/server/screen.c b/server/screen.c index b34480d..a17771c 100644 --- a/server/screen.c +++ b/server/screen.c @@ -14,6 +14,7 @@ #include "main.h" int default_duration = 0; +int default_timeout = -1; screen * screen_create () @@ -36,6 +37,7 @@ screen_create () s->keys = NULL; s->parent = NULL; s->widgets = NULL; + s->timeout = default_timeout; //ignored unless greater than 0. s->widgets = LL_new (); if (!s->widgets) { diff --git a/server/screen.h b/server/screen.h index d9ddc02..0d24305 100644 --- a/server/screen.h +++ b/server/screen.h @@ -11,6 +11,7 @@ typedef struct screen { int priority; int duration; int heartbeat; + int timeout; char *keys; LinkedList *widgets; client *parent;