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:
parent
f02cdc7c8f
commit
a5dff5e08a
|
@ -30,7 +30,7 @@
|
|||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
* $Id: httpd-cfs.c,v 1.22 2010/04/11 20:54:39 oliverschmidt Exp $
|
||||
* $Id: httpd-cfs.c,v 1.23 2010/08/30 19:44:38 oliverschmidt Exp $
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
@ -273,5 +273,8 @@ httpd_init(void)
|
|||
{
|
||||
tcp_listen(HTONS(80));
|
||||
memb_init(&conns);
|
||||
#if URLCONV
|
||||
urlconv_init();
|
||||
#endif /* URLCONV */
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -28,12 +28,13 @@
|
|||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* $Id: urlconv.h,v 1.2 2010/04/11 20:16:56 oliverschmidt Exp $
|
||||
* $Id: urlconv.h,v 1.3 2010/08/30 19:44:38 oliverschmidt Exp $
|
||||
*/
|
||||
|
||||
#ifndef __URLCONV_H__
|
||||
#define __URLCONV_H__
|
||||
|
||||
void urlconv_init(void);
|
||||
void urlconv_tofilename(char *dest, char *source, unsigned char maxlen);
|
||||
|
||||
#endif /* __URLCONV_H__ */
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: httpd-simple.c,v 1.2 2010/05/09 13:29:33 nifi Exp $
|
||||
* $Id: httpd-simple.c,v 1.3 2010/08/30 19:44:38 oliverschmidt Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -251,5 +251,8 @@ httpd_init(void)
|
|||
{
|
||||
tcp_listen(HTONS(80));
|
||||
memb_init(&conns);
|
||||
#if URLCONV
|
||||
urlconv_init();
|
||||
#else /* URLCONV */
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
|
Loading…
Reference in a new issue