$buf = fgets($clientsocket, 4096); // Read line
$buf = substr($buf, 0, (strlen($buf)-1) ); // strip trailing LF
if (CITADEL_DEBUG_CITPROTO == 1) {
- if (!$readblock) printf ("<div class='ctdldbgRead'>");
+ if (!$readblock) printf ("<div class='ctdldbgRead'>\n");
printf($buf);
- if (!$readblock) printf ("</div>");
- else printf ("<br>");
+ if (!$readblock) printf ("\n</div>\n");
+ else printf ("<br>\n");
}
return $buf;
}
+//
+// serv_get_n() -- generic function to read a binary blob from the server
+//
+function serv_get_n($nBytes) {
+ global $clientsocket;
+
+ if (CITADEL_DEBUG_CITPROTO == 1) {
+ printf ("<div class='ctdldbgRead'>\n");
+ printf("reading ".$nBytes." bytes from server\n");
+ printf ("</div>\n");
+ }
+ $i = 0;
+ $buf = "";
+ $nRead = 0;
+// while ($nRead < $nBytes)
+ {
+ $buf = fread($clientsocket, $nBytes);
+// $buf.=fgetc($clientsocket) | die ("fgetc failed");
+// $buf .= serv_gets(TRUE);
+// $tbuf = fgets($clientsocket, $nBytes - $nRead);
+ if (CITADEL_DEBUG_CITPROTO == 1) {
+ if (!$buf) printf ("<div class='ctdldbgRead'>\n");
+ printf($buf);
+ if (!$buf) printf ("</div>\n");
+ else printf ("<br>\n");
+ }
+// $buf .= $tbuf;
+// $nRead = strlen ($buf);
+
+ }
+
+ //$buf = fread($clientsocket, $nBytes) | die ("fread failed"); // Read line
+ if (CITADEL_DEBUG_CITPROTO == 1) {
+ printf ("<div class='ctdldbgRead'>\n");
+ printf($buf);
+ printf ("</div>\n");
+ }
+ print_r($buf);
+ return $buf;
+}
+
//
// serv_puts() -- generic function to write one line of text to the server
//
fwrite($clientsocket, $buf . "\n", (strlen($buf)+1) );
fflush($clientsocket);
if (CITADEL_DEBUG_CITPROTO == 1)
- printf ("<div class='ctdldbgWrite'>".$buf."</div>");
+ printf ("<div class='ctdldbgWrite'>".$buf."</div>\n");
}
+
function read_array() {
$nLines = 0;
if (CITADEL_DEBUG_CITPROTO == 1)
- printf ("<div class='ctdldbgRead'>");
+ printf ("<div class='ctdldbgRead'>\n");
$buf = serv_gets(TRUE);
$ret = array();
while (strcasecmp($buf, "000")){
$nLines++;
}
if (CITADEL_DEBUG_CITPROTO == 1){
- echo "read ".$nLines." lines from the server.";
- printf ("</div>");
+ echo "read ".$nLines." lines from the server.\n";
+ printf ("</div>\n");
}
return $ret;
}
+function read_binary() {
+ $nLines = 0;
+ if (CITADEL_DEBUG_CITPROTO == 1)
+ printf ("<div class='ctdldbgRead'>\n");
+ $buf = serv_gets(TRUE);
+
+ if (CITADEL_DEBUG_CITPROTO == 1){
+ echo "status line from the server\n";
+ }
+
+ $statusline = explode(" ", $buf);
+
+ if ($statusline[0] == 600)
+ {
+ $buf = serv_get_n($statusline[1]);
+
+ }
+
+ if (CITADEL_DEBUG_CITPROTO == 1){
+ echo "read ".$statusline[1]." bytes from the server.\n";
+ printf ("</div>\n");
+ }
+ return array($statusline, $buf);
+}
+
//
}
+//
+// 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();
+ print_r($reply);
+// die ("didn't understand the reply to the INFO command");
+
+}
+
//
// Display a system banner. (Returns completed HTML.)
global $clientsocket;
serv_puts("LKRA");
- $results = read_array();
-
- if (substr($results[0], 0, 1) != "1") {
+ $response = serv_gets();
+ if (substr($response, 0, 1) != "1") {
return array(0, NULL);
}
- array_shift($results);
+ $results = read_array();
$all_lines = array();
$num_lines = 0;
}
+//
+// 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)
+ {
+ echo "<pre>";
+ print_r($oneline);
+ echo "</pre>";
+
+ }
+ $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 one room.
}
+
+function downoad_attachment($msgnum, $attindex)
+{
+ $command = "DLAT ".$msgnum."|".$attindex;
+ serv_puts($command);
+ $reply = read_binary();
+
+ print_r($reply);
+ return $reply;
+
+}
+
+
+
?>