C Collections

chttpserver · Section 3

chttpsvr_router_register_handler

chttpsvr_router_register_handler - register a buffered handler on a sub-router

C Collections (libccollections, -lccollections)

#include <ccollections/chttpserver.h>
 
ccol_retval chttpsvr_router_register_handler(chttpsvr_router *router,
                                  chttp_method method,
                                  const char *pattern,
                                  chttpsvr_handler_fn fn, void *ctx);

The same as chttpsvr_register_handler, except that the route goes on
a sub-router.  All the rules of chttpsvr_register_handler apply here
too: Routing, the leading slash, a trailing slash, two consecutive
slashes, the characters of a parameter name, a parameter name that
appears twice, and thread safety.  CHTTP_ANY works as the method
argument as well.
 
The function first checks that the server that owns router has not
been destroyed.  That check also holds against a destroy running on
another thread at the same time: A call that races a chttpsvr_destroy
of the owning server returns ccol_invalid_args and touches no freed
memory.

ccol_success on success.
ccol_invalid_args when router, pattern or fn is NULL; when method is
                  not one of the seven methods or CHTTP_ANY; when
                  pattern does not start with '/'; when pattern has two
                  consecutive slashes or a trailing slash; when a
                  {name} segment contains a character outside
                  [A-Za-z0-9_]; when the same {name} appears more than
                  once; or when the server that owns router has been
                  destroyed.
ccol_not_enough_memory when an allocation fails.

chttpsvr_register_handler(3), chttpsvr_subrouter(3), chttpsvr_router_use(3)