read image from url

M

Mark McIntyre

I'm not selling anything

I think you're being a little disingenuous to claim that recommending
your product (without declaring an interest) and directing people to your
website (which contains the cost structure), is not an advertisement for
it.
 
D

Default User

Mark said:
Ignoring the thread is counterproductive, both for the OP and for the
group.

It's always somewhat amusing to see the "why didn't you just ignore
it?" messages. After all, that person didn't ignore mine, whoever that
might be, obviously had previously been KFed as I don't see the
original messages. Unable to take their own advice, apparently.





Brian
 
F

Francine.Neary

quickcur said:
For 1), I'd have a function like
int GetHttpUrlToBuffer(char *URL, void *buffer, int bufferLength);
and return the size of the image, or -1 if it didn't fit in the buffer
or there was a network error.

To bring this thread, rich in seasonal cheer, back in the direction of
C...

The implementation of this function would of course be off-topic here,
but your proposed interface is relevant enough.

It's terrible, for several reasons. A bufferLength parameter should be
an unsigned type (usually a size_t). In the case of an error, the
return
code doesn't tell the caller *what* went wrong. If the buffer is too
small, the caller has no choice but to keep enlarging it by trial and
error until the data fits (or the system runs out of memory).

Using this function would be a nightmare!
 
J

jacob navia

To bring this thread, rich in seasonal cheer, back in the direction of
C...

The implementation of this function would of course be off-topic here,
but your proposed interface is relevant enough.

It's terrible, for several reasons. A bufferLength parameter should be
an unsigned type (usually a size_t). In the case of an error, the
return
code doesn't tell the caller *what* went wrong. If the buffer is too
small, the caller has no choice but to keep enlarging it by trial and
error until the data fits (or the system runs out of memory).

Using this function would be a nightmare!

Yes, you are right. That's why I proposed a file as output.

As far as I know, HTTP doesn't allow me to query the size of
the expected file, so there is no way but to keep reading
until I get a signal for EOF...

But maybe there is a way to query the file size.

But it i so trivial to read the file into memory and then
erase it that I do not quite see the point of this.

The disk file has much less limitations than the memory buffer and
allows this function to be easy to use.
 
F

Flash Gordon

jacob navia wrote, On 25/12/07 21:27:
Yes, you are right. That's why I proposed a file as output.

So the program needlessly fails if there is insufficient disk space.
As far as I know, HTTP doesn't allow me to query the size of
the expected file, so there is no way but to keep reading
until I get a signal for EOF...

So? You could give the user some kind of handle which can then be used
on subsequent calls to a "read" function which reads until error or EOF.
You could then talk about reading from the stream...

Oh, and any HTTP library that does not allow access to the headers is of
far less use for serious work.
But maybe there is a way to query the file size.

But it i so trivial to read the file into memory and then
erase it that I do not quite see the point of this.

Race conditions leading to possible exploits are one of the problems
with your method.
The disk file has much less limitations than the memory buffer and
allows this function to be easy to use.

Lets see, if you read it to memory you can write it to disk. On some
systems with some OT knowledge if you read it to memory you can ensure
it is *never* written to disk, which can be important for some
applications. If you provide some kind of streaming or callback method
you can potentially avoid having to wait until the entire file is
downloaded thus enabling the program to give the user some kind of
progress feedback (critically important IMHO for serious programs) and
save time by starting your processing of the data during the slow
process of obtaining it, thus potentially giving a far better user
experience.

I think there are a few reasons for not insisting on writing to a file
and then reading it from there.
 
R

Richard Heathfield

CBFalconer said:
He didn't, at least not in this thread. Give credit where due.

He said you could do it in two seconds "if you use lcc-win under windows",
which looks to me like an attempt at promoting his product. Do you really
think otherwise?
 
M

Mark McIntyre

CBFalconer said:


He said you could do it in two seconds "if you use lcc-win under
windows", which looks to me like an attempt at promoting his product.

It was that, but it was also a valid redirect, just as your suggestion of
libcurl was. Or indeed CBF's occasional recommendation to use his ggets()
function is.

If JN had added that he had a personal interest in the recommended
product (as most others who post pointers to their own code already do),
and had told the OP to ask further questions in the lcc-win32 group, then
he would have been entirely in the clear.
 
J

jacob navia

Richard said:
CBFalconer said:


He said you could do it in two seconds "if you use lcc-win under windows",
which looks to me like an attempt at promoting his product. Do you really
think otherwise?

You promoted libcurl

In http://curl.haxx.se/support.html
I can read:
<quote>

Companies Offering cURL Support

These are companies that offer curl support doing installation,
customizing or even extending it to your every need or simply
writing/improving scripts and programs using curl/libcurl.

Name Located install write scripts/apps customize curl
contributors web hosts
with curl
Haxx Stockholm, Sweden yes yes yes yes no
Originators and massive contributors to curl and libcurl since day
1. We write advanced curl script, libcurl apps as well as related
software. And we do it fast.

We repeatedly and frequently provide fast and accurate curl support and
write curl scripts/programs for satisfied customers all over the globe.

Michael Schrenk Ltd. Minneapolis, Minnesota USA yes yes yes no no
Specialize in writing curl-based web-bots, spiders and web agents
that provide real-time information for businesses.

Sound Commerce Kansas City, Missouri USA yes yes yes no yes
Sound Commerce provides development and consultation services for
over 30+ merchant account credit card gateways. We have the industry
experience to get it right the first time. Web Hosting, cURL
Installation, Security Consulting.

<end quote>

This people are trying to earn their life with libcurl.
In exactly the same way as I try to earn mine with lcc-win.

I am a "money obsessed predator".
Those are "unselfish community loving angels"

Now RH, please take off your glasses and stop insulting
people ok? Every free software project NEEDS a source of
income.
 
J

Joachim Schmitz

jacob navia said:
You promoted libcurl

In http://curl.haxx.se/support.html
I can read:
<quote>

Companies Offering cURL Support snip
<end quote>

This people are trying to earn their life with libcurl.
In exactly the same way as I try to earn mine with lcc-win.
Curl is free and open software, you's is not. Buying support for cURL is
optional, paying a licences fee for your software is not.
Nobody promoted cURL software support here.

There's nothing bad about earning money by creating or supporting software,
most of us do this.
But promoting commercial software (or support) here is SPAM.

Bye, Jojo
 
R

Richard Heathfield

jacob navia said:
You promoted libcurl

Do you really not understand the difference between "recommending product
written by someone else" and "recommending product written by oneself"?

In http://curl.haxx.se/support.html
I can read:
<quote>

Companies Offering cURL Support

These are companies that offer curl support doing installation,
customizing or even extending it to your every need or simply
writing/improving scripts and programs using curl/libcurl.

Yes, but they don't post thinly-disguised advertisements in non-commercial
channels like comp.lang.c.

This people are trying to earn their life with libcurl.

Do you see them promoting their product here? I don't.
In exactly the same way as I try to earn mine with lcc-win.

Not so. You are using a non-commercial channel for promoting your own
product. They are not.
I am a "money obsessed predator".

So you say.
Those are "unselfish community loving angels"

Well, I don't see them promoting their product here.

Now RH, please take off your glasses and stop insulting
people ok?

I'm not insulting you. I'm criticising your behaviour. There's an important
difference.
Every free software project NEEDS a source of income.

I have no objection to people making money from their work. If you think I
do, then you have completely misunderstood my objection.
 
H

Honest Jon

Now RH, please take off your glasses and stop insulting
people ok? Every free software project NEEDS a source of
income.

And which free software project do *you* contribute to?
 
J

jacob navia

Honest said:
And which free software project do *you* contribute to?

I do not believe in GNU sorry.
lcc-win is free in my own definition.
The obligation to avoid using it in commercial software
means only that you can't incorporate it in your software
and use it in a for profit context.
 
H

Honest Jon

I do not believe in GNU sorry.
lcc-win is free in my own definition.
The obligation to avoid using it in commercial software
means only that you can't incorporate it in your software
and use it in a for profit context.

"Words mean what I want them to mean," said the Mad Hatter.

To you, "free software" doesn't mean what it means to the rest of the
world (e.g. http://en.wikipedia.org/wiki/Free_software). Similarly, "C"
doesn't mean to you what it means to the rest of the world - for you, C
is some ill-defined hybrid language full of overloaded operators and
collected garbage.

The trouble with yours and the Mad Hatter's approach to language is that
it makes communication with others rather difficult. It's hardly
surprising that it leads to many misunderstandings, which frequently
turn to vitriol in this newsgroup.
 
C

CBFalconer

Richard said:
CBFalconer said:

He said you could do it in two seconds "if you use lcc-win under
windows", which looks to me like an attempt at promoting his product.
Do you really think otherwise?

Yes.
 
M

Mark McIntyre

On Wed, 26 Dec 2007 13:23:28 +0100, jacob navia wrote:

(snip link to a website offering support for libcurl, which it should be
noted, RJH did /not/ supply)
This people are trying to earn their life with libcurl. In exactly the
same way as I try to earn mine with lcc-win.

True. The difference is that RJH did not recommend going to any of their
websites or downloading their product. Nor did he fail to mention that he
was a direct beneficiary of that download.
I am a "money obsessed predator".

Again you put words in other people's mouths. Nobody has called you that.
We've just asked you to stop advertising your product here.

And if you can't see the difference between directing someone to your own
website (without mentioning that it /was/ yours, or that you stood to
make commercial gain), and suggesting someone use a free tool that can be
installed entirely without going to a commercial website ('yum install
libcurl' does it for me...), perhaps you're the one who needs glasses.
Every free software project NEEDS a source of income.

Interesting claim. Explain why.
 
F

Francine.Neary

jacob said:
Yes, you are right. That's why I proposed a file as output.

As far as I know, HTTP doesn't allow me to query the size of
the expected file, so there is no way but to keep reading
until I get a signal for EOF...

Why not have your GetHttpUrlToBuffer() function allocate a buffer
itself, and realloc() if necessary until the whole file fits? For
security reasons, you'd probably want a parameter letting the caller
of
your function specify that maximal allowable size of a buffer (thus
avoiding "the ggets problem"...). You'd just need to tell the caller
the
size of the downloaded data, and have your documentation instruct the
caller to free() the buffer once she'd finished with it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top