* Cleanup of session creation
authorArt Cancro <ajc@citadel.org>
Fri, 31 Oct 2003 04:16:16 +0000 (04:16 +0000)
committerArt Cancro <ajc@citadel.org>
Fri, 31 Oct 2003 04:16:16 +0000 (04:16 +0000)
ctdlphp/ctdlheader.php
ctdlphp/ctdlprotocol.php
ctdlphp/ctdlsession.php
ctdlphp/logout.php
ctdlphp/sessionproxy.php

index 590fc6992a534d6e7974287760a683f75136fc81..57e78cbad06b6759f0a0a6d1e455d2b16a2db552 100644 (file)
@@ -43,18 +43,9 @@ test_for_echo();
 
 
 function bbs_page_footer() {
-       global $clientsocket;
-
        echo "<HR>";
-
-       if (!fclose($clientsocket)) {
-               echo "Error closing client socket.<BR>\n";
-       }
-
        echo "Copyright &copy; 2003 by The SCO Group.<BR>\n";
        echo "</BODY></HTML>\n";
-
-
 }
 
 ?>
index 50a3e012a2ad9306bdb0220393832dd350e52229..4f0b60e62a80c76fd35eb402b435544532f8e2c1 100644 (file)
@@ -10,7 +10,8 @@ function test_for_echo() {
        flush();
        echo "Writing...<BR>\n";
        flush();
-       fwrite($clientsocket, $command, strlen($command));
+       // fwrite($clientsocket, $command, strlen($command));
+       fwrite($clientsocket, $command);
        echo "Reading...<BR>\n";
        flush();
        $response = fgets($clientsocket, 4096);
index 605529b52d1ec158e52763eeb5cc89cd6447bb55..25427420bafb565c18728b175faccf378ab07aa6 100644 (file)
@@ -51,13 +51,13 @@ function establish_citadel_session() {
                echo "Connected.  Performing echo tests.<BR>\n";
                flush();
                $cmd = "ECHO test echo string upon connection\n";
-               fwrite($clientsocket, $cmd, strlen($cmd));
+               fwrite($clientsocket, $cmd);
                $response = fgets($clientsocket, 4096);
                echo "Response is: ", $response, "<BR>\n";
                flush();
 
                $cmd = "ECHO second test for echo\n";
-               fwrite($clientsocket, $cmd, strlen($cmd));
+               fwrite($clientsocket, $cmd);
                $response = fgets($clientsocket, 4096);
                echo "Response is: ", $response, "<BR>\n";
                flush();
@@ -71,15 +71,20 @@ function establish_citadel_session() {
 }
 
 
+//
+// Clear out both our Citadel session and our PHP session.  We're done.
+//
 function ctdl_end_session() {
        global $clientsocket, $session;
 
-       session_destroy();
+       // Tell the Citadel server to terminate our connection.
+       fwrite($clientsocket, "QUIT\n");
+       fclose($clientsocket);
        unset($clientsocket);
-       unset($session); 
 
-       echo "Session destroyed.<BR>\n";
-       
+       // Now clear our PHP session.
+       unset($session); 
+       session_destroy();
 }
 
 ?>
index 14a2c68d7953d30f042aa8f7b9ad691bf5882759..284983c8a1cfe10df5eacfe7b31e21e51fb34f58 100644 (file)
@@ -13,8 +13,8 @@ You are being logged out.
 
 LITERAL;
 
-       ctdl_end_session();
        bbs_page_footer();
+       ctdl_end_session();
 
 ?>
 
index 5c5ee40c37ca817d1a9e2fce7ed53c8650670c6d..d9977a636a44bfe3cf7521607d2eea8829f93d37 100755 (executable)
@@ -60,18 +60,21 @@ system("/bin/rm -f " . $sockname);
 $sock = socket_create(AF_UNIX, SOCK_STREAM, 0);
 if ($sock < 0) {
        echo "socket_create() failed: ", socket_strerror($sock), "\n";
+       system("/bin/rm -f " . $sockname);
        exit(2);
 }
 
 $ret = socket_bind($sock, $sockname);
 if ($ret < 0) {
        echo "socket_bind() failed: ", socket_strerror($ret), "\n";
+       system("/bin/rm -f " . $sockname);
        exit(3);
 }
 
 $ret = socket_listen($sock, 5);
 if ($ret < 0) {
        echo "socket_listen() failed: ", socket_strerror($ret), "\n";
+       system("/bin/rm -f " . $sockname);
        exit(4);
 }
 
@@ -85,20 +88,23 @@ if (!$ctdlsock) {
        exit(5);
 }
 
-echo "Connected to Citadel server.\n";
-$buf = fgets($ctdlsock, 4096);
-echo $buf, "\n";
+// Read the greeting from the Citadel server.
+if (!$buf = fgets($ctdlsock, 4096)) {
+       socket_close ($sock);
+       system("/bin/rm -f " . $sockname);
+       exit(6);
+}
+
+// Make sure the server is allowing logins.
+if (substr($buf, 0, 1) != "2") {
+       socket_close ($sock);
+       system("/bin/rm -f " . $sockname);
+       exit(7);
+}
 
 do {
        $msgsock = socket_accept($sock);
-       if ($msgsock < 0) {
-               echo "socket_accept() failed: ",
-                       socket_strerror($msgsock), "\n";
-               break;
-       }
-
-       do {
-               echo "Reading a line...\n";
+       if ($msgsock >= 0) do {
                $buf = sock_gets($msgsock);
                if ($buf !== false) {
                        fwrite($ctdlsock, $buf . "\n", (strlen($buf)+1) );
@@ -107,13 +113,12 @@ do {
                }
        } while($buf !== false);
 
-       echo "Closing socket.\n";
-
        socket_close ($msgsock);
 
 } while (true);
 
-socket_close ($sock);
+socket_close($sock);
+socket_close($ctdlsock);
 system("/bin/rm -f " . $sockname);
 exit(0);