Programming a web server in C

Discussion in 'C Programming' started by Georgios Sakalis, Aug 12, 2006.

  1. 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??
     
    Georgios Sakalis, Aug 12, 2006
    #1
    1. Advertising

  2. Georgios Sakalis

    Malcolm Guest

    "Georgios Sakalis" <> wrote in message
    news:ebk6o1$g56$...
    >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.
     
    Malcolm, Aug 12, 2006
    #2
    1. Advertising

  3. Georgios Sakalis

    Morris Dovey Guest

    Georgios Sakalis (in ebk6o1$g56$) 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
     
    Morris Dovey, Aug 12, 2006
    #3
  4. Georgios Sakalis

    jmcgill Guest

    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.
     
    jmcgill, Aug 12, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt
    Replies:
    35
    Views:
    10,631
    George Neuner
    Jul 22, 2004
  2. -
    Replies:
    2
    Views:
    405
    Alan Krueger
    Jul 29, 2005
  3. Casey Hawthorne
    Replies:
    4
    Views:
    1,011
    Jarek Zgoda
    Aug 4, 2006
  4. Don Blow, Jr.

    CGI Programming in C on Xitami Web Server

    Don Blow, Jr., Jun 28, 2004, in forum: C Programming
    Replies:
    9
    Views:
    524
    Default User
    Jul 1, 2004
  5. Joe Mayo
    Replies:
    168
    Views:
    3,325
    David Thompson
    Oct 22, 2007
Loading...

Share This Page