--- parser3/src/classes/math.C 2003/04/15 11:34:03 1.28 +++ parser3/src/classes/math.C 2003/07/24 06:49:22 1.33 @@ -8,7 +8,7 @@ Copyright (C) 1996, 1997, 1998, 1999 Theodore Ts'o. */ -static const char* IDENT_MATH_C="$Date: 2003/04/15 11:34:03 $"; +static const char* IDENT_MATH_C="$Date: 2003/07/24 06:49:22 $"; #include "pa_common.h" #include "pa_vint.h" @@ -148,7 +148,7 @@ static void random(void *buffer, size_t static inline int _random(uint top) { uint raw; random(&raw, sizeof(raw)); - return int(double(raw) / 0x100000000 * top ); + return int(double(raw) / 0xFFFFFFFFu * top ); } static void _random(Request& r, const String& method_name, MethodParams *params) { Pool& pool=r.pool(); @@ -282,6 +282,24 @@ static void _crypt(Request& r, const Str } } +static const char* hex_string(Pool& pool, unsigned char* bytes, size_t size, bool upcase) { + char *bytes_hex=(char *)pool.malloc(size*2/*byte->hh*/+1/*for zero-teminator*/); + unsigned char *src=bytes; + unsigned char *end=bytes+size; + char *dest=bytes_hex; + + static const char *hex=upcase?"0123456789ABCDEF":"0123456789abcdef"; + + const char *format=upcase?"%02X":"%02x"; + for(; srcas_string(0, "parameter must be string").cstr(); @@ -293,14 +311,8 @@ static void _md5(Request& r, const Strin PA_MD5Update(&context, (const unsigned char*)string, strlen(string)); PA_MD5Final(digest, &context); - char *digest_bytes_hex=(char *)pool.malloc(sizeof(digest)*2/*byte->hh*/+1/*for zero-teminator*/); - unsigned char *src=digest; - unsigned char *end=digest+sizeof(digest); - char *dest=digest_bytes_hex; - while(src> 8, uuid.clock_seq & 0xFF, uuid.node[0], uuid.node[1], uuid.node[2], uuid.node[3], uuid.node[4], uuid.node[5]); - r.write_pass_lang(*new(pool) String(pool, guid_cstr)); + r.write_pass_lang(*new(pool) String(pool, uuid_cstr)); +} + +static void _uid64(Request& r, const String& method_name, MethodParams *params) { + Pool& pool=r.pool(); + + unsigned char id[64/8]; + random(&id, sizeof(id)); + + r.write_pass_lang(*new(pool) String(pool, + hex_string(pool, id, sizeof(id), true))); } // constructor @@ -377,8 +399,11 @@ MMath::MMath(Pool& apool) : Methoded(apo // ^md5[string] ADD1(md5); - // ^guid[] - ADD0(guid); + // ^uuid[] + ADD0(uuid); + + // ^uid64[] + ADD0(uid64); } // global variables