[Olsr-dev] [PATCH v1 18/18] info: introduce command prefixes '/http' and '/plain'
Ferry Huberts
(spam-protected)
Sat Dec 10 18:25:28 CET 2016
From: Ferry Huberts <(spam-protected)>
All info plugins support a number of request prefixes:
- /http : forces output WITH http headers, temporarily overriding the
configured "httpheaders" value.
- /plain: forces output WITHOUT http headers, temporarily overriding the
configured "httpheaders" value.
These prefixes have to be at the start of the request string, can occur
only there, and can occur only once.
Note that this will NOT work when there is an internal error (only occurs
when the connection is not ready to be read, which is very unlikely).
Signed-off-by: Ferry Huberts <(spam-protected)>
---
lib/info/README_INFO | 17 +++++++++++++++++
lib/info/info_types.h | 6 ++++++
lib/info/olsrd_info.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 73 insertions(+)
diff --git a/lib/info/README_INFO b/lib/info/README_INFO
index 783d8cf..77d0672 100644
--- a/lib/info/README_INFO
+++ b/lib/info/README_INFO
@@ -38,6 +38,23 @@ assumed.
Check the README of the actual info plugin to see the supported commands.
+================
+REQUEST PREFIXES
+================
+
+All info plugins support a number of request prefixes:
+- /http : forces output WITH http headers, temporarily overriding the
+ configured "httpheaders" value.
+- /plain: forces output WITHOUT http headers, temporarily overriding the
+ configured "httpheaders" value.
+
+These prefixes have to be at the start of the request string, can occur
+only there, and can occur only once.
+
+Note that this will NOT work when there is an internal error (only occurs
+when the connection is not ready to be read, which is very unlikely).
+
+
====================
PLUGIN CONFIGURATION
====================
diff --git a/lib/info/info_types.h b/lib/info/info_types.h
index aae8f9d..57aa7fb 100644
--- a/lib/info/info_types.h
+++ b/lib/info/info_types.h
@@ -111,6 +111,12 @@ typedef struct {
/* everything */
#define SIW_EVERYTHING ((SIW_NETJSON_NETWORK_COLLECTION << 1) - 1)
+/* command prefixes */
+#define SIW_PREFIX_HTTP_TEXT "/http"
+#define SIW_PREFIX_HTTP_TEXT_LEN (sizeof(SIW_PREFIX_HTTP_TEXT) - 1)
+#define SIW_PREFIX_PLAIN_TEXT "/plain"
+#define SIW_PREFIX_PLAIN_TEXT_LEN (sizeof(SIW_PREFIX_PLAIN_TEXT) - 1)
+
typedef void (*init_plugin)(const char *plugin_name);
typedef unsigned long long (*supported_commands_mask_func)(void);
typedef bool (*command_matcher)(const char *str, unsigned long long siw);
diff --git a/lib/info/olsrd_info.c b/lib/info/olsrd_info.c
index 91fd72d..7f5a0ad 100644
--- a/lib/info/olsrd_info.c
+++ b/lib/info/olsrd_info.c
@@ -663,6 +663,52 @@ static char * parseRequest(char * req, size_t *len) {
return req;
}
+static char * checkCommandPrefixes(char * req, size_t *len, bool *add_headers) {
+ if (!req || !len || !*len || !add_headers) {
+ return req;
+ }
+
+ /* '/http/...' */
+
+ if (!strncasecmp(req, SIW_PREFIX_HTTP_TEXT "/", SIW_PREFIX_HTTP_TEXT_LEN + 1)) {
+ *len = *len - SIW_PREFIX_HTTP_TEXT_LEN;
+ req = &req[SIW_PREFIX_HTTP_TEXT_LEN];
+ *add_headers = true;
+ return req;
+ }
+
+ /* '/http' */
+
+ if ((*len == SIW_PREFIX_HTTP_TEXT_LEN) && !strcasecmp(req, SIW_PREFIX_HTTP_TEXT)) {
+ *len = 0;
+ *req = '\0';
+ *add_headers = true;
+ return req;
+ }
+
+ /* '/plain/...' */
+
+ if (!strncasecmp(req, SIW_PREFIX_PLAIN_TEXT "/", SIW_PREFIX_PLAIN_TEXT_LEN + 1)) {
+ *len = *len - SIW_PREFIX_PLAIN_TEXT_LEN;
+ req = &req[SIW_PREFIX_PLAIN_TEXT_LEN];
+ *add_headers = false;
+ return req;
+ }
+
+ /* '/plain' */
+
+ if ((*len == SIW_PREFIX_PLAIN_TEXT_LEN) && !strcasecmp(req, SIW_PREFIX_PLAIN_TEXT)) {
+ *len = 0;
+ *req = '\0';
+ *add_headers = false;
+ return req;
+ }
+
+ /* no prefixes */
+
+ return req;
+}
+
static void drain_request(int ipc_connection) {
static char drain_buffer[AUTOBUFCHUNK];
@@ -763,6 +809,10 @@ static void ipc_action(int fd, void *data __attribute__ ((unused)), unsigned int
req = stripTrailingSlashes(req, (size_t*) &rx_count);
req = skipLeadingWhitespace(req, (size_t*) &rx_count);
req = skipMultipleSlashes(req, (size_t*) &rx_count);
+
+ req = checkCommandPrefixes(req, (size_t*) &rx_count, &add_headers);
+
+ req = skipMultipleSlashes(req, (size_t*) &rx_count);
}
if (outbuffer.count >= MAX_CLIENTS) {
--
2.9.3
More information about the Olsr-dev
mailing list