From c7220c5616abdaaebd4ec688b66a7556e172abac Mon Sep 17 00:00:00 2001 From: c9s Date: Tue, 3 Jun 2014 22:07:46 +0800 Subject: [PATCH] combine match_entry functions into r3.h --- include/match_entry.h | 43 ------------------------------------------- include/r3.h | 38 ++++++++++++++++++++++++++++++++++---- src/match_entry.c | 2 -- 3 files changed, 34 insertions(+), 49 deletions(-) delete mode 100644 include/match_entry.h diff --git a/include/match_entry.h b/include/match_entry.h deleted file mode 100644 index bda1dd3..0000000 --- a/include/match_entry.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * match_entry.h - * Copyright (C) 2014 c9s - * - * Distributed under terms of the MIT license. - */ - -#ifndef MATCH_ENTRY_H -#define MATCH_ENTRY_H - -#include "r3_define.h" -#include "str_array.h" - -#ifdef __cplusplus -extern "C" { -#endif - -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); - -#define match_entry_create(path) match_entry_createl(path,strlen(path)) - -void match_entry_free(match_entry * entry); - -#ifdef __cplusplus -} -#endif - -#endif /* !MATCH_ENTRY_H */ diff --git a/include/r3.h b/include/r3.h index 26a5352..4e7dbe0 100644 --- a/include/r3.h +++ b/include/r3.h @@ -14,9 +14,6 @@ #include #include "r3_define.h" #include "str_array.h" -#include "match_entry.h" - - #ifdef __cplusplus extern "C" { @@ -88,6 +85,27 @@ struct _route { int remote_addr_pattern_len; }; +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; + + + + + + + node * r3_tree_create(int cap); @@ -153,12 +171,13 @@ route * r3_route_create(const char * path); route * r3_route_createl(const char * path, int path_len); -int r3_route_cmp(const route *r1, const match_entry *r2); void r3_node_append_route(node * n, route * route); void r3_route_free(route * route); +int r3_route_cmp(const route *r1, const match_entry *r2); + route * r3_tree_match_route(const node *n, match_entry * entry); #define METHOD_GET 2 @@ -177,6 +196,17 @@ enum { NODE_COMPARE_STR, NODE_COMPARE_PCRE, NODE_COMPARE_OPCODE }; enum { OP_EXPECT_MORE_DIGITS = 1, OP_EXPECT_MORE_WORDS, OP_EXPECT_NOSLASH, OP_EXPECT_NODASH, OP_EXPECT_MORE_ALPHA }; + + +match_entry * match_entry_createl(const char * path, int path_len); + +#define match_entry_create(path) match_entry_createl(path,strlen(path)) + +void match_entry_free(match_entry * entry); + + + + #ifdef __cplusplus } #endif diff --git a/src/match_entry.c b/src/match_entry.c index a3b4fa5..035725a 100644 --- a/src/match_entry.c +++ b/src/match_entry.c @@ -13,8 +13,6 @@ #include "r3.h" #include "zmalloc.h" -#include "match_entry.h" - match_entry * match_entry_createl(const char * path, int path_len) { match_entry * entry = zmalloc(sizeof(match_entry));