[phpxmlrpc] send file contents via phpxmlrpc

Gaetano Giunta giunta.gaetano at sea-aeroportimilano.it
Wed Feb 7 16:32:23 UTC 2007


BTW: I just had a similar effect recently (the PuttyPuttyPutty part).

I think it is a side effect of using xmlrpc_debugmsg() with some data that is not ASCII clean:

The standard debug content outputted by the xmlrpc server is base64 encoded, but the output of xmlrpc_debug is not (it is effectively very hard to encode properly a 'general string', if we do not know its charset, so we only do some guestimate-encoding).

So, if you use it with binary data, you will, most likely,
- break the xml you are sending
- write a log file that, when piped through the less (more/vi) command, will send some weird x-terminal commands and cause the weird PuttyPuttyPutty behaviour

Bye
gaetano

> -----Original Message-----
> From: Manish Marathe [mailto:mmarathe at spikesource.com]
> Sent: Wednesday, January 10, 2007 6:47 PM
> To: Giunta Gaetano
> Subject: Re: [phpxmlrpc] send file contents via phpxmlrpc
> 
> 
> Giunta Gaetano wrote:
> 
> >Sorry, but to get an idea what might be wrong, I would 
> rather have to see the code you are using, rather than the 
> files you are sending.
> >Also "it is not working" is not a very clear description of 
> the error: what results are you getting?
> >Did you enable the debug mode of the client to get more insight?
> >  
> >
> 
> I am sorry, I really didn't give a clear description of the 
> error, I did 
> enable the debugging, both at the client side as well as on 
> the server 
> side although the server side one is not really needed.
> 
> I was getting the following error:
> [09-Jan-2007 16:36:48] XML error at line 1, check URL
> [09-Jan-2007 22:12:07] XML error: Invalid document end at 
> line 2, column 1
> 
> Both are from php's error log.
> 
> >The main question though is: what kind of xmlrpc library is 
> used for this? Is it php-xmlrpc on both sides of the channel 
> or is it only used for the client?
> >  
> >
> 
> Yes I was using php-xmlrpc on both sides, I definitely will be having 
> server from php-xmlrpc but the client will be in python later 
> on but for 
> testing, the above errors were received, when  I wrote the client in 
> php-xmlrpc itself.
> 
> >In case of phpxmlrpc on both sides, there should be no 
> problems really, but when talking with other libraries, you 
> have to make sure that the character set used for 
> communication is understood correctly by both sides.
> >  
> >
> Thats right!
> 
> >Also note that using an xmlrpc string is probably not a good 
> idea in your case, since CR/LF can be normalized when sent as 
> xml content. I would recommend going with a base64 value instead.
> >
> 
> So as you suggested I changed the xmlrpcval from 'string' to 
> base64 and 
> even the error I used to get was gone, well not really 
> because I changed 
> the type, but I had a typo I guess but even this transfer is sending 
> some extra junk with the payload. So if I am running the 
> client from a 
> shell which requests the server, its changing the char-set of 
> the shell. 
> If I run on a terminal like Putty, the server sends extra text 
> "puTTypuTTy" etc. Running the client written in php-xmlrpc 
> does not give 
> any errors though, but still junk. On the other hand if I create a 
> client in python and try to talk to this server, it gives me 
> parse error 
> possibly because the xml payload had junk and unknown char-set to the 
> python client as you said. So what's trick to trim-off this junk.
> 
> Thanks for your help
> 
> -Manish
> 
> Also following is my server:
> <!-----------------     server   START      ------------------->
> function checkForUpdates($message) {
>     require_once "../conf/site-config.php";   
>     require_once "../site-setup.php";
>     $dir = $REPOSITORY_BASE . "/corestack/3.0/x86-win/";
>        
>     if(validateEmail('mmarathe at spikesource.com', $DSN_GENERAL, $LOG)) 
> {       
>         $files = scandir($dir);
> 
>         foreach ($files as $file) {
>             if($file !== '.' || $file !== '..') {
>                 if(end(explode('.', $file)) == 'zip') {       
>             
>                     $file_info .= system("unzip -p " . $dir . "/" . 
> $file . " " . reset(explode('.', $file)) . ".yaml");
>                 } else if(end(explode('.', $file)) == 'gz') {
>                     // Do same thing but for gz
>                 }
>             }  
>         }
>         return new xmlrpcresp(new xmlrpcval($file_info, 'base64'));
>     } else {
>         return new xmlrpcresp(new xmlrpcval("Invalid Email" . $dir, 
> 'string'));
>     }   
> }
> 
> $checkForUpdates_sig = array(array('base64', 'string', 
> 'string', 'string'),
>                                                    array('string', 
> 'string', 'string', 'string'));
> $checkForUpdates_doc = 'Checks for Updates';
> 
> $s = new xmlrpc_server(array( 'checkForUpdates' => 
> array('function' => 
> 'checkForUpdates',
>                                                                
>                                  'signature' => $checkForUpdates_sig,
>                                                               
>                                  'docstring' => $checkForUpdates_doc)
>                                                  ));
> $s->setDebug(3);
> $s->compress_response = true;
> $s->service();                 
> <!-----------------     server   END      ------------------->
> 
> <!-----------------     client   START      ------------------->
> $server = new xmlrpc_client('/spikenet/RPC2/xmlrpc_server.php',
>                             'caledon.spikesource.com', 80);
> 
> $server->setDebug(3);
> $message = new xmlrpcmsg('checkForUpdates',
>                          array(new xmlrpcval('corestack', 'string'),
>                                new xmlrpcval('3.0', 'string'),
>                                new xmlrpcval('x86-win', 'string')));
>                                                              
> $result = $server->send($message);
> 
> // Process the response.
> if (!$result) {
>     print "<p>Could not connect to HTTP server.</p>";
> } elseif ($result->faultCode()) {
>     print "<p>XML-RPC Fault #" . $result->faultCode() . ": " .
>         $result->faultString();
> } else {   
>     print_r($result->value());
> }
> <!-----------------     client   END      ------------------->
> 


More information about the phpxmlrpc mailing list