Changeset 10364


Ignore:
Timestamp:
09/15/08 16:24:07 (5 years ago)
Author:
BrainSlayer
Message:

better header handler

Location:
src/router/httpd
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/router/httpd/httpd.c

    r10363 r10364  
    179179                        char *text ); 
    180180static void send_headers( int status, char *title, char *extra_header, 
    181                           char *mime_type, long length ); 
     181                          char *mime_type, long length ,char *attach_file); 
    182182static int b64_decode( const char *str, unsigned char *space, int size ); 
    183183static int match( const char *pattern, const char *string ); 
     
    313313 
    314314    // jimmy, https, 8/4/2003, fprintf -> wfprintf, fflush -> wfflush 
    315     send_headers( status, title, extra_header, "text/html", 0 ); 
     315    send_headers( status, title, extra_header, "text/html", 0 ,NULL); 
    316316    ( void )wfprintf( conn_fp, 
    317317                      "<HTML><HEAD><TITLE>%d %s</TITLE></HEAD>\n<BODY BGCOLOR=\"#cc9999\"><H4>%d %s</H4>\n", 
     
    324324static void 
    325325send_headers( int status, char *title, char *extra_header, char *mime_type, 
    326               long length ) 
     326              long length , char *attach_file) 
    327327{ 
    328328    time_t now; 
    329329    char timebuf[100]; 
    330  
    331     // jimmy, https, 8/4/2003, fprintf -> wfprintf 
    332330    wfprintf( conn_fp, "%s %d %s\r\n", PROTOCOL, status, title ); 
     331    if( mime_type != ( char * )0 ) 
     332        wfprintf( conn_fp, "Content-Type: %s\r\n", mime_type ); 
     333 
     334 
    333335    wfprintf( conn_fp, "Server: %s\r\n", SERVER_NAME ); 
    334336    now = time( ( time_t * ) 0 ); 
    335337    strftime( timebuf, sizeof( timebuf ), RFC1123FMT, gmtime( &now ) ); 
    336338    wfprintf( conn_fp, "Date: %s\r\n", timebuf ); 
     339    wfprintf( conn_fp, "Connection: close\r\n" ); 
     340    if (attach_file) 
     341        wfprintf( conn_fp, "Content-Disposition: attachment; filename=%s\r\n", attach_file ); 
    337342    if( extra_header != ( char * )0 && *extra_header ) 
    338343        wfprintf( conn_fp, "%s\r\n", extra_header ); 
    339     if( mime_type != ( char * )0 ) 
    340         wfprintf( conn_fp, "Content-Type: %s\r\n", mime_type ); 
    341344    if( length != 0 ) 
    342345        wfprintf( conn_fp, "Content-Length: %ld\r\n", length ); 
    343     wfprintf( conn_fp, "Connection: close\r\n" ); 
    344346    wfprintf( conn_fp, "\r\n" ); 
    345347} 
     
    479481} 
    480482 
    481 void 
     483static void 
    482484//do_file(char *path, FILE *stream) 
    483 do_file( struct mime_handler *handler, char *path, webs_t stream, char *query ) //jimmy, https, 8/4/2003 
     485do_file_2( struct mime_handler *handler, char *path, webs_t stream, char *query,char *attach )  //jimmy, https, 8/4/2003 
    484486{ 
    485487 
     
    521523        if( !handler->send_headers ) 
    522524            send_headers( 200, "Ok", handler->extra_header, 
    523                           handler->mime_type, ftell( fp ) ); 
     525                          handler->mime_type, ftell( fp ) ,attach); 
    524526        fseek( fp, 0, SEEK_SET ); 
    525527        while( ( c = getc( fp ) ) != EOF ) 
     
    534536        if( !handler->send_headers ) 
    535537            send_headers( 200, "Ok", handler->extra_header, 
    536                           handler->mime_type, len ); 
     538                          handler->mime_type, len ,attach); 
    537539        int a; 
    538540        char buf[128]; 
     
    550552    } 
    551553#endif 
     554} 
     555 
     556 
     557void 
     558//do_file(char *path, FILE *stream) 
     559do_file( struct mime_handler *handler, char *path, webs_t stream, char *query ) //jimmy, https, 8/4/2003 
     560{ 
     561 
     562do_file_2(handler,path,stream,query,NULL); 
     563} 
     564void 
     565//do_file(char *path, FILE *stream) 
     566do_file_attach( struct mime_handler *handler, char *path, webs_t stream, char *query,char *attachment ) //jimmy, https, 8/4/2003 
     567{ 
     568 
     569do_file_2(handler,path,stream,query,attachment); 
    552570} 
    553571 
     
    10411059                    if( handler->send_headers ) 
    10421060                        send_headers( 200, "Ok", handler->extra_header, 
    1043                                       handler->mime_type, 0 ); 
     1061                                      handler->mime_type, 0,NULL ); 
    10441062                } 
    10451063                if( handler->output ) 
  • src/router/httpd/httpd.h

    r10356 r10364  
    8787/* Regular file handler */ 
    8888extern void do_file (struct mime_handler *handler,char *path, webs_t stream, char *query); 
     89extern void do_file_attach (struct mime_handler *handler,char *path, webs_t stream, char *query, char *attachment); 
    8990 
    9091/* GoAhead 2.1 compatibility */ 
  • src/router/httpd/modules/broadcom.c

    r10356 r10364  
    14971497{ 
    14981498    system2( "cat /dev/mtd/0 > /tmp/cfe.bin" ); 
    1499     do_file(handler, "/tmp/cfe.bin", stream, NULL ); 
     1499    do_file_attach(handler, "/tmp/cfe.bin", stream, NULL,"cfe.bin" ); 
    15001500    unlink( "/tmp/cfe.bin" ); 
    15011501} 
     
    21642164#ifdef HAVE_DDLAN 
    21652165    {"nvrambak.bin*", "application/octet-stream", no_cache, NULL, nv_file_out, 
    2166      do_auth2,1}, 
     2166     do_auth2,0}, 
    21672167    {"nvrambak**.bin*", "application/octet-stream", no_cache, NULL, 
    21682168     nv_file_out, 
    2169      do_auth2,1}, 
     2169     do_auth2,0}, 
    21702170    {"nvram.cgi*", "text/html", no_cache, nv_file_in, sr_config_cgi, NULL,1}, 
    21712171#else 
    21722172    {"nvrambak.bin*", "application/octet-stream", no_cache, NULL, nv_file_out, 
    2173      do_auth,1}, 
     2173     do_auth,0}, 
    21742174    {"nvrambak**.bin*", "application/octet-stream", no_cache, NULL, 
    21752175     nv_file_out, 
    2176      do_auth,1}, 
     2176     do_auth,0}, 
    21772177    {"nvram.cgi*", "text/html", no_cache, nv_file_in, sr_config_cgi, do_auth,1}, 
    21782178#endif 
  • src/router/httpd/modules/nvramsr.c

    r10356 r10364  
    296296            backupcount++; 
    297297    } 
    298     wfwrite( sign, 6, 1, wp ); 
    299     wfputc( backupcount & 255, wp );    // high byte 
    300     wfputc( backupcount >> 8, wp );     // low byte 
     298    FILE *fp = fopen("/tmp/nvrambak.bin","wb"); 
     299     
     300    fwrite( sign, 6, 1, fp ); 
     301    fputc( backupcount & 255, fp );     // high byte 
     302    fputc( backupcount >> 8, fp );      // low byte 
    301303    while( strlen( p ) != 0 ) 
    302304    { 
     
    308310        char *name = p; 
    309311 
    310         wfputc( strlen( name ), wp ); 
     312        fputc( strlen( name ), fp ); 
    311313 
    312314        for( i = 0; i < strlen( name ); i++ ) 
    313             wfputc( name[i], wp ); 
     315            fputc( name[i], fp ); 
    314316        char *val = nvram_safe_get( name ); 
    315317 
    316         wfputc( strlen( val ) & 255, wp ); 
    317         wfputc( strlen( val ) >> 8, wp ); 
     318        fputc( strlen( val ) & 255, fp ); 
     319        fputc( strlen( val ) >> 8, fp ); 
    318320        for( i = 0; i < strlen( val ); i++ ) 
    319             wfputc( val[i], wp ); 
     321            fputc( val[i], fp ); 
    320322 
    321323        p += len + 1; 
    322324    } 
    323325    free( buf ); 
    324  
     326    fclose(fp); 
     327    do_file_attach(handler,"/tmp/nvrambak.bin",wp,query,"nvrambak.bin"); 
     328    eval("rm","-f","/tmp/nvrambak.bin"); 
    325329    return; 
    326330} 
  • src/router/httpd/xyssl/library/Makefile

    r10362 r10364  
    2828 
    2929libxyssl.a: $(OBJS) 
    30         @echo "  $(AR)    $@"; $(AR) r $@ $(OBJS) 
     30        $(AR) r $@ $(OBJS) 
    3131 
    3232shared: libxyssl.so 
    3333 
    3434libxyssl.so: $(OBJS)  
    35         @echo "  $(LD)    $@"; $(LD) -shared -o $@ $^ 
     35        $(LD) -shared -o $@ $^ 
    3636 
    3737.c.o: 
    38         @echo "  $(CC)    $<"; $(CC) $(CFLAGS) -c $< 
     38        $(CC) $(CFLAGS) -c $< 
    3939 
    4040clean: 
Note: See TracChangeset for help on using the changeset viewer.