2 This file is part of GNUnet.
3 Copyright (C) 2013-2019 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
26 static const char *usage_note =
28 "Scan a QR code using a video device and import\n"
30 "Arguments mandatory for long options are also mandatory for short options.\n"
31 " -c, --config FILENAME use configuration file FILENAME\n"
32 " -d, --device DEVICE use device DEVICE\n"
33 " -s, --silent do not show preview windows\n"
34 " -h, --help print this help\n"
35 " -v, --verbose be verbose\n"
36 "Report bugs to gnunet-developers@gnu.org.\n"
38 "GNUnet home page: https://gnunet.org/\n"
39 "General help using GNU software: https://www.gnu.org/gethelp/\n";
41 int main (int argc, char **argv)
43 const char* configuration = NULL;
44 const char* device = "/dev/video0";
45 static bool verbose = false;
46 static bool silent = false;
48 static struct option long_options[] = {
49 {"verbose", no_argument, 0, 'v'},
50 {"silent", no_argument, 0, 's'},
51 {"help", no_argument, 0, 'h'},
52 {"config", required_argument, 0, 'c'},
53 {"device", required_argument, 0, 'd'},
58 opt = getopt_long (argc, argv, "c:hd:sv",
68 configuration = optarg;
85 /* create a Processor */
86 if (verbose == true) {
87 printf("Initializing\n");
89 zbar_processor_t *proc = zbar_processor_create(1);
91 // FIXME: Wrap all this into a function which returns an error on
92 // failure. And here ensure the processor is destroyed at the end.
94 /* configure the Processor */
95 zbar_processor_parse_config(proc, "enable");
97 /* initialize the Processor */
98 if (verbose == true) {
99 printf("Opening video device %s\n", device);
101 // FIXME: error handling
102 zbar_processor_init(proc, device, 1);
104 /* enable the preview window */
105 zbar_processor_set_visible(proc, 1);
106 zbar_processor_set_active(proc, 1);
108 /* keep scanning until user provides key/mouse input */
109 //zbar_processor_user_wait(proc, -1);
111 // read at least one barcode (or until window closed)
112 if (verbose == true) {
113 printf("Capturing\n");
116 n = zbar_process_one(proc, -1);
117 if (verbose == true) {
118 printf("Got %i images\n", n);
120 // FIXME: Error handling (n = -1)
122 // hide the preview window
123 zbar_processor_set_active(proc, 0);
124 zbar_processor_set_visible(proc, 0);
129 const zbar_symbol_set_t* symbols = zbar_processor_get_results(proc);
130 const zbar_symbol_t* symbol = zbar_symbol_set_first_symbol(symbols);
132 if (symbol != NULL) {
133 const char* data = zbar_symbol_get_data(symbol);
134 if (verbose = true) {
135 zbar_symbol_type_t type =
136 printf("Found %s \"%s\"\n",
137 zbar_get_symbol_name(zbar_symbol_get_type(symbol)), data);
140 args = ["gnunet-uri",
141 // FIXME: "-c", configuration,
143 if (verbose = true) {
144 // TODO: print arguments:
145 printf("Running `%s %s %s %s`", *args, "", ""); // FIXME variable num args
147 rc = popen("gnunet-uri", *args);
150 printf("Failed to add URI %s\n", data);
152 printf("Added URI %s\n", data);
157 zbar_processor_destroy(proc);