cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Impossible to POST binary data with CURLOPT_POSTFIELDS

From: Dan Fandrich <dan_at_coneharvesters.com>
Date: Thu, 11 Oct 2007 14:38:58 -0700

On Thu, Oct 11, 2007 at 11:09:07PM +0200, Daniel Stenberg wrote:
>> 2) Change CURLOPT_POSTFIELDS to include a size parameter
>>
>> 3) Require CURLOPT_POSTFIELDSIZE to be called first
>
> Ouch, yes I can only confirm that you're of course 100% correct and I really
> cannot believe I didn't see this problem before! :-(
>
> I don't like #0, #1 or #2, and #3 would be unfortunate.
>
> I'm thinking perhaps the best approach - which is a bit of a trade-off
> between the old way and the current way - is to allow the options in any
> order but do the actual memory duplication when the *perform() function is
> called...

That eliminates a key benefit of the new approach which is the ability to
create temporary strings on the stack, set them in libcurl and not worry
about them any more. Unless you mean to treat CURLOPT_POSTFIELDS as a
special case and only delay copying that one (better, but inconsistent).

What about copying a hybrid approach; leave the existing behaviour as-is
except:

- If CURLOPT_POSTFIELDSIZE *was* already set, copy that much data in
CURLOPT_POSTFIELDS instead of strdup().

- If it was *not* already set, do strdup() (as now); when
CURLOPT_POSTFIELDSIZE is set, compare the value to the amount of data
actually copied. If it's equal, great. If it's not, do the copy again,
right this time.

That second copy breaks the 7.17.0 model of copy-on-set, but is fully
backwards compatibile with pre-7.17.0 versions. At some point that
compatibility mode could be removed to attain full consistency, and replaced
with an error call. Then, CURLOPT_POSTFIELDSIZE would become mandatory
before CURLOPT_POSTFIELDS.

>>> Dan

-- 
http://www.MoveAnnouncer.com              The web change of address service
          Let webmasters know that your web site has moved
Received on 2007-10-11