RE: Re: Difference between Trim($HTTP_POST_VARS["sh"]) and scalarval()

"Gaetano Giunta" <[email protected]>
Newsgroups gmane.text.xml.rpc.specification
Message-ID <[email protected]>
Ok, I'll try to do my best here, but I still have not yet a very clear understanding of your situation:

0 - what version of phpxmlrpc are you using?


1 - are you coding the server side, the client side, or both? What software is used on the other side for xmlrpc?

your initial statement: "This code is using $HTTP_POST_VARS["var"] to pass parameters. My work is to get this code working in nearly the same way but to pass the parameters in another way."

leaves me quite confused, since HTTP_POST_VARS can only be used server-side, but the rest of your mail indicates that you are working client side...


2 - "The first time I use the method "rpc_call" it returns an scalarval() that consists of 10 digits (yes, it is larger than an normal Int) and I save it like $sh = $v->scalarval()"

this is fine to me, but you should consider giving more info: what kind of xmlrpc value is returned by the method rpc_call: int / string / base64 ? you can see it simply by using $v->scalartyp(). You can also use gettype($v->scalarval()) to see what type of php variable is being used to hold your session ID. And you can use setDebug(1) on the client object to see a nice dump of the HTTP communication with the server.


3 - "xmlrpcval(Trim($v->scalarval()), $xmlrpcInt));" is ok. In in fact $v->scalarval() is a php integer, you can also get rid of the Trim.


4 -  " The code that makes the difference is in the function createPayload(). When it puzzles the xml-tags together the strlen of strlen($p->serialize() returns 43 when I pass the params via $v->scalarval() and 37 if I pass the params via  $HTTP_POST_VARS["sh"])."

I think the problem mosty lies here:
You can simply do a var_dump($p->serialize()) to see the exact XML string that the xmlrpc client will be sending over to the server: not only its length, but also usage of whitespaces/tabs/carriage returns etc... (remember to wrap it in a <pre> tag).
Since you are sending XML, you should keep in mind that the length of the payload 'on the wire' can vary wildly, based on external parameters, such as: usage of http compression, usage of http chunked encoding, usage of different character sets and encoding of characters as xml entities, usage of \n versus \n\r to separate xml elements (whitespace between xml elements can also be tolerated).

5 - "In this case I need the strlen of 37 because otherwise the server takes the http-header and adds 6 empty spaces to the parameter on the server side. This ends up in something like "1234567897      " in this is definitly (not even for me *g*) a number. So the server sends the response that the parameter is wrong because there should be an int as the first parameter but there is an string."

In fact server never sees the length of 37, since it sees the length of the complete xmlrpc request, which is much longer that that.
If the server in fact sees a content length that is bigger than the payload it receives, it should NOT add by itself some extra whitespace to the the xmlrpc value, which is deeply nested inside other xml tags.

The length of 37 is correct. I tested the following code snippet:

include('xmlrpc.inc');
$p = new xmlrpcval('1234567897', 'int');
var_dump($p->serialize());
$p = new xmlrpcval(1234567897, 'int');
var_dump($p->serialize());

and got two strings with a length of 37.

I really fail to see how using "strlen($p->serialize())" whould yeld 43, unless the inner php value held by $p is different from '1234567897'.

I suggest you run var_dump($p) to get a better understanding. In my case I got:

object(xmlrpcval)(2) {
  ["me"]=>
  array(1) {
    ["int"]=>
    int(1234567897)
  }
  ["mytype"]=>
  int(1)
} 


6 - about problems with content-length: take also into account that there is a known bug with the PHP xmlrpc library and apache servers, involving http chunked-encoding.

In some situations, when the phpxmlrpc library is used on the server side, it will send a correct content-length based on the length of the response. Apache will then add chunked-encoding transformation and also a different content-length header before sending ti all to the client.
This causes in turn some problems with xmlrpc clients that validate the http content-length header.

My own personal opinion is that if the content-length http header is wrong, the xmlrpc library should either refuse to carry on and report an error (as many implementations do), or parse the XML anyway (as phpxmlrpc does: in fact it ignores completely the content-length).

There is a slight chance, from your indications, that the xmlrpc server you are querying might be adding by itself some whitespace to the received value in order to obey the http content-length header. This would be very wrong for the server to do, and I really do not think it is happening (unless the server does not use a real XML parser and only bases itself on string manipulation to decode the XMl - in which case I would sugest you avoid using xmlrpc altogheter and stick to using POST values).


Bye
Gaetano


> -----Original Message-----
> From: [email protected] 
> [mailto:[email protected]]On Behalf
> Of erasmus_joshi
> Sent: Tuesday, January 10, 2006 4:13 PM
> To: [email protected]
> Subject: [xml-rpc] Re: Difference between Trim($HTTP_POST_VARS["sh"])
> and scalarval()
> 
> 
> Hello Gaetano,
> 
> thanks for your answer to my confused question. It already helped a
> little bit. I want to try to explain it a better this time:
> 
> There is one code in php that is working. This code is using
> $HTTP_POST_VARS["var"] to pass parameters. My work is to get this code
> working in nearly the same way but to pass the parameters in 
> another way. 
> 
> The first time I use the method "rpc_call" it returns an scalarval()
> that consists of 10 digits (yes, it is larger than an normal Int) and
> I save it like $sh = $v->scalarval();
> 
> This works well. 
> 
> In the next step I want to logout. For this method I have to pass the
> variable $sh to the method like:
> xmlrpcval(Trim($HTTP_POST_VARS["sh"]), $xmlrpcInt)); 
> The developer of the existing and well working code used for this a
> form to post the vars and then used it in the code. 
> 
> The way I have to do it is ... without this form - posting because it
> is part of an workflow: So I wanted to use the code like:
> xmlrpcval(Trim($v->scalarval()), $xmlrpcInt)); 
> For me this meant nearly the same like the code above but I use the
> variable $v->scalarval() direct and not indirect via sending the form
> with the hidden field for sh and use the $HTTP_POST_VARS["sh"]. 
> 
> Like I told.. for me it was the same because the method got a value
> that with the size of 10 characters. 
> The code that makes the difference is in the function createPayload().
> When it puzzles the xml-tags together the strlen of
> strlen($p->serialize() returns 43 when I pass the params via
> $v->scalarval() and 37 if I pass the params via 
> $HTTP_POST_VARS["sh"]).
> 
> Printing out the result of $p->serialize() via echo ... outputs in
> both ways something that has contains of 10 digits. 
> 
> The point I don't get is what kind of control-codes like \n\f .. can
> be hidden in this code, how to make it visible and more over .. how to
> get the same strlen for both values?
> 
> In this case I need the strlen of 37 because otherwise the server
> takes the http-header and adds 6 empty spaces to the parameter on the
> server side. This ends up in something like "1234567897      " in this
> is definitly (not even for me *g*) a number. So the server sends the
> response that the parameter is wrong because there should be an int as
> the first parameter but there is an string. 
> 
> And that the problem. 
> So the question is ... what kind of magic is this (IMHO - really good)
> xmlrpc thing doing in serialize that enlarges the string unneccessary.
> Could it be the encoding and what can I do to make this work. 
> 
> Thanks for reading and hopefully now it gets more clear what's the
> problem between me, xmlrpc and the rest. 
> 
> Thx in advance, Sascha  
> 
> 
> 		}
> --- In [email protected], "Gaetano Giunta" <giunta.gaetano@s...>
> wrote:
> >
> > I might be missing the point, since the description is somewhat
> confused, but...
> > 
> > $p = new xmlrpcval(Trim($HTTP_POST_VARS["sh"]), $xmlrpcInt)
> > 
> > will create an xmlrpcval of type int.
> > This means than when calling $p->serialize(), an <int> tag 
> will be used.
> > The library does NOT coerce the php value passed to it to INT type,
> but it leaves it untouched.
> > This means that if Trim($HTTP_POST_VARS["sh"] is not an integer, it
> will be printed as it is anyway.
> > 
> > In the latest release of the library, only avalibale in CVS (but
> soon it will be posted as 2.0RC3), this has been cahnged:
> > $p->scalarval() will still return the original value you pass to it
> > $p->serialize() will coerce the value to an ineteger before creating
> the xml (ie '0000' will return <int>0</int>, and 'hello' will return 0
> as well).
> > 
> > You should also take care about your code using leading zeroes...
> > 
> > Hope it helps
> > Gaetano
> > 
> > > -----Original Message-----
> > > From: [email protected] 
> > > [mailto:[email protected]]On Behalf
> > > Of erasmus_joshi
> > > Sent: Tuesday, January 10, 2006 1:26 PM
> > > To: [email protected]
> > > Subject: [xml-rpc] Difference between 
> Trim($HTTP_POST_VARS["sh"]) and
> > > scalarval()
> > > 
> > > 
> > > Hello, 
> > > 
> > > I have a - maybe - really stupid question but I am new to 
> this topic
> > > and don't find a way to solve it myself.
> > > 
> > > There is an existing xmlrpc client that works perfectly. I want to
> > > adopt this client to Typo3 and the xmlrpc communications 
> also works
> > > really good. But I have on big problem with the following thing: 
> > > 
> > > The communication is step by step. First I have to connect to the
> > > server. This works perfect. This Server respones with an SessionID
> > > with a length of 10 numbers. And that is the point. I 
> have to use this
> > > number as parameter in all methods. 
> > > 
> > > The new and the old code are only unequal in the type calling the
> > > methods. The working version is reading the variable by
> > > $HTTP_POST_VARS["sh"]. I use the result of the response 
> scalarval..
> > > 
> > > ----snip----
> > > if ($v = rpc_call($c, $f)) {
> > > 			echo "Login () returns: 
> > > ",$v->scalarval(),"<br>";
> > > 			$sh = $v->scalarval();
> > > 
> > > 	$f= new xmlrpcmsg('sdb.Logout');
> > > 		$f->addParam(new 
> > > xmlrpcval(Trim($HTTP_POST_VARS["sh"]), $xmlrpcInt));
> > > 
> > > --- snap ----
> > > 
> > > The point I don't get is that in the method createPayload the 
> > > 		->echo
> > > "Payload -> param -> serialize size = " . strlen($p->serialize()).
> > > "<br>";<--
> > > serialize value send as parameter via $HTTP_POST_VARS has a strlen
> > > that is 6 shorter than the parameter send by scalarval. 
> > > 
> > > Could this be a problem with encoding or has someone a 
> idea what I am
> > > doing wrong?
> > > 
> > > Sorry for the bad description.. but somehow I am really 
> confused at
> > > the moment and hope someone understood what I wanted to tell. 
> > > 
> > > Thx in advance, Sascha
> > > 	
> > > 
> > > 
> > > 
> > > 
> > > 
> > > 
> > > 
> > >  
> > > Yahoo! Groups Links
> > > 
> > > 
> > > 
> > >  
> > > 
> > > 
> > >
> >
> 
> 
> 
> 
> 
> 
> 
>  
> Yahoo! Groups Links
> 
> 
> 
>  
> 
> 
> 

 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/xml-rpc/

<*> To unsubscribe from this group, send an email to:
    [email protected]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.