Commits

toby...@gmail.com  committed 1762739

bugfixes and saner handling of get args etc

  • Participants
  • Parent commits 7726975

Comments (0)

Files changed (3)

     return json_encode($success);
   }
   public function toJS($obj,$j='window'){
-    return "if(typeof($j) === 'undefined')$j={}; RPC_init($j,".json_encode($this->url).",".json_encode($obj->getRemoteMethods()).");";
+    if(get_magic_quotes_gpc()){
+      $j=stripslashes($j);
+    }
+    return "if(typeof($j) === 'undefined')$j=".json_encode($obj)."; RPC_init($j,".json_encode($this->url).",".json_encode($obj->getRemoteMethods()).");";
   }
 
   public function __construct(){
 
   public function serve($rootObj){
     ob_start();
-    session_start();
     set_error_handler('RPC::rpcError');
     if(get_magic_quotes_gpc()){
       $_POST=array_map('stripslashes',$_POST);
     $obj=$rootObj;
 
     $result=null;
-    $rpc->url=$_SERVER['PHP_SELF'];
+    $rpc->url=$_SERVER['REQUEST_URI'];
 
-    if(isset($_GET['obj_id'])){
-      $cls=$_GET['obj_cls'];
+    if(isset($_GET['obj_cls'])){
+      $cls= $_GET['obj_cls'];
       $id = $_GET['obj_id'];
       try{
 	//ensure class name is reasonable
       }catch(Exception $e){
 	  RPC::rpcError(0,"Cannot find class $cls");
       }
+    }elseif($rootObj === null){
+      RPC::rpcError(0,"No class or root object specified");
     }
 
     //return JSON

File php/RemoteObject.php

 <?php
 abstract class RemoteObject {
-  protected $remoteMethods=null;
+  protected $remoteMethods=array();
   
   //return an ID suitable for use with getObj($id)
   //this id will be stored client side, so some security 

File php/server.php

  * {success:{some:"JSON", encoded:["object"]}
  *
  */
-include_once "../classes/autoload.php";
+include_once "autoload.php";
 
 function rpcServer($rpcs){
   RPCFunctions::serveRPC($rpcs);