pico-bmc/cgi.h
ltcptgeneral 914d73a86a move pico libs to pico_lib.h,
add INV option to PW_SWITCH and PW_STATE
2024-02-18 11:55:43 -08:00

45 lines
1022 B
C

#ifndef CGI_H
#define CGI_H
#include "lwip/apps/httpd.h"
#include "handlers.h"
const char * cgi_power_handler (int iIndex, int iNumParams, char * pcParam [], char * pcValue []) {
// Check if an request for power has been made (/power?requested_state=x)
if (strcmp(pcParam[0] , "requested_state") == 0){
if (strcmp(pcValue[0], "0") == 0) {
bmc_power_handler(false);
return "/power.ssi";
}
else if (strcmp(pcValue[0], "1") == 0) {
bmc_power_handler(true);
return "/power.ssi";
}
else {
return "/error_requested_state_invalid.ssi";
}
}
// Send the index page back to the user
else {
return "/error_missing_requested_state.ssi";
}
}
const char * cgi_status_handler (int iIndex, int iNumParams, char *pcParam[], char *pcValue[]) {
return "/status.ssi";
}
static const tCGI cgi_handlers[] = {
{
"/power", cgi_power_handler
},
{
"/status", cgi_status_handler
}
};
void cgi_init(void) {
http_set_cgi_handlers(cgi_handlers, 2);
}
#endif