Back to index

courier  0.68.2
Functions
cgicookie.c File Reference
#include "cgi.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>

Go to the source code of this file.

Functions

void error (const char *)
static void enomem ()
char * cgi_cookie (const char *p)
void cgi_setcookie (const char *name, const char *value)

Function Documentation

char* cgi_cookie ( const char *  p)

Definition at line 22 of file cgicookie.c.

{
size_t pl=strlen(p);
const char *c=getenv("HTTP_COOKIE");
char   *buf;

       while (c && *c)
       {
       size_t i;

              for (i=0; c[i] && c[i] != '='; i++)
                     ;
              if (i == pl && strncmp(p, c, i) == 0)
              {
                     c += i;
                     if (*c)       ++c;   /* skip over = */
                     for (i=0; c[i] && c[i] != ';'; i++)
                            ;

                     buf=malloc(i+1);
                     if (!buf)     enomem();
                     memcpy(buf, c, i);
                     buf[i]=0;
                     cgiurldecode(buf);
                     return (buf);
              }
              c=strchr(c, ';');
              if (c)
                     do
                     {
                            ++c;
                     } while (isspace((int)(unsigned char)*c));
       }
       buf=malloc(1);
       if (!buf)     enomem();
       *buf=0;
       return (buf);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void cgi_setcookie ( const char *  name,
const char *  value 
)

Definition at line 61 of file cgicookie.c.

{
char   *p;
const  char *sn;

       p=cgiurlencode(value);
       sn=getenv("SCRIPT_NAME");
       if (!sn || !*sn)
              sn="/";
       printf("Set-Cookie: %s=%s; path=%s\n", name, value, sn);
       free(p);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void enomem ( ) [static]

Definition at line 17 of file cgicookie.c.

{
       error("Out of memory.");
}

Here is the call graph for this function:

Here is the caller graph for this function:

void error ( const char *  )

Definition at line 23 of file showmsg2html.c.

{
       fprintf(stderr, "%s\n", p);
       exit(1);
}