本文整理汇总了C++中smartlist_add函数的典型用法代码示例。如果您正苦于以下问题:C++ smartlist_add函数的具体用法?C++ smartlist_add怎么用?C++ smartlist_add使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了smartlist_add函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: test_container_smartlist_sort_ptrs
static void
test_container_smartlist_sort_ptrs(void *arg)
{
(void)arg;
int array[10];
int *arrayptrs[11];
smartlist_t *sl = smartlist_new();
unsigned i=0, j;
for (j = 0; j < ARRAY_LENGTH(array); ++j) {
smartlist_add(sl, &array[j]);
arrayptrs[i++] = &array[j];
if (j == 5) {
smartlist_add(sl, &array[j]);
arrayptrs[i++] = &array[j];
}
}
for (i = 0; i < 10; ++i) {
smartlist_shuffle(sl);
smartlist_sort_pointers(sl);
for (j = 0; j < ARRAY_LENGTH(arrayptrs); ++j) {
tt_ptr_op(smartlist_get(sl, j), ==, arrayptrs[j]);
}
}
done:
smartlist_free(sl);
}
开发者ID:1234max,项目名称:tor,代码行数:29,代码来源:test_containers.c
示例2: descbr_get_digests_mock
static smartlist_t *
descbr_get_digests_mock(void)
{
char digest[DIGEST_LEN], *tmp;
int len;
smartlist_t *list = NULL;
if (!disable_descbr) {
/* Just pretend we have only the two hard-coded digests listed above */
list = smartlist_new();
len = base16_decode(digest, DIGEST_LEN,
descbr_digest_1_str, strlen(descbr_digest_1_str));
tt_int_op(len, OP_EQ, DIGEST_LEN);
tmp = tor_malloc(DIGEST_LEN);
memcpy(tmp, digest, DIGEST_LEN);
smartlist_add(list, tmp);
len = base16_decode(digest, DIGEST_LEN,
descbr_digest_2_str, strlen(descbr_digest_2_str));
tt_int_op(len, OP_EQ, DIGEST_LEN);
tmp = tor_malloc(DIGEST_LEN);
memcpy(tmp, digest, DIGEST_LEN);
smartlist_add(list, tmp);
}
done:
return list;
}
开发者ID:francois-wellenreiter,项目名称:tor,代码行数:27,代码来源:test_controller.c
示例3: geoip_add_entry
/** Add an entry to the GeoIP table, mapping all IPs between <b>low</b> and
* <b>high</b>, inclusive, to the 2-letter country code <b>country</b>.
*/
static void
geoip_add_entry(uint32_t low, uint32_t high, const char *country)
{
intptr_t idx;
geoip_entry_t *ent;
void *idxplus1_;
if (high < low)
return;
idxplus1_ = strmap_get_lc(country_idxplus1_by_lc_code, country);
if (!idxplus1_) {
geoip_country_t *c = tor_malloc_zero(sizeof(geoip_country_t));
strlcpy(c->countrycode, country, sizeof(c->countrycode));
tor_strlower(c->countrycode);
smartlist_add(geoip_countries, c);
idx = smartlist_len(geoip_countries) - 1;
strmap_set_lc(country_idxplus1_by_lc_code, country, (void*)(idx+1));
} else {
idx = ((uintptr_t)idxplus1_)-1;
}
{
geoip_country_t *c = smartlist_get(geoip_countries, idx);
tor_assert(!strcasecmp(c->countrycode, country));
}
ent = tor_malloc_zero(sizeof(geoip_entry_t));
ent->ip_low = low;
ent->ip_high = high;
ent->country = idx;
smartlist_add(geoip_entries, ent);
}
开发者ID:fatline,项目名称:Tor-Puzzles,代码行数:35,代码来源:geoip.c
示例4: crypto_write_tagged_contents_to_file
/** Write the <b>datalen</b> bytes from <b>data</b> to the file named
* <b>fname</b> in the tagged-data format. This format contains a
* 32-byte header, followed by the data itself. The header is the
* NUL-padded string "== <b>typestring</b>: <b>tag</b> ==". The length
* of <b>typestring</b> and <b>tag</b> must therefore be no more than
* 24.
**/
int
crypto_write_tagged_contents_to_file(const char *fname,
const char *typestring,
const char *tag,
const uint8_t *data,
size_t datalen)
{
char header[32];
smartlist_t *chunks = smartlist_new();
sized_chunk_t ch0, ch1;
int r = -1;
memset(header, 0, sizeof(header));
if (tor_snprintf(header, sizeof(header),
"== %s: %s ==", typestring, tag) < 0)
goto end;
ch0.bytes = header;
ch0.len = 32;
ch1.bytes = (const char*) data;
ch1.len = datalen;
smartlist_add(chunks, &ch0);
smartlist_add(chunks, &ch1);
r = write_chunks_to_file(fname, chunks, 1, 0);
end:
smartlist_free(chunks);
return r;
}
开发者ID:1234max,项目名称:tor,代码行数:36,代码来源:crypto_format.c
示例5: cert_dl_status_auth_ids_mock
static smartlist_t *
cert_dl_status_auth_ids_mock(void)
{
char digest[DIGEST_LEN], *tmp;
int len;
smartlist_t *list = NULL;
/* Just pretend we have only the two hard-coded digests listed above */
list = smartlist_new();
len = base16_decode(digest, DIGEST_LEN,
auth_id_digest_1_str, strlen(auth_id_digest_1_str));
tt_int_op(len, OP_EQ, DIGEST_LEN);
tmp = tor_malloc(DIGEST_LEN);
memcpy(tmp, digest, DIGEST_LEN);
smartlist_add(list, tmp);
len = base16_decode(digest, DIGEST_LEN,
auth_id_digest_2_str, strlen(auth_id_digest_2_str));
tt_int_op(len, OP_EQ, DIGEST_LEN);
tmp = tor_malloc(DIGEST_LEN);
memcpy(tmp, digest, DIGEST_LEN);
smartlist_add(list, tmp);
done:
return list;
}
开发者ID:francois-wellenreiter,项目名称:tor,代码行数:25,代码来源:test_controller.c
示例6: test_container_smartlist_digests
/** Run unit tests for smartlist-of-digests functions. */
static void
test_container_smartlist_digests(void)
{
smartlist_t *sl = smartlist_new();
/* contains_digest */
smartlist_add(sl, tor_memdup("AAAAAAAAAAAAAAAAAAAA", DIGEST_LEN));
smartlist_add(sl, tor_memdup("\00090AAB2AAAAaasdAAAAA", DIGEST_LEN));
smartlist_add(sl, tor_memdup("\00090AAB2AAAAaasdAAAAA", DIGEST_LEN));
test_eq(0, smartlist_contains_digest(NULL, "AAAAAAAAAAAAAAAAAAAA"));
test_assert(smartlist_contains_digest(sl, "AAAAAAAAAAAAAAAAAAAA"));
test_assert(smartlist_contains_digest(sl, "\00090AAB2AAAAaasdAAAAA"));
test_eq(0, smartlist_contains_digest(sl, "\00090AAB2AAABaasdAAAAA"));
/* sort digests */
smartlist_sort_digests(sl);
test_memeq(smartlist_get(sl, 0), "\00090AAB2AAAAaasdAAAAA", DIGEST_LEN);
test_memeq(smartlist_get(sl, 1), "\00090AAB2AAAAaasdAAAAA", DIGEST_LEN);
test_memeq(smartlist_get(sl, 2), "AAAAAAAAAAAAAAAAAAAA", DIGEST_LEN);
test_eq(3, smartlist_len(sl));
/* uniq_digests */
smartlist_uniq_digests(sl);
test_eq(2, smartlist_len(sl));
test_memeq(smartlist_get(sl, 0), "\00090AAB2AAAAaasdAAAAA", DIGEST_LEN);
test_memeq(smartlist_get(sl, 1), "AAAAAAAAAAAAAAAAAAAA", DIGEST_LEN);
done:
SMARTLIST_FOREACH(sl, char *, cp, tor_free(cp));
smartlist_free(sl);
}
开发者ID:Lab414,项目名称:30May,代码行数:32,代码来源:test_containers.c
示例7: test_container_smartlist_digests
/** Run unit tests for smartlist-of-digests functions. */
static void
test_container_smartlist_digests(void *unused)
{
smartlist_t *sl = smartlist_create();
/* digest_isin. */
smartlist_add(sl, xmemdup("AAAAAAAAAAAAAAAAAAAA", SHA256_LENGTH));
smartlist_add(sl, xmemdup("\00090AAB2AAAAaasdAAAAA", SHA256_LENGTH));
smartlist_add(sl, xmemdup("\00090AAB2AAAAaasdAAAAA", SHA256_LENGTH));
tt_int_op(smartlist_digest_isin(NULL, "AAAAAAAAAAAAAAAAAAAA"), ==, 0);
tt_assert(smartlist_digest_isin(sl, "AAAAAAAAAAAAAAAAAAAA"));
tt_assert(smartlist_digest_isin(sl, "\00090AAB2AAAAaasdAAAAA"));
tt_int_op(smartlist_digest_isin(sl, "\00090AAB2AAABaasdAAAAA"), ==, 0);
/* sort digests */
smartlist_sort_digests(sl);
tt_mem_op(smartlist_get(sl, 0), ==, "\00090AAB2AAAAaasdAAAAA", SHA256_LENGTH);
tt_mem_op(smartlist_get(sl, 1), ==, "\00090AAB2AAAAaasdAAAAA", SHA256_LENGTH);
tt_mem_op(smartlist_get(sl, 2), ==, "AAAAAAAAAAAAAAAAAAAA", SHA256_LENGTH);
tt_int_op(smartlist_len(sl), ==, 3);
/* uniq_digests */
smartlist_uniq_digests(sl);
tt_int_op(smartlist_len(sl), ==, 2);
tt_mem_op(smartlist_get(sl, 0), ==, "\00090AAB2AAAAaasdAAAAA", SHA256_LENGTH);
tt_mem_op(smartlist_get(sl, 1), ==, "AAAAAAAAAAAAAAAAAAAA", SHA256_LENGTH);
end:
SMARTLIST_FOREACH(sl, char *, cp, free(cp));
smartlist_free(sl);
}
开发者ID:FredericJacobs,项目名称:obfsproxy-c,代码行数:32,代码来源:unittest_container.c
示例8: get_ns_str_from_sr_values
/* Given the previous SRV and the current SRV, return a heap allocated
* string with their data that could be put in a vote or a consensus. Caller
* must free the returned string. Return NULL if no SRVs were provided. */
static char *
get_ns_str_from_sr_values(const sr_srv_t *prev_srv, const sr_srv_t *cur_srv)
{
smartlist_t *chunks = NULL;
char *srv_str;
if (!prev_srv && !cur_srv) {
return NULL;
}
chunks = smartlist_new();
if (prev_srv) {
char *srv_line = srv_to_ns_string(prev_srv, previous_srv_str);
smartlist_add(chunks, srv_line);
}
if (cur_srv) {
char *srv_line = srv_to_ns_string(cur_srv, current_srv_str);
smartlist_add(chunks, srv_line);
}
/* Join the line(s) here in one string to return. */
srv_str = smartlist_join_strings(chunks, "", 0, NULL);
SMARTLIST_FOREACH(chunks, char *, s, tor_free(s));
smartlist_free(chunks);
return srv_str;
}
开发者ID:Samdney,项目名称:tor,代码行数:32,代码来源:shared_random.c
示例9: NS
static void
NS(test_main)(void *arg)
{
/* Choose origin_circuit_t wlog. */
origin_circuit_t *mock_circuit1, *mock_circuit2;
int expected_circuits = 2, actual_circuits;
(void)arg;
mock_circuit1 = tor_malloc_zero(sizeof(origin_circuit_t));
mock_circuit2 = tor_malloc_zero(sizeof(origin_circuit_t));
mock_global_circuitlist = smartlist_new();
smartlist_add(mock_global_circuitlist, TO_CIRCUIT(mock_circuit1));
smartlist_add(mock_global_circuitlist, TO_CIRCUIT(mock_circuit2));
NS_MOCK(circuit_get_global_list);
actual_circuits = count_circuits();
tt_assert(expected_circuits == actual_circuits);
done:
tor_free(mock_circuit1);
tor_free(mock_circuit2);
smartlist_free(mock_global_circuitlist);
mock_global_circuitlist = NULL;
NS_UNMOCK(circuit_get_global_list);
}
开发者ID:BwRy,项目名称:Astoria,代码行数:28,代码来源:test_status.c
示例10: NS
static void
NS(test_main)(void *arg)
{
routerset_t *set = routerset_new();
smartlist_t *out = smartlist_new();
int r;
(void)arg;
NS_MOCK(nodelist_get_list);
smartlist_add(set->country_names, tor_strdup("{xx}"));
NS(mock_smartlist) = smartlist_new();
NS(mock_node).is_running = 0;
smartlist_add(NS(mock_smartlist), (void *)&NS(mock_node));
routerset_get_all_nodes(out, set, NULL, 1);
r = smartlist_len(out);
routerset_free(set);
smartlist_free(out);
smartlist_free(NS(mock_smartlist));
tt_int_op(r, ==, 0);
tt_int_op(CALLED(nodelist_get_list), ==, 1);
done:
;
}
开发者ID:caofangkun,项目名称:tor,代码行数:27,代码来源:test_routerset.c
示例11: policy_expand_private
/** Replace all "private" entries in *<b>policy</b> with their expanded
* equivalents. */
void
policy_expand_private(smartlist_t **policy)
{
uint16_t port_min, port_max;
int i;
smartlist_t *tmp;
if (!*policy) /*XXXX disallow NULL policies? */
return;
tmp = smartlist_create();
SMARTLIST_FOREACH(*policy, addr_policy_t *, p,
{
if (! p->is_private) {
smartlist_add(tmp, p);
continue;
}
for (i = 0; private_nets[i]; ++i) {
addr_policy_t policy;
memcpy(&policy, p, sizeof(addr_policy_t));
policy.is_private = 0;
policy.is_canonical = 0;
if (tor_addr_parse_mask_ports(private_nets[i], &policy.addr,
&policy.maskbits, &port_min, &port_max)<0) {
tor_assert(0);
}
smartlist_add(tmp, addr_policy_get_canonical_entry(&policy));
}
addr_policy_free(p);
});
开发者ID:madnessw,项目名称:thesnow,代码行数:34,代码来源:policies.c
示例12: test_container_smartlist_basic
/** Run unit tests for basic dynamic-sized array functionality. */
static void
test_container_smartlist_basic(void *arg)
{
smartlist_t *sl;
char *v0 = tor_strdup("v0");
char *v1 = tor_strdup("v1");
char *v2 = tor_strdup("v2");
char *v3 = tor_strdup("v3");
char *v4 = tor_strdup("v4");
char *v22 = tor_strdup("v22");
char *v99 = tor_strdup("v99");
char *v555 = tor_strdup("v555");
/* XXXX test sort_digests, uniq_strings, uniq_digests */
/* Test smartlist add, del_keeporder, insert, get. */
(void)arg;
sl = smartlist_new();
smartlist_add(sl, v1);
smartlist_add(sl, v2);
smartlist_add(sl, v3);
smartlist_add(sl, v4);
smartlist_del_keeporder(sl, 1);
smartlist_insert(sl, 1, v22);
smartlist_insert(sl, 0, v0);
smartlist_insert(sl, 5, v555);
tt_ptr_op(v0,OP_EQ, smartlist_get(sl,0));
tt_ptr_op(v1,OP_EQ, smartlist_get(sl,1));
tt_ptr_op(v22,OP_EQ, smartlist_get(sl,2));
tt_ptr_op(v3,OP_EQ, smartlist_get(sl,3));
tt_ptr_op(v4,OP_EQ, smartlist_get(sl,4));
tt_ptr_op(v555,OP_EQ, smartlist_get(sl,5));
/* Try deleting in the middle. */
smartlist_del(sl, 1);
tt_ptr_op(v555,OP_EQ, smartlist_get(sl, 1));
/* Try deleting at the end. */
smartlist_del(sl, 4);
tt_int_op(4,OP_EQ, smartlist_len(sl));
/* test isin. */
tt_assert(smartlist_contains(sl, v3));
tt_assert(!smartlist_contains(sl, v99));
done:
smartlist_free(sl);
tor_free(v0);
tor_free(v1);
tor_free(v2);
tor_free(v3);
tor_free(v4);
tor_free(v22);
tor_free(v99);
tor_free(v555);
}
开发者ID:1234max,项目名称:tor,代码行数:55,代码来源:test_containers.c
示例13: test_oos_kill_conn_list
static void
test_oos_kill_conn_list(void *arg)
{
connection_t *c1, *c2;
or_connection_t *or_c1 = NULL;
dir_connection_t *dir_c2 = NULL;
smartlist_t *l = NULL;
(void)arg;
/* Set up mocks */
mark_calls = 0;
MOCK(connection_mark_for_close_internal_, mark_for_close_oos_mock);
cfe_calls = 0;
MOCK(connection_or_close_for_error, close_for_error_mock);
/* Make fake conns */
or_c1 = tor_malloc_zero(sizeof(*or_c1));
or_c1->base_.magic = OR_CONNECTION_MAGIC;
or_c1->base_.type = CONN_TYPE_OR;
c1 = TO_CONN(or_c1);
dir_c2 = tor_malloc_zero(sizeof(*dir_c2));
dir_c2->base_.magic = DIR_CONNECTION_MAGIC;
dir_c2->base_.type = CONN_TYPE_DIR;
dir_c2->base_.state = DIR_CONN_STATE_MIN_;
dir_c2->base_.purpose = DIR_PURPOSE_MIN_;
c2 = TO_CONN(dir_c2);
tt_assert(c1 != NULL);
tt_assert(c2 != NULL);
/* Make list */
l = smartlist_new();
smartlist_add(l, c1);
smartlist_add(l, c2);
/* Run kill_conn_list_for_oos() */
kill_conn_list_for_oos(l);
/* Check call counters */
tt_int_op(mark_calls, OP_EQ, 1);
tt_int_op(cfe_calls, OP_EQ, 1);
done:
UNMOCK(connection_or_close_for_error);
UNMOCK(connection_mark_for_close_internal_);
if (l) smartlist_free(l);
tor_free(or_c1);
tor_free(dir_c2);
return;
}
开发者ID:francois-wellenreiter,项目名称:tor,代码行数:53,代码来源:test_oos.c
示例14: cert_dl_status_sks_for_auth_id_mock
static smartlist_t *
cert_dl_status_sks_for_auth_id_mock(const char *digest)
{
smartlist_t *list = NULL;
char sk[DIGEST_LEN];
char digest_str[HEX_DIGEST_LEN+1];
char *tmp;
int len;
tt_assert(digest != NULL);
base16_encode(digest_str, HEX_DIGEST_LEN + 1,
digest, DIGEST_LEN);
digest_str[HEX_DIGEST_LEN] = '\0';
/*
* Build a list of two hard-coded digests, depending on what we
* were just passed.
*/
if (strcmp(digest_str, auth_id_digest_1_str) == 0) {
list = smartlist_new();
len = base16_decode(sk, DIGEST_LEN,
auth_1_sk_1_str, strlen(auth_1_sk_1_str));
tt_int_op(len, OP_EQ, DIGEST_LEN);
tmp = tor_malloc(DIGEST_LEN);
memcpy(tmp, sk, DIGEST_LEN);
smartlist_add(list, tmp);
len = base16_decode(sk, DIGEST_LEN,
auth_1_sk_2_str, strlen(auth_1_sk_2_str));
tt_int_op(len, OP_EQ, DIGEST_LEN);
tmp = tor_malloc(DIGEST_LEN);
memcpy(tmp, sk, DIGEST_LEN);
smartlist_add(list, tmp);
} else if (strcmp(digest_str, auth_id_digest_2_str) == 0) {
list = smartlist_new();
len = base16_decode(sk, DIGEST_LEN,
auth_2_sk_1_str, strlen(auth_2_sk_1_str));
tt_int_op(len, OP_EQ, DIGEST_LEN);
tmp = tor_malloc(DIGEST_LEN);
memcpy(tmp, sk, DIGEST_LEN);
smartlist_add(list, tmp);
len = base16_decode(sk, DIGEST_LEN,
auth_2_sk_2_str, strlen(auth_2_sk_2_str));
tt_int_op(len, OP_EQ, DIGEST_LEN);
tmp = tor_malloc(DIGEST_LEN);
memcpy(tmp, sk, DIGEST_LEN);
smartlist_add(list, tmp);
}
done:
return list;
}
开发者ID:francois-wellenreiter,项目名称:tor,代码行数:51,代码来源:test_controller.c
示例15: test_pt_get_transport_options
static void
test_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(mp->transports_to_launch, tor_strdup("gruyere"));
smartlist_add(mp->transports_to_launch, tor_strdup("roquefort"));
smartlist_add(mp->transports_to_launch, tor_strdup("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:Archer-sys,项目名称:tor,代码行数:51,代码来源:test_pt.c
示例16: routerset_parse
/** Parse the string <b>s</b> to create a set of routerset entries, and add
* them to <b>target</b>. In log messages, refer to the string as
* <b>description</b>. Return 0 on success, -1 on failure.
*
* Three kinds of elements are allowed in routersets: nicknames, IP address
* patterns, and fingerprints. They may be surrounded by optional space, and
* must be separated by commas.
*/
int
routerset_parse(routerset_t *target, const char *s, const char *description)
{
int r = 0;
int added_countries = 0;
char *countryname;
smartlist_t *list = smartlist_new();
int malformed_list;
smartlist_split_string(list, s, ",",
SPLIT_SKIP_SPACE | SPLIT_IGNORE_BLANK, 0);
SMARTLIST_FOREACH_BEGIN(list, char *, nick) {
addr_policy_t *p;
/* if it doesn't pass our validation, assume it's malformed */
malformed_list = 1;
if (is_legal_hexdigest(nick)) {
char d[DIGEST_LEN];
if (*nick == '$')
++nick;
log_debug(LD_CONFIG, "Adding identity %s to %s", nick, description);
base16_decode(d, sizeof(d), nick, HEX_DIGEST_LEN);
digestmap_set(target->digests, d, (void*)1);
} else if (is_legal_nickname(nick)) {
log_debug(LD_CONFIG, "Adding nickname %s to %s", nick, description);
strmap_set_lc(target->names, nick, (void*)1);
} else if ((countryname = routerset_get_countryname(nick)) != NULL) {
log_debug(LD_CONFIG, "Adding country %s to %s", nick,
description);
smartlist_add(target->country_names, countryname);
added_countries = 1;
} else if ((strchr(nick,'.') || strchr(nick, ':') || strchr(nick, '*'))
&& (p = router_parse_addr_policy_item_from_string(
nick, ADDR_POLICY_REJECT,
&malformed_list))) {
/* IPv4 addresses contain '.', IPv6 addresses contain ':',
* and wildcard addresses contain '*'. */
log_debug(LD_CONFIG, "Adding address %s to %s", nick, description);
smartlist_add(target->policies, p);
} else if (malformed_list) {
log_warn(LD_CONFIG, "Entry '%s' in %s is malformed. Discarding entire"
" list.", nick, description);
r = -1;
tor_free(nick);
SMARTLIST_DEL_CURRENT(list, nick);
} else {
log_notice(LD_CONFIG, "Entry '%s' in %s is ignored. Using the"
" remainder of the list.", nick, description);
tor_free(nick);
SMARTLIST_DEL_CURRENT(list, nick);
}
} SMARTLIST_FOREACH_END(nick);
开发者ID:Samdney,项目名称:tor,代码行数:58,代码来源:routerset.c
示例17: circuit_get_all_pending_on_or_conn
/** Append to <b>out</b> all circuits in state OR_WAIT waiting for
* the given connection. */
void
circuit_get_all_pending_on_or_conn(smartlist_t *out, or_connection_t *or_conn)
{
tor_assert(out);
tor_assert(or_conn);
if (!circuits_pending_or_conns)
return;
SMARTLIST_FOREACH_BEGIN(circuits_pending_or_conns, circuit_t *, circ) {
if (circ->marked_for_close)
continue;
if (!circ->n_hop)
continue;
tor_assert(circ->state == CIRCUIT_STATE_OR_WAIT);
if (tor_digest_is_zero(circ->n_hop->identity_digest)) {
/* Look at addr/port. This is an unkeyed connection. */
if (!tor_addr_eq(&circ->n_hop->addr, &or_conn->_base.addr) ||
circ->n_hop->port != or_conn->_base.port)
continue;
} else {
/* We expected a key. See if it's the right one. */
if (memcmp(or_conn->identity_digest,
circ->n_hop->identity_digest, DIGEST_LEN))
continue;
}
smartlist_add(out, circ);
} SMARTLIST_FOREACH_END(circ);
}
开发者ID:kitsune-dsu,项目名称:kitsune-tor,代码行数:31,代码来源:circuitlist.c
示例18: decode_hashed_passwords
/** Decode the hashed, base64'd passwords stored in <b>passwords</b>.
* Return a smartlist of acceptable passwords (unterminated strings of
* length S2K_RFC2440_SPECIFIER_LEN+DIGEST_LEN) on success, or NULL on
* failure.
*/
smartlist_t *
decode_hashed_passwords(config_line_t *passwords)
{
char decoded[64];
config_line_t *cl;
smartlist_t *sl = smartlist_new();
tor_assert(passwords);
for (cl = passwords; cl; cl = cl->next) {
const char *hashed = cl->value;
if (!strcmpstart(hashed, "16:")) {
if (base16_decode(decoded, sizeof(decoded), hashed+3, strlen(hashed+3))
!= S2K_RFC2440_SPECIFIER_LEN + DIGEST_LEN
|| strlen(hashed+3) != (S2K_RFC2440_SPECIFIER_LEN+DIGEST_LEN)*2) {
goto err;
}
} else {
if (base64_decode(decoded, sizeof(decoded), hashed, strlen(hashed))
!= S2K_RFC2440_SPECIFIER_LEN+DIGEST_LEN) {
goto err;
}
}
smartlist_add(sl,
tor_memdup(decoded, S2K_RFC2440_SPECIFIER_LEN+DIGEST_LEN));
}
return sl;
err:
SMARTLIST_FOREACH(sl, char*, cp, tor_free(cp));
smartlist_free(sl);
return NULL;
}
开发者ID:nmathewson,项目名称:Tor,代码行数:40,代码来源:control_auth.c
示例19: test_routerlist_initiate_descriptor_downloads
static void
test_routerlist_initiate_descriptor_downloads(void *arg)
{
const char *prose = "unhurried and wise, we perceive.";
smartlist_t *digests = smartlist_new();
(void)arg;
for (int i = 0; i < 20; i++) {
smartlist_add(digests, (char*)prose);
}
MOCK(directory_get_from_dirserver, mock_get_from_dirserver);
initiate_descriptor_downloads(NULL, DIR_PURPOSE_FETCH_MICRODESC,
digests, 3, 7, 0);
UNMOCK(directory_get_from_dirserver);
tt_str_op(output, OP_EQ, "d/"
"dW5odXJyaWVkIGFuZCB3aXNlLCB3ZSBwZXJjZWl2ZS4-"
"dW5odXJyaWVkIGFuZCB3aXNlLCB3ZSBwZXJjZWl2ZS4-"
"dW5odXJyaWVkIGFuZCB3aXNlLCB3ZSBwZXJjZWl2ZS4-"
"dW5odXJyaWVkIGFuZCB3aXNlLCB3ZSBwZXJjZWl2ZS4"
".z");
done:
smartlist_free(digests);
}
开发者ID:BwRy,项目名称:Astoria,代码行数:26,代码来源:test_routerlist.c
示例20: test_routerlist_launch_descriptor_downloads
static void
test_routerlist_launch_descriptor_downloads(void *arg)
{
smartlist_t *downloadable = smartlist_new();
time_t now = time(NULL);
char *cp;
(void)arg;
for (int i = 0; i < 100; i++) {
cp = tor_malloc(DIGEST256_LEN);
tt_assert(cp);
crypto_rand(cp, DIGEST256_LEN);
smartlist_add(downloadable, cp);
}
MOCK(initiate_descriptor_downloads, mock_initiate_descriptor_downloads);
launch_descriptor_downloads(DIR_PURPOSE_FETCH_MICRODESC, downloadable,
NULL, now);
tt_int_op(3, ==, count);
UNMOCK(initiate_descriptor_downloads);
done:
SMARTLIST_FOREACH(downloadable, char *, cp1, tor_free(cp1));
smartlist_free(downloadable);
}
开发者ID:BwRy,项目名称:Astoria,代码行数:25,代码来源:test_routerlist.c
注:本文中的smartlist_add函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论