[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: HTTPAPI (version 1.20) - Sending values longer than 256 problem.



Ok, so it has something to do with the varying :-)

Thanks for the complete answer.

Regards, 

-----Original Message-----
From: ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx [mailto:ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Scott Klement
Sent: Wednesday, December 12, 2007 8:56 AM
To: HTTPAPI and FTPAPI Projects
Subject: Re: HTTPAPI (version 1.20) - Sending values longer than 256 problem.

Hi Wouter,

Since the length of VARYING fields can change while a program is 
running, the system needs a way to keep track of what their current 
length is.  Under the covers, RPG does that by storing the current 
length in the first two bytes of a VARYING string.

So if you declare a string as "8000a VARYING", the system actually 
reserves 8002 bytes of memory for the string.  It uses the first two 
bytes to store the length, and the remaining 8000 bytes to store the 
contents of the string.

The problem is:  If you try to reference that VARYING field using it's 
address (i.e. with the %addr() BIF, or with a pointer, etc.) the system 
gives you the address of the whole VARYING field -- which starts with 
the two bytes that contain the length.

That length should NOT be part of the data you submit to the web page. 
So I specify %addr() + 2 to skip those two bytes.

For example... when the RPG program starts, it asks the operating system 
for memory for each of it's variables.  For an 8000A VARYING field, it 
asks for 8002 bytes.  For the sake of example, let's say the OS assigned 
memory position 1000 to store that data in.  (In real life, it'd be a 
much higher number, but I'm picking 1000 because it makes the math easy.)

Since the length is stored in the first two positions, memory locations 
1000 and 1001 contain the length.   Memory locations 1002 - 9001 contain 
the actual string data.

When I pass %addr(Field) + 2, the %addr() BIF retrieves the number 1000. 
  Then adds 2 -- thus skipping over the length in positions 1000-1001, 
and starting with the actual field data that's in position 1002.

This is a very common technique when using pointers with VARYING fields...

wouter.desaedeleer@xxxxxxxxxx wrote:
> 
> Why the +2 in:
> 
> callp   http_url_encoder_addvar( Enc
>                                 : NAME_V
>                                 : %addr(VALUE1_V) + 2
>                                 : %len(VALUE1_V) );
> 
> 
> Does it have something to do with the Varying option?
> 
-----------------------------------------------------------------------
This is the FTPAPI mailing list.  To unsubscribe, please go to:
http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------


= = = = = = = = = = = = = = = = = = = = = = = = =
Fortis disclaimer :
http://www.fortis.be/legal/disclaimer.htm

Privacy policy related to banking activities of Fortis:
http://www.fortis.be/legal/privacy_policy.htm
= = = = = = = = = = = = = = = = = = = = = = = = =



-----------------------------------------------------------------------
This is the FTPAPI mailing list.  To unsubscribe, please go to:
http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------