CGI in C 
Author Message
 CGI in C

Hello, All.

I'm trying to write small application for logging downloaded
files and prevent "leeching".

What is the best way to do that? The simple solution is to
read file and write it's contents to stdout. But what if
file size is say 50MB. As far as I understand it will be whole
put in HTTP server's memory. Am I right? If yes, is there
another solution (without writing TCP server?)

Sorry if that's offtopic here. I couldn't find group for
CGI programming other than Perl/PHP related.




Tue, 08 Feb 2005 05:10:32 GMT  
 CGI in C
: Hello, All.

: I'm trying to write small application for logging downloaded
: files and prevent "leeching".

: What is the best way to do that? The simple solution is to
: read file and write it's contents to stdout. But what if
: file size is say 50MB. As far as I understand it will be whole
: put in HTTP server's memory. Am I right? If yes, is there
: another solution (without writing TCP server?)

I don't quite understand, but...

When the web server gets a POST then it is told the content size via the
Content-length: header, which it passes to the cgi via the CONTENT_LENGTH
environment variable.

The CGI (in any language) then reads that many bytes from stdin to get the
contents.  BUT you do not have to read all those bytes in one read.

The cgi normally reads the input in whatever chunk sizes it wants, and
typically saves the input (one chunk at a time) by writing it into a file.

pseudo code

        while (read_bytes < CONTENT_LENGTH)
        {
                read_bytes += read(STDIN,512,buffer);
                write(save_file,buffer);
        }



Tue, 08 Feb 2005 14:07:47 GMT  
 CGI in C

Quote:
> Hello, All.

> I'm trying to write small application for logging downloaded
> files and prevent "leeching".

> What is the best way to do that? The simple solution is to
> read file and write it's contents to stdout. But what if
> file size is say 50MB. As far as I understand it will be whole
> put in HTTP server's memory. Am I right? If yes, is there
> another solution (without writing TCP server?)

You can buffer the output in, say, 8kB chunks. That's not difficult to write in
C.

Quote:
> Sorry if that's offtopic here. I couldn't find group for
> CGI programming other than Perl/PHP related.

It also is easy to accomplish this in PHP. You simply open a file with fopen()
and output it with fpassthru().

Josef Svoboda



Tue, 08 Feb 2005 16:32:43 GMT  
 CGI in C
Groovy hepcat Andrew Novikov was jivin' on Fri, 23 Aug 2002 00:10:32
+0300 in comp.lang.c.
CGI in C's a cool scene! Dig it!

Quote:
>I'm trying to write small application for logging downloaded
>files and prevent "leeching".

  So, a remote user calls your script from his browser, passing it
(through stdin) the name of the file he wants, then your script opens
that file and sends it back via stdout. Meanwhile, your script logs
this operation. Is that prettymuch what you mean? That's doable.

Quote:
>What is the best way to do that? The simple solution is to
>read file and write it's contents to stdout. But what if

  Right.

Quote:
>file size is say 50MB. As far as I understand it will be whole
>put in HTTP server's memory. Am I right? If yes, is there

  I doubt that. My guess is that it passes output straight back to the
remote browser. It probably depends on the server, though. Consult
your server docs or ask your sysadmin.

Quote:
>another solution (without writing TCP server?)

>Sorry if that's offtopic here. I couldn't find group for
>CGI programming other than Perl/PHP related.

  comp.programming, perhaps. Possibly comp.unix.programmer too.

--

Dig the even newer still, yet more improved, sig!

http://alphalink.com.au/~phaywood/
"Ain't I'm a dog?" - Ronny Self, Ain't I'm a Dog, written by G. Sherry & W. Walker.
I know it's not "technically correct" English; but since when was rock & roll "technically correct"?



Sat, 12 Feb 2005 09:28:28 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Newbie: separate big .cs file into small .cs files

2. Wanted : Someone to convert Perl 5 CGI into C/C++ CGI

3. cgi.h - for c base cgi programing

4. cgi program which is a daemon/starting daemon from cgi

5. How to show/call Form2.cs from Form1.cs ?

6. Include code in other Cs files

7. Reuse of cs files, namespace, arch advice pls

8. word - automatic numbering/bold/underline/italics

9. How to Generate .cs file at Runtime

10. newbe/cs student, need help w/ code

11. Serial.cs

12. Compile CS source code using ICodeCompiler

 

 
Powered by phpBB® Forum Software