"Fossies" - the Fresh Open Source Software Archive

Member "libgcgi.a-0.9.5/examples/gcgiCookieTest.c" (22 Jun 2002, 2735 Bytes) of package /linux/www/old/gcgi-0.9.5.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #include <stdlib.h>
    2 #include <stdio.h>
    3 #include <unistd.h>
    4 
    5 #include "gcgi.h"
    6 
    7 #define SETCOOKIES  1
    8 #define READCOOKIES 2
    9 #define STOREHEADERS 3
   10 
   11 static const char* const strTypes[] = {
   12     "text", 
   13     "image", 
   14     "audio", 
   15     "video", 
   16     "application", 
   17     "multipart", 
   18     "message", 
   19     "unknown"
   20 };
   21 
   22 static const char* const strEncodings[] = {
   23     "7bit", 
   24     "8bit", 
   25     "binary", 
   26     "quoted-printable", 
   27     "base64", 
   28     "unknown"
   29 };
   30 
   31 int main (int argc, char *argv[], char *envp[]) 
   32 {
   33   int             caseAct, i;
   34   char          **cookies, *name, *value;
   35 
   36   /* Set Limits: field limit, query limit */
   37   gcgiSetLimits(1048576, 0);
   38 
   39   //gcgiDebug("./gcgi-env", "./mimedata2");
   40 
   41   if (initCgi() < 0) {
   42     fprintf(stderr, "Unable to parse CGI query.\n");
   43     return -1;
   44   }
   45   
   46   gcgiFetchInteger("caseAct", &caseAct, -1);
   47 
   48   cookies = NULL;
   49 
   50   if (caseAct == SETCOOKIES) {
   51 
   52 #ifdef USE_SSL
   53     gcgiGenerateKey(&key);
   54     gcgiWriteKeyToFile(key, "/tmp/gcgiCookieTest.key");
   55 #endif
   56 
   57     gcgiSendContentType("text/html", NULL, "ISO-8859-1", COOKIE);
   58 
   59 #ifdef USE_SSL
   60     gcgiSendEncryptedCookie("ticket1", "ThisIsTheFirstCookie", "/", "topeka.shingletowngap.org", NULL, 0, key, COOKIE);
   61     gcgiSendEncryptedCookie("ticket2", "ThisIsTheSecondCookie", "/", "topeka.shingletowngap.org", NULL, 0, key, LAST);
   62 #else
   63     gcgiSendCookie("ticket1", "ThisIsTheFirstCookie", "/", "topeka.shingletowngap.org", NULL, 0, COOKIE);
   64     gcgiSendCookie("ticket2", "ThisIsTheSecondCookie", "/", "topeka.shingletowngap.org", NULL, 0, LAST);
   65 #endif
   66 
   67   }
   68   else if (caseAct == READCOOKIES) {
   69 #ifdef USE_SSL
   70     gcgiReadKeyFromFile("/tmp/gcgiCookieTest.key", &key);
   71     unlink("/tmp/gcgiCookieTest.key");
   72 #endif
   73     gcgiSendContentType("text/html", NULL, "ISO-8859-1", LAST);
   74     gcgiFetchCookies(&cookies);
   75   }
   76   else if (caseAct == STOREHEADERS) {
   77     gcgiSaveEnvVariables("./gcgiCookieTest-output.txt");
   78     gcgiSendContentType("text/html", NULL, "ISO-8859-1", LAST);
   79   }
   80 
   81   fprintf(gcgiOut, 
   82       "<html>\n"
   83       "<head><title>gcgiCookieTest: Results</title></head>\n"
   84       "<body>\n"
   85       "<h1>Transaction completed successfully.</h1>\n");
   86 
   87   if (cookies != NULL) {
   88     for (i = 0; cookies[i] != '\0'; i++) {
   89 #ifdef USE_SSL      
   90       gcgiParseEncryptedCookie(cookies[i], key, &name, &value);
   91 #else
   92       gcgiParseCookie(cookies[i], &name, &value);
   93 #endif
   94 
   95       fprintf(gcgiOut, 
   96           "Cookie #%d: %s<br>\n"
   97           "<b>Decoded and Parsed Cookie:</b> Name: %s, Value: %s, Size: %d<br>\n",
   98           i+1, cookies[i], name, value, strlen(value));
   99 
  100       free(name);
  101       free(value);
  102     }
  103 
  104     gcgiFreeCookies(cookies);
  105   }
  106 
  107 
  108   fprintf(gcgiOut,
  109       "</body>\n"
  110       "</html>\n");
  111 
  112   freeCgi();
  113 
  114 #ifdef USE_SSL
  115   free(key);
  116 #endif
  117 
  118   return 0;
  119 }