/* Dynamische CSS, vooral gericht op door voorkeur van bezoekers, via cookies onthouden, gestuurde kleuren. Dynamic CSS, specially targeted to colour schemes determined by user preference, remembered using cookies. Copyright 2002, R.Harmsen 14 July 2013: Added the possibility to reset the cookie. See https://rudhar.com/sfreview/colvaren.htm for first using this possibility. */ #include #include #include #include #include #include "../cgitools/cgitools.h" char *ContentLength = "CONTENT_LENGTH"; extern char **environ; static int GetParmNoWeirdColours (void); int main (void) { time_t Until; int NoWeirdColours; char Expires[128]; struct tm *TimeStruct; NoWeirdColours = GetParmNoWeirdColours(); Until = time(NULL); if (NoWeirdColours >= 0) Until += 6 * 30 * 24L * 3600; else /* Expiration date in past to reset the cookie */ Until -= 24L * 3600; TimeStruct = gmtime(&Until); strftime(Expires, sizeof Expires, "%A, %d-%b-%Y %H:%M:%S GMT", TimeStruct); printf( "Content-type: text/html\n" "Set-cookie: NoWeirdColours=%s; EXPIRES=%s;\n\n", NoWeirdColours ? "1" : "0", Expires); fflush(stdout); if (NoWeirdColours >= 0) { printf( "This %ssets a cookie. If Javascript is allowed in\n" "your browser, you will be returned to the page where you\n" "clicked the link. If not, use your browser's back-button,\n" "and, once arrived back there, press Ctrl-R of Ctrl-F5 to\n" "reload the page with the new colour scheme.\n", NoWeirdColours ? "" : "re"); } /* Setting or resetting the cookie is all I want to do. No page should be displayed. To achieve that, a Javascript function is called to return to the page that contained the button. */ printf( "\n"); fflush(stdout); return 0; } /*********************************************************************** Interpret command line argument of called CGI prog. Return a file pointer to the CSS file, if found, else return NULL ***********************************************************************/ static int GetParmNoWeirdColours (void) { char *query; char **Vars = NULL, **V; int retval = 0; query = getenv("QUERY_STRING"); if (!query) { retval = 0; } else { Vars = CgiConvVars(query, NULL); for (V = Vars; V[0]; V += 2) { if (strcmp(V[0], "NoWeirdColours") == 0) { if (!strcmp(V[1], "1")) { retval = 1; } else if (!strcmp(V[1], "0")) { retval = 0; } else { retval = -1; } break; } } } return retval; }