diff --git a/include/match_entry.h b/include/match_entry.h index 0010dc4..9956dbd 100644 --- a/include/match_entry.h +++ b/include/match_entry.h @@ -8,7 +8,23 @@ #ifndef MATCH_ENTRY_H #define MATCH_ENTRY_H -#include "r3.h" +#include "r3_define.h" +#include "str_array.h" + +typedef struct { + str_array * vars; + const char * path; // current path to dispatch + int path_len; // the length of the current path + int request_method; // current request method + + void * data; // route ptr + + char * host; // the request host + int host_len; + + char * remote_addr; + int remote_addr_len; +} match_entry; match_entry * match_entry_createl(const char * path, int path_len); diff --git a/include/r3.h b/include/r3.h index 9e5a618..f3f689b 100644 --- a/include/r3.h +++ b/include/r3.h @@ -13,37 +13,9 @@ #include #include #include - #include "r3_define.h" - -typedef struct _str_array { - char **tokens; - int len; - int cap; -} str_array; - -str_array * str_array_create(int cap); - -bool str_array_is_full(const str_array * l); - -bool str_array_resize(str_array *l, int new_cap); - -bool str_array_append(str_array * list, char * token); - -void str_array_free(str_array *l); - -void str_array_dump(const str_array *l); - -str_array * split_route_pattern(char *pattern, int pattern_len); - -#define str_array_fetch(t,i) t->tokens[i] -#define str_array_len(t) t->len -#define str_array_cap(t) t->cap - - -#define node_edge_pattern(node,i) node->edges[i]->pattern -#define node_edge_pattern_len(node,i) node->edges[i]->pattern_len - +#include "str_array.h" +#include "match_entry.h" struct _edge; struct _node; @@ -86,6 +58,9 @@ struct _node { void * data; }; +#define node_edge_pattern(node,i) node->edges[i]->pattern +#define node_edge_pattern_len(node,i) node->edges[i]->pattern_len + struct _edge { char * pattern; node * child; @@ -94,21 +69,6 @@ struct _edge { unsigned char has_slug; // 1 bit }; -typedef struct { - str_array * vars; - const char * path; // current path to dispatch - int path_len; // the length of the current path - int request_method; // current request method - - void * data; // route ptr - - char * host; // the request host - int host_len; - - char * remote_addr; - int remote_addr_len; -} match_entry; - struct _route { char * path; int path_len; diff --git a/include/str_array.h b/include/str_array.h new file mode 100644 index 0000000..1414834 --- /dev/null +++ b/include/str_array.h @@ -0,0 +1,35 @@ +/* + * str_array.h + * Copyright (C) 2014 c9s + * + * Distributed under terms of the MIT license. + */ + +#ifndef STR_ARRAY_H +#define STR_ARRAY_H + +typedef struct _str_array { + char **tokens; + int len; + int cap; +} str_array; + +str_array * str_array_create(int cap); + +bool str_array_is_full(const str_array * l); + +bool str_array_resize(str_array *l, int new_cap); + +bool str_array_append(str_array * list, char * token); + +void str_array_free(str_array *l); + +void str_array_dump(const str_array *l); + +str_array * split_route_pattern(char *pattern, int pattern_len); + +#define str_array_fetch(t,i) t->tokens[i] +#define str_array_len(t) t->len +#define str_array_cap(t) t->cap + +#endif /* !STR_ARRAY_H */ diff --git a/src/token.c b/src/token.c index 1bae646..6f3e980 100644 --- a/src/token.c +++ b/src/token.c @@ -10,6 +10,7 @@ #include #include "r3.h" #include "r3_str.h" +#include "str_array.h" #include "zmalloc.h" str_array * str_array_create(int cap) {