combine match_entry functions into r3.h

This commit is contained in:
c9s 2014-06-03 22:07:46 +08:00
parent bad59e99be
commit c7220c5616
3 changed files with 34 additions and 49 deletions

View file

@ -1,43 +0,0 @@
/*
* match_entry.h
* Copyright (C) 2014 c9s <c9s@c9smba.local>
*
* 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 */

View file

@ -14,9 +14,6 @@
#include <stdbool.h>
#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

View file

@ -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));