diff --git a/realm.c b/realm.c index 8e3ae2a..d66c269 100644 --- a/realm.c +++ b/realm.c @@ -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; } diff --git a/universe.c b/universe.c index bd60f4f..4ffb1ec 100644 --- a/universe.c +++ b/universe.c @@ -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) { diff --git a/universe.h b/universe.h index 9d0a4d0..2bee2da 100644 --- a/universe.h +++ b/universe.h @@ -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); diff --git a/xrxs.c b/xrxs.c index 595d2a7..2ea0ea8 100644 --- a/xrxs.c +++ b/xrxs.c @@ -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; }