diff --git a/src/Routes/RouteMatrix.c b/src/Routes/RouteMatrix.c index ee73835..3a03cf9 100644 --- a/src/Routes/RouteMatrix.c +++ b/src/Routes/RouteMatrix.c @@ -34,9 +34,9 @@ ROUTE(RouteMatrix) HashMap *response = NULL; char *pathPart = MATRIX_PATH_POP(path); - (void) args; + (void) args; - if (!MATRIX_PATH_EQUALS(pathPart, "client") || ArraySize(path) != 1) + if (!MATRIX_PATH_EQUALS(pathPart, "client") || MATRIX_PATH_PARTS(path) != 1) { free(pathPart); HttpResponseStatus(context, HTTP_NOT_FOUND); @@ -48,11 +48,11 @@ ROUTE(RouteMatrix) if (MATRIX_PATH_EQUALS(pathPart, "versions")) { - Array *versions = ArrayCreate(); + Array *versions = ArrayCreate(); free(pathPart); - ArrayAdd(versions, JsonValueString(UtilStringDuplicate("v1.4"))); + ArrayAdd(versions, JsonValueString(UtilStringDuplicate("v1.4"))); response = HashMapCreate(); HashMapSet(response, "versions", JsonValueArray(versions)); diff --git a/src/Routes/RouteWellKnown.c b/src/Routes/RouteWellKnown.c index 1130f5a..3aab938 100644 --- a/src/Routes/RouteWellKnown.c +++ b/src/Routes/RouteWellKnown.c @@ -34,7 +34,7 @@ ROUTE(RouteWellKnown) HashMap *response = NULL; char *pathPart = MATRIX_PATH_POP(path); - if (!MATRIX_PATH_EQUALS(pathPart, "matrix") || ArraySize(path) != 1) + if (!MATRIX_PATH_EQUALS(pathPart, "matrix") || MATRIX_PATH_PARTS(path) != 1) { free(pathPart); HttpResponseStatus(context, HTTP_NOT_FOUND); diff --git a/src/include/Matrix.h b/src/include/Matrix.h index af8804c..f969696 100644 --- a/src/include/Matrix.h +++ b/src/include/Matrix.h @@ -30,8 +30,19 @@ #include -#define MATRIX_PATH_POP(arr) ArrayDelete(arr, 0) - +/* + * Abstract away the underlying data structure of the path so that + * routes don't have to care what it is. + * + * This will be helpful, for instance, if we decide to switch to a + * queue (which can be easily done with the current implementation if + * we just add a function that computes how many elements are in a + * queue.) An array isn't the most efficient data structure for this + * purpose; a queue would be much better. This allows us to change that + * down the road without having to rewrite all the routes. + */ +#define MATRIX_PATH_POP(path) ArrayDelete(path, 0) +#define MATRIX_PATH_PARTS(path) ArraySize(path) #define MATRIX_PATH_EQUALS(pathPart, str) ((pathPart != NULL) && (strcmp(pathPart, str) == 0)) typedef enum MatrixError