Changeset 5730:bffff5f70163 in roaraudio


Ignore:
Timestamp:
11/07/12 01:10:52 (11 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

support index files

File:
1 edited

Legend:

Unmodified
Added
Removed
  • plugins/universal/protocol-http.c

    r5729 r5730  
    410410 void * data; 
    411411 ssize_t ret; 
     412 int err; 
    412413 
    413414 // TODO: use content type for some basic filtering. 
     
    420421 
    421422 ret = roar_vio_read(self->input.vio, data, len); 
     423 err = roar_error; 
    422424 
    423425 if ( ret < 1 ) { 
    424426  roar_buffer_free(buffer); 
    425   return 0; 
     427  roar_error = err; 
     428  return -1; 
    426429 } 
    427430 
     
    442445 
    443446static int __res_vio_header_send(struct http_client * self, struct roar_buffer ** obuffer) { 
     447 static const char * index_files[] = {NULL, "index.html", "index.txt", "index"}; 
    444448 struct roar_buffer * buffer; 
    445449 struct roar_keyval * path; 
     
    447451 const char * slash = "/"; 
    448452 const char * content_type = NULL; 
     453 int uste_check; 
     454 size_t i; 
    449455 
    450456 if ( self->pluginpara == NULL ) { 
     
    478484  slash = ""; 
    479485 
    480  snprintf(filename, sizeof(filename), "%s%s%s", path->value, slash, self->path); 
    481  
    482  
    483  self->input.vio = &(self->input.vio_store); 
    484  if ( roar_vio_open_dstr_simple(self->input.vio, filename, ROAR_VIOF_READ|ROAR_VIOF_NONBLOCK) == -1 ) { 
    485   return -1; 
    486  } 
    487  
    488  if ( roar_vio_ctl(self->input.vio, ROAR_VIO_CTL_GET_MIMETYPE, &content_type) == -1 ) 
    489   content_type = NULL; 
    490  
    491  if ( content_type == NULL ) 
    492   content_type = __res_vio_content_type_get(self); 
    493  
    494  if ( __res_vio_check_uste(self, &buffer, content_type) == 1 ) { 
     486 uste_check = -1; 
     487 for (i = 0; uste_check == -1 && i < (sizeof(index_files)/sizeof(*index_files)); i++) { 
     488  snprintf(filename, sizeof(filename), "%s%s%s%s%s", path->value, slash, self->path, 
     489           index_files[i] == NULL ? "" : "/", 
     490           index_files[i] == NULL ? "" : index_files[i]); 
     491 
     492 
     493  self->input.vio = &(self->input.vio_store); 
     494  if ( roar_vio_open_dstr_simple(self->input.vio, filename, ROAR_VIOF_READ|ROAR_VIOF_NONBLOCK) == -1 ) { 
     495   continue; 
     496  } 
     497 
     498  if ( roar_vio_ctl(self->input.vio, ROAR_VIO_CTL_GET_MIMETYPE, &content_type) == -1 ) 
     499   content_type = NULL; 
     500 
     501  if ( content_type == NULL ) 
     502   content_type = __res_vio_content_type_get(self); 
     503 
     504  uste_check = __res_vio_check_uste(self, &buffer, content_type); 
     505  if ( uste_check == -1 ) 
     506   roar_vio_unref(self->input.vio); 
     507 } 
     508 
     509 if ( uste_check == -1 ) 
     510  return -1; 
     511 
     512 if ( uste_check == 1 ) { 
    495513  if ( buffer != NULL ) 
    496514   roar_buffer_free(buffer); 
Note: See TracChangeset for help on using the changeset viewer.