aboutsummaryrefslogtreecommitdiffstats
path: root/lib/libcqrlogo.h
blob: cc3153c48ac48472579e4e3dfab8a77f24fe9349 (about) (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
 * (C) 2013-2016 by Christian Hesse <mail@eworm.de>
 *
 * This software may be used and distributed according to the terms
 * of the GNU General Public License, incorporated herein by reference.
 */

#ifndef _LIBCQRLOGO_H
#define _LIBCQRLOGO_H

#define _GNU_SOURCE

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include <stdbool.h>

#include <png.h>
#include <zlib.h>
#include <qrencode.h>
#include <iniparser.h>

/* a bitmap */
struct cqr_bitmap {
	unsigned int width;
	unsigned int height;
	uint8_t *pixel;
};

/* finished PNG image */
struct cqr_png {
	unsigned char * buffer;
	size_t size;
};

/* config */
struct cqr_conf {
	uint8_t scale;
	uint8_t border;
	uint8_t level;
	bool overwrite;
};

#define CQR_HEADER_CACHE_CONTROL	"Cache-Control: no-cache, max-age=0\n"
#define CQR_HEADER_CONTENT_TYPE		"Content-Type: image/png\n"
#define CQR_HEADER_CONTENT_DISPOSITION	"Content-Disposition: inline; filename=\"cqrlogo.png\"\n"
#define CQR_HEADER_PRAGMA		"Pragma: no-cache\n"

#define CQR_META_COMMENT	0x1
#define CQR_META_REFERER	0x2
#define CQR_META_VERSION	0x4
#define CQR_META_LIBVERSION	0x8
#define CQR_META_ALL		CQR_META_COMMENT + CQR_META_REFERER + CQR_META_VERSION + CQR_META_LIBVERSION

#define CQR_COMMENTSTR	"QR-Code created by cqrlogo - https://github.com/eworm-de/cqrlogo"
#define CQR_VERSIONSTR	VERSION " (" __DATE__ ", " __TIME__ ")"
#define CQR_LIBSSTR	"libqrencode %s, libpng %s, zlib %s"

/*** cqr_png_write_fn ***/
void cqr_png_write_fn(png_structp png_ptr, png_bytep data, png_size_t length);

#if defined PNG_TEXT_SUPPORTED
/*** cqr_png_add_text ***/
png_text * cqr_png_add_text(png_text *pngtext, unsigned int *textcount, char *key, char *text);
#endif

/*** cqr_bitmap_new ***/
struct cqr_bitmap * cqr_bitmap_new(int width, int height);
/*** cqr_bitmap_free ***/
void cqr_bitmap_free(struct cqr_bitmap * bitmap);

/*** cqr_encode_qrcode_to_bitmap ***/
struct cqr_bitmap * cqr_encode_qrcode_to_bitmap(const char *text, const struct cqr_conf conf);
/*** cqr_bitmap_to_png ***/
struct cqr_png * cqr_bitmap_to_png(struct cqr_bitmap *bitmap, const char *text, const uint8_t meta);
/*** cqr_encode_qrcode_to_png ***/
struct cqr_png * cqr_encode_qrcode_to_png(const char *text, const struct cqr_conf conf, const uint8_t meta);

/*** cqr_get_query_uint ***/
unsigned int cqr_get_query_uint(const char *query_string, const char *pattern,
	unsigned int value, unsigned int min, unsigned int max);
/*** get_query_char ***/
char * cqr_get_query_char(const char *query_string, const char *pattern);
/*** cqr_get_ini_value ***/
unsigned int cqr_get_ini_value(dictionary * ini, uint8_t type, const char * section, const char * parameter,
	unsigned int value, unsigned int min, unsigned int max);

/*** cqr_conf_file ***/
void cqr_conf_file(const char * server_name, struct cqr_conf * conf);
/*** cqr_conf_string ***/
void cqr_conf_string(const char * query_string, struct cqr_conf * conf);

#endif /* _LIBCQRLOGO_H */

// vim: set syntax=c: