X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=ctdlphp%2Fctdlprotocol.php;h=80b5a3219739f227664bb79942009ca944a0d5e1;hb=a5c66770dfd125d3d18bbdd607252604748877f3;hp=a104d03bbbaea174efe626da4d3d6e8723baf1d2;hpb=3aece284ede198abf2fb13b643198d9d97b4ecef;p=citadel.git diff --git a/ctdlphp/ctdlprotocol.php b/ctdlphp/ctdlprotocol.php index a104d03bb..80b5a3219 100644 --- a/ctdlphp/ctdlprotocol.php +++ b/ctdlphp/ctdlprotocol.php @@ -1,24 +1,86 @@ -// This program is released under the terms of the GNU General Public License. +// One program is released under the terms of the GNU General Public License. +include "config_ctdlclient.php"; + +define('VIEW_BBS' ,'0'); /* Bulletin board view */ +define('VIEW_MAILBOX' ,'1'); /* Mailbox summary */ +define('VIEW_ADDRESSBOOK' ,'2'); /* Address book view */ +define('VIEW_CALENDAR' ,'3'); /* Calendar view */ +define('VIEW_TASKS' ,'4'); /* Tasks view */ +define('VIEW_NOTES' ,'5'); /* Notes view */ +define("FMT_CITADEL", 0); +define("FMT_FIXED", 1); +define("FMT_RFC822", 4); + +function debugLog($string) +{ + print ($string); +} +function dbgprintf_wrapin($string, $html) +{ + if (!CITADEL_DEBUG_HTML){ + if ($html) + debugLog("<< ".$string."\n"); + } + else + printf($string); +} +function dbgprintf_wrapout($string, $html) +{ + if (!CITADEL_DEBUG_HTML){ + if ($html) + debugLog("<< ".$string."\n"); + } + else + printf($string); +} +//-------------------------------------------------------------------------------- +// internal functions for server communication +//-------------------------------------------------------------------------------- // // serv_gets() -- generic function to read one line of text from the server // -function serv_gets() { +function serv_gets($readblock=FALSE) { global $clientsocket; $buf = fgets($clientsocket, 4096); // Read line $buf = substr($buf, 0, (strlen($buf)-1) ); // strip trailing LF + if (CITADEL_DEBUG_CITPROTO == 1) { + if (!$readblock) dbgprintf_wrapin("
", false); + dbgprintf_wrapout(print_r($server_info, true), true); + dbgprintf_wrapout("", false); + } + return $server_info; + } + else + { + dbgprintf_wrapin ("didn't understand the reply to the INFO command". + print_r($reply, TRUE), false); + + die ("CTDLPHP: didn't understand the reply to the INFO command"); } +} + +// +// Learn all sorts of interesting things about the Citadel server to +// which we are connected. +/* http://www.citadel.org/doku.php/documentation:appproto:connection#info.get.server.info */ +// +function ctdl_get_registration_info() { + serv_puts("GREG"); + $reply = read_array(); + dbgprintf_wrapout(print_r($reply, true), true); +// die ("didn't understand the reply to the INFO command"); } // // Display a system banner. (Returns completed HTML.) -// (This is probably temporary because it outputs more or less finalized +// (One is probably temporary because it outputs more or less finalized // markup. For now it's just usable.) // +/* http://www.citadel.org/doku.php/documentation:appproto:connection#mesg.read.system.message */ function ctdl_mesg($msgname) { global $clientsocket; $msgtext = "
", false); + dbgprintf_wrapout(print_r($oneline, true), true); + dbgprintf_wrapout("", false);; - $tok = strtok("|"); - if ($tok) $thisline["user"] = $tok; - - $tok = strtok("|"); - if ($tok) $thisline["room"] = $tok; - - $tok = strtok("|"); - if ($tok) $thisline["host"] = $tok; - - $tok = strtok("|"); - if ($tok) $thisline["client"] = $tok; + } - // IGnore the rest of the fields for now. - $num_lines = array_push($all_lines, $thisline); + $num_lines = array_push($all_lines, $oneline); } return array($num_lines, $all_lines); @@ -271,13 +534,44 @@ function ctdl_goto($to_where) { serv_puts("GOTO " . $to_where); $response = serv_gets(); - if (substr($response, 0, 1) == "2") { - $_SESSION["room"] = strtok(substr($response, 4), "|"); - return array(TRUE, substr($response, 0, 3)); + $results = explode ("|", $response); + $status_room = array_shift($results); + $status = substr($status_room, 0, 3); + if (substr($status, 0, 1) == "2") { + $room = substr($status_room, 4); + array_unshift($results, $room); + $room_state=array( + "state" => TRUE, + "statereply" => $status, + "roomname" => $results[ 0], + "nunreadmsg" => $results[ 1], + "nmessages" => $results[ 2], + "rinfopresent" => $results[ 3], + "flags" => $results[ 4], + "msgidmax" => $results[ 5], + "msgidreadmax" => $results[ 6], + "ismailroom" => $results[ 7], + "isroomaide" => $results[ 8], + "nnewmessages" => $results[ 9], + "floorid" => $results[10], + "viewselected" => $results[11], + "defaultview" => $results[12], + "istrashcan" => $results[13]); + + $_SESSION["room"] = $room; + if (CITADEL_DEBUG_CITPROTO == 1) + { + dbgprintf_wrapout("
", false); + dbgprintf_wrapout(print_r($room_state, true), true); + dbgprintf_wrapout("", false); + + } + + return $room_state; } else { - return array(FALSE, substr($response, 0, 3)); + return array("state" => FALSE, "statereply" => $status); } } @@ -292,73 +586,108 @@ function ctdl_knrooms() { serv_puts("LKRA"); $response = serv_gets(); - if (substr($response, 0, 1) != "1") { return array(0, NULL); } - + $results = read_array(); $all_lines = array(); $num_lines = 0; - while (strcmp($buf = serv_gets(), "000")) { - - $thisline = array(); - - $tok = strtok($buf, "|"); - if ($tok) $thisline["name"] = $tok; - - $tok = strtok("|"); - if ($tok) $thisline["flags"] = $tok; - - $tok = strtok("|"); - if ($tok) $thisline["floor"] = $tok; - - $tok = strtok("|"); - if ($tok) $thisline["order"] = $tok; - - $tok = strtok("|"); - if ($tok) $thisline["flags2"] = $tok; + foreach ($results as $result){ + $oneline = array(); + $tokens = explode("|",$result); - $tok = strtok("|"); - if ($tok) $thisline["access"] = $tok; + $oneline["name"] = $tokens[0]; + $oneline["flags"] = $tokens[1]; + $oneline["floor"] = $tokens[2]; + $oneline["order"] = $tokens[3]; + $oneline["flags2"] = $tokens[4]; + $oneline["access"] = $tokens[5]; - if ($thisline["access"] & 8) { - $thisline["hasnewmsgs"] = TRUE; + if ($oneline["access"] & 8) { + $oneline["hasnewmsgs"] = TRUE; } else { - $thisline["hasnewmsgs"] = FALSE; + $oneline["hasnewmsgs"] = FALSE; + } + + if (CITADEL_DEBUG_CITPROTO == 1) + { + dbgprintf_wrapout("
", false); + dbgprintf_wrapout(print_r($oneline, true), true); + dbgprintf_wrapout("", false); + } + $num_lines = array_push($all_lines, $oneline); + } - $num_lines = array_push($all_lines, $thisline); + return array($num_lines, $all_lines); + +} + +// +// Fetch the list of known floors. +// +/* http://www.citadel.org/doku.php/documentation:appproto:rooms#lflr.list.all.known.floors */ +function ctdl_knfloors() { + global $clientsocket; + + serv_puts("LFLR"); + $response = serv_gets(); + if (substr($response, 0, 1) != "1") { + return array(0, NULL); + } + + $results = read_array(); + $all_lines = array(); + $num_lines = 0; + + foreach ($results as $result){ + $oneline = array(); + $tokens = explode("|",$result); + + $oneline["id"] = $tokens[0]; + $oneline["name"] = $tokens[1]; + $oneline["nref"] = $tokens[2]; + + if (CITADEL_DEBUG_CITPROTO == 1) + { + dbgprintf_wrapout("
", false); + dbgprintf_wrapout(print_r($oneline, true), true); + dbgprintf_wrapout("", false); + } + $num_lines = array_push($all_lines, $oneline); } return array($num_lines, $all_lines); } +/* http://www.citadel.org/doku.php/documentation:appproto:rooms#cflr.create.a.new.floor */ // -// Fetch the list of messages in this room. +// Fetch the list of messages in one room. // Returns: count, response, message array // function ctdl_msgs($mode, $count) { global $clientsocket; serv_puts("MSGS " . $mode . "|" . $count); - $response = serv_gets(); + $responses = read_array(); + dbgprintf_wrapout(print_r($responses, true), false); + + $response = array_shift($responses); + $num_msgs = count($responses); if (substr($response, 0, 1) != "1") { return array(0, substr($response, 4), NULL); } - $msgs = array(); - $num_msgs = 0; - - while (strcmp($buf = serv_gets(), "000")) { - $num_msgs = array_push($msgs, $buf); + if (CITADEL_DEBUG_CITPROTO == 1) + { + dbgprintf_wrapout("found ".$num_msgs." messages.", true); } - - return array($num_msgs, substr($response, 4), $msgs); + return array($num_msgs, $response, $responses); } @@ -367,17 +696,26 @@ function ctdl_fetch_message($msgnum) { global $clientsocket; serv_puts("MSG4 " . $msgnum); - $response = serv_gets(); + + if (CITADEL_DEBUG_CITPROTO == 1) + dbgprintf_wrapout("