int main (int argc, char *argv[]) { GNUNET_log_setup ("test-regex", "WARNING", NULL); int error; struct REGEX_INTERNAL_Automaton *dfa; unsigned int i; unsigned int num_transitions; char *filename = NULL; struct IteratorContext ctx = { 0, 0, NULL, 0, NULL, 0 }; error = 0; const struct RegexStringPair rxstr[13] = { {INITIAL_PADDING "ab(c|d)+c*(a(b|c)+d)+(bla)+", 2, {INITIAL_PADDING "abcdcdca", INITIAL_PADDING "abcabdbl"}}, {INITIAL_PADDING "abcdefghixxxxxxxxxxxxxjklmnop*qstoisdjfguisdfguihsdfgbdsuivggsd", 1, {INITIAL_PADDING "abcdefgh"}}, {INITIAL_PADDING "VPN-4-1(0|1)*", 2, {INITIAL_PADDING "VPN-4-10", INITIAL_PADDING "VPN-4-11"}}, {INITIAL_PADDING "(a+X*y+c|p|R|Z*K*y*R+w|Y*6+n+h*k*w+V*F|W*B*e*)", 2, {INITIAL_PADDING "aaaaaaaa", INITIAL_PADDING "aaXXyyyc"}}, {INITIAL_PADDING "a*", 1, {INITIAL_PADDING "aaaaaaaa"}}, {INITIAL_PADDING "xzxzxzxzxz", 1, {INITIAL_PADDING "xzxzxzxz"}}, {INITIAL_PADDING "xyz*", 1, {INITIAL_PADDING "xyzzzzzz"}}, {INITIAL_PADDING "abcd:(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1):(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)", 2, {INITIAL_PADDING "abcd:000", INITIAL_PADDING "abcd:101"}}, {INITIAL_PADDING "(x*|(0|1|2)(a|b|c|d)+)", 2, {INITIAL_PADDING "xxxxxxxx", INITIAL_PADDING "0abcdbad"}}, {INITIAL_PADDING "(0|1)(0|1)23456789ABC", 1, {INITIAL_PADDING "11234567"}}, {INITIAL_PADDING "0*123456789ABC*", 3, {INITIAL_PADDING "00123456", INITIAL_PADDING "00000000", INITIAL_PADDING "12345678"}}, {INITIAL_PADDING "0123456789A*BC", 1, {INITIAL_PADDING "01234567"}}, {"GNUNETVPN000100000IPEX6-fc5a:4e1:c2ba::1", 1, {"GNUNETVPN000100000IPEX6-"}} }; const char *graph_start_str = "digraph G {\nrankdir=LR\n"; const char *graph_end_str = "\n}\n"; for (i = 0; i < 13; i++) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Iterating DFA for regex %s\n", rxstr[i].regex); /* Create graph */ if (GNUNET_YES == REGEX_INTERNAL_ITERATE_SAVE_DEBUG_GRAPH) { GNUNET_asprintf (&filename, "iteration_graph_%u.dot", i); ctx.graph_filep = fopen (filename, "w"); if (NULL == ctx.graph_filep) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Could not open file %s for saving iteration graph.\n", filename); ctx.should_save_graph = GNUNET_NO; } else { ctx.should_save_graph = GNUNET_YES; fwrite (graph_start_str, strlen (graph_start_str), 1, ctx.graph_filep); } GNUNET_free (filename); } else { ctx.should_save_graph = GNUNET_NO; ctx.graph_filep = NULL; } /* Iterate over DFA edges */ transition_counter = 0; ctx.string_count = rxstr[i].string_count; ctx.strings = rxstr[i].strings; ctx.match_count = 0; dfa = REGEX_INTERNAL_construct_dfa (rxstr[i].regex, strlen (rxstr[i].regex), 0); REGEX_INTERNAL_iterate_all_edges (dfa, key_iterator, &ctx); num_transitions = REGEX_INTERNAL_get_transition_count (dfa) - dfa->start->transition_count; if (transition_counter < num_transitions) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Automaton has %d transitions, iterated over %d transitions\n", num_transitions, transition_counter); error += 1; } if (ctx.match_count < ctx.string_count) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Missing initial states for regex %s\n", rxstr[i].regex); error += (ctx.string_count - ctx.match_count); } else if (ctx.match_count > ctx.string_count) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Duplicate initial transitions for regex %s\n", rxstr[i].regex); error += (ctx.string_count - ctx.match_count); } REGEX_INTERNAL_automaton_destroy (dfa); /* Finish graph */ if (GNUNET_YES == ctx.should_save_graph) { fwrite (graph_end_str, strlen (graph_end_str), 1, ctx.graph_filep); fclose (ctx.graph_filep); ctx.graph_filep = NULL; ctx.should_save_graph = GNUNET_NO; } } for (i = 0; i < 13; i++) { ctx.string_count = rxstr[i].string_count; ctx.strings = rxstr[i].strings; ctx.match_count = 0; dfa = REGEX_INTERNAL_construct_dfa (rxstr[i].regex, strlen (rxstr[i].regex), 0); REGEX_INTERNAL_dfa_add_multi_strides (NULL, dfa, 2); REGEX_INTERNAL_iterate_all_edges (dfa, key_iterator, &ctx); if (ctx.match_count < ctx.string_count) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Missing initial states for regex %s\n", rxstr[i].regex); error += (ctx.string_count - ctx.match_count); } REGEX_INTERNAL_automaton_destroy (dfa); } error += ctx.error; return error; }
int main (int argc, char *argv[]) { int failureCount = 0; char *c; GNUNET_log_setup ("test_configuration", "WARNING", NULL); cfg = GNUNET_CONFIGURATION_create (); GNUNET_assert (cfg != NULL); if (GNUNET_OK != GNUNET_CONFIGURATION_parse (cfg, "test_configuration_data.conf")) { FPRINTF (stderr, "%s", "Failed to parse configuration file\n"); GNUNET_CONFIGURATION_destroy (cfg); return 1; } failureCount += testConfig (); if (failureCount > 0) goto error; failureCount = testConfigFilenames (); if (failureCount > 0) goto error; if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, "/tmp/gnunet-test.conf")) { FPRINTF (stderr, "%s", "Failed to write configuration file\n"); GNUNET_CONFIGURATION_destroy (cfg); return 1; } GNUNET_CONFIGURATION_destroy (cfg); GNUNET_assert (0 == UNLINK ("/tmp/gnunet-test.conf")); cfg = GNUNET_CONFIGURATION_create (); if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, "test_configuration_data.conf")) { GNUNET_break (0); GNUNET_CONFIGURATION_destroy (cfg); return 1; } if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "TESTING", "WEAKRANDOM", &c)) { GNUNET_break (0); GNUNET_CONFIGURATION_destroy (cfg); return 1; } if (0 != strcmp (c, "YES")) { GNUNET_break (0); GNUNET_free (c); GNUNET_CONFIGURATION_destroy (cfg); return 1; } GNUNET_free (c); GNUNET_CONFIGURATION_destroy (cfg); /* Testing configuration diffs */ cfgDefault = GNUNET_CONFIGURATION_create (); if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfgDefault, NULL)) { GNUNET_break (0); GNUNET_CONFIGURATION_destroy (cfgDefault); return 1; } /* Nothing changed in the new configuration */ failureCount += checkDiffs (cfgDefault, EDIT_NOTHING); /* Modify all entries of the last section */ failureCount += checkDiffs (cfgDefault, EDIT_SECTION); /* Add a new section */ failureCount += checkDiffs (cfgDefault, ADD_NEW_SECTION); /* Add a new entry to the last section */ failureCount += checkDiffs (cfgDefault, ADD_NEW_ENTRY); /* Modify all entries in the configuration */ failureCount += checkDiffs (cfgDefault, EDIT_ALL); GNUNET_CONFIGURATION_destroy (cfgDefault); error: if (failureCount != 0) { FPRINTF (stderr, "Test failed: %u\n", failureCount); return 1; } return 0; }
int main (int argc, char *argv_ign[]) { int ok = 1; char *const argv[] = { "test-statistics-api", "-c", "test_statistics_api_data.conf", "-L", "WARNING", NULL }; struct GNUNET_GETOPT_CommandLineOption options[] = { GNUNET_GETOPT_OPTION_END }; struct GNUNET_OS_Process *proc; char *binary; GNUNET_log_setup ("test_statistics_api", "WARNING", NULL); binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-statistics"); proc = GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, NULL, binary, "gnunet-service-statistics", "-c", "test_statistics_api_data.conf", NULL); GNUNET_assert (NULL != proc); GNUNET_PROGRAM_run (5, argv, "test-statistics-api", "nohelp", options, &run, &ok); if (0 != GNUNET_OS_process_kill (proc, GNUNET_TERM_SIG)) { GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); ok = 1; } GNUNET_OS_process_wait (proc); GNUNET_OS_process_destroy (proc); proc = NULL; if (ok != 0) { GNUNET_free (binary); return ok; } ok = 1; /* restart to check persistence! */ proc = GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, NULL, binary, "gnunet-service-statistics", "-c", "test_statistics_api_data.conf", NULL); GNUNET_PROGRAM_run (5, argv, "test-statistics-api", "nohelp", options, &run_more, &ok); if (0 != GNUNET_OS_process_kill (proc, GNUNET_TERM_SIG)) { GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); ok = 1; } GNUNET_OS_process_wait (proc); GNUNET_OS_process_destroy (proc); proc = NULL; GNUNET_free (binary); return ok; }
/** * Run a standard GNUnet command startup sequence (initialize loggers * and configuration, parse options). * * @param argc number of command line arguments * @param argv command line arguments * @param binaryName our expected name * @param binaryHelp help text for the program * @param options command line options * @param task main function to run * @param task_cls closure for task * @param run_without_scheduler GNUNET_NO start the scheduler, GNUNET_YES do not * start the scheduler just run the main task * @return GNUNET_SYSERR on error, GNUNET_OK on success */ int GNUNET_PROGRAM_run2 (int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls, int run_without_scheduler) { struct CommandContext cc; char *path; char *loglev; char *logfile; int ret; unsigned int cnt; unsigned long long skew_offset; unsigned long long skew_variance; long long clock_offset; struct GNUNET_CONFIGURATION_Handle *cfg; struct GNUNET_GETOPT_CommandLineOption defoptions[] = { GNUNET_GETOPT_OPTION_CFG_FILE (&cc.cfgfile), GNUNET_GETOPT_OPTION_HELP (binaryHelp), GNUNET_GETOPT_OPTION_LOGLEVEL (&loglev), GNUNET_GETOPT_OPTION_LOGFILE (&logfile), GNUNET_GETOPT_OPTION_VERSION (PACKAGE_VERSION) }; struct GNUNET_GETOPT_CommandLineOption *allopts; const char *gargs; char *lpfx; char *spc; logfile = NULL; gargs = getenv ("GNUNET_ARGS"); if (gargs != NULL) { char **gargv; unsigned int gargc; int i; char *tok; char *cargs; gargv = NULL; gargc = 0; for (i = 0; i < argc; i++) GNUNET_array_append (gargv, gargc, GNUNET_strdup (argv[i])); cargs = GNUNET_strdup (gargs); tok = strtok (cargs, " "); while (NULL != tok) { GNUNET_array_append (gargv, gargc, GNUNET_strdup (tok)); tok = strtok (NULL, " "); } GNUNET_free (cargs); GNUNET_array_append (gargv, gargc, NULL); argv = (char *const *) gargv; argc = gargc - 1; } memset (&cc, 0, sizeof (cc)); loglev = NULL; cc.task = task; cc.task_cls = task_cls; cc.cfg = cfg = GNUNET_CONFIGURATION_create (); /* prepare */ #if ENABLE_NLS setlocale (LC_ALL, ""); path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LOCALEDIR); if (path != NULL) { BINDTEXTDOMAIN ("GNUnet", path); GNUNET_free (path); } textdomain ("GNUnet"); #endif cnt = 0; while (options[cnt].name != NULL) cnt++; allopts = GNUNET_malloc ((cnt + 1) * sizeof (struct GNUNET_GETOPT_CommandLineOption) + sizeof (defoptions)); memcpy (allopts, defoptions, sizeof (defoptions)); memcpy (&allopts [sizeof (defoptions) / sizeof (struct GNUNET_GETOPT_CommandLineOption)], options, (cnt + 1) * sizeof (struct GNUNET_GETOPT_CommandLineOption)); cnt += sizeof (defoptions) / sizeof (struct GNUNET_GETOPT_CommandLineOption); qsort (allopts, cnt, sizeof (struct GNUNET_GETOPT_CommandLineOption), &cmd_sorter); loglev = NULL; cc.cfgfile = GNUNET_strdup (GNUNET_DEFAULT_USER_CONFIG_FILE); lpfx = GNUNET_strdup (binaryName); if (NULL != (spc = strstr (lpfx, " "))) *spc = '\0'; if ((-1 == (ret = GNUNET_GETOPT_run (binaryName, allopts, (unsigned int) argc, argv))) || (GNUNET_OK != GNUNET_log_setup (lpfx, loglev, logfile))) { GNUNET_CONFIGURATION_destroy (cfg); GNUNET_free_non_null (cc.cfgfile); GNUNET_free_non_null (loglev); GNUNET_free_non_null (logfile); GNUNET_free (allopts); GNUNET_free (lpfx); return GNUNET_SYSERR; } (void) GNUNET_CONFIGURATION_load (cfg, cc.cfgfile); GNUNET_free (allopts); GNUNET_free (lpfx); if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cc.cfg, "testing", "skew_offset", &skew_offset) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cc.cfg, "testing", "skew_variance", &skew_variance))) { clock_offset = skew_offset - skew_variance; GNUNET_TIME_set_offset (clock_offset); } /* run */ cc.args = &argv[ret]; if (GNUNET_NO == run_without_scheduler) { GNUNET_SCHEDULER_run (&program_main, &cc); } else { GNUNET_RESOLVER_connect (cc.cfg); cc.task (cc.task_cls, cc.args, cc.cfgfile, cc.cfg); } /* clean up */ GNUNET_SPEEDUP_stop_ (); GNUNET_CONFIGURATION_destroy (cfg); GNUNET_free_non_null (cc.cfgfile); GNUNET_free_non_null (loglev); GNUNET_free_non_null (logfile); return GNUNET_OK; }
GstBin * get_app(GNUNET_gstData *d, int type) { GstBin *bin; GstPad *pad, *ghostpad; if ( type == SOURCE ) { bin = GST_BIN(gst_bin_new("Gnunet appsrc")); GNUNET_assert (GNUNET_OK == GNUNET_log_setup ("gnunet-helper-audio-playback", "WARNING", NULL)); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Audio playback starts\n"); printf(" creating appsrc \n "); //d->audio_message.header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO); // d->audio_message = GNUNET_malloc (UINT16_MAX); // d->audio_message = (AudioMessage*)malloc(sizeof(struct AudioMessage)); // d->audio_message = GNUNET_malloc(sizeof(struct AudioMessage)); //d->audio_message.header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO); d->stdin_mst = GNUNET_SERVER_mst_create (&stdin_receiver, d); if ( d->stdin_mst == NULL) printf("stdin_mst = NULL"); d->appsrc = gst_element_factory_make ("appsrc", "appsrc"); gst_bin_add_many( bin, d->appsrc, NULL); // gst_element_link_many ( encoder, muxer, NULL); pad = gst_element_get_static_pad (d->appsrc, "src"); ghostpad = gst_ghost_pad_new ("src", pad); } if ( type == SINK ) { bin = GST_BIN(gst_bin_new("Gnunet appsink")); GNUNET_assert (GNUNET_OK == GNUNET_log_setup ("gnunet-helper-audio-record", "WARNING", NULL)); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Audio source starts\n"); d->appsink = gst_element_factory_make ("appsink", "appsink"); // Move this out of here! d->audio_message = GNUNET_malloc (UINT16_MAX); (d->audio_message)->header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO); g_object_set (G_OBJECT (d->appsink), "emit-signals", TRUE, "sync", TRUE, NULL); g_signal_connect (d->appsink, "new-sample", G_CALLBACK (on_appsink_new_sample), &d); gst_bin_add_many( bin, d->appsink, NULL); // gst_element_link_many ( encoder, muxer, NULL); pad = gst_element_get_static_pad (d->appsink, "sink"); ghostpad = gst_ghost_pad_new ("sink", pad); } /* set the bin pads */ gst_pad_set_active (ghostpad, TRUE); gst_element_add_pad (GST_ELEMENT(bin), ghostpad); gst_object_unref (pad); return bin; }
int main (int argc, char **argv) { GstElement *source, *filter, *encoder, *conv, *resampler, *sink, *oggmux; GstCaps *caps; GstBus *bus; guint bus_watch_id; struct AudioMessage audio_message; int abort_send = 0; typedef void (*SignalHandlerPointer) (int); SignalHandlerPointer inthandler, termhandler; inthandler = signal (SIGINT, signalhandler); termhandler = signal (SIGTERM, signalhandler); #ifdef DEBUG_RECORD_PURE_OGG dump_pure_ogg = getenv ("GNUNET_RECORD_PURE_OGG") ? 1 : 0; #endif #ifdef WINDOWS setmode (1, _O_BINARY); #endif /* Initialisation */ gst_init (&argc, &argv); GNUNET_assert (GNUNET_OK == GNUNET_log_setup ("gnunet-helper-audio-record", "WARNING", NULL)); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Audio source starts\n"); audio_message.header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO); /* Create gstreamer elements */ pipeline = gst_pipeline_new ("audio-recorder"); source = gst_element_factory_make ("autoaudiosrc", "audiosource"); filter = gst_element_factory_make ("capsfilter", "filter"); conv = gst_element_factory_make ("audioconvert", "converter"); resampler= gst_element_factory_make ("audioresample", "resampler"); encoder = gst_element_factory_make ("opusenc", "opus-encoder"); oggmux = gst_element_factory_make ("oggmux", "ogg-muxer"); sink = gst_element_factory_make ("appsink", "audio-output"); if (!pipeline || !filter || !source || !conv || !resampler || !encoder || !oggmux || !sink) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "One element could not be created. Exiting.\n"); return -1; } g_signal_connect (source, "child-added", G_CALLBACK (source_child_added), NULL); /* Set up the pipeline */ caps = gst_caps_new_simple ("audio/x-raw", "format", G_TYPE_STRING, "S16LE", /* "rate", G_TYPE_INT, SAMPLING_RATE,*/ "channels", G_TYPE_INT, OPUS_CHANNELS, /* "layout", G_TYPE_STRING, "interleaved",*/ NULL); g_object_set (G_OBJECT (filter), "caps", caps, NULL); gst_caps_unref (caps); g_object_set (G_OBJECT (encoder), /* "bitrate", 64000, */ /* "bandwidth", OPUS_BANDWIDTH_FULLBAND, */ "inband-fec", INBAND_FEC_MODE, "packet-loss-percentage", PACKET_LOSS_PERCENTAGE, "max-payload-size", MAX_PAYLOAD_SIZE, "audio", FALSE, /* VoIP, not audio */ "frame-size", OPUS_FRAME_SIZE, NULL); g_object_set (G_OBJECT (oggmux), "max-delay", OGG_MAX_DELAY, "max-page-delay", OGG_MAX_PAGE_DELAY, NULL); /* we add a message handler */ bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline)); bus_watch_id = gst_bus_add_watch (bus, bus_call, pipeline); gst_object_unref (bus); /* we add all elements into the pipeline */ /* audiosource | converter | resampler | opus-encoder | audio-output */ gst_bin_add_many (GST_BIN (pipeline), source, filter, conv, resampler, encoder, oggmux, sink, NULL); /* we link the elements together */ gst_element_link_many (source, filter, conv, resampler, encoder, oggmux, sink, NULL); /* Set the pipeline to "playing" state*/ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Now playing\n"); gst_element_set_state (pipeline, GST_STATE_PLAYING); GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Running...\n"); /* Iterate */ while (!abort_send) { GstSample *s; GstBuffer *b; GstMapInfo m; size_t len, msg_size; const char *ptr; int phase; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "pulling...\n"); s = gst_app_sink_pull_sample (GST_APP_SINK (sink)); if (NULL == s) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "pulled NULL\n"); break; } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "...pulled!\n"); { const GstStructure *si; char *si_str; GstCaps *s_caps; char *caps_str; si = gst_sample_get_info (s); if (si) { si_str = gst_structure_to_string (si); if (si_str) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got sample %s\n", si_str); g_free (si_str); } } else GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got sample with no info\n"); s_caps = gst_sample_get_caps (s); if (s_caps) { caps_str = gst_caps_to_string (s_caps); if (caps_str) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got sample with caps %s\n", caps_str); g_free (caps_str); } } else GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got sample with no caps\n"); } b = gst_sample_get_buffer (s); if (NULL == b || !gst_buffer_map (b, &m, GST_MAP_READ)) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "got NULL buffer %p or failed to map the buffer\n", b); gst_sample_unref (s); continue; } len = m.size; if (len > UINT16_MAX - sizeof (struct AudioMessage)) { GNUNET_break (0); len = UINT16_MAX - sizeof (struct AudioMessage); } msg_size = sizeof (struct AudioMessage) + len; audio_message.header.size = htons ((uint16_t) msg_size); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending %u bytes of audio data\n", (unsigned int) msg_size); for (phase = 0; phase < 2; phase++) { size_t offset; size_t to_send; ssize_t ret; if (0 == phase) { #ifdef DEBUG_RECORD_PURE_OGG if (dump_pure_ogg) continue; #endif ptr = (const char *) &audio_message; to_send = sizeof (audio_message); } else { ptr = (const char *) m.data; to_send = len; } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending %u bytes on phase %d\n", (unsigned int) to_send, phase); for (offset = 0; offset < to_send; offset += ret) { ret = write (1, &ptr[offset], to_send - offset); if (0 >= ret) { if (-1 == ret) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to write %u bytes at offset %u (total %u) in phase %d: %s\n", (unsigned int) to_send - offset, (unsigned int) offset, (unsigned int) (to_send + offset), phase, strerror (errno)); abort_send = 1; break; } } if (abort_send) break; } gst_buffer_unmap (b, &m); gst_sample_unref (s); } signal (SIGINT, inthandler); signal (SIGINT, termhandler); GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Returned, stopping playback\n"); quit (); GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Deleting pipeline\n"); gst_object_unref (GST_OBJECT (pipeline)); pipeline = NULL; g_source_remove (bus_watch_id); return 0; }
int main (int argc, char *argv[]) { GNUNET_log_setup ("test_statistics_api", "WARNING", NULL); return check (); }
int main (int argc, char *av[]) { static char *const argv[] = { "test-gnunet-service-arm", "-c", "test_arm_api_data.conf", NULL }; static struct GNUNET_GETOPT_CommandLineOption options[] = { GNUNET_GETOPT_OPTION_END }; char hostname[GNUNET_OS_get_hostname_max_length () + 1]; if (0 != gethostname (hostname, sizeof (hostname) - 1)) { GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "gethostname"); FPRINTF (stderr, "%s", "Failed to determine my own hostname, testcase not run.\n"); return 0; } if ( (0 == strcmp (hostname, "localhost")) || (0 == strcmp (hostname, "ipv6-localnet")) ) { /* we cannot use 'localhost' as this would not trigger the resolver service (see resolver_api.c); so in this case, we fall back to (ab)using gnu.org. */ strcpy (hostname, "www.gnu.org"); } /* trigger DNS lookup */ #if HAVE_GETADDRINFO { struct addrinfo *ai; int ret; if (0 != (ret = getaddrinfo (hostname, NULL, NULL, &ai))) { FPRINTF (stderr, "Failed to resolve my hostname `%s', testcase not run.\n", hostname); return 0; } freeaddrinfo (ai); } #elif HAVE_GETHOSTBYNAME2 { struct hostent *host; host = gethostbyname2 (hostname, AF_INET); if (NULL == host) host = gethostbyname2 (hostname, AF_INET6); if (NULL == host) { FPRINTF (stderr, "Failed to resolve my hostname `%s', testcase not run.\n", hostname); return 0; } } #elif HAVE_GETHOSTBYNAME { struct hostent *host; host = gethostbyname (hostname); if (NULL == host) { FPRINTF (stderr, "Failed to resolve my hostname `%s', testcase not run.\n", hostname); return 0; } } #else FPRINTF (stderr, "libc fails to have resolver function, testcase not run.\n"); return 0; #endif GNUNET_log_setup ("test-gnunet-service-arm", "WARNING", NULL); GNUNET_break (GNUNET_OK == GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, "test-gnunet-service-arm", "nohelp", options, &run, NULL)); if (0 != ret) { fprintf (stderr, "Test failed with error code %d\n", ret); } return ret; }
/** * Main: start test */ int main (int argc, char *argv[]) { initialized = GNUNET_NO; static const struct GNUNET_HashCode *ports[2]; const char *config_file; char port_id[] = "test port"; GNUNET_CRYPTO_hash (port_id, sizeof (port_id), &port); GNUNET_log_setup ("test", "DEBUG", NULL); config_file = "test_cadet.conf"; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Start\n"); /* Find out requested size */ if (strstr (argv[0], "_2_") != NULL) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "DIRECT CONNECTIONs\n"); peers_requested = 2; } else if (strstr (argv[0], "_5_") != NULL) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "5 PEER LINE\n"); peers_requested = 5; } else { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "SIZE UNKNOWN, USING 2\n"); peers_requested = 2; } /* Find out requested test */ if (strstr (argv[0], "_forward") != NULL) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "FORWARD\n"); test = FORWARD; test_name = "unicast"; ok_goal = 4; } else if (strstr (argv[0], "_signal") != NULL) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "SIGNAL\n"); test = P2P_SIGNAL; test_name = "signal"; ok_goal = 4; } else if (strstr (argv[0], "_speed_ack") != NULL) { /* Test is supposed to generate the following callbacks: * 1 incoming channel (@dest) * TOTAL_PACKETS received data packet (@dest) * TOTAL_PACKETS received data packet (@orig) * 1 received channel destroy (@dest) */ ok_goal = TOTAL_PACKETS * 2 + 2; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "SPEED_ACK\n"); test = SPEED_ACK; test_name = "speed ack"; } else if (strstr (argv[0], "_speed") != NULL) { /* Test is supposed to generate the following callbacks: * 1 incoming channel (@dest) * 1 initial packet (@dest) * TOTAL_PACKETS received data packet (@dest) * 1 received data packet (@orig) * 1 received channel destroy (@dest) */ ok_goal = TOTAL_PACKETS + 4; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "SPEED\n"); if (strstr (argv[0], "_reliable") != NULL) { test = SPEED_REL; test_name = "speed reliable"; config_file = "test_cadet_drop.conf"; } else { test = SPEED; test_name = "speed"; } } else if (strstr (argv[0], "_keepalive") != NULL) { test = KEEPALIVE; /* Test is supposed to generate the following callbacks: * 1 incoming channel (@dest) * [wait] * 1 received channel destroy (@dest) */ ok_goal = 2; } else { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "UNKNOWN\n"); test = SETUP; ok_goal = 0; } if (strstr (argv[0], "backwards") != NULL) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "BACKWARDS (LEAF TO ROOT)\n"); test_backwards = GNUNET_YES; GNUNET_asprintf (&test_name, "backwards %s", test_name); } p_ids = 0; ports[0] = &port; ports[1] = NULL; GNUNET_CADET_TEST_run ("test_cadet_small", config_file, peers_requested, &tmain, NULL, /* tmain cls */ &incoming_channel, &channel_cleaner, handlers, ports); if (ok_goal > ok) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "FAILED! (%d/%d)\n", ok, ok_goal); return 1; } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "success\n"); return 0; }
int main (int argc, char *argv[]) { int ok; struct GNUNET_HashCode rid1; struct GNUNET_HashCode id2; struct GNUNET_HashCode rid2; struct GNUNET_HashCode fid; struct GNUNET_HashCode id3; int old; int newVal; struct GNUNET_CONFIGURATION_Handle *cfg; char *name1; char *name2; char *name3; char *name1_unique; char *name2_unique; char *noname; int noname_is_a_dup; int notiCount, fakenotiCount; int count; static char m[1024 * 1024 * 10]; memset (m, 'b', sizeof (m)); m[sizeof (m) - 1] = '\0'; GNUNET_log_setup ("test-pseudonym", "WARNING", NULL); ok = GNUNET_YES; GNUNET_CRYPTO_random_disable_entropy_gathering (); (void) GNUNET_DISK_directory_remove ("/tmp/gnunet-pseudonym-test"); cfg = GNUNET_CONFIGURATION_create (); if (-1 == GNUNET_CONFIGURATION_parse (cfg, "test_pseudonym_data.conf")) { GNUNET_CONFIGURATION_destroy (cfg); GNUNET_break (0); return -1; } notiCount = 0; fakenotiCount = 0; count = 0; GNUNET_PSEUDONYM_discovery_callback_register (cfg, &fake_noti_callback, &fakenotiCount); GNUNET_PSEUDONYM_discovery_callback_register (cfg, ¬i_callback, ¬iCount); GNUNET_PSEUDONYM_discovery_callback_unregister (&false_callback, &count); GNUNET_PSEUDONYM_discovery_callback_unregister (&fake_noti_callback, &fakenotiCount); /* ACTUAL TEST CODE */ old = GNUNET_PSEUDONYM_list_all (cfg, NULL, NULL); meta = GNUNET_CONTAINER_meta_data_create (); GNUNET_CONTAINER_meta_data_insert (meta, "<test>", EXTRACTOR_METATYPE_TITLE, EXTRACTOR_METAFORMAT_UTF8, "text/plain", "test", strlen ("test") + 1); GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &id1); GNUNET_PSEUDONYM_add (cfg, &id1, meta); CHECK (notiCount == 1); GNUNET_PSEUDONYM_add (cfg, &id1, meta); CHECK (notiCount == 2); newVal = GNUNET_PSEUDONYM_list_all (cfg, &iter, &ok); CHECK (old < newVal); old = newVal; GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &id2); GNUNET_PSEUDONYM_add (cfg, &id2, meta); CHECK (notiCount == 3); newVal = GNUNET_PSEUDONYM_list_all (cfg, &iter, &ok); CHECK (old < newVal); GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_meta_data_insert (meta, "<test>", EXTRACTOR_METATYPE_COMMENT, EXTRACTOR_METAFORMAT_UTF8, "text/plain", m, strlen (m) + 1)); GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &id3); GNUNET_PSEUDONYM_add (cfg, &id3, meta); GNUNET_PSEUDONYM_get_info (cfg, &id3, NULL, NULL, &name3, NULL); CHECK (name3 != NULL); GNUNET_PSEUDONYM_get_info (cfg, &id2, NULL, NULL, &name2, NULL); CHECK (name2 != NULL); GNUNET_PSEUDONYM_get_info (cfg, &id1, NULL, NULL, &name1, NULL); CHECK (name1 != NULL); CHECK (0 == strcmp (name1, name2)); name1_unique = GNUNET_PSEUDONYM_name_uniquify (cfg, &id1, name1, NULL); name2_unique = GNUNET_PSEUDONYM_name_uniquify (cfg, &id2, name2, NULL); CHECK (0 != strcmp (name1_unique, name2_unique)); CHECK (GNUNET_SYSERR == GNUNET_PSEUDONYM_name_to_id (cfg, "fake", &rid2)); CHECK (GNUNET_SYSERR == GNUNET_PSEUDONYM_name_to_id (cfg, name2, &rid2)); CHECK (GNUNET_SYSERR == GNUNET_PSEUDONYM_name_to_id (cfg, name1, &rid1)); CHECK (GNUNET_OK == GNUNET_PSEUDONYM_name_to_id (cfg, name2_unique, &rid2)); CHECK (GNUNET_OK == GNUNET_PSEUDONYM_name_to_id (cfg, name1_unique, &rid1)); CHECK (0 == memcmp (&id1, &rid1, sizeof (struct GNUNET_HashCode))); CHECK (0 == memcmp (&id2, &rid2, sizeof (struct GNUNET_HashCode))); GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &fid); GNUNET_log_skip (1, GNUNET_NO); CHECK (0 == GNUNET_PSEUDONYM_rank (cfg, &fid, 0)); GNUNET_log_skip (0, GNUNET_YES); CHECK (GNUNET_OK == GNUNET_PSEUDONYM_get_info (cfg, &fid, NULL, NULL, &noname, &noname_is_a_dup)); CHECK (noname != NULL); CHECK (noname_is_a_dup == GNUNET_YES); CHECK (0 == GNUNET_PSEUDONYM_rank (cfg, &id1, 0)); CHECK (5 == GNUNET_PSEUDONYM_rank (cfg, &id1, 5)); CHECK (-5 == GNUNET_PSEUDONYM_rank (cfg, &id1, -10)); CHECK (0 == GNUNET_PSEUDONYM_rank (cfg, &id1, 5)); GNUNET_free (name1); GNUNET_free (name2); GNUNET_free (name1_unique); GNUNET_free (name2_unique); GNUNET_free (name3); GNUNET_free (noname); /* END OF TEST CODE */ FAILURE: GNUNET_PSEUDONYM_discovery_callback_unregister (¬i_callback, ¬iCount); GNUNET_CONTAINER_meta_data_destroy (meta); GNUNET_CONFIGURATION_destroy (cfg); GNUNET_break (GNUNET_OK == GNUNET_DISK_directory_remove ("/tmp/gnunet-pseudonym-test")); return (ok == GNUNET_YES) ? 0 : 1; }
/** * Run a standard GNUnet service startup sequence (initialize loggers * and configuration, parse options). * * @param argc number of command line arguments * @param argv command line arguments * @param service_name our service name * @param options service options * @param task main task of the service * @param task_cls closure for @a task * @return #GNUNET_SYSERR on error, #GNUNET_OK * if we shutdown nicely */ int GNUNET_SERVICE_run (int argc, char *const *argv, const char *service_name, enum GNUNET_SERVICE_Options options, GNUNET_SERVICE_Main task, void *task_cls) { #define HANDLE_ERROR do { GNUNET_break (0); goto shutdown; } while (0) int err; int ret; char *cfg_fn; char *opt_cfg_fn; char *loglev; char *logfile; int do_daemonize; unsigned int i; unsigned long long skew_offset; unsigned long long skew_variance; long long clock_offset; struct GNUNET_SERVICE_Context sctx; struct GNUNET_CONFIGURATION_Handle *cfg; const char *xdg; struct GNUNET_GETOPT_CommandLineOption service_options[] = { GNUNET_GETOPT_OPTION_CFG_FILE (&opt_cfg_fn), {'d', "daemonize", NULL, gettext_noop ("do daemonize (detach from terminal)"), 0, GNUNET_GETOPT_set_one, &do_daemonize}, GNUNET_GETOPT_OPTION_HELP (NULL), GNUNET_GETOPT_OPTION_LOGLEVEL (&loglev), GNUNET_GETOPT_OPTION_LOGFILE (&logfile), GNUNET_GETOPT_OPTION_VERSION (PACKAGE_VERSION " " VCS_VERSION), GNUNET_GETOPT_OPTION_END }; err = 1; do_daemonize = 0; logfile = NULL; loglev = NULL; opt_cfg_fn = NULL; xdg = getenv ("XDG_CONFIG_HOME"); if (NULL != xdg) GNUNET_asprintf (&cfg_fn, "%s%s%s", xdg, DIR_SEPARATOR_STR, "gnunet.conf"); else cfg_fn = GNUNET_strdup (GNUNET_DEFAULT_USER_CONFIG_FILE); memset (&sctx, 0, sizeof (sctx)); sctx.options = options; sctx.ready_confirm_fd = -1; sctx.ret = GNUNET_OK; sctx.timeout = GNUNET_TIME_UNIT_FOREVER_REL; sctx.task = task; sctx.task_cls = task_cls; sctx.service_name = service_name; sctx.cfg = cfg = GNUNET_CONFIGURATION_create (); /* setup subsystems */ ret = GNUNET_GETOPT_run (service_name, service_options, argc, argv); if (GNUNET_SYSERR == ret) goto shutdown; if (GNUNET_NO == ret) { err = 0; goto shutdown; } if (GNUNET_OK != GNUNET_log_setup (service_name, loglev, logfile)) HANDLE_ERROR; if (NULL == opt_cfg_fn) opt_cfg_fn = GNUNET_strdup (cfg_fn); if (GNUNET_YES == GNUNET_DISK_file_test (opt_cfg_fn)) { if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, opt_cfg_fn)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Malformed configuration file `%s', exit ...\n"), opt_cfg_fn); goto shutdown; } } else { if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, NULL)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Malformed configuration, exit ...\n")); goto shutdown; } if (0 != strcmp (opt_cfg_fn, cfg_fn)) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Could not access configuration file `%s'\n"), opt_cfg_fn); } if (GNUNET_OK != setup_service (&sctx)) goto shutdown; if ((1 == do_daemonize) && (GNUNET_OK != detach_terminal (&sctx))) HANDLE_ERROR; if (GNUNET_OK != set_user_id (&sctx)) goto shutdown; LOG (GNUNET_ERROR_TYPE_DEBUG, "Service `%s' runs with configuration from `%s'\n", service_name, opt_cfg_fn); if ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (sctx.cfg, "TESTING", "SKEW_OFFSET", &skew_offset)) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (sctx.cfg, "TESTING", "SKEW_VARIANCE", &skew_variance))) { clock_offset = skew_offset - skew_variance; GNUNET_TIME_set_offset (clock_offset); LOG (GNUNET_ERROR_TYPE_DEBUG, "Skewing clock by %dll ms\n", clock_offset); } /* actually run service */ err = 0; GNUNET_SCHEDULER_run (&service_task, &sctx); /* shutdown */ if ((1 == do_daemonize) && (NULL != sctx.server)) pid_file_delete (&sctx); GNUNET_free_non_null (sctx.my_handlers); shutdown: if (-1 != sctx.ready_confirm_fd) { if (1 != WRITE (sctx.ready_confirm_fd, err ? "I" : "S", 1)) LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "write"); GNUNET_break (0 == CLOSE (sctx.ready_confirm_fd)); } #if HAVE_MALLINFO { char *counter; if ( (GNUNET_YES == GNUNET_CONFIGURATION_have_value (sctx.cfg, service_name, "GAUGER_HEAP")) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (sctx.cfg, service_name, "GAUGER_HEAP", &counter)) ) { struct mallinfo mi; mi = mallinfo (); GAUGER (service_name, counter, mi.usmblks, "blocks"); GNUNET_free (counter); } } #endif GNUNET_SPEEDUP_stop_ (); GNUNET_CONFIGURATION_destroy (cfg); i = 0; if (NULL != sctx.addrs) while (NULL != sctx.addrs[i]) GNUNET_free (sctx.addrs[i++]); GNUNET_free_non_null (sctx.addrs); GNUNET_free_non_null (sctx.addrlens); GNUNET_free_non_null (logfile); GNUNET_free_non_null (loglev); GNUNET_free (cfg_fn); GNUNET_free_non_null (opt_cfg_fn); GNUNET_free_non_null (sctx.v4_denied); GNUNET_free_non_null (sctx.v6_denied); GNUNET_free_non_null (sctx.v4_allowed); GNUNET_free_non_null (sctx.v6_allowed); return err ? GNUNET_SYSERR : sctx.ret; }
int main (int argc, char *argv[]) { int ok; int status; const char *socksport = "1081"; GNUNET_log_setup ("test_client", "WARNING", NULL); pid_t pid = fork(); GNUNET_assert (pid >= 0); if (pid == 0) { execlp ("ssh", "ssh","-D",socksport, "-o","BatchMode yes", "-o","UserKnownHostsFile /tmp/gnunet_test_socks_ssh_garbage", "-o","StrictHostKeyChecking no", "127.0.0.1","-N",(char*)NULL); perror ("execlp (\"ssh\",\"ssh\",...,\"-D\",\"1081\",\"127.0.0.1\",\"-N\") "); printf ("" "Please ensure you have ssh installed and have sshd installed and running :\n" "\tsudo apt-get install openssh-client openssh-server\n" "If you run Tor as a network proxy then Tor might prevent ssh from connecting\n" "to localhost. Please either run make check from an unproxied user, or else\n" "add these lines to the beginning of your ~/.ssh/config file :" "\tHost 127.0.0.1 localhost\n" "\t CheckHostIP no\n" "\t Protocol 2\n" "\t ProxyCommand nc 127.0.0.1 22\n"); kill (getppid(), SIGALRM); return 1; } if (0 != sleep (1)) { /* sleep interrupted, likely SIGALRM, failure to launch child, terminate */ printf ("" "Please ensure you have ssh installed and have sshd installed and running :\n" "\tsudo apt-get install openssh-client openssh-server\n" "If you run Tor as a network proxy then Tor might prevent ssh from connecting\n" "to localhost. Please either run make check from an unproxied user, or else\n" "add these lines to the beginning of your ~/.ssh/config file :" "\tHost 127.0.0.1 localhost\n" "\t CheckHostIP no\n" "\t Protocol 2\n" "\t ProxyCommand nc 127.0.0.1 22\n"); return 77; } /* check if child exec()ed but died */ if (0 != waitpid (pid, &status, WNOHANG)) { printf ("" "If you run Tor as a network proxy then Tor might prevent ssh from connecting\n" "to localhost. Please either run make check from an unproxied user, or else\n" "add these lines to the beginning of your ~/.ssh/config file :" "\tHost 127.0.0.1 localhost\n" "\t CheckHostIP no\n" "\t Protocol 2\n" "\t ProxyCommand nc 127.0.0.1 22\n"); return 77; } cfg = GNUNET_CONFIGURATION_create (); GNUNET_CONFIGURATION_set_value_string (cfg, MYNAME, "SOCKSHOST", "127.0.0.1"); GNUNET_CONFIGURATION_set_value_string (cfg, MYNAME, "SOCKSPORT", socksport); GNUNET_CONFIGURATION_set_value_number (cfg, MYNAME, "PORT", PORT); GNUNET_CONFIGURATION_set_value_string (cfg, MYNAME, "HOSTNAME", "127.0.0.1"); ok = 1; GNUNET_SCHEDULER_run (&task, &ok); GNUNET_CONFIGURATION_destroy (cfg); GNUNET_break (0 == kill (pid, SIGTERM)); GNUNET_break (pid == waitpid (pid, &status, 0)); return ok; }
int main (int argc, char *argv[]) { int error; struct REGEX_INTERNAL_Automaton *a; unsigned int i; const char *filename = "test_graph.dot"; const char *regex[12] = { "ab(c|d)+c*(a(b|c)+d)+(bla)+", "(bla)*", "b(lab)*la", "(ab)*", "ab(c|d)+c*(a(b|c)+d)+(bla)(bla)*", "z(abc|def)?xyz", "1*0(0|1)*", "a*b*", "a+X*y+c|p|R|Z*K*y*R+w|Y*6+n+h*k*w+V*F|W*B*e*", "a", "a|b", "PADPADPADPADPADPabcdefghixxxxxxxxxxxxxjklmnop*qstoisdjfguisdfguihsdfgbdsuivggsd" }; GNUNET_log_setup ("test-regex", "WARNING", NULL); error = 0; for (i = 0; i < 12; i++) { /* Check NFA graph creation */ a = REGEX_INTERNAL_construct_nfa (regex[i], strlen (regex[i])); REGEX_TEST_automaton_save_graph (a, filename, REGEX_TEST_GRAPH_DEFAULT); REGEX_INTERNAL_automaton_destroy (a); error += filecheck (filename); a = REGEX_INTERNAL_construct_nfa (regex[i], strlen (regex[i])); REGEX_TEST_automaton_save_graph (a, filename, REGEX_TEST_GRAPH_DEFAULT | REGEX_TEST_GRAPH_VERBOSE); REGEX_INTERNAL_automaton_destroy (a); error += filecheck (filename); a = REGEX_INTERNAL_construct_nfa (regex[i], strlen (regex[i])); REGEX_TEST_automaton_save_graph (a, filename, REGEX_TEST_GRAPH_DEFAULT | REGEX_TEST_GRAPH_COLORING); REGEX_INTERNAL_automaton_destroy (a); error += filecheck (filename); a = REGEX_INTERNAL_construct_nfa (regex[i], strlen (regex[i])); REGEX_TEST_automaton_save_graph (a, filename, REGEX_TEST_GRAPH_DEFAULT | REGEX_TEST_GRAPH_VERBOSE | REGEX_TEST_GRAPH_COLORING); REGEX_INTERNAL_automaton_destroy (a); error += filecheck (filename); /* Check DFA graph creation */ a = REGEX_INTERNAL_construct_dfa (regex[i], strlen (regex[i]), 0); REGEX_TEST_automaton_save_graph (a, filename, REGEX_TEST_GRAPH_DEFAULT); REGEX_INTERNAL_automaton_destroy (a); error += filecheck (filename); a = REGEX_INTERNAL_construct_dfa (regex[i], strlen (regex[i]), 0); REGEX_TEST_automaton_save_graph (a, filename, REGEX_TEST_GRAPH_DEFAULT | REGEX_TEST_GRAPH_VERBOSE); REGEX_INTERNAL_automaton_destroy (a); error += filecheck (filename); a = REGEX_INTERNAL_construct_dfa (regex[i], strlen (regex[i]), 0); REGEX_TEST_automaton_save_graph (a, filename, REGEX_TEST_GRAPH_DEFAULT | REGEX_TEST_GRAPH_COLORING); REGEX_INTERNAL_automaton_destroy (a); error += filecheck (filename); a = REGEX_INTERNAL_construct_dfa (regex[i], strlen (regex[i]), 4); REGEX_TEST_automaton_save_graph (a, filename, REGEX_TEST_GRAPH_DEFAULT); REGEX_INTERNAL_automaton_destroy (a); error += filecheck (filename); } return error; }
int main (int argc, char *argv[]) { struct GNUNET_DISK_FileHandle *fh; struct GNUNET_HELLO_Message *orig; struct GNUNET_HELLO_Message *result; struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pk; uint64_t fsize; GNUNET_log_setup ("gnunet-hello", "INFO", NULL); if (argc != 2) { FPRINTF (stderr, "%s", _("Call with name of HELLO file to modify.\n")); return 1; } if (GNUNET_OK != GNUNET_DISK_file_size (argv[1], &fsize, GNUNET_YES, GNUNET_YES)) { FPRINTF (stderr, _("Error accessing file `%s': %s\n"), argv[1], STRERROR (errno)); return 1; } if (fsize > 65536) { FPRINTF (stderr, _("File `%s' is too big to be a HELLO\n"), argv[1]); return 1; } if (fsize < sizeof (struct GNUNET_MessageHeader)) { FPRINTF (stderr, _("File `%s' is too small to be a HELLO\n"), argv[1]); return 1; } fh = GNUNET_DISK_file_open (argv[1], GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_USER_READ); if (NULL == fh) { FPRINTF (stderr, _("Error opening file `%s': %s\n"), argv[1], STRERROR (errno)); return 1; } { char buf[fsize] GNUNET_ALIGN; GNUNET_assert (fsize == GNUNET_DISK_file_read (fh, buf, fsize)); GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh)); orig = (struct GNUNET_HELLO_Message *) buf; if ( (fsize != GNUNET_HELLO_size (orig)) || (GNUNET_OK != GNUNET_HELLO_get_key (orig, &pk)) ) { FPRINTF (stderr, _("Did not find well-formed HELLO in file `%s'\n"), argv[1]); return 1; } result = GNUNET_HELLO_create (&pk, &add_from_hello, &orig); GNUNET_assert (NULL != result); fh = GNUNET_DISK_file_open (argv[1], GNUNET_DISK_OPEN_WRITE, GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE); if (NULL == fh) { FPRINTF (stderr, _("Error opening file `%s': %s\n"), argv[1], STRERROR (errno)); GNUNET_free (result); return 1; } fsize = GNUNET_HELLO_size (result); if (fsize != GNUNET_DISK_file_write (fh, result, fsize)) { FPRINTF (stderr, _("Error writing HELLO to file `%s': %s\n"), argv[1], STRERROR (errno)); (void) GNUNET_DISK_file_close (fh); return 1; } GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh)); } return 0; }