4 require_once("globalLib.php");
5 require_once("gaasClientMessages.php");
7 // I am the gaasd client.. i know all, i see all... I am the "only" way to interact with the gaasd server.
11 // the main send/receive functions. Communicates with gaasd
12 // we always expect one send followed by one receive message
13 function sendReceive($message_type, $message)
15 // yeah... this is totally gunna work
16 global $TCP_PORT_NUMBER;
18 $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
19 $res = socket_connect($socket, "127.0.0.1", $TCP_PORT_NUMBER);
21 socket_close($socket);
25 $msg["type"] = $message_type;
26 $msg["data"] = $message;
28 $datacomp = base64_encode(serialize($msg));
29 $tosend = "AC:$datacomp:EOD";
31 socket_send($socket, $tosend, strlen($tosend), 0);
33 // get up to one meg of data - this is bad... i can feel this function
35 // TODO FIX THIS - its garbage code... im not really sure how to handle this really
36 // we need to read back as AS:data:EOD - i think it now does.. i hope, tho we need
41 $size = socket_recv($socket, $recvd_a, 1024, 0);
43 if(preg_match("/.*\:EOD$/", $recvd)) {
44 // we have a full string... break out
51 // first check we got something that makes sense
52 if(preg_match("/^AS:.*:EOD/", $recvd) < 1) {
53 socket_close($socket);
54 echo "Returned data is not in right format\n";
55 // we have a problem jim
59 $xps = explode(":", $recvd);
61 $component = unserialize(base64_decode($xps[1]));
63 if($component["type"] != $message_type) {
64 echo "Message type was not the same as original message\n";
65 // we have a problem jim
66 socket_close($socket);
70 socket_close($socket);
72 return $component["data"];
75 // this is one thing i love about php... how truely dynamic it can be in very easy to do ways.
76 // im not entirely sure what im doing with this bit yet
77 function __call($func, $params)
79 // im a little stuck here.
80 // want messages to be defineable in terms of plugins
81 // but i dont think this is the way to do it
83 $st_defined = constant($func);
84 //echo "func is $st_defined\n";
85 $function_send = $MESSAGES[$st_defined]."_clientsend";
86 $function_recv = $MESSAGES[$st_defined]."_clientrecv";
87 //echo "real function is $function_send, $function_recv\n";
89 if(function_exists($function_send)) {
90 $fromsend = $this->sendReceive($st_defined, $function_send($params));
91 if(function_exists($function_recv)) {
92 return $function_recv($fromsend);
93 } else return $fromsend;
95 error_log("Function, $function does not exist!");