Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of libMiMic by
Diff: mbed/ModLocalFileSystem.cpp
- Revision:
- 19:33b9ba0859ee
- Parent:
- 18:1970fec78229
- Child:
- 20:3b0b444b4deb
diff -r 1970fec78229 -r 33b9ba0859ee mbed/ModLocalFileSystem.cpp
--- a/mbed/ModLocalFileSystem.cpp Fri Apr 26 14:55:24 2013 +0000
+++ b/mbed/ModLocalFileSystem.cpp Sat Apr 27 13:31:57 2013 +0000
@@ -2,17 +2,17 @@
#include "HttpdConnection.h"
#include "UrlReader.h"
#include "Http.h"
+#include "Httpd.h"
#include "NyLPC_net.h"
#include <stdio.h>
#include <stdlib.h>
#include <typeinfo>
#include "mbed.h"
#include "FATDirHandle.h"
-#define ModLocalFile_SIZE_OF_BUF 256
-static char buf[ModLocalFile_SIZE_OF_BUF];
+
using namespace MiMic;
-static void retDirJson(UrlReader& url,HttpdConnection& i_connection)
+static void retDirJson(UrlReader& url,char* buf,HttpdConnection& i_connection)
{
//assert(HEAD or GET)
//directory-list json
@@ -64,7 +64,7 @@
}
closedir(d);
}
-static void retDirHtml(UrlReader& url,HttpdConnection& i_connection)
+static void retDirHtml(UrlReader& url,char* buf,HttpdConnection& i_connection)
{
//assert(HEAD or GET)
buf[strlen(buf)-1]='\0';//convert to dir path
@@ -114,7 +114,7 @@
}
closedir(d);
}
-static void retFile(UrlReader& url,HttpdConnection& i_connection)
+static void retFile(UrlReader& url,char* buf,HttpdConnection& i_connection)
{
//file contents
{//split URL path and query
@@ -144,12 +144,18 @@
if(!i_connection.isMethodType(Http::MT_GET)){
//nothing to do
}else{
+ {DigitalOut led(LED1);led=0;}
+ {DigitalOut led(LED2);led=0;}
+ {DigitalOut led(LED3);led=0;}
+ {DigitalOut led(LED4);led=1;}
+
for(;;){
- sz=fread(buf,1,ModLocalFile_SIZE_OF_BUF,fp);
+ sz=fread(buf,1,Httpd::SIZE_OF_HTTP_BUF,fp);
if(sz<1){
break;
}
if(!i_connection.sendBody(buf,sz)){
+ {DigitalOut led(LED1);led=1;}
break;
}
//switch transport thread
@@ -161,6 +167,7 @@
}
}
}
+ {DigitalOut led(LED2);led=1;}
fclose(fp);
}
@@ -201,14 +208,16 @@
}
//Httpd lock
i_connection.lockHttpd();
+ char* buf=Httpd::_shared_buf;
+
//set file path
{
//call ModUrl
NyLPC_TcModUrl_t mod;
NyLPC_cModUrl_initialize(&mod);
- if(!NyLPC_cModUrl_execute2(&mod,i_connection._ref_inst,buf,ModLocalFile_SIZE_OF_BUF,0)){
+ if(!NyLPC_cModUrl_execute2(&mod,i_connection._ref_inst,buf,Httpd::SIZE_OF_HTTP_BUF,0,NyLPC_cModUrl_ParseMode_ALL)){
NyLPC_cModUrl_finalize(&mod);
- i_connection.releaseHttpd();
+ i_connection.unlockHttpd();
return true;
}
NyLPC_cModUrl_finalize(&mod);
@@ -216,15 +225,15 @@
UrlReader url(buf);
if(url.hasQueryKey("list")){
// if path has '/?list' query key,return directory information
- retDirJson(url,i_connection);
+ retDirJson(url,buf,i_connection);
}else if(strchr(buf,'?')==NULL && strchr(buf,'#')==NULL && buf[strlen(buf)-1]=='/'){
//return directory html when URL has not bookmark and URL query and terminated by '/'.
- retDirHtml(url,i_connection);
+ retDirHtml(url,buf,i_connection);
}else{
- retFile(url,i_connection);
+ retFile(url,buf,i_connection);
}
//Httpd unlock
- i_connection.releaseHttpd();
+ i_connection.unlockHttpd();
return true;
}
