|
|
| version 1.41, 2005/08/26 11:12:45 | version 1.45, 2007/04/23 10:30:09 |
|---|---|
| Line 166 static inline int _random(uint top) { | Line 166 static inline int _random(uint top) { |
| static void _random(Request& r, MethodParams& params) { | static void _random(Request& r, MethodParams& params) { |
| double top=params.as_double(0, "range must be expression", r); | double top=params.as_double(0, "range must be expression", r); |
| if(top<=0 || top>MAX_UINT) | if(top<=0 || top>MAX_UINT) |
| throw Exception("parser.runtime", | throw Exception(PARSER_RUNTIME, |
| 0, | 0, |
| "top(%g) must be [1..%u]", top, MAX_UINT); | "top(%g) must be [1..%u]", top, MAX_UINT); |
| Line 268 static void _crypt(Request& r, MethodPar | Line 268 static void _crypt(Request& r, MethodPar |
| if(!static_sample_buf // nothing generated | if(!static_sample_buf // nothing generated |
| || !static_sample_buf[0] // generated nothing | || !static_sample_buf[0] // generated nothing |
| || strncmp(static_sample_buf, normal_salt, prefix_size)!=0) // salt prefix not preserved | || strncmp(static_sample_buf, normal_salt, prefix_size)!=0) // salt prefix not preserved |
| throw Exception("parser.runtime", | throw Exception(PARSER_RUNTIME, |
| 0, | 0, |
| "crypt on this platform does not support '%.*s' salt prefix", prefix_size, normal_salt); | "crypt on this platform does not support '%.*s' salt prefix", prefix_size, normal_salt); |
| r.write_pass_lang(String(pa_strdup(static_sample_buf))); | r.write_pass_lang(String(pa_strdup(static_sample_buf))); |
| #else | #else |
| throw Exception("parser.runtime", | throw Exception(PARSER_RUNTIME, |
| 0, | 0, |
| "salt must start with '" PA_MD5PW_ID "'"); | "salt must start with '" PA_MD5PW_ID "'"); |
| #endif | #endif |
| } | } |
| } | } |
| static const char* hex_string(unsigned char* bytes, size_t size, bool upcase) { | |
| char *bytes_hex=new(PointerFreeGC) char [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"; | |
| for(; src<end; src++) { | |
| *dest++=hex[*src/0x10]; | |
| *dest++=hex[*src%0x10]; | |
| } | |
| *dest=0; | |
| return bytes_hex; | |
| } | |
| static void _md5(Request& r, MethodParams& params) { | static void _md5(Request& r, MethodParams& params) { |
| const char *string=params.as_string(0, "parameter must be string").cstr(); | const char *string=params.as_string(0, "parameter must be string").cstr(); |
| PA_MD5_CTX context; | PA_MD5_CTX context; |
| unsigned char digest[16]; | unsigned char digest[16]; |
| pa_MD5Init(&context); | pa_MD5Init(&context); |
| Line 362 static void _uid64(Request& r, MethodPar | Line 344 static void _uid64(Request& r, MethodPar |
| r.write_pass_lang(*new String(hex_string(id, sizeof(id), true))); | r.write_pass_lang(*new String(hex_string(id, sizeof(id), true))); |
| } | } |
| static void _crc32(Request& r, MethodParams& params) { | |
| const char *string=params.as_string(0, "parameter must be string").cstr(); | |
| r.write_no_lang(*new VInt(pa_crc32(string, strlen(string)))); | |
| } | |
| // constructor | // constructor |
| MMath::MMath(): Methoded("math") { | MMath::MMath(): Methoded("math") { |
| Line 392 MMath::MMath(): Methoded("math") { | Line 379 MMath::MMath(): Methoded("math") { |
| // ^md5[string] | // ^md5[string] |
| ADD1(md5); | ADD1(md5); |
| ADD1(crc32); | |
| // ^uuid[] | // ^uuid[] |
| ADD0(uuid); | ADD0(uuid); |