HANDLER_ADD(3)

NAME
handler_add - add an endpoint to a web server handler object

SYNOPSIS

#include <slweb/handler.h>

int handler_add(struct handler *h, const char *url, enum http_op op, handler_fn f, void *user);

DESCRIPTION
The handler_add() function adds an endpoint to a struct handler object previously allocated by handler_alloc(3), pointed to by h. url is a null-terminated string that defines the target resource. The metacharacter * can be used to match any number of characters. For example, /user/*/file shall match resources such as /user/alice/file or /user/bob/nested/file. op describes the HTTP/1.1 operation supported by the endpoint. See the definition for enum http_op for an exhaustive list of supported operations. f is a function pointer that shall be executed by slweb if an incoming request matches the resource and operation defined by url and op, respectively. See slweb_handler(7) for the definition for handler_fn. user is an opaque pointer to a user-defined object that shall be passed to the function pointed to by f. user can be a null pointer.

RETURN VALUE
On success, zero is returned. On error, a negative integer is returned, and errno might be set by the internal calls to realloc(3) or strdup(3).

ERRORS
Refer to malloc(3) and strdup(3) for a list of possible errors.

SEE ALSO
handler_alloc(3), handler_free(3), handler_listen(3), slweb_handler(7).

COPYRIGHT
Copyright (C) 2023 Xavier Del Campo Romero.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.