]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/journal/journal-qrcode.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
10 #include "journal-qrcode.h"
13 #define WHITE_ON_BLACK "\033[40;37;1m"
14 #define NORMAL "\033[0m"
16 static void print_border(FILE *output
, unsigned width
) {
19 /* Four rows of border */
20 for (y
= 0; y
< 4; y
+= 2) {
21 fputs(WHITE_ON_BLACK
, output
);
23 for (x
= 0; x
< 4 + width
+ 4; x
++)
24 fputs("\342\226\210", output
);
26 fputs(NORMAL
"\n", output
);
41 size_t url_size
= 0, i
;
46 assert(seed_size
> 0);
48 f
= open_memstream(&url
, &url_size
);
52 (void) __fsetlocking(f
, FSETLOCKING_BYCALLER
);
56 for (i
= 0; i
< seed_size
; i
++) {
57 if (i
> 0 && i
% 3 == 0)
59 fprintf(f
, "%02x", ((uint8_t*) seed
)[i
]);
62 fprintf(f
, "/%"PRIx64
"-%"PRIx64
"?machine=" SD_ID128_FORMAT_STR
,
65 SD_ID128_FORMAT_VAL(machine
));
68 fprintf(f
, ";hostname=%s", hn
);
78 qr
= QRcode_encodeString(url
, 0, QR_ECLEVEL_L
, QR_MODE_8
, 1);
84 print_border(output
, qr
->width
);
86 for (y
= 0; y
< (unsigned) qr
->width
; y
+= 2) {
87 const uint8_t *row1
, *row2
;
89 row1
= qr
->data
+ qr
->width
* y
;
90 row2
= row1
+ qr
->width
;
92 fputs(WHITE_ON_BLACK
, output
);
93 for (x
= 0; x
< 4; x
++)
94 fputs("\342\226\210", output
);
96 for (x
= 0; x
< (unsigned) qr
->width
; x
++) {
100 b
= (y
+1) < (unsigned) qr
->width
? (row2
[x
] & 1) : false;
105 fputs("\342\226\204", output
);
107 fputs("\342\226\200", output
);
109 fputs("\342\226\210", output
);
112 for (x
= 0; x
< 4; x
++)
113 fputs("\342\226\210", output
);
114 fputs(NORMAL
"\n", output
);
117 print_border(output
, qr
->width
);