/*
* setguid.c - receive a GUID from GUID.org and set a site-specific cookie
*
* Usually used as a reponse to the GUID.org getguid routine, i.e.:
*
*
* For more information, see http://www.guid.org/usage.html
*
*/
#include
#include
#include
#define GUIDLEN 32
char guidstr[] = "GUID=";
char gifbits[] = "GIF89a\x01\x00\x01\x00\x80\xFF\x00\xC0\xC0\xC0\x00\x00\x00!\xF9\x04\x01\x00\x00\x00\x00,\x00\x00\x00\x00\x01\x00\x01\x00@\x02\x02D\x01\x00;";
int main() {
char *query, *begin, *end, guid[GUIDLEN+1];
int i;
guid[0] = 0;
query = getenv("QUERY_STRING");
if (query && query[0] && (begin = strstr(query, guidstr))) {
begin += sizeof(guidstr)-1;
for (end = begin; *end && (*end != '&'); end++) ;
if (end-begin > GUIDLEN) /* truncate overly long GUIDs */
end = begin+GUIDLEN;
strncpy(guid, begin, end-begin+1);
guid[GUIDLEN] = 0;
}
if (guid[0])
printf("Set-Cookie: GUID=%s; Expires=Thu 31-Dec-37 23:59:59 GMT; Path=/\n", guid);
printf("Content-Type: image/gif\n\n");
for (i=0; i