httpc
Loading...
Searching...
No Matches
tree.h
Go to the documentation of this file.
1
4
5#ifndef URI_TREE
6#define URI_TREE
7
8#include "request_parser.h"
9#include "response.h"
10typedef void (*callback_t)(request, response*);
11
36typedef struct node {
38 char* val;
40 struct node* children;
42 struct node* siblings;
44 callback_t callback;
46
52node* find_node_by_val(node* n, char* val);
57node* trace_tree(char route[], node* origin_node);
61node* trace_tree_exact(char route[], node* root);
65void destroy_tree(node* n);
69void print_tree(node* n, int level);
70#endif
Definition tree.h:36
struct node * children
All nodes, whose routes include this node's val in their fsegment.
Definition tree.h:40
struct node * siblings
All nodes, whose routes include this node's, parent's, val in their fsegment.
Definition tree.h:42
callback_t callback
The function that will be ran when a request comes.
Definition tree.h:44
char * val
a URI fsegment
Definition tree.h:38
Definition request_parser.h:11
Definition response.h:12
node * find_node_by_val(node *n, char *val)
gets the node that matches a given val in a DFS manner
Definition tree.c:17
node * trace_tree_exact(char route[], node *root)
returns the node of the last segment in the URI. If a complete trace isn't found, return null.
Definition tree.c:55
void destroy_tree(node *n)
Given a root node, deallocate the entire tree.
Definition tree.c:73
void print_tree(node *n, int level)
Given a root node, print the entire tree in a DFS manner, along with the level of each node.
Definition tree.c:88
node * trace_tree(char route[], node *origin_node)
given a route, return the deepest node that exists in the tree that satisfies the route
Definition tree.c:33