コード例 #1
0
ファイル: bogolexer.c プロジェクト: Distrotech/bogofilter
int main(int argc, char **argv)
{
    token_t t;

    fpo = stdout;

    mbox_mode = true;		/* to allow multiple messages */

    process_arglist(argc, argv);
    process_config_files(false, longopts_bogolexer);

    if (encoding == E_UNKNOWN)
	encoding = E_DEFAULT;

    textblock_init();

    if (!passthrough)
    {
	if (quiet)
	    fprintf(fpo, "quiet mode.\n");
	else
	    fprintf(fpo, "normal mode.\n");
    }

    bogoreader_init(argc, (const char * const *) argv);

    while ((*reader_more)()) {
	word_t token;
	lexer_init();

	while ((t = get_token( &token )) != NONE)
	{
	    count += 1;
	    if (passthrough) {
		fprintf(fpo, "%s\n", token.u.text);
	    }
	    else if (!quiet)
		fprintf(fpo, "get_token: %d \"%s\"\n", (int)t, token.u.text);
	}
    }

    if ( !passthrough )
	fprintf(fpo, "%d tokens read.\n", count);

    /* cleanup storage */
    token_cleanup();
    mime_cleanup();
    textblock_free();

    MEMDISPLAY;

    return 0;
}
コード例 #2
0
static void bogotune_free(void)
{
    xfree(ns_scores);
    xfree(sp_scores);

    filelist_free(ham_files);
    filelist_free(spam_files);

    tunelist_free(ns_msglists);
    tunelist_free(sp_msglists);
    tunelist_free(ns_and_sp);

    word_free(w_msg_count);

    token_cleanup();
    mime_cleanup();

    xfree(ds_path);

    return;
}
コード例 #3
0
ファイル: tokenizer_test.c プロジェクト: arkanis/lagrange
void test_samples() {
	for(size_t i = 0; i < sizeof(samples) / sizeof(samples[0]); i++) {
		char* code = samples[i].code;
		//printf("test: %s\n", code);
		
		token_list_t tokens = { 0 };
		tokenize(str_from_c(code), &tokens, stderr);
		
		st_check_int(tokens.len, samples[i].tokens_len);
		for(size_t j = 0; j < samples[i].tokens_len; j++) {
			token_p actual_token = &tokens.ptr[j];
			token_p expected_token = &samples[i].tokens_ptr[j];
			
			st_check_msg(actual_token->type == expected_token->type, "got %s, expected %s",
				token_type_name(actual_token->type), token_type_name(expected_token->type));
			st_check_int(actual_token->source.len, expected_token->source.len);
			st_check_strn(actual_token->source.ptr, expected_token->source.ptr, expected_token->source.len);
			if (actual_token->type == T_INT) {
				st_check(actual_token->int_val == expected_token->int_val);
			} else if (actual_token->type == T_ERROR) {
				// Check that an error message is present, exact content doesn't matter, will change anyway
				st_check(actual_token->str_val.len > 0);
				st_check_not_null(actual_token->str_val.ptr);
			} else if (expected_token->str_val.ptr != NULL) {
				st_check_int(actual_token->str_val.len, expected_token->str_val.len);
				st_check_strn(actual_token->str_val.ptr, expected_token->str_val.ptr, expected_token->str_val.len);
			} else {
				st_check_null(actual_token->str_val.ptr);
				st_check_int(actual_token->str_val.len, 0);
			}
		}
		
		for(size_t j = 0; j < tokens.len; j++)
			token_cleanup(&tokens.ptr[j]);
		list_destroy(&tokens);
	}
}
コード例 #4
0
ファイル: pgn-tokenizer.c プロジェクト: alexmdc/chesslib
void chess_pgn_tokenizer_cleanup(ChessPgnTokenizer* tokenizer)
{
    token_cleanup(&tokenizer->tokens[0]);
    token_cleanup(&tokenizer->tokens[1]);
    chess_buffer_cleanup(&tokenizer->buffer);
}
コード例 #5
0
ファイル: keystore_pkcs11.c プロジェクト: idtek/knot
int main(int argc, char *argv[])
{
	plan_lazy();

	dnssec_crypto_init();

	// PKCS #11 initialization

	dnssec_keystore_t *store = NULL;
	int r = dnssec_keystore_init_pkcs11(&store);
	if (r == DNSSEC_NOT_IMPLEMENTED_ERROR) {
		skip_all("not supported");
		goto done;
	}
	ok(r == DNSSEC_EOK && store, "dnssec_keystore_init_pkcs11()");

	char *dso_name = libsofthsm_dso();
	if (!dso_name) {
		skip_all("%s not found, set %s environment variable",
			 SOFTHSM_DSO, ENV_SOFTHSM_DSO);
		goto done;
	}
	ok(dso_name != NULL, "find token DSO");

	bool success = token_init();
	if (!success) {
		skip_all("failed to configure and initialize the token");
		goto done;
	}
	ok(success, "initialize the token");

	char config[4096] = { 0 };
	r = snprintf(config, sizeof(config), "pkcs11:token=%s;pin-value=%s %s",
	                                     TOKEN_LABEL, TOKEN_PIN, dso_name);
	free(dso_name);
	ok(r > 0 && r < sizeof(config), "build configuration");

	// key store access

	r = dnssec_keystore_init(store, config);
	ok(r == DNSSEC_NOT_IMPLEMENTED_ERROR, "dnssec_keystore_init(), not implemented");

	r = dnssec_keystore_open(store, config);
	ok(r == DNSSEC_EOK, "dnssec_keystore_open()");

	dnssec_list_t *keys = NULL;
	r = dnssec_keystore_list_keys(store, &keys);
	ok(r == DNSSEC_EOK && dnssec_list_size(keys) == 0, "dnssec_keystore_list_keys(), empty");
	dnssec_list_free_full(keys, NULL, NULL);

	// key manipulation

	static const int KEYS_COUNT = 3;
	static const key_parameters_t *KEYS[] = {
		&SAMPLE_RSA_KEY,
		&SAMPLE_ECDSA_KEY,
		&SAMPLE_DSA_KEY,
	};
	assert(KEYS_COUNT == sizeof(KEYS) / sizeof(*KEYS));

	for (int i = 0; i < KEYS_COUNT; i++) {
		test_algorithm(store, KEYS[i]);
	}

	test_key_listing(store, KEYS, KEYS_COUNT);

	r = dnssec_keystore_close(store);
	ok(r == DNSSEC_EOK, "dnssec_keystore_close()");
done:
	dnssec_keystore_deinit(store);
	dnssec_crypto_cleanup();
	token_cleanup();

	return 0;
}