-/*
+/*
* sample-store.c --
*
* FastCGI example program using fcgi_stdio library
* length, sample-store writes a new snapshot and empties the log.
* This prevents the time needed for restart from growing without
* bound.
- *
+ *
* Since users "visit" Web sites, but never "leave", sample-store
* deletes a shopping cart after the cart has been inactive
* for a certain period of time. This policy prevents sample-store's
*/
#ifndef lint
-static const char rcsid[] = "$Id: sample-store.c,v 1.3 1999/07/26 05:33:00 roberts Exp $";
+static const char rcsid[] = "$Id: sample-store.c,v 1.4 1999/07/28 00:31:56 roberts Exp $";
#endif /* not lint */
-#include "fcgi_stdio.h" /* FCGI_Accept, FCGI_Finish, stdio */
+#include "fcgi_config.h"
+
+#include <assert.h> /* assert */
+#include <dirent.h> /* readdir, closedir, DIR, dirent */
+#include <errno.h> /* errno, ENOENT */
#include <stdlib.h> /* malloc/free, getenv, strtol */
#include <string.h> /* strcmp, strncmp, strlen, strstr, strchr */
#include <tcl.h> /* Tcl_*Hash* functions */
#include <time.h> /* time, time_t */
-#include <assert.h> /* assert */
-#include <errno.h> /* errno, ENOENT */
-#include <dirent.h> /* readdir, closedir, DIR, dirent */
+
+#ifdef HAVE_UNISTD_H
#include <unistd.h> /* fsync */
+#endif
#if defined __linux__
int fsync(int fd);
#endif
+#include "fcgi_stdio.h" /* FCGI_Accept, FCGI_Finish, stdio */
+
/*
* sample-store is designed to be configured as follows (for the OM server):
*
#define Strlen(str) (((str) == NULL) ? 0 : strlen(str))
-void panic(char *format,
- char *arg1, char *arg2, char *arg3, char *arg4,
- char *arg5, char *arg6, char *arg7, char *arg8);
-
static void *Malloc(size_t size);
static void Free(void *ptr);
static char *StringNCopy(char *str, int strLen);
cartEntry = Tcl_FirstHashEntry(cartTablePtr, &search);
for(cartEntry = Tcl_FirstHashEntry(cartTablePtr, &search);
cartEntry != NULL; cartEntry = Tcl_NextHashEntry(&search)) {
- cart = Tcl_GetHashValue(cartEntry);
+ cart = (CartObj *)Tcl_GetHashValue(cartEntry);
if(cart->inactive) {
userId = Tcl_GetHashKey(cartTablePtr, cartEntry);
DoEmptyCart(userId, TRUE);
cartEntry = Tcl_FirstHashEntry(cartTablePtr, &search);
for(cartEntry = Tcl_FirstHashEntry(cartTablePtr, &search);
cartEntry != NULL; cartEntry = Tcl_NextHashEntry(&search)) {
- cart = Tcl_GetHashValue(cartEntry);
+ cart = (CartObj *)Tcl_GetHashValue(cartEntry);
cart->inactive = TRUE;
}
}
static void MarkThisCartActive(char *userId)
{
Tcl_HashEntry *cartEntry = GetCartEntry(userId);
- CartObj *cart = Tcl_GetHashValue(cartEntry);
+ CartObj *cart = (CartObj *)Tcl_GetHashValue(cartEntry);
cart->inactive = FALSE;
}
\f
static Tcl_HashEntry *GetCartEntry(char *userId)
{
Tcl_HashEntry *cartEntry = Tcl_FindHashEntry(cartTablePtr, userId);
- int new;
+ int newCartEntry;
if(cartEntry == NULL) {
- CartObj *cart = Malloc(sizeof(CartObj));
+ CartObj *cart = (CartObj *)Malloc(sizeof(CartObj));
cart->inactive = FALSE;
cart->items = NULL;
- cartEntry = Tcl_CreateHashEntry(cartTablePtr, userId, &new);
- assert(new);
+ cartEntry = Tcl_CreateHashEntry(cartTablePtr, userId, &newCartEntry);
+ assert(newCartEntry);
Tcl_SetHashValue(cartEntry, cart);
}
return cartEntry;
printf("Location: %s?op=%s\r\n"
"\r\n", scriptName, OP_DISPLAY_STORE);
}
-}
+}
static int DoAddItemToCart(char *userId, char *item, int writeLog)
{
return -1;
} else {
Tcl_HashEntry *cartEntry = GetCartEntry(userId);
- CartObj *cart = Tcl_GetHashValue(cartEntry);
+ CartObj *cart = (CartObj *)Tcl_GetHashValue(cartEntry);
cart->items = ListOfString_AppendElement(
cart->items, StringCopy(item));
if(writeLog) {
char *scriptName, char *parent, char *userId, char *processId)
{
Tcl_HashEntry *cartEntry = GetCartEntry(userId);
- CartObj *cart = Tcl_GetHashValue(cartEntry);
+ CartObj *cart = (CartObj *)Tcl_GetHashValue(cartEntry);
ListOfString *items = cart->items;
int numberOfItems = ListOfString_Length(items);
return -1;
} else {
Tcl_HashEntry *cartEntry = GetCartEntry(userId);
- CartObj *cart = Tcl_GetHashValue(cartEntry);
+ CartObj *cart = (CartObj *)Tcl_GetHashValue(cartEntry);
if(ListOfString_IsElement(cart->items, item)) {
cart->items = ListOfString_RemoveElement(cart->items, item);
if (writeLog) {
static int DoEmptyCart(char *userId, int writeLog)
{
Tcl_HashEntry *cartEntry = GetCartEntry(userId);
- CartObj *cart = Tcl_GetHashValue(cartEntry);
+ CartObj *cart = (CartObj *)Tcl_GetHashValue(cartEntry);
ListOfString *items = cart->items;
/*
* Write log *before* tearing down cart structure because userId
*/
static char *StringNCopy(char *str, int strLen)
{
- char *newString = Malloc(strLen + 1);
+ char *newString = (char *)Malloc(strLen + 1);
memcpy(newString, str, strLen);
newString[strLen] = '\000';
return newString;
int str2Len = Strlen(str2);
int str3Len = Strlen(str3);
int str4Len = Strlen(str4);
- char *newString = Malloc(str1Len + str2Len + str3Len + str4Len + 1);
+ char *newString = (char *)Malloc(str1Len + str2Len + str3Len + str4Len + 1);
memcpy(newString, str1, str1Len);
memcpy(newString + str1Len, str2, str2Len);
memcpy(newString + str1Len + str2Len, str3, str3Len);
}
/*
- * Should the Tcl hash package detect an unrecoverable error(!), halt.
- */
-void panic(char *format,
- char *arg1, char *arg2, char *arg3, char *arg4,
- char *arg5, char *arg6, char *arg7, char *arg8)
-{
- assert(FALSE);
-}
-
-
-/*
* ListOfString abstraction
*/
ListOfString *list, char *element)
{
ListOfString *cur;
- ListOfString *newCell = Malloc(sizeof(ListOfString));
+ ListOfString *newCell = (ListOfString *)Malloc(sizeof(ListOfString));
newCell->head = element;
newCell->tail = NULL;
if(list == NULL) {