|
|
| version 1.29, 2003/04/15 14:12:15 | version 1.30, 2003/04/15 14:30:14 |
|---|---|
| Line 282 static void _crypt(Request& r, const Str | Line 282 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; | |
| const char *format=upcase?"%02X":"%02x"; | |
| while(src<end) | |
| dest+=snprintf(dest, 3, format, *src++); | |
| return bytes_hex; | |
| } | |
| static void _md5(Request& r, const String& method_name, MethodParams *params) { | static void _md5(Request& r, const String& method_name, MethodParams *params) { |
| Pool& pool=r.pool(); | Pool& pool=r.pool(); |
| const char *string=params->as_string(0, "parameter must be string").cstr(); | const char *string=params->as_string(0, "parameter must be string").cstr(); |
| Line 293 static void _md5(Request& r, const Strin | Line 305 static void _md5(Request& r, const Strin |
| PA_MD5Update(&context, (const unsigned char*)string, strlen(string)); | PA_MD5Update(&context, (const unsigned char*)string, strlen(string)); |
| PA_MD5Final(digest, &context); | PA_MD5Final(digest, &context); |
| char *digest_bytes_hex=(char *)pool.malloc(sizeof(digest)*2/*byte->hh*/+1/*for zero-teminator*/); | r.write_pass_lang(*new(pool) String(pool, |
| unsigned char *src=digest; | hex_string(pool, digest, sizeof(digest), false))); |
| unsigned char *end=digest+sizeof(digest); | |
| char *dest=digest_bytes_hex; | |
| while(src<end) | |
| dest+=snprintf(dest, 3, "%02x", *src++); | |
| r.write_pass_lang(*new(pool) String(pool, digest_bytes_hex)); | |
| } | } |
| /// to hell with extra bytes on 64bit platforms | /// to hell with extra bytes on 64bit platforms |
| Line 347 static void _uuid(Request& r, const Stri | Line 353 static void _uuid(Request& r, const Stri |
| r.write_pass_lang(*new(pool) String(pool, uuid_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 | // constructor |
| MMath::MMath(Pool& apool) : Methoded(apool, "math") { | MMath::MMath(Pool& apool) : Methoded(apool, "math") { |
| Line 380 MMath::MMath(Pool& apool) : Methoded(apo | Line 396 MMath::MMath(Pool& apool) : Methoded(apo |
| // ^uuid[] | // ^uuid[] |
| ADD0(uuid); | ADD0(uuid); |
| // ^uid16[] | // ^uid64[] |
| //ADD0(uid16); | ADD0(uid64); |
| } | } |
| // global variables | // global variables |