void KPHPArrayObject::AddKrollValueToPHPArray(KValueRef value, zval *phpArray) { if (value->IsNull() || value->IsUndefined()) { add_next_index_null(phpArray); } else if (value->IsBool()) { if (value->ToBool()) add_next_index_bool(phpArray, 1); else add_next_index_bool(phpArray, 0); } else if (value->IsNumber()) { /* No way to check whether the number is an integer or a double here. All Kroll numbers are doubles, so return a double. This could cause some PHP to function incorrectly if it's doing strict type checking. */ add_next_index_double(phpArray, value->ToNumber()); } else if (value->IsString()) { add_next_index_stringl(phpArray, (char *) value->ToString(), strlen(value->ToString()), 1); } else if (value->IsObject()) { /*TODO: Implement*/ } else if (value->IsMethod()) { /*TODO: Implement*/ } else if (value->IsList()) { zval *phpValue; AutoPtr<KPHPArrayObject> pl = value->ToList().cast<KPHPArrayObject>(); if (!pl.isNull()) phpValue = pl->ToPHP(); else phpValue = PHPUtils::ToPHPValue(value); add_next_index_zval(phpArray, phpValue); } }
/** * Unregister the autoload method * * @return Phalcon\Loader */ PHP_METHOD(Phalcon_Loader, unregister){ zval *registered, *autoloader; PHALCON_MM_GROW(); PHALCON_OBS_VAR(registered); phalcon_read_property(®istered, this_ptr, SL("_registered"), PH_NOISY_CC); if (PHALCON_IS_TRUE(registered)) { PHALCON_INIT_VAR(autoloader); array_init_size(autoloader, 2); phalcon_array_append(&autoloader, this_ptr, PH_SEPARATE TSRMLS_CC); add_next_index_stringl(autoloader, SL("autoLoad"), 1); PHALCON_CALL_FUNC_PARAMS_1_NORETURN("spl_autoload_unregister", autoloader); } RETURN_THIS(); }
/* {{{ proto array Riak\Bucket->index(string $index, string $from [, string $to]) Perform a secondary index lookup */ PHP_METHOD(RiakBucket, index) { riack_string rsbucket, rsindex, rsfrom, rsto, *type; riack_string_list *resultlist; char *index, *from, *to; int indexlen, fromlen, tolen, riackstatus, i; riak_connection *connection; zval *zresult; tolen = 0; to = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|s", &index, &indexlen, &from, &fromlen, &to, &tolen) == FAILURE) { zend_throw_exception(riak_badarguments_exception_ce, "Bad or missing argument", 500 TSRMLS_CC); return; } connection = get_riak_connection(getThis() TSRMLS_CC); rsbucket = riack_name_from_bucket(getThis() TSRMLS_CC); type = riack_get_bucket_type_from_bucket(connection->client, getThis() TSRMLS_CC); THROW_EXCEPTION_IF_CONNECTION_IS_NULL(connection); rsindex.len = indexlen; rsindex.value = index; rsfrom.len = fromlen; rsfrom.value = from; if (to != NULL && tolen > 0) { rsto.len = tolen; rsto.value = to; RIACK_RETRY_OP(riackstatus, connection, riack_2i_query_range_ext(connection->client, &rsbucket, type, &rsindex, &rsfrom, &rsto, &resultlist)); } else { RIACK_RETRY_OP(riackstatus, connection, riack_2i_query_exact_ext(connection->client, &rsbucket, type, &rsindex, &rsfrom, &resultlist)); } RFREE(connection->client, type); CHECK_RIACK_STATUS_THROW_AND_RETURN_ON_ERROR(connection, riackstatus); MAKE_STD_ZVAL(zresult); array_init(zresult); for (i=0; i<resultlist->string_count; ++i) { add_next_index_stringl(zresult, resultlist->strings[i].value, resultlist->strings[i].len, 1); } riack_free_string_list_p(connection->client, &resultlist); RETURN_ZVAL(zresult, 0, 1); }
/** * Call single static function on a zval which requires parameters */ inline int phalcon_call_static_zval_func_params(zval *return_value, zval *mixed_name, char *method_name, int method_len, zend_uint param_count, zval *params[], int noreturn TSRMLS_DC){ zval *fn; int status = FAILURE; if (!noreturn) { ALLOC_INIT_ZVAL(return_value); } ALLOC_INIT_ZVAL(fn); array_init(fn); add_next_index_zval(fn, mixed_name); add_next_index_stringl(fn, method_name, method_len, 1); status = phalcon_call_user_function(CG(function_table), NULL, fn, return_value, param_count, params TSRMLS_CC); if (status == FAILURE) { if(Z_TYPE_P(mixed_name) == IS_STRING) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "Call to undefined function %s::%s()", Z_STRVAL_P(mixed_name), method_name); } else { php_error_docref(NULL TSRMLS_CC, E_ERROR, "Call to undefined function not-callable::%s()", method_name); } } zval_ptr_dtor(&fn); if (!noreturn) { zval_ptr_dtor(&return_value); } if (EG(exception)) { status = FAILURE; } if (status == FAILURE) { phalcon_memory_restore_stack(TSRMLS_C); } return status; }
/* {{{ proto string[] Riak\Bucket->getKeyList() List all keys in the bucket */ PHP_METHOD(RiakBucket, getKeyList) { struct RIACK_STRING_LINKED_LIST* resultlist, *curr; RIACK_STRING rsbucket; riak_connection *connection; zval* zresultarr; int riackstatus; GET_RIAK_CONNECTION_RETURN_EXC_ON_ERROR(connection) rsbucket = riack_name_from_bucket(getThis() TSRMLS_CC); riackstatus = riack_list_keys(connection->client, rsbucket, &resultlist); CHECK_RIACK_STATUS_THROW_AND_RETURN_ON_ERROR(connection, riackstatus); MAKE_STD_ZVAL(zresultarr); array_init(zresultarr); curr = resultlist; while (curr) { add_next_index_stringl(zresultarr, curr->string.value, curr->string.len, 1); curr = curr->next; } riack_free_string_linked_list(connection->client, &resultlist); RETURN_ZVAL(zresultarr, 0, 1); }
/* {{{ proto array Riak\Bucket->index(string $index, string $from [, string $to]) Apply given properties to this bucket */ PHP_METHOD(RiakBucket, index) { RIACK_STRING rsbucket, rsindex, rsfrom, rsto; RIACK_STRING_LIST resultlist; char *index, *from, *to; int indexlen, fromlen, tolen, riackstatus, i; riak_connection *connection; zval *zresult; tolen = 0; to = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|s", &index, &indexlen, &from, &fromlen, &to, &tolen) == FAILURE) { return; } GET_RIAK_CONNECTION_RETURN_EXC_ON_ERROR(connection) rsbucket = riack_name_from_bucket(getThis() TSRMLS_CC); rsindex.len = indexlen; rsindex.value = index; rsfrom.len = fromlen; rsfrom.value = from; if (to != NULL && tolen > 0) { rsto.len = tolen; rsto.value = to; riackstatus = riack_2i_query_range(connection->client, rsbucket, rsindex, rsfrom, rsto, &resultlist); } else { riackstatus = riack_2i_query_exact(connection->client, rsbucket, rsindex, rsfrom, &resultlist); } CHECK_RIACK_STATUS_THROW_AND_RETURN_ON_ERROR(connection, riackstatus); MAKE_STD_ZVAL(zresult); array_init(zresult); for (i=0; i<resultlist.string_count; ++i) { add_next_index_stringl(zresult, resultlist.strings[i].value, resultlist.strings[i].len, 1); } riack_free_string_list(connection->client, &resultlist); RETURN_ZVAL(zresult, 0, 1); }
/* {{{ proto string[] Riak\Bucket->getKeyList([int $timeout = 0]) List all keys in the bucket */ PHP_METHOD(RiakBucket, getKeyList) { riack_string_linked_list* resultlist, *curr; riack_string rsbucket, *rstype; riak_connection *connection; zval* zresultarr; long timeout; int riackstatus; timeout = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &timeout) == FAILURE) { zend_throw_exception(riak_badarguments_exception_ce, "Bad or missing argument", 500 TSRMLS_CC); return; } connection = get_riak_connection(getThis() TSRMLS_CC); rsbucket = riack_name_from_bucket(getThis() TSRMLS_CC); THROW_EXCEPTION_IF_CONNECTION_IS_NULL(connection); rstype = riack_get_bucket_type_from_bucket(connection->client, getThis() TSRMLS_CC); // Not gonna do a retry here on purpose... no reason to retry a mistake in the first place riackstatus = riack_list_keys_ext(connection->client, &rsbucket, rstype, &resultlist, timeout); RFREE(connection->client, rstype); CHECK_RIACK_STATUS_THROW_AND_RETURN_ON_ERROR(connection, riackstatus); MAKE_STD_ZVAL(zresultarr); array_init(zresultarr); curr = resultlist; while (curr) { add_next_index_stringl(zresultarr, curr->string.value, curr->string.len, 1); curr = curr->next; } riack_free_string_linked_list_p(connection->client, &resultlist); RETURN_ZVAL(zresultarr, 0, 1); }
/* {{{ _php_mb_regex_ereg_replace_exec */ static void _php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, OnigOptionType options, int is_callable) { zval *arg_pattern_zval; char *arg_pattern; size_t arg_pattern_len; char *replace; size_t replace_len; zend_fcall_info arg_replace_fci; zend_fcall_info_cache arg_replace_fci_cache; char *string; size_t string_len; char *p; php_mb_regex_t *re; OnigSyntaxType *syntax; OnigRegion *regs = NULL; smart_str out_buf = {0}; smart_str eval_buf = {0}; smart_str *pbuf; size_t i; int err, eval, n; OnigUChar *pos; OnigUChar *string_lim; char *description = NULL; char pat_buf[6]; const mbfl_encoding *enc; { const char *current_enc_name; current_enc_name = _php_mb_regex_mbctype2name(MBREX(current_mbctype)); if (current_enc_name == NULL || (enc = mbfl_name2encoding(current_enc_name)) == NULL) { php_error_docref(NULL, E_WARNING, "Unknown error"); RETURN_FALSE; } } eval = 0; { char *option_str = NULL; size_t option_str_len = 0; if (!is_callable) { if (zend_parse_parameters(ZEND_NUM_ARGS(), "zss|s", &arg_pattern_zval, &replace, &replace_len, &string, &string_len, &option_str, &option_str_len) == FAILURE) { RETURN_FALSE; } } else { if (zend_parse_parameters(ZEND_NUM_ARGS(), "zfs|s", &arg_pattern_zval, &arg_replace_fci, &arg_replace_fci_cache, &string, &string_len, &option_str, &option_str_len) == FAILURE) { RETURN_FALSE; } } if (!php_mb_check_encoding( string, string_len, _php_mb_regex_mbctype2name(MBREX(current_mbctype)) )) { RETURN_NULL(); } if (option_str != NULL) { _php_mb_regex_init_options(option_str, option_str_len, &options, &syntax, &eval); } else { options |= MBREX(regex_default_options); syntax = MBREX(regex_default_syntax); } } if (eval && !is_callable) { php_error_docref(NULL, E_DEPRECATED, "The 'e' option is deprecated, use mb_ereg_replace_callback instead"); } if (Z_TYPE_P(arg_pattern_zval) == IS_STRING) { arg_pattern = Z_STRVAL_P(arg_pattern_zval); arg_pattern_len = Z_STRLEN_P(arg_pattern_zval); } else { /* FIXME: this code is not multibyte aware! */ convert_to_long_ex(arg_pattern_zval); pat_buf[0] = (char)Z_LVAL_P(arg_pattern_zval); pat_buf[1] = '\0'; pat_buf[2] = '\0'; pat_buf[3] = '\0'; pat_buf[4] = '\0'; pat_buf[5] = '\0'; arg_pattern = pat_buf; arg_pattern_len = 1; } /* create regex pattern buffer */ re = php_mbregex_compile_pattern(arg_pattern, arg_pattern_len, options, MBREX(current_mbctype), syntax); if (re == NULL) { RETURN_FALSE; } if (eval || is_callable) { pbuf = &eval_buf; description = zend_make_compiled_string_description("mbregex replace"); } else { pbuf = &out_buf; description = NULL; } if (is_callable) { if (eval) { php_error_docref(NULL, E_WARNING, "Option 'e' cannot be used with replacement callback"); RETURN_FALSE; } } /* do the actual work */ err = 0; pos = (OnigUChar *)string; string_lim = (OnigUChar*)(string + string_len); regs = onig_region_new(); while (err >= 0) { err = onig_search(re, (OnigUChar *)string, (OnigUChar *)string_lim, pos, (OnigUChar *)string_lim, regs, 0); if (err <= -2) { OnigUChar err_str[ONIG_MAX_ERROR_MESSAGE_LEN]; onig_error_code_to_str(err_str, err); php_error_docref(NULL, E_WARNING, "mbregex search failure in php_mbereg_replace_exec(): %s", err_str); break; } if (err >= 0) { #if moriyoshi_0 if (regs->beg[0] == regs->end[0]) { php_error_docref(NULL, E_WARNING, "Empty regular expression"); break; } #endif /* copy the part of the string before the match */ smart_str_appendl(&out_buf, (char *)pos, (size_t)((OnigUChar *)(string + regs->beg[0]) - pos)); if (!is_callable) { /* copy replacement and backrefs */ i = 0; p = replace; while (i < replace_len) { int fwd = (int) php_mb_mbchar_bytes_ex(p, enc); n = -1; if ((replace_len - i) >= 2 && fwd == 1 && p[0] == '\\' && p[1] >= '0' && p[1] <= '9') { n = p[1] - '0'; } if (n >= 0 && n < regs->num_regs) { if (regs->beg[n] >= 0 && regs->beg[n] < regs->end[n] && (size_t)regs->end[n] <= string_len) { smart_str_appendl(pbuf, string + regs->beg[n], regs->end[n] - regs->beg[n]); } p += 2; i += 2; } else { smart_str_appendl(pbuf, p, fwd); p += fwd; i += fwd; } } } if (eval) { zval v; zend_string *eval_str; /* null terminate buffer */ smart_str_0(&eval_buf); if (eval_buf.s) { eval_str = eval_buf.s; } else { eval_str = ZSTR_EMPTY_ALLOC(); } /* do eval */ if (zend_eval_stringl(ZSTR_VAL(eval_str), ZSTR_LEN(eval_str), &v, description) == FAILURE) { efree(description); zend_throw_error(NULL, "Failed evaluating code: %s%s", PHP_EOL, ZSTR_VAL(eval_str)); onig_region_free(regs, 0); smart_str_free(&out_buf); smart_str_free(&eval_buf); RETURN_FALSE; } /* result of eval */ convert_to_string(&v); smart_str_appendl(&out_buf, Z_STRVAL(v), Z_STRLEN(v)); /* Clean up */ smart_str_free(&eval_buf); zval_dtor(&v); } else if (is_callable) { zval args[1]; zval subpats, retval; int i; array_init(&subpats); for (i = 0; i < regs->num_regs; i++) { add_next_index_stringl(&subpats, string + regs->beg[i], regs->end[i] - regs->beg[i]); } ZVAL_COPY_VALUE(&args[0], &subpats); /* null terminate buffer */ smart_str_0(&eval_buf); arg_replace_fci.param_count = 1; arg_replace_fci.params = args; arg_replace_fci.retval = &retval; if (zend_call_function(&arg_replace_fci, &arg_replace_fci_cache) == SUCCESS && !Z_ISUNDEF(retval)) { convert_to_string_ex(&retval); smart_str_appendl(&out_buf, Z_STRVAL(retval), Z_STRLEN(retval)); smart_str_free(&eval_buf); zval_ptr_dtor(&retval); } else { if (!EG(exception)) { php_error_docref(NULL, E_WARNING, "Unable to call custom replacement function"); } } zval_ptr_dtor(&subpats); } n = regs->end[0]; if ((pos - (OnigUChar *)string) < n) { pos = (OnigUChar *)string + n; } else { if (pos < string_lim) { smart_str_appendl(&out_buf, (char *)pos, 1); } pos++; } } else { /* nomatch */ /* stick that last bit of string on our output */ if (string_lim - pos > 0) { smart_str_appendl(&out_buf, (char *)pos, string_lim - pos); } } onig_region_free(regs, 0); } if (description) { efree(description); } if (regs != NULL) { onig_region_free(regs, 1); } smart_str_free(&eval_buf); if (err <= -2) { smart_str_free(&out_buf); RETVAL_FALSE; } else if (out_buf.s) { smart_str_0(&out_buf); RETVAL_STR(out_buf.s); } else { RETVAL_EMPTY_STRING(); } }
static int add_stringl(zval* list, char* id, char* string, uint32_t length) { if(id) return add_assoc_stringl(list, id, string, length); else return add_next_index_stringl(list, string, length); }
static void tokenize(zval *return_value) { zval token; zval keyword; int token_type; zend_bool destroy; int token_line = 1; int need_tokens = -1; // for __halt_compiler lexing. -1 = disabled array_init(return_value); ZVAL_NULL(&token); while ((token_type = lex_scan(&token))) { destroy = 1; switch (token_type) { case T_CLOSE_TAG: if (zendtext[zendleng - 1] != '>') { CG(zend_lineno)++; } case T_OPEN_TAG: case T_OPEN_TAG_WITH_ECHO: case T_WHITESPACE: case T_COMMENT: case T_DOC_COMMENT: destroy = 0; break; } if (token_type >= 256) { array_init(&keyword); add_next_index_long(&keyword, token_type); if (token_type == T_END_HEREDOC) { if (CG(increment_lineno)) { token_line = ++CG(zend_lineno); CG(increment_lineno) = 0; } } add_next_index_stringl(&keyword, (char *)zendtext, zendleng); add_next_index_long(&keyword, token_line); add_next_index_zval(return_value, &keyword); } else { add_next_index_stringl(return_value, (char *)zendtext, zendleng); } if (destroy && Z_TYPE(token) != IS_NULL) { zval_dtor(&token); } ZVAL_NULL(&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) { array_init(&keyword); add_next_index_long(&keyword, T_INLINE_HTML); add_next_index_stringl(&keyword, (char *)zendcursor, zendlimit - zendcursor); add_next_index_long(&keyword, token_line); add_next_index_zval(return_value, &keyword); } break; } } else if (token_type == T_HALT_COMPILER) { need_tokens = 3; } token_line = CG(zend_lineno); } }
/* {{{ proto void run() */ PHP_METHOD(slightphp, run) { zval *zone=NULL; zval *page=NULL; zval *entry=NULL; zval path_array; //{{{ int isPart; zval *path; if (ZEND_NUM_ARGS()>0 && zend_parse_parameters(ZEND_NUM_ARGS() , "z/", &path) != FAILURE) { if (Z_TYPE_P(path)!= IS_STRING){ RETURN_FALSE; } isPart = 1; }else{ isPart = 0; zend_is_auto_global_str(ZEND_STRL("_SERVER")); zval *server_vars; if ((server_vars = zend_hash_str_find(&EG(symbol_table), ZEND_STRL("_SERVER"))) != NULL && Z_TYPE_P(server_vars) == IS_ARRAY){ if((path= zend_hash_str_find(Z_ARRVAL_P(server_vars), ZEND_STRL("PATH_INFO")))!=NULL && Z_TYPE_P(path) == IS_STRING) { // }else if((path= zend_hash_str_find(Z_ARRVAL_P(server_vars), ZEND_STRL("REQUEST_URI")))!=NULL && Z_TYPE_P(path) == IS_STRING) { // }else{ debug("path not set in params or server.path_info, server.request_uri"); RETURN_FALSE; } } } /* Skip leading / */ int len = Z_STRLEN_P(path); int start=0; for(start=0;start<len;start++){ if(*(Z_STRVAL_P(path)+start) != '/'){ break; } } zval url; php_url *resource=NULL; resource = php_url_parse(Z_STRVAL_P(path)+start); if(resource != NULL){ if(resource->path != NULL){ ZVAL_STRING(&url,resource->path); }else{ ZVAL_STRING(&url,Z_STRVAL_P(path)); } php_url_free(resource); }else{ ZVAL_STRING(&url,Z_STRVAL_P(path)); } zend_update_static_property(slightphp_ce_ptr,"pathInfo",sizeof("pathInfo")-1,&url TSRMLS_CC); //zend_print_flat_zval_r(path); //}}} array_init(&path_array); { //{{{ zval quotedFlag; regex_t re; char *regex; regmatch_t subs[1]; int err,size; char *strp = Z_STRVAL(url); char *endp = strp + Z_STRLEN(url); zval *splitFlag = zend_read_static_property(slightphp_ce_ptr,"splitFlag",sizeof("splitFlag")-1,1 ); 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); strp += size; } } if (!err || err == REG_NOMATCH) { size = endp - strp; if(size>0) add_next_index_stringl(&path_array, strp, size); } regfree(&re); } efree(regex); zval_dtor("edFlag); //}}} if((zone = zend_hash_index_find(Z_ARRVAL(path_array), 0)) != NULL ) { } if((page = zend_hash_index_find(Z_ARRVAL(path_array), 1)) != NULL ) { } if((entry = zend_hash_index_find(Z_ARRVAL(path_array), 2)) != NULL) { } } if(!zone){ zone = zend_read_static_property(slightphp_ce_ptr,"defaultZone",sizeof("defaultZone")-1,1 ); add_next_index_string(&path_array, Z_STRVAL_P(zone)); } if(!page){ page = zend_read_static_property(slightphp_ce_ptr,"defaultPage",sizeof("defaultPage")-1,1 ); add_next_index_string(&path_array, Z_STRVAL_P(page)); } if(!entry){ entry = zend_read_static_property(slightphp_ce_ptr,"defaultEntry",sizeof("defaultEntry")-1,1 ); add_next_index_string(&path_array, Z_STRVAL_P(entry)); } //{{{ zval *zoneAlias = zend_read_static_property(slightphp_ce_ptr,"zoneAlias",sizeof("zoneAlias")-1,1 ); if(zoneAlias && Z_TYPE_P(zoneAlias)==IS_ARRAY){ zend_ulong num_key; zend_string *string_key= NULL; HashPosition pos; zval *entry2=NULL; zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(zoneAlias), &pos); for (;; zend_hash_move_forward_ex(Z_ARRVAL_P(zoneAlias), &pos)) { if (NULL == (entry2= zend_hash_get_current_data_ex(Z_ARRVAL_P(zoneAlias), &pos))) { break; } if(strcmp(Z_STRVAL_P(entry2) ,Z_STRVAL_P(zone))==0){ switch (pos = zend_hash_get_current_key_ex(Z_ARRVAL_P(zoneAlias), &string_key, &num_key,&pos)) { case HASH_KEY_IS_STRING: ZVAL_STR_COPY(zone,string_key); break; } } } } //}}} if(!isPart){ zend_update_static_property(slightphp_ce_ptr,"zone",sizeof("zone")-1,zone ); zend_update_static_property(slightphp_ce_ptr,"page",sizeof("page")-1,page ); zend_update_static_property(slightphp_ce_ptr,"entry",sizeof("entry")-1,entry ); }else{ if( strcmp(Z_STRVAL_P(zone),Z_STRVAL_P(zend_read_static_property(slightphp_ce_ptr,"zone",sizeof("zone")-1,1 )))==0 && strcmp(Z_STRVAL_P(page),Z_STRVAL_P(zend_read_static_property(slightphp_ce_ptr,"page",sizeof("page")-1,1 )))==0 && strcmp(Z_STRVAL_P(entry),Z_STRVAL_P(zend_read_static_property(slightphp_ce_ptr,"entry",sizeof("entry")-1,1 )))==0 ){ debug("part ignored [%s]",Z_STRVAL(url)); zval_dtor(&path_array); zval_dtor(&url); return; } } zval *appDir = zend_read_static_property(slightphp_ce_ptr,"appDir",sizeof("appDir")-1,1 ); if(slightphp_load(appDir,zone,page ) == SUCCESS){ zval ret; if(slightphp_run(zone,page,entry,&ret,1,&path_array)==SUCCESS){ zval_dtor(&path_array); zval_dtor(&url); RETURN_ZVAL(&ret,0,1); }; } zval_dtor(&url); zval_dtor(&path_array); RETURN_FALSE; }
/* {{{ php_parserr */ static void php_parserr(PDNS_RECORD pRec, int type_to_fetch, int store, int raw, zval *subarray) { int type; u_long ttl; type = pRec->wType; ttl = pRec->dwTtl; if (type_to_fetch != DNS_TYPE_ANY && type != type_to_fetch) { return; } if (!store) { return; } array_init(subarray); add_assoc_string(subarray, "host", pRec->pName); add_assoc_string(subarray, "class", "IN"); add_assoc_long(subarray, "ttl", ttl); if (raw) { add_assoc_long(subarray, "type", type); add_assoc_stringl(subarray, "data", (char*) &pRec->Data, (uint) pRec->wDataLength); return; } switch (type) { case DNS_TYPE_A: { IN_ADDR ipaddr; ipaddr.S_un.S_addr = (pRec->Data.A.IpAddress); add_assoc_string(subarray, "type", "A"); add_assoc_string(subarray, "ip", inet_ntoa(ipaddr)); break; } case DNS_TYPE_MX: add_assoc_string(subarray, "type", "MX"); add_assoc_long(subarray, "pri", pRec->Data.Srv.wPriority); /* no break; */ case DNS_TYPE_CNAME: if (type == DNS_TYPE_CNAME) { add_assoc_string(subarray, "type", "CNAME"); } /* no break; */ case DNS_TYPE_NS: if (type == DNS_TYPE_NS) { add_assoc_string(subarray, "type", "NS"); } /* no break; */ case DNS_TYPE_PTR: if (type == DNS_TYPE_PTR) { add_assoc_string(subarray, "type", "PTR"); } add_assoc_string(subarray, "target", pRec->Data.MX.pNameExchange); break; /* Not available on windows, the query is possible but there is no DNS_HINFO_DATA structure */ case DNS_TYPE_HINFO: case DNS_TYPE_TEXT: { DWORD i = 0; DNS_TXT_DATA *data_txt = &pRec->Data.TXT; DWORD count = data_txt->dwStringCount; zend_string *txt; char *txt_dst; long txt_len = 0; zval entries; add_assoc_string(subarray, "type", "TXT"); array_init(&entries); for (i = 0; i < count; i++) { txt_len += strlen(data_txt->pStringArray[i]) + 1; } txt = zend_string_safe_alloc(txt_len, 2, 0, 0); txt_dst = txt->val; for (i = 0; i < count; i++) { int len = strlen(data_txt->pStringArray[i]); memcpy(txt_dst, data_txt->pStringArray[i], len); add_next_index_stringl(&entries, data_txt->pStringArray[i], len); txt_dst += len; } txt->len = txt_dst - txt->val; add_assoc_str(subarray, "txt", txt); add_assoc_zval(subarray, "entries", &entries); } break; case DNS_TYPE_SOA: { DNS_SOA_DATA *data_soa = &pRec->Data.Soa; add_assoc_string(subarray, "type", "SOA"); add_assoc_string(subarray, "mname", data_soa->pNamePrimaryServer); add_assoc_string(subarray, "rname", data_soa->pNameAdministrator); add_assoc_long(subarray, "serial", data_soa->dwSerialNo); add_assoc_long(subarray, "refresh", data_soa->dwRefresh); add_assoc_long(subarray, "retry", data_soa->dwRetry); add_assoc_long(subarray, "expire", data_soa->dwExpire); add_assoc_long(subarray, "minimum-ttl", data_soa->dwDefaultTtl); } break; case DNS_TYPE_AAAA: { DNS_AAAA_DATA *data_aaaa = &pRec->Data.AAAA; char buf[sizeof("AAAA:AAAA:AAAA:AAAA:AAAA:AAAA:AAAA:AAAA")]; char *tp = buf; int i; unsigned short out[8]; int have_v6_break = 0, in_v6_break = 0; for (i = 0; i < 4; ++i) { DWORD chunk = data_aaaa->Ip6Address.IP6Dword[i]; out[i * 2] = htons(LOWORD(chunk)); out[i * 2 + 1] = htons(HIWORD(chunk)); } for(i=0; i < 8; i++) { if (out[i] != 0) { if (tp > (u_char *)buf) { in_v6_break = 0; tp[0] = ':'; tp++; } tp += sprintf((char*)tp,"%x", out[i]); } else { if (!have_v6_break) { have_v6_break = 1; in_v6_break = 1; tp[0] = ':'; tp++; } else if (!in_v6_break) { tp[0] = ':'; tp++; tp[0] = '0'; tp++; } } } if (have_v6_break && in_v6_break) { tp[0] = ':'; tp++; } tp[0] = '\0'; add_assoc_string(subarray, "type", "AAAA"); add_assoc_string(subarray, "ipv6", buf); } break; #if 0 /* Won't be implemented. A6 is deprecated. (Pierre) */ case DNS_TYPE_A6: break; #endif case DNS_TYPE_SRV: { DNS_SRV_DATA *data_srv = &pRec->Data.Srv; add_assoc_string(subarray, "type", "SRV"); add_assoc_long(subarray, "pri", data_srv->wPriority); add_assoc_long(subarray, "weight", data_srv->wWeight); add_assoc_long(subarray, "port", data_srv->wPort); add_assoc_string(subarray, "target", data_srv->pNameTarget); } break; #if _MSC_VER >= 1500 case DNS_TYPE_NAPTR: { DNS_NAPTR_DATA * data_naptr = &pRec->Data.Naptr; add_assoc_string(subarray, "type", "NAPTR"); add_assoc_long(subarray, "order", data_naptr->wOrder); add_assoc_long(subarray, "pref", data_naptr->wPreference); add_assoc_string(subarray, "flags", data_naptr->pFlags); add_assoc_string(subarray, "services", data_naptr->pService); add_assoc_string(subarray, "regex", data_naptr->pRegularExpression); add_assoc_string(subarray, "replacement", data_naptr->pReplacement); } break; #endif default: /* unknown type */ ZVAL_UNDEF(subarray); return; } }
/* {{{ 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_GET]), "PATH_INFO", sizeof("PATH_INFO"), (void **) &token) == SUCCESS ){ path = *token; }else if(zend_hash_find(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER]), "PATH_INFO", sizeof("PATH_INFO"), (void **) &token) == SUCCESS ){ path = *token; } } } //}}} 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; }
PHP_METHOD(Phalcon_Http_Client_Adapter_Stream, sendInternal){ zval *stream, *http, *option = NULL, *header, *handler, *base_uri, *url = NULL, *method, *useragent, *timeout; zval *fp = NULL, *meta = NULL, *wrapper_data, *bodystr = NULL, *response; PHALCON_MM_GROW(); stream = phalcon_fetch_nproperty_this(this_ptr, SL("_stream"), PH_NOISY TSRMLS_CC); header = phalcon_fetch_nproperty_this(this_ptr, SL("_header"), PH_NOISY TSRMLS_CC); method = phalcon_fetch_nproperty_this(this_ptr, SL("_method"), PH_NOISY TSRMLS_CC); base_uri = phalcon_fetch_nproperty_this(this_ptr, SL("_base_uri"), PH_NOISY TSRMLS_CC); useragent = phalcon_fetch_nproperty_this(this_ptr, SL("_useragent"), PH_NOISY TSRMLS_CC); timeout = phalcon_fetch_nproperty_this(this_ptr, SL("_timeout"), PH_NOISY TSRMLS_CC); PHALCON_INIT_VAR(http); ZVAL_STRING(http, "http", 1); PHALCON_INIT_NVAR(option); ZVAL_STRING(option, "method", 1); PHALCON_CALL_FUNCTION(NULL, "stream_context_set_option", stream, http, option, method); if (PHALCON_IS_NOT_EMPTY(useragent)) { PHALCON_INIT_NVAR(option); ZVAL_STRING(option, "User-Agent", 1); PHALCON_CALL_METHOD(NULL, header, "set", option, useragent); } PHALCON_CALL_FUNCTION(NULL, "stream_context_set_option", stream, http, option, useragent); PHALCON_INIT_NVAR(option); ZVAL_STRING(option, "timeout", 1); PHALCON_CALL_FUNCTION(NULL, "stream_context_set_option", stream, http, option, timeout); PHALCON_CALL_METHOD(&url, base_uri, "build"); PHALCON_CALL_SELF(NULL, "buildBody"); PHALCON_INIT_VAR(handler); array_init_size(handler, 2); phalcon_array_append(&handler, this_ptr, PH_SEPARATE); add_next_index_stringl(handler, SL("errorHandler"), 1); PHALCON_CALL_FUNCTION(NULL, "set_error_handler", handler); PHALCON_INIT_NVAR(option); ZVAL_STRING(option, "r", 1); PHALCON_CALL_FUNCTION(&fp, "fopen", url, option, PHALCON_GLOBAL(z_false), stream); PHALCON_CALL_FUNCTION(NULL, "restore_error_handler"); PHALCON_CALL_FUNCTION(&meta, "stream_get_meta_data", fp); PHALCON_CALL_FUNCTION(&bodystr, "stream_get_contents", fp); PHALCON_CALL_FUNCTION(NULL, "fclose", fp); PHALCON_INIT_VAR(response); object_init_ex(response, phalcon_http_client_response_ce); PHALCON_CALL_METHOD(NULL, response, "__construct"); if (phalcon_array_isset_string_fetch(&wrapper_data, meta, SS("wrapper_data"))) { PHALCON_CALL_METHOD(NULL, response, "setHeader", wrapper_data); } PHALCON_CALL_METHOD(NULL, response, "setbody", bodystr); RETURN_CTOR(response); }
/** * Initialize the metadata for certain table * * @param Phalcon\Mvc\Model $model * @param string $table * @param string $schema */ PHP_METHOD(Phalcon_Mvc_Model_MetaData, _initializeMetaData){ zval *model = NULL, *table = NULL, *schema = NULL, *key = NULL, *connection = NULL, *exists = NULL; zval *complete_table = NULL, *attributes = NULL, *primary_keys = NULL; zval *non_primary_keys = NULL, *numeric_typed = NULL, *not_null = NULL; zval *field_types = NULL, *identity_field = NULL, *columns = NULL; zval *column = NULL, *field_name = NULL, *table_metadata = NULL; zval *t0 = NULL, *t1 = NULL, *t2 = NULL; zval *i0 = NULL; zval *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL, *r4 = NULL, *r5 = NULL, *r6 = NULL; zval *a0 = NULL; HashTable *ah0; HashPosition hp0; zval **hd; int eval_int; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzz", &model, &table, &schema) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } PHALCON_INIT_VAR(key); PHALCON_CONCAT_VV(key, schema, table); PHALCON_ALLOC_ZVAL_MM(t0); phalcon_read_property(&t0, this_ptr, SL("_metaData"), PH_NOISY_CC); eval_int = phalcon_array_isset(t0, key); if (!eval_int) { PHALCON_INIT_VAR(connection); PHALCON_CALL_METHOD(connection, model, "getconnection", PH_NO_CHECK); PHALCON_INIT_VAR(exists); PHALCON_CALL_METHOD_PARAMS_2(exists, connection, "tableexists", table, schema, PH_NO_CHECK); if (!zend_is_true(exists)) { if (zend_is_true(schema)) { PHALCON_INIT_VAR(complete_table); PHALCON_CONCAT_VSV(complete_table, schema, "\".\"", table); } else { PHALCON_CPY_WRT(complete_table, table); } PHALCON_ALLOC_ZVAL_MM(i0); object_init_ex(i0, phalcon_mvc_model_exception_ce); PHALCON_ALLOC_ZVAL_MM(r0); phalcon_get_class(r0, model TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(r1); PHALCON_CONCAT_SVSV(r1, "Table \"", complete_table, "\" doesn't exist on database when dumping meta-data for ", r0); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(i0, "__construct", r1, PH_CHECK); phalcon_throw_exception(i0 TSRMLS_CC); return; } PHALCON_INIT_VAR(attributes); array_init(attributes); PHALCON_INIT_VAR(primary_keys); array_init(primary_keys); PHALCON_INIT_VAR(non_primary_keys); array_init(non_primary_keys); PHALCON_INIT_VAR(numeric_typed); array_init(numeric_typed); PHALCON_INIT_VAR(not_null); array_init(not_null); PHALCON_INIT_VAR(field_types); array_init(field_types); PHALCON_INIT_VAR(identity_field); ZVAL_BOOL(identity_field, 0); PHALCON_INIT_VAR(columns); PHALCON_CALL_METHOD_PARAMS_2(columns, connection, "describecolumns", table, schema, PH_NO_CHECK); if (!phalcon_valid_foreach(columns TSRMLS_CC)) { return; } ah0 = Z_ARRVAL_P(columns); zend_hash_internal_pointer_reset_ex(ah0, &hp0); fes_c40c_0: if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){ goto fee_c40c_0; } PHALCON_INIT_VAR(column); ZVAL_ZVAL(column, *hd, 1, 0); PHALCON_INIT_VAR(field_name); PHALCON_CALL_METHOD(field_name, column, "getname", PH_NO_CHECK); phalcon_array_append(&attributes, field_name, PH_SEPARATE TSRMLS_CC); PHALCON_INIT_VAR(r2); PHALCON_CALL_METHOD(r2, column, "isprimary", PH_NO_CHECK); if (zend_is_true(r2)) { phalcon_array_append(&primary_keys, field_name, PH_SEPARATE TSRMLS_CC); } else { phalcon_array_append(&non_primary_keys, field_name, PH_SEPARATE TSRMLS_CC); } PHALCON_INIT_VAR(r3); PHALCON_CALL_METHOD(r3, column, "isnumeric", PH_NO_CHECK); if (zend_is_true(r3)) { phalcon_array_update_zval_bool(&numeric_typed, field_name, 1, PH_SEPARATE TSRMLS_CC); } PHALCON_INIT_VAR(r4); PHALCON_CALL_METHOD(r4, column, "isnotnull", PH_NO_CHECK); if (zend_is_true(r4)) { phalcon_array_append(¬_null, field_name, PH_SEPARATE TSRMLS_CC); } PHALCON_INIT_VAR(r5); PHALCON_CALL_METHOD(r5, column, "isautoincrement", PH_NO_CHECK); if (zend_is_true(r5)) { PHALCON_CPY_WRT(identity_field, field_name); } PHALCON_INIT_VAR(r6); PHALCON_CALL_METHOD(r6, column, "gettype", PH_NO_CHECK); phalcon_array_update_zval(&field_types, field_name, &r6, PH_COPY | PH_SEPARATE TSRMLS_CC); zend_hash_move_forward_ex(ah0, &hp0); goto fes_c40c_0; fee_c40c_0: if(0){} PHALCON_INIT_VAR(table_metadata); array_init(table_metadata); phalcon_array_update_long(&table_metadata, 0, &attributes, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_long(&table_metadata, 1, &primary_keys, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_long(&table_metadata, 2, &non_primary_keys, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_long(&table_metadata, 3, ¬_null, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_long(&table_metadata, 4, &field_types, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_long(&table_metadata, 5, &numeric_typed, PH_COPY | PH_SEPARATE TSRMLS_CC); phalcon_array_update_long(&table_metadata, 8, &identity_field, PH_COPY | PH_SEPARATE TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(t1); phalcon_read_property(&t1, this_ptr, SL("_metaData"), PH_NOISY_CC); phalcon_array_update_zval(&t1, key, &table_metadata, PH_COPY TSRMLS_CC); phalcon_update_property_zval(this_ptr, SL("_metaData"), t1 TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(t2); phalcon_read_property(&t2, this_ptr, SL("_changed"), PH_NOISY_CC); if (!zend_is_true(t2)) { PHALCON_ALLOC_ZVAL_MM(a0); array_init(a0); phalcon_array_append(&a0, this_ptr, PH_SEPARATE TSRMLS_CC); add_next_index_stringl(a0, SL("storeMetaData"), 1); PHALCON_CALL_FUNC_PARAMS_1_NORETURN("register_shutdown_function", a0); phalcon_update_property_bool(this_ptr, SL("_changed"), 1 TSRMLS_CC); } } PHALCON_MM_RESTORE(); }
short int php_tmpl_pre_parse(t_template* tmpl) { ulong_pair *point; register uchar *p; uchar *buf; uint buf_len, buf_alloc, buf_this; uint i, j, len, close_idx; t_tmpl_tag *tag, *context; zval **ztag; if(FAILURE == php_tmpl_pre_parse_config(tmpl)) return FAILURE; /* Initialize variables */ PAIR_INIT(point); buf_alloc = TMPL_MAX_TAG_LEN+4; buf = (uchar*)emalloc(buf_alloc); /* Searching algorythm will require larger buffer */ (char*)ZV(tmpl->original) = erealloc(ZV(tmpl->original), ZL(tmpl->original) + MAX( ZL(tmpl->tag_left), MAX( ZL(tmpl->tag_right), MAX( ZL(tmpl->ctx_ol), MAX( ZL(tmpl->ctx_or), MAX( ZL(tmpl->ctx_cl), ZL(tmpl->ctx_cr) ) ) ) ) ) ); /* Obtain positions of all tags and contexts */ php_tmpl_pre_parse_search(tmpl, &point, TMPL_TAG, ZV(tmpl->tag_left), ZL(tmpl->tag_left)); php_tmpl_pre_parse_search(tmpl, &point, TMPL_TAG_END, ZV(tmpl->tag_right), ZL(tmpl->tag_right)); php_tmpl_pre_parse_search(tmpl, &point, TMPL_CONTEXT_OPEN_LEFT, ZV(tmpl->ctx_ol), ZL(tmpl->ctx_ol)); php_tmpl_pre_parse_search(tmpl, &point, TMPL_CONTEXT_OPEN_RIGHT, ZV(tmpl->ctx_or), ZL(tmpl->ctx_or)); php_tmpl_pre_parse_search(tmpl, &point, TMPL_CONTEXT_CLOSE_LEFT, ZV(tmpl->ctx_cl), ZL(tmpl->ctx_cl)); if(ZL(tmpl->ctx_cr)) php_tmpl_pre_parse_search(tmpl, &point, TMPL_CONTEXT_CLOSE_RIGHT, ZV(tmpl->ctx_cr), ZL(tmpl->ctx_cr)); if(0 == point[0].r) { TMPL_PRE_PARSE_CLEANUP; return SUCCESS; } qsort(&point[1], point[0].r, sizeof(ulong_pair), ULONG_PAIR_COMPARE); strcpy(buf, "/"); buf_len = buf_this = 1; /* Add root context */ TAG_INIT(tag); tag->loff = 0; tag->roff = ZL(tmpl->original); tag->typ = TMPL_CONTEXT; ZVAL_STRINGL(tag->name, "/", 1, 1); add_assoc_stringl(tmpl->tags, buf, (char*)tag, sizeof(t_tmpl_tag), 0); context = tag; context->size = ZL(tmpl->original); /* Pre parse template */ for(i=1; i <= point[0].r; i++) { switch(point[i].r) { case TMPL_TAG: p = ZV(tmpl->original) + point[i].l + ZL(tmpl->tag_left); TMPL_PRE_PARSE_GET_LEN(TMPL_TAG_END, ZL(tmpl->tag_left)); if(buf_alloc < buf_len+len+1) { while(buf_alloc < buf_len+len+1) buf_alloc += TMPL_MAX_TAG_LEN; buf = (char*)erealloc(buf, buf_alloc); } if(buf_len > 1) buf[buf_len++] = '/'; for(j=0; j < len; j++) buf[buf_len++] = tolower(*(p-len+j)); buf[buf_len] = 0; TAG_INIT(tag); tag->loff = point[i].l; tag->roff = point[close_idx].l + ZL(tmpl->tag_right); tag->size = (tag->roff - tag->loff); tag->typ = TMPL_TAG; tag->tag_num = 1; tag->ctx = context; ZVAL_STRINGL(tag->name, buf+buf_len-len, len, 1); if(FAILURE == zend_hash_find(Z_ARRVAL_P(tmpl->tags), buf, buf_len+1, (void*)&ztag)) { /* There's no the tag defined in the current context. Creating one */ add_assoc_stringl(tmpl->tags, buf, (char*)tag, sizeof(t_tmpl_tag), 0); context->tag_num++; } else { /* add another instance of the tag in the same context */ (Z_TMPL_TAG(ztag)->tag_num)++; add_next_index_stringl(tmpl->dup_tag, (char*)tag, sizeof(t_tmpl_tag), 0); } context->size -= tag->size; while(buf_len > 1 && buf[buf_len-1] != '/') buf[--buf_len] = 0; if(buf_len > 1) buf[--buf_len] = 0; i = close_idx; break; case TMPL_CONTEXT_OPEN_LEFT: p = ZV(tmpl->original) + point[i].l + ZL(tmpl->ctx_ol); TMPL_PRE_PARSE_GET_LEN(TMPL_CONTEXT_OPEN_RIGHT, ZL(tmpl->ctx_ol)); if(buf_alloc < buf_len+len+1) { while(buf_alloc < buf_len+len+1) buf_alloc += TMPL_MAX_TAG_LEN; buf = (char*)erealloc(buf, buf_alloc); } if(buf_len > 1) buf[buf_len++] = '/'; buf_this = buf_len; for(j=0; j < len; j++) buf[buf_len++] = tolower(*(p-len+j)); buf[buf_len] = 0; if(SUCCESS == zend_hash_find(Z_ARRVAL_P(tmpl->tags), buf, buf_len+1, (void*)&ztag)) { php_error(E_ERROR, "Duplicate context \"%s\" in template (line: %d)", buf, php_tmpl_line_num(tmpl, p)); TMPL_PRE_PARSE_CLEANUP; return FAILURE; } TAG_INIT(tag); tag->loff = point[i].l; tag->typ = TMPL_CONTEXT; tag->ctx = context; ZVAL_STRINGL(tag->name, buf+buf_len-len, len, 1); add_assoc_stringl(tmpl->tags, buf, (char*)tag, sizeof(t_tmpl_tag), 0); context->tag_num++; context = tag; i = close_idx; break; case TMPL_CONTEXT_CLOSE_LEFT: p = ZV(tmpl->original) + point[i].l + ZL(tmpl->ctx_cl); if(ZL(tmpl->ctx_cr)) { TMPL_PRE_PARSE_GET_LEN(TMPL_CONTEXT_CLOSE_RIGHT, ZL(tmpl->ctx_cl)); for(j=0; j < len; j++) if(buf[buf_this+j] != tolower(*(p-len+j))) break; if(j < len) continue; } tag = context; tag->roff = ZL(tmpl->ctx_cr) ? point[close_idx].l + ZL(tmpl->ctx_cr) : point[i].l + ZL(tmpl->ctx_cl); tag->size += (tag->roff - tag->loff); while(buf_len > 1 && buf[buf_len-1] != '/') buf[--buf_len] = 0; if(buf_len > 1) buf[--buf_len] = 0; buf_this = buf_len; while(buf_this > 1 && buf[buf_this-1] != '/') --buf_this; if(FAILURE == zend_hash_find(Z_ARRVAL_P(tmpl->tags), buf, buf_len+1, (void*)&ztag)) { php_error(E_ERROR, "Can't find parent context in template. You should not see this message"); TMPL_PRE_PARSE_CLEANUP; return FAILURE; } context = (t_tmpl_tag*)Z_STRVAL_PP(ztag); context->size -= tag->size; if(ZL(tmpl->ctx_cr)) i = close_idx; break; } } if(buf_len != 1) { php_error(E_ERROR, "Can't continue with an unterminated context \"%s\" in template (line:%d)", buf, php_tmpl_line_num(tmpl, ZV(tmpl->original) + context->loff)); TMPL_PRE_PARSE_CLEANUP; return FAILURE; } tmpl->size = context->size; TMPL_PRE_PARSE_CLEANUP; return SUCCESS; }
/** * Rollbacks the transaction * * @param string $rollbackMessage * @param Phalcon_Model_Base $rollbackRecord * @return boolean */ PHP_METHOD(Phalcon_Transaction, rollback){ zval *v0 = NULL, *v1 = NULL, *v2 = NULL; zval *t0 = NULL, *t1 = NULL, *t2 = NULL, *t3 = NULL, *t4 = NULL; zval *a0 = NULL, *a1 = NULL; zval *r0 = NULL, *r1 = NULL; zval *i0 = NULL; zval *p2[] = { NULL, NULL }; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|zz", &v0, &v1) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (!v0) { PHALCON_INIT_VAR(v0); ZVAL_STRING(v0, "", 1); } else { PHALCON_SEPARATE_PARAM(v0); } if (!v1) { PHALCON_INIT_VAR(v1); ZVAL_NULL(v1); } PHALCON_ALLOC_ZVAL_MM(t0); phalcon_read_property(&t0, this_ptr, "_manager", sizeof("_manager")-1, PHALCON_NOISY_FETCH TSRMLS_CC); if (!PHALCON_COMPARE_STRING(t0, "")) { PHALCON_INIT_VAR(a0); array_init(a0); PHALCON_ALLOC_ZVAL_MM(t1); phalcon_read_property(&t1, this_ptr, "_manager", sizeof("_manager")-1, PHALCON_NOISY_FETCH TSRMLS_CC); Z_ADDREF_P(t1); PHALCON_SEPARATE_ARRAY(a0); add_next_index_zval(a0, t1); add_next_index_stringl(a0, "notifyRollback", strlen("notifyRollback"), 1); Z_ADDREF_P(a0); PHALCON_INIT_VAR(a1); array_init(a1); Z_ADDREF_P(this_ptr); PHALCON_SEPARATE_ARRAY(a1); add_next_index_zval(a1, this_ptr); Z_ADDREF_P(a1); PHALCON_CALL_FUNC_PARAMS_2_NORETURN("call_user_func_array", a0, a1, 0x001); Z_DELREF_P(a0); Z_DELREF_P(a1); } PHALCON_ALLOC_ZVAL_MM(r0); PHALCON_ALLOC_ZVAL_MM(t2); phalcon_read_property(&t2, this_ptr, "_connection", sizeof("_connection")-1, PHALCON_NOISY_FETCH TSRMLS_CC); PHALCON_CALL_METHOD(r0, t2, "rollback", PHALCON_CALL_DEFAULT); PHALCON_CPY_WRT(v2, r0); PHALCON_INIT_VAR(t3); ZVAL_BOOL(t3, 1); PHALCON_ALLOC_ZVAL_MM(r1); is_equal_function(r1, v2, t3 TSRMLS_CC); if (zend_is_true(r1)) { if (PHALCON_COMPARE_STRING(v0, "")) { PHALCON_INIT_VAR(v0); ZVAL_STRING(v0, "Transaction aborted", 1); } if (zend_is_true(v1)) { phalcon_update_property_zval(this_ptr, "_rollbackRecord", strlen("_rollbackRecord"), v1 TSRMLS_CC); } PHALCON_ALLOC_ZVAL_MM(i0); object_init_ex(i0, phalcon_transaction_failed_class_entry); Z_ADDREF_P(v0); p2[0] = v0; PHALCON_ALLOC_ZVAL_MM(t4); phalcon_read_property(&t4, this_ptr, "_rollbackRecord", sizeof("_rollbackRecord")-1, PHALCON_NOISY_FETCH TSRMLS_CC); Z_ADDREF_P(t4); p2[1] = t4; PHALCON_CALL_METHOD_PARAMS_NORETURN(i0, "__construct", 2, p2, PHALCON_CALL_CHECK); Z_DELREF_P(p2[0]); Z_DELREF_P(p2[1]); zend_throw_exception_object(i0 TSRMLS_CC); Z_ADDREF_P(i0); PHALCON_MM_RESTORE(); return; } PHALCON_MM_RESTORE(); RETURN_NULL(); }
/** * Dispatches a controller action taking into account the routing parameters * * @param Phalcon_Request $request * @param Phalcon_Response $response * @param Phalcon_View $view * @param Phalcon_Model_Manager $model * @return Phalcon_Controller */ PHP_METHOD(Phalcon_Dispatcher, dispatch){ zval *request = NULL, *response = NULL, *view = NULL, *model = NULL, *controllers_dir = NULL; zval *value = NULL, *controller = NULL, *number_dispatches = NULL; zval *controller_name = NULL, *controllers = NULL, *controller_class = NULL; zval *controller_path = NULL, *params = NULL, *action_name = NULL; zval *action_method = NULL; zval *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL, *r4 = NULL, *r5 = NULL, *r6 = NULL; zval *r7 = NULL, *r8 = NULL, *r9 = NULL, *r10 = NULL, *r11 = NULL, *r12 = NULL; zval *t0 = NULL, *t1 = NULL, *t2 = NULL, *t3 = NULL, *t4 = NULL, *t5 = NULL, *t6 = NULL; zval *t7 = NULL, *t8 = NULL, *t9 = NULL, *t10 = NULL; zval *c0 = NULL, *c1 = NULL, *c2 = NULL; zval *i0 = NULL; zval *a0 = NULL, *a1 = NULL; zval *p0[] = { NULL, NULL, NULL, NULL, NULL }; int eval_int; zend_class_entry *ce0; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz|zz", &request, &response, &view, &model) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (!view) { PHALCON_INIT_VAR(view); ZVAL_NULL(view); } if (!model) { PHALCON_INIT_VAR(model); ZVAL_NULL(model); } PHALCON_ALLOC_ZVAL_MM(r0); PHALCON_ALLOC_ZVAL_MM(t0); phalcon_read_property(&t0, this_ptr, SL("_basePath"), PHALCON_NOISY TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(t1); phalcon_read_property(&t1, this_ptr, SL("_controllersDir"), PHALCON_NOISY TSRMLS_CC); PHALCON_CONCAT_VV(r0, t0, t1); PHALCON_CPY_WRT(controllers_dir, r0); PHALCON_INIT_VAR(value); ZVAL_NULL(value); PHALCON_INIT_VAR(controller); ZVAL_NULL(controller); PHALCON_INIT_VAR(number_dispatches); ZVAL_LONG(number_dispatches, 0); phalcon_update_property_bool(this_ptr, SL("_finished"), 0 TSRMLS_CC); ws_e10f_0: PHALCON_INIT_VAR(t2); phalcon_read_property(&t2, this_ptr, SL("_finished"), PHALCON_NOISY TSRMLS_CC); if (zend_is_true(t2)) { goto we_e10f_0; } phalcon_update_property_bool(this_ptr, SL("_finished"), 1 TSRMLS_CC); PHALCON_INIT_VAR(t3); phalcon_read_property(&t3, this_ptr, SL("_controllerName"), PHALCON_NOISY TSRMLS_CC); PHALCON_CPY_WRT(controller_name, t3); if (!zend_is_true(controller_name)) { PHALCON_INIT_VAR(t4); phalcon_read_property(&t4, this_ptr, SL("_defaultController"), PHALCON_NOISY TSRMLS_CC); PHALCON_CPY_WRT(controller_name, t4); phalcon_update_property_zval(this_ptr, SL("_controllerName"), controller_name TSRMLS_CC); } PHALCON_INIT_VAR(t5); phalcon_read_property(&t5, this_ptr, SL("_controllers"), PHALCON_NOISY TSRMLS_CC); PHALCON_CPY_WRT(controllers, t5); PHALCON_INIT_VAR(r1); PHALCON_INIT_VAR(r2); PHALCON_CALL_STATIC_PARAMS_1(r2, "phalcon_text", "camelize", controller_name); PHALCON_CONCAT_VS(r1, r2, "Controller"); PHALCON_CPY_WRT(controller_class, r1); eval_int = phalcon_array_isset(controllers, controller_class); if (!eval_int) { PHALCON_INIT_VAR(c0); ZVAL_BOOL(c0, 0); PHALCON_INIT_VAR(r3); PHALCON_CALL_FUNC_PARAMS_2(r3, "class_exists", controller_class, c0); if (!zend_is_true(r3)) { PHALCON_INIT_VAR(r4); PHALCON_CONCAT_VVS(r4, controllers_dir, controller_class, ".php"); PHALCON_CPY_WRT(controller_path, r4); if (phalcon_file_exists(controller_path TSRMLS_CC) == SUCCESS) { if (phalcon_require(controller_path TSRMLS_CC) == FAILURE) { return; } } else { PHALCON_INIT_VAR(r5); PHALCON_CONCAT_SVS(r5, "File for controller class ", controller_class, " doesn't exist"); PHALCON_CALL_METHOD_PARAMS_2_NORETURN(this_ptr, "_throwdispatchexception", response, r5, PHALCON_NO_CHECK); } PHALCON_INIT_VAR(c1); ZVAL_BOOL(c1, 0); PHALCON_INIT_VAR(r6); PHALCON_CALL_FUNC_PARAMS_2(r6, "class_exists", controller_class, c1); if (!zend_is_true(r6)) { PHALCON_INIT_VAR(r7); PHALCON_CONCAT_SVS(r7, "Class ", controller_class, " was not found on controller file"); PHALCON_CALL_METHOD_PARAMS_2_NORETURN(this_ptr, "_throwdispatchexception", response, r7, PHALCON_NO_CHECK); } } ce0 = phalcon_fetch_class(controller_class TSRMLS_CC); PHALCON_INIT_VAR(i0); object_init_ex(i0, ce0); p0[0] = this_ptr; p0[1] = request; p0[2] = response; p0[3] = view; p0[4] = model; PHALCON_CALL_METHOD_PARAMS_NORETURN(i0, "__construct", 5, p0, PHALCON_CHECK); PHALCON_CPY_WRT(controller, i0); if (phalcon_method_exists_ex(controller, SL("initialize") TSRMLS_CC) == SUCCESS) { PHALCON_CALL_METHOD_NORETURN(controller, "initialize", PHALCON_NO_CHECK); } PHALCON_INIT_VAR(t6); phalcon_read_property(&t6, this_ptr, SL("_controllers"), PHALCON_NOISY TSRMLS_CC); phalcon_array_update(&t6, controller_class, &controller, PHALCON_NO_SEPARATE_THX, PHALCON_COPY, PHALCON_NO_CTOR TSRMLS_CC); phalcon_update_property_zval(this_ptr, SL("_controllers"), t6 TSRMLS_CC); } else { PHALCON_INIT_VAR(r8); phalcon_array_fetch(&r8, controllers, controller_class, PHALCON_NOISY TSRMLS_CC); PHALCON_CPY_WRT(controller, r8); } PHALCON_INIT_VAR(t7); phalcon_read_property(&t7, this_ptr, SL("_params"), PHALCON_NOISY TSRMLS_CC); PHALCON_CPY_WRT(params, t7); PHALCON_INIT_VAR(t8); phalcon_read_property(&t8, this_ptr, SL("_actionName"), PHALCON_NOISY TSRMLS_CC); PHALCON_CPY_WRT(action_name, t8); if (!zend_is_true(action_name)) { PHALCON_INIT_VAR(t9); phalcon_read_property(&t9, this_ptr, SL("_defaultAction"), PHALCON_NOISY TSRMLS_CC); PHALCON_CPY_WRT(action_name, t9); phalcon_update_property_zval(this_ptr, SL("_actionName"), action_name TSRMLS_CC); } if (phalcon_method_exists_ex(controller, SL("beforedispatch") TSRMLS_CC) == SUCCESS) { PHALCON_INIT_VAR(r9); PHALCON_CALL_METHOD_PARAMS_3(r9, controller, "beforedispatch", controller_name, action_name, params, PHALCON_NO_CHECK); if (Z_TYPE_P(r9) == IS_BOOL && !Z_BVAL_P(r9)) { PHALCON_INIT_VAR(value); ZVAL_BOOL(value, 0); goto we_e10f_0; } } PHALCON_INIT_VAR(r10); PHALCON_CONCAT_VS(r10, action_name, "Action"); PHALCON_CPY_WRT(action_method, r10); if (phalcon_method_exists(controller, action_method TSRMLS_CC) == SUCCESS) { PHALCON_INIT_VAR(a0); array_init(a0); phalcon_array_append(&a0, controller, PHALCON_SEPARATE_PLZ TSRMLS_CC); phalcon_array_append(&a0, action_method, PHALCON_SEPARATE_PLZ TSRMLS_CC); PHALCON_INIT_VAR(value); PHALCON_CALL_FUNC_PARAMS_2(value, "call_user_func_array", a0, params); } else { if (phalcon_method_exists_ex(controller, SL("notfoundaction") TSRMLS_CC) == SUCCESS) { PHALCON_INIT_VAR(a1); array_init(a1); phalcon_array_append(&a1, controller, PHALCON_SEPARATE_PLZ TSRMLS_CC); add_next_index_stringl(a1, SL("notFoundAction"), 1); PHALCON_INIT_VAR(value); PHALCON_CALL_FUNC_PARAMS_2(value, "call_user_func_array", a1, params); } else { PHALCON_INIT_VAR(r11); PHALCON_CONCAT_SVSVS(r11, "Action '", action_name, "' was not found on controller '", controller_name, "'"); PHALCON_CALL_METHOD_PARAMS_2_NORETURN(this_ptr, "_throwdispatchexception", response, r11, PHALCON_NO_CHECK); } } if (phalcon_method_exists_ex(controller, SL("afterdispatch") TSRMLS_CC) == SUCCESS) { PHALCON_CALL_METHOD_PARAMS_3_NORETURN(controller, "afterdispatch", controller_name, action_name, params, PHALCON_NO_CHECK); } PHALCON_SEPARATE(number_dispatches); increment_function(number_dispatches); PHALCON_INIT_VAR(t10); ZVAL_LONG(t10, 256); PHALCON_INIT_VAR(r12); is_smaller_function(r12, t10, number_dispatches TSRMLS_CC); if (zend_is_true(r12)) { PHALCON_INIT_VAR(c2); ZVAL_STRING(c2, "Dispatcher has detected a cyclic routing causing stability problems", 1); PHALCON_CALL_METHOD_PARAMS_2_NORETURN(this_ptr, "_throwdispatchexception", response, c2, PHALCON_NO_CHECK); } goto ws_e10f_0; we_e10f_0: phalcon_update_property_zval(this_ptr, SL("_returnedValue"), value TSRMLS_CC); phalcon_update_property_zval(this_ptr, SL("_lastController"), controller TSRMLS_CC); RETURN_CHECK_CTOR(controller); }
static zend_bool tokenize(zval *return_value, zend_string *source) { zval source_zval; zend_lex_state original_lex_state; zval token; zval keyword; int token_type; int token_line = 1; int need_tokens = -1; /* for __halt_compiler lexing. -1 = disabled */ ZVAL_STR_COPY(&source_zval, source); zend_save_lexical_state(&original_lex_state); if (zend_prepare_string_for_scanning(&source_zval, "") == FAILURE) { zend_restore_lexical_state(&original_lex_state); return 0; } LANG_SCNG(yy_state) = yycINITIAL; array_init(return_value); ZVAL_UNDEF(&token); while ((token_type = lex_scan(&token))) { if (token_type == T_CLOSE_TAG && zendtext[zendleng - 1] != '>') { CG(zend_lineno)++; } if (token_type >= 256) { array_init(&keyword); add_next_index_long(&keyword, token_type); if (token_type == T_END_HEREDOC) { if (CG(increment_lineno)) { token_line = ++CG(zend_lineno); CG(increment_lineno) = 0; } } add_next_index_stringl(&keyword, (char *)zendtext, zendleng); add_next_index_long(&keyword, token_line); add_next_index_zval(return_value, &keyword); } else { add_next_index_stringl(return_value, (char *)zendtext, zendleng); } if (Z_TYPE(token) != IS_UNDEF) { zval_dtor(&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) { array_init(&keyword); add_next_index_long(&keyword, T_INLINE_HTML); add_next_index_stringl(&keyword, (char *)zendcursor, zendlimit - zendcursor); add_next_index_long(&keyword, token_line); add_next_index_zval(return_value, &keyword); } break; } } else if (token_type == T_HALT_COMPILER) { need_tokens = 3; } token_line = CG(zend_lineno); } zval_dtor(&source_zval); zend_restore_lexical_state(&original_lex_state); return 1; }
/* {{{ 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, char *cmd, zval *array, zval *return_value) { FILE *fp; char *buf; size_t l = 0; 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; } if (type == 1) { PHPWRITE(buf, bufl); if (php_output_get_level() < 1) { sapi_flush(); } } else if (type == 2) { /* strip trailing whitespaces */ l = bufl; while (l >= 1 && l-- && isspace(((unsigned char *)buf)[l])); if (l != (bufl - 1)) { bufl = l + 1; buf[bufl] = '\0'; } add_next_index_stringl(array, buf, bufl); } b = buf; } if (bufl) { /* strip trailing whitespaces if we have not done so already */ if ((type == 2 && buf != b) || type != 2) { l = bufl; while (l >= 1 && l-- && isspace(((unsigned char *)buf)[l])); if (l != (bufl - 1)) { bufl = l + 1; buf[bufl] = '\0'; } if (type == 2) { add_next_index_stringl(array, buf, bufl); } } /* Return last line from the shell command */ RETVAL_STRINGL(buf, bufl); } else { /* should return NULL, but for BC we return "" */ RETVAL_EMPTY_STRING(); } } else { while((bufl = php_stream_read(stream, buf, EXEC_INPUT_BUF)) > 0) { PHPWRITE(buf, bufl); } } 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; goto done; }
static int add_blacklist_path(zend_blacklist_entry *p, zval *return_value) { add_next_index_stringl(return_value, p->path, p->path_length); return 0; }
/** * Rollbacks the transaction * * @param string $rollbackMessage * @param Phalcon\Mvc\Model $rollbackRecord * @return boolean */ PHP_METHOD(Phalcon_Mvc_Model_Transaction, rollback){ zval *rollback_message = NULL, *rollback_record = NULL; zval *manager = NULL, *call_object = NULL, *arguments = NULL, *connection = NULL; zval *success = NULL, *exception = NULL; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|zz", &rollback_message, &rollback_record) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (!rollback_message) { PHALCON_ALLOC_ZVAL_MM(rollback_message); ZVAL_NULL(rollback_message); } else { PHALCON_SEPARATE_PARAM(rollback_message); } if (!rollback_record) { PHALCON_ALLOC_ZVAL_MM(rollback_record); ZVAL_NULL(rollback_record); } else { PHALCON_SEPARATE_PARAM(rollback_record); } PHALCON_INIT_VAR(manager); phalcon_read_property(&manager, this_ptr, SL("_manager"), PH_NOISY_CC); if (zend_is_true(manager)) { PHALCON_INIT_VAR(call_object); array_init(call_object); phalcon_array_append(&call_object, manager, PH_SEPARATE TSRMLS_CC); add_next_index_stringl(call_object, SL("notifyRollback"), 1); PHALCON_INIT_VAR(arguments); array_init(arguments); phalcon_array_append(&arguments, this_ptr, PH_SEPARATE TSRMLS_CC); PHALCON_CALL_FUNC_PARAMS_2_NORETURN("call_user_func_array", call_object, arguments); } PHALCON_INIT_VAR(connection); phalcon_read_property(&connection, this_ptr, SL("_connection"), PH_NOISY_CC); PHALCON_INIT_VAR(success); PHALCON_CALL_METHOD(success, connection, "rollback", PH_NO_CHECK); if (zend_is_true(success)) { if (!zend_is_true(rollback_message)) { PHALCON_INIT_VAR(rollback_message); ZVAL_STRING(rollback_message, "Transaction aborted", 1); } if (zend_is_true(rollback_record)) { phalcon_update_property_zval(this_ptr, SL("_rollbackRecord"), rollback_record TSRMLS_CC); } PHALCON_INIT_VAR(rollback_record); phalcon_read_property(&rollback_record, this_ptr, SL("_rollbackRecord"), PH_NOISY_CC); PHALCON_INIT_VAR(exception); object_init_ex(exception, phalcon_mvc_model_transaction_failed_ce); PHALCON_CALL_METHOD_PARAMS_2_NORETURN(exception, "__construct", rollback_message, rollback_record, PH_CHECK); phalcon_throw_exception(exception TSRMLS_CC); return; } PHALCON_MM_RESTORE(); }
static inline int phpdbg_call_register(phpdbg_param_t *stack) /* {{{ */ { phpdbg_param_t *name = NULL; if (stack->type == STACK_PARAM) { char *lc_name; name = stack->next; if (!name || name->type != STR_PARAM) { return FAILURE; } lc_name = zend_str_tolower_dup(name->str, name->len); if (zend_hash_str_exists(&PHPDBG_G(registered), lc_name, name->len)) { zval fretval; zend_fcall_info fci; memset(&fci, 0, sizeof(zend_fcall_info)); ZVAL_STRINGL(&fci.function_name, lc_name, name->len); fci.size = sizeof(zend_fcall_info); fci.function_table = &PHPDBG_G(registered); fci.symbol_table = zend_rebuild_symbol_table(); fci.object = NULL; fci.retval = &fretval; fci.no_separation = 1; if (name->next) { zval params; phpdbg_param_t *next = name->next; array_init(¶ms); while (next) { char *buffered = NULL; switch (next->type) { case OP_PARAM: case COND_PARAM: case STR_PARAM: add_next_index_stringl(¶ms, next->str, next->len); break; case NUMERIC_PARAM: add_next_index_long(¶ms, next->num); break; case METHOD_PARAM: spprintf(&buffered, 0, "%s::%s", next->method.class, next->method.name); add_next_index_string(¶ms, buffered); break; case NUMERIC_METHOD_PARAM: spprintf(&buffered, 0, "%s::%s#%ld", next->method.class, next->method.name, next->num); add_next_index_string(¶ms, buffered); break; case NUMERIC_FUNCTION_PARAM: spprintf(&buffered, 0, "%s#%ld", next->str, next->num); add_next_index_string(¶ms, buffered); break; case FILE_PARAM: spprintf(&buffered, 0, "%s:%ld", next->file.name, next->file.line); add_next_index_string(¶ms, buffered); break; case NUMERIC_FILE_PARAM: spprintf(&buffered, 0, "%s:#%ld", next->file.name, next->file.line); add_next_index_string(¶ms, buffered); break; default: { /* not yet */ } } next = next->next; } zend_fcall_info_args(&fci, ¶ms); } else {
PHP_METHOD(Phalcon_Model_MetaData, _initializeMetaData){ zval *model = NULL, *table = NULL, *schema = NULL, *key = NULL, *connection = NULL, *is_view = NULL; zval *exists = NULL, *meta_datas = NULL, *attributes = NULL, *primary_keys = NULL; zval *non_primary_keys = NULL, *numeric_typed = NULL, *not_null = NULL; zval *field_types = NULL, *identity_field = NULL, *meta_data = NULL; zval *field_name = NULL, *type = NULL, *table_metadata = NULL; zval *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL, *r4 = NULL, *r5 = NULL, *r6 = NULL; zval *r7 = NULL, *r8 = NULL, *r9 = NULL, *r10 = NULL, *r11 = NULL, *r12 = NULL, *r13 = NULL; zval *r14 = NULL, *r15 = NULL, *r16 = NULL, *r17 = NULL; zval *t0 = NULL, *t1 = NULL, *t2 = NULL, *t3 = NULL, *t4 = NULL, *t5 = NULL; zval *i0 = NULL; zval *a0 = NULL, *a1 = NULL, *a2 = NULL, *a3 = NULL, *a4 = NULL, *a5 = NULL, *a6 = NULL; zval *a7 = NULL; zval *c0 = NULL, *c1 = NULL, *c2 = NULL, *c3 = NULL; HashTable *ah0; HashPosition hp0; zval **hd; int eval_int; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzz", &model, &table, &schema) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } PHALCON_ALLOC_ZVAL_MM(r0); PHALCON_CONCAT_VV(r0, schema, table); PHALCON_CPY_WRT(key, r0); PHALCON_ALLOC_ZVAL_MM(t0); phalcon_read_property(&t0, this_ptr, SL("_metaData"), PHALCON_NOISY TSRMLS_CC); eval_int = phalcon_array_isset(t0, key); if (!eval_int) { PHALCON_ALLOC_ZVAL_MM(r1); PHALCON_CALL_METHOD(r1, model, "getconnection", PHALCON_NO_CHECK); PHALCON_CPY_WRT(connection, r1); PHALCON_ALLOC_ZVAL_MM(r2); PHALCON_CALL_METHOD(r2, model, "isview", PHALCON_NO_CHECK); PHALCON_CPY_WRT(is_view, r2); if (!zend_is_true(is_view)) { PHALCON_ALLOC_ZVAL_MM(r3); PHALCON_CALL_METHOD_PARAMS_2(r3, connection, "tableexists", table, schema, PHALCON_NO_CHECK); PHALCON_CPY_WRT(exists, r3); } else { PHALCON_ALLOC_ZVAL_MM(r4); PHALCON_CALL_METHOD_PARAMS_2(r4, connection, "viewexists", table, schema, PHALCON_NO_CHECK); PHALCON_CPY_WRT(exists, r4); } if (!zend_is_true(exists)) { PHALCON_ALLOC_ZVAL_MM(i0); object_init_ex(i0, phalcon_model_exception_ce); PHALCON_ALLOC_ZVAL_MM(r5); PHALCON_ALLOC_ZVAL_MM(r6); phalcon_get_class(r6, model TSRMLS_CC); PHALCON_CONCAT_SVSVSV(r5, "Table \"", schema, "\".\"", table, "\" doesn't exist on database when dumping information for ", r6); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(i0, "__construct", r5, PHALCON_CHECK); phalcon_throw_exception(i0 TSRMLS_CC); return; } else { if (zend_is_true(is_view)) { PHALCON_ALLOC_ZVAL_MM(r7); PHALCON_CALL_METHOD_PARAMS_2(r7, connection, "describeview", table, schema, PHALCON_NO_CHECK); PHALCON_CPY_WRT(meta_datas, r7); } else { PHALCON_ALLOC_ZVAL_MM(r8); PHALCON_CALL_METHOD_PARAMS_2(r8, connection, "describetable", table, schema, PHALCON_NO_CHECK); PHALCON_CPY_WRT(meta_datas, r8); } PHALCON_INIT_VAR(a0); array_init(a0); PHALCON_CPY_WRT(attributes, a0); PHALCON_INIT_VAR(a1); array_init(a1); PHALCON_CPY_WRT(primary_keys, a1); PHALCON_INIT_VAR(a2); array_init(a2); PHALCON_CPY_WRT(non_primary_keys, a2); PHALCON_INIT_VAR(a3); array_init(a3); PHALCON_CPY_WRT(numeric_typed, a3); PHALCON_INIT_VAR(a4); array_init(a4); PHALCON_CPY_WRT(not_null, a4); PHALCON_INIT_VAR(a5); array_init(a5); PHALCON_CPY_WRT(field_types, a5); PHALCON_INIT_VAR(identity_field); ZVAL_BOOL(identity_field, 0); if (phalcon_valid_foreach(meta_datas TSRMLS_CC)) { ah0 = Z_ARRVAL_P(meta_datas); zend_hash_internal_pointer_reset_ex(ah0, &hp0); fes_f5c6_0: if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){ goto fee_f5c6_0; } PHALCON_INIT_VAR(meta_data); ZVAL_ZVAL(meta_data, *hd, 1, 0); PHALCON_INIT_VAR(r9); phalcon_array_fetch_string(&r9, meta_data, SL("Field"), PHALCON_NOISY TSRMLS_CC); PHALCON_CPY_WRT(field_name, r9); phalcon_array_append(&attributes, field_name, PHALCON_SEPARATE_PLZ TSRMLS_CC); PHALCON_INIT_VAR(r10); phalcon_array_fetch_string(&r10, meta_data, SL("Key"), PHALCON_NOISY TSRMLS_CC); if (PHALCON_COMPARE_STRING(r10, "PRI")) { phalcon_array_append(&primary_keys, field_name, PHALCON_SEPARATE_PLZ TSRMLS_CC); } else { phalcon_array_append(&non_primary_keys, field_name, PHALCON_SEPARATE_PLZ TSRMLS_CC); } PHALCON_INIT_VAR(r11); phalcon_array_fetch_string(&r11, meta_data, SL("Type"), PHALCON_NOISY TSRMLS_CC); PHALCON_CPY_WRT(type, r11); phalcon_array_update(&field_types, field_name, &type, PHALCON_SEPARATE_PLZ, PHALCON_COPY, PHALCON_NO_CTOR TSRMLS_CC); PHALCON_INIT_VAR(c0); ZVAL_STRING(c0, "char", 1); PHALCON_INIT_VAR(r12); phalcon_fast_strpos(r12, type, c0 TSRMLS_CC); if (Z_TYPE_P(r12) == IS_BOOL && !Z_BVAL_P(r12)) { PHALCON_INIT_VAR(c1); ZVAL_STRING(c1, "int", 1); PHALCON_INIT_VAR(r13); phalcon_fast_strpos(r13, type, c1 TSRMLS_CC); if (Z_TYPE_P(r13) != IS_BOOL || (Z_TYPE_P(r13) == IS_BOOL && Z_BVAL_P(r13))) { PHALCON_INIT_VAR(t1); ZVAL_BOOL(t1, 1); phalcon_array_update(&numeric_typed, field_name, &t1, PHALCON_SEPARATE_PLZ, PHALCON_COPY, PHALCON_NO_CTOR TSRMLS_CC); } else { PHALCON_INIT_VAR(c2); ZVAL_STRING(c2, "decimal", 1); PHALCON_INIT_VAR(r14); phalcon_fast_strpos(r14, type, c2 TSRMLS_CC); if (Z_TYPE_P(r14) != IS_BOOL || (Z_TYPE_P(r14) == IS_BOOL && Z_BVAL_P(r14))) { PHALCON_INIT_VAR(t2); ZVAL_BOOL(t2, 1); phalcon_array_update(&numeric_typed, field_name, &t2, PHALCON_SEPARATE_PLZ, PHALCON_COPY, PHALCON_NO_CTOR TSRMLS_CC); } else { PHALCON_INIT_VAR(c3); ZVAL_STRING(c3, "numeric", 1); PHALCON_INIT_VAR(r15); phalcon_fast_strpos(r15, type, c3 TSRMLS_CC); if (Z_TYPE_P(r15) != IS_BOOL || (Z_TYPE_P(r15) == IS_BOOL && Z_BVAL_P(r15))) { PHALCON_INIT_VAR(t3); ZVAL_BOOL(t3, 1); phalcon_array_update(&numeric_typed, field_name, &t3, PHALCON_SEPARATE_PLZ, PHALCON_COPY, PHALCON_NO_CTOR TSRMLS_CC); } } } } PHALCON_INIT_VAR(r16); phalcon_array_fetch_string(&r16, meta_data, SL("Null"), PHALCON_NOISY TSRMLS_CC); if (PHALCON_COMPARE_STRING(r16, "NO")) { phalcon_array_append(¬_null, field_name, PHALCON_SEPARATE_PLZ TSRMLS_CC); } PHALCON_INIT_VAR(r17); phalcon_array_fetch_string(&r17, meta_data, SL("Extra"), PHALCON_NOISY TSRMLS_CC); if (PHALCON_COMPARE_STRING(r17, "auto_increment")) { PHALCON_CPY_WRT(identity_field, field_name); } zend_hash_move_forward_ex(ah0, &hp0); goto fes_f5c6_0; fee_f5c6_0: if(0){} } else { return; } PHALCON_INIT_VAR(a6); array_init(a6); PHALCON_CPY_WRT(table_metadata, a6); phalcon_array_update_long(&table_metadata, 0, &attributes, PHALCON_SEPARATE_PLZ, PHALCON_COPY, PHALCON_NO_CTOR TSRMLS_CC); phalcon_array_update_long(&table_metadata, 1, &primary_keys, PHALCON_SEPARATE_PLZ, PHALCON_COPY, PHALCON_NO_CTOR TSRMLS_CC); phalcon_array_update_long(&table_metadata, 2, &non_primary_keys, PHALCON_SEPARATE_PLZ, PHALCON_COPY, PHALCON_NO_CTOR TSRMLS_CC); phalcon_array_update_long(&table_metadata, 3, ¬_null, PHALCON_SEPARATE_PLZ, PHALCON_COPY, PHALCON_NO_CTOR TSRMLS_CC); phalcon_array_update_long(&table_metadata, 4, &field_types, PHALCON_SEPARATE_PLZ, PHALCON_COPY, PHALCON_NO_CTOR TSRMLS_CC); phalcon_array_update_long(&table_metadata, 5, &numeric_typed, PHALCON_SEPARATE_PLZ, PHALCON_COPY, PHALCON_NO_CTOR TSRMLS_CC); phalcon_array_update_long(&table_metadata, 8, &identity_field, PHALCON_SEPARATE_PLZ, PHALCON_COPY, PHALCON_NO_CTOR TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(t4); phalcon_read_property(&t4, this_ptr, SL("_metaData"), PHALCON_NOISY TSRMLS_CC); phalcon_array_update(&t4, key, &table_metadata, PHALCON_NO_SEPARATE_THX, PHALCON_COPY, PHALCON_NO_CTOR TSRMLS_CC); phalcon_update_property_zval(this_ptr, SL("_metaData"), t4 TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(t5); phalcon_read_property(&t5, this_ptr, SL("_changed"), PHALCON_NOISY TSRMLS_CC); if (!zend_is_true(t5)) { PHALCON_INIT_VAR(a7); array_init(a7); phalcon_array_append(&a7, this_ptr, PHALCON_SEPARATE_PLZ TSRMLS_CC); add_next_index_stringl(a7, SL("storeMetaData"), 1); PHALCON_CALL_FUNC_PARAMS_1_NORETURN("register_shutdown_function", a7); phalcon_update_property_bool(this_ptr, SL("_changed"), 1 TSRMLS_CC); } } } PHALCON_MM_RESTORE(); }