* new debug switch for communication in the session-proxy
authorWilfried Göesgens <willi@citadel.org>
Sun, 10 Jun 2007 19:36:41 +0000 (19:36 +0000)
committerWilfried Göesgens <willi@citadel.org>
Sun, 10 Jun 2007 19:36:41 +0000 (19:36 +0000)
* DLAT works now.

ctdlphp/config_ctdlclient.php
ctdlphp/ctdlprotocol.php
ctdlphp/ctdlsession.php
ctdlphp/sessionproxy.php

index ed65575dc53cf4701a3f39d89ccf14b158958adc..40676657df4f411d03a4d8b3c8b2d956c2b01136 100644 (file)
@@ -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
index 677ad5c000e9e482955c51d67aba9f44b1469d21..93ff6f7d4f9c7381f005e3637901d18dbb3447f2 100644 (file)
@@ -39,33 +39,13 @@ function serv_get_n($nBytes) {
                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
+       $buf = fread($clientsocket, $nBytes);
        if (CITADEL_DEBUG_CITPROTO == 1) {
-               printf ("<div class='ctdldbgRead'>\n");
+               if (!$buf) printf ("<div class='ctdldbgRead'>\n");
                printf($buf);
-               printf ("</div>\n");
+               if (!$buf) printf ("</div>\n");
+               else printf ("<br>\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 ("</div>\n");
-       }
+       if (CITADEL_DEBUG_CITPROTO == 1)
+           printf ("</div>\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;
 
 }
index 9dbf0ec22aa6736ed4d138aca88f08f190b34850..3ee4984311e9443a14632ff1b1db9a099fac3d5c 100644 (file)
@@ -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 >/dev/null 2>&1 " .
+                       " </dev/null ".$stdout."2>&1 " .
                        " 3>&1 4>&1 5>&1 6>&1 7>&1 8>&1 & " ;
                exec($cmd);
 
index 59b84c0f8af081449858c6ac808f8b1a4f9d3754..681ee1af5175918db506e55df1ab1a0dd1e643e4 100755 (executable)
@@ -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);