Simple example showing how to access the path segments of the router feature.
#include <stdlib.h>
#include <stdio.h>
static int segments_iter_cb(__SG_UNUSED void *cls, unsigned int index,
const char *segment) {
fprintf(stdout, " %d: %s\n", index, segment);
return 0;
}
static void route_cb(
void *cls,
struct sg_route *route) {
fprintf(stdout,
"%s: %s\n",
sg_route_path(route), (
const char *) cls);
}
int main(void) {
sg_routes_add(&routes,
"/bar/([a-zA-Z]+)/([0-9]+)", route_cb,
"bar-data");
fprintf(stdout, "---\n");
fflush(stdout);
return EXIT_SUCCESS;
}
int sg_router_dispatch(struct sg_router *router, const char *path, void *user_data)
int sg_routes_cleanup(struct sg_route **routes)
const char * sg_route_path(struct sg_route *route)
struct sg_router * sg_router_new(struct sg_route *routes) __attribute__((malloc))
bool sg_routes_add(struct sg_route **routes, const char *pattern, sg_route_cb cb, void *cls)
void sg_router_free(struct sg_router *router)
int sg_route_segments_iter(struct sg_route *route, sg_segments_iter_cb cb, void *cls)