|
|
| version 1.76, 2015/06/02 18:46:05 | version 1.82, 2016/07/21 17:05:37 |
|---|---|
| Line 1 | Line 1 |
| /** @file | /** @file |
| Parser: @b math parser class. | Parser: @b math parser class. |
| Copyright (c) 2001-2012 Art. Lebedev Studio (http://www.artlebedev.com) | Copyright (c) 2001-2015 Art. Lebedev Studio (http://www.artlebedev.com) |
| Author: Alexandr Petrosian <paf@design.ru>(http://paf.design.ru) | Author: Alexandr Petrosian <paf@design.ru>(http://paf.design.ru) |
| portions from gen_uuid.c, | portions from gen_uuid.c, |
| Line 31 volatile const char * IDENT_MATH_C="$Id$ | Line 31 volatile const char * IDENT_MATH_C="$Id$ |
| // class | // class |
| class MMath: public Methoded { | class MMath: public Methoded { |
| public: | |
| MMath(); | |
| public: // Methoded | public: // Methoded |
| bool used_directly() { return false; } | bool used_directly() { return false; } |
| public: | |
| MMath(); | |
| }; | }; |
| // global variables | // global variables |
| DECLARE_CLASS_VAR(math, 0 /*fictive*/, new MMath); | DECLARE_CLASS_VAR(math, new MMath); |
| // methods | // methods |
| Line 112 static void math2(Request& r, MethodPara | Line 112 static void math2(Request& r, MethodPara |
| MATH2(pow) | MATH2(pow) |
| inline bool is_salt_body_char(int c) { | inline bool is_salt_body_char(unsigned char c) { |
| return pa_isalnum(c) || c == '.' || c=='/'; | return pa_isalnum(c) || c == '.' || c=='/'; |
| } | } |
| static size_t calc_prefix_size(const char* salt) { | static size_t calc_prefix_size(const char* salt) { |
| if(strlen(salt)) { | if(strlen(salt)) { |
| if(!is_salt_body_char((unsigned char)salt[0])) { // $... {... | if(!is_salt_body_char((unsigned char)salt[0])) { // $... {... |
| Line 479 static void _digest(Request& r, MethodPa | Line 480 static void _digest(Request& r, MethodPa |
| } | } |
| static void _uuid(Request& r, MethodParams& /*params*/) { | static void _uuid(Request& r, MethodParams& /*params*/) { |
| uuid uuid=get_uuid(); | r.write_pass_lang(*new String(get_uuid_cstr())); |
| const size_t bufsize=36+1/*zero-teminator*/+1/*for faulty snprintfs*/; | |
| char* cstr=new(PointerFreeGC) char[bufsize]; | |
| snprintf(cstr, bufsize, | |
| "%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X", | |
| uuid.time_low, uuid.time_mid, uuid.time_hi_and_version, | |
| uuid.clock_seq >> 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 String(cstr)); | |
| } | } |
| static void _uid64(Request& r, MethodParams& /*params*/) { | static void _uid64(Request& r, MethodParams& /*params*/) { |
| unsigned char id[64/8]; | unsigned char id[64/8]; |
| random(&id, sizeof(id)); | random(&id, sizeof(id)); |
| Line 507 static void _crc32(Request& r, MethodPar | Line 495 static void _crc32(Request& r, MethodPar |
| r.write_no_lang(*new VInt(pa_crc32(string, strlen(string)))); | r.write_no_lang(*new VInt(pa_crc32(string, strlen(string)))); |
| } | } |
| static void toBase(unsigned int value, unsigned int base, char*& ptr){ | static void toBase(unsigned long long int value, unsigned int base, char*& ptr){ |
| static const char* hex="0123456789ABCDEF"; | static const char* hex="0123456789ABCDEF"; |
| int rest = value % base; | unsigned int rest = (unsigned int)(value % base); |
| if(value >= base) | if(value >= base) |
| toBase( (value-rest)/base, base, ptr); | toBase( (value-rest)/base, base, ptr); |
| *ptr++=(char)hex[rest]; | *ptr++=(char)hex[rest]; |
| Line 540 static void _convert(Request& r, MethodP | Line 528 static void _convert(Request& r, MethodP |
| str++; | str++; |
| } | } |
| unsigned int value=pa_atoui(str, base_from); | unsigned long long int value=pa_atoul(str, base_from); |
| char result_cstr[sizeof(unsigned int)*8+1/*minus for negative number*/+1/*terminator*/]; | char result_cstr[sizeof(unsigned long long int)*8+1/*minus for negative number*/+1/*terminator*/]; |
| char* ptr=result_cstr; | char* ptr=result_cstr; |
| if(negative) | if(negative) |
| *ptr++='-'; | *ptr++='-'; |