From: Jeremy Tan Date: Wed, 23 Oct 2013 02:38:12 +0000 (+0800) Subject: fixes X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=f153e203bc4215026abd0dcce8427d633b5a6398;p=matches%2FMCTX3420.git fixes --- diff --git a/server/control.h b/server/control.h index 7081c3f..0dfdc47 100644 --- a/server/control.h +++ b/server/control.h @@ -18,6 +18,8 @@ typedef enum ControlModes { /** The same as INVALID_CHARACTERS, except escaped for use in JSON strings **/ #define INVALID_CHARACTERS_JSON "\\\"*/:<>?\\\\|. " +#define NOAUTH_USERNAME "_anonymous_noauth" + extern void Control_Handler(FCGIContext *context, char *params); extern const char* Control_SetMode(ControlModes desired_mode, void * arg); extern ControlModes Control_GetMode(); diff --git a/server/fastcgi.c b/server/fastcgi.c index af92efd..525e964 100644 --- a/server/fastcgi.c +++ b/server/fastcgi.c @@ -46,8 +46,7 @@ static void IdentifyHandler(FCGIContext *context, char *params) FCGI_BeginJSON(context, STATUS_OK); FCGI_JSONPair("description", "MCTX3420 Server API (2013)"); FCGI_JSONPair("build_date", __DATE__ " " __TIME__); - struct timespec t; - t.tv_sec = 0; t.tv_nsec = 0; + struct timespec t = {0}; clock_getres(CLOCK_MONOTONIC, &t); FCGI_JSONDouble("clock_getres", TIMEVAL_TO_DOUBLE(t)); FCGI_JSONLong("api_version", API_VERSION); @@ -591,13 +590,21 @@ void * FCGI_RequestLoop (void *data) if (module_handler) { - if (g_options.auth_method != AUTH_NONE && module_handler != Login_Handler && module_handler != IdentifyHandler && module_handler) + if (module_handler != Login_Handler && module_handler != IdentifyHandler && module_handler) //if (false) // Testing { if (!FCGI_HasControl(&context)) { - FCGI_RejectJSON(&context, "Please login. Invalid control key."); - continue; + if (g_options.auth_method == AUTH_NONE) + { //:( + Log(LOGWARN, "Locking control (no auth!)"); + FCGI_LockControl(&context, NOAUTH_USERNAME, USER_ADMIN); + } + else + { + FCGI_RejectJSON(&context, "Please login. Invalid control key."); + continue; + } } //Escape all special characters. diff --git a/server/main.c b/server/main.c index fadcd3a..bd649a7 100644 --- a/server/main.c +++ b/server/main.c @@ -205,17 +205,18 @@ int main(int argc, char ** argv) // Try and start things - const char *ret; - if ((ret = Control_SetMode(CONTROL_START, "test")) != NULL) - Fatal("Control_SetMode failed with '%s'", ret); + //const char *ret; + //if ((ret = Control_SetMode(CONTROL_START, "test")) != NULL) + // Fatal("Control_SetMode failed with '%s'", ret); // run request thread in the main thread FCGI_RequestLoop(NULL); - if ((ret = Control_SetMode(CONTROL_STOP, "test")) != NULL) - Fatal("Control_SetMode failed with '%s'", ret); + Conrol_SetMode(CONTROL_STOP, NULL); + //if ((ret = Control_SetMode(CONTROL_STOP, "test")) != NULL) + // Fatal("Control_SetMode failed with '%s'", ret); //Sensor_StopAll(); //Actuator_StopAll();