int main (int argc, char *argv[]) { int verbose = argc > 1 ? 1 : 0; char buf[MAX_LEN]; while (fgets (buf, MAX_LEN, stdin)) { if (strlen (buf) > 0 && buf[strlen (buf) - 1] == '\n') buf[strlen (buf) - 1] = '\0'; if (in_word_set (buf, strlen (buf))) { if (verbose) printf ("in word set %s\n", buf); } else { if (verbose) printf ("NOT in word set %s\n", buf); } } return 0; }
/* * parse a ca section */ static void load_ca(starter_ca_t *ca, starter_config_t *cfg, conf_parser_t *parser) { enumerator_t *enumerator; dictionary_t *dict; const kw_entry_t *entry; kw_token_t token; char *key, *value; DBG2(DBG_APP, "Loading ca '%s'", ca->name); dict = parser->get_section(parser, CONF_PARSER_CA, ca->name); if (!dict) { return; } enumerator = dict->create_enumerator(dict); while (enumerator->enumerate(enumerator, &key, &value)) { bool assigned = FALSE; entry = in_word_set(key, strlen(key)); if (!entry) { DBG1(DBG_APP, "# unknown keyword '%s'", key); cfg->non_fatal_err++; continue; } token = entry->token; if (token == KW_AUTO) { token = KW_CA_SETUP; } if (token < KW_CA_FIRST || token > KW_CA_LAST) { DBG1(DBG_APP, "# unsupported keyword '%s' in ca '%s'", key, ca->name); cfg->err++; continue; } if (is_deprecated(token, key, ca->name)) { cfg->non_fatal_err++; continue; } if (!assign_arg(token, KW_CA_FIRST, key, value, ca, &assigned)) { DBG1(DBG_APP, " bad argument value in ca '%s'", ca->name); cfg->err++; } } enumerator->destroy(enumerator); dict->destroy(dict); /* treat 'route' and 'start' as 'add' */ if (ca->startup != STARTUP_NO) { ca->startup = STARTUP_ADD; } }
/** * Translate a function name into an avs_builtin_functions table index number. * * @param name Name to lookup. * * @return AvsBuiltinFunctionType index number matching 'name'. */ AvsBuiltinFunctionType avs_builtin_function_type(char *name) { AvsBuiltinFunctionToken *tok = in_word_set(name, strlen(name)); if (!tok) return -1; return tok->lookup; }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { struct keyword *pk; /* pointer to keyword structure */ mxArray *pp, *pv; /* pointer to property and value */ element_t *pe; /* pointer to element */ element_t el; int nc, idx; char pstr[PS_LEN]; /* property name string */ char errmsg[ERR_LEN]; if (nrhs != 2) mexErrMsgTxt("set_element_data : must have exactly two arguments."); /* get pointer to input element and make local copy */ pe = (element_t *)mxGetData(prhs[0]); memcpy(&el, pe, sizeof(element_t)); /* check 2nd argument */ if ( !mxIsCell(prhs[1]) ) mexErrMsgTxt("set_element_data : 2nd argument must be cell array."); /* get number of cells */ nc = mxGetNumberOfElements(prhs[1]); if (nc % 2) mexErrMsgTxt("set_element_data : 2nd argument must consist of propery/value pairs."); /* store property/value pairs one-by-one */ for (idx = 0; idx<nc; idx+=2) { /* get next property value pair */ pp = mxGetCell(prhs[1], idx); pv = mxGetCell(prhs[1], idx+1); /* decode property argument using the hash function in prop_hash.h */ if ( !mxIsChar(pp) ) mexErrMsgTxt("set_element_data : properties must be character strings."); mxGetString(pp, pstr, PS_LEN); pk = (struct keyword *)in_word_set(pstr, strlen(pstr)); if (pk == NULL) { sprintf(errmsg, "set_element_data : unknown element property -> %s", pstr); mexErrMsgTxt(errmsg); } /* store the property value in internal structure */ if ( !mxIsEmpty(pv) ) (*pk->set_prop_func)(&el, pv); } /* return element to caller */ plhs[0] = copy_element_to_array(&el); }
/* lookup an ipfix name into its ID int because we need -1 for "not found" */ int ipfix_name_lookup(const char *name) { const struct ipfix_midentifier *tmp; if (!(tmp=in_word_set(name, strlen(name)))) { /* not found */ return -1; } return (int)tmp->id; }
/** * Search builtin function * * @param name Builtin function to find. * * @return AvsRunnableFunction structure matching 'name' on success, NULL on failure. */ AvsRunnableFunction * avs_builtin_function_find(char *name) { AvsBuiltinFunctionToken *tok; tok = in_word_set(name, strlen(name)); if (tok == NULL) return NULL; if (tok->lookup >= sizeof(avs_builtin_functions) / sizeof(AvsRunnableFunction)) return NULL; return &avs_builtin_functions[tok->lookup]; }
int main (int argc, char *argv[]) { int verbose = argc > 1 ? 1 : 0; char buf[MAX_LEN]; char *s; while (gets (buf)) if ((s = in_word_set (buf, strlen (buf))) && verbose) printf ("%s is prefix for %s\n", buf, s); else if (verbose) printf ("NOT in word set %s\n", buf); return 0; }
int find_confstr(const char *name, int *key) { const struct map *rv; rv = in_word_set(name); if (rv != NULL) { if (rv->valid) { *key = rv->key; return 1; } return -1; } return 0; }
int find_progenv(const char *name, const char **alt_path) { const struct map *rv; rv = in_word_set(name); if (rv != NULL) { if (rv->valid) { *alt_path = rv->alt_path; return 1; } return -1; } return 0; }
/* * parse config setup section */ static void load_setup(starter_config_t *cfg, conf_parser_t *parser) { enumerator_t *enumerator; dictionary_t *dict; const kw_entry_t *entry; char *key, *value; DBG2(DBG_APP, "Loading config setup"); dict = parser->get_section(parser, CONF_PARSER_CONFIG_SETUP, NULL); if (!dict) { return; } enumerator = dict->create_enumerator(dict); while (enumerator->enumerate(enumerator, &key, &value)) { bool assigned = FALSE; entry = in_word_set(key, strlen(key)); if (!entry) { DBG1(DBG_APP, "# unknown keyword '%s'", key); cfg->non_fatal_err++; continue; } if ((int)entry->token < KW_SETUP_FIRST || entry->token > KW_SETUP_LAST) { DBG1(DBG_APP, "# unsupported keyword '%s' in config setup", key); cfg->err++; continue; } if (is_deprecated(entry->token, key, "")) { cfg->non_fatal_err++; continue; } if (!assign_arg(entry->token, KW_SETUP_FIRST, key, value, cfg, &assigned)) { DBG1(DBG_APP, " bad argument value in config setup"); cfg->err++; } } enumerator->destroy(enumerator); dict->destroy(dict); }
static inline int parseId(YYSTYPE *lvalp, yyscan_t scanner) { const struct keyword *kw; const unsigned char *in = (const unsigned char*)scanner->in; scanner->state = Initial; while(scanner->pos < scanner->insize) { unsigned char c = in[scanner->pos++]; enum char_class cClass = id_ctype[c]; switch(cClass) { case IdStart: textbuffer_putc(&scanner->buf, c); break; case Operator: /* the table contains OP only for \ */ assert(c == '\\'); if(scanner->pos < scanner->insize && in[scanner->pos++] == 'u') { textbuffer_putc(&scanner->buf, c); break; } if(scanner->pos == scanner->insize) { scanner->pos++; } /* else fallthrough */ default: /* character is no longer part of identifier */ scanner->state = Initial; textbuffer_putc(&scanner->buf, '\0'); scanner->pos--; kw = in_word_set(scanner->buf.data, scanner->buf.pos-1); if(kw) { /* we got a keyword */ TOKEN_SET(lvalp, cstring, kw->name); return kw->val; } /* it is not a keyword, just an identifier */ TOKEN_SET(lvalp, cstring, NULL); return TOK_IDENTIFIER_NAME; } } scanner->state = Identifier; return 0; }
int ch_utf8_to_custom(const char* s) { int i, n; struct utf8_to_custom* res; unsigned char name[8]; n = ch_utf8_length(s); if(n <= 0) return 0; if(n == 1) return (*s - 32); for(i = 0; i < n; i++) name[i] = ((unsigned char*)(s))[i]; name[n] = 0; res = in_word_set(name, n); if(res) return res->value; else return 0; }
static int l_loadbin( lua_State* L ) { gwlua_t* state = get_state( L ); size_t len; const char* name = luaL_checklstring( L, 1, &len ); const struct binary_t* found = in_word_set( name, len ); gwrom_entry_t entry; if ( found ) { entry.data = found->data; entry.size = found->size; } else { if ( gwrom_find( &entry, state->rom, name ) != GWROM_OK ) { return 0; } } lua_pushlstring( L, (char*)entry.data, entry.size ); return 1; }
InsetMathSymbol::InsetMathSymbol(docstring const & name) : sym_(in_word_set(name)), h_(0), kerning_(0), scriptable_(false) {}
/* * parse a conn section */ static void load_conn(starter_conn_t *conn, starter_config_t *cfg, conf_parser_t *parser) { enumerator_t *enumerator; dictionary_t *dict; const kw_entry_t *entry; kw_token_t token; char *key, *value; DBG2(DBG_APP, "Loading conn '%s'", conn->name); dict = parser->get_section(parser, CONF_PARSER_CONN, conn->name); if (!dict) { return; } enumerator = dict->create_enumerator(dict); while (enumerator->enumerate(enumerator, &key, &value)) { bool assigned = FALSE; entry = in_word_set(key, strlen(key)); if (!entry) { DBG1(DBG_APP, "# unknown keyword '%s'", key); cfg->non_fatal_err++; continue; } token = entry->token; if (token >= KW_LEFT_FIRST && token <= KW_LEFT_LAST) { kw_end(conn, &conn->left, token - KW_LEFT_FIRST + KW_END_FIRST, key, value, cfg); continue; } else if (token >= KW_RIGHT_FIRST && token <= KW_RIGHT_LAST) { kw_end(conn, &conn->right, token - KW_RIGHT_FIRST + KW_END_FIRST, key, value, cfg); continue; } if (token == KW_AUTO) { token = KW_CONN_SETUP; } if (token < KW_CONN_FIRST || token > KW_CONN_LAST) { DBG1(DBG_APP, "# unsupported keyword '%s' in conn '%s'", key, conn->name); cfg->err++; continue; } if (is_deprecated(token, key, conn->name)) { cfg->non_fatal_err++; continue; } if (!assign_arg(token, KW_CONN_FIRST, key, value, conn, &assigned)) { DBG1(DBG_APP, " bad argument value in conn '%s'", conn->name); cfg->err++; continue; } if (!assigned) { handle_keyword(token, conn, key, value, cfg); } } enumerator->destroy(enumerator); dict->destroy(dict); handle_firewall("left", &conn->left, cfg); handle_firewall("right", &conn->right, cfg); }
const struct keyword * find_keyword(const char *word) { return in_word_set(word, strlen(word)); }
InsetMathSymbol::InsetMathSymbol(char const * name) : sym_(in_word_set(from_ascii(name))), h_(0), kerning_(0), scriptable_(false) {}
int main(int argc, char *argv[]) { FILE *f; char *line = NULL; size_t line_sz = 0; unsigned int line_num; size_t max_scancode; char const *fname; bool ignore_missing = false; if (argc != 3) { fprintf(stderr, "bad parameters\n"); return EX_USAGE; } fname = argv[1]; if (fname[0] == '-') { ignore_missing = true; ++fname; } f = fopen(fname, "r"); if (f) { ; /* noop */ } else if (ignore_missing) { return EX_OK; } else { fprintf(stderr, "failed to open keymap file '%s': %m\n", fname); return EX_NOINPUT; } max_scancode = strtoul(argv[2], NULL, 10); for (line_num = 1;; ++line_num) { ssize_t l = getline(&line, &line_sz, f); char *ptr; char *err_ptr; unsigned int scancode; unsigned int keyid; struct keymap_data_rpc info = { }; if (l < 0 && feof(f)) { break; } else if (l < 0) { fprintf(stderr, "failed to read from keymap file '%s': %m\n", fname); return EX_IOERR; } ptr = strchr(line, '#'); if (ptr) *ptr = '\0'; l = strlen(line); while (l > 0 && (isspace(line[l-1]) || line[l-1] == '\n' || line[l-1] == '\r')) --l; line[l] = '\0'; ptr = line; while (isspace(*ptr)) ++ptr; scancode = strtoul(ptr, &err_ptr, 0); if (err_ptr == ptr || !isspace(*err_ptr)) { fprintf(stderr, "%s:%u invalid scancode\n", fname, line_num); continue; } ptr = err_ptr; while (isspace(*ptr) && *ptr != '\0') ++ptr; if (*ptr == '$') { ++ptr; keyid = strtoul(ptr, &err_ptr, 0); if (err_ptr == ptr || (!isspace(*err_ptr) && *err_ptr)) { fprintf(stderr, "%s:%u invalid keyid\n", fname, line_num); continue; } } else { struct keymap_def const *def = in_word_set(ptr, line + l - ptr); if (!def) { fprintf(stderr, "%s:%u unknown keyname '%s'", fname, line_num, ptr); continue; } keyid = def->num; } if (scancode >= max_scancode) { fprintf(stderr, "%s:%u scancode %u out of range\n", fname, line_num, scancode); continue; } if (keyid >= KEY_MAX) { fprintf(stderr, "%s:%u unsupported keyid %u\n", fname, line_num, scancode); continue; } info.scancode = scancode; info.keyid = keyid; if (fwrite(&info, sizeof info, 1, stdout) != 1) return EX_OSERR; } fclose(f); return EX_OK; }
/** * 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; }