![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
WIZwiki-REST-io ver.2 Add POST Method
Dependencies: MbedJSONValue_copy WIZnetInterface mbed
Fork of WIZwiki-REST_mc by
Diff: RequestHandler.cpp
- Revision:
- 1:728e5b5c8dae
- Parent:
- 0:5886f525a4ad
- Child:
- 2:ca36ecca24c2
diff -r 5886f525a4ad -r 728e5b5c8dae RequestHandler.cpp --- a/RequestHandler.cpp Wed Mar 02 03:28:08 2016 +0000 +++ b/RequestHandler.cpp Tue Apr 05 11:40:33 2016 +0000 @@ -23,26 +23,75 @@ 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->size() > 0) tmpJson = &((*tmpJson)[tok]); - else - { - tmpJson = 0; - break; - } - tok = strtok_r(0, "/", &last); // 20160226 - } - if(tmpJson && tmpJson->size() > 0) + printf("tok = %s \r\n", tok); // Name + if(tmpJson->hasMember(tok)) { - strcpy(reply, (*tmpJson).serialize().c_str()); - } + tmpJson = &((*tmpJson)[tok]); + name = tok; + tok = strtok_r(0, "/", &last); + depth++; + } else { - strcpy(reply, "{\"Result\" : \"No defined Resource\"}"); + 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)