]> code.citadel.org Git - citadel.git/blobdiff - ctdlphp/sessionproxy.php
* added implementations to the general purpose commands.
[citadel.git] / ctdlphp / sessionproxy.php
index 986eb2a5219a84a702f9daff22b6214fc162afe9..ee919ca99345f70455e1e3ef2d8b4eda611b9354 100755 (executable)
@@ -1,23 +1,26 @@
 #!/usr/bin/php -q
 
 <?php
-
+include "config_ctdlclient.php";
 // $Id$
 //
 // This is the session proxy that binds a unix domain socket to a Citadel
 // server connection.  We need one of these for each session because PHP does
 // not have a way to bind a session to a persistent socket.
 //
+// Web designers: don't touch this module.  It's not included in your web pages
+// and therefore you don't need to be here.
+//
 // Copyright (c) 2003 by Art Cancro <ajc@uncensored.citadel.org>
 // This program is released under the terms of the GNU General Public License.
-//
 
 
 // sock_gets() -- reads one line of text from a socket
 // 
 function sock_gets($sock) {
+       socket_clear_error($msgsock);
        $buf = socket_read($sock, 4096, PHP_NORMAL_READ);
-       if ($buf == false) return false;
+       if (socket_last_error($buf)) return false;
 
        if (preg_match("'\n$'s", $buf)) {
                $buf = substr($buf, 0, strpos($buf, "\n"));
@@ -83,8 +86,7 @@ chmod($sockname, 0600);
 
 // We need to get a connection to the Citadel server going now.
 
-$ctdlsock = fsockopen("uncensored.citadel.org", 504, $errno, $errstr, 30);
-//$ctdlsock = fsockopen("/appl/citadel/citadel.socket", 0, $errno, $errstr, 30);
+$ctdlsock = fsockopen(CITADEL_HOSTNAME, CITADEL_TCP_PORTNO, $errno, $errstr, 30);
 if (!$ctdlsock) {
        socket_close ($sock);
        system("/bin/rm -f " . $sockname);
@@ -141,6 +143,7 @@ do {
                        }
                        socket_write($msgsock, $talkback, strlen($talkback));
 
+                       // LISTING_FOLLOWS mode
                        if (substr($talkback, 0, 1) == "1") do {
                                $buf = fgets($ctdlsock, 4096);
                                if (!$buf) {
@@ -152,6 +155,21 @@ do {
                                }
                        } while ($buf != "000\n");
 
+                       // SEND_LISTING mode
+                       if (substr($talkback, 0, 1) == "4") do {
+                               socket_clear_error($msgsock);
+                               $buf = sock_gets($msgsock);
+                               if (socket_last_error($msgsock)) {
+                                       $buf = "000" ;
+                               }
+                               if (!fwrite($ctdlsock, $buf . "\n")) {
+                                       fclose($ctdlsock);
+                                       socket_close($sock);
+                                       system("/bin/rm -f " . $sockname);
+                                       exit(11);
+                               }
+                       } while ($buf != "000");
+
                }
        } while($buf !== false);