void CCorespondDisplay:: initial_actors(CShape * m_shape) { int size= m_shape->vec_Cor.size(); for (int i = 0; i < size; ++i) { CLineSetDisplay* new_line_set=new CLineSetDisplay(); new_line_set->initial_actors(m_shape->vec_Cor[i]); map_line_actors.insert(std::make_pair(m_shape->vec_Cor[i]->CorrespondLayer1,new_line_set)); map_int_line_actors.insert(std::make_pair(i,new_line_set)); check_level(m_shape->vec_Cor[i]->CorrespondLayer1); check_level(m_shape->vec_Cor[i]->CorrespondLayer2); } }
void _rtpp_log_ewrite(struct cfg *cf, int level, const char *function, const char *format, ...) { va_list ap; char rtpp_log_buff[2048]; char *fmt; if (check_level(cf, cf->log_level, level) == 0) return; va_start(ap, format); if (cf->nodaemon != 0) { fmt = "%s:%s: %s: %s\n"; } else { fmt = "%s:%s: %s: %s"; } snprintf(rtpp_log_buff, sizeof(rtpp_log_buff), fmt, strlvl(level), function, format, strerror(errno)); if (cf->nodaemon != 0) { vfprintf(stderr, rtpp_log_buff, ap); } else { vsyslog_async(level, rtpp_log_buff, ap); } va_end(ap); }
void pack_report(object *obj, int print_message, char *message) { /* Notify the user */ if (print_message) { if (!terse) addmsg(message); msg("(%c%c) %s.", obj->o_type, print_letters[get_ident(obj)], inv_name(obj, !terse)); } if (obj->o_type == ARTIFACT) { has_artifact |= (1 << obj->o_which); picked_artifact |= (1 << obj->o_which); if (!(obj->ar_flags & ISUSED)) { obj->ar_flags |= ISUSED; pstats.s_exp += arts[obj->o_which].ar_worth / 10; check_level(); } } updpack(); return; }
int elevation4(t_serv *serveur, t_client *client, int cs) { int i; t_case *c; c = &serveur->map_case[client[cs].drone->posy][client[cs].drone->posx]; i = check_level(serveur, client[cs].drone->posy, client[cs].drone->posx, 4); if (c->players == 4 && c->linemate == 1 && c->deraumere == 1 && c->sibur == 2 && !c->mendiane && c->phiras == 1 && !c->thystame && i) { if (client[cs].flag == 0) start_inc(serveur, client, cs, 5); if (client[cs].flag == 2) { c->linemate = 0; c->deraumere = 0; c->sibur = 0; c->phiras = 0; success(serveur, client, cs); } } else if (client[cs].flag == 0 || client[cs].flag == 2) fail(serveur, client, cs); return (0); }
int main() { int t; void gotoxy(int x, int y); void dwall(); void dwall1(); void dwall2(); void change(int t); void add(int x, int y); void move(); void choose_level(); void check_level(); void draw_extra_wall(int); void load_data(); void save_data(); void show_top_scores(); void dwall3(); load_data(); choose_level(); //dwall() and select speed add(2, 2); add(2, 3); add(2, 4); while (running) { t = _getch(); change(t); while(!kbhit()) { move(); Sleep(speed); /*用来控制蛇移动的速度*/ check_level(); /*change to next level if snake is long enough*/ score = 10 * node - 30; gotoxy(7, N + 1); printf("Your score is %d", score); gotoxy(0, 10); printf("your score is %d", score); } } save_data(); return 0; }
void dt_info(void *tag, const char *fmt, ...) { if (!check_level(DT_LOG_INFO)) { return; } if (!tag_enable(dtp_setting.log_filter, (char *)tag)) { return; } display_time(); dt_get_log_level(DT_LOG_INFO); printf("[%s] ", (char *) tag); va_list vl; va_start(vl, fmt); #if ENABLE_LINUX vprintf(fmt, vl); #endif #if ENABLE_ANDROID __android_log_vprint(ANDROID_LOG_INFO, tag, fmt, vl); #endif va_end(vl); }
void _rtpp_log_ewrite_va(struct rtpp_log_inst *rli, int level, const char *function, const char *format, va_list ap) { char rtpp_log_buff[2048]; char rtpp_time_buff[32]; const char *call_id; #ifdef RTPP_LOG_ADVANCED va_list apc; #endif if (check_level(rli, level) == 0) return; if (rli->call_id != NULL) { call_id = rli->call_id; } else { call_id = CALL_ID_NONE; } #ifdef RTPP_LOG_ADVANCED if (syslog_async_opened != 0) { snprintf(rtpp_log_buff, sizeof(rtpp_log_buff), rli->eformat_sl, strlvl(level), call_id, function, format, strerror(errno), errno); va_copy(apc, ap); vsyslog_async(level, rtpp_log_buff, apc); va_end(apc); #if !defined(RTPP_DEBUG) return; #endif } #endif ftime(rli, getdtime(), rtpp_time_buff, sizeof(rtpp_time_buff)); snprintf(rtpp_log_buff, sizeof(rtpp_log_buff), rli->eformat_se, rtpp_time_buff, strlvl(level), call_id, function, format, strerror(errno), errno); vfprintf(stderr, rtpp_log_buff, ap); }
static void test_log_level(void) { check_level("CRITICAL", LOG_LEVEL_CRIT); check_level("Error", LOG_LEVEL_ERR); check_level("warning", LOG_LEVEL_WARNING); check_level("notice", LOG_LEVEL_NOTICE); check_level("info", LOG_LEVEL_INFO); check_level("verbose", LOG_LEVEL_VERBOSE); check_level("debug", LOG_LEVEL_DEBUG); // LogLevelFromString should accept half typed strings: assert_int_equal(LogLevelFromString("CRIT"), LOG_LEVEL_CRIT); assert_int_equal(LogLevelFromString("ERR"), LOG_LEVEL_ERR); assert_int_equal(LogLevelFromString("warn"), LOG_LEVEL_WARNING); assert_int_equal(LogLevelFromString("I"), LOG_LEVEL_INFO); assert_int_equal(LogLevelFromString("i"), LOG_LEVEL_INFO); assert_int_equal(LogLevelFromString("information"), LOG_LEVEL_INFO); assert_int_equal(LogLevelFromString("v"), LOG_LEVEL_VERBOSE); //LogLevelFromString should return NOTHING in case of error: assert_int_equal(LogLevelFromString(""), LOG_LEVEL_NOTHING); assert_int_equal(LogLevelFromString("IX"), LOG_LEVEL_NOTHING); assert_int_equal(LogLevelFromString("Infotmation"), LOG_LEVEL_NOTHING); }
/** * gnutls_priority_init: * @priority_cache: is a #gnutls_prioritity_t structure. * @priorities: is a string describing priorities * @err_pos: In case of an error this will have the position in the string the error occured * * Sets priorities for the ciphers, key exchange methods, macs and * compression methods. * * The #priorities option allows you to specify a colon * separated list of the cipher priorities to enable. * Some keywords are defined to provide quick access * to common preferences. * * Unless there is a special need, using "NORMAL" or "NORMAL:%COMPAT" for compatibility * is recommended. * * "PERFORMANCE" means all the "secure" ciphersuites are enabled, * limited to 128 bit ciphers and sorted by terms of speed * performance. * * "NORMAL" means all "secure" ciphersuites. The 256-bit ciphers are * included as a fallback only. The ciphers are sorted by security * margin. * * "PFS" means all "secure" ciphersuites that support perfect forward secrecy. * The 256-bit ciphers are included as a fallback only. * The ciphers are sorted by security margin. * * "SECURE128" means all "secure" ciphersuites of security level 128-bit * or more. * * "SECURE192" means all "secure" ciphersuites of security level 192-bit * or more. * * "SUITEB128" means all the NSA SuiteB ciphersuites with security level * of 128. * * "SUITEB192" means all the NSA SuiteB ciphersuites with security level * of 192. * * "EXPORT" means all ciphersuites are enabled, including the * low-security 40 bit ciphers. * * "NONE" means nothing is enabled. This disables even protocols and * compression methods. * * Special keywords are "!", "-" and "+". * "!" or "-" appended with an algorithm will remove this algorithm. * "+" appended with an algorithm will add this algorithm. * * Check the GnuTLS manual section "Priority strings" for detailed * information. * * Examples: * * "NONE:+VERS-TLS-ALL:+MAC-ALL:+RSA:+AES-128-CBC:+SIGN-ALL:+COMP-NULL" * * "NORMAL:-ARCFOUR-128" means normal ciphers except for ARCFOUR-128. * * "SECURE128:-VERS-SSL3.0:+COMP-DEFLATE" means that only secure ciphers are * enabled, SSL3.0 is disabled, and libz compression enabled. * * "NONE:+VERS-TLS-ALL:+AES-128-CBC:+RSA:+SHA1:+COMP-NULL:+SIGN-RSA-SHA1", * * "NONE:+VERS-TLS-ALL:+AES-128-CBC:+ECDHE-RSA:+SHA1:+COMP-NULL:+SIGN-RSA-SHA1:+CURVE-SECP256R1", * * "SECURE256:+SECURE128", * * Note that "NORMAL:%COMPAT" is the most compatible mode. * * Returns: On syntax error %GNUTLS_E_INVALID_REQUEST is returned, * %GNUTLS_E_SUCCESS on success, or an error code. **/ int gnutls_priority_init(gnutls_priority_t * priority_cache, const char *priorities, const char **err_pos) { char *broken_list[MAX_ELEMENTS]; int broken_list_size = 0, i = 0, j; char *darg = NULL; unsigned ikeyword_set = 0; int algo; rmadd_func *fn; bulk_rmadd_func *bulk_fn; *priority_cache = gnutls_calloc(1, sizeof(struct gnutls_priority_st)); if (*priority_cache == NULL) { gnutls_assert(); return GNUTLS_E_MEMORY_ERROR; } if (err_pos) *err_pos = priorities; /* for now unsafe renegotiation is default on everyone. To be removed * when we make it the default. */ (*priority_cache)->sr = SR_PARTIAL; (*priority_cache)->ssl3_record_version = 1; (*priority_cache)->max_empty_records = DEFAULT_MAX_EMPTY_RECORDS; if (priorities == NULL) priorities = LEVEL_NORMAL; darg = gnutls_strdup(priorities); if (darg == NULL) { gnutls_assert(); goto error; } break_comma_list(darg, broken_list, &broken_list_size, MAX_ELEMENTS, ':'); /* This is our default set of protocol version, certificate types and * compression methods. */ if (strcasecmp(broken_list[0], LEVEL_NONE) != 0) { _set_priority(&(*priority_cache)->protocol, protocol_priority); _set_priority(&(*priority_cache)->compression, comp_priority); _set_priority(&(*priority_cache)->cert_type, cert_type_priority_default); _set_priority(&(*priority_cache)->sign_algo, sign_priority_default); _set_priority(&(*priority_cache)->supported_ecc, supported_ecc_normal); i = 0; } else { ikeyword_set = 1; i = 1; } for (; i < broken_list_size; i++) { if (check_level(broken_list[i], *priority_cache, ikeyword_set) != 0) { ikeyword_set = 1; continue; } else if (broken_list[i][0] == '!' || broken_list[i][0] == '+' || broken_list[i][0] == '-') { if (broken_list[i][0] == '+') { fn = prio_add; bulk_fn = _add_priority; } else { fn = prio_remove; bulk_fn = _clear_priorities; } if (broken_list[i][0] == '+' && check_level(&broken_list[i][1], *priority_cache, 1) != 0) { continue; } else if ((algo = gnutls_mac_get_id(&broken_list[i][1])) != GNUTLS_MAC_UNKNOWN) fn(&(*priority_cache)->mac, algo); else if ((algo = gnutls_cipher_get_id(&broken_list[i][1])) != GNUTLS_CIPHER_UNKNOWN) fn(&(*priority_cache)->cipher, algo); else if ((algo = gnutls_kx_get_id(&broken_list[i][1])) != GNUTLS_KX_UNKNOWN) fn(&(*priority_cache)->kx, algo); else if (strncasecmp (&broken_list[i][1], "VERS-", 5) == 0) { if (strncasecmp (&broken_list[i][1], "VERS-TLS-ALL", 12) == 0) { bulk_fn(&(*priority_cache)-> protocol, protocol_priority); } else if (strncasecmp (&broken_list[i][1], "VERS-DTLS-ALL", 13) == 0) { bulk_fn(&(*priority_cache)-> protocol, dtls_protocol_priority); } else { if ((algo = gnutls_protocol_get_id (&broken_list[i][6])) != GNUTLS_VERSION_UNKNOWN) fn(&(*priority_cache)-> protocol, algo); else goto error; } } /* now check if the element is something like -ALGO */ else if (strncasecmp (&broken_list[i][1], "COMP-", 5) == 0) { if (strncasecmp (&broken_list[i][1], "COMP-ALL", 8) == 0) { bulk_fn(&(*priority_cache)-> compression, comp_priority); } else { if ((algo = gnutls_compression_get_id (&broken_list[i][6])) != GNUTLS_COMP_UNKNOWN) fn(&(*priority_cache)-> compression, algo); else goto error; } } /* now check if the element is something like -ALGO */ else if (strncasecmp (&broken_list[i][1], "CURVE-", 6) == 0) { if (strncasecmp (&broken_list[i][1], "CURVE-ALL", 9) == 0) { bulk_fn(&(*priority_cache)-> supported_ecc, supported_ecc_normal); } else { if ((algo = _gnutls_ecc_curve_get_id (&broken_list[i][7])) != GNUTLS_ECC_CURVE_INVALID) fn(&(*priority_cache)-> supported_ecc, algo); else goto error; } } /* now check if the element is something like -ALGO */ else if (strncasecmp (&broken_list[i][1], "CTYPE-", 6) == 0) { if (strncasecmp (&broken_list[i][1], "CTYPE-ALL", 9) == 0) { bulk_fn(&(*priority_cache)-> cert_type, cert_type_priority_all); } else { if ((algo = gnutls_certificate_type_get_id (&broken_list[i][7])) != GNUTLS_CRT_UNKNOWN) fn(&(*priority_cache)-> cert_type, algo); else goto error; } } /* now check if the element is something like -ALGO */ else if (strncasecmp (&broken_list[i][1], "SIGN-", 5) == 0) { if (strncasecmp (&broken_list[i][1], "SIGN-ALL", 8) == 0) { bulk_fn(&(*priority_cache)-> sign_algo, sign_priority_default); } else { if ((algo = gnutls_sign_get_id (&broken_list[i][6])) != GNUTLS_SIGN_UNKNOWN) fn(&(*priority_cache)-> sign_algo, algo); else goto error; } } else if (strncasecmp (&broken_list[i][1], "MAC-ALL", 7) == 0) { bulk_fn(&(*priority_cache)->mac, mac_priority_normal); } else if (strncasecmp (&broken_list[i][1], "CIPHER-ALL", 10) == 0) { bulk_fn(&(*priority_cache)->cipher, cipher_priority_normal); } else if (strncasecmp (&broken_list[i][1], "KX-ALL", 6) == 0) { bulk_fn(&(*priority_cache)->kx, kx_priority_secure); } else goto error; } else if (broken_list[i][0] == '%') { if (strcasecmp(&broken_list[i][1], "COMPAT") == 0) { ENABLE_COMPAT((*priority_cache)); } else if (strcasecmp(&broken_list[i][1], "DUMBFW") == 0) { (*priority_cache)->dumbfw = 1; } else if (strcasecmp (&broken_list[i][1], "NO_EXTENSIONS") == 0) { (*priority_cache)->no_extensions = 1; } else if (strcasecmp (&broken_list[i][1], "STATELESS_COMPRESSION") == 0) { (*priority_cache)->stateless_compression = 1; } else if (strcasecmp (&broken_list[i][1], "VERIFY_ALLOW_SIGN_RSA_MD5") == 0) { prio_add(&(*priority_cache)->sign_algo, GNUTLS_SIGN_RSA_MD5); (*priority_cache)-> additional_verify_flags |= GNUTLS_VERIFY_ALLOW_SIGN_RSA_MD5; } else if (strcasecmp (&broken_list[i][1], "VERIFY_DISABLE_CRL_CHECKS") == 0) { (*priority_cache)-> additional_verify_flags |= GNUTLS_VERIFY_DISABLE_CRL_CHECKS; } else if (strcasecmp (&broken_list[i][1], "SSL3_RECORD_VERSION") == 0) (*priority_cache)->ssl3_record_version = 1; else if (strcasecmp(&broken_list[i][1], "LATEST_RECORD_VERSION") == 0) (*priority_cache)->ssl3_record_version = 0; else if (strcasecmp(&broken_list[i][1], "VERIFY_ALLOW_X509_V1_CA_CRT") == 0) (*priority_cache)-> additional_verify_flags |= GNUTLS_VERIFY_ALLOW_X509_V1_CA_CRT; else if (strcasecmp (&broken_list[i][1], "UNSAFE_RENEGOTIATION") == 0) { (*priority_cache)->sr = SR_UNSAFE; } else if (strcasecmp (&broken_list[i][1], "SAFE_RENEGOTIATION") == 0) { (*priority_cache)->sr = SR_SAFE; } else if (strcasecmp(&broken_list[i][1], "PARTIAL_RENEGOTIATION") == 0) { (*priority_cache)->sr = SR_PARTIAL; } else if (strcasecmp(&broken_list[i][1], "DISABLE_SAFE_RENEGOTIATION") == 0) { (*priority_cache)->sr = SR_DISABLED; } else if (strcasecmp(&broken_list[i][1], "SERVER_PRECEDENCE") == 0) { (*priority_cache)->server_precedence = 1; } else if (strcasecmp(&broken_list[i][1], "NEW_PADDING") == 0) { (*priority_cache)->new_record_padding = 1; } else goto error; } else goto error; } gnutls_free(darg); return 0; error: if (err_pos != NULL && i < broken_list_size) { *err_pos = priorities; for (j = 0; j < i; j++) { (*err_pos) += strlen(broken_list[j]) + 1; } } gnutls_free(darg); gnutls_free(*priority_cache); *priority_cache = NULL; return GNUTLS_E_INVALID_REQUEST; }
void eat(void) { struct object *obj; int amount; float scale = (float) (LINES * COLS) / (25.0F * 80.0F); if ((obj = get_object(pack, "eat", FOOD, NULL)) == NULL) return; switch (obj->o_which) { case FD_RATION: amount = (int)(scale * (HUNGERTIME + rnd(400) - 200)); if (rnd(100) > 70) { msg("Yuk, this food tastes awful."); pstats.s_exp++; check_level(); } else msg("Yum, that tasted good."); break; case FD_FRUIT: amount = (int)(scale * (200 + rnd(HUNGERTIME))); msg("My, that was a yummy %s.", fruit); break; case FD_CRAM: amount = (int)(scale * (rnd(HUNGERTIME / 2) + 600)); msg("The cram tastes dry in your mouth."); break; case FD_CAKES: amount = (int)(scale * ((HUNGERTIME / 3) + rnd(600))); msg("Yum, the honey cakes tasted good."); break; case FD_LEMBA: amount = (int)(scale * ((HUNGERTIME / 2) + rnd(900))); quaff(&player, P_HEALING, ISNORMAL); break; case FD_MIRUVOR: amount = (int)(scale * ((HUNGERTIME / 3) + rnd(500))); quaff(&player, P_HEALING, ISNORMAL); quaff(&player, P_RESTORE, ISNORMAL); break; default: msg("What a strange thing to eat!"); amount = (int)(scale * HUNGERTIME); } food_left += amount; if (obj->o_flags & ISBLESSED) { food_left += 2 * amount; msg("You have a tingling feeling in your mouth."); } else if (food_left > scale * STOMACHSIZE) { food_left = (int)(scale * STOMACHSIZE); msg("You feel satiated and too full to move."); no_command = HOLDTIME; } hungry_state = F_OK; updpack(); if (obj == cur_weapon) cur_weapon = NULL; if (--obj->o_count <= 0) /* Remove this pack entry if last of food */ discard_pack(obj); }
int add_pack(struct linked_list *item, int print_message) { struct object *obj, *op; int from_floor; if (item == NULL) { from_floor = TRUE; if ((item = find_obj(hero.y, hero.x)) == NULL) { msg("Nothing to pick up."); return(FALSE); } } else from_floor = FALSE; if (from_floor) { item = get_stack(item); if (!item) return(FALSE); } obj = OBJPTR(item); /* If it is gold, just add its value to rogue's purse and get rid of */ if (obj->o_type == GOLD) { struct linked_list *mitem; struct thing *tp; if (print_message) { if (!terse) addmsg("You found "); msg("%d gold pieces.", obj->o_count); } /* * First make sure no greedy monster is after this gold. If * so, make the monster run after the rogue instead. */ for (mitem = mlist; mitem != NULL; mitem = next(mitem)) { tp = THINGPTR(mitem); if (tp->t_horde==obj) { tp->t_ischasing = TRUE; tp->t_chasee = &player; tp->t_horde = NULL; } } /* * This will cause problems if people are able to drop and * pick up gold, or when GOLDSTEAL monsters are killed. */ /* Thieves get EXP for gold they pick up */ if (player.t_ctype == C_THIEF) { pstats.s_exp += obj->o_count / 4; check_level(); } purse += obj->o_count; if (from_floor) rem_obj(item, TRUE); /* Remove object from the level */ return (TRUE); } /* see if he can carry any more weight */ if (itemweight(obj) + pstats.s_pack > pstats.s_carry) { msg("Too much for you to carry."); if (print_message) { msg("%s onto %s", terse ? "Moved" : "You moved", inv_name(obj, LOWERCASE)); } return(FALSE); } /* * Link it into the pack. If the item can be grouped, try to find its * neighbors and bump the count. A special case is food, which can't * be grouped, but an exact match allows the count to get * incremented. */ if ((op = apply_to_bag(pack, obj->o_type, bff_group, NULL, obj)) != NULL) { op->o_count += obj->o_count; /* add it to the rest */ if (from_floor) rem_obj(item, FALSE); pack_report(op, print_message, "You now have "); return(TRUE); } /* Check for and deal with scare monster scrolls */ if (obj->o_type == SCROLL && obj->o_which == S_SCARE) if (obj->o_flags & ISCURSED) { msg("The scroll turns to dust as you pick it up."); rem_obj(item, TRUE); return(TRUE); } /* Check if there is room */ if (count_bag(pack, obj->o_type, NULL) == max_print()) { msg("You have no room for more %s.", name_type(obj->o_type)); if (print_message) { obj = OBJPTR(item); msg("%s onto %s.", terse ? "Moved" : "You moved", inv_name(obj, LOWERCASE)); } return(FALSE); } /* * finally, add the new item to the bag, and free up the linked list * on top of it. */ if (from_floor) rem_obj(item, FALSE); push_bag(&pack, obj); pack_report(obj, print_message, "You now have "); ur_free(item); return(TRUE); /* signal success */ }
/** * gnutls_priority_init: * @priority_cache: is a #gnutls_prioritity_t structure. * @priorities: is a string describing priorities * @err_pos: In case of an error this will have the position in the string the error occurred * * Sets priorities for the ciphers, key exchange methods, macs and * compression methods. * * The #priorities option allows you to specify a colon * separated list of the cipher priorities to enable. * Some keywords are defined to provide quick access * to common preferences. * * Unless there is a special need, use the "NORMAL" keyword to * apply a reasonable security level, or "NORMAL:%COMPAT" for compatibility. * * "PERFORMANCE" means all the "secure" ciphersuites are enabled, * limited to 128 bit ciphers and sorted by terms of speed * performance. * * "LEGACY" the NORMAL settings for GnuTLS 3.2.x or earlier. There is * no verification profile set, and the allowed DH primes are considered * weak today. * * "NORMAL" means all "secure" ciphersuites. The 256-bit ciphers are * included as a fallback only. The ciphers are sorted by security * margin. * * "PFS" means all "secure" ciphersuites that support perfect forward secrecy. * The 256-bit ciphers are included as a fallback only. * The ciphers are sorted by security margin. * * "SECURE128" means all "secure" ciphersuites of security level 128-bit * or more. * * "SECURE192" means all "secure" ciphersuites of security level 192-bit * or more. * * "SUITEB128" means all the NSA SuiteB ciphersuites with security level * of 128. * * "SUITEB192" means all the NSA SuiteB ciphersuites with security level * of 192. * * "EXPORT" means all ciphersuites are enabled, including the * low-security 40 bit ciphers. * * "NONE" means nothing is enabled. This disables even protocols and * compression methods. * * "@KEYWORD" The system administrator imposed settings. The provided keywords * will be expanded from a configuration-time provided file - default is: * /etc/gnutls/default-priorities. Any keywords that follow it, will * be appended to the expanded string. If there is no system string, * then the function will fail. The system file should be formatted * as "KEYWORD=VALUE", e.g., "SYSTEM=NORMAL:-ARCFOUR-128". * * Special keywords are "!", "-" and "+". * "!" or "-" appended with an algorithm will remove this algorithm. * "+" appended with an algorithm will add this algorithm. * * Check the GnuTLS manual section "Priority strings" for detailed * information. * * Examples: * * "NONE:+VERS-TLS-ALL:+MAC-ALL:+RSA:+AES-128-CBC:+SIGN-ALL:+COMP-NULL" * * "NORMAL:-ARCFOUR-128" means normal ciphers except for ARCFOUR-128. * * "SECURE128:-VERS-SSL3.0:+COMP-DEFLATE" means that only secure ciphers are * enabled, SSL3.0 is disabled, and libz compression enabled. * * "NONE:+VERS-TLS-ALL:+AES-128-CBC:+RSA:+SHA1:+COMP-NULL:+SIGN-RSA-SHA1", * * "NONE:+VERS-TLS-ALL:+AES-128-CBC:+ECDHE-RSA:+SHA1:+COMP-NULL:+SIGN-RSA-SHA1:+CURVE-SECP256R1", * * "SECURE256:+SECURE128", * * Note that "NORMAL:%COMPAT" is the most compatible mode. * * Returns: On syntax error %GNUTLS_E_INVALID_REQUEST is returned, * %GNUTLS_E_SUCCESS on success, or an error code. **/ int gnutls_priority_init(gnutls_priority_t * priority_cache, const char *priorities, const char **err_pos) { char *broken_list[MAX_ELEMENTS]; int broken_list_size = 0, i = 0, j; char *darg = NULL; unsigned ikeyword_set = 0; int algo; rmadd_func *fn; bulk_rmadd_func *bulk_fn; if (err_pos) *err_pos = priorities; *priority_cache = gnutls_calloc(1, sizeof(struct gnutls_priority_st)); if (*priority_cache == NULL) { gnutls_assert(); return GNUTLS_E_MEMORY_ERROR; } /* for now unsafe renegotiation is default on everyone. To be removed * when we make it the default. */ (*priority_cache)->sr = SR_PARTIAL; (*priority_cache)->ssl3_record_version = 1; (*priority_cache)->max_empty_records = DEFAULT_MAX_EMPTY_RECORDS; if (priorities == NULL) priorities = "NORMAL"; darg = resolve_priorities(priorities); if (darg == NULL) { gnutls_assert(); goto error; } break_list(darg, broken_list, &broken_list_size); /* This is our default set of protocol version, certificate types and * compression methods. */ if (strcasecmp(broken_list[0], LEVEL_NONE) != 0) { _set_priority(&(*priority_cache)->protocol, protocol_priority); _set_priority(&(*priority_cache)->compression, comp_priority); _set_priority(&(*priority_cache)->cert_type, cert_type_priority_default); _set_priority(&(*priority_cache)->sign_algo, sign_priority_default); _set_priority(&(*priority_cache)->supported_ecc, supported_ecc_normal); i = 0; } else { ikeyword_set = 1; i = 1; } for (; i < broken_list_size; i++) { if (check_level(broken_list[i], *priority_cache, ikeyword_set) != 0) { ikeyword_set = 1; continue; } else if (broken_list[i][0] == '!' || broken_list[i][0] == '+' || broken_list[i][0] == '-') { if (broken_list[i][0] == '+') { fn = prio_add; bulk_fn = _add_priority; } else { fn = prio_remove; bulk_fn = _clear_priorities; } if (broken_list[i][0] == '+' && check_level(&broken_list[i][1], *priority_cache, 1) != 0) { continue; } else if ((algo = gnutls_mac_get_id(&broken_list[i][1])) != GNUTLS_MAC_UNKNOWN) fn(&(*priority_cache)->mac, algo); else if ((algo = gnutls_cipher_get_id(&broken_list[i][1])) != GNUTLS_CIPHER_UNKNOWN) fn(&(*priority_cache)->cipher, algo); else if ((algo = gnutls_kx_get_id(&broken_list[i][1])) != GNUTLS_KX_UNKNOWN) fn(&(*priority_cache)->kx, algo); else if (strncasecmp (&broken_list[i][1], "VERS-", 5) == 0) { if (strncasecmp (&broken_list[i][1], "VERS-TLS-ALL", 12) == 0) { bulk_fn(&(*priority_cache)-> protocol, protocol_priority); } else if (strncasecmp (&broken_list[i][1], "VERS-DTLS-ALL", 13) == 0) { bulk_fn(&(*priority_cache)-> protocol, dtls_protocol_priority); } else { if ((algo = gnutls_protocol_get_id (&broken_list[i][6])) != GNUTLS_VERSION_UNKNOWN) fn(&(*priority_cache)-> protocol, algo); else goto error; } } /* now check if the element is something like -ALGO */ else if (strncasecmp (&broken_list[i][1], "COMP-", 5) == 0) { if (strncasecmp (&broken_list[i][1], "COMP-ALL", 8) == 0) { bulk_fn(&(*priority_cache)-> compression, comp_priority); } else { if ((algo = gnutls_compression_get_id (&broken_list[i][6])) != GNUTLS_COMP_UNKNOWN) fn(&(*priority_cache)-> compression, algo); else goto error; } } /* now check if the element is something like -ALGO */ else if (strncasecmp (&broken_list[i][1], "CURVE-", 6) == 0) { if (strncasecmp (&broken_list[i][1], "CURVE-ALL", 9) == 0) { bulk_fn(&(*priority_cache)-> supported_ecc, supported_ecc_normal); } else { if ((algo = _gnutls_ecc_curve_get_id (&broken_list[i][7])) != GNUTLS_ECC_CURVE_INVALID) fn(&(*priority_cache)-> supported_ecc, algo); else goto error; } } /* now check if the element is something like -ALGO */ else if (strncasecmp (&broken_list[i][1], "CTYPE-", 6) == 0) { if (strncasecmp (&broken_list[i][1], "CTYPE-ALL", 9) == 0) { bulk_fn(&(*priority_cache)-> cert_type, cert_type_priority_all); } else { if ((algo = gnutls_certificate_type_get_id (&broken_list[i][7])) != GNUTLS_CRT_UNKNOWN) fn(&(*priority_cache)-> cert_type, algo); else goto error; } } /* now check if the element is something like -ALGO */ else if (strncasecmp (&broken_list[i][1], "SIGN-", 5) == 0) { if (strncasecmp (&broken_list[i][1], "SIGN-ALL", 8) == 0) { bulk_fn(&(*priority_cache)-> sign_algo, sign_priority_default); } else { if ((algo = gnutls_sign_get_id (&broken_list[i][6])) != GNUTLS_SIGN_UNKNOWN) fn(&(*priority_cache)-> sign_algo, algo); else goto error; } } else if (strncasecmp (&broken_list[i][1], "MAC-ALL", 7) == 0) { bulk_fn(&(*priority_cache)->mac, mac_priority_normal); } else if (strncasecmp (&broken_list[i][1], "CIPHER-ALL", 10) == 0) { bulk_fn(&(*priority_cache)->cipher, cipher_priority_normal); } else if (strncasecmp (&broken_list[i][1], "KX-ALL", 6) == 0) { bulk_fn(&(*priority_cache)->kx, kx_priority_secure); } else goto error; } else if (broken_list[i][0] == '%') { const struct priority_options_st * o; /* to add a new option modify * priority_options.gperf */ o = in_word_set(&broken_list[i][1], strlen(&broken_list[i][1])); if (o == NULL) { goto error; } o->func(*priority_cache); } else goto error; } free(darg); return 0; error: if (err_pos != NULL && i < broken_list_size) { *err_pos = priorities; for (j = 0; j < i; j++) { (*err_pos) += strlen(broken_list[j]) + 1; } } free(darg); gnutls_free(*priority_cache); *priority_cache = NULL; return GNUTLS_E_INVALID_REQUEST; }
int main(void) { hwloc_topology_t topology; unsigned depth; char buffer[1024]; int err; /* check a synthetic topology */ hwloc_topology_init(&topology); err = hwloc_topology_set_synthetic(topology, "pack:2 numa:3 l2:4 core:5 pu:6"); assert(!err); hwloc_topology_load(topology); assert(hwloc_get_memory_parents_depth(topology) == 2); /* internal checks */ hwloc_topology_check(topology); /* local checks */ depth = hwloc_topology_get_depth(topology); assert(depth == 6); check_level(topology, 0, 1, 2); check_level(topology, 1, 2, 3); check_level(topology, 2, 6, 4); check_level(topology, 3, 24, 5); check_level(topology, 4, 120, 6); check_level(topology, 5, 720, 0); check_level(topology, HWLOC_TYPE_DEPTH_NUMANODE, 6, 0); err = hwloc_topology_export_synthetic(topology, buffer, sizeof(buffer), 0); assert(err == 83); err = strcmp("Package:2 Group:3 [NUMANode(memory=1073741824)] L2Cache:4(size=4194304) Core:5 PU:6", buffer); assert(!err); assert(hwloc_get_memory_parents_depth(topology) == 2); err = hwloc_topology_export_synthetic(topology, buffer, sizeof(buffer), HWLOC_TOPOLOGY_EXPORT_SYNTHETIC_FLAG_NO_EXTENDED_TYPES|HWLOC_TOPOLOGY_EXPORT_SYNTHETIC_FLAG_NO_ATTRS|HWLOC_TOPOLOGY_EXPORT_SYNTHETIC_FLAG_V1); assert(err == 47); err = strcmp("Socket:2 Group:3 NUMANode:1 Cache:4 Core:5 PU:6", buffer); assert(!err); hwloc_topology_destroy(topology); hwloc_topology_init(&topology); err = hwloc_topology_set_type_filter(topology, HWLOC_OBJ_L1ICACHE, HWLOC_TYPE_FILTER_KEEP_ALL); err = hwloc_topology_set_synthetic(topology, "pack:2(indexes=3,5) numa:2(memory=256GB indexes=pack) l3u:1(size=20mb) l2:2 l1i:1(size=16kB) l1dcache:2 core:1 pu:2(indexes=l2)"); assert(!err); hwloc_topology_load(topology); assert(hwloc_get_memory_parents_depth(topology) == 2); err = hwloc_topology_export_synthetic(topology, buffer, sizeof(buffer), 0); assert(err == 181); err = strcmp("Package:2 L3Cache:2(size=20971520) [NUMANode(memory=274877906944 indexes=2*2:1*2)] L2Cache:2(size=4194304) L1iCache:1(size=16384) L1dCache:2(size=32768) Core:1 PU:2(indexes=4*8:1*4)", buffer); assert(!err); assert(hwloc_get_obj_by_type(topology, HWLOC_OBJ_PACKAGE, 1)->os_index == 5); assert(hwloc_get_obj_by_type(topology, HWLOC_OBJ_NUMANODE, 1)->os_index == 2); assert(hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, 12)->os_index == 3); assert(hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, 13)->os_index == 11); assert(hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, 14)->os_index == 19); assert(hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, 15)->os_index == 27); assert(hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, 16)->os_index == 4); assert(hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, 17)->os_index == 12); assert(hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, 18)->os_index == 20); assert(hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, 19)->os_index == 28); hwloc_topology_destroy(topology); hwloc_topology_init(&topology); err = hwloc_topology_set_synthetic(topology, "pack:2 core:2 pu:2(indexes=0,4,2,6,1,5,3,7)"); assert(!err); hwloc_topology_load(topology); assert(hwloc_get_memory_parents_depth(topology) == 0); err = hwloc_topology_export_synthetic(topology, buffer, sizeof(buffer), 0); assert(err == 72); err = strcmp("[NUMANode(memory=1073741824)] Package:2 Core:2 PU:2(indexes=4*2:2*2:1*2)", buffer); assert(!err); assert(hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, 0)->os_index == 0); assert(hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, 1)->os_index == 4); assert(hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, 2)->os_index == 2); assert(hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, 3)->os_index == 6); assert(hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, 4)->os_index == 1); assert(hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, 5)->os_index == 5); assert(hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, 6)->os_index == 3); assert(hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, 7)->os_index == 7); hwloc_topology_destroy(topology); hwloc_topology_init(&topology); err = hwloc_topology_set_synthetic(topology, "pack:2 numa:2 core:1 pu:2(indexes=0,4,2,6,1,3,5,7)"); assert(!err); hwloc_topology_load(topology); assert(hwloc_get_memory_parents_depth(topology) == 2); err = hwloc_topology_export_synthetic(topology, buffer, sizeof(buffer), 0); assert(err == 76); err = strcmp("Package:2 Core:2 [NUMANode(memory=1073741824)] PU:2(indexes=0,4,2,6,1,3,5,7)", buffer); assert(!err); assert(hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, 0)->os_index == 0); assert(hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, 1)->os_index == 4); assert(hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, 2)->os_index == 2); assert(hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, 3)->os_index == 6); assert(hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, 4)->os_index == 1); assert(hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, 5)->os_index == 3); assert(hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, 6)->os_index == 5); assert(hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, 7)->os_index == 7); hwloc_topology_destroy(topology); hwloc_topology_init(&topology); err = hwloc_topology_set_synthetic(topology, "pack:2 [numa(memory=1GB)] [numa(memory=1MB)] core:2 [numa(indexes=8,7,5,6,4,3,1,2)] pu:4"); assert(!err); hwloc_topology_load(topology); assert(hwloc_get_memory_parents_depth(topology) == HWLOC_TYPE_DEPTH_MULTIPLE); err = hwloc_topology_export_synthetic(topology, buffer, sizeof(buffer), 0); assert(err == 114); err = strcmp("Package:2 [NUMANode(memory=1073741824)] [NUMANode(memory=1048576)] Core:2 [NUMANode(indexes=8,7,5,6,4,3,1,2)] PU:4", buffer); assert(!err); err = hwloc_topology_export_synthetic(topology, buffer, sizeof(buffer), HWLOC_TOPOLOGY_EXPORT_SYNTHETIC_FLAG_V1); assert(err == -1); assert(errno == EINVAL); err = hwloc_topology_export_synthetic(topology, buffer, sizeof(buffer), HWLOC_TOPOLOGY_EXPORT_SYNTHETIC_FLAG_IGNORE_MEMORY); assert(err == 21); err = strcmp("Package:2 Core:2 PU:4", buffer); assert(!err); hwloc_topology_destroy(topology); return 0; }
void raise_level() { pstats.s_exp = e_levels[pstats.s_lvl-1] + 1L; check_level(); }