2014-05-14 22:10:34 -04:00
|
|
|
/*
|
|
|
|
* node.h
|
|
|
|
* Copyright (C) 2014 c9s <c9s@c9smba.local>
|
|
|
|
*
|
|
|
|
* Distributed under terms of the MIT license.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef NODE_H
|
|
|
|
#define NODE_H
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
2014-05-16 02:05:51 -04:00
|
|
|
#include <pcre.h>
|
2014-05-14 22:10:34 -04:00
|
|
|
|
2014-05-15 01:39:50 -04:00
|
|
|
#include "token.h"
|
|
|
|
|
2014-05-16 03:29:25 -04:00
|
|
|
struct _edge;
|
|
|
|
struct _node;
|
|
|
|
typedef struct _edge edge;
|
|
|
|
typedef struct _node node;
|
2014-05-15 01:39:50 -04:00
|
|
|
|
2014-05-16 03:29:25 -04:00
|
|
|
struct _node {
|
|
|
|
edge ** edges;
|
2014-05-16 02:05:51 -04:00
|
|
|
int edge_len;
|
|
|
|
int edge_cap;
|
|
|
|
|
|
|
|
/* the combined regexp pattern string from pattern_tokens */
|
|
|
|
char * combined_pattern;
|
|
|
|
int combined_pattern_len;
|
|
|
|
pcre * pcre_pattern;
|
2014-05-16 03:29:25 -04:00
|
|
|
pcre_extra * pcre_extra;
|
2014-05-16 02:05:51 -04:00
|
|
|
|
2014-05-16 03:29:25 -04:00
|
|
|
/**
|
|
|
|
* the pointer of route structure
|
|
|
|
*/
|
|
|
|
void * route_ptr;
|
|
|
|
|
2014-05-16 02:05:51 -04:00
|
|
|
int endpoint;
|
|
|
|
};
|
|
|
|
|
2014-05-16 03:29:25 -04:00
|
|
|
struct _edge {
|
2014-05-16 02:05:51 -04:00
|
|
|
char * pattern;
|
|
|
|
int pattern_len;
|
|
|
|
bool has_slug;
|
2014-05-16 03:29:25 -04:00
|
|
|
node * child;
|
2014-05-16 02:05:51 -04:00
|
|
|
};
|
|
|
|
|
2014-05-16 06:03:52 -04:00
|
|
|
typedef struct {
|
|
|
|
char ** vars;
|
|
|
|
int vars_len;
|
|
|
|
char * path; // dispatched path
|
|
|
|
void * route_ptr; // route ptr
|
|
|
|
} match_entry;
|
2014-05-15 01:39:50 -04:00
|
|
|
|
|
|
|
|
2014-05-16 03:29:25 -04:00
|
|
|
node * rtree_create(int cap);
|
|
|
|
|
|
|
|
node * node_create();
|
2014-05-15 01:39:50 -04:00
|
|
|
|
2014-05-16 03:29:25 -04:00
|
|
|
void rtree_free(node * tree);
|
2014-05-15 01:39:50 -04:00
|
|
|
|
2014-05-16 03:29:25 -04:00
|
|
|
void edge_free(edge * edge);
|
2014-05-15 01:39:50 -04:00
|
|
|
|
2014-05-16 03:29:25 -04:00
|
|
|
edge * rtree_add_child(node * n, char * pat , node *child);
|
2014-05-15 01:39:50 -04:00
|
|
|
|
2014-05-16 03:29:25 -04:00
|
|
|
edge * node_find_edge(node * n, char * pat);
|
2014-05-15 01:39:50 -04:00
|
|
|
|
2014-05-16 03:29:25 -04:00
|
|
|
void rtree_append_edge(node *n, edge *child);
|
2014-05-15 01:39:50 -04:00
|
|
|
|
2014-05-16 03:29:25 -04:00
|
|
|
node * rtree_insert_path(node *tree, char *route, void * route_ptr);
|
2014-05-15 06:26:41 -04:00
|
|
|
|
2014-05-16 03:29:25 -04:00
|
|
|
node * rtree_insert_pathn(node *tree, char *route, int route_len, void * route_ptr);
|
2014-05-15 06:26:41 -04:00
|
|
|
|
2014-05-16 03:29:25 -04:00
|
|
|
void rtree_dump(node * n, int level);
|
2014-05-15 01:39:50 -04:00
|
|
|
|
2014-05-16 03:29:25 -04:00
|
|
|
edge * node_find_edge_str(node * n, char * str, int str_len);
|
2014-05-16 02:05:51 -04:00
|
|
|
|
|
|
|
|
2014-05-16 03:29:25 -04:00
|
|
|
void rtree_compile(node *n);
|
2014-05-16 02:05:51 -04:00
|
|
|
|
2014-05-16 03:29:25 -04:00
|
|
|
void rtree_compile_patterns(node * n);
|
2014-05-16 02:05:51 -04:00
|
|
|
|
2014-05-16 06:03:52 -04:00
|
|
|
node * rtree_match(node * n, char * path, int path_len, match_entry * entry);
|
2014-05-15 09:17:30 -04:00
|
|
|
|
2014-05-16 03:29:25 -04:00
|
|
|
bool node_has_slug_edges(node *n);
|
2014-05-16 00:33:59 -04:00
|
|
|
|
2014-05-16 03:29:25 -04:00
|
|
|
node * rtree_lookup(node * tree, char * path, int path_len);
|
2014-05-15 06:28:33 -04:00
|
|
|
|
2014-05-16 03:29:25 -04:00
|
|
|
edge * edge_create(char * pattern, int pattern_len, node * child);
|
2014-05-14 22:10:34 -04:00
|
|
|
|
2014-05-16 03:29:25 -04:00
|
|
|
void edge_branch(edge *e, int dl);
|
2014-05-15 11:46:49 -04:00
|
|
|
|
2014-05-16 03:29:25 -04:00
|
|
|
void edge_free(edge * edge);
|
2014-05-14 22:10:34 -04:00
|
|
|
|
2014-05-16 06:03:52 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
2014-05-14 22:10:34 -04:00
|
|
|
#endif /* !NODE_H */
|