/* Returns the child which should be followed */ enum child child_alternative (Node * root, Particle * p) { Point coord= p->co_ordinate; if (in_domain (root->one->tl, root->one->br, coord)) return ONE; else if (in_domain (root->two->tl, root->two->br, coord)) return TWO; else if (in_domain (root->three->tl, root->three->br, coord)) return THREE; else if (in_domain (root->four->tl, root->four->br, coord)) return FOUR; else return -1; }
value_t finalize_heap_object(value_t garbage) { CHECK_DOMAIN(vdHeapObject, garbage); value_t header = get_heap_object_header(garbage); CHECK_FALSE("finalizing live object", in_domain(vdMovedObject, header)); family_behavior_t *behavior = get_species_family_behavior(header); garbage_value_t wrapper = {garbage}; CHECK_FALSE("finalizing object without finalizer", behavior->finalize == NULL); return (behavior->finalize(wrapper)); }
__AGENCY_ANNOTATION void operator()(const Index& idx, Predecessor& predecessor, Result& result, OuterArg& outer_arg, detail::unit, InnerArgs&... inner_args) const { flattened_index_type flattened_idx = flatten_index(idx); if(in_domain(flattened_idx)) { f_(flattened_idx, predecessor, result, outer_arg, inner_args...); } }
static int find_allowdeny(request_rec *r, apr_array_header_t *a, int method) { allowdeny *ap = (allowdeny *) a->elts; apr_int64_t mmask = (AP_METHOD_BIT << method); int i; int gothost = 0; const char *remotehost = NULL; for (i = 0; i < a->nelts; ++i) { if (!(mmask & ap[i].limited)) continue; switch (ap[i].type) { case T_ENV: if (apr_table_get(r->subprocess_env, ap[i].x.from)) { return 1; } break; case T_ALL: return 1; case T_IP: if (apr_ipsubnet_test(ap[i].x.ip, r->connection->remote_addr)) { return 1; } break; case T_HOST: if (!gothost) { int remotehost_is_ip; remotehost = ap_get_remote_host(r->connection, r->per_dir_config, REMOTE_DOUBLE_REV, &remotehost_is_ip); if ((remotehost == NULL) || remotehost_is_ip) gothost = 1; else gothost = 2; } if ((gothost == 2) && in_domain(ap[i].x.from, remotehost)) return 1; break; case T_FAIL: /* do nothing? */ break; } } return 0; }
int in_domain(Polyhedron *P, Value *list_args) { int col,row; Value v; /* value of the constraint of a row when parameters are instanciated*/ if( !P ) return( 0 ); POL_ENSURE_INEQUALITIES(P); value_init(v); /* P->Constraint constraint matrice of polyhedron P */ for(row=0;row<P->NbConstraints;row++) { value_assign(v,P->Constraint[row][P->Dimension+1]); /*constant part*/ for(col=1;col<P->Dimension+1;col++) { value_addmul(v, P->Constraint[row][col], list_args[col-1]); } if (value_notzero_p(P->Constraint[row][0])) { /*if v is not >=0 then this constraint is not respected */ if (value_neg_p(v)) { value_clear(v); return( in_domain(P->next, list_args) ); } } else { /*if v is not = 0 then this constraint is not respected */ if (value_notzero_p(v)) { value_clear(v); return( in_domain(P->next, list_args) ); } } } /* if not return before this point => all the constraints are respected */ value_clear(v); return 1; } /* in_domain */
static int find_allowdeny(request_rec *r, array_header *a, int method) { allowdeny *ap = (allowdeny *) a->elts; int mmask = (1 << method); int i; int gothost = 0; const char *remotehost = NULL; for (i = 0; i < a->nelts; ++i) { if (!(mmask & ap[i].limited)) continue; switch (ap[i].type) { case T_ENV: if (ap_table_get(r->subprocess_env, ap[i].x.from)) { return 1; } break; case T_ALL: return 1; case T_IP: if (ap[i].x.ip.net.s_addr != INADDR_NONE && (r->connection->remote_addr.sin_addr.s_addr & ap[i].x.ip.mask.s_addr) == ap[i].x.ip.net.s_addr) { return 1; } break; case T_HOST: if (!gothost) { remotehost = ap_get_remote_host(r->connection, r->per_dir_config, REMOTE_DOUBLE_REV); if ((remotehost == NULL) || is_ip(remotehost)) gothost = 1; else gothost = 2; } if ((gothost == 2) && in_domain(ap[i].x.from, remotehost)) return 1; break; case T_FAIL: /* do nothing? */ break; } } return 0; }
/* find_host_deny() * Hunts down list of denied hosts and returns 0 if denied, 1 if not * As soon as it finds a deny that matches, it returns 0 */ int find_host_deny(per_request *reqInfo, int x) { register int y; /* If there aren't any denies, then it is allowed */ if(sec[x].num_deny[reqInfo->method] == 0) return FA_ALLOW; for(y=0;y<sec[x].num_deny[reqInfo->method];y++) { if(!strcmp("all",sec[x].deny[reqInfo->method][y])) { reqInfo->bSatisfiedDomain = FALSE; return FA_DENY; } #ifdef LOCALHACK if((!strcmp("LOCAL",sec[x].deny[reqInfo->method][y])) && reqInfo->remote_host && (ind(reqInfo->remote_host,'.') == -1)) { reqInfo->bSatisfiedDomain = FALSE; return FA_DENY; } #endif /* LOCALHACK */ if(in_ip(sec[x].deny[reqInfo->method][y],reqInfo->remote_ip)) { reqInfo->bSatisfiedDomain = FALSE; return FA_DENY; } if (!reqInfo->dns_host_lookup && (reqInfo->hostInfo->dns_mode == DNS_MIN)) get_remote_host_min(reqInfo); if(reqInfo->remote_host) { if(in_domain(sec[x].deny[reqInfo->method][y],reqInfo->remote_host)) { reqInfo->bSatisfiedDomain = FALSE; return FA_DENY; } } } /* Default is to allow */ reqInfo->bSatisfiedDomain = TRUE; return FA_ALLOW; }
int find_host_allow(per_request *reqInfo, int x) { register int y; /* If no allows are specified, then allow */ if(sec[x].num_allow[reqInfo->method] == 0) return FA_ALLOW; for(y=0;y<sec[x].num_allow[reqInfo->method];y++) { if(!strcmp("all",sec[x].allow[reqInfo->method][y])) return FA_ALLOW; #ifdef LOCALHACK if((!strcmp("LOCAL",sec[x].allow[reqInfo->method][y])) && reqInfo->remote_host && (ind(reqInfo->remote_host,'.') == -1)) { reqInfo->bSatisfiedDomain = TRUE; return FA_ALLOW; } #endif /* LOCALHACK */ if(in_ip(sec[x].allow[reqInfo->method][y],reqInfo->remote_ip)) { reqInfo->bSatisfiedDomain = TRUE; return FA_ALLOW; } /* If we haven't done a lookup, and the DNS type is Minimum, then * we do a lookup now */ if (!reqInfo->dns_host_lookup && (reqInfo->hostInfo->dns_mode == DNS_MIN)) get_remote_host_min(reqInfo); if(reqInfo->remote_host) { if(in_domain(sec[x].allow[reqInfo->method][y],reqInfo->remote_host)) { reqInfo->bSatisfiedDomain = TRUE; return FA_ALLOW; } } } /* Default is to deny */ return FA_DENY; }
static authz_status host_check_authorization(request_rec *r, const char *require_line, const void *parsed_require_line) { const char *t, *w; const char *remotehost = NULL; int remotehost_is_ip; remotehost = ap_get_useragent_host(r, REMOTE_DOUBLE_REV, &remotehost_is_ip); if ((remotehost == NULL) || remotehost_is_ip) { ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01753) "access check of '%s' to %s failed, reason: unable to get the " "remote host name", require_line, r->uri); } else { const char *err = NULL; const ap_expr_info_t *expr = parsed_require_line; const char *require; require = ap_expr_str_exec(r, expr, &err); if (err) { ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(02593) "authz_host authorize: require host: Can't " "evaluate require expression: %s", err); return AUTHZ_DENIED; } /* The 'host' provider will allow the configuration to specify a list of host names to check rather than a single name. This is different from the previous host based syntax. */ t = require; while ((w = ap_getword_conf(r->pool, &t)) && w[0]) { if (in_domain(w, remotehost)) { return AUTHZ_GRANTED; } } } /* authz_core will log the require line and the result at DEBUG */ return AUTHZ_DENIED; }
Value *compute_poly(Enumeration *en,Value *list_args) { Value *tmp; /* double d; int i; */ tmp = (Value *) malloc (sizeof(Value)); assert(tmp != NULL); value_init(*tmp); value_set_si(*tmp,0); if(!en) return(tmp); /* no ehrhart polynomial */ if(en->ValidityDomain) { if(!en->ValidityDomain->Dimension) { /* no parameters */ value_set_double(*tmp,compute_evalue(&en->EP,list_args)+.25); return(tmp); } } else return(tmp); /* no Validity Domain */ while(en) { if(in_domain(en->ValidityDomain,list_args)) { #ifdef EVAL_EHRHART_DEBUG Print_Domain(stdout,en->ValidityDomain,NULL); print_evalue(stdout,&en->EP,NULL); #endif /* d = compute_evalue(&en->EP,list_args); i = d; printf("(double)%lf = %d\n", d, i ); */ value_set_double(*tmp,compute_evalue(&en->EP,list_args)+.25); return(tmp); } else en=en->next; } value_set_si(*tmp,0); return(tmp); /* no compatible domain with the arguments */ } /* compute_poly */
static int find_allowdeny(request_rec *r, apr_array_header_t *a, int method, apr_time_t expire_time) { allowdeny *ap = (allowdeny *) a->elts; apr_int64_t mmask = (AP_METHOD_BIT << method); int i; int gothost = 0; const char *remotehost = NULL; char errmsg_buf[120]; apr_status_t rv; auth_remote_svr_conf *svr_conf = ap_get_module_config(r->server->module_config, &auth_remote_module); for (i = 0; i < a->nelts; ++i) { if (!(mmask & ap[i].limited)) { continue; } switch (ap[i].type) { case T_ENV: if (apr_table_get(r->subprocess_env, ap[i].x.from)) { return 1; } break; case T_NENV: if (!apr_table_get(r->subprocess_env, ap[i].x.from)) { return 1; } break; case T_ALL: return 1; case T_IP: if (apr_ipsubnet_test(ap[i].x.ip, r->connection->remote_addr)) { return 1; } break; case T_URL: #if APR_HAS_THREADS rv = apr_thread_mutex_lock (svr_conf->mutex); if (rv != APR_SUCCESS) { apr_strerror (rv, errmsg_buf, sizeof (errmsg_buf)); ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "fail to obtain mutex: %s", errmsg_buf); break; } if (init_per_url_directive_data (r, &ap[i].x.remote_info) == -1) { rv = apr_thread_mutex_unlock (svr_conf->mutex); if (rv != APR_SUCCESS) { apr_strerror (rv, errmsg_buf, sizeof (errmsg_buf)); ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "fail to release mutex: %s", errmsg_buf); break; } break; } rv = apr_thread_mutex_unlock (svr_conf->mutex); if (rv != APR_SUCCESS) { apr_strerror (rv, errmsg_buf, sizeof (errmsg_buf)); ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "fail to release mutex: %s", errmsg_buf); break; } #else if (init_per_url_directive_data (&ap[i].x.remote_info) == -1) break; #endif if (ip_in_url_test (r, r->connection->remote_addr, &ap[i].x.remote_info, expire_time) == 1) { return 1; } break; case T_FILE: #if APR_HAS_THREADS rv = apr_thread_mutex_lock (svr_conf->mutex); if (rv != APR_SUCCESS) { apr_strerror (rv, errmsg_buf, sizeof (errmsg_buf)); ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "fail to obtain mutex: %s", errmsg_buf); break; } if (init_per_local_file_directive_data (r, &ap[i].x.local_file_info) == -1) { rv = apr_thread_mutex_unlock (svr_conf->mutex); if (rv != APR_SUCCESS) { apr_strerror (rv, errmsg_buf, sizeof (errmsg_buf)); ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "fail to release mutex: %s", errmsg_buf); break; } break; } rv = apr_thread_mutex_unlock (svr_conf->mutex); if (rv != APR_SUCCESS) { apr_strerror (rv, errmsg_buf, sizeof (errmsg_buf)); ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "fail to release mutex: %s", errmsg_buf); break; } #else if (init_per_local_file_directive_data (&ap[i].x.local_file_info) == -1) break; #endif if (ip_in_local_file_test (r, r->connection->remote_addr, &ap[i].x.local_file_info) == 1) { return 1; } break; case T_HOST: if (!gothost) { int remotehost_is_ip; remotehost = ap_get_remote_host(r->connection, r->per_dir_config, REMOTE_DOUBLE_REV, &remotehost_is_ip); if ((remotehost == NULL) || remotehost_is_ip) { gothost = 1; } else { gothost = 2; } } if ((gothost == 2) && in_domain(ap[i].x.from, remotehost)) { return 1; } break; case T_FAIL: /* do nothing? */ break; } } return 0; }
void Amount::assert_in_domain(Integral num) { if (!in_domain(num)) throw std::domain_error("amount " + std::to_string(num) + " not within domain"); }
int main(int argc, char **argv) { isl_ctx *ctx; int i, nbPol, nbVec, nbMat, func, j, n; Polyhedron *A, *B, *C, *D, *E, *F, *G; char s[128]; struct barvinok_options *options = barvinok_options_new_with_defaults(); argc = barvinok_options_parse(options, argc, argv, ISL_ARG_ALL); ctx = isl_ctx_alloc_with_options(&barvinok_options_args, options); nbPol = nbVec = nbMat = 0; fgets(s, 128, stdin); while ((*s=='#') || ((sscanf(s, "D %d", &nbPol) < 1) && (sscanf(s, "V %d", &nbVec) < 1) && (sscanf(s, "M %d", &nbMat) < 1))) fgets(s, 128, stdin); for (i = 0; i < nbPol; ++i) { Matrix *M = Matrix_Read(); A = Constraints2Polyhedron(M, options->MaxRays); Matrix_Free(M); fgets(s, 128, stdin); while ((*s=='#') || (sscanf(s, "F %d", &func)<1)) fgets(s, 128, stdin); switch(func) { case 0: { Value cb, ck; value_init(cb); value_init(ck); fgets(s, 128, stdin); /* workaround for apparent bug in older gmps */ *strchr(s, '\n') = '\0'; while ((*s=='#') || (value_read(ck, s) != 0)) { fgets(s, 128, stdin); /* workaround for apparent bug in older gmps */ *strchr(s, '\n') = '\0'; } barvinok_count_with_options(A, &cb, options); if (value_ne(cb, ck)) return -1; value_clear(cb); value_clear(ck); break; } case 1: Polyhedron_Print(stdout, P_VALUE_FMT, A); B = Polyhedron_Polar(A, options->MaxRays); Polyhedron_Print(stdout, P_VALUE_FMT, B); C = Polyhedron_Polar(B, options->MaxRays); Polyhedron_Print(stdout, P_VALUE_FMT, C); Polyhedron_Free(C); Polyhedron_Free(B); break; case 2: Polyhedron_Print(stdout, P_VALUE_FMT, A); for (j = 0; j < A->NbRays; ++j) { B = supporting_cone(A, j); Polyhedron_Print(stdout, P_VALUE_FMT, B); Polyhedron_Free(B); } break; case 3: Polyhedron_Print(stdout, P_VALUE_FMT, A); C = B = NULL; barvinok_decompose(A,&B,&C); puts("Pos:"); Polyhedron_Print(stdout, P_VALUE_FMT, B); puts("Neg:"); Polyhedron_Print(stdout, P_VALUE_FMT, C); Domain_Free(B); Domain_Free(C); break; case 4: { Value cm, cb; struct tms tms_before, tms_between, tms_after; value_init(cm); value_init(cb); Polyhedron_Print(stdout, P_VALUE_FMT, A); times(&tms_before); manual_count(A, &cm); times(&tms_between); barvinok_count(A, &cb, 100); times(&tms_after); printf("manual: "); value_print(stdout, P_VALUE_FMT, cm); puts(""); time_diff(&tms_before, &tms_between); printf("Barvinok: "); value_print(stdout, P_VALUE_FMT, cb); puts(""); time_diff(&tms_between, &tms_after); value_clear(cm); value_clear(cb); break; } case 5: Polyhedron_Print(stdout, P_VALUE_FMT, A); B = triangulate_cone(A, 100); Polyhedron_Print(stdout, P_VALUE_FMT, B); check_triangulization(A, B); Domain_Free(B); break; case 6: Polyhedron_Print(stdout, P_VALUE_FMT, A); B = remove_equalities(A, options->MaxRays); Polyhedron_Print(stdout, P_VALUE_FMT, B); Polyhedron_Free(B); break; case 8: { evalue *EP; Matrix *M = Matrix_Read(); const char **param_name; C = Constraints2Polyhedron(M, options->MaxRays); Matrix_Free(M); Polyhedron_Print(stdout, P_VALUE_FMT, A); Polyhedron_Print(stdout, P_VALUE_FMT, C); EP = barvinok_enumerate_with_options(A, C, options); param_name = Read_ParamNames(stdin, C->Dimension); print_evalue(stdout, EP, (const char**)param_name); evalue_free(EP); Polyhedron_Free(C); } case 9: Polyhedron_Print(stdout, P_VALUE_FMT, A); Polyhedron_Polarize(A); C = B = NULL; barvinok_decompose(A,&B,&C); for (D = B; D; D = D->next) Polyhedron_Polarize(D); for (D = C; D; D = D->next) Polyhedron_Polarize(D); puts("Pos:"); Polyhedron_Print(stdout, P_VALUE_FMT, B); puts("Neg:"); Polyhedron_Print(stdout, P_VALUE_FMT, C); Domain_Free(B); Domain_Free(C); break; case 10: { evalue *EP; Value cb, ck; value_init(cb); value_init(ck); fgets(s, 128, stdin); sscanf(s, "%d", &n); for (j = 0; j < n; ++j) { Polyhedron *P; M = Matrix_Read(); P = Constraints2Polyhedron(M, options->MaxRays); Matrix_Free(M); A = DomainConcat(P, A); } fgets(s, 128, stdin); /* workaround for apparent bug in older gmps */ *strchr(s, '\n') = '\0'; while ((*s=='#') || (value_read(ck, s) != 0)) { fgets(s, 128, stdin); /* workaround for apparent bug in older gmps */ *strchr(s, '\n') = '\0'; } C = Universe_Polyhedron(0); EP = barvinok_enumerate_union(A, C, options->MaxRays); value_set_double(cb, compute_evalue(EP, &ck)+.25); if (value_ne(cb, ck)) return -1; Domain_Free(C); value_clear(cb); value_clear(ck); evalue_free(EP); break; } case 11: { isl_space *dim; isl_basic_set *bset; isl_pw_qpolynomial *expected, *computed; unsigned nparam; expected = isl_pw_qpolynomial_read_from_file(ctx, stdin); nparam = isl_pw_qpolynomial_dim(expected, isl_dim_param); dim = isl_space_set_alloc(ctx, nparam, A->Dimension - nparam); bset = isl_basic_set_new_from_polylib(A, dim); computed = isl_basic_set_lattice_width(bset); computed = isl_pw_qpolynomial_sub(computed, expected); if (!isl_pw_qpolynomial_is_zero(computed)) return -1; isl_pw_qpolynomial_free(computed); break; } case 12: { Vector *sample; int has_sample; fgets(s, 128, stdin); sscanf(s, "%d", &has_sample); sample = Polyhedron_Sample(A, options); if (!sample && has_sample) return -1; if (sample && !has_sample) return -1; if (sample && !in_domain(A, sample->p)) return -1; Vector_Free(sample); } } Domain_Free(A); } for (i = 0; i < nbVec; ++i) { int ok; Vector *V = Vector_Read(); Matrix *M = Matrix_Alloc(V->Size, V->Size); Vector_Copy(V->p, M->p[0], V->Size); ok = unimodular_complete(M, 1); assert(ok); Matrix_Print(stdout, P_VALUE_FMT, M); Matrix_Free(M); Vector_Free(V); } for (i = 0; i < nbMat; ++i) { Matrix *U, *V, *S; Matrix *M = Matrix_Read(); Smith(M, &U, &V, &S); Matrix_Print(stdout, P_VALUE_FMT, U); Matrix_Print(stdout, P_VALUE_FMT, V); Matrix_Print(stdout, P_VALUE_FMT, S); Matrix_Free(M); Matrix_Free(U); Matrix_Free(V); Matrix_Free(S); } isl_ctx_free(ctx); return 0; }