fix errors reading and writing universe

This commit is contained in:
Iris Lightshard 2021-07-27 23:50:16 -06:00
parent 150b8ae529
commit 41c96c5127
Signed by: Iris Lightshard
GPG key ID: 3B7FBC22144E6398
4 changed files with 29 additions and 21 deletions

10
realm.c
View file

@ -55,9 +55,9 @@ Realm* create_realm(UserInfo* table, char* uname, char* name) {
Realm* parse_realm(char* cart, char* name) {
Realm* self;
FILE* f;
char path[128];
char file[128];
char buf[256];
char path[128] = {0};
char file[128] = {0};
char buf[256] = {0};
scat(path, "carts/");
scat(path, cart);
scat(path, "/realms/");
@ -65,6 +65,8 @@ Realm* parse_realm(char* cart, char* name) {
scpy(path, file, 128);
scat(file, "/realm");
fprintf(stderr, "realm path: %s\n", file);
f = fopen(file, "r");
if (f != nil) {
if (fgets(buf, 256, f)) {
@ -85,7 +87,7 @@ Realm* parse_realm(char* cart, char* name) {
scpy(path, file, 128);
scat(file, "/universe");
self->universe = parse_universe(path);
self->universe = parse_universe(cart, name);
return self;
}

View file

@ -13,7 +13,7 @@ Universe* create_universe() {
return self;
}
Universe* parse_universe(char* realm_name) {
Universe* parse_universe(char* cart, char* realm_name) {
char path[64] = {0};
char buf[256] = {0};
char name[16] = {0};
@ -22,9 +22,12 @@ Universe* parse_universe(char* realm_name) {
Atom* a;
Universe* self;
scat(path, "realms/");
scat(path, "carts/");
scat(path, cart);
scat(path, "/realms/");
scat(path, realm_name);
scat(path, "/universe");
fprintf(stderr, "universe path: %s\n", path);
f = fopen(path, "r");
if (f != nil) {

View file

@ -13,7 +13,7 @@ typedef struct Universe {
} Universe;
Universe* create_universe();
Universe* parse_universe(char* realm_name);
Universe* parse_universe(char* cart, char* realm_name);
void save_universe(char* cart, Universe* self, char* realm_name);
void set_atom(Universe* self, Atom* atom);
Atom* get_atom(Universe* self, char* name);

31
xrxs.c
View file

@ -116,19 +116,23 @@ void write_universe(Req* r) {
char key[16] = {0};
char value[64] = {0};
char* c = r->ifcall.data;
char buffer[1024] = {0};
UserInfo* u = find_user(users_table, r->fid->uid);
Atom* a;
int i;
for (i = 0; i < 15 && i < r->ifcall.count && *c != ' ' && *c != '\n'; i++) {
ccat(key, *c++);
}
c++;
c++;
for (i = 0; i < 63 && i < r->ifcall.count && *c != ' ' && *c != '\n'; i++) {
ccat(value, *c++);
}
scpy(r->ifcall.data, buffer, r->ifcall.count);
sscanf(buffer, "%15s = %63s", key, value);
/* for (i = 0; i < 15 && i < r->ifcall.count && *c != ' ' && *c != '\n'; i++)
{ ccat(key, *c++);
}
c++;
c++;
for (i = 0; i < 63 && i < r->ifcall.count && *c != ' ' && *c != '\n'; i++) {
ccat(value, *c++);
}
*/
if (u != nil && u->realm != nil && u->realm->universe != nil) {
a = get_atom(u->realm->universe, key);
if (a != nil) {
@ -217,7 +221,7 @@ String** list_dir(char* path) {
char* c;
if ((dir = opendir(path)) != NULL) {
while ((ent = readdir(dir)) != NULL) {
if (i = size) {
if (i == size) {
size *= 2;
self = realloc(self, size * sizeof(String*));
}
@ -239,12 +243,9 @@ String** list_dir(char* path) {
}
void s_freemany(String** ss) {
int i;
String** s = ss;
for (i = 0; i < 128; i++) {
if (*s != nil) {
s_free(*s);
}
while (*s != nil) {
s_free(*s++);
}
free(ss);
}
@ -362,12 +363,14 @@ void read_universe(Req* r) {
int i;
if (u == nil || u->realm == nil) {
fprintf(stderr, "realm nil, wtf\n");
respond(r, nil);
return;
}
universe = u->realm->universe;
if (universe == nil) {
fprintf(stderr, "no universe, oh noes!!\n");
respond(r, ENOUNI);
return;
}