Webserver only w/o any other functions, single thread. Running on STM32F013+W5500
Dependencies: NTPClient W5500Interface Watchdog device_configuration eeprom_flash mbed-rpc-nucleo mbed-rtos mbed
Fork of F103-Serial-to-Ethernet by
RPCCommand.cpp@47:d92d2c5b8073, 2016-08-19 (annotated)
- Committer:
- olympux
- Date:
- Fri Aug 19 20:17:00 2016 +0000
- Revision:
- 47:d92d2c5b8073
- Parent:
- 40:c966abbe2d62
forked to create a new repo for webserver on F103+W5500. No other functions
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
olympux | 40:c966abbe2d62 | 1 | #include "RPCCommand.h" |
olympux | 40:c966abbe2d62 | 2 | #include "mbed.h" |
olympux | 40:c966abbe2d62 | 3 | #include "RPCType.h" |
olympux | 40:c966abbe2d62 | 4 | |
olympux | 40:c966abbe2d62 | 5 | |
olympux | 40:c966abbe2d62 | 6 | RPCCommand::RPCCommand(): |
olympux | 40:c966abbe2d62 | 7 | cmd(), |
olympux | 40:c966abbe2d62 | 8 | obj_name(NULL), |
olympux | 40:c966abbe2d62 | 9 | func_name(NULL) |
olympux | 40:c966abbe2d62 | 10 | { |
olympux | 40:c966abbe2d62 | 11 | |
olympux | 40:c966abbe2d62 | 12 | } |
olympux | 40:c966abbe2d62 | 13 | |
olympux | 40:c966abbe2d62 | 14 | bool RPCCommand::decode(char *buffer) |
olympux | 40:c966abbe2d62 | 15 | { |
olympux | 40:c966abbe2d62 | 16 | if(buffer == NULL) |
olympux | 40:c966abbe2d62 | 17 | return false; |
olympux | 40:c966abbe2d62 | 18 | if(buffer[0] != '/') |
olympux | 40:c966abbe2d62 | 19 | return false; |
olympux | 40:c966abbe2d62 | 20 | |
olympux | 40:c966abbe2d62 | 21 | ++buffer; |
olympux | 40:c966abbe2d62 | 22 | char *tmp = strchr(buffer ,'/'); |
olympux | 40:c966abbe2d62 | 23 | |
olympux | 40:c966abbe2d62 | 24 | if(tmp == NULL) |
olympux | 40:c966abbe2d62 | 25 | return false; |
olympux | 40:c966abbe2d62 | 26 | if(tmp == buffer) |
olympux | 40:c966abbe2d62 | 27 | return false; |
olympux | 40:c966abbe2d62 | 28 | |
olympux | 40:c966abbe2d62 | 29 | tmp[0] = '\0'; |
olympux | 40:c966abbe2d62 | 30 | obj_name = buffer; |
olympux | 40:c966abbe2d62 | 31 | |
olympux | 40:c966abbe2d62 | 32 | buffer = tmp+1; |
olympux | 40:c966abbe2d62 | 33 | |
olympux | 40:c966abbe2d62 | 34 | if(buffer[0] == '\0' || buffer[0] == '?') |
olympux | 40:c966abbe2d62 | 35 | return false; |
olympux | 40:c966abbe2d62 | 36 | |
olympux | 40:c966abbe2d62 | 37 | func_name = buffer; |
olympux | 40:c966abbe2d62 | 38 | |
olympux | 40:c966abbe2d62 | 39 | tmp = strchr(buffer, '?'); |
olympux | 40:c966abbe2d62 | 40 | if(tmp != NULL) |
olympux | 40:c966abbe2d62 | 41 | { |
olympux | 40:c966abbe2d62 | 42 | if(tmp[1] == '\0') |
olympux | 40:c966abbe2d62 | 43 | return false; |
olympux | 40:c966abbe2d62 | 44 | tmp[0] = '\0'; |
olympux | 40:c966abbe2d62 | 45 | } |
olympux | 40:c966abbe2d62 | 46 | |
olympux | 40:c966abbe2d62 | 47 | cmd[0] = '\0'; |
olympux | 40:c966abbe2d62 | 48 | strcat(cmd, "/"); |
olympux | 40:c966abbe2d62 | 49 | strcat(cmd, obj_name); |
olympux | 40:c966abbe2d62 | 50 | strcat(cmd, "/"); |
olympux | 40:c966abbe2d62 | 51 | strcat(cmd, func_name); |
olympux | 40:c966abbe2d62 | 52 | |
olympux | 40:c966abbe2d62 | 53 | if(tmp == NULL) |
olympux | 40:c966abbe2d62 | 54 | return true; |
olympux | 40:c966abbe2d62 | 55 | |
olympux | 40:c966abbe2d62 | 56 | buffer = tmp+1; |
olympux | 40:c966abbe2d62 | 57 | do |
olympux | 40:c966abbe2d62 | 58 | { |
olympux | 40:c966abbe2d62 | 59 | tmp = strchr(buffer, '&'); |
olympux | 40:c966abbe2d62 | 60 | |
olympux | 40:c966abbe2d62 | 61 | if(tmp != NULL) |
olympux | 40:c966abbe2d62 | 62 | { |
olympux | 40:c966abbe2d62 | 63 | if(tmp[1] == '\0' || buffer == tmp) |
olympux | 40:c966abbe2d62 | 64 | return false; |
olympux | 40:c966abbe2d62 | 65 | tmp[0] = '\0'; |
olympux | 40:c966abbe2d62 | 66 | } |
olympux | 40:c966abbe2d62 | 67 | |
olympux | 40:c966abbe2d62 | 68 | char *sep = strchr(buffer, '='); |
olympux | 40:c966abbe2d62 | 69 | if(sep == NULL) |
olympux | 40:c966abbe2d62 | 70 | return false; |
olympux | 40:c966abbe2d62 | 71 | if(sep == buffer) |
olympux | 40:c966abbe2d62 | 72 | return false; |
olympux | 40:c966abbe2d62 | 73 | if(sep[1] == '\0' || sep[1] == '&') |
olympux | 40:c966abbe2d62 | 74 | return false; |
olympux | 40:c966abbe2d62 | 75 | |
olympux | 40:c966abbe2d62 | 76 | strcat(cmd, " "); |
olympux | 40:c966abbe2d62 | 77 | strcat(cmd, sep+1); |
olympux | 40:c966abbe2d62 | 78 | |
olympux | 40:c966abbe2d62 | 79 | if(tmp != NULL) |
olympux | 40:c966abbe2d62 | 80 | buffer = tmp+1; |
olympux | 40:c966abbe2d62 | 81 | else |
olympux | 40:c966abbe2d62 | 82 | buffer = NULL; |
olympux | 40:c966abbe2d62 | 83 | }while(buffer); |
olympux | 40:c966abbe2d62 | 84 | |
olympux | 40:c966abbe2d62 | 85 | return true; |
olympux | 40:c966abbe2d62 | 86 | } |
olympux | 40:c966abbe2d62 | 87 | |
olympux | 40:c966abbe2d62 | 88 | |
olympux | 40:c966abbe2d62 | 89 | |
olympux | 40:c966abbe2d62 | 90 | char* RPCCommand::get_cmd() const |
olympux | 40:c966abbe2d62 | 91 | { |
olympux | 40:c966abbe2d62 | 92 | return (char*)cmd; |
olympux | 40:c966abbe2d62 | 93 | } |
olympux | 40:c966abbe2d62 | 94 | |
olympux | 40:c966abbe2d62 | 95 | RPC_COMMAND_TYPE RPCCommand::get_type() const |
olympux | 40:c966abbe2d62 | 96 | { |
olympux | 40:c966abbe2d62 | 97 | if(!strcmp(func_name, "new") && RPCType::instance().is_supported_type(obj_name)) |
olympux | 40:c966abbe2d62 | 98 | return CREATE; |
olympux | 40:c966abbe2d62 | 99 | |
olympux | 40:c966abbe2d62 | 100 | RPC* r = RPC::lookup(obj_name); |
olympux | 40:c966abbe2d62 | 101 | if(r == NULL) |
olympux | 40:c966abbe2d62 | 102 | return INVALID; |
olympux | 40:c966abbe2d62 | 103 | |
olympux | 40:c966abbe2d62 | 104 | if(!strcmp(func_name, "delete")) |
olympux | 40:c966abbe2d62 | 105 | return DELETE; |
olympux | 40:c966abbe2d62 | 106 | |
olympux | 40:c966abbe2d62 | 107 | const struct rpc_method *methods = r->get_rpc_methods(); |
olympux | 40:c966abbe2d62 | 108 | int i = 0; |
olympux | 40:c966abbe2d62 | 109 | while(methods[i].name != NULL) |
olympux | 40:c966abbe2d62 | 110 | { |
olympux | 40:c966abbe2d62 | 111 | if(!strcmp(func_name, methods[i].name)) |
olympux | 40:c966abbe2d62 | 112 | { |
olympux | 40:c966abbe2d62 | 113 | return FUNCTION_CALL; |
olympux | 40:c966abbe2d62 | 114 | } |
olympux | 40:c966abbe2d62 | 115 | ++i; |
olympux | 40:c966abbe2d62 | 116 | } |
olympux | 40:c966abbe2d62 | 117 | |
olympux | 40:c966abbe2d62 | 118 | return INVALID; |
olympux | 40:c966abbe2d62 | 119 | } |
olympux | 40:c966abbe2d62 | 120 | |
olympux | 40:c966abbe2d62 | 121 | char* RPCCommand::get_obj_name() const |
olympux | 40:c966abbe2d62 | 122 | { |
olympux | 40:c966abbe2d62 | 123 | return obj_name; |
olympux | 40:c966abbe2d62 | 124 | } |
olympux | 40:c966abbe2d62 | 125 | |
olympux | 40:c966abbe2d62 | 126 | char* RPCCommand::get_func_name() const |
olympux | 40:c966abbe2d62 | 127 | { |
olympux | 40:c966abbe2d62 | 128 | return func_name; |
olympux | 40:c966abbe2d62 | 129 | } |
olympux | 40:c966abbe2d62 | 130 |