本文整理汇总了C++中smartlist_new函数的典型用法代码示例。如果您正苦于以下问题:C++ smartlist_new函数的具体用法?C++ smartlist_new怎么用?C++ smartlist_new使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了smartlist_new函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: test_container_smartlist_join
/** Run unit tests for concatenate-a-smartlist-of-strings functions. */
static void
test_container_smartlist_join(void)
{
smartlist_t *sl = smartlist_new();
smartlist_t *sl2 = smartlist_new(), *sl3 = smartlist_new(),
*sl4 = smartlist_new();
char *joined=NULL;
/* unique, sorted. */
smartlist_split_string(sl,
"Abashments Ambush Anchorman Bacon Banks Borscht "
"Bunks Inhumane Insurance Knish Know Manners "
"Maraschinos Stamina Sunbonnets Unicorns Wombats",
" ", 0, 0);
/* non-unique, sorted. */
smartlist_split_string(sl2,
"Ambush Anchorman Anchorman Anemias Anemias Bacon "
"Crossbowmen Inhumane Insurance Knish Know Manners "
"Manners Maraschinos Wombats Wombats Work",
" ", 0, 0);
SMARTLIST_FOREACH_JOIN(sl, char *, cp1,
sl2, char *, cp2,
strcmp(cp1,cp2),
smartlist_add(sl3, cp2)) {
test_streq(cp1, cp2);
smartlist_add(sl4, cp1);
} SMARTLIST_FOREACH_JOIN_END(cp1, cp2);
开发者ID:Lab414,项目名称:30May,代码行数:27,代码来源:test_containers.c
示例2: test_rend_cache_store_v2_desc_as_dir_with_different_content
static void
test_rend_cache_store_v2_desc_as_dir_with_different_content(void *data)
{
(void)data;
rend_cache_store_status_t ret;
rend_service_descriptor_t *generated = NULL;
smartlist_t *descs = smartlist_new();
time_t t;
char *service_id = NULL;
rend_encoded_v2_service_descriptor_t *desc_holder_one = NULL;
rend_encoded_v2_service_descriptor_t *desc_holder_two = NULL;
NS_MOCK(router_get_my_routerinfo);
NS_MOCK(hid_serv_responsible_for_desc_id);
rend_cache_init();
t = time(NULL);
create_descriptor(&generated, &service_id, 3);
generated->timestamp = t + RECENT_TIME;
rend_encode_v2_descriptors(descs, generated, t + RECENT_TIME, 0,
REND_NO_AUTH, NULL, NULL);
desc_holder_one = ((rend_encoded_v2_service_descriptor_t *)
smartlist_get(descs, 0));
smartlist_set(descs, 0, NULL);
SMARTLIST_FOREACH(descs, rend_encoded_v2_service_descriptor_t *, d,
rend_encoded_v2_service_descriptor_free(d));
smartlist_free(descs);
descs = smartlist_new();
generated->timestamp = t + RECENT_TIME;
generated->protocols = 41;
rend_encode_v2_descriptors(descs, generated, t + RECENT_TIME, 0,
REND_NO_AUTH, NULL, NULL);
desc_holder_two = ((rend_encoded_v2_service_descriptor_t *)
smartlist_get(descs, 0));
smartlist_set(descs, 0, NULL);
// Test when we have another descriptor stored, with a different descriptor
mock_routerinfo = tor_malloc(sizeof(routerinfo_t));
hid_serv_responsible_for_desc_id_response = 1;
rend_cache_store_v2_desc_as_dir(desc_holder_one->desc_str);
ret = rend_cache_store_v2_desc_as_dir(desc_holder_two->desc_str);
tt_int_op(ret, OP_EQ, RCS_OKAY);
done:
NS_UNMOCK(router_get_my_routerinfo);
NS_UNMOCK(hid_serv_responsible_for_desc_id);
rend_cache_free_all();
rend_service_descriptor_free(generated);
tor_free(service_id);
SMARTLIST_FOREACH(descs, rend_encoded_v2_service_descriptor_t *, d,
rend_encoded_v2_service_descriptor_free(d));
smartlist_free(descs);
rend_encoded_v2_service_descriptor_free(desc_holder_one);
rend_encoded_v2_service_descriptor_free(desc_holder_two);
}
开发者ID:marcelmaatkamp,项目名称:tor,代码行数:60,代码来源:test_rendcache.c
示例3: setup_mock_consensus
static void
setup_mock_consensus(void)
{
current_md_consensus = current_ns_consensus =
tor_malloc_zero(sizeof(networkstatus_t));
current_md_consensus->net_params = smartlist_new();
current_md_consensus->routerstatus_list = smartlist_new();
}
开发者ID:jfrazelle,项目名称:tor,代码行数:8,代码来源:test_sendme.c
示例4: routerset_new
/** Return a new empty routerset. */
routerset_t *
routerset_new(void)
{
routerset_t *result = tor_malloc_zero(sizeof(routerset_t));
result->list = smartlist_new();
result->names = strmap_new();
result->digests = digestmap_new();
result->policies = smartlist_new();
result->country_names = smartlist_new();
return result;
}
开发者ID:Arcoins,项目名称:Arcoin_Source,代码行数:12,代码来源:routerset.c
示例5: helper_create_rend_service
static rend_service_t *
helper_create_rend_service(const char *path)
{
rend_service_t *s = tor_malloc_zero(sizeof(rend_service_t));
s->ports = smartlist_new();
s->intro_nodes = smartlist_new();
s->expiring_nodes = smartlist_new();
if (path) {
s->directory = tor_strdup(path);
}
return s;
}
开发者ID:ageis,项目名称:tor,代码行数:12,代码来源:test_hs.c
示例6: dir_common_setup_vote
/** Initialize networkstatus vote object attributes. */
void
dir_common_setup_vote(networkstatus_t **vote, time_t now)
{
*vote = tor_malloc_zero(sizeof(networkstatus_t));
(*vote)->type = NS_TYPE_VOTE;
(*vote)->published = now;
(*vote)->supported_methods = smartlist_new();
(*vote)->known_flags = smartlist_new();
(*vote)->net_params = smartlist_new();
(*vote)->routerstatus_list = smartlist_new();
(*vote)->voters = smartlist_new();
}
开发者ID:Archer-sys,项目名称:tor,代码行数:13,代码来源:test_dir_common.c
示例7: test_container_smartlist_overlap
/** Run unit tests for smartlist set manipulation functions. */
static void
test_container_smartlist_overlap(void *arg)
{
smartlist_t *sl = smartlist_new();
smartlist_t *ints = smartlist_new();
smartlist_t *odds = smartlist_new();
smartlist_t *evens = smartlist_new();
smartlist_t *primes = smartlist_new();
int i;
(void)arg;
for (i=1; i < 10; i += 2)
smartlist_add(odds, (void*)(uintptr_t)i);
for (i=0; i < 10; i += 2)
smartlist_add(evens, (void*)(uintptr_t)i);
/* add_all */
smartlist_add_all(ints, odds);
smartlist_add_all(ints, evens);
tt_int_op(smartlist_len(ints),OP_EQ, 10);
smartlist_add(primes, (void*)2);
smartlist_add(primes, (void*)3);
smartlist_add(primes, (void*)5);
smartlist_add(primes, (void*)7);
/* overlap */
tt_assert(smartlist_overlap(ints, odds));
tt_assert(smartlist_overlap(odds, primes));
tt_assert(smartlist_overlap(evens, primes));
tt_assert(!smartlist_overlap(odds, evens));
/* intersect */
smartlist_add_all(sl, odds);
smartlist_intersect(sl, primes);
tt_int_op(smartlist_len(sl),OP_EQ, 3);
tt_assert(smartlist_contains(sl, (void*)3));
tt_assert(smartlist_contains(sl, (void*)5));
tt_assert(smartlist_contains(sl, (void*)7));
/* subtract */
smartlist_add_all(sl, primes);
smartlist_subtract(sl, odds);
tt_int_op(smartlist_len(sl),OP_EQ, 1);
tt_assert(smartlist_contains(sl, (void*)2));
done:
smartlist_free(odds);
smartlist_free(evens);
smartlist_free(ints);
smartlist_free(primes);
smartlist_free(sl);
}
开发者ID:1234max,项目名称:tor,代码行数:53,代码来源:test_containers.c
示例8: test_container_smartlist_strings_eq
static void
test_container_smartlist_strings_eq(void *arg)
{
(void)arg;
smartlist_t *sl1 = smartlist_new();
smartlist_t *sl2 = smartlist_new();
#define EQ_SHOULD_SAY(s1,s2,val) \
do { \
SMARTLIST_FOREACH(sl1, char *, cp, tor_free(cp)); \
SMARTLIST_FOREACH(sl2, char *, cp, tor_free(cp)); \
smartlist_clear(sl1); \
smartlist_clear(sl2); \
smartlist_split_string(sl1, (s1), ":", 0, 0); \
smartlist_split_string(sl2, (s2), ":", 0, 0); \
tt_int_op((val), OP_EQ, smartlist_strings_eq(sl1, sl2)); \
} while (0)
/* Both NULL, so equal */
tt_int_op(1, ==, smartlist_strings_eq(NULL, NULL));
/* One NULL, not equal. */
tt_int_op(0, ==, smartlist_strings_eq(NULL, sl1));
tt_int_op(0, ==, smartlist_strings_eq(sl1, NULL));
/* Both empty, both equal. */
EQ_SHOULD_SAY("", "", 1);
/* One empty, not equal */
EQ_SHOULD_SAY("", "ab", 0);
EQ_SHOULD_SAY("", "xy:z", 0);
EQ_SHOULD_SAY("abc", "", 0);
EQ_SHOULD_SAY("abc:cd", "", 0);
/* Different lengths, not equal. */
EQ_SHOULD_SAY("hello:world", "hello", 0);
EQ_SHOULD_SAY("hello", "hello:friends", 0);
/* Same lengths, not equal */
EQ_SHOULD_SAY("Hello:world", "goodbye:world", 0);
EQ_SHOULD_SAY("Hello:world", "Hello:stars", 0);
/* Actually equal */
EQ_SHOULD_SAY("ABC", "ABC", 1);
EQ_SHOULD_SAY(" ab : cd : e", " ab : cd : e", 1);
done:
SMARTLIST_FOREACH(sl1, char *, cp, tor_free(cp));
SMARTLIST_FOREACH(sl2, char *, cp, tor_free(cp));
smartlist_free(sl1);
smartlist_free(sl2);
}
开发者ID:1234max,项目名称:tor,代码行数:51,代码来源:test_containers.c
示例9: 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
示例10: get_majority_srv_from_votes
/* Using a list of <b>votes</b>, return the SRV object from them that has
* been voted by the majority of dirauths. If <b>current</b> is set, we look
* for the current SRV value else the previous one. The returned pointer is
* an object located inside a vote. NULL is returned if no appropriate value
* could be found. */
STATIC sr_srv_t *
get_majority_srv_from_votes(const smartlist_t *votes, int current)
{
int count = 0;
sr_srv_t *most_frequent_srv = NULL;
sr_srv_t *the_srv = NULL;
smartlist_t *srv_list;
tor_assert(votes);
srv_list = smartlist_new();
/* Walk over votes and register any SRVs found. */
SMARTLIST_FOREACH_BEGIN(votes, networkstatus_t *, v) {
sr_srv_t *srv_tmp = NULL;
if (!v->sr_info.participate) {
/* Ignore vote that do not participate. */
continue;
}
/* Do we want previous or current SRV? */
srv_tmp = current ? v->sr_info.current_srv : v->sr_info.previous_srv;
if (!srv_tmp) {
continue;
}
smartlist_add(srv_list, srv_tmp);
} SMARTLIST_FOREACH_END(v);
开发者ID:Samdney,项目名称:tor,代码行数:33,代码来源:shared_random.c
示例11: 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
示例12: pick_oos_victims_mock
static smartlist_t *
pick_oos_victims_mock(int n)
{
smartlist_t *l = NULL;
int i;
++pick_oos_mock_calls;
tt_int_op(n, OP_GT, 0);
if (!pick_oos_mock_fail) {
/*
* connection_check_oos() just passes the list onto
* kill_conn_list_for_oos(); we don't need to simulate
* its content for this mock, just its existence, but
* we do need to check the parameter.
*/
l = smartlist_new();
for (i = 0; i < n; ++i) smartlist_add(l, NULL);
} else {
l = NULL;
}
pick_oos_mock_last_n = n;
done:
return l;
}
开发者ID:francois-wellenreiter,项目名称:tor,代码行数:28,代码来源:test_oos.c
示例13: 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,代码来源:test_dir_common.c
示例14: test_policy_summary_helper
/** Helper: Parse the exit policy string in <b>policy_str</b>, and make sure
* that policies_summarize() produces the string <b>expected_summary</b> from
* it. */
static void
test_policy_summary_helper(const char *policy_str,
const char *expected_summary)
{
config_line_t line;
smartlist_t *policy = smartlist_new();
char *summary = NULL;
char *summary_after = NULL;
int r;
short_policy_t *short_policy = NULL;
line.key = (char*)"foo";
line.value = (char *)policy_str;
line.next = NULL;
r = policies_parse_exit_policy(&line, &policy, 1, 0, 0, 1);
test_eq(r, 0);
summary = policy_summarize(policy, AF_INET);
test_assert(summary != NULL);
test_streq(summary, expected_summary);
short_policy = parse_short_policy(summary);
tt_assert(short_policy);
summary_after = write_short_policy(short_policy);
test_streq(summary, summary_after);
done:
tor_free(summary_after);
tor_free(summary);
if (policy)
addr_policy_list_free(policy);
short_policy_free(short_policy);
}
开发者ID:wfn,项目名称:tor,代码行数:37,代码来源:test_policy.c
示例15: tor_capture_bugs_
void
tor_capture_bugs_(int n)
{
tor_end_capture_bugs_();
bug_messages = smartlist_new();
n_bugs_to_capture = n;
}
开发者ID:nmathewson,项目名称:Tor,代码行数:7,代码来源:util_bug.c
示例16: 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
示例17: 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
示例18: 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
示例19: memarea_new
memarea_t *
memarea_new(void)
{
memarea_t *ma = tor_malloc_zero(sizeof(memarea_t));
ma->pieces = smartlist_new();
return ma;
}
开发者ID:Samdney,项目名称:tor,代码行数:7,代码来源:memarea.c
示例20: get_transport_in_state_by_name
/** Return the config line for transport <b>transport</b> in the current state.
* Return NULL if there is no config line for <b>transport</b>. */
static config_line_t *
get_transport_in_state_by_name(const char *transport)
{
or_state_t *or_state = get_or_state();
config_line_t *line;
config_line_t *ret = NULL;
smartlist_t *items = NULL;
for (line = or_state->TransportProxies ; line ; line = line->next) {
tor_assert(!strcmp(line->key, "TransportProxy"));
items = smartlist_new();
smartlist_split_string(items, line->value, NULL,
SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, -1);
if (smartlist_len(items) != 2) /* broken state */
goto done;
if (!strcmp(smartlist_get(items, 0), transport)) {
ret = line;
goto done;
}
SMARTLIST_FOREACH(items, char*, s, tor_free(s));
smartlist_free(items);
items = NULL;
}
done:
if (items) {
SMARTLIST_FOREACH(items, char*, s, tor_free(s));
smartlist_free(items);
}
return ret;
}
开发者ID:bwrichte,项目名称:TorFinalProject,代码行数:36,代码来源:statefile.c
注:本文中的smartlist_new函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论