![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
WIZwikiREST-io exercise code for WIZnet Academy
Dependencies: MbedJSONValue_v102 WIZnetInterface mbed
Fork of WIZwiki-REST-io_v103 by
RequestHandler.cpp@0:5886f525a4ad, 2016-03-02 (annotated)
- Committer:
- joon874
- Date:
- Wed Mar 02 03:28:08 2016 +0000
- Revision:
- 0:5886f525a4ad
- Child:
- 1:728e5b5c8dae
WIZwikiREST ver1 (Memory problem)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
joon874 | 0:5886f525a4ad | 1 | #include <stdio.h> |
joon874 | 0:5886f525a4ad | 2 | #include <stdlib.h> |
joon874 | 0:5886f525a4ad | 3 | #include <string.h> |
joon874 | 0:5886f525a4ad | 4 | #include "RequestHandler.h" |
joon874 | 0:5886f525a4ad | 5 | #include "MbedJSONValue.h" |
joon874 | 0:5886f525a4ad | 6 | |
joon874 | 0:5886f525a4ad | 7 | extern MbedJSONValue WIZwikiREST; |
joon874 | 0:5886f525a4ad | 8 | |
joon874 | 0:5886f525a4ad | 9 | void GetRequestHandler::handle(char* rest_uri, char *reply) |
joon874 | 0:5886f525a4ad | 10 | { |
joon874 | 0:5886f525a4ad | 11 | MbedJSONValue* tmpJson; |
joon874 | 0:5886f525a4ad | 12 | |
joon874 | 0:5886f525a4ad | 13 | char* tok; |
joon874 | 0:5886f525a4ad | 14 | char* last; |
joon874 | 0:5886f525a4ad | 15 | |
joon874 | 0:5886f525a4ad | 16 | printf("GetRequestHandler():%s\r\n",rest_uri); |
joon874 | 0:5886f525a4ad | 17 | |
joon874 | 0:5886f525a4ad | 18 | if(!strcmp(rest_uri, "/")) |
joon874 | 0:5886f525a4ad | 19 | { |
joon874 | 0:5886f525a4ad | 20 | strcpy(reply, WIZwikiREST.serialize().c_str()); |
joon874 | 0:5886f525a4ad | 21 | return; |
joon874 | 0:5886f525a4ad | 22 | } |
joon874 | 0:5886f525a4ad | 23 | tok = strtok_r(rest_uri+1, "/", &last); // 20160226 |
joon874 | 0:5886f525a4ad | 24 | tmpJson = &WIZwikiREST; |
joon874 | 0:5886f525a4ad | 25 | |
joon874 | 0:5886f525a4ad | 26 | while(tok) |
joon874 | 0:5886f525a4ad | 27 | { |
joon874 | 0:5886f525a4ad | 28 | printf("tok = %s \r\n", tok); // Name |
joon874 | 0:5886f525a4ad | 29 | if(tmpJson->size() > 0) tmpJson = &((*tmpJson)[tok]); |
joon874 | 0:5886f525a4ad | 30 | else |
joon874 | 0:5886f525a4ad | 31 | { |
joon874 | 0:5886f525a4ad | 32 | tmpJson = 0; |
joon874 | 0:5886f525a4ad | 33 | break; |
joon874 | 0:5886f525a4ad | 34 | } |
joon874 | 0:5886f525a4ad | 35 | tok = strtok_r(0, "/", &last); // 20160226 |
joon874 | 0:5886f525a4ad | 36 | } |
joon874 | 0:5886f525a4ad | 37 | if(tmpJson && tmpJson->size() > 0) |
joon874 | 0:5886f525a4ad | 38 | { |
joon874 | 0:5886f525a4ad | 39 | strcpy(reply, (*tmpJson).serialize().c_str()); |
joon874 | 0:5886f525a4ad | 40 | } |
joon874 | 0:5886f525a4ad | 41 | else |
joon874 | 0:5886f525a4ad | 42 | { |
joon874 | 0:5886f525a4ad | 43 | strcpy(reply, "{\"Result\" : \"No defined Resource\"}"); |
joon874 | 0:5886f525a4ad | 44 | } |
joon874 | 0:5886f525a4ad | 45 | return; |
joon874 | 0:5886f525a4ad | 46 | } |
joon874 | 0:5886f525a4ad | 47 | |
joon874 | 0:5886f525a4ad | 48 | void PutRequestHandler::handle(char* rest_uri, char *reply) |
joon874 | 0:5886f525a4ad | 49 | { |
joon874 | 0:5886f525a4ad | 50 | } |
joon874 | 0:5886f525a4ad | 51 | |
joon874 | 0:5886f525a4ad | 52 | void DeleteRequestHandler::handle(char* rest_uri, char *reply) |
joon874 | 0:5886f525a4ad | 53 | { |
joon874 | 0:5886f525a4ad | 54 | } |
joon874 | 0:5886f525a4ad | 55 | |
joon874 | 0:5886f525a4ad | 56 |