SAPI_API int sapi_register_post_entry(sapi_post_entry *post_entry) { if (SG(sapi_started) && EG(current_execute_data)) { return FAILURE; } return zend_hash_str_add_mem(&SG(known_post_content_types), post_entry->content_type, post_entry->content_type_len, (void *) post_entry, sizeof(sapi_post_entry)) ? SUCCESS : FAILURE; }
/* {{{ xmlreader_register_prop_handler */ static void xmlreader_register_prop_handler(HashTable *prop_handler, char *name, xmlreader_read_int_t read_int_func, xmlreader_read_const_char_t read_char_func, int rettype TSRMLS_DC) { xmlreader_prop_handler hnd; hnd.read_char_func = read_char_func; hnd.read_int_func = read_int_func; hnd.type = rettype; zend_hash_str_add_mem(prop_handler, name, strlen(name), &hnd, sizeof(xmlreader_prop_handler)); }
static int php_ini_on_update_tags(zend_ini_entry *entry, zend_string *new_value, void *mh_arg1, void *mh_arg2, void *mh_arg3, int stage, int type) { url_adapt_state_ex_t *ctx; char *key; char *tmp; char *lasts = NULL; if (type) { ctx = &BG(url_adapt_session_ex); } else { ctx = &BG(url_adapt_output_ex); } tmp = estrndup(ZSTR_VAL(new_value), ZSTR_LEN(new_value)); if (ctx->tags) zend_hash_destroy(ctx->tags); else { ctx->tags = malloc(sizeof(HashTable)); if (!ctx->tags) { efree(tmp); return FAILURE; } } zend_hash_init(ctx->tags, 0, NULL, tag_dtor, 1); for (key = php_strtok_r(tmp, ",", &lasts); key; key = php_strtok_r(NULL, ",", &lasts)) { char *val; val = strchr(key, '='); if (val) { char *q; size_t keylen; *val++ = '\0'; for (q = key; *q; q++) { *q = tolower(*q); } keylen = q - key; zend_hash_str_add_mem(ctx->tags, key, keylen, val, strlen(val)+1); } } efree(tmp); return SUCCESS; }
static int timecop_func_override() { const struct timecop_override_func_entry *p; zend_function *zf_orig, *zf_ovrd, *zf_save; p = &(timecop_override_func_table[0]); while (p->orig_func != NULL) { zf_orig = zend_hash_str_find_ptr(EG(function_table), p->orig_func, strlen(p->orig_func)); if (zf_orig == NULL) { // Do nothing. Because some functions are introduced by optional extensions. p++; continue; } zf_ovrd = zend_hash_str_find_ptr(EG(function_table), p->ovrd_func, strlen(p->ovrd_func)); if (zf_ovrd == NULL) { php_error_docref("https://github.com/hnw/php-timecop", E_WARNING, "timecop couldn't find function %s.", p->ovrd_func); p++; continue; } zf_save = zend_hash_str_find_ptr(EG(function_table), p->save_func, strlen(p->save_func)); if (zf_save != NULL) { php_error_docref("https://github.com/hnw/php-timecop", E_WARNING, "timecop couldn't create function %s because already exists.", p->save_func); p++; continue; } TIMECOP_ASSERT(zf_orig->type == ZEND_INTERNAL_FUNCTION); TIMECOP_ASSERT(zf_ovrd->type == ZEND_INTERNAL_FUNCTION); zend_hash_str_add_mem(EG(function_table), p->save_func, strlen(p->save_func), zf_orig, sizeof(zend_internal_function)); function_add_ref(zf_orig); zend_hash_str_update_mem(EG(function_table), p->orig_func, strlen(p->orig_func), zf_ovrd, sizeof(zend_internal_function)); function_add_ref(zf_ovrd); p++; } return SUCCESS; }
static PHP_INI_MH(OnUpdateTags) { url_adapt_state_ex_t *ctx; char *key; char *lasts; char *tmp; ctx = &BG(url_adapt_state_ex); tmp = estrndup(new_value->val, new_value->len); if (ctx->tags) zend_hash_destroy(ctx->tags); else { ctx->tags = malloc(sizeof(HashTable)); if (!ctx->tags) { return FAILURE; } } zend_hash_init(ctx->tags, 0, NULL, tag_dtor, 1); for (key = php_strtok_r(tmp, ",", &lasts); key; key = php_strtok_r(NULL, ",", &lasts)) { char *val; val = strchr(key, '='); if (val) { char *q; int keylen; *val++ = '\0'; for (q = key; *q; q++) *q = tolower(*q); keylen = q - key; /* key is stored withOUT NUL val is stored WITH NUL */ zend_hash_str_add_mem(ctx->tags, key, keylen, val, strlen(val)+1); } } efree(tmp); return SUCCESS; }
static int timecop_class_override() { const struct timecop_override_class_entry *p; zend_class_entry *ce_orig, *ce_ovrd; zend_function *zf_orig, *zf_ovrd, *zf_save, *zf_new; p = &(timecop_override_class_table[0]); while (p->orig_class != NULL) { ce_orig = zend_hash_str_find_ptr(EG(class_table), p->orig_class, strlen(p->orig_class)); if (ce_orig == NULL) { php_error_docref("https://github.com/hnw/php-timecop", E_WARNING, "timecop couldn't find class %s.", p->orig_class); p++; continue; } ce_ovrd = zend_hash_str_find_ptr(EG(class_table), p->ovrd_class, strlen(p->ovrd_class)); if (ce_ovrd == NULL) { php_error_docref("https://github.com/hnw/php-timecop", E_WARNING, "timecop couldn't find class %s.", p->ovrd_class); p++; continue; } zf_orig = zend_hash_str_find_ptr(&ce_orig->function_table, p->orig_method, strlen(p->orig_method)); if (zf_orig == NULL) { php_error_docref("https://github.com/hnw/php-timecop", E_WARNING, "timecop couldn't find method %s::%s.", p->orig_class, p->orig_method); p++; continue; } zf_ovrd = zend_hash_str_find_ptr(&ce_ovrd->function_table, p->orig_method, strlen(p->orig_method)); if (zf_ovrd == NULL) { php_error_docref("https://github.com/hnw/php-timecop", E_WARNING, "timecop couldn't find method %s::%s.", p->ovrd_class, p->orig_method); p++; continue; } zf_save = zend_hash_str_find_ptr(&ce_orig->function_table, p->save_method, strlen(p->save_method)); if (zf_save != NULL) { php_error_docref("https://github.com/hnw/php-timecop", E_WARNING, "timecop couldn't create method %s::%s because already exists.", p->orig_class, p->save_method); p++; continue; } TIMECOP_ASSERT(zf_orig->type == ZEND_INTERNAL_FUNCTION); TIMECOP_ASSERT(ce_orig->type & ZEND_INTERNAL_CLASS); TIMECOP_ASSERT(zf_ovrd->type == ZEND_INTERNAL_FUNCTION); TIMECOP_ASSERT(ce_ovrd->type & ZEND_INTERNAL_CLASS); zend_hash_str_add_mem(&ce_orig->function_table, p->save_method, strlen(p->save_method), zf_orig, sizeof(zend_internal_function)); function_add_ref(zf_orig); zf_new = zend_hash_str_update_mem(&ce_orig->function_table, p->orig_method, strlen(p->orig_method), zf_ovrd, sizeof(zend_internal_function)); function_add_ref(zf_ovrd); TIMECOP_ASSERT(zf_new != NULL); TIMECOP_ASSERT(zf_new != zf_orig); if (strcmp(p->orig_method, "__construct") == 0) { ce_orig->constructor = zf_new; } p++; } return SUCCESS; }