58static char *pngfilename;
79#define LOG(fmt, ...) \
84 GNUNET_log (GNUNET_ERROR_TYPE_INFO, fmt, ## __VA_ARGS__); \
87 fprintf (stdout, fmt, ## __VA_ARGS__); \
123 long unsigned int code)
133 _ (
"Failed to add URI %s\n"),
139 _ (
"Added URI %s\n"),
161 const char *cursor =
uri;
165 if (0 != strncasecmp (
"gnunet://",
167 strlen (
"gnunet://")))
170 _ (
"Invalid URI: does not start with `gnunet://'\n"));
175 cursor += strlen (
"gnunet://");
177 slash = strchr (cursor,
182 _ (
"Invalid URI: fails to specify a subsystem\n"));
199 _ (
"No known handler for subsystem `%s'\n"),
221 _ (
"Unable to start child process `%s'\n"),
244static const zbar_symbol_t *
247 const zbar_symbol_set_t *symbols;
250 if (0 != zbar_processor_parse_config (
proc,
"enable"))
260 _ (
"Failed to open device: `%s': %d\n"),
266 r = zbar_processor_set_visible (
proc, 1);
267 r += zbar_processor_set_active (
proc, 1);
274 LOG (
_ (
"Capturing...\n"));
276 n = zbar_process_one (
proc, -1);
278 zbar_processor_set_active (
proc, 0);
279 zbar_processor_set_visible (
proc, 0);
283 LOG (
_ (
"No captured images\n"));
287 LOG (
_ (
"Got %d images\n"), n);
289 symbols = zbar_processor_get_results (
proc);
296 return zbar_symbol_set_first_symbol (symbols);
308 zbar_processor_t *
proc = zbar_processor_create (1);
309 const zbar_symbol_t *symbol;
327 zbar_processor_destroy (
proc);
331 data = zbar_symbol_get_data (symbol);
335 zbar_processor_destroy (
proc);
339 LOG (
_ (
"Found %s: \"%s\"\n"),
340 zbar_get_symbol_name (zbar_symbol_get_type (symbol)),
345 zbar_processor_destroy (
proc);
360png_parse (uint32_t *width, uint32_t *height)
362 if (NULL == width || NULL == height)
367 FILE *pngfile = fopen (pngfilename,
"rb");
373 unsigned char header[8];
374 if (8 != fread (header, 1, 8, pngfile))
380 if (png_sig_cmp (header, 0, 8))
384 _ (
"%s is not a PNG file\n"),
386 fprintf (stderr,
_ (
"%s is not a PNG file\n"), pngfilename);
392 png_structp png = png_create_read_struct (PNG_LIBPNG_VER_STRING,
403 png_infop pnginfo = png_create_info_struct (png);
407 png_destroy_read_struct (&png, NULL, NULL);
412 if (setjmp (png_jmpbuf (png)))
415 png_destroy_read_struct (&png, &pnginfo, NULL);
420 png_init_io (png, pngfile);
421 png_set_sig_bytes (png, 8);
423 png_read_info (png, pnginfo);
425 png_byte pngcolor = png_get_color_type (png, pnginfo);
426 png_byte pngdepth = png_get_bit_depth (png, pnginfo);
429 if (0 != (pngcolor & PNG_COLOR_TYPE_PALETTE))
431 png_set_palette_to_rgb (png);
434 if (pngcolor == PNG_COLOR_TYPE_GRAY && pngdepth < 8)
436 png_set_expand_gray_1_2_4_to_8 (png);
441 png_set_strip_16 (png);
444 if (0 != (pngcolor & PNG_COLOR_MASK_ALPHA))
446 png_set_strip_alpha (png);
449 if (0 != (pngcolor & PNG_COLOR_MASK_COLOR))
451 png_set_rgb_to_gray_fixed (png, 1, -1, -1);
454 png_uint_32 pngwidth = png_get_image_width (png, pnginfo);
455 png_uint_32 pngheight = png_get_image_height (png, pnginfo);
460 for (png_uint_32 i = 0; i<pngheight; ++i)
462 rows[i] = (
unsigned char *) buffer + (pngwidth * i);
465 png_read_image (png, rows);
487 char *buffer = png_parse (&width, &height);
493 zbar_image_scanner_t *scanner = zbar_image_scanner_create ();
494 zbar_image_scanner_set_config (scanner,0, ZBAR_CFG_ENABLE, 1);
496 zbar_image_t *zimage = zbar_image_create ();
497 zbar_image_set_format (zimage, zbar_fourcc (
'Y',
'8',
'0',
'0'));
498 zbar_image_set_size (zimage, width, height);
499 zbar_image_set_data (zimage, buffer, width * height, &zbar_image_free_data);
501 int n = zbar_scan_image (scanner, zimage);
505 LOG (
_ (
"No captured images\n"));
509 LOG (
_ (
"Got %d images\n"), n);
511 const zbar_symbol_t *symbol = zbar_image_first_symbol (zimage);
513 const char *
data = zbar_symbol_get_data (symbol);
517 zbar_image_destroy (zimage);
518 zbar_image_scanner_destroy (scanner);
522 LOG (
_ (
"Found %s: \"%s\"\n"),
523 zbar_get_symbol_name (zbar_symbol_get_type (symbol)),
528 zbar_image_destroy (zimage);
529 zbar_image_scanner_destroy (scanner);
556 if (NULL != pngfilename)
558 data = run_png_reader ();
568 LOG (
_ (
"No data found\n"));
578 fprintf (stdout,
_ (
"Failed to add URI %s\n"),
data);
584 LOG (
_ (
"Dispatching the URI\n"));
589main (
int argc,
char *
const *argv)
596 gettext_noop (
"use the video device DEVICE (defaults to /dev/video0)"),
615 gettext_noop (
"Scan a QR code and import the URI read"),
struct GNUNET_GETOPT_CommandLineOption options[]
int main()
Program to simulate results from GCP_get_desirability_of_path() for various plausible inputs.
#define gettext_noop(String)
static int ret
Final status code.
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
static char * data
The data to insert into the dht.
static uint32_t type
Type string converted to DNS type value.
static struct GNUNET_FS_Uri * uri
Value of URI provided on command-line (when not publishing a file but just creating UBlocks to refer ...
static unsigned int verbosity
Requested verbosity.
#define LOG(fmt,...)
Macro to handle verbosity when printing messages.
static void shutdown_program(void *cls)
Executed when program is terminating.
static void wait_child(void *cls, enum GNUNET_OS_ProcessStatusType type, long unsigned int code)
Callback executed when the child process terminates.
struct GNUNET_Process * childproc
Child process handle.
static int exit_code
Global exit code.
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
Main function executed by the scheduler.
static void handle_uri(void *cls, const char *uri, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
Dispatch URIs to the appropriate GNUnet helper process.
static char * run_zbar(void)
Run the zbar QR code parser.
static struct GNUNET_ChildWaitHandle * waitchildproc
Child process handle for waiting.
static const zbar_symbol_t * get_symbol(zbar_processor_t *proc)
Obtain a QR code symbol from proc.
static char * device
Video device to capture from.
static char * subsystem
Set to subsystem that we're going to get stats for (or NULL for all).
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
#define GNUNET_GETOPT_OPTION_END
Marker for the end of the list of options.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_verbose(unsigned int *level)
Define the '-V' verbosity option.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_string(char shortName, const char *name, const char *argumentHelp, const char *description, char **str)
Allow user to specify a string.
#define GNUNET_log(kind,...)
void GNUNET_wait_child_cancel(struct GNUNET_ChildWaitHandle *cwh)
Stop waiting on this child.
struct GNUNET_ChildWaitHandle * GNUNET_wait_child(struct GNUNET_Process *proc, GNUNET_ChildCompletedCallback cb, void *cb_cls)
Starts the handling of the child processes.
GNUNET_GenericReturnValue
Named constants for return values.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_ERROR
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_strndup(a, length)
Wrapper around GNUNET_xstrndup_.
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_gnunet(void)
Return default project data used by 'libgnunetutil' for GNUnet.
enum GNUNET_GenericReturnValue GNUNET_process_run_command(struct GNUNET_Process *p, const char *command)
Set the command and start a process.
void GNUNET_process_destroy(struct GNUNET_Process *proc)
Cleans up process structure contents (OS-dependent) and deallocates it.
GNUNET_OS_ProcessStatusType
Process status types.
enum GNUNET_GenericReturnValue GNUNET_process_kill(struct GNUNET_Process *proc, int sig)
Sends a signal to the process.
struct GNUNET_Process * GNUNET_process_create(enum GNUNET_OS_InheritStdioFlags std_inheritance)
Create a process handle.
@ GNUNET_OS_INHERIT_STD_ALL
Use this option to have all of the standard streams (stdin, stdout and stderror) be inherited.
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run(const struct GNUNET_OS_ProjectData *pd, int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls)
Run a standard GNUnet command startup sequence (initialize loggers and configuration,...
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received,...
Struct which defines a Child Wait handle.
struct GNUNET_Process * proc
Child process which is managed.
Definition of a command line option.