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/standard/crypt_sha256.c
/* SHA256-based Unix crypt implementation. Released into the Public Domain by Ulrich Drepper <[email protected]>. */ /* Windows VC++ port by Pierre Joye <[email protected]> */ #include "php.h" #include "php_main.h" #include <errno.h> #include <limits.h> #ifdef PHP_WIN32 # define __alignof__ __alignof #else # ifndef HAVE_ALIGNOF # include <stddef.h> # define __alignof__(type) offsetof (struct { char c; type member;}, member) # endif #endif #include <stdio.h> #include <stdlib.h> #ifdef PHP_WIN32 # include <string.h> #else # include <sys/param.h> # include <sys/types.h> # include <string.h> #endif char * __php_stpncpy(char *dst, const char *src, size_t len) { size_t n = strlen(src); if (n > len) { n = len; } return strncpy(dst, src, len) + n; } void * __php_mempcpy(void * dst, const void * src, size_t len) { return (((char *)memcpy(dst, src, len)) + len); } #ifndef MIN # define MIN(a, b) (((a) < (b)) ? (a) : (b)) #endif #ifndef MAX # define MAX(a, b) (((a) > (b)) ? (a) : (b)) #endif /* Structure to save state of computation between the single steps. */ struct sha256_ctx { uint32_t H[8]; uint32_t total[2]; uint32_t buflen; char buffer[128]; /* NB: always correctly aligned for uint32_t. */ }; #if defined(PHP_WIN32) || (!defined(WORDS_BIGENDIAN)) # define SWAP(n) \ (((n) << 24) | (((n) & 0xff00) << 8) | (((n) >> 8) & 0xff00) | ((n) >> 24)) #else # define SWAP(n) (n) #endif /* This array contains the bytes used to pad the buffer to the next 64-byte boundary. (FIPS 180-2:5.1.1) */ static const unsigned char fillbuf[64] = { 0x80, 0 /* , 0, 0, ... */ }; /* Constants for SHA256 from FIPS 180-2:4.2.2. */ static const uint32_t K[64] = { 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 }; /* Process LEN bytes of BUFFER, accumulating context into CTX. It is assumed that LEN % 64 == 0. */ static void sha256_process_block (const void *buffer, size_t len, struct sha256_ctx *ctx) { const uint32_t *words = buffer; size_t nwords = len / sizeof (uint32_t); unsigned int t; uint32_t a = ctx->H[0]; uint32_t b = ctx->H[1]; uint32_t c = ctx->H[2]; uint32_t d = ctx->H[3]; uint32_t e = ctx->H[4]; uint32_t f = ctx->H[5]; uint32_t g = ctx->H[6]; uint32_t h = ctx->H[7]; /* First increment the byte count. FIPS 180-2 specifies the possible length of the file up to 2^64 bits. Here we only compute the number of bytes. Do a double word increment. */ ctx->total[0] += (uint32_t)len; if (ctx->total[0] < len) { ++ctx->total[1]; } /* Process all bytes in the buffer with 64 bytes in each round of the loop. */ while (nwords > 0) { uint32_t W[64]; uint32_t a_save = a; uint32_t b_save = b; uint32_t c_save = c; uint32_t d_save = d; uint32_t e_save = e; uint32_t f_save = f; uint32_t g_save = g; uint32_t h_save = h; /* Operators defined in FIPS 180-2:4.1.2. */ #define Ch(x, y, z) ((x & y) ^ (~x & z)) #define Maj(x, y, z) ((x & y) ^ (x & z) ^ (y & z)) #define S0(x) (CYCLIC (x, 2) ^ CYCLIC (x, 13) ^ CYCLIC (x, 22)) #define S1(x) (CYCLIC (x, 6) ^ CYCLIC (x, 11) ^ CYCLIC (x, 25)) #define R0(x) (CYCLIC (x, 7) ^ CYCLIC (x, 18) ^ (x >> 3)) #define R1(x) (CYCLIC (x, 17) ^ CYCLIC (x, 19) ^ (x >> 10)) /* It is unfortunate that C does not provide an operator for cyclic rotation. Hope the C compiler is smart enough. */ #define CYCLIC(w, s) ((w >> s) | (w << (32 - s))) /* Compute the message schedule according to FIPS 180-2:6.2.2 step 2. */ for (t = 0; t < 16; ++t) { W[t] = SWAP (*words); ++words; } for (t = 16; t < 64; ++t) W[t] = R1 (W[t - 2]) + W[t - 7] + R0 (W[t - 15]) + W[t - 16]; /* The actual computation according to FIPS 180-2:6.2.2 step 3. */ for (t = 0; t < 64; ++t) { uint32_t T1 = h + S1 (e) + Ch (e, f, g) + K[t] + W[t]; uint32_t T2 = S0 (a) + Maj (a, b, c); h = g; g = f; f = e; e = d + T1; d = c; c = b; b = a; a = T1 + T2; } /* Add the starting values of the context according to FIPS 180-2:6.2.2 step 4. */ a += a_save; b += b_save; c += c_save; d += d_save; e += e_save; f += f_save; g += g_save; h += h_save; /* Prepare for the next round. */ nwords -= 16; } /* Put checksum in context given as argument. */ ctx->H[0] = a; ctx->H[1] = b; ctx->H[2] = c; ctx->H[3] = d; ctx->H[4] = e; ctx->H[5] = f; ctx->H[6] = g; ctx->H[7] = h; } /* Initialize structure containing state of computation. (FIPS 180-2:5.3.2) */ static void sha256_init_ctx(struct sha256_ctx *ctx) { ctx->H[0] = 0x6a09e667; ctx->H[1] = 0xbb67ae85; ctx->H[2] = 0x3c6ef372; ctx->H[3] = 0xa54ff53a; ctx->H[4] = 0x510e527f; ctx->H[5] = 0x9b05688c; ctx->H[6] = 0x1f83d9ab; ctx->H[7] = 0x5be0cd19; ctx->total[0] = ctx->total[1] = 0; ctx->buflen = 0; } /* Process the remaining bytes in the internal buffer and the usual prolog according to the standard and write the result to RESBUF. IMPORTANT: On some systems it is required that RESBUF is correctly aligned for a 32 bits value. */ static void * sha256_finish_ctx(struct sha256_ctx *ctx, void *resbuf) { /* Take yet unprocessed bytes into account. */ uint32_t bytes = ctx->buflen; size_t pad; unsigned int i; /* Now count remaining bytes. */ ctx->total[0] += bytes; if (ctx->total[0] < bytes) { ++ctx->total[1]; } pad = bytes >= 56 ? 64 + 56 - bytes : 56 - bytes; memcpy(&ctx->buffer[bytes], fillbuf, pad); /* Put the 64-bit file length in *bits* at the end of the buffer. */ *(uint32_t *) &ctx->buffer[bytes + pad + 4] = SWAP (ctx->total[0] << 3); *(uint32_t *) &ctx->buffer[bytes + pad] = SWAP ((ctx->total[1] << 3) | (ctx->total[0] >> 29)); /* Process last bytes. */ sha256_process_block(ctx->buffer, bytes + pad + 8, ctx); /* Put result from CTX in first 32 bytes following RESBUF. */ for (i = 0; i < 8; ++i) { ((uint32_t *) resbuf)[i] = SWAP(ctx->H[i]); } return resbuf; } static void sha256_process_bytes(const void *buffer, size_t len, struct sha256_ctx *ctx) { /* When we already have some bits in our internal buffer concatenate both inputs first. */ if (ctx->buflen != 0) { size_t left_over = ctx->buflen; size_t add = 128 - left_over > len ? len : 128 - left_over; memcpy(&ctx->buffer[left_over], buffer, add); ctx->buflen += (uint32_t)add; if (ctx->buflen > 64) { sha256_process_block(ctx->buffer, ctx->buflen & ~63, ctx); ctx->buflen &= 63; /* The regions in the following copy operation cannot overlap. */ memcpy(ctx->buffer, &ctx->buffer[(left_over + add) & ~63], ctx->buflen); } buffer = (const char *) buffer + add; len -= add; } /* Process available complete blocks. */ if (len >= 64) { /* To check alignment gcc has an appropriate operator. Other compilers don't. */ #if __GNUC__ >= 2 # define UNALIGNED_P(p) (((uintptr_t) p) % __alignof__ (uint32_t) != 0) #else # define UNALIGNED_P(p) (((uintptr_t) p) % sizeof (uint32_t) != 0) #endif if (UNALIGNED_P (buffer)) while (len > 64) { sha256_process_block(memcpy(ctx->buffer, buffer, 64), 64, ctx); buffer = (const char *) buffer + 64; len -= 64; } else { sha256_process_block(buffer, len & ~63, ctx); buffer = (const char *) buffer + (len & ~63); len &= 63; } } /* Move remaining bytes into internal buffer. */ if (len > 0) { size_t left_over = ctx->buflen; memcpy(&ctx->buffer[left_over], buffer, len); left_over += len; if (left_over >= 64) { sha256_process_block(ctx->buffer, 64, ctx); left_over -= 64; memcpy(ctx->buffer, &ctx->buffer[64], left_over); } ctx->buflen = (uint32_t)left_over; } } /* Define our magic string to mark salt for SHA256 "encryption" replacement. */ static const char sha256_salt_prefix[] = "$5$"; /* Prefix for optional rounds specification. */ static const char sha256_rounds_prefix[] = "rounds="; /* Maximum salt string length. */ #define SALT_LEN_MAX 16 /* Default number of rounds if not explicitly specified. */ #define ROUNDS_DEFAULT 5000 /* Minimum number of rounds. */ #define ROUNDS_MIN 1000 /* Maximum number of rounds. */ #define ROUNDS_MAX 999999999 /* Table with characters for base64 transformation. */ static const char b64t[64] = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; char * php_sha256_crypt_r(const char *key, const char *salt, char *buffer, int buflen) { #ifdef PHP_WIN32 ZEND_SET_ALIGNED(32, unsigned char alt_result[32]); ZEND_SET_ALIGNED(32, unsigned char temp_result[32]); #else ZEND_SET_ALIGNED(__alignof__ (uint32_t), unsigned char alt_result[32]); ZEND_SET_ALIGNED(__alignof__ (uint32_t), unsigned char temp_result[32]); #endif struct sha256_ctx ctx; struct sha256_ctx alt_ctx; size_t salt_len; size_t key_len; size_t cnt; char *cp; char *copied_key = NULL; char *copied_salt = NULL; char *p_bytes; char *s_bytes; /* Default number of rounds. */ size_t rounds = ROUNDS_DEFAULT; bool rounds_custom = 0; /* Find beginning of salt string. The prefix should normally always be present. Just in case it is not. */ if (strncmp(sha256_salt_prefix, salt, sizeof(sha256_salt_prefix) - 1) == 0) { /* Skip salt prefix. */ salt += sizeof(sha256_salt_prefix) - 1; } if (strncmp(salt, sha256_rounds_prefix, sizeof(sha256_rounds_prefix) - 1) == 0) { const char *num = salt + sizeof(sha256_rounds_prefix) - 1; char *endp; zend_ulong srounds = ZEND_STRTOUL(num, &endp, 10); if (*endp == '$') { salt = endp + 1; if (srounds < ROUNDS_MIN || srounds > ROUNDS_MAX) { return NULL; } rounds = srounds; rounds_custom = 1; } } salt_len = MIN(strcspn(salt, "$"), SALT_LEN_MAX); key_len = strlen(key); char *tmp_key = NULL; ALLOCA_FLAG(use_heap_key); char *tmp_salt = NULL; ALLOCA_FLAG(use_heap_salt); SET_ALLOCA_FLAG(use_heap_key); SET_ALLOCA_FLAG(use_heap_salt); if ((uintptr_t)key % __alignof__ (uint32_t) != 0) { tmp_key = (char *) do_alloca(key_len + __alignof__(uint32_t), use_heap_key); key = copied_key = memcpy(tmp_key + __alignof__(uint32_t) - (uintptr_t)tmp_key % __alignof__(uint32_t), key, key_len); } if ((uintptr_t)salt % __alignof__(uint32_t) != 0) { tmp_salt = (char *) do_alloca(salt_len + 1 + __alignof__(uint32_t), use_heap_salt); salt = copied_salt = memcpy(tmp_salt + __alignof__(uint32_t) - (uintptr_t)tmp_salt % __alignof__ (uint32_t), salt, salt_len); copied_salt[salt_len] = 0; } /* Prepare for the real work. */ sha256_init_ctx(&ctx); /* Add the key string. */ sha256_process_bytes(key, key_len, &ctx); /* The last part is the salt string. This must be at most 16 characters and it ends at the first `$' character (for compatibility with existing implementations). */ sha256_process_bytes(salt, salt_len, &ctx); /* Compute alternate SHA256 sum with input KEY, SALT, and KEY. The final result will be added to the first context. */ sha256_init_ctx(&alt_ctx); /* Add key. */ sha256_process_bytes(key, key_len, &alt_ctx); /* Add salt. */ sha256_process_bytes(salt, salt_len, &alt_ctx); /* Add key again. */ sha256_process_bytes(key, key_len, &alt_ctx); /* Now get result of this (32 bytes) and add it to the other context. */ sha256_finish_ctx(&alt_ctx, alt_result); /* Add for any character in the key one byte of the alternate sum. */ for (cnt = key_len; cnt > 32; cnt -= 32) { sha256_process_bytes(alt_result, 32, &ctx); } sha256_process_bytes(alt_result, cnt, &ctx); /* Take the binary representation of the length of the key and for every 1 add the alternate sum, for every 0 the key. */ for (cnt = key_len; cnt > 0; cnt >>= 1) { if ((cnt & 1) != 0) { sha256_process_bytes(alt_result, 32, &ctx); } else { sha256_process_bytes(key, key_len, &ctx); } } /* Create intermediate result. */ sha256_finish_ctx(&ctx, alt_result); /* Start computation of P byte sequence. */ sha256_init_ctx(&alt_ctx); /* For every character in the password add the entire password. */ for (cnt = 0; cnt < key_len; ++cnt) { sha256_process_bytes(key, key_len, &alt_ctx); } /* Finish the digest. */ sha256_finish_ctx(&alt_ctx, temp_result); /* Create byte sequence P. */ ALLOCA_FLAG(use_heap_p_bytes); cp = p_bytes = do_alloca(key_len, use_heap_p_bytes); for (cnt = key_len; cnt >= 32; cnt -= 32) { cp = __php_mempcpy((void *)cp, (const void *)temp_result, 32); } memcpy(cp, temp_result, cnt); /* Start computation of S byte sequence. */ sha256_init_ctx(&alt_ctx); /* For every character in the password add the entire password. */ for (cnt = 0; cnt < (size_t) (16 + alt_result[0]); ++cnt) { sha256_process_bytes(salt, salt_len, &alt_ctx); } /* Finish the digest. */ sha256_finish_ctx(&alt_ctx, temp_result); /* Create byte sequence S. */ ALLOCA_FLAG(use_heap_s_bytes); cp = s_bytes = do_alloca(salt_len, use_heap_s_bytes); for (cnt = salt_len; cnt >= 32; cnt -= 32) { cp = __php_mempcpy(cp, temp_result, 32); } memcpy(cp, temp_result, cnt); /* Repeatedly run the collected hash value through SHA256 to burn CPU cycles. */ for (cnt = 0; cnt < rounds; ++cnt) { /* New context. */ sha256_init_ctx(&ctx); /* Add key or last result. */ if ((cnt & 1) != 0) { sha256_process_bytes(p_bytes, key_len, &ctx); } else { sha256_process_bytes(alt_result, 32, &ctx); } /* Add salt for numbers not divisible by 3. */ if (cnt % 3 != 0) { sha256_process_bytes(s_bytes, salt_len, &ctx); } /* Add key for numbers not divisible by 7. */ if (cnt % 7 != 0) { sha256_process_bytes(p_bytes, key_len, &ctx); } /* Add key or last result. */ if ((cnt & 1) != 0) { sha256_process_bytes(alt_result, 32, &ctx); } else { sha256_process_bytes(p_bytes, key_len, &ctx); } /* Create intermediate result. */ sha256_finish_ctx(&ctx, alt_result); } /* Now we can construct the result string. It consists of three parts. */ cp = __php_stpncpy(buffer, sha256_salt_prefix, MAX(0, buflen)); buflen -= sizeof(sha256_salt_prefix) - 1; if (rounds_custom) { #ifdef PHP_WIN32 int n = _snprintf(cp, MAX(0, buflen), "%s" ZEND_ULONG_FMT "$", sha256_rounds_prefix, rounds); #else int n = snprintf(cp, MAX(0, buflen), "%s%zu$", sha256_rounds_prefix, rounds); #endif cp += n; buflen -= n; } cp = __php_stpncpy(cp, salt, MIN ((size_t) MAX (0, buflen), salt_len)); buflen -= MIN(MAX (0, buflen), (int)salt_len); if (buflen > 0) { *cp++ = '$'; --buflen; } #define b64_from_24bit(B2, B1, B0, N) \ do { \ unsigned int w = ((B2) << 16) | ((B1) << 8) | (B0); \ int n = (N); \ while (n-- > 0 && buflen > 0) \ { \ *cp++ = b64t[w & 0x3f]; \ --buflen; \ w >>= 6; \ } \ } while (0) b64_from_24bit(alt_result[0], alt_result[10], alt_result[20], 4); b64_from_24bit(alt_result[21], alt_result[1], alt_result[11], 4); b64_from_24bit(alt_result[12], alt_result[22], alt_result[2], 4); b64_from_24bit(alt_result[3], alt_result[13], alt_result[23], 4); b64_from_24bit(alt_result[24], alt_result[4], alt_result[14], 4); b64_from_24bit(alt_result[15], alt_result[25], alt_result[5], 4); b64_from_24bit(alt_result[6], alt_result[16], alt_result[26], 4); b64_from_24bit(alt_result[27], alt_result[7], alt_result[17], 4); b64_from_24bit(alt_result[18], alt_result[28], alt_result[8], 4); b64_from_24bit(alt_result[9], alt_result[19], alt_result[29], 4); b64_from_24bit(0, alt_result[31], alt_result[30], 3); if (buflen <= 0) { errno = ERANGE; buffer = NULL; } else *cp = '\0'; /* Terminate the string. */ /* Clear the buffer for the intermediate result so that people attaching to processes or reading core dumps cannot get any information. We do it in this way to clear correct_words[] inside the SHA256 implementation as well. */ sha256_init_ctx(&ctx); sha256_finish_ctx(&ctx, alt_result); ZEND_SECURE_ZERO(temp_result, sizeof(temp_result)); ZEND_SECURE_ZERO(p_bytes, key_len); ZEND_SECURE_ZERO(s_bytes, salt_len); ZEND_SECURE_ZERO(&ctx, sizeof(ctx)); ZEND_SECURE_ZERO(&alt_ctx, sizeof(alt_ctx)); if (copied_key != NULL) { ZEND_SECURE_ZERO(copied_key, key_len); } if (copied_salt != NULL) { ZEND_SECURE_ZERO(copied_salt, salt_len); } if (tmp_key != NULL) { free_alloca(tmp_key, use_heap_key); } if (tmp_salt != NULL) { free_alloca(tmp_salt, use_heap_salt); } free_alloca(p_bytes, use_heap_p_bytes); free_alloca(s_bytes, use_heap_s_bytes); return buffer; } /* This entry point is equivalent to the `crypt' function in Unix libcs. */ char * php_sha256_crypt(const char *key, const char *salt) { /* We don't want to have an arbitrary limit in the size of the password. We can compute an upper bound for the size of the result in advance and so we can prepare the buffer we pass to `sha256_crypt_r'. */ ZEND_TLS char *buffer; ZEND_TLS int buflen = 0; int needed = (sizeof(sha256_salt_prefix) - 1 + sizeof(sha256_rounds_prefix) + 9 + 1 + (int)strlen(salt) + 1 + 43 + 1); if (buflen < needed) { char *new_buffer = (char *) realloc(buffer, needed); if (new_buffer == NULL) { return NULL; } buffer = new_buffer; buflen = needed; } return php_sha256_crypt_r(key, salt, buffer, buflen); } #ifdef TEST static const struct { const char *input; const char result[32]; } tests[] = { /* Test vectors from FIPS 180-2: appendix B.1. */ { "abc", "\xba\x78\x16\xbf\x8f\x01\xcf\xea\x41\x41\x40\xde\x5d\xae\x22\x23" "\xb0\x03\x61\xa3\x96\x17\x7a\x9c\xb4\x10\xff\x61\xf2\x00\x15\xad" }, /* Test vectors from FIPS 180-2: appendix B.2. */ { "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", "\x24\x8d\x6a\x61\xd2\x06\x38\xb8\xe5\xc0\x26\x93\x0c\x3e\x60\x39" "\xa3\x3c\xe4\x59\x64\xff\x21\x67\xf6\xec\xed\xd4\x19\xdb\x06\xc1" }, /* Test vectors from the NESSIE project. */ { "", "\xe3\xb0\xc4\x42\x98\xfc\x1c\x14\x9a\xfb\xf4\xc8\x99\x6f\xb9\x24" "\x27\xae\x41\xe4\x64\x9b\x93\x4c\xa4\x95\x99\x1b\x78\x52\xb8\x55" }, { "a", "\xca\x97\x81\x12\xca\x1b\xbd\xca\xfa\xc2\x31\xb3\x9a\x23\xdc\x4d" "\xa7\x86\xef\xf8\x14\x7c\x4e\x72\xb9\x80\x77\x85\xaf\xee\x48\xbb" }, { "message digest", "\xf7\x84\x6f\x55\xcf\x23\xe1\x4e\xeb\xea\xb5\xb4\xe1\x55\x0c\xad" "\x5b\x50\x9e\x33\x48\xfb\xc4\xef\xa3\xa1\x41\x3d\x39\x3c\xb6\x50" }, { "abcdefghijklmnopqrstuvwxyz", "\x71\xc4\x80\xdf\x93\xd6\xae\x2f\x1e\xfa\xd1\x44\x7c\x66\xc9\x52" "\x5e\x31\x62\x18\xcf\x51\xfc\x8d\x9e\xd8\x32\xf2\xda\xf1\x8b\x73" }, { "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", "\x24\x8d\x6a\x61\xd2\x06\x38\xb8\xe5\xc0\x26\x93\x0c\x3e\x60\x39" "\xa3\x3c\xe4\x59\x64\xff\x21\x67\xf6\xec\xed\xd4\x19\xdb\x06\xc1" }, { "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", "\xdb\x4b\xfc\xbd\x4d\xa0\xcd\x85\xa6\x0c\x3c\x37\xd3\xfb\xd8\x80" "\x5c\x77\xf1\x5f\xc6\xb1\xfd\xfe\x61\x4e\xe0\xa7\xc8\xfd\xb4\xc0" }, { "123456789012345678901234567890123456789012345678901234567890" "12345678901234567890", "\xf3\x71\xbc\x4a\x31\x1f\x2b\x00\x9e\xef\x95\x2d\xd8\x3c\xa8\x0e" "\x2b\x60\x02\x6c\x8e\x93\x55\x92\xd0\xf9\xc3\x08\x45\x3c\x81\x3e" } }; #define ntests (sizeof (tests) / sizeof (tests[0])) static const struct { const char *salt; const char *input; const char *expected; } tests2[] = { { "$5$saltstring", "Hello world!", "$5$saltstring$5B8vYYiY.CVt1RlTTf8KbXBH3hsxY/GNooZaBBGWEc5" }, { "$5$rounds=10000$saltstringsaltstring", "Hello world!", "$5$rounds=10000$saltstringsaltst$3xv.VbSHBb41AL9AvLeujZkZRBAwqFMz2." "opqey6IcA" }, { "$5$rounds=5000$toolongsaltstring", "This is just a test", "$5$rounds=5000$toolongsaltstrin$Un/5jzAHMgOGZ5.mWJpuVolil07guHPvOW8" "mGRcvxa5" }, { "$5$rounds=1400$anotherlongsaltstring", "a very much longer text to encrypt. This one even stretches over more" "than one line.", "$5$rounds=1400$anotherlongsalts$Rx.j8H.h8HjEDGomFU8bDkXm3XIUnzyxf12" "oP84Bnq1" }, { "$5$rounds=77777$short", "we have a short salt string but not a short password", "$5$rounds=77777$short$JiO1O3ZpDAxGJeaDIuqCoEFysAe1mZNJRs3pw0KQRd/" }, { "$5$rounds=123456$asaltof16chars..", "a short string", "$5$rounds=123456$asaltof16chars..$gP3VQ/6X7UUEW3HkBn2w1/Ptq2jxPyzV/" "cZKmF/wJvD" }, { "$5$rounds=10$roundstoolow", "the minimum number is still observed", "$5$rounds=1000$roundstoolow$yfvwcWrQ8l/K0DAWyuPMDNHpIVlTQebY9l/gL97" "2bIC" }, }; #define ntests2 (sizeof (tests2) / sizeof (tests2[0])) int main(void) { struct sha256_ctx ctx; char sum[32]; int result = 0; int cnt, i; char buf[1000]; static const char expected[32] = "\xcd\xc7\x6e\x5c\x99\x14\xfb\x92\x81\xa1\xc7\xe2\x84\xd7\x3e\x67" "\xf1\x80\x9a\x48\xa4\x97\x20\x0e\x04\x6d\x39\xcc\xc7\x11\x2c\xd0"; for (cnt = 0; cnt < (int) ntests; ++cnt) { sha256_init_ctx(&ctx); sha256_process_bytes(tests[cnt].input, strlen(tests[cnt].input), &ctx); sha256_finish_ctx(&ctx, sum); if (memcmp(tests[cnt].result, sum, 32) != 0) { printf("test %d run %d failed\n", cnt, 1); result = 1; } sha256_init_ctx(&ctx); for (i = 0; tests[cnt].input[i] != '\0'; ++i) { sha256_process_bytes(&tests[cnt].input[i], 1, &ctx); } sha256_finish_ctx(&ctx, sum); if (memcmp(tests[cnt].result, sum, 32) != 0) { printf("test %d run %d failed\n", cnt, 2); result = 1; } } /* Test vector from FIPS 180-2: appendix B.3. */ memset(buf, 'a', sizeof(buf)); sha256_init_ctx(&ctx); for (i = 0; i < 1000; ++i) { sha256_process_bytes (buf, sizeof (buf), &ctx); } sha256_finish_ctx(&ctx, sum); if (memcmp(expected, sum, 32) != 0) { printf("test %d failed\n", cnt); result = 1; } for (cnt = 0; cnt < ntests2; ++cnt) { char *cp = php_sha256_crypt(tests2[cnt].input, tests2[cnt].salt); if (strcmp(cp, tests2[cnt].expected) != 0) { printf("test %d: expected \"%s\", got \"%s\"\n", cnt, tests2[cnt].expected, cp); result = 1; } } if (result == 0) puts("all tests OK"); return result; } #endif
22,617
28.878468
120
c
php-src
php-src-master/ext/standard/css.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: Colin Viebrock <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef CSS_H #define CSS_H PHPAPI void php_info_print_css(void); #endif
1,070
45.565217
75
h
php-src
php-src-master/ext/standard/datetime.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: Andi Gutmans <[email protected]> | | Zeev Suraski <[email protected]> | | Rasmus Lerdorf <[email protected]> | +----------------------------------------------------------------------+ */ #include "php.h" #include "zend_operators.h" #include "datetime.h" #include "php_globals.h" #include <time.h> #ifdef HAVE_SYS_TIME_H # include <sys/time.h> #endif #include <stdio.h> static const char * const mon_short_names[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; static const char * const day_short_names[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; /* {{{ PHPAPI char *php_std_date(time_t t) Return date string in standard format for http headers */ PHPAPI char *php_std_date(time_t t) { struct tm *tm1, tmbuf; char *str; tm1 = php_gmtime_r(&t, &tmbuf); str = emalloc(81); str[0] = '\0'; if (!tm1) { return str; } snprintf(str, 80, "%s, %02d %s %04d %02d:%02d:%02d GMT", day_short_names[tm1->tm_wday], tm1->tm_mday, mon_short_names[tm1->tm_mon], tm1->tm_year + 1900, tm1->tm_hour, tm1->tm_min, tm1->tm_sec); str[79] = 0; return (str); } /* }}} */ #ifdef HAVE_STRPTIME #ifndef HAVE_STRPTIME_DECL_FAILS char *strptime(const char *s, const char *format, struct tm *tm); #endif /* {{{ Parse a time/date generated with strftime() */ PHP_FUNCTION(strptime) { char *ts; size_t ts_length; char *format; size_t format_length; struct tm parsed_time; char *unparsed_part; ZEND_PARSE_PARAMETERS_START(2, 2) Z_PARAM_STRING(ts, ts_length) Z_PARAM_STRING(format, format_length) ZEND_PARSE_PARAMETERS_END(); memset(&parsed_time, 0, sizeof(parsed_time)); unparsed_part = strptime(ts, format, &parsed_time); if (unparsed_part == NULL) { RETURN_FALSE; } array_init(return_value); add_assoc_long(return_value, "tm_sec", parsed_time.tm_sec); add_assoc_long(return_value, "tm_min", parsed_time.tm_min); add_assoc_long(return_value, "tm_hour", parsed_time.tm_hour); add_assoc_long(return_value, "tm_mday", parsed_time.tm_mday); add_assoc_long(return_value, "tm_mon", parsed_time.tm_mon); add_assoc_long(return_value, "tm_year", parsed_time.tm_year); add_assoc_long(return_value, "tm_wday", parsed_time.tm_wday); add_assoc_long(return_value, "tm_yday", parsed_time.tm_yday); add_assoc_string(return_value, "unparsed", unparsed_part); } /* }}} */ #endif
3,359
30.698113
83
c
php-src
php-src-master/ext/standard/datetime.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: Andi Gutmans <[email protected]> | | Zeev Suraski <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef DATETIME_H #define DATETIME_H PHPAPI char *php_std_date(time_t t); #endif /* DATETIME_H */
1,172
47.875
75
h
php-src
php-src-master/ext/standard/dir.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: Thies C. Arntzen <[email protected]> | +----------------------------------------------------------------------+ */ /* {{{ includes/startup/misc */ #include "php.h" #include "fopen_wrappers.h" #include "file.h" #include "php_dir.h" #include "php_string.h" #include "php_scandir.h" #include "basic_functions.h" #include "dir_arginfo.h" #ifdef HAVE_UNISTD_H #include <unistd.h> #endif #include <errno.h> #ifdef PHP_WIN32 #include "win32/readdir.h" #endif #ifdef HAVE_GLOB #ifndef PHP_WIN32 #include <glob.h> #else #include "win32/glob.h" #endif #endif typedef struct { zend_resource *default_dir; } php_dir_globals; #ifdef ZTS #define DIRG(v) ZEND_TSRMG(dir_globals_id, php_dir_globals *, v) int dir_globals_id; #else #define DIRG(v) (dir_globals.v) php_dir_globals dir_globals; #endif static zend_class_entry *dir_class_entry_ptr; #define Z_DIRECTORY_PATH_P(zv) OBJ_PROP_NUM(Z_OBJ_P(zv), 0) #define Z_DIRECTORY_HANDLE_P(zv) OBJ_PROP_NUM(Z_OBJ_P(zv), 1) #define FETCH_DIRP() \ myself = getThis(); \ if (!myself) { \ ZEND_PARSE_PARAMETERS_START(0, 1) \ Z_PARAM_OPTIONAL \ Z_PARAM_RESOURCE_OR_NULL(id) \ ZEND_PARSE_PARAMETERS_END(); \ if (id) { \ if ((dirp = (php_stream *)zend_fetch_resource(Z_RES_P(id), "Directory", php_file_le_stream())) == NULL) { \ RETURN_THROWS(); \ } \ } else { \ if (!DIRG(default_dir)) { \ zend_type_error("No resource supplied"); \ RETURN_THROWS(); \ } \ if ((dirp = (php_stream *)zend_fetch_resource(DIRG(default_dir), "Directory", php_file_le_stream())) == NULL) { \ RETURN_THROWS(); \ } \ } \ } else { \ ZEND_PARSE_PARAMETERS_NONE(); \ zval *handle_zv = Z_DIRECTORY_HANDLE_P(myself); \ if (Z_TYPE_P(handle_zv) != IS_RESOURCE) { \ zend_throw_error(NULL, "Unable to find my handle property"); \ RETURN_THROWS(); \ } \ if ((dirp = (php_stream *)zend_fetch_resource_ex(handle_zv, "Directory", php_file_le_stream())) == NULL) { \ RETURN_THROWS(); \ } \ } static void php_set_default_dir(zend_resource *res) { if (DIRG(default_dir)) { zend_list_delete(DIRG(default_dir)); } if (res) { GC_ADDREF(res); } DIRG(default_dir) = res; } PHP_RINIT_FUNCTION(dir) { DIRG(default_dir) = NULL; return SUCCESS; } PHP_MINIT_FUNCTION(dir) { static char dirsep_str[2], pathsep_str[2]; dir_class_entry_ptr = register_class_Directory(); #ifdef ZTS ts_allocate_id(&dir_globals_id, sizeof(php_dir_globals), NULL, NULL); #endif dirsep_str[0] = DEFAULT_SLASH; dirsep_str[1] = '\0'; REGISTER_STRING_CONSTANT("DIRECTORY_SEPARATOR", dirsep_str, CONST_PERSISTENT); pathsep_str[0] = ZEND_PATHS_SEPARATOR; pathsep_str[1] = '\0'; REGISTER_STRING_CONSTANT("PATH_SEPARATOR", pathsep_str, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SCANDIR_SORT_ASCENDING", PHP_SCANDIR_SORT_ASCENDING, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SCANDIR_SORT_DESCENDING", PHP_SCANDIR_SORT_DESCENDING, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SCANDIR_SORT_NONE", PHP_SCANDIR_SORT_NONE, CONST_PERSISTENT); #ifdef HAVE_GLOB #ifdef GLOB_BRACE REGISTER_LONG_CONSTANT("GLOB_BRACE", GLOB_BRACE, CONST_PERSISTENT); #else # define GLOB_BRACE 0 #endif #ifdef GLOB_MARK REGISTER_LONG_CONSTANT("GLOB_MARK", GLOB_MARK, CONST_PERSISTENT); #else # define GLOB_MARK 0 #endif #ifdef GLOB_NOSORT REGISTER_LONG_CONSTANT("GLOB_NOSORT", GLOB_NOSORT, CONST_PERSISTENT); #else # define GLOB_NOSORT 0 #endif #ifdef GLOB_NOCHECK REGISTER_LONG_CONSTANT("GLOB_NOCHECK", GLOB_NOCHECK, CONST_PERSISTENT); #else # define GLOB_NOCHECK 0 #endif #ifdef GLOB_NOESCAPE REGISTER_LONG_CONSTANT("GLOB_NOESCAPE", GLOB_NOESCAPE, CONST_PERSISTENT); #else # define GLOB_NOESCAPE 0 #endif #ifdef GLOB_ERR REGISTER_LONG_CONSTANT("GLOB_ERR", GLOB_ERR, CONST_PERSISTENT); #else # define GLOB_ERR 0 #endif #ifndef GLOB_ONLYDIR # define GLOB_ONLYDIR (1<<30) # define GLOB_EMULATE_ONLYDIR # define GLOB_FLAGMASK (~GLOB_ONLYDIR) #else # define GLOB_FLAGMASK (~0) #endif /* This is used for checking validity of passed flags (passing invalid flags causes segfault in glob()!! */ #define GLOB_AVAILABLE_FLAGS (0 | GLOB_BRACE | GLOB_MARK | GLOB_NOSORT | GLOB_NOCHECK | GLOB_NOESCAPE | GLOB_ERR | GLOB_ONLYDIR) REGISTER_LONG_CONSTANT("GLOB_ONLYDIR", GLOB_ONLYDIR, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("GLOB_AVAILABLE_FLAGS", GLOB_AVAILABLE_FLAGS, CONST_PERSISTENT); #endif /* HAVE_GLOB */ return SUCCESS; } /* }}} */ /* {{{ internal functions */ static void _php_do_opendir(INTERNAL_FUNCTION_PARAMETERS, int createobject) { char *dirname; size_t dir_len; zval *zcontext = NULL; php_stream_context *context = NULL; php_stream *dirp; ZEND_PARSE_PARAMETERS_START(1, 2) Z_PARAM_PATH(dirname, dir_len) Z_PARAM_OPTIONAL Z_PARAM_RESOURCE_OR_NULL(zcontext) ZEND_PARSE_PARAMETERS_END(); context = php_stream_context_from_zval(zcontext, 0); dirp = php_stream_opendir(dirname, REPORT_ERRORS, context); if (dirp == NULL) { RETURN_FALSE; } dirp->flags |= PHP_STREAM_FLAG_NO_FCLOSE; php_set_default_dir(dirp->res); if (createobject) { object_init_ex(return_value, dir_class_entry_ptr); ZVAL_STRINGL(Z_DIRECTORY_PATH_P(return_value), dirname, dir_len); ZVAL_RES(Z_DIRECTORY_HANDLE_P(return_value), dirp->res); php_stream_auto_cleanup(dirp); /* so we don't get warnings under debug */ } else { php_stream_to_zval(dirp, return_value); } } /* }}} */ /* {{{ Open a directory and return a dir_handle */ PHP_FUNCTION(opendir) { _php_do_opendir(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); } /* }}} */ /* {{{ Directory class with properties, handle and class and methods read, rewind and close */ PHP_FUNCTION(dir) { _php_do_opendir(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); } /* }}} */ /* {{{ Close directory connection identified by the dir_handle */ PHP_FUNCTION(closedir) { zval *id = NULL, *myself; php_stream *dirp; zend_resource *res; FETCH_DIRP(); if (!(dirp->flags & PHP_STREAM_FLAG_IS_DIR)) { zend_argument_type_error(1, "must be a valid Directory resource"); RETURN_THROWS(); } res = dirp->res; zend_list_close(dirp->res); if (res == DIRG(default_dir)) { php_set_default_dir(NULL); } } /* }}} */ #if defined(HAVE_CHROOT) && !defined(ZTS) && defined(ENABLE_CHROOT_FUNC) /* {{{ Change root directory */ PHP_FUNCTION(chroot) { char *str; int ret; size_t str_len; ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_PATH(str, str_len) ZEND_PARSE_PARAMETERS_END(); ret = chroot(str); if (ret != 0) { php_error_docref(NULL, E_WARNING, "%s (errno %d)", strerror(errno), errno); RETURN_FALSE; } php_clear_stat_cache(1, NULL, 0); ret = chdir("/"); if (ret != 0) { php_error_docref(NULL, E_WARNING, "%s (errno %d)", strerror(errno), errno); RETURN_FALSE; } RETURN_TRUE; } /* }}} */ #endif /* {{{ Change the current directory */ PHP_FUNCTION(chdir) { char *str; int ret; size_t str_len; ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_PATH(str, str_len) ZEND_PARSE_PARAMETERS_END(); if (php_check_open_basedir(str)) { RETURN_FALSE; } ret = VCWD_CHDIR(str); if (ret != 0) { php_error_docref(NULL, E_WARNING, "%s (errno %d)", strerror(errno), errno); RETURN_FALSE; } if (BG(CurrentStatFile) && !IS_ABSOLUTE_PATH(ZSTR_VAL(BG(CurrentStatFile)), ZSTR_LEN(BG(CurrentStatFile)))) { zend_string_release(BG(CurrentStatFile)); BG(CurrentStatFile) = NULL; } if (BG(CurrentLStatFile) && !IS_ABSOLUTE_PATH(ZSTR_VAL(BG(CurrentLStatFile)), ZSTR_LEN(BG(CurrentLStatFile)))) { zend_string_release(BG(CurrentLStatFile)); BG(CurrentLStatFile) = NULL; } RETURN_TRUE; } /* }}} */ /* {{{ Gets the current directory */ PHP_FUNCTION(getcwd) { char path[MAXPATHLEN]; char *ret=NULL; ZEND_PARSE_PARAMETERS_NONE(); #ifdef HAVE_GETCWD ret = VCWD_GETCWD(path, MAXPATHLEN); #elif defined(HAVE_GETWD) ret = VCWD_GETWD(path); #endif if (ret) { RETURN_STRING(path); } else { RETURN_FALSE; } } /* }}} */ /* {{{ Rewind dir_handle back to the start */ PHP_FUNCTION(rewinddir) { zval *id = NULL, *myself; php_stream *dirp; FETCH_DIRP(); if (!(dirp->flags & PHP_STREAM_FLAG_IS_DIR)) { zend_argument_type_error(1, "must be a valid Directory resource"); RETURN_THROWS(); } php_stream_rewinddir(dirp); } /* }}} */ /* {{{ Read directory entry from dir_handle */ PHP_FUNCTION(readdir) { zval *id = NULL, *myself; php_stream *dirp; php_stream_dirent entry; FETCH_DIRP(); if (!(dirp->flags & PHP_STREAM_FLAG_IS_DIR)) { zend_argument_type_error(1, "must be a valid Directory resource"); RETURN_THROWS(); } if (php_stream_readdir(dirp, &entry)) { RETURN_STRINGL(entry.d_name, strlen(entry.d_name)); } RETURN_FALSE; } /* }}} */ #ifdef HAVE_GLOB /* {{{ Find pathnames matching a pattern */ PHP_FUNCTION(glob) { size_t cwd_skip = 0; #ifdef ZTS char cwd[MAXPATHLEN]; char work_pattern[MAXPATHLEN]; char *result; #endif char *pattern = NULL; size_t pattern_len; zend_long flags = 0; glob_t globbuf; size_t n; int ret; bool basedir_limit = 0; zval tmp; ZEND_PARSE_PARAMETERS_START(1, 2) Z_PARAM_PATH(pattern, pattern_len) Z_PARAM_OPTIONAL Z_PARAM_LONG(flags) ZEND_PARSE_PARAMETERS_END(); if (pattern_len >= MAXPATHLEN) { php_error_docref(NULL, E_WARNING, "Pattern exceeds the maximum allowed length of %d characters", MAXPATHLEN); RETURN_FALSE; } if ((GLOB_AVAILABLE_FLAGS & flags) != flags) { php_error_docref(NULL, E_WARNING, "At least one of the passed flags is invalid or not supported on this platform"); RETURN_FALSE; } #ifdef ZTS if (!IS_ABSOLUTE_PATH(pattern, pattern_len)) { result = VCWD_GETCWD(cwd, MAXPATHLEN); if (!result) { cwd[0] = '\0'; } #ifdef PHP_WIN32 if (IS_SLASH(*pattern)) { cwd[2] = '\0'; } #endif cwd_skip = strlen(cwd)+1; snprintf(work_pattern, MAXPATHLEN, "%s%c%s", cwd, DEFAULT_SLASH, pattern); pattern = work_pattern; } #endif memset(&globbuf, 0, sizeof(glob_t)); globbuf.gl_offs = 0; if (0 != (ret = glob(pattern, flags & GLOB_FLAGMASK, NULL, &globbuf))) { #ifdef GLOB_NOMATCH if (GLOB_NOMATCH == ret) { /* Some glob implementation simply return no data if no matches were found, others return the GLOB_NOMATCH error code. We don't want to treat GLOB_NOMATCH as an error condition so that PHP glob() behaves the same on both types of implementations and so that 'foreach (glob() as ...' can be used for simple glob() calls without further error checking. */ goto no_results; } #endif RETURN_FALSE; } /* now catch the FreeBSD style of "no matches" */ if (!globbuf.gl_pathc || !globbuf.gl_pathv) { #ifdef GLOB_NOMATCH no_results: #endif array_init(return_value); return; } array_init(return_value); for (n = 0; n < (size_t)globbuf.gl_pathc; n++) { if (PG(open_basedir) && *PG(open_basedir)) { if (php_check_open_basedir_ex(globbuf.gl_pathv[n], 0)) { basedir_limit = 1; continue; } } /* we need to do this every time since GLOB_ONLYDIR does not guarantee that * all directories will be filtered. GNU libc documentation states the * following: * If the information about the type of the file is easily available * non-directories will be rejected but no extra work will be done to * determine the information for each file. I.e., the caller must still be * able to filter directories out. */ if (flags & GLOB_ONLYDIR) { zend_stat_t s = {0}; if (0 != VCWD_STAT(globbuf.gl_pathv[n], &s)) { continue; } if (S_IFDIR != (s.st_mode & S_IFMT)) { continue; } } ZVAL_STRING(&tmp, globbuf.gl_pathv[n]+cwd_skip); zend_hash_next_index_insert_new(Z_ARRVAL_P(return_value), &tmp); } globfree(&globbuf); if (basedir_limit && !zend_hash_num_elements(Z_ARRVAL_P(return_value))) { zend_array_destroy(Z_ARR_P(return_value)); RETURN_FALSE; } } /* }}} */ #endif /* {{{ List files & directories inside the specified path */ PHP_FUNCTION(scandir) { char *dirn; size_t dirn_len; zend_long flags = PHP_SCANDIR_SORT_ASCENDING; zend_string **namelist; int n, i; zval *zcontext = NULL; php_stream_context *context = NULL; ZEND_PARSE_PARAMETERS_START(1, 3) Z_PARAM_PATH(dirn, dirn_len) Z_PARAM_OPTIONAL Z_PARAM_LONG(flags) Z_PARAM_RESOURCE_OR_NULL(zcontext) ZEND_PARSE_PARAMETERS_END(); if (dirn_len < 1) { zend_argument_value_error(1, "cannot be empty"); RETURN_THROWS(); } if (zcontext) { context = php_stream_context_from_zval(zcontext, 0); } if (flags == PHP_SCANDIR_SORT_ASCENDING) { n = php_stream_scandir(dirn, &namelist, context, (void *) php_stream_dirent_alphasort); } else if (flags == PHP_SCANDIR_SORT_NONE) { n = php_stream_scandir(dirn, &namelist, context, NULL); } else { n = php_stream_scandir(dirn, &namelist, context, (void *) php_stream_dirent_alphasortr); } if (n < 0) { php_error_docref(NULL, E_WARNING, "(errno %d): %s", errno, strerror(errno)); RETURN_FALSE; } array_init(return_value); for (i = 0; i < n; i++) { add_next_index_str(return_value, namelist[i]); } if (n) { efree(namelist); } } /* }}} */
13,837
23.277193
128
c
php-src
php-src-master/ext/standard/dl.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: Brian Schaffner <[email protected]> | | Shane Caraveo <[email protected]> | | Zeev Suraski <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef DL_H #define DL_H PHPAPI int php_load_extension(const char *filename, int type, int start_now); PHPAPI void php_dl(const char *file, int type, zval *return_value, int start_now); PHPAPI void *php_load_shlib(const char *path, char **errp); /* dynamic loading functions */ PHPAPI PHP_FUNCTION(dl); PHP_MINFO_FUNCTION(dl); #endif /* DL_H */
1,497
45.8125
82
h
php-src
php-src-master/ext/standard/exec.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: Rasmus Lerdorf <[email protected]> | | Ilia Alshanetsky <[email protected]> | +----------------------------------------------------------------------+ */ #include <stdio.h> #include "php.h" #include <ctype.h> #include "php_string.h" #include "ext/standard/head.h" #include "ext/standard/file.h" #include "basic_functions.h" #include "exec.h" #include "php_globals.h" #include "SAPI.h" #ifdef HAVE_SYS_WAIT_H #include <sys/wait.h> #endif #include <signal.h> #ifdef HAVE_SYS_TYPES_H #include <sys/types.h> #endif #ifdef HAVE_SYS_STAT_H #include <sys/stat.h> #endif #ifdef HAVE_FCNTL_H #include <fcntl.h> #endif #ifdef HAVE_UNISTD_H #include <unistd.h> #endif #include <limits.h> #ifdef PHP_WIN32 # include "win32/nice.h" #endif static size_t cmd_max_len; /* {{{ PHP_MINIT_FUNCTION(exec) */ PHP_MINIT_FUNCTION(exec) { #ifdef _SC_ARG_MAX cmd_max_len = sysconf(_SC_ARG_MAX); if ((size_t)-1 == cmd_max_len) { #ifdef _POSIX_ARG_MAX cmd_max_len = _POSIX_ARG_MAX; #else cmd_max_len = 4096; #endif } #elif defined(ARG_MAX) cmd_max_len = ARG_MAX; #elif defined(PHP_WIN32) /* Executed commands will run through cmd.exe. As long as it's the case, it's just the constant limit.*/ cmd_max_len = 8192; #else /* This is just an arbitrary value for the fallback case. */ cmd_max_len = 4096; #endif return SUCCESS; } /* }}} */ static size_t strip_trailing_whitespace(char *buf, size_t bufl) { size_t l = bufl; while (l-- > 0 && isspace(((unsigned char *)buf)[l])); if (l != (bufl - 1)) { bufl = l + 1; buf[bufl] = '\0'; } return bufl; } static size_t handle_line(int type, zval *array, char *buf, size_t bufl) { if (type == 1) { PHPWRITE(buf, bufl); if (php_output_get_level() < 1) { sapi_flush(); } } else if (type == 2) { bufl = strip_trailing_whitespace(buf, bufl); add_next_index_stringl(array, buf, bufl); } return bufl; } /* {{{ php_exec * If type==0, only last line of output is returned (exec) * If type==1, all lines will be printed and last lined returned (system) * If type==2, all lines will be saved to given array (exec with &$array) * If type==3, output will be printed binary, no lines will be saved or returned (passthru) * */ PHPAPI int php_exec(int type, const char *cmd, zval *array, zval *return_value) { FILE *fp; char *buf; int pclose_return; char *b, *d=NULL; php_stream *stream; size_t buflen, bufl = 0; #if PHP_SIGCHILD void (*sig_handler)() = NULL; #endif #if PHP_SIGCHILD sig_handler = signal (SIGCHLD, SIG_DFL); #endif #ifdef PHP_WIN32 fp = VCWD_POPEN(cmd, "rb"); #else fp = VCWD_POPEN(cmd, "r"); #endif if (!fp) { php_error_docref(NULL, E_WARNING, "Unable to fork [%s]", cmd); goto err; } stream = php_stream_fopen_from_pipe(fp, "rb"); buf = (char *) emalloc(EXEC_INPUT_BUF); buflen = EXEC_INPUT_BUF; if (type != 3) { b = buf; while (php_stream_get_line(stream, b, EXEC_INPUT_BUF, &bufl)) { /* no new line found, let's read some more */ if (b[bufl - 1] != '\n' && !php_stream_eof(stream)) { if (buflen < (bufl + (b - buf) + EXEC_INPUT_BUF)) { bufl += b - buf; buflen = bufl + EXEC_INPUT_BUF; buf = erealloc(buf, buflen); b = buf + bufl; } else { b += bufl; } continue; } else if (b != buf) { bufl += b - buf; } bufl = handle_line(type, array, buf, bufl); b = buf; } if (bufl) { if (buf != b) { /* Process remaining output */ bufl = handle_line(type, array, buf, bufl); } /* Return last line from the shell command */ bufl = strip_trailing_whitespace(buf, bufl); RETVAL_STRINGL(buf, bufl); } else { /* should return NULL, but for BC we return "" */ RETVAL_EMPTY_STRING(); } } else { ssize_t read; while ((read = php_stream_read(stream, buf, EXEC_INPUT_BUF)) > 0) { PHPWRITE(buf, read); } } pclose_return = php_stream_close(stream); efree(buf); done: #if PHP_SIGCHILD if (sig_handler) { signal(SIGCHLD, sig_handler); } #endif if (d) { efree(d); } return pclose_return; err: pclose_return = -1; RETVAL_FALSE; goto done; } /* }}} */ static void php_exec_ex(INTERNAL_FUNCTION_PARAMETERS, int mode) /* {{{ */ { char *cmd; size_t cmd_len; zval *ret_code=NULL, *ret_array=NULL; int ret; ZEND_PARSE_PARAMETERS_START(1, (mode ? 2 : 3)) Z_PARAM_STRING(cmd, cmd_len) Z_PARAM_OPTIONAL if (!mode) { Z_PARAM_ZVAL(ret_array) } Z_PARAM_ZVAL(ret_code) ZEND_PARSE_PARAMETERS_END(); if (!cmd_len) { zend_argument_value_error(1, "cannot be empty"); RETURN_THROWS(); } if (strlen(cmd) != cmd_len) { zend_argument_value_error(1, "must not contain any null bytes"); RETURN_THROWS(); } if (!ret_array) { ret = php_exec(mode, cmd, NULL, return_value); } else { if (Z_TYPE_P(Z_REFVAL_P(ret_array)) == IS_ARRAY) { ZVAL_DEREF(ret_array); SEPARATE_ARRAY(ret_array); } else { ret_array = zend_try_array_init(ret_array); if (!ret_array) { RETURN_THROWS(); } } ret = php_exec(2, cmd, ret_array, return_value); } if (ret_code) { ZEND_TRY_ASSIGN_REF_LONG(ret_code, ret); } } /* }}} */ /* {{{ Execute an external program */ PHP_FUNCTION(exec) { php_exec_ex(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); } /* }}} */ /* {{{ Execute an external program and display output */ PHP_FUNCTION(system) { php_exec_ex(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); } /* }}} */ /* {{{ Execute an external program and display raw output */ PHP_FUNCTION(passthru) { php_exec_ex(INTERNAL_FUNCTION_PARAM_PASSTHRU, 3); } /* }}} */ /* {{{ php_escape_shell_cmd Escape all chars that could possibly be used to break out of a shell command This function emalloc's a string and returns the pointer. Remember to efree it when done with it. *NOT* safe for binary strings */ PHPAPI zend_string *php_escape_shell_cmd(const char *str) { size_t x, y; size_t l = strlen(str); uint64_t estimate = (2 * (uint64_t)l) + 1; zend_string *cmd; #ifndef PHP_WIN32 char *p = NULL; #endif /* max command line length - two single quotes - \0 byte length */ if (l > cmd_max_len - 2 - 1) { php_error_docref(NULL, E_ERROR, "Command exceeds the allowed length of %zu bytes", cmd_max_len); return ZSTR_EMPTY_ALLOC(); } cmd = zend_string_safe_alloc(2, l, 0, 0); for (x = 0, y = 0; x < l; x++) { int mb_len = php_mblen(str + x, (l - x)); /* skip non-valid multibyte characters */ if (mb_len < 0) { continue; } else if (mb_len > 1) { memcpy(ZSTR_VAL(cmd) + y, str + x, mb_len); y += mb_len; x += mb_len - 1; continue; } switch (str[x]) { #ifndef PHP_WIN32 case '"': case '\'': if (!p && (p = memchr(str + x + 1, str[x], l - x - 1))) { /* noop */ } else if (p && *p == str[x]) { p = NULL; } else { ZSTR_VAL(cmd)[y++] = '\\'; } ZSTR_VAL(cmd)[y++] = str[x]; break; #else /* % is Windows specific for environmental variables, ^%PATH% will output PATH while ^%PATH^% will not. escapeshellcmd->val will escape all % and !. */ case '%': case '!': case '"': case '\'': #endif case '#': /* This is character-set independent */ case '&': case ';': case '`': case '|': case '*': case '?': case '~': case '<': case '>': case '^': case '(': case ')': case '[': case ']': case '{': case '}': case '$': case '\\': case '\x0A': /* excluding these two */ case '\xFF': #ifdef PHP_WIN32 ZSTR_VAL(cmd)[y++] = '^'; #else ZSTR_VAL(cmd)[y++] = '\\'; #endif ZEND_FALLTHROUGH; default: ZSTR_VAL(cmd)[y++] = str[x]; } } ZSTR_VAL(cmd)[y] = '\0'; if (y > cmd_max_len + 1) { php_error_docref(NULL, E_ERROR, "Escaped command exceeds the allowed length of %zu bytes", cmd_max_len); zend_string_release_ex(cmd, 0); return ZSTR_EMPTY_ALLOC(); } if ((estimate - y) > 4096) { /* realloc if the estimate was way overill * Arbitrary cutoff point of 4096 */ cmd = zend_string_truncate(cmd, y, 0); } ZSTR_LEN(cmd) = y; return cmd; } /* }}} */ /* {{{ php_escape_shell_arg */ PHPAPI zend_string *php_escape_shell_arg(const char *str) { size_t x, y = 0; size_t l = strlen(str); zend_string *cmd; uint64_t estimate = (4 * (uint64_t)l) + 3; /* max command line length - two single quotes - \0 byte length */ if (l > cmd_max_len - 2 - 1) { php_error_docref(NULL, E_ERROR, "Argument exceeds the allowed length of %zu bytes", cmd_max_len); return ZSTR_EMPTY_ALLOC(); } cmd = zend_string_safe_alloc(4, l, 2, 0); /* worst case */ #ifdef PHP_WIN32 ZSTR_VAL(cmd)[y++] = '"'; #else ZSTR_VAL(cmd)[y++] = '\''; #endif for (x = 0; x < l; x++) { int mb_len = php_mblen(str + x, (l - x)); /* skip non-valid multibyte characters */ if (mb_len < 0) { continue; } else if (mb_len > 1) { memcpy(ZSTR_VAL(cmd) + y, str + x, mb_len); y += mb_len; x += mb_len - 1; continue; } switch (str[x]) { #ifdef PHP_WIN32 case '"': case '%': case '!': ZSTR_VAL(cmd)[y++] = ' '; break; #else case '\'': ZSTR_VAL(cmd)[y++] = '\''; ZSTR_VAL(cmd)[y++] = '\\'; ZSTR_VAL(cmd)[y++] = '\''; #endif ZEND_FALLTHROUGH; default: ZSTR_VAL(cmd)[y++] = str[x]; } } #ifdef PHP_WIN32 if (y > 0 && '\\' == ZSTR_VAL(cmd)[y - 1]) { int k = 0, n = y - 1; for (; n >= 0 && '\\' == ZSTR_VAL(cmd)[n]; n--, k++); if (k % 2) { ZSTR_VAL(cmd)[y++] = '\\'; } } ZSTR_VAL(cmd)[y++] = '"'; #else ZSTR_VAL(cmd)[y++] = '\''; #endif ZSTR_VAL(cmd)[y] = '\0'; if (y > cmd_max_len + 1) { php_error_docref(NULL, E_ERROR, "Escaped argument exceeds the allowed length of %zu bytes", cmd_max_len); zend_string_release_ex(cmd, 0); return ZSTR_EMPTY_ALLOC(); } if ((estimate - y) > 4096) { /* realloc if the estimate was way overill * Arbitrary cutoff point of 4096 */ cmd = zend_string_truncate(cmd, y, 0); } ZSTR_LEN(cmd) = y; return cmd; } /* }}} */ /* {{{ Escape shell metacharacters */ PHP_FUNCTION(escapeshellcmd) { char *command; size_t command_len; ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_STRING(command, command_len) ZEND_PARSE_PARAMETERS_END(); if (command_len) { if (command_len != strlen(command)) { zend_argument_value_error(1, "must not contain any null bytes"); RETURN_THROWS(); } RETVAL_STR(php_escape_shell_cmd(command)); } else { RETVAL_EMPTY_STRING(); } } /* }}} */ /* {{{ Quote and escape an argument for use in a shell command */ PHP_FUNCTION(escapeshellarg) { char *argument; size_t argument_len; ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_STRING(argument, argument_len) ZEND_PARSE_PARAMETERS_END(); if (argument_len != strlen(argument)) { zend_argument_value_error(1, "must not contain any null bytes"); RETURN_THROWS(); } RETVAL_STR(php_escape_shell_arg(argument)); } /* }}} */ /* {{{ Execute command via shell and return complete output as string */ PHP_FUNCTION(shell_exec) { FILE *in; char *command; size_t command_len; zend_string *ret; php_stream *stream; ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_STRING(command, command_len) ZEND_PARSE_PARAMETERS_END(); if (!command_len) { zend_argument_value_error(1, "cannot be empty"); RETURN_THROWS(); } if (strlen(command) != command_len) { zend_argument_value_error(1, "must not contain any null bytes"); RETURN_THROWS(); } #ifdef PHP_WIN32 if ((in=VCWD_POPEN(command, "rt"))==NULL) { #else if ((in=VCWD_POPEN(command, "r"))==NULL) { #endif php_error_docref(NULL, E_WARNING, "Unable to execute '%s'", command); RETURN_FALSE; } stream = php_stream_fopen_from_pipe(in, "rb"); ret = php_stream_copy_to_mem(stream, PHP_STREAM_COPY_ALL, 0); php_stream_close(stream); if (ret && ZSTR_LEN(ret) > 0) { RETVAL_STR(ret); } } /* }}} */ #ifdef HAVE_NICE /* {{{ Change the priority of the current process */ PHP_FUNCTION(proc_nice) { zend_long pri; ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_LONG(pri) ZEND_PARSE_PARAMETERS_END(); errno = 0; php_ignore_value(nice(pri)); if (errno) { #ifdef PHP_WIN32 char *err = php_win_err(); php_error_docref(NULL, E_WARNING, "%s", err); php_win_err_free(err); #else php_error_docref(NULL, E_WARNING, "Only a super user may attempt to increase the priority of a process"); #endif RETURN_FALSE; } RETURN_TRUE; } /* }}} */ #endif
13,094
21.577586
107
c
php-src
php-src-master/ext/standard/exec.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: Rasmus Lerdorf <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef EXEC_H #define EXEC_H PHP_MINIT_FUNCTION(proc_open); PHP_MINIT_FUNCTION(exec); PHPAPI zend_string *php_escape_shell_cmd(const char *str); PHPAPI zend_string *php_escape_shell_arg(const char *str); PHPAPI int php_exec(int type, const char *cmd, zval *array, zval *return_value); #endif /* EXEC_H */
1,304
45.607143
80
h
php-src
php-src-master/ext/standard/file.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: Rasmus Lerdorf <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef FILE_H #define FILE_H #include "php_network.h" PHP_MINIT_FUNCTION(file); PHP_MSHUTDOWN_FUNCTION(file); PHPAPI PHP_FUNCTION(fclose); PHPAPI PHP_FUNCTION(feof); PHPAPI PHP_FUNCTION(fread); PHPAPI PHP_FUNCTION(fgetc); PHPAPI PHP_FUNCTION(fgets); PHPAPI PHP_FUNCTION(fwrite); PHPAPI PHP_FUNCTION(fflush); PHPAPI PHP_FUNCTION(rewind); PHPAPI PHP_FUNCTION(ftell); PHPAPI PHP_FUNCTION(fseek); PHPAPI PHP_FUNCTION(fpassthru); PHP_MINIT_FUNCTION(user_streams); PHPAPI int php_le_stream_context(void); PHPAPI int php_set_sock_blocking(php_socket_t socketd, int block); PHPAPI int php_copy_file(const char *src, const char *dest); PHPAPI int php_copy_file_ex(const char *src, const char *dest, int src_chk); PHPAPI int php_copy_file_ctx(const char *src, const char *dest, int src_chk, php_stream_context *ctx); PHPAPI int php_mkdir_ex(const char *dir, zend_long mode, int options); PHPAPI int php_mkdir(const char *dir, zend_long mode); PHPAPI void php_fstat(php_stream *stream, zval *return_value); PHPAPI void php_flock_common(php_stream *stream, zend_long operation, uint32_t operation_arg_num, zval *wouldblock, zval *return_value); #define PHP_CSV_NO_ESCAPE EOF PHPAPI HashTable *php_bc_fgetcsv_empty_line(void); PHPAPI HashTable *php_fgetcsv(php_stream *stream, char delimiter, char enclosure, int escape_char, size_t buf_len, char *buf); PHPAPI ssize_t php_fputcsv(php_stream *stream, zval *fields, char delimiter, char enclosure, int escape_char, zend_string *eol_str); #define META_DEF_BUFSIZE 8192 #define PHP_FILE_USE_INCLUDE_PATH (1 << 0) #define PHP_FILE_IGNORE_NEW_LINES (1 << 1) #define PHP_FILE_SKIP_EMPTY_LINES (1 << 2) #define PHP_FILE_APPEND (1 << 3) #define PHP_FILE_NO_DEFAULT_CONTEXT (1 << 4) typedef enum _php_meta_tags_token { TOK_EOF = 0, TOK_OPENTAG, TOK_CLOSETAG, TOK_SLASH, TOK_EQUAL, TOK_SPACE, TOK_ID, TOK_STRING, TOK_OTHER } php_meta_tags_token; typedef struct _php_meta_tags_data { php_stream *stream; int ulc; int lc; char *input_buffer; char *token_data; int token_len; int in_meta; } php_meta_tags_data; php_meta_tags_token php_next_meta_token(php_meta_tags_data *); typedef struct { int pclose_ret; size_t def_chunk_size; bool auto_detect_line_endings; zend_long default_socket_timeout; char *user_agent; /* for the http wrapper */ char *from_address; /* for the ftp and http wrappers */ const char *user_stream_current_filename; /* for simple recursion protection */ php_stream_context *default_context; HashTable *stream_wrappers; /* per-request copy of url_stream_wrappers_hash */ HashTable *stream_filters; /* per-request copy of stream_filters_hash */ HashTable *wrapper_errors; /* key: wrapper address; value: linked list of char* */ int pclose_wait; #ifdef HAVE_GETHOSTBYNAME_R struct hostent tmp_host_info; char *tmp_host_buf; size_t tmp_host_buf_len; #endif } php_file_globals; #ifdef ZTS #define FG(v) ZEND_TSRMG(file_globals_id, php_file_globals *, v) extern PHPAPI int file_globals_id; #else #define FG(v) (file_globals.v) extern PHPAPI php_file_globals file_globals; #endif #endif /* FILE_H */
4,088
33.948718
132
h
php-src
php-src-master/ext/standard/file_arginfo.h
/* This is a generated file, edit the .stub.php file instead. * Stub hash: e9a566d5ef96f781074027b1b3ff1824d0208b47 */ static void register_file_symbols(int module_number) { REGISTER_LONG_CONSTANT("SEEK_SET", SEEK_SET, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SEEK_CUR", SEEK_CUR, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SEEK_END", SEEK_END, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("LOCK_SH", PHP_LOCK_SH, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("LOCK_EX", PHP_LOCK_EX, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("LOCK_UN", PHP_LOCK_UN, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("LOCK_NB", PHP_LOCK_NB, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("STREAM_NOTIFY_CONNECT", PHP_STREAM_NOTIFY_CONNECT, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("STREAM_NOTIFY_AUTH_REQUIRED", PHP_STREAM_NOTIFY_AUTH_REQUIRED, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("STREAM_NOTIFY_AUTH_RESULT", PHP_STREAM_NOTIFY_AUTH_RESULT, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("STREAM_NOTIFY_MIME_TYPE_IS", PHP_STREAM_NOTIFY_MIME_TYPE_IS, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("STREAM_NOTIFY_FILE_SIZE_IS", PHP_STREAM_NOTIFY_FILE_SIZE_IS, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("STREAM_NOTIFY_REDIRECTED", PHP_STREAM_NOTIFY_REDIRECTED, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("STREAM_NOTIFY_PROGRESS", PHP_STREAM_NOTIFY_PROGRESS, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("STREAM_NOTIFY_FAILURE", PHP_STREAM_NOTIFY_FAILURE, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("STREAM_NOTIFY_COMPLETED", PHP_STREAM_NOTIFY_COMPLETED, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("STREAM_NOTIFY_RESOLVE", PHP_STREAM_NOTIFY_RESOLVE, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("STREAM_NOTIFY_SEVERITY_INFO", PHP_STREAM_NOTIFY_SEVERITY_INFO, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("STREAM_NOTIFY_SEVERITY_WARN", PHP_STREAM_NOTIFY_SEVERITY_WARN, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("STREAM_NOTIFY_SEVERITY_ERR", PHP_STREAM_NOTIFY_SEVERITY_ERR, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("STREAM_FILTER_READ", PHP_STREAM_FILTER_READ, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("STREAM_FILTER_WRITE", PHP_STREAM_FILTER_WRITE, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("STREAM_FILTER_ALL", PHP_STREAM_FILTER_ALL, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("STREAM_CLIENT_PERSISTENT", PHP_STREAM_CLIENT_PERSISTENT, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("STREAM_CLIENT_ASYNC_CONNECT", PHP_STREAM_CLIENT_ASYNC_CONNECT, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("STREAM_CLIENT_CONNECT", PHP_STREAM_CLIENT_CONNECT, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("STREAM_CRYPTO_METHOD_ANY_CLIENT", STREAM_CRYPTO_METHOD_ANY_CLIENT, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("STREAM_CRYPTO_METHOD_SSLv2_CLIENT", STREAM_CRYPTO_METHOD_SSLv2_CLIENT, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("STREAM_CRYPTO_METHOD_SSLv3_CLIENT", STREAM_CRYPTO_METHOD_SSLv3_CLIENT, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("STREAM_CRYPTO_METHOD_SSLv23_CLIENT", STREAM_CRYPTO_METHOD_SSLv23_CLIENT, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("STREAM_CRYPTO_METHOD_TLS_CLIENT", STREAM_CRYPTO_METHOD_TLS_CLIENT, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT", STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT", STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT", STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("STREAM_CRYPTO_METHOD_TLSv1_3_CLIENT", STREAM_CRYPTO_METHOD_TLSv1_3_CLIENT, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("STREAM_CRYPTO_METHOD_ANY_SERVER", STREAM_CRYPTO_METHOD_ANY_SERVER, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("STREAM_CRYPTO_METHOD_SSLv2_SERVER", STREAM_CRYPTO_METHOD_SSLv2_SERVER, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("STREAM_CRYPTO_METHOD_SSLv3_SERVER", STREAM_CRYPTO_METHOD_SSLv3_SERVER, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("STREAM_CRYPTO_METHOD_SSLv23_SERVER", STREAM_CRYPTO_METHOD_SSLv23_SERVER, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("STREAM_CRYPTO_METHOD_TLS_SERVER", STREAM_CRYPTO_METHOD_TLS_SERVER, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("STREAM_CRYPTO_METHOD_TLSv1_0_SERVER", STREAM_CRYPTO_METHOD_TLSv1_0_SERVER, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("STREAM_CRYPTO_METHOD_TLSv1_1_SERVER", STREAM_CRYPTO_METHOD_TLSv1_1_SERVER, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("STREAM_CRYPTO_METHOD_TLSv1_2_SERVER", STREAM_CRYPTO_METHOD_TLSv1_2_SERVER, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("STREAM_CRYPTO_METHOD_TLSv1_3_SERVER", STREAM_CRYPTO_METHOD_TLSv1_3_SERVER, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("STREAM_CRYPTO_PROTO_SSLv3", STREAM_CRYPTO_METHOD_SSLv3_SERVER, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("STREAM_CRYPTO_PROTO_TLSv1_0", STREAM_CRYPTO_METHOD_TLSv1_0_SERVER, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("STREAM_CRYPTO_PROTO_TLSv1_1", STREAM_CRYPTO_METHOD_TLSv1_1_SERVER, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("STREAM_CRYPTO_PROTO_TLSv1_2", STREAM_CRYPTO_METHOD_TLSv1_2_SERVER, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("STREAM_CRYPTO_PROTO_TLSv1_3", STREAM_CRYPTO_METHOD_TLSv1_3_SERVER, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("STREAM_SHUT_RD", STREAM_SHUT_RD, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("STREAM_SHUT_WR", STREAM_SHUT_WR, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("STREAM_SHUT_RDWR", STREAM_SHUT_RDWR, CONST_PERSISTENT); #if defined(PF_INET) REGISTER_LONG_CONSTANT("STREAM_PF_INET", PF_INET, CONST_PERSISTENT); #endif #if (!defined(PF_INET) && defined(AF_INET)) REGISTER_LONG_CONSTANT("STREAM_PF_INET", AF_INET, CONST_PERSISTENT); #endif #if defined(HAVE_IPV6) && defined(PF_INET6) REGISTER_LONG_CONSTANT("STREAM_PF_INET6", PF_INET6, CONST_PERSISTENT); #endif #if defined(HAVE_IPV6) && (!defined(PF_INET6) && defined(AF_INET6)) REGISTER_LONG_CONSTANT("STREAM_PF_INET6", AF_INET6, CONST_PERSISTENT); #endif #if defined(PF_UNIX) REGISTER_LONG_CONSTANT("STREAM_PF_UNIX", PF_UNIX, CONST_PERSISTENT); #endif #if (!defined(PF_UNIX) && defined(AF_UNIX)) REGISTER_LONG_CONSTANT("STREAM_PF_UNIX", AF_UNIX, CONST_PERSISTENT); #endif #if defined(IPPROTO_IP) REGISTER_LONG_CONSTANT("STREAM_IPPROTO_IP", IPPROTO_IP, CONST_PERSISTENT); #endif #if (defined(IPPROTO_TCP) || defined(PHP_WIN32)) REGISTER_LONG_CONSTANT("STREAM_IPPROTO_TCP", IPPROTO_TCP, CONST_PERSISTENT); #endif #if (defined(IPPROTO_UDP) || defined(PHP_WIN32)) REGISTER_LONG_CONSTANT("STREAM_IPPROTO_UDP", IPPROTO_UDP, CONST_PERSISTENT); #endif #if (defined(IPPROTO_ICMP) || defined(PHP_WIN32)) REGISTER_LONG_CONSTANT("STREAM_IPPROTO_ICMP", IPPROTO_ICMP, CONST_PERSISTENT); #endif #if (defined(IPPROTO_RAW) || defined(PHP_WIN32)) REGISTER_LONG_CONSTANT("STREAM_IPPROTO_RAW", IPPROTO_RAW, CONST_PERSISTENT); #endif REGISTER_LONG_CONSTANT("STREAM_SOCK_STREAM", SOCK_STREAM, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("STREAM_SOCK_DGRAM", SOCK_DGRAM, CONST_PERSISTENT); #if defined(SOCK_RAW) REGISTER_LONG_CONSTANT("STREAM_SOCK_RAW", SOCK_RAW, CONST_PERSISTENT); #endif #if defined(SOCK_SEQPACKET) REGISTER_LONG_CONSTANT("STREAM_SOCK_SEQPACKET", SOCK_SEQPACKET, CONST_PERSISTENT); #endif #if defined(SOCK_RDM) REGISTER_LONG_CONSTANT("STREAM_SOCK_RDM", SOCK_RDM, CONST_PERSISTENT); #endif REGISTER_LONG_CONSTANT("STREAM_PEEK", STREAM_PEEK, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("STREAM_OOB", STREAM_OOB, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("STREAM_SERVER_BIND", STREAM_XPORT_BIND, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("STREAM_SERVER_LISTEN", STREAM_XPORT_LISTEN, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("FILE_USE_INCLUDE_PATH", PHP_FILE_USE_INCLUDE_PATH, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("FILE_IGNORE_NEW_LINES", PHP_FILE_IGNORE_NEW_LINES, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("FILE_SKIP_EMPTY_LINES", PHP_FILE_SKIP_EMPTY_LINES, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("FILE_APPEND", PHP_FILE_APPEND, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("FILE_NO_DEFAULT_CONTEXT", PHP_FILE_NO_DEFAULT_CONTEXT, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("FILE_TEXT", 0, CONST_PERSISTENT | CONST_DEPRECATED); REGISTER_LONG_CONSTANT("FILE_BINARY", 0, CONST_PERSISTENT | CONST_DEPRECATED); #if defined(HAVE_FNMATCH) REGISTER_LONG_CONSTANT("FNM_NOESCAPE", FNM_NOESCAPE, CONST_PERSISTENT); #endif #if defined(HAVE_FNMATCH) REGISTER_LONG_CONSTANT("FNM_PATHNAME", FNM_PATHNAME, CONST_PERSISTENT); #endif #if defined(HAVE_FNMATCH) REGISTER_LONG_CONSTANT("FNM_PERIOD", FNM_PERIOD, CONST_PERSISTENT); #endif #if defined(HAVE_FNMATCH) && defined(FNM_CASEFOLD) REGISTER_LONG_CONSTANT("FNM_CASEFOLD", FNM_CASEFOLD, CONST_PERSISTENT); #endif }
8,613
66.296875
118
h
php-src
php-src-master/ext/standard/flock_compat.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: Sascha Schumann <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef FLOCK_COMPAT_H #define FLOCK_COMPAT_H #ifdef HAVE_STRUCT_FLOCK #include <unistd.h> #include <fcntl.h> #include <sys/file.h> #endif #ifdef PHP_WIN32 #include <io.h> #include "config.w32.h" #endif /* php_flock internally uses fcntl whether or not flock is available * This way our php_flock even works on NFS files. * More info: /usr/src/linux/Documentation */ PHPAPI int php_flock(int fd, int operation); #ifndef HAVE_FLOCK # define LOCK_SH 1 # define LOCK_EX 2 # define LOCK_NB 4 # define LOCK_UN 8 PHPAPI int flock(int fd, int operation); #endif /* Userland LOCK_* constants */ #define PHP_LOCK_SH 1 #define PHP_LOCK_EX 2 #define PHP_LOCK_UN 3 #define PHP_LOCK_NB 4 #ifdef PHP_WIN32 # ifdef EWOULDBLOCK # undef EWOULDBLOCK # endif # define EWOULDBLOCK WSAEWOULDBLOCK # define fsync _commit # define ftruncate(a, b) chsize(a, b) #endif /* defined(PHP_WIN32) */ #ifndef HAVE_INET_ATON # ifdef HAVE_NETINET_IN_H # include <netinet/in.h> # endif # ifdef HAVE_ARPA_INET_H # include <arpa/inet.h> # endif # ifndef PHP_WIN32 extern int inet_aton(const char *, struct in_addr *); # endif #endif #endif /* FLOCK_COMPAT_H */
2,133
28.232877
75
h
php-src
php-src-master/ext/standard/fsock.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: Paul Panotzki - Bunyip Information Systems | | Jim Winstead <[email protected]> | | Wez Furlong | +----------------------------------------------------------------------+ */ #ifndef FSOCK_H #define FSOCK_H #include "file.h" #include "php_network.h" #endif /* FSOCK_H */
1,247
43.571429
75
h
php-src
php-src-master/ext/standard/ftok.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: Andrew Sitnikov <[email protected]> | +----------------------------------------------------------------------+ */ #include "php.h" #include <sys/types.h> #ifdef HAVE_SYS_IPC_H #include <sys/ipc.h> #endif #ifdef PHP_WIN32 #include "win32/ipc.h" #endif #ifdef HAVE_FTOK /* {{{ Convert a pathname and a project identifier to a System V IPC key */ PHP_FUNCTION(ftok) { char *pathname, *proj; size_t pathname_len, proj_len; key_t k; ZEND_PARSE_PARAMETERS_START(2, 2) Z_PARAM_PATH(pathname, pathname_len) Z_PARAM_STRING(proj, proj_len) ZEND_PARSE_PARAMETERS_END(); if (pathname_len == 0){ zend_argument_value_error(1, "cannot be empty"); RETURN_THROWS(); } if (proj_len != 1){ zend_argument_value_error(2, "must be a single character"); RETURN_THROWS(); } if (php_check_open_basedir(pathname)) { RETURN_LONG(-1); } k = ftok(pathname, proj[0]); if (k == -1) { php_error_docref(NULL, E_WARNING, "ftok() failed - %s", strerror(errno)); } RETURN_LONG(k); } /* }}} */ #endif
1,886
28.030769
75
c
php-src
php-src-master/ext/standard/head.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: Rasmus Lerdorf <[email protected]> | +----------------------------------------------------------------------+ */ #include <stdio.h> #include "php.h" #include "ext/standard/php_standard.h" #include "ext/date/php_date.h" #include "SAPI.h" #include "php_main.h" #include "head.h" #include <time.h> #include "php_globals.h" #include "zend_smart_str.h" /* Implementation of the language Header() function */ /* {{{ Sends a raw HTTP header */ PHP_FUNCTION(header) { bool rep = 1; sapi_header_line ctr = {0}; char *line; size_t len; ZEND_PARSE_PARAMETERS_START(1, 3) Z_PARAM_STRING(line, len) Z_PARAM_OPTIONAL Z_PARAM_BOOL(rep) Z_PARAM_LONG(ctr.response_code) ZEND_PARSE_PARAMETERS_END(); ctr.line = line; ctr.line_len = (uint32_t)len; sapi_header_op(rep ? SAPI_HEADER_REPLACE:SAPI_HEADER_ADD, &ctr); } /* }}} */ /* {{{ Removes an HTTP header previously set using header() */ PHP_FUNCTION(header_remove) { sapi_header_line ctr = {0}; char *line = NULL; size_t len = 0; ZEND_PARSE_PARAMETERS_START(0, 1) Z_PARAM_OPTIONAL Z_PARAM_STRING_OR_NULL(line, len) ZEND_PARSE_PARAMETERS_END(); ctr.line = line; ctr.line_len = (uint32_t)len; sapi_header_op(line == NULL ? SAPI_HEADER_DELETE_ALL : SAPI_HEADER_DELETE, &ctr); } /* }}} */ PHPAPI int php_header(void) { if (sapi_send_headers()==FAILURE || SG(request_info).headers_only) { return 0; /* don't allow output */ } else { return 1; /* allow output */ } } #define ILLEGAL_COOKIE_CHARACTER "\",\", \";\", \" \", \"\\t\", \"\\r\", \"\\n\", \"\\013\", or \"\\014\"" PHPAPI zend_result php_setcookie(zend_string *name, zend_string *value, time_t expires, zend_string *path, zend_string *domain, bool secure, bool httponly, zend_string *samesite, bool url_encode) { zend_string *dt; sapi_header_line ctr = {0}; zend_result result; smart_str buf = {0}; if (!ZSTR_LEN(name)) { zend_argument_value_error(1, "cannot be empty"); return FAILURE; } if (strpbrk(ZSTR_VAL(name), "=,; \t\r\n\013\014") != NULL) { /* man isspace for \013 and \014 */ zend_argument_value_error(1, "cannot contain \"=\", " ILLEGAL_COOKIE_CHARACTER); return FAILURE; } if (!url_encode && value && strpbrk(ZSTR_VAL(value), ",; \t\r\n\013\014") != NULL) { /* man isspace for \013 and \014 */ zend_argument_value_error(2, "cannot contain " ILLEGAL_COOKIE_CHARACTER); return FAILURE; } if (path && strpbrk(ZSTR_VAL(path), ",; \t\r\n\013\014") != NULL) { /* man isspace for \013 and \014 */ zend_value_error("%s(): \"path\" option cannot contain " ILLEGAL_COOKIE_CHARACTER, get_active_function_name()); return FAILURE; } if (domain && strpbrk(ZSTR_VAL(domain), ",; \t\r\n\013\014") != NULL) { /* man isspace for \013 and \014 */ zend_value_error("%s(): \"domain\" option cannot contain " ILLEGAL_COOKIE_CHARACTER, get_active_function_name()); return FAILURE; } #ifdef ZEND_ENABLE_ZVAL_LONG64 if (expires >= 253402300800) { zend_value_error("%s(): \"expires\" option cannot have a year greater than 9999", get_active_function_name()); return FAILURE; } #endif /* Should check value of SameSite? */ if (value == NULL || ZSTR_LEN(value) == 0) { /* * MSIE doesn't delete a cookie when you set it to a null value * so in order to force cookies to be deleted, even on MSIE, we * pick an expiry date in the past */ dt = php_format_date("D, d M Y H:i:s \\G\\M\\T", sizeof("D, d M Y H:i:s \\G\\M\\T")-1, 1, 0); smart_str_appends(&buf, "Set-Cookie: "); smart_str_append(&buf, name); smart_str_appends(&buf, "=deleted; expires="); smart_str_append(&buf, dt); smart_str_appends(&buf, "; Max-Age=0"); zend_string_free(dt); } else { smart_str_appends(&buf, "Set-Cookie: "); smart_str_append(&buf, name); smart_str_appendc(&buf, '='); if (url_encode) { zend_string *encoded_value = php_raw_url_encode(ZSTR_VAL(value), ZSTR_LEN(value)); smart_str_append(&buf, encoded_value); zend_string_release_ex(encoded_value, 0); } else { smart_str_append(&buf, value); } if (expires > 0) { double diff; smart_str_appends(&buf, COOKIE_EXPIRES); dt = php_format_date("D, d M Y H:i:s \\G\\M\\T", sizeof("D, d M Y H:i:s \\G\\M\\T")-1, expires, 0); smart_str_append(&buf, dt); zend_string_free(dt); diff = difftime(expires, php_time()); if (diff < 0) { diff = 0; } smart_str_appends(&buf, COOKIE_MAX_AGE); smart_str_append_long(&buf, (zend_long) diff); } } if (path && ZSTR_LEN(path)) { smart_str_appends(&buf, COOKIE_PATH); smart_str_append(&buf, path); } if (domain && ZSTR_LEN(domain)) { smart_str_appends(&buf, COOKIE_DOMAIN); smart_str_append(&buf, domain); } if (secure) { smart_str_appends(&buf, COOKIE_SECURE); } if (httponly) { smart_str_appends(&buf, COOKIE_HTTPONLY); } if (samesite && ZSTR_LEN(samesite)) { smart_str_appends(&buf, COOKIE_SAMESITE); smart_str_append(&buf, samesite); } ctr.line = ZSTR_VAL(buf.s); ctr.line_len = (uint32_t) ZSTR_LEN(buf.s); result = sapi_header_op(SAPI_HEADER_ADD, &ctr); zend_string_release(buf.s); return result; } static zend_result php_head_parse_cookie_options_array(HashTable *options, zend_long *expires, zend_string **path, zend_string **domain, bool *secure, bool *httponly, zend_string **samesite) { zend_string *key; zval *value; ZEND_HASH_FOREACH_STR_KEY_VAL(options, key, value) { if (!key) { zend_value_error("%s(): option array cannot have numeric keys", get_active_function_name()); return FAILURE; } if (zend_string_equals_literal_ci(key, "expires")) { *expires = zval_get_long(value); } else if (zend_string_equals_literal_ci(key, "path")) { *path = zval_get_string(value); } else if (zend_string_equals_literal_ci(key, "domain")) { *domain = zval_get_string(value); } else if (zend_string_equals_literal_ci(key, "secure")) { *secure = zval_is_true(value); } else if (zend_string_equals_literal_ci(key, "httponly")) { *httponly = zval_is_true(value); } else if (zend_string_equals_literal_ci(key, "samesite")) { *samesite = zval_get_string(value); } else { zend_value_error("%s(): option \"%s\" is invalid", get_active_function_name(), ZSTR_VAL(key)); return FAILURE; } } ZEND_HASH_FOREACH_END(); return SUCCESS; } static void php_setcookie_common(INTERNAL_FUNCTION_PARAMETERS, bool is_raw) { HashTable *options = NULL; zend_long expires = 0; zend_string *name, *value = NULL, *path = NULL, *domain = NULL, *samesite = NULL; bool secure = 0, httponly = 0; ZEND_PARSE_PARAMETERS_START(1, 7) Z_PARAM_STR(name) Z_PARAM_OPTIONAL Z_PARAM_STR(value) Z_PARAM_ARRAY_HT_OR_LONG(options, expires) Z_PARAM_STR(path) Z_PARAM_STR(domain) Z_PARAM_BOOL(secure) Z_PARAM_BOOL(httponly) ZEND_PARSE_PARAMETERS_END(); if (options) { if (UNEXPECTED(ZEND_NUM_ARGS() > 3)) { zend_argument_count_error("%s(): Expects exactly 3 arguments when argument #3 " "($expires_or_options) is an array", get_active_function_name()); RETURN_THROWS(); } if (FAILURE == php_head_parse_cookie_options_array(options, &expires, &path, &domain, &secure, &httponly, &samesite) ) { goto cleanup; } } if (php_setcookie(name, value, expires, path, domain, secure, httponly, samesite, !is_raw) == SUCCESS) { RETVAL_TRUE; } else { RETVAL_FALSE; } if (options) { cleanup: if (path) { zend_string_release(path); } if (domain) { zend_string_release(domain); } if (samesite) { zend_string_release(samesite); } } } /* {{{ setcookie(string name [, string value [, array options]]) Send a cookie */ PHP_FUNCTION(setcookie) { php_setcookie_common(INTERNAL_FUNCTION_PARAM_PASSTHRU, false); } /* }}} */ /* {{{ setrawcookie(string name [, string value [, array options]]) Send a cookie with no url encoding of the value */ PHP_FUNCTION(setrawcookie) { php_setcookie_common(INTERNAL_FUNCTION_PARAM_PASSTHRU, true); } /* }}} */ /* {{{ Returns true if headers have already been sent, false otherwise */ PHP_FUNCTION(headers_sent) { zval *arg1 = NULL, *arg2 = NULL; const char *file=""; int line=0; ZEND_PARSE_PARAMETERS_START(0, 2) Z_PARAM_OPTIONAL Z_PARAM_ZVAL(arg1) Z_PARAM_ZVAL(arg2) ZEND_PARSE_PARAMETERS_END(); if (SG(headers_sent)) { line = php_output_get_start_lineno(); file = php_output_get_start_filename(); } switch(ZEND_NUM_ARGS()) { case 2: ZEND_TRY_ASSIGN_REF_LONG(arg2, line); ZEND_FALLTHROUGH; case 1: if (file) { ZEND_TRY_ASSIGN_REF_STRING(arg1, file); } else { ZEND_TRY_ASSIGN_REF_EMPTY_STRING(arg1); } break; } if (SG(headers_sent)) { RETURN_TRUE; } else { RETURN_FALSE; } } /* }}} */ /* {{{ php_head_apply_header_list_to_hash Turn an llist of sapi_header_struct headers into a numerically indexed zval hash */ static void php_head_apply_header_list_to_hash(void *data, void *arg) { sapi_header_struct *sapi_header = (sapi_header_struct *)data; if (arg && sapi_header) { add_next_index_string((zval *)arg, (char *)(sapi_header->header)); } } /* {{{ Return list of headers to be sent / already sent */ PHP_FUNCTION(headers_list) { ZEND_PARSE_PARAMETERS_NONE(); array_init(return_value); zend_llist_apply_with_argument(&SG(sapi_headers).headers, php_head_apply_header_list_to_hash, return_value); } /* }}} */ /* {{{ Sets a response code, or returns the current HTTP response code */ PHP_FUNCTION(http_response_code) { zend_long response_code = 0; ZEND_PARSE_PARAMETERS_START(0, 1) Z_PARAM_OPTIONAL Z_PARAM_LONG(response_code) ZEND_PARSE_PARAMETERS_END(); if (response_code) { if (SG(headers_sent) && !SG(request_info).no_headers) { const char *output_start_filename = php_output_get_start_filename(); int output_start_lineno = php_output_get_start_lineno(); if (output_start_filename) { php_error_docref(NULL, E_WARNING, "Cannot set response code - headers already sent " "(output started at %s:%d)", output_start_filename, output_start_lineno); } else { php_error_docref(NULL, E_WARNING, "Cannot set response code - headers already sent"); } RETURN_FALSE; } zend_long old_response_code; old_response_code = SG(sapi_headers).http_response_code; SG(sapi_headers).http_response_code = (int)response_code; if (old_response_code) { RETURN_LONG(old_response_code); } RETURN_TRUE; } if (!SG(sapi_headers).http_response_code) { RETURN_FALSE; } RETURN_LONG(SG(sapi_headers).http_response_code); } /* }}} */
11,298
27.460957
114
c
php-src
php-src-master/ext/standard/head.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: Rasmus Lerdorf <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef HEAD_H #define HEAD_H #define COOKIE_EXPIRES "; expires=" #define COOKIE_MAX_AGE "; Max-Age=" #define COOKIE_DOMAIN "; domain=" #define COOKIE_PATH "; path=" #define COOKIE_SECURE "; secure" #define COOKIE_HTTPONLY "; HttpOnly" #define COOKIE_SAMESITE "; SameSite=" extern PHP_RINIT_FUNCTION(head); PHPAPI int php_header(void); PHPAPI zend_result php_setcookie(zend_string *name, zend_string *value, time_t expires, zend_string *path, zend_string *domain, bool secure, bool httponly, zend_string *samesite, bool url_encode); #endif
1,565
42.5
87
h
php-src
php-src-master/ext/standard/hrtime.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: Niklas Keller <[email protected]> | | Author: Anatol Belski <[email protected]> | +----------------------------------------------------------------------+ */ #include "php.h" #include "zend_hrtime.h" #ifdef ZEND_ENABLE_ZVAL_LONG64 #define PHP_RETURN_HRTIME(t) RETURN_LONG((zend_long)t) #else #ifdef _WIN32 # define HRTIME_U64A(i, s, len) _ui64toa_s(i, s, len, 10) #else # define HRTIME_U64A(i, s, len) \ do { \ int st = snprintf(s, len, "%llu", i); \ s[st] = '\0'; \ } while (0) #endif #define PHP_RETURN_HRTIME(t) do { \ char _a[ZEND_LTOA_BUF_LEN]; \ double _d; \ HRTIME_U64A(t, _a, ZEND_LTOA_BUF_LEN); \ _d = zend_strtod(_a, NULL); \ RETURN_DOUBLE(_d); \ } while (0) #endif /* {{{ Returns an array of integers in form [seconds, nanoseconds] counted from an arbitrary point in time. If an optional boolean argument is passed, returns an integer on 64-bit platforms or float on 32-bit containing the current high-resolution time in nanoseconds. The delivered timestamp is monotonic and cannot be adjusted. */ PHP_FUNCTION(hrtime) { #if ZEND_HRTIME_AVAILABLE bool get_as_num = 0; zend_hrtime_t t = zend_hrtime(); ZEND_PARSE_PARAMETERS_START(0, 1) Z_PARAM_OPTIONAL Z_PARAM_BOOL(get_as_num) ZEND_PARSE_PARAMETERS_END(); if (UNEXPECTED(get_as_num)) { PHP_RETURN_HRTIME(t); } else { array_init_size(return_value, 2); zend_hash_real_init_packed(Z_ARRVAL_P(return_value)); add_next_index_long(return_value, (zend_long)(t / (zend_hrtime_t)ZEND_NANO_IN_SEC)); add_next_index_long(return_value, (zend_long)(t % (zend_hrtime_t)ZEND_NANO_IN_SEC)); } #else RETURN_FALSE; #endif } /* }}} */
2,533
34.690141
86
c
php-src
php-src-master/ext/standard/incomplete_class.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: Sascha Schumann <[email protected]> | +----------------------------------------------------------------------+ */ #include "php.h" #include "basic_functions.h" #include "php_incomplete_class.h" #define INCOMPLETE_CLASS_MSG \ "The script tried to %s on an incomplete object. " \ "Please ensure that the class definition \"%s\" of the object " \ "you are trying to operate on was loaded _before_ " \ "unserialize() gets called or provide an autoloader " \ "to load the class definition" PHPAPI zend_class_entry *php_ce_incomplete_class; static zend_object_handlers php_incomplete_object_handlers; static void incomplete_class_message(zend_object *object) { zend_string *class_name = php_lookup_class_name(object); php_error_docref(NULL, E_WARNING, INCOMPLETE_CLASS_MSG, "access a property", class_name ? ZSTR_VAL(class_name) : "unknown"); if (class_name) { zend_string_release_ex(class_name, 0); } } static void throw_incomplete_class_error(zend_object *object, const char *what) { zend_string *class_name = php_lookup_class_name(object); zend_throw_error(NULL, INCOMPLETE_CLASS_MSG, what, class_name ? ZSTR_VAL(class_name) : "unknown"); if (class_name) { zend_string_release_ex(class_name, 0); } } static zval *incomplete_class_get_property(zend_object *object, zend_string *member, int type, void **cache_slot, zval *rv) /* {{{ */ { incomplete_class_message(object); if (type == BP_VAR_W || type == BP_VAR_RW) { ZVAL_ERROR(rv); return rv; } else { return &EG(uninitialized_zval); } } /* }}} */ static zval *incomplete_class_write_property(zend_object *object, zend_string *member, zval *value, void **cache_slot) /* {{{ */ { throw_incomplete_class_error(object, "modify a property"); return value; } /* }}} */ static zval *incomplete_class_get_property_ptr_ptr(zend_object *object, zend_string *member, int type, void **cache_slot) /* {{{ */ { throw_incomplete_class_error(object, "modify a property"); return &EG(error_zval); } /* }}} */ static void incomplete_class_unset_property(zend_object *object, zend_string *member, void **cache_slot) /* {{{ */ { throw_incomplete_class_error(object, "modify a property"); } /* }}} */ static int incomplete_class_has_property(zend_object *object, zend_string *member, int check_empty, void **cache_slot) /* {{{ */ { incomplete_class_message(object); return 0; } /* }}} */ static zend_function *incomplete_class_get_method(zend_object **object, zend_string *method, const zval *key) /* {{{ */ { throw_incomplete_class_error(*object, "call a method"); return NULL; } /* }}} */ /* {{{ php_create_incomplete_class */ static zend_object *php_create_incomplete_object(zend_class_entry *class_type) { zend_object *object; object = zend_objects_new( class_type); object->handlers = &php_incomplete_object_handlers; object_properties_init(object, class_type); return object; } PHPAPI void php_register_incomplete_class_handlers(void) { memcpy(&php_incomplete_object_handlers, &std_object_handlers, sizeof(zend_object_handlers)); php_incomplete_object_handlers.read_property = incomplete_class_get_property; php_incomplete_object_handlers.has_property = incomplete_class_has_property; php_incomplete_object_handlers.unset_property = incomplete_class_unset_property; php_incomplete_object_handlers.write_property = incomplete_class_write_property; php_incomplete_object_handlers.get_property_ptr_ptr = incomplete_class_get_property_ptr_ptr; php_incomplete_object_handlers.get_method = incomplete_class_get_method; php_ce_incomplete_class->create_object = php_create_incomplete_object; } /* }}} */ /* {{{ php_lookup_class_name */ PHPAPI zend_string *php_lookup_class_name(zend_object *object) { if (object->properties) { zval *val = zend_hash_str_find(object->properties, MAGIC_MEMBER, sizeof(MAGIC_MEMBER)-1); if (val != NULL && Z_TYPE_P(val) == IS_STRING) { return zend_string_copy(Z_STR_P(val)); } } return NULL; } /* }}} */ /* {{{ php_store_class_name */ PHPAPI void php_store_class_name(zval *object, zend_string *name) { zval val; ZVAL_STR_COPY(&val, name); zend_hash_str_update(Z_OBJPROP_P(object), MAGIC_MEMBER, sizeof(MAGIC_MEMBER)-1, &val); } /* }}} */
5,069
33.026846
133
c
php-src
php-src-master/ext/standard/iptc.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: Thies C. Arntzen <[email protected]> | +----------------------------------------------------------------------+ */ /* * Functions to parse & compse IPTC data. * PhotoShop >= 3.0 can read and write textual data to JPEG files. * ... more to come ..... * * i know, parts of this is now duplicated in image.c * but in this case i think it's okay! */ /* * TODO: * - add IPTC translation table */ #include "php.h" #include "ext/standard/head.h" #include <sys/stat.h> #include <stdint.h> #ifndef PHP_WIN32 # include <inttypes.h> #endif /* some defines for the different JPEG block types */ #define M_SOF0 0xC0 /* Start Of Frame N */ #define M_SOF1 0xC1 /* N indicates which compression process */ #define M_SOF2 0xC2 /* Only SOF0-SOF2 are now in common use */ #define M_SOF3 0xC3 #define M_SOF5 0xC5 /* NB: codes C4 and CC are NOT SOF markers */ #define M_SOF6 0xC6 #define M_SOF7 0xC7 #define M_SOF9 0xC9 #define M_SOF10 0xCA #define M_SOF11 0xCB #define M_SOF13 0xCD #define M_SOF14 0xCE #define M_SOF15 0xCF #define M_SOI 0xD8 #define M_EOI 0xD9 /* End Of Image (end of datastream) */ #define M_SOS 0xDA /* Start Of Scan (begins compressed data) */ #define M_APP0 0xe0 #define M_APP1 0xe1 #define M_APP2 0xe2 #define M_APP3 0xe3 #define M_APP4 0xe4 #define M_APP5 0xe5 #define M_APP6 0xe6 #define M_APP7 0xe7 #define M_APP8 0xe8 #define M_APP9 0xe9 #define M_APP10 0xea #define M_APP11 0xeb #define M_APP12 0xec #define M_APP13 0xed #define M_APP14 0xee #define M_APP15 0xef /* {{{ php_iptc_put1 */ static int php_iptc_put1(FILE *fp, int spool, unsigned char c, unsigned char **spoolbuf) { if (spool > 0) PUTC(c); if (spoolbuf) *(*spoolbuf)++ = c; return c; } /* }}} */ /* {{{ php_iptc_get1 */ static int php_iptc_get1(FILE *fp, int spool, unsigned char **spoolbuf) { int c; char cc; c = getc(fp); if (c == EOF) return EOF; if (spool > 0) { cc = c; PUTC(cc); } if (spoolbuf) *(*spoolbuf)++ = c; return c; } /* }}} */ /* {{{ php_iptc_read_remaining */ static int php_iptc_read_remaining(FILE *fp, int spool, unsigned char **spoolbuf) { while (php_iptc_get1(fp, spool, spoolbuf) != EOF) continue; return M_EOI; } /* }}} */ /* {{{ php_iptc_skip_variable */ static int php_iptc_skip_variable(FILE *fp, int spool, unsigned char **spoolbuf) { unsigned int length; int c1, c2; if ((c1 = php_iptc_get1(fp, spool, spoolbuf)) == EOF) return M_EOI; if ((c2 = php_iptc_get1(fp, spool, spoolbuf)) == EOF) return M_EOI; length = (((unsigned char) c1) << 8) + ((unsigned char) c2); length -= 2; while (length--) if (php_iptc_get1(fp, spool, spoolbuf) == EOF) return M_EOI; return 0; } /* }}} */ /* {{{ php_iptc_next_marker */ static int php_iptc_next_marker(FILE *fp, int spool, unsigned char **spoolbuf) { int c; /* skip unimportant stuff */ c = php_iptc_get1(fp, spool, spoolbuf); if (c == EOF) return M_EOI; while (c != 0xff) { if ((c = php_iptc_get1(fp, spool, spoolbuf)) == EOF) return M_EOI; /* we hit EOF */ } /* get marker byte, swallowing possible padding */ do { c = php_iptc_get1(fp, 0, 0); if (c == EOF) return M_EOI; /* we hit EOF */ else if (c == 0xff) php_iptc_put1(fp, spool, (unsigned char)c, spoolbuf); } while (c == 0xff); return (unsigned int) c; } /* }}} */ static char psheader[] = "\xFF\xED\0\0Photoshop 3.0\08BIM\x04\x04\0\0\0\0"; /* {{{ Embed binary IPTC data into a JPEG image. */ PHP_FUNCTION(iptcembed) { char *iptcdata, *jpeg_file; size_t iptcdata_len, jpeg_file_len; zend_long spool = 0; FILE *fp; unsigned int marker, done = 0; size_t inx; zend_string *spoolbuf = NULL; unsigned char *poi = NULL; zend_stat_t sb = {0}; bool written = 0; ZEND_PARSE_PARAMETERS_START(2, 3) Z_PARAM_STRING(iptcdata, iptcdata_len) Z_PARAM_PATH(jpeg_file, jpeg_file_len) Z_PARAM_OPTIONAL Z_PARAM_LONG(spool) ZEND_PARSE_PARAMETERS_END(); if (php_check_open_basedir(jpeg_file)) { RETURN_FALSE; } if (iptcdata_len >= SIZE_MAX - sizeof(psheader) - 1025) { zend_argument_value_error(1, "is too large"); RETURN_THROWS(); } if ((fp = VCWD_FOPEN(jpeg_file, "rb")) == 0) { php_error_docref(NULL, E_WARNING, "Unable to open %s", jpeg_file); RETURN_FALSE; } if (spool < 2) { if (zend_fstat(fileno(fp), &sb) != 0) { RETURN_FALSE; } spoolbuf = zend_string_safe_alloc(1, iptcdata_len + sizeof(psheader) + 1024 + 1, sb.st_size, 0); poi = (unsigned char*)ZSTR_VAL(spoolbuf); memset(poi, 0, iptcdata_len + sizeof(psheader) + sb.st_size + 1024 + 1); } if (php_iptc_get1(fp, spool, poi?&poi:0) != 0xFF) { fclose(fp); if (spoolbuf) { zend_string_efree(spoolbuf); } RETURN_FALSE; } if (php_iptc_get1(fp, spool, poi?&poi:0) != 0xD8) { fclose(fp); if (spoolbuf) { zend_string_efree(spoolbuf); } RETURN_FALSE; } while (!done) { marker = php_iptc_next_marker(fp, spool, poi?&poi:0); if (marker == M_EOI) { /* EOF */ break; } else if (marker != M_APP13) { php_iptc_put1(fp, spool, (unsigned char)marker, poi?&poi:0); } switch (marker) { case M_APP13: /* we are going to write a new APP13 marker, so don't output the old one */ php_iptc_skip_variable(fp, 0, 0); fgetc(fp); /* skip already copied 0xFF byte */ php_iptc_read_remaining(fp, spool, poi?&poi:0); done = 1; break; case M_APP0: /* APP0 is in each and every JPEG, so when we hit APP0 we insert our new APP13! */ case M_APP1: if (written) { /* don't try to write the data twice */ break; } written = 1; php_iptc_skip_variable(fp, spool, poi?&poi:0); if (iptcdata_len & 1) { iptcdata_len++; /* make the length even */ } psheader[ 2 ] = (char) ((iptcdata_len+28)>>8); psheader[ 3 ] = (iptcdata_len+28)&0xff; for (inx = 0; inx < 28; inx++) { php_iptc_put1(fp, spool, psheader[inx], poi?&poi:0); } php_iptc_put1(fp, spool, (unsigned char)(iptcdata_len>>8), poi?&poi:0); php_iptc_put1(fp, spool, (unsigned char)(iptcdata_len&0xff), poi?&poi:0); for (inx = 0; inx < iptcdata_len; inx++) { php_iptc_put1(fp, spool, iptcdata[inx], poi?&poi:0); } break; case M_SOS: /* we hit data, no more marker-inserting can be done! */ php_iptc_read_remaining(fp, spool, poi?&poi:0); done = 1; break; default: php_iptc_skip_variable(fp, spool, poi?&poi:0); break; } } fclose(fp); if (spool < 2) { spoolbuf = zend_string_truncate(spoolbuf, poi - (unsigned char*)ZSTR_VAL(spoolbuf), 0); RETURN_NEW_STR(spoolbuf); } else { RETURN_TRUE; } } /* }}} */ /* {{{ Parse binary IPTC-data into associative array */ PHP_FUNCTION(iptcparse) { size_t inx = 0, len; unsigned int tagsfound = 0; unsigned char *buffer, recnum, dataset; char *str, key[16]; size_t str_len; zval values, *element; ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_STRING(str, str_len) ZEND_PARSE_PARAMETERS_END(); buffer = (unsigned char *)str; while (inx < str_len) { /* find 1st tag */ if ((buffer[inx] == 0x1c) && ((buffer[inx+1] == 0x01) || (buffer[inx+1] == 0x02))){ break; } else { inx++; } } while (inx < str_len) { if (buffer[ inx++ ] != 0x1c) { break; /* we ran against some data which does not conform to IPTC - stop parsing! */ } if ((inx + 4) >= str_len) break; dataset = buffer[ inx++ ]; recnum = buffer[ inx++ ]; if (buffer[ inx ] & (unsigned char) 0x80) { /* long tag */ if((inx+6) >= str_len) { break; } len = (((zend_long) buffer[ inx + 2 ]) << 24) + (((zend_long) buffer[ inx + 3 ]) << 16) + (((zend_long) buffer[ inx + 4 ]) << 8) + (((zend_long) buffer[ inx + 5 ])); inx += 6; } else { /* short tag */ len = (((unsigned short) buffer[ inx ])<<8) | (unsigned short)buffer[ inx+1 ]; inx += 2; } if ((len > str_len) || (inx + len) > str_len) { break; } snprintf(key, sizeof(key), "%d#%03d", (unsigned int) dataset, (unsigned int) recnum); if (tagsfound == 0) { /* found the 1st tag - initialize the return array */ array_init(return_value); } if ((element = zend_hash_str_find(Z_ARRVAL_P(return_value), key, strlen(key))) == NULL) { array_init(&values); element = zend_hash_str_update(Z_ARRVAL_P(return_value), key, strlen(key), &values); } add_next_index_stringl(element, (char *) buffer+inx, len); inx += len; tagsfound++; } if (! tagsfound) { RETURN_FALSE; } } /* }}} */
9,334
23.893333
98
c
php-src
php-src-master/ext/standard/link.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: | +----------------------------------------------------------------------+ */ #include "php.h" #include "php_filestat.h" #include "php_globals.h" #if defined(HAVE_SYMLINK) || defined(PHP_WIN32) #ifdef PHP_WIN32 #include <WinBase.h> #endif #include <stdlib.h> #ifdef HAVE_UNISTD_H #include <unistd.h> #endif #ifndef PHP_WIN32 #include <sys/stat.h> #endif #include <string.h> #ifdef HAVE_PWD_H #ifdef PHP_WIN32 #include "win32/pwd.h" #else #include <pwd.h> #endif #endif #if HAVE_GRP_H # include <grp.h> #endif #include <errno.h> #include <ctype.h> #include "php_string.h" #ifndef VOLUME_NAME_NT #define VOLUME_NAME_NT 0x2 #endif #ifndef VOLUME_NAME_DOS #define VOLUME_NAME_DOS 0x0 #endif /* {{{ Return the target of a symbolic link */ PHP_FUNCTION(readlink) { char *link; size_t link_len; char buff[MAXPATHLEN]; ssize_t ret; ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_PATH(link, link_len) ZEND_PARSE_PARAMETERS_END(); if (php_check_open_basedir(link)) { RETURN_FALSE; } ret = php_sys_readlink(link, buff, MAXPATHLEN-1); if (ret == -1) { #ifdef PHP_WIN32 php_error_docref(NULL, E_WARNING, "readlink failed to read the symbolic link (%s), error %d", link, GetLastError()); #else php_error_docref(NULL, E_WARNING, "%s", strerror(errno)); #endif RETURN_FALSE; } /* Append NULL to the end of the string */ buff[ret] = '\0'; RETURN_STRINGL(buff, ret); } /* }}} */ /* {{{ Returns the st_dev field of the UNIX C stat structure describing the link */ PHP_FUNCTION(linkinfo) { char *link; char *dirname; size_t link_len; zend_stat_t sb = {0}; int ret; ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_PATH(link, link_len) ZEND_PARSE_PARAMETERS_END(); dirname = estrndup(link, link_len); php_dirname(dirname, link_len); if (php_check_open_basedir(dirname)) { efree(dirname); RETURN_FALSE; } ret = VCWD_LSTAT(link, &sb); if (ret == -1) { php_error_docref(NULL, E_WARNING, "%s", strerror(errno)); efree(dirname); RETURN_LONG(Z_L(-1)); } efree(dirname); RETURN_LONG((zend_long) sb.st_dev); } /* }}} */ /* {{{ Create a symbolic link */ PHP_FUNCTION(symlink) { char *topath, *frompath; size_t topath_len, frompath_len; int ret; char source_p[MAXPATHLEN]; char dest_p[MAXPATHLEN]; char dirname[MAXPATHLEN]; size_t len; ZEND_PARSE_PARAMETERS_START(2, 2) Z_PARAM_PATH(topath, topath_len) Z_PARAM_PATH(frompath, frompath_len) ZEND_PARSE_PARAMETERS_END(); if (!expand_filepath(frompath, source_p)) { php_error_docref(NULL, E_WARNING, "No such file or directory"); RETURN_FALSE; } memcpy(dirname, source_p, sizeof(source_p)); len = php_dirname(dirname, strlen(dirname)); if (!expand_filepath_ex(topath, dest_p, dirname, len)) { php_error_docref(NULL, E_WARNING, "No such file or directory"); RETURN_FALSE; } if (php_stream_locate_url_wrapper(source_p, NULL, STREAM_LOCATE_WRAPPERS_ONLY) || php_stream_locate_url_wrapper(dest_p, NULL, STREAM_LOCATE_WRAPPERS_ONLY) ) { php_error_docref(NULL, E_WARNING, "Unable to symlink to a URL"); RETURN_FALSE; } if (php_check_open_basedir(dest_p)) { RETURN_FALSE; } if (php_check_open_basedir(source_p)) { RETURN_FALSE; } /* For the source, an expanded path must be used (in ZTS an other thread could have changed the CWD). * For the target the exact string given by the user must be used, relative or not, existing or not. * The target is relative to the link itself, not to the CWD. */ ret = php_sys_symlink(topath, source_p); if (ret == -1) { php_error_docref(NULL, E_WARNING, "%s", strerror(errno)); RETURN_FALSE; } RETURN_TRUE; } /* }}} */ /* {{{ Create a hard link */ PHP_FUNCTION(link) { char *topath, *frompath; size_t topath_len, frompath_len; int ret; char source_p[MAXPATHLEN]; char dest_p[MAXPATHLEN]; ZEND_PARSE_PARAMETERS_START(2, 2) Z_PARAM_PATH(topath, topath_len) Z_PARAM_PATH(frompath, frompath_len) ZEND_PARSE_PARAMETERS_END(); if (!expand_filepath(frompath, source_p) || !expand_filepath(topath, dest_p)) { php_error_docref(NULL, E_WARNING, "No such file or directory"); RETURN_FALSE; } if (php_stream_locate_url_wrapper(source_p, NULL, STREAM_LOCATE_WRAPPERS_ONLY) || php_stream_locate_url_wrapper(dest_p, NULL, STREAM_LOCATE_WRAPPERS_ONLY) ) { php_error_docref(NULL, E_WARNING, "Unable to link to a URL"); RETURN_FALSE; } if (php_check_open_basedir(dest_p)) { RETURN_FALSE; } if (php_check_open_basedir(source_p)) { RETURN_FALSE; } #ifndef ZTS ret = php_sys_link(topath, frompath); #else ret = php_sys_link(dest_p, source_p); #endif if (ret == -1) { php_error_docref(NULL, E_WARNING, "%s", strerror(errno)); RETURN_FALSE; } RETURN_TRUE; } /* }}} */ #endif
5,591
23.207792
118
c
php-src
php-src-master/ext/standard/md5.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: Alexander Peslyak (Solar Designer) <solar at openwall.com> | | Lachlan Roche | | Alessandro Astarita <[email protected]> | +----------------------------------------------------------------------+ */ #include "php.h" #include "md5.h" PHPAPI void make_digest(char *md5str, const unsigned char *digest) /* {{{ */ { make_digest_ex(md5str, digest, 16); } /* }}} */ PHPAPI void make_digest_ex(char *md5str, const unsigned char *digest, int len) /* {{{ */ { static const char hexits[17] = "0123456789abcdef"; int i; for (i = 0; i < len; i++) { md5str[i * 2] = hexits[digest[i] >> 4]; md5str[(i * 2) + 1] = hexits[digest[i] & 0x0F]; } md5str[len * 2] = '\0'; } /* }}} */ /* {{{ Calculate the md5 hash of a string */ PHP_FUNCTION(md5) { zend_string *arg; bool raw_output = 0; PHP_MD5_CTX context; unsigned char digest[16]; ZEND_PARSE_PARAMETERS_START(1, 2) Z_PARAM_STR(arg) Z_PARAM_OPTIONAL Z_PARAM_BOOL(raw_output) ZEND_PARSE_PARAMETERS_END(); PHP_MD5Init(&context); PHP_MD5Update(&context, ZSTR_VAL(arg), ZSTR_LEN(arg)); PHP_MD5Final(digest, &context); if (raw_output) { RETURN_STRINGL((char *) digest, 16); } else { RETVAL_NEW_STR(zend_string_alloc(32, 0)); make_digest_ex(Z_STRVAL_P(return_value), digest, 16); } } /* }}} */ /* {{{ Calculate the md5 hash of given filename */ PHP_FUNCTION(md5_file) { char *arg; size_t arg_len; bool raw_output = 0; unsigned char buf[1024]; unsigned char digest[16]; PHP_MD5_CTX context; ssize_t n; php_stream *stream; ZEND_PARSE_PARAMETERS_START(1, 2) Z_PARAM_PATH(arg, arg_len) Z_PARAM_OPTIONAL Z_PARAM_BOOL(raw_output) ZEND_PARSE_PARAMETERS_END(); stream = php_stream_open_wrapper(arg, "rb", REPORT_ERRORS, NULL); if (!stream) { RETURN_FALSE; } PHP_MD5Init(&context); while ((n = php_stream_read(stream, (char*)buf, sizeof(buf))) > 0) { PHP_MD5Update(&context, buf, n); } /* XXX this probably can be improved with some number of retries */ if (!php_stream_eof(stream)) { php_stream_close(stream); PHP_MD5Final(digest, &context); RETURN_FALSE; } php_stream_close(stream); PHP_MD5Final(digest, &context); if (raw_output) { RETURN_STRINGL((char *) digest, 16); } else { RETVAL_NEW_STR(zend_string_alloc(32, 0)); make_digest_ex(Z_STRVAL_P(return_value), digest, 16); } } /* }}} */ /* * This is an OpenSSL-compatible implementation of the RSA Data Security, * Inc. MD5 Message-Digest Algorithm (RFC 1321). * * Written by Solar Designer <solar at openwall.com> in 2001, and placed * in the public domain. There's absolutely no warranty. * * This differs from Colin Plumb's older public domain implementation in * that no 32-bit integer data type is required, there's no compile-time * endianness configuration, and the function prototypes match OpenSSL's. * The primary goals are portability and ease of use. * * This implementation is meant to be fast, but not as fast as possible. * Some known optimizations are not included to reduce source code size * and avoid compile-time configuration. */ #include <string.h> /* * The basic MD5 functions. * * F and G are optimized compared to their RFC 1321 definitions for * architectures that lack an AND-NOT instruction, just like in Colin Plumb's * implementation. */ #define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z)))) #define G(x, y, z) ((y) ^ ((z) & ((x) ^ (y)))) #define H(x, y, z) ((x) ^ (y) ^ (z)) #define I(x, y, z) ((y) ^ ((x) | ~(z))) /* * The MD5 transformation for all four rounds. */ #define STEP(f, a, b, c, d, x, t, s) \ (a) += f((b), (c), (d)) + (x) + (t); \ (a) = (((a) << (s)) | (((a) & 0xffffffff) >> (32 - (s)))); \ (a) += (b); /* * SET reads 4 input bytes in little-endian byte order and stores them * in a properly aligned word in host byte order. * * The check for little-endian architectures that tolerate unaligned * memory accesses is just an optimization. Nothing will break if it * doesn't work. */ #if defined(__i386__) || defined(__x86_64__) || defined(__vax__) typedef ZEND_SET_ALIGNED(1, uint32_t unaligned_uint32_t); # define SET(n) \ (*(unaligned_uint32_t *)&ptr[(n) * 4]) # define GET(n) \ SET(n) #else # define SET(n) \ (ctx->block[(n)] = \ (uint32_t)ptr[(n) * 4] | \ ((uint32_t)ptr[(n) * 4 + 1] << 8) | \ ((uint32_t)ptr[(n) * 4 + 2] << 16) | \ ((uint32_t)ptr[(n) * 4 + 3] << 24)) # define GET(n) \ (ctx->block[(n)]) #endif /* * This processes one or more 64-byte data blocks, but does NOT update * the bit counters. There are no alignment requirements. */ static const void *body(PHP_MD5_CTX *ctx, const void *data, size_t size) { const unsigned char *ptr; uint32_t a, b, c, d; uint32_t saved_a, saved_b, saved_c, saved_d; ptr = data; a = ctx->a; b = ctx->b; c = ctx->c; d = ctx->d; do { saved_a = a; saved_b = b; saved_c = c; saved_d = d; /* Round 1 */ STEP(F, a, b, c, d, SET(0), 0xd76aa478, 7) STEP(F, d, a, b, c, SET(1), 0xe8c7b756, 12) STEP(F, c, d, a, b, SET(2), 0x242070db, 17) STEP(F, b, c, d, a, SET(3), 0xc1bdceee, 22) STEP(F, a, b, c, d, SET(4), 0xf57c0faf, 7) STEP(F, d, a, b, c, SET(5), 0x4787c62a, 12) STEP(F, c, d, a, b, SET(6), 0xa8304613, 17) STEP(F, b, c, d, a, SET(7), 0xfd469501, 22) STEP(F, a, b, c, d, SET(8), 0x698098d8, 7) STEP(F, d, a, b, c, SET(9), 0x8b44f7af, 12) STEP(F, c, d, a, b, SET(10), 0xffff5bb1, 17) STEP(F, b, c, d, a, SET(11), 0x895cd7be, 22) STEP(F, a, b, c, d, SET(12), 0x6b901122, 7) STEP(F, d, a, b, c, SET(13), 0xfd987193, 12) STEP(F, c, d, a, b, SET(14), 0xa679438e, 17) STEP(F, b, c, d, a, SET(15), 0x49b40821, 22) /* Round 2 */ STEP(G, a, b, c, d, GET(1), 0xf61e2562, 5) STEP(G, d, a, b, c, GET(6), 0xc040b340, 9) STEP(G, c, d, a, b, GET(11), 0x265e5a51, 14) STEP(G, b, c, d, a, GET(0), 0xe9b6c7aa, 20) STEP(G, a, b, c, d, GET(5), 0xd62f105d, 5) STEP(G, d, a, b, c, GET(10), 0x02441453, 9) STEP(G, c, d, a, b, GET(15), 0xd8a1e681, 14) STEP(G, b, c, d, a, GET(4), 0xe7d3fbc8, 20) STEP(G, a, b, c, d, GET(9), 0x21e1cde6, 5) STEP(G, d, a, b, c, GET(14), 0xc33707d6, 9) STEP(G, c, d, a, b, GET(3), 0xf4d50d87, 14) STEP(G, b, c, d, a, GET(8), 0x455a14ed, 20) STEP(G, a, b, c, d, GET(13), 0xa9e3e905, 5) STEP(G, d, a, b, c, GET(2), 0xfcefa3f8, 9) STEP(G, c, d, a, b, GET(7), 0x676f02d9, 14) STEP(G, b, c, d, a, GET(12), 0x8d2a4c8a, 20) /* Round 3 */ STEP(H, a, b, c, d, GET(5), 0xfffa3942, 4) STEP(H, d, a, b, c, GET(8), 0x8771f681, 11) STEP(H, c, d, a, b, GET(11), 0x6d9d6122, 16) STEP(H, b, c, d, a, GET(14), 0xfde5380c, 23) STEP(H, a, b, c, d, GET(1), 0xa4beea44, 4) STEP(H, d, a, b, c, GET(4), 0x4bdecfa9, 11) STEP(H, c, d, a, b, GET(7), 0xf6bb4b60, 16) STEP(H, b, c, d, a, GET(10), 0xbebfbc70, 23) STEP(H, a, b, c, d, GET(13), 0x289b7ec6, 4) STEP(H, d, a, b, c, GET(0), 0xeaa127fa, 11) STEP(H, c, d, a, b, GET(3), 0xd4ef3085, 16) STEP(H, b, c, d, a, GET(6), 0x04881d05, 23) STEP(H, a, b, c, d, GET(9), 0xd9d4d039, 4) STEP(H, d, a, b, c, GET(12), 0xe6db99e5, 11) STEP(H, c, d, a, b, GET(15), 0x1fa27cf8, 16) STEP(H, b, c, d, a, GET(2), 0xc4ac5665, 23) /* Round 4 */ STEP(I, a, b, c, d, GET(0), 0xf4292244, 6) STEP(I, d, a, b, c, GET(7), 0x432aff97, 10) STEP(I, c, d, a, b, GET(14), 0xab9423a7, 15) STEP(I, b, c, d, a, GET(5), 0xfc93a039, 21) STEP(I, a, b, c, d, GET(12), 0x655b59c3, 6) STEP(I, d, a, b, c, GET(3), 0x8f0ccc92, 10) STEP(I, c, d, a, b, GET(10), 0xffeff47d, 15) STEP(I, b, c, d, a, GET(1), 0x85845dd1, 21) STEP(I, a, b, c, d, GET(8), 0x6fa87e4f, 6) STEP(I, d, a, b, c, GET(15), 0xfe2ce6e0, 10) STEP(I, c, d, a, b, GET(6), 0xa3014314, 15) STEP(I, b, c, d, a, GET(13), 0x4e0811a1, 21) STEP(I, a, b, c, d, GET(4), 0xf7537e82, 6) STEP(I, d, a, b, c, GET(11), 0xbd3af235, 10) STEP(I, c, d, a, b, GET(2), 0x2ad7d2bb, 15) STEP(I, b, c, d, a, GET(9), 0xeb86d391, 21) a += saved_a; b += saved_b; c += saved_c; d += saved_d; ptr += 64; } while (size -= 64); ctx->a = a; ctx->b = b; ctx->c = c; ctx->d = d; return ptr; } PHPAPI void PHP_MD5InitArgs(PHP_MD5_CTX *ctx, ZEND_ATTRIBUTE_UNUSED HashTable *args) { ctx->a = 0x67452301; ctx->b = 0xefcdab89; ctx->c = 0x98badcfe; ctx->d = 0x10325476; ctx->lo = 0; ctx->hi = 0; } PHPAPI void PHP_MD5Update(PHP_MD5_CTX *ctx, const void *data, size_t size) { uint32_t saved_lo; uint32_t used, free; saved_lo = ctx->lo; if ((ctx->lo = (saved_lo + size) & 0x1fffffff) < saved_lo) { ctx->hi++; } ctx->hi += size >> 29; used = saved_lo & 0x3f; if (used) { free = 64 - used; if (size < free) { memcpy(&ctx->buffer[used], data, size); return; } memcpy(&ctx->buffer[used], data, free); data = (unsigned char *)data + free; size -= free; body(ctx, ctx->buffer, 64); } if (size >= 64) { data = body(ctx, data, size & ~(size_t)0x3f); size &= 0x3f; } memcpy(ctx->buffer, data, size); } PHPAPI void PHP_MD5Final(unsigned char *result, PHP_MD5_CTX *ctx) { uint32_t used, free; used = ctx->lo & 0x3f; ctx->buffer[used++] = 0x80; free = 64 - used; if (free < 8) { memset(&ctx->buffer[used], 0, free); body(ctx, ctx->buffer, 64); used = 0; free = 64; } memset(&ctx->buffer[used], 0, free - 8); ctx->lo <<= 3; ctx->buffer[56] = ctx->lo; ctx->buffer[57] = ctx->lo >> 8; ctx->buffer[58] = ctx->lo >> 16; ctx->buffer[59] = ctx->lo >> 24; ctx->buffer[60] = ctx->hi; ctx->buffer[61] = ctx->hi >> 8; ctx->buffer[62] = ctx->hi >> 16; ctx->buffer[63] = ctx->hi >> 24; body(ctx, ctx->buffer, 64); result[0] = ctx->a; result[1] = ctx->a >> 8; result[2] = ctx->a >> 16; result[3] = ctx->a >> 24; result[4] = ctx->b; result[5] = ctx->b >> 8; result[6] = ctx->b >> 16; result[7] = ctx->b >> 24; result[8] = ctx->c; result[9] = ctx->c >> 8; result[10] = ctx->c >> 16; result[11] = ctx->c >> 24; result[12] = ctx->d; result[13] = ctx->d >> 8; result[14] = ctx->d >> 16; result[15] = ctx->d >> 24; ZEND_SECURE_ZERO(ctx, sizeof(*ctx)); }
10,911
27.051414
88
c
php-src
php-src-master/ext/standard/md5.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: Alexander Peslyak (Solar Designer) <solar at openwall.com> | | Rasmus Lerdorf <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef MD5_H #define MD5_H PHPAPI void make_digest(char *md5str, const unsigned char *digest); PHPAPI void make_digest_ex(char *md5str, const unsigned char *digest, int len); #include "ext/standard/basic_functions.h" /* * This is an OpenSSL-compatible implementation of the RSA Data Security, * Inc. MD5 Message-Digest Algorithm (RFC 1321). * * Written by Solar Designer <solar at openwall.com> in 2001, and placed * in the public domain. There's absolutely no warranty. * * See md5.c for more information. */ /* MD5 context. */ typedef struct { uint32_t lo, hi; uint32_t a, b, c, d; unsigned char buffer[64]; uint32_t block[16]; } PHP_MD5_CTX; #define PHP_MD5_SPEC "llllllb64l16." #define PHP_MD5Init(ctx) PHP_MD5InitArgs(ctx, NULL) PHPAPI void PHP_MD5InitArgs(PHP_MD5_CTX *context, ZEND_ATTRIBUTE_UNUSED HashTable *args); PHPAPI void PHP_MD5Update(PHP_MD5_CTX *ctx, const void *data, size_t size); PHPAPI void PHP_MD5Final(unsigned char *result, PHP_MD5_CTX *ctx); #endif
2,065
39.509804
89
h
php-src
php-src-master/ext/standard/metaphone.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: Thies C. Arntzen <[email protected]> | +----------------------------------------------------------------------+ */ /* Based on CPANs "Text-Metaphone-1.96" by Michael G Schwern <[email protected]> */ #include "php.h" static void metaphone(unsigned char *word, size_t word_len, zend_long max_phonemes, zend_string **phoned_word, int traditional); /* {{{ Break english phrases down into their phonemes */ PHP_FUNCTION(metaphone) { zend_string *str; zend_string *result = NULL; zend_long phones = 0; ZEND_PARSE_PARAMETERS_START(1, 2) Z_PARAM_STR(str) Z_PARAM_OPTIONAL Z_PARAM_LONG(phones) ZEND_PARSE_PARAMETERS_END(); if (phones < 0) { zend_argument_value_error(2, "must be greater than or equal to 0"); RETURN_THROWS(); } metaphone((unsigned char *)ZSTR_VAL(str), ZSTR_LEN(str), phones, &result, 1); RETVAL_STR(result); } /* }}} */ /* this is now the original code by Michael G Schwern: i've changed it just a slightly bit (use emalloc, get rid of includes etc) - thies - 13.09.1999 */ /*----------------------------- */ /* this used to be "metaphone.h" */ /*----------------------------- */ /* Special encodings */ #define SH 'X' #define TH '0' /*----------------------------- */ /* end of "metaphone.h" */ /*----------------------------- */ /*----------------------------- */ /* this used to be "metachar.h" */ /*----------------------------- */ /* Metachar.h ... little bits about characters for metaphone */ /*-- Character encoding array & accessing macros --*/ /* Stolen directly out of the book... */ static const char _codes[26] = { 1, 16, 4, 16, 9, 2, 4, 16, 9, 2, 0, 2, 2, 2, 1, 4, 0, 2, 4, 4, 1, 0, 0, 0, 8, 0 /* a b c d e f g h i j k l m n o p q r s t u v w x y z */ }; /* Note: these functions require an uppercase letter input! */ static zend_always_inline char encode(char c) { if (isalpha(c)) { ZEND_ASSERT(c >= 'A' && c <= 'Z'); return _codes[(c - 'A')]; } else { return 0; } } #define isvowel(c) (encode(c) & 1) /* AEIOU */ /* These letters are passed through unchanged */ #define NOCHANGE(c) (encode(c) & 2) /* FJMNR */ /* These form diphthongs when preceding H */ #define AFFECTH(c) (encode(c) & 4) /* CGPST */ /* These make C and G soft */ #define MAKESOFT(c) (encode(c) & 8) /* EIY */ /* These prevent GH from becoming F */ #define NOGHTOF(c) (encode(c) & 16) /* BDH */ /*----------------------------- */ /* end of "metachar.h" */ /*----------------------------- */ /* I suppose I could have been using a character pointer instead of * accesssing the array directly... */ #define Convert_Raw(c) toupper(c) /* Look at the next letter in the word */ #define Read_Raw_Next_Letter (word[w_idx+1]) #define Read_Next_Letter (Convert_Raw(Read_Raw_Next_Letter)) /* Look at the current letter in the word */ #define Read_Raw_Curr_Letter (word[w_idx]) #define Read_Curr_Letter (Convert_Raw(Read_Raw_Curr_Letter)) /* Go N letters back. */ #define Look_Back_Letter(n) (w_idx >= n ? Convert_Raw(word[w_idx-n]) : '\0') /* Previous letter. I dunno, should this return null on failure? */ #define Read_Prev_Letter (Look_Back_Letter(1)) /* Look two letters down. It makes sure you don't walk off the string. */ #define Read_After_Next_Letter (Read_Raw_Next_Letter != '\0' ? Convert_Raw(word[w_idx+2]) \ : '\0') #define Look_Ahead_Letter(n) (toupper(Lookahead((char *) word+w_idx, n))) /* Allows us to safely look ahead an arbitrary # of letters */ /* I probably could have just used strlen... */ static char Lookahead(char *word, int how_far) { int idx; for (idx = 0; word[idx] != '\0' && idx < how_far; idx++); /* Edge forward in the string... */ return word[idx]; /* idx will be either == to how_far or * at the end of the string where it will be null */ } /* phonize one letter * We don't know the buffers size in advance. On way to solve this is to just * re-allocate the buffer size. We're using an extra of 2 characters (this * could be one though; or more too). */ #define Phonize(c) { \ if (p_idx >= max_buffer_len) { \ *phoned_word = zend_string_extend(*phoned_word, 2 * sizeof(char) + max_buffer_len, 0); \ max_buffer_len += 2; \ } \ ZSTR_VAL(*phoned_word)[p_idx++] = c; \ ZSTR_LEN(*phoned_word) = p_idx; \ } /* Slap a null character on the end of the phoned word */ #define End_Phoned_Word() { \ if (p_idx == max_buffer_len) { \ *phoned_word = zend_string_extend(*phoned_word, 1 * sizeof(char) + max_buffer_len, 0); \ max_buffer_len += 1; \ } \ ZSTR_VAL(*phoned_word)[p_idx] = '\0'; \ ZSTR_LEN(*phoned_word) = p_idx; \ } /* How long is the phoned word? */ #define Phone_Len (p_idx) /* Note is a letter is a 'break' in the word */ #define Isbreak(c) (!isalpha(c)) /* {{{ metaphone */ static void metaphone(unsigned char *word, size_t word_len, zend_long max_phonemes, zend_string **phoned_word, int traditional) { int w_idx = 0; /* point in the phonization we're at. */ size_t p_idx = 0; /* end of the phoned phrase */ size_t max_buffer_len = 0; /* maximum length of the destination buffer */ char curr_letter; ZEND_ASSERT(word != NULL); ZEND_ASSERT(max_phonemes >= 0); /*-- Allocate memory for our phoned_phrase --*/ if (max_phonemes == 0) { /* Assume largest possible */ max_buffer_len = word_len; *phoned_word = zend_string_alloc(sizeof(char) * word_len + 1, 0); } else { max_buffer_len = max_phonemes; *phoned_word = zend_string_alloc(sizeof(char) * max_phonemes + 1, 0); } /*-- The first phoneme has to be processed specially. --*/ /* Find our first letter */ for (; !isalpha(curr_letter = Read_Raw_Curr_Letter); w_idx++) { /* On the off chance we were given nothing but crap... */ if (curr_letter == '\0') { End_Phoned_Word(); return; } } curr_letter = Convert_Raw(curr_letter); switch (curr_letter) { /* AE becomes E */ case 'A': if (Read_Next_Letter == 'E') { Phonize('E'); w_idx += 2; } /* Remember, preserve vowels at the beginning */ else { Phonize('A'); w_idx++; } break; /* [GKP]N becomes N */ case 'G': case 'K': case 'P': if (Read_Next_Letter == 'N') { Phonize('N'); w_idx += 2; } break; /* WH becomes W, WR becomes R W if followed by a vowel */ case 'W': { char next_letter = Read_Next_Letter; if (next_letter == 'R') { Phonize('R'); w_idx += 2; } else if (next_letter == 'H' || isvowel(next_letter)) { Phonize('W'); w_idx += 2; } /* else ignore */ break; } /* X becomes S */ case 'X': Phonize('S'); w_idx++; break; /* Vowels are kept */ /* We did A already case 'A': case 'a': */ case 'E': case 'I': case 'O': case 'U': Phonize(curr_letter); w_idx++; break; default: /* do nothing */ break; } /* On to the metaphoning */ for (; (curr_letter = Read_Raw_Curr_Letter) != '\0' && (max_phonemes == 0 || Phone_Len < (size_t)max_phonemes); w_idx++) { /* How many letters to skip because an eariler encoding handled * multiple letters */ unsigned short int skip_letter = 0; /* THOUGHT: It would be nice if, rather than having things like... * well, SCI. For SCI you encode the S, then have to remember * to skip the C. So the phonome SCI invades both S and C. It would * be better, IMHO, to skip the C from the S part of the encoding. * Hell, I'm trying it. */ /* Ignore non-alphas */ if (!isalpha(curr_letter)) continue; curr_letter = Convert_Raw(curr_letter); /* Note: we can't cache curr_letter from the previous loop * because of the skip_letter variable. */ char prev_letter = Read_Prev_Letter; /* Drop duplicates, except CC */ if (curr_letter == prev_letter && curr_letter != 'C') continue; switch (curr_letter) { /* B -> B unless in MB */ case 'B': if (prev_letter != 'M') Phonize('B'); break; /* 'sh' if -CIA- or -CH, but not SCH, except SCHW. * (SCHW is handled in S) * S if -CI-, -CE- or -CY- * dropped if -SCI-, SCE-, -SCY- (handed in S) * else K */ case 'C': { char next_letter = Read_Next_Letter; if (MAKESOFT(next_letter)) { /* C[IEY] */ if (next_letter == 'I' && Read_After_Next_Letter == 'A') { /* CIA */ Phonize(SH); } /* SC[IEY] */ else if (prev_letter == 'S') { /* Dropped */ } else { Phonize('S'); } } else if (next_letter == 'H') { if ((!traditional) && (prev_letter == 'S' || Read_After_Next_Letter == 'R')) { /* Christ, School */ Phonize('K'); } else { Phonize(SH); } skip_letter++; } else { Phonize('K'); } break; } /* J if in -DGE-, -DGI- or -DGY- * else T */ case 'D': if (Read_Next_Letter == 'G' && MAKESOFT(Read_After_Next_Letter)) { Phonize('J'); skip_letter++; } else Phonize('T'); break; /* F if in -GH and not B--GH, D--GH, -H--GH, -H---GH * else dropped if -GNED, -GN, * else dropped if -DGE-, -DGI- or -DGY- (handled in D) * else J if in -GE-, -GI, -GY and not GG * else K */ case 'G': { char next_letter = Read_Next_Letter; if (next_letter == 'H') { if (!(NOGHTOF(Look_Back_Letter(3)) || Look_Back_Letter(4) == 'H')) { Phonize('F'); skip_letter++; } else { /* silent */ } } else if (next_letter == 'N') { char after_next_letter = Read_After_Next_Letter; if (Isbreak(after_next_letter) || (after_next_letter == 'E' && Look_Ahead_Letter(3) == 'D')) { /* dropped */ } else Phonize('K'); } else if (MAKESOFT(next_letter) && prev_letter != 'G') { Phonize('J'); } else { Phonize('K'); } break; } /* H if before a vowel and not after C,G,P,S,T */ case 'H': if (isvowel(Read_Next_Letter) && !AFFECTH(prev_letter)) Phonize('H'); break; /* dropped if after C * else K */ case 'K': if (prev_letter != 'C') Phonize('K'); break; /* F if before H * else P */ case 'P': if (Read_Next_Letter == 'H') { Phonize('F'); } else { Phonize('P'); } break; /* K */ case 'Q': Phonize('K'); break; /* 'sh' in -SH-, -SIO- or -SIA- or -SCHW- * else S */ case 'S': { char next_letter = Read_Next_Letter; char after_next_letter; if (next_letter == 'I' && ((after_next_letter = Read_After_Next_Letter) == 'O' || after_next_letter == 'A')) { Phonize(SH); } else if (next_letter == 'H') { Phonize(SH); skip_letter++; } else if ((!traditional) && (next_letter == 'C' && Look_Ahead_Letter(2) == 'H' && Look_Ahead_Letter(3) == 'W')) { Phonize(SH); skip_letter += 2; } else { Phonize('S'); } break; } /* 'sh' in -TIA- or -TIO- * else 'th' before H * else T */ case 'T': { char next_letter = Read_Next_Letter; char after_next_letter; if (next_letter == 'I' && ((after_next_letter = Read_After_Next_Letter) == 'O' || after_next_letter == 'A')) { Phonize(SH); } else if (next_letter == 'H') { Phonize(TH); skip_letter++; } else if (!(next_letter == 'C' && Read_After_Next_Letter == 'H')) { Phonize('T'); } break; } /* F */ case 'V': Phonize('F'); break; /* W before a vowel, else dropped */ case 'W': if (isvowel(Read_Next_Letter)) Phonize('W'); break; /* KS */ case 'X': Phonize('K'); Phonize('S'); break; /* Y if followed by a vowel */ case 'Y': if (isvowel(Read_Next_Letter)) Phonize('Y'); break; /* S */ case 'Z': Phonize('S'); break; /* No transformation */ case 'F': case 'J': case 'L': case 'M': case 'N': case 'R': Phonize(curr_letter); break; default: /* nothing */ break; } /* END SWITCH */ w_idx += skip_letter; } /* END FOR */ End_Phoned_Word(); } /* END metaphone */ /* }}} */
12,823
25.550725
128
c
php-src
php-src-master/ext/standard/microtime.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: Paul Panotzki - Bunyip Information Systems | +----------------------------------------------------------------------+ */ #include "php.h" #ifdef HAVE_SYS_TYPES_H #include <sys/types.h> #endif #ifdef PHP_WIN32 #include "win32/time.h" #include "win32/getrusage.h" #else #include <sys/time.h> #endif #ifdef HAVE_SYS_RESOURCE_H #include <sys/resource.h> #endif #ifdef HAVE_UNISTD_H #include <unistd.h> #endif #include <stdlib.h> #include <string.h> #include <stdio.h> #include <errno.h> #include "ext/date/php_date.h" #define NUL '\0' #define MICRO_IN_SEC 1000000.00 #define SEC_IN_MIN 60 #ifdef HAVE_GETTIMEOFDAY static void _php_gettimeofday(INTERNAL_FUNCTION_PARAMETERS, int mode) { bool get_as_float = 0; struct timeval tp = {0}; ZEND_PARSE_PARAMETERS_START(0, 1) Z_PARAM_OPTIONAL Z_PARAM_BOOL(get_as_float) ZEND_PARSE_PARAMETERS_END(); if (gettimeofday(&tp, NULL)) { ZEND_ASSERT(0 && "gettimeofday() can't fail"); } if (get_as_float) { RETURN_DOUBLE((double)(tp.tv_sec + tp.tv_usec / MICRO_IN_SEC)); } if (mode) { timelib_time_offset *offset; offset = timelib_get_time_zone_info(tp.tv_sec, get_timezone_info()); array_init(return_value); add_assoc_long(return_value, "sec", tp.tv_sec); add_assoc_long(return_value, "usec", tp.tv_usec); add_assoc_long(return_value, "minuteswest", -offset->offset / SEC_IN_MIN); add_assoc_long(return_value, "dsttime", offset->is_dst); timelib_time_offset_dtor(offset); } else { RETURN_NEW_STR(zend_strpprintf(0, "%.8F %ld", tp.tv_usec / MICRO_IN_SEC, (long)tp.tv_sec)); } } /* {{{ Returns either a string or a float containing the current time in seconds and microseconds */ PHP_FUNCTION(microtime) { _php_gettimeofday(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); } /* }}} */ /* {{{ Returns the current time as array */ PHP_FUNCTION(gettimeofday) { _php_gettimeofday(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); } #endif /* }}} */ #ifdef HAVE_GETRUSAGE /* {{{ Returns an array of usage statistics */ PHP_FUNCTION(getrusage) { struct rusage usg; zend_long pwho = 0; int who = RUSAGE_SELF; ZEND_PARSE_PARAMETERS_START(0, 1) Z_PARAM_OPTIONAL Z_PARAM_LONG(pwho) ZEND_PARSE_PARAMETERS_END(); if (pwho == 1) { who = RUSAGE_CHILDREN; } memset(&usg, 0, sizeof(struct rusage)); if (getrusage(who, &usg) == -1) { RETURN_FALSE; } array_init(return_value); #define PHP_RUSAGE_PARA(a) \ add_assoc_long(return_value, #a, usg.a) #ifdef PHP_WIN32 /* Windows only implements a limited amount of fields from the rusage struct */ PHP_RUSAGE_PARA(ru_majflt); PHP_RUSAGE_PARA(ru_maxrss); #elif !defined(_OSD_POSIX) && !defined(__HAIKU__) PHP_RUSAGE_PARA(ru_oublock); PHP_RUSAGE_PARA(ru_inblock); PHP_RUSAGE_PARA(ru_msgsnd); PHP_RUSAGE_PARA(ru_msgrcv); PHP_RUSAGE_PARA(ru_maxrss); PHP_RUSAGE_PARA(ru_ixrss); PHP_RUSAGE_PARA(ru_idrss); PHP_RUSAGE_PARA(ru_minflt); PHP_RUSAGE_PARA(ru_majflt); PHP_RUSAGE_PARA(ru_nsignals); PHP_RUSAGE_PARA(ru_nvcsw); PHP_RUSAGE_PARA(ru_nivcsw); PHP_RUSAGE_PARA(ru_nswap); #endif /*_OSD_POSIX*/ PHP_RUSAGE_PARA(ru_utime.tv_usec); PHP_RUSAGE_PARA(ru_utime.tv_sec); PHP_RUSAGE_PARA(ru_stime.tv_usec); PHP_RUSAGE_PARA(ru_stime.tv_sec); #undef PHP_RUSAGE_PARA } #endif /* HAVE_GETRUSAGE */ /* }}} */
4,103
25.823529
100
c
php-src
php-src-master/ext/standard/net.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: Sara Golemon <[email protected]> | +----------------------------------------------------------------------+ */ #include "php.h" #include "php_network.h" #ifdef HAVE_ARPA_INET_H # include <arpa/inet.h> #endif #ifdef HAVE_NET_IF_H # include <net/if.h> #endif #ifdef HAVE_GETIFADDRS # include <ifaddrs.h> #elif defined(__PASE__) /* IBM i implements getifaddrs, but under its own name */ #include <as400_protos.h> #define getifaddrs Qp2getifaddrs #define freeifaddrs Qp2freeifaddrs #define ifaddrs ifaddrs_pase #endif #ifdef PHP_WIN32 # ifndef __clang__ # include <intrin.h> # endif # include <winsock2.h> # include <ws2ipdef.h> # include <Ws2tcpip.h> # include <iphlpapi.h> #else # include <netdb.h> #endif PHPAPI zend_string* php_inet_ntop(const struct sockaddr *addr) { socklen_t addrlen = sizeof(struct sockaddr_in); if (!addr) { return NULL; } /* Prefer inet_ntop() as it's more task-specific and doesn't have to be demangled */ #ifdef HAVE_INET_NTOP switch (addr->sa_family) { #ifdef AF_INET6 case AF_INET6: { zend_string *ret = zend_string_alloc(INET6_ADDRSTRLEN, 0); if (inet_ntop(AF_INET6, &(((struct sockaddr_in6*)addr)->sin6_addr), ZSTR_VAL(ret), INET6_ADDRSTRLEN)) { ZSTR_LEN(ret) = strlen(ZSTR_VAL(ret)); return ret; } zend_string_efree(ret); break; } #endif case AF_INET: { zend_string *ret = zend_string_alloc(INET_ADDRSTRLEN, 0); if (inet_ntop(AF_INET, &(((struct sockaddr_in*)addr)->sin_addr), ZSTR_VAL(ret), INET_ADDRSTRLEN)) { ZSTR_LEN(ret) = strlen(ZSTR_VAL(ret)); return ret; } zend_string_efree(ret); break; } } #endif /* Fallback on getnameinfo() */ switch (addr->sa_family) { #ifdef AF_INET6 case AF_INET6: addrlen = sizeof(struct sockaddr_in6); ZEND_FALLTHROUGH; #endif case AF_INET: { zend_string *ret = zend_string_alloc(NI_MAXHOST, 0); if (getnameinfo(addr, addrlen, ZSTR_VAL(ret), NI_MAXHOST, NULL, 0, NI_NUMERICHOST) == SUCCESS) { /* Also demangle numeric host with %name suffix */ char *colon = strchr(ZSTR_VAL(ret), '%'); if (colon) { *colon = 0; } ZSTR_LEN(ret) = strlen(ZSTR_VAL(ret)); return ret; } zend_string_efree(ret); break; } } return NULL; } #if defined(PHP_WIN32) || defined(HAVE_GETIFADDRS) || defined(__PASE__) static void iface_append_unicast(zval *unicast, zend_long flags, struct sockaddr *addr, struct sockaddr *netmask, struct sockaddr *broadcast, struct sockaddr *ptp) { zend_string *host; zval u; array_init(&u); add_assoc_long(&u, "flags", flags); if (addr) { add_assoc_long(&u, "family", addr->sa_family); if ((host = php_inet_ntop(addr))) { add_assoc_str(&u, "address", host); } } if ((host = php_inet_ntop(netmask))) { add_assoc_str(&u, "netmask", host); } if ((host = php_inet_ntop(broadcast))) { add_assoc_str(&u, "broadcast", host); } if ((host = php_inet_ntop(ptp))) { add_assoc_str(&u, "ptp", host); } add_next_index_zval(unicast, &u); } /* {{{ Returns an array in the form: array( 'ifacename' => array( 'description' => 'Awesome interface', // Win32 only 'mac' => '00:11:22:33:44:55', // Win32 only 'mtu' => 1234, // Win32 only 'unicast' => array( 0 => array( 'family' => 2, // e.g. AF_INET, AF_INET6, AF_PACKET 'address' => '127.0.0.1', 'netmnask' => '255.0.0.0', 'broadcast' => '127.255.255.255', // POSIX only 'ptp' => '127.0.0.2', // POSIX only ), // etc... ), ), // etc... ) */ PHP_FUNCTION(net_get_interfaces) { #ifdef PHP_WIN32 # define MALLOC(x) HeapAlloc(GetProcessHeap(), 0, (x)) # define FREE(x) HeapFree(GetProcessHeap(), 0, (x)) ULONG family = AF_UNSPEC; ULONG flags = GAA_FLAG_INCLUDE_PREFIX; PIP_ADAPTER_ADDRESSES pAddresses = NULL, p; PIP_ADAPTER_UNICAST_ADDRESS u = NULL; ULONG outBufLen = 0; DWORD dwRetVal = 0; ZEND_PARSE_PARAMETERS_NONE(); // Make an initial call to GetAdaptersAddresses to get the // size needed into the outBufLen variable if (GetAdaptersAddresses(family, flags, NULL, pAddresses, &outBufLen) == ERROR_BUFFER_OVERFLOW) { FREE(pAddresses); pAddresses = (IP_ADAPTER_ADDRESSES *) MALLOC(outBufLen); } if (pAddresses == NULL) { zend_error(E_WARNING, "Memory allocation failed for IP_ADAPTER_ADDRESSES struct"); RETURN_FALSE; } dwRetVal = GetAdaptersAddresses(family, flags, NULL, pAddresses, &outBufLen); if (NO_ERROR != dwRetVal) { char *buf = php_win32_error_to_msg(GetLastError()); zend_error(E_WARNING, "GetAdaptersAddresses failed: %s", buf); php_win32_error_msg_free(buf); FREE(pAddresses); RETURN_FALSE; } array_init(return_value); for (p = pAddresses; p; p = p->Next) { zval iface, unicast; if ((IF_TYPE_ETHERNET_CSMACD != p->IfType) && (IF_TYPE_IEEE80211 != p->IfType) && (IF_TYPE_SOFTWARE_LOOPBACK != p->IfType)) { continue; } array_init(&iface); if (p->Description) { char tmp[256]; memset(tmp, 0, sizeof(tmp)); wcstombs(tmp, p->Description, sizeof(tmp)); add_assoc_string(&iface, "description", tmp); } if (p->PhysicalAddressLength > 0) { zend_string *mac = zend_string_alloc(p->PhysicalAddressLength * 3, 0); char *s = ZSTR_VAL(mac); ULONG i; for (i = 0; i < p->PhysicalAddressLength; ++i) { s += snprintf(s, 4, "%02X:", p->PhysicalAddress[i]); } *(--s) = 0; ZSTR_LEN(mac) = s - ZSTR_VAL(mac); add_assoc_str(&iface, "mac", mac); } /* Flags could be placed at this level, * but we repeat it in the unicast subarray * for consistency with the POSIX version. */ add_assoc_long(&iface, "mtu", p->Mtu); array_init(&unicast); for (u = p->FirstUnicastAddress; u; u = u->Next) { switch (u->Address.lpSockaddr->sa_family) { case AF_INET: { ULONG mask; struct sockaddr_in sin_mask; ConvertLengthToIpv4Mask(u->OnLinkPrefixLength, &mask); sin_mask.sin_family = AF_INET; sin_mask.sin_addr.s_addr = mask; iface_append_unicast(&unicast, p->Flags, (struct sockaddr*)u->Address.lpSockaddr, (struct sockaddr*)&sin_mask, NULL, NULL); break; } case AF_INET6: { ULONG i, j; struct sockaddr_in6 sin6_mask; memset(&sin6_mask, 0, sizeof(sin6_mask)); sin6_mask.sin6_family = AF_INET6; for (i = u->OnLinkPrefixLength, j = 0; i > 0; i -= 8, ++j) { sin6_mask.sin6_addr.s6_addr[j] = (i >= 8) ? 0xff : ((ULONG)((0xffU << (8 - i)) & 0xffU)); } iface_append_unicast(&unicast, p->Flags, (struct sockaddr*)u->Address.lpSockaddr, (struct sockaddr*)&sin6_mask, NULL, NULL); break; } } } add_assoc_zval(&iface, "unicast", &unicast); add_assoc_bool(&iface, "up", (p->OperStatus == IfOperStatusUp)); add_assoc_zval(return_value, p->AdapterName, &iface); } FREE(pAddresses); #undef MALLOC #undef FREE #elif HAVE_GETIFADDRS || defined(__PASE__) /* !PHP_WIN32 */ struct ifaddrs *addrs = NULL, *p; ZEND_PARSE_PARAMETERS_NONE(); if (getifaddrs(&addrs)) { php_error(E_WARNING, "getifaddrs() failed %d: %s", errno, strerror(errno)); RETURN_FALSE; } array_init(return_value); for (p = addrs; p; p = p->ifa_next) { zval *iface = zend_hash_str_find(Z_ARR_P(return_value), p->ifa_name, strlen(p->ifa_name)); zval *unicast, *status; if (!iface) { zval newif; array_init(&newif); iface = zend_hash_str_add(Z_ARR_P(return_value), p->ifa_name, strlen(p->ifa_name), &newif); } unicast = zend_hash_str_find(Z_ARR_P(iface), "unicast", sizeof("unicast") - 1); if (!unicast) { zval newuni; array_init(&newuni); unicast = zend_hash_str_add(Z_ARR_P(iface), "unicast", sizeof("unicast") - 1, &newuni); } iface_append_unicast(unicast, p->ifa_flags, p->ifa_addr, p->ifa_netmask, (p->ifa_flags & IFF_BROADCAST) ? p->ifa_broadaddr : NULL, (p->ifa_flags & IFF_POINTOPOINT) ? p->ifa_dstaddr : NULL); status = zend_hash_str_find(Z_ARR_P(iface), "up", sizeof("up") - 1); if (!status) { add_assoc_bool(iface, "up", ((p->ifa_flags & IFF_UP) != 0)); } } freeifaddrs(addrs); #else /* Should never happen as we never register the function */ ZEND_UNREACHABLE(); #endif } #endif /* }}} */
9,242
28.436306
127
c
php-src
php-src-master/ext/standard/pack.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: Rasmus Lerdorf <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef PACK_H #define PACK_H PHP_MINIT_FUNCTION(pack); #endif /* PACK_H */
1,073
45.695652
75
h
php-src
php-src-master/ext/standard/pageinfo.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: Jim Winstead <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef PAGEINFO_H #define PAGEINFO_H PHPAPI void php_statpage(void); PHPAPI time_t php_getlastmod(void); extern zend_long php_getuid(void); extern zend_long php_getgid(void); #endif
1,180
44.423077
75
h
php-src
php-src-master/ext/standard/password.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: Anthony Ferrara <[email protected]> | | Charles R. Portwood II <[email protected]> | +----------------------------------------------------------------------+ */ #include <stdlib.h> #include "php.h" #include "fcntl.h" #include "php_password.h" #include "php_crypt.h" #include "base64.h" #include "zend_interfaces.h" #include "info.h" #include "ext/random/php_random.h" #ifdef HAVE_ARGON2LIB #include "argon2.h" #endif #ifdef PHP_WIN32 #include "win32/winutil.h" #endif static zend_array php_password_algos; int php_password_algo_register(const char *ident, const php_password_algo *algo) { zend_string *key = zend_string_init_interned(ident, strlen(ident), 1); return zend_hash_add_ptr(&php_password_algos, key, (void *) algo) ? SUCCESS : FAILURE; } void php_password_algo_unregister(const char *ident) { zend_hash_str_del(&php_password_algos, ident, strlen(ident)); } static int php_password_salt_to64(const char *str, const size_t str_len, const size_t out_len, char *ret) /* {{{ */ { size_t pos = 0; zend_string *buffer; if ((int) str_len < 0) { return FAILURE; } buffer = php_base64_encode((unsigned char*) str, str_len); if (ZSTR_LEN(buffer) < out_len) { /* Too short of an encoded string generated */ zend_string_release_ex(buffer, 0); return FAILURE; } for (pos = 0; pos < out_len; pos++) { if (ZSTR_VAL(buffer)[pos] == '+') { ret[pos] = '.'; } else if (ZSTR_VAL(buffer)[pos] == '=') { zend_string_free(buffer); return FAILURE; } else { ret[pos] = ZSTR_VAL(buffer)[pos]; } } zend_string_free(buffer); return SUCCESS; } /* }}} */ static zend_string* php_password_make_salt(size_t length) /* {{{ */ { zend_string *ret, *buffer; if (length > (INT_MAX / 3)) { zend_value_error("Length is too large to safely generate"); return NULL; } buffer = zend_string_alloc(length * 3 / 4 + 1, 0); if (FAILURE == php_random_bytes_throw(ZSTR_VAL(buffer), ZSTR_LEN(buffer))) { zend_value_error("Unable to generate salt"); zend_string_release_ex(buffer, 0); return NULL; } ret = zend_string_alloc(length, 0); if (php_password_salt_to64(ZSTR_VAL(buffer), ZSTR_LEN(buffer), length, ZSTR_VAL(ret)) == FAILURE) { zend_value_error("Generated salt too short"); zend_string_release_ex(buffer, 0); zend_string_release_ex(ret, 0); return NULL; } zend_string_release_ex(buffer, 0); ZSTR_VAL(ret)[length] = 0; return ret; } /* }}} */ static zend_string* php_password_get_salt(zval *unused_, size_t required_salt_len, HashTable *options) { if (options && zend_hash_str_exists(options, "salt", sizeof("salt") - 1)) { php_error_docref(NULL, E_WARNING, "The \"salt\" option has been ignored, since providing a custom salt is no longer supported"); } return php_password_make_salt(required_salt_len); } /* bcrypt implementation */ static bool php_password_bcrypt_valid(const zend_string *hash) { const char *h = ZSTR_VAL(hash); return (ZSTR_LEN(hash) == 60) && (h[0] == '$') && (h[1] == '2') && (h[2] == 'y'); } static int php_password_bcrypt_get_info(zval *return_value, const zend_string *hash) { zend_long cost = PHP_PASSWORD_BCRYPT_COST; if (!php_password_bcrypt_valid(hash)) { /* Should never get called this way. */ return FAILURE; } sscanf(ZSTR_VAL(hash), "$2y$" ZEND_LONG_FMT "$", &cost); add_assoc_long(return_value, "cost", cost); return SUCCESS; } static bool php_password_bcrypt_needs_rehash(const zend_string *hash, zend_array *options) { zval *znew_cost; zend_long old_cost = PHP_PASSWORD_BCRYPT_COST; zend_long new_cost = PHP_PASSWORD_BCRYPT_COST; if (!php_password_bcrypt_valid(hash)) { /* Should never get called this way. */ return 1; } sscanf(ZSTR_VAL(hash), "$2y$" ZEND_LONG_FMT "$", &old_cost); if (options && (znew_cost = zend_hash_str_find(options, "cost", sizeof("cost")-1)) != NULL) { new_cost = zval_get_long(znew_cost); } return old_cost != new_cost; } static bool php_password_bcrypt_verify(const zend_string *password, const zend_string *hash) { int status = 0; zend_string *ret = php_crypt(ZSTR_VAL(password), (int)ZSTR_LEN(password), ZSTR_VAL(hash), (int)ZSTR_LEN(hash), 1); if (!ret) { return 0; } if (ZSTR_LEN(hash) < 13) { zend_string_free(ret); return 0; } /* We're using this method instead of == in order to provide * resistance towards timing attacks. This is a constant time * equality check that will always check every byte of both * values. */ status = php_safe_bcmp(ret, hash); zend_string_free(ret); return status == 0; } static zend_string* php_password_bcrypt_hash(const zend_string *password, zend_array *options) { char hash_format[10]; size_t hash_format_len; zend_string *result, *hash, *salt; zval *zcost; zend_long cost = PHP_PASSWORD_BCRYPT_COST; if (options && (zcost = zend_hash_str_find(options, "cost", sizeof("cost")-1)) != NULL) { cost = zval_get_long(zcost); } if (cost < 4 || cost > 31) { zend_value_error("Invalid bcrypt cost parameter specified: " ZEND_LONG_FMT, cost); return NULL; } hash_format_len = snprintf(hash_format, sizeof(hash_format), "$2y$%02" ZEND_LONG_FMT_SPEC "$", cost); if (!(salt = php_password_get_salt(NULL, Z_UL(22), options))) { return NULL; } ZSTR_VAL(salt)[ZSTR_LEN(salt)] = 0; hash = zend_string_alloc(ZSTR_LEN(salt) + hash_format_len, 0); sprintf(ZSTR_VAL(hash), "%s%s", hash_format, ZSTR_VAL(salt)); ZSTR_VAL(hash)[hash_format_len + ZSTR_LEN(salt)] = 0; zend_string_release_ex(salt, 0); /* This cast is safe, since both values are defined here in code and cannot overflow */ result = php_crypt(ZSTR_VAL(password), (int)ZSTR_LEN(password), ZSTR_VAL(hash), (int)ZSTR_LEN(hash), 1); zend_string_release_ex(hash, 0); if (!result) { return NULL; } if (ZSTR_LEN(result) < 13) { zend_string_free(result); return NULL; } return result; } const php_password_algo php_password_algo_bcrypt = { "bcrypt", php_password_bcrypt_hash, php_password_bcrypt_verify, php_password_bcrypt_needs_rehash, php_password_bcrypt_get_info, php_password_bcrypt_valid, }; #ifdef HAVE_ARGON2LIB /* argon2i/argon2id shared implementation */ static int extract_argon2_parameters(const zend_string *hash, zend_long *v, zend_long *memory_cost, zend_long *time_cost, zend_long *threads) /* {{{ */ { const char *p = ZSTR_VAL(hash); if (!hash || (ZSTR_LEN(hash) < sizeof("$argon2id$"))) { return FAILURE; } if (!memcmp(p, "$argon2i$", sizeof("$argon2i$") - 1)) { p += sizeof("$argon2i$") - 1; } else if (!memcmp(p, "$argon2id$", sizeof("$argon2id$") - 1)) { p += sizeof("$argon2id$") - 1; } else { return FAILURE; } sscanf(p, "v=" ZEND_LONG_FMT "$m=" ZEND_LONG_FMT ",t=" ZEND_LONG_FMT ",p=" ZEND_LONG_FMT, v, memory_cost, time_cost, threads); return SUCCESS; } /* }}} */ static int php_password_argon2_get_info(zval *return_value, const zend_string *hash) { zend_long v = 0; zend_long memory_cost = PHP_PASSWORD_ARGON2_MEMORY_COST; zend_long time_cost = PHP_PASSWORD_ARGON2_TIME_COST; zend_long threads = PHP_PASSWORD_ARGON2_THREADS; extract_argon2_parameters(hash, &v, &memory_cost, &time_cost, &threads); add_assoc_long(return_value, "memory_cost", memory_cost); add_assoc_long(return_value, "time_cost", time_cost); add_assoc_long(return_value, "threads", threads); return SUCCESS; } static bool php_password_argon2_needs_rehash(const zend_string *hash, zend_array *options) { zend_long v = 0; zend_long new_memory_cost = PHP_PASSWORD_ARGON2_MEMORY_COST, memory_cost = 0; zend_long new_time_cost = PHP_PASSWORD_ARGON2_TIME_COST, time_cost = 0; zend_long new_threads = PHP_PASSWORD_ARGON2_THREADS, threads = 0; zval *option_buffer; if (options && (option_buffer = zend_hash_str_find(options, "memory_cost", sizeof("memory_cost")-1)) != NULL) { new_memory_cost = zval_get_long(option_buffer); } if (options && (option_buffer = zend_hash_str_find(options, "time_cost", sizeof("time_cost")-1)) != NULL) { new_time_cost = zval_get_long(option_buffer); } if (options && (option_buffer = zend_hash_str_find(options, "threads", sizeof("threads")-1)) != NULL) { new_threads = zval_get_long(option_buffer); } extract_argon2_parameters(hash, &v, &memory_cost, &time_cost, &threads); return (new_time_cost != time_cost) || (new_memory_cost != memory_cost) || (new_threads != threads); } static zend_string *php_password_argon2_hash(const zend_string *password, zend_array *options, argon2_type type) { zval *option_buffer; zend_string *salt, *out, *encoded; size_t time_cost = PHP_PASSWORD_ARGON2_TIME_COST; size_t memory_cost = PHP_PASSWORD_ARGON2_MEMORY_COST; size_t threads = PHP_PASSWORD_ARGON2_THREADS; size_t encoded_len; int status = 0; if (options && (option_buffer = zend_hash_str_find(options, "memory_cost", sizeof("memory_cost")-1)) != NULL) { memory_cost = zval_get_long(option_buffer); } if (memory_cost > ARGON2_MAX_MEMORY || memory_cost < ARGON2_MIN_MEMORY) { zend_value_error("Memory cost is outside of allowed memory range"); return NULL; } if (options && (option_buffer = zend_hash_str_find(options, "time_cost", sizeof("time_cost")-1)) != NULL) { time_cost = zval_get_long(option_buffer); } if (time_cost > ARGON2_MAX_TIME || time_cost < ARGON2_MIN_TIME) { zend_value_error("Time cost is outside of allowed time range"); return NULL; } if (options && (option_buffer = zend_hash_str_find(options, "threads", sizeof("threads")-1)) != NULL) { threads = zval_get_long(option_buffer); } if (threads > ARGON2_MAX_LANES || threads == 0) { zend_value_error("Invalid number of threads"); return NULL; } if (!(salt = php_password_get_salt(NULL, Z_UL(16), options))) { return NULL; } out = zend_string_alloc(32, 0); encoded_len = argon2_encodedlen( time_cost, memory_cost, threads, (uint32_t)ZSTR_LEN(salt), ZSTR_LEN(out), type ); encoded = zend_string_alloc(encoded_len - 1, 0); status = argon2_hash( time_cost, memory_cost, threads, ZSTR_VAL(password), ZSTR_LEN(password), ZSTR_VAL(salt), ZSTR_LEN(salt), ZSTR_VAL(out), ZSTR_LEN(out), ZSTR_VAL(encoded), encoded_len, type, ARGON2_VERSION_NUMBER ); zend_string_release_ex(out, 0); zend_string_release_ex(salt, 0); if (status != ARGON2_OK) { zend_string_efree(encoded); zend_value_error("%s", argon2_error_message(status)); return NULL; } ZSTR_VAL(encoded)[ZSTR_LEN(encoded)] = 0; return encoded; } /* argon2i specific methods */ static bool php_password_argon2i_verify(const zend_string *password, const zend_string *hash) { return ARGON2_OK == argon2_verify(ZSTR_VAL(hash), ZSTR_VAL(password), ZSTR_LEN(password), Argon2_i); } static zend_string *php_password_argon2i_hash(const zend_string *password, zend_array *options) { return php_password_argon2_hash(password, options, Argon2_i); } const php_password_algo php_password_algo_argon2i = { "argon2i", php_password_argon2i_hash, php_password_argon2i_verify, php_password_argon2_needs_rehash, php_password_argon2_get_info, NULL, }; /* argon2id specific methods */ static bool php_password_argon2id_verify(const zend_string *password, const zend_string *hash) { return ARGON2_OK == argon2_verify(ZSTR_VAL(hash), ZSTR_VAL(password), ZSTR_LEN(password), Argon2_id); } static zend_string *php_password_argon2id_hash(const zend_string *password, zend_array *options) { return php_password_argon2_hash(password, options, Argon2_id); } const php_password_algo php_password_algo_argon2id = { "argon2id", php_password_argon2id_hash, php_password_argon2id_verify, php_password_argon2_needs_rehash, php_password_argon2_get_info, NULL, }; #endif PHP_MINIT_FUNCTION(password) /* {{{ */ { zend_hash_init(&php_password_algos, 4, NULL, ZVAL_PTR_DTOR, 1); REGISTER_STRING_CONSTANT("PASSWORD_DEFAULT", "2y", CONST_PERSISTENT); if (FAILURE == php_password_algo_register("2y", &php_password_algo_bcrypt)) { return FAILURE; } REGISTER_STRING_CONSTANT("PASSWORD_BCRYPT", "2y", CONST_PERSISTENT); #ifdef HAVE_ARGON2LIB if (FAILURE == php_password_algo_register("argon2i", &php_password_algo_argon2i)) { return FAILURE; } REGISTER_STRING_CONSTANT("PASSWORD_ARGON2I", "argon2i", CONST_PERSISTENT); if (FAILURE == php_password_algo_register("argon2id", &php_password_algo_argon2id)) { return FAILURE; } REGISTER_STRING_CONSTANT("PASSWORD_ARGON2ID", "argon2id", CONST_PERSISTENT); #endif REGISTER_LONG_CONSTANT("PASSWORD_BCRYPT_DEFAULT_COST", PHP_PASSWORD_BCRYPT_COST, CONST_PERSISTENT); #ifdef HAVE_ARGON2LIB REGISTER_LONG_CONSTANT("PASSWORD_ARGON2_DEFAULT_MEMORY_COST", PHP_PASSWORD_ARGON2_MEMORY_COST, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("PASSWORD_ARGON2_DEFAULT_TIME_COST", PHP_PASSWORD_ARGON2_TIME_COST, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("PASSWORD_ARGON2_DEFAULT_THREADS", PHP_PASSWORD_ARGON2_THREADS, CONST_PERSISTENT); REGISTER_STRING_CONSTANT("PASSWORD_ARGON2_PROVIDER", "standard", CONST_PERSISTENT); #endif return SUCCESS; } /* }}} */ PHP_MSHUTDOWN_FUNCTION(password) /* {{{ */ { #ifdef ZTS if (!tsrm_is_main_thread()) { return SUCCESS; } #endif zend_hash_destroy(&php_password_algos); return SUCCESS; } /* }}} */ const php_password_algo* php_password_algo_default(void) { return &php_password_algo_bcrypt; } const php_password_algo* php_password_algo_find(const zend_string *ident) { zval *tmp; if (!ident) { return NULL; } tmp = zend_hash_find(&php_password_algos, (zend_string*)ident); if (!tmp || (Z_TYPE_P(tmp) != IS_PTR)) { return NULL; } return Z_PTR_P(tmp); } static const php_password_algo* php_password_algo_find_zval(zend_string *arg_str, zend_long arg_long, bool arg_is_null) { if (arg_is_null) { return php_password_algo_default(); } if (arg_str) { return php_password_algo_find(arg_str); } switch (arg_long) { case 0: return php_password_algo_default(); case 1: return &php_password_algo_bcrypt; #ifdef HAVE_ARGON2LIB case 2: return &php_password_algo_argon2i; case 3: return &php_password_algo_argon2id; #else case 2: { zend_string *n = ZSTR_INIT_LITERAL("argon2i", 0); const php_password_algo* ret = php_password_algo_find(n); zend_string_release(n); return ret; } case 3: { zend_string *n = ZSTR_INIT_LITERAL("argon2id", 0); const php_password_algo* ret = php_password_algo_find(n); zend_string_release(n); return ret; } #endif } return NULL; } zend_string *php_password_algo_extract_ident(const zend_string* hash) { const char *ident, *ident_end; if (!hash || ZSTR_LEN(hash) < 3) { /* Minimum prefix: "$x$" */ return NULL; } ident = ZSTR_VAL(hash) + 1; ident_end = strchr(ident, '$'); if (!ident_end) { /* No terminating '$' */ return NULL; } return zend_string_init(ident, ident_end - ident, 0); } const php_password_algo* php_password_algo_identify_ex(const zend_string* hash, const php_password_algo *default_algo) { const php_password_algo *algo; zend_string *ident = php_password_algo_extract_ident(hash); if (!ident) { return default_algo; } algo = php_password_algo_find(ident); zend_string_release(ident); return (!algo || (algo->valid && !algo->valid(hash))) ? default_algo : algo; } /* {{{ Retrieves information about a given hash */ PHP_FUNCTION(password_get_info) { const php_password_algo *algo; zend_string *hash, *ident; zval options; ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_STR(hash) ZEND_PARSE_PARAMETERS_END(); array_init(return_value); array_init(&options); ident = php_password_algo_extract_ident(hash); algo = php_password_algo_find(ident); if (!algo || (algo->valid && !algo->valid(hash))) { if (ident) { zend_string_release(ident); } add_assoc_null(return_value, "algo"); add_assoc_string(return_value, "algoName", "unknown"); add_assoc_zval(return_value, "options", &options); return; } add_assoc_str(return_value, "algo", php_password_algo_extract_ident(hash)); zend_string_release(ident); add_assoc_string(return_value, "algoName", algo->name); if (algo->get_info) { algo->get_info(&options, hash); } add_assoc_zval(return_value, "options", &options); } /** }}} */ /* {{{ Determines if a given hash requires re-hashing based upon parameters */ PHP_FUNCTION(password_needs_rehash) { const php_password_algo *old_algo, *new_algo; zend_string *hash; zend_string *new_algo_str; zend_long new_algo_long; bool new_algo_is_null; zend_array *options = 0; ZEND_PARSE_PARAMETERS_START(2, 3) Z_PARAM_STR(hash) Z_PARAM_STR_OR_LONG_OR_NULL(new_algo_str, new_algo_long, new_algo_is_null) Z_PARAM_OPTIONAL Z_PARAM_ARRAY_HT(options) ZEND_PARSE_PARAMETERS_END(); new_algo = php_password_algo_find_zval(new_algo_str, new_algo_long, new_algo_is_null); if (!new_algo) { /* Unknown new algorithm, never prompt to rehash. */ RETURN_FALSE; } old_algo = php_password_algo_identify_ex(hash, NULL); if (old_algo != new_algo) { /* Different algorithm preferred, always rehash. */ RETURN_TRUE; } RETURN_BOOL(old_algo->needs_rehash(hash, options)); } /* }}} */ /* {{{ Verify a hash created using crypt() or password_hash() */ PHP_FUNCTION(password_verify) { zend_string *password, *hash; const php_password_algo *algo; ZEND_PARSE_PARAMETERS_START(2, 2) Z_PARAM_STR(password) Z_PARAM_STR(hash) ZEND_PARSE_PARAMETERS_END(); algo = php_password_algo_identify(hash); RETURN_BOOL(algo && (!algo->verify || algo->verify(password, hash))); } /* }}} */ /* {{{ Hash a password */ PHP_FUNCTION(password_hash) { zend_string *password, *digest = NULL; zend_string *algo_str; zend_long algo_long; bool algo_is_null; const php_password_algo *algo; zend_array *options = NULL; ZEND_PARSE_PARAMETERS_START(2, 3) Z_PARAM_STR(password) Z_PARAM_STR_OR_LONG_OR_NULL(algo_str, algo_long, algo_is_null) Z_PARAM_OPTIONAL Z_PARAM_ARRAY_HT(options) ZEND_PARSE_PARAMETERS_END(); algo = php_password_algo_find_zval(algo_str, algo_long, algo_is_null); if (!algo) { zend_argument_value_error(2, "must be a valid password hashing algorithm"); RETURN_THROWS(); } digest = algo->hash(password, options); if (!digest) { if (!EG(exception)) { zend_throw_error(NULL, "Password hashing failed for unknown reason"); } RETURN_THROWS(); } RETURN_NEW_STR(digest); } /* }}} */ /* {{{ */ PHP_FUNCTION(password_algos) { zend_string *algo; ZEND_PARSE_PARAMETERS_NONE(); array_init(return_value); ZEND_HASH_MAP_FOREACH_STR_KEY(&php_password_algos, algo) { add_next_index_str(return_value, zend_string_copy(algo)); } ZEND_HASH_FOREACH_END(); } /* }}} */
19,390
27.432551
130
c
php-src
php-src-master/ext/standard/php_assert.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: Thies C. Arntzen <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef PHP_ASSERT_H #define PHP_ASSERT_H PHP_MINIT_FUNCTION(assert); PHP_MSHUTDOWN_FUNCTION(assert); PHP_RINIT_FUNCTION(assert); PHP_RSHUTDOWN_FUNCTION(assert); PHP_MINFO_FUNCTION(assert); enum { PHP_ASSERT_ACTIVE=1, PHP_ASSERT_CALLBACK, PHP_ASSERT_BAIL, PHP_ASSERT_WARNING, PHP_ASSERT_EXCEPTION }; extern PHPAPI zend_class_entry *assertion_error_ce; #endif /* PHP_ASSERT_H */
1,382
36.378378
75
h
php-src
php-src-master/ext/standard/php_browscap.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: Zeev Suraski <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef PHP_BROWSCAP_H #define PHP_BROWSCAP_H PHP_MINIT_FUNCTION(browscap); PHP_MSHUTDOWN_FUNCTION(browscap); #endif /* PHP_BROWSCAP_H */
1,135
46.333333
75
h
php-src
php-src-master/ext/standard/php_crypt.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: Stig Bakken <[email protected]> | | Zeev Suraski <[email protected]> | | Rasmus Lerdorf <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef PHP_CRYPT_H #define PHP_CRYPT_H PHPAPI zend_string *php_crypt(const char *password, const int pass_len, const char *salt, int salt_len, bool quiet); PHP_MINIT_FUNCTION(crypt); PHP_MSHUTDOWN_FUNCTION(crypt); PHP_RINIT_FUNCTION(crypt); /* sha512 crypt has the maximal salt length of 123 characters */ #define PHP_MAX_SALT_LEN 123 #endif
1,493
47.193548
116
h
php-src
php-src-master/ext/standard/php_crypt_r.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: Pierre Alain Joye <[email protected] | +----------------------------------------------------------------------+ */ /* * License for the Unix md5crypt implementation (md5_crypt): * * ---------------------------------------------------------------------------- * "THE BEER-WARE LICENSE" (Revision 42): * <[email protected]> wrote this file. As long as you retain this notice you * can do whatever you want with this stuff. If we meet some day, and you think * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp * ---------------------------------------------------------------------------- * * from FreeBSD: crypt.c,v 1.5 1996/10/14 08:34:02 phk Exp * via OpenBSD: md5crypt.c,v 1.9 1997/07/23 20:58:27 kstailey Exp * via NetBSD: md5crypt.c,v 1.4.2.1 2002/01/22 19:31:59 he Exp * */ #include "php.h" #include <string.h> #ifdef PHP_WIN32 # include <windows.h> # include <Wincrypt.h> #endif #include "php_crypt_r.h" #include "crypt_freesec.h" #include "ext/standard/md5.h" #ifdef ZTS MUTEX_T php_crypt_extended_init_lock; #endif void php_init_crypt_r(void) { #ifdef ZTS php_crypt_extended_init_lock = tsrm_mutex_alloc(); #endif } void php_shutdown_crypt_r(void) { #ifdef ZTS tsrm_mutex_free(php_crypt_extended_init_lock); #endif } void _crypt_extended_init_r(void) { static int initialized = 0; #ifdef ZTS tsrm_mutex_lock(php_crypt_extended_init_lock); #endif if (!initialized) { initialized = 1; _crypt_extended_init(); } #ifdef ZTS tsrm_mutex_unlock(php_crypt_extended_init_lock); #endif } /* MD5 crypt implementation using the windows CryptoApi */ #define MD5_MAGIC "$1$" #define MD5_MAGIC_LEN 3 static const unsigned char itoa64[] = /* 0 ... 63 => ascii - 64 */ "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; /* Convert a 16/32 bit integer to Base64 string representation */ static void to64(char *s, int32_t v, int n) { while (--n >= 0) { *s++ = itoa64[v & 0x3f]; v >>= 6; } } /* * MD5 password encryption. */ char * php_md5_crypt_r(const char *pw, const char *salt, char *out) { ZEND_TLS char passwd[MD5_HASH_MAX_LEN], *p; const char *sp, *ep; unsigned char final[16]; unsigned int i, sl, pwl; PHP_MD5_CTX ctx, ctx1; uint32_t l; int pl; pwl = strlen(pw); /* Refine the salt first */ sp = salt; /* If it starts with the magic string, then skip that */ if (strncmp(sp, MD5_MAGIC, MD5_MAGIC_LEN) == 0) sp += MD5_MAGIC_LEN; /* It stops at the first '$', max 8 chars */ for (ep = sp; *ep != '\0' && *ep != '$' && ep < (sp + 8); ep++); /* get the length of the true salt */ sl = ep - sp; PHP_MD5Init(&ctx); /* The password first, since that is what is most unknown */ PHP_MD5Update(&ctx, (const unsigned char *)pw, pwl); /* Then our magic string */ PHP_MD5Update(&ctx, (const unsigned char *)MD5_MAGIC, MD5_MAGIC_LEN); /* Then the raw salt */ PHP_MD5Update(&ctx, (const unsigned char *)sp, sl); /* Then just as many characters of the MD5(pw,salt,pw) */ PHP_MD5Init(&ctx1); PHP_MD5Update(&ctx1, (const unsigned char *)pw, pwl); PHP_MD5Update(&ctx1, (const unsigned char *)sp, sl); PHP_MD5Update(&ctx1, (const unsigned char *)pw, pwl); PHP_MD5Final(final, &ctx1); for (pl = pwl; pl > 0; pl -= 16) PHP_MD5Update(&ctx, final, (unsigned int)(pl > 16 ? 16 : pl)); /* Don't leave anything around in vm they could use. */ ZEND_SECURE_ZERO(final, sizeof(final)); /* Then something really weird... */ for (i = pwl; i != 0; i >>= 1) if ((i & 1) != 0) PHP_MD5Update(&ctx, final, 1); else PHP_MD5Update(&ctx, (const unsigned char *)pw, 1); /* Now make the output string */ memcpy(passwd, MD5_MAGIC, MD5_MAGIC_LEN); strlcpy(passwd + MD5_MAGIC_LEN, sp, sl + 1); strcat(passwd, "$"); PHP_MD5Final(final, &ctx); /* * And now, just to make sure things don't run too fast. On a 60 MHz * Pentium this takes 34 msec, so you would need 30 seconds to build * a 1000 entry dictionary... */ for (i = 0; i < 1000; i++) { PHP_MD5Init(&ctx1); if ((i & 1) != 0) PHP_MD5Update(&ctx1, (const unsigned char *)pw, pwl); else PHP_MD5Update(&ctx1, final, 16); if ((i % 3) != 0) PHP_MD5Update(&ctx1, (const unsigned char *)sp, sl); if ((i % 7) != 0) PHP_MD5Update(&ctx1, (const unsigned char *)pw, pwl); if ((i & 1) != 0) PHP_MD5Update(&ctx1, final, 16); else PHP_MD5Update(&ctx1, (const unsigned char *)pw, pwl); PHP_MD5Final(final, &ctx1); } p = passwd + sl + MD5_MAGIC_LEN + 1; l = (final[ 0]<<16) | (final[ 6]<<8) | final[12]; to64(p,l,4); p += 4; l = (final[ 1]<<16) | (final[ 7]<<8) | final[13]; to64(p,l,4); p += 4; l = (final[ 2]<<16) | (final[ 8]<<8) | final[14]; to64(p,l,4); p += 4; l = (final[ 3]<<16) | (final[ 9]<<8) | final[15]; to64(p,l,4); p += 4; l = (final[ 4]<<16) | (final[10]<<8) | final[ 5]; to64(p,l,4); p += 4; l = final[11] ; to64(p,l,2); p += 2; *p = '\0'; /* Don't leave anything around in vm they could use. */ ZEND_SECURE_ZERO(final, sizeof(final)); return (passwd); }
5,886
27.717073
79
c
php-src
php-src-master/ext/standard/php_crypt_r.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: Pierre Alain Joye <[email protected] | +----------------------------------------------------------------------+ */ #ifndef _CRYPT_WIHN32_H_ #define _CRYPT_WIHN32_H_ BEGIN_EXTERN_C() #include "crypt_freesec.h" void php_init_crypt_r(void); void php_shutdown_crypt_r(void); extern void _crypt_extended_init_r(void); PHPAPI char *php_crypt_r (const char *__key, const char *__salt, struct php_crypt_extended_data * __data); #define MD5_HASH_MAX_LEN 120 #include "crypt_blowfish.h" extern char * php_md5_crypt_r(const char *pw, const char *salt, char *out); extern char * php_sha512_crypt_r (const char *key, const char *salt, char *buffer, int buflen); extern char * php_sha256_crypt_r (const char *key, const char *salt, char *buffer, int buflen); END_EXTERN_C() #endif /* _CRYPT_WIHN32_H_ */
1,679
41
106
h
php-src
php-src-master/ext/standard/php_dir.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: Thies C. Arntzen <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef PHP_DIR_H #define PHP_DIR_H /* directory functions */ PHP_MINIT_FUNCTION(dir); PHP_RINIT_FUNCTION(dir); #define PHP_SCANDIR_SORT_ASCENDING 0 #define PHP_SCANDIR_SORT_DESCENDING 1 #define PHP_SCANDIR_SORT_NONE 2 #endif /* PHP_DIR_H */
1,241
41.827586
75
h
php-src
php-src-master/ext/standard/php_ext_syslog.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: Stig Sæther Bakken <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef PHP_EXT_SYSLOG_H #define PHP_EXT_SYSLOG_H #ifdef HAVE_SYSLOG_H #include "php_syslog.h" PHP_MINIT_FUNCTION(syslog); PHP_RINIT_FUNCTION(syslog); #ifdef PHP_WIN32 PHP_RSHUTDOWN_FUNCTION(syslog); #endif PHP_MSHUTDOWN_FUNCTION(syslog); #endif #endif /* PHP_EXT_SYSLOG_H */
1,276
36.558824
75
h
php-src
php-src-master/ext/standard/php_filestat.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: Jim Winstead <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef PHP_FILESTAT_H #define PHP_FILESTAT_H PHP_RINIT_FUNCTION(filestat); PHP_RSHUTDOWN_FUNCTION(filestat); #ifdef PHP_WIN32 #define S_IRUSR S_IREAD #define S_IWUSR S_IWRITE #define S_IXUSR S_IEXEC #define S_IRGRP S_IREAD #define S_IWGRP S_IWRITE #define S_IXGRP S_IEXEC #define S_IROTH S_IREAD #define S_IWOTH S_IWRITE #define S_IXOTH S_IEXEC #undef getgid #define getgroups(a, b) 0 #define getgid() 1 #define getuid() 1 #endif /* Compatibility. */ typedef size_t php_stat_len; PHPAPI void php_clear_stat_cache(bool clear_realpath_cache, const char *filename, size_t filename_len); PHPAPI void php_stat(zend_string *filename, int type, zval *return_value); /* Switches for various filestat functions: */ #define FS_PERMS 0 #define FS_INODE 1 #define FS_SIZE 2 #define FS_OWNER 3 #define FS_GROUP 4 #define FS_ATIME 5 #define FS_MTIME 6 #define FS_CTIME 7 #define FS_TYPE 8 #define FS_IS_W 9 #define FS_IS_R 10 #define FS_IS_X 11 #define FS_IS_FILE 12 #define FS_IS_DIR 13 #define FS_IS_LINK 14 #define FS_EXISTS 15 #define FS_LSTAT 16 #define FS_STAT 17 #define FS_LPERMS 18 #endif /* PHP_FILESTAT_H */
2,155
30.705882
103
h
php-src
php-src-master/ext/standard/php_fopen_wrapper.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: Rasmus Lerdorf <[email protected]> | | Jim Winstead <[email protected]> | | Hartmut Holzgraefe <[email protected]> | +----------------------------------------------------------------------+ */ #include <stdio.h> #include <stdlib.h> #ifdef HAVE_UNISTD_H # include <unistd.h> #endif #include "php.h" #include "php_globals.h" #include "php_standard.h" #include "php_memory_streams.h" #include "php_fopen_wrappers.h" #include "SAPI.h" static ssize_t php_stream_output_write(php_stream *stream, const char *buf, size_t count) /* {{{ */ { PHPWRITE(buf, count); return count; } /* }}} */ static ssize_t php_stream_output_read(php_stream *stream, char *buf, size_t count) /* {{{ */ { stream->eof = 1; return -1; } /* }}} */ static int php_stream_output_close(php_stream *stream, int close_handle) /* {{{ */ { return 0; } /* }}} */ const php_stream_ops php_stream_output_ops = { php_stream_output_write, php_stream_output_read, php_stream_output_close, NULL, /* flush */ "Output", NULL, /* seek */ NULL, /* cast */ NULL, /* stat */ NULL /* set_option */ }; typedef struct php_stream_input { /* {{{ */ php_stream *body; zend_off_t position; } php_stream_input_t; /* }}} */ static ssize_t php_stream_input_write(php_stream *stream, const char *buf, size_t count) /* {{{ */ { return -1; } /* }}} */ static ssize_t php_stream_input_read(php_stream *stream, char *buf, size_t count) /* {{{ */ { php_stream_input_t *input = stream->abstract; ssize_t read; if (!SG(post_read) && SG(read_post_bytes) < (int64_t)(input->position + count)) { /* read requested data from SAPI */ size_t read_bytes = sapi_read_post_block(buf, count); if (read_bytes > 0) { php_stream_seek(input->body, 0, SEEK_END); php_stream_write(input->body, buf, read_bytes); } } if (!input->body->readfilters.head) { /* If the input stream contains filters, it's not really seekable. The input->position is likely to be wrong for unfiltered data. */ php_stream_seek(input->body, input->position, SEEK_SET); } read = php_stream_read(input->body, buf, count); if (!read || read == (size_t) -1) { stream->eof = 1; } else { input->position += read; } return read; } /* }}} */ static int php_stream_input_close(php_stream *stream, int close_handle) /* {{{ */ { efree(stream->abstract); stream->abstract = NULL; return 0; } /* }}} */ static int php_stream_input_flush(php_stream *stream) /* {{{ */ { return -1; } /* }}} */ static int php_stream_input_seek(php_stream *stream, zend_off_t offset, int whence, zend_off_t *newoffset) /* {{{ */ { php_stream_input_t *input = stream->abstract; if (input->body) { int sought = php_stream_seek(input->body, offset, whence); *newoffset = input->position = (input->body)->position; return sought; } return -1; } /* }}} */ const php_stream_ops php_stream_input_ops = { php_stream_input_write, php_stream_input_read, php_stream_input_close, php_stream_input_flush, "Input", php_stream_input_seek, NULL, /* cast */ NULL, /* stat */ NULL /* set_option */ }; static void php_stream_apply_filter_list(php_stream *stream, char *filterlist, int read_chain, int write_chain) /* {{{ */ { char *p, *token = NULL; php_stream_filter *temp_filter; p = php_strtok_r(filterlist, "|", &token); while (p) { php_url_decode(p, strlen(p)); if (read_chain) { if ((temp_filter = php_stream_filter_create(p, NULL, php_stream_is_persistent(stream)))) { php_stream_filter_append(&stream->readfilters, temp_filter); } else { php_error_docref(NULL, E_WARNING, "Unable to create filter (%s)", p); } } if (write_chain) { if ((temp_filter = php_stream_filter_create(p, NULL, php_stream_is_persistent(stream)))) { php_stream_filter_append(&stream->writefilters, temp_filter); } else { php_error_docref(NULL, E_WARNING, "Unable to create filter (%s)", p); } } p = php_strtok_r(NULL, "|", &token); } } /* }}} */ php_stream * php_stream_url_wrap_php(php_stream_wrapper *wrapper, const char *path, const char *mode, int options, zend_string **opened_path, php_stream_context *context STREAMS_DC) /* {{{ */ { int fd = -1; int mode_rw = 0; php_stream * stream = NULL; char *p, *token = NULL, *pathdup; zend_long max_memory; FILE *file = NULL; #ifdef PHP_WIN32 int pipe_requested = 0; #endif if (!strncasecmp(path, "php://", 6)) { path += 6; } if (!strncasecmp(path, "temp", 4)) { path += 4; max_memory = PHP_STREAM_MAX_MEM; if (!strncasecmp(path, "/maxmemory:", 11)) { path += 11; max_memory = ZEND_STRTOL(path, NULL, 10); if (max_memory < 0) { zend_argument_value_error(2, "must be greater than or equal to 0"); return NULL; } } mode_rw = php_stream_mode_from_str(mode); return php_stream_temp_create(mode_rw, max_memory); } if (!strcasecmp(path, "memory")) { mode_rw = php_stream_mode_from_str(mode); return php_stream_memory_create(mode_rw); } if (!strcasecmp(path, "output")) { return php_stream_alloc(&php_stream_output_ops, NULL, 0, "wb"); } if (!strcasecmp(path, "input")) { php_stream_input_t *input; if ((options & STREAM_OPEN_FOR_INCLUDE) && !PG(allow_url_include) ) { if (options & REPORT_ERRORS) { php_error_docref(NULL, E_WARNING, "URL file-access is disabled in the server configuration"); } return NULL; } input = ecalloc(1, sizeof(*input)); if ((input->body = SG(request_info).request_body)) { php_stream_rewind(input->body); } else { input->body = php_stream_temp_create_ex(TEMP_STREAM_DEFAULT, SAPI_POST_BLOCK_SIZE, PG(upload_tmp_dir)); SG(request_info).request_body = input->body; } return php_stream_alloc(&php_stream_input_ops, input, 0, "rb"); } if (!strcasecmp(path, "stdin")) { if ((options & STREAM_OPEN_FOR_INCLUDE) && !PG(allow_url_include) ) { if (options & REPORT_ERRORS) { php_error_docref(NULL, E_WARNING, "URL file-access is disabled in the server configuration"); } return NULL; } if (!strcmp(sapi_module.name, "cli")) { static int cli_in = 0; fd = STDIN_FILENO; if (cli_in) { fd = dup(fd); } else { cli_in = 1; file = stdin; } } else { fd = dup(STDIN_FILENO); } #ifdef PHP_WIN32 pipe_requested = 1; #endif } else if (!strcasecmp(path, "stdout")) { if (!strcmp(sapi_module.name, "cli")) { static int cli_out = 0; fd = STDOUT_FILENO; if (cli_out++) { fd = dup(fd); } else { cli_out = 1; file = stdout; } } else { fd = dup(STDOUT_FILENO); } #ifdef PHP_WIN32 pipe_requested = 1; #endif } else if (!strcasecmp(path, "stderr")) { if (!strcmp(sapi_module.name, "cli")) { static int cli_err = 0; fd = STDERR_FILENO; if (cli_err++) { fd = dup(fd); } else { cli_err = 1; file = stderr; } } else { fd = dup(STDERR_FILENO); } #ifdef PHP_WIN32 pipe_requested = 1; #endif } else if (!strncasecmp(path, "fd/", 3)) { const char *start; char *end; zend_long fildes_ori; int dtablesize; if (strcmp(sapi_module.name, "cli")) { if (options & REPORT_ERRORS) { php_error_docref(NULL, E_WARNING, "Direct access to file descriptors is only available from command-line PHP"); } return NULL; } if ((options & STREAM_OPEN_FOR_INCLUDE) && !PG(allow_url_include) ) { if (options & REPORT_ERRORS) { php_error_docref(NULL, E_WARNING, "URL file-access is disabled in the server configuration"); } return NULL; } start = &path[3]; fildes_ori = ZEND_STRTOL(start, &end, 10); if (end == start || *end != '\0') { php_stream_wrapper_log_error(wrapper, options, "php://fd/ stream must be specified in the form php://fd/<orig fd>"); return NULL; } #ifdef HAVE_UNISTD_H dtablesize = getdtablesize(); #else dtablesize = INT_MAX; #endif if (fildes_ori < 0 || fildes_ori >= dtablesize) { php_stream_wrapper_log_error(wrapper, options, "The file descriptors must be non-negative numbers smaller than %d", dtablesize); return NULL; } fd = dup((int)fildes_ori); if (fd == -1) { php_stream_wrapper_log_error(wrapper, options, "Error duping file descriptor " ZEND_LONG_FMT "; possibly it doesn't exist: " "[%d]: %s", fildes_ori, errno, strerror(errno)); return NULL; } } else if (!strncasecmp(path, "filter/", 7)) { /* Save time/memory when chain isn't specified */ if (strchr(mode, 'r') || strchr(mode, '+')) { mode_rw |= PHP_STREAM_FILTER_READ; } if (strchr(mode, 'w') || strchr(mode, '+') || strchr(mode, 'a')) { mode_rw |= PHP_STREAM_FILTER_WRITE; } pathdup = estrndup(path + 6, strlen(path + 6)); p = strstr(pathdup, "/resource="); if (!p) { zend_throw_error(NULL, "No URL resource specified"); efree(pathdup); return NULL; } if (!(stream = php_stream_open_wrapper(p + 10, mode, options, opened_path))) { efree(pathdup); return NULL; } *p = '\0'; p = php_strtok_r(pathdup + 1, "/", &token); while (p) { if (!strncasecmp(p, "read=", 5)) { php_stream_apply_filter_list(stream, p + 5, 1, 0); } else if (!strncasecmp(p, "write=", 6)) { php_stream_apply_filter_list(stream, p + 6, 0, 1); } else { php_stream_apply_filter_list(stream, p, mode_rw & PHP_STREAM_FILTER_READ, mode_rw & PHP_STREAM_FILTER_WRITE); } p = php_strtok_r(NULL, "/", &token); } efree(pathdup); if (EG(exception)) { php_stream_close(stream); return NULL; } return stream; } else { /* invalid php://thingy */ php_error_docref(NULL, E_WARNING, "Invalid php:// URL specified"); return NULL; } /* must be stdin, stderr or stdout */ if (fd == -1) { /* failed to dup */ return NULL; } #if defined(S_IFSOCK) && !defined(PHP_WIN32) do { zend_stat_t st = {0}; memset(&st, 0, sizeof(st)); if (zend_fstat(fd, &st) == 0 && (st.st_mode & S_IFMT) == S_IFSOCK) { stream = php_stream_sock_open_from_socket(fd, NULL); if (stream) { stream->ops = &php_stream_socket_ops; return stream; } } } while (0); #endif if (file) { stream = php_stream_fopen_from_file(file, mode); } else { stream = php_stream_fopen_from_fd(fd, mode, NULL); if (stream == NULL) { close(fd); } } #ifdef PHP_WIN32 if (pipe_requested && stream && context) { zval *blocking_pipes = php_stream_context_get_option(context, "pipe", "blocking"); if (blocking_pipes) { php_stream_set_option(stream, PHP_STREAM_OPTION_PIPE_BLOCKING, zval_get_long(blocking_pipes), NULL); } } #endif return stream; } /* }}} */ static const php_stream_wrapper_ops php_stdio_wops = { php_stream_url_wrap_php, NULL, /* close */ NULL, /* fstat */ NULL, /* stat */ NULL, /* opendir */ "PHP", NULL, /* unlink */ NULL, /* rename */ NULL, /* mkdir */ NULL, /* rmdir */ NULL }; PHPAPI const php_stream_wrapper php_stream_php_wrapper = { &php_stdio_wops, NULL, 0, /* is_url */ };
11,756
25.302013
121
c
php-src
php-src-master/ext/standard/php_http.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: Sara Golemon <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef PHP_HTTP_H #define PHP_HTTP_H #include "php.h" #include "zend_types.h" /* for zend_string */ #include "zend_smart_str.h" PHPAPI void php_url_encode_hash_ex(HashTable *ht, smart_str *formstr, const char *num_prefix, size_t num_prefix_len, const zend_string *key_prefix, zval *type, const zend_string *arg_sep, int enc_type); #endif
1,349
44
75
h
php-src
php-src-master/ext/standard/php_image.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: Rasmus Lerdorf <[email protected]> | | Marcus Boerger <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef PHP_IMAGE_H #define PHP_IMAGE_H /* {{{ enum image_filetype This enum is used to have ext/standard/image.c and ext/exif/exif.c use the same constants for file types. */ typedef enum { IMAGE_FILETYPE_UNKNOWN=0, IMAGE_FILETYPE_GIF=1, IMAGE_FILETYPE_JPEG, IMAGE_FILETYPE_PNG, IMAGE_FILETYPE_SWF, IMAGE_FILETYPE_PSD, IMAGE_FILETYPE_BMP, IMAGE_FILETYPE_TIFF_II, /* intel */ IMAGE_FILETYPE_TIFF_MM, /* motorola */ IMAGE_FILETYPE_JPC, IMAGE_FILETYPE_JP2, IMAGE_FILETYPE_JPX, IMAGE_FILETYPE_JB2, IMAGE_FILETYPE_SWC, IMAGE_FILETYPE_IFF, IMAGE_FILETYPE_WBMP, /* IMAGE_FILETYPE_JPEG2000 is a userland alias for IMAGE_FILETYPE_JPC */ IMAGE_FILETYPE_XBM, IMAGE_FILETYPE_ICO, IMAGE_FILETYPE_WEBP, IMAGE_FILETYPE_AVIF, /* WHEN EXTENDING: PLEASE ALSO REGISTER IN basic_function.stub.php */ IMAGE_FILETYPE_COUNT } image_filetype; /* }}} */ PHPAPI int php_getimagetype(php_stream *stream, const char *input, char *filetype); PHPAPI char * php_image_type_to_mime_type(int image_type); PHPAPI bool php_is_image_avif(php_stream *stream); #endif /* PHP_IMAGE_H */
2,173
35.847458
83
h
php-src
php-src-master/ext/standard/php_incomplete_class.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: Sascha Schumann <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef PHP_INCOMPLETE_CLASS_H #define PHP_INCOMPLETE_CLASS_H #include "ext/standard/basic_functions.h" extern PHPAPI zend_class_entry *php_ce_incomplete_class; #define PHP_IC_ENTRY php_ce_incomplete_class #define PHP_SET_CLASS_ATTRIBUTES(struc) \ /* OBJECTS_FIXME: Fix for new object model */ \ if (Z_OBJCE_P(struc) == php_ce_incomplete_class) { \ class_name = php_lookup_class_name(Z_OBJ_P(struc)); \ if (!class_name) { \ class_name = zend_string_init(INCOMPLETE_CLASS, sizeof(INCOMPLETE_CLASS) - 1, 0); \ } \ incomplete_class = 1; \ } else { \ class_name = zend_string_copy(Z_OBJCE_P(struc)->name); \ } #define PHP_CLEANUP_CLASS_ATTRIBUTES() \ zend_string_release_ex(class_name, 0) #define PHP_CLASS_ATTRIBUTES \ zend_string *class_name; \ bool incomplete_class ZEND_ATTRIBUTE_UNUSED = 0 #define INCOMPLETE_CLASS "__PHP_Incomplete_Class" #define MAGIC_MEMBER "__PHP_Incomplete_Class_Name" #ifdef __cplusplus extern "C" { #endif PHPAPI void php_register_incomplete_class_handlers(void); PHPAPI zend_string *php_lookup_class_name(zend_object *object); PHPAPI void php_store_class_name(zval *object, zend_string *name); #ifdef __cplusplus }; #endif #endif
2,202
35.114754
86
h
php-src
php-src-master/ext/standard/php_mail.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: Rasmus Lerdorf <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef PHP_MAIL_H #define PHP_MAIL_H PHP_MINFO_FUNCTION(mail); PHPAPI zend_string *php_mail_build_headers(HashTable *headers); PHPAPI extern int php_mail(const char *to, const char *subject, const char *message, const char *headers, const char *extra_cmd); #define PHP_MAIL_BUILD_HEADER_CHECK(target, s, key, val) \ do { \ if (Z_TYPE_P(val) == IS_STRING) { \ php_mail_build_headers_elem(&s, key, val); \ } else if (Z_TYPE_P(val) == IS_ARRAY) { \ if (zend_string_equals_literal_ci(key, target)) { \ zend_type_error("Header \"%s\" must be of type string, array given", target); \ break; \ } \ php_mail_build_headers_elems(&s, key, val); \ } else { \ zend_type_error("Header \"%s\" must be of type array|string, %s given", ZSTR_VAL(key), zend_zval_value_name(val)); \ } \ } while(0) #define PHP_MAIL_BUILD_HEADER_DEFAULT(s, key, val) \ do { \ if (Z_TYPE_P(val) == IS_STRING) { \ php_mail_build_headers_elem(&s, key, val); \ } else if (Z_TYPE_P(val) == IS_ARRAY) { \ php_mail_build_headers_elems(&s, key, val); \ } else { \ zend_type_error("Header \"%s\" must be of type array|string, %s given", ZSTR_VAL(key), zend_zval_value_name(val)); \ } \ } while(0) #endif /* PHP_MAIL_H */
2,209
39.925926
129
h
php-src
php-src-master/ext/standard/php_net.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: Sara Golemon <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef PHP_NET_H #define PHP_NET_H #include "php.h" #include "php_network.h" PHPAPI zend_string* php_inet_ntop(const struct sockaddr *addr); #endif /* PHP_NET_H */
1,163
43.769231
75
h
php-src
php-src-master/ext/standard/php_password.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: Anthony Ferrara <[email protected]> | | Charles R. Portwood II <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef PHP_PASSWORD_H #define PHP_PASSWORD_H PHP_MINIT_FUNCTION(password); PHP_MSHUTDOWN_FUNCTION(password); #define PHP_PASSWORD_DEFAULT PHP_PASSWORD_BCRYPT #define PHP_PASSWORD_BCRYPT_COST 10 #ifdef HAVE_ARGON2LIB /** * When updating these values, synchronize ext/sodium/sodium_pwhash.c values. * Note that libargon expresses memlimit in KB, while libsoidum uses bytes. */ #define PHP_PASSWORD_ARGON2_MEMORY_COST (64 << 10) #define PHP_PASSWORD_ARGON2_TIME_COST 4 #define PHP_PASSWORD_ARGON2_THREADS 1 #endif typedef struct _php_password_algo { const char *name; zend_string *(*hash)(const zend_string *password, zend_array *options); bool (*verify)(const zend_string *password, const zend_string *hash); bool (*needs_rehash)(const zend_string *password, zend_array *options); int (*get_info)(zval *return_value, const zend_string *hash); bool (*valid)(const zend_string *hash); } php_password_algo; extern const php_password_algo php_password_algo_bcrypt; #ifdef HAVE_ARGON2LIB extern const php_password_algo php_password_algo_argon2i; extern const php_password_algo php_password_algo_argon2id; #endif PHPAPI int php_password_algo_register(const char*, const php_password_algo*); PHPAPI void php_password_algo_unregister(const char*); PHPAPI const php_password_algo* php_password_algo_default(void); PHPAPI zend_string *php_password_algo_extract_ident(const zend_string*); PHPAPI const php_password_algo* php_password_algo_find(const zend_string*); PHPAPI const php_password_algo* php_password_algo_identify_ex(const zend_string*, const php_password_algo*); static inline const php_password_algo* php_password_algo_identify(const zend_string *hash) { return php_password_algo_identify_ex(hash, php_password_algo_default()); } #endif
2,830
42.553846
108
h
php-src
php-src-master/ext/standard/php_smart_string.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: Sascha Schumann <[email protected]> | | Xinchen Hui <[email protected]> | +----------------------------------------------------------------------+ */ /* Header moved to Zend. This file is retained for BC. */ #include "zend_smart_string.h"
1,161
57.1
75
h
php-src
php-src-master/ext/standard/php_smart_string_public.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: Sascha Schumann <[email protected]> | | Xinchen Hui <[email protected]> | +----------------------------------------------------------------------+ */ /* Header moved to Zend. This file is retained for BC. */ #include "zend_smart_string_public.h"
1,168
57.45
75
h
php-src
php-src-master/ext/standard/php_standard.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: | +----------------------------------------------------------------------+ */ #include "basic_functions.h" #include "php_math.h" #include "php_string.h" #include "base64.h" #include "php_dir.h" #include "php_dns.h" #include "php_mail.h" #include "md5.h" #include "sha1.h" #include "html.h" #include "exec.h" #include "file.h" #include "php_ext_syslog.h" #include "php_filestat.h" #include "php_browscap.h" #include "pack.h" #include "datetime.h" #include "url.h" #include "pageinfo.h" #include "fsock.h" #include "php_image.h" #include "info.h" #include "php_var.h" #include "quot_print.h" #include "dl.h" #include "php_crypt.h" #include "head.h" #include "php_output.h" #include "php_array.h" #include "php_assert.h" #include "php_versioning.h" #include "php_password.h" #include "php_version.h" #define PHP_STANDARD_VERSION PHP_VERSION #define phpext_standard_ptr basic_functions_module_ptr PHP_MINIT_FUNCTION(standard_filters); PHP_MSHUTDOWN_FUNCTION(standard_filters);
1,892
32.803571
75
h
php-src
php-src-master/ext/standard/php_string.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: Rasmus Lerdorf <[email protected]> | | Stig Sæther Bakken <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef PHP_STRING_H #define PHP_STRING_H # include "ext/random/php_random.h" #ifdef ZTS PHP_MINIT_FUNCTION(localeconv); PHP_MSHUTDOWN_FUNCTION(localeconv); #endif #ifdef ZEND_INTRIN_SSE4_2_FUNC_PTR PHP_MINIT_FUNCTION(string_intrin); #endif #define strnatcmp(a, b) \ strnatcmp_ex(a, strlen(a), b, strlen(b), 0) #define strnatcasecmp(a, b) \ strnatcmp_ex(a, strlen(a), b, strlen(b), 1) PHPAPI int strnatcmp_ex(char const *a, size_t a_len, char const *b, size_t b_len, bool is_case_insensitive); PHPAPI struct lconv *localeconv_r(struct lconv *out); PHPAPI char *php_strtoupper(char *s, size_t len); PHPAPI char *php_strtolower(char *s, size_t len); PHPAPI zend_string *php_string_toupper(zend_string *s); PHPAPI zend_string *php_string_tolower(zend_string *s); PHPAPI char *php_strtr(char *str, size_t len, const char *str_from, const char *str_to, size_t trlen); PHPAPI zend_string *php_addslashes(zend_string *str); PHPAPI void php_stripslashes(zend_string *str); PHPAPI zend_string *php_addcslashes_str(const char *str, size_t len, const char *what, size_t what_len); PHPAPI zend_string *php_addcslashes(zend_string *str, const char *what, size_t what_len); PHPAPI void php_stripcslashes(zend_string *str); PHPAPI zend_string *php_basename(const char *s, size_t len, const char *suffix, size_t sufflen); PHPAPI size_t php_dirname(char *str, size_t len); PHPAPI char *php_stristr(char *s, char *t, size_t s_len, size_t t_len); PHPAPI zend_string *php_str_to_str(const char *haystack, size_t length, const char *needle, size_t needle_len, const char *str, size_t str_len); PHPAPI zend_string *php_trim(zend_string *str, const char *what, size_t what_len, int mode); PHPAPI size_t php_strip_tags(char *rbuf, size_t len, const char *allow, size_t allow_len); PHPAPI size_t php_strip_tags_ex(char *rbuf, size_t len, const char *allow, size_t allow_len, bool allow_tag_spaces); PHPAPI void php_implode(const zend_string *delim, HashTable *arr, zval *return_value); PHPAPI void php_explode(const zend_string *delim, zend_string *str, zval *return_value, zend_long limit); PHPAPI size_t php_strspn(const char *s1, const char *s2, const char *s1_end, const char *s2_end); PHPAPI size_t php_strcspn(const char *s1, const char *s2, const char *s1_end, const char *s2_end); PHPAPI int string_natural_compare_function_ex(zval *result, zval *op1, zval *op2, bool case_insensitive); PHPAPI int string_natural_compare_function(zval *result, zval *op1, zval *op2); PHPAPI int string_natural_case_compare_function(zval *result, zval *op1, zval *op2); PHPAPI bool php_binary_string_shuffle(const php_random_algo *algo, php_random_status *status, char *str, zend_long len); #ifdef _REENTRANT # ifdef PHP_WIN32 # include <wchar.h> # endif # define php_mblen(ptr, len) ((int) mbrlen(ptr, len, &BG(mblen_state))) # define php_mb_reset() memset(&BG(mblen_state), 0, sizeof(BG(mblen_state))) #else # define php_mblen(ptr, len) mblen(ptr, len) # define php_mb_reset() php_ignore_value(mblen(NULL, 0)) #endif #define PHP_STR_PAD_LEFT 0 #define PHP_STR_PAD_RIGHT 1 #define PHP_STR_PAD_BOTH 2 #define PHP_PATHINFO_DIRNAME 1 #define PHP_PATHINFO_BASENAME 2 #define PHP_PATHINFO_EXTENSION 4 #define PHP_PATHINFO_FILENAME 8 #define PHP_PATHINFO_ALL (PHP_PATHINFO_DIRNAME | PHP_PATHINFO_BASENAME | PHP_PATHINFO_EXTENSION | PHP_PATHINFO_FILENAME) #define PHP_STR_STRSPN 0 #define PHP_STR_STRCSPN 1 #endif /* PHP_STRING_H */
4,489
48.340659
120
h
php-src
php-src-master/ext/standard/php_uuencode.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: Ilia Alshanetsky <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef PHP_UUENCODE_H #define PHP_UUENCODE_H PHPAPI zend_string *php_uudecode(const char *src, size_t src_len); PHPAPI zend_string *php_uuencode(const char *src, size_t src_len); #endif /* PHP_UUENCODE_H */
1,205
49.25
75
h
php-src
php-src-master/ext/standard/php_versioning.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: Stig Sæther Bakken <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef PHP_VERSIONING_H #define PHP_VERSIONING_H #include "ext/standard/basic_functions.h" PHPAPI char *php_canonicalize_version(const char *); PHPAPI int php_version_compare(const char *, const char *); #endif
1,210
45.576923
75
h
php-src
php-src-master/ext/standard/proc_open.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: Wez Furlong <[email protected]> | +----------------------------------------------------------------------+ */ #ifdef PHP_WIN32 typedef HANDLE php_file_descriptor_t; typedef DWORD php_process_id_t; # define PHP_INVALID_FD INVALID_HANDLE_VALUE #else typedef int php_file_descriptor_t; typedef pid_t php_process_id_t; # define PHP_INVALID_FD (-1) #endif /* Environment block under Win32 is a NUL terminated sequence of NUL terminated * name=value strings. * Under Unix, it is an argv style array. */ typedef struct _php_process_env { char *envp; #ifndef PHP_WIN32 char **envarray; #endif } php_process_env; typedef struct _php_process_handle { php_process_id_t child; #ifdef PHP_WIN32 HANDLE childHandle; #endif int npipes; zend_resource **pipes; zend_string *command; php_process_env env; #if HAVE_SYS_WAIT_H /* We can only request the status once before it becomes unavailable. * Cache the result so we can request it multiple times. */ int cached_exit_wait_status_value; bool has_cached_exit_wait_status; #endif } php_process_handle;
1,939
35.603774
79
h
php-src
php-src-master/ext/standard/quot_print.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: Kirill Maximov <[email protected]> | +----------------------------------------------------------------------+ */ #include <stdlib.h> #ifdef HAVE_UNISTD_H #include <unistd.h> #endif #include <string.h> #include <errno.h> #include "php.h" #include "quot_print.h" #include <stdio.h> /* * Converting HEX char to INT value */ static char php_hex2int(int c) /* {{{ */ { if (isdigit(c)) { return c - '0'; } else if (c >= 'A' && c <= 'F') { return c - 'A' + 10; } else if (c >= 'a' && c <= 'f') { return c - 'a' + 10; } else { return -1; } } /* }}} */ PHPAPI zend_string *php_quot_print_decode(const unsigned char *str, size_t length, int replace_us_by_ws) /* {{{ */ { size_t i; unsigned const char *p1; unsigned char *p2; unsigned int h_nbl, l_nbl; size_t decoded_len, buf_size; zend_string *retval; static unsigned int hexval_tbl[256] = { 64, 64, 64, 64, 64, 64, 64, 64, 64, 32, 16, 64, 64, 16, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 32, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 64, 64, 64, 64, 64, 64, 64, 10, 11, 12, 13, 14, 15, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 10, 11, 12, 13, 14, 15, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 }; if (replace_us_by_ws) { replace_us_by_ws = '_'; } i = length, p1 = str; buf_size = length; while (i > 1 && *p1 != '\0') { if (*p1 == '=') { buf_size -= 2; p1++; i--; } p1++; i--; } retval = zend_string_alloc(buf_size, 0); i = length; p1 = str; p2 = (unsigned char*)ZSTR_VAL(retval); decoded_len = 0; while (i > 0 && *p1 != '\0') { if (*p1 == '=') { i--, p1++; if (i == 0 || *p1 == '\0') { break; } h_nbl = hexval_tbl[*p1]; if (h_nbl < 16) { /* next char should be a hexadecimal digit */ if ((--i) == 0 || (l_nbl = hexval_tbl[*(++p1)]) >= 16) { efree(retval); return NULL; } *(p2++) = (h_nbl << 4) | l_nbl, decoded_len++; i--, p1++; } else if (h_nbl < 64) { /* soft line break */ while (h_nbl == 32) { if (--i == 0 || (h_nbl = hexval_tbl[*(++p1)]) == 64) { efree(retval); return NULL; } } if (p1[0] == '\r' && i >= 2 && p1[1] == '\n') { i--, p1++; } i--, p1++; } else { efree(retval); return NULL; } } else { *(p2++) = (replace_us_by_ws == *p1 ? '\x20': *p1); i--, p1++, decoded_len++; } } *p2 = '\0'; ZSTR_LEN(retval) = decoded_len; return retval; } /* }}} */ #define PHP_QPRINT_MAXL 75 PHPAPI zend_string *php_quot_print_encode(const unsigned char *str, size_t length) /* {{{ */ { zend_ulong lp = 0; unsigned char c, *d; char *hex = "0123456789ABCDEF"; zend_string *ret; ret = zend_string_safe_alloc(3, (length + (((3 * length)/(PHP_QPRINT_MAXL-9)) + 1)), 0, 0); d = (unsigned char*)ZSTR_VAL(ret); while (length--) { if (((c = *str++) == '\015') && (*str == '\012') && length > 0) { *d++ = '\015'; *d++ = *str++; length--; lp = 0; } else { if (iscntrl (c) || (c == 0x7f) || (c & 0x80) || (c == '=') || ((c == ' ') && (*str == '\015'))) { if ((((lp+= 3) > PHP_QPRINT_MAXL) && (c <= 0x7f)) || ((c > 0x7f) && (c <= 0xdf) && ((lp + 3) > PHP_QPRINT_MAXL)) || ((c > 0xdf) && (c <= 0xef) && ((lp + 6) > PHP_QPRINT_MAXL)) || ((c > 0xef) && (c <= 0xf4) && ((lp + 9) > PHP_QPRINT_MAXL))) { *d++ = '='; *d++ = '\015'; *d++ = '\012'; lp = 3; } *d++ = '='; *d++ = hex[c >> 4]; *d++ = hex[c & 0xf]; } else { if ((++lp) > PHP_QPRINT_MAXL) { *d++ = '='; *d++ = '\015'; *d++ = '\012'; lp = 1; } *d++ = c; } } } *d = '\0'; ret = zend_string_truncate(ret, d - (unsigned char*)ZSTR_VAL(ret), 0); return ret; } /* }}} */ /* * * Decoding Quoted-printable string. * */ /* {{{ Convert a quoted-printable string to an 8 bit string */ PHP_FUNCTION(quoted_printable_decode) { zend_string *arg1; char *str_in; zend_string *str_out; size_t i = 0, j = 0, k; ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_STR(arg1) ZEND_PARSE_PARAMETERS_END(); if (ZSTR_LEN(arg1) == 0) { /* shortcut */ RETURN_EMPTY_STRING(); } str_in = ZSTR_VAL(arg1); str_out = zend_string_alloc(ZSTR_LEN(arg1), 0); while (str_in[i]) { switch (str_in[i]) { case '=': if (str_in[i + 1] && str_in[i + 2] && isxdigit((int) str_in[i + 1]) && isxdigit((int) str_in[i + 2])) { ZSTR_VAL(str_out)[j++] = (php_hex2int((int) str_in[i + 1]) << 4) + php_hex2int((int) str_in[i + 2]); i += 3; } else /* check for soft line break according to RFC 2045*/ { k = 1; while (str_in[i + k] && ((str_in[i + k] == 32) || (str_in[i + k] == 9))) { /* Possibly, skip spaces/tabs at the end of line */ k++; } if (!str_in[i + k]) { /* End of line reached */ i += k; } else if ((str_in[i + k] == 13) && (str_in[i + k + 1] == 10)) { /* CRLF */ i += k + 2; } else if ((str_in[i + k] == 13) || (str_in[i + k] == 10)) { /* CR or LF */ i += k + 1; } else { ZSTR_VAL(str_out)[j++] = str_in[i++]; } } break; default: ZSTR_VAL(str_out)[j++] = str_in[i++]; } } ZSTR_VAL(str_out)[j] = '\0'; ZSTR_LEN(str_out) = j; RETVAL_NEW_STR(str_out); } /* }}} */ /* {{{ */ PHP_FUNCTION(quoted_printable_encode) { zend_string *str; zend_string *new_str; ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_STR(str) ZEND_PARSE_PARAMETERS_END(); if (!ZSTR_LEN(str)) { RETURN_EMPTY_STRING(); } new_str = php_quot_print_encode((unsigned char *)ZSTR_VAL(str), ZSTR_LEN(str)); RETURN_STR(new_str); } /* }}} */
7,169
24.884477
114
c
php-src
php-src-master/ext/standard/quot_print.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: Kirill Maximov ([email protected]) | +----------------------------------------------------------------------+ */ #ifndef QUOT_PRINT_H #define QUOT_PRINT_H PHPAPI zend_string *php_quot_print_decode(const unsigned char *str, size_t length, int replace_us_by_ws); PHPAPI zend_string *php_quot_print_encode(const unsigned char *str, size_t length); #endif /* QUOT_PRINT_H */
1,255
51.333333
105
h
php-src
php-src-master/ext/standard/scanf.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: Clayton Collie <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef SCANF_H #define SCANF_H #define SCAN_MAX_ARGS 0xFF /* Maximum number of variable which can be */ /* passed to (f|s)scanf. This is an artificial */ /* upper limit to keep resources in check and */ /* minimize the possibility of exploits */ #define SCAN_SUCCESS SUCCESS #define SCAN_ERROR_EOF -1 /* indicates premature termination of scan */ /* can be caused by bad parameters or format*/ /* string. */ #define SCAN_ERROR_INVALID_FORMAT (SCAN_ERROR_EOF - 1) #define SCAN_ERROR_WRONG_PARAM_COUNT (SCAN_ERROR_INVALID_FORMAT - 1) /* * The following are here solely for the benefit of the scanf type functions * e.g. fscanf */ PHPAPI int ValidateFormat(char *format, int numVars, int *totalVars); PHPAPI int php_sscanf_internal(char *string,char *format,int argCount,zval *args, int varStart, zval *return_value); #endif /* SCANF_H */
1,997
45.465116
83
h
php-src
php-src-master/ext/standard/sha1.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: Stefan Esser <[email protected]> | +----------------------------------------------------------------------+ */ #include "php.h" /* This code is heavily based on the PHP md5 implementation */ #include "sha1.h" #include "md5.h" PHPAPI void make_sha1_digest(char *sha1str, const unsigned char *digest) { make_digest_ex(sha1str, digest, 20); } /* {{{ Calculate the sha1 hash of a string */ PHP_FUNCTION(sha1) { zend_string *arg; bool raw_output = 0; PHP_SHA1_CTX context; unsigned char digest[20]; ZEND_PARSE_PARAMETERS_START(1, 2) Z_PARAM_STR(arg) Z_PARAM_OPTIONAL Z_PARAM_BOOL(raw_output) ZEND_PARSE_PARAMETERS_END(); PHP_SHA1Init(&context); PHP_SHA1Update(&context, (unsigned char *) ZSTR_VAL(arg), ZSTR_LEN(arg)); PHP_SHA1Final(digest, &context); if (raw_output) { RETURN_STRINGL((char *) digest, 20); } else { RETVAL_NEW_STR(zend_string_alloc(40, 0)); make_digest_ex(Z_STRVAL_P(return_value), digest, 20); } } /* }}} */ /* {{{ Calculate the sha1 hash of given filename */ PHP_FUNCTION(sha1_file) { char *arg; size_t arg_len; bool raw_output = 0; unsigned char buf[1024]; unsigned char digest[20]; PHP_SHA1_CTX context; ssize_t n; php_stream *stream; ZEND_PARSE_PARAMETERS_START(1, 2) Z_PARAM_PATH(arg, arg_len) Z_PARAM_OPTIONAL Z_PARAM_BOOL(raw_output) ZEND_PARSE_PARAMETERS_END(); stream = php_stream_open_wrapper(arg, "rb", REPORT_ERRORS, NULL); if (!stream) { RETURN_FALSE; } PHP_SHA1Init(&context); while ((n = php_stream_read(stream, (char *) buf, sizeof(buf))) > 0) { PHP_SHA1Update(&context, buf, n); } PHP_SHA1Final(digest, &context); php_stream_close(stream); if (raw_output) { RETURN_STRINGL((char *) digest, 20); } else { RETVAL_NEW_STR(zend_string_alloc(40, 0)); make_digest_ex(Z_STRVAL_P(return_value), digest, 20); } } /* }}} */ static void SHA1Transform(uint32_t[5], const unsigned char[64]); static void SHA1Encode(unsigned char *, uint32_t *, unsigned int); static void SHA1Decode(uint32_t *, const unsigned char *, unsigned int); 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 }; /* F, G, H and I are basic SHA1 functions. */ #define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z)))) #define G(x, y, z) ((x) ^ (y) ^ (z)) #define H(x, y, z) (((x) & (y)) | ((z) & ((x) | (y)))) #define I(x, y, z) ((x) ^ (y) ^ (z)) /* ROTATE_LEFT rotates x left n bits. */ #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) /* W[i] */ #define W(i) ( tmp=x[(i-3)&15]^x[(i-8)&15]^x[(i-14)&15]^x[i&15], \ (x[i&15]=ROTATE_LEFT(tmp, 1)) ) /* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. */ #define FF(a, b, c, d, e, w) { \ (e) += F ((b), (c), (d)) + (w) + (uint32_t)(0x5A827999); \ (e) += ROTATE_LEFT ((a), 5); \ (b) = ROTATE_LEFT((b), 30); \ } #define GG(a, b, c, d, e, w) { \ (e) += G ((b), (c), (d)) + (w) + (uint32_t)(0x6ED9EBA1); \ (e) += ROTATE_LEFT ((a), 5); \ (b) = ROTATE_LEFT((b), 30); \ } #define HH(a, b, c, d, e, w) { \ (e) += H ((b), (c), (d)) + (w) + (uint32_t)(0x8F1BBCDC); \ (e) += ROTATE_LEFT ((a), 5); \ (b) = ROTATE_LEFT((b), 30); \ } #define II(a, b, c, d, e, w) { \ (e) += I ((b), (c), (d)) + (w) + (uint32_t)(0xCA62C1D6); \ (e) += ROTATE_LEFT ((a), 5); \ (b) = ROTATE_LEFT((b), 30); \ } /* {{{ PHP_SHA1Init * SHA1 initialization. Begins an SHA1 operation, writing a new context. */ PHPAPI void PHP_SHA1InitArgs(PHP_SHA1_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_SHA1Update SHA1 block update operation. Continues an SHA1 message-digest operation, processing another message block, and updating the context. */ PHPAPI void PHP_SHA1Update(PHP_SHA1_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); SHA1Transform(context->state, context->buffer); for (i = partLen; i + 63 < inputLen; i += 64) SHA1Transform(context->state, &input[i]); index = 0; } else i = 0; /* Buffer remaining input */ memcpy ((unsigned char*) & context->buffer[index], (unsigned char*) & input[i], inputLen - i); } /* }}} */ /* {{{ PHP_SHA1Final SHA1 finalization. Ends an SHA1 message-digest operation, writing the the message digest and zeroizing the context. */ PHPAPI void PHP_SHA1Final(unsigned char digest[20], PHP_SHA1_CTX * context) { unsigned char bits[8]; unsigned int index, padLen; /* Save number of bits */ bits[7] = context->count[0] & 0xFF; bits[6] = (context->count[0] >> 8) & 0xFF; bits[5] = (context->count[0] >> 16) & 0xFF; bits[4] = (context->count[0] >> 24) & 0xFF; bits[3] = context->count[1] & 0xFF; bits[2] = (context->count[1] >> 8) & 0xFF; bits[1] = (context->count[1] >> 16) & 0xFF; bits[0] = (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_SHA1Update(context, PADDING, padLen); /* Append length (before padding) */ PHP_SHA1Update(context, bits, 8); /* Store state in digest */ SHA1Encode(digest, context->state, 20); /* Zeroize sensitive information. */ ZEND_SECURE_ZERO((unsigned char*) context, sizeof(*context)); } /* }}} */ /* {{{ SHA1Transform * SHA1 basic transformation. Transforms state based on block. */ static void SHA1Transform(uint32_t state[5], const unsigned char block[64]) { uint32_t a = state[0], b = state[1], c = state[2]; uint32_t d = state[3], e = state[4], x[16], tmp; SHA1Decode(x, block, 64); /* Round 1 */ FF(a, b, c, d, e, x[0]); /* 1 */ FF(e, a, b, c, d, x[1]); /* 2 */ FF(d, e, a, b, c, x[2]); /* 3 */ FF(c, d, e, a, b, x[3]); /* 4 */ FF(b, c, d, e, a, x[4]); /* 5 */ FF(a, b, c, d, e, x[5]); /* 6 */ FF(e, a, b, c, d, x[6]); /* 7 */ FF(d, e, a, b, c, x[7]); /* 8 */ FF(c, d, e, a, b, x[8]); /* 9 */ FF(b, c, d, e, a, x[9]); /* 10 */ FF(a, b, c, d, e, x[10]); /* 11 */ FF(e, a, b, c, d, x[11]); /* 12 */ FF(d, e, a, b, c, x[12]); /* 13 */ FF(c, d, e, a, b, x[13]); /* 14 */ FF(b, c, d, e, a, x[14]); /* 15 */ FF(a, b, c, d, e, x[15]); /* 16 */ FF(e, a, b, c, d, W(16)); /* 17 */ FF(d, e, a, b, c, W(17)); /* 18 */ FF(c, d, e, a, b, W(18)); /* 19 */ FF(b, c, d, e, a, W(19)); /* 20 */ /* Round 2 */ GG(a, b, c, d, e, W(20)); /* 21 */ GG(e, a, b, c, d, W(21)); /* 22 */ GG(d, e, a, b, c, W(22)); /* 23 */ GG(c, d, e, a, b, W(23)); /* 24 */ GG(b, c, d, e, a, W(24)); /* 25 */ GG(a, b, c, d, e, W(25)); /* 26 */ GG(e, a, b, c, d, W(26)); /* 27 */ GG(d, e, a, b, c, W(27)); /* 28 */ GG(c, d, e, a, b, W(28)); /* 29 */ GG(b, c, d, e, a, W(29)); /* 30 */ GG(a, b, c, d, e, W(30)); /* 31 */ GG(e, a, b, c, d, W(31)); /* 32 */ GG(d, e, a, b, c, W(32)); /* 33 */ GG(c, d, e, a, b, W(33)); /* 34 */ GG(b, c, d, e, a, W(34)); /* 35 */ GG(a, b, c, d, e, W(35)); /* 36 */ GG(e, a, b, c, d, W(36)); /* 37 */ GG(d, e, a, b, c, W(37)); /* 38 */ GG(c, d, e, a, b, W(38)); /* 39 */ GG(b, c, d, e, a, W(39)); /* 40 */ /* Round 3 */ HH(a, b, c, d, e, W(40)); /* 41 */ HH(e, a, b, c, d, W(41)); /* 42 */ HH(d, e, a, b, c, W(42)); /* 43 */ HH(c, d, e, a, b, W(43)); /* 44 */ HH(b, c, d, e, a, W(44)); /* 45 */ HH(a, b, c, d, e, W(45)); /* 46 */ HH(e, a, b, c, d, W(46)); /* 47 */ HH(d, e, a, b, c, W(47)); /* 48 */ HH(c, d, e, a, b, W(48)); /* 49 */ HH(b, c, d, e, a, W(49)); /* 50 */ HH(a, b, c, d, e, W(50)); /* 51 */ HH(e, a, b, c, d, W(51)); /* 52 */ HH(d, e, a, b, c, W(52)); /* 53 */ HH(c, d, e, a, b, W(53)); /* 54 */ HH(b, c, d, e, a, W(54)); /* 55 */ HH(a, b, c, d, e, W(55)); /* 56 */ HH(e, a, b, c, d, W(56)); /* 57 */ HH(d, e, a, b, c, W(57)); /* 58 */ HH(c, d, e, a, b, W(58)); /* 59 */ HH(b, c, d, e, a, W(59)); /* 60 */ /* Round 4 */ II(a, b, c, d, e, W(60)); /* 61 */ II(e, a, b, c, d, W(61)); /* 62 */ II(d, e, a, b, c, W(62)); /* 63 */ II(c, d, e, a, b, W(63)); /* 64 */ II(b, c, d, e, a, W(64)); /* 65 */ II(a, b, c, d, e, W(65)); /* 66 */ II(e, a, b, c, d, W(66)); /* 67 */ II(d, e, a, b, c, W(67)); /* 68 */ II(c, d, e, a, b, W(68)); /* 69 */ II(b, c, d, e, a, W(69)); /* 70 */ II(a, b, c, d, e, W(70)); /* 71 */ II(e, a, b, c, d, W(71)); /* 72 */ II(d, e, a, b, c, W(72)); /* 73 */ II(c, d, e, a, b, W(73)); /* 74 */ II(b, c, d, e, a, W(74)); /* 75 */ II(a, b, c, d, e, W(75)); /* 76 */ II(e, a, b, c, d, W(76)); /* 77 */ II(d, e, a, b, c, W(77)); /* 78 */ II(c, d, e, a, b, W(78)); /* 79 */ II(b, c, d, e, a, W(79)); /* 80 */ state[0] += a; state[1] += b; state[2] += c; state[3] += d; state[4] += e; /* Zeroize sensitive information. */ ZEND_SECURE_ZERO((unsigned char*) x, sizeof(x)); } /* }}} */ /* {{{ SHA1Encode Encodes input (uint32_t) into output (unsigned char). Assumes len is a multiple of 4. */ static void SHA1Encode(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] = (unsigned char) ((input[i] >> 24) & 0xff); output[j + 1] = (unsigned char) ((input[i] >> 16) & 0xff); output[j + 2] = (unsigned char) ((input[i] >> 8) & 0xff); output[j + 3] = (unsigned char) (input[i] & 0xff); } } /* }}} */ /* {{{ SHA1Decode Decodes input (unsigned char) into output (uint32_t). Assumes len is a multiple of 4. */ static void SHA1Decode(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 + 3]) | (((uint32_t) input[j + 2]) << 8) | (((uint32_t) input[j + 1]) << 16) | (((uint32_t) input[j]) << 24); } /* }}} */
11,431
28.61658
91
c
php-src
php-src-master/ext/standard/sha1.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: Stefan Esser <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef SHA1_H #define SHA1_H #include "ext/standard/basic_functions.h" /* SHA1 context. */ 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_SHA1_CTX; #define PHP_SHA1_SPEC "l5l2b64." #define PHP_SHA1Init(ctx) PHP_SHA1InitArgs(ctx, NULL) PHPAPI void PHP_SHA1InitArgs(PHP_SHA1_CTX *, ZEND_ATTRIBUTE_UNUSED HashTable *); PHPAPI void PHP_SHA1Update(PHP_SHA1_CTX *, const unsigned char *, size_t); PHPAPI void PHP_SHA1Final(unsigned char[20], PHP_SHA1_CTX *); PHPAPI void make_sha1_digest(char *sha1str, const unsigned char *digest); #endif
1,663
43.972973
80
h
php-src
php-src-master/ext/standard/soundex.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: Bjørn Borud - Guardian Networks AS <[email protected]> | +----------------------------------------------------------------------+ */ #include "php.h" #include <stdlib.h> #include <errno.h> #include <ctype.h> #include "php_string.h" /* Simple soundex algorithm as described by Knuth in TAOCP, vol 3 */ /* {{{ Calculate the soundex key of a string */ PHP_FUNCTION(soundex) { char *str; size_t i, _small, str_len, code, last; char soundex[4 + 1]; static const char soundex_table[26] = {0, /* A */ '1', /* B */ '2', /* C */ '3', /* D */ 0, /* E */ '1', /* F */ '2', /* G */ 0, /* H */ 0, /* I */ '2', /* J */ '2', /* K */ '4', /* L */ '5', /* M */ '5', /* N */ 0, /* O */ '1', /* P */ '2', /* Q */ '6', /* R */ '2', /* S */ '3', /* T */ 0, /* U */ '1', /* V */ 0, /* W */ '2', /* X */ 0, /* Y */ '2'}; /* Z */ ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_STRING(str, str_len) ZEND_PARSE_PARAMETERS_END(); /* build soundex string */ last = -1; for (i = 0, _small = 0; i < str_len && _small < 4; i++) { /* convert chars to upper case and strip non-letter chars */ /* BUG: should also map here accented letters used in non */ /* English words or names (also found in English text!): */ /* esstsett, thorn, n-tilde, c-cedilla, s-caron, ... */ code = toupper((int)(unsigned char)str[i]); if (code >= 'A' && code <= 'Z') { if (_small == 0) { /* remember first valid char */ soundex[_small++] = (char)code; last = soundex_table[code - 'A']; } else { /* ignore sequences of consonants with same soundex */ /* code in trail, and vowels unless they separate */ /* consonant letters */ code = soundex_table[code - 'A']; if (code != last) { if (code != 0) { soundex[_small++] = (char)code; } last = code; } } } } /* pad with '0' and terminate with 0 ;-) */ while (_small < 4) { soundex[_small++] = '0'; } soundex[_small] = '\0'; RETURN_STRINGL(soundex, _small); } /* }}} */
3,014
29.15
75
c
php-src
php-src-master/ext/standard/streamsfuncs.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: Wez Furlong <[email protected]> | +----------------------------------------------------------------------+ */ /* Flags for stream_socket_client */ #define PHP_STREAM_CLIENT_PERSISTENT 1 #define PHP_STREAM_CLIENT_ASYNC_CONNECT 2 #define PHP_STREAM_CLIENT_CONNECT 4
1,137
53.190476
74
h
php-src
php-src-master/ext/standard/strnatcmp.c
/* Modified for PHP by Andrei Zmievski <[email protected]> strnatcmp.c -- Perform 'natural order' comparisons of strings in C. Copyright (C) 2000 by Martin Pool <[email protected]> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include <ctype.h> #include <string.h> #include <stdio.h> #include "php.h" #include "php_string.h" /* {{{ compare_right */ static int compare_right(char const **a, char const *aend, char const **b, char const *bend) { int bias = 0; /* The longest run of digits wins. That aside, the greatest value wins, but we can't know that it will until we've scanned both numbers to know that they have the same magnitude, so we remember it in BIAS. */ for(;; (*a)++, (*b)++) { if ((*a == aend || !isdigit((int)(unsigned char)**a)) && (*b == bend || !isdigit((int)(unsigned char)**b))) return bias; else if (*a == aend || !isdigit((int)(unsigned char)**a)) return -1; else if (*b == bend || !isdigit((int)(unsigned char)**b)) return +1; else if (**a < **b) { if (!bias) bias = -1; } else if (**a > **b) { if (!bias) bias = +1; } } return 0; } /* }}} */ /* {{{ compare_left */ static int compare_left(char const **a, char const *aend, char const **b, char const *bend) { /* Compare two left-aligned numbers: the first to have a different value wins. */ for(;; (*a)++, (*b)++) { if ((*a == aend || !isdigit((int)(unsigned char)**a)) && (*b == bend || !isdigit((int)(unsigned char)**b))) return 0; else if (*a == aend || !isdigit((int)(unsigned char)**a)) return -1; else if (*b == bend || !isdigit((int)(unsigned char)**b)) return +1; else if (**a < **b) return -1; else if (**a > **b) return +1; } return 0; } /* }}} */ /* {{{ strnatcmp_ex */ PHPAPI int strnatcmp_ex(char const *a, size_t a_len, char const *b, size_t b_len, bool is_case_insensitive) { unsigned char ca, cb; char const *ap, *bp; char const *aend = a + a_len, *bend = b + b_len; int fractional, result; if (a_len == 0 || b_len == 0) { return (a_len == b_len ? 0 : (a_len > b_len ? 1 : -1)); } ap = a; bp = b; ca = *ap; cb = *bp; /* skip over leading zeros */ while (ca == '0' && (ap+1 < aend) && isdigit((int)(unsigned char)*(ap+1))) { ca = *++ap; } while (cb == '0' && (bp+1 < bend) && isdigit((int)(unsigned char)*(bp+1))) { cb = *++bp; } while (1) { /* Skip consecutive whitespace */ while (isspace((int)(unsigned char)ca)) { ca = *++ap; } while (isspace((int)(unsigned char)cb)) { cb = *++bp; } /* process run of digits */ if (isdigit((int)(unsigned char)ca) && isdigit((int)(unsigned char)cb)) { fractional = (ca == '0' || cb == '0'); if (fractional) result = compare_left(&ap, aend, &bp, bend); else result = compare_right(&ap, aend, &bp, bend); if (result != 0) return result; else if (ap == aend && bp == bend) /* End of the strings. Let caller sort them out. */ return 0; else if (ap == aend) return -1; else if (bp == bend) return 1; else { /* Keep on comparing from the current point. */ ca = *ap; cb = *bp; } } if (is_case_insensitive) { ca = toupper((int)(unsigned char)ca); cb = toupper((int)(unsigned char)cb); } if (ca < cb) return -1; else if (ca > cb) return +1; ++ap; ++bp; if (ap >= aend && bp >= bend) /* The strings compare the same. Perhaps the caller will want to call strcmp to break the tie. */ return 0; else if (ap >= aend) return -1; else if (bp >= bend) return 1; ca = *ap; cb = *bp; } } /* }}} */
4,400
24.439306
107
c
php-src
php-src-master/ext/standard/syslog.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: Stig Sæther Bakken <[email protected]> | +----------------------------------------------------------------------+ */ #include "php.h" #ifdef HAVE_SYSLOG_H #include "php_ini.h" #include "zend_globals.h" #include <stdlib.h> #ifdef HAVE_UNISTD_H #include <unistd.h> #endif #include <string.h> #include <errno.h> #include <stdio.h> #include "basic_functions.h" #include "php_ext_syslog.h" /* {{{ PHP_MINIT_FUNCTION */ PHP_MINIT_FUNCTION(syslog) { BG(syslog_device)=NULL; return SUCCESS; } /* }}} */ PHP_RINIT_FUNCTION(syslog) { BG(syslog_device) = NULL; return SUCCESS; } #ifdef PHP_WIN32 PHP_RSHUTDOWN_FUNCTION(syslog) { closelog(); return SUCCESS; } #endif PHP_MSHUTDOWN_FUNCTION(syslog) { if (BG(syslog_device)) { free(BG(syslog_device)); BG(syslog_device) = NULL; } return SUCCESS; } /* {{{ Open connection to system logger */ /* ** OpenLog("nettopp", $LOG_PID, $LOG_LOCAL1); ** Syslog($LOG_EMERG, "help me!") ** CloseLog(); */ PHP_FUNCTION(openlog) { char *ident; zend_long option, facility; size_t ident_len; ZEND_PARSE_PARAMETERS_START(3, 3) Z_PARAM_STRING(ident, ident_len) Z_PARAM_LONG(option) Z_PARAM_LONG(facility) ZEND_PARSE_PARAMETERS_END(); if (BG(syslog_device)) { free(BG(syslog_device)); } BG(syslog_device) = zend_strndup(ident, ident_len); php_openlog(BG(syslog_device), option, facility); RETURN_TRUE; } /* }}} */ /* {{{ Close connection to system logger */ PHP_FUNCTION(closelog) { ZEND_PARSE_PARAMETERS_NONE(); php_closelog(); if (BG(syslog_device)) { free(BG(syslog_device)); BG(syslog_device)=NULL; } RETURN_TRUE; } /* }}} */ /* {{{ Generate a system log message */ PHP_FUNCTION(syslog) { zend_long priority; zend_string *message; ZEND_PARSE_PARAMETERS_START(2, 2) Z_PARAM_LONG(priority) Z_PARAM_STR(message) ZEND_PARSE_PARAMETERS_END(); php_syslog_str(priority, message); RETURN_TRUE; } /* }}} */ #endif
2,784
20.929134
75
c
php-src
php-src-master/ext/standard/type.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: Rasmus Lerdorf <[email protected]> | +----------------------------------------------------------------------+ */ #include "php.h" #include "php_incomplete_class.h" /* {{{ Returns the type of the variable */ PHP_FUNCTION(gettype) { zval *arg; zend_string *type; ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_ZVAL(arg) ZEND_PARSE_PARAMETERS_END(); type = zend_zval_get_legacy_type(arg); if (EXPECTED(type)) { RETURN_INTERNED_STR(type); } else { RETURN_STRING("unknown type"); } } /* }}} */ /* {{{ Returns the type of the variable resolving class names */ PHP_FUNCTION(get_debug_type) { zval *arg; const char *name; ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_ZVAL(arg) ZEND_PARSE_PARAMETERS_END(); switch (Z_TYPE_P(arg)) { case IS_NULL: RETURN_INTERNED_STR(ZSTR_KNOWN(ZEND_STR_NULL_LOWERCASE)); case IS_FALSE: case IS_TRUE: RETURN_INTERNED_STR(ZSTR_KNOWN(ZEND_STR_BOOL)); case IS_LONG: RETURN_INTERNED_STR(ZSTR_KNOWN(ZEND_STR_INT)); case IS_DOUBLE: RETURN_INTERNED_STR(ZSTR_KNOWN(ZEND_STR_FLOAT)); case IS_STRING: RETURN_INTERNED_STR(ZSTR_KNOWN(ZEND_STR_STRING)); case IS_ARRAY: RETURN_INTERNED_STR(ZSTR_KNOWN(ZEND_STR_ARRAY)); case IS_OBJECT: if (Z_OBJ_P(arg)->ce->ce_flags & ZEND_ACC_ANON_CLASS) { name = ZSTR_VAL(Z_OBJ_P(arg)->ce->name); RETURN_NEW_STR(zend_string_init(name, strlen(name), 0)); } else { RETURN_STR_COPY(Z_OBJ_P(arg)->ce->name); } case IS_RESOURCE: name = zend_rsrc_list_get_rsrc_type(Z_RES_P(arg)); if (name) { RETURN_NEW_STR(zend_strpprintf(0, "resource (%s)", name)); } else { RETURN_INTERNED_STR(ZSTR_KNOWN(ZEND_STR_CLOSED_RESOURCE)); } default: RETURN_INTERNED_STR(ZSTR_KNOWN(ZEND_STR_UNKNOWN)); } } /* }}} */ /* {{{ Set the type of the variable */ PHP_FUNCTION(settype) { zval *var; zend_string *type; zval tmp, *ptr; ZEND_PARSE_PARAMETERS_START(2, 2) Z_PARAM_ZVAL(var) Z_PARAM_STR(type) ZEND_PARSE_PARAMETERS_END(); ZEND_ASSERT(Z_ISREF_P(var)); if (UNEXPECTED(ZEND_REF_HAS_TYPE_SOURCES(Z_REF_P(var)))) { ZVAL_COPY(&tmp, Z_REFVAL_P(var)); ptr = &tmp; } else { ptr = Z_REFVAL_P(var); } if (zend_string_equals_ci(type, ZSTR_KNOWN(ZEND_STR_INTEGER))) { convert_to_long(ptr); } else if (zend_string_equals_ci(type, ZSTR_KNOWN(ZEND_STR_INT))) { convert_to_long(ptr); } else if (zend_string_equals_ci(type, ZSTR_KNOWN(ZEND_STR_FLOAT))) { convert_to_double(ptr); } else if (zend_string_equals_ci(type, ZSTR_KNOWN(ZEND_STR_DOUBLE))) { /* deprecated */ convert_to_double(ptr); } else if (zend_string_equals_ci(type, ZSTR_KNOWN(ZEND_STR_STRING))) { convert_to_string(ptr); } else if (zend_string_equals_ci(type, ZSTR_KNOWN(ZEND_STR_ARRAY))) { convert_to_array(ptr); } else if (zend_string_equals_ci(type, ZSTR_KNOWN(ZEND_STR_OBJECT))) { convert_to_object(ptr); } else if (zend_string_equals_ci(type, ZSTR_KNOWN(ZEND_STR_BOOL))) { convert_to_boolean(ptr); } else if (zend_string_equals_ci(type, ZSTR_KNOWN(ZEND_STR_BOOLEAN))) { convert_to_boolean(ptr); } else if (zend_string_equals_ci(type, ZSTR_KNOWN(ZEND_STR_NULL_LOWERCASE))) { convert_to_null(ptr); } else { if (ptr == &tmp) { zval_ptr_dtor(&tmp); } if (zend_string_equals_ci(type, ZSTR_KNOWN(ZEND_STR_RESOURCE))) { zend_value_error("Cannot convert to resource type"); } else { zend_argument_value_error(2, "must be a valid type"); } RETURN_THROWS(); } if (ptr == &tmp) { zend_try_assign_typed_ref(Z_REF_P(var), &tmp); } RETVAL_TRUE; } /* }}} */ /* {{{ Get the integer value of a variable using the optional base for the conversion */ PHP_FUNCTION(intval) { zval *num; zend_long base = 10; ZEND_PARSE_PARAMETERS_START(1, 2) Z_PARAM_ZVAL(num) Z_PARAM_OPTIONAL Z_PARAM_LONG(base) ZEND_PARSE_PARAMETERS_END(); if (Z_TYPE_P(num) != IS_STRING || base == 10) { RETVAL_LONG(zval_get_long(num)); return; } if (base == 0 || base == 2) { char *strval = Z_STRVAL_P(num); size_t strlen = Z_STRLEN_P(num); while (isspace(*strval) && strlen) { strval++; strlen--; } /* Length of 3+ covers "0b#" and "-0b" (which results in 0) */ if (strlen > 2) { int offset = 0; if (strval[0] == '-' || strval[0] == '+') { offset = 1; } if (strval[offset] == '0' && (strval[offset + 1] == 'b' || strval[offset + 1] == 'B')) { char *tmpval; strlen -= 2; /* Removing "0b" */ tmpval = emalloc(strlen + 1); /* Place the unary symbol at pos 0 if there was one */ if (offset) { tmpval[0] = strval[0]; } /* Copy the data from after "0b" to the end of the buffer */ memcpy(tmpval + offset, strval + offset + 2, strlen - offset); tmpval[strlen] = 0; RETVAL_LONG(ZEND_STRTOL(tmpval, NULL, 2)); efree(tmpval); return; } } } RETVAL_LONG(ZEND_STRTOL(Z_STRVAL_P(num), NULL, base)); } /* }}} */ /* {{{ Get the float value of a variable */ PHP_FUNCTION(floatval) { zval *num; ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_ZVAL(num) ZEND_PARSE_PARAMETERS_END(); RETURN_DOUBLE(zval_get_double(num)); } /* }}} */ /* {{{ Get the boolean value of a variable */ PHP_FUNCTION(boolval) { zval *value; ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_ZVAL(value) ZEND_PARSE_PARAMETERS_END(); RETURN_BOOL(zend_is_true(value)); } /* }}} */ /* {{{ Get the string value of a variable */ PHP_FUNCTION(strval) { zval *value; ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_ZVAL(value) ZEND_PARSE_PARAMETERS_END(); RETVAL_STR(zval_get_string(value)); } /* }}} */ static inline void php_is_type(INTERNAL_FUNCTION_PARAMETERS, int type) { zval *arg; ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_ZVAL(arg) ZEND_PARSE_PARAMETERS_END(); if (Z_TYPE_P(arg) == type) { if (type == IS_RESOURCE) { const char *type_name = zend_rsrc_list_get_rsrc_type(Z_RES_P(arg)); if (!type_name) { RETURN_FALSE; } } RETURN_TRUE; } else { RETURN_FALSE; } } /* {{{ Returns true if variable is null Warning: This function is special-cased by zend_compile.c and so is usually bypassed */ PHP_FUNCTION(is_null) { php_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_NULL); } /* }}} */ /* {{{ Returns true if variable is a resource Warning: This function is special-cased by zend_compile.c and so is usually bypassed */ PHP_FUNCTION(is_resource) { php_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_RESOURCE); } /* }}} */ /* {{{ Returns true if variable is a boolean Warning: This function is special-cased by zend_compile.c and so is usually bypassed */ PHP_FUNCTION(is_bool) { zval *arg; ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_ZVAL(arg) ZEND_PARSE_PARAMETERS_END(); RETURN_BOOL(Z_TYPE_P(arg) == IS_FALSE || Z_TYPE_P(arg) == IS_TRUE); } /* }}} */ /* {{{ Returns true if variable is an integer Warning: This function is special-cased by zend_compile.c and so is usually bypassed */ PHP_FUNCTION(is_int) { php_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_LONG); } /* }}} */ /* {{{ Returns true if variable is float point Warning: This function is special-cased by zend_compile.c and so is usually bypassed */ PHP_FUNCTION(is_float) { php_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_DOUBLE); } /* }}} */ /* {{{ Returns true if variable is a string Warning: This function is special-cased by zend_compile.c and so is usually bypassed */ PHP_FUNCTION(is_string) { php_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_STRING); } /* }}} */ /* {{{ Returns true if variable is an array Warning: This function is special-cased by zend_compile.c and so is usually bypassed */ PHP_FUNCTION(is_array) { php_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_ARRAY); } /* }}} */ /* {{{ Returns true if $array is an array whose keys are all numeric, sequential, and start at 0 */ PHP_FUNCTION(array_is_list) { HashTable *array; ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_ARRAY_HT(array) ZEND_PARSE_PARAMETERS_END(); RETURN_BOOL(zend_array_is_list(array)); } /* }}} */ /* {{{ Returns true if variable is an object Warning: This function is special-cased by zend_compile.c and so is usually bypassed */ PHP_FUNCTION(is_object) { php_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_OBJECT); } /* }}} */ /* {{{ Returns true if value is a number or a numeric string */ PHP_FUNCTION(is_numeric) { zval *arg; ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_ZVAL(arg) ZEND_PARSE_PARAMETERS_END(); switch (Z_TYPE_P(arg)) { case IS_LONG: case IS_DOUBLE: RETURN_TRUE; break; case IS_STRING: if (is_numeric_string(Z_STRVAL_P(arg), Z_STRLEN_P(arg), NULL, NULL, 0)) { RETURN_TRUE; } else { RETURN_FALSE; } break; default: RETURN_FALSE; break; } } /* }}} */ /* {{{ Returns true if value is a scalar */ PHP_FUNCTION(is_scalar) { zval *arg; ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_ZVAL(arg) ZEND_PARSE_PARAMETERS_END(); switch (Z_TYPE_P(arg)) { case IS_FALSE: case IS_TRUE: case IS_DOUBLE: case IS_LONG: case IS_STRING: RETURN_TRUE; break; default: RETURN_FALSE; break; } } /* }}} */ /* {{{ Returns true if var is callable. */ PHP_FUNCTION(is_callable) { zval *var, *callable_name = NULL; zend_string *name; bool retval; bool syntax_only = 0; int check_flags = 0; ZEND_PARSE_PARAMETERS_START(1, 3) Z_PARAM_ZVAL(var) Z_PARAM_OPTIONAL Z_PARAM_BOOL(syntax_only) Z_PARAM_ZVAL(callable_name) ZEND_PARSE_PARAMETERS_END(); if (syntax_only) { check_flags |= IS_CALLABLE_CHECK_SYNTAX_ONLY; } if (ZEND_NUM_ARGS() > 2) { retval = zend_is_callable_ex(var, NULL, check_flags, &name, NULL, NULL); ZEND_TRY_ASSIGN_REF_STR(callable_name, name); } else { retval = zend_is_callable_ex(var, NULL, check_flags, NULL, NULL, NULL); } RETURN_BOOL(retval); } /* }}} */ /* {{{ Returns true if var is iterable (array or instance of Traversable). */ PHP_FUNCTION(is_iterable) { zval *var; ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_ZVAL(var) ZEND_PARSE_PARAMETERS_END(); RETURN_BOOL(zend_is_iterable(var)); } /* }}} */ /* {{{ Returns true if var is countable (array or instance of Countable). */ PHP_FUNCTION(is_countable) { zval *var; ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_ZVAL(var) ZEND_PARSE_PARAMETERS_END(); RETURN_BOOL(zend_is_countable(var)); } /* }}} */
11,086
23.367033
99
c
php-src
php-src-master/ext/standard/uniqid.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: Stig Sæther Bakken <[email protected]> | +----------------------------------------------------------------------+ */ #include "php.h" #include <stdlib.h> #ifdef HAVE_UNISTD_H #include <unistd.h> #endif #include <string.h> #include <errno.h> #include <stdio.h> #ifdef PHP_WIN32 #include "win32/time.h" #else #include <sys/time.h> #endif #include "ext/random/php_random.h" #ifdef HAVE_GETTIMEOFDAY ZEND_TLS struct timeval prev_tv = { 0, 0 }; /* {{{ Generates a unique ID */ PHP_FUNCTION(uniqid) { char *prefix = ""; bool more_entropy = 0; zend_string *uniqid; int sec, usec; size_t prefix_len = 0; struct timeval tv; ZEND_PARSE_PARAMETERS_START(0, 2) Z_PARAM_OPTIONAL Z_PARAM_STRING(prefix, prefix_len) Z_PARAM_BOOL(more_entropy) ZEND_PARSE_PARAMETERS_END(); /* This implementation needs current microsecond to change, * hence we poll time until it does. This is much faster than * calling usleep(1) which may cause the kernel to schedule * another process, causing a pause of around 10ms. */ do { (void)gettimeofday((struct timeval *) &tv, (struct timezone *) NULL); } while (tv.tv_sec == prev_tv.tv_sec && tv.tv_usec == prev_tv.tv_usec); prev_tv.tv_sec = tv.tv_sec; prev_tv.tv_usec = tv.tv_usec; sec = (int) tv.tv_sec; usec = (int) (tv.tv_usec % 0x100000); /* The max value usec can have is 0xF423F, so we use only five hex * digits for usecs. */ if (more_entropy) { uint32_t bytes; double seed; if (php_random_bytes_silent(&bytes, sizeof(uint32_t)) == FAILURE) { seed = php_combined_lcg() * 10; } else { seed = ((double) bytes / UINT32_MAX) * 10.0; } uniqid = strpprintf(0, "%s%08x%05x%.8F", prefix, sec, usec, seed); } else { uniqid = strpprintf(0, "%s%08x%05x", prefix, sec, usec); } RETURN_STR(uniqid); } #endif /* }}} */
2,677
28.755556
75
c
php-src
php-src-master/ext/standard/url.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: Jim Winstead <[email protected]> | +----------------------------------------------------------------------+ */ #include <stdlib.h> #include <string.h> #include <ctype.h> #include <sys/types.h> #ifdef __SSE2__ #include <emmintrin.h> #endif #include "php.h" #include "url.h" #include "file.h" /* {{{ free_url */ PHPAPI void php_url_free(php_url *theurl) { if (theurl->scheme) zend_string_release_ex(theurl->scheme, 0); if (theurl->user) zend_string_release_ex(theurl->user, 0); if (theurl->pass) zend_string_release_ex(theurl->pass, 0); if (theurl->host) zend_string_release_ex(theurl->host, 0); if (theurl->path) zend_string_release_ex(theurl->path, 0); if (theurl->query) zend_string_release_ex(theurl->query, 0); if (theurl->fragment) zend_string_release_ex(theurl->fragment, 0); efree(theurl); } /* }}} */ /* {{{ php_replace_controlchars_ex */ PHPAPI char *php_replace_controlchars_ex(char *str, size_t len) { unsigned char *s = (unsigned char *)str; unsigned char *e = (unsigned char *)str + len; if (!str) { return (NULL); } while (s < e) { if (iscntrl(*s)) { *s='_'; } s++; } return (str); } /* }}} */ PHPAPI char *php_replace_controlchars(char *str) { return php_replace_controlchars_ex(str, strlen(str)); } PHPAPI php_url *php_url_parse(char const *str) { return php_url_parse_ex(str, strlen(str)); } static const char *binary_strcspn(const char *s, const char *e, const char *chars) { while (*chars) { const char *p = memchr(s, *chars, e - s); if (p) { e = p; } chars++; } return e; } /* {{{ php_url_parse */ PHPAPI php_url *php_url_parse_ex(char const *str, size_t length) { bool has_port; return php_url_parse_ex2(str, length, &has_port); } /* {{{ php_url_parse_ex2 */ PHPAPI php_url *php_url_parse_ex2(char const *str, size_t length, bool *has_port) { char port_buf[6]; php_url *ret = ecalloc(1, sizeof(php_url)); char const *s, *e, *p, *pp, *ue; *has_port = 0; s = str; ue = s + length; /* parse scheme */ if ((e = memchr(s, ':', length)) && e != s) { /* validate scheme */ p = s; while (p < e) { /* scheme = 1*[ lowalpha | digit | "+" | "-" | "." ] */ if (!isalpha(*p) && !isdigit(*p) && *p != '+' && *p != '.' && *p != '-') { if (e + 1 < ue && e < binary_strcspn(s, ue, "?#")) { goto parse_port; } else if (s + 1 < ue && *s == '/' && *(s + 1) == '/') { /* relative-scheme URL */ s += 2; e = 0; goto parse_host; } else { goto just_path; } } p++; } if (e + 1 == ue) { /* only scheme is available */ ret->scheme = zend_string_init(s, (e - s), 0); php_replace_controlchars_ex(ZSTR_VAL(ret->scheme), ZSTR_LEN(ret->scheme)); return ret; } /* * certain schemas like mailto: and zlib: may not have any / after them * this check ensures we support those. */ if (*(e+1) != '/') { /* check if the data we get is a port this allows us to * correctly parse things like a.com:80 */ p = e + 1; while (p < ue && isdigit(*p)) { p++; } if ((p == ue || *p == '/') && (p - e) < 7) { goto parse_port; } ret->scheme = zend_string_init(s, (e-s), 0); php_replace_controlchars_ex(ZSTR_VAL(ret->scheme), ZSTR_LEN(ret->scheme)); s = e + 1; goto just_path; } else { ret->scheme = zend_string_init(s, (e-s), 0); php_replace_controlchars_ex(ZSTR_VAL(ret->scheme), ZSTR_LEN(ret->scheme)); if (e + 2 < ue && *(e + 2) == '/') { s = e + 3; if (zend_string_equals_literal_ci(ret->scheme, "file")) { if (e + 3 < ue && *(e + 3) == '/') { /* support windows drive letters as in: file:///c:/somedir/file.txt */ if (e + 5 < ue && *(e + 5) == ':') { s = e + 4; } goto just_path; } } } else { s = e + 1; goto just_path; } } } else if (e) { /* no scheme; starts with colon: look for port */ parse_port: p = e + 1; pp = p; while (pp < ue && pp - p < 6 && isdigit(*pp)) { pp++; } if (pp - p > 0 && pp - p < 6 && (pp == ue || *pp == '/')) { zend_long port; char *end; memcpy(port_buf, p, (pp - p)); port_buf[pp - p] = '\0'; port = ZEND_STRTOL(port_buf, &end, 10); if (port >= 0 && port <= 65535 && end != port_buf) { *has_port = 1; ret->port = (unsigned short) port; if (s + 1 < ue && *s == '/' && *(s + 1) == '/') { /* relative-scheme URL */ s += 2; } } else { php_url_free(ret); return NULL; } } else if (p == pp && pp == ue) { php_url_free(ret); return NULL; } else if (s + 1 < ue && *s == '/' && *(s + 1) == '/') { /* relative-scheme URL */ s += 2; } else { goto just_path; } } else if (s + 1 < ue && *s == '/' && *(s + 1) == '/') { /* relative-scheme URL */ s += 2; } else { goto just_path; } parse_host: e = binary_strcspn(s, ue, "/?#"); /* check for login and password */ if ((p = zend_memrchr(s, '@', (e-s)))) { if ((pp = memchr(s, ':', (p-s)))) { ret->user = zend_string_init(s, (pp-s), 0); php_replace_controlchars_ex(ZSTR_VAL(ret->user), ZSTR_LEN(ret->user)); pp++; ret->pass = zend_string_init(pp, (p-pp), 0); php_replace_controlchars_ex(ZSTR_VAL(ret->pass), ZSTR_LEN(ret->pass)); } else { ret->user = zend_string_init(s, (p-s), 0); php_replace_controlchars_ex(ZSTR_VAL(ret->user), ZSTR_LEN(ret->user)); } s = p + 1; } /* check for port */ if (s < ue && *s == '[' && *(e-1) == ']') { /* Short circuit portscan, we're dealing with an IPv6 embedded address */ p = NULL; } else { p = zend_memrchr(s, ':', (e-s)); } if (p) { if (!ret->port) { p++; if (e-p > 5) { /* port cannot be longer then 5 characters */ php_url_free(ret); return NULL; } else if (e - p > 0) { zend_long port; char *end; memcpy(port_buf, p, (e - p)); port_buf[e - p] = '\0'; port = ZEND_STRTOL(port_buf, &end, 10); if (port >= 0 && port <= 65535 && end != port_buf) { *has_port = 1; ret->port = (unsigned short)port; } else { php_url_free(ret); return NULL; } } p--; } } else { p = e; } /* check if we have a valid host, if we don't reject the string as url */ if ((p-s) < 1) { php_url_free(ret); return NULL; } ret->host = zend_string_init(s, (p-s), 0); php_replace_controlchars_ex(ZSTR_VAL(ret->host), ZSTR_LEN(ret->host)); if (e == ue) { return ret; } s = e; just_path: e = ue; p = memchr(s, '#', (e - s)); if (p) { p++; if (p < e) { ret->fragment = zend_string_init(p, (e - p), 0); php_replace_controlchars_ex(ZSTR_VAL(ret->fragment), ZSTR_LEN(ret->fragment)); } else { ret->fragment = ZSTR_EMPTY_ALLOC(); } e = p-1; } p = memchr(s, '?', (e - s)); if (p) { p++; if (p < e) { ret->query = zend_string_init(p, (e - p), 0); php_replace_controlchars_ex(ZSTR_VAL(ret->query), ZSTR_LEN(ret->query)); } else { ret->query = ZSTR_EMPTY_ALLOC(); } e = p-1; } if (s < e || s == ue) { ret->path = zend_string_init(s, (e - s), 0); php_replace_controlchars_ex(ZSTR_VAL(ret->path), ZSTR_LEN(ret->path)); } return ret; } /* }}} */ /* {{{ Parse a URL and return its components */ PHP_FUNCTION(parse_url) { char *str; size_t str_len; php_url *resource; zend_long key = -1; zval tmp; bool has_port; ZEND_PARSE_PARAMETERS_START(1, 2) Z_PARAM_STRING(str, str_len) Z_PARAM_OPTIONAL Z_PARAM_LONG(key) ZEND_PARSE_PARAMETERS_END(); resource = php_url_parse_ex2(str, str_len, &has_port); if (resource == NULL) { /* @todo Find a method to determine why php_url_parse_ex() failed */ RETURN_FALSE; } if (key > -1) { switch (key) { case PHP_URL_SCHEME: if (resource->scheme != NULL) RETVAL_STR_COPY(resource->scheme); break; case PHP_URL_HOST: if (resource->host != NULL) RETVAL_STR_COPY(resource->host); break; case PHP_URL_PORT: if (has_port) RETVAL_LONG(resource->port); break; case PHP_URL_USER: if (resource->user != NULL) RETVAL_STR_COPY(resource->user); break; case PHP_URL_PASS: if (resource->pass != NULL) RETVAL_STR_COPY(resource->pass); break; case PHP_URL_PATH: if (resource->path != NULL) RETVAL_STR_COPY(resource->path); break; case PHP_URL_QUERY: if (resource->query != NULL) RETVAL_STR_COPY(resource->query); break; case PHP_URL_FRAGMENT: if (resource->fragment != NULL) RETVAL_STR_COPY(resource->fragment); break; default: zend_argument_value_error(2, "must be a valid URL component identifier, " ZEND_LONG_FMT " given", key); break; } goto done; } /* allocate an array for return */ array_init(return_value); /* add the various elements to the array */ if (resource->scheme != NULL) { ZVAL_STR_COPY(&tmp, resource->scheme); zend_hash_add_new(Z_ARRVAL_P(return_value), ZSTR_KNOWN(ZEND_STR_SCHEME), &tmp); } if (resource->host != NULL) { ZVAL_STR_COPY(&tmp, resource->host); zend_hash_add_new(Z_ARRVAL_P(return_value), ZSTR_KNOWN(ZEND_STR_HOST), &tmp); } if (has_port) { ZVAL_LONG(&tmp, resource->port); zend_hash_add_new(Z_ARRVAL_P(return_value), ZSTR_KNOWN(ZEND_STR_PORT), &tmp); } if (resource->user != NULL) { ZVAL_STR_COPY(&tmp, resource->user); zend_hash_add_new(Z_ARRVAL_P(return_value), ZSTR_KNOWN(ZEND_STR_USER), &tmp); } if (resource->pass != NULL) { ZVAL_STR_COPY(&tmp, resource->pass); zend_hash_add_new(Z_ARRVAL_P(return_value), ZSTR_KNOWN(ZEND_STR_PASS), &tmp); } if (resource->path != NULL) { ZVAL_STR_COPY(&tmp, resource->path); zend_hash_add_new(Z_ARRVAL_P(return_value), ZSTR_KNOWN(ZEND_STR_PATH), &tmp); } if (resource->query != NULL) { ZVAL_STR_COPY(&tmp, resource->query); zend_hash_add_new(Z_ARRVAL_P(return_value), ZSTR_KNOWN(ZEND_STR_QUERY), &tmp); } if (resource->fragment != NULL) { ZVAL_STR_COPY(&tmp, resource->fragment); zend_hash_add_new(Z_ARRVAL_P(return_value), ZSTR_KNOWN(ZEND_STR_FRAGMENT), &tmp); } done: php_url_free(resource); } /* }}} */ /* {{{ php_htoi */ static int php_htoi(char *s) { int value; int c; c = ((unsigned char *)s)[0]; if (isupper(c)) c = tolower(c); value = (c >= '0' && c <= '9' ? c - '0' : c - 'a' + 10) * 16; c = ((unsigned char *)s)[1]; if (isupper(c)) c = tolower(c); value += c >= '0' && c <= '9' ? c - '0' : c - 'a' + 10; return (value); } /* }}} */ /* rfc1738: ...The characters ";", "/", "?", ":", "@", "=" and "&" are the characters which may be reserved for special meaning within a scheme... ...Thus, only alphanumerics, the special characters "$-_.+!*'(),", and reserved characters used for their reserved purposes may be used unencoded within a URL... For added safety, we only leave -_. unencoded. */ static const unsigned char hexchars[] = "0123456789ABCDEF"; static zend_always_inline zend_string *php_url_encode_impl(const char *s, size_t len, bool raw) /* {{{ */ { unsigned char c; unsigned char *to; unsigned char const *from, *end; zend_string *start; from = (unsigned char *)s; end = (unsigned char *)s + len; start = zend_string_safe_alloc(3, len, 0, 0); to = (unsigned char*)ZSTR_VAL(start); #ifdef __SSE2__ while (from + 16 < end) { __m128i mask; uint32_t bits; const __m128i _A = _mm_set1_epi8('A' - 1); const __m128i Z_ = _mm_set1_epi8('Z' + 1); const __m128i _a = _mm_set1_epi8('a' - 1); const __m128i z_ = _mm_set1_epi8('z' + 1); const __m128i _zero = _mm_set1_epi8('0' - 1); const __m128i nine_ = _mm_set1_epi8('9' + 1); const __m128i dot = _mm_set1_epi8('.'); const __m128i minus = _mm_set1_epi8('-'); const __m128i under = _mm_set1_epi8('_'); __m128i in = _mm_loadu_si128((__m128i *)from); __m128i gt = _mm_cmpgt_epi8(in, _A); __m128i lt = _mm_cmplt_epi8(in, Z_); mask = _mm_and_si128(lt, gt); /* upper */ gt = _mm_cmpgt_epi8(in, _a); lt = _mm_cmplt_epi8(in, z_); mask = _mm_or_si128(mask, _mm_and_si128(lt, gt)); /* lower */ gt = _mm_cmpgt_epi8(in, _zero); lt = _mm_cmplt_epi8(in, nine_); mask = _mm_or_si128(mask, _mm_and_si128(lt, gt)); /* number */ mask = _mm_or_si128(mask, _mm_cmpeq_epi8(in, dot)); mask = _mm_or_si128(mask, _mm_cmpeq_epi8(in, minus)); mask = _mm_or_si128(mask, _mm_cmpeq_epi8(in, under)); if (!raw) { const __m128i blank = _mm_set1_epi8(' '); __m128i eq = _mm_cmpeq_epi8(in, blank); if (_mm_movemask_epi8(eq)) { in = _mm_add_epi8(in, _mm_and_si128(eq, _mm_set1_epi8('+' - ' '))); mask = _mm_or_si128(mask, eq); } } if (raw) { const __m128i wavy = _mm_set1_epi8('~'); mask = _mm_or_si128(mask, _mm_cmpeq_epi8(in, wavy)); } if (((bits = _mm_movemask_epi8(mask)) & 0xffff) == 0xffff) { _mm_storeu_si128((__m128i*)to, in); to += 16; } else { int i; unsigned char xmm[16]; _mm_storeu_si128((__m128i*)xmm, in); for (i = 0; i < sizeof(xmm); i++) { if ((bits & (0x1 << i))) { *to++ = xmm[i]; } else { *to++ = '%'; *to++ = hexchars[xmm[i] >> 4]; *to++ = hexchars[xmm[i] & 0xf]; } } } from += 16; } #endif while (from < end) { c = *from++; if (!raw && c == ' ') { *to++ = '+'; } else if ((c < '0' && c != '-' && c != '.') || (c < 'A' && c > '9') || (c > 'Z' && c < 'a' && c != '_') || (c > 'z' && (!raw || c != '~'))) { to[0] = '%'; to[1] = hexchars[c >> 4]; to[2] = hexchars[c & 15]; to += 3; } else { *to++ = c; } } *to = '\0'; start = zend_string_truncate(start, to - (unsigned char*)ZSTR_VAL(start), 0); return start; } /* }}} */ /* {{{ php_url_encode */ PHPAPI zend_string *php_url_encode(char const *s, size_t len) { return php_url_encode_impl(s, len, 0); } /* }}} */ /* {{{ URL-encodes string */ PHP_FUNCTION(urlencode) { zend_string *in_str; ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_STR(in_str) ZEND_PARSE_PARAMETERS_END(); RETURN_STR(php_url_encode(ZSTR_VAL(in_str), ZSTR_LEN(in_str))); } /* }}} */ /* {{{ Decodes URL-encoded string */ PHP_FUNCTION(urldecode) { zend_string *in_str, *out_str; ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_STR(in_str) ZEND_PARSE_PARAMETERS_END(); out_str = zend_string_init(ZSTR_VAL(in_str), ZSTR_LEN(in_str), 0); ZSTR_LEN(out_str) = php_url_decode(ZSTR_VAL(out_str), ZSTR_LEN(out_str)); RETURN_NEW_STR(out_str); } /* }}} */ /* {{{ php_url_decode */ PHPAPI size_t php_url_decode(char *str, size_t len) { char *dest = str; char *data = str; while (len--) { if (*data == '+') { *dest = ' '; } else if (*data == '%' && len >= 2 && isxdigit((int) *(data + 1)) && isxdigit((int) *(data + 2))) { *dest = (char) php_htoi(data + 1); data += 2; len -= 2; } else { *dest = *data; } data++; dest++; } *dest = '\0'; return dest - str; } /* }}} */ /* {{{ php_raw_url_encode */ PHPAPI zend_string *php_raw_url_encode(char const *s, size_t len) { return php_url_encode_impl(s, len, 1); } /* }}} */ /* {{{ URL-encodes string */ PHP_FUNCTION(rawurlencode) { zend_string *in_str; ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_STR(in_str) ZEND_PARSE_PARAMETERS_END(); RETURN_STR(php_raw_url_encode(ZSTR_VAL(in_str), ZSTR_LEN(in_str))); } /* }}} */ /* {{{ Decodes URL-encodes string */ PHP_FUNCTION(rawurldecode) { zend_string *in_str, *out_str; ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_STR(in_str) ZEND_PARSE_PARAMETERS_END(); out_str = zend_string_init(ZSTR_VAL(in_str), ZSTR_LEN(in_str), 0); ZSTR_LEN(out_str) = php_raw_url_decode(ZSTR_VAL(out_str), ZSTR_LEN(out_str)); RETURN_NEW_STR(out_str); } /* }}} */ /* {{{ php_raw_url_decode */ PHPAPI size_t php_raw_url_decode(char *str, size_t len) { char *dest = str; char *data = str; while (len--) { if (*data == '%' && len >= 2 && isxdigit((int) *(data + 1)) && isxdigit((int) *(data + 2))) { *dest = (char) php_htoi(data + 1); data += 2; len -= 2; } else { *dest = *data; } data++; dest++; } *dest = '\0'; return dest - str; } /* }}} */ /* {{{ fetches all the headers sent by the server in response to a HTTP request */ PHP_FUNCTION(get_headers) { char *url; size_t url_len; php_stream *stream; zval *prev_val, *hdr = NULL; bool format = 0; zval *zcontext = NULL; php_stream_context *context; ZEND_PARSE_PARAMETERS_START(1, 3) Z_PARAM_PATH(url, url_len) Z_PARAM_OPTIONAL Z_PARAM_BOOL(format) Z_PARAM_RESOURCE_OR_NULL(zcontext) ZEND_PARSE_PARAMETERS_END(); context = php_stream_context_from_zval(zcontext, 0); if (!(stream = php_stream_open_wrapper_ex(url, "r", REPORT_ERRORS | STREAM_USE_URL | STREAM_ONLY_GET_HEADERS, NULL, context))) { RETURN_FALSE; } if (Z_TYPE(stream->wrapperdata) != IS_ARRAY) { php_stream_close(stream); RETURN_FALSE; } array_init(return_value); ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(&stream->wrapperdata), hdr) { if (Z_TYPE_P(hdr) != IS_STRING) { continue; } if (!format) { no_name_header: add_next_index_str(return_value, zend_string_copy(Z_STR_P(hdr))); } else { char c; char *s, *p; if ((p = strchr(Z_STRVAL_P(hdr), ':'))) { c = *p; *p = '\0'; s = p + 1; while (isspace((int)*(unsigned char *)s)) { s++; } if ((prev_val = zend_hash_str_find(Z_ARRVAL_P(return_value), Z_STRVAL_P(hdr), (p - Z_STRVAL_P(hdr)))) == NULL) { add_assoc_stringl_ex(return_value, Z_STRVAL_P(hdr), (p - Z_STRVAL_P(hdr)), s, (Z_STRLEN_P(hdr) - (s - Z_STRVAL_P(hdr)))); } else { /* some headers may occur more than once, therefore we need to remake the string into an array */ convert_to_array(prev_val); add_next_index_stringl(prev_val, s, (Z_STRLEN_P(hdr) - (s - Z_STRVAL_P(hdr)))); } *p = c; } else { goto no_name_header; } } } ZEND_HASH_FOREACH_END(); php_stream_close(stream); } /* }}} */
18,509
23.812332
129
c
php-src
php-src-master/ext/standard/url.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: Jim Winstead <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef URL_H #define URL_H typedef struct php_url { zend_string *scheme; zend_string *user; zend_string *pass; zend_string *host; unsigned short port; zend_string *path; zend_string *query; zend_string *fragment; } php_url; PHPAPI void php_url_free(php_url *theurl); PHPAPI php_url *php_url_parse(char const *str); PHPAPI php_url *php_url_parse_ex(char const *str, size_t length); PHPAPI php_url *php_url_parse_ex2(char const *str, size_t length, bool *has_port); PHPAPI size_t php_url_decode(char *str, size_t len); /* return value: length of decoded string */ PHPAPI size_t php_raw_url_decode(char *str, size_t len); /* return value: length of decoded string */ PHPAPI zend_string *php_url_encode(char const *s, size_t len); PHPAPI zend_string *php_raw_url_encode(char const *s, size_t len); PHPAPI char *php_replace_controlchars_ex(char *str, size_t len); #define PHP_URL_SCHEME 0 #define PHP_URL_HOST 1 #define PHP_URL_PORT 2 #define PHP_URL_USER 3 #define PHP_URL_PASS 4 #define PHP_URL_PATH 5 #define PHP_URL_QUERY 6 #define PHP_URL_FRAGMENT 7 #define PHP_QUERY_RFC1738 1 #define PHP_QUERY_RFC3986 2 #endif /* URL_H */
2,135
38.555556
101
h
php-src
php-src-master/ext/standard/user_filters.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: | | Wez Furlong ([email protected]) | | Sara Golemon ([email protected]) | +----------------------------------------------------------------------+ */ #include "php.h" #include "php_globals.h" #include "ext/standard/basic_functions.h" #include "ext/standard/file.h" #include "ext/standard/user_filters_arginfo.h" #define PHP_STREAM_BRIGADE_RES_NAME "userfilter.bucket brigade" #define PHP_STREAM_BUCKET_RES_NAME "userfilter.bucket" #define PHP_STREAM_FILTER_RES_NAME "userfilter.filter" struct php_user_filter_data { zend_class_entry *ce; /* variable length; this *must* be last in the structure */ zend_string *classname; }; /* to provide context for calling into the next filter from user-space */ static int le_bucket_brigade; static int le_bucket; /* define the base filter class */ PHP_METHOD(php_user_filter, filter) { zval *in, *out, *consumed; bool closing; if (zend_parse_parameters(ZEND_NUM_ARGS(), "rrzb", &in, &out, &consumed, &closing) == FAILURE) { RETURN_THROWS(); } RETURN_LONG(PSFS_ERR_FATAL); } PHP_METHOD(php_user_filter, onCreate) { ZEND_PARSE_PARAMETERS_NONE(); RETURN_TRUE; } PHP_METHOD(php_user_filter, onClose) { ZEND_PARSE_PARAMETERS_NONE(); } static zend_class_entry *user_filter_class_entry; static ZEND_RSRC_DTOR_FUNC(php_bucket_dtor) { php_stream_bucket *bucket = (php_stream_bucket *)res->ptr; if (bucket) { php_stream_bucket_delref(bucket); bucket = NULL; } } PHP_MINIT_FUNCTION(user_filters) { /* init the filter class ancestor */ user_filter_class_entry = register_class_php_user_filter(); /* Filters will dispose of their brigades */ le_bucket_brigade = zend_register_list_destructors_ex(NULL, NULL, PHP_STREAM_BRIGADE_RES_NAME, module_number); /* Brigades will dispose of their buckets */ le_bucket = zend_register_list_destructors_ex(php_bucket_dtor, NULL, PHP_STREAM_BUCKET_RES_NAME, module_number); if (le_bucket_brigade == FAILURE) { return FAILURE; } register_user_filters_symbols(module_number); return SUCCESS; } PHP_RSHUTDOWN_FUNCTION(user_filters) { if (BG(user_filter_map)) { zend_hash_destroy(BG(user_filter_map)); efree(BG(user_filter_map)); BG(user_filter_map) = NULL; } return SUCCESS; } static void userfilter_dtor(php_stream_filter *thisfilter) { zval *obj = &thisfilter->abstract; zval retval; if (Z_ISUNDEF_P(obj)) { /* If there's no object associated then there's nothing to dispose of */ return; } zend_string *func_name = ZSTR_INIT_LITERAL("onclose", 0); zend_call_method_if_exists(Z_OBJ_P(obj), func_name, &retval, 0, NULL); zend_string_release(func_name); zval_ptr_dtor(&retval); /* kill the object */ zval_ptr_dtor(obj); } php_stream_filter_status_t userfilter_filter( php_stream *stream, php_stream_filter *thisfilter, php_stream_bucket_brigade *buckets_in, php_stream_bucket_brigade *buckets_out, size_t *bytes_consumed, int flags ) { int ret = PSFS_ERR_FATAL; zval *obj = &thisfilter->abstract; zval func_name; zval retval; zval args[4]; int call_result; /* the userfilter object probably doesn't exist anymore */ if (CG(unclean_shutdown)) { return ret; } /* Make sure the stream is not closed while the filter callback executes. */ uint32_t orig_no_fclose = stream->flags & PHP_STREAM_FLAG_NO_FCLOSE; stream->flags |= PHP_STREAM_FLAG_NO_FCLOSE; zval *stream_prop = zend_hash_str_find_ind(Z_OBJPROP_P(obj), "stream", sizeof("stream")-1); if (stream_prop) { /* Give the userfilter class a hook back to the stream */ zval_ptr_dtor(stream_prop); php_stream_to_zval(stream, stream_prop); Z_ADDREF_P(stream_prop); } ZVAL_STRINGL(&func_name, "filter", sizeof("filter")-1); /* Setup calling arguments */ ZVAL_RES(&args[0], zend_register_resource(buckets_in, le_bucket_brigade)); ZVAL_RES(&args[1], zend_register_resource(buckets_out, le_bucket_brigade)); if (bytes_consumed) { ZVAL_LONG(&args[2], *bytes_consumed); } else { ZVAL_NULL(&args[2]); } ZVAL_MAKE_REF(&args[2]); ZVAL_BOOL(&args[3], flags & PSFS_FLAG_FLUSH_CLOSE); call_result = call_user_function(NULL, obj, &func_name, &retval, 4, args); zval_ptr_dtor(&func_name); if (call_result == SUCCESS && Z_TYPE(retval) != IS_UNDEF) { convert_to_long(&retval); ret = (int)Z_LVAL(retval); } else if (call_result == FAILURE) { php_error_docref(NULL, E_WARNING, "Failed to call filter function"); } if (bytes_consumed) { *bytes_consumed = zval_get_long(&args[2]); } if (buckets_in->head) { php_stream_bucket *bucket; php_error_docref(NULL, E_WARNING, "Unprocessed filter buckets remaining on input brigade"); while ((bucket = buckets_in->head)) { /* Remove unconsumed buckets from the brigade */ php_stream_bucket_unlink(bucket); php_stream_bucket_delref(bucket); } } if (ret != PSFS_PASS_ON) { php_stream_bucket *bucket = buckets_out->head; while (bucket != NULL) { php_stream_bucket_unlink(bucket); php_stream_bucket_delref(bucket); bucket = buckets_out->head; } } /* filter resources are cleaned up by the stream destructor, * keeping a reference to the stream resource here would prevent it * from being destroyed properly */ if (stream_prop) { convert_to_null(stream_prop); } zval_ptr_dtor(&args[3]); zval_ptr_dtor(&args[2]); zval_ptr_dtor(&args[1]); zval_ptr_dtor(&args[0]); stream->flags &= ~PHP_STREAM_FLAG_NO_FCLOSE; stream->flags |= orig_no_fclose; return ret; } static const php_stream_filter_ops userfilter_ops = { userfilter_filter, userfilter_dtor, "user-filter" }; static php_stream_filter *user_filter_factory_create(const char *filtername, zval *filterparams, uint8_t persistent) { struct php_user_filter_data *fdat = NULL; php_stream_filter *filter; zval obj; zval retval; size_t len; /* some sanity checks */ if (persistent) { php_error_docref(NULL, E_WARNING, "Cannot use a user-space filter with a persistent stream"); return NULL; } len = strlen(filtername); /* determine the classname/class entry */ if (NULL == (fdat = zend_hash_str_find_ptr(BG(user_filter_map), (char*)filtername, len))) { char *period; /* Userspace Filters using ambiguous wildcards could cause problems. i.e.: myfilter.foo.bar will always call into myfilter.foo.* never seeing myfilter.* TODO: Allow failed userfilter creations to continue scanning through the list */ if ((period = strrchr(filtername, '.'))) { char *wildcard = safe_emalloc(len, 1, 3); /* Search for wildcard matches instead */ memcpy(wildcard, filtername, len + 1); /* copy \0 */ period = wildcard + (period - filtername); while (period) { ZEND_ASSERT(period[0] == '.'); period[1] = '*'; period[2] = '\0'; if (NULL != (fdat = zend_hash_str_find_ptr(BG(user_filter_map), wildcard, strlen(wildcard)))) { period = NULL; } else { *period = '\0'; period = strrchr(wildcard, '.'); } } efree(wildcard); } ZEND_ASSERT(fdat); } /* bind the classname to the actual class */ if (fdat->ce == NULL) { if (NULL == (fdat->ce = zend_lookup_class(fdat->classname))) { php_error_docref(NULL, E_WARNING, "User-filter \"%s\" requires class \"%s\", but that class is not defined", filtername, ZSTR_VAL(fdat->classname)); return NULL; } } /* create the object */ if (object_init_ex(&obj, fdat->ce) == FAILURE) { return NULL; } filter = php_stream_filter_alloc(&userfilter_ops, NULL, 0); if (filter == NULL) { zval_ptr_dtor(&obj); return NULL; } /* filtername */ add_property_string(&obj, "filtername", (char*)filtername); /* and the parameters, if any */ if (filterparams) { add_property_zval(&obj, "params", filterparams); } else { add_property_null(&obj, "params"); } /* invoke the constructor */ zend_string *func_name = ZSTR_INIT_LITERAL("oncreate", 0); zend_call_method_if_exists(Z_OBJ(obj), func_name, &retval, 0, NULL); zend_string_release(func_name); if (Z_TYPE(retval) != IS_UNDEF) { if (Z_TYPE(retval) == IS_FALSE) { /* User reported filter creation error "return false;" */ zval_ptr_dtor(&retval); /* Kill the filter (safely) */ ZVAL_UNDEF(&filter->abstract); php_stream_filter_free(filter); /* Kill the object */ zval_ptr_dtor(&obj); /* Report failure to filter_alloc */ return NULL; } zval_ptr_dtor(&retval); } ZVAL_OBJ(&filter->abstract, Z_OBJ(obj)); return filter; } static const php_stream_filter_factory user_filter_factory = { user_filter_factory_create }; static void filter_item_dtor(zval *zv) { struct php_user_filter_data *fdat = Z_PTR_P(zv); zend_string_release_ex(fdat->classname, 0); efree(fdat); } /* {{{ Return a bucket object from the brigade for operating on */ PHP_FUNCTION(stream_bucket_make_writeable) { zval *zbrigade, zbucket; php_stream_bucket_brigade *brigade; php_stream_bucket *bucket; ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_RESOURCE(zbrigade) ZEND_PARSE_PARAMETERS_END(); if ((brigade = (php_stream_bucket_brigade*)zend_fetch_resource( Z_RES_P(zbrigade), PHP_STREAM_BRIGADE_RES_NAME, le_bucket_brigade)) == NULL) { RETURN_THROWS(); } ZVAL_NULL(return_value); if (brigade->head && (bucket = php_stream_bucket_make_writeable(brigade->head))) { ZVAL_RES(&zbucket, zend_register_resource(bucket, le_bucket)); object_init(return_value); add_property_zval(return_value, "bucket", &zbucket); /* add_property_zval increments the refcount which is unwanted here */ zval_ptr_dtor(&zbucket); add_property_stringl(return_value, "data", bucket->buf, bucket->buflen); add_property_long(return_value, "datalen", bucket->buflen); } } /* }}} */ /* {{{ php_stream_bucket_attach */ static void php_stream_bucket_attach(int append, INTERNAL_FUNCTION_PARAMETERS) { zval *zbrigade, *zobject; zval *pzbucket, *pzdata; php_stream_bucket_brigade *brigade; php_stream_bucket *bucket; ZEND_PARSE_PARAMETERS_START(2, 2) Z_PARAM_RESOURCE(zbrigade) Z_PARAM_OBJECT(zobject) ZEND_PARSE_PARAMETERS_END(); if (NULL == (pzbucket = zend_hash_str_find_deref(Z_OBJPROP_P(zobject), "bucket", sizeof("bucket")-1))) { zend_argument_value_error(2, "must be an object that has a \"bucket\" property"); RETURN_THROWS(); } if ((brigade = (php_stream_bucket_brigade*)zend_fetch_resource( Z_RES_P(zbrigade), PHP_STREAM_BRIGADE_RES_NAME, le_bucket_brigade)) == NULL) { RETURN_THROWS(); } if ((bucket = (php_stream_bucket *)zend_fetch_resource_ex(pzbucket, PHP_STREAM_BUCKET_RES_NAME, le_bucket)) == NULL) { RETURN_THROWS(); } if (NULL != (pzdata = zend_hash_str_find_deref(Z_OBJPROP_P(zobject), "data", sizeof("data")-1)) && Z_TYPE_P(pzdata) == IS_STRING) { if (!bucket->own_buf) { bucket = php_stream_bucket_make_writeable(bucket); } if (bucket->buflen != Z_STRLEN_P(pzdata)) { bucket->buf = perealloc(bucket->buf, Z_STRLEN_P(pzdata), bucket->is_persistent); bucket->buflen = Z_STRLEN_P(pzdata); } memcpy(bucket->buf, Z_STRVAL_P(pzdata), bucket->buflen); } if (append) { php_stream_bucket_append(brigade, bucket); } else { php_stream_bucket_prepend(brigade, bucket); } /* This is a hack necessary to accommodate situations where bucket is appended to the stream * multiple times. See bug35916.phpt for reference. */ if (bucket->refcount == 1) { bucket->refcount++; } } /* }}} */ /* {{{ Prepend bucket to brigade */ PHP_FUNCTION(stream_bucket_prepend) { php_stream_bucket_attach(0, INTERNAL_FUNCTION_PARAM_PASSTHRU); } /* }}} */ /* {{{ Append bucket to brigade */ PHP_FUNCTION(stream_bucket_append) { php_stream_bucket_attach(1, INTERNAL_FUNCTION_PARAM_PASSTHRU); } /* }}} */ /* {{{ Create a new bucket for use on the current stream */ PHP_FUNCTION(stream_bucket_new) { zval *zstream, zbucket; php_stream *stream; char *buffer; char *pbuffer; size_t buffer_len; php_stream_bucket *bucket; ZEND_PARSE_PARAMETERS_START(2, 2) Z_PARAM_ZVAL(zstream) Z_PARAM_STRING(buffer, buffer_len) ZEND_PARSE_PARAMETERS_END(); php_stream_from_zval(stream, zstream); pbuffer = pemalloc(buffer_len, php_stream_is_persistent(stream)); memcpy(pbuffer, buffer, buffer_len); bucket = php_stream_bucket_new(stream, pbuffer, buffer_len, 1, php_stream_is_persistent(stream)); ZVAL_RES(&zbucket, zend_register_resource(bucket, le_bucket)); object_init(return_value); add_property_zval(return_value, "bucket", &zbucket); /* add_property_zval increments the refcount which is unwanted here */ zval_ptr_dtor(&zbucket); add_property_stringl(return_value, "data", bucket->buf, bucket->buflen); add_property_long(return_value, "datalen", bucket->buflen); } /* }}} */ /* {{{ Returns a list of registered filters */ PHP_FUNCTION(stream_get_filters) { zend_string *filter_name; HashTable *filters_hash; ZEND_PARSE_PARAMETERS_NONE(); array_init(return_value); filters_hash = php_get_stream_filters_hash(); if (filters_hash && !HT_IS_PACKED(filters_hash)) { ZEND_HASH_MAP_FOREACH_STR_KEY(filters_hash, filter_name) { if (filter_name) { add_next_index_str(return_value, zend_string_copy(filter_name)); } } ZEND_HASH_FOREACH_END(); } /* It's okay to return an empty array if no filters are registered */ } /* }}} */ /* {{{ Registers a custom filter handler class */ PHP_FUNCTION(stream_filter_register) { zend_string *filtername, *classname; struct php_user_filter_data *fdat; ZEND_PARSE_PARAMETERS_START(2, 2) Z_PARAM_STR(filtername) Z_PARAM_STR(classname) ZEND_PARSE_PARAMETERS_END(); if (!ZSTR_LEN(filtername)) { zend_argument_value_error(1, "must be a non-empty string"); RETURN_THROWS(); } if (!ZSTR_LEN(classname)) { zend_argument_value_error(2, "must be a non-empty string"); RETURN_THROWS(); } if (!BG(user_filter_map)) { BG(user_filter_map) = (HashTable*) emalloc(sizeof(HashTable)); zend_hash_init(BG(user_filter_map), 8, NULL, (dtor_func_t) filter_item_dtor, 0); } fdat = ecalloc(1, sizeof(struct php_user_filter_data)); fdat->classname = zend_string_copy(classname); if (zend_hash_add_ptr(BG(user_filter_map), filtername, fdat) != NULL && php_stream_filter_register_factory_volatile(filtername, &user_filter_factory) == SUCCESS) { RETVAL_TRUE; } else { zend_string_release_ex(classname, 0); efree(fdat); RETVAL_FALSE; } } /* }}} */
15,254
27.042279
132
c
php-src
php-src-master/ext/standard/uuencode.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: Ilia Alshanetsky <[email protected]> | +----------------------------------------------------------------------+ */ /* * Portions of this code are based on Berkeley's uuencode/uudecode * implementation. * * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include <math.h> #include "php.h" #include "php_uuencode.h" #define PHP_UU_ENC(c) ((c) ? ((c) & 077) + ' ' : '`') #define PHP_UU_ENC_C2(c) PHP_UU_ENC(((*(c) << 4) & 060) | ((*((c) + 1) >> 4) & 017)) #define PHP_UU_ENC_C3(c) PHP_UU_ENC(((*(c + 1) << 2) & 074) | ((*((c) + 2) >> 6) & 03)) #define PHP_UU_DEC(c) (((c) - ' ') & 077) PHPAPI zend_string *php_uuencode(const char *src, size_t src_len) /* {{{ */ { size_t len = 45; unsigned char *p; const unsigned char *s, *e, *ee; zend_string *dest; /* encoded length is ~ 38% greater than the original Use 1.5 for easier calculation. */ dest = zend_string_safe_alloc(src_len/2, 3, 46, 0); p = (unsigned char *) ZSTR_VAL(dest); s = (unsigned char *) src; e = s + src_len; while ((s + 3) < e) { ee = s + len; if (ee > e) { ee = e; len = ee - s; if (len % 3) { ee = s + (int) (floor((double)len / 3) * 3); } } *p++ = PHP_UU_ENC(len); while (s < ee) { *p++ = PHP_UU_ENC(*s >> 2); *p++ = PHP_UU_ENC_C2(s); *p++ = PHP_UU_ENC_C3(s); *p++ = PHP_UU_ENC(*(s + 2) & 077); s += 3; } if (len == 45) { *p++ = '\n'; } } if (s < e) { if (len == 45) { *p++ = PHP_UU_ENC(e - s); len = 0; } *p++ = PHP_UU_ENC(*s >> 2); *p++ = PHP_UU_ENC_C2(s); *p++ = ((e - s) > 1) ? PHP_UU_ENC_C3(s) : PHP_UU_ENC('\0'); *p++ = ((e - s) > 2) ? PHP_UU_ENC(*(s + 2) & 077) : PHP_UU_ENC('\0'); } if (len < 45) { *p++ = '\n'; } *p++ = PHP_UU_ENC('\0'); *p++ = '\n'; *p = '\0'; dest = zend_string_truncate(dest, (char *) p - ZSTR_VAL(dest), 0); return dest; } /* }}} */ PHPAPI zend_string *php_uudecode(const char *src, size_t src_len) /* {{{ */ { size_t len, total_len=0; char *p; const char *s, *e, *ee; zend_string *dest; if (src_len == 0) { return NULL; } dest = zend_string_alloc((size_t) ceil(src_len * 0.75), 0); p = ZSTR_VAL(dest); s = src; e = src + src_len; while (s < e) { if ((len = PHP_UU_DEC(*s++)) == 0) { break; } /* sanity check */ if (len > src_len) { goto err; } total_len += len; ee = s + (len == 45 ? 60 : (int) floor(len * 1.33)); /* sanity check */ if (ee > e) { goto err; } while (s < ee) { if(s+4 > e) { goto err; } *p++ = PHP_UU_DEC(*s) << 2 | PHP_UU_DEC(*(s + 1)) >> 4; *p++ = PHP_UU_DEC(*(s + 1)) << 4 | PHP_UU_DEC(*(s + 2)) >> 2; *p++ = PHP_UU_DEC(*(s + 2)) << 6 | PHP_UU_DEC(*(s + 3)); s += 4; } if (len < 45) { break; } /* skip \n */ s++; } assert(p >= ZSTR_VAL(dest)); if ((len = total_len) > (size_t)(p - ZSTR_VAL(dest))) { *p++ = PHP_UU_DEC(*s) << 2 | PHP_UU_DEC(*(s + 1)) >> 4; if (len > 1) { *p++ = PHP_UU_DEC(*(s + 1)) << 4 | PHP_UU_DEC(*(s + 2)) >> 2; if (len > 2) { *p++ = PHP_UU_DEC(*(s + 2)) << 6 | PHP_UU_DEC(*(s + 3)); } } } ZSTR_LEN(dest) = total_len; ZSTR_VAL(dest)[ZSTR_LEN(dest)] = '\0'; return dest; err: zend_string_efree(dest); return NULL; } /* }}} */ /* {{{ uuencode a string */ PHP_FUNCTION(convert_uuencode) { zend_string *src; ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_STR(src) ZEND_PARSE_PARAMETERS_END(); RETURN_STR(php_uuencode(ZSTR_VAL(src), ZSTR_LEN(src))); } /* }}} */ /* {{{ decode a uuencoded string */ PHP_FUNCTION(convert_uudecode) { zend_string *src; zend_string *dest; ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_STR(src) ZEND_PARSE_PARAMETERS_END(); if ((dest = php_uudecode(ZSTR_VAL(src), ZSTR_LEN(src))) == NULL) { php_error_docref(NULL, E_WARNING, "Argument #1 ($data) is not a valid uuencoded string"); RETURN_FALSE; } RETURN_STR(dest); } /* }}} */
6,506
26.807692
91
c
php-src
php-src-master/ext/standard/versioning.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: Stig Sæther Bakken <[email protected]> | +----------------------------------------------------------------------+ */ #include <stdio.h> #include <sys/types.h> #include <ctype.h> #include <stdlib.h> #include <string.h> #include "php.h" #include "php_versioning.h" /* {{{ php_canonicalize_version() */ PHPAPI char * php_canonicalize_version(const char *version) { size_t len = strlen(version); char *buf = safe_emalloc(len, 2, 1), *q, lp, lq; const char *p; if (len == 0) { *buf = '\0'; return buf; } p = version; q = buf; *q++ = lp = *p++; while (*p) { /* s/[-_+]/./g; * s/([^\d\.])([^\D\.])/$1.$2/g; * s/([^\D\.])([^\d\.])/$1.$2/g; */ #define isdig(x) (isdigit(x)&&(x)!='.') #define isndig(x) (!isdigit(x)&&(x)!='.') #define isspecialver(x) ((x)=='-'||(x)=='_'||(x)=='+') lq = *(q - 1); if (isspecialver(*p)) { if (lq != '.') { *q++ = '.'; } } else if ((isndig(lp) && isdig(*p)) || (isdig(lp) && isndig(*p))) { if (lq != '.') { *q++ = '.'; } *q++ = *p; } else if (!isalnum(*p)) { if (lq != '.') { *q++ = '.'; } } else { *q++ = *p; } lp = *p++; } *q++ = '\0'; return buf; } /* }}} */ /* {{{ compare_special_version_forms() */ typedef struct { const char *name; int order; } special_forms_t; static int compare_special_version_forms(char *form1, char *form2) { int found1 = -1, found2 = -1; special_forms_t special_forms[11] = { {"dev", 0}, {"alpha", 1}, {"a", 1}, {"beta", 2}, {"b", 2}, {"RC", 3}, {"rc", 3}, {"#", 4}, {"pl", 5}, {"p", 5}, {NULL, 0}, }; special_forms_t *pp; for (pp = special_forms; pp && pp->name; pp++) { if (strncmp(form1, pp->name, strlen(pp->name)) == 0) { found1 = pp->order; break; } } for (pp = special_forms; pp && pp->name; pp++) { if (strncmp(form2, pp->name, strlen(pp->name)) == 0) { found2 = pp->order; break; } } return ZEND_NORMALIZE_BOOL(found1 - found2); } /* }}} */ /* {{{ php_version_compare() */ PHPAPI int php_version_compare(const char *orig_ver1, const char *orig_ver2) { char *ver1; char *ver2; char *p1, *p2, *n1, *n2; long l1, l2; int compare = 0; if (!*orig_ver1 || !*orig_ver2) { if (!*orig_ver1 && !*orig_ver2) { return 0; } else { return *orig_ver1 ? 1 : -1; } } if (orig_ver1[0] == '#') { ver1 = estrdup(orig_ver1); } else { ver1 = php_canonicalize_version(orig_ver1); } if (orig_ver2[0] == '#') { ver2 = estrdup(orig_ver2); } else { ver2 = php_canonicalize_version(orig_ver2); } p1 = n1 = ver1; p2 = n2 = ver2; while (*p1 && *p2 && n1 && n2) { if ((n1 = strchr(p1, '.')) != NULL) { *n1 = '\0'; } if ((n2 = strchr(p2, '.')) != NULL) { *n2 = '\0'; } if (isdigit(*p1) && isdigit(*p2)) { /* compare element numerically */ l1 = strtol(p1, NULL, 10); l2 = strtol(p2, NULL, 10); compare = ZEND_NORMALIZE_BOOL(l1 - l2); } else if (!isdigit(*p1) && !isdigit(*p2)) { /* compare element names */ compare = compare_special_version_forms(p1, p2); } else { /* mix of names and numbers */ if (isdigit(*p1)) { compare = compare_special_version_forms("#N#", p2); } else { compare = compare_special_version_forms(p1, "#N#"); } } if (compare != 0) { break; } if (n1 != NULL) { p1 = n1 + 1; } if (n2 != NULL) { p2 = n2 + 1; } } if (compare == 0) { if (n1 != NULL) { if (isdigit(*p1)) { compare = 1; } else { compare = php_version_compare(p1, "#N#"); } } else if (n2 != NULL) { if (isdigit(*p2)) { compare = -1; } else { compare = php_version_compare("#N#", p2); } } } efree(ver1); efree(ver2); return compare; } /* }}} */ /* {{{ Compares two "PHP-standardized" version number strings */ PHP_FUNCTION(version_compare) { char *v1, *v2; zend_string *op = NULL; size_t v1_len, v2_len; int compare; ZEND_PARSE_PARAMETERS_START(2, 3) Z_PARAM_STRING(v1, v1_len) Z_PARAM_STRING(v2, v2_len) Z_PARAM_OPTIONAL Z_PARAM_STR_OR_NULL(op) ZEND_PARSE_PARAMETERS_END(); compare = php_version_compare(v1, v2); if (!op) { RETURN_LONG(compare); } if (zend_string_equals_literal(op, "<") || zend_string_equals_literal(op, "lt")) { RETURN_BOOL(compare == -1); } if (zend_string_equals_literal(op, "<=") || zend_string_equals_literal(op, "le")) { RETURN_BOOL(compare != 1); } if (zend_string_equals_literal(op, ">") || zend_string_equals_literal(op, "gt")) { RETURN_BOOL(compare == 1); } if (zend_string_equals_literal(op, ">=") || zend_string_equals_literal(op, "ge")) { RETURN_BOOL(compare != -1); } if (zend_string_equals_literal(op, "==") || zend_string_equals_literal(op, "=") || zend_string_equals_literal(op, "eq")) { RETURN_BOOL(compare == 0); } if (zend_string_equals_literal(op, "!=") || zend_string_equals_literal(op, "<>") || zend_string_equals_literal(op, "ne")) { RETURN_BOOL(compare != 0); } zend_argument_value_error(3, "must be a valid comparison operator"); } /* }}} */
5,823
22.771429
124
c
php-src
php-src-master/ext/standard/winver.h
#ifndef _PHP_WINVER_H #define _PHP_WINVER_H #ifndef SM_TABLETPC #define SM_TABLETPC 86 #endif #ifndef SM_MEDIACENTER #define SM_MEDIACENTER 87 #endif #ifndef SM_STARTER #define SM_STARTER 88 #endif #ifndef SM_SERVERR2 #define SM_SERVERR2 89 #endif #ifndef VER_SUITE_WH_SERVER #define VER_SUITE_WH_SERVER 0x8000 #endif #ifndef PRODUCT_ULTIMATE #define PRODUCT_UNDEFINED 0x00000000 #define PRODUCT_ULTIMATE 0x00000001 #define PRODUCT_HOME_BASIC 0x00000002 #define PRODUCT_HOME_PREMIUM 0x00000003 #define PRODUCT_ENTERPRISE 0x00000004 #define PRODUCT_HOME_BASIC_N 0x00000005 #define PRODUCT_BUSINESS 0x00000006 #define PRODUCT_STANDARD_SERVER 0x00000007 #define PRODUCT_DATACENTER_SERVER 0x00000008 #define PRODUCT_SMALLBUSINESS_SERVER 0x00000009 #define PRODUCT_ENTERPRISE_SERVER 0x0000000A #define PRODUCT_STARTER 0x0000000B #define PRODUCT_DATACENTER_SERVER_CORE 0x0000000C #define PRODUCT_STANDARD_SERVER_CORE 0x0000000D #define PRODUCT_ENTERPRISE_SERVER_CORE 0x0000000E #define PRODUCT_ENTERPRISE_SERVER_IA64 0x0000000F #define PRODUCT_BUSINESS_N 0x00000010 #define PRODUCT_WEB_SERVER 0x00000011 #define PRODUCT_CLUSTER_SERVER 0x00000012 #define PRODUCT_HOME_SERVER 0x00000013 #define PRODUCT_STORAGE_EXPRESS_SERVER 0x00000014 #define PRODUCT_STORAGE_STANDARD_SERVER 0x00000015 #define PRODUCT_STORAGE_WORKGROUP_SERVER 0x00000016 #define PRODUCT_STORAGE_ENTERPRISE_SERVER 0x00000017 #define PRODUCT_SERVER_FOR_SMALLBUSINESS 0x00000018 #define PRODUCT_SMALLBUSINESS_SERVER_PREMIUM 0x00000019 #define PRODUCT_HOME_PREMIUM_N 0x0000001A #define PRODUCT_ENTERPRISE_N 0x0000001B #define PRODUCT_ULTIMATE_N 0x0000001C #define PRODUCT_WEB_SERVER_CORE 0x0000001D #define PRODUCT_MEDIUMBUSINESS_SERVER_MANAGEMENT 0x0000001E #define PRODUCT_MEDIUMBUSINESS_SERVER_SECURITY 0x0000001F #define PRODUCT_MEDIUMBUSINESS_SERVER_MESSAGING 0x00000020 #define PRODUCT_SERVER_FOUNDATION 0x00000021 #define PRODUCT_HOME_PREMIUM_SERVER 0x00000022 #define PRODUCT_SERVER_FOR_SMALLBUSINESS_V 0x00000023 #define PRODUCT_STANDARD_SERVER_V 0x00000024 #define PRODUCT_DATACENTER_SERVER_V 0x00000025 #define PRODUCT_ENTERPRISE_SERVER_V 0x00000026 #define PRODUCT_DATACENTER_SERVER_CORE_V 0x00000027 #define PRODUCT_STANDARD_SERVER_CORE_V 0x00000028 #define PRODUCT_ENTERPRISE_SERVER_CORE_V 0x00000029 #define PRODUCT_HYPERV 0x0000002A #define PRODUCT_STORAGE_EXPRESS_SERVER_CORE 0x0000002B #define PRODUCT_STORAGE_STANDARD_SERVER_CORE 0x0000002C #define PRODUCT_STORAGE_WORKGROUP_SERVER_CORE 0x0000002D #define PRODUCT_STORAGE_ENTERPRISE_SERVER_CORE 0x0000002E #define PRODUCT_STARTER_N 0x0000002F #define PRODUCT_PROFESSIONAL 0x00000030 #define PRODUCT_PROFESSIONAL_N 0x00000031 #define PRODUCT_SB_SOLUTION_SERVER 0x00000032 #define PRODUCT_SERVER_FOR_SB_SOLUTIONS 0x00000033 #define PRODUCT_STANDARD_SERVER_SOLUTIONS 0x00000034 #define PRODUCT_STANDARD_SERVER_SOLUTIONS_CORE 0x00000035 #define PRODUCT_SB_SOLUTION_SERVER_EM 0x00000036 #define PRODUCT_SERVER_FOR_SB_SOLUTIONS_EM 0x00000037 #define PRODUCT_SOLUTION_EMBEDDEDSERVER 0x00000038 #define PRODUCT_ESSENTIALBUSINESS_SERVER_MGMT 0x0000003B #define PRODUCT_ESSENTIALBUSINESS_SERVER_ADDL 0x0000003C #define PRODUCT_ESSENTIALBUSINESS_SERVER_MGMTSVC 0x0000003D #define PRODUCT_ESSENTIALBUSINESS_SERVER_ADDLSVC 0x0000003E #define PRODUCT_SMALLBUSINESS_SERVER_PREMIUM_CORE 0x0000003F #define PRODUCT_CLUSTER_SERVER_V 0x00000040 #define PRODUCT_ENTERPRISE_EVALUATION 0x00000048 #define PRODUCT_MULTIPOINT_STANDARD_SERVER 0x0000004C #define PRODUCT_MULTIPOINT_PREMIUM_SERVER 0x0000004D #define PRODUCT_STANDARD_EVALUATION_SERVER 0x0000004F #define PRODUCT_DATACENTER_EVALUATION_SERVER 0x00000050 #define PRODUCT_ENTERPRISE_N_EVALUATION 0x00000054 #define PRODUCT_STORAGE_WORKGROUP_EVALUATION_SERVER 0x0000005F #define PRODUCT_STORAGE_STANDARD_EVALUATION_SERVER 0x00000060 #define PRODUCT_CORE_N 0x00000062 #define PRODUCT_CORE_COUNTRYSPECIFIC 0x00000063 #define PRODUCT_CORE_SINGLELANGUAGE 0x00000064 #define PRODUCT_CORE 0x00000065 #define PRODUCT_PROFESSIONAL_WMC 0x00000067 #endif #ifndef VER_NT_WORKSTATION #define VER_NT_WORKSTATION 0x0000001 #define VER_NT_DOMAIN_CONTROLLER 0x0000002 #define VER_NT_SERVER 0x0000003 #endif #ifndef VER_SUITE_SMALLBUSINESS #define VER_SUITE_SMALLBUSINESS 0x00000001 #define VER_SUITE_ENTERPRISE 0x00000002 #define VER_SUITE_BACKOFFICE 0x00000004 #define VER_SUITE_COMMUNICATIONS 0x00000008 #define VER_SUITE_TERMINAL 0x00000010 #define VER_SUITE_SMALLBUSINESS_RESTRICTED 0x00000020 #define VER_SUITE_EMBEDDEDNT 0x00000040 #define VER_SUITE_DATACENTER 0x00000080 #define VER_SUITE_SINGLEUSERTS 0x00000100 #define VER_SUITE_PERSONAL 0x00000200 #define VER_SUITE_BLADE 0x00000400 #define VER_SUITE_EMBEDDED_RESTRICTED 0x00000800 #define VER_SUITE_SECURITY_APPLIANCE 0x00001000 #endif #ifndef VER_SUITE_STORAGE_SERVER # define VER_SUITE_STORAGE_SERVER 0x00002000 #endif #ifndef VER_SUITE_COMPUTE_SERVER # define VER_SUITE_COMPUTE_SERVER 0x00004000 #endif #ifndef PROCESSOR_ARCHITECTURE_AMD64 #define PROCESSOR_ARCHITECTURE_AMD64 9 #endif #endif
6,377
46.597015
62
h
php-src
php-src-master/ext/standard/libavifinfo/avifinfo.h
// Copyright (c) 2021, Alliance for Open Media. All rights reserved // // This source code is subject to the terms of the BSD 2 Clause License and // the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License // was not distributed with this source code in the LICENSE file, you can // obtain it at www.aomedia.org/license/software. If the Alliance for Open // Media Patent License 1.0 was not distributed with this source code in the // PATENTS file, you can obtain it at www.aomedia.org/license/patent. #ifndef AVIFINFO_H_ #define AVIFINFO_H_ #include <stddef.h> #include <stdint.h> #ifdef __cplusplus extern "C" { #endif //------------------------------------------------------------------------------ typedef enum { kAvifInfoOk, // The file was correctly parsed and the requested // information was extracted. It is not guaranteed // that the input bitstream is a valid complete // AVIF file. kAvifInfoNotEnoughData, // The input bitstream was correctly parsed until // now but bytes are missing. The request should be // repeated with more input bytes. kAvifInfoTooComplex, // The input bitstream was correctly parsed until // now but it is too complex. The parsing was // stopped to avoid any timeout or crash. kAvifInfoInvalidFile, // The input bitstream is not a valid AVIF file, // truncated or not. } AvifInfoStatus; typedef struct { uint32_t width, height; // In number of pixels. Ignores mirror and rotation. uint32_t bit_depth; // Likely 8, 10 or 12 bits per channel per pixel. uint32_t num_channels; // Likely 1, 2, 3 or 4 channels: // (1 monochrome or 3 colors) + (0 or 1 alpha) } AvifInfoFeatures; //------------------------------------------------------------------------------ // Fixed-size input API // Use this API if a raw byte array of fixed size is available as input. // Parses the 'data' and returns kAvifInfoOk if it is identified as an AVIF. // The file type can be identified in the first 12 bytes of most AVIF files. AvifInfoStatus AvifInfoIdentify(const uint8_t* data, size_t data_size); // Parses the identified AVIF 'data' and extracts its 'features'. // 'data' can be partial but must point to the beginning of the AVIF file. // The 'features' can be parsed in the first 450 bytes of most AVIF files. // 'features' are set to 0 unless kAvifInfoOk is returned. AvifInfoStatus AvifInfoGetFeatures(const uint8_t* data, size_t data_size, AvifInfoFeatures* features); //------------------------------------------------------------------------------ // Streamed input API // Use this API if the input bytes must be fetched and/or if the AVIF payload // size is unknown. Implement the two function signatures below and pass them to // AvifInfoRead*() with a 'stream', which can be anything (file, struct etc.). // Reads 'num_bytes' from the 'stream'. // The position in the 'stream' must be advanced by 'num_bytes'. // Returns a pointer to the 'num_bytes' or null if it cannot be fulfilled. // The returned data must remain valid until the next read. typedef const uint8_t* (*read_stream_t)(void* stream, size_t num_bytes); // Advances the position in the 'stream' by 'num_bytes'. typedef void (*skip_stream_t)(void* stream, size_t num_bytes); // Maximum number of bytes requested per read. There is no limit per skip. #define AVIFINFO_MAX_NUM_READ_BYTES 64 // Same as AvifInfo*() but takes a 'stream' as input. AvifInfo*Stream() does // not access the 'stream' directly but passes it as is to 'read' and 'skip'. // 'read' cannot be null. If 'skip' is null, 'read' is called instead. AvifInfoStatus AvifInfoIdentifyStream(void* stream, read_stream_t read, skip_stream_t skip); // Can be called right after AvifInfoIdentifyStream() with the same 'stream'. AvifInfoStatus AvifInfoGetFeaturesStream(void* stream, read_stream_t read, skip_stream_t skip, AvifInfoFeatures* features); //------------------------------------------------------------------------------ #ifdef __cplusplus } // extern "C" #endif #endif // AVIFINFO_H_
4,427
46.612903
80
h
php-src
php-src-master/ext/sysvmsg/php_sysvmsg.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: Wez Furlong <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef PHP_SYSVMSG_H #define PHP_SYSVMSG_H #ifdef HAVE_SYSVMSG extern zend_module_entry sysvmsg_module_entry; #define phpext_sysvmsg_ptr &sysvmsg_module_entry #include "php_version.h" #define PHP_SYSVMSG_VERSION PHP_VERSION #endif /* HAVE_SYSVMSG */ /* In order to detect MSG_EXCEPT use at run time; we have no way * of knowing what the bit definitions are, so we can't just define * our own MSG_EXCEPT value. */ #define PHP_MSG_IPC_NOWAIT 1 #define PHP_MSG_NOERROR 2 #define PHP_MSG_EXCEPT 4 #endif /* PHP_SYSVMSG_H */
1,521
39.052632
74
h
php-src
php-src-master/ext/sysvmsg/sysvmsg.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: Wez Furlong <[email protected]> | +----------------------------------------------------------------------+ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "php.h" #include "php_globals.h" #include "ext/standard/info.h" #include "php_sysvmsg.h" #include "sysvmsg_arginfo.h" #include "ext/standard/php_var.h" #include "zend_smart_str.h" #include <sys/types.h> #include <sys/ipc.h> #include <sys/msg.h> PHP_MINIT_FUNCTION(sysvmsg); PHP_MINFO_FUNCTION(sysvmsg); typedef struct { key_t key; zend_long id; zend_object std; } sysvmsg_queue_t; struct php_msgbuf { zend_long mtype; char mtext[1]; }; /* {{{ sysvmsg_module_entry */ zend_module_entry sysvmsg_module_entry = { STANDARD_MODULE_HEADER, "sysvmsg", ext_functions, PHP_MINIT(sysvmsg), NULL, NULL, NULL, PHP_MINFO(sysvmsg), PHP_SYSVMSG_VERSION, STANDARD_MODULE_PROPERTIES }; /* }}} */ #ifdef COMPILE_DL_SYSVMSG ZEND_GET_MODULE(sysvmsg) #endif /* SysvMessageQueue class */ zend_class_entry *sysvmsg_queue_ce; static zend_object_handlers sysvmsg_queue_object_handlers; static inline sysvmsg_queue_t *sysvmsg_queue_from_obj(zend_object *obj) { return (sysvmsg_queue_t *)((char *)(obj) - XtOffsetOf(sysvmsg_queue_t, std)); } #define Z_SYSVMSG_QUEUE_P(zv) sysvmsg_queue_from_obj(Z_OBJ_P(zv)) static zend_object *sysvmsg_queue_create_object(zend_class_entry *class_type) { sysvmsg_queue_t *intern = zend_object_alloc(sizeof(sysvmsg_queue_t), class_type); zend_object_std_init(&intern->std, class_type); object_properties_init(&intern->std, class_type); return &intern->std; } static zend_function *sysvmsg_queue_get_constructor(zend_object *object) { zend_throw_error(NULL, "Cannot directly construct SysvMessageQueue, use msg_get_queue() instead"); return NULL; } static void sysvmsg_queue_free_obj(zend_object *object) { sysvmsg_queue_t *sysvmsg_queue = sysvmsg_queue_from_obj(object); zend_object_std_dtor(&sysvmsg_queue->std); } /* }}} */ /* {{{ PHP_MINIT_FUNCTION */ PHP_MINIT_FUNCTION(sysvmsg) { sysvmsg_queue_ce = register_class_SysvMessageQueue(); sysvmsg_queue_ce->create_object = sysvmsg_queue_create_object; sysvmsg_queue_ce->default_object_handlers = &sysvmsg_queue_object_handlers; memcpy(&sysvmsg_queue_object_handlers, &std_object_handlers, sizeof(zend_object_handlers)); sysvmsg_queue_object_handlers.offset = XtOffsetOf(sysvmsg_queue_t, std); sysvmsg_queue_object_handlers.free_obj = sysvmsg_queue_free_obj; sysvmsg_queue_object_handlers.get_constructor = sysvmsg_queue_get_constructor; sysvmsg_queue_object_handlers.clone_obj = NULL; sysvmsg_queue_object_handlers.compare = zend_objects_not_comparable; register_sysvmsg_symbols(module_number); return SUCCESS; } /* }}} */ /* {{{ PHP_MINFO_FUNCTION */ PHP_MINFO_FUNCTION(sysvmsg) { php_info_print_table_start(); php_info_print_table_row(2, "sysvmsg support", "enabled"); php_info_print_table_end(); } /* }}} */ /* {{{ Set information for a message queue */ PHP_FUNCTION(msg_set_queue) { zval *queue, *data; sysvmsg_queue_t *mq = NULL; struct msqid_ds stat; RETVAL_FALSE; if (zend_parse_parameters(ZEND_NUM_ARGS(), "Oa", &queue, sysvmsg_queue_ce, &data) == FAILURE) { RETURN_THROWS(); } mq = Z_SYSVMSG_QUEUE_P(queue); if (msgctl(mq->id, IPC_STAT, &stat) == 0) { zval *item; /* now pull out members of data and set them in the stat buffer */ if ((item = zend_hash_str_find(Z_ARRVAL_P(data), "msg_perm.uid", sizeof("msg_perm.uid") - 1)) != NULL) { stat.msg_perm.uid = zval_get_long(item); } if ((item = zend_hash_str_find(Z_ARRVAL_P(data), "msg_perm.gid", sizeof("msg_perm.gid") - 1)) != NULL) { stat.msg_perm.gid = zval_get_long(item); } if ((item = zend_hash_str_find(Z_ARRVAL_P(data), "msg_perm.mode", sizeof("msg_perm.mode") - 1)) != NULL) { stat.msg_perm.mode = zval_get_long(item); } if ((item = zend_hash_str_find(Z_ARRVAL_P(data), "msg_qbytes", sizeof("msg_qbytes") - 1)) != NULL) { stat.msg_qbytes = zval_get_long(item); } if (msgctl(mq->id, IPC_SET, &stat) == 0) { RETVAL_TRUE; } } } /* }}} */ /* {{{ Returns information about a message queue */ PHP_FUNCTION(msg_stat_queue) { zval *queue; sysvmsg_queue_t *mq = NULL; struct msqid_ds stat; RETVAL_FALSE; if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &queue, sysvmsg_queue_ce) == FAILURE) { RETURN_THROWS(); } mq = Z_SYSVMSG_QUEUE_P(queue); if (msgctl(mq->id, IPC_STAT, &stat) == 0) { array_init(return_value); add_assoc_long(return_value, "msg_perm.uid", stat.msg_perm.uid); add_assoc_long(return_value, "msg_perm.gid", stat.msg_perm.gid); add_assoc_long(return_value, "msg_perm.mode", stat.msg_perm.mode); add_assoc_long(return_value, "msg_stime", stat.msg_stime); add_assoc_long(return_value, "msg_rtime", stat.msg_rtime); add_assoc_long(return_value, "msg_ctime", stat.msg_ctime); add_assoc_long(return_value, "msg_qnum", stat.msg_qnum); add_assoc_long(return_value, "msg_qbytes", stat.msg_qbytes); add_assoc_long(return_value, "msg_lspid", stat.msg_lspid); add_assoc_long(return_value, "msg_lrpid", stat.msg_lrpid); } } /* }}} */ /* {{{ Check whether a message queue exists */ PHP_FUNCTION(msg_queue_exists) { zend_long key; if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &key) == FAILURE) { RETURN_THROWS(); } if (msgget(key, 0) < 0) { RETURN_FALSE; } RETURN_TRUE; } /* }}} */ /* {{{ Attach to a message queue */ PHP_FUNCTION(msg_get_queue) { zend_long key; zend_long perms = 0666; sysvmsg_queue_t *mq; if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|l", &key, &perms) == FAILURE) { RETURN_THROWS(); } object_init_ex(return_value, sysvmsg_queue_ce); mq = Z_SYSVMSG_QUEUE_P(return_value); mq->key = key; mq->id = msgget(key, 0); if (mq->id < 0) { /* doesn't already exist; create it */ mq->id = msgget(key, IPC_CREAT | IPC_EXCL | perms); if (mq->id < 0) { php_error_docref(NULL, E_WARNING, "Failed for key 0x" ZEND_XLONG_FMT ": %s", key, strerror(errno)); zval_ptr_dtor(return_value); RETURN_FALSE; } } } /* }}} */ /* {{{ Destroy the queue */ PHP_FUNCTION(msg_remove_queue) { zval *queue; sysvmsg_queue_t *mq = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &queue, sysvmsg_queue_ce) == FAILURE) { RETURN_THROWS(); } mq = Z_SYSVMSG_QUEUE_P(queue); if (msgctl(mq->id, IPC_RMID, NULL) == 0) { RETVAL_TRUE; } else { RETVAL_FALSE; } } /* }}} */ /* {{{ Send a message of type msgtype (must be > 0) to a message queue */ PHP_FUNCTION(msg_receive) { zval *out_message, *queue, *out_msgtype, *zerrcode = NULL; zend_long desiredmsgtype, maxsize, flags = 0; zend_long realflags = 0; bool do_unserialize = 1; sysvmsg_queue_t *mq = NULL; struct php_msgbuf *messagebuffer = NULL; /* buffer to transmit */ int result; RETVAL_FALSE; if (zend_parse_parameters(ZEND_NUM_ARGS(), "Olzlz|blz", &queue, sysvmsg_queue_ce, &desiredmsgtype, &out_msgtype, &maxsize, &out_message, &do_unserialize, &flags, &zerrcode) == FAILURE) { RETURN_THROWS(); } if (maxsize <= 0) { zend_argument_value_error(4, "must be greater than 0"); RETURN_THROWS(); } if (flags != 0) { if (flags & PHP_MSG_EXCEPT) { #ifndef MSG_EXCEPT php_error_docref(NULL, E_WARNING, "MSG_EXCEPT is not supported on your system"); RETURN_FALSE; #else realflags |= MSG_EXCEPT; #endif } if (flags & PHP_MSG_NOERROR) { realflags |= MSG_NOERROR; } if (flags & PHP_MSG_IPC_NOWAIT) { realflags |= IPC_NOWAIT; } } mq = Z_SYSVMSG_QUEUE_P(queue); messagebuffer = (struct php_msgbuf *) safe_emalloc(maxsize, 1, sizeof(struct php_msgbuf)); result = msgrcv(mq->id, messagebuffer, maxsize, desiredmsgtype, realflags); if (result >= 0) { /* got it! */ ZEND_TRY_ASSIGN_REF_LONG(out_msgtype, messagebuffer->mtype); if (zerrcode) { ZEND_TRY_ASSIGN_REF_LONG(zerrcode, 0); } RETVAL_TRUE; if (do_unserialize) { php_unserialize_data_t var_hash; zval tmp; const unsigned char *p = (const unsigned char *) messagebuffer->mtext; PHP_VAR_UNSERIALIZE_INIT(var_hash); if (!php_var_unserialize(&tmp, &p, p + result, &var_hash)) { php_error_docref(NULL, E_WARNING, "Message corrupted"); ZEND_TRY_ASSIGN_REF_FALSE(out_message); RETVAL_FALSE; } else { ZEND_TRY_ASSIGN_REF_TMP(out_message, &tmp); } PHP_VAR_UNSERIALIZE_DESTROY(var_hash); } else { ZEND_TRY_ASSIGN_REF_STRINGL(out_message, messagebuffer->mtext, result); } } else { ZEND_TRY_ASSIGN_REF_LONG(out_msgtype, 0); ZEND_TRY_ASSIGN_REF_FALSE(out_message); if (zerrcode) { ZEND_TRY_ASSIGN_REF_LONG(zerrcode, errno); } } efree(messagebuffer); } /* }}} */ /* {{{ Send a message of type msgtype (must be > 0) to a message queue */ PHP_FUNCTION(msg_send) { zval *message, *queue, *zerror=NULL; zend_long msgtype; bool do_serialize = 1, blocking = 1; sysvmsg_queue_t * mq = NULL; struct php_msgbuf * messagebuffer = NULL; /* buffer to transmit */ int result; size_t message_len = 0; RETVAL_FALSE; if (zend_parse_parameters(ZEND_NUM_ARGS(), "Olz|bbz", &queue, sysvmsg_queue_ce, &msgtype, &message, &do_serialize, &blocking, &zerror) == FAILURE) { RETURN_THROWS(); } mq = Z_SYSVMSG_QUEUE_P(queue); if (do_serialize) { smart_str msg_var = {0}; php_serialize_data_t var_hash; PHP_VAR_SERIALIZE_INIT(var_hash); php_var_serialize(&msg_var, message, &var_hash); PHP_VAR_SERIALIZE_DESTROY(var_hash); /* NB: php_msgbuf is 1 char bigger than a long, so there is no need to * allocate the extra byte. */ messagebuffer = safe_emalloc(ZSTR_LEN(msg_var.s), 1, sizeof(struct php_msgbuf)); memcpy(messagebuffer->mtext, ZSTR_VAL(msg_var.s), ZSTR_LEN(msg_var.s) + 1); message_len = ZSTR_LEN(msg_var.s); smart_str_free(&msg_var); } else { char *p; switch (Z_TYPE_P(message)) { case IS_STRING: p = Z_STRVAL_P(message); message_len = Z_STRLEN_P(message); break; case IS_LONG: message_len = spprintf(&p, 0, ZEND_LONG_FMT, Z_LVAL_P(message)); break; case IS_FALSE: message_len = spprintf(&p, 0, "0"); break; case IS_TRUE: message_len = spprintf(&p, 0, "1"); break; case IS_DOUBLE: message_len = spprintf(&p, 0, "%F", Z_DVAL_P(message)); break; default: zend_argument_type_error(3, "must be of type string|int|float|bool, %s given", zend_zval_value_name(message)); RETURN_THROWS(); } messagebuffer = safe_emalloc(message_len, 1, sizeof(struct php_msgbuf)); memcpy(messagebuffer->mtext, p, message_len + 1); if (Z_TYPE_P(message) != IS_STRING) { efree(p); } } /* set the message type */ messagebuffer->mtype = msgtype; result = msgsnd(mq->id, messagebuffer, message_len, blocking ? 0 : IPC_NOWAIT); efree(messagebuffer); if (result == -1) { php_error_docref(NULL, E_WARNING, "msgsnd failed: %s", strerror(errno)); if (zerror) { ZEND_TRY_ASSIGN_REF_LONG(zerror, errno); } } else { RETVAL_TRUE; } } /* }}} */
11,735
26.293023
114
c
php-src
php-src-master/ext/sysvmsg/sysvmsg_arginfo.h
/* This is a generated file, edit the .stub.php file instead. * Stub hash: ed5b1e4e5dda6a65ce336fc4daa975520c354f17 */ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_msg_get_queue, 0, 1, SysvMessageQueue, MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, key, IS_LONG, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, permissions, IS_LONG, 0, "0666") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_msg_send, 0, 3, _IS_BOOL, 0) ZEND_ARG_OBJ_INFO(0, queue, SysvMessageQueue, 0) ZEND_ARG_TYPE_INFO(0, message_type, IS_LONG, 0) ZEND_ARG_INFO(0, message) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, serialize, _IS_BOOL, 0, "true") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, blocking, _IS_BOOL, 0, "true") ZEND_ARG_INFO_WITH_DEFAULT_VALUE(1, error_code, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_msg_receive, 0, 5, _IS_BOOL, 0) ZEND_ARG_OBJ_INFO(0, queue, SysvMessageQueue, 0) ZEND_ARG_TYPE_INFO(0, desired_message_type, IS_LONG, 0) ZEND_ARG_INFO(1, received_message_type) ZEND_ARG_TYPE_INFO(0, max_message_size, IS_LONG, 0) ZEND_ARG_TYPE_INFO(1, message, IS_MIXED, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, unserialize, _IS_BOOL, 0, "true") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "0") ZEND_ARG_INFO_WITH_DEFAULT_VALUE(1, error_code, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_msg_remove_queue, 0, 1, _IS_BOOL, 0) ZEND_ARG_OBJ_INFO(0, queue, SysvMessageQueue, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_msg_stat_queue, 0, 1, MAY_BE_ARRAY|MAY_BE_FALSE) ZEND_ARG_OBJ_INFO(0, queue, SysvMessageQueue, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_msg_set_queue, 0, 2, _IS_BOOL, 0) ZEND_ARG_OBJ_INFO(0, queue, SysvMessageQueue, 0) ZEND_ARG_TYPE_INFO(0, data, IS_ARRAY, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_msg_queue_exists, 0, 1, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO(0, key, IS_LONG, 0) ZEND_END_ARG_INFO() ZEND_FUNCTION(msg_get_queue); ZEND_FUNCTION(msg_send); ZEND_FUNCTION(msg_receive); ZEND_FUNCTION(msg_remove_queue); ZEND_FUNCTION(msg_stat_queue); ZEND_FUNCTION(msg_set_queue); ZEND_FUNCTION(msg_queue_exists); static const zend_function_entry ext_functions[] = { ZEND_FE(msg_get_queue, arginfo_msg_get_queue) ZEND_FE(msg_send, arginfo_msg_send) ZEND_FE(msg_receive, arginfo_msg_receive) ZEND_FE(msg_remove_queue, arginfo_msg_remove_queue) ZEND_FE(msg_stat_queue, arginfo_msg_stat_queue) ZEND_FE(msg_set_queue, arginfo_msg_set_queue) ZEND_FE(msg_queue_exists, arginfo_msg_queue_exists) ZEND_FE_END }; static const zend_function_entry class_SysvMessageQueue_methods[] = { ZEND_FE_END }; static void register_sysvmsg_symbols(int module_number) { REGISTER_LONG_CONSTANT("MSG_IPC_NOWAIT", PHP_MSG_IPC_NOWAIT, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("MSG_EAGAIN", EAGAIN, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("MSG_ENOMSG", ENOMSG, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("MSG_NOERROR", PHP_MSG_NOERROR, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("MSG_EXCEPT", PHP_MSG_EXCEPT, CONST_PERSISTENT); } static zend_class_entry *register_class_SysvMessageQueue(void) { zend_class_entry ce, *class_entry; INIT_CLASS_ENTRY(ce, "SysvMessageQueue", class_SysvMessageQueue_methods); class_entry = zend_register_internal_class_ex(&ce, NULL); class_entry->ce_flags |= ZEND_ACC_FINAL|ZEND_ACC_NO_DYNAMIC_PROPERTIES|ZEND_ACC_NOT_SERIALIZABLE; return class_entry; }
3,480
37.252747
104
h
php-src
php-src-master/ext/sysvsem/php_sysvsem.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: Tom May <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef PHP_SYSVSEM_H #define PHP_SYSVSEM_H #ifdef HAVE_SYSVSEM extern zend_module_entry sysvsem_module_entry; #define sysvsem_module_ptr &sysvsem_module_entry #include "php_version.h" #define PHP_SYSVSEM_VERSION PHP_VERSION PHP_MINIT_FUNCTION(sysvsem); PHP_MINFO_FUNCTION(sysvsem); typedef struct { int key; /* For error reporting. */ int semid; /* Returned by semget(). */ int count; /* Acquire count for auto-release. */ int auto_release; /* flag that says to auto-release. */ zend_object std; } sysvsem_sem; #else #define sysvsem_module_ptr NULL #endif #define phpext_sysvsem_ptr sysvsem_module_ptr #endif /* PHP_SYSVSEM_H */
1,654
33.479167
75
h
php-src
php-src-master/ext/sysvsem/sysvsem.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: Tom May <[email protected]> | | Gavin Sherry <[email protected]> | +----------------------------------------------------------------------+ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "php.h" #ifdef HAVE_SYSVSEM #include <sys/types.h> #include <sys/ipc.h> #include <sys/sem.h> #include <errno.h> #include "sysvsem_arginfo.h" #include "php_sysvsem.h" #include "ext/standard/info.h" #if !HAVE_SEMUN union semun { int val; /* value for SETVAL */ struct semid_ds *buf; /* buffer for IPC_STAT, IPC_SET */ unsigned short int *array; /* array for GETALL, SETALL */ struct seminfo *__buf; /* buffer for IPC_INFO */ }; #undef HAVE_SEMUN #define HAVE_SEMUN 1 #endif /* {{{ sysvsem_module_entry */ zend_module_entry sysvsem_module_entry = { STANDARD_MODULE_HEADER, "sysvsem", ext_functions, PHP_MINIT(sysvsem), NULL, NULL, NULL, PHP_MINFO(sysvsem), PHP_SYSVSEM_VERSION, STANDARD_MODULE_PROPERTIES }; /* }}} */ #ifdef COMPILE_DL_SYSVSEM ZEND_GET_MODULE(sysvsem) #endif /* Semaphore functions using System V semaphores. Each semaphore * actually consists of three semaphores allocated as a unit under the * same key. Semaphore 0 (SYSVSEM_SEM) is the actual semaphore, it is * initialized to max_acquire and decremented as processes acquire it. * The value of semaphore 1 (SYSVSEM_USAGE) is a count of the number * of processes using the semaphore. After calling semget(), if a * process finds that the usage count is 1, it will set the value of * SYSVSEM_SEM to max_acquire. This allows max_acquire to be set and * track the PHP code without having a global init routine or external * semaphore init code. Except see the bug regarding a race condition * php_sysvsem_get(). Semaphore 2 (SYSVSEM_SETVAL) serializes the * calls to GETVAL SYSVSEM_USAGE and SETVAL SYSVSEM_SEM. It can be * acquired only when it is zero. */ #define SYSVSEM_SEM 0 #define SYSVSEM_USAGE 1 #define SYSVSEM_SETVAL 2 /* SysvSemaphore class */ zend_class_entry *sysvsem_ce; static zend_object_handlers sysvsem_object_handlers; static inline sysvsem_sem *sysvsem_from_obj(zend_object *obj) { return (sysvsem_sem *)((char *)(obj) - XtOffsetOf(sysvsem_sem, std)); } #define Z_SYSVSEM_P(zv) sysvsem_from_obj(Z_OBJ_P(zv)) static zend_object *sysvsem_create_object(zend_class_entry *class_type) { sysvsem_sem *intern = zend_object_alloc(sizeof(sysvsem_sem), class_type); zend_object_std_init(&intern->std, class_type); object_properties_init(&intern->std, class_type); return &intern->std; } static zend_function *sysvsem_get_constructor(zend_object *object) { zend_throw_error(NULL, "Cannot directly construct SysvSemaphore, use sem_get() instead"); return NULL; } static void sysvsem_free_obj(zend_object *object) { sysvsem_sem *sem_ptr = sysvsem_from_obj(object); struct sembuf sop[2]; int opcount = 1; /* * if count == -1, semaphore has been removed * Need better way to handle this */ if (sem_ptr->count == -1 || !sem_ptr->auto_release) { zend_object_std_dtor(&sem_ptr->std); return; } /* Decrement the usage count. */ sop[0].sem_num = SYSVSEM_USAGE; sop[0].sem_op = -1; sop[0].sem_flg = SEM_UNDO; /* Release the semaphore if it has been acquired but not released. */ if (sem_ptr->count) { sop[1].sem_num = SYSVSEM_SEM; sop[1].sem_op = sem_ptr->count; sop[1].sem_flg = SEM_UNDO; opcount++; } semop(sem_ptr->semid, sop, opcount); zend_object_std_dtor(&sem_ptr->std); } /* }}} */ /* {{{ PHP_MINIT_FUNCTION */ PHP_MINIT_FUNCTION(sysvsem) { sysvsem_ce = register_class_SysvSemaphore(); sysvsem_ce->create_object = sysvsem_create_object; sysvsem_ce->default_object_handlers = &sysvsem_object_handlers; memcpy(&sysvsem_object_handlers, &std_object_handlers, sizeof(zend_object_handlers)); sysvsem_object_handlers.offset = XtOffsetOf(sysvsem_sem, std); sysvsem_object_handlers.free_obj = sysvsem_free_obj; sysvsem_object_handlers.get_constructor = sysvsem_get_constructor; sysvsem_object_handlers.clone_obj = NULL; sysvsem_object_handlers.compare = zend_objects_not_comparable; return SUCCESS; } /* }}} */ /* {{{ PHP_MINFO_FUNCTION */ PHP_MINFO_FUNCTION(sysvsem) { php_info_print_table_start(); php_info_print_table_row(2, "sysvsem support", "enabled"); php_info_print_table_end(); } /* }}} */ #define SETVAL_WANTS_PTR #if defined(_AIX) #undef SETVAL_WANTS_PTR #endif /* {{{ Return an id for the semaphore with the given key, and allow max_acquire (default 1) processes to acquire it simultaneously */ PHP_FUNCTION(sem_get) { zend_long key, max_acquire = 1, perm = 0666; bool auto_release = 1; int semid; struct sembuf sop[3]; int count; sysvsem_sem *sem_ptr; if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS(), "l|llb", &key, &max_acquire, &perm, &auto_release)) { RETURN_THROWS(); } /* Get/create the semaphore. Note that we rely on the semaphores * being zeroed when they are created. Despite the fact that * the(?) Linux semget() man page says they are not initialized, * the kernel versions 2.0.x and 2.1.z do in fact zero them. */ semid = semget(key, 3, perm|IPC_CREAT); if (semid == -1) { php_error_docref(NULL, E_WARNING, "Failed for key 0x" ZEND_XLONG_FMT ": %s", key, strerror(errno)); RETURN_FALSE; } /* Find out how many processes are using this semaphore. Note * that on Linux (at least) there is a race condition here because * semaphore undo on process exit is not atomic, so we could * acquire SYSVSEM_SETVAL before a crashed process has decremented * SYSVSEM_USAGE in which case count will be greater than it * should be and we won't set max_acquire. Fortunately this * doesn't actually matter in practice. */ /* Wait for sem 1 to be zero . . . */ sop[0].sem_num = SYSVSEM_SETVAL; sop[0].sem_op = 0; sop[0].sem_flg = 0; /* . . . and increment it so it becomes non-zero . . . */ sop[1].sem_num = SYSVSEM_SETVAL; sop[1].sem_op = 1; sop[1].sem_flg = SEM_UNDO; /* . . . and increment the usage count. */ sop[2].sem_num = SYSVSEM_USAGE; sop[2].sem_op = 1; sop[2].sem_flg = SEM_UNDO; while (semop(semid, sop, 3) == -1) { if (errno != EINTR) { php_error_docref(NULL, E_WARNING, "Failed acquiring SYSVSEM_SETVAL for key 0x" ZEND_XLONG_FMT ": %s", key, strerror(errno)); break; } } /* Get the usage count. */ count = semctl(semid, SYSVSEM_USAGE, GETVAL, NULL); if (count == -1) { php_error_docref(NULL, E_WARNING, "Failed for key 0x" ZEND_XLONG_FMT ": %s", key, strerror(errno)); } /* If we are the only user, then take this opportunity to set the max. */ if (count == 1) { #if HAVE_SEMUN /* This is correct for Linux which has union semun. */ union semun semarg; semarg.val = max_acquire; if (semctl(semid, SYSVSEM_SEM, SETVAL, semarg) == -1) { php_error_docref(NULL, E_WARNING, "Failed for key 0x" ZEND_XLONG_FMT ": %s", key, strerror(errno)); } #elif defined(SETVAL_WANTS_PTR) /* This is correct for Solaris 2.6 which does not have union semun. */ if (semctl(semid, SYSVSEM_SEM, SETVAL, &max_acquire) == -1) { php_error_docref(NULL, E_WARNING, "Failed for key 0x%lx: %s", key, strerror(errno)); } #else /* This works for i.e. AIX */ if (semctl(semid, SYSVSEM_SEM, SETVAL, max_acquire) == -1) { php_error_docref(NULL, E_WARNING, "Failed for key 0x%lx: %s", key, strerror(errno)); } #endif } /* Set semaphore 1 back to zero. */ sop[0].sem_num = SYSVSEM_SETVAL; sop[0].sem_op = -1; sop[0].sem_flg = SEM_UNDO; while (semop(semid, sop, 1) == -1) { if (errno != EINTR) { php_error_docref(NULL, E_WARNING, "Failed releasing SYSVSEM_SETVAL for key 0x" ZEND_XLONG_FMT ": %s", key, strerror(errno)); break; } } object_init_ex(return_value, sysvsem_ce); sem_ptr = Z_SYSVSEM_P(return_value); sem_ptr->key = key; sem_ptr->semid = semid; sem_ptr->count = 0; sem_ptr->auto_release = (int) auto_release; } /* }}} */ /* {{{ php_sysvsem_semop */ static void php_sysvsem_semop(INTERNAL_FUNCTION_PARAMETERS, int acquire) { zval *arg_id; bool nowait = 0; sysvsem_sem *sem_ptr; struct sembuf sop; if (acquire) { if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|b", &arg_id, sysvsem_ce, &nowait) == FAILURE) { RETURN_THROWS(); } } else { if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &arg_id, sysvsem_ce) == FAILURE) { RETURN_THROWS(); } } sem_ptr = Z_SYSVSEM_P(arg_id); if (!acquire && sem_ptr->count == 0) { php_error_docref(NULL, E_WARNING, "SysV semaphore for key 0x%x is not currently acquired", sem_ptr->key); RETURN_FALSE; } sop.sem_num = SYSVSEM_SEM; sop.sem_op = acquire ? -1 : 1; sop.sem_flg = SEM_UNDO | (nowait ? IPC_NOWAIT : 0); while (semop(sem_ptr->semid, &sop, 1) == -1) { if (errno != EINTR) { if (errno != EAGAIN) { php_error_docref(NULL, E_WARNING, "Failed to %s key 0x%x: %s", acquire ? "acquire" : "release", sem_ptr->key, strerror(errno)); } RETURN_FALSE; } } sem_ptr->count -= acquire ? -1 : 1; RETURN_TRUE; } /* }}} */ /* {{{ Acquires the semaphore with the given id, blocking if necessary */ PHP_FUNCTION(sem_acquire) { php_sysvsem_semop(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); } /* }}} */ /* {{{ Releases the semaphore with the given id */ PHP_FUNCTION(sem_release) { php_sysvsem_semop(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); } /* }}} */ /* {{{ Removes semaphore from Unix systems */ /* * contributed by Gavin Sherry [email protected] * Fri Mar 16 00:50:13 EST 2001 */ PHP_FUNCTION(sem_remove) { zval *arg_id; sysvsem_sem *sem_ptr; #if HAVE_SEMUN union semun un; struct semid_ds buf; #endif if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &arg_id, sysvsem_ce) == FAILURE) { RETURN_THROWS(); } sem_ptr = Z_SYSVSEM_P(arg_id); #if HAVE_SEMUN un.buf = &buf; if (semctl(sem_ptr->semid, 0, IPC_STAT, un) < 0) { #else if (semctl(sem_ptr->semid, 0, IPC_STAT, NULL) < 0) { #endif php_error_docref(NULL, E_WARNING, "SysV semaphore for key 0x%x does not (any longer) exist", sem_ptr->key); RETURN_FALSE; } #if HAVE_SEMUN if (semctl(sem_ptr->semid, 0, IPC_RMID, un) < 0) { #else if (semctl(sem_ptr->semid, 0, IPC_RMID, NULL) < 0) { #endif php_error_docref(NULL, E_WARNING, "Failed for SysV semaphore for key 0x%x: %s", sem_ptr->key, strerror(errno)); RETURN_FALSE; } /* let release_sysvsem_sem know we have removed * the semaphore to avoid issues with releasing. */ sem_ptr->count = -1; RETURN_TRUE; } /* }}} */ #endif /* HAVE_SYSVSEM */
11,360
27.331671
133
c
php-src
php-src-master/ext/sysvsem/sysvsem_arginfo.h
/* This is a generated file, edit the .stub.php file instead. * Stub hash: 946ea9d0d2156ced1bac460d7d5fc3420e1934bb */ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_sem_get, 0, 1, SysvSemaphore, MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, key, IS_LONG, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, max_acquire, IS_LONG, 0, "1") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, permissions, IS_LONG, 0, "0666") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, auto_release, _IS_BOOL, 0, "true") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sem_acquire, 0, 1, _IS_BOOL, 0) ZEND_ARG_OBJ_INFO(0, semaphore, SysvSemaphore, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, non_blocking, _IS_BOOL, 0, "false") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sem_release, 0, 1, _IS_BOOL, 0) ZEND_ARG_OBJ_INFO(0, semaphore, SysvSemaphore, 0) ZEND_END_ARG_INFO() #define arginfo_sem_remove arginfo_sem_release ZEND_FUNCTION(sem_get); ZEND_FUNCTION(sem_acquire); ZEND_FUNCTION(sem_release); ZEND_FUNCTION(sem_remove); static const zend_function_entry ext_functions[] = { ZEND_FE(sem_get, arginfo_sem_get) ZEND_FE(sem_acquire, arginfo_sem_acquire) ZEND_FE(sem_release, arginfo_sem_release) ZEND_FE(sem_remove, arginfo_sem_remove) ZEND_FE_END }; static const zend_function_entry class_SysvSemaphore_methods[] = { ZEND_FE_END }; static zend_class_entry *register_class_SysvSemaphore(void) { zend_class_entry ce, *class_entry; INIT_CLASS_ENTRY(ce, "SysvSemaphore", class_SysvSemaphore_methods); class_entry = zend_register_internal_class_ex(&ce, NULL); class_entry->ce_flags |= ZEND_ACC_FINAL|ZEND_ACC_NO_DYNAMIC_PROPERTIES|ZEND_ACC_NOT_SERIALIZABLE; return class_entry; }
1,709
31.884615
98
h
php-src
php-src-master/ext/sysvshm/php_sysvshm.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: Christian Cartus <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef PHP_SYSVSHM_H #define PHP_SYSVSHM_H #ifdef HAVE_SYSVSHM extern zend_module_entry sysvshm_module_entry; #define sysvshm_module_ptr &sysvshm_module_entry #include "php_version.h" #define PHP_SYSVSHM_VERSION PHP_VERSION #include <sys/types.h> #ifdef PHP_WIN32 # include <TSRM/tsrm_win32.h> # include "win32/ipc.h" #else # include <sys/ipc.h> # include <sys/shm.h> #endif typedef struct { zend_long init_mem; } sysvshm_module; typedef struct { zend_long key; zend_long length; zend_long next; char mem; } sysvshm_chunk; typedef struct { char magic[8]; zend_long start; zend_long end; zend_long free; zend_long total; } sysvshm_chunk_head; typedef struct { key_t key; /* key set by user */ zend_long id; /* returned by shmget */ sysvshm_chunk_head *ptr; /* memory address of shared memory */ zend_object std; } sysvshm_shm; PHP_MINIT_FUNCTION(sysvshm); PHP_MINFO_FUNCTION(sysvshm); extern sysvshm_module php_sysvshm; #else #define sysvshm_module_ptr NULL #endif #define phpext_sysvshm_ptr sysvshm_module_ptr #endif /* PHP_SYSVSHM_H */
2,093
25.846154
75
h
php-src
php-src-master/ext/sysvshm/sysvshm_arginfo.h
/* This is a generated file, edit the .stub.php file instead. * Stub hash: 93677b78d9aaa4d6dbb5d1dcf3e79a8418add5c0 */ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_shm_attach, 0, 1, SysvSharedMemory, MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, key, IS_LONG, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, size, IS_LONG, 1, "null") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, permissions, IS_LONG, 0, "0666") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_shm_detach, 0, 1, _IS_BOOL, 0) ZEND_ARG_OBJ_INFO(0, shm, SysvSharedMemory, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_shm_has_var, 0, 2, _IS_BOOL, 0) ZEND_ARG_OBJ_INFO(0, shm, SysvSharedMemory, 0) ZEND_ARG_TYPE_INFO(0, key, IS_LONG, 0) ZEND_END_ARG_INFO() #define arginfo_shm_remove arginfo_shm_detach ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_shm_put_var, 0, 3, _IS_BOOL, 0) ZEND_ARG_OBJ_INFO(0, shm, SysvSharedMemory, 0) ZEND_ARG_TYPE_INFO(0, key, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, value, IS_MIXED, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_shm_get_var, 0, 2, IS_MIXED, 0) ZEND_ARG_OBJ_INFO(0, shm, SysvSharedMemory, 0) ZEND_ARG_TYPE_INFO(0, key, IS_LONG, 0) ZEND_END_ARG_INFO() #define arginfo_shm_remove_var arginfo_shm_has_var ZEND_FUNCTION(shm_attach); ZEND_FUNCTION(shm_detach); ZEND_FUNCTION(shm_has_var); ZEND_FUNCTION(shm_remove); ZEND_FUNCTION(shm_put_var); ZEND_FUNCTION(shm_get_var); ZEND_FUNCTION(shm_remove_var); static const zend_function_entry ext_functions[] = { ZEND_FE(shm_attach, arginfo_shm_attach) ZEND_FE(shm_detach, arginfo_shm_detach) ZEND_FE(shm_has_var, arginfo_shm_has_var) ZEND_FE(shm_remove, arginfo_shm_remove) ZEND_FE(shm_put_var, arginfo_shm_put_var) ZEND_FE(shm_get_var, arginfo_shm_get_var) ZEND_FE(shm_remove_var, arginfo_shm_remove_var) ZEND_FE_END }; static const zend_function_entry class_SysvSharedMemory_methods[] = { ZEND_FE_END }; static zend_class_entry *register_class_SysvSharedMemory(void) { zend_class_entry ce, *class_entry; INIT_CLASS_ENTRY(ce, "SysvSharedMemory", class_SysvSharedMemory_methods); class_entry = zend_register_internal_class_ex(&ce, NULL); class_entry->ce_flags |= ZEND_ACC_FINAL|ZEND_ACC_NO_DYNAMIC_PROPERTIES|ZEND_ACC_NOT_SERIALIZABLE; return class_entry; }
2,301
31.885714
101
h
php-src
php-src-master/ext/tidy/php_tidy.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: John Coggeshall <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef PHP_TIDY_H #define PHP_TIDY_H extern zend_module_entry tidy_module_entry; #define phpext_tidy_ptr &tidy_module_entry #include "php_version.h" #define PHP_TIDY_VERSION PHP_VERSION ZEND_BEGIN_MODULE_GLOBALS(tidy) char *default_config; bool clean_output; ZEND_END_MODULE_GLOBALS(tidy) #define TG(v) ZEND_MODULE_GLOBALS_ACCESSOR(tidy, v) #if defined(ZTS) && defined(COMPILE_DL_TIDY) ZEND_TSRMLS_CACHE_EXTERN() #endif #endif
1,418
36.342105
74
h
php-src
php-src-master/ext/tokenizer/php_tokenizer.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: Andrei Zmievski <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef PHP_TOKENIZER_H #define PHP_TOKENIZER_H extern zend_module_entry tokenizer_module_entry; #define phpext_tokenizer_ptr &tokenizer_module_entry #include "php_version.h" #define PHP_TOKENIZER_VERSION PHP_VERSION #define TOKEN_PARSE (1 << 0) #ifdef ZTS #include "TSRM.h" #endif char *get_token_type_name(int token_type); PHP_MINIT_FUNCTION(tokenizer); PHP_MINFO_FUNCTION(tokenizer); #endif /* PHP_TOKENIZER_H */
1,420
35.435897
75
h
php-src
php-src-master/ext/tokenizer/tokenizer.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: Andrei Zmievski <[email protected]> | +----------------------------------------------------------------------+ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "php.h" #include "php_ini.h" #include "ext/standard/info.h" #include "php_tokenizer.h" #include "zend.h" #include "zend_exceptions.h" #include "zend_language_scanner.h" #include "zend_language_scanner_defs.h" #include <zend_language_parser.h> #include "zend_interfaces.h" #include "tokenizer_data_arginfo.h" #include "tokenizer_arginfo.h" #define zendtext LANG_SCNG(yy_text) #define zendleng LANG_SCNG(yy_leng) #define zendcursor LANG_SCNG(yy_cursor) #define zendlimit LANG_SCNG(yy_limit) zend_class_entry *php_token_ce; /* {{{ tokenizer_module_entry */ zend_module_entry tokenizer_module_entry = { STANDARD_MODULE_HEADER, "tokenizer", ext_functions, PHP_MINIT(tokenizer), NULL, NULL, NULL, PHP_MINFO(tokenizer), PHP_TOKENIZER_VERSION, STANDARD_MODULE_PROPERTIES }; /* }}} */ #ifdef COMPILE_DL_TOKENIZER ZEND_GET_MODULE(tokenizer) #endif static zval *php_token_get_id(zval *obj) { zval *id = OBJ_PROP_NUM(Z_OBJ_P(obj), 0); if (Z_ISUNDEF_P(id)) { zend_throw_error(NULL, "Typed property PhpToken::$id must not be accessed before initialization"); return NULL; } ZVAL_DEREF(id); ZEND_ASSERT(Z_TYPE_P(id) == IS_LONG); return id; } static zend_string *php_token_get_text(zval *obj) { zval *text_zval = OBJ_PROP_NUM(Z_OBJ_P(obj), 1); if (Z_ISUNDEF_P(text_zval)) { zend_throw_error(NULL, "Typed property PhpToken::$text must not be accessed before initialization"); return NULL; } ZVAL_DEREF(text_zval); ZEND_ASSERT(Z_TYPE_P(text_zval) == IS_STRING); return Z_STR_P(text_zval); } static bool tokenize_common( zval *return_value, zend_string *source, zend_long flags, zend_class_entry *token_class); PHP_METHOD(PhpToken, tokenize) { zend_string *source; zend_long flags = 0; zend_class_entry *token_class; ZEND_PARSE_PARAMETERS_START(1, 2) Z_PARAM_STR(source) Z_PARAM_OPTIONAL Z_PARAM_LONG(flags) ZEND_PARSE_PARAMETERS_END(); token_class = zend_get_called_scope(execute_data); /* Check construction preconditions in advance, so these are not repeated for each token. */ if (token_class->ce_flags & ZEND_ACC_EXPLICIT_ABSTRACT_CLASS) { zend_throw_error(NULL, "Cannot instantiate abstract class %s", ZSTR_VAL(token_class->name)); RETURN_THROWS(); } if (zend_update_class_constants(token_class) == FAILURE) { RETURN_THROWS(); } if (!tokenize_common(return_value, source, flags, token_class)) { RETURN_THROWS(); } } PHP_METHOD(PhpToken, __construct) { zend_long id; zend_string *text; zend_long line = -1; zend_long pos = -1; zend_object *obj = Z_OBJ_P(ZEND_THIS); ZEND_PARSE_PARAMETERS_START(2, 4) Z_PARAM_LONG(id) Z_PARAM_STR(text) Z_PARAM_OPTIONAL Z_PARAM_LONG(line) Z_PARAM_LONG(pos) ZEND_PARSE_PARAMETERS_END(); ZVAL_LONG(OBJ_PROP_NUM(obj, 0), id); zval_ptr_dtor(OBJ_PROP_NUM(obj, 1)); ZVAL_STR_COPY(OBJ_PROP_NUM(obj, 1), text); ZVAL_LONG(OBJ_PROP_NUM(obj, 2), line); ZVAL_LONG(OBJ_PROP_NUM(obj, 3), pos); } PHP_METHOD(PhpToken, is) { zval *kind; ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_ZVAL(kind) ZEND_PARSE_PARAMETERS_END(); if (Z_TYPE_P(kind) == IS_LONG) { zval *id_zval = php_token_get_id(ZEND_THIS); if (!id_zval) { RETURN_THROWS(); } RETURN_BOOL(Z_LVAL_P(id_zval) == Z_LVAL_P(kind)); } else if (Z_TYPE_P(kind) == IS_STRING) { zend_string *text = php_token_get_text(ZEND_THIS); if (!text) { RETURN_THROWS(); } RETURN_BOOL(zend_string_equals(text, Z_STR_P(kind))); } else if (Z_TYPE_P(kind) == IS_ARRAY) { zval *id_zval = NULL, *entry; zend_string *text = NULL; ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(kind), entry) { ZVAL_DEREF(entry); if (Z_TYPE_P(entry) == IS_LONG) { if (!id_zval) { id_zval = php_token_get_id(ZEND_THIS); if (!id_zval) { RETURN_THROWS(); } } if (Z_LVAL_P(id_zval) == Z_LVAL_P(entry)) { RETURN_TRUE; } } else if (Z_TYPE_P(entry) == IS_STRING) { if (!text) { text = php_token_get_text(ZEND_THIS); if (!text) { RETURN_THROWS(); } } if (zend_string_equals(text, Z_STR_P(entry))) { RETURN_TRUE; } } else { zend_argument_type_error(1, "must only have elements of type string|int, %s given", zend_zval_value_name(entry)); RETURN_THROWS(); } } ZEND_HASH_FOREACH_END(); RETURN_FALSE; } else { zend_argument_type_error(1, "must be of type string|int|array, %s given", zend_zval_value_name(kind)); RETURN_THROWS(); } } PHP_METHOD(PhpToken, isIgnorable) { ZEND_PARSE_PARAMETERS_NONE(); zval *id_zval = php_token_get_id(ZEND_THIS); if (!id_zval) { RETURN_THROWS(); } zend_long id = Z_LVAL_P(id_zval); RETURN_BOOL(id == T_WHITESPACE || id == T_COMMENT || id == T_DOC_COMMENT || id == T_OPEN_TAG); } PHP_METHOD(PhpToken, getTokenName) { ZEND_PARSE_PARAMETERS_NONE(); zval *id_zval = php_token_get_id(ZEND_THIS); if (!id_zval) { RETURN_THROWS(); } if (Z_LVAL_P(id_zval) < 256) { RETURN_CHAR(Z_LVAL_P(id_zval)); } else { const char *token_name = get_token_type_name(Z_LVAL_P(id_zval)); if (!token_name) { RETURN_NULL(); } RETURN_STRING(token_name); } } PHP_METHOD(PhpToken, __toString) { ZEND_PARSE_PARAMETERS_NONE(); zend_string *text = php_token_get_text(ZEND_THIS); if (!text) { RETURN_THROWS(); } RETURN_STR_COPY(text); } /* {{{ PHP_MINIT_FUNCTION */ PHP_MINIT_FUNCTION(tokenizer) { register_tokenizer_data_symbols(module_number); register_tokenizer_symbols(module_number); php_token_ce = register_class_PhpToken(zend_ce_stringable); return SUCCESS; } /* }}} */ /* {{{ PHP_MINFO_FUNCTION */ PHP_MINFO_FUNCTION(tokenizer) { php_info_print_table_start(); php_info_print_table_row(2, "Tokenizer Support", "enabled"); php_info_print_table_end(); } /* }}} */ static zend_string *make_str(unsigned char *text, size_t leng, HashTable *interned_strings) { if (leng == 1) { return ZSTR_CHAR(text[0]); } else if (interned_strings) { zend_string *interned_str = zend_hash_str_find_ptr(interned_strings, (char *) text, leng); if (interned_str) { return zend_string_copy(interned_str); } interned_str = zend_string_init((char *) text, leng, 0); zend_hash_add_new_ptr(interned_strings, interned_str, interned_str); return interned_str; } else { return zend_string_init((char *) text, leng, 0); } } static void add_token( zval *return_value, int token_type, unsigned char *text, size_t leng, int lineno, zend_class_entry *token_class, HashTable *interned_strings) { zval token; if (token_class) { zend_object *obj = zend_objects_new(token_class); ZVAL_OBJ(&token, obj); ZVAL_LONG(OBJ_PROP_NUM(obj, 0), token_type); ZVAL_STR(OBJ_PROP_NUM(obj, 1), make_str(text, leng, interned_strings)); ZVAL_LONG(OBJ_PROP_NUM(obj, 2), lineno); ZVAL_LONG(OBJ_PROP_NUM(obj, 3), text - LANG_SCNG(yy_start)); /* If the class is extended with additional properties, initialized them as well. */ if (UNEXPECTED(token_class->default_properties_count > 4)) { zval *dst = OBJ_PROP_NUM(obj, 4); zval *src = &token_class->default_properties_table[4]; zval *end = token_class->default_properties_table + token_class->default_properties_count; for (; src < end; src++, dst++) { ZVAL_COPY_PROP(dst, src); } } } else if (token_type >= 256) { array_init_size(&token, 3); zend_hash_real_init_packed(Z_ARRVAL(token)); ZEND_HASH_FILL_PACKED(Z_ARRVAL(token)) { ZEND_HASH_FILL_SET_LONG(token_type); ZEND_HASH_FILL_NEXT(); ZEND_HASH_FILL_SET_STR(make_str(text, leng, interned_strings)); ZEND_HASH_FILL_NEXT(); ZEND_HASH_FILL_SET_LONG(lineno); ZEND_HASH_FILL_NEXT(); } ZEND_HASH_FILL_END(); } else { ZVAL_STR(&token, make_str(text, leng, interned_strings)); } zend_hash_next_index_insert_new(Z_ARRVAL_P(return_value), &token); } static bool tokenize(zval *return_value, zend_string *source, zend_class_entry *token_class) { zval source_zval; zend_lex_state original_lex_state; zval token; int token_type; int token_line = 1; int need_tokens = -1; /* for __halt_compiler lexing. -1 = disabled */ HashTable interned_strings; ZVAL_STR_COPY(&source_zval, source); zend_save_lexical_state(&original_lex_state); zend_prepare_string_for_scanning(&source_zval, ZSTR_EMPTY_ALLOC()); LANG_SCNG(yy_state) = yycINITIAL; zend_hash_init(&interned_strings, 0, NULL, NULL, 0); array_init(return_value); while ((token_type = lex_scan(&token, NULL))) { ZEND_ASSERT(token_type != T_ERROR); add_token( return_value, token_type, zendtext, zendleng, token_line, token_class, &interned_strings); if (Z_TYPE(token) != IS_UNDEF) { zval_ptr_dtor_nogc(&token); ZVAL_UNDEF(&token); } /* after T_HALT_COMPILER collect the next three non-dropped tokens */ if (need_tokens != -1) { if (token_type != T_WHITESPACE && token_type != T_OPEN_TAG && token_type != T_COMMENT && token_type != T_DOC_COMMENT && --need_tokens == 0 ) { /* fetch the rest into a T_INLINE_HTML */ if (zendcursor < zendlimit) { add_token( return_value, T_INLINE_HTML, zendcursor, zendlimit - zendcursor, token_line, token_class, &interned_strings); } break; } } else if (token_type == T_HALT_COMPILER) { need_tokens = 3; } if (CG(increment_lineno)) { CG(zend_lineno)++; CG(increment_lineno) = 0; } token_line = CG(zend_lineno); } zval_ptr_dtor_str(&source_zval); zend_restore_lexical_state(&original_lex_state); zend_hash_destroy(&interned_strings); return 1; } struct event_context { zval *tokens; zend_class_entry *token_class; }; static zval *extract_token_id_to_replace(zval *token_zv, const char *text, size_t length) { zval *id_zv, *text_zv; ZEND_ASSERT(token_zv); if (Z_TYPE_P(token_zv) == IS_ARRAY) { id_zv = zend_hash_index_find(Z_ARRVAL_P(token_zv), 0); text_zv = zend_hash_index_find(Z_ARRVAL_P(token_zv), 1); } else if (Z_TYPE_P(token_zv) == IS_OBJECT) { id_zv = OBJ_PROP_NUM(Z_OBJ_P(token_zv), 0); text_zv = OBJ_PROP_NUM(Z_OBJ_P(token_zv), 1); } else { return NULL; } /* There are multiple candidate tokens to which this feedback may apply, * check text to make sure this is the right one. */ ZEND_ASSERT(Z_TYPE_P(text_zv) == IS_STRING); if (Z_STRLEN_P(text_zv) == length && !memcmp(Z_STRVAL_P(text_zv), text, length)) { return id_zv; } return NULL; } void on_event( zend_php_scanner_event event, int token, int line, const char *text, size_t length, void *context) { struct event_context *ctx = context; switch (event) { case ON_TOKEN: if (token == END) break; /* Special cases */ if (token == ';' && LANG_SCNG(yy_leng) > 1) { /* ?> or ?>\n or ?>\r\n */ token = T_CLOSE_TAG; } else if (token == T_ECHO && LANG_SCNG(yy_leng) == sizeof("<?=") - 1) { token = T_OPEN_TAG_WITH_ECHO; } add_token( ctx->tokens, token, (unsigned char *) text, length, line, ctx->token_class, NULL); break; case ON_FEEDBACK: { HashTable *tokens_ht = Z_ARRVAL_P(ctx->tokens); zval *token_zv, *id_zv = NULL; ZEND_HASH_REVERSE_FOREACH_VAL(tokens_ht, token_zv) { id_zv = extract_token_id_to_replace(token_zv, text, length); if (id_zv) { break; } } ZEND_HASH_FOREACH_END(); ZEND_ASSERT(id_zv); ZVAL_LONG(id_zv, token); break; } case ON_STOP: if (LANG_SCNG(yy_cursor) != LANG_SCNG(yy_limit)) { add_token(ctx->tokens, T_INLINE_HTML, LANG_SCNG(yy_cursor), LANG_SCNG(yy_limit) - LANG_SCNG(yy_cursor), CG(zend_lineno), ctx->token_class, NULL); } break; } } static bool tokenize_parse( zval *return_value, zend_string *source, zend_class_entry *token_class) { zval source_zval; struct event_context ctx; zval token_stream; zend_lex_state original_lex_state; bool original_in_compilation; bool success; ZVAL_STR_COPY(&source_zval, source); original_in_compilation = CG(in_compilation); CG(in_compilation) = 1; zend_save_lexical_state(&original_lex_state); zend_prepare_string_for_scanning(&source_zval, ZSTR_EMPTY_ALLOC()); array_init(&token_stream); ctx.tokens = &token_stream; ctx.token_class = token_class; CG(ast) = NULL; CG(ast_arena) = zend_arena_create(1024 * 32); LANG_SCNG(yy_state) = yycINITIAL; LANG_SCNG(on_event) = on_event; LANG_SCNG(on_event_context) = &ctx; if((success = (zendparse() == SUCCESS))) { ZVAL_COPY_VALUE(return_value, &token_stream); } else { zval_ptr_dtor(&token_stream); } zend_ast_destroy(CG(ast)); zend_arena_destroy(CG(ast_arena)); /* restore compiler and scanner global states */ zend_restore_lexical_state(&original_lex_state); CG(in_compilation) = original_in_compilation; zval_ptr_dtor_str(&source_zval); return success; } static bool tokenize_common( zval *return_value, zend_string *source, zend_long flags, zend_class_entry *token_class) { if (flags & TOKEN_PARSE) { return tokenize_parse(return_value, source, token_class); } else { int success = tokenize(return_value, source, token_class); /* Normal token_get_all() should not throw. */ zend_clear_exception(); return success; } } /* }}} */ /* {{{ */ PHP_FUNCTION(token_get_all) { zend_string *source; zend_long flags = 0; ZEND_PARSE_PARAMETERS_START(1, 2) Z_PARAM_STR(source) Z_PARAM_OPTIONAL Z_PARAM_LONG(flags) ZEND_PARSE_PARAMETERS_END(); if (!tokenize_common(return_value, source, flags, /* token_class */ NULL)) { RETURN_THROWS(); } } /* }}} */ /* {{{ */ PHP_FUNCTION(token_name) { zend_long type; ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_LONG(type) ZEND_PARSE_PARAMETERS_END(); const char *token_name = get_token_type_name(type); if (!token_name) { token_name = "UNKNOWN"; } RETURN_STRING(token_name); } /* }}} */
14,618
25.628415
117
c
php-src
php-src-master/ext/tokenizer/tokenizer_data.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: Johannes Schlueter <[email protected]> | +----------------------------------------------------------------------+ */ /* DO NOT EDIT THIS FILE! This file is generated using tokenizer_data_gen.php */ #include "php.h" #include "zend.h" #include <zend_language_parser.h> char *get_token_type_name(int token_type) { switch (token_type) { case T_LNUMBER: return "T_LNUMBER"; case T_DNUMBER: return "T_DNUMBER"; case T_STRING: return "T_STRING"; case T_NAME_FULLY_QUALIFIED: return "T_NAME_FULLY_QUALIFIED"; case T_NAME_RELATIVE: return "T_NAME_RELATIVE"; case T_NAME_QUALIFIED: return "T_NAME_QUALIFIED"; case T_VARIABLE: return "T_VARIABLE"; case T_INLINE_HTML: return "T_INLINE_HTML"; case T_ENCAPSED_AND_WHITESPACE: return "T_ENCAPSED_AND_WHITESPACE"; case T_CONSTANT_ENCAPSED_STRING: return "T_CONSTANT_ENCAPSED_STRING"; case T_STRING_VARNAME: return "T_STRING_VARNAME"; case T_NUM_STRING: return "T_NUM_STRING"; case T_INCLUDE: return "T_INCLUDE"; case T_INCLUDE_ONCE: return "T_INCLUDE_ONCE"; case T_EVAL: return "T_EVAL"; case T_REQUIRE: return "T_REQUIRE"; case T_REQUIRE_ONCE: return "T_REQUIRE_ONCE"; case T_LOGICAL_OR: return "T_LOGICAL_OR"; case T_LOGICAL_XOR: return "T_LOGICAL_XOR"; case T_LOGICAL_AND: return "T_LOGICAL_AND"; case T_PRINT: return "T_PRINT"; case T_YIELD: return "T_YIELD"; case T_YIELD_FROM: return "T_YIELD_FROM"; case T_INSTANCEOF: return "T_INSTANCEOF"; case T_NEW: return "T_NEW"; case T_CLONE: return "T_CLONE"; case T_EXIT: return "T_EXIT"; case T_IF: return "T_IF"; case T_ELSEIF: return "T_ELSEIF"; case T_ELSE: return "T_ELSE"; case T_ENDIF: return "T_ENDIF"; case T_ECHO: return "T_ECHO"; case T_DO: return "T_DO"; case T_WHILE: return "T_WHILE"; case T_ENDWHILE: return "T_ENDWHILE"; case T_FOR: return "T_FOR"; case T_ENDFOR: return "T_ENDFOR"; case T_FOREACH: return "T_FOREACH"; case T_ENDFOREACH: return "T_ENDFOREACH"; case T_DECLARE: return "T_DECLARE"; case T_ENDDECLARE: return "T_ENDDECLARE"; case T_AS: return "T_AS"; case T_SWITCH: return "T_SWITCH"; case T_ENDSWITCH: return "T_ENDSWITCH"; case T_CASE: return "T_CASE"; case T_DEFAULT: return "T_DEFAULT"; case T_MATCH: return "T_MATCH"; case T_BREAK: return "T_BREAK"; case T_CONTINUE: return "T_CONTINUE"; case T_GOTO: return "T_GOTO"; case T_FUNCTION: return "T_FUNCTION"; case T_FN: return "T_FN"; case T_CONST: return "T_CONST"; case T_RETURN: return "T_RETURN"; case T_TRY: return "T_TRY"; case T_CATCH: return "T_CATCH"; case T_FINALLY: return "T_FINALLY"; case T_THROW: return "T_THROW"; case T_USE: return "T_USE"; case T_INSTEADOF: return "T_INSTEADOF"; case T_GLOBAL: return "T_GLOBAL"; case T_STATIC: return "T_STATIC"; case T_ABSTRACT: return "T_ABSTRACT"; case T_FINAL: return "T_FINAL"; case T_PRIVATE: return "T_PRIVATE"; case T_PROTECTED: return "T_PROTECTED"; case T_PUBLIC: return "T_PUBLIC"; case T_READONLY: return "T_READONLY"; case T_VAR: return "T_VAR"; case T_UNSET: return "T_UNSET"; case T_ISSET: return "T_ISSET"; case T_EMPTY: return "T_EMPTY"; case T_HALT_COMPILER: return "T_HALT_COMPILER"; case T_CLASS: return "T_CLASS"; case T_TRAIT: return "T_TRAIT"; case T_INTERFACE: return "T_INTERFACE"; case T_ENUM: return "T_ENUM"; case T_EXTENDS: return "T_EXTENDS"; case T_IMPLEMENTS: return "T_IMPLEMENTS"; case T_NAMESPACE: return "T_NAMESPACE"; case T_LIST: return "T_LIST"; case T_ARRAY: return "T_ARRAY"; case T_CALLABLE: return "T_CALLABLE"; case T_LINE: return "T_LINE"; case T_FILE: return "T_FILE"; case T_DIR: return "T_DIR"; case T_CLASS_C: return "T_CLASS_C"; case T_TRAIT_C: return "T_TRAIT_C"; case T_METHOD_C: return "T_METHOD_C"; case T_FUNC_C: return "T_FUNC_C"; case T_NS_C: return "T_NS_C"; case T_ATTRIBUTE: return "T_ATTRIBUTE"; case T_PLUS_EQUAL: return "T_PLUS_EQUAL"; case T_MINUS_EQUAL: return "T_MINUS_EQUAL"; case T_MUL_EQUAL: return "T_MUL_EQUAL"; case T_DIV_EQUAL: return "T_DIV_EQUAL"; case T_CONCAT_EQUAL: return "T_CONCAT_EQUAL"; case T_MOD_EQUAL: return "T_MOD_EQUAL"; case T_AND_EQUAL: return "T_AND_EQUAL"; case T_OR_EQUAL: return "T_OR_EQUAL"; case T_XOR_EQUAL: return "T_XOR_EQUAL"; case T_SL_EQUAL: return "T_SL_EQUAL"; case T_SR_EQUAL: return "T_SR_EQUAL"; case T_COALESCE_EQUAL: return "T_COALESCE_EQUAL"; case T_BOOLEAN_OR: return "T_BOOLEAN_OR"; case T_BOOLEAN_AND: return "T_BOOLEAN_AND"; case T_IS_EQUAL: return "T_IS_EQUAL"; case T_IS_NOT_EQUAL: return "T_IS_NOT_EQUAL"; case T_IS_IDENTICAL: return "T_IS_IDENTICAL"; case T_IS_NOT_IDENTICAL: return "T_IS_NOT_IDENTICAL"; case T_IS_SMALLER_OR_EQUAL: return "T_IS_SMALLER_OR_EQUAL"; case T_IS_GREATER_OR_EQUAL: return "T_IS_GREATER_OR_EQUAL"; case T_SPACESHIP: return "T_SPACESHIP"; case T_SL: return "T_SL"; case T_SR: return "T_SR"; case T_INC: return "T_INC"; case T_DEC: return "T_DEC"; case T_INT_CAST: return "T_INT_CAST"; case T_DOUBLE_CAST: return "T_DOUBLE_CAST"; case T_STRING_CAST: return "T_STRING_CAST"; case T_ARRAY_CAST: return "T_ARRAY_CAST"; case T_OBJECT_CAST: return "T_OBJECT_CAST"; case T_BOOL_CAST: return "T_BOOL_CAST"; case T_UNSET_CAST: return "T_UNSET_CAST"; case T_OBJECT_OPERATOR: return "T_OBJECT_OPERATOR"; case T_NULLSAFE_OBJECT_OPERATOR: return "T_NULLSAFE_OBJECT_OPERATOR"; case T_DOUBLE_ARROW: return "T_DOUBLE_ARROW"; case T_COMMENT: return "T_COMMENT"; case T_DOC_COMMENT: return "T_DOC_COMMENT"; case T_OPEN_TAG: return "T_OPEN_TAG"; case T_OPEN_TAG_WITH_ECHO: return "T_OPEN_TAG_WITH_ECHO"; case T_CLOSE_TAG: return "T_CLOSE_TAG"; case T_WHITESPACE: return "T_WHITESPACE"; case T_START_HEREDOC: return "T_START_HEREDOC"; case T_END_HEREDOC: return "T_END_HEREDOC"; case T_DOLLAR_OPEN_CURLY_BRACES: return "T_DOLLAR_OPEN_CURLY_BRACES"; case T_CURLY_OPEN: return "T_CURLY_OPEN"; case T_PAAMAYIM_NEKUDOTAYIM: return "T_DOUBLE_COLON"; case T_NS_SEPARATOR: return "T_NS_SEPARATOR"; case T_ELLIPSIS: return "T_ELLIPSIS"; case T_COALESCE: return "T_COALESCE"; case T_POW: return "T_POW"; case T_POW_EQUAL: return "T_POW_EQUAL"; case T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG: return "T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG"; case T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG: return "T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG"; case T_BAD_CHARACTER: return "T_BAD_CHARACTER"; } return NULL; }
7,318
39.436464
101
c
php-src
php-src-master/ext/tokenizer/tokenizer_data_arginfo.h
/* This is a generated file, edit the .stub.php file instead. * Stub hash: 1dd42ee5b5b818c5bd131b5c4bbb13c153d99499 */ static void register_tokenizer_data_symbols(int module_number) { REGISTER_LONG_CONSTANT("T_LNUMBER", T_LNUMBER, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_DNUMBER", T_DNUMBER, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_STRING", T_STRING, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_NAME_FULLY_QUALIFIED", T_NAME_FULLY_QUALIFIED, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_NAME_RELATIVE", T_NAME_RELATIVE, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_NAME_QUALIFIED", T_NAME_QUALIFIED, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_VARIABLE", T_VARIABLE, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_INLINE_HTML", T_INLINE_HTML, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_ENCAPSED_AND_WHITESPACE", T_ENCAPSED_AND_WHITESPACE, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_CONSTANT_ENCAPSED_STRING", T_CONSTANT_ENCAPSED_STRING, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_STRING_VARNAME", T_STRING_VARNAME, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_NUM_STRING", T_NUM_STRING, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_INCLUDE", T_INCLUDE, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_INCLUDE_ONCE", T_INCLUDE_ONCE, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_EVAL", T_EVAL, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_REQUIRE", T_REQUIRE, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_REQUIRE_ONCE", T_REQUIRE_ONCE, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_LOGICAL_OR", T_LOGICAL_OR, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_LOGICAL_XOR", T_LOGICAL_XOR, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_LOGICAL_AND", T_LOGICAL_AND, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_PRINT", T_PRINT, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_YIELD", T_YIELD, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_YIELD_FROM", T_YIELD_FROM, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_INSTANCEOF", T_INSTANCEOF, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_NEW", T_NEW, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_CLONE", T_CLONE, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_EXIT", T_EXIT, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_IF", T_IF, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_ELSEIF", T_ELSEIF, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_ELSE", T_ELSE, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_ENDIF", T_ENDIF, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_ECHO", T_ECHO, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_DO", T_DO, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_WHILE", T_WHILE, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_ENDWHILE", T_ENDWHILE, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_FOR", T_FOR, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_ENDFOR", T_ENDFOR, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_FOREACH", T_FOREACH, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_ENDFOREACH", T_ENDFOREACH, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_DECLARE", T_DECLARE, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_ENDDECLARE", T_ENDDECLARE, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_AS", T_AS, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_SWITCH", T_SWITCH, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_ENDSWITCH", T_ENDSWITCH, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_CASE", T_CASE, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_DEFAULT", T_DEFAULT, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_MATCH", T_MATCH, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_BREAK", T_BREAK, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_CONTINUE", T_CONTINUE, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_GOTO", T_GOTO, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_FUNCTION", T_FUNCTION, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_FN", T_FN, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_CONST", T_CONST, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_RETURN", T_RETURN, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_TRY", T_TRY, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_CATCH", T_CATCH, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_FINALLY", T_FINALLY, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_THROW", T_THROW, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_USE", T_USE, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_INSTEADOF", T_INSTEADOF, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_GLOBAL", T_GLOBAL, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_STATIC", T_STATIC, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_ABSTRACT", T_ABSTRACT, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_FINAL", T_FINAL, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_PRIVATE", T_PRIVATE, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_PROTECTED", T_PROTECTED, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_PUBLIC", T_PUBLIC, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_READONLY", T_READONLY, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_VAR", T_VAR, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_UNSET", T_UNSET, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_ISSET", T_ISSET, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_EMPTY", T_EMPTY, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_HALT_COMPILER", T_HALT_COMPILER, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_CLASS", T_CLASS, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_TRAIT", T_TRAIT, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_INTERFACE", T_INTERFACE, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_ENUM", T_ENUM, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_EXTENDS", T_EXTENDS, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_IMPLEMENTS", T_IMPLEMENTS, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_NAMESPACE", T_NAMESPACE, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_LIST", T_LIST, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_ARRAY", T_ARRAY, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_CALLABLE", T_CALLABLE, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_LINE", T_LINE, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_FILE", T_FILE, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_DIR", T_DIR, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_CLASS_C", T_CLASS_C, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_TRAIT_C", T_TRAIT_C, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_METHOD_C", T_METHOD_C, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_FUNC_C", T_FUNC_C, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_NS_C", T_NS_C, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_ATTRIBUTE", T_ATTRIBUTE, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_PLUS_EQUAL", T_PLUS_EQUAL, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_MINUS_EQUAL", T_MINUS_EQUAL, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_MUL_EQUAL", T_MUL_EQUAL, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_DIV_EQUAL", T_DIV_EQUAL, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_CONCAT_EQUAL", T_CONCAT_EQUAL, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_MOD_EQUAL", T_MOD_EQUAL, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_AND_EQUAL", T_AND_EQUAL, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_OR_EQUAL", T_OR_EQUAL, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_XOR_EQUAL", T_XOR_EQUAL, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_SL_EQUAL", T_SL_EQUAL, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_SR_EQUAL", T_SR_EQUAL, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_COALESCE_EQUAL", T_COALESCE_EQUAL, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_BOOLEAN_OR", T_BOOLEAN_OR, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_BOOLEAN_AND", T_BOOLEAN_AND, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_IS_EQUAL", T_IS_EQUAL, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_IS_NOT_EQUAL", T_IS_NOT_EQUAL, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_IS_IDENTICAL", T_IS_IDENTICAL, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_IS_NOT_IDENTICAL", T_IS_NOT_IDENTICAL, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_IS_SMALLER_OR_EQUAL", T_IS_SMALLER_OR_EQUAL, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_IS_GREATER_OR_EQUAL", T_IS_GREATER_OR_EQUAL, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_SPACESHIP", T_SPACESHIP, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_SL", T_SL, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_SR", T_SR, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_INC", T_INC, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_DEC", T_DEC, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_INT_CAST", T_INT_CAST, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_DOUBLE_CAST", T_DOUBLE_CAST, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_STRING_CAST", T_STRING_CAST, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_ARRAY_CAST", T_ARRAY_CAST, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_OBJECT_CAST", T_OBJECT_CAST, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_BOOL_CAST", T_BOOL_CAST, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_UNSET_CAST", T_UNSET_CAST, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_OBJECT_OPERATOR", T_OBJECT_OPERATOR, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_NULLSAFE_OBJECT_OPERATOR", T_NULLSAFE_OBJECT_OPERATOR, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_DOUBLE_ARROW", T_DOUBLE_ARROW, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_COMMENT", T_COMMENT, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_DOC_COMMENT", T_DOC_COMMENT, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_OPEN_TAG", T_OPEN_TAG, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_OPEN_TAG_WITH_ECHO", T_OPEN_TAG_WITH_ECHO, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_CLOSE_TAG", T_CLOSE_TAG, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_WHITESPACE", T_WHITESPACE, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_START_HEREDOC", T_START_HEREDOC, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_END_HEREDOC", T_END_HEREDOC, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_DOLLAR_OPEN_CURLY_BRACES", T_DOLLAR_OPEN_CURLY_BRACES, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_CURLY_OPEN", T_CURLY_OPEN, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_PAAMAYIM_NEKUDOTAYIM", T_PAAMAYIM_NEKUDOTAYIM, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_NS_SEPARATOR", T_NS_SEPARATOR, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_ELLIPSIS", T_ELLIPSIS, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_COALESCE", T_COALESCE, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_POW", T_POW, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_POW_EQUAL", T_POW_EQUAL, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG", T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG", T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_BAD_CHARACTER", T_BAD_CHARACTER, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("T_DOUBLE_COLON", T_PAAMAYIM_NEKUDOTAYIM, CONST_PERSISTENT); }
10,593
66.910256
130
h
php-src
php-src-master/ext/xml/php_xml.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: Stig Sæther Bakken <[email protected]> | | Thies C. Arntzen <[email protected]> | | Sterling Hughes <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef PHP_XML_H #define PHP_XML_H #ifdef HAVE_XML extern zend_module_entry xml_module_entry; #define xml_module_ptr &xml_module_entry #include "php_version.h" #define PHP_XML_VERSION PHP_VERSION #include "expat_compat.h" #ifdef XML_UNICODE #error "UTF-16 Unicode support not implemented!" #endif #else #define xml_module_ptr NULL #endif /* HAVE_XML */ #define phpext_xml_ptr xml_module_ptr enum php_xml_option { PHP_XML_OPTION_CASE_FOLDING = 1, PHP_XML_OPTION_TARGET_ENCODING, PHP_XML_OPTION_SKIP_TAGSTART, PHP_XML_OPTION_SKIP_WHITE }; #ifdef LIBXML_EXPAT_COMPAT #define PHP_XML_SAX_IMPL "libxml" #else #define PHP_XML_SAX_IMPL "expat" #endif #endif /* PHP_XML_H */
1,829
31.678571
75
h
php-src
php-src-master/ext/xml/xml_arginfo.h
/* This is a generated file, edit the .stub.php file instead. * Stub hash: cd199a8733c51c8bb5970f86b7797ca91e6e59c6 */ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_xml_parser_create, 0, 0, XMLParser, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, encoding, IS_STRING, 1, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_xml_parser_create_ns, 0, 0, XMLParser, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, encoding, IS_STRING, 1, "null") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, separator, IS_STRING, 0, "\":\"") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_xml_set_object, 0, 2, IS_TRUE, 0) ZEND_ARG_OBJ_INFO(0, parser, XMLParser, 0) ZEND_ARG_TYPE_INFO(0, object, IS_OBJECT, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_xml_set_element_handler, 0, 3, IS_TRUE, 0) ZEND_ARG_OBJ_INFO(0, parser, XMLParser, 0) ZEND_ARG_INFO(0, start_handler) ZEND_ARG_INFO(0, end_handler) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_xml_set_character_data_handler, 0, 2, IS_TRUE, 0) ZEND_ARG_OBJ_INFO(0, parser, XMLParser, 0) ZEND_ARG_INFO(0, handler) ZEND_END_ARG_INFO() #define arginfo_xml_set_processing_instruction_handler arginfo_xml_set_character_data_handler #define arginfo_xml_set_default_handler arginfo_xml_set_character_data_handler #define arginfo_xml_set_unparsed_entity_decl_handler arginfo_xml_set_character_data_handler #define arginfo_xml_set_notation_decl_handler arginfo_xml_set_character_data_handler #define arginfo_xml_set_external_entity_ref_handler arginfo_xml_set_character_data_handler #define arginfo_xml_set_start_namespace_decl_handler arginfo_xml_set_character_data_handler #define arginfo_xml_set_end_namespace_decl_handler arginfo_xml_set_character_data_handler ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_xml_parse, 0, 2, IS_LONG, 0) ZEND_ARG_OBJ_INFO(0, parser, XMLParser, 0) ZEND_ARG_TYPE_INFO(0, data, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, is_final, _IS_BOOL, 0, "false") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_xml_parse_into_struct, 0, 3, IS_LONG, 0) ZEND_ARG_OBJ_INFO(0, parser, XMLParser, 0) ZEND_ARG_TYPE_INFO(0, data, IS_STRING, 0) ZEND_ARG_INFO(1, values) ZEND_ARG_INFO_WITH_DEFAULT_VALUE(1, index, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_xml_get_error_code, 0, 1, IS_LONG, 0) ZEND_ARG_OBJ_INFO(0, parser, XMLParser, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_xml_error_string, 0, 1, IS_STRING, 1) ZEND_ARG_TYPE_INFO(0, error_code, IS_LONG, 0) ZEND_END_ARG_INFO() #define arginfo_xml_get_current_line_number arginfo_xml_get_error_code #define arginfo_xml_get_current_column_number arginfo_xml_get_error_code #define arginfo_xml_get_current_byte_index arginfo_xml_get_error_code ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_xml_parser_free, 0, 1, _IS_BOOL, 0) ZEND_ARG_OBJ_INFO(0, parser, XMLParser, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_xml_parser_set_option, 0, 3, _IS_BOOL, 0) ZEND_ARG_OBJ_INFO(0, parser, XMLParser, 0) ZEND_ARG_TYPE_INFO(0, option, IS_LONG, 0) ZEND_ARG_INFO(0, value) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_xml_parser_get_option, 0, 2, MAY_BE_STRING|MAY_BE_LONG|MAY_BE_BOOL) ZEND_ARG_OBJ_INFO(0, parser, XMLParser, 0) ZEND_ARG_TYPE_INFO(0, option, IS_LONG, 0) ZEND_END_ARG_INFO() ZEND_FUNCTION(xml_parser_create); ZEND_FUNCTION(xml_parser_create_ns); ZEND_FUNCTION(xml_set_object); ZEND_FUNCTION(xml_set_element_handler); ZEND_FUNCTION(xml_set_character_data_handler); ZEND_FUNCTION(xml_set_processing_instruction_handler); ZEND_FUNCTION(xml_set_default_handler); ZEND_FUNCTION(xml_set_unparsed_entity_decl_handler); ZEND_FUNCTION(xml_set_notation_decl_handler); ZEND_FUNCTION(xml_set_external_entity_ref_handler); ZEND_FUNCTION(xml_set_start_namespace_decl_handler); ZEND_FUNCTION(xml_set_end_namespace_decl_handler); ZEND_FUNCTION(xml_parse); ZEND_FUNCTION(xml_parse_into_struct); ZEND_FUNCTION(xml_get_error_code); ZEND_FUNCTION(xml_error_string); ZEND_FUNCTION(xml_get_current_line_number); ZEND_FUNCTION(xml_get_current_column_number); ZEND_FUNCTION(xml_get_current_byte_index); ZEND_FUNCTION(xml_parser_free); ZEND_FUNCTION(xml_parser_set_option); ZEND_FUNCTION(xml_parser_get_option); static const zend_function_entry ext_functions[] = { ZEND_FE(xml_parser_create, arginfo_xml_parser_create) ZEND_FE(xml_parser_create_ns, arginfo_xml_parser_create_ns) ZEND_FE(xml_set_object, arginfo_xml_set_object) ZEND_FE(xml_set_element_handler, arginfo_xml_set_element_handler) ZEND_FE(xml_set_character_data_handler, arginfo_xml_set_character_data_handler) ZEND_FE(xml_set_processing_instruction_handler, arginfo_xml_set_processing_instruction_handler) ZEND_FE(xml_set_default_handler, arginfo_xml_set_default_handler) ZEND_FE(xml_set_unparsed_entity_decl_handler, arginfo_xml_set_unparsed_entity_decl_handler) ZEND_FE(xml_set_notation_decl_handler, arginfo_xml_set_notation_decl_handler) ZEND_FE(xml_set_external_entity_ref_handler, arginfo_xml_set_external_entity_ref_handler) ZEND_FE(xml_set_start_namespace_decl_handler, arginfo_xml_set_start_namespace_decl_handler) ZEND_FE(xml_set_end_namespace_decl_handler, arginfo_xml_set_end_namespace_decl_handler) ZEND_FE(xml_parse, arginfo_xml_parse) ZEND_FE(xml_parse_into_struct, arginfo_xml_parse_into_struct) ZEND_FE(xml_get_error_code, arginfo_xml_get_error_code) ZEND_FE(xml_error_string, arginfo_xml_error_string) ZEND_FE(xml_get_current_line_number, arginfo_xml_get_current_line_number) ZEND_FE(xml_get_current_column_number, arginfo_xml_get_current_column_number) ZEND_FE(xml_get_current_byte_index, arginfo_xml_get_current_byte_index) ZEND_FE(xml_parser_free, arginfo_xml_parser_free) ZEND_FE(xml_parser_set_option, arginfo_xml_parser_set_option) ZEND_FE(xml_parser_get_option, arginfo_xml_parser_get_option) ZEND_FE_END }; static const zend_function_entry class_XMLParser_methods[] = { ZEND_FE_END }; static void register_xml_symbols(int module_number) { REGISTER_LONG_CONSTANT("XML_ERROR_NONE", XML_ERROR_NONE, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("XML_ERROR_NO_MEMORY", XML_ERROR_NO_MEMORY, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("XML_ERROR_SYNTAX", XML_ERROR_SYNTAX, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("XML_ERROR_NO_ELEMENTS", XML_ERROR_NO_ELEMENTS, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("XML_ERROR_INVALID_TOKEN", XML_ERROR_INVALID_TOKEN, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("XML_ERROR_UNCLOSED_TOKEN", XML_ERROR_UNCLOSED_TOKEN, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("XML_ERROR_PARTIAL_CHAR", XML_ERROR_PARTIAL_CHAR, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("XML_ERROR_TAG_MISMATCH", XML_ERROR_TAG_MISMATCH, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("XML_ERROR_DUPLICATE_ATTRIBUTE", XML_ERROR_DUPLICATE_ATTRIBUTE, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("XML_ERROR_JUNK_AFTER_DOC_ELEMENT", XML_ERROR_JUNK_AFTER_DOC_ELEMENT, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("XML_ERROR_PARAM_ENTITY_REF", XML_ERROR_PARAM_ENTITY_REF, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("XML_ERROR_UNDEFINED_ENTITY", XML_ERROR_UNDEFINED_ENTITY, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("XML_ERROR_RECURSIVE_ENTITY_REF", XML_ERROR_RECURSIVE_ENTITY_REF, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("XML_ERROR_ASYNC_ENTITY", XML_ERROR_ASYNC_ENTITY, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("XML_ERROR_BAD_CHAR_REF", XML_ERROR_BAD_CHAR_REF, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("XML_ERROR_BINARY_ENTITY_REF", XML_ERROR_BINARY_ENTITY_REF, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF", XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("XML_ERROR_MISPLACED_XML_PI", XML_ERROR_MISPLACED_XML_PI, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("XML_ERROR_UNKNOWN_ENCODING", XML_ERROR_UNKNOWN_ENCODING, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("XML_ERROR_INCORRECT_ENCODING", XML_ERROR_INCORRECT_ENCODING, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("XML_ERROR_UNCLOSED_CDATA_SECTION", XML_ERROR_UNCLOSED_CDATA_SECTION, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("XML_ERROR_EXTERNAL_ENTITY_HANDLING", XML_ERROR_EXTERNAL_ENTITY_HANDLING, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("XML_OPTION_CASE_FOLDING", PHP_XML_OPTION_CASE_FOLDING, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("XML_OPTION_TARGET_ENCODING", PHP_XML_OPTION_TARGET_ENCODING, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("XML_OPTION_SKIP_TAGSTART", PHP_XML_OPTION_SKIP_TAGSTART, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("XML_OPTION_SKIP_WHITE", PHP_XML_OPTION_SKIP_WHITE, CONST_PERSISTENT); REGISTER_STRING_CONSTANT("XML_SAX_IMPL", PHP_XML_SAX_IMPL, CONST_PERSISTENT); } static zend_class_entry *register_class_XMLParser(void) { zend_class_entry ce, *class_entry; INIT_CLASS_ENTRY(ce, "XMLParser", class_XMLParser_methods); class_entry = zend_register_internal_class_ex(&ce, NULL); class_entry->ce_flags |= ZEND_ACC_FINAL|ZEND_ACC_NO_DYNAMIC_PROPERTIES|ZEND_ACC_NOT_SERIALIZABLE; return class_entry; }
9,122
49.126374
126
h
php-src
php-src-master/ext/xmlreader/php_xmlreader.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: Rob Richards <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef PHP_XMLREADER_H #define PHP_XMLREADER_H extern zend_module_entry xmlreader_module_entry; #define phpext_xmlreader_ptr &xmlreader_module_entry #include "php_version.h" #define PHP_XMLREADER_VERSION PHP_VERSION #ifdef ZTS #include "TSRM.h" #endif #include "ext/libxml/php_libxml.h" #include <libxml/xmlreader.h> /* If xmlreader and dom both are compiled statically, no DLL import should be used in xmlreader for dom symbols. */ #ifdef PHP_WIN32 # if defined(HAVE_DOM) && !defined(COMPILE_DL_DOM) && !defined(COMPILE_DL_XMLREADER) # define DOM_LOCAL_DEFINES 1 # endif #endif typedef struct _xmlreader_object { xmlTextReaderPtr ptr; /* strings must be set in input buffer as copy is required */ xmlParserInputBufferPtr input; void *schema; HashTable *prop_handler; zend_object std; } xmlreader_object; static inline xmlreader_object *php_xmlreader_fetch_object(zend_object *obj) { return (xmlreader_object *)((char*)(obj) - XtOffsetOf(xmlreader_object, std)); } #define Z_XMLREADER_P(zv) php_xmlreader_fetch_object(Z_OBJ_P((zv))) PHP_MINIT_FUNCTION(xmlreader); PHP_MSHUTDOWN_FUNCTION(xmlreader); PHP_MINFO_FUNCTION(xmlreader); #endif /* PHP_XMLREADER_H */
2,164
34.491803
84
h
php-src
php-src-master/ext/xmlwriter/php_xmlwriter.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: Rob Richards <[email protected]> | | Pierre-A. Joye <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef PHP_XMLWRITER_H #define PHP_XMLWRITER_H extern zend_module_entry xmlwriter_module_entry; #define phpext_xmlwriter_ptr &xmlwriter_module_entry #include "php_version.h" #define PHP_XMLWRITER_VERSION PHP_VERSION #ifdef ZTS #include "TSRM.h" #endif #include <libxml/tree.h> #include <libxml/xmlwriter.h> #include <libxml/uri.h> /* Extends zend object */ typedef struct _ze_xmlwriter_object { xmlTextWriterPtr ptr; xmlBufferPtr output; zend_object std; } ze_xmlwriter_object; static inline ze_xmlwriter_object *php_xmlwriter_fetch_object(zend_object *obj) { return (ze_xmlwriter_object *)((char*)(obj) - XtOffsetOf(ze_xmlwriter_object, std)); } #define Z_XMLWRITER_P(zv) php_xmlwriter_fetch_object(Z_OBJ_P((zv))) #endif /* PHP_XMLWRITER_H */
1,814
36.040816
85
h
php-src
php-src-master/ext/xmlwriter/php_xmlwriter_arginfo.h
/* This is a generated file, edit the .stub.php file instead. * Stub hash: 820ad2d68166b189b9163c2c3dfcc76806d41b7d */ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_xmlwriter_open_uri, 0, 1, XMLWriter, MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, uri, IS_STRING, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_xmlwriter_open_memory, 0, 0, XMLWriter, MAY_BE_FALSE) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_xmlwriter_set_indent, 0, 2, _IS_BOOL, 0) ZEND_ARG_OBJ_INFO(0, writer, XMLWriter, 0) ZEND_ARG_TYPE_INFO(0, enable, _IS_BOOL, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_xmlwriter_set_indent_string, 0, 2, _IS_BOOL, 0) ZEND_ARG_OBJ_INFO(0, writer, XMLWriter, 0) ZEND_ARG_TYPE_INFO(0, indentation, IS_STRING, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_xmlwriter_start_comment, 0, 1, _IS_BOOL, 0) ZEND_ARG_OBJ_INFO(0, writer, XMLWriter, 0) ZEND_END_ARG_INFO() #define arginfo_xmlwriter_end_comment arginfo_xmlwriter_start_comment ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_xmlwriter_start_attribute, 0, 2, _IS_BOOL, 0) ZEND_ARG_OBJ_INFO(0, writer, XMLWriter, 0) ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0) ZEND_END_ARG_INFO() #define arginfo_xmlwriter_end_attribute arginfo_xmlwriter_start_comment ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_xmlwriter_write_attribute, 0, 3, _IS_BOOL, 0) ZEND_ARG_OBJ_INFO(0, writer, XMLWriter, 0) ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, value, IS_STRING, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_xmlwriter_start_attribute_ns, 0, 4, _IS_BOOL, 0) ZEND_ARG_OBJ_INFO(0, writer, XMLWriter, 0) ZEND_ARG_TYPE_INFO(0, prefix, IS_STRING, 1) ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, namespace, IS_STRING, 1) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_xmlwriter_write_attribute_ns, 0, 5, _IS_BOOL, 0) ZEND_ARG_OBJ_INFO(0, writer, XMLWriter, 0) ZEND_ARG_TYPE_INFO(0, prefix, IS_STRING, 1) ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, namespace, IS_STRING, 1) ZEND_ARG_TYPE_INFO(0, value, IS_STRING, 0) ZEND_END_ARG_INFO() #define arginfo_xmlwriter_start_element arginfo_xmlwriter_start_attribute #define arginfo_xmlwriter_end_element arginfo_xmlwriter_start_comment #define arginfo_xmlwriter_full_end_element arginfo_xmlwriter_start_comment #define arginfo_xmlwriter_start_element_ns arginfo_xmlwriter_start_attribute_ns ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_xmlwriter_write_element, 0, 2, _IS_BOOL, 0) ZEND_ARG_OBJ_INFO(0, writer, XMLWriter, 0) ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, content, IS_STRING, 1, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_xmlwriter_write_element_ns, 0, 4, _IS_BOOL, 0) ZEND_ARG_OBJ_INFO(0, writer, XMLWriter, 0) ZEND_ARG_TYPE_INFO(0, prefix, IS_STRING, 1) ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, namespace, IS_STRING, 1) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, content, IS_STRING, 1, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_xmlwriter_start_pi, 0, 2, _IS_BOOL, 0) ZEND_ARG_OBJ_INFO(0, writer, XMLWriter, 0) ZEND_ARG_TYPE_INFO(0, target, IS_STRING, 0) ZEND_END_ARG_INFO() #define arginfo_xmlwriter_end_pi arginfo_xmlwriter_start_comment ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_xmlwriter_write_pi, 0, 3, _IS_BOOL, 0) ZEND_ARG_OBJ_INFO(0, writer, XMLWriter, 0) ZEND_ARG_TYPE_INFO(0, target, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, content, IS_STRING, 0) ZEND_END_ARG_INFO() #define arginfo_xmlwriter_start_cdata arginfo_xmlwriter_start_comment #define arginfo_xmlwriter_end_cdata arginfo_xmlwriter_start_comment ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_xmlwriter_write_cdata, 0, 2, _IS_BOOL, 0) ZEND_ARG_OBJ_INFO(0, writer, XMLWriter, 0) ZEND_ARG_TYPE_INFO(0, content, IS_STRING, 0) ZEND_END_ARG_INFO() #define arginfo_xmlwriter_text arginfo_xmlwriter_write_cdata #define arginfo_xmlwriter_write_raw arginfo_xmlwriter_write_cdata ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_xmlwriter_start_document, 0, 1, _IS_BOOL, 0) ZEND_ARG_OBJ_INFO(0, writer, XMLWriter, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, version, IS_STRING, 1, "\"1.0\"") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, encoding, IS_STRING, 1, "null") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, standalone, IS_STRING, 1, "null") ZEND_END_ARG_INFO() #define arginfo_xmlwriter_end_document arginfo_xmlwriter_start_comment #define arginfo_xmlwriter_write_comment arginfo_xmlwriter_write_cdata ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_xmlwriter_start_dtd, 0, 2, _IS_BOOL, 0) ZEND_ARG_OBJ_INFO(0, writer, XMLWriter, 0) ZEND_ARG_TYPE_INFO(0, qualifiedName, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, publicId, IS_STRING, 1, "null") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, systemId, IS_STRING, 1, "null") ZEND_END_ARG_INFO() #define arginfo_xmlwriter_end_dtd arginfo_xmlwriter_start_comment ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_xmlwriter_write_dtd, 0, 2, _IS_BOOL, 0) ZEND_ARG_OBJ_INFO(0, writer, XMLWriter, 0) ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, publicId, IS_STRING, 1, "null") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, systemId, IS_STRING, 1, "null") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, content, IS_STRING, 1, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_xmlwriter_start_dtd_element, 0, 2, _IS_BOOL, 0) ZEND_ARG_OBJ_INFO(0, writer, XMLWriter, 0) ZEND_ARG_TYPE_INFO(0, qualifiedName, IS_STRING, 0) ZEND_END_ARG_INFO() #define arginfo_xmlwriter_end_dtd_element arginfo_xmlwriter_start_comment ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_xmlwriter_write_dtd_element, 0, 3, _IS_BOOL, 0) ZEND_ARG_OBJ_INFO(0, writer, XMLWriter, 0) ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, content, IS_STRING, 0) ZEND_END_ARG_INFO() #define arginfo_xmlwriter_start_dtd_attlist arginfo_xmlwriter_start_attribute #define arginfo_xmlwriter_end_dtd_attlist arginfo_xmlwriter_start_comment #define arginfo_xmlwriter_write_dtd_attlist arginfo_xmlwriter_write_dtd_element ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_xmlwriter_start_dtd_entity, 0, 3, _IS_BOOL, 0) ZEND_ARG_OBJ_INFO(0, writer, XMLWriter, 0) ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, isParam, _IS_BOOL, 0) ZEND_END_ARG_INFO() #define arginfo_xmlwriter_end_dtd_entity arginfo_xmlwriter_start_comment ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_xmlwriter_write_dtd_entity, 0, 3, _IS_BOOL, 0) ZEND_ARG_OBJ_INFO(0, writer, XMLWriter, 0) ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, content, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, isParam, _IS_BOOL, 0, "false") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, publicId, IS_STRING, 1, "null") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, systemId, IS_STRING, 1, "null") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, notationData, IS_STRING, 1, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_xmlwriter_output_memory, 0, 1, IS_STRING, 0) ZEND_ARG_OBJ_INFO(0, writer, XMLWriter, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flush, _IS_BOOL, 0, "true") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_xmlwriter_flush, 0, 1, MAY_BE_STRING|MAY_BE_LONG) ZEND_ARG_OBJ_INFO(0, writer, XMLWriter, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, empty, _IS_BOOL, 0, "true") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_XMLWriter_openUri, 0, 1, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO(0, uri, IS_STRING, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_XMLWriter_openMemory, 0, 0, _IS_BOOL, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_XMLWriter_setIndent, 0, 1, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO(0, enable, _IS_BOOL, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_XMLWriter_setIndentString, 0, 1, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO(0, indentation, IS_STRING, 0) ZEND_END_ARG_INFO() #define arginfo_class_XMLWriter_startComment arginfo_class_XMLWriter_openMemory #define arginfo_class_XMLWriter_endComment arginfo_class_XMLWriter_openMemory ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_XMLWriter_startAttribute, 0, 1, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0) ZEND_END_ARG_INFO() #define arginfo_class_XMLWriter_endAttribute arginfo_class_XMLWriter_openMemory ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_XMLWriter_writeAttribute, 0, 2, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, value, IS_STRING, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_XMLWriter_startAttributeNs, 0, 3, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO(0, prefix, IS_STRING, 1) ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, namespace, IS_STRING, 1) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_XMLWriter_writeAttributeNs, 0, 4, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO(0, prefix, IS_STRING, 1) ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, namespace, IS_STRING, 1) ZEND_ARG_TYPE_INFO(0, value, IS_STRING, 0) ZEND_END_ARG_INFO() #define arginfo_class_XMLWriter_startElement arginfo_class_XMLWriter_startAttribute #define arginfo_class_XMLWriter_endElement arginfo_class_XMLWriter_openMemory #define arginfo_class_XMLWriter_fullEndElement arginfo_class_XMLWriter_openMemory #define arginfo_class_XMLWriter_startElementNs arginfo_class_XMLWriter_startAttributeNs ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_XMLWriter_writeElement, 0, 1, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, content, IS_STRING, 1, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_XMLWriter_writeElementNs, 0, 3, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO(0, prefix, IS_STRING, 1) ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, namespace, IS_STRING, 1) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, content, IS_STRING, 1, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_XMLWriter_startPi, 0, 1, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO(0, target, IS_STRING, 0) ZEND_END_ARG_INFO() #define arginfo_class_XMLWriter_endPi arginfo_class_XMLWriter_openMemory ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_XMLWriter_writePi, 0, 2, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO(0, target, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, content, IS_STRING, 0) ZEND_END_ARG_INFO() #define arginfo_class_XMLWriter_startCdata arginfo_class_XMLWriter_openMemory #define arginfo_class_XMLWriter_endCdata arginfo_class_XMLWriter_openMemory ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_XMLWriter_writeCdata, 0, 1, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO(0, content, IS_STRING, 0) ZEND_END_ARG_INFO() #define arginfo_class_XMLWriter_text arginfo_class_XMLWriter_writeCdata #define arginfo_class_XMLWriter_writeRaw arginfo_class_XMLWriter_writeCdata ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_XMLWriter_startDocument, 0, 0, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, version, IS_STRING, 1, "\"1.0\"") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, encoding, IS_STRING, 1, "null") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, standalone, IS_STRING, 1, "null") ZEND_END_ARG_INFO() #define arginfo_class_XMLWriter_endDocument arginfo_class_XMLWriter_openMemory #define arginfo_class_XMLWriter_writeComment arginfo_class_XMLWriter_writeCdata ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_XMLWriter_startDtd, 0, 1, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO(0, qualifiedName, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, publicId, IS_STRING, 1, "null") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, systemId, IS_STRING, 1, "null") ZEND_END_ARG_INFO() #define arginfo_class_XMLWriter_endDtd arginfo_class_XMLWriter_openMemory ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_XMLWriter_writeDtd, 0, 1, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, publicId, IS_STRING, 1, "null") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, systemId, IS_STRING, 1, "null") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, content, IS_STRING, 1, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_XMLWriter_startDtdElement, 0, 1, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO(0, qualifiedName, IS_STRING, 0) ZEND_END_ARG_INFO() #define arginfo_class_XMLWriter_endDtdElement arginfo_class_XMLWriter_openMemory ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_XMLWriter_writeDtdElement, 0, 2, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, content, IS_STRING, 0) ZEND_END_ARG_INFO() #define arginfo_class_XMLWriter_startDtdAttlist arginfo_class_XMLWriter_startAttribute #define arginfo_class_XMLWriter_endDtdAttlist arginfo_class_XMLWriter_openMemory #define arginfo_class_XMLWriter_writeDtdAttlist arginfo_class_XMLWriter_writeDtdElement ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_XMLWriter_startDtdEntity, 0, 2, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, isParam, _IS_BOOL, 0) ZEND_END_ARG_INFO() #define arginfo_class_XMLWriter_endDtdEntity arginfo_class_XMLWriter_openMemory ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_XMLWriter_writeDtdEntity, 0, 2, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, content, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, isParam, _IS_BOOL, 0, "false") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, publicId, IS_STRING, 1, "null") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, systemId, IS_STRING, 1, "null") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, notationData, IS_STRING, 1, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_XMLWriter_outputMemory, 0, 0, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flush, _IS_BOOL, 0, "true") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_MASK_EX(arginfo_class_XMLWriter_flush, 0, 0, MAY_BE_STRING|MAY_BE_LONG) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, empty, _IS_BOOL, 0, "true") ZEND_END_ARG_INFO() ZEND_FUNCTION(xmlwriter_open_uri); ZEND_FUNCTION(xmlwriter_open_memory); ZEND_FUNCTION(xmlwriter_set_indent); ZEND_FUNCTION(xmlwriter_set_indent_string); ZEND_FUNCTION(xmlwriter_start_comment); ZEND_FUNCTION(xmlwriter_end_comment); ZEND_FUNCTION(xmlwriter_start_attribute); ZEND_FUNCTION(xmlwriter_end_attribute); ZEND_FUNCTION(xmlwriter_write_attribute); ZEND_FUNCTION(xmlwriter_start_attribute_ns); ZEND_FUNCTION(xmlwriter_write_attribute_ns); ZEND_FUNCTION(xmlwriter_start_element); ZEND_FUNCTION(xmlwriter_end_element); ZEND_FUNCTION(xmlwriter_full_end_element); ZEND_FUNCTION(xmlwriter_start_element_ns); ZEND_FUNCTION(xmlwriter_write_element); ZEND_FUNCTION(xmlwriter_write_element_ns); ZEND_FUNCTION(xmlwriter_start_pi); ZEND_FUNCTION(xmlwriter_end_pi); ZEND_FUNCTION(xmlwriter_write_pi); ZEND_FUNCTION(xmlwriter_start_cdata); ZEND_FUNCTION(xmlwriter_end_cdata); ZEND_FUNCTION(xmlwriter_write_cdata); ZEND_FUNCTION(xmlwriter_text); ZEND_FUNCTION(xmlwriter_write_raw); ZEND_FUNCTION(xmlwriter_start_document); ZEND_FUNCTION(xmlwriter_end_document); ZEND_FUNCTION(xmlwriter_write_comment); ZEND_FUNCTION(xmlwriter_start_dtd); ZEND_FUNCTION(xmlwriter_end_dtd); ZEND_FUNCTION(xmlwriter_write_dtd); ZEND_FUNCTION(xmlwriter_start_dtd_element); ZEND_FUNCTION(xmlwriter_end_dtd_element); ZEND_FUNCTION(xmlwriter_write_dtd_element); ZEND_FUNCTION(xmlwriter_start_dtd_attlist); ZEND_FUNCTION(xmlwriter_end_dtd_attlist); ZEND_FUNCTION(xmlwriter_write_dtd_attlist); ZEND_FUNCTION(xmlwriter_start_dtd_entity); ZEND_FUNCTION(xmlwriter_end_dtd_entity); ZEND_FUNCTION(xmlwriter_write_dtd_entity); ZEND_FUNCTION(xmlwriter_output_memory); ZEND_FUNCTION(xmlwriter_flush); static const zend_function_entry ext_functions[] = { ZEND_FE(xmlwriter_open_uri, arginfo_xmlwriter_open_uri) ZEND_FE(xmlwriter_open_memory, arginfo_xmlwriter_open_memory) ZEND_FE(xmlwriter_set_indent, arginfo_xmlwriter_set_indent) ZEND_FE(xmlwriter_set_indent_string, arginfo_xmlwriter_set_indent_string) ZEND_FE(xmlwriter_start_comment, arginfo_xmlwriter_start_comment) ZEND_FE(xmlwriter_end_comment, arginfo_xmlwriter_end_comment) ZEND_FE(xmlwriter_start_attribute, arginfo_xmlwriter_start_attribute) ZEND_FE(xmlwriter_end_attribute, arginfo_xmlwriter_end_attribute) ZEND_FE(xmlwriter_write_attribute, arginfo_xmlwriter_write_attribute) ZEND_FE(xmlwriter_start_attribute_ns, arginfo_xmlwriter_start_attribute_ns) ZEND_FE(xmlwriter_write_attribute_ns, arginfo_xmlwriter_write_attribute_ns) ZEND_FE(xmlwriter_start_element, arginfo_xmlwriter_start_element) ZEND_FE(xmlwriter_end_element, arginfo_xmlwriter_end_element) ZEND_FE(xmlwriter_full_end_element, arginfo_xmlwriter_full_end_element) ZEND_FE(xmlwriter_start_element_ns, arginfo_xmlwriter_start_element_ns) ZEND_FE(xmlwriter_write_element, arginfo_xmlwriter_write_element) ZEND_FE(xmlwriter_write_element_ns, arginfo_xmlwriter_write_element_ns) ZEND_FE(xmlwriter_start_pi, arginfo_xmlwriter_start_pi) ZEND_FE(xmlwriter_end_pi, arginfo_xmlwriter_end_pi) ZEND_FE(xmlwriter_write_pi, arginfo_xmlwriter_write_pi) ZEND_FE(xmlwriter_start_cdata, arginfo_xmlwriter_start_cdata) ZEND_FE(xmlwriter_end_cdata, arginfo_xmlwriter_end_cdata) ZEND_FE(xmlwriter_write_cdata, arginfo_xmlwriter_write_cdata) ZEND_FE(xmlwriter_text, arginfo_xmlwriter_text) ZEND_FE(xmlwriter_write_raw, arginfo_xmlwriter_write_raw) ZEND_FE(xmlwriter_start_document, arginfo_xmlwriter_start_document) ZEND_FE(xmlwriter_end_document, arginfo_xmlwriter_end_document) ZEND_FE(xmlwriter_write_comment, arginfo_xmlwriter_write_comment) ZEND_FE(xmlwriter_start_dtd, arginfo_xmlwriter_start_dtd) ZEND_FE(xmlwriter_end_dtd, arginfo_xmlwriter_end_dtd) ZEND_FE(xmlwriter_write_dtd, arginfo_xmlwriter_write_dtd) ZEND_FE(xmlwriter_start_dtd_element, arginfo_xmlwriter_start_dtd_element) ZEND_FE(xmlwriter_end_dtd_element, arginfo_xmlwriter_end_dtd_element) ZEND_FE(xmlwriter_write_dtd_element, arginfo_xmlwriter_write_dtd_element) ZEND_FE(xmlwriter_start_dtd_attlist, arginfo_xmlwriter_start_dtd_attlist) ZEND_FE(xmlwriter_end_dtd_attlist, arginfo_xmlwriter_end_dtd_attlist) ZEND_FE(xmlwriter_write_dtd_attlist, arginfo_xmlwriter_write_dtd_attlist) ZEND_FE(xmlwriter_start_dtd_entity, arginfo_xmlwriter_start_dtd_entity) ZEND_FE(xmlwriter_end_dtd_entity, arginfo_xmlwriter_end_dtd_entity) ZEND_FE(xmlwriter_write_dtd_entity, arginfo_xmlwriter_write_dtd_entity) ZEND_FE(xmlwriter_output_memory, arginfo_xmlwriter_output_memory) ZEND_FE(xmlwriter_flush, arginfo_xmlwriter_flush) ZEND_FE_END }; static const zend_function_entry class_XMLWriter_methods[] = { ZEND_ME_MAPPING(openUri, xmlwriter_open_uri, arginfo_class_XMLWriter_openUri, ZEND_ACC_PUBLIC) ZEND_ME_MAPPING(openMemory, xmlwriter_open_memory, arginfo_class_XMLWriter_openMemory, ZEND_ACC_PUBLIC) ZEND_ME_MAPPING(setIndent, xmlwriter_set_indent, arginfo_class_XMLWriter_setIndent, ZEND_ACC_PUBLIC) ZEND_ME_MAPPING(setIndentString, xmlwriter_set_indent_string, arginfo_class_XMLWriter_setIndentString, ZEND_ACC_PUBLIC) ZEND_ME_MAPPING(startComment, xmlwriter_start_comment, arginfo_class_XMLWriter_startComment, ZEND_ACC_PUBLIC) ZEND_ME_MAPPING(endComment, xmlwriter_end_comment, arginfo_class_XMLWriter_endComment, ZEND_ACC_PUBLIC) ZEND_ME_MAPPING(startAttribute, xmlwriter_start_attribute, arginfo_class_XMLWriter_startAttribute, ZEND_ACC_PUBLIC) ZEND_ME_MAPPING(endAttribute, xmlwriter_end_attribute, arginfo_class_XMLWriter_endAttribute, ZEND_ACC_PUBLIC) ZEND_ME_MAPPING(writeAttribute, xmlwriter_write_attribute, arginfo_class_XMLWriter_writeAttribute, ZEND_ACC_PUBLIC) ZEND_ME_MAPPING(startAttributeNs, xmlwriter_start_attribute_ns, arginfo_class_XMLWriter_startAttributeNs, ZEND_ACC_PUBLIC) ZEND_ME_MAPPING(writeAttributeNs, xmlwriter_write_attribute_ns, arginfo_class_XMLWriter_writeAttributeNs, ZEND_ACC_PUBLIC) ZEND_ME_MAPPING(startElement, xmlwriter_start_element, arginfo_class_XMLWriter_startElement, ZEND_ACC_PUBLIC) ZEND_ME_MAPPING(endElement, xmlwriter_end_element, arginfo_class_XMLWriter_endElement, ZEND_ACC_PUBLIC) ZEND_ME_MAPPING(fullEndElement, xmlwriter_full_end_element, arginfo_class_XMLWriter_fullEndElement, ZEND_ACC_PUBLIC) ZEND_ME_MAPPING(startElementNs, xmlwriter_start_element_ns, arginfo_class_XMLWriter_startElementNs, ZEND_ACC_PUBLIC) ZEND_ME_MAPPING(writeElement, xmlwriter_write_element, arginfo_class_XMLWriter_writeElement, ZEND_ACC_PUBLIC) ZEND_ME_MAPPING(writeElementNs, xmlwriter_write_element_ns, arginfo_class_XMLWriter_writeElementNs, ZEND_ACC_PUBLIC) ZEND_ME_MAPPING(startPi, xmlwriter_start_pi, arginfo_class_XMLWriter_startPi, ZEND_ACC_PUBLIC) ZEND_ME_MAPPING(endPi, xmlwriter_end_pi, arginfo_class_XMLWriter_endPi, ZEND_ACC_PUBLIC) ZEND_ME_MAPPING(writePi, xmlwriter_write_pi, arginfo_class_XMLWriter_writePi, ZEND_ACC_PUBLIC) ZEND_ME_MAPPING(startCdata, xmlwriter_start_cdata, arginfo_class_XMLWriter_startCdata, ZEND_ACC_PUBLIC) ZEND_ME_MAPPING(endCdata, xmlwriter_end_cdata, arginfo_class_XMLWriter_endCdata, ZEND_ACC_PUBLIC) ZEND_ME_MAPPING(writeCdata, xmlwriter_write_cdata, arginfo_class_XMLWriter_writeCdata, ZEND_ACC_PUBLIC) ZEND_ME_MAPPING(text, xmlwriter_text, arginfo_class_XMLWriter_text, ZEND_ACC_PUBLIC) ZEND_ME_MAPPING(writeRaw, xmlwriter_write_raw, arginfo_class_XMLWriter_writeRaw, ZEND_ACC_PUBLIC) ZEND_ME_MAPPING(startDocument, xmlwriter_start_document, arginfo_class_XMLWriter_startDocument, ZEND_ACC_PUBLIC) ZEND_ME_MAPPING(endDocument, xmlwriter_end_document, arginfo_class_XMLWriter_endDocument, ZEND_ACC_PUBLIC) ZEND_ME_MAPPING(writeComment, xmlwriter_write_comment, arginfo_class_XMLWriter_writeComment, ZEND_ACC_PUBLIC) ZEND_ME_MAPPING(startDtd, xmlwriter_start_dtd, arginfo_class_XMLWriter_startDtd, ZEND_ACC_PUBLIC) ZEND_ME_MAPPING(endDtd, xmlwriter_end_dtd, arginfo_class_XMLWriter_endDtd, ZEND_ACC_PUBLIC) ZEND_ME_MAPPING(writeDtd, xmlwriter_write_dtd, arginfo_class_XMLWriter_writeDtd, ZEND_ACC_PUBLIC) ZEND_ME_MAPPING(startDtdElement, xmlwriter_start_dtd_element, arginfo_class_XMLWriter_startDtdElement, ZEND_ACC_PUBLIC) ZEND_ME_MAPPING(endDtdElement, xmlwriter_end_dtd_element, arginfo_class_XMLWriter_endDtdElement, ZEND_ACC_PUBLIC) ZEND_ME_MAPPING(writeDtdElement, xmlwriter_write_dtd_element, arginfo_class_XMLWriter_writeDtdElement, ZEND_ACC_PUBLIC) ZEND_ME_MAPPING(startDtdAttlist, xmlwriter_start_dtd_attlist, arginfo_class_XMLWriter_startDtdAttlist, ZEND_ACC_PUBLIC) ZEND_ME_MAPPING(endDtdAttlist, xmlwriter_end_dtd_attlist, arginfo_class_XMLWriter_endDtdAttlist, ZEND_ACC_PUBLIC) ZEND_ME_MAPPING(writeDtdAttlist, xmlwriter_write_dtd_attlist, arginfo_class_XMLWriter_writeDtdAttlist, ZEND_ACC_PUBLIC) ZEND_ME_MAPPING(startDtdEntity, xmlwriter_start_dtd_entity, arginfo_class_XMLWriter_startDtdEntity, ZEND_ACC_PUBLIC) ZEND_ME_MAPPING(endDtdEntity, xmlwriter_end_dtd_entity, arginfo_class_XMLWriter_endDtdEntity, ZEND_ACC_PUBLIC) ZEND_ME_MAPPING(writeDtdEntity, xmlwriter_write_dtd_entity, arginfo_class_XMLWriter_writeDtdEntity, ZEND_ACC_PUBLIC) ZEND_ME_MAPPING(outputMemory, xmlwriter_output_memory, arginfo_class_XMLWriter_outputMemory, ZEND_ACC_PUBLIC) ZEND_ME_MAPPING(flush, xmlwriter_flush, arginfo_class_XMLWriter_flush, ZEND_ACC_PUBLIC) ZEND_FE_END }; static zend_class_entry *register_class_XMLWriter(void) { zend_class_entry ce, *class_entry; INIT_CLASS_ENTRY(ce, "XMLWriter", class_XMLWriter_methods); class_entry = zend_register_internal_class_ex(&ce, NULL); return class_entry; }
23,977
49.268344
123
h
php-src
php-src-master/ext/xsl/php_xsl.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: Christian Stocker <[email protected]> | +----------------------------------------------------------------------+ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "php.h" #include "php_ini.h" #include "ext/standard/info.h" #include "php_xsl.h" #include "php_xsl_arginfo.h" zend_class_entry *xsl_xsltprocessor_class_entry; static zend_object_handlers xsl_object_handlers; static const zend_module_dep xsl_deps[] = { ZEND_MOD_REQUIRED("libxml") ZEND_MOD_END }; /* {{{ xsl_module_entry */ zend_module_entry xsl_module_entry = { STANDARD_MODULE_HEADER_EX, NULL, xsl_deps, "xsl", NULL, PHP_MINIT(xsl), PHP_MSHUTDOWN(xsl), NULL, NULL, PHP_MINFO(xsl), PHP_XSL_VERSION, STANDARD_MODULE_PROPERTIES }; /* }}} */ #ifdef COMPILE_DL_XSL ZEND_GET_MODULE(xsl) #endif /* {{{ xsl_objects_free_storage */ void xsl_objects_free_storage(zend_object *object) { xsl_object *intern = php_xsl_fetch_object(object); zend_object_std_dtor(&intern->std); zend_hash_destroy(intern->parameter); FREE_HASHTABLE(intern->parameter); zend_hash_destroy(intern->registered_phpfunctions); FREE_HASHTABLE(intern->registered_phpfunctions); if (intern->node_list) { zend_hash_destroy(intern->node_list); FREE_HASHTABLE(intern->node_list); } if (intern->doc) { php_libxml_decrement_doc_ref(intern->doc); efree(intern->doc); } if (intern->ptr) { /* free wrapper */ if (((xsltStylesheetPtr) intern->ptr)->_private != NULL) { ((xsltStylesheetPtr) intern->ptr)->_private = NULL; } xsltFreeStylesheet((xsltStylesheetPtr) intern->ptr); intern->ptr = NULL; } if (intern->profiling) { efree(intern->profiling); } } /* }}} */ /* {{{ xsl_objects_new */ zend_object *xsl_objects_new(zend_class_entry *class_type) { xsl_object *intern; intern = zend_object_alloc(sizeof(xsl_object), class_type); intern->securityPrefs = XSL_SECPREF_DEFAULT; zend_object_std_init(&intern->std, class_type); object_properties_init(&intern->std, class_type); intern->parameter = zend_new_array(0); intern->registered_phpfunctions = zend_new_array(0); return &intern->std; } /* }}} */ /* {{{ PHP_MINIT_FUNCTION */ PHP_MINIT_FUNCTION(xsl) { memcpy(&xsl_object_handlers, &std_object_handlers, sizeof(zend_object_handlers)); xsl_object_handlers.offset = XtOffsetOf(xsl_object, std); xsl_object_handlers.clone_obj = NULL; xsl_object_handlers.free_obj = xsl_objects_free_storage; xsl_xsltprocessor_class_entry = register_class_XSLTProcessor(); xsl_xsltprocessor_class_entry->create_object = xsl_objects_new; xsl_xsltprocessor_class_entry->default_object_handlers = &xsl_object_handlers; #ifdef HAVE_XSL_EXSLT exsltRegisterAll(); #endif xsltRegisterExtModuleFunction ((const xmlChar *) "functionString", (const xmlChar *) "http://php.net/xsl", xsl_ext_function_string_php); xsltRegisterExtModuleFunction ((const xmlChar *) "function", (const xmlChar *) "http://php.net/xsl", xsl_ext_function_object_php); xsltSetGenericErrorFunc(NULL, php_libxml_error_handler); register_php_xsl_symbols(module_number); return SUCCESS; } /* }}} */ /* {{{ xsl_object_get_data */ zval *xsl_object_get_data(void *obj) { zval *dom_wrapper; dom_wrapper = ((xsltStylesheetPtr) obj)->_private; return dom_wrapper; } /* }}} */ /* {{{ xsl_object_set_data */ static void xsl_object_set_data(void *obj, zval *wrapper) { ((xsltStylesheetPtr) obj)->_private = wrapper; } /* }}} */ /* {{{ php_xsl_set_object */ void php_xsl_set_object(zval *wrapper, void *obj) { xsl_object *object; object = Z_XSL_P(wrapper); object->ptr = obj; xsl_object_set_data(obj, wrapper); } /* }}} */ /* {{{ php_xsl_create_object */ void php_xsl_create_object(xsltStylesheetPtr obj, zval *wrapper_in, zval *return_value ) { zval *wrapper; zend_class_entry *ce; if (!obj) { wrapper = wrapper_in; ZVAL_NULL(wrapper); return; } if ((wrapper = xsl_object_get_data((void *) obj))) { ZVAL_COPY(wrapper, wrapper_in); return; } if (!wrapper_in) { wrapper = return_value; } else { wrapper = wrapper_in; } ce = xsl_xsltprocessor_class_entry; if (!wrapper_in) { object_init_ex(wrapper, ce); } php_xsl_set_object(wrapper, (void *) obj); return; } /* }}} */ /* {{{ PHP_MSHUTDOWN_FUNCTION */ PHP_MSHUTDOWN_FUNCTION(xsl) { xsltUnregisterExtModuleFunction ((const xmlChar *) "functionString", (const xmlChar *) "http://php.net/xsl"); xsltUnregisterExtModuleFunction ((const xmlChar *) "function", (const xmlChar *) "http://php.net/xsl"); xsltSetGenericErrorFunc(NULL, NULL); xsltCleanupGlobals(); return SUCCESS; } /* }}} */ /* {{{ PHP_MINFO_FUNCTION */ PHP_MINFO_FUNCTION(xsl) { php_info_print_table_start(); { char buffer[128]; int major, minor, subminor; php_info_print_table_row(2, "XSL", "enabled"); major = xsltLibxsltVersion/10000; minor = (xsltLibxsltVersion - major * 10000) / 100; subminor = (xsltLibxsltVersion - major * 10000 - minor * 100); snprintf(buffer, 128, "%d.%d.%d", major, minor, subminor); php_info_print_table_row(2, "libxslt Version", buffer); major = xsltLibxmlVersion/10000; minor = (xsltLibxmlVersion - major * 10000) / 100; subminor = (xsltLibxmlVersion - major * 10000 - minor * 100); snprintf(buffer, 128, "%d.%d.%d", major, minor, subminor); php_info_print_table_row(2, "libxslt compiled against libxml Version", buffer); } #ifdef HAVE_XSL_EXSLT php_info_print_table_row(2, "EXSLT", "enabled"); php_info_print_table_row(2, "libexslt Version", LIBEXSLT_DOTTED_VERSION); #endif php_info_print_table_end(); } /* }}} */
6,399
25.337449
88
c
php-src
php-src-master/ext/xsl/php_xsl.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: | +----------------------------------------------------------------------+ */ #ifndef PHP_XSL_H #define PHP_XSL_H extern zend_module_entry xsl_module_entry; #define phpext_xsl_ptr &xsl_module_entry #include "php_version.h" #define PHP_XSL_VERSION PHP_VERSION #ifdef ZTS #include "TSRM.h" #endif #include <libxslt/xsltconfig.h> #include <libxslt/xsltInternals.h> #include <libxslt/xsltutils.h> #include <libxslt/transform.h> #include <libxslt/security.h> #ifdef HAVE_XSL_EXSLT #include <libexslt/exslt.h> #include <libexslt/exsltconfig.h> #endif #include "../dom/xml_common.h" #include <libxslt/extensions.h> #include <libxml/xpathInternals.h> #define XSL_SECPREF_NONE 0 #define XSL_SECPREF_READ_FILE 2 #define XSL_SECPREF_WRITE_FILE 4 #define XSL_SECPREF_CREATE_DIRECTORY 8 #define XSL_SECPREF_READ_NETWORK 16 #define XSL_SECPREF_WRITE_NETWORK 32 /* Default == disable all write access == XSL_SECPREF_WRITE_NETWORK | XSL_SECPREF_CREATE_DIRECTORY | XSL_SECPREF_WRITE_FILE */ #define XSL_SECPREF_DEFAULT 44 typedef struct _xsl_object { void *ptr; HashTable *prop_handler; zval handle; HashTable *parameter; int hasKeys; int registerPhpFunctions; HashTable *registered_phpfunctions; HashTable *node_list; php_libxml_node_object *doc; char *profiling; zend_long securityPrefs; int securityPrefsSet; zend_object std; } xsl_object; static inline xsl_object *php_xsl_fetch_object(zend_object *obj) { return (xsl_object *)((char*)(obj) - XtOffsetOf(xsl_object, std)); } #define Z_XSL_P(zv) php_xsl_fetch_object(Z_OBJ_P((zv))) void php_xsl_set_object(zval *wrapper, void *obj); void xsl_objects_free_storage(zend_object *object); void php_xsl_create_object(xsltStylesheetPtr obj, zval *wrapper_in, zval *return_value ); void xsl_ext_function_string_php(xmlXPathParserContextPtr ctxt, int nargs); void xsl_ext_function_object_php(xmlXPathParserContextPtr ctxt, int nargs); PHP_MINIT_FUNCTION(xsl); PHP_MSHUTDOWN_FUNCTION(xsl); PHP_RINIT_FUNCTION(xsl); PHP_RSHUTDOWN_FUNCTION(xsl); PHP_MINFO_FUNCTION(xsl); #endif /* PHP_XSL_H */
2,953
31.822222
127
h
php-src
php-src-master/ext/zend_test/fiber.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: Aaron Piotrowski <[email protected]> | +----------------------------------------------------------------------+ */ #include "php_test.h" #include "fiber.h" #include "fiber_arginfo.h" #include "zend_fibers.h" #include "zend_exceptions.h" static zend_class_entry *zend_test_fiber_class; static zend_object_handlers zend_test_fiber_handlers; static zend_fiber_transfer zend_test_fiber_switch_to(zend_fiber_context *context, zval *value, bool exception) { zend_fiber_transfer transfer = { .context = context, .flags = exception ? ZEND_FIBER_TRANSFER_FLAG_ERROR : 0, }; if (value) { ZVAL_COPY(&transfer.value, value); } else { ZVAL_NULL(&transfer.value); } zend_fiber_switch_context(&transfer); /* Forward bailout into current fiber. */ if (UNEXPECTED(transfer.flags & ZEND_FIBER_TRANSFER_FLAG_BAILOUT)) { zend_bailout(); } return transfer; } static zend_fiber_transfer zend_test_fiber_resume(zend_test_fiber *fiber, zval *value, bool exception) { zend_test_fiber *previous = ZT_G(active_fiber); fiber->caller = EG(current_fiber_context); ZT_G(active_fiber) = fiber; zend_fiber_transfer transfer = zend_test_fiber_switch_to(fiber->previous, value, exception); ZT_G(active_fiber) = previous; return transfer; } static zend_fiber_transfer zend_test_fiber_suspend(zend_test_fiber *fiber, zval *value) { ZEND_ASSERT(fiber->caller != NULL); zend_fiber_context *caller = fiber->caller; fiber->previous = EG(current_fiber_context); fiber->caller = NULL; return zend_test_fiber_switch_to(caller, value, false); } static ZEND_STACK_ALIGNED void zend_test_fiber_execute(zend_fiber_transfer *transfer) { zend_test_fiber *fiber = ZT_G(active_fiber); zval retval; zend_execute_data *execute_data; EG(vm_stack) = NULL; transfer->flags = 0; zend_first_try { zend_vm_stack stack = zend_vm_stack_new_page(ZEND_FIBER_VM_STACK_SIZE, NULL); EG(vm_stack) = stack; EG(vm_stack_top) = stack->top + ZEND_CALL_FRAME_SLOT; EG(vm_stack_end) = stack->end; EG(vm_stack_page_size) = ZEND_FIBER_VM_STACK_SIZE; execute_data = (zend_execute_data *) stack->top; memset(execute_data, 0, sizeof(zend_execute_data)); EG(current_execute_data) = execute_data; EG(jit_trace_num) = 0; #ifdef ZEND_CHECK_STACK_LIMIT EG(stack_base) = zend_fiber_stack_base(fiber->context.stack); EG(stack_limit) = zend_fiber_stack_limit(fiber->context.stack); #endif fiber->fci.retval = &retval; zend_call_function(&fiber->fci, &fiber->fci_cache); zval_ptr_dtor(&fiber->result); // Destroy param from symmetric coroutine. zval_ptr_dtor(&fiber->fci.function_name); if (EG(exception)) { if (!(fiber->flags & ZEND_FIBER_FLAG_DESTROYED) || !(zend_is_graceful_exit(EG(exception)) || zend_is_unwind_exit(EG(exception))) ) { fiber->flags |= ZEND_FIBER_FLAG_THREW; transfer->flags = ZEND_FIBER_TRANSFER_FLAG_ERROR; ZVAL_OBJ_COPY(&transfer->value, EG(exception)); } zend_clear_exception(); } else { ZVAL_COPY_VALUE(&fiber->result, &retval); ZVAL_COPY(&transfer->value, &fiber->result); } } zend_catch { fiber->flags |= ZEND_FIBER_FLAG_BAILOUT; transfer->flags = ZEND_FIBER_TRANSFER_FLAG_BAILOUT; } zend_end_try(); zend_vm_stack_destroy(); if (fiber->target) { zend_fiber_context *target = &fiber->target->context; zend_fiber_init_context(target, zend_test_fiber_class, zend_test_fiber_execute, EG(fiber_stack_size)); transfer->context = target; ZVAL_COPY(&fiber->target->result, &fiber->result); fiber->target->fci.params = &fiber->target->result; fiber->target->fci.param_count = 1; fiber->target->caller = fiber->caller; ZT_G(active_fiber) = fiber->target; } else { transfer->context = fiber->caller; } fiber->caller = NULL; } static zend_object *zend_test_fiber_object_create(zend_class_entry *ce) { zend_test_fiber *fiber; fiber = emalloc(sizeof(zend_test_fiber)); memset(fiber, 0, sizeof(zend_test_fiber)); zend_object_std_init(&fiber->std, ce); return &fiber->std; } static void zend_test_fiber_object_destroy(zend_object *object) { zend_test_fiber *fiber = (zend_test_fiber *) object; if (fiber->context.status != ZEND_FIBER_STATUS_SUSPENDED) { return; } zend_object *exception = EG(exception); EG(exception) = NULL; fiber->flags |= ZEND_FIBER_FLAG_DESTROYED; zend_fiber_transfer transfer = zend_test_fiber_resume(fiber, NULL, false); if (transfer.flags & ZEND_FIBER_TRANSFER_FLAG_ERROR) { EG(exception) = Z_OBJ(transfer.value); if (!exception && EG(current_execute_data) && EG(current_execute_data)->func && ZEND_USER_CODE(EG(current_execute_data)->func->common.type)) { zend_rethrow_exception(EG(current_execute_data)); } zend_exception_set_previous(EG(exception), exception); if (!EG(current_execute_data)) { zend_exception_error(EG(exception), E_ERROR); } } else { zval_ptr_dtor(&transfer.value); EG(exception) = exception; } } static void zend_test_fiber_object_free(zend_object *object) { zend_test_fiber *fiber = (zend_test_fiber *) object; if (fiber->context.status == ZEND_FIBER_STATUS_INIT) { // Fiber was never started, so we need to release the reference to the callback. zval_ptr_dtor(&fiber->fci.function_name); } if (fiber->target) { OBJ_RELEASE(&fiber->target->std); } zval_ptr_dtor(&fiber->result); zend_object_std_dtor(&fiber->std); } static zend_always_inline void delegate_transfer_result( zend_test_fiber *fiber, zend_fiber_transfer *transfer, INTERNAL_FUNCTION_PARAMETERS ) { if (transfer->flags & ZEND_FIBER_TRANSFER_FLAG_ERROR) { zend_throw_exception_internal(Z_OBJ(transfer->value)); RETURN_THROWS(); } if (fiber->context.status == ZEND_FIBER_STATUS_DEAD) { zval_ptr_dtor(&transfer->value); RETURN_NULL(); } RETURN_COPY_VALUE(&transfer->value); } static ZEND_METHOD(_ZendTestFiber, __construct) { zend_test_fiber *fiber = (zend_test_fiber *) Z_OBJ_P(getThis()); ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_FUNC(fiber->fci, fiber->fci_cache) ZEND_PARSE_PARAMETERS_END(); // Keep a reference to closures or callable objects while the fiber is running. Z_TRY_ADDREF(fiber->fci.function_name); } static ZEND_METHOD(_ZendTestFiber, start) { zend_test_fiber *fiber = (zend_test_fiber *) Z_OBJ_P(getThis()); zval *params; uint32_t param_count; zend_array *named_params; ZEND_PARSE_PARAMETERS_START(0, -1) Z_PARAM_VARIADIC_WITH_NAMED(params, param_count, named_params); ZEND_PARSE_PARAMETERS_END(); ZEND_ASSERT(fiber->context.status == ZEND_FIBER_STATUS_INIT); if (fiber->previous != NULL) { zend_throw_error(NULL, "Cannot start a fiber that is the target of another fiber"); RETURN_THROWS(); } fiber->fci.params = params; fiber->fci.param_count = param_count; fiber->fci.named_params = named_params; zend_fiber_init_context(&fiber->context, zend_test_fiber_class, zend_test_fiber_execute, EG(fiber_stack_size)); fiber->previous = &fiber->context; zend_fiber_transfer transfer = zend_test_fiber_resume(fiber, NULL, false); delegate_transfer_result(fiber, &transfer, INTERNAL_FUNCTION_PARAM_PASSTHRU); } static ZEND_METHOD(_ZendTestFiber, suspend) { zval *value = NULL; ZEND_PARSE_PARAMETERS_START(0, 1) Z_PARAM_OPTIONAL Z_PARAM_ZVAL(value); ZEND_PARSE_PARAMETERS_END(); zend_test_fiber *fiber = ZT_G(active_fiber); ZEND_ASSERT(fiber); zend_fiber_transfer transfer = zend_test_fiber_suspend(fiber, value); if (fiber->flags & ZEND_FIBER_FLAG_DESTROYED) { // This occurs when the test fiber is GC'ed while suspended. zval_ptr_dtor(&transfer.value); zend_throw_graceful_exit(); RETURN_THROWS(); } delegate_transfer_result(fiber, &transfer, INTERNAL_FUNCTION_PARAM_PASSTHRU); } static ZEND_METHOD(_ZendTestFiber, resume) { zend_test_fiber *fiber; zval *value = NULL; ZEND_PARSE_PARAMETERS_START(0, 1) Z_PARAM_OPTIONAL Z_PARAM_ZVAL(value); ZEND_PARSE_PARAMETERS_END(); fiber = (zend_test_fiber *) Z_OBJ_P(getThis()); if (UNEXPECTED(fiber->context.status != ZEND_FIBER_STATUS_SUSPENDED || fiber->caller != NULL)) { zend_throw_error(NULL, "Cannot resume a fiber that is not suspended"); RETURN_THROWS(); } zend_fiber_transfer transfer = zend_test_fiber_resume(fiber, value, false); delegate_transfer_result(fiber, &transfer, INTERNAL_FUNCTION_PARAM_PASSTHRU); } static ZEND_METHOD(_ZendTestFiber, pipeTo) { zend_fcall_info fci; zend_fcall_info_cache fci_cache; ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_FUNC(fci, fci_cache) ZEND_PARSE_PARAMETERS_END(); zend_test_fiber *fiber = (zend_test_fiber *) Z_OBJ_P(getThis()); zend_test_fiber *target = (zend_test_fiber *) zend_test_fiber_class->create_object(zend_test_fiber_class); target->fci = fci; target->fci_cache = fci_cache; Z_TRY_ADDREF(target->fci.function_name); target->previous = &fiber->context; if (fiber->target) { OBJ_RELEASE(&fiber->target->std); } fiber->target = target; RETURN_OBJ_COPY(&target->std); } void zend_test_fiber_init(void) { zend_test_fiber_class = register_class__ZendTestFiber(); zend_test_fiber_class->create_object = zend_test_fiber_object_create; zend_test_fiber_class->default_object_handlers = &zend_test_fiber_handlers; zend_test_fiber_handlers = std_object_handlers; zend_test_fiber_handlers.dtor_obj = zend_test_fiber_object_destroy; zend_test_fiber_handlers.free_obj = zend_test_fiber_object_free; }
10,180
27.598315
112
c
php-src
php-src-master/ext/zend_test/fiber.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: Aaron Piotrowski <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef ZEND_TEST_FIBER_H #define ZEND_TEST_FIBER_H #include "zend_fibers.h" typedef struct _zend_test_fiber zend_test_fiber; struct _zend_test_fiber { zend_object std; uint8_t flags; zend_fiber_context context; zend_fiber_context *caller; zend_fiber_context *previous; zend_test_fiber *target; zend_fcall_info fci; zend_fcall_info_cache fci_cache; zval result; }; void zend_test_fiber_init(void); #endif
1,401
34.948718
74
h
php-src
php-src-master/ext/zend_test/fiber_arginfo.h
/* This is a generated file, edit the .stub.php file instead. * Stub hash: 8cd7626122b050585503ccebe370a61781ff83f2 */ ZEND_BEGIN_ARG_INFO_EX(arginfo_class__ZendTestFiber___construct, 0, 0, 1) ZEND_ARG_TYPE_INFO(0, callback, IS_CALLABLE, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class__ZendTestFiber_start, 0, 0, IS_MIXED, 0) ZEND_ARG_VARIADIC_TYPE_INFO(0, args, IS_MIXED, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class__ZendTestFiber_resume, 0, 0, IS_MIXED, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, value, IS_MIXED, 0, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class__ZendTestFiber_pipeTo, 0, 1, _ZendTestFiber, 0) ZEND_ARG_TYPE_INFO(0, callback, IS_CALLABLE, 0) ZEND_END_ARG_INFO() #define arginfo_class__ZendTestFiber_suspend arginfo_class__ZendTestFiber_resume static ZEND_METHOD(_ZendTestFiber, __construct); static ZEND_METHOD(_ZendTestFiber, start); static ZEND_METHOD(_ZendTestFiber, resume); static ZEND_METHOD(_ZendTestFiber, pipeTo); static ZEND_METHOD(_ZendTestFiber, suspend); static const zend_function_entry class__ZendTestFiber_methods[] = { ZEND_ME(_ZendTestFiber, __construct, arginfo_class__ZendTestFiber___construct, ZEND_ACC_PUBLIC) ZEND_ME(_ZendTestFiber, start, arginfo_class__ZendTestFiber_start, ZEND_ACC_PUBLIC) ZEND_ME(_ZendTestFiber, resume, arginfo_class__ZendTestFiber_resume, ZEND_ACC_PUBLIC) ZEND_ME(_ZendTestFiber, pipeTo, arginfo_class__ZendTestFiber_pipeTo, ZEND_ACC_PUBLIC) ZEND_ME(_ZendTestFiber, suspend, arginfo_class__ZendTestFiber_suspend, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) ZEND_FE_END }; static zend_class_entry *register_class__ZendTestFiber(void) { zend_class_entry ce, *class_entry; INIT_CLASS_ENTRY(ce, "_ZendTestFiber", class__ZendTestFiber_methods); class_entry = zend_register_internal_class_ex(&ce, NULL); class_entry->ce_flags |= ZEND_ACC_FINAL; return class_entry; }
1,942
38.653061
104
h
php-src
php-src-master/ext/zend_test/observer.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: | +----------------------------------------------------------------------+ */ #ifndef ZEND_TEST_OBSERVER_H #define ZEND_TEST_OBSERVER_H void zend_test_observer_init(INIT_FUNC_ARGS); void zend_test_observer_shutdown(SHUTDOWN_FUNC_ARGS); void zend_test_observer_ginit(zend_zend_test_globals *zend_test_globals); void zend_test_observer_gshutdown(zend_zend_test_globals *zend_test_globals); #endif
1,301
49.076923
77
h
php-src
php-src-master/ext/zend_test/php_test.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: | +----------------------------------------------------------------------+ */ #ifndef PHP_TEST_H #define PHP_TEST_H #include "fiber.h" extern zend_module_entry zend_test_module_entry; #define phpext_zend_test_ptr &zend_test_module_entry #define PHP_ZEND_TEST_VERSION "0.1.0" #ifdef ZTS #include "TSRM.h" #endif #if defined(ZTS) && defined(COMPILE_DL_ZEND_TEST) ZEND_TSRMLS_CACHE_EXTERN() #endif ZEND_BEGIN_MODULE_GLOBALS(zend_test) int observer_enabled; int observer_show_output; int observer_observe_all; int observer_observe_includes; int observer_observe_functions; int observer_observe_declaring; zend_array *observer_observe_function_names; int observer_show_return_type; int observer_show_return_value; int observer_show_init_backtrace; int observer_show_opcode; char *observer_show_opcode_in_user_handler; int observer_nesting_depth; int observer_fiber_init; int observer_fiber_switch; int observer_fiber_destroy; int observer_execute_internal; HashTable global_weakmap; int replace_zend_execute_ex; int register_passes; bool print_stderr_mshutdown; zend_long limit_copy_file_range; zend_test_fiber *active_fiber; zend_long quantity_value; zend_string *str_test; zend_string *not_empty_str_test; ZEND_END_MODULE_GLOBALS(zend_test) extern ZEND_DECLARE_MODULE_GLOBALS(zend_test) #define ZT_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(zend_test, v) struct bug79096 { uint64_t a; uint64_t b; }; #ifdef PHP_WIN32 # define PHP_ZEND_TEST_API __declspec(dllexport) #elif defined(__GNUC__) && __GNUC__ >= 4 # define PHP_ZEND_TEST_API __attribute__ ((visibility("default"))) #else # define PHP_ZEND_TEST_API #endif PHP_ZEND_TEST_API int ZEND_FASTCALL bug78270(const char *str, size_t str_len); PHP_ZEND_TEST_API struct bug79096 bug79096(void); PHP_ZEND_TEST_API void bug79532(off_t *array, size_t elems); extern PHP_ZEND_TEST_API int *(*bug79177_cb)(void); PHP_ZEND_TEST_API void bug79177(void); #endif
2,836
30.522222
78
h
php-src
php-src-master/ext/zip/zip_stream.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: Piere-Alain Joye <[email protected]> | +----------------------------------------------------------------------+ */ #ifdef HAVE_CONFIG_H # include "config.h" #endif #include "php.h" #ifdef HAVE_ZIP #include "php_streams.h" #include "ext/standard/file.h" #include "ext/standard/php_string.h" #include "fopen_wrappers.h" #include "php_zip.h" #include "ext/standard/url.h" /* needed for ssize_t definition */ #include <sys/types.h> struct php_zip_stream_data_t { struct zip *za; struct zip_file *zf; size_t cursor; php_stream *stream; }; #define STREAM_DATA_FROM_STREAM() \ struct php_zip_stream_data_t *self = (struct php_zip_stream_data_t *) stream->abstract; /* {{{ php_zip_ops_read */ static ssize_t php_zip_ops_read(php_stream *stream, char *buf, size_t count) { ssize_t n = 0; STREAM_DATA_FROM_STREAM(); if (self->zf) { n = zip_fread(self->zf, buf, count); if (n < 0) { #if LIBZIP_VERSION_MAJOR < 1 int ze, se; zip_file_error_get(self->zf, &ze, &se); stream->eof = 1; php_error_docref(NULL, E_WARNING, "Zip stream error: %s", zip_file_strerror(self->zf)); #else zip_error_t *err; err = zip_file_get_error(self->zf); stream->eof = 1; php_error_docref(NULL, E_WARNING, "Zip stream error: %s", zip_error_strerror(err)); zip_error_fini(err); #endif return -1; } /* cast count to signed value to avoid possibly negative n * being cast to unsigned value */ if (n == 0 || n < (ssize_t)count) { stream->eof = 1; } else { self->cursor += n; } } return n; } /* }}} */ /* {{{ php_zip_ops_write */ static ssize_t php_zip_ops_write(php_stream *stream, const char *buf, size_t count) { if (!stream) { return -1; } return count; } /* }}} */ /* {{{ php_zip_ops_close */ static int php_zip_ops_close(php_stream *stream, int close_handle) { STREAM_DATA_FROM_STREAM(); if (close_handle) { if (self->zf) { zip_fclose(self->zf); self->zf = NULL; } if (self->za) { zip_close(self->za); self->za = NULL; } } efree(self); stream->abstract = NULL; return EOF; } /* }}} */ /* {{{ php_zip_ops_flush */ static int php_zip_ops_flush(php_stream *stream) { if (!stream) { return 0; } return 0; } /* }}} */ static int php_zip_ops_stat(php_stream *stream, php_stream_statbuf *ssb) /* {{{ */ { struct zip_stat sb; const char *path = stream->orig_path; size_t path_len = strlen(stream->orig_path); char file_dirname[MAXPATHLEN]; struct zip *za; char *fragment; size_t fragment_len; int err; zend_string *file_basename; fragment = strchr(path, '#'); if (!fragment) { return -1; } if (strncasecmp("zip://", path, 6) == 0) { path += 6; } fragment_len = strlen(fragment); if (fragment_len < 1) { return -1; } path_len = strlen(path); if (path_len >= MAXPATHLEN) { return -1; } memcpy(file_dirname, path, path_len - fragment_len); file_dirname[path_len - fragment_len] = '\0'; file_basename = php_basename((char *)path, path_len - fragment_len, NULL, 0); fragment++; if (ZIP_OPENBASEDIR_CHECKPATH(file_dirname)) { zend_string_release_ex(file_basename, 0); return -1; } za = zip_open(file_dirname, ZIP_CREATE, &err); if (za) { memset(ssb, 0, sizeof(php_stream_statbuf)); if (zip_stat(za, fragment, ZIP_FL_NOCASE, &sb) != 0) { zip_close(za); zend_string_release_ex(file_basename, 0); return -1; } zip_close(za); if (path[path_len-1] != '/') { ssb->sb.st_size = sb.size; ssb->sb.st_mode |= S_IFREG; /* regular file */ } else { ssb->sb.st_size = 0; ssb->sb.st_mode |= S_IFDIR; /* regular directory */ } ssb->sb.st_mtime = sb.mtime; ssb->sb.st_atime = sb.mtime; ssb->sb.st_ctime = sb.mtime; ssb->sb.st_nlink = 1; ssb->sb.st_rdev = -1; #ifndef PHP_WIN32 ssb->sb.st_blksize = -1; ssb->sb.st_blocks = -1; #endif ssb->sb.st_ino = -1; } zend_string_release_ex(file_basename, 0); return 0; } /* }}} */ #if LIBZIP_ATLEAST(1,9,1) /* {{{ php_zip_ops_seek */ static int php_zip_ops_seek(php_stream *stream, zend_off_t offset, int whence, zend_off_t *newoffset) { int ret = -1; STREAM_DATA_FROM_STREAM(); if (self->zf) { ret = zip_fseek(self->zf, offset, whence); *newoffset = zip_ftell(self->zf); } return ret; } /* }}} */ /* with seek command */ const php_stream_ops php_stream_zipio_seek_ops = { php_zip_ops_write, php_zip_ops_read, php_zip_ops_close, php_zip_ops_flush, "zip", php_zip_ops_seek, /* seek */ NULL, /* cast */ php_zip_ops_stat, /* stat */ NULL /* set_option */ }; #endif /* without seek command */ const php_stream_ops php_stream_zipio_ops = { php_zip_ops_write, php_zip_ops_read, php_zip_ops_close, php_zip_ops_flush, "zip", NULL, /* seek */ NULL, /* cast */ php_zip_ops_stat, /* stat */ NULL /* set_option */ }; /* {{{ php_stream_zip_open */ php_stream *php_stream_zip_open(struct zip *arch, struct zip_stat *sb, const char *mode, zip_flags_t flags STREAMS_DC) { struct zip_file *zf = NULL; php_stream *stream = NULL; struct php_zip_stream_data_t *self; if (strncmp(mode,"r", strlen("r")) != 0) { return NULL; } if (arch) { zf = zip_fopen_index(arch, sb->index, flags); if (zf) { self = emalloc(sizeof(*self)); self->za = NULL; /* to keep it open on stream close */ self->zf = zf; self->stream = NULL; self->cursor = 0; #if LIBZIP_ATLEAST(1,9,1) if (zip_file_is_seekable(zf) > 0) { stream = php_stream_alloc(&php_stream_zipio_seek_ops, self, NULL, mode); } else #endif { stream = php_stream_alloc(&php_stream_zipio_ops, self, NULL, mode); } stream->orig_path = estrdup(sb->name); } } return stream; } /* }}} */ /* {{{ php_stream_zip_opener */ php_stream *php_stream_zip_opener(php_stream_wrapper *wrapper, const char *path, const char *mode, int options, zend_string **opened_path, php_stream_context *context STREAMS_DC) { size_t path_len; zend_string *file_basename; char file_dirname[MAXPATHLEN]; struct zip *za; struct zip_file *zf = NULL; char *fragment; size_t fragment_len; int err; php_stream *stream = NULL; struct php_zip_stream_data_t *self; fragment = strchr(path, '#'); if (!fragment) { return NULL; } if (strncasecmp("zip://", path, 6) == 0) { path += 6; } fragment_len = strlen(fragment); if (fragment_len < 1) { return NULL; } path_len = strlen(path); if (path_len >= MAXPATHLEN || mode[0] != 'r') { return NULL; } memcpy(file_dirname, path, path_len - fragment_len); file_dirname[path_len - fragment_len] = '\0'; file_basename = php_basename(path, path_len - fragment_len, NULL, 0); fragment++; if (ZIP_OPENBASEDIR_CHECKPATH(file_dirname)) { zend_string_release_ex(file_basename, 0); return NULL; } za = zip_open(file_dirname, ZIP_CREATE, &err); if (za) { zval *tmpzval; if (context && NULL != (tmpzval = php_stream_context_get_option(context, "zip", "password"))) { if (Z_TYPE_P(tmpzval) != IS_STRING || zip_set_default_password(za, Z_STRVAL_P(tmpzval))) { php_error_docref(NULL, E_WARNING, "Can't set zip password"); } } zf = zip_fopen(za, fragment, 0); if (zf) { self = emalloc(sizeof(*self)); self->za = za; self->zf = zf; self->stream = NULL; self->cursor = 0; #if LIBZIP_ATLEAST(1,9,1) if (zip_file_is_seekable(zf) > 0) { stream = php_stream_alloc(&php_stream_zipio_seek_ops, self, NULL, mode); } else #endif { stream = php_stream_alloc(&php_stream_zipio_ops, self, NULL, mode); } if (opened_path) { *opened_path = zend_string_init(path, strlen(path), 0); } } else { zip_close(za); } } zend_string_release_ex(file_basename, 0); if (!stream) { return NULL; } else { return stream; } } /* }}} */ static const php_stream_wrapper_ops zip_stream_wops = { php_stream_zip_opener, NULL, /* close */ NULL, /* fstat */ NULL, /* stat */ NULL, /* opendir */ "zip wrapper", NULL, /* unlink */ NULL, /* rename */ NULL, /* mkdir */ NULL, /* rmdir */ NULL /* metadata */ }; const php_stream_wrapper php_stream_zip_wrapper = { &zip_stream_wops, NULL, 0 /* is_url */ }; #endif /* HAVE_ZIP */
8,951
21.778626
118
c
php-src
php-src-master/ext/zlib/zlib_arginfo.h
/* This is a generated file, edit the .stub.php file instead. * Stub hash: 3660ad3239f93c84b6909c36ddfcc92dd0773c70 */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_ob_gzhandler, 0, 2, MAY_BE_STRING|MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, data, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, flags, IS_LONG, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_zlib_get_coding_type, 0, 0, MAY_BE_STRING|MAY_BE_FALSE) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_gzfile, 0, 1, MAY_BE_ARRAY|MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, use_include_path, IS_LONG, 0, "0") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_gzopen, 0, 0, 2) ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, mode, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, use_include_path, IS_LONG, 0, "0") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_readgzfile, 0, 1, MAY_BE_LONG|MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, use_include_path, IS_LONG, 0, "0") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_zlib_encode, 0, 2, MAY_BE_STRING|MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, data, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, encoding, IS_LONG, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, level, IS_LONG, 0, "-1") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_zlib_decode, 0, 1, MAY_BE_STRING|MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, data, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, max_length, IS_LONG, 0, "0") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_gzdeflate, 0, 1, MAY_BE_STRING|MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, data, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, level, IS_LONG, 0, "-1") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, encoding, IS_LONG, 0, "ZLIB_ENCODING_RAW") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_gzencode, 0, 1, MAY_BE_STRING|MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, data, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, level, IS_LONG, 0, "-1") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, encoding, IS_LONG, 0, "ZLIB_ENCODING_GZIP") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_gzcompress, 0, 1, MAY_BE_STRING|MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, data, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, level, IS_LONG, 0, "-1") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, encoding, IS_LONG, 0, "ZLIB_ENCODING_DEFLATE") ZEND_END_ARG_INFO() #define arginfo_gzinflate arginfo_zlib_decode #define arginfo_gzdecode arginfo_zlib_decode #define arginfo_gzuncompress arginfo_zlib_decode ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_gzwrite, 0, 2, MAY_BE_LONG|MAY_BE_FALSE) ZEND_ARG_INFO(0, stream) ZEND_ARG_TYPE_INFO(0, data, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, length, IS_LONG, 1, "null") ZEND_END_ARG_INFO() #define arginfo_gzputs arginfo_gzwrite ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_gzrewind, 0, 1, _IS_BOOL, 0) ZEND_ARG_INFO(0, stream) ZEND_END_ARG_INFO() #define arginfo_gzclose arginfo_gzrewind #define arginfo_gzeof arginfo_gzrewind ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_gzgetc, 0, 1, MAY_BE_STRING|MAY_BE_FALSE) ZEND_ARG_INFO(0, stream) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_gzpassthru, 0, 1, IS_LONG, 0) ZEND_ARG_INFO(0, stream) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_gzseek, 0, 2, IS_LONG, 0) ZEND_ARG_INFO(0, stream) ZEND_ARG_TYPE_INFO(0, offset, IS_LONG, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, whence, IS_LONG, 0, "SEEK_SET") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_gztell, 0, 1, MAY_BE_LONG|MAY_BE_FALSE) ZEND_ARG_INFO(0, stream) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_gzread, 0, 2, MAY_BE_STRING|MAY_BE_FALSE) ZEND_ARG_INFO(0, stream) ZEND_ARG_TYPE_INFO(0, length, IS_LONG, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_gzgets, 0, 1, MAY_BE_STRING|MAY_BE_FALSE) ZEND_ARG_INFO(0, stream) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, length, IS_LONG, 1, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_deflate_init, 0, 1, DeflateContext, MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, encoding, IS_LONG, 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_deflate_add, 0, 2, MAY_BE_STRING|MAY_BE_FALSE) ZEND_ARG_OBJ_INFO(0, context, DeflateContext, 0) ZEND_ARG_TYPE_INFO(0, data, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flush_mode, IS_LONG, 0, "ZLIB_SYNC_FLUSH") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_inflate_init, 0, 1, InflateContext, MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, encoding, IS_LONG, 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_inflate_add, 0, 2, MAY_BE_STRING|MAY_BE_FALSE) ZEND_ARG_OBJ_INFO(0, context, InflateContext, 0) ZEND_ARG_TYPE_INFO(0, data, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flush_mode, IS_LONG, 0, "ZLIB_SYNC_FLUSH") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_inflate_get_status, 0, 1, IS_LONG, 0) ZEND_ARG_OBJ_INFO(0, context, InflateContext, 0) ZEND_END_ARG_INFO() #define arginfo_inflate_get_read_len arginfo_inflate_get_status ZEND_FUNCTION(ob_gzhandler); ZEND_FUNCTION(zlib_get_coding_type); ZEND_FUNCTION(gzfile); ZEND_FUNCTION(gzopen); ZEND_FUNCTION(readgzfile); ZEND_FUNCTION(zlib_encode); ZEND_FUNCTION(zlib_decode); ZEND_FUNCTION(gzdeflate); ZEND_FUNCTION(gzencode); ZEND_FUNCTION(gzcompress); ZEND_FUNCTION(gzinflate); ZEND_FUNCTION(gzdecode); ZEND_FUNCTION(gzuncompress); ZEND_FUNCTION(fwrite); ZEND_FUNCTION(rewind); ZEND_FUNCTION(fclose); ZEND_FUNCTION(feof); ZEND_FUNCTION(fgetc); ZEND_FUNCTION(fpassthru); ZEND_FUNCTION(fseek); ZEND_FUNCTION(ftell); ZEND_FUNCTION(fread); ZEND_FUNCTION(fgets); ZEND_FUNCTION(deflate_init); ZEND_FUNCTION(deflate_add); ZEND_FUNCTION(inflate_init); ZEND_FUNCTION(inflate_add); ZEND_FUNCTION(inflate_get_status); ZEND_FUNCTION(inflate_get_read_len); static const zend_function_entry ext_functions[] = { ZEND_FE(ob_gzhandler, arginfo_ob_gzhandler) ZEND_FE(zlib_get_coding_type, arginfo_zlib_get_coding_type) ZEND_FE(gzfile, arginfo_gzfile) ZEND_FE(gzopen, arginfo_gzopen) ZEND_FE(readgzfile, arginfo_readgzfile) ZEND_FE(zlib_encode, arginfo_zlib_encode) ZEND_FE(zlib_decode, arginfo_zlib_decode) ZEND_FE(gzdeflate, arginfo_gzdeflate) ZEND_FE(gzencode, arginfo_gzencode) ZEND_FE(gzcompress, arginfo_gzcompress) ZEND_FE(gzinflate, arginfo_gzinflate) ZEND_FE(gzdecode, arginfo_gzdecode) ZEND_FE(gzuncompress, arginfo_gzuncompress) ZEND_FALIAS(gzwrite, fwrite, arginfo_gzwrite) ZEND_FALIAS(gzputs, fwrite, arginfo_gzputs) ZEND_FALIAS(gzrewind, rewind, arginfo_gzrewind) ZEND_FALIAS(gzclose, fclose, arginfo_gzclose) ZEND_FALIAS(gzeof, feof, arginfo_gzeof) ZEND_FALIAS(gzgetc, fgetc, arginfo_gzgetc) ZEND_FALIAS(gzpassthru, fpassthru, arginfo_gzpassthru) ZEND_FALIAS(gzseek, fseek, arginfo_gzseek) ZEND_FALIAS(gztell, ftell, arginfo_gztell) ZEND_FALIAS(gzread, fread, arginfo_gzread) ZEND_FALIAS(gzgets, fgets, arginfo_gzgets) ZEND_FE(deflate_init, arginfo_deflate_init) ZEND_FE(deflate_add, arginfo_deflate_add) ZEND_FE(inflate_init, arginfo_inflate_init) ZEND_FE(inflate_add, arginfo_inflate_add) ZEND_FE(inflate_get_status, arginfo_inflate_get_status) ZEND_FE(inflate_get_read_len, arginfo_inflate_get_read_len) ZEND_FE_END }; static const zend_function_entry class_InflateContext_methods[] = { ZEND_FE_END }; static const zend_function_entry class_DeflateContext_methods[] = { ZEND_FE_END }; static void register_zlib_symbols(int module_number) { REGISTER_LONG_CONSTANT("FORCE_GZIP", PHP_ZLIB_ENCODING_GZIP, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("FORCE_DEFLATE", PHP_ZLIB_ENCODING_DEFLATE, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("ZLIB_ENCODING_RAW", PHP_ZLIB_ENCODING_RAW, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("ZLIB_ENCODING_GZIP", PHP_ZLIB_ENCODING_GZIP, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("ZLIB_ENCODING_DEFLATE", PHP_ZLIB_ENCODING_DEFLATE, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("ZLIB_NO_FLUSH", Z_NO_FLUSH, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("ZLIB_PARTIAL_FLUSH", Z_PARTIAL_FLUSH, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("ZLIB_SYNC_FLUSH", Z_SYNC_FLUSH, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("ZLIB_FULL_FLUSH", Z_FULL_FLUSH, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("ZLIB_BLOCK", Z_BLOCK, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("ZLIB_FINISH", Z_FINISH, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("ZLIB_FILTERED", Z_FILTERED, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("ZLIB_HUFFMAN_ONLY", Z_HUFFMAN_ONLY, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("ZLIB_RLE", Z_RLE, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("ZLIB_FIXED", Z_FIXED, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("ZLIB_DEFAULT_STRATEGY", Z_DEFAULT_STRATEGY, CONST_PERSISTENT); REGISTER_STRING_CONSTANT("ZLIB_VERSION", ZLIB_VERSION, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("ZLIB_VERNUM", ZLIB_VERNUM, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("ZLIB_OK", Z_OK, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("ZLIB_STREAM_END", Z_STREAM_END, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("ZLIB_NEED_DICT", Z_NEED_DICT, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("ZLIB_ERRNO", Z_ERRNO, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("ZLIB_STREAM_ERROR", Z_STREAM_ERROR, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("ZLIB_DATA_ERROR", Z_DATA_ERROR, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("ZLIB_MEM_ERROR", Z_MEM_ERROR, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("ZLIB_BUF_ERROR", Z_BUF_ERROR, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("ZLIB_VERSION_ERROR", Z_VERSION_ERROR, CONST_PERSISTENT); } static zend_class_entry *register_class_InflateContext(void) { zend_class_entry ce, *class_entry; INIT_CLASS_ENTRY(ce, "InflateContext", class_InflateContext_methods); class_entry = zend_register_internal_class_ex(&ce, NULL); class_entry->ce_flags |= ZEND_ACC_FINAL|ZEND_ACC_NO_DYNAMIC_PROPERTIES|ZEND_ACC_NOT_SERIALIZABLE; return class_entry; } static zend_class_entry *register_class_DeflateContext(void) { zend_class_entry ce, *class_entry; INIT_CLASS_ENTRY(ce, "DeflateContext", class_DeflateContext_methods); class_entry = zend_register_internal_class_ex(&ce, NULL); class_entry->ce_flags |= ZEND_ACC_FINAL|ZEND_ACC_NO_DYNAMIC_PROPERTIES|ZEND_ACC_NOT_SERIALIZABLE; return class_entry; }
10,700
39.688213
103
h
php-src
php-src-master/ext/zlib/zlib_filter.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: Sara Golemon ([email protected]) | +----------------------------------------------------------------------+ */ #include "php.h" #include "php_zlib.h" /* {{{ data structure */ /* Passed as opaque in malloc callbacks */ typedef struct _php_zlib_filter_data { z_stream strm; unsigned char *inbuf; size_t inbuf_len; unsigned char *outbuf; size_t outbuf_len; int persistent; bool finished; /* for zlib.deflate: signals that no flush is pending */ } php_zlib_filter_data; /* }}} */ /* {{{ Memory management wrappers */ static voidpf php_zlib_alloc(voidpf opaque, uInt items, uInt size) { return (voidpf)safe_pemalloc(items, size, 0, ((php_zlib_filter_data*)opaque)->persistent); } static void php_zlib_free(voidpf opaque, voidpf address) { pefree((void*)address, ((php_zlib_filter_data*)opaque)->persistent); } /* }}} */ /* {{{ zlib.inflate filter implementation */ static php_stream_filter_status_t php_zlib_inflate_filter( php_stream *stream, php_stream_filter *thisfilter, php_stream_bucket_brigade *buckets_in, php_stream_bucket_brigade *buckets_out, size_t *bytes_consumed, int flags ) { php_zlib_filter_data *data; php_stream_bucket *bucket; size_t consumed = 0; int status; php_stream_filter_status_t exit_status = PSFS_FEED_ME; if (!thisfilter || !Z_PTR(thisfilter->abstract)) { /* Should never happen */ return PSFS_ERR_FATAL; } data = (php_zlib_filter_data *)(Z_PTR(thisfilter->abstract)); while (buckets_in->head) { size_t bin = 0, desired; bucket = php_stream_bucket_make_writeable(buckets_in->head); while (bin < (unsigned int) bucket->buflen && !data->finished) { desired = bucket->buflen - bin; if (desired > data->inbuf_len) { desired = data->inbuf_len; } memcpy(data->strm.next_in, bucket->buf + bin, desired); data->strm.avail_in = desired; status = inflate(&(data->strm), flags & PSFS_FLAG_FLUSH_CLOSE ? Z_FINISH : Z_SYNC_FLUSH); if (status == Z_STREAM_END) { inflateEnd(&(data->strm)); data->finished = '\1'; exit_status = PSFS_PASS_ON; } else if (status != Z_OK && status != Z_BUF_ERROR) { /* Something bad happened */ php_error_docref(NULL, E_NOTICE, "zlib: %s", zError(status)); php_stream_bucket_delref(bucket); /* reset these because despite the error the filter may be used again */ data->strm.next_in = data->inbuf; data->strm.avail_in = 0; return PSFS_ERR_FATAL; } desired -= data->strm.avail_in; /* desired becomes what we consumed this round through */ data->strm.next_in = data->inbuf; data->strm.avail_in = 0; bin += desired; if (data->strm.avail_out < data->outbuf_len) { php_stream_bucket *out_bucket; size_t bucketlen = data->outbuf_len - data->strm.avail_out; out_bucket = php_stream_bucket_new( stream, estrndup((char *) data->outbuf, bucketlen), bucketlen, 1, 0); php_stream_bucket_append(buckets_out, out_bucket); data->strm.avail_out = data->outbuf_len; data->strm.next_out = data->outbuf; exit_status = PSFS_PASS_ON; } } consumed += bucket->buflen; php_stream_bucket_delref(bucket); } if (!data->finished && flags & PSFS_FLAG_FLUSH_CLOSE) { /* Spit it out! */ status = Z_OK; while (status == Z_OK) { status = inflate(&(data->strm), Z_FINISH); if (data->strm.avail_out < data->outbuf_len) { size_t bucketlen = data->outbuf_len - data->strm.avail_out; bucket = php_stream_bucket_new( stream, estrndup((char *) data->outbuf, bucketlen), bucketlen, 1, 0); php_stream_bucket_append(buckets_out, bucket); data->strm.avail_out = data->outbuf_len; data->strm.next_out = data->outbuf; exit_status = PSFS_PASS_ON; } } } if (bytes_consumed) { *bytes_consumed = consumed; } return exit_status; } static void php_zlib_inflate_dtor(php_stream_filter *thisfilter) { if (thisfilter && Z_PTR(thisfilter->abstract)) { php_zlib_filter_data *data = Z_PTR(thisfilter->abstract); if (!data->finished) { inflateEnd(&(data->strm)); } pefree(data->inbuf, data->persistent); pefree(data->outbuf, data->persistent); pefree(data, data->persistent); } } static const php_stream_filter_ops php_zlib_inflate_ops = { php_zlib_inflate_filter, php_zlib_inflate_dtor, "zlib.inflate" }; /* }}} */ /* {{{ zlib.deflate filter implementation */ static php_stream_filter_status_t php_zlib_deflate_filter( php_stream *stream, php_stream_filter *thisfilter, php_stream_bucket_brigade *buckets_in, php_stream_bucket_brigade *buckets_out, size_t *bytes_consumed, int flags ) { php_zlib_filter_data *data; php_stream_bucket *bucket; size_t consumed = 0; int status; php_stream_filter_status_t exit_status = PSFS_FEED_ME; if (!thisfilter || !Z_PTR(thisfilter->abstract)) { /* Should never happen */ return PSFS_ERR_FATAL; } data = (php_zlib_filter_data *)(Z_PTR(thisfilter->abstract)); while (buckets_in->head) { size_t bin = 0, desired; bucket = buckets_in->head; bucket = php_stream_bucket_make_writeable(bucket); while (bin < (unsigned int) bucket->buflen) { int flush_mode; desired = bucket->buflen - bin; if (desired > data->inbuf_len) { desired = data->inbuf_len; } memcpy(data->strm.next_in, bucket->buf + bin, desired); data->strm.avail_in = desired; flush_mode = flags & PSFS_FLAG_FLUSH_CLOSE ? Z_FULL_FLUSH : (flags & PSFS_FLAG_FLUSH_INC ? Z_SYNC_FLUSH : Z_NO_FLUSH); data->finished = flush_mode != Z_NO_FLUSH; status = deflate(&(data->strm), flush_mode); if (status != Z_OK) { /* Something bad happened */ php_stream_bucket_delref(bucket); return PSFS_ERR_FATAL; } desired -= data->strm.avail_in; /* desired becomes what we consumed this round through */ data->strm.next_in = data->inbuf; data->strm.avail_in = 0; bin += desired; if (data->strm.avail_out < data->outbuf_len) { php_stream_bucket *out_bucket; size_t bucketlen = data->outbuf_len - data->strm.avail_out; out_bucket = php_stream_bucket_new( stream, estrndup((char *) data->outbuf, bucketlen), bucketlen, 1, 0); php_stream_bucket_append(buckets_out, out_bucket); data->strm.avail_out = data->outbuf_len; data->strm.next_out = data->outbuf; exit_status = PSFS_PASS_ON; } } consumed += bucket->buflen; php_stream_bucket_delref(bucket); } if (flags & PSFS_FLAG_FLUSH_CLOSE || ((flags & PSFS_FLAG_FLUSH_INC) && !data->finished)) { /* Spit it out! */ status = Z_OK; while (status == Z_OK) { status = deflate(&(data->strm), (flags & PSFS_FLAG_FLUSH_CLOSE ? Z_FINISH : Z_SYNC_FLUSH)); data->finished = 1; if (data->strm.avail_out < data->outbuf_len) { size_t bucketlen = data->outbuf_len - data->strm.avail_out; bucket = php_stream_bucket_new( stream, estrndup((char *) data->outbuf, bucketlen), bucketlen, 1, 0); php_stream_bucket_append(buckets_out, bucket); data->strm.avail_out = data->outbuf_len; data->strm.next_out = data->outbuf; exit_status = PSFS_PASS_ON; } } } if (bytes_consumed) { *bytes_consumed = consumed; } return exit_status; } static void php_zlib_deflate_dtor(php_stream_filter *thisfilter) { if (thisfilter && Z_PTR(thisfilter->abstract)) { php_zlib_filter_data *data = Z_PTR(thisfilter->abstract); deflateEnd(&(data->strm)); pefree(data->inbuf, data->persistent); pefree(data->outbuf, data->persistent); pefree(data, data->persistent); } } static const php_stream_filter_ops php_zlib_deflate_ops = { php_zlib_deflate_filter, php_zlib_deflate_dtor, "zlib.deflate" }; /* }}} */ /* {{{ zlib.* common factory */ static php_stream_filter *php_zlib_filter_create(const char *filtername, zval *filterparams, uint8_t persistent) { const php_stream_filter_ops *fops = NULL; php_zlib_filter_data *data; int status; /* Create this filter */ data = pecalloc(1, sizeof(php_zlib_filter_data), persistent); if (!data) { php_error_docref(NULL, E_WARNING, "Failed allocating %zd bytes", sizeof(php_zlib_filter_data)); return NULL; } /* Circular reference */ data->strm.opaque = (voidpf) data; data->strm.zalloc = (alloc_func) php_zlib_alloc; data->strm.zfree = (free_func) php_zlib_free; data->strm.avail_out = data->outbuf_len = data->inbuf_len = 0x8000; data->strm.next_in = data->inbuf = (Bytef *) pemalloc(data->inbuf_len, persistent); if (!data->inbuf) { php_error_docref(NULL, E_WARNING, "Failed allocating %zd bytes", data->inbuf_len); pefree(data, persistent); return NULL; } data->strm.avail_in = 0; data->strm.next_out = data->outbuf = (Bytef *) pemalloc(data->outbuf_len, persistent); if (!data->outbuf) { php_error_docref(NULL, E_WARNING, "Failed allocating %zd bytes", data->outbuf_len); pefree(data->inbuf, persistent); pefree(data, persistent); return NULL; } data->strm.data_type = Z_ASCII; if (strcasecmp(filtername, "zlib.inflate") == 0) { int windowBits = -MAX_WBITS; if (filterparams) { zval *tmpzval; if ((Z_TYPE_P(filterparams) == IS_ARRAY || Z_TYPE_P(filterparams) == IS_OBJECT) && (tmpzval = zend_hash_str_find(HASH_OF(filterparams), "window", sizeof("window") - 1))) { /* log-2 base of history window (9 - 15) */ zend_long tmp = zval_get_long(tmpzval); if (tmp < -MAX_WBITS || tmp > MAX_WBITS + 32) { php_error_docref(NULL, E_WARNING, "Invalid parameter given for window size (" ZEND_LONG_FMT ")", tmp); } else { windowBits = tmp; } } } /* RFC 1951 Inflate */ data->finished = '\0'; status = inflateInit2(&(data->strm), windowBits); fops = &php_zlib_inflate_ops; } else if (strcasecmp(filtername, "zlib.deflate") == 0) { /* RFC 1951 Deflate */ int level = Z_DEFAULT_COMPRESSION; int windowBits = -MAX_WBITS; int memLevel = MAX_MEM_LEVEL; if (filterparams) { zval *tmpzval; zend_long tmp; /* filterparams can either be a scalar value to indicate compression level (shortcut method) Or can be a hash containing one or more of 'window', 'memory', and/or 'level' members. */ switch (Z_TYPE_P(filterparams)) { case IS_ARRAY: case IS_OBJECT: if ((tmpzval = zend_hash_str_find(HASH_OF(filterparams), "memory", sizeof("memory") -1))) { /* Memory Level (1 - 9) */ tmp = zval_get_long(tmpzval); if (tmp < 1 || tmp > MAX_MEM_LEVEL) { php_error_docref(NULL, E_WARNING, "Invalid parameter given for memory level (" ZEND_LONG_FMT ")", tmp); } else { memLevel = tmp; } } if ((tmpzval = zend_hash_str_find(HASH_OF(filterparams), "window", sizeof("window") - 1))) { /* log-2 base of history window (9 - 15) */ tmp = zval_get_long(tmpzval); if (tmp < -MAX_WBITS || tmp > MAX_WBITS + 16) { php_error_docref(NULL, E_WARNING, "Invalid parameter given for window size (" ZEND_LONG_FMT ")", tmp); } else { windowBits = tmp; } } if ((tmpzval = zend_hash_str_find(HASH_OF(filterparams), "level", sizeof("level") - 1))) { tmp = zval_get_long(tmpzval); /* Pseudo pass through to catch level validating code */ goto factory_setlevel; } break; case IS_STRING: case IS_DOUBLE: case IS_LONG: tmp = zval_get_long(filterparams); factory_setlevel: /* Set compression level within reason (-1 == default, 0 == none, 1-9 == least to most compression */ if (tmp < -1 || tmp > 9) { php_error_docref(NULL, E_WARNING, "Invalid compression level specified. (" ZEND_LONG_FMT ")", tmp); } else { level = tmp; } break; default: php_error_docref(NULL, E_WARNING, "Invalid filter parameter, ignored"); } } status = deflateInit2(&(data->strm), level, Z_DEFLATED, windowBits, memLevel, 0); data->finished = 1; fops = &php_zlib_deflate_ops; } else { status = Z_DATA_ERROR; } if (status != Z_OK) { /* Unspecified (probably strm) error, let stream-filter error do its own whining */ pefree(data->strm.next_in, persistent); pefree(data->strm.next_out, persistent); pefree(data, persistent); return NULL; } return php_stream_filter_alloc(fops, data, persistent); } const php_stream_filter_factory php_zlib_filter_factory = { php_zlib_filter_create }; /* }}} */
13,056
29.867612
121
c
php-src
php-src-master/ext/zlib/zlib_fopen_wrapper.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: Wez Furlong <[email protected]>, based on work by: | | Hartmut Holzgraefe <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef _GNU_SOURCE # define _GNU_SOURCE #endif #include "php.h" #include "php_zlib.h" #include "fopen_wrappers.h" #include "main/php_network.h" struct php_gz_stream_data_t { gzFile gz_file; php_stream *stream; }; static ssize_t php_gziop_read(php_stream *stream, char *buf, size_t count) { struct php_gz_stream_data_t *self = (struct php_gz_stream_data_t *) stream->abstract; int read; /* XXX this needs to be looped for the case count > UINT_MAX */ read = gzread(self->gz_file, buf, count); if (gzeof(self->gz_file)) { stream->eof = 1; } return read; } static ssize_t php_gziop_write(php_stream *stream, const char *buf, size_t count) { struct php_gz_stream_data_t *self = (struct php_gz_stream_data_t *) stream->abstract; /* XXX this needs to be looped for the case count > UINT_MAX */ return gzwrite(self->gz_file, (char *) buf, count); } static int php_gziop_seek(php_stream *stream, zend_off_t offset, int whence, zend_off_t *newoffs) { struct php_gz_stream_data_t *self = (struct php_gz_stream_data_t *) stream->abstract; assert(self != NULL); if (whence == SEEK_END) { php_error_docref(NULL, E_WARNING, "SEEK_END is not supported"); return -1; } *newoffs = gzseek(self->gz_file, offset, whence); return (*newoffs < 0) ? -1 : 0; } static int php_gziop_close(php_stream *stream, int close_handle) { struct php_gz_stream_data_t *self = (struct php_gz_stream_data_t *) stream->abstract; int ret = EOF; if (close_handle) { if (self->gz_file) { ret = gzclose(self->gz_file); self->gz_file = NULL; } if (self->stream) { php_stream_close(self->stream); self->stream = NULL; } } efree(self); return ret; } static int php_gziop_flush(php_stream *stream) { struct php_gz_stream_data_t *self = (struct php_gz_stream_data_t *) stream->abstract; return gzflush(self->gz_file, Z_SYNC_FLUSH); } const php_stream_ops php_stream_gzio_ops = { php_gziop_write, php_gziop_read, php_gziop_close, php_gziop_flush, "ZLIB", php_gziop_seek, NULL, /* cast */ NULL, /* stat */ NULL /* set_option */ }; php_stream *php_stream_gzopen(php_stream_wrapper *wrapper, const char *path, const char *mode, int options, zend_string **opened_path, php_stream_context *context STREAMS_DC) { struct php_gz_stream_data_t *self; php_stream *stream = NULL, *innerstream = NULL; /* sanity check the stream: it can be either read-only or write-only */ if (strchr(mode, '+')) { if (options & REPORT_ERRORS) { php_error_docref(NULL, E_WARNING, "Cannot open a zlib stream for reading and writing at the same time!"); } return NULL; } if (strncasecmp("compress.zlib://", path, 16) == 0) { path += 16; } else if (strncasecmp("zlib:", path, 5) == 0) { path += 5; } innerstream = php_stream_open_wrapper_ex(path, mode, STREAM_MUST_SEEK | options | STREAM_WILL_CAST, opened_path, context); if (innerstream) { php_socket_t fd; if (SUCCESS == php_stream_cast(innerstream, PHP_STREAM_AS_FD, (void **) &fd, REPORT_ERRORS)) { self = emalloc(sizeof(*self)); self->stream = innerstream; self->gz_file = gzdopen(dup(fd), mode); if (self->gz_file) { zval *zlevel = context ? php_stream_context_get_option(context, "zlib", "level") : NULL; if (zlevel && (Z_OK != gzsetparams(self->gz_file, zval_get_long(zlevel), Z_DEFAULT_STRATEGY))) { php_error(E_WARNING, "failed setting compression level"); } stream = php_stream_alloc_rel(&php_stream_gzio_ops, self, 0, mode); if (stream) { stream->flags |= PHP_STREAM_FLAG_NO_BUFFER; return stream; } gzclose(self->gz_file); } efree(self); if (options & REPORT_ERRORS) { php_error_docref(NULL, E_WARNING, "gzopen failed"); } } php_stream_close(innerstream); } return NULL; } static const php_stream_wrapper_ops gzip_stream_wops = { php_stream_gzopen, NULL, /* close */ NULL, /* stat */ NULL, /* stat_url */ NULL, /* opendir */ "ZLIB", NULL, /* unlink */ NULL, /* rename */ NULL, /* mkdir */ NULL, /* rmdir */ NULL }; const php_stream_wrapper php_stream_gzip_wrapper = { &gzip_stream_wops, NULL, 0, /* is_url */ };
5,189
27.206522
123
c
php-src
php-src-master/main/explicit_bzero.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: | +----------------------------------------------------------------------+ */ #include "php.h" #ifndef HAVE_EXPLICIT_BZERO /* $OpenBSD: explicit_bzero.c,v 1.4 2015/08/31 02:53:57 guenther Exp $ */ /* * Public domain. * Written by Matthew Dempsky. */ #include <string.h> PHPAPI void php_explicit_bzero(void *dst, size_t siz) { #ifdef HAVE_EXPLICIT_MEMSET explicit_memset(dst, 0, siz); #elif defined(PHP_WIN32) RtlSecureZeroMemory(dst, siz); #elif defined(__GNUC__) memset(dst, 0, siz); asm __volatile__("" :: "r"(dst) : "memory"); #else size_t i = 0; volatile unsigned char *buf = (volatile unsigned char *)dst; for (; i < siz; i ++) buf[i] = 0; #endif } #endif
1,585
32.744681
74
c
php-src
php-src-master/main/fastcgi.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: Dmitry Stogov <[email protected]> | +----------------------------------------------------------------------+ */ /* FastCGI protocol */ #define FCGI_VERSION_1 1 #define FCGI_MAX_LENGTH 0xffff #define FCGI_KEEP_CONN 1 /* this is near the perfect hash function for most useful FastCGI variables * which combines efficiency and minimal hash collisions */ #define FCGI_HASH_FUNC(var, var_len) \ (UNEXPECTED(var_len < 3) ? (unsigned int)var_len : \ (((unsigned int)var[3]) << 2) + \ (((unsigned int)var[var_len-2]) << 4) + \ (((unsigned int)var[var_len-1]) << 2) + \ var_len) #define FCGI_GETENV(request, name) \ fcgi_quick_getenv(request, name, sizeof(name)-1, FCGI_HASH_FUNC(name, sizeof(name)-1)) #define FCGI_PUTENV(request, name, value) \ fcgi_quick_putenv(request, name, sizeof(name)-1, FCGI_HASH_FUNC(name, sizeof(name)-1), value) typedef enum _fcgi_role { FCGI_RESPONDER = 1, FCGI_AUTHORIZER = 2, FCGI_FILTER = 3 } fcgi_role; enum { FCGI_DEBUG = 1, FCGI_NOTICE = 2, FCGI_WARNING = 3, FCGI_ERROR = 4, FCGI_ALERT = 5, }; typedef enum _fcgi_request_type { FCGI_BEGIN_REQUEST = 1, /* [in] */ FCGI_ABORT_REQUEST = 2, /* [in] (not supported) */ FCGI_END_REQUEST = 3, /* [out] */ FCGI_PARAMS = 4, /* [in] environment variables */ FCGI_STDIN = 5, /* [in] post data */ FCGI_STDOUT = 6, /* [out] response */ FCGI_STDERR = 7, /* [out] errors */ FCGI_DATA = 8, /* [in] filter data (not supported) */ FCGI_GET_VALUES = 9, /* [in] */ FCGI_GET_VALUES_RESULT = 10 /* [out] */ } fcgi_request_type; typedef enum _fcgi_protocol_status { FCGI_REQUEST_COMPLETE = 0, FCGI_CANT_MPX_CONN = 1, FCGI_OVERLOADED = 2, FCGI_UNKNOWN_ROLE = 3 } dcgi_protocol_status; /* FastCGI client API */ typedef void (*fcgi_apply_func)(const char *var, unsigned int var_len, char *val, unsigned int val_len, void *arg); #define FCGI_HASH_TABLE_SIZE 128 #define FCGI_HASH_TABLE_MASK (FCGI_HASH_TABLE_SIZE - 1) #define FCGI_HASH_SEG_SIZE 4096 typedef struct _fcgi_request fcgi_request; int fcgi_init(void); void fcgi_shutdown(void); int fcgi_is_fastcgi(void); int fcgi_is_closed(fcgi_request *req); void fcgi_close(fcgi_request *req, int force, int destroy); int fcgi_in_shutdown(void); void fcgi_terminate(void); int fcgi_listen(const char *path, int backlog); fcgi_request* fcgi_init_request(int listen_socket, void(*on_accept)(void), void(*on_read)(void), void(*on_close)(void)); void fcgi_destroy_request(fcgi_request *req); void fcgi_set_allowed_clients(char *ip); int fcgi_accept_request(fcgi_request *req); int fcgi_finish_request(fcgi_request *req, int force_close); const char *fcgi_get_last_client_ip(void); void fcgi_set_in_shutdown(int new_value); void fcgi_request_set_keep(fcgi_request *req, int new_value); #ifndef HAVE_ATTRIBUTE_WEAK typedef void (*fcgi_logger)(int type, const char *fmt, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3); void fcgi_set_logger(fcgi_logger lg); #endif int fcgi_has_env(fcgi_request *req); char* fcgi_getenv(fcgi_request *req, const char* var, int var_len); char* fcgi_putenv(fcgi_request *req, char* var, int var_len, char* val); char* fcgi_quick_getenv(fcgi_request *req, const char* var, int var_len, unsigned int hash_value); char* fcgi_quick_putenv(fcgi_request *req, char* var, int var_len, unsigned int hash_value, char* val); void fcgi_loadenv(fcgi_request *req, fcgi_apply_func load_func, zval *array); int fcgi_read(fcgi_request *req, char *str, int len); int fcgi_write(fcgi_request *req, fcgi_request_type type, const char *str, int len); int fcgi_flush(fcgi_request *req, int end); int fcgi_end(fcgi_request *req); #ifdef PHP_WIN32 void fcgi_impersonate(void); #endif void fcgi_set_mgmt_var(const char * name, size_t name_len, const char * value, size_t value_len); void fcgi_free_mgmt_var_cb(zval *zv);
4,892
37.527559
120
h
php-src
php-src-master/main/http_status_codes.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: Andrea Faulds <[email protected]> | +----------------------------------------------------------------------+ */ #ifndef HTTP_STATUS_CODES_H #define HTTP_STATUS_CODES_H typedef struct _http_response_status_code_pair { const int code; const char *str; } http_response_status_code_pair; static const http_response_status_code_pair http_status_map[] = { { 100, "Continue" }, { 101, "Switching Protocols" }, { 200, "OK" }, { 201, "Created" }, { 202, "Accepted" }, { 203, "Non-Authoritative Information" }, { 204, "No Content" }, { 205, "Reset Content" }, { 206, "Partial Content" }, { 300, "Multiple Choices" }, { 301, "Moved Permanently" }, { 302, "Found" }, { 303, "See Other" }, { 304, "Not Modified" }, { 305, "Use Proxy" }, { 307, "Temporary Redirect" }, { 308, "Permanent Redirect" }, { 400, "Bad Request" }, { 401, "Unauthorized" }, { 402, "Payment Required" }, { 403, "Forbidden" }, { 404, "Not Found" }, { 405, "Method Not Allowed" }, { 406, "Not Acceptable" }, { 407, "Proxy Authentication Required" }, { 408, "Request Timeout" }, { 409, "Conflict" }, { 410, "Gone" }, { 411, "Length Required" }, { 412, "Precondition Failed" }, { 413, "Request Entity Too Large" }, { 414, "Request-URI Too Long" }, { 415, "Unsupported Media Type" }, { 416, "Requested Range Not Satisfiable" }, { 417, "Expectation Failed" }, { 426, "Upgrade Required" }, { 428, "Precondition Required" }, { 429, "Too Many Requests" }, { 431, "Request Header Fields Too Large" }, { 451, "Unavailable For Legal Reasons"}, { 500, "Internal Server Error" }, { 501, "Not Implemented" }, { 502, "Bad Gateway" }, { 503, "Service Unavailable" }, { 504, "Gateway Timeout" }, { 505, "HTTP Version Not Supported" }, { 506, "Variant Also Negotiates" }, { 511, "Network Authentication Required" }, /* to allow search with while() loop */ { 0, NULL } }; static const size_t http_status_map_len = (sizeof(http_status_map) / sizeof(http_response_status_code_pair)) - 1; #endif /* HTTP_STATUS_CODES_H */
2,898
34.790123
113
h
php-src
php-src-master/main/internal_functions_win32.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: Andi Gutmans <[email protected]> | | Zeev Suraski <[email protected]> | +----------------------------------------------------------------------+ */ /* {{{ includes */ #include "php.h" #include "php_main.h" #include "zend_modules.h" #include "zend_compile.h" #include <stdarg.h> #include <stdlib.h> #include <stdio.h> #include "ext/standard/dl.h" #include "ext/standard/file.h" #include "ext/standard/fsock.h" #include "ext/standard/head.h" #include "ext/standard/pack.h" #include "ext/standard/php_browscap.h" #include "ext/standard/php_crypt.h" #include "ext/standard/php_dir.h" #include "ext/standard/php_filestat.h" #include "ext/standard/php_mail.h" #include "ext/standard/php_ext_syslog.h" #include "ext/standard/php_standard.h" #include "ext/standard/php_array.h" #include "ext/standard/php_assert.h" #include "ext/reflection/php_reflection.h" #include "ext/random/php_random.h" #if HAVE_BCMATH #include "ext/bcmath/php_bcmath.h" #endif #if HAVE_CALENDAR #include "ext/calendar/php_calendar.h" #endif #if HAVE_CTYPE #include "ext/ctype/php_ctype.h" #endif #include "ext/date/php_date.h" #if HAVE_FTP #include "ext/ftp/php_ftp.h" #endif #if HAVE_ICONV #include "ext/iconv/php_iconv.h" #endif #include "ext/standard/reg.h" #include "ext/pcre/php_pcre.h" #if HAVE_UODBC #include "ext/odbc/php_odbc.h" #endif #if HAVE_PHP_SESSION #include "ext/session/php_session.h" #endif #if HAVE_MBSTRING #include "ext/mbstring/mbstring.h" #endif #if HAVE_TOKENIZER #include "ext/tokenizer/php_tokenizer.h" #endif #if HAVE_ZLIB #include "ext/zlib/php_zlib.h" #endif #if HAVE_LIBXML #include "ext/libxml/php_libxml.h" #if HAVE_DOM #include "ext/dom/php_dom.h" #endif #if HAVE_SIMPLEXML #include "ext/simplexml/php_simplexml.h" #endif #endif #if HAVE_XML #include "ext/xml/php_xml.h" #endif #include "ext/com_dotnet/php_com_dotnet.h" #include "ext/spl/php_spl.h" #if HAVE_XML && HAVE_XMLREADER #include "ext/xmlreader/php_xmlreader.h" #endif #if HAVE_XML && HAVE_XMLWRITER #include "ext/xmlwriter/php_xmlwriter.h" #endif /* }}} */ /* {{{ php_builtin_extensions[] */ static zend_module_entry * const php_builtin_extensions[] = { phpext_standard_ptr #if HAVE_BCMATH ,phpext_bcmath_ptr #endif #if HAVE_CALENDAR ,phpext_calendar_ptr #endif ,phpext_com_dotnet_ptr #if HAVE_CTYPE ,phpext_ctype_ptr #endif ,phpext_date_ptr #if HAVE_FTP ,phpext_ftp_ptr #endif ,phpext_hash_ptr #if HAVE_ICONV ,phpext_iconv_ptr #endif #if HAVE_MBSTRING ,phpext_mbstring_ptr #endif #if HAVE_UODBC ,phpext_odbc_ptr #endif ,phpext_pcre_ptr ,phpext_reflection_ptr #if HAVE_PHP_SESSION ,phpext_session_ptr #endif #if HAVE_TOKENIZER ,phpext_tokenizer_ptr #endif #if HAVE_ZLIB ,phpext_zlib_ptr #endif #if HAVE_LIBXML ,phpext_libxml_ptr #if HAVE_DOM ,phpext_dom_ptr #endif #if HAVE_SIMPLEXML ,phpext_simplexml_ptr #endif #endif #if HAVE_XML ,phpext_xml_ptr #endif ,phpext_spl_ptr #if HAVE_XML && HAVE_XMLREADER ,phpext_xmlreader_ptr #endif #if HAVE_XML && HAVE_XMLWRITER ,phpext_xmlwriter_ptr #endif }; /* }}} */ #define EXTCOUNT (sizeof(php_builtin_extensions)/sizeof(zend_module_entry *)) PHPAPI int php_register_internal_extensions(void) { return php_register_extensions(php_builtin_extensions, EXTCOUNT); }
4,087
23.926829
77
c