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 // we have a problem jim
58 $xps = explode(":", $recvd);
60 $component = unserialize(base64_decode($xps[1]));
62 if($component["type"] != $message_type) {
63 // we have a problem jim
64 socket_close($socket);
68 socket_close($socket);
70 return $component["data"];
73 // this is one thing i love about php... how truely dynamic it can be in very easy to do ways.
74 // im not entirely sure what im doing with this bit yet
75 function __call($func, $params)
77 // im a little stuck here.
78 // want messages to be defineable in terms of plugins
79 // but i dont think this is the way to do it
81 $st_defined = constant($func);
82 //echo "func is $st_defined\n";
83 $function_send = $MESSAGES[$st_defined]."_clientsend";
84 $function_recv = $MESSAGES[$st_defined]."_clientrecv";
85 //echo "real function is $function_send, $function_recv\n";
87 if(function_exists($function_send) && function_exists($function_recv)) {
88 $function_recv($this->sendReceive($st_defined, $function_send($params)));
90 error_log("Function, $function does not exist!");