]>
git.proxmox.com Git - systemd.git/blob - src/journal/journal-qrcode.c
2 This file is part of systemd.
4 Copyright 2012 Lennart Poettering
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
27 #include "journal-qrcode.h"
29 #define WHITE_ON_BLACK "\033[40;37;1m"
30 #define NORMAL "\033[0m"
32 static void print_border(FILE *output
, unsigned width
) {
35 /* Four rows of border */
36 for (y
= 0; y
< 4; y
+= 2) {
37 fputs(WHITE_ON_BLACK
, output
);
39 for (x
= 0; x
< 4 + width
+ 4; x
++)
40 fputs("\342\226\210", output
);
42 fputs(NORMAL
"\n", output
);
57 size_t url_size
= 0, i
;
62 assert(seed_size
> 0);
64 f
= open_memstream(&url
, &url_size
);
70 for (i
= 0; i
< seed_size
; i
++) {
71 if (i
> 0 && i
% 3 == 0)
73 fprintf(f
, "%02x", ((uint8_t*) seed
)[i
]);
76 fprintf(f
, "/%"PRIx64
"-%"PRIx64
"?machine=" SD_ID128_FORMAT_STR
,
79 SD_ID128_FORMAT_VAL(machine
));
82 fprintf(f
, ";hostname=%s", hn
);
92 qr
= QRcode_encodeString(url
, 0, QR_ECLEVEL_L
, QR_MODE_8
, 1);
98 print_border(output
, qr
->width
);
100 for (y
= 0; y
< (unsigned) qr
->width
; y
+= 2) {
101 const uint8_t *row1
, *row2
;
103 row1
= qr
->data
+ qr
->width
* y
;
104 row2
= row1
+ qr
->width
;
106 fputs(WHITE_ON_BLACK
, output
);
107 for (x
= 0; x
< 4; x
++)
108 fputs("\342\226\210", output
);
110 for (x
= 0; x
< (unsigned) qr
->width
; x
++) {
114 b
= (y
+1) < (unsigned) qr
->width
? (row2
[x
] & 1) : false;
119 fputs("\342\226\204", output
);
121 fputs("\342\226\200", output
);
123 fputs("\342\226\210", output
);
126 for (x
= 0; x
< 4; x
++)
127 fputs("\342\226\210", output
);
128 fputs(NORMAL
"\n", output
);
131 print_border(output
, qr
->width
);