[0001]
[0002]
[0003]
[0004]
[0005]
[0006]
[0007]
[0008]
[0009]
[0010]
[0011]
[0012]
[0013]
[0014]
[0015]
[0016]
[0017]
[0018]
[0019]
[0020]
[0021]
[0022]
[0023]
[0024]
[0025]
[0026]
[0027]
[0028]
[0029]
[0030]
[0031]
[0032]
[0033]
[0034]
[0035]
[0036]
[0037]
[0038]
[0039]
[0040]
[0041]
[0042]
[0043]
[0044]
[0045]
[0046]
[0047]
[0048]
[0049]
[0050]
[0051]
[0052]
[0053]
[0054]
[0055]
[0056]
[0057]
[0058]
[0059]
[0060]
[0061]
[0062]
[0063]
[0064]
[0065]
[0066]
[0067]
[0068]
[0069]
[0070]
[0071]
[0072]
[0073]
[0074]
[0075]
[0076]
[0077]
[0078]
[0079]
[0080]
[0081]
[0082]
[0083]
[0084]
[0085]
[0086]
[0087]
[0088]
[0089]
[0090]
[0091]
[0092]
[0093]
[0094]
[0095]
[0096]
[0097]
[0098]
[0099]
[0100]
[0101]
[0102]
[0103]
[0104]
[0105]
[0106]
[0107]
[0108]
[0109]
[0110]
[0111]
[0112]
[0113]
/*****************************************************************************/
/*
                                  dict.h
*/
/*****************************************************************************/

#ifndef DICT_H_LOADED
#define DICT_H_LOADED 1

#include "wasd.h"

/**********/
/* macros */
/**********/

#define DICT_DEFAULT_SIZE  32  /* hash entries */
#define DICT_MIN_BYTES     64  /* minimum chunk of memory for entry strings */

#define DICT_HASH_MULT  69069  /* hash multiplier */

/* some of these are design elements and currently not in use */
#define DICT_TYPE_CONFIG     "~"  /* configuration/mapping entry */
#define DICT_TYPE_INTERNAL   "$"  /* server internal */
#define DICT_TYPE_GLOBAL     "_"  /* global configuration */
#define DICT_TYPE_OPAQUE     "?"  /* opaque value (not string) */
#define DICT_TYPE_OPAQUE_KEY "|"  /* opaque key and value (not strings) */
#define DICT_TYPE_REQUEST    ">"  /* request header */
#define DICT_TYPE_RESERVED   "!"  /* used by METACON.C to remove an entry */
#define DICT_TYPE_RESPONSE   "<"  /* response header */
#define DICT_TYPE_SSI        "^"  /* nudge, nudge, wink, wink */
#define DICT_TYPE_UNDEFINED  ""   /* null character */

#define DICT_TYPE_UNIQUE           0x80    /* enumerated entries */
#define DICT_TYPE_RESPONSE_UNIQUE  "\xbc"  /* enumerated response header */

#define DICT_GET_COUNT(ptr) (((DICT_STRUCT*)(ptr))->count)
#define DICT_GET_KEY(ptr) (((DICT_ENTRY_STRUCT*)(ptr))->key)
#define DICT_GET_KEY_LEN(ptr) (((DICT_ENTRY_STRUCT*)(ptr))->klen)
#define DICT_GET_TYPE(ptr) (((DICT_ENTRY_STRUCT*)(ptr))->type)
#define DICT_GET_VALUE(ptr) (((DICT_ENTRY_STRUCT*)(ptr))->value)
#define DICT_GET_VALUE_LEN(ptr) (((DICT_ENTRY_STRUCT*)(ptr))->vlen)
#define DICT_GET_BYTES(ptr) (((DICT_ENTRY_STRUCT*)(ptr))->bytes)
#define DICT_GET_VALUE_SIZE(ptr) \
((((DICT_ENTRY_STRUCT*)(ptr))->bytes) - (((DICT_ENTRY_STRUCT*)(ptr))->klen))

/**************/
/* structures */
/**************/

#pragma member_alignment __save
#pragma member_alignment

typedef struct DictStruct DICT_STRUCT; 
typedef struct DictEntryStruct DICT_ENTRY_STRUCT; 

struct DictEntryStruct
{
    DICT_ENTRY_STRUCT *blink,
                      *clink,
                      *flink;
    DICT_STRUCT *DictPtr;
    uint bytes,
         extract,
         hash,
         klen,
         vlen;
    uchar *key,
          *value;
    uchar type[2];
    uchar buffer[];
};

struct DictStruct
{
    uint bytes,
         count,
         dirty,
         size,
         unique;
    REQUEST_STRUCT *RequestPtr;
    DICT_ENTRY_STRUCT *head,
                      *next,
                      *tail;
    DICT_ENTRY_STRUCT **table;
};

#pragma member_alignment __restore

/***********************/
/* function prototypes */
/***********************/

DICT_STRUCT* DictCreate (REQUEST_STRUCT*, int);
DICT_STRUCT* DictDestroy (DICT_STRUCT*);
DICT_STRUCT* DictDuplicate (REQUEST_STRUCT*, DICT_STRUCT*);
uint DictDirty (DICT_STRUCT*);
DICT_ENTRY_STRUCT* DictExpandEntry (DICT_ENTRY_STRUCT*, uint);
DICT_ENTRY_STRUCT* DictExtractEntry (DICT_ENTRY_STRUCT*);
DICT_ENTRY_STRUCT* DictInsert (DICT_STRUCT*, uchar*, uchar*, int, uchar*, int);
DICT_ENTRY_STRUCT* DictInsertEntry (DICT_STRUCT*, DICT_ENTRY_STRUCT*);
DICT_ENTRY_STRUCT* DictIterate (DICT_STRUCT*, uchar*);
DICT_ENTRY_STRUCT* DictLookup (DICT_STRUCT*, uchar*, uchar*, int);
DICT_ENTRY_STRUCT* DictRemove (DICT_STRUCT*, uchar*, uchar*, int);
DICT_ENTRY_STRUCT* DictRemoveEntry (DICT_ENTRY_STRUCT*);
void DictValueLength (DICT_ENTRY_STRUCT*, uint);
void DictWatch (DICT_STRUCT*, uchar*, uchar*);
void DictWatchEntry (DICT_ENTRY_STRUCT*);
void DictTest (char*);

#endif /* DICT_H_LOADED */

/*****************************************************************************/