diff options
-rw-r--r-- | src/util/gnunet-qr.c | 132 |
1 files changed, 66 insertions, 66 deletions
diff --git a/src/util/gnunet-qr.c b/src/util/gnunet-qr.c index fa95d6c05..ff781f726 100644 --- a/src/util/gnunet-qr.c +++ b/src/util/gnunet-qr.c | |||
@@ -29,12 +29,14 @@ | |||
29 | #include "platform.h" | 29 | #include "platform.h" |
30 | #include "gnunet_util_lib.h" | 30 | #include "gnunet_util_lib.h" |
31 | 31 | ||
32 | #define LOG(fmt, ...) if (verbose == true) printf(fmt, ## __VA_ARGS__) | 32 | #define LOG(fmt, ...) \ |
33 | if (verbose == true) \ | ||
34 | printf (fmt, ##__VA_ARGS__) | ||
33 | 35 | ||
34 | /** | 36 | /** |
35 | * Video device to capture from. Sane default for GNU/Linux systems. | 37 | * Video device to capture from. Sane default for GNU/Linux systems. |
36 | */ | 38 | */ |
37 | static char* device = "/dev/video0"; | 39 | static char *device = "/dev/video0"; |
38 | 40 | ||
39 | /** | 41 | /** |
40 | * --verbose option | 42 | * --verbose option |
@@ -74,9 +76,8 @@ maint_child_death (void *cls) | |||
74 | { | 76 | { |
75 | enum GNUNET_OS_ProcessStatusType type; | 77 | enum GNUNET_OS_ProcessStatusType type; |
76 | 78 | ||
77 | if ( (GNUNET_OK != | 79 | if ((GNUNET_OK != GNUNET_OS_process_status (p, &type, &exit_code)) || |
78 | GNUNET_OS_process_status (p, &type, &exit_code)) || | 80 | (type != GNUNET_OS_PROCESS_EXITED)) |
79 | (type != GNUNET_OS_PROCESS_EXITED) ) | ||
80 | GNUNET_break (0 == GNUNET_OS_process_kill (p, GNUNET_TERM_SIG)); | 81 | GNUNET_break (0 == GNUNET_OS_process_kill (p, GNUNET_TERM_SIG)); |
81 | GNUNET_OS_process_destroy (p); | 82 | GNUNET_OS_process_destroy (p); |
82 | } | 83 | } |
@@ -100,46 +101,45 @@ gnunet_uri (void *cls, | |||
100 | const char *slash; | 101 | const char *slash; |
101 | char *subsystem; | 102 | char *subsystem; |
102 | char *program; | 103 | char *program; |
103 | struct GNUNET_SCHEDULER_Task * rt; | 104 | struct GNUNET_SCHEDULER_Task *rt; |
104 | 105 | ||
105 | orig_uri = uri; | 106 | orig_uri = uri; |
106 | if (0 != strncasecmp ("gnunet://", uri, strlen ("gnunet://"))) { | 107 | if (0 != strncasecmp ("gnunet://", uri, strlen ("gnunet://"))) |
108 | { | ||
107 | fprintf (stderr, | 109 | fprintf (stderr, |
108 | _("Invalid URI: does not start with `%s'\n"), | 110 | _ ("Invalid URI: does not start with `%s'\n"), |
109 | "gnunet://"); | 111 | "gnunet://"); |
110 | return; | 112 | return; |
111 | } | 113 | } |
112 | uri += strlen ("gnunet://"); | 114 | uri += strlen ("gnunet://"); |
113 | if (NULL == (slash = strchr (uri, '/'))) | 115 | if (NULL == (slash = strchr (uri, '/'))) |
114 | { | 116 | { |
115 | fprintf (stderr, | 117 | fprintf (stderr, _ ("Invalid URI: fails to specify subsystem\n")); |
116 | _("Invalid URI: fails to specify subsystem\n")); | ||
117 | return; | 118 | return; |
118 | } | 119 | } |
119 | subsystem = GNUNET_strndup (uri, slash - uri); | 120 | subsystem = GNUNET_strndup (uri, slash - uri); |
120 | if (GNUNET_OK != | 121 | if (GNUNET_OK != |
121 | GNUNET_CONFIGURATION_get_value_string (cfg, | 122 | GNUNET_CONFIGURATION_get_value_string (cfg, "uri", subsystem, &program)) |
122 | "uri", | ||
123 | subsystem, | ||
124 | &program)) | ||
125 | { | 123 | { |
126 | fprintf (stderr, | 124 | fprintf (stderr, _ ("No handler known for subsystem `%s'\n"), subsystem); |
127 | _("No handler known for subsystem `%s'\n"), | ||
128 | subsystem); | ||
129 | GNUNET_free (subsystem); | 125 | GNUNET_free (subsystem); |
130 | return; | 126 | return; |
131 | } | 127 | } |
132 | GNUNET_free (subsystem); | 128 | GNUNET_free (subsystem); |
133 | rt = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, | 129 | rt = GNUNET_SCHEDULER_add_read_file ( |
134 | GNUNET_DISK_pipe_handle (sigpipe, | 130 | GNUNET_TIME_UNIT_FOREVER_REL, |
135 | GNUNET_DISK_PIPE_END_READ), | 131 | GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ), |
136 | &maint_child_death, NULL); | 132 | &maint_child_death, |
137 | p = GNUNET_OS_start_process (GNUNET_NO, 0, | 133 | NULL); |
138 | NULL, NULL, NULL, | 134 | p = GNUNET_OS_start_process (GNUNET_NO, |
139 | program, | 135 | 0, |
140 | program, | 136 | NULL, |
141 | orig_uri, | 137 | NULL, |
142 | NULL); | 138 | NULL, |
139 | program, | ||
140 | program, | ||
141 | orig_uri, | ||
142 | NULL); | ||
143 | GNUNET_free (program); | 143 | GNUNET_free (program); |
144 | if (NULL == p) | 144 | if (NULL == p) |
145 | GNUNET_SCHEDULER_cancel (rt); | 145 | GNUNET_SCHEDULER_cancel (rt); |
@@ -155,20 +155,18 @@ gnunet_uri (void *cls, | |||
155 | static const zbar_symbol_t * | 155 | static const zbar_symbol_t * |
156 | get_symbol (zbar_processor_t *proc) | 156 | get_symbol (zbar_processor_t *proc) |
157 | { | 157 | { |
158 | const zbar_symbol_set_t* symbols; | 158 | const zbar_symbol_set_t *symbols; |
159 | int rc; | 159 | int rc; |
160 | int n; | 160 | int n; |
161 | 161 | ||
162 | if (0 != | 162 | if (0 != zbar_processor_parse_config (proc, "enable")) |
163 | zbar_processor_parse_config (proc, "enable")) | ||
164 | { | 163 | { |
165 | GNUNET_break (0); | 164 | GNUNET_break (0); |
166 | return NULL; | 165 | return NULL; |
167 | } | 166 | } |
168 | 167 | ||
169 | /* initialize the Processor */ | 168 | /* initialize the Processor */ |
170 | if (0 != | 169 | if (0 != (rc = zbar_processor_init (proc, device, 1))) |
171 | (rc = zbar_processor_init(proc, device, 1))) | ||
172 | { | 170 | { |
173 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 171 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
174 | "Failed to open device `%s': %d\n", | 172 | "Failed to open device `%s': %d\n", |
@@ -178,8 +176,8 @@ get_symbol (zbar_processor_t *proc) | |||
178 | } | 176 | } |
179 | 177 | ||
180 | /* enable the preview window */ | 178 | /* enable the preview window */ |
181 | if ( (0 != (rc = zbar_processor_set_visible (proc, 1))) || | 179 | if ((0 != (rc = zbar_processor_set_visible (proc, 1))) || |
182 | (0 != (rc = zbar_processor_set_active(proc, 1))) ) | 180 | (0 != (rc = zbar_processor_set_active (proc, 1)))) |
183 | { | 181 | { |
184 | GNUNET_break (0); | 182 | GNUNET_break (0); |
185 | return NULL; | 183 | return NULL; |
@@ -194,8 +192,7 @@ get_symbol (zbar_processor_t *proc) | |||
194 | (void) zbar_processor_set_visible (proc, 0); | 192 | (void) zbar_processor_set_visible (proc, 0); |
195 | if (-1 == n) | 193 | if (-1 == n) |
196 | return NULL; /* likely user closed the window */ | 194 | return NULL; /* likely user closed the window */ |
197 | LOG ("Got %i images\n", | 195 | LOG ("Got %i images\n", n); |
198 | n); | ||
199 | /* extract results */ | 196 | /* extract results */ |
200 | symbols = zbar_processor_get_results (proc); | 197 | symbols = zbar_processor_get_results (proc); |
201 | if (NULL == symbols) | 198 | if (NULL == symbols) |
@@ -218,7 +215,7 @@ run_zbar () | |||
218 | zbar_processor_t *proc; | 215 | zbar_processor_t *proc; |
219 | const char *data; | 216 | const char *data; |
220 | char *ret; | 217 | char *ret; |
221 | const zbar_symbol_t* symbol; | 218 | const zbar_symbol_t *symbol; |
222 | 219 | ||
223 | /* configure the Processor */ | 220 | /* configure the Processor */ |
224 | proc = zbar_processor_create (1); | 221 | proc = zbar_processor_create (1); |
@@ -242,11 +239,11 @@ run_zbar () | |||
242 | return NULL; | 239 | return NULL; |
243 | } | 240 | } |
244 | LOG ("Found %s \"%s\"\n", | 241 | LOG ("Found %s \"%s\"\n", |
245 | zbar_get_symbol_name (zbar_symbol_get_type(symbol)), | 242 | zbar_get_symbol_name (zbar_symbol_get_type (symbol)), |
246 | data); | 243 | data); |
247 | ret = GNUNET_strdup (data); | 244 | ret = GNUNET_strdup (data); |
248 | /* clean up */ | 245 | /* clean up */ |
249 | zbar_processor_destroy(proc); | 246 | zbar_processor_destroy (proc); |
250 | return ret; | 247 | return ret; |
251 | } | 248 | } |
252 | 249 | ||
@@ -270,19 +267,14 @@ run (void *cls, | |||
270 | data = run_zbar (); | 267 | data = run_zbar (); |
271 | if (NULL == data) | 268 | if (NULL == data) |
272 | return; | 269 | return; |
273 | gnunet_uri (cls, | 270 | gnunet_uri (cls, data, cfgfile, cfg); |
274 | data, | ||
275 | cfgfile, | ||
276 | cfg); | ||
277 | if (exit_code != 0) | 271 | if (exit_code != 0) |
278 | { | 272 | { |
279 | printf ("Failed to add URI %s\n", | 273 | printf ("Failed to add URI %s\n", data); |
280 | data); | ||
281 | } | 274 | } |
282 | else | 275 | else |
283 | { | 276 | { |
284 | printf ("Added URI %s\n", | 277 | printf ("Added URI %s\n", data); |
285 | data); | ||
286 | } | 278 | } |
287 | GNUNET_free (data); | 279 | GNUNET_free (data); |
288 | }; | 280 | }; |
@@ -292,23 +284,31 @@ int | |||
292 | main (int argc, char *const *argv) | 284 | main (int argc, char *const *argv) |
293 | { | 285 | { |
294 | int ret; | 286 | int ret; |
295 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 287 | struct GNUNET_GETOPT_CommandLineOption options[] = |
296 | GNUNET_GETOPT_option_string ('d', "device", "DEVICE", | 288 | {GNUNET_GETOPT_option_string ( |
297 | gettext_noop ("use video-device DEVICE (default: /dev/video0"), | 289 | 'd', |
298 | &device), | 290 | "device", |
299 | GNUNET_GETOPT_option_flag ('\0', "verbose", | 291 | "DEVICE", |
300 | gettext_noop ("be verbose"), | 292 | gettext_noop ("use video-device DEVICE (default: /dev/video0"), |
301 | &verbose), | 293 | &device), |
302 | GNUNET_GETOPT_option_flag ('s', "silent", | 294 | GNUNET_GETOPT_option_flag ('\0', |
303 | gettext_noop ("do not show preview windows"), | 295 | "verbose", |
304 | &silent), | 296 | gettext_noop ("be verbose"), |
305 | GNUNET_GETOPT_OPTION_END | 297 | &verbose), |
306 | }; | 298 | GNUNET_GETOPT_option_flag ('s', |
307 | 299 | "silent", | |
308 | ret = GNUNET_PROGRAM_run (argc, | 300 | gettext_noop ("do not show preview windows"), |
309 | argv, | 301 | &silent), |
310 | "gnunet-qr", | 302 | GNUNET_GETOPT_OPTION_END}; |
311 | gettext_noop ("Scan a QR code using a video device and import the uri read"), | 303 | |
312 | options, &run, NULL); | 304 | ret = GNUNET_PROGRAM_run ( |
305 | argc, | ||
306 | argv, | ||
307 | "gnunet-qr", | ||
308 | gettext_noop ( | ||
309 | "Scan a QR code using a video device and import the uri read"), | ||
310 | options, | ||
311 | &run, | ||
312 | NULL); | ||
313 | return ((GNUNET_OK == ret) && (0 == exit_code)) ? 0 : 1; | 313 | return ((GNUNET_OK == ret) && (0 == exit_code)) ? 0 : 1; |
314 | } | 314 | } |