Lawrence Lee / Mbed 2 deprecated WIZwiki-REST

Dependencies:   MbedJSONValue WIZnetInterface mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers RequestHandler.cpp Source File

RequestHandler.cpp

00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <string.h>
00004 #include "RequestHandler.h"
00005 #include "MbedJSONValue.h"
00006 
00007 extern MbedJSONValue WIZwikiREST;
00008 
00009 void GetRequestHandler::handle(char* rest_uri, char *reply)
00010 {
00011     MbedJSONValue* tmpJson;
00012 
00013       char* tok;
00014       char* last;
00015 
00016     printf("GetRequestHandler():%s\r\n",rest_uri);
00017     
00018     if(!strcmp(rest_uri, "/"))
00019     {
00020         strcpy(reply, WIZwikiREST.serialize().c_str());     
00021                 return;
00022     }
00023         tok = strtok_r(rest_uri+1, "/", &last);             // 20160226
00024         tmpJson = &WIZwikiREST;
00025     
00026     while(tok)
00027     {
00028             printf("tok = %s \r\n", tok);               // Name
00029               if(tmpJson->size() > 0)       tmpJson = &((*tmpJson)[tok]);
00030         else
00031                 {
00032              tmpJson = 0;
00033                      break;
00034                 }
00035                 tok = strtok_r(0, "/", &last);              // 20160226             
00036     }
00037         if(tmpJson && tmpJson->size() > 0)
00038         {
00039              strcpy(reply, (*tmpJson).serialize().c_str());
00040         }   
00041         else
00042         {
00043             strcpy(reply, "{\"Result\" : \"No defined Resource\"}");
00044         }
00045         return;
00046 }
00047 
00048 void PutRequestHandler::handle(char* rest_uri, char *reply)
00049 {
00050 }
00051 
00052 void DeleteRequestHandler::handle(char* rest_uri, char *reply)
00053 {
00054 }
00055 
00056