Pipe data from curl_easy_perform - c

I am trying to use libcurl to pipe data from an arbitrary (user given) url to my application:
The https.c example shows how to retrieve content from a URL and immediately write it to somewhere as it comes in, for example stdout or a file.
The sendrecv.c example shows how to setup a pipe by making the application repeatedly call curl_easy_recv to retrieve chunks of data.
However I don't understand how to combine the two. It seems like curl_easy_recv only works when:
/* Do not do the transfer - only connect to host */
curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L);
When this option is set curl_easy_perform does not retrieve any data, it just connects. In the example, the application proceeds by manually sending an http command using curl_easy_send. However I just want to retrieve the data specified in the URL, without writing manual http or ftp commands.
Is there a way to use curl_easy_recv or something similar in combination with the default behavior of curl_easy_perform automatically taking care of retrieving the content specified in the url?

First, curl_easy_send and curl_easy_recv are really only meant to be used if you're not doing one of the protocols libcurl already supports so in most cases they are not the correct answer. It doesn't sound like you need them.
curl_easy_perform() does the transfer of the given URL and it'll call the CURLOPT_WRITEFUNCTION as soon as data has arrived and you can then make use of that data or send it somewhere of your choice. Is that not enough?

Related

Taking input from multiple files to a camel route

I want to write a camel route which will take input from multiple file destination and process them after aggregating.
is it possible to take input from multiple files for a single route?
Yes you can use poll-enrich to call consumer-endpoints like file to enrich the message. This works for many other consumer-endpoints as well like SFTP or message queues.
If you need to read same file multiple times it can get trickier as you'll likely have to set noop=true and possibly use something like dummy idempotent repository to get around camels default behavior.
Note that calling pollEnrich seems to clear headers / create new message so use exchange properties to persist data between pollEnrich calls.
from("file:someDirectory")
.setProperty("file1").body()
.pollEnrich("file:otherDirectory", 3000)
.setProperty("file2").body()
.pollEnrich("file:yetAnotherDirectory", 3000)
.setProperty("file3").body();

SIP protocol / call waiting

First i would like to apologize for my bad english, I wish you will understand my problem.
Here's my question, for my internship, I need to create a fonctionality that allows a caller to put his call in waiting, with a button, and to take the call back with that button again. And i think there's an option with SIP protocol that allows to do that, but i just can't find it, i searched in internet in some documentations, the only thing I might know and i'm not even sure is that it could be an option in a re-INVITE request, that can be send by the called or the caller one, if someone could help me ?
Thanks
The feature you are looking for is achieved by implementing the Call Hold Scenario on a SIP Call.
there are 3 ways to put the call on hold at the press of the button.
Generate a Re-INVITE SDP with SendOnly option - the answer shall contain a recvonly and in this case you can go ahead and inject hold music media through the rtp stream.
Sending inactive in the Re-INVITE SDP which basically puts the media inactive for the session. This is when no rtp exchange is desired.
Sending the 0.0.0.0 notation for the Re-INVITE SDP - This is the old deprecated format of call hold when IPV4 was still the norm [still is!!] but it makes sure the RTP doesn't have a ip to be sent.
All of these mechanisms rely on the basic methods and hence it shouldn't be very difficult to achieve using any client software.

Format=RAW parameter for "Users.threads: get" request

I'd like to get raw messages for a particilar thread via "Users.threads: get" request. Is it possible to use format=raw parameter in this request somehow? I know it is possible for message request but I really need to do that for this one.
It might be useful to specify the format (raw or minimal) when requesting a thread, unfortunately this is not currently possible. The format can only be set for a message request. Requesting a thread in raw format however would not be a good idea since a thread could contain many large messages.
It is possible to set the format, but for some reason google doesn't allow the raw format when getting threads.
See the docs here

How to change the content length in request?

It's regarding content length.
I know its use. It tells the receiver that "this much" data I am sending.
It's available with both request & response. In Java, we have setContentLength() method for response, we can set content length to some value using this method and browser is going to read only up to that point in the body.
In request, we don't have any setContentLength() method - at least not in Java. So I believe browser sets this as per the data request is containing. Now let’s say if I modify this request in between – change a parameter value to some bigger value, how do I change the content length? If I don’t change content length, server doesn’t read the complete body – it only reads up to content length & ignores rest of the body content.
I hope my question is clear.
Thanks.
PS: I am changing request in a C filter in web server before request goes to application server.
I'm not sure if it's a good idea to change content length of request, I don't think you can achieve that simply, the only way i can think of is parse the content of request, the strip unneeded data and the generate the request that simple mimics original request but contains stripped data, it also depends on the whenever you are using POST or GET requests

Determining response length from an ISAPI filter

I am working on an ISAPI Filter to strip certain content out of responses. I need to collect all the body of the response before I do the processing, as the content I'm stripping could overlap send buffers.
To do this I'd like to buffer the response content with each SF_NOTIFY_SEND_RAW_DATA notification until I get to the last one, then send the translated data. I would like to know the best way to determine which SF_NOTIFY_SEND_RAW_DATA is actually the last. If I wait until the SF_NOTIFY_END_OF_REQUESTnotification, then I don't know how to send the data I've buffered.
One approach would be to use the content-length. This would require I detect the end of the headers. It would also require assuming the content-length header is correct (is that guaranteed?). Since HTTP doesn't even require a content-length header, I'm not even sure it will always be there. There seems like there should be an easier way.
I'm assuming the response is not chunked, so I am not handling dechunking before I do the response change. Also, when I do the modifications to the response body, the size of teh response body will not change, so I do not need to go back and update the content-length.
I eventually found some good discussions via google.
This posts answers my questions, as well as raises issues a more complicated filter would have to address: http://groups.google.com/group/microsoft.public.platformsdk.internet.server.isapi-dev/browse_thread/thread/85a5e75f342fad2b/cbb638f9a85c9e03?q=HTTP_FILTER_RAW_DATA&_done=%2Fgroups%3Fq%3DHTTP_FILTER_RAW_DATA%26start%3D20%26&_doneTitle=Back+to+Search&&d&pli=1
The filter I have s buffering the full request into its own buffer then using the SF_NOTIFY_END_OF_REQUEST to send the contents. The modification it does does not change the size, and precludes the possibility that the response is chunked, so in my case the filter is relatively simple.

Resources