From f3432f5956a3d9daa740b09cc92f769451666d63 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Wilfried=20G=C3=B6esgens?= Date: Sun, 10 Jun 2007 19:36:41 +0000 Subject: [PATCH] * new debug switch for communication in the session-proxy * DLAT works now. --- ctdlphp/config_ctdlclient.php | 1 + ctdlphp/ctdlprotocol.php | 37 +++++---------------------- ctdlphp/ctdlsession.php | 9 ++++++- ctdlphp/sessionproxy.php | 47 +++++++++++++++++++++++++++-------- 4 files changed, 52 insertions(+), 42 deletions(-) diff --git a/ctdlphp/config_ctdlclient.php b/ctdlphp/config_ctdlclient.php index ed65575dc..40676657d 100644 --- a/ctdlphp/config_ctdlclient.php +++ b/ctdlphp/config_ctdlclient.php @@ -8,4 +8,5 @@ define('CITADEL_TCP_PORTNO','504'); #do you want to see the server conversation for exploring the protocol? define('CITADEL_DEBUG_CITPROTO',1); +define('CITADEL_DEBUG_PROXY', TRUE); ?> \ No newline at end of file diff --git a/ctdlphp/ctdlprotocol.php b/ctdlphp/ctdlprotocol.php index 677ad5c00..93ff6f7d4 100644 --- a/ctdlphp/ctdlprotocol.php +++ b/ctdlphp/ctdlprotocol.php @@ -39,33 +39,13 @@ function serv_get_n($nBytes) { printf("reading ".$nBytes." bytes from server\n"); printf ("\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 ("
\n"); - printf($buf); - if (!$buf) printf ("
\n"); - else printf ("
\n"); - } -// $buf .= $tbuf; -// $nRead = strlen ($buf); - - } - - //$buf = fread($clientsocket, $nBytes) | die ("fread failed"); // Read line + $buf = fread($clientsocket, $nBytes); if (CITADEL_DEBUG_CITPROTO == 1) { - printf ("
\n"); + if (!$buf) printf ("
\n"); printf($buf); - printf ("
\n"); + if (!$buf) printf ("
\n"); + else printf ("
\n"); } - print_r($buf); return $buf; } @@ -117,11 +97,8 @@ function read_binary() { $buf = serv_get_n($statusline[1]); } - - if (CITADEL_DEBUG_CITPROTO == 1){ - echo "read ".$statusline[1]." bytes from the server.\n"; - printf ("\n"); - } + if (CITADEL_DEBUG_CITPROTO == 1) + printf ("\n"); return array($statusline, $buf); } @@ -736,8 +713,6 @@ function downoad_attachment($msgnum, $attindex) $command = "DLAT ".$msgnum."|".$attindex; serv_puts($command); $reply = read_binary(); - - print_r($reply); return $reply; } diff --git a/ctdlphp/ctdlsession.php b/ctdlphp/ctdlsession.php index 9dbf0ec22..3ee498431 100644 --- a/ctdlphp/ctdlsession.php +++ b/ctdlphp/ctdlsession.php @@ -42,8 +42,15 @@ function establish_citadel_session() { //exec($cmd); // It ain't there, dude. Open up the proxy. (PHP version) + if (CITADEL_DEBUG_PROXY){ + $stdout = '>>/tmp/sessionproxyout.txt'; + } + else{ + $stdout = '>/dev/null'; + } + $cmd = "./sessionproxy.php " . $sockname . - " /dev/null 2>&1 " . + " &1 " . " 3>&1 4>&1 5>&1 6>&1 7>&1 8>&1 & " ; exec($cmd); diff --git a/ctdlphp/sessionproxy.php b/ctdlphp/sessionproxy.php index 59b84c0f8..681ee1af5 100755 --- a/ctdlphp/sessionproxy.php +++ b/ctdlphp/sessionproxy.php @@ -17,11 +17,21 @@ include "config_ctdlclient.php"; // sock_gets() -- reads one line of text from a socket // -$logfd = +$msgsock; +if (CITADEL_DEBUG_PROXY) +{ + define_syslog_variables(); + openlog("sessionproxylog", LOG_PID | LOG_PERROR, LOG_LOCAL0); +} function sock_gets($sock) { + global $msgsock; socket_clear_error($msgsock); $buf = socket_read($sock, 4096, PHP_NORMAL_READ); - if (socket_last_error($buf)) return false; + if (CITADEL_DEBUG_PROXY) + { + syslog(LOG_DEBUG, "gets Read: ".$buf); + } + if (socket_last_error($sock)) return false; if (preg_match("'\n$'s", $buf)) { $buf = substr($buf, 0, strpos($buf, "\n")); @@ -33,7 +43,6 @@ function sock_gets($sock) { - // *** Start of main program *** error_reporting(E_ALL); @@ -129,6 +138,8 @@ do { if ($msgsock >= 0) do { $buf = sock_gets($msgsock); if ($buf !== false) { +// fwrite($logfd, ">>"); +// fwride($logfd, $buf); if (!fwrite($ctdlsock, $buf . "\n")) { fclose($ctdlsock); socket_close($sock); @@ -136,7 +147,15 @@ do { exit(9); } $talkback = fgets($ctdlsock, 4096); + if (CITADEL_DEBUG_PROXY) + { + syslog(LOG_DEBUG, "talkback: ".$talkback); + } if (!$talkback) { + if (CITADEL_DEBUG_PROXY) + { + syslog(LOG_ERROR, "closing socket."); + } fclose($ctdlsock); socket_close($sock); system("/bin/rm -f " . $sockname); @@ -144,6 +163,21 @@ do { } socket_write($msgsock, $talkback, strlen($talkback)); + // BINARY_FOLLOWS mode + if (substr($talkback, 0, 1) == "6") { + $bytes = intval(substr($talkback, 4)); + if (CITADEL_DEBUG_PROXY) + { + syslog(LOG_DEBUG, "reading ".$bytes." bytes from server"); + } + $buf = fread($ctdlsock, $bytes); + if (CITADEL_DEBUG_PROXY) + { + syslog(LOG_DEBUG, "Read: ".$buf); + } + socket_write($msgsock, $buf, $bytes); + } + // LISTING_FOLLOWS mode if (substr($talkback, 0, 1) == "1") do { $buf = fgets($ctdlsock, 4096); @@ -156,13 +190,6 @@ do { } } while ($buf != "000\n"); - // BINARY_FOLLOWS mode - if (substr($talkback, 0, 1) == "6") { - $bytes = intval(substr($talkback, 4)); - $buf = fread($ctdlock, $bytes); - socket_write($msgsock, $buf, $bytes); - } - // SEND_LISTING mode if (substr($talkback, 0, 1) == "4") do { socket_clear_error($msgsock); -- 2.30.2