curl / Mailing Lists / curl-library / Single Mail
Buy commercial curl support from WolfSSL. We help you work out your issues, debug your libcurl applications, use the API, port to new platforms, add new features and more. With a team lead by the curl founder himself.

Re: Curl handle as a FILE *

From: Timothe Litt <litt_at_acm.org>
Date: Tue, 6 Dec 2022 09:50:35 -0500


On 06-Dec-22 09:24, Patrick Monnerat via curl-library wrote:
>
> On 12/6/22 13:08, Daniel Stenberg wrote:
>> On Tue, 6 Dec 2022, Patrick Monnerat via curl-library wrote:
>>
>>> Please find the source code and use examples of functions
>>> curl_fopen() and curl_fdopen() in attachement.
>>>
>>> These allow associating an URL or a curl handle with a standard C
>>> FILE pointer and use the standard C IO API on it.
>>
>> Fun!
>>
>> Also a quick reminder to readers that if you want an
>> fopen/fread/frite style API for libcurl, there is also this start =>
>> https://github.com/curl/fcurl
>
>
> Thanks for your feedback. And the reminder was a good idea.
>
> Although the goal is the same, I targetted something really compatible
> with C FILE. This allows to easily insert libcurl use in existing
> programs as old as C iitself and use on a handle a much wider range of
> API without having to write wrappers. The real challenge was "FILE *" !
>
> I know fcurl is not complete yet, but noted the method is a bit
> different: curl_fopen plays with the pause flags and unpause only when
> enough buffer is available (that is: when in read or write). I did it
> this way because I support writes too and to prevent buffer overflows.
>
>
> If you try my code on an Apache+PHP-FPM web service, you might
> experience problems while posting: there currently is an Apache bug on
> handling chunked post input. It works perfectly with nginx.
>
> Patrick
>
It's a good idea.

I don't think your seek() semantics are correct.  seek(SEEK_END)
terminates connection, which isn't what seek does, or what a C program
would expect.  seek just positions.  I think that what you're doing maps
to fclose().

seek should return errno = EBADF if not implemented.  EINVAL is for a
bad 'whence' .

The idea of doing range requests based on seek from fcurll's issues has
merit.  May need some support in the library.

You might also provide these as curl_xxx(), using curl handles. While
transparency is nice, you can't always hook the C RTL. curl_xxx could be
the portable version - it's a pretty simple search-and-replace for
users.  And your hooked version, if available at configure time, can be
used where it's available.

I think that would give you the best of both approaches. curl_portable
API that looks like FILE *, or transparent FILE * handles where they are
available.  The internals will be largely the same.

You may also want to consider other key functions, including delete and
rename.  With ftp, at least: chmod, chown...

There's quite a bit to making network operations look exactly like local
files.  But you're definitely on to a useful subset.


Timothe Litt
ACM Distinguished Engineer
--------------------------
This communication may not represent the ACM or my employer's views,
if any, on the matters discussed.


-- 
Unsubscribe: https://lists.haxx.se/listinfo/curl-library
Etiquette:   https://curl.se/mail/etiquette.html
Received on 2022-12-06