Ignore:
Timestamp:
Feb 4, 2016, 11:11:09 PM (8 years ago)
Author:
coas-nagasima
Message:

URLがフォルダを指している場合、/index.htmlにリダイレクトするよう変更。

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uKadecot/trunk/uip/apps/webserver/httpd-fs.c

    r154 r155  
    4040#include "mmc_rspi.h"
    4141#include <string.h>
     42#include "http-strings.h"
     43
     44#ifndef _MSC_VER
     45#ifndef strcat_s
     46#define strcat_s(dst, dsz, src) strcat(dst, src)
     47#endif
     48#endif
    4249
    4350//#define FILE_DUMP
     
    114121/*-----------------------------------------------------------------------------------*/
    115122int
    116 httpd_fs_open(int drv, const char *name, struct httpd_fs_file *file)
     123httpd_fs_open(int drv, char *name, int len, struct httpd_fs_file *file)
    117124{
    118125        FRESULT res;
    119         FATFS *fs = (FATFS *)file->fs;
     126        FATFS *fs = (FATFS *)&file->fs;
     127        FILINFO fno;
     128        DIR dir;
    120129
    121130        file->pos = 0;
     
    123132        file->drv = drv;
    124133        file->name = name;
     134        file->redirect = 0;
    125135        memset(fs, 0, sizeof(FATFS));
    126136
     
    143153        }
    144154
    145         if((res = pf_open(fs, name)) != FR_OK){
    146                 printf("pf_open(%d:%s) => %d\n", drv, name, res);
    147                 return 0;
     155        if ((res = pf_open(fs, name)) != FR_OK) {
     156                dir.fs = fs;
     157                if ((res = pf_opendir(&dir, name)) != FR_OK) {
     158                        printf("pf_opendir(%d:%s) => %d\n", drv, name, res);
     159                        return 0;
     160                }
     161
     162                if ((res = pf_readdir(&dir, &fno)) != FR_OK) {
     163                        printf("pf_readdir(%d:%s) => %d\n", drv, name, res);
     164                        return 0;
     165                }
     166
     167                if (len != 0/*fno.fattrib & AM_DIR*/) {
     168                        strcat_s(name, len, http_index_html);
     169                        res = pf_open(fs, name);
     170                        file->redirect = res == FR_OK;
     171                }
     172                else
     173                        res = FR_NO_FILE;
     174
     175                if (res != FR_OK) {
     176                        printf("pf_open(%d:%s) => %d %x\n", drv, name, res, fno.fattrib);
     177                        return 0;
     178                }
    148179        }
    149180
     
    160191        FRESULT ret;
    161192        UINT rlen;
    162         FATFS *fs = (FATFS *)file->fs;
     193        FATFS *fs = (FATFS *)&file->fs;
    163194
    164195        if((ret = pf_lseek(fs, file->pos)) != FR_OK){
Note: See TracChangeset for help on using the changeset viewer.