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,7 +30,7 @@
* *
* Author: Adam Dunkels <adam@sics.se> * 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> #include <stdio.h>
@ -273,5 +273,8 @@ httpd_init(void)
{ {
tcp_listen(HTONS(80)); tcp_listen(HTONS(80));
memb_init(&conns); memb_init(&conns);
#if URLCONV
urlconv_init();
#endif /* URLCONV */
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/

View File

@ -30,11 +30,12 @@
* *
* Author: Kajtar Zsolt <soci@c64.rulez.org> * 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 <string.h>
#include "cfs/cfs.h"
#include "http-strings.h" #include "http-strings.h"
#define ISO_number 0x23 #define ISO_number 0x23
@ -43,9 +44,22 @@
#define ISO_slash 0x2f #define ISO_slash 0x2f
#define ISO_question 0x3f #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 /* URL to filename conversion
* *
* prepends wwwroot prefix
* normalizes path by removing "/./" * normalizes path by removing "/./"
* interprets "/../" and calculates path accordingly * interprets "/../" and calculates path accordingly
* resulting path is always absolute * 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 c, hex1;
static unsigned char *from, *to; static unsigned char *from, *to;
*dest = ISO_slash;
strncpy(dest + 1, wwwroot, wwwrootlen);
len = 0; len = 0;
from = source; to = dest; from = source; to = dest + wwwrootlen;
*to = ISO_slash; maxlen -= 2 + wwwrootlen;
maxlen -= 2;
do { do {
c = *(from++); c = *(from++);
switch(c) { switch(c) {

View File

@ -28,12 +28,13 @@
* *
* This file is part of the Contiki operating system. * 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__ #ifndef __URLCONV_H__
#define __URLCONV_H__ #define __URLCONV_H__
void urlconv_init(void);
void urlconv_tofilename(char *dest, char *source, unsigned char maxlen); void urlconv_tofilename(char *dest, char *source, unsigned char maxlen);
#endif /* __URLCONV_H__ */ #endif /* __URLCONV_H__ */

View File

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * 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)); tcp_listen(HTONS(80));
memb_init(&conns); memb_init(&conns);
#if URLCONV
urlconv_init();
#else /* URLCONV */
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/