diff --git a/.gitignore b/.gitignore index c68d06b..215e916 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ src/*.o *.o .cache/ +*swp* diff --git a/include/Routes.h b/include/Routes.h index c7bc2a1..41e29f1 100644 --- a/include/Routes.h +++ b/include/Routes.h @@ -10,7 +10,7 @@ struct Route { struct Route * initRoute(char* key, char* value); -struct Route * addRoute(struct Route * root, char* key, char* value); +void addRoute(struct Route ** root, char* key, char* value); struct Route * search(struct Route * root, char * key); diff --git a/src/Routes.c b/src/Routes.c index 367d3ef..ae0bc2a 100644 --- a/src/Routes.c +++ b/src/Routes.c @@ -23,18 +23,17 @@ void inorder(struct Route* root) } } -struct Route * addRoute(struct Route * root, char* key, char* value) { - if (root == NULL) { - return initRoute(key, value); +void addRoute(struct Route ** root, char* key, char* value) { + if (*root == NULL) { + *root = initRoute(key, value); } - - if (strcmp(key, root->key) == 0) { + else if (strcmp(key, (*root)->key) == 0) { printf("============ WARNING ============\n"); printf("A Route For \"%s\" Already Exists\n", key); - }else if (strcmp(key, root->key) > 0) { - root->right = addRoute(root->right, key, value); + }else if (strcmp(key, (*root)->key) > 0) { + addRoute(&(*root)->right, key, value); }else { - root->left = addRoute(root->left, key, value); + addRoute(&(*root)->left, key, value); } } diff --git a/src/main.c b/src/main.c index 867ae86..720cf4c 100644 --- a/src/main.c +++ b/src/main.c @@ -21,7 +21,9 @@ int main() { // registering Routes struct Route * route = initRoute("/", "index.html"); - addRoute(route, "/about", "about.html"); + addRoute(&route, "/about", "about.html"); + addRoute(&route, "/sth", "sth.html"); + addRoute(&route, "/chicken", "chicken.html"); printf("\n====================================\n"); diff --git a/templates/chicken.html b/templates/chicken.html new file mode 100644 index 0000000..b983bda --- /dev/null +++ b/templates/chicken.html @@ -0,0 +1,9 @@ + + + + Cerveur + + +

chicken page

+ + diff --git a/templates/sth.html b/templates/sth.html new file mode 100644 index 0000000..0da4453 --- /dev/null +++ b/templates/sth.html @@ -0,0 +1,9 @@ + + + + Cerveur + + +

somethin' page

+ +