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.

Curl handle as a FILE *

From: Patrick Monnerat via curl-library <curl-library_at_lists.haxx.se>
Date: Tue, 6 Dec 2022 13:01:48 +0100

Hi friends,

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.

There is a built-in CRLF conversion feature and a no-wait mode.

I wrote them for fun and as a proof of concept, so there is no doc. Look
at the prototypes and examples.

I think it can be useful for the community or as a base of a
non-callback API for our project, but I don't really know what to do it
with now that it mostly works! May be a curl doc example?

You will find use examples embedded within the source: simple download,
mail sending, copy a handle to another, mixing protocols and even using
an handle as the data source for another one.

Please feel free to use it at your convenience.


Now, the main drawbacks:

- It uses the GNU-specific function fopencookie(): there is no support
for other environment yet. An equivalent facility exists in BSD
(funopen), but I did not find one for other systems.

- Chunked output MUST be enabled, as we don't know the write data size
in advance.

- There is no way to get the CURL handle from the file outside the
package itself.

- A FILE-attached CURL handle is not reusable outside this context:
closing the FILE deletes it.

- Only limited seek support is available (of course!): rewind and flush
to request termination.

- By the non-callback nature of the C IO API, one must know at each time
if input or output is expected.

- Because file:// URLs do not support pausing, they are open as normal C
files.

- There's a lot of buffer copying, probably adding overhead (I did not
measure perfomance).

- As it is built outside libcurl, it has no access to the internal
structures.

- Redirection of upload/post request is not possible. This probably is
also the case for multi-pass authentication.

- FILE/curl tuned buffer size is important: better not change it!


Have fun!

Patrick


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