]> code.citadel.org Git - citadel.git/blobdiff - ctdlphp/ctdlprotocol.php
* put the vcard we just read back in.
[citadel.git] / ctdlphp / ctdlprotocol.php
index bd619598e257c688a8e0bac8c0cd77e012d6529e..7a332052b4ca57faa305968aa9e239900c26b3c5 100644 (file)
@@ -8,6 +8,10 @@
 include "config_ctdlclient.php";
 
 
+define("FMT_CITADEL", 0);
+define("FMT_FIXED", 1);
+define("FMT_RFC822", 4);
+
 //--------------------------------------------------------------------------------
 //   internal functions for server communication
 //--------------------------------------------------------------------------------
@@ -20,10 +24,31 @@ function serv_gets($readblock=FALSE) {
        $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 ("\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");
+       }
+       $buf = fread($clientsocket, $nBytes);
+       if (CITADEL_DEBUG_CITPROTO == 1) {
+               if (!$buf) printf ("<div class='ctdldbgRead'>\n");
                printf($buf);
-               if (!$readblock) printf ("</div>");
-               else printf ("<br>");
+               if (!$buf) printf ("</div>\n");
+               else printf ("<br>\n");
        }
        return $buf;
 }
@@ -37,13 +62,14 @@ function serv_puts($buf) {
        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")){
@@ -52,12 +78,34 @@ function read_array() {
                $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)
+           printf ("</div>\n");
+       return array($statusline, $buf);
+}
+
 
 
 // 
@@ -310,6 +358,19 @@ function ctdl_get_serv_info() {
 
 }
 
+//
+// 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.)
@@ -464,12 +525,11 @@ function ctdl_knrooms() {
        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;
 
@@ -505,6 +565,46 @@ function ctdl_knrooms() {
 
 }
 
+//
+// 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.
@@ -611,4 +711,87 @@ function ctdl_msg4_from_server() {
 }
 
 
+
+function download_attachment($msgnum, $attindex)
+{
+       $command = "DLAT ".$msgnum."|".$attindex;
+       serv_puts($command);
+       $reply = read_binary();
+       return $reply;
+
+}
+
+
+function enter_message_0($msgHdr, $contentType, $data)
+{
+       $send = array();
+
+       if (isset($msgHdr['newusermail']))
+               array_unshift($send, $msgHdr['newusermail']);
+       else
+               array_unshift($send, "");
+
+       if (isset($msgHdr['supplied_euid']))
+               array_unshift($send, $msgHdr['supplied_euid']);
+       else
+               array_unshift($send, "");
+
+       if (isset($msgHdr['bcc']))
+               array_unshift($send, $msgHdr['bcc']);
+       else
+               array_unshift($send, "");
+
+       if (isset($msgHdr['cc']))
+               array_unshift($send, $msgHdr['cc']);
+       else
+               array_unshift($send, "");
+
+       if (isset($msgHdr['do_confirm']))
+               array_unshift($send, $msgHdr['do_confirm']);
+       else
+               array_unshift($send, "");
+
+       if (isset($msgHdr['newusername']))
+               array_unshift($send, $msgHdr['newusername']);
+       else
+               array_unshift($send, "");
+
+       if (isset($msgHdr['subject']))
+               array_unshift($send, $msgHdr['subject']);
+       else
+               array_unshift($send, "");
+
+       if (isset($msgHdr['format_type']))
+               array_unshift($send, $msgHdr['format_type']);
+       else
+               array_unshift($send, "");
+
+       if (isset($msgHdr['anon_flag']))
+               array_unshift($send, $msgHdr['anon_flag']);
+       else
+               array_unshift($send, "");
+
+       if (isset($msgHdr['recp']))
+               array_unshift($send, $msgHdr['recp']);
+       else
+               array_unshift($send, "");
+
+       if (isset($msgHdr['post']))
+               array_unshift($send, $msgHdr['post']);
+       else
+               array_unshift($send, "");
+
+       $params = implode('|', $send);
+       serv_puts("ENT0 ".$params);
+
+       $reply=serv_gets();
+       if (substr($reply, 0, 1) != 4)
+               return array(false, array(), array());
+       serv_puts("Content-type: ".$contentType);
+       serv_puts("");
+       serv_puts($data."\r\n");
+       serv_puts("000");
+}
+
+
 ?>