aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2013-05-30 22:28:47 +0200
committerGravatar Christian Hesse <mail@eworm.de>2013-05-30 22:28:47 +0200
commit5ece91d61135a878df15bac6da104df875ae42a7 (patch)
tree0fc2cff8347d43d8373c93c094e131cf11967465
parent70f2ae0d2a2d215e8d4387c3063f4985569e05c9 (diff)
downloadcqrlogo-5ece91d61135a878df15bac6da104df875ae42a7.tar.gz
cqrlogo-5ece91d61135a878df15bac6da104df875ae42a7.tar.zst
work without referer and extend meta data
If HTTP_REFERER is not defined we return SERVER_NAME. Additionally add meta data for referer.
-rw-r--r--cqrlogo.c42
1 files changed, 23 insertions, 19 deletions
diff --git a/cqrlogo.c b/cqrlogo.c
index 2a14e37..c67ca06 100644
--- a/cqrlogo.c
+++ b/cqrlogo.c
@@ -59,7 +59,7 @@ int main(int argc, char **argv) {
regex_t preg;
size_t nmatch = 1;
regmatch_t pmatch[1];
- int rc;
+ int rc = 0;
GdkPixbuf *pixbuf;
@@ -67,27 +67,30 @@ int main(int argc, char **argv) {
gsize size;
/* check if we have environment variables from CGI */
- if ((http_referer = getenv("HTTP_REFERER")) == NULL ||
- (server_name = getenv("SERVER_NAME")) == NULL) {
+ if ((server_name = getenv("SERVER_NAME")) == NULL) {
fprintf(stderr, "This is a CGI executable. Running without a web service is not supported.\n"
- "Note that HTTP_REFERER and SERVER_NAME need to be defined.\n");
+ "Note that SERVER_NAME needs to be defined, for full features the client has\n"
+ "to send referer information.\n");
return EXIT_FAILURE;
}
-
- /* prepare pattern matching */
- pattern = malloc(28 + strlen(server_name));
- sprintf(pattern, "^[hH][tT][tT][pP][sS]\\?://%s/", server_name);
- if ((rc = regcomp(&preg, pattern, 0)) != 0)
- fprintf(stderr, "regcomp() failed, returning nonzero (%d)\n", rc);
-
- /* check if the QR-Code is for the correct server */
- if ((rc = regexec(&preg, http_referer, nmatch, pmatch, 0)) != 0) {
- http_referer = malloc(44 + strlen(server_name));
- sprintf(http_referer, "This QR Code has been stolen from http://%s/!", server_name);
- }
+ if ((http_referer = getenv("HTTP_REFERER")) == NULL) {
+ http_referer = server_name;
+ } else {
+ /* prepare pattern matching */
+ pattern = malloc(28 + strlen(server_name));
+ sprintf(pattern, "^[hH][tT][tT][pP][sS]\\?://%s/", server_name);
+ if ((rc = regcomp(&preg, pattern, 0)) != 0)
+ fprintf(stderr, "regcomp() failed, returning nonzero (%d)\n", rc);
+
+ /* check if the QR-Code is for the correct server */
+ if ((rc = regexec(&preg, http_referer, nmatch, pmatch, 0)) != 0) {
+ http_referer = malloc(44 + strlen(server_name));
+ sprintf(http_referer, "This QR Code has been stolen from %s!", server_name);
+ }
- regfree(&preg);
- free(pattern);
+ regfree(&preg);
+ free(pattern);
+ }
/* initialize type system for glib < 2.36 */
#ifndef GLIB_VERSION_2_36
@@ -106,7 +109,8 @@ int main(int argc, char **argv) {
/* print PNG data */
gdk_pixbuf_save_to_buffer (pixbuf, &buffer, &size, "png", NULL,
- "tEXt::comment", "QR-Code created by cqrlogo - https://github.com/eworm-de/cqrlogo", NULL);
+ "tEXt::comment", "QR-Code created by cqrlogo - https://github.com/eworm-de/cqrlogo",
+ "tEXt::referer", http_referer, NULL);
fwrite (buffer, 1, size, stdout);
if (rc)