|
|
| version 1.29, 2003/04/15 14:12:15 | version 1.32, 2003/05/26 09:32:29 |
|---|---|
| Line 148 static void random(void *buffer, size_t | Line 148 static void random(void *buffer, size_t |
| static inline int _random(uint top) { | static inline int _random(uint top) { |
| uint raw; | uint raw; |
| random(&raw, sizeof(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) { | static void _random(Request& r, const String& method_name, MethodParams *params) { |
| Pool& pool=r.pool(); | Pool& pool=r.pool(); |
| 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; | |
| static const char *hex=upcase?"0123456789ABCDEF":"0123456789abcdef"; | |
| const char *format=upcase?"%02X":"%02x"; | |
| for(; src<end; src++) { | |
| *dest++=hex[*src/0x10]; | |
| *dest++=hex[*src%0x10]; | |
| } | |
| *dest=0; | |
| 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 311 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 359 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 402 MMath::MMath(Pool& apool) : Methoded(apo |
| // ^uuid[] | // ^uuid[] |
| ADD0(uuid); | ADD0(uuid); |
| // ^uid16[] | // ^uid64[] |
| //ADD0(uid16); | ADD0(uid64); |
| } | } |
| // global variables | // global variables |