WIZwikiREST-io exercise code for WIZnet Academy
Dependencies: MbedJSONValue_v102 WIZnetInterface mbed
Fork of WIZwiki-REST-io_v103 by
RequestHandler.cpp
- Committer:
- MidnightCow
- Date:
- 2016-04-05
- Revision:
- 1:728e5b5c8dae
- Parent:
- 0:5886f525a4ad
- Child:
- 2:ca36ecca24c2
File content as of revision 1:728e5b5c8dae:
#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; char depth = 0; char* name = 0; while(tok) { printf("tok = %s \r\n", tok); // Name if(tmpJson->hasMember(tok)) { tmpJson = &((*tmpJson)[tok]); name = tok; tok = strtok_r(0, "/", &last); depth++; } else { printf("No Member\r\n"); break; } } /* if(tmpJson && tmpJson->size() > 0) { strcpy(reply, (*tmpJson).serialize().c_str()); } else { strcpy(reply, "{\"Result\" : \"No defined Resource\"}"); } */ /* if(name) { printf("name=%s, tok=%s\r\n",name,tok); if(tok) { if(depth == 2) { if(!strcmp(name, "MAC")) strcpy(reply, "{\"Result\" : \"No Accessible\"}"); else { if(tmpJson->size() > 0) *tmpJson = std::string(tok); else *tmpJson = atoi(tok); strcpy(reply, (*tmpJson).serialize().c_str()); } } else if(depth == 1) strcpy(reply, "{\"Result : No Accessible\"}"); } else strcpy(reply, (*tmpJson).serialize().c_str()); return; } strcpy(reply, "{\"Result\" : \"No defined Resource\"}"); */ if(name) { if(tok) { if(tmpJson->accessible) { printf("accessible : tmpJson->size()=%d\r\n",tmpJson->size()); if(tmpJson->size() > 0) {*tmpJson = std::string(tok); tmpJson->cb_action((void*)tok); printf("set string:%s\r\n",tok);} else {*tmpJson = atoi(tok); tmpJson->cb_action(&tmpJson->_value); printf("set int:%d\r\n",atoi(tok));} strcpy(reply, (*tmpJson).serialize().c_str()); } else strcpy(reply, "{\"Result : No Accessible\"}"); } else 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) { }