本文整理汇总了C++中GNUNET_strdup函数的典型用法代码示例。如果您正苦于以下问题:C++ GNUNET_strdup函数的具体用法?C++ GNUNET_strdup怎么用?C++ GNUNET_strdup使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GNUNET_strdup函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GNUNET_TESTBED_test_run
/**
* Convenience method for running a "simple" test on the local system
* with a single call from 'main'. Underlay and overlay topology are
* configured using the "UNDERLAY" and "OVERLAY" options in the
* "[testbed]" section of the configuration (with possible options
* given in "UNDERLAY_XXX" and/or "OVERLAY_XXX").
*
* The test is to be terminated using a call to
* "GNUNET_SCHEDULER_shutdown". If starting the test fails,
* the program is stopped without 'master' ever being run.
*
* NOTE: this function should be called from 'main', NOT from
* within a GNUNET_SCHEDULER-loop. This function will initialze
* the scheduler loop, the testbed and then pass control to
* 'master'.
*
* @param testname name of the testcase (to configure logging, etc.)
* @param cfg_filename configuration filename to use
* (for testbed, controller and peers)
* @param num_peers number of peers to start
* @param event_mask bit mask with set of events to call 'cc' for;
* or-ed values of "1LL" shifted by the
* respective 'enum GNUNET_TESTBED_EventType'
* (i.e. "(1LL << GNUNET_TESTBED_ET_CONNECT) || ...")
* @param cc controller callback to invoke on events; This callback is called
* for all peer start events even if GNUNET_TESTBED_ET_PEER_START isn't
* set in the event_mask as this is the only way get access to the
* handle of each peer
* @param cc_cls closure for cc
* @param test_master task to run once the test is ready
* @param test_master_cls closure for 'task'.
* @return GNUNET_SYSERR on error, GNUNET_OK on success
*/
int
GNUNET_TESTBED_test_run (const char *testname, const char *cfg_filename,
unsigned int num_peers, uint64_t event_mask,
GNUNET_TESTBED_ControllerCallback cc, void *cc_cls,
GNUNET_TESTBED_TestMaster test_master,
void *test_master_cls)
{
char *argv2[] = {
NULL,
"-c",
NULL,
NULL
};
struct GNUNET_GETOPT_CommandLineOption options[] = {
GNUNET_GETOPT_OPTION_END
};
struct TestRunContext *rc;
int ret;
argv2[0] = GNUNET_strdup (testname);
argv2[2] = GNUNET_strdup (cfg_filename);
GNUNET_assert (NULL != test_master);
GNUNET_assert (num_peers > 0);
rc = GNUNET_malloc (sizeof (struct TestRunContext) +
(num_peers * sizeof (struct GNUNET_TESTBED_Peer *)));
rc->test_master = test_master;
rc->test_master_cls = test_master_cls;
rc->num_peers = num_peers;
rc->event_mask = event_mask;
rc->cc = cc;
rc->cc_cls = cc_cls;
ret =
GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2,
testname, "nohelp", options, &run, rc);
GNUNET_free (rc);
GNUNET_free (argv2[0]);
GNUNET_free (argv2[2]);
return ret;
}
示例2: testing_connect_cb
static void
testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls)
{
cc = NULL;
char *p1_c = GNUNET_strdup (GNUNET_i2s (&p1->id));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected: %u (%s) <-> %u (%s)\n",
p1->no, p1_c, p2->no, GNUNET_i2s (&p2->id));
GNUNET_free (p1_c);
s_connected = GNUNET_YES;
send_task = GNUNET_SCHEDULER_add_now (&sendtask, NULL);
}
示例3: testing_connect_cb
static void
testing_connect_cb (struct PeerContext *p1,
struct PeerContext *p2,
void *cls)
{
char *ps = GNUNET_strdup (GNUNET_i2s (&p1->id));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Peer %u (`%4s') connected to peer %u (`%s')!\n", p1->no, ps,
p2->no, GNUNET_i2s (&p2->id));
GNUNET_free (ps);
GNUNET_SCHEDULER_add_now (&end, NULL);
}
示例4: GNUNET_NAMESTORE_zone_to_name
/**
* Look for an existing PKEY delegation record for a given public key.
* Returns at most one result to the processor.
*
* @param h handle to the namestore
* @param zone hash of public key of the zone to look up in, never NULL
* @param value_zone hash of the public key of the target zone (value), never NULL
* @param proc function to call on the matching records, or with
* NULL (rd_count == 0) if there are no matching records
* @param proc_cls closure for proc
* @return a handle that can be used to
* cancel
*/
struct GNUNET_NAMESTORE_QueueEntry *
GNUNET_NAMESTORE_zone_to_name (struct GNUNET_NAMESTORE_Handle *h,
const struct GNUNET_CRYPTO_ShortHashCode *zone,
const struct GNUNET_CRYPTO_ShortHashCode *value_zone,
GNUNET_NAMESTORE_RecordProcessor proc, void *proc_cls)
{
struct GNUNET_NAMESTORE_QueueEntry *qe;
struct PendingMessage *pe;
size_t msg_size = 0;
uint32_t rid = 0;
GNUNET_assert (NULL != h);
GNUNET_assert (NULL != zone);
GNUNET_assert (NULL != value_zone);
rid = get_op_id(h);
qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry));
qe->nsh = h;
qe->proc = proc;
qe->proc_cls = proc_cls;
qe->op_id = rid;
GNUNET_CONTAINER_DLL_insert_tail(h->op_head, h->op_tail, qe);
/* set msg_size*/
msg_size = sizeof (struct ZoneToNameMessage);
pe = GNUNET_malloc(sizeof (struct PendingMessage) + msg_size);
/* create msg here */
struct ZoneToNameMessage * msg;
pe->size = msg_size;
pe->is_init = GNUNET_NO;
msg = (struct ZoneToNameMessage *) &pe[1];
msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME);
msg->gns_header.header.size = htons (msg_size);
msg->gns_header.r_id = htonl (rid);
msg->zone = *zone;
msg->value_zone = *value_zone;
char * z_tmp = GNUNET_strdup (GNUNET_short_h2s (zone));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message for zone `%s' in zone `%s'\n",
"NAMESTORE_ZONE_TO_NAME",
z_tmp,
GNUNET_short_h2s (value_zone));
GNUNET_free (z_tmp);
/* transmit message */
GNUNET_CONTAINER_DLL_insert_tail (h->pending_head, h->pending_tail, pe);
do_transmit(h);
return qe;
}
示例5: key_iterator
void
key_iterator (void *cls, const struct GNUNET_HashCode *key, const char *proof,
int accepting, unsigned int num_edges,
const struct GNUNET_REGEX_Edge *edges)
{
unsigned int i;
struct IteratorContext *ctx = cls;
char *out_str;
char *state_id = GNUNET_strdup (GNUNET_h2s (key));
if (GNUNET_YES == ctx->should_save_graph)
{
if (GNUNET_YES == accepting)
GNUNET_asprintf (&out_str, "\"%s\" [shape=doublecircle]\n", state_id);
else
GNUNET_asprintf (&out_str, "\"%s\" [shape=circle]\n", state_id);
fwrite (out_str, strlen (out_str), 1, ctx->graph_filep);
GNUNET_free (out_str);
for (i = 0; i < num_edges; i++)
{
transition_counter++;
GNUNET_asprintf (&out_str, "\"%s\" -> \"%s\" [label = \"%s (%s)\"]\n",
state_id, GNUNET_h2s (&edges[i].destination),
edges[i].label, proof);
fwrite (out_str, strlen (out_str), 1, ctx->graph_filep);
GNUNET_free (out_str);
}
}
else
{
for (i = 0; i < num_edges; i++)
transition_counter++;
}
for (i = 0; i < ctx->string_count; i++)
{
if (0 == strcmp (proof, ctx->strings[i]))
ctx->match_count++;
}
if (GNUNET_OK != GNUNET_REGEX_check_proof (proof, key))
{
ctx->error++;
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Proof check failed: proof: %s key: %s\n", proof, state_id);
}
GNUNET_free (state_id);
}
示例6: write_pid_file
/**
* Write PID file.
*
* @param sctx service context
* @param pid PID to write (should be equal to 'getpid()'
* @return #GNUNET_OK on success (including no work to be done)
*/
static int
write_pid_file (struct GNUNET_SERVICE_Context *sctx, pid_t pid)
{
FILE *pidfd;
char *pif;
char *user;
char *rdir;
int len;
if (NULL == (pif = get_pid_file_name (sctx)))
return GNUNET_OK; /* no file desired */
user = get_user_name (sctx);
rdir = GNUNET_strdup (pif);
len = strlen (rdir);
while ((len > 0) && (rdir[len] != DIR_SEPARATOR))
len--;
rdir[len] = '\0';
if (0 != ACCESS (rdir, F_OK))
{
/* we get to create a directory -- and claim it
* as ours! */
(void) GNUNET_DISK_directory_create (rdir);
if ((NULL != user) && (0 < strlen (user)))
GNUNET_DISK_file_change_owner (rdir, user);
}
if (0 != ACCESS (rdir, W_OK | X_OK))
{
LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "access", rdir);
GNUNET_free (rdir);
GNUNET_free_non_null (user);
GNUNET_free (pif);
return GNUNET_SYSERR;
}
GNUNET_free (rdir);
pidfd = FOPEN (pif, "w");
if (NULL == pidfd)
{
LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "fopen", pif);
GNUNET_free (pif);
GNUNET_free_non_null (user);
return GNUNET_SYSERR;
}
if (0 > FPRINTF (pidfd, "%u", pid))
LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fprintf", pif);
GNUNET_break (0 == FCLOSE (pidfd));
if ((NULL != user) && (0 < strlen (user)))
GNUNET_DISK_file_change_owner (pif, user);
GNUNET_free_non_null (user);
GNUNET_free (pif);
return GNUNET_OK;
}
示例7: notify_disconnect
static void
notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
{
struct PeerContext *p = cls;
char *ps = GNUNET_strdup (GNUNET_i2s (&p->id));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Peer %u (`%4s'): peer (`%s') disconnected from me!\n", p->no, ps,
GNUNET_i2s (peer));
if (th != NULL)
GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
th = NULL;
}
示例8: testCanonicalize
static int
testCanonicalize ()
{
char *fn = GNUNET_strdup ("ab?><|cd*ef:/g\"");
GNUNET_DISK_filename_canonicalize (fn);
if (0 != strcmp (fn, "ab____cd_ef__g_"))
{
GNUNET_free (fn);
return 1;
}
GNUNET_free (fn);
return 0;
}
示例9: unindex_reader
/**
* Function called by the tree encoder to obtain
* a block of plaintext data (for the lowest level
* of the tree).
*
* @param cls our publishing context
* @param offset identifies which block to get
* @param max (maximum) number of bytes to get; returning
* fewer will also cause errors
* @param buf where to copy the plaintext buffer
* @param emsg location to store an error message (on error)
* @return number of bytes copied to buf, 0 on error
*/
static size_t
unindex_reader (void *cls,
uint64_t offset,
size_t max,
void *buf,
char **emsg)
{
struct GNUNET_FS_UnindexContext *uc = cls;
size_t pt_size;
pt_size = GNUNET_MIN (max, uc->file_size - offset);
if (offset != GNUNET_DISK_file_seek (uc->fh, offset, GNUNET_DISK_SEEK_SET))
{
*emsg = GNUNET_strdup (_("Failed to find given position in file"));
return 0;
}
if (pt_size != GNUNET_DISK_file_read (uc->fh, buf, pt_size))
{
*emsg = GNUNET_strdup (_("Failed to read file"));
return 0;
}
return pt_size;
}
示例10: testing_connect_cb
static void
testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls)
{
cc = NULL;
char *p1_c = GNUNET_strdup (GNUNET_i2s (&p1->id));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected: %s <-> %s\n", p1_c,
GNUNET_i2s (&p2->id));
GNUNET_free (p1_c);
// FIXME: THIS IS REQUIRED! SEEMS TO BE A BUG!
send_task =
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &sendtask, NULL);
}
示例11: GNUNET_TRANSPORT_TESTING_log_disconnect
/**
* Log a disconnect event.
*
* @param cls NULL
* @param me peer that had the event
* @param other peer that disconnected.
*/
void
GNUNET_TRANSPORT_TESTING_log_disconnect (void *cls,
struct GNUNET_TRANSPORT_TESTING_PeerContext *me,
const struct GNUNET_PeerIdentity *other)
{
char *ps;
ps = GNUNET_strdup (GNUNET_i2s (&me->id));
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Peer `%s' disconnected from %u (%s)!\n",
GNUNET_i2s (other),
me->no,
ps);
}
示例12: GNUNET_PEERSTORE_store
/**
* Store a new entry in the PEERSTORE.
* Note that stored entries can be lost in some cases
* such as power failure.
*
* @param h Handle to the PEERSTORE service
* @param sub_system name of the sub system
* @param peer Peer Identity
* @param key entry key
* @param value entry value BLOB
* @param size size of @e value
* @param expiry absolute time after which the entry is (possibly) deleted
* @param options options specific to the storage operation
* @param cont Continuation function after the store request is sent
* @param cont_cls Closure for @a cont
*/
struct GNUNET_PEERSTORE_StoreContext *
GNUNET_PEERSTORE_store (struct GNUNET_PEERSTORE_Handle *h,
const char *sub_system,
const struct GNUNET_PeerIdentity *peer, const char *key,
const void *value, size_t size,
struct GNUNET_TIME_Absolute expiry,
enum GNUNET_PEERSTORE_StoreOption options,
GNUNET_PEERSTORE_Continuation cont, void *cont_cls)
{
struct GNUNET_MQ_Envelope *ev;
struct GNUNET_PEERSTORE_StoreContext *sc;
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Storing value (size: %lu) for subsytem `%s', peer `%s', key `%s'\n",
size, sub_system, GNUNET_i2s (peer), key);
ev = PEERSTORE_create_record_mq_envelope (sub_system, peer, key, value, size,
&expiry, options,
GNUNET_MESSAGE_TYPE_PEERSTORE_STORE);
sc = GNUNET_new (struct GNUNET_PEERSTORE_StoreContext);
sc->sub_system = GNUNET_strdup (sub_system);
sc->peer = *peer;
sc->key = GNUNET_strdup (key);
sc->value = GNUNET_memdup (value, size);
sc->size = size;
sc->expiry = expiry;
sc->options = options;
sc->cont = cont;
sc->cont_cls = cont_cls;
sc->h = h;
GNUNET_CONTAINER_DLL_insert_tail (h->store_head, h->store_tail, sc);
GNUNET_MQ_notify_sent (ev, &store_request_sent, sc);
GNUNET_MQ_send (h->mq, ev);
return sc;
}
示例13: convert_with_table
/**
* Convert a string of the form "4 X 5 Y" into a numeric value
* by interpreting "X" and "Y" as units and then multiplying
* the numbers with the values associated with the respective
* unit from the conversion table.
*
* @param input input string to parse
* @param table table with the conversion of unit names to numbers
* @param output where to store the result
* @return #GNUNET_OK on success, #GNUNET_SYSERR on error
*/
static int
convert_with_table (const char *input,
const struct ConversionTable *table,
unsigned long long *output)
{
unsigned long long ret;
char *in;
const char *tok;
unsigned long long last;
unsigned int i;
ret = 0;
last = 0;
in = GNUNET_strdup (input);
for (tok = strtok (in, " "); tok != NULL; tok = strtok (NULL, " "))
{
do
{
i = 0;
while ((table[i].name != NULL) && (0 != strcasecmp (table[i].name, tok)))
i++;
if (table[i].name != NULL)
{
last *= table[i].value;
break; /* next tok */
}
else
{
char *endptr;
ret += last;
errno = 0;
last = strtoull (tok, &endptr, 10);
if ((0 != errno) || (endptr == tok))
{
GNUNET_free (in);
return GNUNET_SYSERR; /* expected number */
}
if ('\0' == endptr[0])
break; /* next tok */
else
tok = endptr; /* and re-check (handles times like "10s") */
}
} while (GNUNET_YES);
}
ret += last;
*output = ret;
GNUNET_free (in);
return GNUNET_OK;
}
示例14: notify_receive
static void
notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_MessageHeader *message,
const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
{
struct PeerContext *p = cls;
struct PeerContext *t = NULL;
if (0 == memcmp (peer, &p1->id, sizeof (struct GNUNET_PeerIdentity)))
t = p1;
if (0 == memcmp (peer, &p2->id, sizeof (struct GNUNET_PeerIdentity)))
t = p2;
GNUNET_assert (t != NULL);
char *ps = GNUNET_strdup (GNUNET_i2s (&p->id));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Peer %u (`%4s') received message of type %d and size %u size from peer %u (`%4s')!\n",
p->no, ps, ntohs (message->type), ntohs (message->size), t->no,
GNUNET_i2s (&t->id));
GNUNET_free (ps);
if ((MTYPE == ntohs (message->type)) &&
(sizeof (struct GNUNET_MessageHeader) == ntohs (message->size)))
{
if (restarted == GNUNET_NO)
{
restarted = GNUNET_YES;
restart (p1, cfg_file_p1);
restart (p2, cfg_file_p2);
return;
}
else
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Restarted peers connected, stopping test...\n");
ok = 0;
end ();
}
}
else
{
GNUNET_break (0);
ok = 1;
if (die_task != GNUNET_SCHEDULER_NO_TASK)
GNUNET_SCHEDULER_cancel (die_task);
die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
}
}
示例15: GNUNET_FS_unindex_do_remove_
/**
* Connect to the datastore and remove the blocks.
*
* @param uc context for the unindex operation.
*/
void
GNUNET_FS_unindex_do_remove_ (struct GNUNET_FS_UnindexContext *uc)
{
if (NULL == uc->dsh)
uc->dsh = GNUNET_DATASTORE_connect (uc->h->cfg);
if (NULL == uc->dsh)
{
uc->state = UNINDEX_STATE_ERROR;
uc->emsg = GNUNET_strdup (_("Failed to connect to `datastore' service."));
GNUNET_FS_unindex_sync_ (uc);
signal_unindex_error (uc);
return;
}
uc->fh =
GNUNET_DISK_file_open (uc->filename, GNUNET_DISK_OPEN_READ,
GNUNET_DISK_PERM_NONE);
if (NULL == uc->fh)
{
GNUNET_DATASTORE_disconnect (uc->dsh, GNUNET_NO);
uc->dsh = NULL;
uc->state = UNINDEX_STATE_ERROR;
uc->emsg = GNUNET_strdup (_("Failed to open file for unindexing."));
GNUNET_FS_unindex_sync_ (uc);
signal_unindex_error (uc);
return;
}
uc->tc =
GNUNET_FS_tree_encoder_create (uc->h,
uc->file_size,
uc,
&unindex_reader,
&unindex_process,
&unindex_progress,
&unindex_extract_keywords);
GNUNET_FS_tree_encoder_next (uc->tc);
}