comms work between authd and authclient
[ga4php.git] / authserver / lib / authClient.php
1 <?php
2
3 require_once("lib.php");
4
5 class GAAuthClient {
6         
7         function setUserToken($username, $token) {
8                 global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
9                 
10                 
11                 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
12                         return false;
13                 }
14
15                 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
16                         return false;
17                 }
18                 // TODO we need to setup a client queue sem lock here
19                 
20                 $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
21                 $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
22                 
23                 $message["username"] = $username;
24                 $message["token"] = $token;
25                 
26                 msg_send($sr_queue, MSG_SET_USER_TOKEN, $message, true, true, $msg_err);
27                 echo "message sent\n";
28                 
29                 msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
30                 echo "message received?\n";
31                 print_r($msg);
32                 
33                 
34         }
35         
36         function setUserPass($username, $password) {
37                 global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
38                 
39                 
40                 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
41                         return false;
42                 }
43
44                 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
45                         return false;
46                 }
47                 // TODO we need to setup a client queue sem lock here
48                 
49                 $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
50                 $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
51
52                 $message["username"] = $username;
53                 $message["password"] = $password;
54                 
55                 msg_send($sr_queue, MSG_SET_USER_PASSWORD, $message, true, true, $msg_err);
56                 echo "message sent\n";
57                 
58                 msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
59                 echo "message received?\n";
60                 print_r($msg);          
61         
62         }
63         
64         function authUserPass($username, $password) {
65                 global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
66                 
67                 
68                 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
69                         return false;
70                 }
71
72                 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
73                         return false;
74                 }
75                 // TODO we need to setup a client queue sem lock here
76                 
77                 $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
78                 $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
79
80                 $message["username"] = $username;
81                 $message["password"] = $password;
82                 
83                 msg_send($sr_queue, MSG_AUTH_USER_PASSWORD, $message, true, true, $msg_err);
84                 echo "message sent\n";
85                 
86                 msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
87                 echo "message received?\n";
88                 print_r($msg);
89                 
90         }
91         
92         function deleteUser($username) {
93                 global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
94                 
95                 
96                 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
97                         return false;
98                 }
99
100                 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
101                         return false;
102                 }
103                 // TODO we need to setup a client queue sem lock here
104                 
105                 $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
106                 $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
107
108                 $message["username"] = $username;
109                 
110                 msg_send($sr_queue, MSG_DELETE_USER, $message, true, true, $msg_err);
111                 echo "message sent\n";
112                 
113                 msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
114                 echo "message received?\n";
115                 print_r($msg);
116                 
117         }
118         
119         function setUserRealName($username, $realname) {
120                 global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
121                 
122                 
123                 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
124                         return false;
125                 }
126
127                 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
128                         return false;
129                 }
130                 // TODO we need to setup a client queue sem lock here
131                 
132                 $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
133                 $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
134
135                 $message["username"] = $username;
136                 $message["realname"] = $realname;
137                 
138                 msg_send($sr_queue, MSG_SET_USER_REALNAME, $message, true, true, $msg_err);
139                 echo "message sent\n";
140                 
141                 msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
142                 echo "message received?\n";
143                 print_r($msg);
144                 
145         }
146         
147         function getUsers() {
148                 global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
149                 
150                 
151                 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
152                         return false;
153                 }
154
155                 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
156                         return false;
157                 }
158                 // TODO we need to setup a client queue sem lock here
159                 
160                 $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
161                 $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
162                 
163                 msg_send($sr_queue, MSG_GET_USERS, "", true, true, $msg_err);
164                 echo "message sent\n";
165                 
166                 msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
167                 echo "message received?\n";
168                 print_r($msg);
169                 
170                 return $msg;
171         }
172         
173         function authUserToken($username, $passcode) {
174                 global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
175                 
176                 
177                 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
178                         return false;
179                 }
180
181                 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
182                         return false;
183                 }
184                 // TODO we need to setup a client queue sem lock here
185                 
186                 $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
187                 $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
188                 
189                 
190                 $message["username"] = $username;
191                 $message["passcode"] = $passcode;
192                 
193                 msg_send($sr_queue, MSG_AUTH_USER, $message, true, true, $msg_err);
194                 echo "message sent\n";
195                 
196                 msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
197                 echo "message received?\n";
198                 print_r($msg);
199                 
200                 return $msg;
201         }
202         
203         function addUser($username) {
204                 global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
205                 
206                 
207                 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
208                         return false;
209                 }
210
211                 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
212                         return false;
213                 }
214                 
215                 // TODO we need to setup a client queue sem lock here
216                 
217                 $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
218                 $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
219                 
220                 
221                 $message["username"] = $username;
222                 
223                 msg_send($sr_queue, MSG_ADD_USER_TOKEN, $message, true, true, $msg_err);
224                 echo "message sent\n";
225                 
226                 msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
227                 echo "message received?\n";
228                 print_r($msg);
229                 
230                 return $msg;
231                 
232         }
233
234         function setTokenType($username, $tokentype) {
235                 global $MSG_QUEUE_KEY_ID_SERVER, $MSG_QUEUE_KEY_ID_CLIENT;
236                 
237                 
238                 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_SERVER)) {
239                         return false;
240                 }
241
242                 if(!msg_queue_exists($MSG_QUEUE_KEY_ID_CLIENT)) {
243                         return false;
244                 }
245                 
246                 // TODO we need to setup a client queue sem lock here
247                 
248                 $cl_queue = msg_get_queue($MSG_QUEUE_KEY_ID_CLIENT);
249                 $sr_queue = msg_get_queue($MSG_QUEUE_KEY_ID_SERVER);
250                 
251                 
252                 
253                 $message["username"] = $username;
254                 $message["tokentype"] = $tokentype;
255                 
256                 msg_send($sr_queue, MSG_ADD_USER, $message, true, true, $msg_err);
257                 echo "message sent\n";
258                 
259                 msg_receive($cl_queue, 0, $msg_type, 16384, $msg);
260                 echo "message received?\n";
261                 print_r($msg);
262                 
263                 return $msg;
264                 
265         }
266 }
267
268 ?>