Programming a web server in C

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Georgios Sakalis

    #1

    Programming a web server in C

    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??


  • Malcolm

    #2
    Re: Programming a web server in C




    "Georgios Sakalis" <sakalis@gmail. comwrote in message
    news:ebk6o1$g56 $1@volcano1.grn et.gr...
    >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(cha r *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.


    --

    freeware games to download.


    Comment

    • Morris Dovey

      #3
      Re: Programming a web server in C

      Georgios Sakalis (in ebk6o1$g56$1@vo lcano1.grnet.gr ) 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



      Comment

      • jmcgill

        #4
        Re: Programming a web server in C

        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.

        Comment

        Working...