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/>.
30 #include "journal-qrcode.h"
32 #define WHITE_ON_BLACK "\033[40;37;1m"
33 #define NORMAL "\033[0m"
35 static void print_border(FILE *output, unsigned width) {
38 /* Four rows of border */
39 for (y = 0; y < 4; y += 2) {
40 fputs(WHITE_ON_BLACK, output);
42 for (x = 0; x < 4 + width + 4; x++)
43 fputs("\342\226\210", output);
45 fputs(NORMAL "\n", output);
60 size_t url_size = 0, i;
65 assert(seed_size > 0);
67 f = open_memstream(&url, &url_size);
73 for (i = 0; i < seed_size; i++) {
74 if (i > 0 && i % 3 == 0)
76 fprintf(f, "%02x", ((uint8_t*) seed)[i]);
79 fprintf(f, "/%llx-%llx?machine=" SD_ID128_FORMAT_STR,
80 (unsigned long long) start,
81 (unsigned long long) interval,
82 SD_ID128_FORMAT_VAL(machine));
85 fprintf(f, ";hostname=%s", hn);
95 qr = QRcode_encodeString(url, 0, QR_ECLEVEL_L, QR_MODE_8, 1);
101 print_border(output, qr->width);
103 for (y = 0; y < (unsigned) qr->width; y += 2) {
104 const uint8_t *row1, *row2;
106 row1 = qr->data + qr->width * y;
107 row2 = row1 + qr->width;
109 fputs(WHITE_ON_BLACK, output);
110 for (x = 0; x < 4; x++)
111 fputs("\342\226\210", output);
113 for (x = 0; x < (unsigned) qr->width; x ++) {
117 b = (y+1) < (unsigned) qr->width ? (row2[x] & 1) : false;
122 fputs("\342\226\204", output);
124 fputs("\342\226\200", output);
126 fputs("\342\226\210", output);
129 for (x = 0; x < 4; x++)
130 fputs("\342\226\210", output);
131 fputs(NORMAL "\n", output);
134 print_border(output, qr->width);