r3/include/node.h

88 lines
1.6 KiB
C
Raw Normal View History

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-15 06:02:10 -04:00
struct _redge;
struct _rnode;
typedef struct _redge redge;
2014-05-15 01:39:50 -04:00
typedef struct _rnode rnode;
2014-05-16 02:05:51 -04:00
struct _rnode {
redge ** edges;
int edge_len;
int edge_cap;
/* the combined regexp pattern string from pattern_tokens */
char * combined_pattern;
int combined_pattern_len;
pcre * pcre_pattern;
int endpoint;
};
struct _redge {
char * pattern;
int pattern_len;
bool has_slug;
rnode * child;
};
2014-05-15 01:39:50 -04:00
rnode * rnode_create(int cap);
void rnode_free(rnode * tree);
2014-05-15 06:02:10 -04:00
void redge_free(redge * edge);
2014-05-15 01:39:50 -04:00
2014-05-15 10:57:13 -04:00
redge * rnode_add_child(rnode * n, char * pat , rnode *child);
2014-05-15 01:39:50 -04:00
2014-05-15 06:02:10 -04:00
redge * rnode_find_edge(rnode * n, char * pat);
2014-05-15 01:39:50 -04:00
2014-05-15 06:02:10 -04:00
void rnode_append_edge(rnode *n, redge *child);
2014-05-15 01:39:50 -04:00
2014-05-15 06:02:10 -04:00
rnode * rnode_insert_tokens(rnode * tree, token_array * tokens);
2014-05-15 01:39:50 -04:00
2014-05-15 06:26:41 -04:00
rnode * rnode_insert_route(rnode *tree, char *route);
rnode * rnode_insert_routel(rnode *tree, char *route, int route_len);
2014-05-15 06:02:10 -04:00
void rnode_dump(rnode * n, int level);
2014-05-15 01:39:50 -04:00
2014-05-16 02:05:51 -04:00
redge * rnode_find_edge_str(rnode * n, char * str, int str_len);
void rnode_compile(rnode *n);
void rnode_compile_patterns(rnode * n);
rnode * rnode_match(rnode * n, char * path, int path_len);
2014-05-15 09:17:30 -04:00
2014-05-16 00:33:59 -04:00
bool rnode_has_slug_edges(rnode *n);
2014-05-15 06:28:33 -04:00
rnode * rnode_lookup(rnode * tree, char * path, int path_len);
2014-05-15 06:02:10 -04:00
redge * redge_create(char * pattern, int pattern_len, rnode * child);
2014-05-14 22:10:34 -04:00
void redge_branch(redge *e, int dl);
2014-05-15 06:02:10 -04:00
void redge_free(redge * edge);
2014-05-14 22:10:34 -04:00
#endif /* !NODE_H */