这篇教程C++ tor_strdup函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中tor_strdup函数的典型用法代码示例。如果您正苦于以下问题:C++ tor_strdup函数的具体用法?C++ tor_strdup怎么用?C++ tor_strdup使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了tor_strdup函数的25个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: test_crypto_curve25519_persiststatic voidtest_crypto_curve25519_persist(void *arg){ curve25519_keypair_t keypair, keypair2; char *fname = tor_strdup(get_fname("curve25519_keypair")); char *tag = NULL; char *content = NULL; const char *cp; struct stat st; size_t taglen; (void)arg; tt_int_op(0,==,curve25519_keypair_generate(&keypair, 0)); tt_int_op(0,==,curve25519_keypair_write_to_file(&keypair, fname, "testing")); tt_int_op(0,==,curve25519_keypair_read_from_file(&keypair2, &tag, fname)); tt_str_op(tag,==,"testing"); tor_free(tag); test_memeq(keypair.pubkey.public_key, keypair2.pubkey.public_key, CURVE25519_PUBKEY_LEN); test_memeq(keypair.seckey.secret_key, keypair2.seckey.secret_key, CURVE25519_SECKEY_LEN); content = read_file_to_str(fname, RFTS_BIN, &st); tt_assert(content); taglen = strlen("== c25519v1: testing =="); tt_int_op(st.st_size, ==, 32+CURVE25519_PUBKEY_LEN+CURVE25519_SECKEY_LEN); tt_assert(fast_memeq(content, "== c25519v1: testing ==", taglen)); tt_assert(tor_mem_is_zero(content+taglen, 32-taglen)); cp = content + 32; test_memeq(keypair.seckey.secret_key, cp, CURVE25519_SECKEY_LEN); cp += CURVE25519_SECKEY_LEN; test_memeq(keypair.pubkey.public_key, cp, CURVE25519_SECKEY_LEN); tor_free(fname); fname = tor_strdup(get_fname("bogus_keypair")); tt_int_op(-1, ==, curve25519_keypair_read_from_file(&keypair2, &tag, fname)); tor_free(tag); content[69] ^= 0xff; tt_int_op(0, ==, write_bytes_to_file(fname, content, (size_t)st.st_size, 1)); tt_int_op(-1, ==, curve25519_keypair_read_from_file(&keypair2, &tag, fname)); done: tor_free(fname); tor_free(content); tor_free(tag);}
开发者ID:Lab414,项目名称:30May,代码行数:57,
示例2: test_ext_or_init_authstatic voidtest_ext_or_init_auth(void *arg){ or_options_t *options = get_options_mutable(); const char *fn; char *cp = NULL; struct stat st; char cookie0[32]; (void)arg; /* Check default filename location */ tor_free(options->DataDirectory); options->DataDirectory = tor_strdup("foo"); cp = get_ext_or_auth_cookie_file_name(); tt_str_op(cp, OP_EQ, "foo"PATH_SEPARATOR"extended_orport_auth_cookie"); tor_free(cp); /* Shouldn't be initialized already, or our tests will be a bit * meaningless */ ext_or_auth_cookie = tor_malloc_zero(32); tt_assert(tor_mem_is_zero((char*)ext_or_auth_cookie, 32)); /* Now make sure we use a temporary file */ fn = get_fname("ext_cookie_file"); options->ExtORPortCookieAuthFile = tor_strdup(fn); cp = get_ext_or_auth_cookie_file_name(); tt_str_op(cp, OP_EQ, fn); tor_free(cp); /* Test the initialization function with a broken write_bytes_to_file(). See if the problem is handled properly. */ MOCK(write_bytes_to_file, write_bytes_to_file_fail); tt_int_op(-1, OP_EQ, init_ext_or_cookie_authentication(1)); tt_int_op(ext_or_auth_cookie_is_set, OP_EQ, 0); UNMOCK(write_bytes_to_file); /* Now do the actual initialization. */ tt_int_op(0, OP_EQ, init_ext_or_cookie_authentication(1)); tt_int_op(ext_or_auth_cookie_is_set, OP_EQ, 1); cp = read_file_to_str(fn, RFTS_BIN, &st); tt_ptr_op(cp, OP_NE, NULL); tt_u64_op((uint64_t)st.st_size, OP_EQ, 64); tt_mem_op(cp,OP_EQ, "! Extended ORPort Auth Cookie !/x0a", 32); tt_mem_op(cp+32,OP_EQ, ext_or_auth_cookie, 32); memcpy(cookie0, ext_or_auth_cookie, 32); tt_assert(!tor_mem_is_zero((char*)ext_or_auth_cookie, 32)); /* Operation should be idempotent. */ tt_int_op(0, OP_EQ, init_ext_or_cookie_authentication(1)); tt_mem_op(cookie0,OP_EQ, ext_or_auth_cookie, 32); done: tor_free(cp); ext_orport_free_all();}
开发者ID:1234max,项目名称:tor,代码行数:55,
示例3: good_bridge_line_test/* Test helper function: Make sure that a bridge line gets parsed * properly. Also make sure that the resulting bridge_line_t structure * has its fields set correctly. */static voidgood_bridge_line_test(const char *string, const char *test_addrport, const char *test_digest, const char *test_transport, const smartlist_t *test_socks_args){ char *tmp = NULL; bridge_line_t *bridge_line = parse_bridge_line(string); test_assert(bridge_line); /* test addrport */ tmp = tor_strdup(fmt_addrport(&bridge_line->addr, bridge_line->port)); test_streq(test_addrport, tmp); tor_free(tmp); /* If we were asked to validate a digest, but we did not get a digest after parsing, we failed. */ if (test_digest && tor_digest_is_zero(bridge_line->digest)) test_assert(0); /* If we were not asked to validate a digest, and we got a digest after parsing, we failed again. */ if (!test_digest && !tor_digest_is_zero(bridge_line->digest)) test_assert(0); /* If we were asked to validate a digest, and we got a digest after parsing, make sure it's correct. */ if (test_digest) { tmp = tor_strdup(hex_str(bridge_line->digest, DIGEST_LEN)); tor_strlower(tmp); test_streq(test_digest, tmp); tor_free(tmp); } /* If we were asked to validate a transport name, make sure tha it matches with the transport name that was parsed. */ if (test_transport && !bridge_line->transport_name) test_assert(0); if (!test_transport && bridge_line->transport_name) test_assert(0); if (test_transport) test_streq(test_transport, bridge_line->transport_name); /* Validate the SOCKS argument smartlist. */ if (test_socks_args && !bridge_line->socks_args) test_assert(0); if (!test_socks_args && bridge_line->socks_args) test_assert(0); if (test_socks_args) test_assert(smartlist_strings_eq(test_socks_args, bridge_line->socks_args)); done: tor_free(tmp); bridge_line_free(bridge_line);}
开发者ID:BenGant,项目名称:tor,代码行数:58,
示例4: config_get_lines/** Helper: parse the config string and strdup into key/value * strings. Set *result to the list, or NULL if parsing the string * failed. Return 0 on success, -1 on failure. Warn and ignore any * misformatted lines. * * If <b>extended</b> is set, then treat keys beginning with / and with + as * indicating "clear" and "append" respectively. */intconfig_get_lines(const char *string, config_line_t **result, int extended){ config_line_t *list = NULL, **next; char *k, *v; const char *parse_err; next = &list; do { k = v = NULL; string = parse_config_line_from_str_verbose(string, &k, &v, &parse_err); if (!string) { log_warn(LD_CONFIG, "Error while parsing configuration: %s", parse_err?parse_err:"<unknown>"); config_free_lines(list); tor_free(k); tor_free(v); return -1; } if (k && v) { unsigned command = CONFIG_LINE_NORMAL; if (extended) { if (k[0] == '+') { char *k_new = tor_strdup(k+1); tor_free(k); k = k_new; command = CONFIG_LINE_APPEND; } else if (k[0] == '/') { char *k_new = tor_strdup(k+1); tor_free(k); k = k_new; tor_free(v); v = tor_strdup(""); command = CONFIG_LINE_CLEAR; } } /* This list can get long, so we keep a pointer to the end of it * rather than using config_line_append over and over and getting * n^2 performance. */ *next = tor_malloc_zero(sizeof(config_line_t)); (*next)->key = k; (*next)->value = v; (*next)->next = NULL; (*next)->command = command; next = &((*next)->next); } else { tor_free(k); tor_free(v); } } while (*string); *result = list; return 0;}
开发者ID:Archer-sys,项目名称:tor,代码行数:61,
示例5: test_conn_edge_ap_handshake_rewrite_and_attach_closes_conn_for_excluded_exitstatic voidtest_conn_edge_ap_handshake_rewrite_and_attach_closes_conn_for_excluded_exit(void *data){ entry_connection_t *conn = entry_connection_new(CONN_TYPE_AP, AF_INET); addressmap_init(); origin_circuit_t *circuit = NULL; crypt_path_t *path = NULL; (void) data; MOCK(get_options, get_options_mock); MOCK(connection_ap_handshake_rewrite, connection_ap_handshake_rewrite_mock); MOCK(connection_mark_unattached_ap_, connection_mark_unattached_ap_mock); MOCK(node_get_by_nickname, node_get_by_nickname_mock); init_rewrite_mock(); init_exit_node_mock(); init_mock_options(); rewrite_mock->should_close = 0; rewrite_mock->exit_source = ADDRMAPSRC_NONE; SET_SOCKS_ADDRESS(conn->socks_request, "http://www.wellformed.exit"); conn->socks_request->command = SOCKS_COMMAND_CONNECT; strlcpy(exit_node_mock->rs->nickname, "wellformed", MAX_NICKNAME_LEN+1); options_mock->AllowDotExit = 1; options_mock->StrictNodes = 0; options_mock->SafeLogging_ = SAFELOG_SCRUB_NONE; excluded_nodes = routerset_new(); smartlist_add(excluded_nodes->list, tor_strdup("wellformed")); strmap_set(excluded_nodes->names, tor_strdup("wellformed"), exit_node_mock); options_mock->ExcludeExitNodes = excluded_nodes; int prev_log = setup_capture_of_logs(LOG_INFO); int res = connection_ap_handshake_rewrite_and_attach(conn, circuit, path); tt_int_op(unattachment_reason_spy, OP_EQ, END_STREAM_REASON_TORPROTOCOL); tt_int_op(res, OP_EQ, -1); tt_str_op(mock_saved_log_at(-1), OP_EQ, "Excluded relay in exit address 'http://www.exit'. Refusing./n"); done: UNMOCK(get_options); UNMOCK(connection_ap_handshake_rewrite); UNMOCK(connection_mark_unattached_ap_); UNMOCK(node_get_by_nickname); destroy_rewrite_mock(); destroy_mock_options(); destroy_exit_node_mock(); tor_free(excluded_nodes); tor_free(circuit); tor_free(path); teardown_capture_of_logs(prev_log);}
开发者ID:twstrike,项目名称:tor,代码行数:54,
示例6: test_pt_get_transport_optionsstatic voidtest_pt_get_transport_options(void *arg){ char **execve_args; smartlist_t *transport_list = smartlist_new(); managed_proxy_t *mp; or_options_t *options = get_options_mutable(); char *opt_str = NULL; config_line_t *cl = NULL; (void)arg; execve_args = tor_malloc(sizeof(char*)*2); execve_args[0] = tor_strdup("cheeseshop"); execve_args[1] = NULL; mp = managed_proxy_create(transport_list, execve_args, 1); tt_ptr_op(mp, OP_NE, NULL); opt_str = get_transport_options_for_server_proxy(mp); tt_ptr_op(opt_str, OP_EQ, NULL); smartlist_add_strdup(mp->transports_to_launch, "gruyere"); smartlist_add_strdup(mp->transports_to_launch, "roquefort"); smartlist_add_strdup(mp->transports_to_launch, "stnectaire"); tt_assert(options); cl = tor_malloc_zero(sizeof(config_line_t)); cl->value = tor_strdup("gruyere melty=10 hardness=se;ven"); options->ServerTransportOptions = cl; cl = tor_malloc_zero(sizeof(config_line_t)); cl->value = tor_strdup("stnectaire melty=4 hardness=three"); cl->next = options->ServerTransportOptions; options->ServerTransportOptions = cl; cl = tor_malloc_zero(sizeof(config_line_t)); cl->value = tor_strdup("pepperjack melty=12 hardness=five"); cl->next = options->ServerTransportOptions; options->ServerTransportOptions = cl; opt_str = get_transport_options_for_server_proxy(mp); tt_str_op(opt_str, OP_EQ, "gruyere:melty=10;gruyere:hardness=se//;ven;" "stnectaire:melty=4;stnectaire:hardness=three"); done: tor_free(opt_str); config_free_lines(cl); managed_proxy_destroy(mp, 0); smartlist_free(transport_list);}
开发者ID:unixninja92,项目名称:Tor,代码行数:51,
示例7: dnsserv_launch_request/** Helper function: called whenever the client sends a resolve request to our * controller. We need to eventually answer the request <b>req</b>. * Returns 0 if the controller will be getting (or has gotten) an event in * response; -1 if we couldn't launch the request. */intdnsserv_launch_request(const char *name, int reverse){ entry_connection_t *entry_conn; edge_connection_t *conn; char *q_name; /* Make a new dummy AP connection, and attach the request to it. */ entry_conn = entry_connection_new(CONN_TYPE_AP, AF_INET); conn = ENTRY_TO_EDGE_CONN(entry_conn); conn->base_.state = AP_CONN_STATE_RESOLVE_WAIT; if (reverse) entry_conn->socks_request->command = SOCKS_COMMAND_RESOLVE_PTR; else entry_conn->socks_request->command = SOCKS_COMMAND_RESOLVE; conn->is_dns_request = 1; strlcpy(entry_conn->socks_request->address, name, sizeof(entry_conn->socks_request->address)); entry_conn->socks_request->listener_type = CONN_TYPE_CONTROL_LISTENER; entry_conn->original_dest_address = tor_strdup(name); entry_conn->session_group = SESSION_GROUP_CONTROL_RESOLVE; entry_conn->nym_epoch = get_signewnym_epoch(); entry_conn->isolation_flags = ISO_DEFAULT; if (connection_add(TO_CONN(conn))<0) { log_warn(LD_APP, "Couldn't register dummy connection for RESOLVE request"); connection_free(TO_CONN(conn)); return -1; } /* Now, unless a controller asked us to leave streams unattached, * throw the connection over to get rewritten (which will * answer it immediately if it's in the cache, or completely bogus, or * automapped), and then attached to a circuit. */ log_info(LD_APP, "Passing request for %s to rewrite_and_attach.", escaped_safe_str_client(name)); q_name = tor_strdup(name); /* q could be freed in rewrite_and_attach */ connection_ap_rewrite_and_attach_if_allowed(entry_conn, NULL, NULL); /* Now, the connection is marked if it was bad. */ log_info(LD_APP, "Passed request for %s to rewrite_and_attach_if_allowed.", escaped_safe_str_client(q_name)); tor_free(q_name); return 0;}
开发者ID:fatline,项目名称:Tor-Puzzles,代码行数:54,
示例8: test_conn_download_status_add_a_connectionstatic dir_connection_t *test_conn_download_status_add_a_connection(const char *resource){ dir_connection_t *conn = DOWNCAST(dir_connection_t, test_conn_get_connection( TEST_CONN_STATE, TEST_CONN_TYPE, TEST_CONN_RSRC_PURPOSE)); tt_assert(conn); assert_connection_ok(&conn->base_, time(NULL)); /* Replace the existing resource with the one we want */ if (resource) { if (conn->requested_resource) { tor_free(conn->requested_resource); } conn->requested_resource = tor_strdup(resource); assert_connection_ok(&conn->base_, time(NULL)); } return conn; done: test_conn_get_rsrc_teardown(NULL, conn); return NULL;}
开发者ID:isislovecruft,项目名称:tor,代码行数:27,
示例9: test_storagedir_emptystatic voidtest_storagedir_empty(void *arg){ char *dirname = tor_strdup(get_fname_rnd("store_dir")); storage_dir_t *d = NULL; (void)arg; tt_int_op(FN_NOENT, OP_EQ, file_status(dirname)); d = storage_dir_new(dirname, 10); tt_assert(d); tt_int_op(FN_DIR, OP_EQ, file_status(dirname)); tt_int_op(0, OP_EQ, smartlist_len(storage_dir_list(d))); tt_u64_op(0, OP_EQ, storage_dir_get_usage(d)); storage_dir_free(d); d = storage_dir_new(dirname, 10); tt_assert(d); tt_int_op(FN_DIR, OP_EQ, file_status(dirname)); tt_int_op(0, OP_EQ, smartlist_len(storage_dir_list(d))); tt_u64_op(0, OP_EQ, storage_dir_get_usage(d)); done: storage_dir_free(d); tor_free(dirname);}
开发者ID:jfrazelle,项目名称:tor,代码行数:30,
示例10: NSstatic voidNS(test_main)(void *arg){ routerset_t *set = NULL; int is_empty; (void)arg; is_empty = routerset_is_empty(set); tt_int_op(is_empty, !=, 0); set = routerset_new(); is_empty = routerset_is_empty(set); routerset_free(set); set = NULL; tt_int_op(is_empty, !=, 0); set = routerset_new(); smartlist_add(set->list, tor_strdup("{xx}")); is_empty = routerset_is_empty(set); routerset_free(set); set = NULL; tt_int_op(is_empty, ==, 0); done: ;}
开发者ID:caofangkun,项目名称:tor,代码行数:26,
示例11: test_storagedir_fullstatic voidtest_storagedir_full(void *arg){ (void)arg; char *dirname = tor_strdup(get_fname_rnd("store_dir")); storage_dir_t *d = NULL; const char str[] = "enemies of the peephole"; int r; d = storage_dir_new(dirname, 3); tt_assert(d); r = storage_dir_save_string_to_file(d, str, 1, NULL); tt_int_op(r, OP_EQ, 0); r = storage_dir_save_string_to_file(d, str, 1, NULL); tt_int_op(r, OP_EQ, 0); r = storage_dir_save_string_to_file(d, str, 1, NULL); tt_int_op(r, OP_EQ, 0); // These should fail! r = storage_dir_save_string_to_file(d, str, 1, NULL); tt_int_op(r, OP_EQ, -1); r = storage_dir_save_string_to_file(d, str, 1, NULL); tt_int_op(r, OP_EQ, -1); tt_u64_op(strlen(str) * 3, OP_EQ, storage_dir_get_usage(d)); done: tor_free(dirname); storage_dir_free(d);}
开发者ID:jfrazelle,项目名称:tor,代码行数:32,
示例12: test_config_write_to_data_subdirstatic voidtest_config_write_to_data_subdir(void *arg){ or_options_t* options = get_options_mutable(); char *datadir; char *cp = NULL; const char* subdir = "test_stats"; const char* fname = "test_file"; const char* str = "Lorem ipsum dolor sit amet, consetetur sadipscing/n" "elitr, sed diam nonumy eirmod/n" "tempor invidunt ut labore et dolore magna aliquyam/n" "erat, sed diam voluptua./n" "At vero eos et accusam et justo duo dolores et ea/n" "rebum. Stet clita kasd gubergren,/n" "no sea takimata sanctus est Lorem ipsum dolor sit amet./n" "Lorem ipsum dolor sit amet,/n" "consetetur sadipscing elitr, sed diam nonumy eirmod/n" "tempor invidunt ut labore et dolore/n" "magna aliquyam erat, sed diam voluptua. At vero eos et/n" "accusam et justo duo dolores et/n" "ea rebum. Stet clita kasd gubergren, no sea takimata/n" "sanctus est Lorem ipsum dolor sit amet."; char* filepath = NULL; (void)arg; tor_free(options->DataDirectory); datadir = options->DataDirectory = tor_strdup(get_fname("datadir-1")); filepath = get_datadir_fname2(subdir, fname);#if defined (_WIN32) tt_int_op(mkdir(options->DataDirectory), ==, 0);#else tt_int_op(mkdir(options->DataDirectory, 0700), ==, 0);#endif // Write attempt shoudl fail, if subdirectory doesn't exist. test_assert(write_to_data_subdir(subdir, fname, str, NULL)); test_assert(! check_or_create_data_subdir(subdir)); // Content of file after write attempt should be // equal to the original string. test_assert(!write_to_data_subdir(subdir, fname, str, NULL)); cp = read_file_to_str(filepath, 0, NULL); test_streq(cp, str); tor_free(cp); // A second write operation should overwrite the old content. test_assert(!write_to_data_subdir(subdir, fname, str, NULL)); cp = read_file_to_str(filepath, 0, NULL); test_streq(cp, str); tor_free(cp); done: (void) unlink(filepath); rmdir(options->DataDirectory); tor_free(datadir); tor_free(filepath); tor_free(cp);}
开发者ID:BenGant,项目名称:tor,代码行数:60,
示例13: NSstatic voidNS(test_main)(void *arg){ int retval; int made_pending; const tor_addr_t *resolved_addr; tor_addr_t addr_to_compare; (void)arg; tor_addr_parse(&addr_to_compare, "8.8.8.8"); or_circuit_t *on_circ = tor_malloc_zero(sizeof(or_circuit_t)); edge_connection_t *exitconn = create_valid_exitconn(); TO_CONN(exitconn)->address = tor_strdup("8.8.8.8"); retval = dns_resolve_impl(exitconn, 1, on_circ, NULL, &made_pending, NULL); resolved_addr = &(exitconn->base_.addr); tt_int_op(retval,OP_EQ,1); tt_assert(tor_addr_eq(resolved_addr, (const tor_addr_t *)&addr_to_compare)); tt_int_op(exitconn->address_ttl,OP_EQ,DEFAULT_DNS_TTL); done: tor_free(on_circ); tor_free(TO_CONN(exitconn)->address); tor_free(exitconn); return;}
开发者ID:Samdney,项目名称:tor,代码行数:33,
示例14: sandbox_add_addrinfointsandbox_add_addrinfo(const char* name){ int ret; struct addrinfo hints; sb_addr_info_t *el = NULL; el = tor_malloc(sizeof(sb_addr_info_t)); memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_INET; hints.ai_socktype = SOCK_STREAM; ret = getaddrinfo(name, NULL, &hints, &(el->info)); if (ret) { log_err(LD_BUG,"(Sandbox) failed to getaddrinfo"); ret = -2; tor_free(el); goto out; } el->name = tor_strdup(name); el->next = sb_addr_info; sb_addr_info = el; out: return ret;}
开发者ID:Arcoins,项目名称:Arcoin_Source,代码行数:28,
示例15: config_line_append/** Helper: allocate a new configuration option mapping 'key' to 'val', * append it to *<b>lst</b>. */voidconfig_line_append(config_line_t **lst, const char *key, const char *val){ config_line_t *newline; newline = tor_malloc_zero(sizeof(config_line_t)); newline->key = tor_strdup(key); newline->value = tor_strdup(val); newline->next = NULL; while (*lst) lst = &((*lst)->next); (*lst) = newline;}
开发者ID:Archer-sys,项目名称:tor,代码行数:18,
示例16: dir_common_generate_ri_from_rs/** Helper: Make a new routerinfo containing the right information for a * given vote_routerstatus_t. */routerinfo_t *dir_common_generate_ri_from_rs(const vote_routerstatus_t *vrs){ routerinfo_t *r; const routerstatus_t *rs = &vrs->status; static time_t published = 0; r = tor_malloc_zero(sizeof(routerinfo_t)); r->cert_expiration_time = TIME_MAX; memcpy(r->cache_info.identity_digest, rs->identity_digest, DIGEST_LEN); memcpy(r->cache_info.signed_descriptor_digest, rs->descriptor_digest, DIGEST_LEN); r->cache_info.do_not_cache = 1; r->cache_info.routerlist_index = -1; r->cache_info.signed_descriptor_body = tor_strdup("123456789012345678901234567890123"); r->cache_info.signed_descriptor_len = strlen(r->cache_info.signed_descriptor_body); r->exit_policy = smartlist_new(); r->cache_info.published_on = ++published + time(NULL); if (rs->has_bandwidth) { /* * Multiply by 1000 because the routerinfo_t and the routerstatus_t * seem to use different units (*sigh*) and because we seem stuck on * icky and perverse decimal kilobytes (*double sigh*) - see * router_get_advertised_bandwidth_capped() of routerlist.c and * routerstatus_format_entry() of dirserv.c. */ r->bandwidthrate = rs->bandwidth_kb * 1000; r->bandwidthcapacity = rs->bandwidth_kb * 1000; } return r;}
开发者ID:Archer-sys,项目名称:tor,代码行数:35,
示例17: cache_dir_desc_new/* Create a new directory cache descriptor object from a encoded descriptor. * On success, return the heap-allocated cache object, otherwise return NULL if * we can't decode the descriptor. */static hs_cache_dir_descriptor_t *cache_dir_desc_new(const char *desc){ hs_cache_dir_descriptor_t *dir_desc; tor_assert(desc); dir_desc = tor_malloc_zero(sizeof(hs_cache_dir_descriptor_t)); dir_desc->plaintext_data = tor_malloc_zero(sizeof(hs_desc_plaintext_data_t)); dir_desc->encoded_desc = tor_strdup(desc); if (hs_desc_decode_plaintext(desc, dir_desc->plaintext_data) < 0) { log_debug(LD_DIR, "Unable to decode descriptor. Rejecting."); goto err; } /* The blinded pubkey is the indexed key. */ dir_desc->key = dir_desc->plaintext_data->blinded_pubkey.pubkey; dir_desc->created_ts = time(NULL); return dir_desc; err: cache_dir_desc_free(dir_desc); return NULL;}
开发者ID:jfrazelle,项目名称:tor,代码行数:29,
示例18: test_md_cache_brokenstatic voidtest_md_cache_broken(void *data){ or_options_t *options; char *fn=NULL; microdesc_cache_t *mc = NULL; (void)data; options = get_options_mutable(); tt_assert(options); tor_free(options->CacheDirectory); options->CacheDirectory = tor_strdup(get_fname("md_datadir_test2"));#ifdef _WIN32 tt_int_op(0, OP_EQ, mkdir(options->CacheDirectory));#else tt_int_op(0, OP_EQ, mkdir(options->CacheDirectory, 0700));#endif tor_asprintf(&fn, "%s"PATH_SEPARATOR"cached-microdescs", options->CacheDirectory); write_str_to_file(fn, truncated_md, 1); mc = get_microdesc_cache(); tt_assert(mc); done: if (options) tor_free(options->CacheDirectory); tor_free(fn); microdesc_free_all();}
开发者ID:Samdney,项目名称:tor,代码行数:34,
示例19: test_config_fix_my_family// Tests if an options with MyFamily fingerprints missing '$' normalises// them correctly and also ensure it also works with multiple fingerprintsstatic voidtest_config_fix_my_family(void *arg){ char *err = NULL; const char *family = "$1111111111111111111111111111111111111111, " "1111111111111111111111111111111111111112, " "$1111111111111111111111111111111111111113"; or_options_t* options = options_new(); or_options_t* defaults = options_new(); (void) arg; options_init(options); options_init(defaults); options->MyFamily = tor_strdup(family); options_validate(NULL, options, defaults, 0, &err) ; if (err != NULL) { TT_FAIL(("options_validate failed: %s", err)); } test_streq(options->MyFamily, "$1111111111111111111111111111111111111111, " "$1111111111111111111111111111111111111112, " "$1111111111111111111111111111111111111113"); done: if (err != NULL) { tor_free(err); } or_options_free(options); or_options_free(defaults);}
开发者ID:BenGant,项目名称:tor,代码行数:36,
示例20: dir_common_construct_vote_2/** See dir_common_construct_vote_1. * Produces a vote with slightly different values. */intdir_common_construct_vote_2(networkstatus_t **vote, authority_cert_t *cert, crypto_pk_t *sign_skey, vote_routerstatus_t * (*vrs_gen)(int idx, time_t now), networkstatus_t **vote_out, int *n_vrs, time_t now, int clear_rl){ networkstatus_voter_info_t *voter; dir_common_setup_vote(vote, now); (*vote)->type = NS_TYPE_VOTE; (*vote)->published += 1; (*vote)->valid_after = now+1000; (*vote)->fresh_until = now+3005; (*vote)->valid_until = now+3000; (*vote)->vote_seconds = 100; (*vote)->dist_seconds = 300; smartlist_split_string((*vote)->supported_methods, "1 2 3", NULL, 0, -1); smartlist_split_string((*vote)->known_flags, "Authority Exit Fast Guard MadeOfCheese MadeOfTin " "Running Stable V2Dir Valid", 0, SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0); voter = tor_malloc_zero(sizeof(networkstatus_voter_info_t)); voter->nickname = tor_strdup("Voter2"); voter->address = tor_strdup("2.3.4.5"); voter->addr = 0x02030405; voter->dir_port = 80; voter->or_port = 9000; voter->contact = tor_strdup("[email C++ torture_assert函数代码示例 C++ tor_malloc_zero函数代码示例
|