/** * Reads an item from an array using a zval as index */ int phalcon_array_fetch(zval **return_value, zval *arr, zval *index, int silent TSRMLS_DC) { zval **zv; int result = FAILURE, type; if (Z_TYPE_P(index) == IS_ARRAY || Z_TYPE_P(index) == IS_OBJECT) { ZVAL_NULL(*return_value); if (silent == PH_NOISY) { php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Illegal offset type"); } return FAILURE; } if (Z_TYPE_P(index) == IS_NULL) { convert_to_string(index); } ZVAL_NULL(*return_value); if (Z_TYPE_P(arr) == IS_NULL || Z_TYPE_P(arr) == IS_BOOL) { return FAILURE; } if (Z_TYPE_P(index) != IS_STRING && Z_TYPE_P(index) != IS_LONG && Z_TYPE_P(index) != IS_DOUBLE) { if (silent == PH_NOISY) { php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Illegal offset type"); } return FAILURE; } if (Z_TYPE_P(index) == IS_STRING) { if((type = is_numeric_string(Z_STRVAL_P(index), Z_STRLEN_P(index), NULL, NULL, 0))) { if (type == IS_LONG) { convert_to_long(index); } } } else { if (Z_TYPE_P(index) == IS_DOUBLE) { convert_to_long(index); } } if (Z_TYPE_P(index) == IS_STRING) { if((result = zend_hash_find(Z_ARRVAL_P(arr), Z_STRVAL_P(index), Z_STRLEN_P(index)+1, (void**) &zv)) == SUCCESS) { zval_ptr_dtor(return_value); *return_value = *zv; Z_ADDREF_PP(return_value); return SUCCESS; } } if (Z_TYPE_P(index) == IS_LONG) { if ((result = zend_hash_index_find(Z_ARRVAL_P(arr), Z_LVAL_P(index), (void**) &zv)) == SUCCESS) { zval_ptr_dtor(return_value); *return_value = *zv; Z_ADDREF_PP(return_value); return SUCCESS; } } if (silent == PH_NOISY) { if (Z_TYPE_P(index) == IS_LONG) { php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Undefined index: %ld", Z_LVAL_P(index)); } else { php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Undefined index: %s", Z_STRVAL_P(index)); } } return FAILURE; }
PHP_METHOD(WinGdiPath, draw) { wingdi_devicecontext_object *dc_obj; wingdi_path_object *path_obj; zval ***parameters, **x, **y, **type; POINT *points = NULL; BYTE *types = NULL; int points_total = 0; int param_count, i; WINGDI_ERROR_HANDLING(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "+", ¶meters, ¶m_count) == FAILURE) return; WINGDI_RESTORE_ERRORS(); path_obj = zend_object_store_get_object(getThis() TSRMLS_CC); dc_obj = zend_object_store_get_object(path_obj->device_context TSRMLS_CC); points = emalloc(param_count * sizeof(POINT)); types = emalloc(param_count * sizeof(BYTE)); for (i = 0; i < param_count; i++) { // We expect only arrays if (Z_TYPE_PP(parameters[i]) != IS_ARRAY) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "expected array for parameter %d, got %s", i + 1, zend_zval_type_name(*(parameters[i]))); goto CLEANUP; } else { // We want 3 elements if (zend_hash_num_elements(Z_ARRVAL_PP(parameters[i])) != 3) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "expected 3 elements for array at parameter %d, got %d", i + 1, zend_hash_num_elements(Z_ARRVAL_PP(parameters[i]))); goto CLEANUP; } else { zend_hash_index_find(Z_ARRVAL_PP(parameters[i]), 0, (void **)&x); zend_hash_index_find(Z_ARRVAL_PP(parameters[i]), 1, (void **)&y); zend_hash_index_find(Z_ARRVAL_PP(parameters[i]), 2, (void **)&type); if (Z_TYPE_PP(x) != IS_LONG) convert_to_long(*x); if (Z_TYPE_PP(y) != IS_LONG) convert_to_long(*y); if (Z_TYPE_PP(type) != IS_LONG) convert_to_long(*type); points[i].x = Z_LVAL_PP(x); points[i].y = Z_LVAL_PP(y); types[i] = (BYTE)Z_LVAL_PP(type); points_total++; } } } RETVAL_BOOL(PolyDraw(dc_obj->hdc, points, types, points_total)); CLEANUP: efree(points); efree(types); }
PHP_METHOD(WinGdiPath, line) { wingdi_devicecontext_object *dc_obj; wingdi_path_object *path_obj = zend_object_store_get_object(getThis() TSRMLS_CC); POINT *points = NULL; DWORD *point_counts = NULL; zval ***parameters, **x, **y, **current_elem; HashTable *current_param; HashPointer p; int param_count = 0, total_points = 0, // The amount of POINTs in points i; WINGDI_ERROR_HANDLING(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "+", ¶meters, ¶m_count) == FAILURE) return; WINGDI_RESTORE_ERRORS(); for (i = 0; i < param_count; i++) { // All parameters should be arrays if (Z_TYPE_PP(parameters[i]) == IS_ARRAY) { // Add room for new DWORD point_counts = erealloc(point_counts, (i + 1) * sizeof(DWORD)); // Initialise number of points for current array point_counts[i] = 0; // Less typing current_param = Z_ARRVAL_PP(parameters[i]); // Loop over all elements in current array parameter for (zend_hash_internal_pointer_reset(current_param); zend_hash_has_more_elements(current_param) == SUCCESS; zend_hash_move_forward(current_param)) { // Add room for new POINT points = erealloc(points, (total_points + 1) * sizeof(POINT)); // We want the hash pointer so we know what index we're at currently zend_hash_get_pointer(current_param, &p); // Pull the current data from hashtable zend_hash_get_current_data(current_param, (void **)¤t_elem); // Sanity checks: // 1) An array // 2) 2 elements if (Z_TYPE_PP(current_elem) != IS_ARRAY) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "expected point-array for parameter %d, index %d, got %s", i + 1, p.h, zend_zval_type_name(*current_elem)); goto CLEANUP; } if (zend_hash_num_elements(Z_ARRVAL_PP(current_elem)) != 2) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "expected point-array for parameter %d index %d to have exactly 2 elements, %d given", i + 1, p.h, zend_hash_num_elements(Z_ARRVAL_PP(current_elem))); goto CLEANUP; } // Grab x and y coord and convert to long if needed zend_hash_index_find(Z_ARRVAL_PP(current_elem), 0, (void **)&x); zend_hash_index_find(Z_ARRVAL_PP(current_elem), 1, (void **)&y); if (Z_TYPE_PP(x) != IS_LONG) convert_to_long(*x); if (Z_TYPE_PP(y) != IS_LONG) convert_to_long(*y); // Store points[total_points].x = Z_LVAL_PP(x); points[total_points].y = Z_LVAL_PP(y); total_points++; point_counts[i]++; } } else { php_error_docref(NULL TSRMLS_CC, E_ERROR, "expected array for parameter %d, got %s", i + 1, zend_zval_type_name(*(parameters[i]))); goto CLEANUP; } } dc_obj = zend_object_store_get_object(path_obj->device_context TSRMLS_CC); RETURN_BOOL(PolyPolyline(dc_obj->hdc, points, point_counts, total_points)); CLEANUP: efree(points); efree(point_counts); }
// A carbon copy of the Win\Gdi\Region\Polygon implementation // without some parameter checks (no poly-fill-mode given) PHP_METHOD(WinGdiRegionPolygon, polygon) { wingdi_devicecontext_object *dc_obj; wingdi_path_object *path_obj; HashPointer p; // We use this to determine what index we are at in the array POINT *points = NULL; zval ***parameters, **current_elem, **x, **y; INT *point_counts = NULL; // Number of POINTs in corresponding points array int ints_in_count = 0, // Number of ints in point_counts param_count, i, t = 0; // Total number of POINTs WINGDI_ERROR_HANDLING(); // Will throw an exception if no parameters are given if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "+", ¶meters, ¶m_count) == FAILURE) return; WINGDI_RESTORE_ERRORS(); point_counts = emalloc(param_count * sizeof(INT)); for (i = 0; i < param_count; i++) { if (Z_TYPE_PP(parameters[i]) == IS_ARRAY) { point_counts[ints_in_count] = 0; for (zend_hash_internal_pointer_reset(Z_ARRVAL_PP(parameters[i])); zend_hash_has_more_elements(Z_ARRVAL_PP(parameters[i])) == SUCCESS; zend_hash_move_forward(Z_ARRVAL_PP(parameters[i]))) { points = erealloc(points, t * sizeof(POINT) + sizeof(POINT)); zend_hash_get_pointer(Z_ARRVAL_PP(parameters[i]), &p); zend_hash_get_current_data(Z_ARRVAL_PP(parameters[i]), (void **)¤t_elem); if (Z_TYPE_PP(current_elem) != IS_ARRAY) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "expected array in array for parameter %d, got %s", i + 1, zend_zval_type_name(*current_elem)); goto CLEANUP; } else { if (zend_hash_num_elements(Z_ARRVAL_PP(current_elem)) != 2) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "expected point-array at index %d for parameter %d to have 2 elements, %d given", p.h, i + 1, zend_hash_num_elements(Z_ARRVAL_PP(current_elem))); goto CLEANUP; } else { zend_hash_index_find(Z_ARRVAL_PP(current_elem), 0, (void **)&x); zend_hash_index_find(Z_ARRVAL_PP(current_elem), 1, (void **)&y); if (Z_TYPE_PP(x) != IS_LONG) convert_to_long(*x); if (Z_TYPE_PP(y) != IS_LONG) convert_to_long(*y); points[t].x = Z_LVAL_PP(x); points[t].y = Z_LVAL_PP(y); t++; point_counts[ints_in_count]++; } } } ints_in_count++; } else { php_error_docref(NULL TSRMLS_CC, E_ERROR, "expecting array for parameter %d, got %s", zend_zval_type_name(*(parameters[i]))); goto CLEANUP; } } path_obj = zend_object_store_get_object(getThis() TSRMLS_CC); dc_obj = zend_object_store_get_object(path_obj->device_context TSRMLS_CC); RETURN_BOOL(PolyPolygon(dc_obj->hdc, points, point_counts, ints_in_count)); CLEANUP: efree(parameters); efree(points); efree(point_counts); }
static inline int process_nested_data(UNSERIALIZE_PARAMETER, HashTable *ht, long elements, int objprops) { while (elements-- > 0) { zval *key, *data, **old_data; ALLOC_INIT_ZVAL(key); if (!php_var_unserialize(&key, p, max, NULL TSRMLS_CC)) { zval_dtor(key); FREE_ZVAL(key); return 0; } if (Z_TYPE_P(key) != IS_LONG && Z_TYPE_P(key) != IS_STRING) { zval_dtor(key); FREE_ZVAL(key); return 0; } ALLOC_INIT_ZVAL(data); if (!php_var_unserialize(&data, p, max, var_hash TSRMLS_CC)) { zval_dtor(key); FREE_ZVAL(key); zval_dtor(data); FREE_ZVAL(data); return 0; } if (!objprops) { switch (Z_TYPE_P(key)) { case IS_LONG: if (zend_hash_index_find(ht, Z_LVAL_P(key), (void **)&old_data)==SUCCESS) { var_push_dtor(var_hash, old_data); } zend_hash_index_update(ht, Z_LVAL_P(key), &data, sizeof(data), NULL); break; case IS_STRING: if (zend_symtable_find(ht, Z_STRVAL_P(key), Z_STRLEN_P(key) + 1, (void **)&old_data)==SUCCESS) { var_push_dtor(var_hash, old_data); } zend_symtable_update(ht, Z_STRVAL_P(key), Z_STRLEN_P(key) + 1, &data, sizeof(data), NULL); break; } } else { /* object properties should include no integers */ convert_to_string(key); zend_hash_update(ht, Z_STRVAL_P(key), Z_STRLEN_P(key) + 1, &data, sizeof data, NULL); } zval_dtor(key); FREE_ZVAL(key); if (elements && *(*p-1) != ';' && *(*p-1) != '}') { (*p)--; return 0; } } return 1; }
/** * Applies a format to a message before sending it to the log * * @param string $message * @param int $type * @param int $timestamp * @return string */ PHP_METHOD(Phalcon_Logger_Formatter_Firephp, format) { zval *message, *type, *type_str = NULL, *timestamp; zval *payload, *body, *backtrace, *meta, *encoded; zval *show_backtrace; smart_str result = { NULL, 0, 0 }; int i; Bucket *p; phalcon_fetch_params(0, 3, 0, &message, &type, ×tamp); /** * We intentionally do not use Phalcon's MM for better performance. * All variables allocated with PHALCON_ALLOC_ZVAL() will have * their reference count set to 1 and therefore they can be nicely * put into the result array; when that array will be destroyed, * all inserted variables will be automatically destroyed, too * and we will just save some time by not using Z_ADDREF_P and Z_DELREF_P */ PHALCON_ALLOC_ZVAL(type_str); phalcon_call_method_p1(type_str, this_ptr, "gettypestring", type); phalcon_read_property_this(&show_backtrace, getThis(), SL("_showBacktrace"), PH_NOISY TSRMLS_CC); Z_DELREF_P(show_backtrace); /** * Get the backtrace. This differs for differemt PHP versions. * 5.3.6+ allows us to skip the function arguments which will save some memory * For 5.4+ there is an extra argument. */ PHALCON_ALLOC_ZVAL(backtrace); if (zend_is_true(show_backtrace)) { #if PHP_VERSION_ID < 50306 zend_fetch_debug_backtrace(backtrace, 1, 0 TSRMLS_CC); #elif PHP_VERSION_ID < 50400 zend_fetch_debug_backtrace(backtrace, 1, DEBUG_BACKTRACE_IGNORE_ARGS TSRMLS_CC); #else zend_fetch_debug_backtrace(backtrace, 1, DEBUG_BACKTRACE_IGNORE_ARGS, 0 TSRMLS_CC); #endif if (Z_TYPE_P(backtrace) == IS_ARRAY) { HashPosition pos; HashTable *ht = Z_ARRVAL_P(backtrace); zval **ppzval; int found = 0; ulong idx; char *key; uint key_len; /** * At this point we know that the backtrace is the array. * Again, we intentionally do not use Phalcon's API because we know * that we are working with the array / hash table and thus we can * save some time by omitting Z_TYPE_P(x) == IS_ARRAY checks */ for ( zend_hash_internal_pointer_reset_ex(ht, &pos); zend_hash_has_more_elements_ex(ht, &pos) == SUCCESS; ) { zend_hash_get_current_data_ex(ht, (void**)&ppzval, &pos); zend_hash_get_current_key_ex(ht, &key, &key_len, &idx, 0, &pos); zend_hash_move_forward_ex(ht, &pos); if (Z_TYPE_PP(ppzval) == IS_ARRAY) { /** * Here we need to skip the latest calls into Phalcon's core. * Calls to Zend internal functions will have "file" index not set. * We remove these entries from the array. */ if (!found && !zend_hash_exists(Z_ARRVAL_PP(ppzval), SS("file"))) { zend_hash_index_del(ht, idx); } else { /** * Remove args and object indices. They usually give * too much information; this is not suitable to send * in the HTTP headers */ zend_hash_del(Z_ARRVAL_PP(ppzval), "args", sizeof("args")); zend_hash_del(Z_ARRVAL_PP(ppzval), "object", sizeof("object")); found = 1; } } } /** * Now we need to renumber the hash table because we removed several * heading elements. If we don't do this, json_encode() will convert * this array to a JavaScript object which is an unwanted side effect */ p = ht->pListHead; i = 0; while (p != NULL) { p->nKeyLength = 0; p->h = i++; p = p->pListNext; } ht->nNextFreeElement = i; zend_hash_rehash(ht); } } /** * The result will looks like this: * * array( * array('Type' => 'message type', 'Label' => 'message'), * array('backtrace' => array(backtrace goes here) * ) */ MAKE_STD_ZVAL(payload); array_init_size(payload, 2); PHALCON_ALLOC_ZVAL(meta); array_init_size(meta, 4); add_assoc_zval_ex(meta, SS("Type"), type_str); Z_ADDREF_P(message); add_assoc_zval_ex(meta, SS("Label"), message); if (Z_TYPE_P(backtrace) == IS_ARRAY) { zval **ppzval; if (likely(SUCCESS == zend_hash_index_find(Z_ARRVAL_P(backtrace), 0, (void**)&ppzval)) && likely(Z_TYPE_PP(ppzval) == IS_ARRAY)) { zval **file = NULL, **line = NULL; zend_hash_quick_find(Z_ARRVAL_PP(ppzval), SS("file"), zend_inline_hash_func(SS("file")), (void**)&file); zend_hash_quick_find(Z_ARRVAL_PP(ppzval), SS("line"), zend_inline_hash_func(SS("line")), (void**)&line); if (likely(file != NULL)) { Z_ADDREF_PP(file); add_assoc_zval_ex(meta, SS("File"), *file); } if (likely(line != NULL)) { Z_ADDREF_PP(line); add_assoc_zval_ex(meta, SS("Line"), *line); } } } MAKE_STD_ZVAL(body); array_init_size(body, 1); if (zend_is_true(show_backtrace)) { add_assoc_zval_ex(body, SS("backtrace"), backtrace); } else { zval_ptr_dtor(&backtrace); } add_next_index_zval(payload, meta); add_next_index_zval(payload, body); /** * Convert everything to JSON */ ALLOC_INIT_ZVAL(encoded); phalcon_json_encode(encoded, payload, 0 TSRMLS_CC); /** * As promised, kill the payload and all associated elements */ zval_ptr_dtor(&payload); /** * We don't want to use Phalcon's concatenation API because it * requires the memory manager. Therefore we fall back to using smart strings. * smart_str_alloc4() will allocate all required memory amount (plus some more) * in one go and this allows us to avoid performance penalties due to * memory reallocations. */ smart_str_alloc4(&result, Z_STRLEN_P(encoded) + 2 + 5, 0, i); /** * The format is: * * <size>|[meta,body]| * * Meta and body are contained in encoded inside the array, as required * by the protocol specification * @see http://www.firephp.org/Wiki/Reference/Protocol */ smart_str_append_long(&result, Z_STRLEN_P(encoded)); smart_str_appendc(&result, '|'); smart_str_appendl(&result, Z_STRVAL_P(encoded), Z_STRLEN_P(encoded)); smart_str_appendc(&result, '|'); smart_str_0(&result); /* We don't need the JSON message anymore */ zval_ptr_dtor(&encoded); /* Do not free the samrt string because we steal its data for zval */ RETURN_STRINGL(result.c, result.len, 0); }
/* {{{ proto void run() */ PHP_METHOD(slightphp, run) { zval *zone=NULL; zval *page=NULL; zval *entry=NULL; zval **token; zval *path_array; //{{{ int isPart; zval * path = NULL; if (ZEND_NUM_ARGS()>0 && zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z/", &path) != FAILURE) { if (Z_TYPE_P(path)!= IS_STRING){ RETURN_FALSE; } isPart = 1; }else{ isPart = 0; path = zend_read_static_property(slightphp_ce_ptr,"pathInfo",sizeof("pathInfo")-1,1 TSRMLS_CC); int s = Z_STRLEN_P(path); if(s==0){ zend_is_auto_global("_SERVER", sizeof("_SERVER") - 1 TSRMLS_CC); if(zend_hash_find(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER]), "PATH_INFO", sizeof("PATH_INFO"), (void **) &token) == SUCCESS ){ path = *token; }else if(zend_hash_find(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER]), "REQUEST_URI", sizeof("REQUEST_URI"), (void **) &token) == SUCCESS ){ php_url *resource=NULL; resource = php_url_parse(Z_STRVAL_PP(token)); if(resource != NULL && resource->path != NULL){ ZVAL_STRING(path,resource->path,1); }else{ path = *token; } if (resource) { php_url_free(resource); } } } } //}}} MAKE_STD_ZVAL(path_array); array_init(path_array); if (path){ //{{{ zval quotedFlag; regex_t re; char *regex; regmatch_t subs[1]; int err,size; char *strp = Z_STRVAL_P(path); char *endp = strp + Z_STRLEN_P(path); zval *splitFlag = zend_read_static_property(slightphp_ce_ptr,"splitFlag",sizeof("splitFlag")-1,1 TSRMLS_CC); if(preg_quote(splitFlag,"edFlag)>0){ spprintf(®ex,0,"[%s\\/]",Z_STRVAL(quotedFlag)); }else{ spprintf(®ex,0,"[\\/]"); } err = regcomp(&re, regex, REG_ICASE); if (err) { }else{ while (!(err = regexec(&re, strp, 1, subs, 0))) { if (subs[0].rm_so == 0 && subs[0].rm_eo) { //ignore empty string strp += subs[0].rm_eo; }else if (subs[0].rm_so == 0 && subs[0].rm_eo == 0) { }else{ size = subs[0].rm_so; add_next_index_stringl(path_array, strp, size, 1); strp += size; } } if (!err || err == REG_NOMATCH) { size = endp - strp; if(size>0) add_next_index_stringl(path_array, strp, size, 1); } regfree(&re); } efree(regex); //}}} //int n_elems = zend_hash_num_elements(Z_ARRVAL_P(path_array)); if(zend_hash_index_find(Z_ARRVAL_P(path_array), 0, (void **)&token) != FAILURE) { zone = *token; } if(zend_hash_index_find(Z_ARRVAL_P(path_array), 1, (void **)&token) != FAILURE) { page = *token; } if(zend_hash_index_find(Z_ARRVAL_P(path_array), 2, (void **)&token) != FAILURE) { entry = *token; } } if(!zone){ zone = zend_read_static_property(slightphp_ce_ptr,"defaultZone",sizeof("defaultZone")-1,1 TSRMLS_CC); zend_hash_next_index_insert(Z_ARRVAL_P(path_array),&zone,sizeof(zval*),NULL); } if(!page){ page = zend_read_static_property(slightphp_ce_ptr,"defaultPage",sizeof("defaultPage")-1,1 TSRMLS_CC); zend_hash_next_index_insert(Z_ARRVAL_P(path_array),&page,sizeof(zval*),NULL); } if(!entry){ entry = zend_read_static_property(slightphp_ce_ptr,"defaultEntry",sizeof("defaultEntry")-1,1 TSRMLS_CC); zend_hash_next_index_insert(Z_ARRVAL_P(path_array),&entry,sizeof(zval*),NULL); } //{{{ zval *zoneAlias = zend_read_static_property(slightphp_ce_ptr,"zoneAlias",sizeof("zoneAlias")-1,1 TSRMLS_CC); if(zoneAlias && Z_TYPE_P(zoneAlias)==IS_ARRAY){ char *string_key;uint str_key_len;ulong num_key; HashPosition pos; zval **entry2; zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(zoneAlias), &pos); while (zend_hash_get_current_data_ex(Z_ARRVAL_P(zoneAlias), (void **)&entry2, &pos) == SUCCESS) { if(strcmp(Z_STRVAL_PP(entry2) ,Z_STRVAL_P(zone))==0){ switch (zend_hash_get_current_key_ex(Z_ARRVAL_P(zoneAlias), &string_key, &str_key_len, &num_key, 0, &pos)) { case HASH_KEY_IS_STRING: ZVAL_STRING(zone,string_key,1); break; } } zend_hash_move_forward_ex(Z_ARRVAL_P(zoneAlias), &pos); } if(entry2)zval_ptr_dtor(entry2); if(string_key)efree(string_key); } //if(zoneAlias)FREE_ZVAL(zoneAlias); //}}} if(!isPart){ zend_update_static_property(slightphp_ce_ptr,"zone",sizeof("zone")-1,zone TSRMLS_CC); zend_update_static_property(slightphp_ce_ptr,"page",sizeof("page")-1,page TSRMLS_CC); zend_update_static_property(slightphp_ce_ptr,"entry",sizeof("entry")-1,entry TSRMLS_CC); }else{ if( strcmp(Z_STRVAL_P(zone),Z_STRVAL_P(zend_read_static_property(slightphp_ce_ptr,"zone",sizeof("zone")-1,1 TSRMLS_CC)))==0 && strcmp(Z_STRVAL_P(page),Z_STRVAL_P(zend_read_static_property(slightphp_ce_ptr,"page",sizeof("page")-1,1 TSRMLS_CC)))==0 && strcmp(Z_STRVAL_P(entry),Z_STRVAL_P(zend_read_static_property(slightphp_ce_ptr,"entry",sizeof("entry")-1,1 TSRMLS_CC)))==0 ){ debug("part ignored [%s]",Z_STRVAL_P(path)); return; } } zval *appDir = zend_read_static_property(slightphp_ce_ptr,"appDir",sizeof("appDir")-1,1 TSRMLS_CC); zval *params[1]; params[0]=path_array; if(slightphp_load(appDir,zone,page TSRMLS_CC) == SUCCESS){ if(slightphp_run(zone,page,entry,return_value,1,params TSRMLS_CC)==SUCCESS){ if(path_array)FREE_ZVAL(path_array); RETURN_ZVAL(return_value,1,0); }; } if(path_array)FREE_ZVAL(path_array); RETURN_FALSE; }
/* }}} */ static void xc_coverager_save_cov(char *srcfile, char *outfilename, coverager_t cov TSRMLS_DC) /* {{{ */ { long *buf = NULL, *p; long covlines, *phits; int fd = -1; int size; int newfile; struct stat srcstat, outstat; HashPosition pos; char *contents = NULL; long len; if (stat(srcfile, &srcstat) != 0) { return; } newfile = 0; if (stat(outfilename, &outstat) != 0) { newfile = 1; } else { if (srcstat.st_mtime > outstat.st_mtime) { newfile = 1; } } fd = open(outfilename, O_RDWR | O_CREAT, 0600); if (fd < 0) { char *chr; chr = strrchr(srcfile, PHP_DIR_SEPARATOR); if (chr) { *chr = '\0'; xcache_mkdirs_ex(xc_coveragedump_dir, strlen(xc_coveragedump_dir), srcfile, chr - srcfile TSRMLS_CC); *chr = PHP_DIR_SEPARATOR; } fd = open(outfilename, O_RDWR | O_CREAT, 0600); if (fd < 0) { goto bailout; } } if (flock(fd, LOCK_EX) != SUCCESS) { goto bailout; } if (newfile) { TRACE("%s", "new file"); } else if (outstat.st_size) { len = outstat.st_size; contents = emalloc(len); if (read(fd, (void *) contents, len) != len) { goto bailout; } TRACE("oldsize %d", (int) len); do { p = (long *) contents; len -= sizeof(long); if (len < 0) { break; } if (*p++ != PCOV_HEADER_MAGIC) { TRACE("wrong magic in file %s", outfilename); break; } p += 2; /* skip covliens */ len -= sizeof(long) * 2; if (len < 0) { break; } for (; len >= sizeof(long) * 2; len -= sizeof(long) * 2, p += 2) { if (zend_hash_index_find(cov, p[0], (void**)&phits) == SUCCESS) { if (p[1] == -1) { /* OPTIMIZE: already marked */ continue; } if (*phits != -1) { p[1] += *phits; } } zend_hash_index_update(cov, p[0], &p[1], sizeof(p[1]), NULL); } } while (0); efree(contents); contents = NULL; } /* serialize */ size = (zend_hash_num_elements(cov) + 1) * sizeof(long) * 2 + sizeof(long); p = buf = emalloc(size); *p++ = PCOV_HEADER_MAGIC; p += 2; /* for covlines */ covlines = 0; zend_hash_internal_pointer_reset_ex(cov, &pos); while (zend_hash_get_current_data_ex(cov, (void**)&phits, &pos) == SUCCESS) { *p++ = pos->h; *p++ = *phits; if (*phits > 0) { covlines ++; } zend_hash_move_forward_ex(cov, &pos); } p = buf + 1; p[0] = 0; p[1] = covlines; ftruncate(fd, 0); lseek(fd, 0, SEEK_SET); write(fd, (char *) buf, size); bailout: if (contents) efree(contents); if (fd >= 0) close(fd); if (buf) efree(buf); }