]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/journal/journal-qrcode.c
1dd20bb1ccfb7720dbfd58fce771405553bbe7ee
1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 Copyright 2012 Lennart Poettering
10 #include <stdio_ext.h>
13 #include "journal-qrcode.h"
16 #define WHITE_ON_BLACK "\033[40;37;1m"
17 #define NORMAL "\033[0m"
19 static void print_border(FILE *output
, unsigned width
) {
22 /* Four rows of border */
23 for (y
= 0; y
< 4; y
+= 2) {
24 fputs(WHITE_ON_BLACK
, output
);
26 for (x
= 0; x
< 4 + width
+ 4; x
++)
27 fputs("\342\226\210", output
);
29 fputs(NORMAL
"\n", output
);
44 size_t url_size
= 0, i
;
49 assert(seed_size
> 0);
51 f
= open_memstream(&url
, &url_size
);
55 (void) __fsetlocking(f
, FSETLOCKING_BYCALLER
);
59 for (i
= 0; i
< seed_size
; i
++) {
60 if (i
> 0 && i
% 3 == 0)
62 fprintf(f
, "%02x", ((uint8_t*) seed
)[i
]);
65 fprintf(f
, "/%"PRIx64
"-%"PRIx64
"?machine=" SD_ID128_FORMAT_STR
,
68 SD_ID128_FORMAT_VAL(machine
));
71 fprintf(f
, ";hostname=%s", hn
);
81 qr
= QRcode_encodeString(url
, 0, QR_ECLEVEL_L
, QR_MODE_8
, 1);
87 print_border(output
, qr
->width
);
89 for (y
= 0; y
< (unsigned) qr
->width
; y
+= 2) {
90 const uint8_t *row1
, *row2
;
92 row1
= qr
->data
+ qr
->width
* y
;
93 row2
= row1
+ qr
->width
;
95 fputs(WHITE_ON_BLACK
, output
);
96 for (x
= 0; x
< 4; x
++)
97 fputs("\342\226\210", output
);
99 for (x
= 0; x
< (unsigned) qr
->width
; x
++) {
103 b
= (y
+1) < (unsigned) qr
->width
? (row2
[x
] & 1) : false;
108 fputs("\342\226\204", output
);
110 fputs("\342\226\200", output
);
112 fputs("\342\226\210", output
);
115 for (x
= 0; x
< 4; x
++)
116 fputs("\342\226\210", output
);
117 fputs(NORMAL
"\n", output
);
120 print_border(output
, qr
->width
);