jf-framework
Loading...
Searching...
No Matches
router.c File Reference
#include <router.h>
#include <http.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Include dependency graph for router.c:

Functions

void jf_RouterDestroy (Router *router)
 Cleans up router object.
uint32_t jf_RouterAdd (Router *router, const char *method, const char *path, route_handler_t handler)
 Adds route to router.
Router * jf_CreateRouter (void)
 Allocates and creates router object.
static size_t jf_RouterNextSegment (const char **path, const char **segment)
static uint32_t jf_RouterMatchSegment (const char *routeSegemnt, size_t routeSegmentLength, const char *requestSegment, size_t requestSegmentLength, HttpRequest *httpRequest)
static uint32_t jf_RouterMatchPath (const Route *route, const char *requestPath, HttpRequest *httpRequest)
static const Route * jf_RouterMatch (Router *router, HttpRequest *httpRequest)
uint32_t jf_RouterDispatch (Router *router, HttpRequest *httpRequest, HttpResponse *httpResponse)
 Handles routes.
uint32_t jf_RouterUse (Router *router, middleware_t middleware)
 Adds middleware to router.

Detailed Description

Author
Avis

Function Documentation

◆ jf_CreateRouter()

Router * jf_CreateRouter ( void )

Allocates and creates router object.

Author
Avis
Returns
Pointer to router, NULL on failure

◆ jf_RouterAdd()

uint32_t jf_RouterAdd ( Router * router,
const char * method,
const char * path,
route_handler_t handler )

Adds route to router.

Author
Avis
Returns
Returns 0 on failure, 1 on success, and 2 if max routes in exceeded

◆ jf_RouterDestroy()

void jf_RouterDestroy ( Router * router)

Cleans up router object.

Author
Avis

◆ jf_RouterDispatch()

uint32_t jf_RouterDispatch ( Router * router,
HttpRequest * httpRequest,
HttpResponse * httpResponse )

Handles routes.

Author
Avis
Returns
Returns 0 on error, 1 on success
Here is the caller graph for this function:

◆ jf_RouterUse()

uint32_t jf_RouterUse ( Router * router,
middleware_t middleware )

Adds middleware to router.

Author
Avis
Returns
0 on failure, 1 on success, 2 if max middleware is exceeded