]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/journal/journal-qrcode.c
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2012 Lennart Poettering
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
29 #include "journal-qrcode.h"
31 #define WHITE_ON_BLACK "\033[40;37;1m"
32 #define NORMAL "\033[0m"
34 static void print_border(FILE *output
, unsigned width
) {
37 /* Four rows of border */
38 for (y
= 0; y
< 4; y
+= 2) {
39 fputs(WHITE_ON_BLACK
, output
);
41 for (x
= 0; x
< 4 + width
+ 4; x
++)
42 fputs("\342\226\210", output
);
44 fputs(NORMAL
"\n", output
);
59 size_t url_size
= 0, i
;
64 assert(seed_size
> 0);
66 f
= open_memstream(&url
, &url_size
);
72 for (i
= 0; i
< seed_size
; i
++) {
73 if (i
> 0 && i
% 3 == 0)
75 fprintf(f
, "%02x", ((uint8_t*) seed
)[i
]);
78 fprintf(f
, "/%"PRIx64
"-%"PRIx64
"?machine=" SD_ID128_FORMAT_STR
,
81 SD_ID128_FORMAT_VAL(machine
));
84 fprintf(f
, ";hostname=%s", hn
);
94 qr
= QRcode_encodeString(url
, 0, QR_ECLEVEL_L
, QR_MODE_8
, 1);
100 print_border(output
, qr
->width
);
102 for (y
= 0; y
< (unsigned) qr
->width
; y
+= 2) {
103 const uint8_t *row1
, *row2
;
105 row1
= qr
->data
+ qr
->width
* y
;
106 row2
= row1
+ qr
->width
;
108 fputs(WHITE_ON_BLACK
, output
);
109 for (x
= 0; x
< 4; x
++)
110 fputs("\342\226\210", output
);
112 for (x
= 0; x
< (unsigned) qr
->width
; x
++) {
116 b
= (y
+1) < (unsigned) qr
->width
? (row2
[x
] & 1) : false;
121 fputs("\342\226\204", output
);
123 fputs("\342\226\200", output
);
125 fputs("\342\226\210", output
);
128 for (x
= 0; x
< 4; x
++)
129 fputs("\342\226\210", output
);
130 fputs(NORMAL
"\n", output
);
133 print_border(output
, qr
->width
);