58 static char *pngfilename = NULL;
79 #define LOG(fmt, ...) \
84 GNUNET_log (GNUNET_ERROR_TYPE_INFO, fmt, ##__VA_ARGS__); \
87 fprintf (stdout, fmt, ##__VA_ARGS__); \
120 long unsigned int code)
130 fprintf (stdout,
_(
"Failed to add URI %s\n"),
uri);
134 fprintf (stdout,
_(
"Added URI %s\n"),
uri);
156 const char *cursor =
uri;
158 if (0 != strncasecmp (
"gnunet://",
uri, strlen (
"gnunet://")))
161 _(
"Invalid URI: does not start with `gnunet://'\n"));
166 cursor += strlen (
"gnunet://");
168 const char *slash = strchr (cursor,
'/');
171 fprintf (stderr,
_(
"Invalid URI: fails to specify a subsystem\n"));
177 char *program = NULL;
182 fprintf (stderr,
_(
"No known handler for subsystem `%s'\n"),
subsystem);
190 char **childargv = NULL;
191 unsigned int childargc = 0;
193 for (
const char *token=strtok (program,
" ");
195 token=strtok(NULL,
" "))
208 for (
size_t i=0; i<childargc-1; ++i)
218 _(
"Unable to start child process `%s'\n"),
234 static const zbar_symbol_t *
237 if (0 != zbar_processor_parse_config (
proc,
"enable"))
243 int r = zbar_processor_init (
proc,
device, 1);
247 _(
"Failed to open device: `%s': %d\n"),
253 r = zbar_processor_set_visible (
proc, 1);
254 r += zbar_processor_set_active (
proc, 1);
261 LOG (
_(
"Capturing...\n"));
263 int n = zbar_process_one (
proc, -1);
265 zbar_processor_set_active (
proc, 0);
266 zbar_processor_set_visible (
proc, 0);
270 LOG (
_(
"No captured images\n"));
274 LOG(
_(
"Got %d images\n"), n);
276 const zbar_symbol_set_t *symbols = zbar_processor_get_results (
proc);
283 return zbar_symbol_set_first_symbol (symbols);
294 zbar_processor_t *
proc = zbar_processor_create (1);
309 zbar_processor_destroy (
proc);
313 const char *
data = zbar_symbol_get_data (symbol);
317 zbar_processor_destroy (
proc);
321 LOG (
_(
"Found %s: \"%s\"\n"),
322 zbar_get_symbol_name (zbar_symbol_get_type (symbol)),
327 zbar_processor_destroy (
proc);
341 png_parse (uint32_t *width, uint32_t *height)
343 if (NULL == width || NULL == height)
348 FILE *pngfile = fopen (pngfilename,
"rb");
354 unsigned char header[8];
355 if (8 != fread (header, 1, 8, pngfile))
361 if (png_sig_cmp (header, 0, 8))
365 _(
"%s is not a PNG file\n"),
367 fprintf (stderr,
_(
"%s is not a PNG file\n"), pngfilename);
373 png_structp png = png_create_read_struct (PNG_LIBPNG_VER_STRING,
384 png_infop pnginfo = png_create_info_struct (png);
388 png_destroy_read_struct (&png, NULL, NULL);
393 if (setjmp (png_jmpbuf (png)))
396 png_destroy_read_struct (&png, &pnginfo, NULL);
401 png_init_io (png, pngfile);
402 png_set_sig_bytes (png, 8);
404 png_read_info (png, pnginfo);
406 png_byte pngcolor = png_get_color_type (png, pnginfo);
407 png_byte pngdepth = png_get_bit_depth (png, pnginfo);
410 if (0 != (pngcolor & PNG_COLOR_TYPE_PALETTE))
412 png_set_palette_to_rgb (png);
415 if (pngcolor == PNG_COLOR_TYPE_GRAY && pngdepth < 8)
417 png_set_expand_gray_1_2_4_to_8 (png);
422 png_set_strip_16 (png);
425 if (0 != (pngcolor & PNG_COLOR_MASK_ALPHA))
427 png_set_strip_alpha (png);
430 if (0 != (pngcolor & PNG_COLOR_MASK_COLOR))
432 png_set_rgb_to_gray_fixed (png, 1, -1, -1);
435 png_uint_32 pngwidth = png_get_image_width (png, pnginfo);
436 png_uint_32 pngheight = png_get_image_height (png, pnginfo);
441 for (png_uint_32 i=0; i<pngheight; ++i)
443 rows[i] = (
unsigned char *)buffer + (pngwidth * i);
446 png_read_image (png, rows);
463 run_png_reader (
void)
467 char *buffer = png_parse (&width, &height);
473 zbar_image_scanner_t *scanner = zbar_image_scanner_create ();
474 zbar_image_scanner_set_config (scanner,0, ZBAR_CFG_ENABLE, 1);
476 zbar_image_t *zimage = zbar_image_create ();
477 zbar_image_set_format (zimage, zbar_fourcc (
'Y',
'8',
'0',
'0'));
478 zbar_image_set_size (zimage, width, height);
479 zbar_image_set_data (zimage, buffer, width * height, &zbar_image_free_data);
481 int n = zbar_scan_image (scanner, zimage);
485 LOG (
_(
"No captured images\n"));
489 LOG(
_(
"Got %d images\n"), n);
491 const zbar_symbol_t *symbol = zbar_image_first_symbol (zimage);
493 const char *
data = zbar_symbol_get_data (symbol);
497 zbar_image_destroy (zimage);
498 zbar_image_scanner_destroy (scanner);
502 LOG (
_(
"Found %s: \"%s\"\n"),
503 zbar_get_symbol_name (zbar_symbol_get_type (symbol)),
508 zbar_image_destroy (zimage);
509 zbar_image_scanner_destroy (scanner);
534 if (NULL != pngfilename)
536 data = run_png_reader ();
546 LOG (
_(
"No data found\n"));
556 fprintf (stdout,
_(
"Failed to add URI %s\n"),
data);
562 LOG (
_(
"Dispatching the URI\n"));
566 main (
int argc,
char *
const *argv)
573 gettext_noop (
"use the video device DEVICE (defaults to /dev/video0)"),
591 gettext_noop (
"Scan a QR code and import the URI read"),
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
struct GNUNET_GETOPT_CommandLineOption options[]
#define gettext_noop(String)
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
static int ret
Return value of the commandline.
uint32_t data
The data 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 char * run_zbar(void)
Run the zbar QR code parser.
static unsigned int verbosity
Requested verbosity.
static const zbar_symbol_t * get_symbol(zbar_processor_t *proc)
Obtain a QR code symbol from proc.
#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.
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.
int main(int argc, char *const *argv)
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.
struct GNUNET_OS_Process * childproc
Child process handle.
static struct GNUNET_ChildWaitHandle * waitchildproc
Child process handle for waiting.
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.
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.
GNUNET_GenericReturnValue
Named constants for return values.
struct GNUNET_ChildWaitHandle * GNUNET_wait_child(struct GNUNET_OS_Process *proc, GNUNET_ChildCompletedCallback cb, void *cb_cls)
Starts the handling of the child processes.
#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
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_array_grow(arr, size, tsize)
Grow a well-typed (!) array.
#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_array_append(arr, len, element)
Append an element to an array (growing the array by one).
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_OS_Process * GNUNET_OS_start_process_vap(enum GNUNET_OS_InheritStdioFlags std_inheritance, struct GNUNET_DISK_PipeHandle *pipe_stdin, struct GNUNET_DISK_PipeHandle *pipe_stdout, struct GNUNET_DISK_PipeHandle *pipe_stderr, const char *filename, char *const argv[])
Start a process.
GNUNET_OS_ProcessStatusType
Process status types.
void GNUNET_OS_process_destroy(struct GNUNET_OS_Process *proc)
Cleans up process structure contents (OS-dependent) and deallocates it.
int GNUNET_OS_process_kill(struct GNUNET_OS_Process *proc, int sig)
Sends a signal to the process.
@ 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(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_OS_Process * proc
Child process which is managed.
Definition of a command line option.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model