pull of unix socket to interact with apache2
[brisk.git] / web / spush / brisk-spush.php
index bb0cf4e..00d3e64 100755 (executable)
  * not, write to the Free Software Foundation, Inc, 59 Temple Place -
  * Suite 330, Boston, MA 02111-1307, USA.
  *
- * TODO
- *
- *   - pari + 72 non fa 4x ma attualmente fa 3x, da correggere
- *   - parametrization of $DOCUMENT_ROOT  var in brisk-spush.phh file
- *   - parametrization of SITE_PREFIX(_LEN) define
- *   - move the name of the named socket into the configuration file
- *   DISABLED_TO_FIX - DNS access (perform blocking dns requests, must be fixed)
- *
- *   TEST - database connection fails after a while, check close and try PGSQL_CONNECT_FORCE_NEW.
- *   TEST - images flickering on slow windows: try to poll stream every 300 ms
- *
- *   - centralize all '<script ...' incapsulation to allow multiple transport system.
- *
- *   - WIP (half tested) manage and test cross forwarder between table and room
- *   - log_legal address fix
- *   - setcookie (for tables only and persist prefs)
- *   - 404 wrong page management
- *
- *   TEST - unneeded garbage_time.expired access
- *   TEST - BUG: fast loop on stream index_rd_ifra page (js watchdog start without timeout corrupt counts)
- *   TEST - BUG: lurker are logged out (and remain a pending socket opened (look the spush log)
- *   TEST - BUG: logout failed (fixed with a garbage_collector wrapper at sac-a-push level
- *   TEST - garbage management
- *
- *   DONE/FROZEN - problema con getpeer (HOSTADDR)
- *
- *   DONE - configuration file management
- *   DONE - app level keep-alive
- *   DONE - index_wr other issues
- *   DONE - from room to table
- *   DONE - from table to room
- *   DONE - chunked
- *   DONE - bug: read from a not resource handle (already closed because a new socket substitute it)
- *   DONE - partial write for normal page management
- *   DONE - index_rd_ifra: last_clean issue
- *   DONE - fwrite failed error management (select, buffer where store unsent data, and fwrite check and retry)
- *   DONE - bug: after restart index_rd.php receive from prev clients a lot of req
- *   DONE - index_wr.php::chat
- *   DONE - index_wr.php::exit
- *   DONE - index_rd.php porting
- *   DONE - generic var management from internet
- *   DONE - index.php auth part
- *   ABRT - index_wr.php::reload - reload is js-only function
- *   ABRT - keepalive management - not interesting for our purposes
  */
 
 $G_base = "../";
@@ -72,32 +28,61 @@ $G_base = "../";
 require_once($G_base."Obj/sac-a-push.phh");
 require_once("./brisk-spush.phh");
 require_once($G_base."Obj/user.phh");
+@include_once($G_base."Obj/curl-de-brisk.phh");
 require_once($G_base."Obj/brisk.phh");
 require_once($G_base."Obj/auth.phh");
 require_once($G_base."Obj/zlibstream.phh");
-// require_once("../Obj/proxyscan.phh");
+require_once($G_base."Obj/mail.phh");
+require_once($G_base."Obj/provider_proxy.phh");
 require_once($G_base."index.php");
 require_once($G_base."index_wr.php");
 require_once($G_base."briskin5/Obj/briskin5.phh");
 require_once($G_base."briskin5/index.php");
 require_once($G_base."briskin5/index_wr.php");
 
+if (FALSE) {
+function my_e($number, $msg, $file, $line, $vars) {
+    print_r(debug_backtrace());
+    die();
+}
 
-function main()
+function my_for_fatal()
 {
-    if (($room = Room::create()) == FALSE) {
-        log_crit("room::create failed");
-        exit(1);
-    }
+    // $error = error_get_last();
+    // if ( $error["type"] == E_ERROR ) {
+        print_r(debug_backtrace());
+        die();
+        // }
+    //   log_error( $error["type"], $error["message"], $error["file"], $error["line"] );
+}
+
+register_shutdown_function( "my_for_fatal" );
+set_error_handler('my_e');
+}
+
+function main($argv)
+{
+    GLOBAL $G_ban_list, $G_black_list, $G_cloud_smasher, $G_provider_proxy;
+
+    pid_save();
+    do {
+        if (($brisk = Brisk::create(LEGAL_PATH."/brisk-crystal.data", $G_ban_list, $G_black_list, $G_cloud_smasher)) == FALSE) {
+            log_crit("Brisk::create failed");
+            $ret = 1;
+            break;
+        }
 
-    if (($s_a_p = Sac_a_push::create($room, "/tmp/brisk.sock", 0, 0)) === FALSE) {
-        exit(1);
-    }
+        if (($s_a_p = Sac_a_push::create($brisk, USOCK_PATH_PFX, 0, 0, $G_provider_proxy, $argv)) === FALSE) {
+            $ret = 2;
+            break;
+        }
 
-    $s_a_p->run();
+        $ret = $s_a_p->run();
+    } while (0);
 
-    exit(0);
+    pid_remove();
+    exit($ret);
 }
 
-main();
+main($argv);
 ?>