WIZwikiREST-io Reference code for WIZnet Academy
Dependencies: DHT MbedJSONValue_v102 WIZnetInterface mbed-src
Fork of WIZwiki-REST-io_v103 by
Diff: RequestHandler.cpp
- Revision:
- 0:5886f525a4ad
- Child:
- 1:728e5b5c8dae
diff -r 000000000000 -r 5886f525a4ad RequestHandler.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/RequestHandler.cpp Wed Mar 02 03:28:08 2016 +0000 @@ -0,0 +1,56 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include "RequestHandler.h" +#include "MbedJSONValue.h" + +extern MbedJSONValue WIZwikiREST; + +void GetRequestHandler::handle(char* rest_uri, char *reply) +{ + MbedJSONValue* tmpJson; + + char* tok; + char* last; + + printf("GetRequestHandler():%s\r\n",rest_uri); + + if(!strcmp(rest_uri, "/")) + { + strcpy(reply, WIZwikiREST.serialize().c_str()); + return; + } + tok = strtok_r(rest_uri+1, "/", &last); // 20160226 + tmpJson = &WIZwikiREST; + + while(tok) + { + printf("tok = %s \r\n", tok); // Name + if(tmpJson->size() > 0) tmpJson = &((*tmpJson)[tok]); + else + { + tmpJson = 0; + break; + } + tok = strtok_r(0, "/", &last); // 20160226 + } + if(tmpJson && tmpJson->size() > 0) + { + strcpy(reply, (*tmpJson).serialize().c_str()); + } + else + { + strcpy(reply, "{\"Result\" : \"No defined Resource\"}"); + } + return; +} + +void PutRequestHandler::handle(char* rest_uri, char *reply) +{ +} + +void DeleteRequestHandler::handle(char* rest_uri, char *reply) +{ +} + +