repo
stringlengths
1
152
file
stringlengths
14
221
code
stringlengths
501
25k
file_length
int64
501
25k
avg_line_length
float64
20
99.5
max_line_length
int64
21
134
extension_type
stringclasses
2 values
php-src
php-src-master/ext/hash/hash_ripemd.c
/* +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: Sara Golemon <[email protected]> | +----------------------------------------------------------------------+ */ /* Heavily borrowed from md5.c & sha1.c of PHP archival fame Note that ripemd laughs in the face of logic and uses little endian byte ordering */ #include "php_hash.h" #include "php_hash_ripemd.h" const php_hash_ops php_hash_ripemd128_ops = { "ripemd128", (php_hash_init_func_t) PHP_RIPEMD128Init, (php_hash_update_func_t) PHP_RIPEMD128Update, (php_hash_final_func_t) PHP_RIPEMD128Final, php_hash_copy, php_hash_serialize, php_hash_unserialize, PHP_RIPEMD128_SPEC, 16, 64, sizeof(PHP_RIPEMD128_CTX), 1 }; const php_hash_ops php_hash_ripemd160_ops = { "ripemd160", (php_hash_init_func_t) PHP_RIPEMD160Init, (php_hash_update_func_t) PHP_RIPEMD160Update, (php_hash_final_func_t) PHP_RIPEMD160Final, php_hash_copy, php_hash_serialize, php_hash_unserialize, PHP_RIPEMD160_SPEC, 20, 64, sizeof(PHP_RIPEMD160_CTX), 1 }; const php_hash_ops php_hash_ripemd256_ops = { "ripemd256", (php_hash_init_func_t) PHP_RIPEMD256Init, (php_hash_update_func_t) PHP_RIPEMD256Update, (php_hash_final_func_t) PHP_RIPEMD256Final, php_hash_copy, php_hash_serialize, php_hash_unserialize, PHP_RIPEMD256_SPEC, 32, 64, sizeof(PHP_RIPEMD256_CTX), 1 }; const php_hash_ops php_hash_ripemd320_ops = { "ripemd320", (php_hash_init_func_t) PHP_RIPEMD320Init, (php_hash_update_func_t) PHP_RIPEMD320Update, (php_hash_final_func_t) PHP_RIPEMD320Final, php_hash_copy, php_hash_serialize, php_hash_unserialize, PHP_RIPEMD320_SPEC, 40, 64, sizeof(PHP_RIPEMD320_CTX), 1 }; /* {{{ PHP_RIPEMD128Init * ripemd128 initialization. Begins a ripemd128 operation, writing a new context. */ PHP_HASH_API void PHP_RIPEMD128Init(PHP_RIPEMD128_CTX * context, ZEND_ATTRIBUTE_UNUSED HashTable *args) { context->count[0] = context->count[1] = 0; /* Load magic initialization constants. */ context->state[0] = 0x67452301; context->state[1] = 0xEFCDAB89; context->state[2] = 0x98BADCFE; context->state[3] = 0x10325476; } /* }}} */ /* {{{ PHP_RIPEMD256Init * ripemd256 initialization. Begins a ripemd256 operation, writing a new context. */ PHP_HASH_API void PHP_RIPEMD256Init(PHP_RIPEMD256_CTX * context, ZEND_ATTRIBUTE_UNUSED HashTable *args) { context->count[0] = context->count[1] = 0; /* Load magic initialization constants. */ context->state[0] = 0x67452301; context->state[1] = 0xEFCDAB89; context->state[2] = 0x98BADCFE; context->state[3] = 0x10325476; context->state[4] = 0x76543210; context->state[5] = 0xFEDCBA98; context->state[6] = 0x89ABCDEF; context->state[7] = 0x01234567; } /* }}} */ /* {{{ PHP_RIPEMD160Init * ripemd160 initialization. Begins a ripemd160 operation, writing a new context. */ PHP_HASH_API void PHP_RIPEMD160Init(PHP_RIPEMD160_CTX * context, ZEND_ATTRIBUTE_UNUSED HashTable *args) { context->count[0] = context->count[1] = 0; /* Load magic initialization constants. */ context->state[0] = 0x67452301; context->state[1] = 0xEFCDAB89; context->state[2] = 0x98BADCFE; context->state[3] = 0x10325476; context->state[4] = 0xC3D2E1F0; } /* }}} */ /* {{{ PHP_RIPEMD320Init * ripemd320 initialization. Begins a ripemd320 operation, writing a new context. */ PHP_HASH_API void PHP_RIPEMD320Init(PHP_RIPEMD320_CTX * context, ZEND_ATTRIBUTE_UNUSED HashTable *args) { context->count[0] = context->count[1] = 0; /* Load magic initialization constants. */ context->state[0] = 0x67452301; context->state[1] = 0xEFCDAB89; context->state[2] = 0x98BADCFE; context->state[3] = 0x10325476; context->state[4] = 0xC3D2E1F0; context->state[5] = 0x76543210; context->state[6] = 0xFEDCBA98; context->state[7] = 0x89ABCDEF; context->state[8] = 0x01234567; context->state[9] = 0x3C2D1E0F; } /* }}} */ /* Basic ripemd function */ #define F0(x,y,z) ((x) ^ (y) ^ (z)) #define F1(x,y,z) (((x) & (y)) | ((~(x)) & (z))) #define F2(x,y,z) (((x) | (~(y))) ^ (z)) #define F3(x,y,z) (((x) & (z)) | ((y) & (~(z)))) #define F4(x,y,z) ((x) ^ ((y) | (~(z)))) static const uint32_t K_values[5] = { 0x00000000, 0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xA953FD4E }; /* 128, 256, 160, 320 */ static const uint32_t KK_values[4] = { 0x50A28BE6, 0x5C4DD124, 0x6D703EF3, 0x00000000 }; /* 128 & 256 */ static const uint32_t KK160_values[5] = { 0x50A28BE6, 0x5C4DD124, 0x6D703EF3, 0x7A6D76E9, 0x00000000 }; /* 160 & 320 */ #define K(n) K_values[ (n) >> 4] #define KK(n) KK_values[(n) >> 4] #define KK160(n) KK160_values[(n) >> 4] static const unsigned char R[80] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8, 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12, 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2, 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13 }; static const unsigned char RR[80] = { 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12, 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2, 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13, 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14, 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11 }; static const unsigned char S[80] = { 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8, 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12, 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5, 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12, 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6 }; static const unsigned char SS[80] = { 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6, 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11, 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5, 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8, 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11 }; #define ROLS(j, x) (((x) << S[j]) | ((x) >> (32 - S[j]))) #define ROLSS(j, x) (((x) << SS[j]) | ((x) >> (32 - SS[j]))) #define ROL(n, x) (((x) << n) | ((x) >> (32 - n))) /* {{{ RIPEMDDecode Decodes input (unsigned char) into output (uint32_t). Assumes len is a multiple of 4. */ static void RIPEMDDecode(uint32_t *output, const unsigned char *input, unsigned int len) { unsigned int i, j; for (i = 0, j = 0; j < len; i++, j += 4) output[i] = ((uint32_t) input[j + 0]) | (((uint32_t) input[j + 1]) << 8) | (((uint32_t) input[j + 2]) << 16) | (((uint32_t) input[j + 3]) << 24); } /* }}} */ /* {{{ RIPEMD128Transform * ripemd128 basic transformation. Transforms state based on block. */ static void RIPEMD128Transform(uint32_t state[4], const unsigned char block[64]) { uint32_t a = state[0], b = state[1], c = state[2], d = state[3]; uint32_t aa = state[0], bb = state[1], cc = state[2], dd = state[3]; uint32_t tmp, x[16]; int j; RIPEMDDecode(x, block, 64); for(j = 0; j < 16; j++) { tmp = ROLS( j, a + F0(b, c, d) + x[R[j]] + K(j)); a = d; d = c; c = b; b = tmp; tmp = ROLSS(j, aa + F3(bb, cc, dd) + x[RR[j]] + KK(j)); aa = dd; dd = cc; cc = bb; bb = tmp; } for(j = 16; j < 32; j++) { tmp = ROLS( j, a + F1(b, c, d) + x[R[j]] + K(j)); a = d; d = c; c = b; b = tmp; tmp = ROLSS(j, aa + F2(bb, cc, dd) + x[RR[j]] + KK(j)); aa = dd; dd = cc; cc = bb; bb = tmp; } for(j = 32; j < 48; j++) { tmp = ROLS( j, a + F2(b, c, d) + x[R[j]] + K(j)); a = d; d = c; c = b; b = tmp; tmp = ROLSS(j, aa + F1(bb, cc, dd) + x[RR[j]] + KK(j)); aa = dd; dd = cc; cc = bb; bb = tmp; } for(j = 48; j < 64; j++) { tmp = ROLS( j, a + F3(b, c, d) + x[R[j]] + K(j)); a = d; d = c; c = b; b = tmp; tmp = ROLSS(j, aa + F0(bb, cc, dd) + x[RR[j]] + KK(j)); aa = dd; dd = cc; cc = bb; bb = tmp; } tmp = state[1] + c + dd; state[1] = state[2] + d + aa; state[2] = state[3] + a + bb; state[3] = state[0] + b + cc; state[0] = tmp; tmp = 0; ZEND_SECURE_ZERO(x, sizeof(x)); } /* }}} */ /* {{{ PHP_RIPEMD128Update ripemd128 block update operation. Continues a ripemd128 message-digest operation, processing another message block, and updating the context. */ PHP_HASH_API void PHP_RIPEMD128Update(PHP_RIPEMD128_CTX * context, const unsigned char *input, size_t inputLen) { unsigned int i, index, partLen; /* Compute number of bytes mod 64 */ index = (unsigned int) ((context->count[0] >> 3) & 0x3F); /* Update number of bits */ if ((context->count[0] += ((uint32_t) inputLen << 3)) < ((uint32_t) inputLen << 3)) { context->count[1]++; } context->count[1] += ((uint32_t) inputLen >> 29); partLen = 64 - index; /* Transform as many times as possible. */ if (inputLen >= partLen) { memcpy((unsigned char*) & context->buffer[index], (unsigned char*) input, partLen); RIPEMD128Transform(context->state, context->buffer); for (i = partLen; i + 63 < inputLen; i += 64) { RIPEMD128Transform(context->state, &input[i]); } index = 0; } else { i = 0; } /* Buffer remaining input */ memcpy((unsigned char*) & context->buffer[index], (unsigned char*) & input[i], inputLen - i); } /* }}} */ /* {{{ RIPEMD256Transform * ripemd256 basic transformation. Transforms state based on block. */ static void RIPEMD256Transform(uint32_t state[8], const unsigned char block[64]) { uint32_t a = state[0], b = state[1], c = state[2], d = state[3]; uint32_t aa = state[4], bb = state[5], cc = state[6], dd = state[7]; uint32_t tmp, x[16]; int j; RIPEMDDecode(x, block, 64); for(j = 0; j < 16; j++) { tmp = ROLS( j, a + F0(b, c, d) + x[R[j]] + K(j)); a = d; d = c; c = b; b = tmp; tmp = ROLSS(j, aa + F3(bb, cc, dd) + x[RR[j]] + KK(j)); aa = dd; dd = cc; cc = bb; bb = tmp; } tmp = a; a = aa; aa = tmp; for(j = 16; j < 32; j++) { tmp = ROLS( j, a + F1(b, c, d) + x[R[j]] + K(j)); a = d; d = c; c = b; b = tmp; tmp = ROLSS(j, aa + F2(bb, cc, dd) + x[RR[j]] + KK(j)); aa = dd; dd = cc; cc = bb; bb = tmp; } tmp = b; b = bb; bb = tmp; for(j = 32; j < 48; j++) { tmp = ROLS( j, a + F2(b, c, d) + x[R[j]] + K(j)); a = d; d = c; c = b; b = tmp; tmp = ROLSS(j, aa + F1(bb, cc, dd) + x[RR[j]] + KK(j)); aa = dd; dd = cc; cc = bb; bb = tmp; } tmp = c; c = cc; cc = tmp; for(j = 48; j < 64; j++) { tmp = ROLS( j, a + F3(b, c, d) + x[R[j]] + K(j)); a = d; d = c; c = b; b = tmp; tmp = ROLSS(j, aa + F0(bb, cc, dd) + x[RR[j]] + KK(j)); aa = dd; dd = cc; cc = bb; bb = tmp; } tmp = d; d = dd; dd = tmp; state[0] += a; state[1] += b; state[2] += c; state[3] += d; state[4] += aa; state[5] += bb; state[6] += cc; state[7] += dd; tmp = 0; ZEND_SECURE_ZERO(x, sizeof(x)); } /* }}} */ /* {{{ PHP_RIPEMD256Update ripemd256 block update operation. Continues a ripemd256 message-digest operation, processing another message block, and updating the context. */ PHP_HASH_API void PHP_RIPEMD256Update(PHP_RIPEMD256_CTX * context, const unsigned char *input, size_t inputLen) { unsigned int i, index, partLen; /* Compute number of bytes mod 64 */ index = (unsigned int) ((context->count[0] >> 3) & 0x3F); /* Update number of bits */ if ((context->count[0] += ((uint32_t) inputLen << 3)) < ((uint32_t) inputLen << 3)) { context->count[1]++; } context->count[1] += ((uint32_t) inputLen >> 29); partLen = 64 - index; /* Transform as many times as possible. */ if (inputLen >= partLen) { memcpy((unsigned char*) & context->buffer[index], (unsigned char*) input, partLen); RIPEMD256Transform(context->state, context->buffer); for (i = partLen; i + 63 < inputLen; i += 64) { RIPEMD256Transform(context->state, &input[i]); } index = 0; } else { i = 0; } /* Buffer remaining input */ memcpy((unsigned char*) & context->buffer[index], (unsigned char*) & input[i], inputLen - i); } /* }}} */ /* {{{ RIPEMD160Transform * ripemd160 basic transformation. Transforms state based on block. */ static void RIPEMD160Transform(uint32_t state[5], const unsigned char block[64]) { uint32_t a = state[0], b = state[1], c = state[2], d = state[3], e = state[4]; uint32_t aa = state[0], bb = state[1], cc = state[2], dd = state[3], ee = state[4]; uint32_t tmp, x[16]; int j; RIPEMDDecode(x, block, 64); for(j = 0; j < 16; j++) { tmp = ROLS( j, a + F0(b, c, d) + x[R[j]] + K(j)) + e; a = e; e = d; d = ROL(10, c); c = b; b = tmp; tmp = ROLSS(j, aa + F4(bb, cc, dd) + x[RR[j]] + KK160(j)) + ee; aa = ee; ee = dd; dd = ROL(10, cc); cc = bb; bb = tmp; } for(j = 16; j < 32; j++) { tmp = ROLS( j, a + F1(b, c, d) + x[R[j]] + K(j)) + e; a = e; e = d; d = ROL(10, c); c = b; b = tmp; tmp = ROLSS(j, aa + F3(bb, cc, dd) + x[RR[j]] + KK160(j)) + ee; aa = ee; ee = dd; dd = ROL(10, cc); cc = bb; bb = tmp; } for(j = 32; j < 48; j++) { tmp = ROLS( j, a + F2(b, c, d) + x[R[j]] + K(j)) + e; a = e; e = d; d = ROL(10, c); c = b; b = tmp; tmp = ROLSS(j, aa + F2(bb, cc, dd) + x[RR[j]] + KK160(j)) + ee; aa = ee; ee = dd; dd = ROL(10, cc); cc = bb; bb = tmp; } for(j = 48; j < 64; j++) { tmp = ROLS( j, a + F3(b, c, d) + x[R[j]] + K(j)) + e; a = e; e = d; d = ROL(10, c); c = b; b = tmp; tmp = ROLSS(j, aa + F1(bb, cc, dd) + x[RR[j]] + KK160(j)) + ee; aa = ee; ee = dd; dd = ROL(10, cc); cc = bb; bb = tmp; } for(j = 64; j < 80; j++) { tmp = ROLS( j, a + F4(b, c, d) + x[R[j]] + K(j)) + e; a = e; e = d; d = ROL(10, c); c = b; b = tmp; tmp = ROLSS(j, aa + F0(bb, cc, dd) + x[RR[j]] + KK160(j)) + ee; aa = ee; ee = dd; dd = ROL(10, cc); cc = bb; bb = tmp; } tmp = state[1] + c + dd; state[1] = state[2] + d + ee; state[2] = state[3] + e + aa; state[3] = state[4] + a + bb; state[4] = state[0] + b + cc; state[0] = tmp; tmp = 0; ZEND_SECURE_ZERO(x, sizeof(x)); } /* }}} */ /* {{{ PHP_RIPEMD160Update ripemd160 block update operation. Continues a ripemd160 message-digest operation, processing another message block, and updating the context. */ PHP_HASH_API void PHP_RIPEMD160Update(PHP_RIPEMD160_CTX * context, const unsigned char *input, size_t inputLen) { unsigned int i, index, partLen; /* Compute number of bytes mod 64 */ index = (unsigned int) ((context->count[0] >> 3) & 0x3F); /* Update number of bits */ if ((context->count[0] += ((uint32_t) inputLen << 3)) < ((uint32_t) inputLen << 3)) { context->count[1]++; } context->count[1] += ((uint32_t) inputLen >> 29); partLen = 64 - index; /* Transform as many times as possible. */ if (inputLen >= partLen) { memcpy((unsigned char*) & context->buffer[index], (unsigned char*) input, partLen); RIPEMD160Transform(context->state, context->buffer); for (i = partLen; i + 63 < inputLen; i += 64) { RIPEMD160Transform(context->state, &input[i]); } index = 0; } else { i = 0; } /* Buffer remaining input */ memcpy((unsigned char*) & context->buffer[index], (unsigned char*) & input[i], inputLen - i); } /* }}} */ /* {{{ RIPEMD320Transform * ripemd320 basic transformation. Transforms state based on block. */ static void RIPEMD320Transform(uint32_t state[10], const unsigned char block[64]) { uint32_t a = state[0], b = state[1], c = state[2], d = state[3], e = state[4]; uint32_t aa = state[5], bb = state[6], cc = state[7], dd = state[8], ee = state[9]; uint32_t tmp, x[16]; int j; RIPEMDDecode(x, block, 64); for(j = 0; j < 16; j++) { tmp = ROLS( j, a + F0(b, c, d) + x[R[j]] + K(j)) + e; a = e; e = d; d = ROL(10, c); c = b; b = tmp; tmp = ROLSS(j, aa + F4(bb, cc, dd) + x[RR[j]] + KK160(j)) + ee; aa = ee; ee = dd; dd = ROL(10, cc); cc = bb; bb = tmp; } tmp = b; b = bb; bb = tmp; for(j = 16; j < 32; j++) { tmp = ROLS( j, a + F1(b, c, d) + x[R[j]] + K(j)) + e; a = e; e = d; d = ROL(10, c); c = b; b = tmp; tmp = ROLSS(j, aa + F3(bb, cc, dd) + x[RR[j]] + KK160(j)) + ee; aa = ee; ee = dd; dd = ROL(10, cc); cc = bb; bb = tmp; } tmp = d; d = dd; dd = tmp; for(j = 32; j < 48; j++) { tmp = ROLS( j, a + F2(b, c, d) + x[R[j]] + K(j)) + e; a = e; e = d; d = ROL(10, c); c = b; b = tmp; tmp = ROLSS(j, aa + F2(bb, cc, dd) + x[RR[j]] + KK160(j)) + ee; aa = ee; ee = dd; dd = ROL(10, cc); cc = bb; bb = tmp; } tmp = a; a = aa; aa = tmp; for(j = 48; j < 64; j++) { tmp = ROLS( j, a + F3(b, c, d) + x[R[j]] + K(j)) + e; a = e; e = d; d = ROL(10, c); c = b; b = tmp; tmp = ROLSS(j, aa + F1(bb, cc, dd) + x[RR[j]] + KK160(j)) + ee; aa = ee; ee = dd; dd = ROL(10, cc); cc = bb; bb = tmp; } tmp = c; c = cc; cc = tmp; for(j = 64; j < 80; j++) { tmp = ROLS( j, a + F4(b, c, d) + x[R[j]] + K(j)) + e; a = e; e = d; d = ROL(10, c); c = b; b = tmp; tmp = ROLSS(j, aa + F0(bb, cc, dd) + x[RR[j]] + KK160(j)) + ee; aa = ee; ee = dd; dd = ROL(10, cc); cc = bb; bb = tmp; } tmp = e; e = ee; ee = tmp; state[0] += a; state[1] += b; state[2] += c; state[3] += d; state[4] += e; state[5] += aa; state[6] += bb; state[7] += cc; state[8] += dd; state[9] += ee; tmp = 0; ZEND_SECURE_ZERO(x, sizeof(x)); } /* }}} */ /* {{{ PHP_RIPEMD320Update ripemd320 block update operation. Continues a ripemd320 message-digest operation, processing another message block, and updating the context. */ PHP_HASH_API void PHP_RIPEMD320Update(PHP_RIPEMD320_CTX * context, const unsigned char *input, size_t inputLen) { unsigned int i, index, partLen; /* Compute number of bytes mod 64 */ index = (unsigned int) ((context->count[0] >> 3) & 0x3F); /* Update number of bits */ if ((context->count[0] += ((uint32_t) inputLen << 3)) < ((uint32_t) inputLen << 3)) { context->count[1]++; } context->count[1] += ((uint32_t) inputLen >> 29); partLen = 64 - index; /* Transform as many times as possible. */ if (inputLen >= partLen) { memcpy((unsigned char*) & context->buffer[index], (unsigned char*) input, partLen); RIPEMD320Transform(context->state, context->buffer); for (i = partLen; i + 63 < inputLen; i += 64) { RIPEMD320Transform(context->state, &input[i]); } index = 0; } else { i = 0; } /* Buffer remaining input */ memcpy((unsigned char*) & context->buffer[index], (unsigned char*) & input[i], inputLen - i); } /* }}} */ static const unsigned char PADDING[64] = { 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; /* {{{ RIPEMDEncode Encodes input (uint32_t) into output (unsigned char). Assumes len is a multiple of 4. */ static void RIPEMDEncode(unsigned char *output, uint32_t *input, unsigned int len) { unsigned int i, j; for (i = 0, j = 0; j < len; i++, j += 4) { output[j + 3] = (unsigned char) ((input[i] >> 24) & 0xff); output[j + 2] = (unsigned char) ((input[i] >> 16) & 0xff); output[j + 1] = (unsigned char) ((input[i] >> 8) & 0xff); output[j + 0] = (unsigned char) (input[i] & 0xff); } } /* }}} */ /* {{{ PHP_RIPEMD128Final ripemd128 finalization. Ends a ripemd128 message-digest operation, writing the the message digest and zeroizing the context. */ PHP_HASH_API void PHP_RIPEMD128Final(unsigned char digest[16], PHP_RIPEMD128_CTX * context) { unsigned char bits[8]; unsigned int index, padLen; /* Save number of bits */ bits[0] = (unsigned char) (context->count[0] & 0xFF); bits[1] = (unsigned char) ((context->count[0] >> 8) & 0xFF); bits[2] = (unsigned char) ((context->count[0] >> 16) & 0xFF); bits[3] = (unsigned char) ((context->count[0] >> 24) & 0xFF); bits[4] = (unsigned char) (context->count[1] & 0xFF); bits[5] = (unsigned char) ((context->count[1] >> 8) & 0xFF); bits[6] = (unsigned char) ((context->count[1] >> 16) & 0xFF); bits[7] = (unsigned char) ((context->count[1] >> 24) & 0xFF); /* Pad out to 56 mod 64. */ index = (unsigned int) ((context->count[0] >> 3) & 0x3f); padLen = (index < 56) ? (56 - index) : (120 - index); PHP_RIPEMD128Update(context, PADDING, padLen); /* Append length (before padding) */ PHP_RIPEMD128Update(context, bits, 8); /* Store state in digest */ RIPEMDEncode(digest, context->state, 16); /* Zeroize sensitive information. */ ZEND_SECURE_ZERO((unsigned char*) context, sizeof(*context)); } /* }}} */ /* {{{ PHP_RIPEMD256Final ripemd256 finalization. Ends a ripemd256 message-digest operation, writing the the message digest and zeroizing the context. */ PHP_HASH_API void PHP_RIPEMD256Final(unsigned char digest[32], PHP_RIPEMD256_CTX * context) { unsigned char bits[8]; unsigned int index, padLen; /* Save number of bits */ bits[0] = (unsigned char) (context->count[0] & 0xFF); bits[1] = (unsigned char) ((context->count[0] >> 8) & 0xFF); bits[2] = (unsigned char) ((context->count[0] >> 16) & 0xFF); bits[3] = (unsigned char) ((context->count[0] >> 24) & 0xFF); bits[4] = (unsigned char) (context->count[1] & 0xFF); bits[5] = (unsigned char) ((context->count[1] >> 8) & 0xFF); bits[6] = (unsigned char) ((context->count[1] >> 16) & 0xFF); bits[7] = (unsigned char) ((context->count[1] >> 24) & 0xFF); /* Pad out to 56 mod 64. */ index = (unsigned int) ((context->count[0] >> 3) & 0x3f); padLen = (index < 56) ? (56 - index) : (120 - index); PHP_RIPEMD256Update(context, PADDING, padLen); /* Append length (before padding) */ PHP_RIPEMD256Update(context, bits, 8); /* Store state in digest */ RIPEMDEncode(digest, context->state, 32); /* Zeroize sensitive information. */ ZEND_SECURE_ZERO((unsigned char*) context, sizeof(*context)); } /* }}} */ /* {{{ PHP_RIPEMD160Final ripemd160 finalization. Ends a ripemd160 message-digest operation, writing the the message digest and zeroizing the context. */ PHP_HASH_API void PHP_RIPEMD160Final(unsigned char digest[20], PHP_RIPEMD160_CTX * context) { unsigned char bits[8]; unsigned int index, padLen; /* Save number of bits */ bits[0] = (unsigned char) (context->count[0] & 0xFF); bits[1] = (unsigned char) ((context->count[0] >> 8) & 0xFF); bits[2] = (unsigned char) ((context->count[0] >> 16) & 0xFF); bits[3] = (unsigned char) ((context->count[0] >> 24) & 0xFF); bits[4] = (unsigned char) (context->count[1] & 0xFF); bits[5] = (unsigned char) ((context->count[1] >> 8) & 0xFF); bits[6] = (unsigned char) ((context->count[1] >> 16) & 0xFF); bits[7] = (unsigned char) ((context->count[1] >> 24) & 0xFF); /* Pad out to 56 mod 64. */ index = (unsigned int) ((context->count[0] >> 3) & 0x3f); padLen = (index < 56) ? (56 - index) : (120 - index); PHP_RIPEMD160Update(context, PADDING, padLen); /* Append length (before padding) */ PHP_RIPEMD160Update(context, bits, 8); /* Store state in digest */ RIPEMDEncode(digest, context->state, 20); /* Zeroize sensitive information. */ ZEND_SECURE_ZERO((unsigned char*) context, sizeof(*context)); } /* }}} */ /* {{{ PHP_RIPEMD320Final ripemd320 finalization. Ends a ripemd320 message-digest operation, writing the the message digest and zeroizing the context. */ PHP_HASH_API void PHP_RIPEMD320Final(unsigned char digest[40], PHP_RIPEMD320_CTX * context) { unsigned char bits[8]; unsigned int index, padLen; /* Save number of bits */ bits[0] = (unsigned char) (context->count[0] & 0xFF); bits[1] = (unsigned char) ((context->count[0] >> 8) & 0xFF); bits[2] = (unsigned char) ((context->count[0] >> 16) & 0xFF); bits[3] = (unsigned char) ((context->count[0] >> 24) & 0xFF); bits[4] = (unsigned char) (context->count[1] & 0xFF); bits[5] = (unsigned char) ((context->count[1] >> 8) & 0xFF); bits[6] = (unsigned char) ((context->count[1] >> 16) & 0xFF); bits[7] = (unsigned char) ((context->count[1] >> 24) & 0xFF); /* Pad out to 56 mod 64. */ index = (unsigned int) ((context->count[0] >> 3) & 0x3f); padLen = (index < 56) ? (56 - index) : (120 - index); PHP_RIPEMD320Update(context, PADDING, padLen); /* Append length (before padding) */ PHP_RIPEMD320Update(context, bits, 8); /* Store state in digest */ RIPEMDEncode(digest, context->state, 40); /* Zeroize sensitive information. */ ZEND_SECURE_ZERO((unsigned char*) context, sizeof(*context)); } /* }}} */
24,952
30.868455
128
c
php-src
php-src-master/ext/hash/hash_sha3.c
/* +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: Sara Golemon <[email protected]> | +----------------------------------------------------------------------+ */ #include "php_hash.h" #include "php_hash_sha3.h" #ifdef HAVE_SLOW_HASH3 // ================= slow algo ============================================== #if (defined(__APPLE__) || defined(__APPLE_CC__)) && \ (defined(__BIG_ENDIAN__) || defined(__LITTLE_ENDIAN__)) # if defined(__LITTLE_ENDIAN__) # undef WORDS_BIGENDIAN # else # if defined(__BIG_ENDIAN__) # define WORDS_BIGENDIAN # endif # endif #endif static inline uint64_t rol64(uint64_t v, unsigned char b) { return (v << b) | (v >> (64 - b)); } static inline unsigned char idx(unsigned char x, unsigned char y) { return x + (5 * y); } #ifdef WORDS_BIGENDIAN static inline uint64_t load64(const unsigned char* x) { signed char i; uint64_t ret = 0; for (i = 7; i >= 0; --i) { ret <<= 8; ret |= x[i]; } return ret; } static inline void store64(unsigned char* x, uint64_t val) { size_t i; for (i = 0; i < 8; ++i) { x[i] = val & 0xFF; val >>= 8; } } static inline void xor64(unsigned char* x, uint64_t val) { size_t i; for (i = 0; i < 8; ++i) { x[i] ^= val & 0xFF; val >>= 8; } } # define readLane(x, y) load64(ctx->state+sizeof(uint64_t)*idx(x, y)) # define writeLane(x, y, v) store64(ctx->state+sizeof(uint64_t)*idx(x, y), v) # define XORLane(x, y, v) xor64(ctx->state+sizeof(uint64_t)*idx(x, y), v) #else # define readLane(x, y) (((uint64_t*)ctx->state)[idx(x,y)]) # define writeLane(x, y, v) (((uint64_t*)ctx->state)[idx(x,y)] = v) # define XORLane(x, y, v) (((uint64_t*)ctx->state)[idx(x,y)] ^= v) #endif static inline char LFSR86540(unsigned char* pLFSR) { unsigned char LFSR = *pLFSR; char result = LFSR & 0x01; if (LFSR & 0x80) { // Primitive polynomial over GF(2): x^8+x^6+x^5+x^4+1 LFSR = (LFSR << 1) ^ 0x71; } else { LFSR <<= 1; } *pLFSR = LFSR; return result; } static void permute(PHP_SHA3_CTX* ctx) { unsigned char LFSRstate = 0x01; unsigned char round; for (round = 0; round < 24; ++round) { { // Theta step (see [Keccak Reference, Section 2.3.2]) uint64_t C[5], D; unsigned char x, y; for (x = 0; x < 5; ++x) { C[x] = readLane(x, 0) ^ readLane(x, 1) ^ readLane(x, 2) ^ readLane(x, 3) ^ readLane(x, 4); } for (x = 0; x < 5; ++x) { D = C[(x+4)%5] ^ rol64(C[(x+1)%5], 1); for (y = 0; y < 5; ++y) { XORLane(x, y, D); } } } { // p and Pi steps (see [Keccak Reference, Sections 2.3.3 and 2.3.4]) unsigned char x = 1, y = 0, t; uint64_t current = readLane(x, y); for (t = 0; t < 24; ++t) { unsigned char r = ((t + 1) * (t + 2) / 2) % 64; unsigned char Y = (2*x + 3*y) % 5; uint64_t temp; x = y; y = Y; temp = readLane(x, y); writeLane(x, y, rol64(current, r)); current = temp; } } { // X step (see [Keccak Reference, Section 2.3.1]) unsigned char x, y; for (y = 0; y < 5; ++y) { uint64_t temp[5]; for (x = 0; x < 5; ++x) { temp[x] = readLane(x, y); } for (x = 0; x < 5; ++x) { writeLane(x, y, temp[x] ^((~temp[(x+1)%5]) & temp[(x+2)%5])); } } } { // i step (see [Keccak Reference, Section 2.3.5]) unsigned char j; for (j = 0; j < 7; ++j) { if (LFSR86540(&LFSRstate)) { uint64_t bitPos = (1<<j) - 1; XORLane(0, 0, (uint64_t)1 << bitPos); } } } } } // ========================================================================== static void PHP_SHA3_Init(PHP_SHA3_CTX* ctx, int bits) { memset(ctx, 0, sizeof(PHP_SHA3_CTX)); } static void PHP_SHA3_Update(PHP_SHA3_CTX* ctx, const unsigned char* buf, size_t count, size_t block_size) { while (count > 0) { size_t len = block_size - ctx->pos; if (len > count) { len = count; } count -= len; while (len-- > 0) { ctx->state[ctx->pos++] ^= *(buf++); } if (ctx->pos >= block_size) { permute(ctx); ctx->pos = 0; } } } static void PHP_SHA3_Final(unsigned char* digest, PHP_SHA3_CTX* ctx, size_t block_size, size_t digest_size) { size_t len = digest_size; // Pad state to finalize ctx->state[ctx->pos++] ^= 0x06; ctx->state[block_size-1] ^= 0x80; permute(ctx); // Square output for digest for(;;) { int bs = (len < block_size) ? len : block_size; memcpy(digest, ctx->state, bs); digest += bs; len -= bs; if (!len) break; permute(ctx); } // Zero out context ZEND_SECURE_ZERO(ctx, sizeof(PHP_SHA3_CTX)); } static int php_sha3_unserialize(php_hashcontext_object *hash, zend_long magic, const zval *zv, size_t block_size) { PHP_SHA3_CTX *ctx = (PHP_SHA3_CTX *) hash->context; int r = FAILURE; if (magic == PHP_HASH_SERIALIZE_MAGIC_SPEC && (r = php_hash_unserialize_spec(hash, zv, PHP_SHA3_SPEC)) == SUCCESS && ctx->pos < block_size) { return SUCCESS; } else { return r != SUCCESS ? r : -2000; } } // ========================================================================== #define DECLARE_SHA3_OPS(bits) \ void PHP_SHA3##bits##Init(PHP_SHA3_##bits##_CTX* ctx, ZEND_ATTRIBUTE_UNUSED HashTable *args) { \ PHP_SHA3_Init(ctx, bits); \ } \ void PHP_SHA3##bits##Update(PHP_SHA3_##bits##_CTX* ctx, \ const unsigned char* input, \ size_t inputLen) { \ PHP_SHA3_Update(ctx, input, inputLen, \ (1600 - (2 * bits)) >> 3); \ } \ void PHP_SHA3##bits##Final(unsigned char* digest, \ PHP_SHA3_##bits##_CTX* ctx) { \ PHP_SHA3_Final(digest, ctx, \ (1600 - (2 * bits)) >> 3, \ bits >> 3); \ } \ static int php_sha3##bits##_unserialize(php_hashcontext_object *hash, \ zend_long magic, \ const zval *zv) { \ return php_sha3_unserialize(hash, magic, zv, (1600 - (2 * bits)) >> 3); \ } \ const php_hash_ops php_hash_sha3_##bits##_ops = { \ "sha3-" #bits, \ (php_hash_init_func_t) PHP_SHA3##bits##Init, \ (php_hash_update_func_t) PHP_SHA3##bits##Update, \ (php_hash_final_func_t) PHP_SHA3##bits##Final, \ php_hash_copy, \ php_hash_serialize, \ php_sha3##bits##_unserialize, \ PHP_SHA3_SPEC, \ bits >> 3, \ (1600 - (2 * bits)) >> 3, \ sizeof(PHP_SHA3_##bits##_CTX), \ 1 \ } #else // ================= fast algo ============================================== #define SUCCESS SHA3_SUCCESS /* Avoid conflict between KeccacHash.h and zend_types.h */ #include "KeccakHash.h" /* KECCAK SERIALIZATION Keccak_HashInstance consists of: KeccakWidth1600_SpongeInstance { unsigned char state[200]; unsigned int rate; -- fixed for digest size unsigned int byteIOIndex; -- in range [0, rate/8) int squeezing; -- 0 normally, 1 only during finalize } sponge; unsigned int fixedOutputLength; -- fixed for digest size unsigned char delimitedSuffix; -- fixed for digest size NB If the external sha3/ library is updated, the serialization code may need to be updated. The simpler SHA3 code's serialization states are not interchangeable with Keccak. Furthermore, the Keccak sponge state is sensitive to architecture -- 32-bit and 64-bit implementations produce different states. It does not appear that the state is sensitive to endianness. */ #if Keccak_HashInstance_ImplType == 64 /* corresponds to sha3/generic64lc */ # define PHP_HASH_SERIALIZE_MAGIC_KECCAK 100 #elif Keccak_HashInstance_ImplType == 32 /* corresponds to sha3/generic32lc */ # define PHP_HASH_SERIALIZE_MAGIC_KECCAK 101 #else # error "Unknown Keccak_HashInstance_ImplType" #endif #define PHP_KECCAK_SPEC "b200IiIIB" static int php_keccak_serialize(const php_hashcontext_object *hash, zend_long *magic, zval *zv) { *magic = PHP_HASH_SERIALIZE_MAGIC_KECCAK; return php_hash_serialize_spec(hash, zv, PHP_KECCAK_SPEC); } static int php_keccak_unserialize(php_hashcontext_object *hash, zend_long magic, const zval *zv) { Keccak_HashInstance *ctx = (Keccak_HashInstance *) hash->context; int r = FAILURE; if (magic == PHP_HASH_SERIALIZE_MAGIC_KECCAK && (r = php_hash_unserialize_spec(hash, zv, PHP_KECCAK_SPEC)) == SUCCESS && ctx->sponge.byteIOIndex < ctx->sponge.rate / 8) { return SUCCESS; } else { return r != SUCCESS ? r : -2000; } } // ========================================================================== #define DECLARE_SHA3_OPS(bits) \ void PHP_SHA3##bits##Init(PHP_SHA3_##bits##_CTX* ctx, ZEND_ATTRIBUTE_UNUSED HashTable *args) { \ ZEND_ASSERT(sizeof(Keccak_HashInstance) <= sizeof(PHP_SHA3_##bits##_CTX)); \ Keccak_HashInitialize_SHA3_##bits((Keccak_HashInstance *)ctx); \ } \ void PHP_SHA3##bits##Update(PHP_SHA3_##bits##_CTX* ctx, \ const unsigned char* input, \ size_t inputLen) { \ Keccak_HashUpdate((Keccak_HashInstance *)ctx, input, inputLen * 8); \ } \ void PHP_SHA3##bits##Final(unsigned char* digest, \ PHP_SHA3_##bits##_CTX* ctx) { \ Keccak_HashFinal((Keccak_HashInstance *)ctx, digest); \ } \ const php_hash_ops php_hash_sha3_##bits##_ops = { \ "sha3-" #bits, \ (php_hash_init_func_t) PHP_SHA3##bits##Init, \ (php_hash_update_func_t) PHP_SHA3##bits##Update, \ (php_hash_final_func_t) PHP_SHA3##bits##Final, \ php_hash_copy, \ php_keccak_serialize, \ php_keccak_unserialize, \ PHP_KECCAK_SPEC, \ bits >> 3, \ (1600 - (2 * bits)) >> 3, \ sizeof(PHP_SHA3_CTX), \ 1 \ } #endif // ================= both algo ============================================== DECLARE_SHA3_OPS(224); DECLARE_SHA3_OPS(256); DECLARE_SHA3_OPS(384); DECLARE_SHA3_OPS(512); #undef DECLARE_SHA3_OPS
10,581
28.808451
96
c
php-src
php-src-master/ext/hash/hash_snefru.c
/* +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Michael Wallner <[email protected]> | | Sara Golemon <[email protected]> | +----------------------------------------------------------------------+ */ #include "php_hash.h" #include "php_hash_snefru.h" #include "php_hash_snefru_tables.h" #define round(L, C, N, SB) \ SBE = SB[C & 0xff]; \ L ^= SBE; \ N ^= SBE #ifndef DBG_SNEFRU #define DBG_SNEFRU 0 #endif #if DBG_SNEFRU void ph(uint32_t h[16]) { int i; for (i = 0; i < 16; i++) printf ("%08lx", h[i]); printf("\n"); } #endif static inline void Snefru(uint32_t input[16]) { static const int shifts[4] = {16, 8, 16, 24}; int b, index, rshift, lshift; const uint32_t *t0,*t1; uint32_t SBE,B00,B01,B02,B03,B04,B05,B06,B07,B08,B09,B10,B11,B12,B13,B14,B15; B00 = input[0]; B01 = input[1]; B02 = input[2]; B03 = input[3]; B04 = input[4]; B05 = input[5]; B06 = input[6]; B07 = input[7]; B08 = input[8]; B09 = input[9]; B10 = input[10]; B11 = input[11]; B12 = input[12]; B13 = input[13]; B14 = input[14]; B15 = input[15]; for (index = 0; index < 8; index++) { t0 = tables[2*index+0]; t1 = tables[2*index+1]; for (b = 0; b < 4; b++) { round(B15, B00, B01, t0); round(B00, B01, B02, t0); round(B01, B02, B03, t1); round(B02, B03, B04, t1); round(B03, B04, B05, t0); round(B04, B05, B06, t0); round(B05, B06, B07, t1); round(B06, B07, B08, t1); round(B07, B08, B09, t0); round(B08, B09, B10, t0); round(B09, B10, B11, t1); round(B10, B11, B12, t1); round(B11, B12, B13, t0); round(B12, B13, B14, t0); round(B13, B14, B15, t1); round(B14, B15, B00, t1); rshift = shifts[b]; lshift = 32-rshift; B00 = (B00 >> rshift) | (B00 << lshift); B01 = (B01 >> rshift) | (B01 << lshift); B02 = (B02 >> rshift) | (B02 << lshift); B03 = (B03 >> rshift) | (B03 << lshift); B04 = (B04 >> rshift) | (B04 << lshift); B05 = (B05 >> rshift) | (B05 << lshift); B06 = (B06 >> rshift) | (B06 << lshift); B07 = (B07 >> rshift) | (B07 << lshift); B08 = (B08 >> rshift) | (B08 << lshift); B09 = (B09 >> rshift) | (B09 << lshift); B10 = (B10 >> rshift) | (B10 << lshift); B11 = (B11 >> rshift) | (B11 << lshift); B12 = (B12 >> rshift) | (B12 << lshift); B13 = (B13 >> rshift) | (B13 << lshift); B14 = (B14 >> rshift) | (B14 << lshift); B15 = (B15 >> rshift) | (B15 << lshift); } } input[0] ^= B15; input[1] ^= B14; input[2] ^= B13; input[3] ^= B12; input[4] ^= B11; input[5] ^= B10; input[6] ^= B09; input[7] ^= B08; #if DBG_SNEFRU ph(input); #endif } static inline void SnefruTransform(PHP_SNEFRU_CTX *context, const unsigned char input[32]) { int i, j; for (i = 0, j = 0; i < 32; i += 4, ++j) { context->state[8+j] = ((unsigned)input[i] << 24) | ((unsigned)input[i+1] << 16) | ((unsigned)input[i+2] << 8) | (unsigned)input[i+3]; } Snefru(context->state); ZEND_SECURE_ZERO(&context->state[8], sizeof(uint32_t) * 8); } PHP_HASH_API void PHP_SNEFRUInit(PHP_SNEFRU_CTX *context, ZEND_ATTRIBUTE_UNUSED HashTable *args) { memset(context, 0, sizeof(*context)); } static const uint32_t MAX32 = 0xffffffffLU; PHP_HASH_API void PHP_SNEFRUUpdate(PHP_SNEFRU_CTX *context, const unsigned char *input, size_t len) { if ((MAX32 - context->count[1]) < (len * 8)) { context->count[0]++; context->count[1] = MAX32 - context->count[1]; context->count[1] = ((uint32_t) len * 8) - context->count[1]; } else { context->count[1] += (uint32_t) len * 8; } if (context->length + len < 32) { memcpy(&context->buffer[context->length], input, len); context->length += (unsigned char)len; } else { size_t i = 0, r = (context->length + len) % 32; if (context->length) { i = 32 - context->length; memcpy(&context->buffer[context->length], input, i); SnefruTransform(context, context->buffer); } for (; i + 32 <= len; i += 32) { SnefruTransform(context, input + i); } memcpy(context->buffer, input + i, r); ZEND_SECURE_ZERO(&context->buffer[r], 32 - r); context->length = (unsigned char)r; } } PHP_HASH_API void PHP_SNEFRUFinal(unsigned char digest[32], PHP_SNEFRU_CTX *context) { uint32_t i, j; if (context->length) { SnefruTransform(context, context->buffer); } context->state[14] = context->count[0]; context->state[15] = context->count[1]; Snefru(context->state); for (i = 0, j = 0; j < 32; i++, j += 4) { digest[j] = (unsigned char) ((context->state[i] >> 24) & 0xff); digest[j + 1] = (unsigned char) ((context->state[i] >> 16) & 0xff); digest[j + 2] = (unsigned char) ((context->state[i] >> 8) & 0xff); digest[j + 3] = (unsigned char) (context->state[i] & 0xff); } ZEND_SECURE_ZERO(context, sizeof(*context)); } static int php_snefru_unserialize(php_hashcontext_object *hash, zend_long magic, const zval *zv) { PHP_SNEFRU_CTX *ctx = (PHP_SNEFRU_CTX *) hash->context; int r = FAILURE; if (magic == PHP_HASH_SERIALIZE_MAGIC_SPEC && (r = php_hash_unserialize_spec(hash, zv, PHP_SNEFRU_SPEC)) == SUCCESS && ctx->length < sizeof(ctx->buffer)) { return SUCCESS; } else { return r != SUCCESS ? r : -2000; } } const php_hash_ops php_hash_snefru_ops = { "snefru", (php_hash_init_func_t) PHP_SNEFRUInit, (php_hash_update_func_t) PHP_SNEFRUUpdate, (php_hash_final_func_t) PHP_SNEFRUFinal, php_hash_copy, php_hash_serialize, php_snefru_unserialize, PHP_SNEFRU_SPEC, 32, 32, sizeof(PHP_SNEFRU_CTX), 1 };
6,262
27.598174
99
c
php-src
php-src-master/ext/hash/hash_tiger.c
/* +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Michael Wallner <[email protected]> | | Sara Golemon <[email protected]> | +----------------------------------------------------------------------+ */ #include "php_hash.h" #include "php_hash_tiger.h" #include "php_hash_tiger_tables.h" #if (defined(__APPLE__) || defined(__APPLE_CC__)) && (defined(__BIG_ENDIAN__) || defined(__LITTLE_ENDIAN__)) # if defined(__LITTLE_ENDIAN__) # undef WORDS_BIGENDIAN # else # if defined(__BIG_ENDIAN__) # define WORDS_BIGENDIAN # endif # endif #endif /* {{{ */ #define save_abc \ aa = a; \ bb = b; \ cc = c; #define round(a,b,c,x,mul) \ c ^= x; \ a -= t1[(unsigned char)(c)] ^ \ t2[(unsigned char)(((uint32_t)(c))>>(2*8))] ^ \ t3[(unsigned char)((c)>>(4*8))] ^ \ t4[(unsigned char)(((uint32_t)((c)>>(4*8)))>>(2*8))] ; \ b += t4[(unsigned char)(((uint32_t)(c))>>(1*8))] ^ \ t3[(unsigned char)(((uint32_t)(c))>>(3*8))] ^ \ t2[(unsigned char)(((uint32_t)((c)>>(4*8)))>>(1*8))] ^ \ t1[(unsigned char)(((uint32_t)((c)>>(4*8)))>>(3*8))]; \ b *= mul; #define pass(a,b,c,mul) \ round(a,b,c,x0,mul) \ round(b,c,a,x1,mul) \ round(c,a,b,x2,mul) \ round(a,b,c,x3,mul) \ round(b,c,a,x4,mul) \ round(c,a,b,x5,mul) \ round(a,b,c,x6,mul) \ round(b,c,a,x7,mul) #define key_schedule \ x0 -= x7 ^ L64(0xA5A5A5A5A5A5A5A5); \ x1 ^= x0; \ x2 += x1; \ x3 -= x2 ^ ((~x1)<<19); \ x4 ^= x3; \ x5 += x4; \ x6 -= x5 ^ ((~x4)>>23); \ x7 ^= x6; \ x0 += x7; \ x1 -= x0 ^ ((~x7)<<19); \ x2 ^= x1; \ x3 += x2; \ x4 -= x3 ^ ((~x2)>>23); \ x5 ^= x4; \ x6 += x5; \ x7 -= x6 ^ L64(0x0123456789ABCDEF); #define feedforward \ a ^= aa; \ b -= bb; \ c += cc; #define compress(passes) \ save_abc \ pass(a,b,c,5) \ key_schedule \ pass(c,a,b,7) \ key_schedule \ pass(b,c,a,9) \ for(pass_no=0; pass_no<passes; pass_no++) { \ key_schedule \ pass(a,b,c,9) \ tmpa=a; a=c; c=b; b=tmpa; \ } \ feedforward #define split_ex(str) \ x0=str[0]; x1=str[1]; x2=str[2]; x3=str[3]; \ x4=str[4]; x5=str[5]; x6=str[6]; x7=str[7]; #ifdef WORDS_BIGENDIAN # define split(str) \ { \ int i; \ uint64_t tmp[8]; \ \ for (i = 0; i < 64; ++i) { \ ((unsigned char *) tmp)[i^7] = ((unsigned char *) str)[i]; \ } \ split_ex(tmp); \ } #else # define split split_ex #endif #define tiger_compress(passes, str, state) \ { \ register uint64_t a, b, c, tmpa, x0, x1, x2, x3, x4, x5, x6, x7; \ uint64_t aa, bb, cc; \ unsigned int pass_no; \ \ a = state[0]; \ b = state[1]; \ c = state[2]; \ \ split(str); \ \ compress(passes); \ \ state[0] = a; \ state[1] = b; \ state[2] = c; \ } /* }}} */ static inline void TigerFinalize(PHP_TIGER_CTX *context) { context->passed += (uint64_t) context->length << 3; context->buffer[context->length++] = 0x1; if (context->length % 8) { memset(&context->buffer[context->length], 0, 8-context->length%8); context->length += 8-context->length%8; } if (context->length > 56) { memset(&context->buffer[context->length], 0, 64 - context->length); tiger_compress(context->passes, ((uint64_t *) context->buffer), context->state); memset(context->buffer, 0, 56); } else { memset(&context->buffer[context->length], 0, 56 - context->length); } #ifndef WORDS_BIGENDIAN memcpy(&context->buffer[56], &context->passed, sizeof(uint64_t)); #else context->buffer[56] = (unsigned char) (context->passed & 0xff); context->buffer[57] = (unsigned char) ((context->passed >> 8) & 0xff); context->buffer[58] = (unsigned char) ((context->passed >> 16) & 0xff); context->buffer[59] = (unsigned char) ((context->passed >> 24) & 0xff); context->buffer[60] = (unsigned char) ((context->passed >> 32) & 0xff); context->buffer[61] = (unsigned char) ((context->passed >> 40) & 0xff); context->buffer[62] = (unsigned char) ((context->passed >> 48) & 0xff); context->buffer[63] = (unsigned char) ((context->passed >> 56) & 0xff); #endif tiger_compress(context->passes, ((uint64_t *) context->buffer), context->state); } static inline void TigerDigest(unsigned char *digest_str, unsigned int digest_len, PHP_TIGER_CTX *context) { unsigned int i; for (i = 0; i < digest_len; ++i) { digest_str[i] = (unsigned char) ((context->state[i/8] >> (8 * (i%8))) & 0xff); } } PHP_HASH_API void PHP_3TIGERInit(PHP_TIGER_CTX *context, ZEND_ATTRIBUTE_UNUSED HashTable *args) { memset(context, 0, sizeof(*context)); context->state[0] = L64(0x0123456789ABCDEF); context->state[1] = L64(0xFEDCBA9876543210); context->state[2] = L64(0xF096A5B4C3B2E187); } PHP_HASH_API void PHP_4TIGERInit(PHP_TIGER_CTX *context, ZEND_ATTRIBUTE_UNUSED HashTable *args) { memset(context, 0, sizeof(*context)); context->passes = 1; context->state[0] = L64(0x0123456789ABCDEF); context->state[1] = L64(0xFEDCBA9876543210); context->state[2] = L64(0xF096A5B4C3B2E187); } PHP_HASH_API void PHP_TIGERUpdate(PHP_TIGER_CTX *context, const unsigned char *input, size_t len) { if (context->length + len < 64) { memcpy(&context->buffer[context->length], input, len); context->length += len; } else { size_t i = 0, r = (context->length + len) % 64; if (context->length) { i = 64 - context->length; memcpy(&context->buffer[context->length], input, i); tiger_compress(context->passes, ((const uint64_t *) context->buffer), context->state); ZEND_SECURE_ZERO(context->buffer, 64); context->passed += 512; } for (; i + 64 <= len; i += 64) { memcpy(context->buffer, &input[i], 64); tiger_compress(context->passes, ((const uint64_t *) context->buffer), context->state); context->passed += 512; } ZEND_SECURE_ZERO(&context->buffer[r], 64-r); memcpy(context->buffer, &input[i], r); context->length = r; } } PHP_HASH_API void PHP_TIGER128Final(unsigned char digest[16], PHP_TIGER_CTX *context) { TigerFinalize(context); TigerDigest(digest, 16, context); ZEND_SECURE_ZERO(context, sizeof(*context)); } PHP_HASH_API void PHP_TIGER160Final(unsigned char digest[20], PHP_TIGER_CTX *context) { TigerFinalize(context); TigerDigest(digest, 20, context); ZEND_SECURE_ZERO(context, sizeof(*context)); } PHP_HASH_API void PHP_TIGER192Final(unsigned char digest[24], PHP_TIGER_CTX *context) { TigerFinalize(context); TigerDigest(digest, 24, context); ZEND_SECURE_ZERO(context, sizeof(*context)); } static int php_tiger_unserialize(php_hashcontext_object *hash, zend_long magic, const zval *zv) { PHP_TIGER_CTX *ctx = (PHP_TIGER_CTX *) hash->context; int r = FAILURE; if (magic == PHP_HASH_SERIALIZE_MAGIC_SPEC && (r = php_hash_unserialize_spec(hash, zv, PHP_TIGER_SPEC)) == SUCCESS && ctx->length < sizeof(ctx->buffer)) { return SUCCESS; } else { return r != SUCCESS ? r : -2000; } } #define PHP_HASH_TIGER_OPS(p, b) \ const php_hash_ops php_hash_##p##tiger##b##_ops = { \ "tiger" #b "," #p, \ (php_hash_init_func_t) PHP_##p##TIGERInit, \ (php_hash_update_func_t) PHP_TIGERUpdate, \ (php_hash_final_func_t) PHP_TIGER##b##Final, \ php_hash_copy, \ php_hash_serialize, \ php_tiger_unserialize, \ PHP_TIGER_SPEC, \ b/8, \ 64, \ sizeof(PHP_TIGER_CTX), \ 1 \ } PHP_HASH_TIGER_OPS(3, 128); PHP_HASH_TIGER_OPS(3, 160); PHP_HASH_TIGER_OPS(3, 192); PHP_HASH_TIGER_OPS(4, 128); PHP_HASH_TIGER_OPS(4, 160); PHP_HASH_TIGER_OPS(4, 192);
8,080
28.173285
108
c
php-src
php-src-master/ext/hash/hash_whirlpool.c
/* +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Michael Wallner <[email protected]> | | Sara Golemon <[email protected]> | +----------------------------------------------------------------------+ */ #include "php_hash.h" /* * TODO: simplify Update and Final, those look ridiculously complex * Mike, 2005-11-23 */ #include "php_hash_whirlpool.h" #include "php_hash_whirlpool_tables.h" #define DIGESTBYTES 64 #define DIGESTBITS (8*DIGESTBYTES) /* 512 */ #define WBLOCKBYTES 64 #define WBLOCKBITS (8*WBLOCKBYTES) /* 512 */ #define LENGTHBYTES 32 #define LENGTHBITS (8*LENGTHBYTES) /* 256 */ static void WhirlpoolTransform(PHP_WHIRLPOOL_CTX *context) { int i, r; uint64_t K[8]; /* the round key */ uint64_t block[8]; /* mu(buffer) */ uint64_t state[8]; /* the cipher state */ uint64_t L[8]; unsigned char *buffer = context->buffer.data; /* * map the buffer to a block: */ for (i = 0; i < 8; i++, buffer += 8) { block[i] = (((uint64_t)buffer[0] ) << 56) ^ (((uint64_t)buffer[1] & 0xffL) << 48) ^ (((uint64_t)buffer[2] & 0xffL) << 40) ^ (((uint64_t)buffer[3] & 0xffL) << 32) ^ (((uint64_t)buffer[4] & 0xffL) << 24) ^ (((uint64_t)buffer[5] & 0xffL) << 16) ^ (((uint64_t)buffer[6] & 0xffL) << 8) ^ (((uint64_t)buffer[7] & 0xffL) ); } /* * compute and apply K^0 to the cipher state: */ state[0] = block[0] ^ (K[0] = context->state[0]); state[1] = block[1] ^ (K[1] = context->state[1]); state[2] = block[2] ^ (K[2] = context->state[2]); state[3] = block[3] ^ (K[3] = context->state[3]); state[4] = block[4] ^ (K[4] = context->state[4]); state[5] = block[5] ^ (K[5] = context->state[5]); state[6] = block[6] ^ (K[6] = context->state[6]); state[7] = block[7] ^ (K[7] = context->state[7]); /* * iterate over all rounds: */ for (r = 1; r <= R; r++) { /* * compute K^r from K^{r-1}: */ L[0] = C0[(int)(K[0] >> 56) ] ^ C1[(int)(K[7] >> 48) & 0xff] ^ C2[(int)(K[6] >> 40) & 0xff] ^ C3[(int)(K[5] >> 32) & 0xff] ^ C4[(int)(K[4] >> 24) & 0xff] ^ C5[(int)(K[3] >> 16) & 0xff] ^ C6[(int)(K[2] >> 8) & 0xff] ^ C7[(int)(K[1] ) & 0xff] ^ rc[r]; L[1] = C0[(int)(K[1] >> 56) ] ^ C1[(int)(K[0] >> 48) & 0xff] ^ C2[(int)(K[7] >> 40) & 0xff] ^ C3[(int)(K[6] >> 32) & 0xff] ^ C4[(int)(K[5] >> 24) & 0xff] ^ C5[(int)(K[4] >> 16) & 0xff] ^ C6[(int)(K[3] >> 8) & 0xff] ^ C7[(int)(K[2] ) & 0xff]; L[2] = C0[(int)(K[2] >> 56) ] ^ C1[(int)(K[1] >> 48) & 0xff] ^ C2[(int)(K[0] >> 40) & 0xff] ^ C3[(int)(K[7] >> 32) & 0xff] ^ C4[(int)(K[6] >> 24) & 0xff] ^ C5[(int)(K[5] >> 16) & 0xff] ^ C6[(int)(K[4] >> 8) & 0xff] ^ C7[(int)(K[3] ) & 0xff]; L[3] = C0[(int)(K[3] >> 56) ] ^ C1[(int)(K[2] >> 48) & 0xff] ^ C2[(int)(K[1] >> 40) & 0xff] ^ C3[(int)(K[0] >> 32) & 0xff] ^ C4[(int)(K[7] >> 24) & 0xff] ^ C5[(int)(K[6] >> 16) & 0xff] ^ C6[(int)(K[5] >> 8) & 0xff] ^ C7[(int)(K[4] ) & 0xff]; L[4] = C0[(int)(K[4] >> 56) ] ^ C1[(int)(K[3] >> 48) & 0xff] ^ C2[(int)(K[2] >> 40) & 0xff] ^ C3[(int)(K[1] >> 32) & 0xff] ^ C4[(int)(K[0] >> 24) & 0xff] ^ C5[(int)(K[7] >> 16) & 0xff] ^ C6[(int)(K[6] >> 8) & 0xff] ^ C7[(int)(K[5] ) & 0xff]; L[5] = C0[(int)(K[5] >> 56) ] ^ C1[(int)(K[4] >> 48) & 0xff] ^ C2[(int)(K[3] >> 40) & 0xff] ^ C3[(int)(K[2] >> 32) & 0xff] ^ C4[(int)(K[1] >> 24) & 0xff] ^ C5[(int)(K[0] >> 16) & 0xff] ^ C6[(int)(K[7] >> 8) & 0xff] ^ C7[(int)(K[6] ) & 0xff]; L[6] = C0[(int)(K[6] >> 56) ] ^ C1[(int)(K[5] >> 48) & 0xff] ^ C2[(int)(K[4] >> 40) & 0xff] ^ C3[(int)(K[3] >> 32) & 0xff] ^ C4[(int)(K[2] >> 24) & 0xff] ^ C5[(int)(K[1] >> 16) & 0xff] ^ C6[(int)(K[0] >> 8) & 0xff] ^ C7[(int)(K[7] ) & 0xff]; L[7] = C0[(int)(K[7] >> 56) ] ^ C1[(int)(K[6] >> 48) & 0xff] ^ C2[(int)(K[5] >> 40) & 0xff] ^ C3[(int)(K[4] >> 32) & 0xff] ^ C4[(int)(K[3] >> 24) & 0xff] ^ C5[(int)(K[2] >> 16) & 0xff] ^ C6[(int)(K[1] >> 8) & 0xff] ^ C7[(int)(K[0] ) & 0xff]; K[0] = L[0]; K[1] = L[1]; K[2] = L[2]; K[3] = L[3]; K[4] = L[4]; K[5] = L[5]; K[6] = L[6]; K[7] = L[7]; /* * apply the r-th round transformation: */ L[0] = C0[(int)(state[0] >> 56) ] ^ C1[(int)(state[7] >> 48) & 0xff] ^ C2[(int)(state[6] >> 40) & 0xff] ^ C3[(int)(state[5] >> 32) & 0xff] ^ C4[(int)(state[4] >> 24) & 0xff] ^ C5[(int)(state[3] >> 16) & 0xff] ^ C6[(int)(state[2] >> 8) & 0xff] ^ C7[(int)(state[1] ) & 0xff] ^ K[0]; L[1] = C0[(int)(state[1] >> 56) ] ^ C1[(int)(state[0] >> 48) & 0xff] ^ C2[(int)(state[7] >> 40) & 0xff] ^ C3[(int)(state[6] >> 32) & 0xff] ^ C4[(int)(state[5] >> 24) & 0xff] ^ C5[(int)(state[4] >> 16) & 0xff] ^ C6[(int)(state[3] >> 8) & 0xff] ^ C7[(int)(state[2] ) & 0xff] ^ K[1]; L[2] = C0[(int)(state[2] >> 56) ] ^ C1[(int)(state[1] >> 48) & 0xff] ^ C2[(int)(state[0] >> 40) & 0xff] ^ C3[(int)(state[7] >> 32) & 0xff] ^ C4[(int)(state[6] >> 24) & 0xff] ^ C5[(int)(state[5] >> 16) & 0xff] ^ C6[(int)(state[4] >> 8) & 0xff] ^ C7[(int)(state[3] ) & 0xff] ^ K[2]; L[3] = C0[(int)(state[3] >> 56) ] ^ C1[(int)(state[2] >> 48) & 0xff] ^ C2[(int)(state[1] >> 40) & 0xff] ^ C3[(int)(state[0] >> 32) & 0xff] ^ C4[(int)(state[7] >> 24) & 0xff] ^ C5[(int)(state[6] >> 16) & 0xff] ^ C6[(int)(state[5] >> 8) & 0xff] ^ C7[(int)(state[4] ) & 0xff] ^ K[3]; L[4] = C0[(int)(state[4] >> 56) ] ^ C1[(int)(state[3] >> 48) & 0xff] ^ C2[(int)(state[2] >> 40) & 0xff] ^ C3[(int)(state[1] >> 32) & 0xff] ^ C4[(int)(state[0] >> 24) & 0xff] ^ C5[(int)(state[7] >> 16) & 0xff] ^ C6[(int)(state[6] >> 8) & 0xff] ^ C7[(int)(state[5] ) & 0xff] ^ K[4]; L[5] = C0[(int)(state[5] >> 56) ] ^ C1[(int)(state[4] >> 48) & 0xff] ^ C2[(int)(state[3] >> 40) & 0xff] ^ C3[(int)(state[2] >> 32) & 0xff] ^ C4[(int)(state[1] >> 24) & 0xff] ^ C5[(int)(state[0] >> 16) & 0xff] ^ C6[(int)(state[7] >> 8) & 0xff] ^ C7[(int)(state[6] ) & 0xff] ^ K[5]; L[6] = C0[(int)(state[6] >> 56) ] ^ C1[(int)(state[5] >> 48) & 0xff] ^ C2[(int)(state[4] >> 40) & 0xff] ^ C3[(int)(state[3] >> 32) & 0xff] ^ C4[(int)(state[2] >> 24) & 0xff] ^ C5[(int)(state[1] >> 16) & 0xff] ^ C6[(int)(state[0] >> 8) & 0xff] ^ C7[(int)(state[7] ) & 0xff] ^ K[6]; L[7] = C0[(int)(state[7] >> 56) ] ^ C1[(int)(state[6] >> 48) & 0xff] ^ C2[(int)(state[5] >> 40) & 0xff] ^ C3[(int)(state[4] >> 32) & 0xff] ^ C4[(int)(state[3] >> 24) & 0xff] ^ C5[(int)(state[2] >> 16) & 0xff] ^ C6[(int)(state[1] >> 8) & 0xff] ^ C7[(int)(state[0] ) & 0xff] ^ K[7]; state[0] = L[0]; state[1] = L[1]; state[2] = L[2]; state[3] = L[3]; state[4] = L[4]; state[5] = L[5]; state[6] = L[6]; state[7] = L[7]; } /* * apply the Miyaguchi-Preneel compression function: */ context->state[0] ^= state[0] ^ block[0]; context->state[1] ^= state[1] ^ block[1]; context->state[2] ^= state[2] ^ block[2]; context->state[3] ^= state[3] ^ block[3]; context->state[4] ^= state[4] ^ block[4]; context->state[5] ^= state[5] ^ block[5]; context->state[6] ^= state[6] ^ block[6]; context->state[7] ^= state[7] ^ block[7]; ZEND_SECURE_ZERO(state, sizeof(state)); } PHP_HASH_API void PHP_WHIRLPOOLInit(PHP_WHIRLPOOL_CTX *context, ZEND_ATTRIBUTE_UNUSED HashTable *args) { memset(context, 0, sizeof(*context)); } PHP_HASH_API void PHP_WHIRLPOOLUpdate(PHP_WHIRLPOOL_CTX *context, const unsigned char *input, size_t len) { uint64_t sourceBits = len * 8; int sourcePos = 0; /* index of leftmost source unsigned char containing data (1 to 8 bits). */ int sourceGap = (8 - ((int)sourceBits & 7)) & 7; /* space on source[sourcePos]. */ int bufferRem = context->buffer.bits & 7; /* occupied bits on buffer[bufferPos]. */ const unsigned char *source = input; unsigned char *buffer = context->buffer.data; unsigned char *bitLength = context->bitlength; int bufferBits = context->buffer.bits; int bufferPos = context->buffer.pos; uint32_t b, carry; int i; /* * tally the length of the added data: */ uint64_t value = sourceBits; for (i = 31, carry = 0; i >= 0 && (carry != 0 || value != L64(0)); i--) { carry += bitLength[i] + ((uint32_t)value & 0xff); bitLength[i] = (unsigned char)carry; carry >>= 8; value >>= 8; } /* * process data in chunks of 8 bits (a more efficient approach would be to take whole-word chunks): */ while (sourceBits > 8) { /* N.B. at least source[sourcePos] and source[sourcePos+1] contain data. */ /* * take a byte from the source: */ b = ((source[sourcePos] << sourceGap) & 0xff) | ((source[sourcePos + 1] & 0xff) >> (8 - sourceGap)); /* * process this byte: */ buffer[bufferPos++] |= (unsigned char)(b >> bufferRem); bufferBits += 8 - bufferRem; /* bufferBits = 8*bufferPos; */ if (bufferBits == DIGESTBITS) { /* * process data block: */ WhirlpoolTransform(context); /* * reset buffer: */ bufferBits = bufferPos = 0; } buffer[bufferPos] = (unsigned char) (b << (8 - bufferRem)); bufferBits += bufferRem; /* * proceed to remaining data: */ sourceBits -= 8; sourcePos++; } /* now 0 <= sourceBits <= 8; * furthermore, all data (if any is left) is in source[sourcePos]. */ if (sourceBits > 0) { b = (source[sourcePos] << sourceGap) & 0xff; /* bits are left-justified on b. */ /* * process the remaining bits: */ buffer[bufferPos] |= b >> bufferRem; } else { b = 0; } if (bufferRem + sourceBits < 8) { /* * all remaining data fits on buffer[bufferPos], * and there still remains some space. */ bufferBits += (int) sourceBits; } else { /* * buffer[bufferPos] is full: */ bufferPos++; bufferBits += 8 - bufferRem; /* bufferBits = 8*bufferPos; */ sourceBits -= 8 - bufferRem; /* now 0 <= sourceBits < 8; * furthermore, all data (if any is left) is in source[sourcePos]. */ if (bufferBits == DIGESTBITS) { /* * process data block: */ WhirlpoolTransform(context); /* * reset buffer: */ bufferBits = bufferPos = 0; } buffer[bufferPos] = (unsigned char) (b << (8 - bufferRem)); bufferBits += (int)sourceBits; } context->buffer.bits = bufferBits; context->buffer.pos = bufferPos; } PHP_HASH_API void PHP_WHIRLPOOLFinal(unsigned char digest[64], PHP_WHIRLPOOL_CTX *context) { int i; unsigned char *buffer = context->buffer.data; unsigned char *bitLength = context->bitlength; int bufferBits = context->buffer.bits; int bufferPos = context->buffer.pos; /* * append a '1'-bit: */ buffer[bufferPos] |= 0x80U >> (bufferBits & 7); bufferPos++; /* all remaining bits on the current unsigned char are set to zero. */ /* * pad with zero bits to complete (N*WBLOCKBITS - LENGTHBITS) bits: */ if (bufferPos > WBLOCKBYTES - LENGTHBYTES) { if (bufferPos < WBLOCKBYTES) { memset(&buffer[bufferPos], 0, WBLOCKBYTES - bufferPos); } /* * process data block: */ WhirlpoolTransform(context); /* * reset buffer: */ bufferPos = 0; } if (bufferPos < WBLOCKBYTES - LENGTHBYTES) { memset(&buffer[bufferPos], 0, (WBLOCKBYTES - LENGTHBYTES) - bufferPos); } bufferPos = WBLOCKBYTES - LENGTHBYTES; /* * append bit length of hashed data: */ memcpy(&buffer[WBLOCKBYTES - LENGTHBYTES], bitLength, LENGTHBYTES); /* * process data block: */ WhirlpoolTransform(context); /* * return the completed message digest: */ for (i = 0; i < DIGESTBYTES/8; i++) { digest[0] = (unsigned char)(context->state[i] >> 56); digest[1] = (unsigned char)(context->state[i] >> 48); digest[2] = (unsigned char)(context->state[i] >> 40); digest[3] = (unsigned char)(context->state[i] >> 32); digest[4] = (unsigned char)(context->state[i] >> 24); digest[5] = (unsigned char)(context->state[i] >> 16); digest[6] = (unsigned char)(context->state[i] >> 8); digest[7] = (unsigned char)(context->state[i] ); digest += 8; } ZEND_SECURE_ZERO(context, sizeof(*context)); } static int php_whirlpool_unserialize(php_hashcontext_object *hash, zend_long magic, const zval *zv) { PHP_WHIRLPOOL_CTX *ctx = (PHP_WHIRLPOOL_CTX *) hash->context; int r = FAILURE; if (magic == PHP_HASH_SERIALIZE_MAGIC_SPEC && (r = php_hash_unserialize_spec(hash, zv, PHP_WHIRLPOOL_SPEC)) == SUCCESS && ctx->buffer.pos >= 0 && ctx->buffer.pos < (int) sizeof(ctx->buffer.data) && ctx->buffer.bits >= ctx->buffer.pos * 8 && ctx->buffer.bits < ctx->buffer.pos * 8 + 8) { return SUCCESS; } else { return r != SUCCESS ? r : -2000; } } const php_hash_ops php_hash_whirlpool_ops = { "whirlpool", (php_hash_init_func_t) PHP_WHIRLPOOLInit, (php_hash_update_func_t) PHP_WHIRLPOOLUpdate, (php_hash_final_func_t) PHP_WHIRLPOOLFinal, php_hash_copy, php_hash_serialize, php_whirlpool_unserialize, PHP_WHIRLPOOL_SPEC, 64, 64, sizeof(PHP_WHIRLPOOL_CTX), 1 };
16,477
34.666667
105
c
php-src
php-src-master/ext/hash/hash_xxhash.c
/* +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: Anatol Belski <[email protected]> | +----------------------------------------------------------------------+ */ #include "php_hash.h" #include "php_hash_xxhash.h" static int php_hash_xxh32_unserialize( php_hashcontext_object *hash, zend_long magic, const zval *zv); static int php_hash_xxh64_unserialize( php_hashcontext_object *hash, zend_long magic, const zval *zv); const php_hash_ops php_hash_xxh32_ops = { "xxh32", (php_hash_init_func_t) PHP_XXH32Init, (php_hash_update_func_t) PHP_XXH32Update, (php_hash_final_func_t) PHP_XXH32Final, (php_hash_copy_func_t) PHP_XXH32Copy, php_hash_serialize, php_hash_xxh32_unserialize, PHP_XXH32_SPEC, 4, 4, sizeof(PHP_XXH32_CTX), 0 }; PHP_HASH_API void PHP_XXH32Init(PHP_XXH32_CTX *ctx, HashTable *args) { /* XXH32_createState() is not used intentionally. */ memset(&ctx->s, 0, sizeof ctx->s); if (args) { zval *seed = zend_hash_str_find_deref(args, "seed", sizeof("seed") - 1); /* This might be a bit too restrictive, but thinking that a seed might be set once and for all, it should be done a clean way. */ if (seed && IS_LONG == Z_TYPE_P(seed)) { XXH32_reset(&ctx->s, (XXH32_hash_t)Z_LVAL_P(seed)); } else { XXH32_reset(&ctx->s, 0); } } else { XXH32_reset(&ctx->s, 0); } } PHP_HASH_API void PHP_XXH32Update(PHP_XXH32_CTX *ctx, const unsigned char *in, size_t len) { XXH32_update(&ctx->s, in, len); } PHP_HASH_API void PHP_XXH32Final(unsigned char digest[4], PHP_XXH32_CTX *ctx) { XXH32_canonicalFromHash((XXH32_canonical_t*)digest, XXH32_digest(&ctx->s)); } PHP_HASH_API int PHP_XXH32Copy(const php_hash_ops *ops, PHP_XXH32_CTX *orig_context, PHP_XXH32_CTX *copy_context) { copy_context->s = orig_context->s; return SUCCESS; } static int php_hash_xxh32_unserialize( php_hashcontext_object *hash, zend_long magic, const zval *zv) { PHP_XXH32_CTX *ctx = (PHP_XXH32_CTX *) hash->context; int r = FAILURE; if (magic == PHP_HASH_SERIALIZE_MAGIC_SPEC && (r = php_hash_unserialize_spec(hash, zv, PHP_XXH32_SPEC)) == SUCCESS && ctx->s.memsize < 16) { return SUCCESS; } else { return r != SUCCESS ? r : -2000; } } const php_hash_ops php_hash_xxh64_ops = { "xxh64", (php_hash_init_func_t) PHP_XXH64Init, (php_hash_update_func_t) PHP_XXH64Update, (php_hash_final_func_t) PHP_XXH64Final, (php_hash_copy_func_t) PHP_XXH64Copy, php_hash_serialize, php_hash_xxh64_unserialize, PHP_XXH64_SPEC, 8, 8, sizeof(PHP_XXH64_CTX), 0 }; PHP_HASH_API void PHP_XXH64Init(PHP_XXH64_CTX *ctx, HashTable *args) { /* XXH64_createState() is not used intentionally. */ memset(&ctx->s, 0, sizeof ctx->s); if (args) { zval *seed = zend_hash_str_find_deref(args, "seed", sizeof("seed") - 1); /* This might be a bit too restrictive, but thinking that a seed might be set once and for all, it should be done a clean way. */ if (seed && IS_LONG == Z_TYPE_P(seed)) { XXH64_reset(&ctx->s, (XXH64_hash_t)Z_LVAL_P(seed)); } else { XXH64_reset(&ctx->s, 0); } } else { XXH64_reset(&ctx->s, 0); } } PHP_HASH_API void PHP_XXH64Update(PHP_XXH64_CTX *ctx, const unsigned char *in, size_t len) { XXH64_update(&ctx->s, in, len); } PHP_HASH_API void PHP_XXH64Final(unsigned char digest[8], PHP_XXH64_CTX *ctx) { XXH64_canonicalFromHash((XXH64_canonical_t*)digest, XXH64_digest(&ctx->s)); } PHP_HASH_API int PHP_XXH64Copy(const php_hash_ops *ops, PHP_XXH64_CTX *orig_context, PHP_XXH64_CTX *copy_context) { copy_context->s = orig_context->s; return SUCCESS; } const php_hash_ops php_hash_xxh3_64_ops = { "xxh3", (php_hash_init_func_t) PHP_XXH3_64_Init, (php_hash_update_func_t) PHP_XXH3_64_Update, (php_hash_final_func_t) PHP_XXH3_64_Final, (php_hash_copy_func_t) PHP_XXH3_64_Copy, php_hash_serialize, php_hash_unserialize, NULL, 8, 8, sizeof(PHP_XXH3_64_CTX), 0 }; typedef XXH_errorcode (*xxh3_reset_with_secret_func_t)(XXH3_state_t*, const void*, size_t); typedef XXH_errorcode (*xxh3_reset_with_seed_func_t)(XXH3_state_t*, XXH64_hash_t); zend_always_inline static void _PHP_XXH3_Init(PHP_XXH3_64_CTX *ctx, HashTable *args, xxh3_reset_with_seed_func_t func_init_seed, xxh3_reset_with_secret_func_t func_init_secret, const char* algo_name) { memset(&ctx->s, 0, sizeof ctx->s); if (args) { zval *_seed = zend_hash_str_find_deref(args, "seed", sizeof("seed") - 1); zval *_secret = zend_hash_str_find_deref(args, "secret", sizeof("secret") - 1); if (_seed && _secret) { zend_throw_error(NULL, "%s: Only one of seed or secret is to be passed for initialization", algo_name); return; } if (_seed && IS_LONG == Z_TYPE_P(_seed)) { /* This might be a bit too restrictive, but thinking that a seed might be set once and for all, it should be done a clean way. */ func_init_seed(&ctx->s, (XXH64_hash_t)Z_LVAL_P(_seed)); return; } else if (_secret) { if (!try_convert_to_string(_secret)) { return; } size_t len = Z_STRLEN_P(_secret); if (len < PHP_XXH3_SECRET_SIZE_MIN) { zend_throw_error(NULL, "%s: Secret length must be >= %u bytes, %zu bytes passed", algo_name, XXH3_SECRET_SIZE_MIN, len); return; } if (len > sizeof(ctx->secret)) { len = sizeof(ctx->secret); php_error_docref(NULL, E_WARNING, "%s: Secret content exceeding %zu bytes discarded", algo_name, sizeof(ctx->secret)); } memcpy((unsigned char *)ctx->secret, Z_STRVAL_P(_secret), len); func_init_secret(&ctx->s, ctx->secret, len); return; } } func_init_seed(&ctx->s, 0); } PHP_HASH_API void PHP_XXH3_64_Init(PHP_XXH3_64_CTX *ctx, HashTable *args) { _PHP_XXH3_Init(ctx, args, XXH3_64bits_reset_withSeed, XXH3_64bits_reset_withSecret, "xxh3"); } PHP_HASH_API void PHP_XXH3_64_Update(PHP_XXH3_64_CTX *ctx, const unsigned char *in, size_t len) { XXH3_64bits_update(&ctx->s, in, len); } PHP_HASH_API void PHP_XXH3_64_Final(unsigned char digest[8], PHP_XXH3_64_CTX *ctx) { XXH64_canonicalFromHash((XXH64_canonical_t*)digest, XXH3_64bits_digest(&ctx->s)); } PHP_HASH_API int PHP_XXH3_64_Copy(const php_hash_ops *ops, PHP_XXH3_64_CTX *orig_context, PHP_XXH3_64_CTX *copy_context) { copy_context->s = orig_context->s; return SUCCESS; } static int php_hash_xxh64_unserialize( php_hashcontext_object *hash, zend_long magic, const zval *zv) { PHP_XXH64_CTX *ctx = (PHP_XXH64_CTX *) hash->context; int r = FAILURE; if (magic == PHP_HASH_SERIALIZE_MAGIC_SPEC && (r = php_hash_unserialize_spec(hash, zv, PHP_XXH64_SPEC)) == SUCCESS && ctx->s.memsize < 32) { return SUCCESS; } else { return r != SUCCESS ? r : -2000; } } const php_hash_ops php_hash_xxh3_128_ops = { "xxh128", (php_hash_init_func_t) PHP_XXH3_128_Init, (php_hash_update_func_t) PHP_XXH3_128_Update, (php_hash_final_func_t) PHP_XXH3_128_Final, (php_hash_copy_func_t) PHP_XXH3_128_Copy, php_hash_serialize, php_hash_unserialize, NULL, 16, 8, sizeof(PHP_XXH3_128_CTX), 0 }; PHP_HASH_API void PHP_XXH3_128_Init(PHP_XXH3_128_CTX *ctx, HashTable *args) { _PHP_XXH3_Init(ctx, args, XXH3_128bits_reset_withSeed, XXH3_128bits_reset_withSecret, "xxh128"); } PHP_HASH_API void PHP_XXH3_128_Update(PHP_XXH3_128_CTX *ctx, const unsigned char *in, size_t len) { XXH3_128bits_update(&ctx->s, in, len); } PHP_HASH_API void PHP_XXH3_128_Final(unsigned char digest[16], PHP_XXH3_128_CTX *ctx) { XXH128_canonicalFromHash((XXH128_canonical_t*)digest, XXH3_128bits_digest(&ctx->s)); } PHP_HASH_API int PHP_XXH3_128_Copy(const php_hash_ops *ops, PHP_XXH3_128_CTX *orig_context, PHP_XXH3_128_CTX *copy_context) { copy_context->s = orig_context->s; return SUCCESS; }
8,391
30.197026
124
c
php-src
php-src-master/ext/hash/php_hash.h
/* +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: Sara Golemon <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef PHP_HASH_H #define PHP_HASH_H #include "php.h" #define PHP_HASH_EXTNAME "hash" #define PHP_HASH_VERSION PHP_VERSION #define PHP_MHASH_VERSION PHP_VERSION #define PHP_HASH_HMAC 0x0001 #define PHP_HASH_SERIALIZE_MAGIC_SPEC 2 #define L64 INT64_C typedef struct _php_hashcontext_object php_hashcontext_object; typedef void (*php_hash_init_func_t)(void *context, HashTable *args); typedef void (*php_hash_update_func_t)(void *context, const unsigned char *buf, size_t count); typedef void (*php_hash_final_func_t)(unsigned char *digest, void *context); typedef int (*php_hash_copy_func_t)(const void *ops, void *orig_context, void *dest_context); typedef int (*php_hash_serialize_func_t)(const php_hashcontext_object *hash, zend_long *magic, zval *zv); typedef int (*php_hash_unserialize_func_t)(php_hashcontext_object *hash, zend_long magic, const zval *zv); typedef struct _php_hash_ops { const char *algo; php_hash_init_func_t hash_init; php_hash_update_func_t hash_update; php_hash_final_func_t hash_final; php_hash_copy_func_t hash_copy; php_hash_serialize_func_t hash_serialize; php_hash_unserialize_func_t hash_unserialize; const char *serialize_spec; size_t digest_size; size_t block_size; size_t context_size; unsigned is_crypto: 1; } php_hash_ops; struct _php_hashcontext_object { const php_hash_ops *ops; void *context; zend_long options; unsigned char *key; zend_object std; }; static inline php_hashcontext_object *php_hashcontext_from_object(zend_object *obj) { return ((php_hashcontext_object*)(obj + 1)) - 1; } extern const php_hash_ops php_hash_md2_ops; extern const php_hash_ops php_hash_md4_ops; extern const php_hash_ops php_hash_md5_ops; extern const php_hash_ops php_hash_sha1_ops; extern const php_hash_ops php_hash_sha224_ops; extern const php_hash_ops php_hash_sha256_ops; extern const php_hash_ops php_hash_sha384_ops; extern const php_hash_ops php_hash_sha512_ops; extern const php_hash_ops php_hash_sha512_256_ops; extern const php_hash_ops php_hash_sha512_224_ops; extern const php_hash_ops php_hash_sha3_224_ops; extern const php_hash_ops php_hash_sha3_256_ops; extern const php_hash_ops php_hash_sha3_384_ops; extern const php_hash_ops php_hash_sha3_512_ops; extern const php_hash_ops php_hash_ripemd128_ops; extern const php_hash_ops php_hash_ripemd160_ops; extern const php_hash_ops php_hash_ripemd256_ops; extern const php_hash_ops php_hash_ripemd320_ops; extern const php_hash_ops php_hash_whirlpool_ops; extern const php_hash_ops php_hash_3tiger128_ops; extern const php_hash_ops php_hash_3tiger160_ops; extern const php_hash_ops php_hash_3tiger192_ops; extern const php_hash_ops php_hash_4tiger128_ops; extern const php_hash_ops php_hash_4tiger160_ops; extern const php_hash_ops php_hash_4tiger192_ops; extern const php_hash_ops php_hash_snefru_ops; extern const php_hash_ops php_hash_gost_ops; extern const php_hash_ops php_hash_gost_crypto_ops; extern const php_hash_ops php_hash_adler32_ops; extern const php_hash_ops php_hash_crc32_ops; extern const php_hash_ops php_hash_crc32b_ops; extern const php_hash_ops php_hash_crc32c_ops; extern const php_hash_ops php_hash_fnv132_ops; extern const php_hash_ops php_hash_fnv1a32_ops; extern const php_hash_ops php_hash_fnv164_ops; extern const php_hash_ops php_hash_fnv1a64_ops; extern const php_hash_ops php_hash_joaat_ops; extern const php_hash_ops php_hash_murmur3a_ops; extern const php_hash_ops php_hash_murmur3c_ops; extern const php_hash_ops php_hash_murmur3f_ops; extern const php_hash_ops php_hash_xxh32_ops; extern const php_hash_ops php_hash_xxh64_ops; extern const php_hash_ops php_hash_xxh3_64_ops; extern const php_hash_ops php_hash_xxh3_128_ops; #define PHP_HASH_HAVAL_OPS(p,b) extern const php_hash_ops php_hash_##p##haval##b##_ops; PHP_HASH_HAVAL_OPS(3,128) PHP_HASH_HAVAL_OPS(3,160) PHP_HASH_HAVAL_OPS(3,192) PHP_HASH_HAVAL_OPS(3,224) PHP_HASH_HAVAL_OPS(3,256) PHP_HASH_HAVAL_OPS(4,128) PHP_HASH_HAVAL_OPS(4,160) PHP_HASH_HAVAL_OPS(4,192) PHP_HASH_HAVAL_OPS(4,224) PHP_HASH_HAVAL_OPS(4,256) PHP_HASH_HAVAL_OPS(5,128) PHP_HASH_HAVAL_OPS(5,160) PHP_HASH_HAVAL_OPS(5,192) PHP_HASH_HAVAL_OPS(5,224) PHP_HASH_HAVAL_OPS(5,256) extern zend_module_entry hash_module_entry; #define phpext_hash_ptr &hash_module_entry #ifdef PHP_WIN32 # define PHP_HASH_API __declspec(dllexport) #elif defined(__GNUC__) && __GNUC__ >= 4 # define PHP_HASH_API __attribute__ ((visibility("default"))) #else # define PHP_HASH_API #endif extern PHP_HASH_API zend_class_entry *php_hashcontext_ce; PHP_HASH_API const php_hash_ops *php_hash_fetch_ops(zend_string *algo); PHP_HASH_API void php_hash_register_algo(const char *algo, const php_hash_ops *ops); PHP_HASH_API int php_hash_copy(const void *ops, void *orig_context, void *dest_context); PHP_HASH_API int php_hash_serialize(const php_hashcontext_object *context, zend_long *magic, zval *zv); PHP_HASH_API int php_hash_unserialize(php_hashcontext_object *context, zend_long magic, const zval *zv); PHP_HASH_API int php_hash_serialize_spec(const php_hashcontext_object *context, zval *zv, const char *spec); PHP_HASH_API int php_hash_unserialize_spec(php_hashcontext_object *hash, const zval *zv, const char *spec); static inline void *php_hash_alloc_context(const php_hash_ops *ops) { /* Zero out context memory so serialization doesn't expose internals */ return ecalloc(1, ops->context_size); } static inline void php_hash_bin2hex(char *out, const unsigned char *in, size_t in_len) { static const char hexits[17] = "0123456789abcdef"; size_t i; for(i = 0; i < in_len; i++) { out[i * 2] = hexits[in[i] >> 4]; out[(i * 2) + 1] = hexits[in[i] & 0x0F]; } } #endif /* PHP_HASH_H */
6,660
37.50289
108
h
php-src
php-src-master/ext/hash/php_hash_adler32.h
/* +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: Michael Wallner <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef PHP_HASH_ADLER32_H #define PHP_HASH_ADLER32_H #include "ext/standard/basic_functions.h" typedef struct { uint32_t state; } PHP_ADLER32_CTX; #define PHP_ADLER32_SPEC "l." PHP_HASH_API void PHP_ADLER32Init(PHP_ADLER32_CTX *context, ZEND_ATTRIBUTE_UNUSED HashTable *args); PHP_HASH_API void PHP_ADLER32Update(PHP_ADLER32_CTX *context, const unsigned char *input, size_t len); PHP_HASH_API void PHP_ADLER32Final(unsigned char digest[4], PHP_ADLER32_CTX *context); PHP_HASH_API int PHP_ADLER32Copy(const php_hash_ops *ops, PHP_ADLER32_CTX *orig_context, PHP_ADLER32_CTX *copy_context); #endif
1,596
47.393939
120
h
php-src
php-src-master/ext/hash/php_hash_crc32.h
/* +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: Michael Wallner <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef PHP_HASH_CRC32_H #define PHP_HASH_CRC32_H #include "ext/standard/basic_functions.h" typedef struct { uint32_t state; } PHP_CRC32_CTX; #define PHP_CRC32_SPEC "l." PHP_HASH_API void PHP_CRC32Init(PHP_CRC32_CTX *context, ZEND_ATTRIBUTE_UNUSED HashTable *args); PHP_HASH_API void PHP_CRC32Update(PHP_CRC32_CTX *context, const unsigned char *input, size_t len); PHP_HASH_API void PHP_CRC32BUpdate(PHP_CRC32_CTX *context, const unsigned char *input, size_t len); PHP_HASH_API void PHP_CRC32CUpdate(PHP_CRC32_CTX *context, const unsigned char *input, size_t len); PHP_HASH_API void PHP_CRC32LEFinal(unsigned char digest[4], PHP_CRC32_CTX *context); PHP_HASH_API void PHP_CRC32BEFinal(unsigned char digest[4], PHP_CRC32_CTX *context); PHP_HASH_API int PHP_CRC32Copy(const php_hash_ops *ops, PHP_CRC32_CTX *orig_context, PHP_CRC32_CTX *copy_context); #endif
1,857
50.611111
114
h
php-src
php-src-master/ext/hash/php_hash_crc32_tables.h
/* +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: Michael Wallner <[email protected]> | +----------------------------------------------------------------------+ */ static const uint32_t crc32_table[] = { 0x0, 0x04c11db7, 0x09823b6e, 0x0d4326d9, 0x130476dc, 0x17c56b6b, 0x1a864db2, 0x1e475005, 0x2608edb8, 0x22c9f00f, 0x2f8ad6d6, 0x2b4bcb61, 0x350c9b64, 0x31cd86d3, 0x3c8ea00a, 0x384fbdbd, 0x4c11db70, 0x48d0c6c7, 0x4593e01e, 0x4152fda9, 0x5f15adac, 0x5bd4b01b, 0x569796c2, 0x52568b75, 0x6a1936c8, 0x6ed82b7f, 0x639b0da6, 0x675a1011, 0x791d4014, 0x7ddc5da3, 0x709f7b7a, 0x745e66cd, 0x9823b6e0, 0x9ce2ab57, 0x91a18d8e, 0x95609039, 0x8b27c03c, 0x8fe6dd8b, 0x82a5fb52, 0x8664e6e5, 0xbe2b5b58, 0xbaea46ef, 0xb7a96036, 0xb3687d81, 0xad2f2d84, 0xa9ee3033, 0xa4ad16ea, 0xa06c0b5d, 0xd4326d90, 0xd0f37027, 0xddb056fe, 0xd9714b49, 0xc7361b4c, 0xc3f706fb, 0xceb42022, 0xca753d95, 0xf23a8028, 0xf6fb9d9f, 0xfbb8bb46, 0xff79a6f1, 0xe13ef6f4, 0xe5ffeb43, 0xe8bccd9a, 0xec7dd02d, 0x34867077, 0x30476dc0, 0x3d044b19, 0x39c556ae, 0x278206ab, 0x23431b1c, 0x2e003dc5, 0x2ac12072, 0x128e9dcf, 0x164f8078, 0x1b0ca6a1, 0x1fcdbb16, 0x018aeb13, 0x054bf6a4, 0x0808d07d, 0x0cc9cdca, 0x7897ab07, 0x7c56b6b0, 0x71159069, 0x75d48dde, 0x6b93dddb, 0x6f52c06c, 0x6211e6b5, 0x66d0fb02, 0x5e9f46bf, 0x5a5e5b08, 0x571d7dd1, 0x53dc6066, 0x4d9b3063, 0x495a2dd4, 0x44190b0d, 0x40d816ba, 0xaca5c697, 0xa864db20, 0xa527fdf9, 0xa1e6e04e, 0xbfa1b04b, 0xbb60adfc, 0xb6238b25, 0xb2e29692, 0x8aad2b2f, 0x8e6c3698, 0x832f1041, 0x87ee0df6, 0x99a95df3, 0x9d684044, 0x902b669d, 0x94ea7b2a, 0xe0b41de7, 0xe4750050, 0xe9362689, 0xedf73b3e, 0xf3b06b3b, 0xf771768c, 0xfa325055, 0xfef34de2, 0xc6bcf05f, 0xc27dede8, 0xcf3ecb31, 0xcbffd686, 0xd5b88683, 0xd1799b34, 0xdc3abded, 0xd8fba05a, 0x690ce0ee, 0x6dcdfd59, 0x608edb80, 0x644fc637, 0x7a089632, 0x7ec98b85, 0x738aad5c, 0x774bb0eb, 0x4f040d56, 0x4bc510e1, 0x46863638, 0x42472b8f, 0x5c007b8a, 0x58c1663d, 0x558240e4, 0x51435d53, 0x251d3b9e, 0x21dc2629, 0x2c9f00f0, 0x285e1d47, 0x36194d42, 0x32d850f5, 0x3f9b762c, 0x3b5a6b9b, 0x0315d626, 0x07d4cb91, 0x0a97ed48, 0x0e56f0ff, 0x1011a0fa, 0x14d0bd4d, 0x19939b94, 0x1d528623, 0xf12f560e, 0xf5ee4bb9, 0xf8ad6d60, 0xfc6c70d7, 0xe22b20d2, 0xe6ea3d65, 0xeba91bbc, 0xef68060b, 0xd727bbb6, 0xd3e6a601, 0xdea580d8, 0xda649d6f, 0xc423cd6a, 0xc0e2d0dd, 0xcda1f604, 0xc960ebb3, 0xbd3e8d7e, 0xb9ff90c9, 0xb4bcb610, 0xb07daba7, 0xae3afba2, 0xaafbe615, 0xa7b8c0cc, 0xa379dd7b, 0x9b3660c6, 0x9ff77d71, 0x92b45ba8, 0x9675461f, 0x8832161a, 0x8cf30bad, 0x81b02d74, 0x857130c3, 0x5d8a9099, 0x594b8d2e, 0x5408abf7, 0x50c9b640, 0x4e8ee645, 0x4a4ffbf2, 0x470cdd2b, 0x43cdc09c, 0x7b827d21, 0x7f436096, 0x7200464f, 0x76c15bf8, 0x68860bfd, 0x6c47164a, 0x61043093, 0x65c52d24, 0x119b4be9, 0x155a565e, 0x18197087, 0x1cd86d30, 0x029f3d35, 0x065e2082, 0x0b1d065b, 0x0fdc1bec, 0x3793a651, 0x3352bbe6, 0x3e119d3f, 0x3ad08088, 0x2497d08d, 0x2056cd3a, 0x2d15ebe3, 0x29d4f654, 0xc5a92679, 0xc1683bce, 0xcc2b1d17, 0xc8ea00a0, 0xd6ad50a5, 0xd26c4d12, 0xdf2f6bcb, 0xdbee767c, 0xe3a1cbc1, 0xe760d676, 0xea23f0af, 0xeee2ed18, 0xf0a5bd1d, 0xf464a0aa, 0xf9278673, 0xfde69bc4, 0x89b8fd09, 0x8d79e0be, 0x803ac667, 0x84fbdbd0, 0x9abc8bd5, 0x9e7d9662, 0x933eb0bb, 0x97ffad0c, 0xafb010b1, 0xab710d06, 0xa6322bdf, 0xa2f33668, 0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4 }; static const uint32_t crc32b_table[] = { 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d, }; static const uint32_t crc32c_table[] = { 0x00000000, 0xf26b8303, 0xe13b70f7, 0x1350f3f4, 0xc79a971f, 0x35f1141c, 0x26a1e7e8, 0xd4ca64eb, 0x8ad958cf, 0x78b2dbcc, 0x6be22838, 0x9989ab3b, 0x4d43cfd0, 0xbf284cd3, 0xac78bf27, 0x5e133c24, 0x105ec76f, 0xe235446c, 0xf165b798, 0x030e349b, 0xd7c45070, 0x25afd373, 0x36ff2087, 0xc494a384, 0x9a879fa0, 0x68ec1ca3, 0x7bbcef57, 0x89d76c54, 0x5d1d08bf, 0xaf768bbc, 0xbc267848, 0x4e4dfb4b, 0x20bd8ede, 0xd2d60ddd, 0xc186fe29, 0x33ed7d2a, 0xe72719c1, 0x154c9ac2, 0x061c6936, 0xf477ea35, 0xaa64d611, 0x580f5512, 0x4b5fa6e6, 0xb93425e5, 0x6dfe410e, 0x9f95c20d, 0x8cc531f9, 0x7eaeb2fa, 0x30e349b1, 0xc288cab2, 0xd1d83946, 0x23b3ba45, 0xf779deae, 0x05125dad, 0x1642ae59, 0xe4292d5a, 0xba3a117e, 0x4851927d, 0x5b016189, 0xa96ae28a, 0x7da08661, 0x8fcb0562, 0x9c9bf696, 0x6ef07595, 0x417b1dbc, 0xb3109ebf, 0xa0406d4b, 0x522bee48, 0x86e18aa3, 0x748a09a0, 0x67dafa54, 0x95b17957, 0xcba24573, 0x39c9c670, 0x2a993584, 0xd8f2b687, 0x0c38d26c, 0xfe53516f, 0xed03a29b, 0x1f682198, 0x5125dad3, 0xa34e59d0, 0xb01eaa24, 0x42752927, 0x96bf4dcc, 0x64d4cecf, 0x77843d3b, 0x85efbe38, 0xdbfc821c, 0x2997011f, 0x3ac7f2eb, 0xc8ac71e8, 0x1c661503, 0xee0d9600, 0xfd5d65f4, 0x0f36e6f7, 0x61c69362, 0x93ad1061, 0x80fde395, 0x72966096, 0xa65c047d, 0x5437877e, 0x4767748a, 0xb50cf789, 0xeb1fcbad, 0x197448ae, 0x0a24bb5a, 0xf84f3859, 0x2c855cb2, 0xdeeedfb1, 0xcdbe2c45, 0x3fd5af46, 0x7198540d, 0x83f3d70e, 0x90a324fa, 0x62c8a7f9, 0xb602c312, 0x44694011, 0x5739b3e5, 0xa55230e6, 0xfb410cc2, 0x092a8fc1, 0x1a7a7c35, 0xe811ff36, 0x3cdb9bdd, 0xceb018de, 0xdde0eb2a, 0x2f8b6829, 0x82f63b78, 0x709db87b, 0x63cd4b8f, 0x91a6c88c, 0x456cac67, 0xb7072f64, 0xa457dc90, 0x563c5f93, 0x082f63b7, 0xfa44e0b4, 0xe9141340, 0x1b7f9043, 0xcfb5f4a8, 0x3dde77ab, 0x2e8e845f, 0xdce5075c, 0x92a8fc17, 0x60c37f14, 0x73938ce0, 0x81f80fe3, 0x55326b08, 0xa759e80b, 0xb4091bff, 0x466298fc, 0x1871a4d8, 0xea1a27db, 0xf94ad42f, 0x0b21572c, 0xdfeb33c7, 0x2d80b0c4, 0x3ed04330, 0xccbbc033, 0xa24bb5a6, 0x502036a5, 0x4370c551, 0xb11b4652, 0x65d122b9, 0x97baa1ba, 0x84ea524e, 0x7681d14d, 0x2892ed69, 0xdaf96e6a, 0xc9a99d9e, 0x3bc21e9d, 0xef087a76, 0x1d63f975, 0x0e330a81, 0xfc588982, 0xb21572c9, 0x407ef1ca, 0x532e023e, 0xa145813d, 0x758fe5d6, 0x87e466d5, 0x94b49521, 0x66df1622, 0x38cc2a06, 0xcaa7a905, 0xd9f75af1, 0x2b9cd9f2, 0xff56bd19, 0x0d3d3e1a, 0x1e6dcdee, 0xec064eed, 0xc38d26c4, 0x31e6a5c7, 0x22b65633, 0xd0ddd530, 0x0417b1db, 0xf67c32d8, 0xe52cc12c, 0x1747422f, 0x49547e0b, 0xbb3ffd08, 0xa86f0efc, 0x5a048dff, 0x8ecee914, 0x7ca56a17, 0x6ff599e3, 0x9d9e1ae0, 0xd3d3e1ab, 0x21b862a8, 0x32e8915c, 0xc083125f, 0x144976b4, 0xe622f5b7, 0xf5720643, 0x07198540, 0x590ab964, 0xab613a67, 0xb831c993, 0x4a5a4a90, 0x9e902e7b, 0x6cfbad78, 0x7fab5e8c, 0x8dc0dd8f, 0xe330a81a, 0x115b2b19, 0x020bd8ed, 0xf0605bee, 0x24aa3f05, 0xd6c1bc06, 0xc5914ff2, 0x37faccf1, 0x69e9f0d5, 0x9b8273d6, 0x88d28022, 0x7ab90321, 0xae7367ca, 0x5c18e4c9, 0x4f48173d, 0xbd23943e, 0xf36e6f75, 0x0105ec76, 0x12551f82, 0xe03e9c81, 0x34f4f86a, 0xc69f7b69, 0xd5cf889d, 0x27a40b9e, 0x79b737ba, 0x8bdcb4b9, 0x988c474d, 0x6ae7c44e, 0xbe2da0a5, 0x4c4623a6, 0x5f16d052, 0xad7d5351, };
10,517
50.307317
75
h
php-src
php-src-master/ext/hash/php_hash_fnv.h
/* +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: Michael Maclean <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef PHP_HASH_FNV_H #define PHP_HASH_FNV_H #define PHP_FNV1_32_INIT ((uint32_t)0x811c9dc5) #define PHP_FNV_32_PRIME ((uint32_t)0x01000193) #define PHP_FNV1_64_INIT ((uint64_t)0xcbf29ce484222325ULL) #define PHP_FNV_64_PRIME ((uint64_t)0x100000001b3ULL) /* * hash types */ enum php_fnv_type { PHP_FNV_NONE = 0, /* invalid FNV hash type */ PHP_FNV0_32 = 1, /* FNV-0 32 bit hash */ PHP_FNV1_32 = 2, /* FNV-1 32 bit hash */ PHP_FNV1a_32 = 3, /* FNV-1a 32 bit hash */ PHP_FNV0_64 = 4, /* FNV-0 64 bit hash */ PHP_FNV1_64 = 5, /* FNV-1 64 bit hash */ PHP_FNV1a_64 = 6, /* FNV-1a 64 bit hash */ }; typedef struct { uint32_t state; } PHP_FNV132_CTX; #define PHP_FNV132_SPEC "l." typedef struct { uint64_t state; } PHP_FNV164_CTX; #define PHP_FNV164_SPEC "q." PHP_HASH_API void PHP_FNV132Init(PHP_FNV132_CTX *context, ZEND_ATTRIBUTE_UNUSED HashTable *args); PHP_HASH_API void PHP_FNV132Update(PHP_FNV132_CTX *context, const unsigned char *input, size_t inputLen); PHP_HASH_API void PHP_FNV1a32Update(PHP_FNV132_CTX *context, const unsigned char *input, size_t inputLen); PHP_HASH_API void PHP_FNV132Final(unsigned char digest[4], PHP_FNV132_CTX * context); PHP_HASH_API void PHP_FNV164Init(PHP_FNV164_CTX *context, ZEND_ATTRIBUTE_UNUSED HashTable *args); PHP_HASH_API void PHP_FNV164Update(PHP_FNV164_CTX *context, const unsigned char *input, size_t inputLen); PHP_HASH_API void PHP_FNV1a64Update(PHP_FNV164_CTX *context, const unsigned char *input, size_t inputLen); PHP_HASH_API void PHP_FNV164Final(unsigned char digest[8], PHP_FNV164_CTX * context); static uint32_t fnv_32_buf(void *buf, size_t len, uint32_t hval, int alternate); static uint64_t fnv_64_buf(void *buf, size_t len, uint64_t hval, int alternate); #endif
2,733
39.80597
106
h
php-src
php-src-master/ext/hash/php_hash_gost.h
/* +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: Michael Wallner <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef PHP_HASH_GOST_H #define PHP_HASH_GOST_H #include "ext/standard/basic_functions.h" /* GOST context */ typedef struct { uint32_t state[16]; uint32_t count[2]; unsigned char length; unsigned char buffer[32]; const uint32_t (*tables)[4][256]; } PHP_GOST_CTX; #define PHP_GOST_SPEC "l16l2bb32" PHP_HASH_API void PHP_GOSTInit(PHP_GOST_CTX *, ZEND_ATTRIBUTE_UNUSED HashTable *args); PHP_HASH_API void PHP_GOSTUpdate(PHP_GOST_CTX *, const unsigned char *, size_t); PHP_HASH_API void PHP_GOSTFinal(unsigned char[32], PHP_GOST_CTX *); #endif
1,544
40.756757
86
h
php-src
php-src-master/ext/hash/php_hash_haval.h
/* +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: Sara Golemon <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef PHP_HASH_HAVAL_H #define PHP_HASH_HAVAL_H #include "ext/standard/basic_functions.h" /* HAVAL context. */ typedef struct { uint32_t state[8]; uint32_t count[2]; unsigned char buffer[128]; char passes; short output; void (*Transform)(uint32_t state[8], const unsigned char block[128]); } PHP_HAVAL_CTX; #define PHP_HAVAL_SPEC "l8l2b128" #define PHP_HASH_HAVAL_INIT_DECL(p,b) PHP_HASH_API void PHP_##p##HAVAL##b##Init(PHP_HAVAL_CTX *, ZEND_ATTRIBUTE_UNUSED HashTable *); \ PHP_HASH_API void PHP_HAVAL##b##Final(unsigned char*, PHP_HAVAL_CTX *); PHP_HASH_API void PHP_HAVALUpdate(PHP_HAVAL_CTX *, const unsigned char *, size_t); PHP_HASH_HAVAL_INIT_DECL(3,128) PHP_HASH_HAVAL_INIT_DECL(3,160) PHP_HASH_HAVAL_INIT_DECL(3,192) PHP_HASH_HAVAL_INIT_DECL(3,224) PHP_HASH_HAVAL_INIT_DECL(3,256) PHP_HASH_HAVAL_INIT_DECL(4,128) PHP_HASH_HAVAL_INIT_DECL(4,160) PHP_HASH_HAVAL_INIT_DECL(4,192) PHP_HASH_HAVAL_INIT_DECL(4,224) PHP_HASH_HAVAL_INIT_DECL(4,256) PHP_HASH_HAVAL_INIT_DECL(5,128) PHP_HASH_HAVAL_INIT_DECL(5,160) PHP_HASH_HAVAL_INIT_DECL(5,192) PHP_HASH_HAVAL_INIT_DECL(5,224) PHP_HASH_HAVAL_INIT_DECL(5,256) #endif
2,139
36.54386
134
h
php-src
php-src-master/ext/hash/php_hash_joaat.h
/* +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: Martin Jansen <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef PHP_HASH_JOAAT_H #define PHP_HASH_JOAAT_H typedef struct { uint32_t state; } PHP_JOAAT_CTX; #define PHP_JOAAT_SPEC "l." PHP_HASH_API void PHP_JOAATInit(PHP_JOAAT_CTX *context, ZEND_ATTRIBUTE_UNUSED HashTable *args); PHP_HASH_API void PHP_JOAATUpdate(PHP_JOAAT_CTX *context, const unsigned char *input, size_t inputLen); PHP_HASH_API void PHP_JOAATFinal(unsigned char digest[4], PHP_JOAAT_CTX * context); static uint32_t joaat_buf(void *buf, size_t len, uint32_t hval); #endif
1,471
45
103
h
php-src
php-src-master/ext/hash/php_hash_md.h
/* +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Original Author: Rasmus Lerdorf <[email protected]> | | Modified for pHASH by: Sara Golemon <[email protected]> +----------------------------------------------------------------------+ */ #ifndef PHP_HASH_MD_H #define PHP_HASH_MD_H #include "ext/standard/md5.h" /* MD4 context */ typedef struct { uint32_t state[4]; uint32_t count[2]; unsigned char buffer[64]; } PHP_MD4_CTX; #define PHP_MD4_SPEC "l4l2b64." #define PHP_MD4Init(ctx) PHP_MD4InitArgs(ctx, NULL) PHP_HASH_API void PHP_MD4InitArgs(PHP_MD4_CTX *, ZEND_ATTRIBUTE_UNUSED HashTable *); PHP_HASH_API void PHP_MD4Update(PHP_MD4_CTX *context, const unsigned char *, size_t); PHP_HASH_API void PHP_MD4Final(unsigned char[16], PHP_MD4_CTX *); /* MD2 context */ typedef struct { unsigned char state[48]; unsigned char checksum[16]; unsigned char buffer[16]; unsigned char in_buffer; } PHP_MD2_CTX; #define PHP_MD2_SPEC "b48b16b16b." #define PHP_MD2Init(ctx) PHP_MD2InitArgs(ctx, NULL) PHP_HASH_API void PHP_MD2InitArgs(PHP_MD2_CTX *context, ZEND_ATTRIBUTE_UNUSED HashTable *args); PHP_HASH_API void PHP_MD2Update(PHP_MD2_CTX *context, const unsigned char *, size_t); PHP_HASH_API void PHP_MD2Final(unsigned char[16], PHP_MD2_CTX *); #endif
2,072
39.647059
95
h
php-src
php-src-master/ext/hash/php_hash_murmur.h
/* +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: Anatol Belski <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef PHP_HASH_MURMUR_H #define PHP_HASH_MURMUR_H typedef struct { uint32_t h; uint32_t carry; uint32_t len; } PHP_MURMUR3A_CTX; #define PHP_MURMUR3A_SPEC "lll" PHP_HASH_API void PHP_MURMUR3AInit(PHP_MURMUR3A_CTX *ctx, HashTable *args); PHP_HASH_API void PHP_MURMUR3AUpdate(PHP_MURMUR3A_CTX *ctx, const unsigned char *in, size_t len); PHP_HASH_API void PHP_MURMUR3AFinal(unsigned char digest[4], PHP_MURMUR3A_CTX *ctx); PHP_HASH_API int PHP_MURMUR3ACopy(const php_hash_ops *ops, PHP_MURMUR3A_CTX *orig_context, PHP_MURMUR3A_CTX *copy_context); typedef struct { uint32_t h[4]; uint32_t carry[4]; uint32_t len; } PHP_MURMUR3C_CTX; #define PHP_MURMUR3C_SPEC "lllllllll" PHP_HASH_API void PHP_MURMUR3CInit(PHP_MURMUR3C_CTX *ctx, HashTable *args); PHP_HASH_API void PHP_MURMUR3CUpdate(PHP_MURMUR3C_CTX *ctx, const unsigned char *in, size_t len); PHP_HASH_API void PHP_MURMUR3CFinal(unsigned char digest[16], PHP_MURMUR3C_CTX *ctx); PHP_HASH_API int PHP_MURMUR3CCopy(const php_hash_ops *ops, PHP_MURMUR3C_CTX *orig_context, PHP_MURMUR3C_CTX *copy_context); typedef struct { uint64_t h[2]; uint64_t carry[2]; uint32_t len; } PHP_MURMUR3F_CTX; #define PHP_MURMUR3F_SPEC "qqqql" PHP_HASH_API void PHP_MURMUR3FInit(PHP_MURMUR3F_CTX *ctx, HashTable *args); PHP_HASH_API void PHP_MURMUR3FUpdate(PHP_MURMUR3F_CTX *ctx, const unsigned char *in, size_t len); PHP_HASH_API void PHP_MURMUR3FFinal(unsigned char digest[16], PHP_MURMUR3F_CTX *ctx); PHP_HASH_API int PHP_MURMUR3FCopy(const php_hash_ops *ops, PHP_MURMUR3F_CTX *orig_context, PHP_MURMUR3F_CTX *copy_context); #endif /* PHP_HASH_MURMUR_H */
2,599
43.827586
123
h
php-src
php-src-master/ext/hash/php_hash_ripemd.h
/* +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: Sara Golemon <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef PHP_HASH_RIPEMD_H #define PHP_HASH_RIPEMD_H #include "ext/standard/basic_functions.h" /* RIPEMD context. */ typedef struct { uint32_t state[4]; /* state (ABCD) */ uint32_t count[2]; /* number of bits, modulo 2^64 (lsb first) */ unsigned char buffer[64]; /* input buffer */ } PHP_RIPEMD128_CTX; #define PHP_RIPEMD128_SPEC "l4l2b64." typedef struct { uint32_t state[5]; /* state (ABCD) */ uint32_t count[2]; /* number of bits, modulo 2^64 (lsb first) */ unsigned char buffer[64]; /* input buffer */ } PHP_RIPEMD160_CTX; #define PHP_RIPEMD160_SPEC "l5l2b64." typedef struct { uint32_t state[8]; /* state (ABCD) */ uint32_t count[2]; /* number of bits, modulo 2^64 (lsb first) */ unsigned char buffer[64]; /* input buffer */ } PHP_RIPEMD256_CTX; #define PHP_RIPEMD256_SPEC "l8l2b64." typedef struct { uint32_t state[10]; /* state (ABCD) */ uint32_t count[2]; /* number of bits, modulo 2^64 (lsb first) */ unsigned char buffer[64]; /* input buffer */ } PHP_RIPEMD320_CTX; #define PHP_RIPEMD320_SPEC "l10l2b64." PHP_HASH_API void PHP_RIPEMD128Init(PHP_RIPEMD128_CTX *, ZEND_ATTRIBUTE_UNUSED HashTable *); PHP_HASH_API void PHP_RIPEMD128Update(PHP_RIPEMD128_CTX *, const unsigned char *, size_t); PHP_HASH_API void PHP_RIPEMD128Final(unsigned char[16], PHP_RIPEMD128_CTX *); PHP_HASH_API void PHP_RIPEMD160Init(PHP_RIPEMD160_CTX *, ZEND_ATTRIBUTE_UNUSED HashTable *); PHP_HASH_API void PHP_RIPEMD160Update(PHP_RIPEMD160_CTX *, const unsigned char *, size_t); PHP_HASH_API void PHP_RIPEMD160Final(unsigned char[20], PHP_RIPEMD160_CTX *); PHP_HASH_API void PHP_RIPEMD256Init(PHP_RIPEMD256_CTX *, ZEND_ATTRIBUTE_UNUSED HashTable *); PHP_HASH_API void PHP_RIPEMD256Update(PHP_RIPEMD256_CTX *, const unsigned char *, size_t); PHP_HASH_API void PHP_RIPEMD256Final(unsigned char[32], PHP_RIPEMD256_CTX *); PHP_HASH_API void PHP_RIPEMD320Init(PHP_RIPEMD320_CTX *, ZEND_ATTRIBUTE_UNUSED HashTable *); PHP_HASH_API void PHP_RIPEMD320Update(PHP_RIPEMD320_CTX *, const unsigned char *, size_t); PHP_HASH_API void PHP_RIPEMD320Final(unsigned char[40], PHP_RIPEMD320_CTX *); #endif /* PHP_HASH_RIPEMD_H */
3,117
45.537313
92
h
php-src
php-src-master/ext/hash/php_hash_sha.h
/* +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | SHA1 Author: Stefan Esser <[email protected]> | | SHA256 Author: Sara Golemon <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef PHP_HASH_SHA_H #define PHP_HASH_SHA_H #include "ext/standard/sha1.h" #include "ext/standard/basic_functions.h" /* SHA224 context. */ typedef struct { uint32_t state[8]; /* state */ uint32_t count[2]; /* number of bits, modulo 2^64 */ unsigned char buffer[64]; /* input buffer */ } PHP_SHA224_CTX; #define PHP_SHA224_SPEC "l8l2b64." #define PHP_SHA224Init(ctx) PHP_SHA224InitArgs(ctx, NULL) PHP_HASH_API void PHP_SHA224InitArgs(PHP_SHA224_CTX *, ZEND_ATTRIBUTE_UNUSED HashTable *); PHP_HASH_API void PHP_SHA224Update(PHP_SHA224_CTX *, const unsigned char *, size_t); PHP_HASH_API void PHP_SHA224Final(unsigned char[28], PHP_SHA224_CTX *); /* SHA256 context. */ typedef struct { uint32_t state[8]; /* state */ uint32_t count[2]; /* number of bits, modulo 2^64 */ unsigned char buffer[64]; /* input buffer */ } PHP_SHA256_CTX; #define PHP_SHA256_SPEC "l8l2b64." #define PHP_SHA256Init(ctx) PHP_SHA256InitArgs(ctx, NULL) PHP_HASH_API void PHP_SHA256InitArgs(PHP_SHA256_CTX *, ZEND_ATTRIBUTE_UNUSED HashTable *); PHP_HASH_API void PHP_SHA256Update(PHP_SHA256_CTX *, const unsigned char *, size_t); PHP_HASH_API void PHP_SHA256Final(unsigned char[32], PHP_SHA256_CTX *); /* SHA384 context */ typedef struct { uint64_t state[8]; /* state */ uint64_t count[2]; /* number of bits, modulo 2^128 */ unsigned char buffer[128]; /* input buffer */ } PHP_SHA384_CTX; #define PHP_SHA384_SPEC "q8q2b128." #define PHP_SHA384Init(ctx) PHP_SHA384InitArgs(ctx, NULL) PHP_HASH_API void PHP_SHA384InitArgs(PHP_SHA384_CTX *, ZEND_ATTRIBUTE_UNUSED HashTable *); PHP_HASH_API void PHP_SHA384Update(PHP_SHA384_CTX *, const unsigned char *, size_t); PHP_HASH_API void PHP_SHA384Final(unsigned char[48], PHP_SHA384_CTX *); /* SHA512 context */ typedef struct { uint64_t state[8]; /* state */ uint64_t count[2]; /* number of bits, modulo 2^128 */ unsigned char buffer[128]; /* input buffer */ } PHP_SHA512_CTX; #define PHP_SHA512_SPEC "q8q2b128." #define PHP_SHA512Init(ctx) PHP_SHA512InitArgs(ctx, NULL) PHP_HASH_API void PHP_SHA512InitArgs(PHP_SHA512_CTX *, ZEND_ATTRIBUTE_UNUSED HashTable *); PHP_HASH_API void PHP_SHA512Update(PHP_SHA512_CTX *, const unsigned char *, size_t); PHP_HASH_API void PHP_SHA512Final(unsigned char[64], PHP_SHA512_CTX *); #define PHP_SHA512_256Init(ctx) PHP_SHA512_256InitArgs(ctx, NULL) PHP_HASH_API void PHP_SHA512_256InitArgs(PHP_SHA512_CTX *, ZEND_ATTRIBUTE_UNUSED HashTable *); #define PHP_SHA512_256Update PHP_SHA512Update PHP_HASH_API void PHP_SHA512_256Final(unsigned char[32], PHP_SHA512_CTX *); #define PHP_SHA512_224Init(ctx) PHP_SHA512_224InitArgs(ctx, NULL) PHP_HASH_API void PHP_SHA512_224InitArgs(PHP_SHA512_CTX *, ZEND_ATTRIBUTE_UNUSED HashTable *); #define PHP_SHA512_224Update PHP_SHA512Update PHP_HASH_API void PHP_SHA512_224Final(unsigned char[28], PHP_SHA512_CTX *); #endif /* PHP_HASH_SHA_H */
3,924
44.114943
94
h
php-src
php-src-master/ext/hash/php_hash_sha3.h
/* +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: Sara Golemon <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef PHP_HASH_SHA3_H #define PHP_HASH_SHA3_H #include "php.h" typedef struct { #ifdef HAVE_SLOW_HASH3 unsigned char state[200]; // 5 * 5 * sizeof(uint64) uint32_t pos; #else unsigned char state[224]; // this must fit a Keccak_HashInstance #endif } PHP_SHA3_CTX; #ifdef HAVE_SLOW_HASH3 #define PHP_SHA3_SPEC "b200l." #endif typedef PHP_SHA3_CTX PHP_SHA3_224_CTX; typedef PHP_SHA3_CTX PHP_SHA3_256_CTX; typedef PHP_SHA3_CTX PHP_SHA3_384_CTX; typedef PHP_SHA3_CTX PHP_SHA3_512_CTX; PHP_HASH_API void PHP_SHA3224Init(PHP_SHA3_224_CTX*, ZEND_ATTRIBUTE_UNUSED HashTable *); PHP_HASH_API void PHP_SHA3224Update(PHP_SHA3_224_CTX*, const unsigned char*, size_t); PHP_HASH_API void PHP_SAH3224Final(unsigned char[32], PHP_SHA3_224_CTX*); PHP_HASH_API void PHP_SHA3256Init(PHP_SHA3_256_CTX*, ZEND_ATTRIBUTE_UNUSED HashTable *); PHP_HASH_API void PHP_SHA3256Update(PHP_SHA3_256_CTX*, const unsigned char*, size_t); PHP_HASH_API void PHP_SAH3256Final(unsigned char[32], PHP_SHA3_256_CTX*); PHP_HASH_API void PHP_SHA3384Init(PHP_SHA3_384_CTX*, ZEND_ATTRIBUTE_UNUSED HashTable *); PHP_HASH_API void PHP_SHA3384Update(PHP_SHA3_384_CTX*, const unsigned char*, size_t); PHP_HASH_API void PHP_SAH3384Final(unsigned char[32], PHP_SHA3_384_CTX*); PHP_HASH_API void PHP_SHA3512Init(PHP_SHA3_512_CTX*, ZEND_ATTRIBUTE_UNUSED HashTable *); PHP_HASH_API void PHP_SHA3512Update(PHP_SHA3_512_CTX*, const unsigned char*, size_t); PHP_HASH_API void PHP_SAH3512Final(unsigned char[32], PHP_SHA3_512_CTX*); #endif
2,491
43.5
88
h
php-src
php-src-master/ext/hash/php_hash_snefru.h
/* +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: Michael Wallner <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef PHP_HASH_SNEFRU_H #define PHP_HASH_SNEFRU_H /* SNEFRU-2.5a with 8 passes and 256 bit hash output * AKA "Xerox Secure Hash Function" */ #include "ext/standard/basic_functions.h" /* SNEFRU context */ typedef struct { uint32_t state[16]; uint32_t count[2]; unsigned char length; unsigned char buffer[32]; } PHP_SNEFRU_CTX; #define PHP_SNEFRU_SPEC "l16l2bb32" PHP_HASH_API void PHP_SNEFRUInit(PHP_SNEFRU_CTX *, ZEND_ATTRIBUTE_UNUSED HashTable *); PHP_HASH_API void PHP_SNEFRUUpdate(PHP_SNEFRU_CTX *, const unsigned char *, size_t); PHP_HASH_API void PHP_SNEFRUFinal(unsigned char[32], PHP_SNEFRU_CTX *); #endif
1,621
39.55
86
h
php-src
php-src-master/ext/hash/php_hash_tiger.h
/* +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: Michael Wallner <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef PHP_HASH_TIGER_H #define PHP_HASH_TIGER_H /* TIGER context */ typedef struct { uint64_t state[3]; uint64_t passed; unsigned char buffer[64]; uint32_t length; unsigned int passes:1; } PHP_TIGER_CTX; #define PHP_TIGER_SPEC "q3qb64l" PHP_HASH_API void PHP_3TIGERInit(PHP_TIGER_CTX *context, ZEND_ATTRIBUTE_UNUSED HashTable *args); PHP_HASH_API void PHP_4TIGERInit(PHP_TIGER_CTX *context, ZEND_ATTRIBUTE_UNUSED HashTable *args); PHP_HASH_API void PHP_TIGERUpdate(PHP_TIGER_CTX *context, const unsigned char *input, size_t len); PHP_HASH_API void PHP_TIGER128Final(unsigned char digest[16], PHP_TIGER_CTX *context); PHP_HASH_API void PHP_TIGER160Final(unsigned char digest[20], PHP_TIGER_CTX *context); PHP_HASH_API void PHP_TIGER192Final(unsigned char digest[24], PHP_TIGER_CTX *context); #endif
1,803
46.473684
98
h
php-src
php-src-master/ext/hash/php_hash_whirlpool.h
/* +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: Michael Wallner <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef PHP_HASH_WHIRLPOOL_H #define PHP_HASH_WHIRLPOOL_H /* WHIRLPOOL context */ typedef struct { uint64_t state[8]; unsigned char bitlength[32]; struct { int pos; int bits; unsigned char data[64]; } buffer; } PHP_WHIRLPOOL_CTX; #define PHP_WHIRLPOOL_SPEC "q8b32iib64." PHP_HASH_API void PHP_WHIRLPOOLInit(PHP_WHIRLPOOL_CTX *, ZEND_ATTRIBUTE_UNUSED HashTable *); PHP_HASH_API void PHP_WHIRLPOOLUpdate(PHP_WHIRLPOOL_CTX *, const unsigned char *, size_t); PHP_HASH_API void PHP_WHIRLPOOLFinal(unsigned char[64], PHP_WHIRLPOOL_CTX *); #endif
1,548
40.864865
92
h
php-src
php-src-master/ext/hash/php_hash_xxhash.h
/* +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: Anatol Belski <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef PHP_HASH_XXHASH_H #define PHP_HASH_XXHASH_H #define XXH_INLINE_ALL 1 #include "xxhash.h" typedef struct { XXH32_state_t s; } PHP_XXH32_CTX; #define PHP_XXH32_SPEC "llllllllllll" PHP_HASH_API void PHP_XXH32Init(PHP_XXH32_CTX *ctx, HashTable *args); PHP_HASH_API void PHP_XXH32Update(PHP_XXH32_CTX *ctx, const unsigned char *in, size_t len); PHP_HASH_API void PHP_XXH32Final(unsigned char digest[4], PHP_XXH32_CTX *ctx); PHP_HASH_API int PHP_XXH32Copy(const php_hash_ops *ops, PHP_XXH32_CTX *orig_context, PHP_XXH32_CTX *copy_context); typedef struct { XXH64_state_t s; } PHP_XXH64_CTX; #define PHP_XXH64_SPEC "qqqqqqqqqllq" PHP_HASH_API void PHP_XXH64Init(PHP_XXH64_CTX *ctx, HashTable *args); PHP_HASH_API void PHP_XXH64Update(PHP_XXH64_CTX *ctx, const unsigned char *in, size_t len); PHP_HASH_API void PHP_XXH64Final(unsigned char digest[8], PHP_XXH64_CTX *ctx); PHP_HASH_API int PHP_XXH64Copy(const php_hash_ops *ops, PHP_XXH64_CTX *orig_context, PHP_XXH64_CTX *copy_context); #define PHP_XXH3_SECRET_SIZE_MIN XXH3_SECRET_SIZE_MIN #define PHP_XXH3_SECRET_SIZE_MAX 256 typedef struct { XXH3_state_t s; /* The value must survive the whole streaming cycle from init to final. A more flexible mechanism would be to carry zend_string* passed through the options. However, that will require to introduce a destructor handler for ctx, so then it wolud be automatically called from the object destructor. Until that is given, the viable way is to use a plausible max secret length. */ const unsigned char secret[PHP_XXH3_SECRET_SIZE_MAX]; } PHP_XXH3_CTX; typedef PHP_XXH3_CTX PHP_XXH3_64_CTX; PHP_HASH_API void PHP_XXH3_64_Init(PHP_XXH3_64_CTX *ctx, HashTable *args); PHP_HASH_API void PHP_XXH3_64_Update(PHP_XXH3_64_CTX *ctx, const unsigned char *in, size_t len); PHP_HASH_API void PHP_XXH3_64_Final(unsigned char digest[8], PHP_XXH3_64_CTX *ctx); PHP_HASH_API int PHP_XXH3_64_Copy(const php_hash_ops *ops, PHP_XXH3_64_CTX *orig_context, PHP_XXH3_64_CTX *copy_context); typedef PHP_XXH3_CTX PHP_XXH3_128_CTX; PHP_HASH_API void PHP_XXH3_128_Init(PHP_XXH3_128_CTX *ctx, HashTable *args); PHP_HASH_API void PHP_XXH3_128_Update(PHP_XXH3_128_CTX *ctx, const unsigned char *in, size_t len); PHP_HASH_API void PHP_XXH3_128_Final(unsigned char digest[16], PHP_XXH3_128_CTX *ctx); PHP_HASH_API int PHP_XXH3_128_Copy(const php_hash_ops *ops, PHP_XXH3_128_CTX *orig_context, PHP_XXH3_128_CTX *copy_context); #endif /* PHP_HASH_XXHASH_H */
3,465
45.837838
124
h
php-src
php-src-master/ext/hash/murmur/PMurHash.c
/*----------------------------------------------------------------------------- * MurmurHash3 was written by Austin Appleby, and is placed in the public * domain. * * This implementation was written by Shane Day, and is also public domain. * * This is a portable ANSI C implementation of MurmurHash3_x86_32 (Murmur3A) * with support for progressive processing. */ /*----------------------------------------------------------------------------- If you want to understand the MurmurHash algorithm you would be much better off reading the original source. Just point your browser at: http://code.google.com/p/smhasher/source/browse/trunk/MurmurHash3.cpp What this version provides? 1. Progressive data feeding. Useful when the entire payload to be hashed does not fit in memory or when the data is streamed through the application. Also useful when hashing a number of strings with a common prefix. A partial hash of a prefix string can be generated and reused for each suffix string. How does it work? We can only process entire 32 bit chunks of input, except for the very end that may be shorter. So along with the partial hash we need to give back to the caller a carry containing up to 3 bytes that we were unable to process. This carry also needs to record the number of bytes the carry holds. I use the low 2 bits as a count (0..3) and the carry bytes are shifted into the high byte in stream order. To handle endianess I simply use a macro that reads a uint32_t and define that macro to be a direct read on little endian machines, a read and swap on big endian machines, or a byte-by-byte read if the endianess is unknown. -----------------------------------------------------------------------------*/ #include "PMurHash.h" // /* MSVC warnings we choose to ignore */ // #if defined(_MSC_VER) // #pragma warning(disable: 4127) /* conditional expression is constant */ // #endif /*----------------------------------------------------------------------------- * Endianess, misalignment capabilities and util macros * * The following 3 macros are defined in this section. The other macros defined * are only needed to help derive these 3. * * READ_UINT32(x) Read a little endian unsigned 32-bit int * UNALIGNED_SAFE Defined if READ_UINT32 works on non-word boundaries * ROTL32(x,r) Rotate x left by r bits */ /* I386 or AMD64 */ #if defined(_M_I86) || defined(_M_IX86) || defined(_X86_) || defined(__i386__) || defined(__i386) || defined(i386) \ || defined(_M_X64) || defined(__x86_64__) || defined(__x86_64) || defined(__amd64__) || defined(__amd64) #define UNALIGNED_SAFE #endif /* I386 or AMD64 */ #if defined(_M_I86) || defined(_M_IX86) || defined(_X86_) || defined(__i386__) || defined(__i386) || defined(i386) \ || defined(_M_X64) || defined(__x86_64__) || defined(__x86_64) || defined(__amd64__) || defined(__amd64) #define UNALIGNED_SAFE #endif /* Find best way to ROTL */ #if defined(_MSC_VER) #define FORCE_INLINE static __forceinline #include <stdlib.h> /* Microsoft put _rotl declaration in here */ #define ROTL32(x,y) _rotl(x,y) #else #define FORCE_INLINE static inline __attribute__((always_inline)) /* gcc recognises this code and generates a rotate instruction for CPUs with one */ #define ROTL32(x,r) (((uint32_t)x << r) | ((uint32_t)x >> (32 - r))) #endif #include "endianness.h" #define READ_UINT32(ptr) getblock32((uint32_t *)ptr, 0) /*----------------------------------------------------------------------------- * Core murmurhash algorithm macros */ static const uint32_t kC1 = 0xcc9e2d51; static const uint32_t kC2 = 0x1b873593; /* This is the main processing body of the algorithm. It operates * on each full 32-bits of input. */ #define doblock(h1, k1) \ do {\ k1 *= kC1;\ k1 = ROTL32(k1,15);\ k1 *= kC2;\ \ h1 ^= k1;\ h1 = ROTL32(h1,13);\ h1 = h1*5+0xe6546b64;\ } while(0) /* Append unaligned bytes to carry, forcing hash churn if we have 4 bytes */ /* cnt=bytes to process, h1=name of h1 var, c=carry, n=bytes in c, ptr/len=payload */ #define dobytes(cnt, h1, c, n, ptr, len) \ do {\ unsigned __cnt = cnt;\ while(__cnt--) {\ c = c>>8 | (uint32_t)*ptr++<<24;\ n++; len--;\ if(n==4) {\ doblock(h1, c);\ n = 0;\ }\ }\ } while(0) /*---------------------------------------------------------------------------*/ /* Main hashing function. Initialise carry to 0 and h1 to 0 or an initial seed * if wanted. Both ph1 and pcarry are required arguments. */ void PMurHash32_Process(uint32_t *ph1, uint32_t *pcarry, const void *key, int len) { uint32_t h1 = *ph1; uint32_t c = *pcarry; const uint8_t *ptr = (uint8_t*)key; const uint8_t *end; /* Extract carry count from low 2 bits of c value */ int n = c & 3; #if defined(UNALIGNED_SAFE) /* This CPU handles unaligned word access */ // #pragma message ( "UNALIGNED_SAFE" ) /* Consume any carry bytes */ int i = (4-n) & 3; if(i && i <= len) { dobytes(i, h1, c, n, ptr, len); } /* Process 32-bit chunks */ end = ptr + (len & ~3); for( ; ptr < end ; ptr+=4) { uint32_t k1 = READ_UINT32(ptr); doblock(h1, k1); } #else /*UNALIGNED_SAFE*/ /* This CPU does not handle unaligned word access */ // #pragma message ( "ALIGNED" ) /* Consume enough so that the next data byte is word aligned */ int i = -(intptr_t)(void *)ptr & 3; if(i && i <= len) { dobytes(i, h1, c, n, ptr, len); } /* We're now aligned. Process in aligned blocks. Specialise for each possible carry count */ end = ptr + (len & ~3); switch(n) { /* how many bytes in c */ case 0: /* c=[----] w=[3210] b=[3210]=w c'=[----] */ for( ; ptr < end ; ptr+=4) { uint32_t k1 = READ_UINT32(ptr); doblock(h1, k1); } break; case 1: /* c=[0---] w=[4321] b=[3210]=c>>24|w<<8 c'=[4---] */ for( ; ptr < end ; ptr+=4) { uint32_t k1 = c>>24; c = READ_UINT32(ptr); k1 |= c<<8; doblock(h1, k1); } break; case 2: /* c=[10--] w=[5432] b=[3210]=c>>16|w<<16 c'=[54--] */ for( ; ptr < end ; ptr+=4) { uint32_t k1 = c>>16; c = READ_UINT32(ptr); k1 |= c<<16; doblock(h1, k1); } break; case 3: /* c=[210-] w=[6543] b=[3210]=c>>8|w<<24 c'=[654-] */ for( ; ptr < end ; ptr+=4) { uint32_t k1 = c>>8; c = READ_UINT32(ptr); k1 |= c<<24; doblock(h1, k1); } } #endif /*UNALIGNED_SAFE*/ /* Advance over whole 32-bit chunks, possibly leaving 1..3 bytes */ len -= len & ~3; /* Append any remaining bytes into carry */ dobytes(len, h1, c, n, ptr, len); /* Copy out new running hash and carry */ *ph1 = h1; *pcarry = (c & ~0xff) | n; } /*---------------------------------------------------------------------------*/ /* Finalize a hash. To match the original Murmur3A the total_length must be provided */ uint32_t PMurHash32_Result(uint32_t h, uint32_t carry, uint32_t total_length) { uint32_t k1; int n = carry & 3; if(n) { k1 = carry >> (4-n)*8; k1 *= kC1; k1 = ROTL32(k1,15); k1 *= kC2; h ^= k1; } h ^= total_length; /* fmix */ h ^= h >> 16; h *= 0x85ebca6b; h ^= h >> 13; h *= 0xc2b2ae35; h ^= h >> 16; return h; }
7,209
30.762115
116
c
php-src
php-src-master/ext/hash/murmur/PMurHash.h
/*----------------------------------------------------------------------------- * MurmurHash3 was written by Austin Appleby, and is placed in the public * domain. * * This implementation was written by Shane Day, and is also public domain. * * This implementation was modified to match PMurHash128.cpp. */ /* ------------------------------------------------------------------------- */ // Microsoft Visual Studio #if defined(_MSC_VER) && (_MSC_VER < 1600) typedef unsigned char uint8_t; typedef unsigned int uint32_t; // Other compilers #else // defined(_MSC_VER) #include <stdint.h> #endif // !defined(_MSC_VER) /* ------------------------------------------------------------------------- */ /* Prototypes */ void PMurHash32_Process(uint32_t *ph1, uint32_t *pcarry, const void *key, int len); uint32_t PMurHash32_Result(uint32_t h1, uint32_t carry, uint32_t total_length);
891
26.875
83
h
php-src
php-src-master/ext/hash/murmur/PMurHash128.h
/*----------------------------------------------------------------------------- * MurmurHash3 was written by Austin Appleby, and is placed in the public * domain. * * This is a c++ implementation of MurmurHash3_128 with support for progressive * processing based on PMurHash implementation written by Shane Day. */ /* ------------------------------------------------------------------------- */ // Microsoft Visual Studio #if defined(_MSC_VER) && (_MSC_VER < 1600) typedef unsigned char uint8_t; typedef unsigned int uint32_t; typedef unsigned __int64 uint64_t; // Other compilers #else // defined(_MSC_VER) #include <stdint.h> #endif // !defined(_MSC_VER) /* ------------------------------------------------------------------------- */ /* Formal prototypes */ // PMurHash128x64 void PMurHash128x64_Process(uint64_t ph[2], uint64_t pcarry[2], const void *key, int len); void PMurHash128x64_Result(const uint64_t ph[2], const uint64_t pcarry[2], uint32_t total_length, uint64_t out[2]); void PMurHash128x64(const void * key, const int len, uint32_t seed, void * out); // PMurHash128x86 void PMurHash128x86_Process(uint32_t ph[4], uint32_t pcarry[4], const void *key, int len); void PMurHash128x86_Result(const uint32_t ph[4], const uint32_t pcarry[4], uint32_t total_length, uint32_t out[4]); void PMurHash128x86(const void * key, const int len, uint32_t seed, void * out);
1,391
33.8
115
h
php-src
php-src-master/ext/hash/murmur/endianness.h
static const union { uint8_t u8[2]; uint16_t u16; } EndianMix = {{ 1, 0 }}; FORCE_INLINE int IsBigEndian(void) { // Constant-folded by the compiler. return EndianMix.u16 != 1; } #if defined(_MSC_VER) # include <stdlib.h> # define BSWAP32(u) _byteswap_ulong(u) # define BSWAP64(u) _byteswap_uint64(u) #else # ifdef __has_builtin # if __has_builtin(__builtin_bswap32) # define BSWAP32(u) __builtin_bswap32(u) # endif // __has_builtin(__builtin_bswap32) # if __has_builtin(__builtin_bswap64) # define BSWAP64(u) __builtin_bswap64(u) # endif // __has_builtin(__builtin_bswap64) # elif defined(__GNUC__) && ( \ __GNUC__ > 4 || ( \ __GNUC__ == 4 && ( \ __GNUC_MINOR__ >= 3 \ ) \ ) \ ) # define BSWAP32(u) __builtin_bswap32(u) # define BSWAP64(u) __builtin_bswap64(u) # endif // __has_builtin #endif // defined(_MSC_VER) #ifndef BSWAP32 FORCE_INLINE uint32_t BSWAP32(uint32_t u) { return (((u & 0xff000000) >> 24) | ((u & 0x00ff0000) >> 8) | ((u & 0x0000ff00) << 8) | ((u & 0x000000ff) << 24)); } #endif #ifndef BSWAP64 FORCE_INLINE uint64_t BSWAP64(uint64_t u) { return (((u & 0xff00000000000000ULL) >> 56) | ((u & 0x00ff000000000000ULL) >> 40) | ((u & 0x0000ff0000000000ULL) >> 24) | ((u & 0x000000ff00000000ULL) >> 8) | ((u & 0x00000000ff000000ULL) << 8) | ((u & 0x0000000000ff0000ULL) << 24) | ((u & 0x000000000000ff00ULL) << 40) | ((u & 0x00000000000000ffULL) << 56)); } #endif #if defined(__clang__) || defined(__GNUC__) && __GNUC__ >= 8 # define NO_SANITIZE_ALIGNMENT __attribute__((no_sanitize("alignment"))) #else # define NO_SANITIZE_ALIGNMENT #endif NO_SANITIZE_ALIGNMENT FORCE_INLINE uint32_t getblock32 ( const uint32_t * const p, const int i) { if (IsBigEndian()) { return BSWAP32(p[i]); } else { return p[i]; } } NO_SANITIZE_ALIGNMENT FORCE_INLINE uint64_t getblock64 ( const uint64_t * const p, const int i) { if (IsBigEndian()) { return BSWAP64(p[i]); } else { return p[i]; } } #undef NO_SANITIZE_ALIGNMENT
2,229
25.235294
73
h
php-src
php-src-master/ext/hash/sha3/generic32lc/KeccakSponge.c
/* Implementation by the Keccak, Keyak and Ketje Teams, namely, Guido Bertoni, Joan Daemen, Michaël Peeters, Gilles Van Assche and Ronny Van Keer, hereby denoted as "the implementer". For more information, feedback or questions, please refer to our websites: http://keccak.noekeon.org/ http://keyak.noekeon.org/ http://ketje.noekeon.org/ To the extent possible under law, the implementer has waived all copyright and related or neighboring rights to the source code in this file. http://creativecommons.org/publicdomain/zero/1.0/ */ #include "KeccakSponge.h" #ifdef KeccakReference #include "displayIntermediateValues.h" #endif #ifndef KeccakP200_excluded #include "KeccakP-200-SnP.h" #define prefix KeccakWidth200 #define SnP KeccakP200 #define SnP_width 200 #define SnP_Permute KeccakP200_Permute_18rounds #if defined(KeccakF200_FastLoop_supported) #define SnP_FastLoop_Absorb KeccakF200_FastLoop_Absorb #endif #include "KeccakSponge.inc" #undef prefix #undef SnP #undef SnP_width #undef SnP_Permute #undef SnP_FastLoop_Absorb #endif #ifndef KeccakP400_excluded #include "KeccakP-400-SnP.h" #define prefix KeccakWidth400 #define SnP KeccakP400 #define SnP_width 400 #define SnP_Permute KeccakP400_Permute_20rounds #if defined(KeccakF400_FastLoop_supported) #define SnP_FastLoop_Absorb KeccakF400_FastLoop_Absorb #endif #include "KeccakSponge.inc" #undef prefix #undef SnP #undef SnP_width #undef SnP_Permute #undef SnP_FastLoop_Absorb #endif #ifndef KeccakP800_excluded #include "KeccakP-800-SnP.h" #define prefix KeccakWidth800 #define SnP KeccakP800 #define SnP_width 800 #define SnP_Permute KeccakP800_Permute_22rounds #if defined(KeccakF800_FastLoop_supported) #define SnP_FastLoop_Absorb KeccakF800_FastLoop_Absorb #endif #include "KeccakSponge.inc" #undef prefix #undef SnP #undef SnP_width #undef SnP_Permute #undef SnP_FastLoop_Absorb #endif #ifndef KeccakP1600_excluded #include "KeccakP-1600-SnP.h" #define prefix KeccakWidth1600 #define SnP KeccakP1600 #define SnP_width 1600 #define SnP_Permute KeccakP1600_Permute_24rounds #if defined(KeccakF1600_FastLoop_supported) #define SnP_FastLoop_Absorb KeccakF1600_FastLoop_Absorb #endif #include "KeccakSponge.inc" #undef prefix #undef SnP #undef SnP_width #undef SnP_Permute #undef SnP_FastLoop_Absorb #endif #ifndef KeccakP1600_excluded #include "KeccakP-1600-SnP.h" #define prefix KeccakWidth1600_12rounds #define SnP KeccakP1600 #define SnP_width 1600 #define SnP_Permute KeccakP1600_Permute_12rounds #if defined(KeccakP1600_12rounds_FastLoop_supported) #define SnP_FastLoop_Absorb KeccakP1600_12rounds_FastLoop_Absorb #endif #include "KeccakSponge.inc" #undef prefix #undef SnP #undef SnP_width #undef SnP_Permute #undef SnP_FastLoop_Absorb #endif
3,049
26.477477
75
c
php-src
php-src-master/ext/hash/sha3/generic32lc/align.h
/* Implementation by the Keccak, Keyak and Ketje Teams, namely, Guido Bertoni, Joan Daemen, Michaël Peeters, Gilles Van Assche and Ronny Van Keer, hereby denoted as "the implementer". For more information, feedback or questions, please refer to our websites: http://keccak.noekeon.org/ http://keyak.noekeon.org/ http://ketje.noekeon.org/ To the extent possible under law, the implementer has waived all copyright and related or neighboring rights to the source code in this file. http://creativecommons.org/publicdomain/zero/1.0/ */ #ifndef _align_h_ #define _align_h_ /* on Mac OS-X and possibly others, ALIGN(x) is defined in param.h, and -Werror chokes on the redef. */ #ifdef ALIGN #undef ALIGN #endif #if defined(__GNUC__) #define ALIGN(x) __attribute__ ((aligned(x))) #elif defined(_MSC_VER) #define ALIGN(x) __declspec(align(x)) #elif defined(__ARMCC_VERSION) #define ALIGN(x) __align(x) #else #define ALIGN(x) #endif #endif
938
25.828571
103
h
php-src
php-src-master/ext/hash/sha3/generic32lc/brg_endian.h
/* --------------------------------------------------------------------------- Copyright (c) 1998-2008, Brian Gladman, Worcester, UK. All rights reserved. LICENSE TERMS The redistribution and use of this software (with or without changes) is allowed without the payment of fees or royalties provided that: 1. source code distributions include the above copyright notice, this list of conditions and the following disclaimer; 2. binary distributions include the above copyright notice, this list of conditions and the following disclaimer in their documentation; 3. the name of the copyright holder is not used to endorse products built using this software without specific written permission. DISCLAIMER This software is provided 'as is' with no explicit or implied warranties in respect of its properties, including, but not limited to, correctness and/or fitness for purpose. --------------------------------------------------------------------------- Issue Date: 20/12/2007 Changes for ARM 9/9/2010 */ #ifndef _BRG_ENDIAN_H #define _BRG_ENDIAN_H #define IS_BIG_ENDIAN 4321 /* byte 0 is most significant (mc68k) */ #define IS_LITTLE_ENDIAN 1234 /* byte 0 is least significant (i386) */ #if 0 /* Include files where endian defines and byteswap functions may reside */ #if defined( __sun ) # include <sys/isa_defs.h> #elif defined( __FreeBSD__ ) || defined( __OpenBSD__ ) || defined( __NetBSD__ ) # include <sys/endian.h> #elif defined( BSD ) && ( BSD >= 199103 ) || defined( __APPLE__ ) || \ defined( __CYGWIN32__ ) || defined( __DJGPP__ ) || defined( __osf__ ) # include <machine/endian.h> #elif defined( __linux__ ) || defined( __GNUC__ ) || defined( __GNU_LIBRARY__ ) # if !defined( __MINGW32__ ) && !defined( _AIX ) # include <endian.h> # if !defined( __BEOS__ ) # include <byteswap.h> # endif # endif #endif #endif /* Now attempt to set the define for platform byte order using any */ /* of the four forms SYMBOL, _SYMBOL, __SYMBOL & __SYMBOL__, which */ /* seem to encompass most endian symbol definitions */ #if defined( BIG_ENDIAN ) && defined( LITTLE_ENDIAN ) # if defined( BYTE_ORDER ) && BYTE_ORDER == BIG_ENDIAN # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN # elif defined( BYTE_ORDER ) && BYTE_ORDER == LITTLE_ENDIAN # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN # endif #elif defined( BIG_ENDIAN ) # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN #elif defined( LITTLE_ENDIAN ) # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN #endif #if defined( _BIG_ENDIAN ) && defined( _LITTLE_ENDIAN ) # if defined( _BYTE_ORDER ) && _BYTE_ORDER == _BIG_ENDIAN # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN # elif defined( _BYTE_ORDER ) && _BYTE_ORDER == _LITTLE_ENDIAN # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN # endif #elif defined( _BIG_ENDIAN ) # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN #elif defined( _LITTLE_ENDIAN ) # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN #endif #if defined( __BIG_ENDIAN ) && defined( __LITTLE_ENDIAN ) # if defined( __BYTE_ORDER ) && __BYTE_ORDER == __BIG_ENDIAN # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN # elif defined( __BYTE_ORDER ) && __BYTE_ORDER == __LITTLE_ENDIAN # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN # endif #elif defined( __BIG_ENDIAN ) # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN #elif defined( __LITTLE_ENDIAN ) # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN #endif #if defined( __BIG_ENDIAN__ ) && defined( __LITTLE_ENDIAN__ ) # if defined( __BYTE_ORDER__ ) && __BYTE_ORDER__ == __BIG_ENDIAN__ # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN # elif defined( __BYTE_ORDER__ ) && __BYTE_ORDER__ == __LITTLE_ENDIAN__ # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN # endif #elif defined( __BIG_ENDIAN__ ) # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN #elif defined( __LITTLE_ENDIAN__ ) # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN #endif /* if the platform byte order could not be determined, then try to */ /* set this define using common machine defines */ #if !defined(PLATFORM_BYTE_ORDER) #if defined( __alpha__ ) || defined( __alpha ) || defined( i386 ) || \ defined( __i386__ ) || defined( _M_I86 ) || defined( _M_IX86 ) || \ defined( __OS2__ ) || defined( sun386 ) || defined( __TURBOC__ ) || \ defined( vax ) || defined( vms ) || defined( VMS ) || \ defined( __VMS ) || defined( _M_X64 ) # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN #elif defined( AMIGA ) || defined( applec ) || defined( __AS400__ ) || \ defined( _CRAY ) || defined( __hppa ) || defined( __hp9000 ) || \ defined( ibm370 ) || defined( mc68000 ) || defined( m68k ) || \ defined( __MRC__ ) || defined( __MVS__ ) || defined( __MWERKS__ ) || \ defined( sparc ) || defined( __sparc) || defined( SYMANTEC_C ) || \ defined( __VOS__ ) || defined( __TIGCC__ ) || defined( __TANDEM ) || \ defined( THINK_C ) || defined( __VMCMS__ ) || defined( _AIX ) # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN #elif defined(__arm__) # ifdef __BIG_ENDIAN # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN # else # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN # endif #elif 1 /* **** EDIT HERE IF NECESSARY **** */ # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN #elif 0 /* **** EDIT HERE IF NECESSARY **** */ # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN #else # error Please edit lines 132 or 134 in brg_endian.h to set the platform byte order #endif #endif #endif
5,546
37.79021
84
h
php-src
php-src-master/ext/hash/sha3/generic64lc/KeccakSponge.c
/* Implementation by the Keccak, Keyak and Ketje Teams, namely, Guido Bertoni, Joan Daemen, Michaël Peeters, Gilles Van Assche and Ronny Van Keer, hereby denoted as "the implementer". For more information, feedback or questions, please refer to our websites: http://keccak.noekeon.org/ http://keyak.noekeon.org/ http://ketje.noekeon.org/ To the extent possible under law, the implementer has waived all copyright and related or neighboring rights to the source code in this file. http://creativecommons.org/publicdomain/zero/1.0/ */ #include "KeccakSponge.h" #ifdef KeccakReference #include "displayIntermediateValues.h" #endif #ifndef KeccakP200_excluded #include "KeccakP-200-SnP.h" #define prefix KeccakWidth200 #define SnP KeccakP200 #define SnP_width 200 #define SnP_Permute KeccakP200_Permute_18rounds #if defined(KeccakF200_FastLoop_supported) #define SnP_FastLoop_Absorb KeccakF200_FastLoop_Absorb #endif #include "KeccakSponge.inc" #undef prefix #undef SnP #undef SnP_width #undef SnP_Permute #undef SnP_FastLoop_Absorb #endif #ifndef KeccakP400_excluded #include "KeccakP-400-SnP.h" #define prefix KeccakWidth400 #define SnP KeccakP400 #define SnP_width 400 #define SnP_Permute KeccakP400_Permute_20rounds #if defined(KeccakF400_FastLoop_supported) #define SnP_FastLoop_Absorb KeccakF400_FastLoop_Absorb #endif #include "KeccakSponge.inc" #undef prefix #undef SnP #undef SnP_width #undef SnP_Permute #undef SnP_FastLoop_Absorb #endif #ifndef KeccakP800_excluded #include "KeccakP-800-SnP.h" #define prefix KeccakWidth800 #define SnP KeccakP800 #define SnP_width 800 #define SnP_Permute KeccakP800_Permute_22rounds #if defined(KeccakF800_FastLoop_supported) #define SnP_FastLoop_Absorb KeccakF800_FastLoop_Absorb #endif #include "KeccakSponge.inc" #undef prefix #undef SnP #undef SnP_width #undef SnP_Permute #undef SnP_FastLoop_Absorb #endif #ifndef KeccakP1600_excluded #include "KeccakP-1600-SnP.h" #define prefix KeccakWidth1600 #define SnP KeccakP1600 #define SnP_width 1600 #define SnP_Permute KeccakP1600_Permute_24rounds #if defined(KeccakF1600_FastLoop_supported) #define SnP_FastLoop_Absorb KeccakF1600_FastLoop_Absorb #endif #include "KeccakSponge.inc" #undef prefix #undef SnP #undef SnP_width #undef SnP_Permute #undef SnP_FastLoop_Absorb #endif #ifndef KeccakP1600_excluded #include "KeccakP-1600-SnP.h" #define prefix KeccakWidth1600_12rounds #define SnP KeccakP1600 #define SnP_width 1600 #define SnP_Permute KeccakP1600_Permute_12rounds #if defined(KeccakP1600_12rounds_FastLoop_supported) #define SnP_FastLoop_Absorb KeccakP1600_12rounds_FastLoop_Absorb #endif #include "KeccakSponge.inc" #undef prefix #undef SnP #undef SnP_width #undef SnP_Permute #undef SnP_FastLoop_Absorb #endif
3,049
26.477477
75
c
php-src
php-src-master/ext/hash/sha3/generic64lc/align.h
/* Implementation by the Keccak, Keyak and Ketje Teams, namely, Guido Bertoni, Joan Daemen, Michaël Peeters, Gilles Van Assche and Ronny Van Keer, hereby denoted as "the implementer". For more information, feedback or questions, please refer to our websites: http://keccak.noekeon.org/ http://keyak.noekeon.org/ http://ketje.noekeon.org/ To the extent possible under law, the implementer has waived all copyright and related or neighboring rights to the source code in this file. http://creativecommons.org/publicdomain/zero/1.0/ */ #ifndef _align_h_ #define _align_h_ /* on Mac OS-X and possibly others, ALIGN(x) is defined in param.h, and -Werror chokes on the redef. */ #ifdef ALIGN #undef ALIGN #endif #if defined(__GNUC__) #define ALIGN(x) __attribute__ ((aligned(x))) #elif defined(_MSC_VER) #define ALIGN(x) __declspec(align(x)) #elif defined(__ARMCC_VERSION) #define ALIGN(x) __align(x) #else #define ALIGN(x) #endif #endif
938
25.828571
103
h
php-src
php-src-master/ext/hash/sha3/generic64lc/brg_endian.h
/* --------------------------------------------------------------------------- Copyright (c) 1998-2008, Brian Gladman, Worcester, UK. All rights reserved. LICENSE TERMS The redistribution and use of this software (with or without changes) is allowed without the payment of fees or royalties provided that: 1. source code distributions include the above copyright notice, this list of conditions and the following disclaimer; 2. binary distributions include the above copyright notice, this list of conditions and the following disclaimer in their documentation; 3. the name of the copyright holder is not used to endorse products built using this software without specific written permission. DISCLAIMER This software is provided 'as is' with no explicit or implied warranties in respect of its properties, including, but not limited to, correctness and/or fitness for purpose. --------------------------------------------------------------------------- Issue Date: 20/12/2007 Changes for ARM 9/9/2010 */ #ifndef _BRG_ENDIAN_H #define _BRG_ENDIAN_H #define IS_BIG_ENDIAN 4321 /* byte 0 is most significant (mc68k) */ #define IS_LITTLE_ENDIAN 1234 /* byte 0 is least significant (i386) */ #if 0 /* Include files where endian defines and byteswap functions may reside */ #if defined( __sun ) # include <sys/isa_defs.h> #elif defined( __FreeBSD__ ) || defined( __OpenBSD__ ) || defined( __NetBSD__ ) # include <sys/endian.h> #elif defined( BSD ) && ( BSD >= 199103 ) || defined( __APPLE__ ) || \ defined( __CYGWIN32__ ) || defined( __DJGPP__ ) || defined( __osf__ ) # include <machine/endian.h> #elif defined( __linux__ ) || defined( __GNUC__ ) || defined( __GNU_LIBRARY__ ) # if !defined( __MINGW32__ ) && !defined( _AIX ) # include <endian.h> # if !defined( __BEOS__ ) # include <byteswap.h> # endif # endif #endif #endif /* Now attempt to set the define for platform byte order using any */ /* of the four forms SYMBOL, _SYMBOL, __SYMBOL & __SYMBOL__, which */ /* seem to encompass most endian symbol definitions */ #if defined( BIG_ENDIAN ) && defined( LITTLE_ENDIAN ) # if defined( BYTE_ORDER ) && BYTE_ORDER == BIG_ENDIAN # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN # elif defined( BYTE_ORDER ) && BYTE_ORDER == LITTLE_ENDIAN # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN # endif #elif defined( BIG_ENDIAN ) # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN #elif defined( LITTLE_ENDIAN ) # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN #endif #if defined( _BIG_ENDIAN ) && defined( _LITTLE_ENDIAN ) # if defined( _BYTE_ORDER ) && _BYTE_ORDER == _BIG_ENDIAN # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN # elif defined( _BYTE_ORDER ) && _BYTE_ORDER == _LITTLE_ENDIAN # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN # endif #elif defined( _BIG_ENDIAN ) # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN #elif defined( _LITTLE_ENDIAN ) # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN #endif #if defined( __BIG_ENDIAN ) && defined( __LITTLE_ENDIAN ) # if defined( __BYTE_ORDER ) && __BYTE_ORDER == __BIG_ENDIAN # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN # elif defined( __BYTE_ORDER ) && __BYTE_ORDER == __LITTLE_ENDIAN # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN # endif #elif defined( __BIG_ENDIAN ) # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN #elif defined( __LITTLE_ENDIAN ) # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN #endif #if defined( __BIG_ENDIAN__ ) && defined( __LITTLE_ENDIAN__ ) # if defined( __BYTE_ORDER__ ) && __BYTE_ORDER__ == __BIG_ENDIAN__ # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN # elif defined( __BYTE_ORDER__ ) && __BYTE_ORDER__ == __LITTLE_ENDIAN__ # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN # endif #elif defined( __BIG_ENDIAN__ ) # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN #elif defined( __LITTLE_ENDIAN__ ) # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN #endif /* if the platform byte order could not be determined, then try to */ /* set this define using common machine defines */ #if !defined(PLATFORM_BYTE_ORDER) #if defined( __alpha__ ) || defined( __alpha ) || defined( i386 ) || \ defined( __i386__ ) || defined( _M_I86 ) || defined( _M_IX86 ) || \ defined( __OS2__ ) || defined( sun386 ) || defined( __TURBOC__ ) || \ defined( vax ) || defined( vms ) || defined( VMS ) || \ defined( __VMS ) || defined( _M_X64 ) # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN #elif defined( AMIGA ) || defined( applec ) || defined( __AS400__ ) || \ defined( _CRAY ) || defined( __hppa ) || defined( __hp9000 ) || \ defined( ibm370 ) || defined( mc68000 ) || defined( m68k ) || \ defined( __MRC__ ) || defined( __MVS__ ) || defined( __MWERKS__ ) || \ defined( sparc ) || defined( __sparc) || defined( SYMANTEC_C ) || \ defined( __VOS__ ) || defined( __TIGCC__ ) || defined( __TANDEM ) || \ defined( THINK_C ) || defined( __VMCMS__ ) || defined( _AIX ) # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN #elif defined(__arm__) # ifdef __BIG_ENDIAN # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN # else # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN # endif #elif 1 /* **** EDIT HERE IF NECESSARY **** */ # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN #elif 0 /* **** EDIT HERE IF NECESSARY **** */ # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN #else # error Please edit lines 132 or 134 in brg_endian.h to set the platform byte order #endif #endif #endif
5,546
37.79021
84
h
php-src
php-src-master/ext/iconv/iconv_arginfo.h
/* This is a generated file, edit the .stub.php file instead. * Stub hash: 4367fa431d3e4814e42d9aa514c10cae1d842d8f */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_iconv_strlen, 0, 1, MAY_BE_LONG|MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, encoding, IS_STRING, 1, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_iconv_substr, 0, 2, MAY_BE_STRING|MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, offset, IS_LONG, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, length, IS_LONG, 1, "null") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, encoding, IS_STRING, 1, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_iconv_strpos, 0, 2, MAY_BE_LONG|MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, haystack, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, needle, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, offset, IS_LONG, 0, "0") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, encoding, IS_STRING, 1, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_iconv_strrpos, 0, 2, MAY_BE_LONG|MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, haystack, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, needle, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, encoding, IS_STRING, 1, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_iconv_mime_encode, 0, 2, MAY_BE_STRING|MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, field_name, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, field_value, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, options, IS_ARRAY, 0, "[]") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_iconv_mime_decode, 0, 1, MAY_BE_STRING|MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, mode, IS_LONG, 0, "0") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, encoding, IS_STRING, 1, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_iconv_mime_decode_headers, 0, 1, MAY_BE_ARRAY|MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, headers, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, mode, IS_LONG, 0, "0") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, encoding, IS_STRING, 1, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_iconv, 0, 3, MAY_BE_STRING|MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, from_encoding, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, to_encoding, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_iconv_set_encoding, 0, 2, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO(0, type, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, encoding, IS_STRING, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_iconv_get_encoding, 0, 0, MAY_BE_ARRAY|MAY_BE_STRING|MAY_BE_FALSE) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, type, IS_STRING, 0, "\"all\"") ZEND_END_ARG_INFO() ZEND_FUNCTION(iconv_strlen); ZEND_FUNCTION(iconv_substr); ZEND_FUNCTION(iconv_strpos); ZEND_FUNCTION(iconv_strrpos); ZEND_FUNCTION(iconv_mime_encode); ZEND_FUNCTION(iconv_mime_decode); ZEND_FUNCTION(iconv_mime_decode_headers); ZEND_FUNCTION(iconv); ZEND_FUNCTION(iconv_set_encoding); ZEND_FUNCTION(iconv_get_encoding); static const zend_function_entry ext_functions[] = { ZEND_FE(iconv_strlen, arginfo_iconv_strlen) ZEND_FE(iconv_substr, arginfo_iconv_substr) ZEND_FE(iconv_strpos, arginfo_iconv_strpos) ZEND_FE(iconv_strrpos, arginfo_iconv_strrpos) ZEND_FE(iconv_mime_encode, arginfo_iconv_mime_encode) ZEND_FE(iconv_mime_decode, arginfo_iconv_mime_decode) ZEND_FE(iconv_mime_decode_headers, arginfo_iconv_mime_decode_headers) ZEND_FE(iconv, arginfo_iconv) ZEND_FE(iconv_set_encoding, arginfo_iconv_set_encoding) ZEND_FE(iconv_get_encoding, arginfo_iconv_get_encoding) ZEND_FE_END }; static void register_iconv_symbols(int module_number) { REGISTER_STRING_CONSTANT("ICONV_IMPL", PHP_ICONV_IMPL_VALUE, CONST_PERSISTENT); REGISTER_STRING_CONSTANT("ICONV_VERSION", get_iconv_version(), CONST_PERSISTENT); REGISTER_LONG_CONSTANT("ICONV_MIME_DECODE_STRICT", PHP_ICONV_MIME_DECODE_STRICT, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("ICONV_MIME_DECODE_CONTINUE_ON_ERROR", PHP_ICONV_MIME_DECODE_CONTINUE_ON_ERROR, CONST_PERSISTENT); }
4,255
43.333333
122
h
php-src
php-src-master/ext/imap/php_imap.h
/* +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Rex Logan <[email protected]> | | Mark Musone <[email protected]> | | Brian Wang <[email protected]> | | Kaj-Michael Lang <[email protected]> | | Antoni Pamies Olive <[email protected]> | | Rasmus Lerdorf <[email protected]> | | Chuck Hagenbuch <[email protected]> | | Andrew Skalski <[email protected]> | | Hartmut Holzgraefe <[email protected]> | | Jani Taskinen <[email protected]> | | Daniel R. Kalowsky <[email protected]> | | PHP 4.0 updates: Zeev Suraski <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef PHP_IMAP_H #define PHP_IMAP_H #ifdef HAVE_IMAP #if defined(HAVE_IMAP2000) || defined(HAVE_IMAP2001) /* For now these appear on Windows, remove this check if it appears outside */ # ifdef PHP_WIN32 /* Undefine these LOG defines to avoid warnings */ # undef LOG_EMERG # undef LOG_CRIT # undef LOG_ERR # undef LOG_WARNING # undef LOG_NOTICE # undef LOG_DEBUG /* c-client also redefines its own ftruncate */ # undef ftruncate # endif /* these are used for quota support */ ZEND_CGG_DIAGNOSTIC_IGNORED_START("-Wstrict-prototypes") # include "c-client.h" /* includes mail.h and rfc822.h */ ZEND_CGG_DIAGNOSTIC_IGNORED_END # include "imap4r1.h" /* location of c-client quota functions */ #else # include "mail.h" # include "rfc822.h" #endif extern zend_module_entry imap_module_entry; #define imap_module_ptr &imap_module_entry #include "php_version.h" #define PHP_IMAP_VERSION PHP_VERSION /* Data types */ #ifdef IMAP41 #define LSIZE text.size #define LTEXT text.data #define DTYPE int #define CONTENT_PART nested.part #define CONTENT_MSG_BODY nested.msg->body #define IMAPVER "Imap 4R1" #else #define LSIZE size #define LTEXT text #define DTYPE char #define CONTENT_PART contents.part #define CONTENT_MSG_BODY contents.msg.body #define IMAPVER "Imap 4" #endif /* Determines how mm_list() and mm_lsub() are to return their results. */ typedef enum { FLIST_ARRAY, FLIST_OBJECT } folderlist_style_t; typedef struct php_imap_mailbox_struct { SIZEDTEXT text; DTYPE delimiter; long attributes; struct php_imap_mailbox_struct *next; } FOBJECTLIST; typedef struct php_imap_error_struct { SIZEDTEXT text; long errflg; struct php_imap_error_struct *next; } ERRORLIST; typedef struct _php_imap_message_struct { unsigned long msgid; struct _php_imap_message_struct *next; } MESSAGELIST; /* Functions */ PHP_MINIT_FUNCTION(imap); PHP_RINIT_FUNCTION(imap); PHP_RSHUTDOWN_FUNCTION(imap); PHP_MINFO_FUNCTION(imap); ZEND_BEGIN_MODULE_GLOBALS(imap) char *imap_user; char *imap_password; STRINGLIST *imap_alertstack; ERRORLIST *imap_errorstack; STRINGLIST *imap_folders; STRINGLIST *imap_folders_tail; STRINGLIST *imap_sfolders; STRINGLIST *imap_sfolders_tail; MESSAGELIST *imap_messages; MESSAGELIST *imap_messages_tail; FOBJECTLIST *imap_folder_objects; FOBJECTLIST *imap_folder_objects_tail; FOBJECTLIST *imap_sfolder_objects; FOBJECTLIST *imap_sfolder_objects_tail; folderlist_style_t folderlist_style; long status_flags; unsigned long status_messages; unsigned long status_recent; unsigned long status_unseen; unsigned long status_uidnext; unsigned long status_uidvalidity; #if defined(HAVE_IMAP2000) || defined(HAVE_IMAP2001) zval **quota_return; zval *imap_acl_list; #endif /* php_stream for php_mail_gets() */ php_stream *gets_stream; bool enable_rsh; ZEND_END_MODULE_GLOBALS(imap) #if defined(ZTS) && defined(COMPILE_DL_IMAP) ZEND_TSRMLS_CACHE_EXTERN() #endif ZEND_EXTERN_MODULE_GLOBALS(imap) #define IMAPG(v) ZEND_MODULE_GLOBALS_ACCESSOR(imap, v) #else #define imap_module_ptr NULL #endif #define phpext_imap_ptr imap_module_ptr #endif /* PHP_IMAP_H */
4,957
28.86747
79
h
php-src
php-src-master/ext/intl/intl_common.h
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Vadim Savchuk <[email protected]> | | Dmitry Lakhtyuk <[email protected]> | | Stanislav Malyshev <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef INTL_COMMON_H #define INTL_COMMON_H /* Auxiliary macros */ BEGIN_EXTERN_C() #include <php.h> END_EXTERN_C() #include <unicode/utypes.h> #ifndef UBYTES # define UBYTES(len) ((len) * sizeof(UChar)) #endif #ifndef eumalloc # define eumalloc(size) (UChar*)safe_emalloc(size, sizeof(UChar), 0) #endif #ifndef eurealloc # define eurealloc(ptr, size) (UChar*)erealloc((ptr), size * sizeof(UChar)) #endif #define USIZE(data) sizeof((data))/sizeof(UChar) #define UCHARS(len) ((len) / sizeof(UChar)) #define INTL_ZSTR_VAL(str) (UChar*) ZSTR_VAL(str) #define INTL_ZSTR_LEN(str) UCHARS(ZSTR_LEN(str)) BEGIN_EXTERN_C() extern zend_class_entry *IntlException_ce_ptr; END_EXTERN_C() #endif /* INTL_COMMON_H */
1,709
33.897959
76
h
php-src
php-src-master/ext/intl/intl_convert.c
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Vadim Savchuk <[email protected]> | | Dmitry Lakhtyuk <[email protected]> | +----------------------------------------------------------------------+ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include <php.h> #include "intl_common.h" #include "intl_convert.h" /* {{{ intl_convert_utf8_to_utf16 * Convert given string from UTF-8 to UTF-16 to *target buffer. * * It *target is NULL then we allocate a large enough buffer, * store the converted string into it, and make target point to it. * * Otherwise, if *target is non-NULL, we assume that it points to a * dynamically allocated buffer of *target_len bytes length. * In this case the buffer will be used to store the converted string to, * and may be resized (made larger) if needed. * * Note that ICU uses int32_t as string length and PHP uses size_t. While * it is not likely in practical situations to have strings longer than * INT32_MAX, these are different types and need to be handled carefully. * * @param target Where to place the result. * @param target_len Result length. * @param source String to convert. * @param source_len Length of the source string. * @param status Conversion status. * * @return void This function does not return anything. */ void intl_convert_utf8_to_utf16( UChar** target, int32_t* target_len, const char* src, size_t src_len, UErrorCode* status ) { UChar* dst_buf = NULL; int32_t dst_len = 0; /* If *target is NULL determine required destination buffer size (pre-flighting). * Otherwise, attempt to convert source string; if *target buffer is not large enough * it will be resized appropriately. */ *status = U_ZERO_ERROR; if(src_len > INT32_MAX) { /* we cannot fit this string */ *status = U_BUFFER_OVERFLOW_ERROR; return; } u_strFromUTF8( *target, *target_len, &dst_len, src, (int32_t)src_len, status ); if( *status == U_ZERO_ERROR ) { /* String is converted successfully */ (*target)[dst_len] = 0; *target_len = dst_len; return; } /* Bail out if an unexpected error occurred. * (U_BUFFER_OVERFLOW_ERROR means that *target buffer is not large enough). * (U_STRING_NOT_TERMINATED_WARNING usually means that the input string is empty). */ if( *status != U_BUFFER_OVERFLOW_ERROR && *status != U_STRING_NOT_TERMINATED_WARNING ) return; /* Allocate memory for the destination buffer (it will be zero-terminated). */ dst_buf = eumalloc( dst_len + 1 ); /* Convert source string from UTF-8 to UTF-16. */ *status = U_ZERO_ERROR; u_strFromUTF8( dst_buf, dst_len+1, NULL, src, src_len, status ); if( U_FAILURE( *status ) ) { efree( dst_buf ); return; } dst_buf[dst_len] = 0; if( *target ) efree( *target ); *target = dst_buf; *target_len = dst_len; } /* }}} */ /* {{{ intl_convert_utf16_to_utf8 * Convert given string from UTF-16 to UTF-8. * * @param source String to convert. * @param source_len Length of the source string. * @param status Conversion status. * * @return zend_string */ zend_string* intl_convert_utf16_to_utf8( const UChar* src, int32_t src_len, UErrorCode* status ) { zend_string* dst; int32_t dst_len; /* Determine required destination buffer size (pre-flighting). */ *status = U_ZERO_ERROR; u_strToUTF8( NULL, 0, &dst_len, src, src_len, status ); /* Bail out if an unexpected error occurred. * (U_BUFFER_OVERFLOW_ERROR means that *target buffer is not large enough). * (U_STRING_NOT_TERMINATED_WARNING usually means that the input string is empty). */ if( *status != U_BUFFER_OVERFLOW_ERROR && *status != U_STRING_NOT_TERMINATED_WARNING ) return NULL; /* Allocate memory for the destination buffer (it will be zero-terminated). */ dst = zend_string_alloc(dst_len, 0); /* Convert source string from UTF-8 to UTF-16. */ *status = U_ZERO_ERROR; u_strToUTF8( ZSTR_VAL(dst), dst_len, NULL, src, src_len, status ); if( U_FAILURE( *status ) ) { zend_string_efree(dst); return NULL; } /* U_STRING_NOT_TERMINATED_WARNING is OK for us => reset 'status'. */ *status = U_ZERO_ERROR; ZSTR_VAL(dst)[dst_len] = 0; return dst; } /* }}} */
4,910
31.098039
87
c
php-src
php-src-master/ext/intl/intl_convert.h
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Vadim Savchuk <[email protected]> | | Dmitry Lakhtyuk <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef INTL_CONVERT_H #define INTL_CONVERT_H #include <unicode/ustring.h> void intl_convert_utf8_to_utf16( UChar** target, int32_t* target_len, const char* src, size_t src_len, UErrorCode* status ); zend_string* intl_convert_utf16_to_utf8( const UChar* src, int32_t src_len, UErrorCode* status ); #endif // INTL_CONVERT_H
1,265
39.83871
75
h
php-src
php-src-master/ext/intl/intl_convertcpp.h
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Gustavo Lopes <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef INTL_CONVERTCPP_H #define INTL_CONVERTCPP_H #ifndef __cplusplus #error Should be included only in C++ Files #endif #include <unicode/unistr.h> #include <zend_types.h> using icu::UnicodeString; int intl_stringFromChar(UnicodeString &ret, char *str, size_t str_len, UErrorCode *status); zend_string* intl_charFromString(const UnicodeString &from, UErrorCode *status); #endif /* INTL_CONVERTCPP_H */
1,254
38.21875
91
h
php-src
php-src-master/ext/intl/intl_cppshims.h
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Gustavo Lopes <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef INTL_CPPSHIMS_H #define INTL_CPPSHIMS_H #ifndef __cplusplus #error For inclusion form C++ files only #endif #ifdef _MSC_VER //This is only required for old versions of ICU only #include <stdio.h> #include <math.h> /* avoid redefinition of int8_t, also defined in unicode/pwin32.h */ #define _MSC_STDINT_H_ 1 #endif #endif
1,178
34.727273
75
h
php-src
php-src-master/ext/intl/intl_data.h
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Vadim Savchuk <[email protected]> | | Dmitry Lakhtyuk <[email protected]> | | Stanislav Malyshev <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef INTL_DATA_H #define INTL_DATA_H #include <unicode/utypes.h> #include "intl_error.h" /* Mock object to generalize error handling in sub-modules. Sub-module data structures should always have error as first element for this to work! */ typedef struct _intl_data { intl_error error; zend_object zo; } intl_object; #define INTL_METHOD_INIT_VARS(oclass, obj) \ zval* object = NULL; \ oclass##_object* obj = NULL; \ intl_error_reset( NULL ); #define INTL_DATA_ERROR(obj) (((intl_object *)(obj))->error) #define INTL_DATA_ERROR_P(obj) (&(INTL_DATA_ERROR((obj)))) #define INTL_DATA_ERROR_CODE(obj) INTL_ERROR_CODE(INTL_DATA_ERROR((obj))) #define INTL_METHOD_FETCH_OBJECT(oclass, obj) \ obj = Z_##oclass##_P( object ); \ intl_error_reset( INTL_DATA_ERROR_P(obj) ); \ /* Check status by error code, if error return false */ #define INTL_CHECK_STATUS(err, msg) \ intl_error_set_code( NULL, (err) ); \ if( U_FAILURE((err)) ) \ { \ intl_error_set_custom_msg( NULL, msg, 0 ); \ RETURN_FALSE; \ } /* Check status by error code, if error return null */ #define INTL_CHECK_STATUS_OR_NULL(err, msg) \ intl_error_set_code( NULL, (err) ); \ if( U_FAILURE((err)) ) \ { \ intl_error_set_custom_msg( NULL, msg, 0 ); \ RETURN_NULL(); \ } /* Check status in object, if error return false */ #define INTL_METHOD_CHECK_STATUS(obj, msg) \ intl_error_set_code( NULL, INTL_DATA_ERROR_CODE((obj)) ); \ if( U_FAILURE( INTL_DATA_ERROR_CODE((obj)) ) ) \ { \ intl_errors_set_custom_msg( INTL_DATA_ERROR_P((obj)), msg, 0 ); \ RETURN_FALSE; \ } /* Check status in object, if error goto a label */ #define INTL_METHOD_CHECK_STATUS_OR_GOTO(obj, msg, label) \ intl_error_set_code( NULL, INTL_DATA_ERROR_CODE((obj)) ); \ if( U_FAILURE( INTL_DATA_ERROR_CODE((obj)) ) ) \ { \ intl_errors_set_custom_msg( INTL_DATA_ERROR_P((obj)), msg, 0 ); \ RETVAL_FALSE; \ goto label; \ } /* Check status in object, if error return null */ #define INTL_METHOD_CHECK_STATUS_OR_NULL(obj, msg) \ intl_error_set_code( NULL, INTL_DATA_ERROR_CODE((obj)) ); \ if( U_FAILURE( INTL_DATA_ERROR_CODE((obj)) ) ) \ { \ intl_errors_set_custom_msg( INTL_DATA_ERROR_P((obj)), msg, 0 ); \ zval_ptr_dtor(return_value); \ RETURN_NULL(); \ } /* Check status in object, if error return FAILURE */ #define INTL_CTOR_CHECK_STATUS(obj, msg) \ intl_error_set_code( NULL, INTL_DATA_ERROR_CODE((obj)) ); \ if( U_FAILURE( INTL_DATA_ERROR_CODE((obj)) ) ) \ { \ intl_errors_set_custom_msg( INTL_DATA_ERROR_P((obj)), msg, 0 ); \ return FAILURE; \ } #define INTL_METHOD_RETVAL_UTF8(obj, ustring, ulen, free_it) \ { \ zend_string *u8str; \ u8str = intl_convert_utf16_to_utf8(ustring, ulen, &INTL_DATA_ERROR_CODE((obj))); \ if((free_it)) { \ efree(ustring); \ } \ INTL_METHOD_CHECK_STATUS((obj), "Error converting value to UTF-8"); \ RETVAL_NEW_STR(u8str); \ } #define INTL_MAX_LOCALE_LEN (ULOC_FULLNAME_CAPACITY-1) #define INTL_CHECK_LOCALE_LEN(locale_len) \ if((locale_len) > INTL_MAX_LOCALE_LEN) { \ char *_msg; \ spprintf(&_msg, 0, "Locale string too long, should be no longer than %d characters", INTL_MAX_LOCALE_LEN); \ intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, _msg, 1); \ efree(_msg); \ RETURN_NULL(); \ } #define INTL_CHECK_LOCALE_LEN_OR_FAILURE(locale_len) \ if((locale_len) > INTL_MAX_LOCALE_LEN) { \ char *_msg; \ spprintf(&_msg, 0, "Locale string too long, should be no longer than %d characters", INTL_MAX_LOCALE_LEN); \ intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, _msg, 1); \ efree(_msg); \ return FAILURE; \ } #endif // INTL_DATA_H
5,460
39.451852
112
h
php-src
php-src-master/ext/intl/intl_error.c
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Vadim Savchuk <[email protected]> | | Dmitry Lakhtyuk <[email protected]> | | Stanislav Malyshev <[email protected]> | +----------------------------------------------------------------------+ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include <php.h> #include <zend_exceptions.h> #include "php_intl.h" #include "intl_error.h" #include "intl_convert.h" ZEND_EXTERN_MODULE_GLOBALS( intl ) zend_class_entry *IntlException_ce_ptr; /* {{{ Return global error structure. */ static intl_error* intl_g_error_get( void ) { return &INTL_G( g_error ); } /* }}} */ /* {{{ Free mem. */ static void intl_free_custom_error_msg( intl_error* err ) { if( !err && !( err = intl_g_error_get( ) ) ) return; if(err->free_custom_error_message ) { efree( err->custom_error_message ); } err->custom_error_message = NULL; err->free_custom_error_message = 0; } /* }}} */ /* {{{ Create and initialize internals of 'intl_error'. */ intl_error* intl_error_create( void ) { intl_error* err = ecalloc( 1, sizeof( intl_error ) ); intl_error_init( err ); return err; } /* }}} */ /* {{{ Initialize internals of 'intl_error'. */ void intl_error_init( intl_error* err ) { if( !err && !( err = intl_g_error_get( ) ) ) return; err->code = U_ZERO_ERROR; err->custom_error_message = NULL; err->free_custom_error_message = 0; } /* }}} */ /* {{{ Set last error code to 0 and unset last error message */ void intl_error_reset( intl_error* err ) { if( !err && !( err = intl_g_error_get( ) ) ) return; err->code = U_ZERO_ERROR; intl_free_custom_error_msg( err ); } /* }}} */ /* {{{ Set last error message to msg copying it if needed. */ void intl_error_set_custom_msg( intl_error* err, const char* msg, int copyMsg ) { if( !msg ) return; if( !err ) { if( INTL_G( error_level ) ) php_error_docref( NULL, INTL_G( error_level ), "%s", msg ); if( INTL_G( use_exceptions ) ) zend_throw_exception_ex( IntlException_ce_ptr, 0, "%s", msg ); } if( !err && !( err = intl_g_error_get( ) ) ) return; /* Free previous message if any */ intl_free_custom_error_msg( err ); /* Mark message copied if any */ err->free_custom_error_message = copyMsg; /* Set user's error text message */ err->custom_error_message = copyMsg ? estrdup( msg ) : (char *) msg; } /* }}} */ /* {{{ Create output message in format "<intl_error_text>: <extra_user_error_text>". */ zend_string * intl_error_get_message( intl_error* err ) { const char *uErrorName = NULL; zend_string *errMessage = 0; if( !err && !( err = intl_g_error_get( ) ) ) return ZSTR_EMPTY_ALLOC(); uErrorName = u_errorName( err->code ); /* Format output string */ if( err->custom_error_message ) { errMessage = strpprintf(0, "%s: %s", err->custom_error_message, uErrorName ); } else { errMessage = strpprintf(0, "%s", uErrorName ); } return errMessage; } /* }}} */ /* {{{ Set last error code. */ void intl_error_set_code( intl_error* err, UErrorCode err_code ) { if( !err && !( err = intl_g_error_get( ) ) ) return; err->code = err_code; } /* }}} */ /* {{{ Return last error code. */ UErrorCode intl_error_get_code( intl_error* err ) { if( !err && !( err = intl_g_error_get( ) ) ) return U_ZERO_ERROR; return err->code; } /* }}} */ /* {{{ Set error code and message. */ void intl_error_set( intl_error* err, UErrorCode code, const char* msg, int copyMsg ) { intl_error_set_code( err, code ); intl_error_set_custom_msg( err, msg, copyMsg ); } /* }}} */ /* {{{ Set error code and message. */ void intl_errors_set( intl_error* err, UErrorCode code, const char* msg, int copyMsg ) { intl_errors_set_code( err, code ); intl_errors_set_custom_msg( err, msg, copyMsg ); } /* }}} */ /* {{{ */ void intl_errors_reset( intl_error* err ) { if(err) { intl_error_reset( err ); } intl_error_reset( NULL ); } /* }}} */ /* {{{ */ void intl_errors_set_custom_msg( intl_error* err, const char* msg, int copyMsg ) { if(err) { intl_error_set_custom_msg( err, msg, copyMsg ); } intl_error_set_custom_msg( NULL, msg, copyMsg ); } /* }}} */ /* {{{ */ void intl_errors_set_code( intl_error* err, UErrorCode err_code ) { if(err) { intl_error_set_code( err, err_code ); } intl_error_set_code( NULL, err_code ); } /* }}} */ smart_str intl_parse_error_to_string( UParseError* pe ) { smart_str ret = {0}; zend_string *u8str; UErrorCode status; int any = 0; assert( pe != NULL ); smart_str_appends( &ret, "parse error " ); if( pe->line > 0 ) { smart_str_appends( &ret, "on line " ); smart_str_append_long( &ret, (zend_long ) pe->line ); any = 1; } if( pe->offset >= 0 ) { if( any ) smart_str_appends( &ret, ", " ); else smart_str_appends( &ret, "at " ); smart_str_appends( &ret, "offset " ); smart_str_append_long( &ret, (zend_long ) pe->offset ); any = 1; } if (pe->preContext[0] != 0 ) { if( any ) smart_str_appends( &ret, ", " ); smart_str_appends( &ret, "after \"" ); u8str = intl_convert_utf16_to_utf8(pe->preContext, -1, &status ); if( !u8str ) { smart_str_appends( &ret, "(could not convert parser error pre-context to UTF-8)" ); } else { smart_str_append( &ret, u8str ); zend_string_release_ex( u8str, 0 ); } smart_str_appends( &ret, "\"" ); any = 1; } if( pe->postContext[0] != 0 ) { if( any ) smart_str_appends( &ret, ", " ); smart_str_appends( &ret, "before or at \"" ); u8str = intl_convert_utf16_to_utf8(pe->postContext, -1, &status ); if( !u8str ) { smart_str_appends( &ret, "(could not convert parser error post-context to UTF-8)" ); } else { smart_str_append( &ret, u8str ); zend_string_release_ex( u8str, 0 ); } smart_str_appends( &ret, "\"" ); any = 1; } if( !any ) { smart_str_free( &ret ); smart_str_appends( &ret, "no parse error" ); } smart_str_0( &ret ); return ret; }
6,660
22.789286
87
c
php-src
php-src-master/ext/intl/intl_error.h
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Vadim Savchuk <[email protected]> | | Dmitry Lakhtyuk <[email protected]> | | Stanislav Malyshev <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef INTL_ERROR_H #define INTL_ERROR_H #include <unicode/utypes.h> #include <unicode/parseerr.h> #include <zend_smart_str.h> #define INTL_ERROR_CODE(e) (e).code typedef struct _intl_error { UErrorCode code; int free_custom_error_message; char* custom_error_message; } intl_error; intl_error* intl_error_create( void ); void intl_error_init( intl_error* err ); void intl_error_reset( intl_error* err ); void intl_error_set_code( intl_error* err, UErrorCode err_code ); void intl_error_set_custom_msg( intl_error* err, const char* msg, int copyMsg ); void intl_error_set( intl_error* err, UErrorCode code, const char* msg, int copyMsg ); UErrorCode intl_error_get_code( intl_error* err ); zend_string* intl_error_get_message( intl_error* err ); // Wrappers to synchonize object's and global error structures. void intl_errors_reset( intl_error* err ); void intl_errors_set_custom_msg( intl_error* err, const char* msg, int copyMsg ); void intl_errors_set_code( intl_error* err, UErrorCode err_code ); void intl_errors_set( intl_error* err, UErrorCode code, const char* msg, int copyMsg ); // Other error helpers smart_str intl_parse_error_to_string( UParseError* pe ); #endif // INTL_ERROR_H
2,290
43.921569
94
h
php-src
php-src-master/ext/intl/php_intl.c
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Vadim Savchuk <[email protected]> | | Dmitry Lakhtyuk <[email protected]> | | Stanislav Malyshev <[email protected]> | | Kirti Velankar <[email protected]> | +----------------------------------------------------------------------+ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "php_intl.h" #include "intl_error.h" #include "collator/collator_class.h" #include "collator/collator.h" #include "collator/collator_sort.h" #include "collator/collator_convert.h" #include "converter/converter.h" #include "formatter/formatter_class.h" #include "formatter/formatter_format.h" #include "grapheme/grapheme.h" #include "msgformat/msgformat_class.h" #include "normalizer/normalizer_class.h" #include "locale/locale.h" #include "locale/locale_class.h" #include "dateformat/dateformat.h" #include "dateformat/dateformat_class.h" #include "dateformat/dateformat_data.h" #include "dateformat/datepatterngenerator_class.h" #include "resourcebundle/resourcebundle_class.h" #include "transliterator/transliterator.h" #include "transliterator/transliterator_class.h" #include "timezone/timezone_class.h" #include "calendar/calendar_class.h" #include "breakiterator/breakiterator_class.h" #include "breakiterator/breakiterator_iterators.h" #include <unicode/uidna.h> #include "idn/idn.h" #include "uchar/uchar.h" # include "spoofchecker/spoofchecker_class.h" #include "common/common_enum.h" #include <unicode/uloc.h> #include <unicode/uclean.h> #include <ext/standard/info.h> #include "php_ini.h" #include "php_intl_arginfo.h" /* * locale_get_default has a conflict since ICU also has * a function with the same name * in fact ICU appends the version no. to it also * Hence the following undef for ICU version * Same true for the locale_set_default function */ #undef locale_get_default #undef locale_set_default ZEND_DECLARE_MODULE_GLOBALS( intl ) const char *intl_locale_get_default( void ) { if( INTL_G(default_locale) == NULL ) { return uloc_getDefault(); } return INTL_G(default_locale); } /* {{{ INI Settings */ PHP_INI_BEGIN() STD_PHP_INI_ENTRY(LOCALE_INI_NAME, NULL, PHP_INI_ALL, OnUpdateStringUnempty, default_locale, zend_intl_globals, intl_globals) STD_PHP_INI_ENTRY("intl.error_level", "0", PHP_INI_ALL, OnUpdateLong, error_level, zend_intl_globals, intl_globals) STD_PHP_INI_BOOLEAN("intl.use_exceptions", "0", PHP_INI_ALL, OnUpdateBool, use_exceptions, zend_intl_globals, intl_globals) PHP_INI_END() /* }}} */ static PHP_GINIT_FUNCTION(intl); /* {{{ intl_module_entry */ zend_module_entry intl_module_entry = { STANDARD_MODULE_HEADER, "intl", ext_functions, PHP_MINIT( intl ), PHP_MSHUTDOWN( intl ), PHP_RINIT( intl ), PHP_RSHUTDOWN( intl ), PHP_MINFO( intl ), PHP_INTL_VERSION, PHP_MODULE_GLOBALS(intl), /* globals descriptor */ PHP_GINIT(intl), /* globals ctor */ NULL, /* globals dtor */ NULL, /* post deactivate */ STANDARD_MODULE_PROPERTIES_EX }; /* }}} */ #ifdef COMPILE_DL_INTL #ifdef ZTS ZEND_TSRMLS_CACHE_DEFINE() #endif ZEND_GET_MODULE( intl ) #endif /* {{{ intl_init_globals */ static PHP_GINIT_FUNCTION(intl) { #if defined(COMPILE_DL_INTL) && defined(ZTS) ZEND_TSRMLS_CACHE_UPDATE(); #endif memset( intl_globals, 0, sizeof(zend_intl_globals) ); } /* }}} */ /* {{{ PHP_MINIT_FUNCTION */ PHP_MINIT_FUNCTION( intl ) { /* For the default locale php.ini setting */ REGISTER_INI_ENTRIES(); register_php_intl_symbols(module_number); /* Register collator symbols and classes */ collator_register_Collator_symbols(module_number); /* Register 'NumberFormatter' PHP class */ formatter_register_class( ); /* Register 'Normalizer' PHP class */ normalizer_register_Normalizer_class( ); /* Register 'Locale' PHP class */ locale_register_Locale_class( ); msgformat_register_class(); /* Register 'DateFormat' PHP class */ dateformat_register_IntlDateFormatter_class( ); /* Register 'IntlDateTimeFormatter' PHP class */ dateformat_register_IntlDatePatternGenerator_class( ); /* Register 'ResourceBundle' PHP class */ resourcebundle_register_class( ); /* Register 'Transliterator' PHP class */ transliterator_register_Transliterator_class( ); /* Register 'IntlTimeZone' PHP class */ timezone_register_IntlTimeZone_class( ); /* Register 'IntlCalendar' PHP class */ calendar_register_IntlCalendar_class( ); /* Register 'Spoofchecker' PHP class */ spoofchecker_register_Spoofchecker_class( ); /* Register 'IntlException' PHP class */ IntlException_ce_ptr = register_class_IntlException(zend_ce_exception); IntlException_ce_ptr->create_object = zend_ce_exception->create_object; /* Register common symbols and classes */ intl_register_common_symbols(module_number); /* Register 'BreakIterator' class */ breakiterator_register_BreakIterator_class( ); /* Register 'IntlPartsIterator' class */ breakiterator_register_IntlPartsIterator_class(); /* Global error handling. */ intl_error_init( NULL ); /* 'Converter' class for codepage conversions */ php_converter_minit(INIT_FUNC_ARGS_PASSTHRU); /* IntlChar class */ php_uchar_minit(INIT_FUNC_ARGS_PASSTHRU); return SUCCESS; } /* }}} */ #define EXPLICIT_CLEANUP_ENV_VAR "INTL_EXPLICIT_CLEANUP" /* {{{ PHP_MSHUTDOWN_FUNCTION */ PHP_MSHUTDOWN_FUNCTION( intl ) { const char *cleanup; /* For the default locale php.ini setting */ UNREGISTER_INI_ENTRIES(); cleanup = getenv(EXPLICIT_CLEANUP_ENV_VAR); if (cleanup != NULL && !(cleanup[0] == '0' && cleanup[1] == '\0')) { u_cleanup(); } return SUCCESS; } /* }}} */ /* {{{ PHP_RINIT_FUNCTION */ PHP_RINIT_FUNCTION( intl ) { return SUCCESS; } /* }}} */ /* {{{ PHP_RSHUTDOWN_FUNCTION */ PHP_RSHUTDOWN_FUNCTION( intl ) { INTL_G(current_collator) = NULL; if (INTL_G(grapheme_iterator)) { grapheme_close_global_iterator( ); INTL_G(grapheme_iterator) = NULL; } intl_error_reset( NULL); return SUCCESS; } /* }}} */ /* {{{ PHP_MINFO_FUNCTION */ PHP_MINFO_FUNCTION( intl ) { #if !UCONFIG_NO_FORMATTING UErrorCode status = U_ZERO_ERROR; const char *tzdata_ver = NULL; #endif php_info_print_table_start(); php_info_print_table_row( 2, "Internationalization support", "enabled" ); php_info_print_table_row( 2, "ICU version", U_ICU_VERSION ); #ifdef U_ICU_DATA_VERSION php_info_print_table_row( 2, "ICU Data version", U_ICU_DATA_VERSION ); #endif #if !UCONFIG_NO_FORMATTING tzdata_ver = ucal_getTZDataVersion(&status); if (U_ZERO_ERROR == status) { php_info_print_table_row( 2, "ICU TZData version", tzdata_ver); } #endif php_info_print_table_row( 2, "ICU Unicode version", U_UNICODE_VERSION ); php_info_print_table_end(); /* For the default locale php.ini setting */ DISPLAY_INI_ENTRIES() ; } /* }}} */
7,531
26.093525
126
c
php-src
php-src-master/ext/intl/php_intl.h
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Vadim Savchuk <[email protected]> | | Dmitry Lakhtyuk <[email protected]> | | Stanislav Malyshev <[email protected]> | | Kirti Velankar <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef PHP_INTL_H #define PHP_INTL_H #include <php.h> /* Even if we're included from C++, don't introduce C++ definitions * because we were included with extern "C". The effect would be that * when the headers defined any method, they would do so with C linkage */ #undef U_SHOW_CPLUSPLUS_API #define U_SHOW_CPLUSPLUS_API 0 #include "collator/collator_sort.h" #include <unicode/ubrk.h> #include "intl_error.h" #include "Zend/zend_exceptions.h" extern zend_module_entry intl_module_entry; #define phpext_intl_ptr &intl_module_entry #ifdef PHP_WIN32 #define PHP_INTL_API __declspec(dllexport) #else #define PHP_INTL_API #endif #ifdef ZTS #include "TSRM.h" #endif ZEND_BEGIN_MODULE_GLOBALS(intl) struct UCollator *current_collator; char* default_locale; collator_compare_func_t compare_func; UBreakIterator* grapheme_iterator; intl_error g_error; zend_long error_level; bool use_exceptions; ZEND_END_MODULE_GLOBALS(intl) #if defined(ZTS) && defined(COMPILE_DL_INTL) ZEND_TSRMLS_CACHE_EXTERN() #endif ZEND_EXTERN_MODULE_GLOBALS(intl) /* Macro to access request-wide global variables. */ #define INTL_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(intl, v) PHP_MINIT_FUNCTION(intl); PHP_MSHUTDOWN_FUNCTION(intl); PHP_RINIT_FUNCTION(intl); PHP_RSHUTDOWN_FUNCTION(intl); PHP_MINFO_FUNCTION(intl); const char *intl_locale_get_default( void ); #define PHP_INTL_VERSION PHP_VERSION #endif /* PHP_INTL_H */
2,478
32.053333
75
h
php-src
php-src-master/ext/intl/breakiterator/breakiterator_class.h
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Gustavo Lopes <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef BREAKITERATOR_CLASS_H #define BREAKITERATOR_CLASS_H //redefinition of inline in PHP headers causes problems, so include this before #include <math.h> #include <php.h> #include "../intl_error.h" #include "../intl_data.h" #ifndef USE_BREAKITERATOR_POINTER typedef void BreakIterator; #else using icu::BreakIterator; #endif typedef struct { // error handling intl_error err; // ICU break iterator BreakIterator* biter; // current text zval text; zend_object zo; } BreakIterator_object; static inline BreakIterator_object *php_intl_breakiterator_fetch_object(zend_object *obj) { return (BreakIterator_object *)((char*)(obj) - XtOffsetOf(BreakIterator_object, zo)); } #define Z_INTL_BREAKITERATOR_P(zv) php_intl_breakiterator_fetch_object(Z_OBJ_P(zv)) #define BREAKITER_ERROR(bio) (bio)->err #define BREAKITER_ERROR_P(bio) &(BREAKITER_ERROR(bio)) #define BREAKITER_ERROR_CODE(bio) INTL_ERROR_CODE(BREAKITER_ERROR(bio)) #define BREAKITER_ERROR_CODE_P(bio) &(INTL_ERROR_CODE(BREAKITER_ERROR(bio))) #define BREAKITER_METHOD_INIT_VARS INTL_METHOD_INIT_VARS(BreakIterator, bio) #define BREAKITER_METHOD_FETCH_OBJECT_NO_CHECK INTL_METHOD_FETCH_OBJECT(INTL_BREAKITERATOR, bio) #define BREAKITER_METHOD_FETCH_OBJECT \ BREAKITER_METHOD_FETCH_OBJECT_NO_CHECK; \ if (bio->biter == NULL) \ { \ zend_throw_error(NULL, "Found unconstructed BreakIterator"); \ RETURN_THROWS(); \ } void breakiterator_object_create(zval *object, BreakIterator *break_iter, int brand_new); void breakiterator_object_construct(zval *object, BreakIterator *break_iter); void breakiterator_register_BreakIterator_class(void); extern zend_class_entry *BreakIterator_ce_ptr, *RuleBasedBreakIterator_ce_ptr; extern zend_object_handlers BreakIterator_handlers; #endif /* #ifndef BREAKITERATOR_CLASS_H */
2,662
33.584416
96
h
php-src
php-src-master/ext/intl/breakiterator/breakiterator_iterators.h
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Gustavo Lopes <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef INTL_BREAKITERATOR_ITERATORS_H #define INTL_BREAKITERATOR_ITERATORS_H #include <unicode/umachine.h> U_CDECL_BEGIN #include <math.h> #include <php.h> U_CDECL_END typedef enum { PARTS_ITERATOR_KEY_SEQUENTIAL, PARTS_ITERATOR_KEY_LEFT, PARTS_ITERATOR_KEY_RIGHT, } parts_iter_key_type; #ifdef __cplusplus void IntlIterator_from_BreakIterator_parts(zval *break_iter_zv, zval *object, parts_iter_key_type key_type); #endif U_CFUNC zend_object_iterator *_breakiterator_get_iterator( zend_class_entry *ce, zval *object, int by_ref); U_CFUNC void breakiterator_register_IntlPartsIterator_class(void); #endif
1,485
35.243902
75
h
php-src
php-src-master/ext/intl/breakiterator/breakiterator_iterators_arginfo.h
/* This is a generated file, edit the .stub.php file instead. * Stub hash: 2b201b4c2f4fb706484085c9fff483d66a7285ea */ ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_OBJ_INFO_EX(arginfo_class_IntlPartsIterator_getBreakIterator, 0, 0, IntlBreakIterator, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_IntlPartsIterator_getRuleStatus, 0, 0, IS_LONG, 0) ZEND_END_ARG_INFO() ZEND_METHOD(IntlPartsIterator, getBreakIterator); ZEND_METHOD(IntlPartsIterator, getRuleStatus); static const zend_function_entry class_IntlPartsIterator_methods[] = { ZEND_ME(IntlPartsIterator, getBreakIterator, arginfo_class_IntlPartsIterator_getBreakIterator, ZEND_ACC_PUBLIC) ZEND_ME(IntlPartsIterator, getRuleStatus, arginfo_class_IntlPartsIterator_getRuleStatus, ZEND_ACC_PUBLIC) ZEND_FE_END }; static zend_class_entry *register_class_IntlPartsIterator(zend_class_entry *class_entry_IntlIterator) { zend_class_entry ce, *class_entry; INIT_CLASS_ENTRY(ce, "IntlPartsIterator", class_IntlPartsIterator_methods); class_entry = zend_register_internal_class_ex(&ce, class_entry_IntlIterator); class_entry->ce_flags |= ZEND_ACC_NOT_SERIALIZABLE; zval const_KEY_SEQUENTIAL_value; ZVAL_LONG(&const_KEY_SEQUENTIAL_value, PARTS_ITERATOR_KEY_SEQUENTIAL); zend_string *const_KEY_SEQUENTIAL_name = zend_string_init_interned("KEY_SEQUENTIAL", sizeof("KEY_SEQUENTIAL") - 1, 1); zend_declare_class_constant_ex(class_entry, const_KEY_SEQUENTIAL_name, &const_KEY_SEQUENTIAL_value, ZEND_ACC_PUBLIC, NULL); zend_string_release(const_KEY_SEQUENTIAL_name); zval const_KEY_LEFT_value; ZVAL_LONG(&const_KEY_LEFT_value, PARTS_ITERATOR_KEY_LEFT); zend_string *const_KEY_LEFT_name = zend_string_init_interned("KEY_LEFT", sizeof("KEY_LEFT") - 1, 1); zend_declare_class_constant_ex(class_entry, const_KEY_LEFT_name, &const_KEY_LEFT_value, ZEND_ACC_PUBLIC, NULL); zend_string_release(const_KEY_LEFT_name); zval const_KEY_RIGHT_value; ZVAL_LONG(&const_KEY_RIGHT_value, PARTS_ITERATOR_KEY_RIGHT); zend_string *const_KEY_RIGHT_name = zend_string_init_interned("KEY_RIGHT", sizeof("KEY_RIGHT") - 1, 1); zend_declare_class_constant_ex(class_entry, const_KEY_RIGHT_name, &const_KEY_RIGHT_value, ZEND_ACC_PUBLIC, NULL); zend_string_release(const_KEY_RIGHT_name); return class_entry; }
2,291
45.77551
126
h
php-src
php-src-master/ext/intl/breakiterator/codepointiterator_internal.h
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Gustavo Lopes <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef CODEPOINTITERATOR_INTERNAL_H #define CODEPOINTITERATOR_INTERNAL_H #include <unicode/brkiter.h> #include <unicode/unistr.h> using icu::BreakIterator; using icu::CharacterIterator; using icu::UnicodeString; namespace PHP { class CodePointBreakIterator : public BreakIterator { public: static UClassID getStaticClassID(); CodePointBreakIterator(); CodePointBreakIterator(const CodePointBreakIterator &other); CodePointBreakIterator& operator=(const CodePointBreakIterator& that); ~CodePointBreakIterator() override; #if U_ICU_VERSION_MAJOR_NUM >= 70 bool operator==(const BreakIterator& that) const override; #else UBool operator==(const BreakIterator& that) const override; #endif CodePointBreakIterator* clone(void) const override; UClassID getDynamicClassID(void) const override; CharacterIterator& getText(void) const override; UText *getUText(UText *fillIn, UErrorCode &status) const override; void setText(const UnicodeString &text) override; void setText(UText *text, UErrorCode &status) override; void adoptText(CharacterIterator* it) override; int32_t first(void) override; int32_t last(void) override; int32_t previous(void) override; int32_t next(void) override; int32_t current(void) const override; int32_t following(int32_t offset) override; int32_t preceding(int32_t offset) override; UBool isBoundary(int32_t offset) override; int32_t next(int32_t n) override; CodePointBreakIterator *createBufferClone(void *stackBuffer, int32_t &BufferSize, UErrorCode &status) override; CodePointBreakIterator &refreshInputText(UText *input, UErrorCode &status) override; inline UChar32 getLastCodePoint() { return this->lastCodePoint; } private: UText *fText; UChar32 lastCodePoint; mutable CharacterIterator *fCharIter; inline void clearCurrentCharIter() { delete this->fCharIter; this->fCharIter = NULL; this->lastCodePoint = U_SENTINEL; } }; } #endif
2,854
26.451923
86
h
php-src
php-src-master/ext/intl/calendar/calendar_class.h
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Gustavo Lopes <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef CALENDAR_CLASS_H #define CALENDAR_CLASS_H //redefinition of inline in PHP headers causes problems, so include this before #include <math.h> #include <php.h> #include "intl_error.h" #include "intl_data.h" #ifndef USE_CALENDAR_POINTER typedef void Calendar; #else using icu::Calendar; #endif typedef struct { // error handling intl_error err; // ICU calendar Calendar* ucal; zend_object zo; } Calendar_object; static inline Calendar_object *php_intl_calendar_fetch_object(zend_object *obj) { return (Calendar_object *)((char*)(obj) - XtOffsetOf(Calendar_object, zo)); } #define Z_INTL_CALENDAR_P(zv) php_intl_calendar_fetch_object(Z_OBJ_P(zv)) #define CALENDAR_ERROR(co) (co)->err #define CALENDAR_ERROR_P(co) &(CALENDAR_ERROR(co)) #define CALENDAR_ERROR_CODE(co) INTL_ERROR_CODE(CALENDAR_ERROR(co)) #define CALENDAR_ERROR_CODE_P(co) &(INTL_ERROR_CODE(CALENDAR_ERROR(co))) #define CALENDAR_METHOD_INIT_VARS INTL_METHOD_INIT_VARS(Calendar, co) #define CALENDAR_METHOD_FETCH_OBJECT_NO_CHECK INTL_METHOD_FETCH_OBJECT(INTL_CALENDAR, co) #define CALENDAR_METHOD_FETCH_OBJECT \ CALENDAR_METHOD_FETCH_OBJECT_NO_CHECK; \ if (co->ucal == NULL) \ { \ zend_throw_error(NULL, "Found unconstructed IntlCalendar"); \ RETURN_THROWS(); \ } void calendar_object_create(zval *object, Calendar *calendar); Calendar *calendar_fetch_native_calendar(zend_object *object); void calendar_object_construct(zval *object, Calendar *calendar); void calendar_register_IntlCalendar_class(void); extern zend_class_entry *Calendar_ce_ptr, *GregorianCalendar_ce_ptr; extern zend_object_handlers Calendar_handlers; #endif /* #ifndef CALENDAR_CLASS_H */
2,513
32.52
89
h
php-src
php-src-master/ext/intl/collator/collator.h
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Vadim Savchuk <[email protected]> | | Dmitry Lakhtyuk <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef COLLATOR_COLLATOR_H #define COLLATOR_COLLATOR_H #include <php.h> #define COLLATOR_SORT_REGULAR 0 #define COLLATOR_SORT_STRING 1 #define COLLATOR_SORT_NUMERIC 2 #endif // COLLATOR_COLLATOR_H
1,128
42.423077
75
h
php-src
php-src-master/ext/intl/collator/collator_attr.c
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Vadim Savchuk <[email protected]> | | Dmitry Lakhtyuk <[email protected]> | +----------------------------------------------------------------------+ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "php_intl.h" #include "collator_class.h" #include "collator_convert.h" #include <unicode/ustring.h> /* {{{ Get collation attribute value. */ PHP_FUNCTION( collator_get_attribute ) { zend_long attribute, value; COLLATOR_METHOD_INIT_VARS /* Parse parameters. */ if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "Ol", &object, Collator_ce_ptr, &attribute ) == FAILURE ) { RETURN_THROWS(); } /* Fetch the object. */ COLLATOR_METHOD_FETCH_OBJECT; value = ucol_getAttribute( co->ucoll, attribute, COLLATOR_ERROR_CODE_P( co ) ); COLLATOR_CHECK_STATUS( co, "Error getting attribute value" ); RETURN_LONG( value ); } /* }}} */ /* {{{ Set collation attribute. */ PHP_FUNCTION( collator_set_attribute ) { zend_long attribute, value; COLLATOR_METHOD_INIT_VARS /* Parse parameters. */ if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "Oll", &object, Collator_ce_ptr, &attribute, &value ) == FAILURE) { RETURN_THROWS(); } /* Fetch the object. */ COLLATOR_METHOD_FETCH_OBJECT; /* Set new value for the given attribute. */ ucol_setAttribute( co->ucoll, attribute, value, COLLATOR_ERROR_CODE_P( co ) ); COLLATOR_CHECK_STATUS( co, "Error setting attribute value" ); RETURN_TRUE; } /* }}} */ /* {{{ Returns the current collation strength. */ PHP_FUNCTION( collator_get_strength ) { COLLATOR_METHOD_INIT_VARS /* Parse parameters. */ if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "O", &object, Collator_ce_ptr ) == FAILURE ) { RETURN_THROWS(); } /* Fetch the object. */ COLLATOR_METHOD_FETCH_OBJECT; /* Get current strength and return it. */ RETURN_LONG( ucol_getStrength( co->ucoll ) ); } /* }}} */ /* {{{ Set the collation strength. */ PHP_FUNCTION( collator_set_strength ) { zend_long strength; COLLATOR_METHOD_INIT_VARS /* Parse parameters. */ if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "Ol", &object, Collator_ce_ptr, &strength ) == FAILURE ) { RETURN_THROWS(); } /* Fetch the object. */ COLLATOR_METHOD_FETCH_OBJECT; /* Set given strength. */ ucol_setStrength( co->ucoll, strength ); RETURN_TRUE; } /* }}} */
3,115
25.40678
80
c
php-src
php-src-master/ext/intl/collator/collator_class.c
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Vadim Savchuk <[email protected]> | | Dmitry Lakhtyuk <[email protected]> | +----------------------------------------------------------------------+ */ #include "collator.h" #include "collator_class.h" #include "php_intl.h" #include "collator_sort.h" #include "collator_convert.h" #include "intl_error.h" #include <unicode/ucol.h> #include "collator_arginfo.h" zend_class_entry *Collator_ce_ptr = NULL; static zend_object_handlers Collator_handlers; /* * Auxiliary functions needed by objects of 'Collator' class */ /* {{{ Collator_objects_free */ void Collator_objects_free(zend_object *object ) { Collator_object* co = php_intl_collator_fetch_object(object); zend_object_std_dtor(&co->zo ); collator_object_destroy(co ); } /* }}} */ /* {{{ Collator_object_create */ zend_object *Collator_object_create(zend_class_entry *ce ) { Collator_object *intern = zend_object_alloc(sizeof(Collator_object), ce); intl_error_init(COLLATOR_ERROR_P(intern)); zend_object_std_init(&intern->zo, ce ); object_properties_init(&intern->zo, ce); return &intern->zo; } /* }}} */ /* * 'Collator' class registration structures & functions */ /* {{{ collator_register_Collator_symbols * Initialize 'Collator' class */ void collator_register_Collator_symbols(int module_number) { register_collator_symbols(module_number); /* Create and register 'Collator' class. */ Collator_ce_ptr = register_class_Collator(); Collator_ce_ptr->create_object = Collator_object_create; Collator_ce_ptr->default_object_handlers = &Collator_handlers; memcpy(&Collator_handlers, &std_object_handlers, sizeof Collator_handlers); /* Collator has no usable clone semantics - ucol_cloneBinary/ucol_openBinary require binary buffer for which we don't have the place to keep */ Collator_handlers.offset = XtOffsetOf(Collator_object, zo); Collator_handlers.clone_obj = NULL; Collator_handlers.free_obj = Collator_objects_free; /* Declare 'Collator' class properties. */ if( !Collator_ce_ptr ) { zend_error( E_ERROR, "Collator: attempt to create properties " "on a non-registered class." ); return; } } /* }}} */ /* {{{ void collator_object_init( Collator_object* co ) * Initialize internals of Collator_object. * Must be called before any other call to 'collator_object_...' functions. */ void collator_object_init( Collator_object* co ) { if( !co ) return; intl_error_init( COLLATOR_ERROR_P( co ) ); } /* }}} */ /* {{{ void collator_object_destroy( Collator_object* co ) * Clean up mem allocted by internals of Collator_object */ void collator_object_destroy( Collator_object* co ) { if( !co ) return; if( co->ucoll ) { ucol_close( co->ucoll ); co->ucoll = NULL; } intl_error_reset( COLLATOR_ERROR_P( co ) ); } /* }}} */
3,521
27.868852
99
c
php-src
php-src-master/ext/intl/collator/collator_class.h
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Vadim Savchuk <[email protected]> | | Dmitry Lakhtyuk <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef COLLATOR_CLASS_H #define COLLATOR_CLASS_H #include <php.h> #include "../intl_common.h" #include "../intl_error.h" #include "../intl_data.h" #include <unicode/ucol.h> typedef struct { // error handling intl_error err; // ICU collator UCollator* ucoll; zend_object zo; } Collator_object; #define COLLATOR_ERROR(co) (co)->err #define COLLATOR_ERROR_P(co) &(COLLATOR_ERROR(co)) #define COLLATOR_ERROR_CODE(co) INTL_ERROR_CODE(COLLATOR_ERROR(co)) #define COLLATOR_ERROR_CODE_P(co) &(INTL_ERROR_CODE(COLLATOR_ERROR(co))) static inline Collator_object *php_intl_collator_fetch_object(zend_object *obj) { return (Collator_object *)((char*)(obj) - XtOffsetOf(Collator_object, zo)); } #define Z_INTL_COLLATOR_P(zv) php_intl_collator_fetch_object(Z_OBJ_P(zv)) void collator_register_Collator_symbols(int module_number); void collator_object_init( Collator_object* co ); void collator_object_destroy( Collator_object* co ); extern zend_class_entry *Collator_ce_ptr; /* Auxiliary macros */ #define COLLATOR_METHOD_INIT_VARS \ zval* object = NULL; \ Collator_object* co = NULL; \ intl_error_reset( NULL ); \ #define COLLATOR_METHOD_FETCH_OBJECT INTL_METHOD_FETCH_OBJECT(INTL_COLLATOR, co) // Macro to check return value of a ucol_* function call. #define COLLATOR_CHECK_STATUS( co, msg ) \ intl_error_set_code( NULL, COLLATOR_ERROR_CODE( co ) ); \ if( U_FAILURE( COLLATOR_ERROR_CODE( co ) ) ) \ { \ intl_errors_set_custom_msg( COLLATOR_ERROR_P( co ), msg, 0 ); \ RETURN_FALSE; \ } \ #endif // #ifndef COLLATOR_CLASS_H
2,826
37.202703
81
h
php-src
php-src-master/ext/intl/collator/collator_compare.c
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Vadim Savchuk <[email protected]> | | Dmitry Lakhtyuk <[email protected]> | +----------------------------------------------------------------------+ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "php_intl.h" #include "collator_class.h" #include "intl_convert.h" /* {{{ Compare two strings. */ PHP_FUNCTION( collator_compare ) { char* str1 = NULL; char* str2 = NULL; size_t str1_len = 0; size_t str2_len = 0; UChar* ustr1 = NULL; UChar* ustr2 = NULL; int ustr1_len = 0; int ustr2_len = 0; UCollationResult result; COLLATOR_METHOD_INIT_VARS /* Parse parameters. */ if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "Oss", &object, Collator_ce_ptr, &str1, &str1_len, &str2, &str2_len ) == FAILURE ) { RETURN_THROWS(); } /* Fetch the object. */ COLLATOR_METHOD_FETCH_OBJECT; if (!co || !co->ucoll) { intl_error_set_code( NULL, COLLATOR_ERROR_CODE( co ) ); intl_errors_set_custom_msg( COLLATOR_ERROR_P( co ), "Object not initialized", 0 ); zend_throw_error(NULL, "Object not initialized"); RETURN_THROWS(); } /* * Compare given strings (converting them to UTF-16 first). */ /* First convert the strings to UTF-16. */ intl_convert_utf8_to_utf16( &ustr1, &ustr1_len, str1, str1_len, COLLATOR_ERROR_CODE_P( co ) ); if( U_FAILURE( COLLATOR_ERROR_CODE( co ) ) ) { /* Set global error code. */ intl_error_set_code( NULL, COLLATOR_ERROR_CODE( co ) ); /* Set error messages. */ intl_errors_set_custom_msg( COLLATOR_ERROR_P( co ), "Error converting first argument to UTF-16", 0 ); if (ustr1) { efree( ustr1 ); } RETURN_FALSE; } intl_convert_utf8_to_utf16( &ustr2, &ustr2_len, str2, str2_len, COLLATOR_ERROR_CODE_P( co ) ); if( U_FAILURE( COLLATOR_ERROR_CODE( co ) ) ) { /* Set global error code. */ intl_error_set_code( NULL, COLLATOR_ERROR_CODE( co ) ); /* Set error messages. */ intl_errors_set_custom_msg( COLLATOR_ERROR_P( co ), "Error converting second argument to UTF-16", 0 ); if (ustr1) { efree( ustr1 ); } if (ustr2) { efree( ustr2 ); } RETURN_FALSE; } /* Then compare them. */ result = ucol_strcoll( co->ucoll, ustr1, ustr1_len, ustr2, ustr2_len ); if( ustr1 ) efree( ustr1 ); if( ustr2 ) efree( ustr2 ); /* Return result of the comparison. */ RETURN_LONG( result ); } /* }}} */
3,214
26.956522
77
c
php-src
php-src-master/ext/intl/collator/collator_convert.h
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Vadim Savchuk <[email protected]> | | Dmitry Lakhtyuk <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef COLLATOR_CONVERT_H #define COLLATOR_CONVERT_H #include <php.h> #include <unicode/utypes.h> void collator_convert_hash_from_utf8_to_utf16( HashTable* hash, UErrorCode* status ); void collator_convert_hash_from_utf16_to_utf8( HashTable* hash, UErrorCode* status ); zval* collator_convert_zstr_utf16_to_utf8( zval* utf16_zval, zval *rv ); zend_string *collator_convert_zstr_utf8_to_utf16(zend_string *utf8_str); zval* collator_normalize_sort_argument( zval* arg, zval *rv ); zval* collator_convert_object_to_string( zval* obj, zval *rv ); zval* collator_convert_string_to_number( zval* arg, zval *rv ); zval* collator_convert_string_to_number_if_possible( zval* str, zval *rv ); zval* collator_convert_string_to_double( zval* str, zval *rv ); zend_string *collator_zval_to_string(zval *arg); #endif // COLLATOR_CONVERT_H
1,752
46.378378
85
h
php-src
php-src-master/ext/intl/collator/collator_create.c
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Vadim Savchuk <[email protected]> | | Dmitry Lakhtyuk <[email protected]> | +----------------------------------------------------------------------+ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "php_intl.h" #include "collator_class.h" #include "intl_data.h" /* {{{ */ static int collator_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_error_handling *error_handling, bool *error_handling_replaced) { const char* locale; size_t locale_len = 0; zval* object; Collator_object* co; intl_error_reset( NULL ); object = return_value; /* Parse parameters. */ if( zend_parse_parameters( ZEND_NUM_ARGS(), "s", &locale, &locale_len ) == FAILURE ) { return FAILURE; } if (error_handling != NULL) { zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, error_handling); *error_handling_replaced = 1; } INTL_CHECK_LOCALE_LEN_OR_FAILURE(locale_len); COLLATOR_METHOD_FETCH_OBJECT; if(locale_len == 0) { locale = intl_locale_get_default(); } /* Open ICU collator. */ co->ucoll = ucol_open( locale, COLLATOR_ERROR_CODE_P( co ) ); INTL_CTOR_CHECK_STATUS(co, "collator_create: unable to open ICU collator"); return SUCCESS; } /* }}} */ /* {{{ Create collator. */ PHP_FUNCTION( collator_create ) { object_init_ex( return_value, Collator_ce_ptr ); if (collator_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, NULL, NULL) == FAILURE) { zval_ptr_dtor(return_value); RETURN_NULL(); } } /* }}} */ /* {{{ Collator object constructor. */ PHP_METHOD( Collator, __construct ) { zend_error_handling error_handling; bool error_handling_replaced = 0; return_value = ZEND_THIS; if (collator_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, &error_handling, &error_handling_replaced) == FAILURE) { if (!EG(exception)) { zend_throw_exception(IntlException_ce_ptr, "Constructor failed", 0); } } if (error_handling_replaced) { zend_restore_error_handling(&error_handling); } } /* }}} */
2,701
29.704545
122
c
php-src
php-src-master/ext/intl/collator/collator_error.c
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Vadim Savchuk <[email protected]> | | Dmitry Lakhtyuk <[email protected]> | +----------------------------------------------------------------------+ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "php_intl.h" #include "collator_class.h" /* {{{ Get collator's last error code. */ PHP_FUNCTION( collator_get_error_code ) { COLLATOR_METHOD_INIT_VARS /* Parse parameters. */ if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "O", &object, Collator_ce_ptr ) == FAILURE ) { RETURN_THROWS(); } /* Fetch the object (without resetting its last error code). */ co = Z_INTL_COLLATOR_P(object); if( co == NULL ) RETURN_FALSE; /* Return collator's last error code. */ RETURN_LONG( COLLATOR_ERROR_CODE( co ) ); } /* }}} */ /* {{{ Get text description for collator's last error code. */ PHP_FUNCTION( collator_get_error_message ) { zend_string* message = NULL; COLLATOR_METHOD_INIT_VARS /* Parse parameters. */ if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "O", &object, Collator_ce_ptr ) == FAILURE ) { RETURN_THROWS(); } /* Fetch the object (without resetting its last error code). */ co = Z_INTL_COLLATOR_P( object ); if( co == NULL ) RETURN_FALSE; /* Return last error message. */ message = intl_error_get_message( COLLATOR_ERROR_P( co ) ); RETURN_STR(message); } /* }}} */
2,116
29.681159
75
c
php-src
php-src-master/ext/intl/collator/collator_functions_arginfo.h
/* This is a generated file, edit the .stub.php file instead. */ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_collator_create, 0, 1, Collator, 1) ZEND_ARG_TYPE_INFO(0, locale, IS_STRING, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_collator_compare, 0, 3, MAY_BE_LONG|MAY_BE_FALSE) ZEND_ARG_OBJ_INFO(0, object, Collator, 0) ZEND_ARG_TYPE_INFO(0, str1, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, str2, IS_STRING, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_collator_get_attribute, 0, 2, MAY_BE_LONG|MAY_BE_FALSE) ZEND_ARG_OBJ_INFO(0, object, Collator, 0) ZEND_ARG_TYPE_INFO(0, attr, IS_LONG, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_collator_set_attribute, 0, 3, _IS_BOOL, 0) ZEND_ARG_OBJ_INFO(0, object, Collator, 0) ZEND_ARG_TYPE_INFO(0, attr, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, val, IS_LONG, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_collator_get_strength, 0, 1, IS_LONG, 0) ZEND_ARG_OBJ_INFO(0, object, Collator, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_collator_set_strength, 0, 2, _IS_BOOL, 0) ZEND_ARG_OBJ_INFO(0, object, Collator, 0) ZEND_ARG_TYPE_INFO(0, strength, IS_LONG, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_collator_sort, 0, 2, _IS_BOOL, 0) ZEND_ARG_OBJ_INFO(0, object, Collator, 0) ZEND_ARG_TYPE_INFO(1, arr, IS_ARRAY, 0) ZEND_ARG_TYPE_INFO(0, sort_flag, IS_LONG, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_collator_sort_with_sort_keys, 0, 2, _IS_BOOL, 0) ZEND_ARG_OBJ_INFO(0, object, Collator, 0) ZEND_ARG_TYPE_INFO(1, arr, IS_ARRAY, 0) ZEND_END_ARG_INFO() #define arginfo_collator_asort arginfo_collator_sort ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_collator_get_locale, 0, 2, MAY_BE_STRING|MAY_BE_FALSE) ZEND_ARG_OBJ_INFO(0, object, Collator, 0) ZEND_ARG_TYPE_INFO(0, type, IS_LONG, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_collator_get_error_code, 0, 1, MAY_BE_LONG|MAY_BE_FALSE) ZEND_ARG_OBJ_INFO(0, object, Collator, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_collator_get_error_message, 0, 1, MAY_BE_STRING|MAY_BE_FALSE) ZEND_ARG_OBJ_INFO(0, object, Collator, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_collator_get_sort_key, 0, 2, MAY_BE_STRING|MAY_BE_FALSE) ZEND_ARG_OBJ_INFO(0, object, Collator, 0) ZEND_ARG_TYPE_INFO(0, str, IS_STRING, 0) ZEND_END_ARG_INFO()
2,510
38.857143
109
h
php-src
php-src-master/ext/intl/collator/collator_is_numeric.c
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Vadim Savchuk <[email protected]> | | Dmitry Lakhtyuk <[email protected]> | +----------------------------------------------------------------------+ */ #include "collator_is_numeric.h" /* {{{ Taken from PHP6:zend_u_strtod() */ static double collator_u_strtod(const UChar *nptr, UChar **endptr) /* {{{ */ { const UChar *u = nptr, *nstart; UChar c = *u; int any = 0; while (u_isspace(c)) { c = *++u; } nstart = u; if (c == 0x2D /*'-'*/ || c == 0x2B /*'+'*/) { c = *++u; } while (c >= 0x30 /*'0'*/ && c <= 0x39 /*'9'*/) { any = 1; c = *++u; } if (c == 0x2E /*'.'*/) { c = *++u; while (c >= 0x30 /*'0'*/ && c <= 0x39 /*'9'*/) { any = 1; c = *++u; } } if ((c == 0x65 /*'e'*/ || c == 0x45 /*'E'*/) && any) { const UChar *e = u; int any_exp = 0; c = *++u; if (c == 0x2D /*'-'*/ || c == 0x2B /*'+'*/) { c = *++u; } while (c >= 0x30 /*'0'*/ && c <= 0x39 /*'9'*/) { any_exp = 1; c = *++u; } if (!any_exp) { u = e; } } if (any) { char buf[64], *numbuf, *bufpos; size_t length = u - nstart; double value; ALLOCA_FLAG(use_heap = 0); if (length < sizeof(buf)) { numbuf = buf; } else { numbuf = (char *) do_alloca(length + 1, use_heap); } bufpos = numbuf; while (nstart < u) { *bufpos++ = (char) *nstart++; } *bufpos = '\0'; value = zend_strtod(numbuf, NULL); if (numbuf != buf) { free_alloca(numbuf, use_heap); } if (endptr != NULL) { *endptr = (UChar *)u; } return value; } if (endptr != NULL) { *endptr = (UChar *)nptr; } return 0; } /* }}} */ /* {{{ collator_u_strtol * Taken from PHP6:zend_u_strtol() * * Convert a Unicode string to a long integer. * * Ignores `locale' stuff. */ static zend_long collator_u_strtol(const UChar *nptr, UChar **endptr, int base) { const UChar *s = nptr; zend_ulong acc; UChar c; zend_ulong cutoff; int neg = 0, any, cutlim; if (s == NULL) { errno = ERANGE; if (endptr != NULL) { *endptr = NULL; } return 0; } /* * Skip white space and pick up leading +/- sign if any. * If base is 0, allow 0x for hex and 0 for octal, else * assume decimal; if base is already 16, allow 0x. */ do { c = *s++; } while (u_isspace(c)); if (c == 0x2D /*'-'*/) { neg = 1; c = *s++; } else if (c == 0x2B /*'+'*/) c = *s++; if ((base == 0 || base == 16) && (c == 0x30 /*'0'*/) && (*s == 0x78 /*'x'*/ || *s == 0x58 /*'X'*/)) { c = s[1]; s += 2; base = 16; } if (base == 0) base = (c == 0x30 /*'0'*/) ? 8 : 10; /* * Compute the cutoff value between legal numbers and illegal * numbers. That is the largest legal value, divided by the * base. An input number that is greater than this value, if * followed by a legal input character, is too big. One that * is equal to this value may be valid or not; the limit * between valid and invalid numbers is then based on the last * digit. For instance, if the range for longs is * [-2147483648..2147483647] and the input base is 10, * cutoff will be set to 214748364 and cutlim to either * 7 (neg==0) or 8 (neg==1), meaning that if we have accumulated * a value > 214748364, or equal but the next digit is > 7 (or 8), * the number is too big, and we will return a range error. * * Set any if any `digits' consumed; make it negative to indicate * overflow. */ cutoff = neg ? -(zend_ulong)ZEND_LONG_MIN : ZEND_LONG_MAX; cutlim = cutoff % (zend_ulong)base; cutoff /= (zend_ulong)base; for (acc = 0, any = 0;; c = *s++) { if (c >= 0x30 /*'0'*/ && c <= 0x39 /*'9'*/) c -= 0x30 /*'0'*/; else if (c >= 0x41 /*'A'*/ && c <= 0x5A /*'Z'*/) c -= 0x41 /*'A'*/ - 10; else if (c >= 0x61 /*'a'*/ && c <= 0x7A /*'z'*/) c -= 0x61 /*'a'*/ - 10; else break; if (c >= base) break; if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) any = -1; else { any = 1; acc *= base; acc += c; } } if (any < 0) { acc = neg ? ZEND_LONG_MIN : ZEND_LONG_MAX; errno = ERANGE; } else if (neg) acc = -acc; if (endptr != NULL) *endptr = (UChar *)(any ? s - 1 : nptr); return (acc); } /* }}} */ /* {{{ collator_is_numeric] * Taken from PHP6:is_numeric_unicode() */ uint8_t collator_is_numeric( UChar *str, int32_t length, zend_long *lval, double *dval, bool allow_errors ) { zend_long local_lval; double local_dval; UChar *end_ptr_long, *end_ptr_double; if (!length) { return 0; } errno=0; local_lval = collator_u_strtol(str, &end_ptr_long, 10); if (errno != ERANGE) { if (end_ptr_long == str+length) { /* integer string */ if (lval) { *lval = local_lval; } return IS_LONG; } else if (end_ptr_long == str && *end_ptr_long != '\0' && *str != '.' && *str != '-') { /* ignore partial string matches */ return 0; } } else { end_ptr_long = NULL; } local_dval = collator_u_strtod(str, &end_ptr_double); if (local_dval == 0 && end_ptr_double == str) { end_ptr_double = NULL; } else { if (end_ptr_double == str+length) { /* floating point string */ if (!zend_finite(local_dval)) { /* "inf","nan" and maybe other weird ones */ return 0; } if (dval) { *dval = local_dval; } return IS_DOUBLE; } } if (!allow_errors) { return 0; } if (allow_errors) { if (end_ptr_double > end_ptr_long && dval) { *dval = local_dval; return IS_DOUBLE; } else if (end_ptr_long && lval) { *lval = local_lval; return IS_LONG; } } return 0; } /* }}} */
6,207
22.426415
126
c
php-src
php-src-master/ext/intl/collator/collator_is_numeric.h
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Vadim Savchuk <[email protected]> | | Dmitry Lakhtyuk <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef COLLATOR_IS_NUMERIC_H #define COLLATOR_IS_NUMERIC_H #include <php.h> #include <unicode/uchar.h> #include <stdint.h> uint8_t collator_is_numeric( UChar *str, int32_t length, zend_long *lval, double *dval, bool allow_errors ); #endif // COLLATOR_IS_NUMERIC_H
1,188
44.730769
108
h
php-src
php-src-master/ext/intl/collator/collator_locale.c
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Vadim Savchuk <[email protected]> | | Dmitry Lakhtyuk <[email protected]> | +----------------------------------------------------------------------+ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "php_intl.h" #include "collator_class.h" #include "intl_convert.h" #include <zend_API.h> /* {{{ Gets the locale name of the collator. */ PHP_FUNCTION( collator_get_locale ) { zend_long type = 0; char* locale_name = NULL; COLLATOR_METHOD_INIT_VARS /* Parse parameters. */ if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "Ol", &object, Collator_ce_ptr, &type ) == FAILURE ) { RETURN_THROWS(); } /* Fetch the object. */ COLLATOR_METHOD_FETCH_OBJECT; if (!co || !co->ucoll) { intl_error_set_code( NULL, COLLATOR_ERROR_CODE( co ) ); intl_errors_set_custom_msg( COLLATOR_ERROR_P( co ), "Object not initialized", 0 ); zend_throw_error(NULL, "Object not initialized"); RETURN_THROWS(); } /* Get locale by specified type. */ locale_name = (char*) ucol_getLocaleByType( co->ucoll, type, COLLATOR_ERROR_CODE_P( co ) ); COLLATOR_CHECK_STATUS( co, "Error getting locale by type" ); /* Return it. */ RETVAL_STRINGL( locale_name, strlen(locale_name) ); } /* }}} */
1,994
31.177419
75
c
php-src
php-src-master/ext/intl/collator/collator_sort.c
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Vadim Savchuk <[email protected]> | | Dmitry Lakhtyuk <[email protected]> | +----------------------------------------------------------------------+ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "php_intl.h" #include "collator.h" #include "collator_class.h" #include "collator_sort.h" #include "collator_convert.h" #include "intl_convert.h" #if !defined(HAVE_PTRDIFF_T) && !defined(_PTRDIFF_T_DEFINED) typedef zend_long ptrdiff_t; #endif /** * Declare 'index' which will point to sort key in sort key * buffer. */ typedef struct _collator_sort_key_index { char* key; /* pointer to sort key */ zval* zstr; /* pointer to original string(hash-item) */ } collator_sort_key_index_t; ZEND_EXTERN_MODULE_GLOBALS( intl ) static const size_t DEF_SORT_KEYS_BUF_SIZE = 1048576; static const size_t DEF_SORT_KEYS_BUF_INCREMENT = 1048576; static const size_t DEF_SORT_KEYS_INDX_BUF_SIZE = 1048576; static const size_t DEF_SORT_KEYS_INDX_BUF_INCREMENT = 1048576; static const size_t DEF_UTF16_BUF_SIZE = 1024; /* {{{ collator_regular_compare_function */ static int collator_regular_compare_function(zval *result, zval *op1, zval *op2) { int rc = SUCCESS; zval str1, str2; zval num1, num2; zval norm1, norm2; zval *num1_p = NULL, *num2_p = NULL; zval *norm1_p = NULL, *norm2_p = NULL; zval *str1_p, *str2_p; ZVAL_NULL(&str1); str1_p = collator_convert_object_to_string( op1, &str1 ); ZVAL_NULL(&str2); str2_p = collator_convert_object_to_string( op2, &str2 ); /* If both args are strings AND either of args is not numeric string * then use ICU-compare. Otherwise PHP-compare. */ if( Z_TYPE_P(str1_p) == IS_STRING && Z_TYPE_P(str2_p) == IS_STRING && ( str1_p == ( num1_p = collator_convert_string_to_number_if_possible( str1_p, &num1 ) ) || str2_p == ( num2_p = collator_convert_string_to_number_if_possible( str2_p, &num2 ) ) ) ) { /* Compare the strings using ICU. */ ZEND_ASSERT(INTL_G(current_collator) != NULL); ZVAL_LONG(result, ucol_strcoll( INTL_G(current_collator), INTL_ZSTR_VAL(Z_STR_P(str1_p)), INTL_ZSTR_LEN(Z_STR_P(str1_p)), INTL_ZSTR_VAL(Z_STR_P(str2_p)), INTL_ZSTR_LEN(Z_STR_P(str2_p)) )); } else { /* num1 is set if str1 and str2 are strings. */ if( num1_p ) { if( num1_p == str1_p ) { /* str1 is string but not numeric string * just convert it to utf8. */ norm1_p = collator_convert_zstr_utf16_to_utf8( str1_p, &norm1 ); /* num2 is not set but str2 is string => do normalization. */ norm2_p = collator_normalize_sort_argument( str2_p, &norm2 ); } else { /* str1 is numeric strings => passthru to PHP-compare. */ Z_TRY_ADDREF_P(num1_p); norm1_p = num1_p; /* str2 is numeric strings => passthru to PHP-compare. */ Z_TRY_ADDREF_P(num2_p); norm2_p = num2_p; } } else { /* num1 is not set if str1 or str2 is not a string => do normalization. */ norm1_p = collator_normalize_sort_argument( str1_p, &norm1 ); /* if num1 is not set then num2 is not set as well => do normalization. */ norm2_p = collator_normalize_sort_argument( str2_p, &norm2 ); } rc = compare_function( result, norm1_p, norm2_p ); zval_ptr_dtor( norm1_p ); zval_ptr_dtor( norm2_p ); } if( num1_p ) zval_ptr_dtor( num1_p ); if( num2_p ) zval_ptr_dtor( num2_p ); zval_ptr_dtor( str1_p ); zval_ptr_dtor( str2_p ); return rc; } /* }}} */ /* {{{ collator_numeric_compare_function * Convert input args to double and compare it. */ static int collator_numeric_compare_function(zval *result, zval *op1, zval *op2) { zval num1, num2; zval *num1_p = NULL; zval *num2_p = NULL; if( Z_TYPE_P(op1) == IS_STRING ) { num1_p = collator_convert_string_to_double( op1, &num1 ); op1 = num1_p; } if( Z_TYPE_P(op2) == IS_STRING ) { num2_p = collator_convert_string_to_double( op2, &num2 ); op2 = num2_p; } ZVAL_LONG(result, numeric_compare_function(op1, op2)); if( num1_p ) zval_ptr_dtor( num1_p ); if( num2_p ) zval_ptr_dtor( num2_p ); return SUCCESS; } /* }}} */ /* {{{ collator_icu_compare_function * Direct use of ucol_strcoll. */ static int collator_icu_compare_function(zval *result, zval *op1, zval *op2) { int rc = SUCCESS; zend_string *str1 = collator_zval_to_string(op1); zend_string *str2 = collator_zval_to_string(op2); /* Compare the strings using ICU. */ ZEND_ASSERT(INTL_G(current_collator) != NULL); ZVAL_LONG(result, ucol_strcoll( INTL_G(current_collator), INTL_ZSTR_VAL(str1), INTL_ZSTR_LEN(str1), INTL_ZSTR_VAL(str2), INTL_ZSTR_LEN(str2) )); zend_string_release(str1); zend_string_release(str2); return rc; } /* }}} */ /* {{{ collator_compare_func * Taken from PHP7 source (array_data_compare). */ static int collator_compare_func(Bucket *f, Bucket *s) { zval result; zval *first = &f->val; zval *second = &s->val; if( INTL_G(compare_func)( &result, first, second) == FAILURE ) return 0; if( Z_TYPE(result) == IS_DOUBLE ) { if( Z_DVAL(result) < 0 ) return -1; else if( Z_DVAL(result) > 0 ) return 1; else return 0; } convert_to_long(&result); if( Z_LVAL(result) < 0 ) return -1; else if( Z_LVAL(result) > 0 ) return 1; return 0; } /* }}} */ /* {{{ Compare sort keys */ static int collator_cmp_sort_keys( const void *p1, const void *p2 ) { char* key1 = ((collator_sort_key_index_t*)p1)->key; char* key2 = ((collator_sort_key_index_t*)p2)->key; return strcmp( key1, key2 ); } /* }}} */ /* {{{ Choose compare function according to sort flags. */ static collator_compare_func_t collator_get_compare_function( const zend_long sort_flags ) { collator_compare_func_t func; switch( sort_flags ) { case COLLATOR_SORT_NUMERIC: func = collator_numeric_compare_function; break; case COLLATOR_SORT_STRING: func = collator_icu_compare_function; break; case COLLATOR_SORT_REGULAR: default: func = collator_regular_compare_function; break; } return func; } /* }}} */ /* {{{ Common code shared by collator_sort() and collator_asort() API functions. */ static void collator_sort_internal( int renumber, INTERNAL_FUNCTION_PARAMETERS ) { UCollator* saved_collator; zval* array = NULL; HashTable* hash = NULL; zend_long sort_flags = COLLATOR_SORT_REGULAR; COLLATOR_METHOD_INIT_VARS /* Parse parameters. */ if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "Oa/|l", &object, Collator_ce_ptr, &array, &sort_flags ) == FAILURE ) { RETURN_THROWS(); } /* Fetch the object. */ COLLATOR_METHOD_FETCH_OBJECT; if (!co->ucoll) { zend_throw_error(NULL, "Object not initialized"); RETURN_THROWS(); } /* Set 'compare function' according to sort flags. */ INTL_G(compare_func) = collator_get_compare_function( sort_flags ); hash = Z_ARRVAL_P( array ); /* Convert strings in the specified array from UTF-8 to UTF-16. */ collator_convert_hash_from_utf8_to_utf16( hash, COLLATOR_ERROR_CODE_P( co ) ); COLLATOR_CHECK_STATUS( co, "Error converting hash from UTF-8 to UTF-16" ); /* Save specified collator in the request-global (?) variable. */ saved_collator = INTL_G( current_collator ); INTL_G( current_collator ) = co->ucoll; /* Sort specified array. */ zend_hash_sort(hash, collator_compare_func, renumber); /* Restore saved collator. */ INTL_G( current_collator ) = saved_collator; /* Convert strings in the specified array back to UTF-8. */ collator_convert_hash_from_utf16_to_utf8( hash, COLLATOR_ERROR_CODE_P( co ) ); COLLATOR_CHECK_STATUS( co, "Error converting hash from UTF-16 to UTF-8" ); RETURN_TRUE; } /* }}} */ /* {{{ Sort array using specified collator. */ PHP_FUNCTION( collator_sort ) { collator_sort_internal( true, INTERNAL_FUNCTION_PARAM_PASSTHRU ); } /* }}} */ static void collator_sortkey_swap(collator_sort_key_index_t *p, collator_sort_key_index_t *q) /* {{{ */ { collator_sort_key_index_t t; t = *p; *p = *q; *q = t; } /* }}} */ /* {{{ Equivalent to standard PHP sort using Collator. * Uses ICU ucol_getSortKey for performance. */ PHP_FUNCTION( collator_sort_with_sort_keys ) { zval* array = NULL; zval garbage; HashTable* hash = NULL; zval* hashData = NULL; /* currently processed item of input hash */ char* sortKeyBuf = NULL; /* buffer to store sort keys */ uint32_t sortKeyBufSize = DEF_SORT_KEYS_BUF_SIZE; /* buffer size */ ptrdiff_t sortKeyBufOffset = 0; /* pos in buffer to store sort key */ uint32_t sortKeyLen = 0; /* the length of currently processing key */ uint32_t bufLeft = 0; uint32_t bufIncrement = 0; collator_sort_key_index_t* sortKeyIndxBuf = NULL; /* buffer to store 'indexes' which will be passed to 'qsort' */ uint32_t sortKeyIndxBufSize = DEF_SORT_KEYS_INDX_BUF_SIZE; uint32_t sortKeyIndxSize = sizeof( collator_sort_key_index_t ); uint32_t sortKeyCount = 0; uint32_t j = 0; UChar* utf16_buf = NULL; /* tmp buffer to hold current processing string in utf-16 */ int utf16_buf_size = DEF_UTF16_BUF_SIZE; /* the length of utf16_buf */ int utf16_len = 0; /* length of converted string */ COLLATOR_METHOD_INIT_VARS /* Parse parameters. */ if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "Oa", &object, Collator_ce_ptr, &array ) == FAILURE ) { RETURN_THROWS(); } /* Fetch the object. */ COLLATOR_METHOD_FETCH_OBJECT; if (!co || !co->ucoll) { intl_error_set_code( NULL, COLLATOR_ERROR_CODE( co ) ); intl_errors_set_custom_msg( COLLATOR_ERROR_P( co ), "Object not initialized", 0 ); zend_throw_error(NULL, "Object not initialized"); RETURN_THROWS(); } /* * Sort specified array. */ hash = Z_ARRVAL_P( array ); if( !hash || zend_hash_num_elements( hash ) == 0 ) RETURN_TRUE; /* Create bufers */ sortKeyBuf = ecalloc( sortKeyBufSize, sizeof( char ) ); sortKeyIndxBuf = ecalloc( sortKeyIndxBufSize, sizeof( uint8_t ) ); utf16_buf = eumalloc( utf16_buf_size ); /* Iterate through input hash and create a sort key for each value. */ ZEND_HASH_FOREACH_VAL(hash, hashData) { /* Convert current hash item from UTF-8 to UTF-16LE and save the result to utf16_buf. */ utf16_len = utf16_buf_size; /* Process string values only. */ if( Z_TYPE_P( hashData ) == IS_STRING ) { intl_convert_utf8_to_utf16( &utf16_buf, &utf16_len, Z_STRVAL_P( hashData ), Z_STRLEN_P( hashData ), COLLATOR_ERROR_CODE_P( co ) ); if( U_FAILURE( COLLATOR_ERROR_CODE( co ) ) ) { intl_error_set_code( NULL, COLLATOR_ERROR_CODE( co ) ); intl_errors_set_custom_msg( COLLATOR_ERROR_P( co ), "Sort with sort keys failed", 0 ); if( utf16_buf ) efree( utf16_buf ); efree( sortKeyIndxBuf ); efree( sortKeyBuf ); RETURN_FALSE; } } else { /* Set empty string */ utf16_len = 0; utf16_buf[utf16_len] = 0; } if( (utf16_len + 1) > utf16_buf_size ) utf16_buf_size = utf16_len + 1; /* Get sort key, reallocating the buffer if needed. */ bufLeft = sortKeyBufSize - sortKeyBufOffset; sortKeyLen = ucol_getSortKey( co->ucoll, utf16_buf, utf16_len, (uint8_t*)sortKeyBuf + sortKeyBufOffset, bufLeft ); /* check for sortKeyBuf overflow, increasing its size of the buffer if needed */ if( sortKeyLen > bufLeft ) { bufIncrement = ( sortKeyLen > DEF_SORT_KEYS_BUF_INCREMENT ) ? sortKeyLen : DEF_SORT_KEYS_BUF_INCREMENT; sortKeyBufSize += bufIncrement; bufLeft += bufIncrement; sortKeyBuf = erealloc( sortKeyBuf, sortKeyBufSize ); sortKeyLen = ucol_getSortKey( co->ucoll, utf16_buf, utf16_len, (uint8_t*)sortKeyBuf + sortKeyBufOffset, bufLeft ); } /* check sortKeyIndxBuf overflow, increasing its size of the buffer if needed */ if( ( sortKeyCount + 1 ) * sortKeyIndxSize > sortKeyIndxBufSize ) { bufIncrement = ( sortKeyIndxSize > DEF_SORT_KEYS_INDX_BUF_INCREMENT ) ? sortKeyIndxSize : DEF_SORT_KEYS_INDX_BUF_INCREMENT; sortKeyIndxBufSize += bufIncrement; sortKeyIndxBuf = erealloc( sortKeyIndxBuf, sortKeyIndxBufSize ); } sortKeyIndxBuf[sortKeyCount].key = (char*)sortKeyBufOffset; /* remember just offset, cause address */ /* of 'sortKeyBuf' may be changed due to realloc. */ sortKeyIndxBuf[sortKeyCount].zstr = hashData; sortKeyBufOffset += sortKeyLen; ++sortKeyCount; } ZEND_HASH_FOREACH_END(); /* update ptrs to point to valid keys. */ for( j = 0; j < sortKeyCount; j++ ) sortKeyIndxBuf[j].key = sortKeyBuf + (ptrdiff_t)sortKeyIndxBuf[j].key; /* sort it */ zend_sort( sortKeyIndxBuf, sortKeyCount, sortKeyIndxSize, collator_cmp_sort_keys, (swap_func_t)collator_sortkey_swap); ZVAL_COPY_VALUE(&garbage, array); /* for resulting hash we'll assign new hash keys rather then reordering */ array_init(array); for( j = 0; j < sortKeyCount; j++ ) { Z_TRY_ADDREF_P( sortKeyIndxBuf[j].zstr ); zend_hash_next_index_insert( Z_ARRVAL_P(array), sortKeyIndxBuf[j].zstr); } if( utf16_buf ) efree( utf16_buf ); zval_ptr_dtor(&garbage); efree( sortKeyIndxBuf ); efree( sortKeyBuf ); RETURN_TRUE; } /* }}} */ /* {{{ Sort array using specified collator, maintaining index association. */ PHP_FUNCTION( collator_asort ) { collator_sort_internal( false, INTERNAL_FUNCTION_PARAM_PASSTHRU ); } /* }}} */ /* {{{ Get a sort key for a string from a Collator. */ PHP_FUNCTION( collator_get_sort_key ) { char* str = NULL; size_t str_len = 0; UChar* ustr = NULL; int32_t ustr_len = 0; int key_len = 0; zend_string* key_str; COLLATOR_METHOD_INIT_VARS /* Parse parameters. */ if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "Os", &object, Collator_ce_ptr, &str, &str_len ) == FAILURE ) { RETURN_THROWS(); } /* Fetch the object. */ COLLATOR_METHOD_FETCH_OBJECT; if (!co || !co->ucoll) { intl_error_set_code( NULL, COLLATOR_ERROR_CODE( co ) ); intl_errors_set_custom_msg( COLLATOR_ERROR_P( co ), "Object not initialized", 0 ); zend_throw_error(NULL, "Object not initialized"); RETURN_THROWS(); } /* * Compare given strings (converting them to UTF-16 first). */ /* First convert the strings to UTF-16. */ intl_convert_utf8_to_utf16( &ustr, &ustr_len, str, str_len, COLLATOR_ERROR_CODE_P( co ) ); if( U_FAILURE( COLLATOR_ERROR_CODE( co ) ) ) { /* Set global error code. */ intl_error_set_code( NULL, COLLATOR_ERROR_CODE( co ) ); /* Set error messages. */ intl_errors_set_custom_msg( COLLATOR_ERROR_P( co ), "Error converting first argument to UTF-16", 0 ); efree( ustr ); RETURN_FALSE; } /* ucol_getSortKey is exception in that the key length includes the * NUL terminator*/ key_len = ucol_getSortKey(co->ucoll, ustr, ustr_len, NULL, 0); if(!key_len) { efree( ustr ); RETURN_FALSE; } key_str = zend_string_alloc(key_len, 0); key_len = ucol_getSortKey(co->ucoll, ustr, ustr_len, (uint8_t*)ZSTR_VAL(key_str), key_len); efree( ustr ); if(!key_len) { RETURN_FALSE; } ZSTR_LEN(key_str) = key_len - 1; RETVAL_NEW_STR(key_str); } /* }}} */
16,182
27.642478
133
c
php-src
php-src-master/ext/intl/collator/collator_sort.h
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Vadim Savchuk <[email protected]> | | Dmitry Lakhtyuk <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef COLLATOR_SORT_H #define COLLATOR_SORT_H #include <php.h> typedef int (*collator_compare_func_t)( zval *result, zval *op1, zval *op2 ); #endif // COLLATOR_SORT_H
1,092
44.541667
77
h
php-src
php-src-master/ext/intl/common/common_arginfo.h
/* This is a generated file, edit the .stub.php file instead. * Stub hash: 83971f2cec8c413d6207382e6ebc4ebf500e805f */ ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_IntlIterator_current, 0, 0, IS_MIXED, 0) ZEND_END_ARG_INFO() #define arginfo_class_IntlIterator_key arginfo_class_IntlIterator_current ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_IntlIterator_next, 0, 0, IS_VOID, 0) ZEND_END_ARG_INFO() #define arginfo_class_IntlIterator_rewind arginfo_class_IntlIterator_next ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_IntlIterator_valid, 0, 0, _IS_BOOL, 0) ZEND_END_ARG_INFO() ZEND_METHOD(IntlIterator, current); ZEND_METHOD(IntlIterator, key); ZEND_METHOD(IntlIterator, next); ZEND_METHOD(IntlIterator, rewind); ZEND_METHOD(IntlIterator, valid); static const zend_function_entry class_IntlIterator_methods[] = { ZEND_ME(IntlIterator, current, arginfo_class_IntlIterator_current, ZEND_ACC_PUBLIC) ZEND_ME(IntlIterator, key, arginfo_class_IntlIterator_key, ZEND_ACC_PUBLIC) ZEND_ME(IntlIterator, next, arginfo_class_IntlIterator_next, ZEND_ACC_PUBLIC) ZEND_ME(IntlIterator, rewind, arginfo_class_IntlIterator_rewind, ZEND_ACC_PUBLIC) ZEND_ME(IntlIterator, valid, arginfo_class_IntlIterator_valid, ZEND_ACC_PUBLIC) ZEND_FE_END }; static void register_common_symbols(int module_number) { REGISTER_LONG_CONSTANT("U_USING_FALLBACK_WARNING", U_USING_FALLBACK_WARNING, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_ERROR_WARNING_START", U_ERROR_WARNING_START, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_USING_DEFAULT_WARNING", U_USING_DEFAULT_WARNING, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_SAFECLONE_ALLOCATED_WARNING", U_SAFECLONE_ALLOCATED_WARNING, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_STATE_OLD_WARNING", U_STATE_OLD_WARNING, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_STRING_NOT_TERMINATED_WARNING", U_STRING_NOT_TERMINATED_WARNING, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_SORT_KEY_TOO_SHORT_WARNING", U_SORT_KEY_TOO_SHORT_WARNING, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_AMBIGUOUS_ALIAS_WARNING", U_AMBIGUOUS_ALIAS_WARNING, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_DIFFERENT_UCA_VERSION", U_DIFFERENT_UCA_VERSION, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_ERROR_WARNING_LIMIT", U_ERROR_WARNING_LIMIT, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_ZERO_ERROR", U_ZERO_ERROR, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_ILLEGAL_ARGUMENT_ERROR", U_ILLEGAL_ARGUMENT_ERROR, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_MISSING_RESOURCE_ERROR", U_MISSING_RESOURCE_ERROR, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_INVALID_FORMAT_ERROR", U_INVALID_FORMAT_ERROR, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_FILE_ACCESS_ERROR", U_FILE_ACCESS_ERROR, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_INTERNAL_PROGRAM_ERROR", U_INTERNAL_PROGRAM_ERROR, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_MESSAGE_PARSE_ERROR", U_MESSAGE_PARSE_ERROR, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_MEMORY_ALLOCATION_ERROR", U_MEMORY_ALLOCATION_ERROR, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_INDEX_OUTOFBOUNDS_ERROR", U_INDEX_OUTOFBOUNDS_ERROR, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_PARSE_ERROR", U_PARSE_ERROR, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_INVALID_CHAR_FOUND", U_INVALID_CHAR_FOUND, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_TRUNCATED_CHAR_FOUND", U_TRUNCATED_CHAR_FOUND, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_ILLEGAL_CHAR_FOUND", U_ILLEGAL_CHAR_FOUND, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_INVALID_TABLE_FORMAT", U_INVALID_TABLE_FORMAT, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_INVALID_TABLE_FILE", U_INVALID_TABLE_FILE, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_BUFFER_OVERFLOW_ERROR", U_BUFFER_OVERFLOW_ERROR, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_UNSUPPORTED_ERROR", U_UNSUPPORTED_ERROR, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_RESOURCE_TYPE_MISMATCH", U_RESOURCE_TYPE_MISMATCH, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_ILLEGAL_ESCAPE_SEQUENCE", U_ILLEGAL_ESCAPE_SEQUENCE, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_UNSUPPORTED_ESCAPE_SEQUENCE", U_UNSUPPORTED_ESCAPE_SEQUENCE, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_NO_SPACE_AVAILABLE", U_NO_SPACE_AVAILABLE, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_CE_NOT_FOUND_ERROR", U_CE_NOT_FOUND_ERROR, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_PRIMARY_TOO_LONG_ERROR", U_PRIMARY_TOO_LONG_ERROR, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_STATE_TOO_OLD_ERROR", U_STATE_TOO_OLD_ERROR, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_TOO_MANY_ALIASES_ERROR", U_TOO_MANY_ALIASES_ERROR, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_ENUM_OUT_OF_SYNC_ERROR", U_ENUM_OUT_OF_SYNC_ERROR, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_INVARIANT_CONVERSION_ERROR", U_INVARIANT_CONVERSION_ERROR, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_INVALID_STATE_ERROR", U_INVALID_STATE_ERROR, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_COLLATOR_VERSION_MISMATCH", U_COLLATOR_VERSION_MISMATCH, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_USELESS_COLLATOR_ERROR", U_USELESS_COLLATOR_ERROR, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_NO_WRITE_PERMISSION", U_NO_WRITE_PERMISSION, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_STANDARD_ERROR_LIMIT", U_STANDARD_ERROR_LIMIT, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_BAD_VARIABLE_DEFINITION", U_BAD_VARIABLE_DEFINITION, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_PARSE_ERROR_START", U_PARSE_ERROR_START, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_MALFORMED_RULE", U_MALFORMED_RULE, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_MALFORMED_SET", U_MALFORMED_SET, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_MALFORMED_SYMBOL_REFERENCE", U_MALFORMED_SYMBOL_REFERENCE, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_MALFORMED_UNICODE_ESCAPE", U_MALFORMED_UNICODE_ESCAPE, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_MALFORMED_VARIABLE_DEFINITION", U_MALFORMED_VARIABLE_DEFINITION, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_MALFORMED_VARIABLE_REFERENCE", U_MALFORMED_VARIABLE_REFERENCE, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_MISMATCHED_SEGMENT_DELIMITERS", U_MISMATCHED_SEGMENT_DELIMITERS, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_MISPLACED_ANCHOR_START", U_MISPLACED_ANCHOR_START, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_MISPLACED_CURSOR_OFFSET", U_MISPLACED_CURSOR_OFFSET, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_MISPLACED_QUANTIFIER", U_MISPLACED_QUANTIFIER, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_MISSING_OPERATOR", U_MISSING_OPERATOR, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_MISSING_SEGMENT_CLOSE", U_MISSING_SEGMENT_CLOSE, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_MULTIPLE_ANTE_CONTEXTS", U_MULTIPLE_ANTE_CONTEXTS, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_MULTIPLE_CURSORS", U_MULTIPLE_CURSORS, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_MULTIPLE_POST_CONTEXTS", U_MULTIPLE_POST_CONTEXTS, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_TRAILING_BACKSLASH", U_TRAILING_BACKSLASH, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_UNDEFINED_SEGMENT_REFERENCE", U_UNDEFINED_SEGMENT_REFERENCE, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_UNDEFINED_VARIABLE", U_UNDEFINED_VARIABLE, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_UNQUOTED_SPECIAL", U_UNQUOTED_SPECIAL, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_UNTERMINATED_QUOTE", U_UNTERMINATED_QUOTE, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_RULE_MASK_ERROR", U_RULE_MASK_ERROR, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_MISPLACED_COMPOUND_FILTER", U_MISPLACED_COMPOUND_FILTER, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_MULTIPLE_COMPOUND_FILTERS", U_MULTIPLE_COMPOUND_FILTERS, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_INVALID_RBT_SYNTAX", U_INVALID_RBT_SYNTAX, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_INVALID_PROPERTY_PATTERN", U_INVALID_PROPERTY_PATTERN, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_MALFORMED_PRAGMA", U_MALFORMED_PRAGMA, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_UNCLOSED_SEGMENT", U_UNCLOSED_SEGMENT, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_ILLEGAL_CHAR_IN_SEGMENT", U_ILLEGAL_CHAR_IN_SEGMENT, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_VARIABLE_RANGE_EXHAUSTED", U_VARIABLE_RANGE_EXHAUSTED, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_VARIABLE_RANGE_OVERLAP", U_VARIABLE_RANGE_OVERLAP, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_ILLEGAL_CHARACTER", U_ILLEGAL_CHARACTER, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_INTERNAL_TRANSLITERATOR_ERROR", U_INTERNAL_TRANSLITERATOR_ERROR, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_INVALID_ID", U_INVALID_ID, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_INVALID_FUNCTION", U_INVALID_FUNCTION, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_PARSE_ERROR_LIMIT", U_PARSE_ERROR_LIMIT, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_UNEXPECTED_TOKEN", U_UNEXPECTED_TOKEN, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_FMT_PARSE_ERROR_START", U_FMT_PARSE_ERROR_START, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_MULTIPLE_DECIMAL_SEPARATORS", U_MULTIPLE_DECIMAL_SEPARATORS, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_MULTIPLE_DECIMAL_SEPERATORS", U_MULTIPLE_DECIMAL_SEPERATORS, CONST_PERSISTENT | CONST_DEPRECATED); REGISTER_LONG_CONSTANT("U_MULTIPLE_EXPONENTIAL_SYMBOLS", U_MULTIPLE_EXPONENTIAL_SYMBOLS, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_MALFORMED_EXPONENTIAL_PATTERN", U_MALFORMED_EXPONENTIAL_PATTERN, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_MULTIPLE_PERCENT_SYMBOLS", U_MULTIPLE_PERCENT_SYMBOLS, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_MULTIPLE_PERMILL_SYMBOLS", U_MULTIPLE_PERMILL_SYMBOLS, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_MULTIPLE_PAD_SPECIFIERS", U_MULTIPLE_PAD_SPECIFIERS, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_PATTERN_SYNTAX_ERROR", U_PATTERN_SYNTAX_ERROR, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_ILLEGAL_PAD_POSITION", U_ILLEGAL_PAD_POSITION, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_UNMATCHED_BRACES", U_UNMATCHED_BRACES, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_UNSUPPORTED_PROPERTY", U_UNSUPPORTED_PROPERTY, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_UNSUPPORTED_ATTRIBUTE", U_UNSUPPORTED_ATTRIBUTE, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_FMT_PARSE_ERROR_LIMIT", U_FMT_PARSE_ERROR_LIMIT, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_BRK_INTERNAL_ERROR", U_BRK_INTERNAL_ERROR, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_BRK_ERROR_START", U_BRK_ERROR_START, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_BRK_HEX_DIGITS_EXPECTED", U_BRK_HEX_DIGITS_EXPECTED, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_BRK_SEMICOLON_EXPECTED", U_BRK_SEMICOLON_EXPECTED, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_BRK_RULE_SYNTAX", U_BRK_RULE_SYNTAX, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_BRK_UNCLOSED_SET", U_BRK_UNCLOSED_SET, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_BRK_ASSIGN_ERROR", U_BRK_ASSIGN_ERROR, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_BRK_VARIABLE_REDFINITION", U_BRK_VARIABLE_REDFINITION, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_BRK_MISMATCHED_PAREN", U_BRK_MISMATCHED_PAREN, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_BRK_NEW_LINE_IN_QUOTED_STRING", U_BRK_NEW_LINE_IN_QUOTED_STRING, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_BRK_UNDEFINED_VARIABLE", U_BRK_UNDEFINED_VARIABLE, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_BRK_INIT_ERROR", U_BRK_INIT_ERROR, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_BRK_RULE_EMPTY_SET", U_BRK_RULE_EMPTY_SET, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_BRK_UNRECOGNIZED_OPTION", U_BRK_UNRECOGNIZED_OPTION, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_BRK_MALFORMED_RULE_TAG", U_BRK_MALFORMED_RULE_TAG, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_BRK_ERROR_LIMIT", U_BRK_ERROR_LIMIT, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_REGEX_INTERNAL_ERROR", U_REGEX_INTERNAL_ERROR, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_REGEX_ERROR_START", U_REGEX_ERROR_START, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_REGEX_RULE_SYNTAX", U_REGEX_RULE_SYNTAX, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_REGEX_INVALID_STATE", U_REGEX_INVALID_STATE, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_REGEX_BAD_ESCAPE_SEQUENCE", U_REGEX_BAD_ESCAPE_SEQUENCE, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_REGEX_PROPERTY_SYNTAX", U_REGEX_PROPERTY_SYNTAX, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_REGEX_UNIMPLEMENTED", U_REGEX_UNIMPLEMENTED, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_REGEX_MISMATCHED_PAREN", U_REGEX_MISMATCHED_PAREN, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_REGEX_NUMBER_TOO_BIG", U_REGEX_NUMBER_TOO_BIG, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_REGEX_BAD_INTERVAL", U_REGEX_BAD_INTERVAL, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_REGEX_MAX_LT_MIN", U_REGEX_MAX_LT_MIN, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_REGEX_INVALID_BACK_REF", U_REGEX_INVALID_BACK_REF, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_REGEX_INVALID_FLAG", U_REGEX_INVALID_FLAG, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_REGEX_LOOK_BEHIND_LIMIT", U_REGEX_LOOK_BEHIND_LIMIT, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_REGEX_SET_CONTAINS_STRING", U_REGEX_SET_CONTAINS_STRING, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_REGEX_ERROR_LIMIT", U_REGEX_ERROR_LIMIT, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_IDNA_PROHIBITED_ERROR", U_IDNA_PROHIBITED_ERROR, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_IDNA_ERROR_START", U_IDNA_ERROR_START, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_IDNA_UNASSIGNED_ERROR", U_IDNA_UNASSIGNED_ERROR, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_IDNA_CHECK_BIDI_ERROR", U_IDNA_CHECK_BIDI_ERROR, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_IDNA_STD3_ASCII_RULES_ERROR", U_IDNA_STD3_ASCII_RULES_ERROR, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_IDNA_ACE_PREFIX_ERROR", U_IDNA_ACE_PREFIX_ERROR, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_IDNA_VERIFICATION_ERROR", U_IDNA_VERIFICATION_ERROR, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_IDNA_LABEL_TOO_LONG_ERROR", U_IDNA_LABEL_TOO_LONG_ERROR, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_IDNA_ZERO_LENGTH_LABEL_ERROR", U_IDNA_ZERO_LENGTH_LABEL_ERROR, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_IDNA_DOMAIN_NAME_TOO_LONG_ERROR", U_IDNA_DOMAIN_NAME_TOO_LONG_ERROR, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_IDNA_ERROR_LIMIT", U_IDNA_ERROR_LIMIT, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_STRINGPREP_PROHIBITED_ERROR", U_STRINGPREP_PROHIBITED_ERROR, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_STRINGPREP_UNASSIGNED_ERROR", U_STRINGPREP_UNASSIGNED_ERROR, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_STRINGPREP_CHECK_BIDI_ERROR", U_STRINGPREP_CHECK_BIDI_ERROR, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("U_ERROR_LIMIT", U_ERROR_LIMIT, CONST_PERSISTENT); } static zend_class_entry *register_class_IntlIterator(zend_class_entry *class_entry_Iterator) { zend_class_entry ce, *class_entry; INIT_CLASS_ENTRY(ce, "IntlIterator", class_IntlIterator_methods); class_entry = zend_register_internal_class_ex(&ce, NULL); class_entry->ce_flags |= ZEND_ACC_NOT_SERIALIZABLE; zend_class_implements(class_entry, 1, class_entry_Iterator); return class_entry; }
15,129
78.631579
125
h
php-src
php-src-master/ext/intl/common/common_date.h
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Gustavo Lopes <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef COMMON_DATE_H #define COMMON_DATE_H #include <unicode/umachine.h> U_CDECL_BEGIN #include <php.h> #include "../intl_error.h" U_CDECL_END #ifdef __cplusplus #include <unicode/timezone.h> using icu::TimeZone; U_CFUNC TimeZone *timezone_convert_datetimezone(int type, void *object, int is_datetime, intl_error *outside_error, const char *func); U_CFUNC int intl_datetime_decompose(zval *z, double *millis, TimeZone **tz, intl_error *err, const char *func); #endif U_CFUNC double intl_zval_to_millis(zval *z, intl_error *err, const char *func); #endif /* COMMON_DATE_H */
1,429
34.75
134
h
php-src
php-src-master/ext/intl/common/common_enum.h
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Vadim Savchuk <[email protected]> | | Dmitry Lakhtyuk <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef INTL_COMMON_ENUM_H #define INTL_COMMON_ENUM_H #include <unicode/umachine.h> #ifdef __cplusplus #include <unicode/strenum.h> extern "C" { #include <math.h> #endif #include <php.h> #include "../intl_error.h" #include "../intl_data.h" #ifdef __cplusplus } #endif #define INTLITERATOR_ERROR(ii) (ii)->err #define INTLITERATOR_ERROR_P(ii) &(INTLITERATOR_ERROR(ii)) #define INTLITERATOR_ERROR_CODE(ii) INTL_ERROR_CODE(INTLITERATOR_ERROR(ii)) #define INTLITERATOR_ERROR_CODE_P(ii) &(INTL_ERROR_CODE(INTLITERATOR_ERROR(ii))) #define INTLITERATOR_METHOD_INIT_VARS INTL_METHOD_INIT_VARS(IntlIterator, ii) #define INTLITERATOR_METHOD_FETCH_OBJECT_NO_CHECK INTL_METHOD_FETCH_OBJECT(INTL_ITERATOR, ii) #define INTLITERATOR_METHOD_FETCH_OBJECT\ object = ZEND_THIS; \ INTLITERATOR_METHOD_FETCH_OBJECT_NO_CHECK; \ if (ii->iterator == NULL) { \ zend_throw_error(NULL, "Found unconstructed IntlIterator"); \ RETURN_THROWS(); \ } typedef struct { intl_error err; zend_object_iterator *iterator; zend_object zo; } IntlIterator_object; static inline IntlIterator_object *php_intl_iterator_fetch_object(zend_object *obj) { return (IntlIterator_object *)((char*)(obj) - XtOffsetOf(IntlIterator_object, zo)); } #define Z_INTL_ITERATOR_P(zv) php_intl_iterator_fetch_object(Z_OBJ_P(zv)) typedef struct { zend_object_iterator zoi; zval current; zval wrapping_obj; void (*destroy_it)(zend_object_iterator *iterator); } zoi_with_current; extern zend_class_entry *IntlIterator_ce_ptr; extern zend_object_handlers IntlIterator_handlers; U_CFUNC void zoi_with_current_dtor(zend_object_iterator *iter); U_CFUNC int zoi_with_current_valid(zend_object_iterator *iter); U_CFUNC zval *zoi_with_current_get_current_data(zend_object_iterator *iter); U_CFUNC void zoi_with_current_invalidate_current(zend_object_iterator *iter); #ifdef __cplusplus using icu::StringEnumeration; U_CFUNC void IntlIterator_from_StringEnumeration(StringEnumeration *se, zval *object); #endif U_CFUNC void intl_register_common_symbols(int module_number); #endif // INTL_COMMON_ENUM_H
3,017
35.361446
93
h
php-src
php-src-master/ext/intl/common/common_error.c
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Vadim Savchuk <[email protected]> | | Dmitry Lakhtyuk <[email protected]> | +----------------------------------------------------------------------+ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "php_intl.h" #include "intl_error.h" /* {{{ Get code of the last occurred error. */ PHP_FUNCTION( intl_get_error_code ) { if (zend_parse_parameters_none() == FAILURE) { RETURN_THROWS(); } RETURN_LONG( intl_error_get_code( NULL ) ); } /* }}} */ /* {{{ Get text description of the last occurred error. */ PHP_FUNCTION( intl_get_error_message ) { if (zend_parse_parameters_none() == FAILURE) { RETURN_THROWS(); } RETURN_STR(intl_error_get_message( NULL )); } /* }}} */ /* {{{ Check whether the given error code indicates a failure. * Returns true if it does, and false if the code * indicates success or a warning. */ PHP_FUNCTION( intl_is_failure ) { zend_long err_code; /* Parse parameters. */ if( zend_parse_parameters( ZEND_NUM_ARGS(), "l", &err_code ) == FAILURE ) { RETURN_THROWS(); } RETURN_BOOL( U_FAILURE( err_code ) ); } /* }}} */ /* {{{ Return a string for a given error code. * The string will be the same as the name of the error code constant. */ PHP_FUNCTION( intl_error_name ) { zend_long err_code; /* Parse parameters. */ if( zend_parse_parameters( ZEND_NUM_ARGS(), "l", &err_code ) == FAILURE ) { RETURN_THROWS(); } RETURN_STRING( (char*)u_errorName( err_code ) ); } /* }}} */
2,215
26.358025
75
c
php-src
php-src-master/ext/intl/converter/converter.h
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Sara Golemon <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef PHP_INTL_CONVERTER_H #define PHP_INTL_CONVERTER_H #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "php.h" int php_converter_minit(INIT_FUNC_ARGS); #endif /* PHP_INTL_CONVERTER_H */
1,023
36.925926
73
h
php-src
php-src-master/ext/intl/dateformat/dateformat.c
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Kirti Velankar <[email protected]> | +----------------------------------------------------------------------+ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include <unicode/udat.h> #include "php_intl.h" #include "dateformat_class.h" #include "dateformat.h" /* {{{ Get formatter's last error code. */ PHP_FUNCTION( datefmt_get_error_code ) { DATE_FORMAT_METHOD_INIT_VARS; /* Parse parameters. */ if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "O", &object, IntlDateFormatter_ce_ptr ) == FAILURE ) { RETURN_THROWS(); } dfo = Z_INTL_DATEFORMATTER_P( object ); /* Return formatter's last error code. */ RETURN_LONG( INTL_DATA_ERROR_CODE(dfo) ); } /* }}} */ /* {{{ Get text description for formatter's last error code. */ PHP_FUNCTION( datefmt_get_error_message ) { zend_string *message = NULL; DATE_FORMAT_METHOD_INIT_VARS; /* Parse parameters. */ if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "O", &object, IntlDateFormatter_ce_ptr ) == FAILURE ) { RETURN_THROWS(); } dfo = Z_INTL_DATEFORMATTER_P( object ); /* Return last error message. */ message = intl_error_get_message( INTL_DATA_ERROR_P(dfo) ); RETURN_STR( message); } /* }}} */
1,934
29.714286
75
c
php-src
php-src-master/ext/intl/dateformat/dateformat.h
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Kirti Velankar <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef DATE_FORMATTER_H #define DATE_FORMATTER_H #include <php.h> /* These are not necessary at this point of time #define DATEF_GREGORIAN 1 #define DATEF_CUSTOMARY 2 #define DATEF_BUDDHIST 3 #define DATEF_JAPANESE_IMPERIAL 4 */ #define CALENDAR_SEC "tm_sec" #define CALENDAR_MIN "tm_min" #define CALENDAR_HOUR "tm_hour" #define CALENDAR_MDAY "tm_mday" #define CALENDAR_MON "tm_mon" #define CALENDAR_YEAR "tm_year" #define CALENDAR_WDAY "tm_wday" #define CALENDAR_YDAY "tm_yday" #define CALENDAR_ISDST "tm_isdst" #endif // DATE_FORMATTER_H
1,387
35.526316
75
h
php-src
php-src-master/ext/intl/dateformat/dateformat_attr.c
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Kirti Velankar <[email protected]> | +----------------------------------------------------------------------+ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "../php_intl.h" #include "dateformat_class.h" #include "../intl_convert.h" #include "dateformat_class.h" #include <unicode/ustring.h> #include <unicode/udat.h> /* {{{ Get formatter datetype. */ PHP_FUNCTION( datefmt_get_datetype ) { DATE_FORMAT_METHOD_INIT_VARS; /* Parse parameters. */ if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "O", &object, IntlDateFormatter_ce_ptr ) == FAILURE ) { RETURN_THROWS(); } /* Fetch the object. */ DATE_FORMAT_METHOD_FETCH_OBJECT; INTL_METHOD_CHECK_STATUS(dfo, "Error getting formatter datetype." ); RETURN_LONG(dfo->date_type ); } /* }}} */ /* {{{ Get formatter timetype. */ PHP_FUNCTION( datefmt_get_timetype ) { DATE_FORMAT_METHOD_INIT_VARS; /* Parse parameters. */ if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "O", &object, IntlDateFormatter_ce_ptr ) == FAILURE ) { RETURN_THROWS(); } /* Fetch the object. */ DATE_FORMAT_METHOD_FETCH_OBJECT; INTL_METHOD_CHECK_STATUS(dfo, "Error getting formatter timetype." ); RETURN_LONG(dfo->time_type ); } /* }}} */ /* {{{ Get formatter pattern. */ PHP_FUNCTION( datefmt_get_pattern ) { UChar value_buf[64]; uint32_t length = USIZE( value_buf ); UChar* value = value_buf; bool is_pattern_localized = false; DATE_FORMAT_METHOD_INIT_VARS; /* Parse parameters. */ if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "O", &object, IntlDateFormatter_ce_ptr ) == FAILURE ) { RETURN_THROWS(); } /* Fetch the object. */ DATE_FORMAT_METHOD_FETCH_OBJECT; length = udat_toPattern(DATE_FORMAT_OBJECT(dfo), is_pattern_localized, value, length, &INTL_DATA_ERROR_CODE(dfo)); if(INTL_DATA_ERROR_CODE(dfo) == U_BUFFER_OVERFLOW_ERROR && length >= USIZE( value_buf )) { ++length; /* to avoid U_STRING_NOT_TERMINATED_WARNING */ INTL_DATA_ERROR_CODE(dfo) = U_ZERO_ERROR; value = eumalloc(length); length = udat_toPattern(DATE_FORMAT_OBJECT(dfo), is_pattern_localized, value, length, &INTL_DATA_ERROR_CODE(dfo) ); if(U_FAILURE(INTL_DATA_ERROR_CODE(dfo))) { efree(value); value = value_buf; } } INTL_METHOD_CHECK_STATUS(dfo, "Error getting formatter pattern" ); INTL_METHOD_RETVAL_UTF8( dfo, value, length, ( value != value_buf ) ); } /* }}} */ /* {{{ Set formatter pattern. */ PHP_FUNCTION( datefmt_set_pattern ) { char* value = NULL; size_t value_len = 0; int32_t slength = 0; UChar* svalue = NULL; bool is_pattern_localized = false; DATE_FORMAT_METHOD_INIT_VARS; /* Parse parameters. */ if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "Os", &object, IntlDateFormatter_ce_ptr, &value, &value_len ) == FAILURE ) { RETURN_THROWS(); } DATE_FORMAT_METHOD_FETCH_OBJECT; /* Convert given pattern to UTF-16. */ intl_convert_utf8_to_utf16(&svalue, &slength, value, value_len, &INTL_DATA_ERROR_CODE(dfo)); INTL_METHOD_CHECK_STATUS(dfo, "Error converting pattern to UTF-16" ); udat_applyPattern(DATE_FORMAT_OBJECT(dfo), (UBool)is_pattern_localized, svalue, slength); if (svalue) { efree(svalue); } INTL_METHOD_CHECK_STATUS(dfo, "Error setting symbol value"); RETURN_TRUE; } /* }}} */ /* {{{ Get formatter locale. */ PHP_FUNCTION( datefmt_get_locale ) { char *loc; zend_long loc_type =ULOC_ACTUAL_LOCALE; DATE_FORMAT_METHOD_INIT_VARS; /* Parse parameters. */ if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "O|l", &object, IntlDateFormatter_ce_ptr,&loc_type) == FAILURE ) { RETURN_THROWS(); } /* Fetch the object. */ DATE_FORMAT_METHOD_FETCH_OBJECT; loc = (char *)udat_getLocaleByType(DATE_FORMAT_OBJECT(dfo), loc_type,&INTL_DATA_ERROR_CODE(dfo)); INTL_METHOD_CHECK_STATUS(dfo, "Error getting locale"); RETURN_STRING(loc); } /* }}} */ /* {{{ Get formatter isLenient. */ PHP_FUNCTION( datefmt_is_lenient ) { DATE_FORMAT_METHOD_INIT_VARS; /* Parse parameters. */ if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "O", &object, IntlDateFormatter_ce_ptr ) == FAILURE ) { RETURN_THROWS(); } /* Fetch the object. */ DATE_FORMAT_METHOD_FETCH_OBJECT; RETVAL_BOOL(udat_isLenient(DATE_FORMAT_OBJECT(dfo))); } /* }}} */ /* {{{ Set formatter lenient. */ PHP_FUNCTION( datefmt_set_lenient ) { bool isLenient = false; DATE_FORMAT_METHOD_INIT_VARS; /* Parse parameters. */ if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "Ob", &object, IntlDateFormatter_ce_ptr,&isLenient ) == FAILURE ) { RETURN_THROWS(); } /* Fetch the object. */ DATE_FORMAT_METHOD_FETCH_OBJECT; udat_setLenient(DATE_FORMAT_OBJECT(dfo), (UBool)isLenient ); } /* }}} */
5,460
25.769608
117
c
php-src
php-src-master/ext/intl/dateformat/dateformat_class.c
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Kirti Velankar <[email protected]> | +----------------------------------------------------------------------+ */ #include <unicode/unum.h> #include "dateformat_class.h" #include "php_intl.h" #include "dateformat_data.h" #include "dateformat.h" #include "dateformat_arginfo.h" #include <zend_exceptions.h> zend_class_entry *IntlDateFormatter_ce_ptr = NULL; static zend_object_handlers IntlDateFormatter_handlers; /* * Auxiliary functions needed by objects of 'IntlDateFormatter' class */ /* {{{ IntlDateFormatter_objects_free */ void IntlDateFormatter_object_free( zend_object *object ) { IntlDateFormatter_object* dfo = php_intl_dateformatter_fetch_object(object); zend_object_std_dtor( &dfo->zo ); if (dfo->requested_locale) { efree( dfo->requested_locale ); } dateformat_data_free( &dfo->datef_data ); } /* }}} */ /* {{{ IntlDateFormatter_object_create */ zend_object *IntlDateFormatter_object_create(zend_class_entry *ce) { IntlDateFormatter_object* intern; intern = zend_object_alloc(sizeof(IntlDateFormatter_object), ce); dateformat_data_init( &intern->datef_data ); zend_object_std_init( &intern->zo, ce ); object_properties_init(&intern->zo, ce); intern->date_type = 0; intern->time_type = 0; intern->calendar = -1; intern->requested_locale = NULL; return &intern->zo; } /* }}} */ /* {{{ IntlDateFormatter_object_clone */ zend_object *IntlDateFormatter_object_clone(zend_object *object) { IntlDateFormatter_object *dfo, *new_dfo; zend_object *new_obj; dfo = php_intl_dateformatter_fetch_object(object); intl_error_reset(INTL_DATA_ERROR_P(dfo)); new_obj = IntlDateFormatter_ce_ptr->create_object(object->ce); new_dfo = php_intl_dateformatter_fetch_object(new_obj); /* clone standard parts */ zend_objects_clone_members(&new_dfo->zo, &dfo->zo); /* clone formatter object */ if (dfo->datef_data.udatf != NULL) { DATE_FORMAT_OBJECT(new_dfo) = udat_clone(DATE_FORMAT_OBJECT(dfo), &INTL_DATA_ERROR_CODE(dfo)); if (U_FAILURE(INTL_DATA_ERROR_CODE(dfo))) { /* set up error in case error handler is interested */ intl_errors_set(INTL_DATA_ERROR_P(dfo), INTL_DATA_ERROR_CODE(dfo), "Failed to clone IntlDateFormatter object", 0 ); zend_throw_exception(NULL, "Failed to clone IntlDateFormatter object", 0); } } else { zend_throw_exception(NULL, "Cannot clone unconstructed IntlDateFormatter", 0); } return new_obj; } /* }}} */ /* * 'IntlDateFormatter' class registration structures & functions */ /* {{{ dateformat_register_class * Initialize 'IntlDateFormatter' class */ void dateformat_register_IntlDateFormatter_class( void ) { /* Create and register 'IntlDateFormatter' class. */ IntlDateFormatter_ce_ptr = register_class_IntlDateFormatter(); IntlDateFormatter_ce_ptr->create_object = IntlDateFormatter_object_create; IntlDateFormatter_ce_ptr->default_object_handlers = &IntlDateFormatter_handlers; memcpy(&IntlDateFormatter_handlers, &std_object_handlers, sizeof IntlDateFormatter_handlers); IntlDateFormatter_handlers.offset = XtOffsetOf(IntlDateFormatter_object, zo); IntlDateFormatter_handlers.clone_obj = IntlDateFormatter_object_clone; IntlDateFormatter_handlers.free_obj = IntlDateFormatter_object_free; } /* }}} */
3,946
33.622807
97
c
php-src
php-src-master/ext/intl/dateformat/dateformat_class.h
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Kirti Velankar <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef DATE_FORMAT_CLASS_H #define DATE_FORMAT_CLASS_H #include <php.h> #include "intl_common.h" #include "intl_error.h" #include "intl_data.h" #include "dateformat_data.h" typedef struct { dateformat_data datef_data; int date_type; int time_type; int calendar; char *requested_locale; zend_object zo; } IntlDateFormatter_object; static inline IntlDateFormatter_object *php_intl_dateformatter_fetch_object(zend_object *obj) { return (IntlDateFormatter_object *)((char*)(obj) - XtOffsetOf(IntlDateFormatter_object, zo)); } #define Z_INTL_DATEFORMATTER_P(zv) php_intl_dateformatter_fetch_object(Z_OBJ_P(zv)) void dateformat_register_IntlDateFormatter_class( void ); extern zend_class_entry *IntlDateFormatter_ce_ptr; /* Auxiliary macros */ #define DATE_FORMAT_METHOD_INIT_VARS INTL_METHOD_INIT_VARS(IntlDateFormatter, dfo) #define DATE_FORMAT_METHOD_FETCH_OBJECT_NO_CHECK INTL_METHOD_FETCH_OBJECT(INTL_DATEFORMATTER, dfo) #define DATE_FORMAT_METHOD_FETCH_OBJECT \ DATE_FORMAT_METHOD_FETCH_OBJECT_NO_CHECK; \ if (dfo->datef_data.udatf == NULL) \ { \ zend_throw_error(NULL, "Found unconstructed IntlDateFormatter"); \ RETURN_THROWS(); \ } #define DATE_FORMAT_OBJECT(dfo) (dfo)->datef_data.udatf #endif // #ifndef DATE_FORMAT_CLASS_H
2,134
37.125
98
h
php-src
php-src-master/ext/intl/dateformat/dateformat_create.h
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Gustavo Lopes <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef DATE_FORMATTER_H #define DATE_FORMATTER_H #include <php.h> #endif // DATE_FORMATTER_H
938
45.95
75
h
php-src
php-src-master/ext/intl/dateformat/dateformat_data.c
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Kirti Velankar <[email protected]> | +----------------------------------------------------------------------+ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "dateformat_data.h" /* {{{ void dateformat_data_init( dateformat_data* datef_data ) * Initialize internals of dateformat_data. */ void dateformat_data_init( dateformat_data* datef_data ) { if( !datef_data ) return; datef_data->udatf = NULL; intl_error_reset( &datef_data->error ); } /* }}} */ /* {{{ void dateformat_data_free( dateformat_data* datef_data ) * Clean up memory allocated for dateformat_data */ void dateformat_data_free( dateformat_data* datef_data ) { if( !datef_data ) return; if( datef_data->udatf ) udat_close( datef_data->udatf ); datef_data->udatf = NULL; intl_error_reset( &datef_data->error ); } /* }}} */ /* {{{ dateformat_data* dateformat_data_create() * Allocate memory for dateformat_data and initialize it with default values. */ dateformat_data* dateformat_data_create( void ) { dateformat_data* datef_data = ecalloc( 1, sizeof(dateformat_data) ); dateformat_data_init( datef_data ); return datef_data; } /* }}} */
1,873
29.721311
77
c
php-src
php-src-master/ext/intl/dateformat/dateformat_data.h
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Kirti Velankar <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef DATE_FORMAT_DATA_H #define DATE_FORMAT_DATA_H #include <php.h> #include <unicode/udat.h> #include "intl_error.h" typedef struct { // error handling intl_error error; // formatter handling UDateFormat * udatf; } dateformat_data; dateformat_data* dateformat_data_create( void ); void dateformat_data_init( dateformat_data* datef_data ); void dateformat_data_free( dateformat_data* datef_data ); #endif // DATE_FORMAT_DATA_H
1,289
34.833333
75
h
php-src
php-src-master/ext/intl/dateformat/dateformat_format.c
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Kirti Velankar <[email protected]> | +----------------------------------------------------------------------+ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "../php_intl.h" #include <unicode/ustring.h> #include <unicode/ucal.h> #include "../intl_convert.h" #include "../common/common_date.h" #include "dateformat.h" #include "dateformat_class.h" #include "dateformat_data.h" /* {{{ Internal function which calls the udat_format */ static void internal_format(IntlDateFormatter_object *dfo, UDate timestamp, zval *return_value) { UChar* formatted = NULL; int32_t resultlengthneeded =0 ; resultlengthneeded=udat_format( DATE_FORMAT_OBJECT(dfo), timestamp, NULL, resultlengthneeded, NULL, &INTL_DATA_ERROR_CODE(dfo)); if(INTL_DATA_ERROR_CODE(dfo)==U_BUFFER_OVERFLOW_ERROR) { INTL_DATA_ERROR_CODE(dfo)=U_ZERO_ERROR; formatted=(UChar*)emalloc(sizeof(UChar) * resultlengthneeded); udat_format( DATE_FORMAT_OBJECT(dfo), timestamp, formatted, resultlengthneeded, NULL, &INTL_DATA_ERROR_CODE(dfo)); } if (formatted && U_FAILURE( INTL_DATA_ERROR_CODE(dfo) ) ) { efree(formatted); } INTL_METHOD_CHECK_STATUS( dfo, "Date formatting failed" ); INTL_METHOD_RETVAL_UTF8( dfo, formatted, resultlengthneeded, 1 ); } /* }}} */ /* {{{ Internal function which fetches an element from the passed array for the key_name passed */ static int32_t internal_get_arr_ele(IntlDateFormatter_object *dfo, HashTable* hash_arr, char* key_name, intl_error *err) { zval *ele_value = NULL; int32_t result = 0; char *message; if (U_FAILURE(err->code)) { return result; } if ((ele_value = zend_hash_str_find(hash_arr, key_name, strlen(key_name))) != NULL) { if(Z_TYPE_P(ele_value) != IS_LONG) { spprintf(&message, 0, "datefmt_format: parameter array contains " "a non-integer element for key '%s'", key_name); intl_errors_set(err, U_ILLEGAL_ARGUMENT_ERROR, message, 1); efree(message); } else { if (Z_LVAL_P(ele_value) > INT32_MAX || Z_LVAL_P(ele_value) < INT32_MIN) { spprintf(&message, 0, "datefmt_format: value " ZEND_LONG_FMT " is out of " "bounds for a 32-bit integer in key '%s'", Z_LVAL_P(ele_value), key_name); intl_errors_set(err, U_ILLEGAL_ARGUMENT_ERROR, message, 1); efree(message); } else { result = Z_LVAL_P(ele_value); } } } return result; } /* }}} */ /* {{{ Internal function which sets UCalendar from the passed array and retrieves timestamp */ static UDate internal_get_timestamp(IntlDateFormatter_object *dfo, HashTable *hash_arr) { int32_t year, month, hour, minute, second, mday; UCalendar *pcal; UDate result; intl_error *err = &dfo->datef_data.error; #define INTL_GET_ELEM(elem) \ internal_get_arr_ele(dfo, hash_arr, (elem), err) /* Fetch values from the incoming array */ year = INTL_GET_ELEM(CALENDAR_YEAR) + 1900; /* tm_year is years since 1900 */ /* Month in ICU and PHP starts from January =0 */ month = INTL_GET_ELEM(CALENDAR_MON); hour = INTL_GET_ELEM(CALENDAR_HOUR); minute = INTL_GET_ELEM(CALENDAR_MIN); second = INTL_GET_ELEM(CALENDAR_SEC); /* For the ucal_setDateTime() function, this is the 'date' value */ mday = INTL_GET_ELEM(CALENDAR_MDAY); #undef INTL_GET_ELEM pcal = ucal_clone(udat_getCalendar(DATE_FORMAT_OBJECT(dfo)), &INTL_DATA_ERROR_CODE(dfo)); if (INTL_DATA_ERROR_CODE(dfo) != U_ZERO_ERROR) { intl_errors_set(err, INTL_DATA_ERROR_CODE(dfo), "datefmt_format: " "error cloning calendar", 0); return 0; } /* set the incoming values for the calendar */ ucal_setDateTime(pcal, year, month, mday, hour, minute, second, &INTL_DATA_ERROR_CODE(dfo)); /* actually, ucal_setDateTime cannot fail */ /* Fetch the timestamp from the UCalendar */ result = ucal_getMillis(pcal, &INTL_DATA_ERROR_CODE(dfo)); ucal_close(pcal); return result; } /* {{{ Format the time value as a string. */ PHP_FUNCTION(datefmt_format) { UDate timestamp = 0; HashTable *hash_arr = NULL; zval *zarg = NULL; DATE_FORMAT_METHOD_INIT_VARS; /* Parse parameters. */ if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Oz", &object, IntlDateFormatter_ce_ptr, &zarg) == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "datefmt_format: unable " "to parse input params", 0 ); RETURN_THROWS(); } DATE_FORMAT_METHOD_FETCH_OBJECT; if (Z_TYPE_P(zarg) == IS_ARRAY) { hash_arr = Z_ARRVAL_P(zarg); if (!hash_arr || zend_hash_num_elements(hash_arr) == 0) { RETURN_FALSE; } timestamp = internal_get_timestamp(dfo, hash_arr); INTL_METHOD_CHECK_STATUS(dfo, "datefmt_format: date formatting failed") } else { timestamp = intl_zval_to_millis(zarg, INTL_DATA_ERROR_P(dfo), "datefmt_format"); if (U_FAILURE(INTL_DATA_ERROR_CODE(dfo))) { RETURN_FALSE; } } internal_format( dfo, timestamp, return_value); } /* }}} */
5,567
30.106145
129
c
php-src
php-src-master/ext/intl/dateformat/dateformat_helpers.h
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Gustavo Lopes <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef DATEFORMAT_HELPERS_H #define DATEFORMAT_HELPERS_H #ifndef __cplusplus #error For C++ only #endif #include <unicode/calendar.h> #include <unicode/datefmt.h> extern "C" { #include "../php_intl.h" } using icu::Locale; using icu::Calendar; using icu::DateFormat; int datefmt_process_calendar_arg( zend_object *calendar_obj, zend_long calendar_long, bool calendar_is_null, Locale const& locale, const char *func_name, intl_error *err, Calendar*& cal, zend_long& cal_int_type, bool& calendar_owned ); #endif /* DATEFORMAT_HELPERS_H */
1,388
34.615385
102
h
php-src
php-src-master/ext/intl/dateformat/datepatterngenerator_arginfo.h
/* This is a generated file, edit the .stub.php file instead. * Stub hash: 4456b13f7ed59847bbf129cd45b0d1f63ce70108 */ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_IntlDatePatternGenerator___construct, 0, 0, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, locale, IS_STRING, 1, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_IntlDatePatternGenerator_create, 0, 0, IntlDatePatternGenerator, 1) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, locale, IS_STRING, 1, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_class_IntlDatePatternGenerator_getBestPattern, 0, 1, MAY_BE_STRING|MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, skeleton, IS_STRING, 0) ZEND_END_ARG_INFO() ZEND_METHOD(IntlDatePatternGenerator, __construct); ZEND_METHOD(IntlDatePatternGenerator, create); ZEND_METHOD(IntlDatePatternGenerator, getBestPattern); static const zend_function_entry class_IntlDatePatternGenerator_methods[] = { ZEND_ME(IntlDatePatternGenerator, __construct, arginfo_class_IntlDatePatternGenerator___construct, ZEND_ACC_PUBLIC) ZEND_ME(IntlDatePatternGenerator, create, arginfo_class_IntlDatePatternGenerator_create, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) ZEND_ME(IntlDatePatternGenerator, getBestPattern, arginfo_class_IntlDatePatternGenerator_getBestPattern, ZEND_ACC_PUBLIC) ZEND_FE_END }; static zend_class_entry *register_class_IntlDatePatternGenerator(void) { zend_class_entry ce, *class_entry; INIT_CLASS_ENTRY(ce, "IntlDatePatternGenerator", class_IntlDatePatternGenerator_methods); class_entry = zend_register_internal_class_ex(&ce, NULL); class_entry->ce_flags |= ZEND_ACC_NOT_SERIALIZABLE; return class_entry; }
1,661
41.615385
128
h
php-src
php-src-master/ext/intl/dateformat/datepatterngenerator_class.h
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | http://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Mel Dafert ([email protected]) | +----------------------------------------------------------------------+ */ #ifndef DATEPATTERNGENERATOR_CLASS_H #define DATEPATTERNGENERATOR_CLASS_H #include <php.h> #include "intl_common.h" #include "intl_error.h" #include "intl_data.h" #ifndef USE_DATETIMEPATTERNGENERATOR_POINTER typedef void DateTimePatternGenerator; #else using icu::DateTimePatternGenerator; #endif typedef struct { // error handling intl_error err; // ICU break iterator DateTimePatternGenerator *dtpg; zend_object zo; } IntlDatePatternGenerator_object; static inline IntlDatePatternGenerator_object *php_intl_datepatterngenerator_fetch_object(zend_object *obj) { return (IntlDatePatternGenerator_object *)((char*)(obj) - XtOffsetOf(IntlDatePatternGenerator_object, zo)); } #define Z_INTL_DATEPATTERNGENERATOR_P(zv) php_intl_datepatterngenerator_fetch_object(Z_OBJ_P(zv)) #define DTPATTERNGEN_ERROR(dtpgo) (dtpgo)->err #define DTPATTERNGEN_ERROR_P(dtpgo) &(DTPATTERNGEN_ERROR(dtpgo)) #define DTPATTERNGEN_ERROR_CODE(dtpgo) INTL_ERROR_CODE(DTPATTERNGEN_ERROR(dtpgo)) #define DTPATTERNGEN_ERROR_CODE_P(dtpgo) &(INTL_ERROR_CODE(DTPATTERNGEN_ERROR(dtpgo))) #define DTPATTERNGEN_METHOD_INIT_VARS INTL_METHOD_INIT_VARS(IntlDatePatternGenerator, dtpgo) #define DTPATTERNGEN_METHOD_FETCH_OBJECT_NO_CHECK INTL_METHOD_FETCH_OBJECT(INTL_DATEPATTERNGENERATOR, dtpgo) #define DTPATTERNGEN_METHOD_FETCH_OBJECT \ DTPATTERNGEN_METHOD_FETCH_OBJECT_NO_CHECK; \ if (dtpgo->dtpg == NULL) \ { \ zend_throw_error(NULL, "Found unconstructed IntlDatePatternGenerator"); \ RETURN_THROWS(); \ } void dateformat_register_IntlDatePatternGenerator_class(void); extern zend_class_entry *IntlDatePatternGenerator_ce_ptr; extern zend_object_handlers IntlDatePatternGenerator_handlers; #endif /* #ifndef DATEPATTERNGENERATOR_CLASS_H */
2,584
37.58209
109
h
php-src
php-src-master/ext/intl/formatter/formatter_attr.c
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Stanislav Malyshev <[email protected]> | +----------------------------------------------------------------------+ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "php_intl.h" #include "formatter_class.h" #include "intl_convert.h" #include <unicode/ustring.h> /* {{{ Get formatter attribute value. */ PHP_FUNCTION( numfmt_get_attribute ) { zend_long attribute, value; FORMATTER_METHOD_INIT_VARS; /* Parse parameters. */ if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "Ol", &object, NumberFormatter_ce_ptr, &attribute ) == FAILURE ) { RETURN_THROWS(); } /* Fetch the object. */ FORMATTER_METHOD_FETCH_OBJECT; switch(attribute) { case UNUM_PARSE_INT_ONLY: case UNUM_GROUPING_USED: case UNUM_DECIMAL_ALWAYS_SHOWN: case UNUM_MAX_INTEGER_DIGITS: case UNUM_MIN_INTEGER_DIGITS: case UNUM_INTEGER_DIGITS: case UNUM_MAX_FRACTION_DIGITS: case UNUM_MIN_FRACTION_DIGITS: case UNUM_FRACTION_DIGITS: case UNUM_MULTIPLIER: case UNUM_GROUPING_SIZE: case UNUM_ROUNDING_MODE: case UNUM_FORMAT_WIDTH: case UNUM_PADDING_POSITION: case UNUM_SECONDARY_GROUPING_SIZE: case UNUM_SIGNIFICANT_DIGITS_USED: case UNUM_MIN_SIGNIFICANT_DIGITS: case UNUM_MAX_SIGNIFICANT_DIGITS: case UNUM_LENIENT_PARSE: value = unum_getAttribute(FORMATTER_OBJECT(nfo), attribute); if(value == -1) { INTL_DATA_ERROR_CODE(nfo) = U_UNSUPPORTED_ERROR; } else { RETVAL_LONG(value); } break; case UNUM_ROUNDING_INCREMENT: { double value_double = unum_getDoubleAttribute(FORMATTER_OBJECT(nfo), attribute); if(value_double == -1) { INTL_DATA_ERROR_CODE(nfo) = U_UNSUPPORTED_ERROR; } else { RETVAL_DOUBLE(value_double); } } break; default: INTL_DATA_ERROR_CODE(nfo) = U_UNSUPPORTED_ERROR; break; } INTL_METHOD_CHECK_STATUS( nfo, "Error getting attribute value" ); } /* }}} */ /* {{{ Get formatter attribute value. */ PHP_FUNCTION( numfmt_get_text_attribute ) { zend_long attribute; UChar value_buf[64]; int32_t value_buf_size = USIZE( value_buf ); UChar* value = value_buf; int32_t length = 0; FORMATTER_METHOD_INIT_VARS; /* Parse parameters. */ if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "Ol", &object, NumberFormatter_ce_ptr, &attribute ) == FAILURE ) { RETURN_THROWS(); } /* Fetch the object. */ FORMATTER_METHOD_FETCH_OBJECT; length = unum_getTextAttribute( FORMATTER_OBJECT(nfo), attribute, value, value_buf_size, &INTL_DATA_ERROR_CODE(nfo) ); if(INTL_DATA_ERROR_CODE(nfo) == U_BUFFER_OVERFLOW_ERROR && length >= value_buf_size) { ++length; /* to avoid U_STRING_NOT_TERMINATED_WARNING */ INTL_DATA_ERROR_CODE(nfo) = U_ZERO_ERROR; value = eumalloc(length); length = unum_getTextAttribute( FORMATTER_OBJECT(nfo), attribute, value, length, &INTL_DATA_ERROR_CODE(nfo) ); if(U_FAILURE(INTL_DATA_ERROR_CODE(nfo))) { efree(value); value = value_buf; } } INTL_METHOD_CHECK_STATUS( nfo, "Error getting attribute value" ); INTL_METHOD_RETVAL_UTF8( nfo, value, length, ( value != value_buf ) ); } /* }}} */ /* {{{ Get formatter attribute value. */ PHP_FUNCTION( numfmt_set_attribute ) { zend_long attribute; zval *value; FORMATTER_METHOD_INIT_VARS; /* Parse parameters. */ if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "Oln", &object, NumberFormatter_ce_ptr, &attribute, &value ) == FAILURE) { RETURN_THROWS(); } /* Fetch the object. */ FORMATTER_METHOD_FETCH_OBJECT; switch(attribute) { case UNUM_PARSE_INT_ONLY: case UNUM_GROUPING_USED: case UNUM_DECIMAL_ALWAYS_SHOWN: case UNUM_MAX_INTEGER_DIGITS: case UNUM_MIN_INTEGER_DIGITS: case UNUM_INTEGER_DIGITS: case UNUM_MAX_FRACTION_DIGITS: case UNUM_MIN_FRACTION_DIGITS: case UNUM_FRACTION_DIGITS: case UNUM_MULTIPLIER: case UNUM_GROUPING_SIZE: case UNUM_ROUNDING_MODE: case UNUM_FORMAT_WIDTH: case UNUM_PADDING_POSITION: case UNUM_SECONDARY_GROUPING_SIZE: case UNUM_SIGNIFICANT_DIGITS_USED: case UNUM_MIN_SIGNIFICANT_DIGITS: case UNUM_MAX_SIGNIFICANT_DIGITS: case UNUM_LENIENT_PARSE: unum_setAttribute(FORMATTER_OBJECT(nfo), attribute, zval_get_long(value)); break; case UNUM_ROUNDING_INCREMENT: unum_setDoubleAttribute(FORMATTER_OBJECT(nfo), attribute, zval_get_double(value)); break; default: INTL_DATA_ERROR_CODE(nfo) = U_UNSUPPORTED_ERROR; break; } INTL_METHOD_CHECK_STATUS( nfo, "Error setting attribute value" ); RETURN_TRUE; } /* }}} */ /* {{{ Get formatter attribute value. */ PHP_FUNCTION( numfmt_set_text_attribute ) { int32_t slength = 0; UChar *svalue = NULL; zend_long attribute; char *value; size_t len; FORMATTER_METHOD_INIT_VARS; /* Parse parameters. */ if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "Ols", &object, NumberFormatter_ce_ptr, &attribute, &value, &len ) == FAILURE) { RETURN_THROWS(); } /* Fetch the object. */ FORMATTER_METHOD_FETCH_OBJECT; /* Convert given attribute value to UTF-16. */ intl_convert_utf8_to_utf16(&svalue, &slength, value, len, &INTL_DATA_ERROR_CODE(nfo)); INTL_METHOD_CHECK_STATUS( nfo, "Error converting attribute value to UTF-16" ); /* Actually set new attribute value. */ unum_setTextAttribute(FORMATTER_OBJECT(nfo), attribute, svalue, slength, &INTL_DATA_ERROR_CODE(nfo)); if (svalue) { efree(svalue); } INTL_METHOD_CHECK_STATUS( nfo, "Error setting text attribute" ); RETURN_TRUE; } /* }}} */ /* {{{ Get formatter symbol value. */ PHP_FUNCTION( numfmt_get_symbol ) { zend_long symbol; UChar value_buf[4]; UChar *value = value_buf; uint32_t length = USIZE(value_buf); FORMATTER_METHOD_INIT_VARS; /* Parse parameters. */ if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "Ol", &object, NumberFormatter_ce_ptr, &symbol ) == FAILURE ) { RETURN_THROWS(); } if(symbol >= UNUM_FORMAT_SYMBOL_COUNT || symbol < 0) { intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "numfmt_get_symbol: invalid symbol value", 0 ); RETURN_FALSE; } /* Fetch the object. */ FORMATTER_METHOD_FETCH_OBJECT; length = unum_getSymbol(FORMATTER_OBJECT(nfo), symbol, value_buf, length, &INTL_DATA_ERROR_CODE(nfo)); if(INTL_DATA_ERROR_CODE(nfo) == U_BUFFER_OVERFLOW_ERROR && length >= USIZE( value_buf )) { ++length; /* to avoid U_STRING_NOT_TERMINATED_WARNING */ INTL_DATA_ERROR_CODE(nfo) = U_ZERO_ERROR; value = eumalloc(length); length = unum_getSymbol(FORMATTER_OBJECT(nfo), symbol, value, length, &INTL_DATA_ERROR_CODE(nfo)); if(U_FAILURE(INTL_DATA_ERROR_CODE(nfo))) { efree(value); value = value_buf; } } INTL_METHOD_CHECK_STATUS( nfo, "Error getting symbol value" ); INTL_METHOD_RETVAL_UTF8( nfo, value, length, ( value_buf != value ) ); } /* }}} */ /* {{{ Set formatter symbol value. */ PHP_FUNCTION( numfmt_set_symbol ) { zend_long symbol; char* value = NULL; size_t value_len = 0; UChar* svalue = 0; int32_t slength = 0; FORMATTER_METHOD_INIT_VARS; /* Parse parameters. */ if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "Ols", &object, NumberFormatter_ce_ptr, &symbol, &value, &value_len ) == FAILURE ) { RETURN_THROWS(); } if (symbol >= UNUM_FORMAT_SYMBOL_COUNT || symbol < 0) { intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "numfmt_set_symbol: invalid symbol value", 0 ); RETURN_FALSE; } /* Fetch the object. */ FORMATTER_METHOD_FETCH_OBJECT; /* Convert given symbol to UTF-16. */ intl_convert_utf8_to_utf16(&svalue, &slength, value, value_len, &INTL_DATA_ERROR_CODE(nfo)); INTL_METHOD_CHECK_STATUS( nfo, "Error converting symbol value to UTF-16" ); /* Actually set the symbol. */ unum_setSymbol(FORMATTER_OBJECT(nfo), symbol, svalue, slength, &INTL_DATA_ERROR_CODE(nfo)); if (svalue) { efree(svalue); } INTL_METHOD_CHECK_STATUS( nfo, "Error setting symbol value" ); RETURN_TRUE; } /* }}} */ /* {{{ Get formatter pattern. */ PHP_FUNCTION( numfmt_get_pattern ) { UChar value_buf[64]; uint32_t length = USIZE( value_buf ); UChar* value = value_buf; FORMATTER_METHOD_INIT_VARS; /* Parse parameters. */ if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "O", &object, NumberFormatter_ce_ptr ) == FAILURE ) { RETURN_THROWS(); } /* Fetch the object. */ FORMATTER_METHOD_FETCH_OBJECT; length = unum_toPattern(FORMATTER_OBJECT(nfo), 0, value, length, &INTL_DATA_ERROR_CODE(nfo)); if(INTL_DATA_ERROR_CODE(nfo) == U_BUFFER_OVERFLOW_ERROR && length >= USIZE( value_buf )) { ++length; /* to avoid U_STRING_NOT_TERMINATED_WARNING */ INTL_DATA_ERROR_CODE(nfo) = U_ZERO_ERROR; value = eumalloc(length); length = unum_toPattern( FORMATTER_OBJECT(nfo), 0, value, length, &INTL_DATA_ERROR_CODE(nfo) ); if(U_FAILURE(INTL_DATA_ERROR_CODE(nfo))) { efree(value); value = value_buf; } } INTL_METHOD_CHECK_STATUS( nfo, "Error getting formatter pattern" ); INTL_METHOD_RETVAL_UTF8( nfo, value, length, ( value != value_buf ) ); } /* }}} */ /* {{{ Set formatter pattern. */ PHP_FUNCTION( numfmt_set_pattern ) { char* value = NULL; size_t value_len = 0; int32_t slength = 0; UChar* svalue = NULL; UParseError spattern_error = {0}; FORMATTER_METHOD_INIT_VARS; /* Parse parameters. */ if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "Os", &object, NumberFormatter_ce_ptr, &value, &value_len ) == FAILURE ) { RETURN_THROWS(); } FORMATTER_METHOD_FETCH_OBJECT; /* Convert given pattern to UTF-16. */ intl_convert_utf8_to_utf16(&svalue, &slength, value, value_len, &INTL_DATA_ERROR_CODE(nfo)); INTL_METHOD_CHECK_STATUS( nfo, "Error converting pattern to UTF-16" ); unum_applyPattern(FORMATTER_OBJECT(nfo), 0, svalue, slength, &spattern_error, &INTL_DATA_ERROR_CODE(nfo)); if (svalue) { efree(svalue); } if (U_FAILURE(INTL_DATA_ERROR_CODE(nfo))) { char *msg; spprintf(&msg, 0, "Error setting pattern value at line %d, offset %d", spattern_error.line, spattern_error.offset); intl_errors_set_custom_msg(INTL_DATA_ERROR_P(nfo), msg, 1); efree(msg); RETURN_FALSE; } RETURN_TRUE; } /* }}} */ /* {{{ Get formatter locale. */ PHP_FUNCTION( numfmt_get_locale ) { zend_long type = ULOC_ACTUAL_LOCALE; char* loc; FORMATTER_METHOD_INIT_VARS; /* Parse parameters. */ if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "O|l", &object, NumberFormatter_ce_ptr, &type ) == FAILURE ) { RETURN_THROWS(); } /* Fetch the object. */ FORMATTER_METHOD_FETCH_OBJECT; loc = (char *)unum_getLocaleByType(FORMATTER_OBJECT(nfo), type, &INTL_DATA_ERROR_CODE(nfo)); INTL_METHOD_CHECK_STATUS( nfo, "Error getting locale" ); RETURN_STRING(loc); } /* }}} */
11,301
28.053985
119
c
php-src
php-src-master/ext/intl/formatter/formatter_class.c
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Stanislav Malyshev <[email protected]> | +----------------------------------------------------------------------+ */ #include <unicode/unum.h> #include "formatter_class.h" #include "php_intl.h" #include "formatter_data.h" #include "formatter_format.h" #include "formatter_arginfo.h" #include <zend_exceptions.h> #include "Zend/zend_interfaces.h" zend_class_entry *NumberFormatter_ce_ptr = NULL; static zend_object_handlers NumberFormatter_handlers; /* * Auxiliary functions needed by objects of 'NumberFormatter' class */ /* {{{ NumberFormatter_objects_free */ void NumberFormatter_object_free( zend_object *object ) { NumberFormatter_object* nfo = php_intl_number_format_fetch_object(object); zend_object_std_dtor( &nfo->zo ); formatter_data_free( &nfo->nf_data ); } /* }}} */ /* {{{ NumberFormatter_object_create */ zend_object *NumberFormatter_object_create(zend_class_entry *ce) { NumberFormatter_object* intern; intern = zend_object_alloc(sizeof(NumberFormatter_object), ce); formatter_data_init( &intern->nf_data ); zend_object_std_init( &intern->zo, ce ); object_properties_init(&intern->zo, ce); return &intern->zo; } /* }}} */ /* {{{ NumberFormatter_object_clone */ zend_object *NumberFormatter_object_clone(zend_object *object) { NumberFormatter_object *nfo, *new_nfo; zend_object *new_obj; nfo = php_intl_number_format_fetch_object(object); intl_error_reset(INTL_DATA_ERROR_P(nfo)); new_obj = NumberFormatter_ce_ptr->create_object(object->ce); new_nfo = php_intl_number_format_fetch_object(new_obj); /* clone standard parts */ zend_objects_clone_members(&new_nfo->zo, &nfo->zo); /* clone formatter object. It may fail, the destruction code must handle this case */ if (FORMATTER_OBJECT(nfo) != NULL) { FORMATTER_OBJECT(new_nfo) = unum_clone(FORMATTER_OBJECT(nfo), &INTL_DATA_ERROR_CODE(nfo)); if (U_FAILURE(INTL_DATA_ERROR_CODE(nfo))) { /* set up error in case error handler is interested */ intl_errors_set(INTL_DATA_ERROR_P(nfo), INTL_DATA_ERROR_CODE(nfo), "Failed to clone NumberFormatter object", 0); zend_throw_exception(NULL, "Failed to clone NumberFormatter object", 0); } } else { zend_throw_exception(NULL, "Cannot clone unconstructed NumberFormatter", 0); } return new_obj; } /* }}} */ /* * 'NumberFormatter' class registration structures & functions */ /* {{{ formatter_register_class * Initialize 'NumberFormatter' class */ void formatter_register_class( void ) { /* Create and register 'NumberFormatter' class. */ NumberFormatter_ce_ptr = register_class_NumberFormatter(); NumberFormatter_ce_ptr->create_object = NumberFormatter_object_create; NumberFormatter_ce_ptr->default_object_handlers = &NumberFormatter_handlers; memcpy(&NumberFormatter_handlers, &std_object_handlers, sizeof(NumberFormatter_handlers)); NumberFormatter_handlers.offset = XtOffsetOf(NumberFormatter_object, zo); NumberFormatter_handlers.clone_obj = NumberFormatter_object_clone; NumberFormatter_handlers.free_obj = NumberFormatter_object_free; } /* }}} */
3,765
33.550459
86
c
php-src
php-src-master/ext/intl/formatter/formatter_class.h
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Stanislav Malyshev <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef FORMATTER_CLASS_H #define FORMATTER_CLASS_H #include <php.h> #include "intl_common.h" #include "intl_error.h" #include "intl_data.h" #include "formatter_data.h" typedef struct { formatter_data nf_data; zend_object zo; } NumberFormatter_object; static inline NumberFormatter_object *php_intl_number_format_fetch_object(zend_object *obj) { return (NumberFormatter_object *)((char*)(obj) - XtOffsetOf(NumberFormatter_object, zo)); } #define Z_INTL_NUMBERFORMATTER_P(zv) php_intl_number_format_fetch_object(Z_OBJ_P(zv)) void formatter_register_class( void ); extern zend_class_entry *NumberFormatter_ce_ptr; /* Auxiliary macros */ #define FORMATTER_METHOD_INIT_VARS INTL_METHOD_INIT_VARS(NumberFormatter, nfo) #define FORMATTER_OBJECT(nfo) (nfo)->nf_data.unum #define FORMATTER_METHOD_FETCH_OBJECT_NO_CHECK INTL_METHOD_FETCH_OBJECT(INTL_NUMBERFORMATTER, nfo) #define FORMATTER_METHOD_FETCH_OBJECT \ FORMATTER_METHOD_FETCH_OBJECT_NO_CHECK; \ if (FORMATTER_OBJECT(nfo) == NULL) \ { \ zend_throw_error(NULL, "Found unconstructed NumberFormatter"); \ RETURN_THROWS(); \ } #endif // #ifndef FORMATTER_CLASS_H
1,984
36.45283
98
h
php-src
php-src-master/ext/intl/formatter/formatter_data.c
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Stanislav Malyshev <[email protected]> | +----------------------------------------------------------------------+ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "formatter_data.h" /* {{{ void formatter_data_init( formatter_data* nf_data ) * Initialize internals of formatter_data. */ void formatter_data_init( formatter_data* nf_data ) { if( !nf_data ) return; nf_data->unum = NULL; intl_error_reset( &nf_data->error ); } /* }}} */ /* {{{ void formatter_data_free( formatter_data* nf_data ) * Clean up mem allocted by internals of formatter_data */ void formatter_data_free( formatter_data* nf_data ) { if( !nf_data ) return; if( nf_data->unum ) unum_close( nf_data->unum ); nf_data->unum = NULL; intl_error_reset( &nf_data->error ); } /* }}} */ /* {{{ formatter_data* formatter_data_create() * Alloc mem for formatter_data and initialize it with default values. */ formatter_data* formatter_data_create( void ) { formatter_data* nf_data = ecalloc( 1, sizeof(formatter_data) ); formatter_data_init( nf_data ); return nf_data; } /* }}} */
1,824
28.435484
75
c
php-src
php-src-master/ext/intl/formatter/formatter_data.h
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Stanislav Malyshev <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef FORMATTER_DATA_H #define FORMATTER_DATA_H #include <php.h> #include <unicode/unum.h> #include "intl_error.h" typedef struct { // error hangling intl_error error; // formatter handling UNumberFormat* unum; } formatter_data; formatter_data* formatter_data_create( void ); void formatter_data_init( formatter_data* nf_data ); void formatter_data_free( formatter_data* nf_data ); #endif // FORMATTER_DATA_H
1,272
33.405405
75
h
php-src
php-src-master/ext/intl/formatter/formatter_format.h
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Stanislav Malyshev <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef FORMATTER_FORMAT_H #define FORMATTER_FORMAT_H #include <php.h> #define FORMAT_TYPE_DEFAULT 0 #define FORMAT_TYPE_INT32 1 #define FORMAT_TYPE_INT64 2 #define FORMAT_TYPE_DOUBLE 3 #define FORMAT_TYPE_CURRENCY 4 #endif // FORMATTER_FORMAT_H
1,093
39.518519
75
h
php-src
php-src-master/ext/intl/formatter/formatter_functions_arginfo.h
/* This is a generated file, edit the .stub.php file instead. */ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_numfmt_create, 0, 2, NumberFormatter, 1) ZEND_ARG_TYPE_INFO(0, locale, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, style, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, pattern, IS_STRING, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_numfmt_format, 0, 2, MAY_BE_STRING|MAY_BE_FALSE) ZEND_ARG_OBJ_INFO(0, fmt, NumberFormatter, 0) ZEND_ARG_TYPE_MASK(0, value, MAY_BE_LONG|MAY_BE_DOUBLE) ZEND_ARG_TYPE_INFO(0, type, IS_LONG, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_numfmt_parse, 0, 2, MAY_BE_LONG|MAY_BE_DOUBLE|MAY_BE_FALSE) ZEND_ARG_OBJ_INFO(0, fmt, NumberFormatter, 0) ZEND_ARG_TYPE_INFO(0, value, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, type, IS_LONG, 0) ZEND_ARG_INFO(1, position) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_numfmt_format_currency, 0, 3, MAY_BE_STRING|MAY_BE_FALSE) ZEND_ARG_OBJ_INFO(0, fmt, NumberFormatter, 0) ZEND_ARG_TYPE_INFO(0, value, IS_DOUBLE, 0) ZEND_ARG_TYPE_INFO(0, currency, IS_STRING, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_numfmt_parse_currency, 0, 3, MAY_BE_DOUBLE|MAY_BE_FALSE) ZEND_ARG_OBJ_INFO(0, fmt, NumberFormatter, 0) ZEND_ARG_TYPE_INFO(0, value, IS_STRING, 0) ZEND_ARG_INFO(1, currency) ZEND_ARG_INFO(1, position) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_numfmt_set_attribute, 0, 3, _IS_BOOL, 0) ZEND_ARG_OBJ_INFO(0, fmt, NumberFormatter, 0) ZEND_ARG_TYPE_INFO(0, attr, IS_LONG, 0) ZEND_ARG_INFO(0, value) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_numfmt_get_attribute, 0, 2, double, MAY_BE_LONG|MAY_BE_FALSE) ZEND_ARG_OBJ_INFO(0, fmt, NumberFormatter, 0) ZEND_ARG_TYPE_INFO(0, attr, IS_LONG, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_numfmt_set_text_attribute, 0, 3, _IS_BOOL, 0) ZEND_ARG_OBJ_INFO(0, fmt, NumberFormatter, 0) ZEND_ARG_TYPE_INFO(0, attr, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, value, IS_STRING, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_numfmt_get_text_attribute, 0, 2, MAY_BE_STRING|MAY_BE_FALSE) ZEND_ARG_OBJ_INFO(0, fmt, NumberFormatter, 0) ZEND_ARG_TYPE_INFO(0, attr, IS_LONG, 0) ZEND_END_ARG_INFO() #define arginfo_numfmt_set_symbol arginfo_numfmt_set_text_attribute #define arginfo_numfmt_get_symbol arginfo_numfmt_get_text_attribute ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_numfmt_set_pattern, 0, 2, _IS_BOOL, 0) ZEND_ARG_OBJ_INFO(0, fmt, NumberFormatter, 0) ZEND_ARG_TYPE_INFO(0, pattern, IS_STRING, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_numfmt_get_pattern, 0, 1, MAY_BE_STRING|MAY_BE_FALSE) ZEND_ARG_OBJ_INFO(0, fmt, NumberFormatter, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_numfmt_get_locale, 0, 1, MAY_BE_STRING|MAY_BE_FALSE) ZEND_ARG_OBJ_INFO(0, fmt, NumberFormatter, 0) ZEND_ARG_TYPE_INFO(0, type, IS_LONG, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_numfmt_get_error_code, 0, 1, IS_LONG, 0) ZEND_ARG_OBJ_INFO(0, fmt, NumberFormatter, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_numfmt_get_error_message, 0, 1, IS_STRING, 0) ZEND_ARG_OBJ_INFO(0, fmt, NumberFormatter, 0) ZEND_END_ARG_INFO()
3,346
39.817073
113
h
php-src
php-src-master/ext/intl/formatter/formatter_main.c
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Stanislav Malyshev <[email protected]> | +----------------------------------------------------------------------+ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include <unicode/ustring.h> #include "php_intl.h" #include "formatter_class.h" #include "intl_convert.h" /* {{{ */ static int numfmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_error_handling *error_handling, bool *error_handling_replaced) { const char* locale; char* pattern = NULL; size_t locale_len = 0, pattern_len = 0; zend_long style; UChar* spattern = NULL; int32_t spattern_len = 0; FORMATTER_METHOD_INIT_VARS; /* Parse parameters. */ if( zend_parse_parameters( ZEND_NUM_ARGS(), "sl|s!", &locale, &locale_len, &style, &pattern, &pattern_len ) == FAILURE ) { return FAILURE; } if (error_handling != NULL) { zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, error_handling); *error_handling_replaced = 1; } INTL_CHECK_LOCALE_LEN_OR_FAILURE(locale_len); object = return_value; FORMATTER_METHOD_FETCH_OBJECT_NO_CHECK; if (FORMATTER_OBJECT(nfo)) { zend_throw_error(NULL, "NumberFormatter object is already constructed"); return FAILURE; } /* Convert pattern (if specified) to UTF-16. */ if(pattern && pattern_len) { intl_convert_utf8_to_utf16(&spattern, &spattern_len, pattern, pattern_len, &INTL_DATA_ERROR_CODE(nfo)); INTL_CTOR_CHECK_STATUS(nfo, "numfmt_create: error converting pattern to UTF-16"); } if(locale_len == 0) { locale = intl_locale_get_default(); } /* Create an ICU number formatter. */ FORMATTER_OBJECT(nfo) = unum_open(style, spattern, spattern_len, locale, NULL, &INTL_DATA_ERROR_CODE(nfo)); if(spattern) { efree(spattern); } INTL_CTOR_CHECK_STATUS(nfo, "numfmt_create: number formatter creation failed"); return SUCCESS; } /* }}} */ /* {{{ Create number formatter. */ PHP_FUNCTION( numfmt_create ) { object_init_ex( return_value, NumberFormatter_ce_ptr ); if (numfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, NULL, NULL) == FAILURE) { zval_ptr_dtor(return_value); RETURN_NULL(); } } /* }}} */ /* {{{ NumberFormatter object constructor. */ PHP_METHOD( NumberFormatter, __construct ) { zend_error_handling error_handling; bool error_handling_replaced = 0; return_value = ZEND_THIS; if (numfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, &error_handling, &error_handling_replaced) == FAILURE) { if (!EG(exception)) { zend_throw_exception(IntlException_ce_ptr, "Constructor failed", 0); } } if (error_handling_replaced) { zend_restore_error_handling(&error_handling); } } /* }}} */ /* {{{ Get formatter's last error code. */ PHP_FUNCTION( numfmt_get_error_code ) { FORMATTER_METHOD_INIT_VARS /* Parse parameters. */ if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "O", &object, NumberFormatter_ce_ptr ) == FAILURE ) { RETURN_THROWS(); } nfo = Z_INTL_NUMBERFORMATTER_P(object); /* Return formatter's last error code. */ RETURN_LONG( INTL_DATA_ERROR_CODE(nfo) ); } /* }}} */ /* {{{ Get text description for formatter's last error code. */ PHP_FUNCTION( numfmt_get_error_message ) { zend_string *message = NULL; FORMATTER_METHOD_INIT_VARS /* Parse parameters. */ if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "O", &object, NumberFormatter_ce_ptr ) == FAILURE ) { RETURN_THROWS(); } nfo = Z_INTL_NUMBERFORMATTER_P(object); /* Return last error message. */ message = intl_error_get_message( INTL_DATA_ERROR_P(nfo) ); RETURN_STR(message); } /* }}} */
4,230
27.979452
120
c
php-src
php-src-master/ext/intl/formatter/formatter_parse.c
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Stanislav Malyshev <[email protected]> | +----------------------------------------------------------------------+ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "php_intl.h" #include <unicode/ustring.h> #include <locale.h> #include "formatter_class.h" #include "formatter_format.h" #include "intl_convert.h" #define ICU_LOCALE_BUG 1 /* {{{ Parse a number. */ PHP_FUNCTION( numfmt_parse ) { zend_long type = FORMAT_TYPE_DOUBLE; UChar* sstr = NULL; int32_t sstr_len = 0; char* str = NULL; size_t str_len; int32_t val32, position = 0; int64_t val64; double val_double; int32_t* position_p = NULL; zval *zposition = NULL; char *oldlocale; FORMATTER_METHOD_INIT_VARS; /* Parse parameters. */ if (zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "Os|lz!", &object, NumberFormatter_ce_ptr, &str, &str_len, &type, &zposition ) == FAILURE ) { RETURN_THROWS(); } if (zposition) { position = (int32_t) zval_get_long(zposition); position_p = &position; } /* Fetch the object. */ FORMATTER_METHOD_FETCH_OBJECT; /* Convert given string to UTF-16. */ intl_convert_utf8_to_utf16(&sstr, &sstr_len, str, str_len, &INTL_DATA_ERROR_CODE(nfo)); INTL_METHOD_CHECK_STATUS( nfo, "String conversion to UTF-16 failed" ); #if ICU_LOCALE_BUG && defined(LC_NUMERIC) /* need to copy here since setlocale may change it later */ oldlocale = estrdup(setlocale(LC_NUMERIC, NULL)); setlocale(LC_NUMERIC, "C"); #endif switch(type) { case FORMAT_TYPE_INT32: val32 = unum_parse(FORMATTER_OBJECT(nfo), sstr, sstr_len, position_p, &INTL_DATA_ERROR_CODE(nfo)); RETVAL_LONG(val32); break; case FORMAT_TYPE_INT64: val64 = unum_parseInt64(FORMATTER_OBJECT(nfo), sstr, sstr_len, position_p, &INTL_DATA_ERROR_CODE(nfo)); if(val64 > ZEND_LONG_MAX || val64 < ZEND_LONG_MIN) { RETVAL_DOUBLE(val64); } else { RETVAL_LONG((zend_long)val64); } break; case FORMAT_TYPE_DOUBLE: val_double = unum_parseDouble(FORMATTER_OBJECT(nfo), sstr, sstr_len, position_p, &INTL_DATA_ERROR_CODE(nfo)); RETVAL_DOUBLE(val_double); break; case FORMAT_TYPE_CURRENCY: if (getThis()) { const char *space; const char *class_name = get_active_class_name(&space); zend_argument_value_error(2, "cannot be NumberFormatter::TYPE_CURRENCY constant, " "use %s%sparseCurrency() method instead", class_name, space); } else { zend_argument_value_error(3, "cannot be NumberFormatter::TYPE_CURRENCY constant, use numfmt_parse_currency() function instead"); } goto cleanup; default: zend_argument_value_error(getThis() ? 2 : 3, "must be a NumberFormatter::TYPE_* constant"); goto cleanup; } if (zposition) { ZEND_TRY_ASSIGN_REF_LONG(zposition, position); } cleanup: #if ICU_LOCALE_BUG && defined(LC_NUMERIC) setlocale(LC_NUMERIC, oldlocale); efree(oldlocale); #endif if (sstr) { efree(sstr); } INTL_METHOD_CHECK_STATUS( nfo, "Number parsing failed" ); } /* }}} */ /* {{{ Parse a number as currency. */ PHP_FUNCTION( numfmt_parse_currency ) { double number; UChar currency[5] = {0}; UChar* sstr = NULL; int32_t sstr_len = 0; zend_string *u8str; char *str; size_t str_len; int32_t* position_p = NULL; int32_t position = 0; zval *zcurrency, *zposition = NULL; FORMATTER_METHOD_INIT_VARS; /* Parse parameters. */ if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "Osz/|z!", &object, NumberFormatter_ce_ptr, &str, &str_len, &zcurrency, &zposition ) == FAILURE ) { RETURN_THROWS(); } /* Fetch the object. */ FORMATTER_METHOD_FETCH_OBJECT; /* Convert given string to UTF-16. */ intl_convert_utf8_to_utf16(&sstr, &sstr_len, str, str_len, &INTL_DATA_ERROR_CODE(nfo)); INTL_METHOD_CHECK_STATUS( nfo, "String conversion to UTF-16 failed" ); if(zposition) { position = (int32_t) zval_get_long(zposition); position_p = &position; } number = unum_parseDoubleCurrency(FORMATTER_OBJECT(nfo), sstr, sstr_len, position_p, currency, &INTL_DATA_ERROR_CODE(nfo)); if(zposition) { ZEND_TRY_ASSIGN_REF_LONG(zposition, position); } if (sstr) { efree(sstr); } INTL_METHOD_CHECK_STATUS( nfo, "Number parsing failed" ); /* Convert parsed currency to UTF-8 and pass it back to caller. */ u8str = intl_convert_utf16_to_utf8(currency, u_strlen(currency), &INTL_DATA_ERROR_CODE(nfo)); INTL_METHOD_CHECK_STATUS( nfo, "Currency conversion to UTF-8 failed" ); zval_ptr_dtor( zcurrency ); ZVAL_NEW_STR(zcurrency, u8str); RETVAL_DOUBLE( number ); } /* }}} */
5,205
28.91954
132
c
php-src
php-src-master/ext/intl/grapheme/grapheme.h
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Ed Batutis <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef GRAPHEME_GRAPHEME_H #define GRAPHEME_GRAPHEME_H #include <php.h> #include <unicode/utypes.h> void grapheme_close_global_iterator( void ); #define GRAPHEME_EXTRACT_TYPE_COUNT 0 #define GRAPHEME_EXTRACT_TYPE_MAXBYTES 1 #define GRAPHEME_EXTRACT_TYPE_MAXCHARS 2 #define GRAPHEME_EXTRACT_TYPE_MIN GRAPHEME_EXTRACT_TYPE_COUNT #define GRAPHEME_EXTRACT_TYPE_MAX GRAPHEME_EXTRACT_TYPE_MAXCHARS #endif // GRAPHEME_GRAPHEME_H
1,272
41.433333
75
h
php-src
php-src-master/ext/intl/grapheme/grapheme_string.c
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: Ed Batutis <[email protected]> | +----------------------------------------------------------------------+ */ /* {{{ includes */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include <php.h> #include "grapheme.h" #include "grapheme_util.h" #include <unicode/utypes.h> #include <unicode/utf8.h> #include <unicode/ucol.h> #include <unicode/ustring.h> #include <unicode/ubrk.h> /* }}} */ /* {{{ Get number of graphemes in a string */ PHP_FUNCTION(grapheme_strlen) { char* string; size_t string_len; UChar* ustring = NULL; int ustring_len = 0; zend_long ret_len; UErrorCode status; if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &string, &string_len) == FAILURE) { RETURN_THROWS(); } ret_len = grapheme_ascii_check((unsigned char *)string, string_len); if ( ret_len >= 0 ) RETURN_LONG(string_len); /* convert the string to UTF-16. */ status = U_ZERO_ERROR; intl_convert_utf8_to_utf16(&ustring, &ustring_len, string, string_len, &status ); if ( U_FAILURE( status ) ) { /* Set global error code. */ intl_error_set_code( NULL, status ); /* Set error messages. */ intl_error_set_custom_msg( NULL, "Error converting input string to UTF-16", 0 ); if (ustring) { efree( ustring ); } RETURN_NULL(); } ret_len = grapheme_split_string(ustring, ustring_len, NULL, 0 ); if (ustring) { efree( ustring ); } if (ret_len >= 0) { RETVAL_LONG(ret_len); } else { RETVAL_FALSE; } } /* }}} */ /* {{{ Find position of first occurrence of a string within another */ PHP_FUNCTION(grapheme_strpos) { char *haystack, *needle; size_t haystack_len, needle_len; const char *found; zend_long loffset = 0; int32_t offset = 0; size_t noffset = 0; zend_long ret_pos; if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|l", &haystack, &haystack_len, &needle, &needle_len, &loffset) == FAILURE) { RETURN_THROWS(); } if ( OUTSIDE_STRING(loffset, haystack_len) ) { zend_argument_value_error(3, "must be contained in argument #1 ($haystack)"); RETURN_THROWS(); } /* we checked that it will fit: */ offset = (int32_t) loffset; noffset = offset >= 0 ? offset : (int32_t)haystack_len + offset; /* the offset is 'grapheme count offset' so it still might be invalid - we'll check it later */ if (offset >= 0 && grapheme_ascii_check((unsigned char *)haystack, haystack_len) >= 0) { /* quick check to see if the string might be there * I realize that 'offset' is 'grapheme count offset' but will work in spite of that */ found = php_memnstr(haystack + noffset, needle, needle_len, haystack + haystack_len); /* if it isn't there the we are done */ if (found) { RETURN_LONG(found - haystack); } RETURN_FALSE; } /* do utf16 part of the strpos */ ret_pos = grapheme_strpos_utf16(haystack, haystack_len, needle, needle_len, offset, NULL, 0 /* fIgnoreCase */, 0 /* last */ ); if ( ret_pos >= 0 ) { RETURN_LONG(ret_pos); } else { RETURN_FALSE; } } /* }}} */ /* {{{ Find position of first occurrence of a string within another, ignoring case differences */ PHP_FUNCTION(grapheme_stripos) { char *haystack, *needle; size_t haystack_len, needle_len; const char *found; zend_long loffset = 0; int32_t offset = 0; zend_long ret_pos; int is_ascii; if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|l", &haystack, &haystack_len, &needle, &needle_len, &loffset) == FAILURE) { RETURN_THROWS(); } if ( OUTSIDE_STRING(loffset, haystack_len) ) { zend_argument_value_error(3, "must be contained in argument #1 ($haystack)"); RETURN_THROWS(); } /* we checked that it will fit: */ offset = (int32_t) loffset; /* the offset is 'grapheme count offset' so it still might be invalid - we'll check it later */ is_ascii = ( grapheme_ascii_check((unsigned char*)haystack, haystack_len) >= 0 ); if ( is_ascii ) { char *haystack_dup, *needle_dup; int32_t noffset = offset >= 0 ? offset : (int32_t)haystack_len + offset; needle_dup = estrndup(needle, needle_len); zend_str_tolower(needle_dup, needle_len); haystack_dup = estrndup(haystack, haystack_len); zend_str_tolower(haystack_dup, haystack_len); found = php_memnstr(haystack_dup + noffset, needle_dup, needle_len, haystack_dup + haystack_len); efree(haystack_dup); efree(needle_dup); if (found) { RETURN_LONG(found - haystack_dup); } /* if needle was ascii too, we are all done, otherwise we need to try using Unicode to see what we get */ if ( grapheme_ascii_check((unsigned char *)needle, needle_len) >= 0 ) { RETURN_FALSE; } } /* do utf16 part of the strpos */ ret_pos = grapheme_strpos_utf16(haystack, haystack_len, needle, needle_len, offset, NULL, 1 /* fIgnoreCase */, 0 /*last */ ); if ( ret_pos >= 0 ) { RETURN_LONG(ret_pos); } else { RETURN_FALSE; } } /* }}} */ /* {{{ Find position of last occurrence of a string within another */ PHP_FUNCTION(grapheme_strrpos) { char *haystack, *needle; size_t haystack_len, needle_len; zend_long loffset = 0; int32_t offset = 0; zend_long ret_pos; int is_ascii; if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|l", &haystack, &haystack_len, &needle, &needle_len, &loffset) == FAILURE) { RETURN_THROWS(); } if ( OUTSIDE_STRING(loffset, haystack_len) ) { zend_argument_value_error(3, "must be contained in argument #1 ($haystack)"); RETURN_THROWS(); } /* we checked that it will fit: */ offset = (int32_t) loffset; /* the offset is 'grapheme count offset' so it still might be invalid - we'll check it later */ is_ascii = grapheme_ascii_check((unsigned char *)haystack, haystack_len) >= 0; if ( is_ascii ) { ret_pos = grapheme_strrpos_ascii(haystack, haystack_len, needle, needle_len, offset); if ( ret_pos >= 0 ) { RETURN_LONG(ret_pos); } /* if the needle was ascii too, we are done */ if ( grapheme_ascii_check((unsigned char *)needle, needle_len) >= 0 ) { RETURN_FALSE; } /* else we need to continue via utf16 */ } ret_pos = grapheme_strpos_utf16(haystack, haystack_len, needle, needle_len, offset, NULL, 0 /* f_ignore_case */, 1/* last */); if ( ret_pos >= 0 ) { RETURN_LONG(ret_pos); } else { RETURN_FALSE; } } /* }}} */ /* {{{ Find position of last occurrence of a string within another, ignoring case */ PHP_FUNCTION(grapheme_strripos) { char *haystack, *needle; size_t haystack_len, needle_len; zend_long loffset = 0; int32_t offset = 0; zend_long ret_pos; int is_ascii; if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|l", &haystack, &haystack_len, &needle, &needle_len, &loffset) == FAILURE) { RETURN_THROWS(); } if ( OUTSIDE_STRING(loffset, haystack_len) ) { zend_argument_value_error(3, "must be contained in argument #1 ($haystack)"); RETURN_THROWS(); } /* we checked that it will fit: */ offset = (int32_t) loffset; /* the offset is 'grapheme count offset' so it still might be invalid - we'll check it later */ is_ascii = grapheme_ascii_check((unsigned char *)haystack, haystack_len) >= 0; if ( is_ascii ) { char *needle_dup, *haystack_dup; needle_dup = estrndup(needle, needle_len); zend_str_tolower(needle_dup, needle_len); haystack_dup = estrndup(haystack, haystack_len); zend_str_tolower(haystack_dup, haystack_len); ret_pos = grapheme_strrpos_ascii(haystack_dup, haystack_len, needle_dup, needle_len, offset); efree(haystack_dup); efree(needle_dup); if ( ret_pos >= 0 ) { RETURN_LONG(ret_pos); } /* if the needle was ascii too, we are done */ if ( grapheme_ascii_check((unsigned char *)needle, needle_len) >= 0 ) { RETURN_FALSE; } /* else we need to continue via utf16 */ } ret_pos = grapheme_strpos_utf16(haystack, haystack_len, needle, needle_len, offset, NULL, 1 /* f_ignore_case */, 1 /*last */); if ( ret_pos >= 0 ) { RETURN_LONG(ret_pos); } else { RETURN_FALSE; } } /* }}} */ /* {{{ Returns part of a string */ PHP_FUNCTION(grapheme_substr) { char *str; zend_string *u8_sub_str; UChar *ustr; size_t str_len; int32_t ustr_len; zend_long lstart = 0, length = 0; int32_t start = 0; int iter_val; UErrorCode status; unsigned char u_break_iterator_buffer[U_BRK_SAFECLONE_BUFFERSIZE]; UBreakIterator* bi = NULL; int sub_str_start_pos, sub_str_end_pos; int32_t (*iter_func)(UBreakIterator *); bool no_length = 1; if (zend_parse_parameters(ZEND_NUM_ARGS(), "sl|l!", &str, &str_len, &lstart, &length, &no_length) == FAILURE) { RETURN_THROWS(); } if (lstart < INT32_MIN || lstart > INT32_MAX) { zend_argument_value_error(2, "is too large"); RETURN_THROWS(); } start = (int32_t) lstart; if (no_length) { length = str_len; } if (length < INT32_MIN || length > INT32_MAX) { zend_argument_value_error(3, "is too large"); RETURN_THROWS(); } /* the offset is 'grapheme count offset' so it still might be invalid - we'll check it later */ if ( grapheme_ascii_check((unsigned char *)str, str_len) >= 0 ) { int32_t asub_str_len; char *sub_str; grapheme_substr_ascii(str, str_len, start, (int32_t)length, &sub_str, &asub_str_len); if ( NULL == sub_str ) { intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "grapheme_substr: invalid parameters", 1 ); RETURN_FALSE; } RETURN_STRINGL(sub_str, asub_str_len); } ustr = NULL; ustr_len = 0; status = U_ZERO_ERROR; intl_convert_utf8_to_utf16(&ustr, &ustr_len, str, str_len, &status); if ( U_FAILURE( status ) ) { /* Set global error code. */ intl_error_set_code( NULL, status ); /* Set error messages. */ intl_error_set_custom_msg( NULL, "Error converting input string to UTF-16", 0 ); if (ustr) { efree( ustr ); } RETURN_FALSE; } bi = grapheme_get_break_iterator((void*)u_break_iterator_buffer, &status ); if( U_FAILURE(status) ) { RETURN_FALSE; } ubrk_setText(bi, ustr, ustr_len, &status); if ( start < 0 ) { iter_func = ubrk_previous; ubrk_last(bi); iter_val = 1; } else { iter_func = ubrk_next; iter_val = -1; } sub_str_start_pos = 0; while ( start ) { sub_str_start_pos = iter_func(bi); if ( UBRK_DONE == sub_str_start_pos ) { break; } start += iter_val; } if (0 != start) { if (start > 0) { if (ustr) { efree(ustr); } ubrk_close(bi); RETURN_EMPTY_STRING(); } sub_str_start_pos = 0; ubrk_first(bi); } /* OK to convert here since if str_len were big, convert above would fail */ if (length >= (int32_t)str_len) { /* no length supplied or length is too big, return the rest of the string */ status = U_ZERO_ERROR; u8_sub_str = intl_convert_utf16_to_utf8(ustr + sub_str_start_pos, ustr_len - sub_str_start_pos, &status); if (ustr) { efree( ustr ); } ubrk_close( bi ); if ( !u8_sub_str ) { /* Set global error code. */ intl_error_set_code( NULL, status ); /* Set error messages. */ intl_error_set_custom_msg( NULL, "Error converting output string to UTF-8", 0 ); RETURN_FALSE; } /* return the allocated string, not a duplicate */ RETVAL_NEW_STR(u8_sub_str); return; } if(length == 0) { /* empty length - we've validated start, we can return "" now */ if (ustr) { efree(ustr); } ubrk_close(bi); RETURN_EMPTY_STRING(); } /* find the end point of the string to return */ if ( length < 0 ) { iter_func = ubrk_previous; ubrk_last(bi); iter_val = 1; } else { iter_func = ubrk_next; iter_val = -1; } sub_str_end_pos = 0; while ( length ) { sub_str_end_pos = iter_func(bi); if ( UBRK_DONE == sub_str_end_pos ) { break; } length += iter_val; } ubrk_close(bi); if ( UBRK_DONE == sub_str_end_pos) { if (length < 0) { efree(ustr); RETURN_EMPTY_STRING(); } else { sub_str_end_pos = ustr_len; } } if (sub_str_start_pos > sub_str_end_pos) { efree(ustr); RETURN_EMPTY_STRING(); } status = U_ZERO_ERROR; u8_sub_str = intl_convert_utf16_to_utf8(ustr + sub_str_start_pos, ( sub_str_end_pos - sub_str_start_pos ), &status); efree( ustr ); if ( !u8_sub_str ) { /* Set global error code. */ intl_error_set_code( NULL, status ); /* Set error messages. */ intl_error_set_custom_msg( NULL, "Error converting output string to UTF-8", 0 ); RETURN_FALSE; } /* return the allocated string, not a duplicate */ RETVAL_NEW_STR(u8_sub_str); } /* }}} */ /* {{{ strstr_common_handler */ static void strstr_common_handler(INTERNAL_FUNCTION_PARAMETERS, int f_ignore_case) { char *haystack, *needle; const char *found; size_t haystack_len, needle_len; int32_t ret_pos, uchar_pos; bool part = 0; if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|b", &haystack, &haystack_len, &needle, &needle_len, &part) == FAILURE) { RETURN_THROWS(); } if ( !f_ignore_case ) { /* ASCII optimization: quick check to see if the string might be there */ found = php_memnstr(haystack, needle, needle_len, haystack + haystack_len); /* if it isn't there the we are done */ if ( !found ) { RETURN_FALSE; } /* if it is there, and if the haystack is ascii, we are all done */ if ( grapheme_ascii_check((unsigned char *)haystack, haystack_len) >= 0 ) { size_t found_offset = found - haystack; if (part) { RETURN_STRINGL(haystack, found_offset); } else { RETURN_STRINGL(found, haystack_len - found_offset); } } } /* need to work in utf16 */ ret_pos = grapheme_strpos_utf16(haystack, haystack_len, needle, needle_len, 0, &uchar_pos, f_ignore_case, 0 /*last */ ); if ( ret_pos < 0 ) { RETURN_FALSE; } /* uchar_pos is the 'nth' Unicode character position of the needle */ ret_pos = 0; U8_FWD_N(haystack, ret_pos, haystack_len, uchar_pos); if (part) { RETURN_STRINGL(haystack, ret_pos); } else { RETURN_STRINGL(haystack + ret_pos, haystack_len - ret_pos); } } /* }}} */ /* {{{ Finds first occurrence of a string within another */ PHP_FUNCTION(grapheme_strstr) { strstr_common_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0 /* f_ignore_case */); } /* }}} */ /* {{{ Finds first occurrence of a string within another */ PHP_FUNCTION(grapheme_stristr) { strstr_common_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1 /* f_ignore_case */); } /* }}} */ /* {{{ grapheme_extract_charcount_iter - grapheme iterator for grapheme_extract MAXCHARS */ static inline int32_t grapheme_extract_charcount_iter(UBreakIterator *bi, int32_t csize, unsigned char *pstr, int32_t str_len) { int pos = 0; int ret_pos = 0; int break_pos, prev_break_pos; int count = 0; while ( 1 ) { pos = ubrk_next(bi); if ( UBRK_DONE == pos ) { break; } for ( break_pos = ret_pos; break_pos < pos; ) { count++; prev_break_pos = break_pos; U8_FWD_1(pstr, break_pos, str_len); if ( prev_break_pos == break_pos ) { /* something wrong - malformed utf8? */ csize = 0; break; } } /* if we are beyond our limit, then the loop is done */ if ( count > csize ) { break; } ret_pos = break_pos; } return ret_pos; } /* }}} */ /* {{{ grapheme_extract_bytecount_iter - grapheme iterator for grapheme_extract MAXBYTES */ static inline int32_t grapheme_extract_bytecount_iter(UBreakIterator *bi, int32_t bsize, unsigned char *pstr, int32_t str_len) { int pos = 0; int ret_pos = 0; while ( 1 ) { pos = ubrk_next(bi); if ( UBRK_DONE == pos ) { break; } if ( pos > bsize ) { break; } ret_pos = pos; } return ret_pos; } /* }}} */ /* {{{ grapheme_extract_count_iter - grapheme iterator for grapheme_extract COUNT */ static inline int32_t grapheme_extract_count_iter(UBreakIterator *bi, int32_t size, unsigned char *pstr, int32_t str_len) { int next_pos = 0; int ret_pos = 0; while ( size ) { next_pos = ubrk_next(bi); if ( UBRK_DONE == next_pos ) { break; } ret_pos = next_pos; size--; } return ret_pos; } /* }}} */ /* {{{ grapheme extract iter function pointer array */ typedef int32_t (*grapheme_extract_iter)(UBreakIterator * /*bi*/, int32_t /*size*/, unsigned char * /*pstr*/, int32_t /*str_len*/); static const grapheme_extract_iter grapheme_extract_iters[] = { &grapheme_extract_count_iter, &grapheme_extract_bytecount_iter, &grapheme_extract_charcount_iter, }; /* }}} */ /* {{{ Function to extract a sequence of default grapheme clusters */ PHP_FUNCTION(grapheme_extract) { char *str, *pstr; UText ut = UTEXT_INITIALIZER; size_t str_len; zend_long size; /* maximum number of grapheme clusters, bytes, or characters (based on extract_type) to return */ zend_long lstart = 0; /* starting position in str in bytes */ int32_t start = 0; zend_long extract_type = GRAPHEME_EXTRACT_TYPE_COUNT; UErrorCode status; unsigned char u_break_iterator_buffer[U_BRK_SAFECLONE_BUFFERSIZE]; UBreakIterator* bi = NULL; int ret_pos; zval *next = NULL; /* return offset of next part of the string */ if (zend_parse_parameters(ZEND_NUM_ARGS(), "sl|llz", &str, &str_len, &size, &extract_type, &lstart, &next) == FAILURE) { RETURN_THROWS(); } if (lstart < 0) { lstart += str_len; } if ( NULL != next ) { if ( !Z_ISREF_P(next) ) { intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "grapheme_extract: 'next' was not passed by reference", 0 ); RETURN_FALSE; } else { ZVAL_DEREF(next); /* initialize next */ zval_ptr_dtor(next); ZVAL_LONG(next, lstart); } } if ( extract_type < GRAPHEME_EXTRACT_TYPE_MIN || extract_type > GRAPHEME_EXTRACT_TYPE_MAX ) { zend_argument_value_error(3, "must be one of GRAPHEME_EXTR_COUNT, GRAPHEME_EXTR_MAXBYTES, or GRAPHEME_EXTR_MAXCHARS"); RETURN_THROWS(); } if ( lstart > INT32_MAX || lstart < 0 || (size_t)lstart >= str_len ) { intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "grapheme_extract: start not contained in string", 0 ); RETURN_FALSE; } if (size < 0) { zend_argument_value_error(2, "must be greater than or equal to 0"); RETURN_THROWS(); } if (size > INT32_MAX) { zend_argument_value_error(2, "is too large"); RETURN_THROWS(); } if (size == 0) { RETURN_EMPTY_STRING(); } /* we checked that it will fit: */ start = (int32_t) lstart; pstr = str + start; /* just in case pstr points in the middle of a character, move forward to the start of the next char */ if ( !U8_IS_SINGLE(*pstr) && !U8_IS_LEAD(*pstr) ) { char *str_end = str + str_len; while ( !U8_IS_SINGLE(*pstr) && !U8_IS_LEAD(*pstr) ) { pstr++; if ( pstr >= str_end ) { intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "grapheme_extract: invalid input string", 0 ); RETURN_FALSE; } } } str_len -= (pstr - str); /* if the string is all ASCII up to size+1 - or str_len whichever is first - then we are done. (size + 1 because the size-th character might be the beginning of a grapheme cluster) */ if ( -1 != grapheme_ascii_check((unsigned char *)pstr, MIN(size + 1, str_len)) ) { size_t nsize = MIN(size, str_len); if ( NULL != next ) { ZVAL_LONG(next, start+nsize); } RETURN_STRINGL(pstr, nsize); } status = U_ZERO_ERROR; utext_openUTF8(&ut, pstr, str_len, &status); if ( U_FAILURE( status ) ) { /* Set global error code. */ intl_error_set_code( NULL, status ); /* Set error messages. */ intl_error_set_custom_msg( NULL, "Error opening UTF-8 text", 0 ); RETURN_FALSE; } bi = NULL; status = U_ZERO_ERROR; bi = grapheme_get_break_iterator(u_break_iterator_buffer, &status ); ubrk_setUText(bi, &ut, &status); /* if the caller put us in the middle of a grapheme, we can't detect it in all cases since we can't back up. So, we will not do anything. */ /* now we need to find the end of the chunk the user wants us to return */ /* it's ok to convert str_len to in32_t since if it were too big intl_convert_utf8_to_utf16 above would fail */ ret_pos = (*grapheme_extract_iters[extract_type])(bi, size, (unsigned char *)pstr, (int32_t)str_len); utext_close(&ut); ubrk_close(bi); if ( NULL != next ) { ZVAL_LONG(next, start+ret_pos); } RETURN_STRINGL(((char *)pstr), ret_pos); } /* }}} */
20,448
23.937805
131
c
php-src
php-src-master/ext/intl/idn/idn.c
/* +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: Pierre A. Joye <[email protected]> | | Gustavo Lopes <[email protected]> | +----------------------------------------------------------------------+ */ /* {{{ includes */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include <php.h> #include <unicode/uidna.h> #include <unicode/ustring.h> #include "ext/standard/php_string.h" #include "idn.h" #include "intl_error.h" #include "intl_convert.h" /* }}} */ enum { INTL_IDN_TO_ASCII = 0, INTL_IDN_TO_UTF8 }; /* like INTL_CHECK_STATUS, but as a function and varying the name of the func */ static int php_intl_idn_check_status(UErrorCode err, const char *msg) { intl_error_set_code(NULL, err); if (U_FAILURE(err)) { char *buff; spprintf(&buff, 0, "%s: %s", get_active_function_name(), msg); intl_error_set_custom_msg(NULL, buff, 1); efree(buff); return FAILURE; } return SUCCESS; } static inline void php_intl_bad_args(const char *msg) { php_intl_idn_check_status(U_ILLEGAL_ARGUMENT_ERROR, msg); } static void php_intl_idn_to_46(INTERNAL_FUNCTION_PARAMETERS, const zend_string *domain, uint32_t option, int mode, zval *idna_info) { UErrorCode status = U_ZERO_ERROR; UIDNA *uts46; int32_t len; zend_string *buffer; UIDNAInfo info = UIDNA_INFO_INITIALIZER; uts46 = uidna_openUTS46(option, &status); if (php_intl_idn_check_status(status, "failed to open UIDNA instance") == FAILURE) { RETURN_FALSE; } if (mode == INTL_IDN_TO_ASCII) { const int32_t buffer_capac = 255; buffer = zend_string_alloc(buffer_capac, 0); len = uidna_nameToASCII_UTF8(uts46, ZSTR_VAL(domain), ZSTR_LEN(domain), ZSTR_VAL(buffer), buffer_capac, &info, &status); if (len >= buffer_capac || php_intl_idn_check_status(status, "failed to convert name") == FAILURE) { uidna_close(uts46); zend_string_efree(buffer); RETURN_FALSE; } } else { const int32_t buffer_capac = 252*4; buffer = zend_string_alloc(buffer_capac, 0); len = uidna_nameToUnicodeUTF8(uts46, ZSTR_VAL(domain), ZSTR_LEN(domain), ZSTR_VAL(buffer), buffer_capac, &info, &status); if (len >= buffer_capac || php_intl_idn_check_status(status, "failed to convert name") == FAILURE) { uidna_close(uts46); zend_string_efree(buffer); RETURN_FALSE; } } ZSTR_VAL(buffer)[len] = '\0'; ZSTR_LEN(buffer) = len; if (info.errors == 0) { RETVAL_STR_COPY(buffer); } else { RETVAL_FALSE; } if (idna_info) { add_assoc_str_ex(idna_info, "result", sizeof("result")-1, zend_string_copy(buffer)); add_assoc_bool_ex(idna_info, "isTransitionalDifferent", sizeof("isTransitionalDifferent")-1, info.isTransitionalDifferent); add_assoc_long_ex(idna_info, "errors", sizeof("errors")-1, (zend_long)info.errors); } zend_string_release(buffer); uidna_close(uts46); } static void php_intl_idn_handoff(INTERNAL_FUNCTION_PARAMETERS, int mode) { zend_string *domain; zend_long option = UIDNA_DEFAULT, variant = INTL_IDN_VARIANT_UTS46; zval *idna_info = NULL; intl_error_reset(NULL); if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|llz", &domain, &option, &variant, &idna_info) == FAILURE) { RETURN_THROWS(); } if (variant != INTL_IDN_VARIANT_UTS46) { php_intl_bad_args("invalid variant, must be INTL_IDNA_VARIANT_UTS46"); RETURN_FALSE; } if (ZSTR_LEN(domain) < 1) { php_intl_bad_args("empty domain name"); RETURN_FALSE; } if (ZSTR_LEN(domain) > INT32_MAX - 1) { php_intl_bad_args("domain name too large"); RETURN_FALSE; } /* don't check options; it wasn't checked before */ if (idna_info != NULL) { idna_info = zend_try_array_init(idna_info); if (!idna_info) { RETURN_THROWS(); } } php_intl_idn_to_46(INTERNAL_FUNCTION_PARAM_PASSTHRU, domain, (uint32_t)option, mode, idna_info); } /* {{{ Converts an Unicode domain to ASCII representation, as defined in the IDNA RFC */ PHP_FUNCTION(idn_to_ascii) { php_intl_idn_handoff(INTERNAL_FUNCTION_PARAM_PASSTHRU, INTL_IDN_TO_ASCII); } /* }}} */ /* {{{ Converts an ASCII representation of the domain to Unicode (UTF-8), as defined in the IDNA RFC */ PHP_FUNCTION(idn_to_utf8) { php_intl_idn_handoff(INTERNAL_FUNCTION_PARAM_PASSTHRU, INTL_IDN_TO_UTF8); } /* }}} */
5,050
28.711765
103
c
php-src
php-src-master/ext/intl/idn/idn.h
/* +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: Pierre A. Joye <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef IDN_IDN_H #define IDN_IDN_H #include <php.h> enum { INTL_IDN_VARIANT_UTS46 = 1 }; #endif /* IDN_IDN_H */
1,113
40.259259
75
h
php-src
php-src-master/ext/intl/locale/locale.c
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: Kirti Velankar <[email protected]> | +----------------------------------------------------------------------+ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "locale_class.h" #include "locale.h" #include <unicode/utypes.h> #include <unicode/uloc.h> #include <unicode/ustring.h>
1,022
39.92
75
c
php-src
php-src-master/ext/intl/locale/locale.h
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Kirti Velankar <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef LOCALE_LOCALE_H #define LOCALE_LOCALE_H #include <php.h> #define OPTION_DEFAULT NULL #define LOC_LANG_TAG "language" #define LOC_SCRIPT_TAG "script" #define LOC_REGION_TAG "region" #define LOC_VARIANT_TAG "variant" #define LOC_EXTLANG_TAG "extlang" #define LOC_GRANDFATHERED_LANG_TAG "grandfathered" #define LOC_PRIVATE_TAG "private" #define LOC_CANONICALIZE_TAG "canonicalize" #define LOCALE_INI_NAME "intl.default_locale" #endif // LOCALE_LOCALE_H
1,305
38.575758
75
h
php-src
php-src-master/ext/intl/locale/locale_class.c
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Kirti Velankar <[email protected]> | +----------------------------------------------------------------------+ */ #include <unicode/uloc.h> #include "php_intl.h" #include "intl_error.h" #include "locale_class.h" #include "locale.h" #include "locale_arginfo.h" zend_class_entry *Locale_ce_ptr = NULL; /* * 'Locale' class registration structures & functions */ /* {{{ locale_register_Locale_class * Initialize 'Locale' class */ void locale_register_Locale_class( void ) { /* Create and register 'Locale' class. */ Locale_ce_ptr = register_class_Locale(); Locale_ce_ptr->create_object = NULL; } /* }}} */
1,341
34.315789
75
c
php-src
php-src-master/ext/intl/locale/locale_class.h
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Kirti Velankar <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef LOCALE_CLASS_H #define LOCALE_CLASS_H #include <php.h> #include "intl_common.h" #include "intl_error.h" #include <unicode/uloc.h> typedef struct { zend_object zo; // ICU locale char* uloc1; } Locale_object; void locale_register_Locale_class( void ); extern zend_class_entry *Locale_ce_ptr; /* Auxiliary macros */ #define LOCALE_METHOD_INIT_VARS \ zval* object = NULL; \ intl_error_reset( NULL ); \ #endif // #ifndef LOCALE_CLASS_H
1,338
28.755556
75
h
php-src
php-src-master/ext/intl/msgformat/msgformat.c
/* +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | https://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Stanislav Malyshev <[email protected]> | +----------------------------------------------------------------------+ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include <unicode/ustring.h> #include <unicode/umsg.h> #include "php_intl.h" #include "msgformat_class.h" #include "msgformat_data.h" #include "intl_convert.h" /* {{{ */ static int msgfmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_error_handling *error_handling, bool *error_handling_replaced) { const char* locale; char* pattern; size_t locale_len = 0, pattern_len = 0; UChar* spattern = NULL; int spattern_len = 0; zval* object; MessageFormatter_object* mfo; UParseError parse_error; intl_error_reset( NULL ); object = return_value; /* Parse parameters. */ if( zend_parse_parameters( ZEND_NUM_ARGS(), "ss", &locale, &locale_len, &pattern, &pattern_len ) == FAILURE ) { return FAILURE; } if (error_handling != NULL) { zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, error_handling); *error_handling_replaced = 1; } INTL_CHECK_LOCALE_LEN_OR_FAILURE(locale_len); MSG_FORMAT_METHOD_FETCH_OBJECT_NO_CHECK; /* Convert pattern (if specified) to UTF-16. */ if(pattern && pattern_len) { intl_convert_utf8_to_utf16(&spattern, &spattern_len, pattern, pattern_len, &INTL_DATA_ERROR_CODE(mfo)); INTL_CTOR_CHECK_STATUS(mfo, "msgfmt_create: error converting pattern to UTF-16"); } else { spattern_len = 0; spattern = NULL; } if(locale_len == 0) { locale = intl_locale_get_default(); } #ifdef MSG_FORMAT_QUOTE_APOS if(msgformat_fix_quotes(&spattern, &spattern_len, &INTL_DATA_ERROR_CODE(mfo)) != SUCCESS) { INTL_CTOR_CHECK_STATUS(mfo, "msgfmt_create: error converting pattern to quote-friendly format"); } #endif if ((mfo)->mf_data.orig_format) { msgformat_data_free(&mfo->mf_data); } (mfo)->mf_data.orig_format = estrndup(pattern, pattern_len); (mfo)->mf_data.orig_format_len = pattern_len; /* Create an ICU message formatter. */ MSG_FORMAT_OBJECT(mfo) = umsg_open(spattern, spattern_len, locale, &parse_error, &INTL_DATA_ERROR_CODE(mfo)); if(spattern) { efree(spattern); } if (INTL_DATA_ERROR_CODE( mfo ) == U_PATTERN_SYNTAX_ERROR) { char *msg = NULL; smart_str parse_error_str; parse_error_str = intl_parse_error_to_string( &parse_error ); spprintf( &msg, 0, "pattern syntax error (%s)", parse_error_str.s? ZSTR_VAL(parse_error_str.s) : "unknown parser error" ); smart_str_free( &parse_error_str ); intl_error_set_code( NULL, INTL_DATA_ERROR_CODE( mfo ) ); intl_errors_set_custom_msg( INTL_DATA_ERROR_P( mfo ), msg, 1 ); efree( msg ); return FAILURE; } INTL_CTOR_CHECK_STATUS(mfo, "msgfmt_create: message formatter creation failed"); return SUCCESS; } /* }}} */ /* {{{ Create formatter. */ PHP_FUNCTION( msgfmt_create ) { object_init_ex( return_value, MessageFormatter_ce_ptr ); if (msgfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, NULL, NULL) == FAILURE) { zval_ptr_dtor(return_value); RETURN_NULL(); } } /* }}} */ /* {{{ MessageFormatter object constructor. */ PHP_METHOD( MessageFormatter, __construct ) { zend_error_handling error_handling; bool error_handling_replaced = 0; return_value = ZEND_THIS; if (msgfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, &error_handling, &error_handling_replaced) == FAILURE) { if (!EG(exception)) { zend_string *err = intl_error_get_message(NULL); zend_throw_exception(IntlException_ce_ptr, ZSTR_VAL(err), intl_error_get_code(NULL)); zend_string_release_ex(err, 0); } } if (error_handling_replaced) { zend_restore_error_handling(&error_handling); } } /* }}} */ /* {{{ Get formatter's last error code. */ PHP_FUNCTION( msgfmt_get_error_code ) { zval* object = NULL; MessageFormatter_object* mfo = NULL; /* Parse parameters. */ if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "O", &object, MessageFormatter_ce_ptr ) == FAILURE ) { RETURN_THROWS(); } mfo = Z_INTL_MESSAGEFORMATTER_P( object ); /* Return formatter's last error code. */ RETURN_LONG( INTL_DATA_ERROR_CODE(mfo) ); } /* }}} */ /* {{{ Get text description for formatter's last error code. */ PHP_FUNCTION( msgfmt_get_error_message ) { zend_string* message = NULL; zval* object = NULL; MessageFormatter_object* mfo = NULL; /* Parse parameters. */ if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "O", &object, MessageFormatter_ce_ptr ) == FAILURE ) { RETURN_THROWS(); } mfo = Z_INTL_MESSAGEFORMATTER_P( object ); /* Return last error message. */ message = intl_error_get_message( &mfo->mf_data.error ); RETURN_STR(message); } /* }}} */
5,405
29.033333
124
c
php-src
php-src-master/ext/intl/msgformat/msgformat_arginfo.h
/* This is a generated file, edit the .stub.php file instead. * Stub hash: d595f5c582996ebb96ab39df8cb56c4cf6c8dfcf */ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_MessageFormatter___construct, 0, 0, 2) ZEND_ARG_TYPE_INFO(0, locale, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, pattern, IS_STRING, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_OBJ_INFO_EX(arginfo_class_MessageFormatter_create, 0, 2, MessageFormatter, 1) ZEND_ARG_TYPE_INFO(0, locale, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, pattern, IS_STRING, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_MASK_EX(arginfo_class_MessageFormatter_format, 0, 1, MAY_BE_STRING|MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, values, IS_ARRAY, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_MASK_EX(arginfo_class_MessageFormatter_formatMessage, 0, 3, MAY_BE_STRING|MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, locale, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, pattern, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, values, IS_ARRAY, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_MASK_EX(arginfo_class_MessageFormatter_parse, 0, 1, MAY_BE_ARRAY|MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_MASK_EX(arginfo_class_MessageFormatter_parseMessage, 0, 3, MAY_BE_ARRAY|MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, locale, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, pattern, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, message, IS_STRING, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_MessageFormatter_setPattern, 0, 1, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO(0, pattern, IS_STRING, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_MASK_EX(arginfo_class_MessageFormatter_getPattern, 0, 0, MAY_BE_STRING|MAY_BE_FALSE) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_MessageFormatter_getLocale, 0, 0, IS_STRING, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_MessageFormatter_getErrorCode, 0, 0, IS_LONG, 0) ZEND_END_ARG_INFO() #define arginfo_class_MessageFormatter_getErrorMessage arginfo_class_MessageFormatter_getLocale ZEND_METHOD(MessageFormatter, __construct); ZEND_FUNCTION(msgfmt_create); ZEND_FUNCTION(msgfmt_format); ZEND_FUNCTION(msgfmt_format_message); ZEND_FUNCTION(msgfmt_parse); ZEND_FUNCTION(msgfmt_parse_message); ZEND_FUNCTION(msgfmt_set_pattern); ZEND_FUNCTION(msgfmt_get_pattern); ZEND_FUNCTION(msgfmt_get_locale); ZEND_FUNCTION(msgfmt_get_error_code); ZEND_FUNCTION(msgfmt_get_error_message); static const zend_function_entry class_MessageFormatter_methods[] = { ZEND_ME(MessageFormatter, __construct, arginfo_class_MessageFormatter___construct, ZEND_ACC_PUBLIC) ZEND_ME_MAPPING(create, msgfmt_create, arginfo_class_MessageFormatter_create, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) ZEND_ME_MAPPING(format, msgfmt_format, arginfo_class_MessageFormatter_format, ZEND_ACC_PUBLIC) ZEND_ME_MAPPING(formatMessage, msgfmt_format_message, arginfo_class_MessageFormatter_formatMessage, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) ZEND_ME_MAPPING(parse, msgfmt_parse, arginfo_class_MessageFormatter_parse, ZEND_ACC_PUBLIC) ZEND_ME_MAPPING(parseMessage, msgfmt_parse_message, arginfo_class_MessageFormatter_parseMessage, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) ZEND_ME_MAPPING(setPattern, msgfmt_set_pattern, arginfo_class_MessageFormatter_setPattern, ZEND_ACC_PUBLIC) ZEND_ME_MAPPING(getPattern, msgfmt_get_pattern, arginfo_class_MessageFormatter_getPattern, ZEND_ACC_PUBLIC) ZEND_ME_MAPPING(getLocale, msgfmt_get_locale, arginfo_class_MessageFormatter_getLocale, ZEND_ACC_PUBLIC) ZEND_ME_MAPPING(getErrorCode, msgfmt_get_error_code, arginfo_class_MessageFormatter_getErrorCode, ZEND_ACC_PUBLIC) ZEND_ME_MAPPING(getErrorMessage, msgfmt_get_error_message, arginfo_class_MessageFormatter_getErrorMessage, ZEND_ACC_PUBLIC) ZEND_FE_END }; static zend_class_entry *register_class_MessageFormatter(void) { zend_class_entry ce, *class_entry; INIT_CLASS_ENTRY(ce, "MessageFormatter", class_MessageFormatter_methods); class_entry = zend_register_internal_class_ex(&ce, NULL); class_entry->ce_flags |= ZEND_ACC_NOT_SERIALIZABLE; return class_entry; }
4,200
46.738636
133
h