/[cvs]/nfo/php/libs/org.netfrag.flib/Application/RPC/Remote.php
ViewVC logotype

Annotation of /nfo/php/libs/org.netfrag.flib/Application/RPC/Remote.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (hide annotations)
Sun Dec 22 13:24:09 2002 UTC (21 years, 9 months ago) by jonen
Branch: MAIN
Changes since 1.4: +17 -7 lines
+ added utf8 encoding at 'send()' toggled by option

1 joko 1.1 <?
2     ## --------------------------------------------------------------------------
3 jonen 1.5 ## $Id: Remote.php,v 1.4 2002/12/19 02:02:25 jonen Exp $
4 joko 1.1 ## --------------------------------------------------------------------------
5 joko 1.2 ## $Log: Remote.php,v $
6 jonen 1.5 ## Revision 1.4 2002/12/19 02:02:25 jonen
7     ## + minor changes
8     ##
9 jonen 1.4 ## Revision 1.3 2002/12/19 01:59:37 jonen
10     ## + minor changes: coment debug prints
11     ##
12 jonen 1.3 ## Revision 1.2 2002/12/05 21:45:31 joko
13     ## + debugging
14     ##
15 joko 1.2 ## Revision 1.1 2002/12/01 17:23:58 joko
16     ## + initial check-in
17     ##
18 joko 1.1 ## Revision 1.3 2002/12/01 06:22:57 cvsjoko
19     ## + minor update: now can use config defaults or given args
20     ##
21     ## Revision 1.2 2002/10/29 19:14:45 cvsjoko
22     ## - bugfix: dont' do utf8-encoding here
23     ##
24     ## Revision 1.1 2002/10/09 00:51:39 cvsjoko
25     ## + new
26     ##
27     ##
28     ## -------------------------------------------------------------------------
29    
30     class Remote {
31    
32     function Remote($args = array()) {
33     global $cfg;
34 joko 1.2 //print "new Remote<br>";
35 joko 1.1 $this->host = $cfg[rpcinfo][Host];
36     $this->port = $cfg[rpcinfo][Port];
37     if ($args['Host']) { $this->host = $args['Host']; }
38     if ($args['Port']) { $this->port = $args['Port']; }
39     }
40    
41 jonen 1.5 function send($command, $data = "", $options = array()) {
42     // do 'encode' here and ...
43     if ($options[utf8]) {
44     $encoder = new TextEncode($data);
45     $encoder->toUTF8();
46     }
47     // call '_call' with 'decode'
48     return $this->_call($command, $data, 1);
49 joko 1.1 }
50    
51 jonen 1.5 function _call($command, $data = "", $decode = 0) {
52 joko 1.2
53 jonen 1.5 //print "call: $command<hr>";
54    
55     // print Dumper($data);
56 joko 1.1
57     // data
58     $data_enc = XML_RPC_encode($data);
59    
60     // message - request
61     $msg = new XML_RPC_Message($command);
62     $msg->addParam($data_enc);
63 jonen 1.5 //print htmlentities($msg->serialize());
64 joko 1.1 // remote procedure call
65     $rpc = new XML_RPC_Client("/", $this->host, $this->port);
66     $rpc->setDebug(0);
67     if ( !$msg_response = $rpc->send($msg) ) {
68 joko 1.2 // TODO: redirect this error elsewhere!
69 jonen 1.3 print "RPC-error!<br>";
70 joko 1.1 return;
71     }
72     // message - response
73     $response_enc = $msg_response->value();
74    
75     // TODO: what's this? prematurely returning here should not be considered "stable"....
76     return $this->decodeData($response_enc);
77    
78     if ($decode) {
79     return $this->decodeData($response_enc);
80     } else {
81     return $response_enc;
82     }
83    
84     }
85    
86     function &decodeData(&$payload) {
87     //if (!is_object($payload)) { return; }
88     if ($payload) {
89     // data
90     $data = XML_RPC_decode($payload);
91     //print "data: " . dumpVar($response);
92     return $data;
93     } else {
94     //print "ERROR!<br>";
95     return 0;
96     }
97     }
98    
99     }
100    
101     ?>

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed