Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Programming a web server in C

Reply
Thread Tools

Programming a web server in C

 
 
Georgios Sakalis
Guest
Posts: n/a
 
      08-12-2006
I need some help for proect of mine

I am bulding a web server in c

To parse the request I am using a char *buffer, with a default size at te
begining, If the bytes that been read are equal to that size I realloc the
buffer and so on.

The problem is when I am trying to implement file uploading. I read also the
file in the buffer, but the problem is that i cannot find the size of the
binary file in order to say how many bytes should write to the file.

Any ideas or code??


 
Reply With Quote
 
 
 
 
Malcolm
Guest
Posts: n/a
 
      08-12-2006



"Georgios Sakalis" <(E-Mail Removed)> wrote in message
news:ebk6o1$g56$(E-Mail Removed)...
>I need some help for proect of mine
>
> I am bulding a web server in c
>
> To parse the request I am using a char *buffer, with a default size at te
> begining, If the bytes that been read are equal to that size I realloc the
> buffer and so on.
>
> The problem is when I am trying to implement file uploading. I read also
> the file in the buffer, but the problem is that i cannot find the size of
> the binary file in order to say how many bytes should write to the file.
>
> Any ideas or code??
>


Good enough code

long getfilesize(char *path)
{
FILE *fp;
long answer;

fp = fopen(path, "rb");
if(!fp)
return -1;
fseek(fp, 0, SEEK_END):
answer = ftell(fp);
fclose(fp);

return answer;
}

Add a few bytes to your buffer for luck.
The code will work, but unfortunately falls foul of a few caveats in the
standard, there to support really huge files and stuff like that.


--
www.personal.leeds.ac.uk/~bgy1mm
freeware games to download.


 
Reply With Quote
 
 
 
 
Morris Dovey
Guest
Posts: n/a
 
      08-12-2006
Georgios Sakalis (in ebk6o1$g56$(E-Mail Removed)) said:

| I need some help for proect of mine
|
| I am bulding a web server in c
|
| To parse the request I am using a char *buffer, with a default size
| at te begining, If the bytes that been read are equal to that size
| I realloc the buffer and so on.
|
| The problem is when I am trying to implement file uploading. I read
| also the file in the buffer, but the problem is that i cannot find
| the size of the binary file in order to say how many bytes should
| write to the file.
|
| Any ideas or code??

For uploading binary files, you might do well to use fixed-size
buffers obtained as needed from a pool of available empty buffers.
Buffers can be flushed to a disk file as needed to prevent an attacker
from eating all of server memory, causing a buffer overrun, etc.

comp.lang.c is for discussion of C - not for discussion of all of the
things one might /do/ with C. A better source of information would
probably be a networking newsgroup that focuses on your platform.

--
Morris Dovey
DeSoto Solar
DeSoto, Iowa USA
http://www.iedu.com/DeSoto


 
Reply With Quote
 
jmcgill
Guest
Posts: n/a
 
      08-12-2006
Georgios Sakalis wrote:

> The problem is when I am trying to implement file uploading. I read also the
> file in the buffer, but the problem is that i cannot find the size of the
> binary file in order to say how many bytes should write to the file.
>
> Any ideas or code??


I gather you are not requiring a Content-Length header on PUT requests.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
C (functional programming) VS C++ (object oriented programming) Joe Mayo C Programming 168 10-22-2007 01:00 AM
Can Your Programming Language Do This? Joel on functional programming and briefly on anonymous functions! Casey Hawthorne Python 4 08-04-2006 05:23 AM
Server to server = Server client to server? - Java 2 07-29-2005 10:46 PM
systems programming versus application programming Matt Java 35 07-22-2004 08:10 AM
CGI Programming in C on Xitami Web Server Don Blow, Jr. C Programming 9 07-01-2004 04:32 PM



Advertisments