diff options
author | Christian Grothoff <christian@grothoff.org> | 2018-05-30 10:28:51 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2018-05-30 10:28:51 +0200 |
commit | 30fb422df59da0e650eb790933dadbd4bb189658 (patch) | |
tree | b37f7529e275671ce3e640b4064a8945f658d442 /src/util | |
parent | 0a0ac96d8be21130ccbb885537b0b179b16842e4 (diff) | |
parent | a46fff931d631a176f56547692b16ae32c89299b (diff) | |
download | gnunet-30fb422df59da0e650eb790933dadbd4bb189658.tar.gz gnunet-30fb422df59da0e650eb790933dadbd4bb189658.zip |
Merge branch 'master' of ssh://gnunet.org/gnunet
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/common_logging.c | 14 | ||||
-rw-r--r-- | src/util/crypto_bug.c | 2 | ||||
-rw-r--r-- | src/util/crypto_ecc.c | 10 | ||||
-rwxr-xr-x | src/util/gnunet-qr.py.in | 173 | ||||
-rw-r--r-- | src/util/mq.c | 26 | ||||
-rw-r--r-- | src/util/resolver_api.c | 4 |
6 files changed, 134 insertions, 95 deletions
diff --git a/src/util/common_logging.c b/src/util/common_logging.c index df501fbcd..ce9bd6e46 100644 --- a/src/util/common_logging.c +++ b/src/util/common_logging.c | |||
@@ -1344,14 +1344,15 @@ GNUNET_h2s_full (const struct GNUNET_HashCode * hc) | |||
1344 | const char * | 1344 | const char * |
1345 | GNUNET_i2s (const struct GNUNET_PeerIdentity *pid) | 1345 | GNUNET_i2s (const struct GNUNET_PeerIdentity *pid) |
1346 | { | 1346 | { |
1347 | static char buf[256]; | 1347 | static char buf[5]; |
1348 | char *ret; | 1348 | char *ret; |
1349 | 1349 | ||
1350 | if (NULL == pid) | 1350 | if (NULL == pid) |
1351 | return "NULL"; | 1351 | return "NULL"; |
1352 | ret = GNUNET_CRYPTO_eddsa_public_key_to_string (&pid->public_key); | 1352 | ret = GNUNET_CRYPTO_eddsa_public_key_to_string (&pid->public_key); |
1353 | strcpy (buf, | 1353 | strncpy (buf, |
1354 | ret); | 1354 | ret, |
1355 | sizeof (buf) - 1); | ||
1355 | GNUNET_free (ret); | 1356 | GNUNET_free (ret); |
1356 | buf[4] = '\0'; | 1357 | buf[4] = '\0'; |
1357 | return buf; | 1358 | return buf; |
@@ -1372,14 +1373,15 @@ GNUNET_i2s (const struct GNUNET_PeerIdentity *pid) | |||
1372 | const char * | 1373 | const char * |
1373 | GNUNET_i2s2 (const struct GNUNET_PeerIdentity *pid) | 1374 | GNUNET_i2s2 (const struct GNUNET_PeerIdentity *pid) |
1374 | { | 1375 | { |
1375 | static char buf[256]; | 1376 | static char buf[5]; |
1376 | char *ret; | 1377 | char *ret; |
1377 | 1378 | ||
1378 | if (NULL == pid) | 1379 | if (NULL == pid) |
1379 | return "NULL"; | 1380 | return "NULL"; |
1380 | ret = GNUNET_CRYPTO_eddsa_public_key_to_string (&pid->public_key); | 1381 | ret = GNUNET_CRYPTO_eddsa_public_key_to_string (&pid->public_key); |
1381 | strcpy (buf, | 1382 | strncpy (buf, |
1382 | ret); | 1383 | ret, |
1384 | sizeof (buf) - 1); | ||
1383 | GNUNET_free (ret); | 1385 | GNUNET_free (ret); |
1384 | buf[4] = '\0'; | 1386 | buf[4] = '\0'; |
1385 | return buf; | 1387 | return buf; |
diff --git a/src/util/crypto_bug.c b/src/util/crypto_bug.c index c25e79c63..1c3e9225e 100644 --- a/src/util/crypto_bug.c +++ b/src/util/crypto_bug.c | |||
@@ -28,7 +28,7 @@ | |||
28 | * Enable work-around. Will cause code to call #check_eddsa_key() to | 28 | * Enable work-around. Will cause code to call #check_eddsa_key() to |
29 | * see if we have a bad key, and if so, create a new one. | 29 | * see if we have a bad key, and if so, create a new one. |
30 | */ | 30 | */ |
31 | #define CRYPTO_BUG 1 | 31 | #define CRYPTO_BUG 0 |
32 | 32 | ||
33 | 33 | ||
34 | #if CRYPTO_BUG | 34 | #if CRYPTO_BUG |
diff --git a/src/util/crypto_ecc.c b/src/util/crypto_ecc.c index 1abf0fddc..8d9091b23 100644 --- a/src/util/crypto_ecc.c +++ b/src/util/crypto_ecc.c | |||
@@ -1281,6 +1281,16 @@ eddsa_d_to_a (gcry_mpi_t d) | |||
1281 | gcry_mpi_print (GCRYMPI_FMT_USG, | 1281 | gcry_mpi_print (GCRYMPI_FMT_USG, |
1282 | rawmpi, rawmpilen, &rawmpilen, | 1282 | rawmpi, rawmpilen, &rawmpilen, |
1283 | d)); | 1283 | d)); |
1284 | if (rawmpilen < 32) | ||
1285 | { | ||
1286 | memmove (rawmpi + 32 - rawmpilen, | ||
1287 | rawmpi, | ||
1288 | rawmpilen); | ||
1289 | memset (rawmpi, | ||
1290 | 0, | ||
1291 | 32 - rawmpilen); | ||
1292 | rawmpilen = 32; | ||
1293 | } | ||
1284 | hvec[0].data = digest; | 1294 | hvec[0].data = digest; |
1285 | hvec[0].off = 0; | 1295 | hvec[0].off = 0; |
1286 | hvec[0].len = b > rawmpilen ? (b - rawmpilen) : 0; | 1296 | hvec[0].len = b > rawmpilen ? (b - rawmpilen) : 0; |
diff --git a/src/util/gnunet-qr.py.in b/src/util/gnunet-qr.py.in index 549ce5af1..a5918fdf8 100755 --- a/src/util/gnunet-qr.py.in +++ b/src/util/gnunet-qr.py.in | |||
@@ -4,105 +4,106 @@ import getopt | |||
4 | import subprocess | 4 | import subprocess |
5 | from sys import argv | 5 | from sys import argv |
6 | try: | 6 | try: |
7 | import zbar | 7 | import zbar |
8 | except ImportError as e: | 8 | except ImportError as e: |
9 | print('Cannot run gnunet-qr, please install zbar-python') | 9 | print('Cannot run gnunet-qr, please install zbar-python') |
10 | sys.exit (1) | 10 | sys.exit(1) |
11 | 11 | ||
12 | def help (): | 12 | |
13 | print('gnunet-qr\n\ | 13 | def help(): |
14 | print('gnunet-qr\n\ | ||
14 | Scan a QR code using a video device and import\n\ | 15 | Scan a QR code using a video device and import\n\ |
15 | Arguments mandatory for long options are also mandatory for short options.\n\ | 16 | Arguments mandatory for long options are also mandatory for short options.\n\ |
16 | -c, --config=FILENAME use configuration file FILENAME\n\ | 17 | -c, --config=FILENAME use configuration file FILENAME\n\ |
17 | -d, --device=DEVICE use device DEVICE\n\ | 18 | -d, --device=DEVICE use device DEVICE\n\ |
18 | -s, --silent do not show preview windows\n\ | 19 | -s, --silent do not show preview windows\n\ |
19 | -h, --help print this help\n\ | 20 | -h, --help print this help\n\ |
20 | -v, --verbose be verbose\n\ | 21 | -v, --verbose be verbose\n\ |
21 | Report bugs to gnunet-developers@gnu.org.\n\ | 22 | Report bugs to gnunet-developers@gnu.org.\n\ |
22 | GNUnet home page: http://www.gnu.org/software/gnunet/\n\ | 23 | GNUnet home page: http://www.gnu.org/software/gnunet/\n\ |
23 | General help using GNU software: http://www.gnu.org/gethelp/') | 24 | General help using GNU software: http://www.gnu.org/gethelp/') |
24 | 25 | ||
25 | 26 | ||
26 | if __name__ == '__main__': | 27 | if __name__ == '__main__': |
27 | configuration = '' | 28 | configuration = '' |
28 | device = '/dev/video0' | 29 | device = '/dev/video0' |
29 | url = '' | 30 | url = '' |
30 | verbose = False | 31 | verbose = False |
31 | silent = False | 32 | silent = False |
32 | # Parse arguments | 33 | # Parse arguments |
33 | try: | 34 | try: |
34 | opts, args = getopt.gnu_getopt(sys.argv[1:], "c:hd:sv", ["config","help", "device","silent","verbose"]) | 35 | opts, args = getopt.gnu_getopt(sys.argv[1:], "c:hd:sv", ["config", "help", "device", "silent", "verbose"]) |
35 | except getopt.GetoptError as e: | 36 | except getopt.GetoptError as e: |
36 | help () | 37 | help() |
37 | print(str (e)) | 38 | print(str(e)) |
38 | exit (1) | 39 | exit(1) |
39 | for o,a in opts: | 40 | for o, a in opts: |
40 | if o in ("-h", "--help"): | 41 | if o in ("-h", "--help"): |
41 | help () | 42 | help() |
42 | sys.exit (0) | 43 | sys.exit(0) |
43 | elif o in ("-c", "--config"): | 44 | elif o in ("-c", "--config"): |
44 | configuration = a | 45 | configuration = a |
45 | elif o in ("-d", "--device"): | 46 | elif o in ("-d", "--device"): |
46 | device = a | 47 | device = a |
47 | elif o in ("-s", "--silent"): | 48 | elif o in ("-s", "--silent"): |
48 | silent = True | 49 | silent = True |
49 | elif o in ("-v", "--verbose"): | 50 | elif o in ("-v", "--verbose"): |
50 | verbose = True | 51 | verbose = True |
51 | if (True == verbose): | 52 | if (True == verbose): |
52 | print('Initializing') | 53 | print('Initializing') |
53 | # create a Processor | 54 | # create a Processor |
54 | proc = zbar.Processor() | 55 | proc = zbar.Processor() |
56 | |||
57 | # configure the Processor | ||
58 | proc.parse_config('enable') | ||
59 | |||
60 | # initialize the Processor | ||
61 | try: | ||
62 | if (True == verbose): | ||
63 | print('Opening video device ' + device) | ||
64 | proc.init(device) | ||
65 | except Exception as e: | ||
66 | print('Failed to open device ' + device) | ||
67 | exit(1) | ||
68 | |||
69 | # enable the preview window | ||
70 | # if (True == silent): | ||
71 | # proc.visible = True | ||
72 | # else: | ||
73 | # proc.visible = False | ||
74 | |||
75 | proc.visible = True | ||
76 | # read at least one barcode (or until window closed) | ||
77 | try: | ||
78 | if (True == verbose): | ||
79 | print('Capturing') | ||
80 | proc.process_one() | ||
81 | except Exception as e: | ||
82 | # Window was closed without finding code | ||
83 | exit(1) | ||
55 | 84 | ||
56 | # configure the Processor | 85 | # hide the preview window |
57 | proc.parse_config('enable') | 86 | proc.visible = False |
58 | 87 | ||
59 | # initialize the Processor | 88 | # extract results |
60 | try: | 89 | for symbol in proc.results: |
61 | if (True == verbose): | 90 | # do something useful with results |
62 | print('Opening video device ' + device) | 91 | if (True == verbose): |
63 | proc.init(device) | 92 | print('Found ', symbol.type, ' symbol ', '"%s"' % symbol.data) |
64 | except Exception as e: | 93 | args = list() |
65 | print('Failed to open device ' + device) | 94 | args.append("gnunet-uri") |
66 | exit (1) | 95 | if (configuration != ''): |
67 | 96 | args.append(str("-c " + str(configuration))) | |
68 | # enable the preview window | 97 | args.append(str(symbol.data)) |
69 | #if (True == silent): | 98 | cmd = '' |
70 | # proc.visible = True | 99 | for a in args: |
71 | #else: | 100 | cmd += " " + str(a) |
72 | # proc.visible = False | 101 | if (verbose): |
73 | 102 | print('Running `' + cmd +'`') | |
74 | proc.visible = True | 103 | res=subprocess.call(args) |
75 | # read at least one barcode (or until window closed) | 104 | if (0 != res): |
76 | try: | 105 | print('Failed to add URI ' + str(symbol.data)) |
77 | if (True == verbose): | 106 | else: |
78 | print('Capturing') | 107 | print('Added URI ' + str(symbol.data)) |
79 | proc.process_one() | 108 | exit(res) |
80 | except Exception as e: | 109 | exit(1) |
81 | # Window was closed without finding code | ||
82 | exit (1) | ||
83 | |||
84 | # hide the preview window | ||
85 | proc.visible = False | ||
86 | |||
87 | # extract results | ||
88 | for symbol in proc.results: | ||
89 | # do something useful with results | ||
90 | if (True == verbose): | ||
91 | print('Found ', symbol.type, ' symbol ', '"%s"' % symbol.data) | ||
92 | args = list() | ||
93 | args.append("gnunet-uri") | ||
94 | if (configuration != ''): | ||
95 | args.append (str("-c " + str(configuration))) | ||
96 | args.append (str(symbol.data)) | ||
97 | cmd = '' | ||
98 | for a in args: | ||
99 | cmd += " " + str(a) | ||
100 | if (verbose): | ||
101 | print('Running `' + cmd +'`') | ||
102 | res=subprocess.call(args) | ||
103 | if (0 != res): | ||
104 | print('Failed to add URI ' + str(symbol.data)) | ||
105 | else: | ||
106 | print('Added URI ' + str(symbol.data)) | ||
107 | exit (res) | ||
108 | exit (1) | ||
diff --git a/src/util/mq.c b/src/util/mq.c index dbcce704d..81a42e0c6 100644 --- a/src/util/mq.c +++ b/src/util/mq.c | |||
@@ -1071,6 +1071,32 @@ GNUNET_MQ_set_options (struct GNUNET_MQ_Handle *mq, | |||
1071 | 1071 | ||
1072 | 1072 | ||
1073 | /** | 1073 | /** |
1074 | * Obtain message contained in envelope. | ||
1075 | * | ||
1076 | * @param env the envelope | ||
1077 | * @return message contained in the envelope | ||
1078 | */ | ||
1079 | const struct GNUNET_MessageHeader * | ||
1080 | GNUNET_MQ_env_get_msg (const struct GNUNET_MQ_Envelope *env) | ||
1081 | { | ||
1082 | return env->mh; | ||
1083 | } | ||
1084 | |||
1085 | |||
1086 | /** | ||
1087 | * Return next envelope in queue. | ||
1088 | * | ||
1089 | * @param env a queued envelope | ||
1090 | * @return next one, or NULL | ||
1091 | */ | ||
1092 | const struct GNUNET_MQ_Envelope * | ||
1093 | GNUNET_MQ_env_next (const struct GNUNET_MQ_Envelope *env) | ||
1094 | { | ||
1095 | return env->next; | ||
1096 | } | ||
1097 | |||
1098 | |||
1099 | /** | ||
1074 | * Register function to be called whenever @a mq is being | 1100 | * Register function to be called whenever @a mq is being |
1075 | * destroyed. | 1101 | * destroyed. |
1076 | * | 1102 | * |
diff --git a/src/util/resolver_api.c b/src/util/resolver_api.c index 68f02587a..21f902578 100644 --- a/src/util/resolver_api.c +++ b/src/util/resolver_api.c | |||
@@ -515,8 +515,8 @@ handle_response (void *cls, | |||
515 | if ( (NULL != rh->addr_callback) && | 515 | if ( (NULL != rh->addr_callback) && |
516 | (GNUNET_SYSERR != rh->was_transmitted) ) | 516 | (GNUNET_SYSERR != rh->was_transmitted) ) |
517 | rh->addr_callback (rh->cls, | 517 | rh->addr_callback (rh->cls, |
518 | NULL, | 518 | NULL, |
519 | 0); | 519 | 0); |
520 | } | 520 | } |
521 | rh->was_transmitted = GNUNET_NO; | 521 | rh->was_transmitted = GNUNET_NO; |
522 | GNUNET_RESOLVER_request_cancel (rh); | 522 | GNUNET_RESOLVER_request_cancel (rh); |