forked from Telodendria/Telodendria
Abstract the data structure out of the path handling logic.
This commit is contained in:
parent
90166882b0
commit
271cdd8ff0
3 changed files with 18 additions and 7 deletions
|
@ -36,7 +36,7 @@ ROUTE(RouteMatrix)
|
|||
|
||||
(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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -30,8 +30,19 @@
|
|||
|
||||
#include <TelodendriaConfig.h>
|
||||
|
||||
#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
|
||||
|
|
Loading…
Reference in a new issue