Replace tabs by spaces

This commit is contained in:
smallmodel 2025-02-28 18:11:09 +01:00
parent c1a66bf9e7
commit f89bfba5dc
No known key found for this signature in database
GPG key ID: 9F2D623CEDF08512
12 changed files with 1085 additions and 1052 deletions

View file

@ -20,30 +20,30 @@
#define DEF_GROWBY 8 #define DEF_GROWBY 8
#ifdef _NO_NOPORT_H_ #ifdef _NO_NOPORT_H_
#define gsimalloc malloc #define gsimalloc malloc
#define gsifree free #define gsifree free
#define gsirealloc realloc #define gsirealloc realloc
#include "common/gsAssert.h" #include "common/gsAssert.h"
#else #else
#include "nonport.h" //for gsimalloc/realloc/free/GS_ASSERT #include "nonport.h" //for gsimalloc/realloc/free/GS_ASSERT
#endif #endif
// STRUCTURES // STRUCTURES
struct DArrayImplementation struct DArrayImplementation
{ {
int count, capacity; int count, capacity;
int elemsize; int elemsize;
int growby; int growby;
ArrayElementFreeFn elemfreefn; ArrayElementFreeFn elemfreefn;
void *list; //array of elements void *list; //array of elements
}; };
// PROTOTYPES // PROTOTYPES
static void *mylsearch(const void *key, void *base, int count, int size, static void *mylsearch(const void *key, void *base, int count, int size,
ArrayCompareFn comparator); ArrayCompareFn comparator);
static void *mybsearch(const void *elem, void *base, int num, int elemsize, static void *mybsearch(const void *elem, void *base, int num, int elemsize,
ArrayCompareFn comparator, int *found); ArrayCompareFn comparator, int *found);
// FUNCTIONS // FUNCTIONS
/* FreeElement /* FreeElement
@ -51,8 +51,8 @@ static void *mybsearch(const void *elem, void *base, int num, int elemsize,
*/ */
static void FreeElement(DArray array, int n) static void FreeElement(DArray array, int n)
{ {
if (array->elemfreefn != NULL) if (array->elemfreefn != NULL)
array->elemfreefn(ArrayNth(array,n)); array->elemfreefn(ArrayNth(array,n));
} }
/* ArrayGrow /* ArrayGrow
@ -60,10 +60,10 @@ static void FreeElement(DArray array, int n)
*/ */
static void ArrayGrow(DArray array) static void ArrayGrow(DArray array)
{ {
GS_ASSERT(array->elemsize) // sanity check -mj Oct 31st GS_ASSERT(array->elemsize) // sanity check -mj Oct 31st
array->capacity += array->growby; array->capacity += array->growby;
array->list = gsirealloc(array->list, (size_t) array->capacity * array->elemsize); array->list = gsirealloc(array->list, (size_t) array->capacity * array->elemsize);
GS_ASSERT(array->list); GS_ASSERT(array->list);
} }
/* SetElement /* SetElement
@ -71,94 +71,94 @@ static void ArrayGrow(DArray array)
*/ */
static void SetElement(DArray array, const void *elem, int pos) static void SetElement(DArray array, const void *elem, int pos)
{ {
GS_ASSERT(array) // safety check -mj Oct 31st GS_ASSERT(array) // safety check -mj Oct 31st
GS_ASSERT(elem) GS_ASSERT(elem)
GS_ASSERT(array->elemsize) GS_ASSERT(array->elemsize)
memcpy(ArrayNth(array,pos), elem, (size_t)array->elemsize); memcpy(ArrayNth(array,pos), elem, (size_t)array->elemsize);
} }
DArray ArrayNew(int elemSize, int numElemsToAllocate, DArray ArrayNew(int elemSize, int numElemsToAllocate,
ArrayElementFreeFn elemFreeFn) ArrayElementFreeFn elemFreeFn)
{ {
DArray array; DArray array;
array = (DArray) gsimalloc(sizeof(struct DArrayImplementation)); array = (DArray) gsimalloc(sizeof(struct DArrayImplementation));
GS_ASSERT(array); GS_ASSERT(array);
GS_ASSERT(elemSize); GS_ASSERT(elemSize);
if (numElemsToAllocate == 0) if (numElemsToAllocate == 0)
numElemsToAllocate = DEF_GROWBY; numElemsToAllocate = DEF_GROWBY;
array->count = 0; array->count = 0;
array->capacity = numElemsToAllocate;; array->capacity = numElemsToAllocate;;
array->elemsize = elemSize; array->elemsize = elemSize;
array->growby = numElemsToAllocate; array->growby = numElemsToAllocate;
array->elemfreefn = elemFreeFn; array->elemfreefn = elemFreeFn;
if (array->capacity != 0) if (array->capacity != 0)
{ {
array->list = gsimalloc((size_t)array->capacity * array->elemsize); array->list = gsimalloc((size_t)array->capacity * array->elemsize);
GS_ASSERT(array->list); GS_ASSERT(array->list);
} else } else
array->list = NULL; array->list = NULL;
return array; return array;
} }
void ArrayFree(DArray array) void ArrayFree(DArray array)
{ {
int i; int i;
GS_ASSERT(array); GS_ASSERT(array);
for (i = 0; i < array->count; i++) for (i = 0; i < array->count; i++)
{ {
FreeElement(array, i); FreeElement(array, i);
} }
// mj to do: move these asserts into gsi_free. maybe, depends on whether user overloads them // mj to do: move these asserts into gsi_free. maybe, depends on whether user overloads them
GS_ASSERT(array->list) GS_ASSERT(array->list)
GS_ASSERT(array) GS_ASSERT(array)
gsifree(array->list); gsifree(array->list);
gsifree(array); gsifree(array);
} }
void *ArrayGetDataPtr(DArray array) void *ArrayGetDataPtr(DArray array)
{ {
GS_ASSERT(array); GS_ASSERT(array);
return array->list; return array->list;
} }
void ArraySetDataPtr(DArray array, void *ptr, int count, int capacity) void ArraySetDataPtr(DArray array, void *ptr, int count, int capacity)
{ {
int i; int i;
GS_ASSERT(array); GS_ASSERT(array);
if (array->list != NULL) if (array->list != NULL)
{ {
for (i = 0; i < array->count; i++) for (i = 0; i < array->count; i++)
{ {
FreeElement(array, i); FreeElement(array, i);
} }
gsifree(array->list); gsifree(array->list);
} }
array->list = ptr; array->list = ptr;
array->count = count; array->count = count;
array->capacity = capacity; array->capacity = capacity;
} }
int ArrayLength(const DArray array) int ArrayLength(const DArray array)
{ {
GS_ASSERT(array) GS_ASSERT(array)
return array->count; return array->count;
} }
void *ArrayNth(DArray array, int n) void *ArrayNth(DArray array, int n)
{ {
// 2004.Nov.16.JED - modified GS_ASSERT to include "if" to add robustness // 2004.Nov.16.JED - modified GS_ASSERT to include "if" to add robustness
GS_ASSERT( (n >= 0) && (n < array->count)); GS_ASSERT( (n >= 0) && (n < array->count));
if( ! ((n >= 0) && (n < array->count)) ) if( ! ((n >= 0) && (n < array->count)) )
return NULL; return NULL;
return (char *)array->list + array->elemsize*n; return (char *)array->list + array->elemsize*n;
} }
/* ArrayAppend /* ArrayAppend
@ -166,166 +166,166 @@ void *ArrayNth(DArray array, int n)
*/ */
void ArrayAppend(DArray array, const void *newElem) void ArrayAppend(DArray array, const void *newElem)
{ {
GS_ASSERT(array); GS_ASSERT(array);
if(array) if(array)
ArrayInsertAt(array, newElem, array->count); ArrayInsertAt(array, newElem, array->count);
} }
void ArrayInsertAt(DArray array, const void *newElem, int n) void ArrayInsertAt(DArray array, const void *newElem, int n)
{ {
GS_ASSERT (array) GS_ASSERT (array)
GS_ASSERT ( (n >= 0) && (n <= array->count)); GS_ASSERT ( (n >= 0) && (n <= array->count));
if (array->count == array->capacity) if (array->count == array->capacity)
ArrayGrow(array); ArrayGrow(array);
array->count++; array->count++;
if (n < array->count - 1) //if we aren't appending if (n < array->count - 1) //if we aren't appending
memmove(ArrayNth(array, n+1), ArrayNth(array,n), memmove(ArrayNth(array, n+1), ArrayNth(array,n),
(size_t)(array->count - 1 - n) * array->elemsize); (size_t)(array->count - 1 - n) * array->elemsize);
SetElement(array, newElem, n); SetElement(array, newElem, n);
} }
void ArrayInsertSorted(DArray array, const void *newElem, ArrayCompareFn comparator) void ArrayInsertSorted(DArray array, const void *newElem, ArrayCompareFn comparator)
{ {
int n; int n;
void *res; void *res;
int found; int found;
GS_ASSERT (array) GS_ASSERT (array)
GS_ASSERT (comparator); GS_ASSERT (comparator);
res=mybsearch(newElem, array->list, array->count, array->elemsize, comparator, &found); res=mybsearch(newElem, array->list, array->count, array->elemsize, comparator, &found);
n = (((char *)res - (char *)array->list) / array->elemsize); n = (((char *)res - (char *)array->list) / array->elemsize);
ArrayInsertAt(array, newElem, n); ArrayInsertAt(array, newElem, n);
} }
void ArrayRemoveAt(DArray array, int n) void ArrayRemoveAt(DArray array, int n)
{ {
GS_ASSERT (array) GS_ASSERT (array)
GS_ASSERT( (n >= 0) && (n < array->count)); GS_ASSERT( (n >= 0) && (n < array->count));
if (n < array->count - 1) //if not last element if (n < array->count - 1) //if not last element
memmove(ArrayNth(array,n),ArrayNth(array,n+1), memmove(ArrayNth(array,n),ArrayNth(array,n+1),
(size_t)(array->count - 1 - n) * array->elemsize); (size_t)(array->count - 1 - n) * array->elemsize);
array->count--; array->count--;
} }
void ArrayDeleteAt(DArray array, int n) void ArrayDeleteAt(DArray array, int n)
{ {
GS_ASSERT (array) GS_ASSERT (array)
GS_ASSERT ( (n >= 0) && (n < array->count)); GS_ASSERT ( (n >= 0) && (n < array->count));
FreeElement(array,n); FreeElement(array,n);
ArrayRemoveAt(array, n); ArrayRemoveAt(array, n);
} }
void ArrayReplaceAt(DArray array, const void *newElem, int n) void ArrayReplaceAt(DArray array, const void *newElem, int n)
{ {
GS_ASSERT (array) GS_ASSERT (array)
GS_ASSERT ( (n >= 0) && (n < array->count)); GS_ASSERT ( (n >= 0) && (n < array->count));
FreeElement(array, n); FreeElement(array, n);
SetElement(array, newElem,n); SetElement(array, newElem,n);
} }
void ArraySort(DArray array, ArrayCompareFn comparator) void ArraySort(DArray array, ArrayCompareFn comparator)
{ {
GS_ASSERT (array) GS_ASSERT (array)
qsort(array->list, (size_t)array->count, (size_t)array->elemsize, comparator); qsort(array->list, (size_t)array->count, (size_t)array->elemsize, comparator);
} }
//GS_ASSERT will be raised by ArrayNth if fromindex out of range //GS_ASSERT will be raised by ArrayNth if fromindex out of range
int ArraySearch(DArray array, const void *key, ArrayCompareFn comparator, int ArraySearch(DArray array, const void *key, ArrayCompareFn comparator,
int fromIndex, int isSorted) int fromIndex, int isSorted)
{ {
void *res; void *res;
int found = 1; int found = 1;
if (!array || array->count == 0) if (!array || array->count == 0)
return NOT_FOUND; return NOT_FOUND;
if (isSorted) if (isSorted)
res=mybsearch(key, ArrayNth(array,fromIndex), res=mybsearch(key, ArrayNth(array,fromIndex),
array->count - fromIndex, array->elemsize, comparator, &found); array->count - fromIndex, array->elemsize, comparator, &found);
else else
res=mylsearch(key, ArrayNth(array, fromIndex), res=mylsearch(key, ArrayNth(array, fromIndex),
array->count - fromIndex, array->elemsize, comparator); array->count - fromIndex, array->elemsize, comparator);
if (res != NULL && found) if (res != NULL && found)
return (((char *)res - (char *)array->list) / array->elemsize); return (((char *)res - (char *)array->list) / array->elemsize);
else else
return NOT_FOUND; return NOT_FOUND;
} }
void ArrayMap(DArray array, ArrayMapFn fn, void *clientData) void ArrayMap(DArray array, ArrayMapFn fn, void *clientData)
{ {
int i; int i;
GS_ASSERT (array) GS_ASSERT (array)
GS_ASSERT(fn); GS_ASSERT(fn);
for (i = 0; i < array->count; i++) for (i = 0; i < array->count; i++)
fn(ArrayNth(array,i), clientData); fn(ArrayNth(array,i), clientData);
} }
void ArrayMapBackwards(DArray array, ArrayMapFn fn, void *clientData) void ArrayMapBackwards(DArray array, ArrayMapFn fn, void *clientData)
{ {
int i; int i;
GS_ASSERT(fn); GS_ASSERT(fn);
for (i = (array->count - 1) ; i >= 0 ; i--) for (i = (array->count - 1) ; i >= 0 ; i--)
fn(ArrayNth(array,i), clientData); fn(ArrayNth(array,i), clientData);
} }
void * ArrayMap2(DArray array, ArrayMapFn2 fn, void *clientData) void * ArrayMap2(DArray array, ArrayMapFn2 fn, void *clientData)
{ {
int i; int i;
void * pcurr; void * pcurr;
GS_ASSERT(fn); GS_ASSERT(fn);
GS_ASSERT(clientData); GS_ASSERT(clientData);
for (i = 0; i < array->count; i++) for (i = 0; i < array->count; i++)
{ {
pcurr = ArrayNth(array,i); pcurr = ArrayNth(array,i);
if(!fn(pcurr, clientData)) if(!fn(pcurr, clientData))
return pcurr; return pcurr;
} }
return NULL; return NULL;
} }
void * ArrayMapBackwards2(DArray array, ArrayMapFn2 fn, void *clientData) void * ArrayMapBackwards2(DArray array, ArrayMapFn2 fn, void *clientData)
{ {
int i; int i;
void * pcurr; void * pcurr;
GS_ASSERT(fn); GS_ASSERT(fn);
GS_ASSERT(clientData); GS_ASSERT(clientData);
for (i = (array->count - 1) ; i >= 0 ; i--) for (i = (array->count - 1) ; i >= 0 ; i--)
{ {
pcurr = ArrayNth(array,i); pcurr = ArrayNth(array,i);
if(!fn(pcurr, clientData)) if(!fn(pcurr, clientData))
return pcurr; return pcurr;
} }
return NULL; return NULL;
} }
void ArrayClear(DArray array) void ArrayClear(DArray array)
{ {
int i; int i;
// This could be more optimal! // This could be more optimal!
////////////////////////////// //////////////////////////////
for(i = (ArrayLength(array) - 1) ; i >= 0 ; i--) for(i = (ArrayLength(array) - 1) ; i >= 0 ; i--)
ArrayDeleteAt(array, i); ArrayDeleteAt(array, i);
} }
/* mylsearch /* mylsearch
@ -333,17 +333,17 @@ void ArrayClear(DArray array)
* couldn't use lfind * couldn't use lfind
*/ */
static void *mylsearch(const void *key, void *base, int count, int size, static void *mylsearch(const void *key, void *base, int count, int size,
ArrayCompareFn comparator) ArrayCompareFn comparator)
{ {
int i; int i;
GS_ASSERT(key); GS_ASSERT(key);
GS_ASSERT(base); GS_ASSERT(base);
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
{ {
if (comparator(key, (char *)base + size*i) == 0) if (comparator(key, (char *)base + size*i) == 0)
return (char *)base + size*i; return (char *)base + size*i;
} }
return NULL; return NULL;
} }
/* mybsearch /* mybsearch
@ -351,27 +351,27 @@ static void *mylsearch(const void *key, void *base, int count, int size,
*/ */
static void *mybsearch(const void *elem, void *base, int num, int elemsize, ArrayCompareFn comparator, int *found) static void *mybsearch(const void *elem, void *base, int num, int elemsize, ArrayCompareFn comparator, int *found)
{ {
int L, H, I, C; int L, H, I, C;
GS_ASSERT(elem); GS_ASSERT(elem);
GS_ASSERT(base); GS_ASSERT(base);
GS_ASSERT(found); GS_ASSERT(found);
L = 0; L = 0;
H = num - 1; H = num - 1;
*found = 0; *found = 0;
while (L <= H) while (L <= H)
{ {
I = (L + H) >> 1; I = (L + H) >> 1;
C = comparator(((char *)base) + I * elemsize,elem); C = comparator(((char *)base) + I * elemsize,elem);
if (C == 0) if (C == 0)
*found = 1; *found = 1;
if (C < 0) if (C < 0)
L = I + 1; L = I + 1;
else else
{ {
H = I - 1; H = I - 1;
} }
} }
return ((char *)base) + L * elemsize; return ((char *)base) + L * elemsize;
} }

View file

@ -43,9 +43,9 @@ typedef struct DArrayImplementation *DArray;
* If the two elements are "equal", return 0. * If the two elements are "equal", return 0.
*/ */
#if defined(WIN32) #if defined(WIN32)
typedef int (__cdecl *ArrayCompareFn)(const void *elem1, const void *elem2); typedef int (__cdecl *ArrayCompareFn)(const void *elem1, const void *elem2);
#else #else
typedef int (*ArrayCompareFn)(const void *elem1, const void *elem2); typedef int (*ArrayCompareFn)(const void *elem1, const void *elem2);
#endif #endif

View file

@ -188,3 +188,36 @@ void crypt_docrypt(GCryptInfo *info, unsigned char *out, int len)
info->wordPtr++; info->wordPtr++;
} }
} }
int enctype2_encoder(unsigned char *secKey, unsigned char *data, int size)
{
GCryptInfo info = {0};
int i;
int header_size = 8;
// move the data and put it after the header
for (i = size - 1; i >= 0; i--) {
data[1 + header_size + i] = data[i];
}
// initialize the header
for (i = 0; i < header_size; i++) {
data[i + 1] = 0;
}
// initialize the crypt key
init_crypt_key(data + 1, header_size, &info);
for (i = 0; i < 6; i++) {
data[1 + header_size + size + i] = 0;
}
crypt_docrypt(&info, data + 1 + header_size, size + 6);
for (i = 0; secKey[i]; i++) {
data[i + 1] ^= secKey[i];
}
size += 1 + header_size + 6;
*data = header_size ^ 0xec;
return size;
}

View file

@ -13,17 +13,17 @@ Fax(714)549-0757
****** ******
Updated 10-15-99 (BGW) Updated 10-15-99 (BGW)
Modified ServerParseKeyVals to actually parse and store empty Modified ServerParseKeyVals to actually parse and store empty
values for keys (i.e. "\delete\\" adds key="delete" and value="") values for keys (i.e. "\delete\\" adds key="delete" and value="")
Updated 6-17-99 (DDW) Updated 6-17-99 (DDW)
Added new tokenize function to handle empty values for keys Added new tokenize function to handle empty values for keys
*******/ *******/
#if defined(applec) || defined(THINK_C) || defined(__MWERKS__) && !defined(__KATANA__) #if defined(applec) || defined(THINK_C) || defined(__MWERKS__) && !defined(__KATANA__)
#include "::nonport.h" #include "::nonport.h"
#else #else
#include "../nonport.h" #include "../nonport.h"
#endif #endif
#include "goaceng.h" #include "goaceng.h"
#include "gserver.h" #include "gserver.h"
@ -43,11 +43,11 @@ static char *LookupKey(GServer server, char *k);
void ServerFree(void *elem) void ServerFree(void *elem)
{ {
//free a server! //free a server!
GServer server = *(GServer *)elem; GServer server = *(GServer *)elem;
TableFree(server->keyvals); TableFree(server->keyvals);
free(server); free(server);
} }
static void ServerSetAddressFromString (GServer server, char *address) static void ServerSetAddressFromString (GServer server, char *address)
@ -106,107 +106,107 @@ GServer ServerNewData(char **fieldlist, int fieldcount, char *serverdata, GQuery
GServer ServerNew(unsigned long ip, unsigned short port, GQueryType qtype, HashTable keylist) GServer ServerNew(unsigned long ip, unsigned short port, GQueryType qtype, HashTable keylist)
{ {
GServer server; GServer server;
int nBuckets, nChains; int nBuckets, nChains;
server = malloc(sizeof(struct GServerImplementation)); server = malloc(sizeof(struct GServerImplementation));
server->ip = ip; server->ip = ip;
server->port = port; server->port = port;
server->ping = 9999; server->ping = 9999;
server->querytype = qtype; server->querytype = qtype;
/* optimize the number of buckets / chains based on query type */ /* optimize the number of buckets / chains based on query type */
switch (qtype) switch (qtype)
{ {
case qt_basic: case qt_basic:
nBuckets = 4; nBuckets = 4;
nChains = 2; nChains = 2;
break; break;
case qt_info: case qt_info:
nBuckets = 6; nBuckets = 6;
nChains = 2; nChains = 2;
break; break;
case qt_players: case qt_players:
case qt_rules: case qt_rules:
nBuckets = 8; nBuckets = 8;
nChains = 2; nChains = 2;
break; break;
case qt_info_rules: case qt_info_rules:
case qt_status: case qt_status:
default: default:
nBuckets = 8; nBuckets = 8;
nChains= 4; nChains= 4;
break; break;
} }
server->keyvals = TableNew2(sizeof(GKeyValuePair),nBuckets,nChains, KeyValHashKeyP, KeyValCompareKeyP, NULL); server->keyvals = TableNew2(sizeof(GKeyValuePair),nBuckets,nChains, KeyValHashKeyP, KeyValCompareKeyP, NULL);
server->keylist = keylist; server->keylist = keylist;
return server; return server;
} }
static char *mytok(char *instr, char delim) static char *mytok(char *instr, char delim)
{ {
char *result; char *result;
static char *thestr; static char *thestr;
if (instr) if (instr)
thestr = instr; thestr = instr;
result=thestr; result=thestr;
while (*thestr && *thestr != delim) while (*thestr && *thestr != delim)
{ {
thestr++; thestr++;
} }
if (thestr == result) if (thestr == result)
result = NULL; result = NULL;
if (*thestr) //not the null term if (*thestr) //not the null term
*thestr++ = '\0'; *thestr++ = '\0';
return result; return result;
} }
static int CheckValidKey(char *key) static int CheckValidKey(char *key)
{ {
const char *InvalidKeys[]={"queryid","final"}; const char *InvalidKeys[]={"queryid","final"};
int i; int i;
for (i = 0; i < sizeof(InvalidKeys)/sizeof(InvalidKeys[0]); i++) for (i = 0; i < sizeof(InvalidKeys)/sizeof(InvalidKeys[0]); i++)
{ {
if (strcmp(key,InvalidKeys[i]) == 0) if (strcmp(key,InvalidKeys[i]) == 0)
return 0; return 0;
} }
return 1; return 1;
} }
static char *LookupKey(GServer server, char *k) static char *LookupKey(GServer server, char *k)
{ {
char **keyindex; char **keyindex;
keyindex = (char **)TableLookup(server->keylist,&k); keyindex = (char **)TableLookup(server->keylist,&k);
if (keyindex != NULL) if (keyindex != NULL)
return *keyindex; return *keyindex;
k = strdup(k); k = strdup(k);
TableEnter(server->keylist,&k); TableEnter(server->keylist,&k);
return k; return k;
} }
void ServerParseKeyVals(GServer server, char *keyvals) void ServerParseKeyVals(GServer server, char *keyvals)
{ {
char *k, *v; char *k, *v;
GKeyValuePair kvpair; GKeyValuePair kvpair;
k = mytok(++keyvals,'\\'); //skip over starting backslash k = mytok(++keyvals,'\\'); //skip over starting backslash
while (k != NULL) while (k != NULL)
{ {
v = mytok(NULL,'\\'); v = mytok(NULL,'\\');
if (v == NULL) if (v == NULL)
v = ""; v = "";
if (CheckValidKey(k)) if (CheckValidKey(k))
{ {
kvpair.key = LookupKey(server, k); kvpair.key = LookupKey(server, k);
kvpair.value = LookupKey(server, v); kvpair.value = LookupKey(server, v);
TableEnter(server->keyvals, &kvpair); TableEnter(server->keyvals, &kvpair);
} }
k = mytok(NULL,'\\'); k = mytok(NULL,'\\');
} }
} }
@ -215,7 +215,7 @@ void ServerParseKeyVals(GServer server, char *keyvals)
Returns the ping for the specified server. */ Returns the ping for the specified server. */
int ServerGetPing(GServer server) int ServerGetPing(GServer server)
{ {
return server->ping; return server->ping;
} }
/* ServerGetAddress /* ServerGetAddress
@ -223,7 +223,7 @@ int ServerGetPing(GServer server)
Returns the string, dotted IP address for the specified server */ Returns the string, dotted IP address for the specified server */
char *ServerGetAddress(GServer server) char *ServerGetAddress(GServer server)
{ {
return (char *)inet_ntoa(*(struct in_addr*)&server->ip); return (char *)inet_ntoa(*(struct in_addr*)&server->ip);
} }
/* ServerGetInetAddress /* ServerGetInetAddress
@ -231,7 +231,7 @@ char *ServerGetAddress(GServer server)
Returns the IP address for the specified server */ Returns the IP address for the specified server */
unsigned int ServerGetInetAddress(GServer server) unsigned int ServerGetInetAddress(GServer server)
{ {
return server->ip; return server->ip;
} }
@ -240,18 +240,18 @@ unsigned int ServerGetInetAddress(GServer server)
Returns the "query" port for the specified server. */ Returns the "query" port for the specified server. */
int ServerGetQueryPort(GServer server) int ServerGetQueryPort(GServer server)
{ {
return server->port; return server->port;
} }
static GKeyValuePair *ServerRuleLookup(GServer server, char *key) static GKeyValuePair *ServerRuleLookup(GServer server, char *key)
{ {
GKeyValuePair kvp; GKeyValuePair kvp;
char **keyindex; char **keyindex;
keyindex = (char **)TableLookup(server->keylist, &key); keyindex = (char **)TableLookup(server->keylist, &key);
if (keyindex == NULL) if (keyindex == NULL)
return NULL; //otherwise, the keyindex->keyindex is valid, so use it to lookup return NULL; //otherwise, the keyindex->keyindex is valid, so use it to lookup
kvp.key = *keyindex; kvp.key = *keyindex;
return (GKeyValuePair *)TableLookup(server->keyvals, &kvp); return (GKeyValuePair *)TableLookup(server->keyvals, &kvp);
} }
/* ServerGet[]Value /* ServerGet[]Value
@ -259,60 +259,60 @@ static GKeyValuePair *ServerRuleLookup(GServer server, char *key)
Returns the value for the specified key. */ Returns the value for the specified key. */
char *ServerGetStringValue(GServer server, char *key, char *sdefault) char *ServerGetStringValue(GServer server, char *key, char *sdefault)
{ {
GKeyValuePair *kv; GKeyValuePair *kv;
if (strcmp(key,"hostaddr") == 0) //ooh! they want the hostaddr! if (strcmp(key,"hostaddr") == 0) //ooh! they want the hostaddr!
return ServerGetAddress(server); return ServerGetAddress(server);
kv = ServerRuleLookup(server,key); kv = ServerRuleLookup(server,key);
if (!kv) if (!kv)
return sdefault; return sdefault;
return kv->value; return kv->value;
} }
int ServerGetIntValue(GServer server, char *key, int idefault) int ServerGetIntValue(GServer server, char *key, int idefault)
{ {
GKeyValuePair *kv; GKeyValuePair *kv;
if (strcmp(key,"ping") == 0) //ooh! they want the ping! if (strcmp(key,"ping") == 0) //ooh! they want the ping!
return ServerGetPing(server); return ServerGetPing(server);
kv = ServerRuleLookup(server,key); kv = ServerRuleLookup(server,key);
if (!kv) if (!kv)
return idefault; return idefault;
return atoi(kv->value); return atoi(kv->value);
} }
double ServerGetFloatValue(GServer server, char *key, double fdefault) double ServerGetFloatValue(GServer server, char *key, double fdefault)
{ {
GKeyValuePair *kv; GKeyValuePair *kv;
kv = ServerRuleLookup(server,key); kv = ServerRuleLookup(server,key);
if (!kv) if (!kv)
return fdefault; return fdefault;
return atof(kv->value); return atof(kv->value);
} }
char *ServerGetPlayerStringValue(GServer server, int playernum, char *key, char *sdefault) char *ServerGetPlayerStringValue(GServer server, int playernum, char *key, char *sdefault)
{ {
char newkey[32]; char newkey[32];
sprintf(newkey,"%s_%d",key,playernum); sprintf(newkey,"%s_%d",key,playernum);
return ServerGetStringValue(server, newkey, sdefault); return ServerGetStringValue(server, newkey, sdefault);
} }
int ServerGetPlayerIntValue(GServer server, int playernum, char *key, int idefault) int ServerGetPlayerIntValue(GServer server, int playernum, char *key, int idefault)
{ {
char newkey[32]; char newkey[32];
sprintf(newkey,"%s_%d",key,playernum); sprintf(newkey,"%s_%d",key,playernum);
return ServerGetIntValue(server, newkey, idefault); return ServerGetIntValue(server, newkey, idefault);
} }
double ServerGetPlayerFloatValue(GServer server, int playernum, char *key, double fdefault) double ServerGetPlayerFloatValue(GServer server, int playernum, char *key, double fdefault)
{ {
char newkey[32]; char newkey[32];
sprintf(newkey,"%s_%d",key,playernum); sprintf(newkey,"%s_%d",key,playernum);
return ServerGetFloatValue(server, newkey, fdefault); return ServerGetFloatValue(server, newkey, fdefault);
} }
@ -324,20 +324,20 @@ key/value. The user-defined instance data will be passed to the KeyFn callback *
static void KeyMapF(void *elem, void *clientData) static void KeyMapF(void *elem, void *clientData)
{ {
GKeyValuePair *kv = (GKeyValuePair *)elem; GKeyValuePair *kv = (GKeyValuePair *)elem;
GEnumData *ped = (GEnumData *)clientData; GEnumData *ped = (GEnumData *)clientData;
ped->EnumFn(kv->key, kv->value, ped->instance); ped->EnumFn(kv->key, kv->value, ped->instance);
} }
void ServerEnumKeys(GServer server, KeyEnumFn KeyFn, void *instance) void ServerEnumKeys(GServer server, KeyEnumFn KeyFn, void *instance)
{ {
GEnumData ed; GEnumData ed;
ed.EnumFn = KeyFn; ed.EnumFn = KeyFn;
ed.instance = instance; ed.instance = instance;
ed.keylist = server->keylist; ed.keylist = server->keylist;
TableMap(server->keyvals, KeyMapF, &ed); TableMap(server->keyvals, KeyMapF, &ed);
} }
@ -349,21 +349,21 @@ void ServerEnumKeys(GServer server, KeyEnumFn KeyFn, void *instance)
#define MULTIPLIER -1664117991 #define MULTIPLIER -1664117991
static int StringHash(char *s, int numbuckets) static int StringHash(char *s, int numbuckets)
{ {
unsigned long hashcode = 0; unsigned long hashcode = 0;
while (*s != 0) while (*s != 0)
hashcode = hashcode * MULTIPLIER + tolower(*s++); hashcode = hashcode * MULTIPLIER + tolower(*s++);
return (hashcode % numbuckets); return (hashcode % numbuckets);
} }
int GStringHash(const void *elem, int numbuckets) int GStringHash(const void *elem, int numbuckets)
{ {
return StringHash(*(char **)elem, numbuckets); return StringHash(*(char **)elem, numbuckets);
} }
static int KeyValHashKeyP(const void *elem, int numbuckets) static int KeyValHashKeyP(const void *elem, int numbuckets)
{ {
return StringHash(((GKeyValuePair *)elem)->key, numbuckets); return StringHash(((GKeyValuePair *)elem)->key, numbuckets);
} }
@ -384,12 +384,12 @@ int GCaseInsensitiveCompare(const void *entry1, const void *entry2)
*/ */
static int KeyValCompareKeyP(const void *entry1, const void *entry2) static int KeyValCompareKeyP(const void *entry1, const void *entry2)
{ {
return ((GKeyValuePair *)entry1)->key - ((GKeyValuePair *)entry2)->key; return ((GKeyValuePair *)entry1)->key - ((GKeyValuePair *)entry2)->key;
} }
void GStringFree(void *elem) void GStringFree(void *elem)
{ {
free(*(char **)elem); free(*(char **)elem);
} }
/* keyval /* keyval
@ -397,8 +397,8 @@ void GStringFree(void *elem)
* *
static int KeyValCompareKeyA(const void *entry1, const void *entry2) static int KeyValCompareKeyA(const void *entry1, const void *entry2)
{ {
return CaseInsensitiveCompare(&((GKeyValuePair *)entry1)->key, return CaseInsensitiveCompare(&((GKeyValuePair *)entry1)->key,
&((GKeyValuePair *)entry2)->key); &((GKeyValuePair *)entry2)->key);
} }
*/ */

View file

@ -27,38 +27,38 @@ extern "C" {
#endif #endif
#if defined(applec) || defined(THINK_C) || defined(__MWERKS__) && !defined(__KATANA__) #if defined(applec) || defined(THINK_C) || defined(__MWERKS__) && !defined(__KATANA__)
#include "::hashtable.h" #include "::hashtable.h"
#else #else
#include "../hashtable.h" #include "../hashtable.h"
#endif #endif
struct GServerImplementation struct GServerImplementation
{ {
unsigned long ip; unsigned long ip;
unsigned short port; unsigned short port;
short ping; short ping;
GQueryType querytype; GQueryType querytype;
HashTable keyvals; HashTable keyvals;
HashTable keylist; HashTable keylist;
}; };
typedef struct typedef struct
{ {
char *key; char *key;
char *value; char *value;
} GKeyValuePair; } GKeyValuePair;
/* /*
typedef struct typedef struct
{ {
char *key, *value; char *key, *value;
} GKeyValuePair; } GKeyValuePair;
*/ */
typedef struct typedef struct
{ {
KeyEnumFn EnumFn; KeyEnumFn EnumFn;
void *instance; void *instance;
HashTable keylist; HashTable keylist;
} GEnumData; } GEnumData;
void ServerFree(void *elem); void ServerFree(void *elem);

File diff suppressed because it is too large Load diff

View file

@ -18,68 +18,68 @@ typedef unsigned char uchar;
static void swap_byte(uchar* a, uchar* b) static void swap_byte(uchar* a, uchar* b)
{ {
uchar swapByte; uchar swapByte;
swapByte = *a; swapByte = *a;
*a = *b; *a = *b;
*b = swapByte; *b = swapByte;
} }
static uchar encode_ct(uchar c) static uchar encode_ct(uchar c)
{ {
if (c < 26) return (uchar)('A' + c); if (c < 26) return (uchar)('A' + c);
if (c < 52) return (uchar)('a' + c - 26); if (c < 52) return (uchar)('a' + c - 26);
if (c < 62) return (uchar)('0' + c - 52); if (c < 62) return (uchar)('0' + c - 52);
if (c == 62) return (uchar)('+'); if (c == 62) return (uchar)('+');
if (c == 63) return (uchar)('/'); if (c == 63) return (uchar)('/');
return 0; return 0;
} }
void gs_encode(uchar* ins, int size, uchar* result) void gs_encode(uchar* ins, int size, uchar* result)
{ {
int i, pos; int i, pos;
uchar trip[3]; uchar trip[3];
uchar kwart[4]; uchar kwart[4];
i = 0; i = 0;
while (i < size) while (i < size)
{ {
for (pos = 0; pos <= 2; pos++, i++) for (pos = 0; pos <= 2; pos++, i++)
if (i < size) trip[pos] = *ins++; if (i < size) trip[pos] = *ins++;
else trip[pos] = '\0'; else trip[pos] = '\0';
kwart[0] = (unsigned char)((trip[0]) >> 2); kwart[0] = (unsigned char)((trip[0]) >> 2);
kwart[1] = (unsigned char)((((trip[0]) & 3) << 4) + ((trip[1]) >> 4)); kwart[1] = (unsigned char)((((trip[0]) & 3) << 4) + ((trip[1]) >> 4));
kwart[2] = (unsigned char)((((trip[1]) & 15) << 2) + ((trip[2]) >> 6)); kwart[2] = (unsigned char)((((trip[1]) & 15) << 2) + ((trip[2]) >> 6));
kwart[3] = (unsigned char)((trip[2]) & 63); kwart[3] = (unsigned char)((trip[2]) & 63);
for (pos = 0; pos <= 3; pos++) *result++ = encode_ct(kwart[pos]); for (pos = 0; pos <= 3; pos++) *result++ = encode_ct(kwart[pos]);
} }
*result = '\0'; *result = '\0';
} }
void gs_encrypt(uchar* key, int key_len, uchar* buffer_ptr, int buffer_len) void gs_encrypt(uchar* key, int key_len, uchar* buffer_ptr, int buffer_len)
{ {
int counter; int counter;
uchar x, y, xorIndex; uchar x, y, xorIndex;
uchar state[256]; uchar state[256];
for (counter = 0; counter < 256; counter++) state[counter] = (uchar)counter; for (counter = 0; counter < 256; counter++) state[counter] = (uchar)counter;
x = 0; y = 0; x = 0; y = 0;
for (counter = 0; counter < 256; counter++) for (counter = 0; counter < 256; counter++)
{ {
y = (uchar)((key[x] + state[counter] + y) % 256); y = (uchar)((key[x] + state[counter] + y) % 256);
x = (uchar)((x + 1) % key_len); x = (uchar)((x + 1) % key_len);
swap_byte(&state[counter], &state[y]); swap_byte(&state[counter], &state[y]);
} }
x = 0; y = 0; x = 0; y = 0;
for (counter = 0; counter < buffer_len; counter++) for (counter = 0; counter < buffer_len; counter++)
{ {
x = (uchar)((x + buffer_ptr[counter] + 1) % 256); x = (uchar)((x + buffer_ptr[counter] + 1) % 256);
y = (uchar)((state[x] + y) % 256); y = (uchar)((state[x] + y) % 256);
swap_byte(&state[x], &state[y]); swap_byte(&state[x], &state[y]);
xorIndex = (uchar)((state[x] + state[y]) % 256); xorIndex = (uchar)((state[x] + state[y]) % 256);
buffer_ptr[counter] ^= state[xorIndex]; buffer_ptr[counter] ^= state[xorIndex];
} }
} }

View file

@ -27,7 +27,7 @@ size: size of the buffer
OUT OUT
--- ---
result: pointer to buffer to store result. Size should be (4 * size) / 3 + 1 result: pointer to buffer to store result. Size should be (4 * size) / 3 + 1
result will be null terminated. result will be null terminated.
**********/ **********/
void gs_encode(uchar* ins, int size, uchar* result); void gs_encode(uchar* ins, int size, uchar* result);

View file

@ -22,208 +22,208 @@
#ifdef _NO_NOPORT_H_ #ifdef _NO_NOPORT_H_
#define gsimalloc malloc #define gsimalloc malloc
#define gsifree free #define gsifree free
#define gsirealloc realloc #define gsirealloc realloc
#include <assert.h> #include <assert.h>
#else #else
#include "nonport.h" //for gsimalloc/realloc/free/assert #include "nonport.h" //for gsimalloc/realloc/free/assert
#endif #endif
struct HashImplementation struct HashImplementation
{ {
DArray *buckets; DArray *buckets;
int nbuckets; int nbuckets;
TableElementFreeFn freefn; TableElementFreeFn freefn;
TableHashFn hashfn; TableHashFn hashfn;
TableCompareFn compfn; TableCompareFn compfn;
}; };
HashTable TableNew(int elemSize, int nBuckets, HashTable TableNew(int elemSize, int nBuckets,
TableHashFn hashFn, TableCompareFn compFn, TableHashFn hashFn, TableCompareFn compFn,
TableElementFreeFn freeFn) TableElementFreeFn freeFn)
{ {
return TableNew2(elemSize, nBuckets, 4, hashFn, compFn, freeFn); return TableNew2(elemSize, nBuckets, 4, hashFn, compFn, freeFn);
} }
HashTable TableNew2(int elemSize, int nBuckets, int nChains, HashTable TableNew2(int elemSize, int nBuckets, int nChains,
TableHashFn hashFn, TableCompareFn compFn, TableHashFn hashFn, TableCompareFn compFn,
TableElementFreeFn freeFn) TableElementFreeFn freeFn)
{ {
HashTable table; HashTable table;
int i; int i;
assert(hashFn); assert(hashFn);
assert(compFn); assert(compFn);
assert(elemSize); assert(elemSize);
assert(nBuckets); assert(nBuckets);
table = (HashTable)gsimalloc(sizeof(struct HashImplementation)); table = (HashTable)gsimalloc(sizeof(struct HashImplementation));
assert(table); assert(table);
table->buckets = (DArray *)gsimalloc(nBuckets * sizeof(DArray)); table->buckets = (DArray *)gsimalloc(nBuckets * sizeof(DArray));
assert(table->buckets); assert(table->buckets);
for (i = 0; i < nBuckets; i++) //ArrayNew will assert if allocation fails for (i = 0; i < nBuckets; i++) //ArrayNew will assert if allocation fails
table->buckets[i] = ArrayNew(elemSize, nChains, freeFn); table->buckets[i] = ArrayNew(elemSize, nChains, freeFn);
table->nbuckets = nBuckets; table->nbuckets = nBuckets;
table->freefn = freeFn; table->freefn = freeFn;
table->compfn = compFn; table->compfn = compFn;
table->hashfn = hashFn; table->hashfn = hashFn;
return table; return table;
} }
void TableFree(HashTable table) void TableFree(HashTable table)
{ {
int i; int i;
assert(table); assert(table);
if (NULL == table ) if (NULL == table )
return; return;
for (i = 0 ; i < table->nbuckets ; i++) for (i = 0 ; i < table->nbuckets ; i++)
ArrayFree(table->buckets[i]); ArrayFree(table->buckets[i]);
gsifree(table->buckets); gsifree(table->buckets);
gsifree(table); gsifree(table);
} }
int TableCount(HashTable table) int TableCount(HashTable table)
{ {
int i, count = 0; int i, count = 0;
assert(table); assert(table);
if (NULL == table ) if (NULL == table )
return count; return count;
for (i = 0 ; i < table->nbuckets ; i++) for (i = 0 ; i < table->nbuckets ; i++)
count += ArrayLength(table->buckets[i]); count += ArrayLength(table->buckets[i]);
return count; return count;
} }
void TableEnter(HashTable table, const void *newElem) void TableEnter(HashTable table, const void *newElem)
{ {
int hash, itempos; int hash, itempos;
assert(table); assert(table);
if (NULL == table ) if (NULL == table )
return; return;
hash = table->hashfn(newElem, table->nbuckets); hash = table->hashfn(newElem, table->nbuckets);
itempos = ArraySearch(table->buckets[hash], newElem, table->compfn, 0,0); itempos = ArraySearch(table->buckets[hash], newElem, table->compfn, 0,0);
if (itempos == NOT_FOUND) if (itempos == NOT_FOUND)
ArrayAppend(table->buckets[hash], newElem); ArrayAppend(table->buckets[hash], newElem);
else else
ArrayReplaceAt(table->buckets[hash], newElem, itempos); ArrayReplaceAt(table->buckets[hash], newElem, itempos);
} }
int TableRemove(HashTable table, const void *delElem) int TableRemove(HashTable table, const void *delElem)
{ {
int hash, itempos; int hash, itempos;
assert(table); assert(table);
if (NULL == table ) if (NULL == table )
return 0; return 0;
hash = table->hashfn(delElem, table->nbuckets); hash = table->hashfn(delElem, table->nbuckets);
itempos = ArraySearch(table->buckets[hash], delElem, table->compfn, 0,0); itempos = ArraySearch(table->buckets[hash], delElem, table->compfn, 0,0);
if (itempos == NOT_FOUND) if (itempos == NOT_FOUND)
return 0; return 0;
else else
ArrayDeleteAt(table->buckets[hash], itempos); ArrayDeleteAt(table->buckets[hash], itempos);
return 1; return 1;
} }
void *TableLookup(HashTable table, const void *elemKey) void *TableLookup(HashTable table, const void *elemKey)
{ {
int hash, itempos; int hash, itempos;
assert(table); assert(table);
if (NULL == table ) if (NULL == table )
return NULL; return NULL;
hash = table->hashfn(elemKey, table->nbuckets); hash = table->hashfn(elemKey, table->nbuckets);
itempos = ArraySearch(table->buckets[hash], elemKey, table->compfn, 0, itempos = ArraySearch(table->buckets[hash], elemKey, table->compfn, 0,
0); 0);
if (itempos == NOT_FOUND) if (itempos == NOT_FOUND)
return NULL; return NULL;
else else
return ArrayNth(table->buckets[hash], itempos); return ArrayNth(table->buckets[hash], itempos);
} }
void TableMap(HashTable table, TableMapFn fn, void *clientData) void TableMap(HashTable table, TableMapFn fn, void *clientData)
{ {
int i; int i;
assert(table); assert(table);
assert(fn); assert(fn);
if (NULL == table || NULL == fn) if (NULL == table || NULL == fn)
return; return;
for (i = 0 ; i < table->nbuckets ; i++) for (i = 0 ; i < table->nbuckets ; i++)
ArrayMap(table->buckets[i], fn, clientData); ArrayMap(table->buckets[i], fn, clientData);
} }
void TableMapSafe(HashTable table, TableMapFn fn, void *clientData) void TableMapSafe(HashTable table, TableMapFn fn, void *clientData)
{ {
int i; int i;
assert(fn); assert(fn);
for (i = 0 ; i < table->nbuckets ; i++) for (i = 0 ; i < table->nbuckets ; i++)
ArrayMapBackwards(table->buckets[i], fn, clientData); ArrayMapBackwards(table->buckets[i], fn, clientData);
} }
void * TableMap2(HashTable table, TableMapFn2 fn, void *clientData) void * TableMap2(HashTable table, TableMapFn2 fn, void *clientData)
{ {
int i; int i;
void * pcurr; void * pcurr;
assert(fn); assert(fn);
for (i = 0 ; i < table->nbuckets ; i++) for (i = 0 ; i < table->nbuckets ; i++)
{ {
pcurr = ArrayMap2(table->buckets[i], fn, clientData); pcurr = ArrayMap2(table->buckets[i], fn, clientData);
if(pcurr) if(pcurr)
return pcurr; return pcurr;
} }
return NULL; return NULL;
} }
void * TableMapSafe2(HashTable table, TableMapFn2 fn, void *clientData) void * TableMapSafe2(HashTable table, TableMapFn2 fn, void *clientData)
{ {
int i; int i;
void * pcurr; void * pcurr;
assert(fn); assert(fn);
for (i = 0 ; i < table->nbuckets ; i++) for (i = 0 ; i < table->nbuckets ; i++)
{ {
pcurr = ArrayMapBackwards2(table->buckets[i], fn, clientData); pcurr = ArrayMapBackwards2(table->buckets[i], fn, clientData);
if(pcurr) if(pcurr)
return pcurr; return pcurr;
} }
return NULL; return NULL;
} }
void TableClear(HashTable table) void TableClear(HashTable table)
{ {
int i; int i;
for (i = 0 ; i < table->nbuckets ; i++) for (i = 0 ; i < table->nbuckets ; i++)
ArrayClear(table->buckets[i]); ArrayClear(table->buckets[i]);
} }

View file

@ -126,11 +126,11 @@ extern "C" {
HashTable TableNew(int elemSize, int nBuckets, HashTable TableNew(int elemSize, int nBuckets,
TableHashFn hashFn, TableCompareFn compFn, TableHashFn hashFn, TableCompareFn compFn,
TableElementFreeFn freeFn); TableElementFreeFn freeFn);
HashTable TableNew2(int elemSize, int nBuckets, int nChains, HashTable TableNew2(int elemSize, int nBuckets, int nChains,
TableHashFn hashFn, TableCompareFn compFn, TableHashFn hashFn, TableCompareFn compFn,
TableElementFreeFn freeFn); TableElementFreeFn freeFn);
/* TableFree /* TableFree

View file

@ -38,7 +38,7 @@ The following makes PROTOTYPES default to 0 if it has not already
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#ifndef PROTOTYPES #ifndef PROTOTYPES
#define PROTOTYPES 1 #define PROTOTYPES 1
#endif #endif

View file

@ -305,7 +305,7 @@ static void Decode (UINT4 *output, unsigned char *input, unsigned int len)
*/ */
static void MD5_memcpy (POINTER output, POINTER input, unsigned int len) static void MD5_memcpy (POINTER output, POINTER input, unsigned int len)
{ {
memcpy(output, input, len); memcpy(output, input, len);
/* unsigned int i; /* unsigned int i;
for (i = 0; i < len; i++) for (i = 0; i < len; i++)
@ -316,7 +316,7 @@ static void MD5_memcpy (POINTER output, POINTER input, unsigned int len)
*/ */
static void MD5_memset (POINTER output, int value, unsigned int len) static void MD5_memset (POINTER output, int value, unsigned int len)
{ {
memset(output, value, len); memset(output, value, len);
/* unsigned int i; /* unsigned int i;
for (i = 0; i < len; i++) for (i = 0; i < len; i++)
@ -327,26 +327,26 @@ static void MD5_memset (POINTER output, int value, unsigned int len)
void MD5Print (unsigned char digest[16], char output[33]) void MD5Print (unsigned char digest[16], char output[33])
{ {
static const char hex_digits[] = "0123456789abcdef"; static const char hex_digits[] = "0123456789abcdef";
unsigned int i; unsigned int i;
for (i = 0; i < 16; i++) for (i = 0; i < 16; i++)
{ {
output[i*2 ] = hex_digits[digest[i] / 16]; output[i*2 ] = hex_digits[digest[i] / 16];
output[i*2+1] = hex_digits[digest[i] % 16]; output[i*2+1] = hex_digits[digest[i] % 16];
} }
output[32] = '\0'; output[32] = '\0';
} }
void MD5Digest (unsigned char *input, unsigned int len, char output[33]) void MD5Digest (unsigned char *input, unsigned int len, char output[33])
{ {
MD5_CTX ctx; MD5_CTX ctx;
unsigned char digest[16]; unsigned char digest[16];
MD5Init(&ctx); MD5Init(&ctx);
MD5Update(&ctx, input, len); MD5Update(&ctx, input, len);
MD5Final(digest, &ctx); MD5Final(digest, &ctx);
MD5Print(digest, output); MD5Print(digest, output);
} }
#ifdef __cplusplus #ifdef __cplusplus