REST processing fixed in server. Major packet handling bug found.

This commit is contained in:
Scott Duensing 2022-01-12 20:40:46 -06:00
parent 41a45260c4
commit d7dcd43c5f
7 changed files with 22 additions and 13 deletions

View file

@ -257,6 +257,9 @@ int main(int argc, char *argv[]) {
__runtimeData.strings = NULL;
__runtimeData.protocolVersion = 0;
sh_new_strdup(__runtimeData.integers);
sh_new_strdup(__runtimeData.strings);
//taskCreate(taskComDebugLoop, NULL);
taskCreate(taskWelcome, NULL);
taskCreate(taskGuiEventLoop, NULL);

View file

@ -183,7 +183,6 @@ static void taskConnectClick(void *data) {
case PACKET_TYPE_VERSION:
__runtimeData.protocolVersion = *(uint32_t *)decoded->data;
packetDecodeDataDestroy(&decoded);
// Do we need to update?
if (PACKET_PROTOCOL_VERSION == __runtimeData.protocolVersion) {
// Nope, we're good.
@ -207,6 +206,7 @@ static void taskConnectClick(void *data) {
logWrite("Unexpected packet received: %d\n", decoded->packetType);
break;
}
packetDecodeDataDestroy(&decoded);
}
taskYield();
if (__timerSecondTick) timeout--;

View file

@ -76,8 +76,8 @@ class KwConfig {
if (V::minlength($input['data'], 1) === false) {
throw new InvalidArgumentException('The data must not be empty');
}
if (V::maxlength($input['data'], 4096) === false) {
throw new InvalidArgumentException('The data must not be longer than 4096 characters');
if (V::maxlength($input['data'], 1024) === false) {
throw new InvalidArgumentException('The data must not be longer than 1024 characters');
}
if (V::maxlength($input['description'], 255) === false) {

View file

@ -76,8 +76,8 @@ class KwStrings {
if (V::minlength($input['data'], 1) === false) {
throw new InvalidArgumentException('The data must not be empty');
}
if (V::maxlength($input['data'], 4096) === false) {
throw new InvalidArgumentException('The data must not be longer than 4096 characters');
if (V::maxlength($input['data'], 1024) === false) {
throw new InvalidArgumentException('The data must not be longer than 1024 characters');
}
if (V::maxlength($input['description'], 255) === false) {

View file

@ -136,6 +136,7 @@ static void clientProcessPacket(ClientThreadT *client, PacketDecodeDataT *data)
// Send it.
packetSend(client->packetThreadData, &encoded);
DEL(buffer);
//logWrite("[%s] = [%s]\r\n", strings[i].key, strings[i].value);
}
restHelperConfigStringMapRelease(strings);
// Fetch number table from REST.
@ -174,6 +175,7 @@ static void clientProcessPacket(ClientThreadT *client, PacketDecodeDataT *data)
// Send it.
packetSend(client->packetThreadData, &encoded);
DEL(buffer);
//logWrite("[%s] = [%d]\r\n", integers[i].key, integers[i].value);
}
restHelperConfigIntegerMapRelease(integers);
// Build PROCEED packet.

View file

@ -52,7 +52,7 @@ int64_t restHelperConfigIntegerGet(json_object *object, char *name, int64_t defa
json_object *item = NULL;
int64_t result = defaultValue;
config = json_object_object_get(object, "config");
config = json_object_object_get(object, "payload");
if (config) {
data = json_object_object_get(config, "data");
if (data) {
@ -78,7 +78,9 @@ RestIntegerMapT *restHelperConfigIntegerMapGet(json_object *object) {
json_object *item = NULL;
RestIntegerMapT *result = NULL;
config = json_object_object_get(object, "config");
sh_new_strdup(result);
config = json_object_object_get(object, "payload");
if (config) {
data = json_object_object_get(config, "data");
if (data) {
@ -109,7 +111,7 @@ char *restHelperConfigStringGet(json_object *object, char *name, char *defaultVa
json_object *item = NULL;
char *result = strdup(defaultValue);
config = json_object_object_get(object, "config");
config = json_object_object_get(object, "payload");
if (config) {
data = json_object_object_get(config, "data");
if (data) {
@ -136,7 +138,9 @@ RestStringMapT *restHelperConfigStringMapGet(json_object *object) {
json_object *item = NULL;
RestStringMapT *result = NULL;
config = json_object_object_get(object, "config");
sh_new_strdup(result);
config = json_object_object_get(object, "payload");
if (config) {
data = json_object_object_get(config, "data");
if (data) {
@ -208,10 +212,10 @@ json_object *restRequest(char *command, char *format, ...) {
}
va_end(args);
logWrite("Request: %s\n", json_object_to_json_string_ext(request, JSON_C_TO_STRING_PRETTY));
//logWrite("Request: %s\n", json_object_to_json_string_ext(request, JSON_C_TO_STRING_PRETTY));
response = restUrlPost(request);
json_object_put(request);
logWrite("Response: %s\n", json_object_to_json_string_ext(response, JSON_C_TO_STRING_PRETTY));
//logWrite("Response: %s\n", json_object_to_json_string_ext(response, JSON_C_TO_STRING_PRETTY));
if (response) {
if (json_object_get_boolean(json_object_object_get(response, "result")) != TRUE) {

View file

@ -40,8 +40,8 @@
*/
#define PACKET_MAX 1024 // Maximum number of bytes per packet
#define PACKET_SEQUENCE_MAX 16 // Five bits of data, 32 max.
#define PACKET_MAX 1024 // Maximum number of bytes per packet.
#define PACKET_SEQUENCE_MAX 32 // Five bits of data, 32 max. Represents size of replay history. Also maximum number of packets on the wire at a time.
#define PACKET_INPUT_QUEUE_SIZE 4096
#define PACKET_BUFFER_SIZE (PACKET_MAX * 2 + 2 + 8) // Worst case, every byte is a PACKET_FRAME. Add two for ending frame. Add 8 for worst case header and CRC.