PHP_METHOD(JsonPath, find) { char *path; #if PHP_MAJOR_VERSION < 7 int path_len; #else size_t path_len; #endif zval *z_array; HashTable *arr; if (zend_parse_parameters(ZEND_NUM_ARGS()TSRMLS_CC, "as", &z_array, &path, &path_len) == FAILURE) { return; } array_init(return_value); lex_token lex_tok[PARSE_BUF_LEN]; char lex_tok_values[PARSE_BUF_LEN][PARSE_BUF_LEN]; int lex_tok_count = 0; char *p = path; char buffer[PARSE_BUF_LEN]; lex_token *ptr = lex_tok; lex_error err; while ((*ptr = scan(&p, buffer, sizeof(buffer), &err)) != LEX_NOT_FOUND) { switch (*ptr) { case LEX_NODE: case LEX_LITERAL: strcpy(lex_tok_values[lex_tok_count], buffer); break; case LEX_ERR: snprintf(err.msg, sizeof(err.msg), "%s at position %d", err.msg, (err.pos - path)); zend_throw_exception(spl_ce_RuntimeException, err.msg, 0 TSRMLS_CC); return; default: lex_tok_values[lex_tok_count][0] = '\0'; break; } ptr++; lex_tok_count++; } operator tok[100]; int tok_count = 0; int *int_ptr = &tok_count; parse_error p_err; if (!build_parse_tree(lex_tok, lex_tok_values, lex_tok_count, tok, int_ptr, &p_err)) { zend_throw_exception(spl_ce_RuntimeException, p_err.msg, 0 TSRMLS_CC); } operator * tok_ptr_start; operator * tok_ptr_end; tok_ptr_start = &tok[0]; tok_ptr_end = &tok[tok_count - 1]; iterate(z_array, tok_ptr_start, tok_ptr_end, return_value TSRMLS_CC); operator * fr = tok_ptr_start; while (fr <= tok_ptr_end) { if (fr->filter_type == FLTR_EXPR) { efree((void *)fr->expressions); } fr++; } if (zend_hash_num_elements(HASH_OF(return_value)) == 0) { convert_to_boolean(return_value); RETURN_FALSE; } 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_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; }
/** * Checks if a role has access to a resource * * @param string $roleName * @param string $resourceName * @param string $access * @param string $action */ PHP_METHOD(Phalcon_Acl_Adapter_Memory, _allowOrDeny){ zval *role_name, *resource_name, *access, *action; zval *roles_names, *exception_message = NULL, *resources_names; zval *default_access, *access_list, *access_name = NULL; zval *empty_arr = NULL, *_access = NULL; zval *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL, *r4 = NULL, *r5 = NULL, *r6 = NULL; zval *r7 = NULL; zval *t0 = NULL, *t1 = NULL, *t2 = NULL, *t3 = NULL, *t4 = NULL, *t5 = NULL, *t6 = NULL; zval *t7 = NULL, *t8 = NULL, *t9 = NULL; HashTable *ah0, *ah1; HashPosition hp0, hp1; zval **hd; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzzz", &role_name, &resource_name, &access, &action) == FAILURE) { RETURN_MM_NULL(); } PHALCON_OBS_VAR(roles_names); phalcon_read_property(&roles_names, this_ptr, SL("_rolesNames"), PH_NOISY_CC); if (!phalcon_array_isset(roles_names, role_name)) { PHALCON_INIT_VAR(exception_message); PHALCON_CONCAT_SVS(exception_message, "Role \"", role_name, "\" does not exist in ACL"); PHALCON_THROW_EXCEPTION_ZVAL(phalcon_acl_exception_ce, exception_message); return; } PHALCON_OBS_VAR(resources_names); phalcon_read_property(&resources_names, this_ptr, SL("_resourcesNames"), PH_NOISY_CC); if (!phalcon_array_isset(resources_names, resource_name)) { PHALCON_INIT_NVAR(exception_message); PHALCON_CONCAT_SVS(exception_message, "Resource \"", resource_name, "\" does not exist in ACL"); PHALCON_THROW_EXCEPTION_ZVAL(phalcon_acl_exception_ce, exception_message); return; } PHALCON_OBS_VAR(default_access); phalcon_read_property(&default_access, this_ptr, SL("_defaultAccess"), PH_NOISY_CC); if (Z_TYPE_P(access) == IS_ARRAY) { PHALCON_OBS_VAR(access_list); phalcon_read_property(&access_list, this_ptr, SL("_accessList"), PH_NOISY_CC); if (!phalcon_is_iterable(access, &ah0, &hp0, 0, 0 TSRMLS_CC)) { return; } while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_FOREACH_VALUE(access_name); PHALCON_OBS_NVAR(r0); phalcon_array_fetch(&r0, access_list, resource_name, PH_NOISY_CC); if (!phalcon_array_isset(r0, access_name)) { PHALCON_INIT_NVAR(exception_message); PHALCON_CONCAT_SVSVS(exception_message, "Acccess '", access_name, "' does not exist in resource '", resource_name, "' in ACL"); PHALCON_THROW_EXCEPTION_ZVAL(phalcon_acl_exception_ce, exception_message); return; } zend_hash_move_forward_ex(ah0, &hp0); } if (!phalcon_is_iterable(access, &ah1, &hp1, 0, 0 TSRMLS_CC)) { return; } while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { PHALCON_GET_FOREACH_VALUE(access_name); PHALCON_OBS_NVAR(t0); phalcon_read_property(&t0, this_ptr, SL("_access"), PH_NOISY_CC); PHALCON_OBS_NVAR(r1); phalcon_array_fetch(&r1, t0, role_name, PH_NOISY_CC); if (!phalcon_array_isset(r1, resource_name)) { PHALCON_INIT_NVAR(empty_arr); array_init(empty_arr); PHALCON_OBS_NVAR(_access); phalcon_read_property(&_access, this_ptr, SL("_access"), PH_NOISY_CC); phalcon_array_update_multi_2(&_access, role_name, resource_name, &empty_arr, 0 TSRMLS_CC); phalcon_update_property_zval(this_ptr, SL("_access"), _access TSRMLS_CC); } PHALCON_OBS_NVAR(t1); phalcon_read_property(&t1, this_ptr, SL("_access"), PH_NOISY_CC); phalcon_array_update_zval_zval_zval_multi_3(&t1, role_name, resource_name, access_name, &action, 0 TSRMLS_CC); PHALCON_OBS_NVAR(t2); phalcon_read_property(&t2, this_ptr, SL("_access"), PH_NOISY_CC); PHALCON_OBS_NVAR(r2); phalcon_array_fetch(&r2, t2, role_name, PH_NOISY_CC); PHALCON_OBS_NVAR(r3); phalcon_array_fetch(&r3, r2, resource_name, PH_NOISY_CC); if (!phalcon_array_isset_string(r3, SS("*"))) { PHALCON_OBS_NVAR(t3); phalcon_read_property(&t3, this_ptr, SL("_access"), PH_NOISY_CC); phalcon_array_update_string_zval_zval_multi_3(&t3, role_name, resource_name, SL("*"), &default_access, 0 TSRMLS_CC); } zend_hash_move_forward_ex(ah1, &hp1); } } else { if (!PHALCON_IS_STRING(access, "*")) { PHALCON_OBS_VAR(t4); phalcon_read_property(&t4, this_ptr, SL("_accessList"), PH_NOISY_CC); PHALCON_OBS_VAR(r4); phalcon_array_fetch(&r4, t4, resource_name, PH_NOISY_CC); if (!phalcon_array_isset(r4, access)) { PHALCON_INIT_NVAR(exception_message); PHALCON_CONCAT_SVSVS(exception_message, "Acccess '", access, "' does not exist in resource '", resource_name, "' in ACL"); PHALCON_THROW_EXCEPTION_ZVAL(phalcon_acl_exception_ce, exception_message); return; } } PHALCON_OBS_VAR(t5); phalcon_read_property(&t5, this_ptr, SL("_access"), PH_NOISY_CC); PHALCON_OBS_VAR(r5); phalcon_array_fetch(&r5, t5, role_name, PH_NOISY_CC); if (!phalcon_array_isset(r5, resource_name)) { PHALCON_INIT_NVAR(empty_arr); array_init(empty_arr); PHALCON_OBS_VAR(t6); phalcon_read_property(&t6, this_ptr, SL("_access"), PH_NOISY_CC); phalcon_array_update_multi_2(&t6, role_name, resource_name, &empty_arr, 0 TSRMLS_CC); phalcon_update_property_zval(this_ptr, SL("_access"), t6 TSRMLS_CC); } PHALCON_OBS_VAR(t7); phalcon_read_property(&t7, this_ptr, SL("_access"), PH_NOISY_CC); PHALCON_OBS_VAR(r6); phalcon_array_fetch(&r6, t7, role_name, PH_NOISY_CC); PHALCON_OBS_VAR(r7); phalcon_array_fetch(&r7, r6, resource_name, PH_NOISY_CC); if (!phalcon_array_isset_string(r7, SS("*"))) { PHALCON_OBS_VAR(t8); phalcon_read_property(&t8, this_ptr, SL("_access"), PH_NOISY_CC); phalcon_array_update_string_zval_zval_multi_3(&t8, role_name, resource_name, SL("*"), &default_access, 0 TSRMLS_CC); } PHALCON_OBS_VAR(t9); phalcon_read_property(&t9, this_ptr, SL("_access"), PH_NOISY_CC); phalcon_array_update_zval_zval_zval_multi_3(&t9, role_name, resource_name, access, &action, 0 TSRMLS_CC); } PHALCON_CALL_METHOD_NORETURN(this_ptr, "_rebuildaccesslist"); PHALCON_MM_RESTORE(); }
int main(int argc, char **argv) { int c; char *scan; /* the + on the front tells GNU getopt not to rearrange argv */ const char *optlist = "+F:f:v:W;m:D"; int stopped_early = FALSE; int old_optind; extern int optind; extern int opterr; extern char *optarg; int i; int stdio_problem = FALSE; /* do these checks early */ if (getenv("TIDYMEM") != NULL) do_tidy_mem = TRUE; if (getenv("WHINY_USERS") != NULL) whiny_users = TRUE; #ifdef HAVE_MCHECK_H if (do_tidy_mem) mtrace(); #endif /* HAVE_MCHECK_H */ #if defined(LC_CTYPE) setlocale(LC_CTYPE, ""); #endif #if defined(LC_COLLATE) setlocale(LC_COLLATE, ""); #endif #if defined(LC_MESSAGES) setlocale(LC_MESSAGES, ""); #endif #if defined(LC_NUMERIC) /* * Force the issue here. According to POSIX 2001, decimal * point is used for parsing source code and for command-line * assignments and the locale value for processing input, * number to string conversion, and printing output. */ setlocale(LC_NUMERIC, "C"); #endif #if defined(LC_TIME) setlocale(LC_TIME, ""); #endif #ifdef MBS_SUPPORT /* * In glibc, MB_CUR_MAX is actually a function. This value is * tested *a lot* in many speed-critical places in gawk. Caching * this value once makes a speed difference. */ gawk_mb_cur_max = MB_CUR_MAX; /* Without MBS_SUPPORT, gawk_mb_cur_max is 1. */ #endif (void) bindtextdomain(PACKAGE, LOCALEDIR); (void) textdomain(PACKAGE); (void) signal(SIGFPE, catchsig); (void) signal(SIGSEGV, catchsig); #ifdef SIGBUS (void) signal(SIGBUS, catchsig); #endif myname = gawk_name(argv[0]); argv[0] = (char *) myname; os_arg_fixup(&argc, &argv); /* emulate redirection, expand wildcards */ /* remove sccs gunk */ if (strncmp(version_string, "@(#)", 4) == 0) version_string += 4; if (argc < 2) usage(1, stderr); /* Robustness: check that file descriptors 0, 1, 2 are open */ init_fds(); /* init array handling. */ array_init(); /* we do error messages ourselves on invalid options */ opterr = FALSE; /* option processing. ready, set, go! */ for (optopt = 0, old_optind = 1; (c = getopt_long(argc, argv, optlist, optab, NULL)) != EOF; optopt = 0, old_optind = optind) { if (do_posix) opterr = TRUE; switch (c) { case 'F': preassigns_add(PRE_ASSIGN_FS, optarg); break; case 'S': disallow_var_assigns = TRUE; /* fall through */ case 'f': /* * a la MKS awk, allow multiple -f options. * this makes function libraries real easy. * most of the magic is in the scanner. * * The following is to allow for whitespace at the end * of a #! /bin/gawk line in an executable file */ scan = optarg; if (argv[optind-1] != optarg) while (ISSPACE(*scan)) scan++; srcfiles_add(SOURCEFILE, (*scan == '\0' ? argv[optind++] : optarg)); break; case 'v': preassigns_add(PRE_ASSIGN, optarg); break; case 'm': /* * Research awk extension. * -mf nnn set # fields, gawk ignores * -mr nnn set record length, ditto */ if (do_lint) lintwarn(_("`-m[fr]' option irrelevant in gawk")); if (optarg[0] != 'r' && optarg[0] != 'f') warning(_("-m option usage: `-m[fr] nnn'")); /* * Set fixed length records for Tandem, * ignored on other platforms (see io.c:get_a_record). */ if (optarg[0] == 'r') { if (ISDIGIT(optarg[1])) MRL = atoi(optarg+1); else { MRL = atoi(argv[optind]); optind++; } } else if (optarg[1] == '\0') optind++; break; case 'W': /* gawk specific options - now in getopt_long */ fprintf(stderr, _("%s: option `-W %s' unrecognized, ignored\n"), argv[0], optarg); break; /* These can only come from long form options */ case 'C': copyleft(); break; case 'd': do_dump_vars = TRUE; if (optarg != NULL && optarg[0] != '\0') varfile = optarg; break; case 'l': #ifndef NO_LINT do_lint = LINT_ALL; if (optarg != NULL) { if (strcmp(optarg, "fatal") == 0) lintfunc = r_fatal; else if (strcmp(optarg, "invalid") == 0) do_lint = LINT_INVALID; } #endif break; case 'p': do_profiling = TRUE; if (optarg != NULL) set_prof_file(optarg); else set_prof_file(DEFAULT_PROFILE); break; case 's': if (optarg[0] == '\0') warning(_("empty argument to `--source' ignored")); else srcfiles_add(CMDLINE, optarg); break; case 'u': usage(0, stdout); /* per coding stds */ break; case 'V': version(); break; case 0: /* * getopt_long found an option that sets a variable * instead of returning a letter. Do nothing, just * cycle around for the next one. */ break; case 'D': #ifdef GAWKDEBUG yydebug = 2; break; #endif /* if not debugging, fall through */ case '?': default: /* * New behavior. If not posix, an unrecognized * option stops argument processing so that it can * go into ARGV for the awk program to see. This * makes use of ``#! /bin/gawk -f'' easier. * * However, it's never simple. If optopt is set, * an option that requires an argument didn't get the * argument. We care because if opterr is 0, then * getopt_long won't print the error message for us. */ if (! do_posix && (optopt == '\0' || strchr(optlist, optopt) == NULL)) { /* * can't just do optind--. In case of an * option with >= 2 letters, getopt_long * won't have incremented optind. */ optind = old_optind; stopped_early = TRUE; goto out; } else if (optopt != '\0') /* Use 1003.2 required message format */ fprintf(stderr, _("%s: option requires an argument -- %c\n"), myname, optopt); /* else let getopt print error message for us */ break; } if (c == 'S') /* --exec ends option processing */ break; } out: if (do_nostalgia) nostalgia(); /* check for POSIXLY_CORRECT environment variable */ if (! do_posix && getenv("POSIXLY_CORRECT") != NULL) { do_posix = TRUE; if (do_lint) lintwarn( _("environment variable `POSIXLY_CORRECT' set: turning on `--posix'")); } if (do_posix) { if (do_traditional) /* both on command line */ warning(_("`--posix' overrides `--traditional'")); else do_traditional = TRUE; /* * POSIX compliance also implies * no GNU extensions either. */ } if (do_traditional && do_non_decimal_data) { do_non_decimal_data = FALSE; warning(_("`--posix'/`--traditional' overrides `--non-decimal-data'")); } if (do_lint && os_is_setuid()) warning(_("running %s setuid root may be a security problem"), myname); /* * Force profiling if this is pgawk. * Don't bother if the command line already set profiling up. */ if (! do_profiling) init_profiling(& do_profiling, DEFAULT_PROFILE); /* load group set */ init_groupset(); /* initialize the null string */ Nnull_string = make_string("", 0); Nnull_string->numbr = 0.0; Nnull_string->type = Node_val; Nnull_string->flags = (PERM|STRCUR|STRING|NUMCUR|NUMBER); /* * Tell the regex routines how they should work. * Do this before initializing variables, since * they could want to do a regexp compile. */ resetup(); /* Set up the special variables */ init_vars(); /* Set up the field variables */ init_fields(); /* Now process the pre-assignments */ for (i = 0; i <= numassigns; i++) if (preassigns[i].stype == PRE_ASSIGN) (void) arg_assign(preassigns[i].val, TRUE); else /* PRE_ASSIGN_FS */ cmdline_fs(preassigns[i].val); free(preassigns); if ((BINMODE & 1) != 0) if (os_setbinmode(fileno(stdin), O_BINARY) == -1) fatal(_("can't set binary mode on stdin (%s)"), strerror(errno)); if ((BINMODE & 2) != 0) { if (os_setbinmode(fileno(stdout), O_BINARY) == -1) fatal(_("can't set binary mode on stdout (%s)"), strerror(errno)); if (os_setbinmode(fileno(stderr), O_BINARY) == -1) fatal(_("can't set binary mode on stderr (%s)"), strerror(errno)); } #ifdef GAWKDEBUG setbuf(stdout, (char *) NULL); /* make debugging easier */ #endif if (isatty(fileno(stdout))) output_is_tty = TRUE; /* No -f or --source options, use next arg */ if (numfiles == -1) { if (optind > argc - 1 || stopped_early) /* no args left or no program */ usage(1, stderr); srcfiles_add(CMDLINE, argv[optind]); optind++; } init_args(optind, argc, (char *) myname, argv); (void) tokexpand(); #if defined(LC_NUMERIC) /* * FRAGILE! CAREFUL! * Pre-initing the variables with arg_assign() can change the * locale. Force it to C before parsing the program. */ setlocale(LC_NUMERIC, "C"); #endif /* Read in the program */ if (yyparse() != 0 || errcount != 0) exit(1); free(srcfiles); if (do_intl) exit(0); if (do_lint && begin_block == NULL && expression_value == NULL && end_block == NULL) lintwarn(_("no program text at all!")); if (do_lint) shadow_funcs(); init_profiling_signals(); #if defined(LC_NUMERIC) /* See comment above. */ setlocale(LC_NUMERIC, ""); #endif #if defined(HAVE_LOCALE_H) loc = *localeconv(); /* Make a local copy of locale numeric info */ #endif /* Whew. Finally, run the program. */ if (begin_block != NULL) { in_begin_rule = TRUE; (void) interpret(begin_block); } in_begin_rule = FALSE; if (! exiting && (expression_value != NULL || end_block != NULL)) do_input(); if (end_block != NULL) { in_end_rule = TRUE; (void) interpret(end_block); } in_end_rule = FALSE; /* * This used to be: * * if (close_io() != 0 && ! exiting && exit_val == 0) * exit_val = 1; * * Other awks don't care about problems closing open files * and pipes, in that it doesn't affect their exit status. * So we no longer do either. */ (void) close_io(& stdio_problem); /* * However, we do want to exit non-zero if there was a problem * with stdout/stderr, so we reinstate a slightly different * version of the above: */ if (stdio_problem && ! exiting && exit_val == 0) exit_val = 1; if (do_profiling) { dump_prog(begin_block, expression_value, end_block); dump_funcs(); } if (do_dump_vars) dump_vars(varfile); if (do_tidy_mem) release_all_vars(); exit(exit_val); /* more portable */ return exit_val; /* to suppress warnings */ }
/** * Rpc call * * @param string $method * @param string $data * @return Phalcon\JsonRpc\Response */ PHP_METHOD(Phalcon_JsonRpc_Client, call){ zval *method = NULL, *data = NULL, *httpclient, *id, *jsonrpc_message, *json_message = NULL, *response = NULL; zval *code = NULL, *body = NULL, *json = NULL, *jsonrpc_response, *result, *error; int i; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 1, &method, &data); httpclient = phalcon_fetch_nproperty_this(this_ptr, SL("_httpclient"), PH_NOISY TSRMLS_CC); id = phalcon_fetch_nproperty_this(this_ptr, SL("_id"), PH_NOISY TSRMLS_CC); i = Z_LVAL_P(id) + 1; ZVAL_LONG(id, i); phalcon_update_property_this(this_ptr, SL("_id"), id TSRMLS_CC); PHALCON_INIT_VAR(jsonrpc_message); array_init(jsonrpc_message); phalcon_array_update_string_string(&jsonrpc_message, SL("jsonrpc"), SL("2.0"), 0); phalcon_array_update_string(&jsonrpc_message, SL("method"), method, PH_COPY); if (data) { phalcon_array_update_string(&jsonrpc_message, SL("params"), data, PH_COPY); } phalcon_array_update_string(&jsonrpc_message, SL("id"), id, PH_COPY); PHALCON_CALL_FUNCTION(&json_message, "json_encode", jsonrpc_message); PHALCON_CALL_METHOD(NULL, httpclient, "setdata", json_message); PHALCON_CALL_METHOD(&response, httpclient, "post"); PHALCON_VERIFY_CLASS_EX(response, phalcon_http_client_response_ce, phalcon_jsonrpc_client_exception_ce, 1); PHALCON_CALL_METHOD(&code, response, "getstatuscode"); PHALCON_CALL_METHOD(&body, response, "getbody"); PHALCON_INIT_VAR(jsonrpc_response); object_init_ex(jsonrpc_response, phalcon_jsonrpc_client_response_ce); PHALCON_CALL_METHOD(NULL, jsonrpc_response, "__construct", body); PHALCON_CALL_METHOD(NULL, jsonrpc_response, "setcode", code); if (PHALCON_IS_NOT_EMPTY(body)) { PHALCON_CALL_FUNCTION(&json, "json_decode", body, PHALCON_GLOBAL(z_true)); if (Z_TYPE_P(json) == IS_ARRAY) { if (phalcon_array_isset_string(json, SS("id"))) { PHALCON_OBS_VAR(id); phalcon_array_fetch_string(&id, json, SL("id"), PH_NOISY); PHALCON_CALL_METHOD(NULL, jsonrpc_response, "setid", id); } if (phalcon_array_isset_string(json, SS("result"))) { PHALCON_OBS_VAR(result); phalcon_array_fetch_string(&result, json, SL("result"), PH_NOISY); PHALCON_CALL_METHOD(NULL, jsonrpc_response, "setresult", result); } if (phalcon_array_isset_string(json, SS("error"))) { PHALCON_OBS_VAR(error); phalcon_array_fetch_string(&error, json, SL("error"), PH_NOISY); PHALCON_CALL_METHOD(NULL, jsonrpc_response, "seterror", error); } } } RETURN_CTOR(jsonrpc_response); }
/** * Do a role inherit from another existing role * * @param string $roleName * @param string $roleToInherit */ PHP_METHOD(Phalcon_Acl_Adapter_Memory, addInherit){ zval *role_name, *role_to_inherit, *roles_names; zval *exception_message = NULL, *role_inherit_name = NULL; zval *roles_inherits, *empty_arr, *_roleInherits; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &role_name, &role_to_inherit) == FAILURE) { RETURN_MM_NULL(); } PHALCON_OBS_VAR(roles_names); phalcon_read_property(&roles_names, this_ptr, SL("_rolesNames"), PH_NOISY_CC); if (!phalcon_array_isset(roles_names, role_name)) { PHALCON_INIT_VAR(exception_message); PHALCON_CONCAT_SVS(exception_message, "Role '", role_name, "' does not exist in the role list"); PHALCON_THROW_EXCEPTION_ZVAL(phalcon_acl_exception_ce, exception_message); return; } if (Z_TYPE_P(role_to_inherit) == IS_OBJECT) { PHALCON_INIT_VAR(role_inherit_name); PHALCON_CALL_METHOD(role_inherit_name, role_to_inherit, "getname"); } else { PHALCON_CPY_WRT(role_inherit_name, role_to_inherit); } /** * Check if the role to inherit is valid */ if (!phalcon_array_isset(roles_names, role_inherit_name)) { PHALCON_INIT_NVAR(exception_message); PHALCON_CONCAT_SVS(exception_message, "Role '", role_inherit_name, "' (to inherit) does not exist in the role list"); PHALCON_THROW_EXCEPTION_ZVAL(phalcon_acl_exception_ce, exception_message); return; } if (PHALCON_IS_EQUAL(role_inherit_name, role_name)) { RETURN_MM_FALSE; } PHALCON_OBS_VAR(roles_inherits); phalcon_read_property(&roles_inherits, this_ptr, SL("_roleInherits"), PH_NOISY_CC); if (!phalcon_array_isset(roles_inherits, role_name)) { PHALCON_INIT_VAR(empty_arr); array_init(empty_arr); phalcon_update_property_array(this_ptr, SL("_roleInherits"), role_name, empty_arr TSRMLS_CC); } PHALCON_OBS_VAR(_roleInherits); phalcon_read_property(&_roleInherits, this_ptr, SL("_roleInherits"), PH_NOISY_CC); phalcon_array_update_append_multi_2(&_roleInherits, role_name, role_inherit_name, 0 TSRMLS_CC); phalcon_update_property_zval(this_ptr, SL("_roleInherits"), _roleInherits TSRMLS_CC); /** * Re-build the access list with its inherited roles */ PHALCON_CALL_METHOD_NORETURN(this_ptr, "_rebuildaccesslist"); RETURN_MM_TRUE; }
/** * Generates SQL to create a table in PostgreSQL * * @param string $tableName * @param string $schemaName * @param array $definition * @return string */ PHP_METHOD(Phalcon_Db_Dialect_Postgresql, createTable){ zval *table_name = NULL, *schema_name = NULL, *definition = NULL; zval *table = NULL, *temporary = NULL, *sql = NULL, *create_lines = NULL, *column = NULL; zval *column_line = NULL, *index = NULL, *index_name = NULL, *column_list = NULL; zval *reference = NULL, *reference_sql = 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, *r18 = NULL, *r19 = NULL, *r20 = NULL; zval *r21 = NULL, *r22 = NULL, *r23 = NULL, *r24 = NULL, *r25 = NULL, *r26 = NULL, *r27 = NULL; zval *r28 = NULL, *r29 = NULL, *r30 = NULL; zval *a0 = NULL; zval *t0 = NULL, *t1 = NULL; zval *c0 = NULL; HashTable *ah0, *ah1, *ah2; HashPosition hp0, hp1, hp2; zval **hd; int eval_int; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzz", &table_name, &schema_name, &definition) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (zend_is_true(schema_name)) { PHALCON_ALLOC_ZVAL_MM(r0); PHALCON_CONCAT_VSV(r0, schema_name, ".", table_name); PHALCON_CPY_WRT(table, r0); } else { PHALCON_CPY_WRT(table, table_name); } PHALCON_INIT_VAR(temporary); ZVAL_BOOL(temporary, 0); eval_int = phalcon_array_isset_string(definition, SL("options")+1); if (eval_int) { PHALCON_ALLOC_ZVAL_MM(r1); phalcon_array_fetch_string(&r1, definition, SL("options"), PHALCON_NOISY TSRMLS_CC); eval_int = phalcon_array_isset_string(r1, SL("temporary")+1); if (eval_int) { PHALCON_ALLOC_ZVAL_MM(r2); phalcon_array_fetch_string(&r2, definition, SL("options"), PHALCON_NOISY TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(r3); phalcon_array_fetch_string(&r3, r2, SL("temporary"), PHALCON_NOISY TSRMLS_CC); if (zend_is_true(r3)) { PHALCON_INIT_VAR(temporary); ZVAL_BOOL(temporary, 1); } } } if (zend_is_true(temporary)) { PHALCON_ALLOC_ZVAL_MM(r4); PHALCON_CONCAT_SVS(r4, "CREATE TEMPORARY TABLE ", table, " (\n\t"); PHALCON_CPY_WRT(sql, r4); } else { PHALCON_ALLOC_ZVAL_MM(r5); PHALCON_CONCAT_SVS(r5, "CREATE TABLE ", table, " (\n\t"); PHALCON_CPY_WRT(sql, r5); } PHALCON_INIT_VAR(a0); array_init(a0); PHALCON_CPY_WRT(create_lines, a0); PHALCON_ALLOC_ZVAL_MM(r6); phalcon_array_fetch_string(&r6, definition, SL("columns"), PHALCON_NOISY TSRMLS_CC); if (phalcon_valid_foreach(r6 TSRMLS_CC)) { ah0 = Z_ARRVAL_P(r6); zend_hash_internal_pointer_reset_ex(ah0, &hp0); fes_46b6_2: if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){ goto fee_46b6_2; } PHALCON_INIT_VAR(column); ZVAL_ZVAL(column, *hd, 1, 0); PHALCON_INIT_VAR(r7); PHALCON_INIT_VAR(r8); PHALCON_CALL_METHOD(r8, column, "getname", PHALCON_NO_CHECK); PHALCON_INIT_VAR(r9); PHALCON_CALL_SELF_PARAMS_1(r9, this_ptr, "getcolumndefinition", column); PHALCON_CONCAT_SVSV(r7, "`", r8, "` ", r9); PHALCON_CPY_WRT(column_line, r7); PHALCON_INIT_VAR(r10); PHALCON_CALL_METHOD(r10, column, "isnotnull", PHALCON_NO_CHECK); if (zend_is_true(r10)) { PHALCON_INIT_VAR(t0); ZVAL_STRING(t0, " NOT NULL", 1); phalcon_concat_self(&column_line, t0 TSRMLS_CC); } PHALCON_INIT_VAR(r11); PHALCON_CALL_METHOD(r11, column, "isautoincrement", PHALCON_NO_CHECK); if (zend_is_true(r11)) { PHALCON_INIT_VAR(t1); ZVAL_STRING(t1, " AUTO_INCREMENT", 1); phalcon_concat_self(&column_line, t1 TSRMLS_CC); } phalcon_array_append(&create_lines, column_line, PHALCON_SEPARATE_PLZ TSRMLS_CC); zend_hash_move_forward_ex(ah0, &hp0); goto fes_46b6_2; fee_46b6_2: if(0){} } else { return; } eval_int = phalcon_array_isset_string(definition, SL("indexes")+1); if (eval_int) { PHALCON_ALLOC_ZVAL_MM(r12); phalcon_array_fetch_string(&r12, definition, SL("indexes"), PHALCON_NOISY TSRMLS_CC); if (phalcon_valid_foreach(r12 TSRMLS_CC)) { ah1 = Z_ARRVAL_P(r12); zend_hash_internal_pointer_reset_ex(ah1, &hp1); fes_46b6_3: if(zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) != SUCCESS){ goto fee_46b6_3; } PHALCON_INIT_VAR(index); ZVAL_ZVAL(index, *hd, 1, 0); PHALCON_INIT_VAR(r13); PHALCON_CALL_METHOD(r13, index, "getname", PHALCON_NO_CHECK); PHALCON_CPY_WRT(index_name, r13); PHALCON_INIT_VAR(r14); PHALCON_INIT_VAR(r15); PHALCON_CALL_METHOD(r15, index, "getcolumns", PHALCON_NO_CHECK); PHALCON_CALL_SELF_PARAMS_1(r14, this_ptr, "getcolumnlist", r15); PHALCON_CPY_WRT(column_list, r14); if (PHALCON_COMPARE_STRING(index_name, "PRIMARY")) { PHALCON_INIT_VAR(r16); PHALCON_CONCAT_SVS(r16, "PRIMARY KEY (", column_list, ")"); phalcon_array_append(&create_lines, r16, PHALCON_SEPARATE_PLZ TSRMLS_CC); } else { PHALCON_INIT_VAR(r17); PHALCON_CONCAT_SVSVS(r17, "KEY `", index_name, "` (", column_list, ")"); phalcon_array_append(&create_lines, r17, PHALCON_SEPARATE_PLZ TSRMLS_CC); } zend_hash_move_forward_ex(ah1, &hp1); goto fes_46b6_3; fee_46b6_3: if(0){} } else { return; } } eval_int = phalcon_array_isset_string(definition, SL("references")+1); if (eval_int) { PHALCON_ALLOC_ZVAL_MM(r18); phalcon_array_fetch_string(&r18, definition, SL("references"), PHALCON_NOISY TSRMLS_CC); if (phalcon_valid_foreach(r18 TSRMLS_CC)) { ah2 = Z_ARRVAL_P(r18); zend_hash_internal_pointer_reset_ex(ah2, &hp2); fes_46b6_4: if(zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) != SUCCESS){ goto fee_46b6_4; } PHALCON_INIT_VAR(reference); ZVAL_ZVAL(reference, *hd, 1, 0); PHALCON_INIT_VAR(r19); PHALCON_INIT_VAR(r20); PHALCON_CALL_METHOD(r20, reference, "getname", PHALCON_NO_CHECK); PHALCON_INIT_VAR(r21); PHALCON_INIT_VAR(r22); PHALCON_CALL_METHOD(r22, reference, "getcolumns", PHALCON_NO_CHECK); PHALCON_CALL_SELF_PARAMS_1(r21, this_ptr, "getcolumnlist", r22); PHALCON_CONCAT_SVSV(r19, "CONSTRAINT `", r20, "` FOREIGN KEY (", r21); PHALCON_CPY_WRT(reference_sql, r19); PHALCON_INIT_VAR(r23); PHALCON_INIT_VAR(r24); PHALCON_CALL_METHOD(r24, reference, "getreferencedtable", PHALCON_NO_CHECK); PHALCON_INIT_VAR(r25); PHALCON_INIT_VAR(r26); PHALCON_CALL_METHOD(r26, reference, "getreferencedcolumns", PHALCON_NO_CHECK); PHALCON_CALL_SELF_PARAMS_1(r25, this_ptr, "getcolumnlist", r26); PHALCON_CONCAT_SVSVS(r23, ") REFERENCES `", r24, "`(", r25, ")"); phalcon_concat_self(&reference_sql, r23 TSRMLS_CC); phalcon_array_append(&create_lines, reference_sql, PHALCON_SEPARATE_PLZ TSRMLS_CC); zend_hash_move_forward_ex(ah2, &hp2); goto fes_46b6_4; fee_46b6_4: if(0){} } else { return; } } PHALCON_ALLOC_ZVAL_MM(r27); PHALCON_INIT_VAR(c0); ZVAL_STRING(c0, ",\n\t", 1); PHALCON_ALLOC_ZVAL_MM(r28); phalcon_fast_join(r28, c0, create_lines TSRMLS_CC); PHALCON_CONCAT_VS(r27, r28, "\n)"); phalcon_concat_self(&sql, r27 TSRMLS_CC); eval_int = phalcon_array_isset_string(definition, SL("options")+1); if (eval_int) { PHALCON_ALLOC_ZVAL_MM(r29); PHALCON_ALLOC_ZVAL_MM(r30); PHALCON_CALL_SELF_PARAMS_1(r30, this_ptr, "_gettableoptions", definition); PHALCON_CONCAT_SV(r29, " ", r30); phalcon_concat_self(&sql, r29 TSRMLS_CC); } RETURN_CTOR(sql); }
/*--Function for Decompressor--*/ void decompress(struct bitio* file_to_read,struct bitio* file,lz78_decompressor* in) { //char * out=malloc(sizeof(char)*150); char out[50]; out[0]='\0'; int i=0; int j=0; char first_char=0; file_to_read=bit_open(in->file_to_decompress,0); if(file_to_read==NULL){ printf("File not found or you don't have enough privilege to open a file\n"); return; } uint64_t inp=0; int temp=0; char prec_char=0; int first_father; int ret=0; int x=0; //fseek(file_to_read->f,4,SEEK_SET); in->info_ptr=getinfo(file_to_read); reset: while(x>=0){ ret=bit_read(file_to_read,16,&inp); first_father=temp=(int)(inp&((1UL<<16)-1))-1; if(first_father<=0)goto fine_file; while((first_char=look_up_array(temp))==-1){ out[i]=(char)array_tree[temp].c; temp=(int)array_tree[temp].father_num; i++; } if(ret<=0) { fine_file:printf("The file was correctly extracted...\n"); //no more data to read flush_out_buffer(file); break; } out[i]=first_char; if(x==0){ prec_char=(int)(inp&((1UL<<16)-1))-1; //printf("ricevuto :%d Inserisco il nodo %d con padre %d\n",first_father,(int)in->counter_child_tree-1,prec_char); array_tree[(int)in->counter_child_tree-1].father_num=(int)((inp&((1UL<<16)-1))-1); in->counter_child_tree++; } if(x>0){ //printf("Inserisco %c nel nodo %d temp:%d\n",array_tree[temp].c,(int)in->counter_child_tree-2,temp); array_tree[(int)in->counter_child_tree-2].c=array_tree[temp].c; //printf("Inserisco il nodo %d con padre %d\n",(int)in->counter_child_tree-1,(int)(inp&((1UL<<16)-1))-1); /*I have to add a new node*/ array_tree[(int)in->counter_child_tree-1].father_num=(int)(inp&((1UL<<16)-1))-1; out[0]=((int)in->counter_child_tree-2==(int)((inp&((1UL<<16)-1))-1))?array_tree[temp].c:(char)array_tree[(int)((inp&((1UL<<16)-1))-1)].c; //If i have received the last node insert, i have to update the output string becouse i didn't have the char of the node received in->counter_child_tree++; } //out[i+1]='\0'; for(j=i;j>=0;j--){bit_write(file,8, out[j]); //printf("%c",(out[j])); } // I print the buffer string //printf("\n"); i=0; x++; out[0]='\0'; if(in->counter_child_tree>=in->d_max-1){ //need to empty the array based tree for the decompressor free(array_tree); in->counter_child_tree=0; array_init(6700417,in); x=0; goto reset; } } /*rewind(file_to_read->f); uint64_t r; bit_read(file_to_read,8,&r); printf("%c aad\n",(char)r&((1UL<<8)-1)); bit_read(file_to_read,8,&r); printf("%c aad\n",(char)r&((1UL<<8)-1)); bit_read(file_to_read,8,&r); printf("%c aad\n",(char)r&((1UL<<8)-1)); bit_read(file_to_read,8,&r); printf("%c aad\n",(char)r&((1UL<<8)-1)); */ bit_close(file_to_read); }
/** * Sanitizes a value with a specified single or set of filters * * @param mixed $value * @param mixed $filters * @return mixed */ PHP_METHOD(Phalcon_Filter, sanitize){ zval *value, *filters, *new_value = NULL, *filter = NULL, *array_value = NULL; zval *item_value = NULL, *key = NULL, *filter_value = NULL, *sanizited_value = NULL; HashTable *ah0, *ah1, *ah2; HashPosition hp0, hp1, hp2; zval **hd; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &value, &filters) == FAILURE) { RETURN_MM_NULL(); } /** * Apply an array of filters */ if (Z_TYPE_P(filters) == IS_ARRAY) { PHALCON_CPY_WRT(new_value, value); if (Z_TYPE_P(value) != IS_NULL) { if (!phalcon_is_iterable(filters, &ah0, &hp0, 0, 0 TSRMLS_CC)) { return; } while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_FOREACH_VALUE(filter); /** * If the value to filter is an array we apply the filters recursively */ if (Z_TYPE_P(new_value) == IS_ARRAY) { PHALCON_INIT_NVAR(array_value); array_init(array_value); if (!phalcon_is_iterable(new_value, &ah1, &hp1, 0, 0 TSRMLS_CC)) { return; } while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { PHALCON_GET_FOREACH_KEY(key, ah1, hp1); PHALCON_GET_FOREACH_VALUE(item_value); PHALCON_INIT_NVAR(filter_value); PHALCON_CALL_METHOD_PARAMS_2(filter_value, this_ptr, "_sanitize", item_value, filter); phalcon_array_update_zval(&array_value, key, &filter_value, PH_COPY | PH_SEPARATE TSRMLS_CC); zend_hash_move_forward_ex(ah1, &hp1); } PHALCON_CPY_WRT(new_value, array_value); } else { PHALCON_INIT_NVAR(filter_value); PHALCON_CALL_METHOD_PARAMS_2(filter_value, this_ptr, "_sanitize", new_value, filter); PHALCON_CPY_WRT(new_value, filter_value); } zend_hash_move_forward_ex(ah0, &hp0); } } RETURN_CCTOR(new_value); } /** * Apply a single filter value */ if (Z_TYPE_P(value) == IS_ARRAY) { PHALCON_INIT_VAR(sanizited_value); array_init(sanizited_value); if (!phalcon_is_iterable(value, &ah2, &hp2, 0, 0 TSRMLS_CC)) { return; } while (zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) == SUCCESS) { PHALCON_GET_FOREACH_KEY(key, ah2, hp2); PHALCON_GET_FOREACH_VALUE(item_value); PHALCON_INIT_NVAR(filter_value); PHALCON_CALL_METHOD_PARAMS_2(filter_value, this_ptr, "_sanitize", item_value, filters); phalcon_array_update_zval(&sanizited_value, key, &filter_value, PH_COPY | PH_SEPARATE TSRMLS_CC); zend_hash_move_forward_ex(ah2, &hp2); } } else { PHALCON_INIT_NVAR(sanizited_value); PHALCON_CALL_METHOD_PARAMS_2(sanizited_value, this_ptr, "_sanitize", value, filters); } RETURN_CCTOR(sanizited_value); }
/** * Generates SQL to add the table creation options * * @param array $definition * @return array */ PHP_METHOD(Phalcon_Db_Dialect_Postgresql, _getTableOptions){ zval *definition = NULL, *table_options = NULL, *engine = NULL, *auto_increment = NULL; zval *table_collation = NULL, *collation_parts = NULL; zval *a0 = 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, *r18 = NULL; zval *c0 = NULL, *c1 = NULL; int eval_int; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &definition) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } PHALCON_INIT_VAR(a0); array_init(a0); PHALCON_CPY_WRT(table_options, a0); PHALCON_ALLOC_ZVAL_MM(r0); phalcon_array_fetch_string(&r0, definition, SL("options"), PHALCON_NOISY TSRMLS_CC); eval_int = phalcon_array_isset_string(r0, SL("ENGINE")+1); if (eval_int) { PHALCON_ALLOC_ZVAL_MM(r1); phalcon_array_fetch_string(&r1, definition, SL("options"), PHALCON_NOISY TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(r2); phalcon_array_fetch_string(&r2, r1, SL("ENGINE"), PHALCON_NOISY TSRMLS_CC); PHALCON_CPY_WRT(engine, r2); PHALCON_ALLOC_ZVAL_MM(r3); phalcon_array_fetch_string(&r3, definition, SL("options"), PHALCON_NOISY TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(r4); phalcon_array_fetch_string(&r4, r3, SL("ENGINE"), PHALCON_NOISY TSRMLS_CC); if (zend_is_true(r4)) { PHALCON_ALLOC_ZVAL_MM(r5); PHALCON_CONCAT_SV(r5, "ENGINE=", engine); phalcon_array_append(&table_options, r5, PHALCON_SEPARATE_PLZ TSRMLS_CC); } } PHALCON_ALLOC_ZVAL_MM(r6); phalcon_array_fetch_string(&r6, definition, SL("options"), PHALCON_NOISY TSRMLS_CC); eval_int = phalcon_array_isset_string(r6, SL("AUTO_INCREMENT")+1); if (eval_int) { PHALCON_ALLOC_ZVAL_MM(r7); phalcon_array_fetch_string(&r7, definition, SL("options"), PHALCON_NOISY TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(r8); phalcon_array_fetch_string(&r8, r7, SL("AUTO_INCREMENT"), PHALCON_NOISY TSRMLS_CC); PHALCON_CPY_WRT(auto_increment, r8); if (zend_is_true(auto_increment)) { PHALCON_ALLOC_ZVAL_MM(r9); PHALCON_CONCAT_SV(r9, "AUTO_INCREMENT=", auto_increment); phalcon_array_append(&table_options, r9, PHALCON_SEPARATE_PLZ TSRMLS_CC); } } PHALCON_ALLOC_ZVAL_MM(r10); phalcon_array_fetch_string(&r10, definition, SL("options"), PHALCON_NOISY TSRMLS_CC); eval_int = phalcon_array_isset_string(r10, SL("TABLE_COLLATION")+1); if (eval_int) { PHALCON_ALLOC_ZVAL_MM(r11); phalcon_array_fetch_string(&r11, definition, SL("options"), PHALCON_NOISY TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(r12); phalcon_array_fetch_string(&r12, r11, SL("TABLE_COLLATION"), PHALCON_NOISY TSRMLS_CC); PHALCON_CPY_WRT(table_collation, r12); if (zend_is_true(table_collation)) { PHALCON_INIT_VAR(c0); ZVAL_STRING(c0, "_", 1); PHALCON_ALLOC_ZVAL_MM(r13); phalcon_fast_explode(r13, c0, table_collation TSRMLS_CC); PHALCON_CPY_WRT(collation_parts, r13); PHALCON_ALLOC_ZVAL_MM(r14); PHALCON_ALLOC_ZVAL_MM(r15); phalcon_array_fetch_long(&r15, collation_parts, 0, PHALCON_NOISY TSRMLS_CC); PHALCON_CONCAT_SV(r14, "DEFAULT CHARSET=", r15); phalcon_array_append(&table_options, r14, PHALCON_SEPARATE_PLZ TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(r16); PHALCON_CONCAT_SV(r16, "COLLATE=", table_collation); phalcon_array_append(&table_options, r16, PHALCON_SEPARATE_PLZ TSRMLS_CC); } } PHALCON_ALLOC_ZVAL_MM(r17); phalcon_fast_count(r17, table_options TSRMLS_CC); if (zend_is_true(r17)) { PHALCON_INIT_VAR(c1); ZVAL_STRING(c1, " ", 1); PHALCON_ALLOC_ZVAL_MM(r18); phalcon_fast_join(r18, c1, table_options TSRMLS_CC); RETURN_DZVAL(r18); } PHALCON_MM_RESTORE(); RETURN_NULL(); }
void uri_template_parse(char *tpl, zval *return_value, zval *vars, zval *capture) { smart_str result = {0}; zval *expressions = NULL; zval vars_ptr; unsigned char c; char *start; int state = URI_TEMPLATE_ERROR_NONE; if (capture != NULL) { MAKE_STD_ZVAL(expressions); array_init(expressions); } vars_ptr = *vars; zval_copy_ctor(&vars_ptr); while (*tpl) { if (*tpl == '{') { start = tpl + 1; while (*(tpl++) && *tpl != '}' && *tpl != '{'); if (*tpl == '}') { if (tpl - start > 0) { uri_template_expr *expr = build_expr(start, tpl - start); if (expr->error) { append_malformed_expr(&result, start, tpl - start); if (state == URI_TEMPLATE_ERROR_NONE) { state = URI_TEMPLATE_ERROR_EXPRESSION; } } else { uri_template_process(expr, &vars_ptr, &result); } if (expressions != NULL) { add_expr_to_array(expressions, expr); } uri_template_expr_free(expr); } else { smart_str_appends(&result, "{}"); } } else if (*tpl == '{') { smart_str_appendl(&result, start - 1, tpl - start + 1); state = URI_TEMPLATE_ERROR_SYNTAX; tpl--; } else { smart_str_appendc(&result, '{'); smart_str_appendl(&result, start, tpl - start); state = URI_TEMPLATE_ERROR_SYNTAX; } } else { c = *tpl; if (c == '}') { smart_str_appendc(&result, '}'); state = URI_TEMPLATE_ERROR_SYNTAX; } else if (c == '%' && isxdigit(*(tpl + 1)) && isxdigit(*(tpl + 2))) { smart_str_appendc(&result, '%'); smart_str_appendc(&result, *(++tpl)); smart_str_appendc(&result, *(++tpl)); } else { int result_len = result.len; int distance = 0; uri_template_substr_copy(&result, tpl, 1, URI_TEMPLATE_ALLOW_RESERVED); distance = result.len - result_len; tpl += (distance % 3 ? 1 : distance / 3) - 1; } } tpl++; } smart_str_0(&result); ZVAL_STRING(return_value, result.c ? result.c : "", 1); if (capture != NULL) { add_assoc_string(capture, "result", result.c ? result.c : "", 1); add_assoc_long(capture, "state", state); add_assoc_zval(capture, "expressions", expressions); } zval_dtor(&vars_ptr); smart_str_free(&result); }
/** * Extracts a slice from a string/array/traversable object value */ PHP_METHOD(Phalcon_Mvc_View_Engine_Volt, slice) { zephir_fcall_cache_entry *_3 = NULL, *_4 = NULL, *_6 = NULL; zend_bool _1; int start, position, ZEPHIR_LAST_CALL_STATUS; zval *value, *start_param = NULL, *end = NULL, *length, *slice, *_0 = NULL, *_2 = NULL, _5 = zval_used_for_init; ZEPHIR_MM_GROW(); zephir_fetch_params(1, 1, 2, &value, &start_param, &end); if (!start_param) { start = 0; } else { start = zephir_get_intval(start_param); } if (!end) { ZEPHIR_CPY_WRT(end, ZEPHIR_GLOBAL(global_null)); } else { ZEPHIR_SEPARATE_PARAM(end); } if (Z_TYPE_P(value) == IS_OBJECT) { if (Z_TYPE_P(end) == IS_NULL) { ZEPHIR_INIT_NVAR(end); ZVAL_LONG(end, (zephir_fast_count_int(value TSRMLS_CC) - 1)); } position = 0; ZEPHIR_INIT_VAR(slice); array_init(slice); ZEPHIR_CALL_METHOD(NULL, value, "rewind", NULL, 0); zephir_check_call_status(); while (1) { ZEPHIR_CALL_METHOD(&_0, value, "valid", NULL, 0); zephir_check_call_status(); if (!(zephir_is_true(_0))) { break; } _1 = position >= start; if (_1) { _1 = ZEPHIR_GE_LONG(end, position); } if (_1) { ZEPHIR_CALL_METHOD(&_2, value, "current", &_3, 0); zephir_check_call_status(); zephir_array_append(&slice, _2, PH_SEPARATE, "phalcon/mvc/view/engine/volt.zep", 231); } ZEPHIR_CALL_METHOD(NULL, value, "next", &_4, 0); zephir_check_call_status(); position++; } RETURN_CCTOR(slice); } ZEPHIR_INIT_VAR(length); if (Z_TYPE_P(end) != IS_NULL) { ZVAL_LONG(length, (((zephir_get_numberval(end) - start)) + 1)); } else { ZVAL_NULL(length); } if (Z_TYPE_P(value) == IS_ARRAY) { ZEPHIR_SINIT_VAR(_5); ZVAL_LONG(&_5, start); ZEPHIR_RETURN_CALL_FUNCTION("array_slice", NULL, 373, value, &_5, length); zephir_check_call_status(); RETURN_MM(); } if ((zephir_function_exists_ex(SS("mb_substr") TSRMLS_CC) == SUCCESS)) { if (Z_TYPE_P(length) != IS_NULL) { ZEPHIR_SINIT_NVAR(_5); ZVAL_LONG(&_5, start); ZEPHIR_RETURN_CALL_FUNCTION("mb_substr", &_6, 374, value, &_5, length); zephir_check_call_status(); RETURN_MM(); } ZEPHIR_SINIT_NVAR(_5); ZVAL_LONG(&_5, start); ZEPHIR_RETURN_CALL_FUNCTION("mb_substr", &_6, 374, value, &_5); zephir_check_call_status(); RETURN_MM(); } if (Z_TYPE_P(length) != IS_NULL) { ZEPHIR_SINIT_NVAR(_5); ZVAL_LONG(&_5, start); zephir_substr(return_value, value, zephir_get_intval(&_5), zephir_get_intval(length), 0); RETURN_MM(); } ZEPHIR_SINIT_NVAR(_5); ZVAL_LONG(&_5, start); zephir_substr(return_value, value, zephir_get_intval(&_5), 0, ZEPHIR_SUBSTR_NO_LENGTH); RETURN_MM(); }
/** * Returns an array of Phalcon\Db\Column objects describing a table * * <code>print_r($connection->describeColumns("posts")); ?></code> */ PHP_METHOD(Phalcon_Db_Adapter_Pdo_Oracle, describeColumns) { HashTable *_5; HashPosition _4; zephir_fcall_cache_entry *_24 = NULL; int ZEPHIR_LAST_CALL_STATUS; zval *table_param = NULL, *schema_param = NULL, *columns = NULL, *oldColumn = NULL, *field = NULL, *definition = NULL, *columnSize = NULL, *columnPrecision = NULL, *columnScale = NULL, *columnType = NULL, *columnName = NULL, *_0 = NULL, *_1, *_2 = NULL, *_3, **_6, *_7$$5 = NULL, *_8$$5 = NULL, *_9$$6 = NULL, *_10$$6 = NULL, *_11$$7 = NULL, *_12$$8 = NULL, *_13$$8 = NULL, *_14$$9 = NULL, *_15$$10 = NULL, *_16$$11 = NULL, *_17$$12 = NULL, *_18$$13 = NULL, *_19$$14 = NULL, *_20$$4 = NULL, *_21$$3, *_22$$3, *_23$$3 = NULL; zval *table = NULL, *schema = NULL; ZEPHIR_MM_GROW(); zephir_fetch_params(1, 1, 1, &table_param, &schema_param); if (unlikely(Z_TYPE_P(table_param) != IS_STRING && Z_TYPE_P(table_param) != IS_NULL)) { zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'table' must be a string") TSRMLS_CC); RETURN_MM_NULL(); } if (likely(Z_TYPE_P(table_param) == IS_STRING)) { zephir_get_strval(table, table_param); } else { ZEPHIR_INIT_VAR(table); ZVAL_EMPTY_STRING(table); } if (!schema_param) { ZEPHIR_INIT_VAR(schema); ZVAL_EMPTY_STRING(schema); } else { zephir_get_strval(schema, schema_param); } ZEPHIR_INIT_VAR(columns); array_init(columns); ZEPHIR_INIT_VAR(oldColumn); ZVAL_NULL(oldColumn); _1 = zephir_fetch_nproperty_this(this_ptr, SL("_dialect"), PH_NOISY_CC); ZEPHIR_CALL_METHOD(&_2, _1, "describecolumns", NULL, 0, table, schema); zephir_check_call_status(); ZEPHIR_INIT_VAR(_3); ZVAL_LONG(_3, 3); ZEPHIR_CALL_METHOD(&_0, this_ptr, "fetchall", NULL, 0, _2, _3); zephir_check_call_status(); zephir_is_iterable(_0, &_5, &_4, 0, 0, "phalcon/db/adapter/pdo/oracle.zep", 208); for ( ; zephir_hash_get_current_data_ex(_5, (void**) &_6, &_4) == SUCCESS ; zephir_hash_move_forward_ex(_5, &_4) ) { ZEPHIR_GET_HVALUE(field, _6); ZEPHIR_INIT_NVAR(definition); zephir_create_array(definition, 1, 0 TSRMLS_CC); add_assoc_long_ex(definition, SS("bindType"), 2); ZEPHIR_OBS_NVAR(columnSize); zephir_array_fetch_long(&columnSize, field, 2, PH_NOISY, "phalcon/db/adapter/pdo/oracle.zep", 102 TSRMLS_CC); ZEPHIR_OBS_NVAR(columnPrecision); zephir_array_fetch_long(&columnPrecision, field, 3, PH_NOISY, "phalcon/db/adapter/pdo/oracle.zep", 103 TSRMLS_CC); ZEPHIR_OBS_NVAR(columnScale); zephir_array_fetch_long(&columnScale, field, 4, PH_NOISY, "phalcon/db/adapter/pdo/oracle.zep", 104 TSRMLS_CC); ZEPHIR_OBS_NVAR(columnType); zephir_array_fetch_long(&columnType, field, 1, PH_NOISY, "phalcon/db/adapter/pdo/oracle.zep", 105 TSRMLS_CC); while (1) { if (zephir_memnstr_str(columnType, SL("NUMBER"), "phalcon/db/adapter/pdo/oracle.zep", 112)) { ZEPHIR_INIT_NVAR(_7$$5); ZVAL_LONG(_7$$5, 3); zephir_array_update_string(&definition, SL("type"), &_7$$5, PH_COPY | PH_SEPARATE); zephir_array_update_string(&definition, SL("isNumeric"), &ZEPHIR_GLOBAL(global_true), PH_COPY | PH_SEPARATE); zephir_array_update_string(&definition, SL("size"), &columnPrecision, PH_COPY | PH_SEPARATE); zephir_array_update_string(&definition, SL("scale"), &columnScale, PH_COPY | PH_SEPARATE); ZEPHIR_INIT_NVAR(_8$$5); ZVAL_LONG(_8$$5, 32); zephir_array_update_string(&definition, SL("bindType"), &_8$$5, PH_COPY | PH_SEPARATE); break; } if (zephir_memnstr_str(columnType, SL("INTEGER"), "phalcon/db/adapter/pdo/oracle.zep", 121)) { ZEPHIR_INIT_NVAR(_9$$6); ZVAL_LONG(_9$$6, 0); zephir_array_update_string(&definition, SL("type"), &_9$$6, PH_COPY | PH_SEPARATE); zephir_array_update_string(&definition, SL("isNumeric"), &ZEPHIR_GLOBAL(global_true), PH_COPY | PH_SEPARATE); zephir_array_update_string(&definition, SL("size"), &columnPrecision, PH_COPY | PH_SEPARATE); ZEPHIR_INIT_NVAR(_10$$6); ZVAL_LONG(_10$$6, 1); zephir_array_update_string(&definition, SL("bindType"), &_10$$6, PH_COPY | PH_SEPARATE); break; } if (zephir_memnstr_str(columnType, SL("VARCHAR2"), "phalcon/db/adapter/pdo/oracle.zep", 129)) { ZEPHIR_INIT_NVAR(_11$$7); ZVAL_LONG(_11$$7, 2); zephir_array_update_string(&definition, SL("type"), &_11$$7, PH_COPY | PH_SEPARATE); zephir_array_update_string(&definition, SL("size"), &columnSize, PH_COPY | PH_SEPARATE); break; } if (zephir_memnstr_str(columnType, SL("FLOAT"), "phalcon/db/adapter/pdo/oracle.zep", 135)) { ZEPHIR_INIT_NVAR(_12$$8); ZVAL_LONG(_12$$8, 7); zephir_array_update_string(&definition, SL("type"), &_12$$8, PH_COPY | PH_SEPARATE); zephir_array_update_string(&definition, SL("isNumeric"), &ZEPHIR_GLOBAL(global_true), PH_COPY | PH_SEPARATE); zephir_array_update_string(&definition, SL("size"), &columnSize, PH_COPY | PH_SEPARATE); zephir_array_update_string(&definition, SL("scale"), &columnScale, PH_COPY | PH_SEPARATE); ZEPHIR_INIT_NVAR(_13$$8); ZVAL_LONG(_13$$8, 32); zephir_array_update_string(&definition, SL("bindType"), &_13$$8, PH_COPY | PH_SEPARATE); break; } if (zephir_memnstr_str(columnType, SL("TIMESTAMP"), "phalcon/db/adapter/pdo/oracle.zep", 144)) { ZEPHIR_INIT_NVAR(_14$$9); ZVAL_LONG(_14$$9, 17); zephir_array_update_string(&definition, SL("type"), &_14$$9, PH_COPY | PH_SEPARATE); break; } if (zephir_memnstr_str(columnType, SL("DATE"), "phalcon/db/adapter/pdo/oracle.zep", 149)) { ZEPHIR_INIT_NVAR(_15$$10); ZVAL_LONG(_15$$10, 1); zephir_array_update_string(&definition, SL("type"), &_15$$10, PH_COPY | PH_SEPARATE); break; } if (zephir_memnstr_str(columnType, SL("RAW"), "phalcon/db/adapter/pdo/oracle.zep", 154)) { ZEPHIR_INIT_NVAR(_16$$11); ZVAL_LONG(_16$$11, 6); zephir_array_update_string(&definition, SL("type"), &_16$$11, PH_COPY | PH_SEPARATE); break; } if (zephir_memnstr_str(columnType, SL("BLOB"), "phalcon/db/adapter/pdo/oracle.zep", 159)) { ZEPHIR_INIT_NVAR(_17$$12); ZVAL_LONG(_17$$12, 6); zephir_array_update_string(&definition, SL("type"), &_17$$12, PH_COPY | PH_SEPARATE); break; } if (zephir_memnstr_str(columnType, SL("CLOB"), "phalcon/db/adapter/pdo/oracle.zep", 164)) { ZEPHIR_INIT_NVAR(_18$$13); ZVAL_LONG(_18$$13, 6); zephir_array_update_string(&definition, SL("type"), &_18$$13, PH_COPY | PH_SEPARATE); break; } if (zephir_memnstr_str(columnType, SL("CHAR"), "phalcon/db/adapter/pdo/oracle.zep", 169)) { ZEPHIR_INIT_NVAR(_19$$14); ZVAL_LONG(_19$$14, 5); zephir_array_update_string(&definition, SL("type"), &_19$$14, PH_COPY | PH_SEPARATE); zephir_array_update_string(&definition, SL("size"), &columnSize, PH_COPY | PH_SEPARATE); break; } ZEPHIR_INIT_NVAR(_20$$4); ZVAL_LONG(_20$$4, 6); zephir_array_update_string(&definition, SL("type"), &_20$$4, PH_COPY | PH_SEPARATE); break; } if (Z_TYPE_P(oldColumn) == IS_NULL) { zephir_array_update_string(&definition, SL("first"), &ZEPHIR_GLOBAL(global_true), PH_COPY | PH_SEPARATE); } else { zephir_array_update_string(&definition, SL("after"), &oldColumn, PH_COPY | PH_SEPARATE); } zephir_array_fetch_long(&_21$$3, field, 6, PH_NOISY | PH_READONLY, "phalcon/db/adapter/pdo/oracle.zep", 188 TSRMLS_CC); if (ZEPHIR_IS_STRING(_21$$3, "P")) { zephir_array_update_string(&definition, SL("primary"), &ZEPHIR_GLOBAL(global_true), PH_COPY | PH_SEPARATE); } zephir_array_fetch_long(&_22$$3, field, 5, PH_NOISY | PH_READONLY, "phalcon/db/adapter/pdo/oracle.zep", 195 TSRMLS_CC); if (ZEPHIR_IS_STRING(_22$$3, "N")) { zephir_array_update_string(&definition, SL("notNull"), &ZEPHIR_GLOBAL(global_true), PH_COPY | PH_SEPARATE); } zephir_array_fetch_long(&columnName, field, 0, PH_NOISY | PH_READONLY, "phalcon/db/adapter/pdo/oracle.zep", 199 TSRMLS_CC); ZEPHIR_INIT_NVAR(_23$$3); object_init_ex(_23$$3, phalcon_db_column_ce); ZEPHIR_CALL_METHOD(NULL, _23$$3, "__construct", &_24, 137, columnName, definition); zephir_check_call_status(); zephir_array_append(&columns, _23$$3, PH_SEPARATE, "phalcon/db/adapter/pdo/oracle.zep", 204); ZEPHIR_CPY_WRT(oldColumn, columnName); } RETURN_CCTOR(columns); }
PHP_METHOD(Transbybd_TransApi, translate) { zval *args = NULL; int ZEPHIR_LAST_CALL_STATUS; zval *query_param = NULL, *from_param = NULL, *to_param = NULL, *ret = NULL, *_0, _1, _2, *_3 = NULL, *_4, *_5; zval *query = NULL, *from = NULL, *to = NULL; ZEPHIR_MM_GROW(); zephir_fetch_params(1, 3, 0, &query_param, &from_param, &to_param); if (unlikely(Z_TYPE_P(query_param) != IS_STRING && Z_TYPE_P(query_param) != IS_NULL)) { zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'query' must be a string") TSRMLS_CC); RETURN_MM_NULL(); } if (likely(Z_TYPE_P(query_param) == IS_STRING)) { zephir_get_strval(query, query_param); } else { ZEPHIR_INIT_VAR(query); ZVAL_EMPTY_STRING(query); } if (unlikely(Z_TYPE_P(from_param) != IS_STRING && Z_TYPE_P(from_param) != IS_NULL)) { zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'from' must be a string") TSRMLS_CC); RETURN_MM_NULL(); } if (likely(Z_TYPE_P(from_param) == IS_STRING)) { zephir_get_strval(from, from_param); } else { ZEPHIR_INIT_VAR(from); ZVAL_EMPTY_STRING(from); } if (unlikely(Z_TYPE_P(to_param) != IS_STRING && Z_TYPE_P(to_param) != IS_NULL)) { zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'to' must be a string") TSRMLS_CC); RETURN_MM_NULL(); } if (likely(Z_TYPE_P(to_param) == IS_STRING)) { zephir_get_strval(to, to_param); } else { ZEPHIR_INIT_VAR(to); ZVAL_EMPTY_STRING(to); } ZEPHIR_INIT_VAR(args); array_init(args); ZEPHIR_INIT_NVAR(args); zephir_create_array(args, 5, 0 TSRMLS_CC); zephir_array_update_string(&args, SL("q"), &query, PH_COPY | PH_SEPARATE); ZEPHIR_OBS_VAR(_0); zephir_read_property_this(&_0, this_ptr, SL("app_id"), PH_NOISY_CC); zephir_array_update_string(&args, SL("appid"), &_0, PH_COPY | PH_SEPARATE); ZEPHIR_SINIT_VAR(_1); ZVAL_LONG(&_1, 10000); ZEPHIR_SINIT_VAR(_2); ZVAL_LONG(&_2, 99999); ZEPHIR_CALL_FUNCTION(&_3, "rand", NULL, 1, &_1, &_2); zephir_check_call_status(); zephir_array_update_string(&args, SL("salt"), &_3, PH_COPY | PH_SEPARATE); zephir_array_update_string(&args, SL("from"), &from, PH_COPY | PH_SEPARATE); zephir_array_update_string(&args, SL("to"), &to, PH_COPY | PH_SEPARATE); zephir_array_fetch_string(&_4, args, SL("salt"), PH_NOISY | PH_READONLY, "transbybd/transApi.zep", 33 TSRMLS_CC); ZEPHIR_CALL_METHOD(&_3, this_ptr, "__buildsign", NULL, 2, query, _4); zephir_check_call_status(); zephir_array_update_string(&args, SL("sign"), &_3, PH_COPY | PH_SEPARATE); ZEPHIR_CALL_METHOD(&ret, this_ptr, "__callmutil", NULL, 3, args); zephir_check_call_status(); ZEPHIR_INIT_VAR(_5); zephir_json_decode(_5, &(_5), ret, zephir_get_intval(ZEPHIR_GLOBAL(global_true)) TSRMLS_CC); ZEPHIR_CPY_WRT(ret, _5); RETURN_CCTOR(ret); }
static int http_request_on_header_value(php_http_parser *parser, const char *at, size_t length) { TSRMLS_FETCH_FROM_CTX(sw_thread_ctx ? sw_thread_ctx : NULL); http_client *client = parser->data; char *header_name = zend_str_tolower_dup(client->current_header_name, client->current_header_name_len); if (memcmp(header_name, ZEND_STRL("cookie")) == 0) { zval *cookie; MAKE_STD_ZVAL(cookie); array_init(cookie); zend_update_property(swoole_http_request_class_entry_ptr, client->zrequest, ZEND_STRL("cookie"), cookie TSRMLS_CC); struct { char *k; int klen; char *v; int vlen; } kv = { 0 }; char keybuf[SW_HTTP_COOKIE_KEYLEN]; char *_c = (char *) at; int n = 1; kv.k = _c; while (_c < at + length) { if (*_c == '=') { kv.v = _c + 1; kv.klen = n; n = 0; } else if (*_c == ';') { kv.vlen = n; if (kv.klen >= SW_HTTP_COOKIE_KEYLEN) { kv.klen = SW_HTTP_COOKIE_KEYLEN - 1; } memcpy(keybuf, kv.k, kv.klen - 1); keybuf[kv.klen - 1] = 0; add_assoc_stringl_ex(cookie, keybuf, kv.klen, kv.v, kv.vlen, 1); kv.k = _c + 2; n = 0; } else { n++; } _c++; } kv.vlen = n; if (kv.klen >= SW_HTTP_COOKIE_KEYLEN) { kv.klen = SW_HTTP_COOKIE_KEYLEN - 1; } memcpy(keybuf, kv.k, kv.klen - 1); keybuf[kv.klen - 1] = 0; add_assoc_stringl_ex(cookie, keybuf, kv.klen , kv.v, kv.vlen, 1); ZEND_SET_SYMBOL(&EG(symbol_table), "_COOKIE", cookie); } else if (memcmp(header_name, ZEND_STRL("upgrade")) == 0 && memcmp(at, ZEND_STRL("websocket")) == 0) { SwooleG.lock.lock(&SwooleG.lock); swConnection *conn = swServer_connection_get(SwooleG.serv, client->fd); if(conn->websocket_status == 0) { conn->websocket_status = WEBSOCKET_STATUS_CONNECTION; } SwooleG.lock.unlock(&SwooleG.lock); zval *header = zend_read_property(swoole_http_request_class_entry_ptr, client->zrequest, ZEND_STRL("header"), 1 TSRMLS_CC); add_assoc_stringl_ex(header, header_name, client->current_header_name_len + 1, (char *) at, length, 1); } else if (parser->method == PHP_HTTP_POST && memcmp(header_name, ZEND_STRL("content-type")) == 0 && memcmp(at, ZEND_STRL("application/x-www-form-urlencoded")) == 0) { client->request.post_form_urlencoded = 1; zval *header = zend_read_property(swoole_http_request_class_entry_ptr, client->zrequest, ZEND_STRL("header"), 1 TSRMLS_CC); add_assoc_stringl_ex(header, header_name, client->current_header_name_len + 1, (char *) at, length, 1); } else { zval *header = zend_read_property(swoole_http_request_class_entry_ptr, client->zrequest, ZEND_STRL("header"), 1 TSRMLS_CC); add_assoc_stringl_ex(header, header_name, client->current_header_name_len + 1, (char *) at, length, 1); } if (client->current_header_name_allocated) { efree(client->current_header_name); client->current_header_name_allocated = 0; } efree(header_name); return 0; }
/** * Checks for annotations in the public methods of the controller * * @param string module * @param string namespaceName * @param string controller * @param string action * @param Phalcon\Annotations\Annotation annotation */ PHP_METHOD(Phalcon_Mvc_Router_Annotations, processActionAnnotation) { zephir_fcall_cache_entry *_7 = NULL, *_11 = NULL; HashTable *_5, *_9; HashPosition _4, _8; int ZEPHIR_LAST_CALL_STATUS; zend_bool isRoute, _12; zval *module_param = NULL, *namespaceName_param = NULL, *controller_param = NULL, *action_param = NULL, *annotation, *name = NULL, *actionName, *routePrefix, *paths = NULL, *value = NULL, *uri = NULL, *route = NULL, *methods = NULL, *converts = NULL, *param = NULL, *convert = NULL, *conversorParam = NULL, *routeName = NULL, *beforeMatch = NULL, *_0, *_1, _2, *_3 = NULL, **_6, **_10; zval *module = NULL, *namespaceName = NULL, *controller = NULL, *action = NULL; ZEPHIR_MM_GROW(); zephir_fetch_params(1, 5, 0, &module_param, &namespaceName_param, &controller_param, &action_param, &annotation); if (unlikely(Z_TYPE_P(module_param) != IS_STRING && Z_TYPE_P(module_param) != IS_NULL)) { zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'module' must be a string") TSRMLS_CC); RETURN_MM_NULL(); } if (likely(Z_TYPE_P(module_param) == IS_STRING)) { zephir_get_strval(module, module_param); } else { ZEPHIR_INIT_VAR(module); ZVAL_EMPTY_STRING(module); } if (unlikely(Z_TYPE_P(namespaceName_param) != IS_STRING && Z_TYPE_P(namespaceName_param) != IS_NULL)) { zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'namespaceName' must be a string") TSRMLS_CC); RETURN_MM_NULL(); } if (likely(Z_TYPE_P(namespaceName_param) == IS_STRING)) { zephir_get_strval(namespaceName, namespaceName_param); } else { ZEPHIR_INIT_VAR(namespaceName); ZVAL_EMPTY_STRING(namespaceName); } if (unlikely(Z_TYPE_P(controller_param) != IS_STRING && Z_TYPE_P(controller_param) != IS_NULL)) { zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'controller' must be a string") TSRMLS_CC); RETURN_MM_NULL(); } if (likely(Z_TYPE_P(controller_param) == IS_STRING)) { zephir_get_strval(controller, controller_param); } else { ZEPHIR_INIT_VAR(controller); ZVAL_EMPTY_STRING(controller); } if (unlikely(Z_TYPE_P(action_param) != IS_STRING && Z_TYPE_P(action_param) != IS_NULL)) { zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'action' must be a string") TSRMLS_CC); RETURN_MM_NULL(); } if (likely(Z_TYPE_P(action_param) == IS_STRING)) { zephir_get_strval(action, action_param); } else { ZEPHIR_INIT_VAR(action); ZVAL_EMPTY_STRING(action); } isRoute = 0; ZEPHIR_INIT_VAR(methods); ZVAL_NULL(methods); ZEPHIR_CALL_METHOD(&name, annotation, "getname", NULL, 0); zephir_check_call_status(); do { if (ZEPHIR_IS_STRING(name, "Route")) { isRoute = 1; break; } if (ZEPHIR_IS_STRING(name, "Get")) { isRoute = 1; ZEPHIR_INIT_NVAR(methods); ZVAL_STRING(methods, "GET", 1); break; } if (ZEPHIR_IS_STRING(name, "Post")) { isRoute = 1; ZEPHIR_INIT_NVAR(methods); ZVAL_STRING(methods, "POST", 1); break; } if (ZEPHIR_IS_STRING(name, "Put")) { isRoute = 1; ZEPHIR_INIT_NVAR(methods); ZVAL_STRING(methods, "PUT", 1); break; } if (ZEPHIR_IS_STRING(name, "Delete")) { isRoute = 1; ZEPHIR_INIT_NVAR(methods); ZVAL_STRING(methods, "DELETE", 1); break; } if (ZEPHIR_IS_STRING(name, "Options")) { isRoute = 1; ZEPHIR_INIT_NVAR(methods); ZVAL_STRING(methods, "OPTIONS", 1); break; } } while(0); if (isRoute == 1) { ZEPHIR_INIT_VAR(_0); _1 = zephir_fetch_nproperty_this(this_ptr, SL("_actionSuffix"), PH_NOISY_CC); ZEPHIR_SINIT_VAR(_2); ZVAL_STRING(&_2, "", 0); zephir_fast_str_replace(&_0, _1, &_2, action TSRMLS_CC); ZEPHIR_INIT_VAR(actionName); zephir_fast_strtolower(actionName, _0); ZEPHIR_OBS_VAR(routePrefix); zephir_read_property_this(&routePrefix, this_ptr, SL("_routePrefix"), PH_NOISY_CC); ZEPHIR_INIT_VAR(_3); ZVAL_STRING(_3, "paths", ZEPHIR_TEMP_PARAM_COPY); ZEPHIR_CALL_METHOD(&paths, annotation, "getnamedargument", NULL, 0, _3); zephir_check_temp_parameter(_3); zephir_check_call_status(); if (Z_TYPE_P(paths) != IS_ARRAY) { ZEPHIR_INIT_NVAR(paths); array_init(paths); } if (!(ZEPHIR_IS_EMPTY(module))) { zephir_array_update_string(&paths, SL("module"), &module, PH_COPY | PH_SEPARATE); } if (!(ZEPHIR_IS_EMPTY(namespaceName))) { zephir_array_update_string(&paths, SL("namespace"), &namespaceName, PH_COPY | PH_SEPARATE); } zephir_array_update_string(&paths, SL("controller"), &controller, PH_COPY | PH_SEPARATE); zephir_array_update_string(&paths, SL("action"), &actionName, PH_COPY | PH_SEPARATE); ZEPHIR_INIT_NVAR(_3); ZVAL_LONG(_3, 0); ZEPHIR_CALL_METHOD(&value, annotation, "getargument", NULL, 0, _3); zephir_check_call_status(); if (Z_TYPE_P(value) != IS_NULL) { if (!ZEPHIR_IS_STRING(value, "/")) { ZEPHIR_INIT_VAR(uri); ZEPHIR_CONCAT_VV(uri, routePrefix, value); } else { if (Z_TYPE_P(routePrefix) != IS_NULL) { ZEPHIR_CPY_WRT(uri, routePrefix); } else { ZEPHIR_CPY_WRT(uri, value); } } } else { ZEPHIR_INIT_NVAR(uri); ZEPHIR_CONCAT_VV(uri, routePrefix, actionName); } ZEPHIR_CALL_METHOD(&route, this_ptr, "add", NULL, 0, uri, paths); zephir_check_call_status(); if (Z_TYPE_P(methods) != IS_NULL) { ZEPHIR_CALL_METHOD(NULL, route, "via", NULL, 0, methods); zephir_check_call_status(); } else { ZEPHIR_INIT_NVAR(_3); ZVAL_STRING(_3, "methods", ZEPHIR_TEMP_PARAM_COPY); ZEPHIR_CALL_METHOD(&methods, annotation, "getnamedargument", NULL, 0, _3); zephir_check_temp_parameter(_3); zephir_check_call_status(); if (Z_TYPE_P(methods) == IS_ARRAY) { ZEPHIR_CALL_METHOD(NULL, route, "via", NULL, 0, methods); zephir_check_call_status(); } else { if (Z_TYPE_P(methods) == IS_STRING) { ZEPHIR_CALL_METHOD(NULL, route, "via", NULL, 0, methods); zephir_check_call_status(); } } } ZEPHIR_INIT_NVAR(_3); ZVAL_STRING(_3, "converts", ZEPHIR_TEMP_PARAM_COPY); ZEPHIR_CALL_METHOD(&converts, annotation, "getnamedargument", NULL, 0, _3); zephir_check_temp_parameter(_3); zephir_check_call_status(); if (Z_TYPE_P(converts) == IS_ARRAY) { zephir_is_iterable(converts, &_5, &_4, 0, 0, "phalcon/mvc/router/annotations.zep", 360); for ( ; zephir_hash_get_current_data_ex(_5, (void**) &_6, &_4) == SUCCESS ; zephir_hash_move_forward_ex(_5, &_4) ) { ZEPHIR_GET_HMKEY(param, _5, _4); ZEPHIR_GET_HVALUE(convert, _6); ZEPHIR_CALL_METHOD(NULL, route, "convert", &_7, 0, param, convert); zephir_check_call_status(); } } ZEPHIR_INIT_NVAR(_3); ZVAL_STRING(_3, "conversors", ZEPHIR_TEMP_PARAM_COPY); ZEPHIR_CALL_METHOD(&converts, annotation, "getnamedargument", NULL, 0, _3); zephir_check_temp_parameter(_3); zephir_check_call_status(); if (Z_TYPE_P(converts) == IS_ARRAY) { zephir_is_iterable(converts, &_9, &_8, 0, 0, "phalcon/mvc/router/annotations.zep", 370); for ( ; zephir_hash_get_current_data_ex(_9, (void**) &_10, &_8) == SUCCESS ; zephir_hash_move_forward_ex(_9, &_8) ) { ZEPHIR_GET_HMKEY(conversorParam, _9, _8); ZEPHIR_GET_HVALUE(convert, _10); ZEPHIR_CALL_METHOD(NULL, route, "convert", &_11, 0, conversorParam, convert); zephir_check_call_status(); } } ZEPHIR_INIT_NVAR(_3); ZVAL_STRING(_3, "beforeMatch", ZEPHIR_TEMP_PARAM_COPY); ZEPHIR_CALL_METHOD(&beforeMatch, annotation, "getnamedargument", NULL, 0, _3); zephir_check_temp_parameter(_3); zephir_check_call_status(); _12 = Z_TYPE_P(beforeMatch) == IS_ARRAY; if (!(_12)) { _12 = Z_TYPE_P(beforeMatch) == IS_STRING; } if (_12) { ZEPHIR_CALL_METHOD(NULL, route, "beforematch", NULL, 0, beforeMatch); zephir_check_call_status(); } ZEPHIR_INIT_NVAR(_3); ZVAL_STRING(_3, "name", ZEPHIR_TEMP_PARAM_COPY); ZEPHIR_CALL_METHOD(&routeName, annotation, "getnamedargument", NULL, 0, _3); zephir_check_temp_parameter(_3); zephir_check_call_status(); if (Z_TYPE_P(routeName) == IS_STRING) { ZEPHIR_CALL_METHOD(NULL, route, "setname", NULL, 0, routeName); zephir_check_call_status(); } RETURN_MM_BOOL(1); } ZEPHIR_MM_RESTORE(); }
static int http_onReceive(swFactory *factory, swEventData *req) { TSRMLS_FETCH_FROM_CTX(sw_thread_ctx ? sw_thread_ctx : NULL); int fd = req->info.fd; // swTrace("on receive:%s pid:%d\n", zdata, getpid()); swConnection *conn = swServer_connection_get(SwooleG.serv, fd); if(conn->websocket_status == WEBSOCKET_STATUS_HANDSHAKE) //websocket callback { zval *zdata = php_swoole_get_data(req TSRMLS_CC); swTrace("on message callback\n"); char *buf = Z_STRVAL_P(zdata); long fin = buf[0] ? 1 : 0; long opcode = buf[1] ? 1 : 0; buf+=2; zval *zresponse; MAKE_STD_ZVAL(zresponse); object_init_ex(zresponse, swoole_http_wsresponse_class_entry_ptr); //socket fd zend_update_property_long(swoole_http_wsresponse_class_entry_ptr, zresponse, ZEND_STRL("fd"), fd TSRMLS_CC); zend_update_property_long(swoole_http_wsresponse_class_entry_ptr, zresponse, ZEND_STRL("fin"), fin TSRMLS_CC); zend_update_property_long(swoole_http_wsresponse_class_entry_ptr, zresponse, ZEND_STRL("opcode"), opcode TSRMLS_CC); zend_update_property_stringl(swoole_http_wsresponse_class_entry_ptr, zresponse, ZEND_STRL("data"), buf, (Z_STRLEN_P(zdata)-2) TSRMLS_CC); zval **args[1]; args[0] = &zresponse; zval *retval; if (call_user_function_ex(EG(function_table), NULL, php_sw_http_server_callbacks[1], &retval, 1, args, 0, NULL TSRMLS_CC) == FAILURE) { zval_ptr_dtor(&zdata); php_error_docref(NULL TSRMLS_CC, E_WARNING, "onMessage handler error"); } swTrace("===== message callback end======"); if (EG(exception)) { zval_ptr_dtor(&zdata); zend_exception_error(EG(exception), E_ERROR TSRMLS_CC); } if (retval) { zval_ptr_dtor(&retval); } zval_ptr_dtor(&zdata); return SW_OK; } http_client *client = swHashMap_find_int(php_sw_http_clients, fd); if (!client) { client = http_client_new(fd TSRMLS_CC); } php_http_parser *parser = &client->parser; /** * create request and response object */ http_request_new(client TSRMLS_CC); parser->data = client; php_http_parser_init(parser, PHP_HTTP_REQUEST); zval *zdata = php_swoole_get_data(req TSRMLS_CC); //server info zval *_request; MAKE_STD_ZVAL(_request); array_init(_request); zend_update_property(swoole_http_request_class_entry_ptr, client->zrequest, ZEND_STRL("request"), _request TSRMLS_CC); size_t n = php_http_parser_execute(parser, &http_parser_settings, Z_STRVAL_P(zdata), Z_STRLEN_P(zdata)); zval_ptr_dtor(&zdata); if (n < 0) { swWarn("php_http_parser_execute failed."); if(conn->websocket_status == WEBSOCKET_STATUS_CONNECTION) { SwooleG.serv->factory.end(&SwooleG.serv->factory, fd); } } else { if(conn->websocket_status == WEBSOCKET_STATUS_CONNECTION) // need handshake { if(php_sw_http_server_callbacks[2] == NULL) { int ret = websocket_handshake(client); http_request_free(client TSRMLS_CC); if (ret == SW_ERR) { swTrace("websocket handshake error\n"); SwooleG.serv->factory.end(&SwooleG.serv->factory, fd); } else { handshake_success(fd); swTrace("websocket handshake_success\n"); return SW_OK; } return ret; } } zval *retval; zval **args[2]; zval *zrequest = client->zrequest; //server info zval *zserver; MAKE_STD_ZVAL(zserver); array_init(zserver); zend_update_property(swoole_http_request_class_entry_ptr, zrequest, ZEND_STRL("server"), zserver TSRMLS_CC); switch (parser->method) { case PHP_HTTP_GET: add_assoc_string(zserver, "REQUEST_METHOD", "GET", 1);break; case PHP_HTTP_POST: add_assoc_string(zserver, "REQUEST_METHOD", "POST", 1);break; case PHP_HTTP_HEAD: add_assoc_string(zserver, "REQUEST_METHOD", "HEAD", 1);break; case PHP_HTTP_PUT: add_assoc_string(zserver, "REQUEST_METHOD", "PUT", 1);break; case PHP_HTTP_DELETE: add_assoc_string(zserver, "REQUEST_METHOD", "DELETE", 1);break; case PHP_HTTP_PATCH: add_assoc_string(zserver, "REQUEST_METHOD", "PATCH", 1);break; /* pathological */ case PHP_HTTP_CONNECT: add_assoc_string(zserver, "REQUEST_METHOD", "CONNECT", 1);break; case PHP_HTTP_OPTIONS: add_assoc_string(zserver, "REQUEST_METHOD", "OPTIONS", 1);break; case PHP_HTTP_TRACE: add_assoc_string(zserver, "REQUEST_METHOD", "TRACE", 1);break; /* webdav */ case PHP_HTTP_COPY: add_assoc_string(zserver, "REQUEST_METHOD", "COPY", 1);break; case PHP_HTTP_LOCK: add_assoc_string(zserver, "REQUEST_METHOD", "LOCK", 1);break; case PHP_HTTP_MKCOL: add_assoc_string(zserver, "REQUEST_METHOD", "MKCOL", 1);break; case PHP_HTTP_MOVE: add_assoc_string(zserver, "REQUEST_METHOD", "MOVE", 1);break; case PHP_HTTP_PROPFIND: add_assoc_string(zserver, "REQUEST_METHOD", "PROPFIND", 1);break; case PHP_HTTP_PROPPATCH: add_assoc_string(zserver, "REQUEST_METHOD", "PROPPATCH", 1);break; case PHP_HTTP_UNLOCK: add_assoc_string(zserver, "REQUEST_METHOD", "UNLOCK", 1);break; /* subversion */ case PHP_HTTP_REPORT: add_assoc_string(zserver, "REQUEST_METHOD", "REPORT", 1);break; case PHP_HTTP_MKACTIVITY: add_assoc_string(zserver, "REQUEST_METHOD", "MKACTIVITY", 1);break; case PHP_HTTP_CHECKOUT: add_assoc_string(zserver, "REQUEST_METHOD", "CHECKOUT", 1);break; case PHP_HTTP_MERGE: add_assoc_string(zserver, "REQUEST_METHOD", "MERGE", 1);break; /* upnp */ case PHP_HTTP_MSEARCH: add_assoc_string(zserver, "REQUEST_METHOD", "MSEARCH", 1);break; case PHP_HTTP_NOTIFY: add_assoc_string(zserver, "REQUEST_METHOD", "NOTIFY", 1);break; case PHP_HTTP_SUBSCRIBE: add_assoc_string(zserver, "REQUEST_METHOD", "SUBSCRIBE", 1);break; case PHP_HTTP_UNSUBSCRIBE: add_assoc_string(zserver, "REQUEST_METHOD", "UNSUBSCRIBE", 1);break; case PHP_HTTP_NOT_IMPLEMENTED: add_assoc_string(zserver, "REQUEST_METHOD", "GET", 1);break; } // if (parser->method == PHP_HTTP_POST) // { // add_assoc_string(zserver, "REQUEST_METHOD", "POST", 1); // } // else // { // add_assoc_string(zserver, "REQUEST_METHOD", "GET", 1); // } add_assoc_stringl(zserver, "REQUEST_URI", client->request.path, client->request.path_len, 1); add_assoc_stringl(zserver, "PATH_INFO", client->request.path, client->request.path_len, 1); add_assoc_long_ex(zserver, ZEND_STRS("REQUEST_TIME"), SwooleGS->now); swConnection *conn = swServer_connection_get(SwooleG.serv, fd); add_assoc_long(zserver, "SERVER_PORT", SwooleG.serv->connection_list[conn->from_fd].addr.sin_port); add_assoc_long(zserver, "REMOTE_PORT", ntohs(conn->addr.sin_port)); add_assoc_string(zserver, "REMOTE_ADDR", inet_ntoa(conn->addr.sin_addr), 1); if (client->request.version == 101) { add_assoc_string(zserver, "SERVER_PROTOCOL", "HTTP/1.1", 1); } else { add_assoc_string(zserver, "SERVER_PROTOCOL", "HTTP/1.0", 1); } add_assoc_string(zserver, "SERVER_SOFTWARE", SW_HTTP_SERVER_SOFTWARE, 1); add_assoc_string(zserver, "GATEWAY_INTERFACE", SW_HTTP_SERVER_SOFTWARE, 1); // ZEND_SET_SYMBOL(&EG(symbol_table), "_SERVER", zserver); zval *zresponse; MAKE_STD_ZVAL(zresponse); object_init_ex(zresponse, swoole_http_response_class_entry_ptr); //socket fd zend_update_property_long(swoole_http_response_class_entry_ptr, zresponse, ZEND_STRL("fd"), client->fd TSRMLS_CC); client->zresponse = zresponse; args[0] = &zrequest; args[1] = &zresponse; int called = 0; if(conn->websocket_status == WEBSOCKET_STATUS_CONNECTION) { called = 2; } if (call_user_function_ex(EG(function_table), NULL, php_sw_http_server_callbacks[called], &retval, 2, args, 0, NULL TSRMLS_CC) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "onRequest handler error"); } if (EG(exception)) { zend_exception_error(EG(exception), E_ERROR TSRMLS_CC); } if (retval) { zval_ptr_dtor(&retval); } swTrace("======call end======\n"); if(called == 2) { handshake_success(fd); } } return SW_OK; }
/* {{{ 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; } ALLOC_INIT_ZVAL(*subarray); array_init(*subarray); add_assoc_string(*subarray, "host", pRec->pName, 1); add_assoc_string(*subarray, "class", "IN", 1); 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, 1); 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", 1); add_assoc_string(*subarray, "ip", inet_ntoa(ipaddr), 1); break; } case DNS_TYPE_MX: add_assoc_string(*subarray, "type", "MX", 1); 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", 1); } /* no break; */ case DNS_TYPE_NS: if (type == DNS_TYPE_NS) { add_assoc_string(*subarray, "type", "NS", 1); } /* no break; */ case DNS_TYPE_PTR: if (type == DNS_TYPE_PTR) { add_assoc_string(*subarray, "type", "PTR", 1); } add_assoc_string(*subarray, "target", pRec->Data.MX.pNameExchange, 1); 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; char *txt, *txt_dst; long txt_len = 0; zval *entries; add_assoc_string(*subarray, "type", "TXT", 1); ALLOC_INIT_ZVAL(entries); array_init(entries); for (i = 0; i < count; i++) { txt_len += strlen(data_txt->pStringArray[i]) + 1; } txt = ecalloc(txt_len * 2, 1); txt_dst = txt; 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, 1); txt_dst += len; } add_assoc_string(*subarray, "txt", txt, 0); 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", 1); add_assoc_string(*subarray, "mname", data_soa->pNamePrimaryServer, 1); add_assoc_string(*subarray, "rname", data_soa->pNameAdministrator, 1); 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", 1); add_assoc_string(*subarray, "ipv6", buf, 1); } 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", 1); 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, 1); } break; #if _MSC_VER >= 1500 case DNS_TYPE_NAPTR: { DNS_NAPTR_DATA * data_naptr = &pRec->Data.Naptr; add_assoc_string(*subarray, "type", "NAPTR", 1); add_assoc_long(*subarray, "order", data_naptr->wOrder); add_assoc_long(*subarray, "pref", data_naptr->wPreference); add_assoc_string(*subarray, "flags", data_naptr->pFlags, 1); add_assoc_string(*subarray, "services", data_naptr->pService, 1); add_assoc_string(*subarray, "regex", data_naptr->pRegularExpression, 1); add_assoc_string(*subarray, "replacement", data_naptr->pReplacement, 1); } break; #endif default: /* unkown type */ zval_ptr_dtor(subarray); *subarray = NULL; return; } }
/** * Reads annotations from the class dockblocks, its methods and/or properties */ PHP_METHOD(Phalcon_Annotations_Reader, parse) { HashTable *_3$$5, *_9$$10; HashPosition _2$$5, _8$$10; int ZEPHIR_LAST_CALL_STATUS, line = 0; zval *className_param = NULL, *annotations = NULL, *reflection = NULL, *comment = NULL, *properties = NULL, *methods = NULL, *property = NULL, *method = NULL, *classAnnotations = NULL, *annotationsProperties = NULL, *propertyAnnotations = NULL, *annotationsMethods = NULL, *methodAnnotations = NULL, *_0$$3 = NULL, *_1$$3 = NULL, **_4$$5, *_5$$7 = NULL, *_6$$7 = NULL, *_7$$8 = NULL, **_10$$10, *_11$$12 = NULL, *_12$$12 = NULL, *_13$$13 = NULL; zval *className = NULL; ZEPHIR_MM_GROW(); zephir_fetch_params(1, 1, 0, &className_param); zephir_get_strval(className, className_param); ZEPHIR_INIT_VAR(annotations); array_init(annotations); ZEPHIR_INIT_VAR(reflection); object_init_ex(reflection, zephir_get_internal_ce(SS("reflectionclass") TSRMLS_CC)); ZEPHIR_CALL_METHOD(NULL, reflection, "__construct", NULL, 85, className); zephir_check_call_status(); ZEPHIR_CALL_METHOD(&comment, reflection, "getdoccomment", NULL, 86); zephir_check_call_status(); if (Z_TYPE_P(comment) == IS_STRING) { ZEPHIR_INIT_VAR(classAnnotations); ZEPHIR_CALL_METHOD(&_0$$3, reflection, "getfilename", NULL, 87); zephir_check_call_status(); ZEPHIR_CALL_METHOD(&_1$$3, reflection, "getstartline", NULL, 88); zephir_check_call_status(); ZEPHIR_LAST_CALL_STATUS = phannot_parse_annotations(classAnnotations, comment, _0$$3, _1$$3 TSRMLS_CC); zephir_check_call_status(); if (Z_TYPE_P(classAnnotations) == IS_ARRAY) { zephir_array_update_string(&annotations, SL("class"), &classAnnotations, PH_COPY | PH_SEPARATE); } } ZEPHIR_CALL_METHOD(&properties, reflection, "getproperties", NULL, 89); zephir_check_call_status(); if (zephir_fast_count_int(properties TSRMLS_CC)) { line = 1; ZEPHIR_INIT_VAR(annotationsProperties); array_init(annotationsProperties); zephir_is_iterable(properties, &_3$$5, &_2$$5, 0, 0, "phalcon/annotations/reader.zep", 96); for ( ; zephir_hash_get_current_data_ex(_3$$5, (void**) &_4$$5, &_2$$5) == SUCCESS ; zephir_hash_move_forward_ex(_3$$5, &_2$$5) ) { ZEPHIR_GET_HVALUE(property, _4$$5); ZEPHIR_CALL_METHOD(&comment, property, "getdoccomment", NULL, 0); zephir_check_call_status(); if (Z_TYPE_P(comment) == IS_STRING) { ZEPHIR_INIT_NVAR(propertyAnnotations); ZEPHIR_CALL_METHOD(&_5$$7, reflection, "getfilename", NULL, 87); zephir_check_call_status(); ZEPHIR_INIT_NVAR(_6$$7); ZVAL_LONG(_6$$7, line); ZEPHIR_LAST_CALL_STATUS = phannot_parse_annotations(propertyAnnotations, comment, _5$$7, _6$$7 TSRMLS_CC); zephir_check_call_status(); if (Z_TYPE_P(propertyAnnotations) == IS_ARRAY) { ZEPHIR_OBS_NVAR(_7$$8); zephir_read_property(&_7$$8, property, SL("name"), PH_NOISY_CC); zephir_array_update_zval(&annotationsProperties, _7$$8, &propertyAnnotations, PH_COPY | PH_SEPARATE); } } } if (zephir_fast_count_int(annotationsProperties TSRMLS_CC)) { zephir_array_update_string(&annotations, SL("properties"), &annotationsProperties, PH_COPY | PH_SEPARATE); } } ZEPHIR_CALL_METHOD(&methods, reflection, "getmethods", NULL, 90); zephir_check_call_status(); if (zephir_fast_count_int(methods TSRMLS_CC)) { ZEPHIR_INIT_VAR(annotationsMethods); array_init(annotationsMethods); zephir_is_iterable(methods, &_9$$10, &_8$$10, 0, 0, "phalcon/annotations/reader.zep", 126); for ( ; zephir_hash_get_current_data_ex(_9$$10, (void**) &_10$$10, &_8$$10) == SUCCESS ; zephir_hash_move_forward_ex(_9$$10, &_8$$10) ) { ZEPHIR_GET_HVALUE(method, _10$$10); ZEPHIR_CALL_METHOD(&comment, method, "getdoccomment", NULL, 0); zephir_check_call_status(); if (Z_TYPE_P(comment) == IS_STRING) { ZEPHIR_INIT_NVAR(methodAnnotations); ZEPHIR_CALL_METHOD(&_11$$12, method, "getfilename", NULL, 0); zephir_check_call_status(); ZEPHIR_CALL_METHOD(&_12$$12, method, "getstartline", NULL, 0); zephir_check_call_status(); ZEPHIR_LAST_CALL_STATUS = phannot_parse_annotations(methodAnnotations, comment, _11$$12, _12$$12 TSRMLS_CC); zephir_check_call_status(); if (Z_TYPE_P(methodAnnotations) == IS_ARRAY) { ZEPHIR_OBS_NVAR(_13$$13); zephir_read_property(&_13$$13, method, SL("name"), PH_NOISY_CC); zephir_array_update_zval(&annotationsMethods, _13$$13, &methodAnnotations, PH_COPY | PH_SEPARATE); } } } if (zephir_fast_count_int(annotationsMethods TSRMLS_CC)) { zephir_array_update_string(&annotations, SL("methods"), &annotationsMethods, PH_COPY | PH_SEPARATE); } } RETURN_CCTOR(annotations); }