From daddd6cb7d021a73de45cd21f42da438c65dc1df Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Mon, 9 May 2016 11:53:44 +0200 Subject: introduce cqr_get_query_char() --- lib/libcqrlogo.c | 22 ++++++++++++++++++++++ lib/libcqrlogo.h | 2 ++ 2 files changed, 24 insertions(+) diff --git a/lib/libcqrlogo.c b/lib/libcqrlogo.c index d2690ab..1502887 100644 --- a/lib/libcqrlogo.c +++ b/lib/libcqrlogo.c @@ -261,6 +261,28 @@ unsigned int cqr_get_query_uint(const char *query_string, const char *pattern, return value; } +/*** get_query_char ***/ +char * cqr_get_query_char(const char *query_string, const char *pattern) { + char *value = NULL, *cut = NULL; + const char *tmp = NULL, *match = NULL; + + if ((match = strstr(query_string, pattern)) == NULL) + return NULL; + + if ((tmp = strchr(match, '=')) == NULL) + return NULL; + + if (strlen(tmp) < 1) + return NULL; + + value = strdup(tmp + 1); + + if ((cut = strchr(value, '&')) != NULL) + *cut = '\0'; + + return value; +} + /*** get_ini_value ***/ unsigned int get_ini_value(dictionary * ini, uint8_t type, const char * section, const char * parameter, unsigned int value, unsigned int min, unsigned int max) { diff --git a/lib/libcqrlogo.h b/lib/libcqrlogo.h index 4be5087..cc3153c 100644 --- a/lib/libcqrlogo.h +++ b/lib/libcqrlogo.h @@ -80,6 +80,8 @@ struct cqr_png * cqr_encode_qrcode_to_png(const char *text, const struct cqr_con /*** 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); -- cgit v1.2.3-54-g00ecf