58static char *pngfilename = NULL;
79#define LOG(fmt, ...) \
84 GNUNET_log (GNUNET_ERROR_TYPE_INFO, fmt, ## __VA_ARGS__); \
87 fprintf (stdout, fmt, ## __VA_ARGS__); \
121 long unsigned int code)
131 fprintf (stdout,
_ (
"Failed to add URI %s\n"),
uri);
135 fprintf (stdout,
_ (
"Added URI %s\n"),
uri);
158 const char *cursor =
uri;
161 char *program = NULL;
163 if (0 != strncasecmp (
"gnunet://",
uri, strlen (
"gnunet://")))
166 _ (
"Invalid URI: does not start with `gnunet://'\n"));
171 cursor += strlen (
"gnunet://");
173 slash = strchr (cursor,
'/');
176 fprintf (stderr,
_ (
"Invalid URI: fails to specify a subsystem\n"));
187 fprintf (stderr,
_ (
"No known handler for subsystem `%s'\n"),
subsystem);
196 char **childargv = NULL;
197 unsigned int childargc = 0;
199 for (
const char *token = strtok (program,
" ");
201 token = strtok (NULL,
" "))
214 for (
size_t i = 0; i<childargc - 1; ++i)
224 _ (
"Unable to start child process `%s'\n"),
242static const zbar_symbol_t *
245 const zbar_symbol_set_t *symbols;
248 if (0 != zbar_processor_parse_config (
proc,
"enable"))
258 _ (
"Failed to open device: `%s': %d\n"),
264 r = zbar_processor_set_visible (
proc, 1);
265 r += zbar_processor_set_active (
proc, 1);
272 LOG (
_ (
"Capturing...\n"));
274 n = zbar_process_one (
proc, -1);
276 zbar_processor_set_active (
proc, 0);
277 zbar_processor_set_visible (
proc, 0);
281 LOG (
_ (
"No captured images\n"));
285 LOG (
_ (
"Got %d images\n"), n);
287 symbols = zbar_processor_get_results (
proc);
294 return zbar_symbol_set_first_symbol (symbols);
306 zbar_processor_t *
proc = zbar_processor_create (1);
307 const zbar_symbol_t *symbol;
325 zbar_processor_destroy (
proc);
329 data = zbar_symbol_get_data (symbol);
333 zbar_processor_destroy (
proc);
337 LOG (
_ (
"Found %s: \"%s\"\n"),
338 zbar_get_symbol_name (zbar_symbol_get_type (symbol)),
343 zbar_processor_destroy (
proc);
358png_parse (uint32_t *width, uint32_t *height)
360 if (NULL == width || NULL == height)
365 FILE *pngfile = fopen (pngfilename,
"rb");
371 unsigned char header[8];
372 if (8 != fread (header, 1, 8, pngfile))
378 if (png_sig_cmp (header, 0, 8))
382 _ (
"%s is not a PNG file\n"),
384 fprintf (stderr,
_ (
"%s is not a PNG file\n"), pngfilename);
390 png_structp png = png_create_read_struct (PNG_LIBPNG_VER_STRING,
401 png_infop pnginfo = png_create_info_struct (png);
405 png_destroy_read_struct (&png, NULL, NULL);
410 if (setjmp (png_jmpbuf (png)))
413 png_destroy_read_struct (&png, &pnginfo, NULL);
418 png_init_io (png, pngfile);
419 png_set_sig_bytes (png, 8);
421 png_read_info (png, pnginfo);
423 png_byte pngcolor = png_get_color_type (png, pnginfo);
424 png_byte pngdepth = png_get_bit_depth (png, pnginfo);
427 if (0 != (pngcolor & PNG_COLOR_TYPE_PALETTE))
429 png_set_palette_to_rgb (png);
432 if (pngcolor == PNG_COLOR_TYPE_GRAY && pngdepth < 8)
434 png_set_expand_gray_1_2_4_to_8 (png);
439 png_set_strip_16 (png);
442 if (0 != (pngcolor & PNG_COLOR_MASK_ALPHA))
444 png_set_strip_alpha (png);
447 if (0 != (pngcolor & PNG_COLOR_MASK_COLOR))
449 png_set_rgb_to_gray_fixed (png, 1, -1, -1);
452 png_uint_32 pngwidth = png_get_image_width (png, pnginfo);
453 png_uint_32 pngheight = png_get_image_height (png, pnginfo);
458 for (png_uint_32 i = 0; i<pngheight; ++i)
460 rows[i] = (
unsigned char *) buffer + (pngwidth * i);
463 png_read_image (png, rows);
485 char *buffer = png_parse (&width, &height);
491 zbar_image_scanner_t *scanner = zbar_image_scanner_create ();
492 zbar_image_scanner_set_config (scanner,0, ZBAR_CFG_ENABLE, 1);
494 zbar_image_t *zimage = zbar_image_create ();
495 zbar_image_set_format (zimage, zbar_fourcc (
'Y',
'8',
'0',
'0'));
496 zbar_image_set_size (zimage, width, height);
497 zbar_image_set_data (zimage, buffer, width * height, &zbar_image_free_data);
499 int n = zbar_scan_image (scanner, zimage);
503 LOG (
_ (
"No captured images\n"));
507 LOG (
_ (
"Got %d images\n"), n);
509 const zbar_symbol_t *symbol = zbar_image_first_symbol (zimage);
511 const char *
data = zbar_symbol_get_data (symbol);
515 zbar_image_destroy (zimage);
516 zbar_image_scanner_destroy (scanner);
520 LOG (
_ (
"Found %s: \"%s\"\n"),
521 zbar_get_symbol_name (zbar_symbol_get_type (symbol)),
526 zbar_image_destroy (zimage);
527 zbar_image_scanner_destroy (scanner);
554 if (NULL != pngfilename)
556 data = run_png_reader ();
566 LOG (
_ (
"No data found\n"));
576 fprintf (stdout,
_ (
"Failed to add URI %s\n"),
data);
582 LOG (
_ (
"Dispatching the URI\n"));
587main (
int argc,
char *
const *argv)
594 gettext_noop (
"use the video device DEVICE (defaults to /dev/video0)"),
613 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 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.
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.
static char * run_zbar(void)
Run the zbar QR code parser.
struct GNUNET_OS_Process * childproc
Child process handle.
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.
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_OS_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
#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.
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_gnunet(void)
Return default project data used by 'libgnunetutil' for GNUnet.
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.
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_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_OS_Process * proc
Child process which is managed.
Definition of a command line option.