just trying to figure out how to create the db properly
[ga4php.git] / authserver / lib / authClient.php
index 2783e91..22a08b3 100644 (file)
@@ -5,26 +5,146 @@ require_once("lib.php");
 class GAAuthClient {
        
        function setUserToken($username, $token) {
+               global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
+               
+               
+               if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
+                       return false;
+               }
+
+               if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
+                       return false;
+               }
+               // TODO we need to setup a client queue sem lock here
+               
+               $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
+               $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
+               
+               $message["username"] = $username;
+               $message["token"] = $token;
+               
+               msg_send($sr_queue, MSG_SET_USER_TOKEN, $message, true, true, $msg_err);
+               echo "message sent\n";
+               
+               msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
+               echo "message received?\n";
+               print_r($msg);
+               
                
        }
        
        function setUserPass($username, $password) {
+               global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
+               
+               
+               if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
+                       return false;
+               }
+
+               if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
+                       return false;
+               }
+               // TODO we need to setup a client queue sem lock here
+               
+               $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
+               $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
+
+               $message["username"] = $username;
+               $message["password"] = $password;
+               
+               msg_send($sr_queue, MSG_SET_USER_PASSWORD, $message, true, true, $msg_err);
+               echo "message sent\n";
                
+               msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
+               echo "message received?\n";
+               print_r($msg);          
+       
        }
        
        function authUserPass($username, $password) {
+               global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
+               
+               
+               if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
+                       return false;
+               }
+
+               if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
+                       return false;
+               }
+               // TODO we need to setup a client queue sem lock here
+               
+               $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
+               $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
+
+               $message["username"] = $username;
+               $message["password"] = $password;
+               
+               msg_send($sr_queue, MSG_AUTH_USER_PASSWORD, $message, true, true, $msg_err);
+               echo "message sent\n";
+               
+               msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
+               echo "message received?\n";
+               print_r($msg);
                
        }
        
        function deleteUser($username) {
+               global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
+               
+               
+               if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
+                       return false;
+               }
+
+               if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
+                       return false;
+               }
+               // TODO we need to setup a client queue sem lock here
+               
+               $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
+               $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
+
+               $message["username"] = $username;
+               
+               msg_send($sr_queue, MSG_DELETE_USER, $message, true, true, $msg_err);
+               echo "message sent\n";
+               
+               msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
+               echo "message received?\n";
+               print_r($msg);
                
        }
        
        function setUserRealName($username, $realname) {
+               global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
+               
+               
+               if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
+                       return false;
+               }
+
+               if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
+                       return false;
+               }
+               // TODO we need to setup a client queue sem lock here
+               
+               $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
+               $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
+
+               $message["username"] = $username;
+               $message["realname"] = $realname;
+               
+               msg_send($sr_queue, MSG_SET_USER_REALNAME, $message, true, true, $msg_err);
+               echo "message sent\n";
+               
+               msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
+               echo "message received?\n";
+               print_r($msg);
                
        }
        
-       function authUser($username, $passcode) {
+       function getUsers() {
                global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
                
                
@@ -40,8 +160,34 @@ class GAAuthClient {
                $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
                $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
                
+               msg_send($sr_queue, MSG_GET_USERS, "", true, true, $msg_err);
+               echo "message sent\n";
+               
+               msg_receive($cl_queue, 0, $msg_type, 524288, $msg);
+               echo "message received?\n";
+               print_r($msg);
+               
+               return $msg;
+       }
+       
+       function authUserToken($username, $passcode) {
+               global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
+               
                
-               $message["user"] = $username;
+               if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
+                       return false;
+               }
+
+               if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
+                       return false;
+               }
+               // TODO we need to setup a client queue sem lock here
+               
+               $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
+               $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
+               
+               
+               $message["username"] = $username;
                $message["passcode"] = $passcode;
                
                msg_send($sr_queue, MSG_AUTH_USER, $message, true, true, $msg_err);
@@ -51,7 +197,7 @@ class GAAuthClient {
                echo "message received?\n";
                print_r($msg);
                
-               return false;
+               return $msg;
        }
        
        function addUser($username) {
@@ -74,6 +220,39 @@ class GAAuthClient {
                
                $message["username"] = $username;
                
+               msg_send($sr_queue, MSG_ADD_USER_TOKEN, $message, true, true, $msg_err);
+               echo "message sent\n";
+               
+               msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
+               echo "message received?\n";
+               print_r($msg);
+               
+               return $msg;
+               
+       }
+
+       function setTokenType($username, $tokentype) {
+               global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
+               
+               
+               if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
+                       return false;
+               }
+
+               if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
+                       return false;
+               }
+               
+               // TODO we need to setup a client queue sem lock here
+               
+               $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
+               $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
+               
+               
+               
+               $message["username"] = $username;
+               $message["tokentype"] = $tokentype;
+               
                msg_send($sr_queue, MSG_ADD_USER, $message, true, true, $msg_err);
                echo "message sent\n";
                
@@ -81,9 +260,9 @@ class GAAuthClient {
                echo "message received?\n";
                print_r($msg);
                
-               return false;
+               return $msg;
                
        }
 }
 
-?>
\ No newline at end of file
+?>