separate header files
This commit is contained in:
parent
9cb2f80e1f
commit
072c72621c
4 changed files with 58 additions and 46 deletions
|
@ -8,7 +8,23 @@
|
||||||
#ifndef MATCH_ENTRY_H
|
#ifndef MATCH_ENTRY_H
|
||||||
#define 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);
|
match_entry * match_entry_createl(const char * path, int path_len);
|
||||||
|
|
||||||
|
|
50
include/r3.h
50
include/r3.h
|
@ -13,37 +13,9 @@
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <pcre.h>
|
#include <pcre.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
#include "r3_define.h"
|
#include "r3_define.h"
|
||||||
|
#include "str_array.h"
|
||||||
typedef struct _str_array {
|
#include "match_entry.h"
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
struct _edge;
|
struct _edge;
|
||||||
struct _node;
|
struct _node;
|
||||||
|
@ -86,6 +58,9 @@ struct _node {
|
||||||
void * data;
|
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 {
|
struct _edge {
|
||||||
char * pattern;
|
char * pattern;
|
||||||
node * child;
|
node * child;
|
||||||
|
@ -94,21 +69,6 @@ struct _edge {
|
||||||
unsigned char has_slug; // 1 bit
|
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 {
|
struct _route {
|
||||||
char * path;
|
char * path;
|
||||||
int path_len;
|
int path_len;
|
||||||
|
|
35
include/str_array.h
Normal file
35
include/str_array.h
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
/*
|
||||||
|
* str_array.h
|
||||||
|
* Copyright (C) 2014 c9s <c9s@c9smba.local>
|
||||||
|
*
|
||||||
|
* 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 */
|
|
@ -10,6 +10,7 @@
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include "r3.h"
|
#include "r3.h"
|
||||||
#include "r3_str.h"
|
#include "r3_str.h"
|
||||||
|
#include "str_array.h"
|
||||||
#include "zmalloc.h"
|
#include "zmalloc.h"
|
||||||
|
|
||||||
str_array * str_array_create(int cap) {
|
str_array * str_array_create(int cap) {
|
||||||
|
|
Loading…
Reference in a new issue