C:\$Recycle.Bin\S-1-5-21-3967099092-2644009230-141905953-500\$RX0XZUC\php\lib\rpc.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<?php

    define
('RPC_DISCOVER''discover');

    class 
turboRpcCodec
    
{
        function &
decode(&$inBuffer)
        {
            return 
$inBuffer;
        }
        function &
encode(&$inBuffer)
        {
            return 
$inBuffer;
        }
    }
    
    class 
turboRpcResponse
    
{
        var 
$result NULL;
        var 
$error NULL;
        var 
$id 0;
        var 
$debug '[turboRpc:]';
        var 
$trip 0;
        function 
turboRpcResponse($inId=0)
        {
            
$this->id $inId;
        }
    }

    function 
turboRpcDebug($inMsg NULL)
    {
        static 
$_debug '';
        if (
$inMsg)
            
$_debug .= "[$inMsg]<br>";
        return 
$_debug;
    }
    
    class 
turboRpc
    
{
        var 
$Targets;
        var 
$Response;
        var 
$Config;
        var 
$Codec;
        
        function 
turboRpc($inCodec NULL)
        {
            
$this->Codec $inCodec;
            
$this->Response = new turboRpcResponse();
            
$old_error_handler set_error_handler(array(&$this"rpcErrorHandler"));
        }

        function 
debug($inMsg NULL)
        {
            static 
$_debug '';
            if (
$inMsg)
                
$_debug .= "[$inMsg]<br>";
            return 
$_debug;
        }

        function 
addTarget(&$inTarget)
        
// various ampersands needed to avoid deep-copying objects in PHP4
        
{
            
$this->Targets[] = &$inTarget;
            
$inTarget->rpc = &$this;
        }
        
        function 
getTargetMethods($inTargets)
        {
            
$result = array();
            
$c count($inTargets);
            
//
            // 'for' instead of 'foreach' to avoid deep-copying objects in PHP4
            
for ($i=0$i $c$i++)
            {
                
$methods array_diff(get_class_methods($inTargets[$i]), array(get_class($inTargets[$i])));
                
$methods array_filter($methodscreate_function('$v''return ($v && $v{0}!="_");'));
                
$result array_merge($result$methods);
            }
            return 
$result;
        }
        
        function 
getMethodList()
        {
            return 
$this->getTargetMethods($this->Targets);
        }
        
        function &
findInTargets($inMethod, &$inTargets)
        {
            
$c count($inTargets);
            
// 'for' instead of 'foreach' to avoid deep-copying objects in PHP4
            
for ($i=0$i $c$i++)
                if (
method_exists($inTargets[$i], $inMethod))
                    return 
$inTargets[$i];
            return 
null;
        }
        
        function &
findTarget($inMethod)
        {
            
$target $this->findInTargets($inMethod$this->Targets);
            
// error output is here because subclasses may have other
            // reasons for returning a NULL target
            
if ($target == NULL)
                
$this->Response->error "rpc: could not find remote procedure '$request->method'";
            return 
$target;                
        }

        function 
_dispatch($inRequest)
        {
            
//echo "method: ".$inRequest->method;
            //$this->Response = new turboRpcResponse($inRequest->id);
            
$this->Response->id $inRequest->id;
            if (
$inRequest->method == RPC_DISCOVER)
                
$this->Response->result $this->getMethodList();
            else {
                
$target =& $this->findTarget($inRequest->method);
                if (
$target !== NULL)
                    
$this->Response->result call_user_func_array(array(&$target$inRequest->method), $inRequest->arguments);
            }
        }
        
        function 
dispatch(&$inRequest)
        {
            
//file_put_contents('rpc.txt', $inRequest);
            
$this->_dispatch($this->Codec->decode($inRequest));
            
$this->finish();
        }

        function 
error($inError)
        {
            
$this->Response->error $inError;
            
$this->finish();
        } 
        
        function 
finish()
        {
            
$this->Response->debug turboRpcDebug();
            echo 
$this->Codec->encode($this->Response);
            exit;
        }
        
        function 
rpcErrorHandler($errno$errmsg$filename$linenum$vars
        {
            switch (
$errno)
            {
                case 
E_USER_NOTICE:
                    
$this->error($errmsg);
                    break;
                case 
E_USER_ERROR:
                case 
E_USER_WARNING:
                    
$this->error("$errmsg (line $linenum in " basename($filename) . ")");
                    
//$this->error(array($errmsg, basename($filename), $linenum));
                    
break;
                default:
                    break;
            }                
        }
        
    }

?>