/**
* Create the HTML for a QR code for a URI.
*
* @param uri input string to encode
* @return NULL on error, encoded URI otherwise
*/
char *
TMH_create_qrcode (const char *uri)
{
QRinput *qri;
QRcode *qrc;
struct GNUNET_Buffer buf = { 0 };
qri = QRinput_new2 (0,
QR_ECLEVEL_M);
if (NULL == qri)
{
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
"QRinput_new2");
return NULL;
}
/* first try encoding as uppercase-only alpha-numerical
QR code (much smaller encoding); if that fails, also
try using binary encoding */
if ( (0 !=
QRinput_append (qri,
QR_MODE_AN,
strlen (uri),
(unsigned char *) uri)) &&
(0 !=
QRinput_append (qri,
QR_MODE_8,
strlen (uri),
(unsigned char *) uri)) )
{
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
"QRinput_append");
QRinput_free (qri);
return NULL;
}
qrc = QRcode_encodeInput (qri);
if (NULL == qrc)
{
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
"QRcode_encodeInput");
QRinput_free (qri);
return NULL;
}
QRinput_free (qri);
/* FIXME-Dold: generate with inline SVG instead of here! */
GNUNET_buffer_write_str (&buf,
"
\n
\n
\n
\n");
for (unsigned int y = 0; ywidth; y++)
{
GNUNET_buffer_write_str (&buf,
" ");
for (unsigned int x = 0; xwidth; x++)
{
unsigned int off = x + y * qrc->width;
GNUNET_buffer_write_fstr (&buf,
"%s",
(0 != (qrc->data[off] & 1))
? "██"
: " ");
}
GNUNET_buffer_write_str (&buf,
"
");
}
GNUNET_buffer_write_str (&buf,
"
\n
\n
\n
\n
");
QRcode_free (qrc);
return GNUNET_buffer_reap_str (&buf);
}