read_uuid_from_file(plugin_name, uuidfile);
}
+bool isCommand(const char *str, unsigned int siw) {
+ switch (siw) {
+ case SIW_OLSRD_CONF:
+ return strstr(str, "/olsrd.conf");
+
+ case SIW_ALL:
+ return strstr(str, "/all");
+
+ case SIW_RUNTIME_ALL:
+ return strstr(str, "/runtime");
+
+ case SIW_STARTUP_ALL:
+ return strstr(str, "/startup");
+
+ case SIW_NEIGHBORS:
+ return strstr(str, "/neighbors");
+
+ case SIW_LINKS:
+ return strstr(str, "/links");
+
+ case SIW_ROUTES:
+ return strstr(str, "/routes");
+
+ case SIW_HNA:
+ return strstr(str, "/hna");
+
+ case SIW_MID:
+ return strstr(str, "/mid");
+
+ case SIW_TOPOLOGY:
+ return strstr(str, "/topology");
+
+ case SIW_GATEWAYS:
+ return strstr(str, "/gateways");
+
+ case SIW_INTERFACES:
+ return strstr(str, "/interfaces");
+
+ case SIW_2HOP:
+ return strstr(str, "/2hop");
+
+ case SIW_SGW:
+ return strstr(str, "/sgw");
+
+ case SIW_VERSION:
+ return strstr(str, "/version");
+
+ case SIW_CONFIG:
+ return strstr(str, "/config");
+
+ case SIW_PLUGINS:
+ return strstr(str, "/plugins");
+
+ case SIW_NEIGHBORS_FREIFUNK:
+ return strstr(str, "/neighbours");
+
+ default:
+ return false;
+ }
+}
+
const char * determine_mime_type(unsigned int send_what) {
return (send_what & SIW_ALL) ? "application/json; charset=utf-8" : "text/plain; charset=utf-8";
}
static printer_functions_t printer_functions = { //
//
.init = &plugin_init, //
+ .is_command = &isCommand, //
.determine_mime_type = &determine_mime_type, //
.neighbors = &ipc_print_neighbors, //
.links = &ipc_print_links, //
};
static void determine_action(unsigned int *send_what, char *requ) {
- if (strstr(requ, "/olsrd.conf"))
+ if (!printer_functions.is_command)
+ *send_what = 0;
+ else if ((*printer_functions.is_command)(requ, SIW_OLSRD_CONF))
*send_what |= SIW_OLSRD_CONF;
- else if (strstr(requ, "/all"))
+ else if ((*printer_functions.is_command)(requ, SIW_ALL))
*send_what = SIW_ALL;
else {
// these are the two overarching categories
- if (strstr(requ, "/runtime"))
+ if ((*printer_functions.is_command)(requ, SIW_RUNTIME_ALL))
*send_what |= SIW_RUNTIME_ALL;
- if (strstr(requ, "/startup"))
+ if ((*printer_functions.is_command)(requ, SIW_STARTUP_ALL))
*send_what |= SIW_STARTUP_ALL;
// these are the individual sections
- if (strstr(requ, "/neighbors"))
+ if ((*printer_functions.is_command)(requ, SIW_NEIGHBORS))
*send_what |= SIW_NEIGHBORS;
- if (strstr(requ, "/links"))
+ if ((*printer_functions.is_command)(requ, SIW_LINKS))
*send_what |= SIW_LINKS;
- if (strstr(requ, "/routes"))
+ if ((*printer_functions.is_command)(requ, SIW_ROUTES))
*send_what |= SIW_ROUTES;
- if (strstr(requ, "/hna"))
+ if ((*printer_functions.is_command)(requ, SIW_HNA))
*send_what |= SIW_HNA;
- if (strstr(requ, "/mid"))
+ if ((*printer_functions.is_command)(requ, SIW_MID))
*send_what |= SIW_MID;
- if (strstr(requ, "/topology"))
+ if ((*printer_functions.is_command)(requ, SIW_TOPOLOGY))
*send_what |= SIW_TOPOLOGY;
- if (strstr(requ, "/gateways"))
+ if ((*printer_functions.is_command)(requ, SIW_GATEWAYS))
*send_what |= SIW_GATEWAYS;
- if (strstr(requ, "/interfaces"))
+ if ((*printer_functions.is_command)(requ, SIW_INTERFACES))
*send_what |= SIW_INTERFACES;
- if (strstr(requ, "/2hop"))
+ if ((*printer_functions.is_command)(requ, SIW_2HOP))
*send_what |= SIW_2HOP;
- if (strstr(requ, "/sgw"))
+ if ((*printer_functions.is_command)(requ, SIW_SGW))
*send_what |= SIW_SGW;
// specials
- if (strstr(requ, "/version"))
+ if ((*printer_functions.is_command)(requ, SIW_VERSION))
*send_what |= SIW_VERSION;
- if (strstr(requ, "/config"))
+ if ((*printer_functions.is_command)(requ, SIW_CONFIG))
*send_what |= SIW_CONFIG;
- if (strstr(requ, "/plugins"))
+ if ((*printer_functions.is_command)(requ, SIW_PLUGINS))
*send_what |= SIW_PLUGINS;
/* To print out neighbours only on the Freifunk Status
* page the normal output is somewhat lengthy. The
* header parsing is sufficient for standard wget.
*/
- if (strstr(requ, "/neighbours"))
- *send_what = SIW_NEIGHBORS | SIW_LINKS;
+ if ((*printer_functions.is_command)(requ, SIW_NEIGHBORS_FREIFUNK))
+ *send_what = SIW_NEIGHBORS_FREIFUNK;
}
}