Modify sandia code to use the library

This commit is contained in:
nezbednik 2023-08-28 13:00:28 +02:00
parent 086116422f
commit c85a69fa93
4 changed files with 14 additions and 37 deletions

3
.gitmodules vendored
View File

@ -1,3 +0,0 @@
[submodule "source/sandia"]
path = source/sandia
url = https://git.donut.eu.org/libreshop/sandia-Wii.git

View File

@ -33,7 +33,7 @@ LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map
#---------------------------------------------------------------------------------
# any extra libraries we wish to link with the project
#---------------------------------------------------------------------------------
LIBS := -lwiiuse -lbte -logc -lm -ljansson
LIBS := -lwiiuse -lbte -logc -lm -lsandia -ljansson
#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing

View File

@ -5,8 +5,7 @@
#include <wiiuse/wpad.h>
#include <jansson.h>
#include <stdbool.h>
#include "sandia/sandia.h"
#include <sandia.h>
#include "input_macros.h"
@ -90,38 +89,20 @@ int main(int argc, char **argv) {
printf("%s.\n", localip);
sandia req = sandia_create("libreshop.donut.eu.org", 80);
sandia_response res = sandia_get_request(&req, "/");
bool lastWasNewline = false;
int resBodyLength = strlen(res.body);
for (int i = 0; i < resBodyLength; i++) {
if (res.body[i] == '\r') continue;
sandia_response res = sandia_get_request(&req, "/", true, true);
if (res.body[i] == '\n') {
if (lastWasNewline) {
int rBL = resBodyLength - i;
char* body = malloc(rBL);
for (int j = 0; j < rBL; j++) {
body[j] = res.body[j + i + 1];
}
json_error_t error;
json_t *root = json_loads(res.body, 0, &error);
json_error_t error;
json_t *root = json_loads(body, 0, &error);
if (!root || !json_is_array(root)) {
printf("failed decoding\n");
}
else {
printf("%s\n", body);
for (int j = 0; j < json_array_size(root); j++) {
json_t *data = json_array_get(root, j);
printf("%s\n", json_string_value(data));
}
}
break;
}
else lastWasNewline = true;
if (!root || !json_is_array(root)) {
printf("failed decoding\n");
}
else {
printf("%s\n", res.body);
for (int j = 0; j < json_array_size(root); j++) {
json_t *data = json_array_get(root, j);
printf("%s\n", json_string_value(data));
}
else lastWasNewline = false;
}
printf("\n");
sandia_close(&req);

@ -1 +0,0 @@
Subproject commit 8f4d62429b06bb851f03c21c7796ae69f78541a8