X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=ctdlphp%2Fctdlprotocol.php;h=80b5a3219739f227664bb79942009ca944a0d5e1;hb=51b18018ff923284d76a36cbd421d62abf6afcf4;hp=bd619598e257c688a8e0bac8c0cd77e012d6529e;hpb=c474bf690e7c1410e6d9331f46a968a44e7be877;p=citadel.git diff --git a/ctdlphp/ctdlprotocol.php b/ctdlphp/ctdlprotocol.php index bd619598e..80b5a3219 100644 --- a/ctdlphp/ctdlprotocol.php +++ b/ctdlphp/ctdlprotocol.php @@ -7,7 +7,40 @@ // 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 //-------------------------------------------------------------------------------- @@ -20,10 +53,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 ("
"); - printf($buf); - if (!$readblock) printf ("
"); - else printf ("
"); + if (!$readblock) dbgprintf_wrapin("
\n", false); + dbgprintf_wrapin($buf, true); + if (!$readblock) dbgprintf_wrapin ("\n
\n", false); + else dbgprintf_wrapin ("
\n", false); + } + 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) { + dbgprintf_wrapin ("
\n", false); + dbgprintf_wrapin("reading ".$nBytes." bytes from server\n", true); + dbgprintf_wrapin ("
\n", false); + } + $buf = fread($clientsocket, $nBytes); + if (CITADEL_DEBUG_CITPROTO == 1) { + if (!$buf) dbgprintf_wrapin ("
\n", false); + dbgprintf_wrapin($buf, true); + if (!$buf) dbgprintf_wrapin ("
\n", false); + else dbgprintf_wrapin ("
\n", false); } return $buf; } @@ -36,14 +90,18 @@ function serv_puts($buf) { fwrite($clientsocket, $buf . "\n", (strlen($buf)+1) ); fflush($clientsocket); - if (CITADEL_DEBUG_CITPROTO == 1) - printf ("
".$buf."
"); + if (CITADEL_DEBUG_CITPROTO == 1) { + dbgprintf_wrapin("
", false); + dbgprintf_wrapin($buf, true); + dbgprintf_wrapin("
\n", false); + } } + function read_array() { $nLines = 0; if (CITADEL_DEBUG_CITPROTO == 1) - printf ("
"); + dbgprintf_wrapout("
\n", false); $buf = serv_gets(TRUE); $ret = array(); while (strcasecmp($buf, "000")){ @@ -52,12 +110,34 @@ function read_array() { $nLines++; } if (CITADEL_DEBUG_CITPROTO == 1){ - echo "read ".$nLines." lines from the server."; - printf ("
"); + dbgprintf_wrapout("read ".$nLines." lines from the server.\n", true); + dbgprintf_wrapout ("
\n", false); } return $ret; } +function read_binary() { + $nLines = 0; + if (CITADEL_DEBUG_CITPROTO == 1) + dbgprintf_wrapout ("
\n", false); + $buf = serv_gets(TRUE); + + if (CITADEL_DEBUG_CITPROTO == 1){ + dbgprintf_wrapout("status line from the server\n", true); + } + + $statusline = explode(" ", $buf); + + if ($statusline[0] == 600) + { + $buf = serv_get_n($statusline[1]); + + } + if (CITADEL_DEBUG_CITPROTO == 1) + dbgprintf_wrapout ("
\n", false); + return array($statusline, $buf); +} + // @@ -211,7 +291,11 @@ function login_existing_user($user, $pass) { serv_puts("USER " . $user); $resp = serv_gets(); + + if (substr($resp, 0, 3) == 541) // we're already logged in. + return array(TRUE, substr($resp, 4)); if (substr($resp, 0, 1) != "3") { + return array(FALSE, substr($resp, 4)); } @@ -288,7 +372,7 @@ function become_logged_in($server_parms) { function ctdl_get_serv_info() { serv_puts("INFO"); $reply = read_array(); - if ((count($reply) == 18) && + if ((count($reply) == 23) && substr($reply[0], 0, 1) == "1") { $server_info=array(); $server_info["serv_nodename"] = $reply[1]; @@ -299,14 +383,31 @@ function ctdl_get_serv_info() { $server_info["serv_sysadmin"] = $reply[7]; if (CITADEL_DEBUG_CITPROTO == 1) { - echo "
";
-			print_r($server_info);
-			echo "
"; + dbgprintf_wrapout("
", false);
+			dbgprintf_wrapout(print_r($server_info, true), true);
+			dbgprintf_wrapout("
", false); } return $server_info; } else - die ("didn't understand the reply to the INFO command"); + { + 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"); } @@ -337,6 +438,26 @@ function ctdl_mesg($msgname) { return($msgtext); } +// +// Delete a Message. +// http://www.citadel.org/doku.php/documentation:appproto:room_indexes_and_messages#dele.delete.a.message + +function ctdl_dele($msgname) { + global $clientsocket; + + $msgtext = "
\n"; + + serv_puts("DELE " . $msgname); + $response = serv_gets(); + + if (substr($response[0], 0, 1) == "1") { + return TRUE; + } + else { + return FALSE; + } +} + /* http://www.citadel.org/doku.php/documentation:appproto:connection#mesg.read.system.message */ //// TODO: is this still supported? function ctdl_mrtg($what) { @@ -390,9 +511,9 @@ function ctdl_rwho() { // IGnore the rest of the fields for now. if (CITADEL_DEBUG_CITPROTO == 1) { - echo "
";
-			print_r($oneline);
-			echo "
"; + dbgprintf_wrapout("
", false);
+			dbgprintf_wrapout(print_r($oneline, true), true);
+			dbgprintf_wrapout("
", false);; } @@ -440,9 +561,9 @@ function ctdl_goto($to_where) { $_SESSION["room"] = $room; if (CITADEL_DEBUG_CITPROTO == 1) { - echo "
";
-			print_r($room_state);
-			echo "
"; + dbgprintf_wrapout("
", false);
+			dbgprintf_wrapout(print_r($room_state, true), true);
+			dbgprintf_wrapout("
", false); } @@ -464,12 +585,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; @@ -493,10 +613,48 @@ function ctdl_knrooms() { if (CITADEL_DEBUG_CITPROTO == 1) { - echo "
";
-			print_r($oneline);
-			echo "
"; + 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); + +} + +// +// 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); } @@ -505,6 +663,7 @@ function ctdl_knrooms() { } +/* http://www.citadel.org/doku.php/documentation:appproto:rooms#cflr.create.a.new.floor */ // // Fetch the list of messages in one room. @@ -515,7 +674,7 @@ function ctdl_msgs($mode, $count) { serv_puts("MSGS " . $mode . "|" . $count); $responses = read_array(); - print_r($responses); + dbgprintf_wrapout(print_r($responses, true), false); $response = array_shift($responses); @@ -526,7 +685,7 @@ function ctdl_msgs($mode, $count) { if (CITADEL_DEBUG_CITPROTO == 1) { - printf("found ".$num_msgs." messages."); + dbgprintf_wrapout("found ".$num_msgs." messages.", true); } return array($num_msgs, $response, $responses); } @@ -539,7 +698,7 @@ function ctdl_fetch_message($msgnum) { serv_puts("MSG4 " . $msgnum); if (CITADEL_DEBUG_CITPROTO == 1) - printf ("
"); + dbgprintf_wrapout("
", false); $response = serv_gets(TRUE); if (substr($response, 0, 1) != "1") { @@ -550,11 +709,13 @@ function ctdl_fetch_message($msgnum) { while (strcmp($buf = serv_gets(TRUE), "000")) { if (substr($buf, 0, 4) == "text") { if (CITADEL_DEBUG_CITPROTO == 1) - printf ("
\n

Message Body Follows

"); + dbgprintf_wrapout("
\n

Message Body Follows

", false); // We're in the text body. New loop here. - $fields["text"] = ctdl_msg4_from_server(); + $texts = ctdl_msg4_from_server(); + $fields["text"] = $texts[0]; + $fields["formated_text"]=$texts[1]; if (CITADEL_DEBUG_CITPROTO == 1) - printf ("
"); + dbgprintf_wrapout ("
", false); return array(TRUE, substr($response, 4), $fields); } else { @@ -566,12 +727,44 @@ function ctdl_fetch_message($msgnum) { return array(FALSE, substr($response, 4), $fields); } +// Load a message from the server. +function ctdl_fetch_message_rfc822($msgnum) { + global $clientsocket; + + serv_puts("MSG2 " . $msgnum); + + if (CITADEL_DEBUG_CITPROTO == 1) + dbgprintf_wrapout("
", false); + $response = serv_gets(TRUE); + + if (substr($response, 0, 1) != "1") { + return array(FALSE, NULL); + } + $message = ""; + $buf=""; + while ($buf = serv_gets(TRUE)) { +// dbgprintf_wrapout($buf, true); + if ($buf=="000") + { + $message .= "\n.\n"; + break; + } + $message = $message . "\n" . $buf; + $buf = ""; + } + +// dbgprintf_wrapout($message, true); + // Message terminated prematurely (no text body) + return array(TRUE, $message); +} + // Support function for ctdl_fetch_message(). This handles the text body // portion of the message, converting various formats to HTML as // appropriate. function ctdl_msg4_from_server() { $txt = ""; + $modified_txt = ""; $msgformat = "text/plain"; $in_body = FALSE; @@ -592,7 +785,9 @@ function ctdl_msg4_from_server() { $txt .= $buf; } else if (!strcasecmp($msgformat, "text/plain")) { - $txt .= "" . htmlspecialchars($buf) . "
\n" ; + $txt .= "\r\n".$buf; + $modified_txt .= "" . htmlspecialchars($buf) . "
\n" ; + } else if (!strcasecmp($msgformat, "text/x-citadel-variformat")) { if (substr($previous_line, 0, 1) == " ") { @@ -607,7 +802,90 @@ function ctdl_msg4_from_server() { } } - return($txt); + return(array($txt, $modified_txt)); +} + + + +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"); }