View | Details | Raw Unified | Return to bug 29725
Collapse All | Expand All

(-)simple_httpd.c 2001/08/15 09:32:34 1.9 (-25 / +31 lines)
Lines 47-52 Link Here
47
#include <time.h>
47
#include <time.h>
48
#include <unistd.h>
48
#include <unistd.h>
49
49
50
#include "mime_t.h"
51
50
int             http_port = 80;
52
int             http_port = 80;
51
int             daemonize = 1;
53
int             daemonize = 1;
52
int             verbose = 0;
54
int             verbose = 0;
Lines 99-105 Link Here
99
               perror("bind socket");
101
               perror("bind socket");
100
               exit(1);
102
               exit(1);
101
       }
103
       }
102
        if (verbose) printf("simple_httpd\n",http_port);
104
        if (verbose) printf("simple_httpd:%d\n",http_port);
103
}
105
}
104
106
105
/*
107
/*
Lines 191-204 Link Here
191
 */
193
 */
192
http_request()
194
http_request()
193
{
195
{
194
       int             fd, lg, ld, i; 
196
       int             fd, lg, /*ld,*/ i; 
195
       int             cmd = 0;
197
       int             cmd = 0;
196
       int             http1 = 0;
198
/*     int             http1 = 0; */
197
       char           *p, *par;
199
       char           *p, *par;
198
       char           *filename, *c;
200
       char           *filename, *c;
201
       size_t          fname_len;
199
       struct stat     file_status;
202
       struct stat     file_status;
200
       char            req[1024];
203
       char            req[1024];
201
        char            msg[1024];
204
/*      char            msg[1024]; */
202
       char            buff[8192];
205
       char            buff[8192];
203
206
204
       lg = read(con_sock, req, 1024);
207
       lg = read(con_sock, req, 1024);
Lines 231-240 Link Here
231
234
232
       c = strtok(NULL, " ");
235
       c = strtok(NULL, " ");
233
       if (fetch_mode[0] != NULL) strcpy(filename,fetch_mode); 
236
       if (fetch_mode[0] != NULL) strcpy(filename,fetch_mode); 
234
       if (filename == NULL || 
237
       fname_len=strlen(filename);
235
            strlen(filename)==1) filename="/index.html"; 
238
       if (filename == NULL || fname_len == 1) {
239
         filename="/index.html";
240
         fname_len=11;
241
       }
236
242
237
       while (filename[0]== '/') filename++;        
243
       while (filename[0]== '/') { filename++; fname_len--; }
238
       
244
       
239
        /* CGI handling.  Untested */
245
        /* CGI handling.  Untested */
240
        if (!strncmp(filename,"cgi-bin/",8))           
246
        if (!strncmp(filename,"cgi-bin/",8))           
Lines 243-248 Link Here
243
           if (par=strstr(filename,"?"))                        
249
           if (par=strstr(filename,"?"))                        
244
              {
250
              {
245
               *par=0;            
251
               *par=0;            
252
/*             fname_len=par-filename;  // not used but note to the future */
246
                par++;      
253
                par++;      
247
              } 
254
              } 
248
           if (access(filename,X_OK)) goto conti;
255
           if (access(filename,X_OK)) goto conti;
Lines 309-331 Link Here
309
       http_output(httpd_server_ident);
316
       http_output(httpd_server_ident);
310
       http_date();
317
       http_date();
311
318
312
       sprintf(buff, "Content-length: %d\r\n", file_status.st_size);
319
       sprintf(buff, "Content-length: %lld\r\n", file_status.st_size);
313
314
       if (strstr(filename,".txt")) {
315
         strcpy(buff,"Content-type: text/plain\r\n");
316
       } else if (strstr(filename,".html") || strstr(filename,".htm")) {
317
           strcpy(buff,"Content-type: text/html\r\n");
318
       } else if (strstr(filename,".gif")) {
319
         strcpy(buff,"Content-type: image/gif\r\n");
320
       } else if (strstr(filename,".jpg")) {
321
         strcpy(buff,"Content-type: image/jpeg\r\n");
322
       } else {
323
         /* Take a guess at content if we don't have something already */
324
         strcpy(buff,"Content-type: ");
325
         strcat(buff,strstr(filename,".")+1);
326
         strcat(buff,"\r\n");
327
       }
328
       write(con_sock, buff, strlen(buff));
320
       write(con_sock, buff, strlen(buff));
321
322
       strcpy(buff,"Content-type: ");
323
       i=-1;
324
        if (strchr(filename,'.'))      
325
         for (i=mime_type_max; i>=0; i--)      /* file has an extention */
326
           if ((c=strstr(filename,mime_type[i][0])))
327
             if (filename+fname_len==c+strlen(mime_type[i][0])) {
328
               strcat(buff,mime_type[i][1]);
329
               break;
330
             }
331
             
332
       if (i<0)                                /* extention is unknown */
333
         strcat(buff,default_mime_type);       /* or file has no extention */
334
       http_output(buff);
329
       
335
       
330
       strftime(buff, 50, "Last-Modified: %a, %d %h %Y %H:%M:%S %Z\r\n\r\n",
336
       strftime(buff, 50, "Last-Modified: %a, %d %h %Y %H:%M:%S %Z\r\n\r\n",
331
       write(con_sock, buff, strlen(buff));
337
       write(con_sock, buff, strlen(buff));
Lines 351-358 Link Here
351
{
357
{
352
        extern char *optarg;
358
        extern char *optarg;
353
        extern int optind;
359
        extern int optind;
354
        int bflag, ch, fd, ld;
360
        int /*bflag,*/ ch, /*fd,*/ ld;
355
        int             lg;
361
/*      int             lg; */
356
       int             httpd_group = 65534;
362
       int             httpd_group = 65534;
357
        pid_t server_pid;
363
        pid_t server_pid;

Return to bug 29725