Up to now the root of the webserver filesystem was always the current directory. Now an optional file 'wwwroot.cfg' is read. If present its content is used as prefix in the conversion of http paths to local paths. This prefix may be a relative path as well as an absolute path.

This is especially useful for the cc65-based targets as it ain't possible there to "just change into the wwwroot directory and start the webserver using its pathname".
This commit is contained in:
oliverschmidt 2010-08-30 19:44:38 +00:00
parent f02cdc7c8f
commit a5dff5e08a
4 changed files with 29 additions and 7 deletions

View file

@ -30,11 +30,12 @@
*
* Author: Kajtar Zsolt <soci@c64.rulez.org>
*
* $Id: urlconv.c,v 1.1 2010/04/11 19:18:47 oliverschmidt Exp $
* $Id: urlconv.c,v 1.2 2010/08/30 19:44:38 oliverschmidt Exp $
*/
#include <string.h>
#include "cfs/cfs.h"
#include "http-strings.h"
#define ISO_number 0x23
@ -43,9 +44,22 @@
#define ISO_slash 0x2f
#define ISO_question 0x3f
static char wwwroot[40];
static unsigned char wwwrootlen;
void
urlconv_init(void)
{
int fd = cfs_open("wwwroot.cfg", CFS_READ);
int rd = cfs_read(fd, wwwroot, sizeof(wwwroot));
cfs_close(fd);
if(rd != -1) wwwrootlen = rd;
}
/*---------------------------------------------------------------------------*/
/* URL to filename conversion
*
* prepends wwwroot prefix
* normalizes path by removing "/./"
* interprets "/../" and calculates path accordingly
* resulting path is always absolute
@ -64,10 +78,11 @@ urlconv_tofilename(char *dest, char *source, unsigned char maxlen)
static unsigned char c, hex1;
static unsigned char *from, *to;
*dest = ISO_slash;
strncpy(dest + 1, wwwroot, wwwrootlen);
len = 0;
from = source; to = dest;
*to = ISO_slash;
maxlen -= 2;
from = source; to = dest + wwwrootlen;
maxlen -= 2 + wwwrootlen;
do {
c = *(from++);
switch(c) {