fixes
authorJeremy Tan <[email protected]>
Wed, 23 Oct 2013 02:38:12 +0000 (10:38 +0800)
committerJeremy Tan <[email protected]>
Wed, 23 Oct 2013 02:38:12 +0000 (10:38 +0800)
server/control.h
server/fastcgi.c
server/main.c

index 7081c3f..0dfdc47 100644 (file)
@@ -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();
index af92efd..525e964 100644 (file)
@@ -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.
index fadcd3a..bd649a7 100644 (file)
@@ -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();

UCC git Repository :: git.ucc.asn.au