]>
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_unlocked(&url
, &url_size
);
54 for (i
= 0; i
< seed_size
; i
++) {
55 if (i
> 0 && i
% 3 == 0)
57 fprintf(f
, "%02x", ((uint8_t*) seed
)[i
]);
60 fprintf(f
, "/%"PRIx64
"-%"PRIx64
"?machine=" SD_ID128_FORMAT_STR
,
63 SD_ID128_FORMAT_VAL(machine
));
66 fprintf(f
, ";hostname=%s", hn
);
76 qr
= QRcode_encodeString(url
, 0, QR_ECLEVEL_L
, QR_MODE_8
, 1);
82 print_border(output
, qr
->width
);
84 for (y
= 0; y
< (unsigned) qr
->width
; y
+= 2) {
85 const uint8_t *row1
, *row2
;
87 row1
= qr
->data
+ qr
->width
* y
;
88 row2
= row1
+ qr
->width
;
90 fputs(WHITE_ON_BLACK
, output
);
91 for (x
= 0; x
< 4; x
++)
92 fputs("\342\226\210", output
);
94 for (x
= 0; x
< (unsigned) qr
->width
; x
++) {
98 b
= (y
+1) < (unsigned) qr
->width
? (row2
[x
] & 1) : false;
103 fputs("\342\226\204", output
);
105 fputs("\342\226\200", output
);
107 fputs("\342\226\210", output
);
110 for (x
= 0; x
< 4; x
++)
111 fputs("\342\226\210", output
);
112 fputs(NORMAL
"\n", output
);
115 print_border(output
, qr
->width
);