]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/journal/journal-qrcode.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 This file is part of systemd.
5 Copyright 2012 Lennart Poettering
7 systemd is free software; you can redistribute it and/or modify it
8 under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 2.1 of the License, or
10 (at your option) any later version.
12 systemd is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public License
18 along with systemd; If not, see <http://www.gnu.org/licenses/>.
27 #include "journal-qrcode.h"
30 #define WHITE_ON_BLACK "\033[40;37;1m"
31 #define NORMAL "\033[0m"
33 static void print_border(FILE *output
, unsigned width
) {
36 /* Four rows of border */
37 for (y
= 0; y
< 4; y
+= 2) {
38 fputs(WHITE_ON_BLACK
, output
);
40 for (x
= 0; x
< 4 + width
+ 4; x
++)
41 fputs("\342\226\210", output
);
43 fputs(NORMAL
"\n", output
);
58 size_t url_size
= 0, i
;
63 assert(seed_size
> 0);
65 f
= open_memstream(&url
, &url_size
);
69 fputs_unlocked("fss://", f
);
71 for (i
= 0; i
< seed_size
; i
++) {
72 if (i
> 0 && i
% 3 == 0)
73 fputc_unlocked('-', f
);
74 fprintf(f
, "%02x", ((uint8_t*) seed
)[i
]);
77 fprintf(f
, "/%"PRIx64
"-%"PRIx64
"?machine=" SD_ID128_FORMAT_STR
,
80 SD_ID128_FORMAT_VAL(machine
));
83 fprintf(f
, ";hostname=%s", hn
);
93 qr
= QRcode_encodeString(url
, 0, QR_ECLEVEL_L
, QR_MODE_8
, 1);
99 print_border(output
, qr
->width
);
101 for (y
= 0; y
< (unsigned) qr
->width
; y
+= 2) {
102 const uint8_t *row1
, *row2
;
104 row1
= qr
->data
+ qr
->width
* y
;
105 row2
= row1
+ qr
->width
;
107 fputs(WHITE_ON_BLACK
, output
);
108 for (x
= 0; x
< 4; x
++)
109 fputs("\342\226\210", output
);
111 for (x
= 0; x
< (unsigned) qr
->width
; x
++) {
115 b
= (y
+1) < (unsigned) qr
->width
? (row2
[x
] & 1) : false;
120 fputs("\342\226\204", output
);
122 fputs("\342\226\200", output
);
124 fputs("\342\226\210", output
);
127 for (x
= 0; x
< 4; x
++)
128 fputs("\342\226\210", output
);
129 fputs(NORMAL
"\n", output
);
132 print_border(output
, qr
->width
);