From 0222b75e8554796548e079aa3393c512ae30ac24 Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Romero Date: Tue, 10 Oct 2023 23:21:35 +0200 Subject: Rename project from slweb to libweb It was found out there was another project of the same name around (https://git.sr.ht/~strahinja/slweb/), also related to website generation. In order to avoid confusion, a new name has been chosen for this project. Surprisingly, libweb was not in use by any distributions (according to https://repology.org and AUR index), and it should reflect well the intention behind this project i.e., being a library to build web-related stuff. --- include/libweb/handler.h | 24 +++++++++ include/libweb/html.h | 15 ++++++ include/libweb/http.h | 110 ++++++++++++++++++++++++++++++++++++++++++ include/libweb/server.h | 15 ++++++ include/libweb/wildcard_cmp.h | 8 +++ include/slweb/handler.h | 24 --------- include/slweb/html.h | 15 ------ include/slweb/http.h | 110 ------------------------------------------ include/slweb/server.h | 15 ------ include/slweb/wildcard_cmp.h | 8 --- 10 files changed, 172 insertions(+), 172 deletions(-) create mode 100644 include/libweb/handler.h create mode 100644 include/libweb/html.h create mode 100644 include/libweb/http.h create mode 100644 include/libweb/server.h create mode 100644 include/libweb/wildcard_cmp.h delete mode 100644 include/slweb/handler.h delete mode 100644 include/slweb/html.h delete mode 100644 include/slweb/http.h delete mode 100644 include/slweb/server.h delete mode 100644 include/slweb/wildcard_cmp.h (limited to 'include') diff --git a/include/libweb/handler.h b/include/libweb/handler.h new file mode 100644 index 0000000..9cde129 --- /dev/null +++ b/include/libweb/handler.h @@ -0,0 +1,24 @@ +#ifndef HANDLER_H +#define HANDLER_H + +#include "libweb/http.h" +#include + +typedef int (*handler_fn)(const struct http_payload *p, + struct http_response *r, void *user); + +struct handler_cfg +{ + const char *tmpdir; + int (*length)(unsigned long long len, const struct http_cookie *c, + struct http_response *r, void *user); + void *user; +}; + +struct handler *handler_alloc(const struct handler_cfg *cfg); +void handler_free(struct handler *h); +int handler_add(struct handler *h, const char *url, enum http_op op, + handler_fn f, void *user); +int handler_listen(struct handler *h, unsigned short port); + +#endif /* HANDLER_H */ diff --git a/include/libweb/html.h b/include/libweb/html.h new file mode 100644 index 0000000..e62575e --- /dev/null +++ b/include/libweb/html.h @@ -0,0 +1,15 @@ +#ifndef HTML_H +#define HTML_H + +#include + +struct html_node *html_node_alloc(const char *element); +void html_node_free(struct html_node *n); +int html_node_set_value(struct html_node *n, const char *val); +int html_node_set_value_unescaped(struct html_node *n, const char *val); +int html_node_add_attr(struct html_node *n, const char *attr, const char *val); +struct html_node *html_node_add_child(struct html_node *n, const char *elem); +void html_node_add_sibling(struct html_node *n, struct html_node *sibling); +int html_serialize(const struct html_node *n, struct dynstr *d); + +#endif /* HTML_H */ diff --git a/include/libweb/http.h b/include/libweb/http.h new file mode 100644 index 0000000..68ffb9a --- /dev/null +++ b/include/libweb/http.h @@ -0,0 +1,110 @@ +#ifndef HTTP_H +#define HTTP_H + +#include +#include +#include + +struct http_payload +{ + enum http_op + { + HTTP_OP_GET, + HTTP_OP_POST, + HTTP_OP_HEAD + } op; + + const char *resource; + + struct http_cookie + { + const char *field, *value; + } cookie; + + union + { + struct http_post + { + bool expect_continue; + const char *data; + size_t nfiles, npairs; + + const struct http_post_pair + { + const char *name, *value; + } *pairs; + + const struct http_post_file + { + const char *name, *tmpname, *filename; + } *files; + } post; + } u; + + const struct http_arg + { + char *key, *value; + } *args; + + size_t n_args; +}; + +#define HTTP_STATUSES \ + X(CONTINUE, "Continue", 100) \ + X(OK, "OK", 200) \ + X(SEE_OTHER, "See other", 303) \ + X(BAD_REQUEST, "Bad Request", 400) \ + X(UNAUTHORIZED, "Unauthorized", 401) \ + X(FORBIDDEN, "Forbidden", 403) \ + X(NOT_FOUND, "Not found", 404) \ + X(PAYLOAD_TOO_LARGE, "Payload too large", 413) \ + X(INTERNAL_ERROR, "Internal Server Error", 500) + +struct http_response +{ + enum http_status + { +#define X(x, y, z) HTTP_STATUS_##x, + HTTP_STATUSES +#undef X + } status; + + struct http_header + { + char *header, *value; + } *headers; + + union + { + const void *ro; + void *rw; + } buf; + + FILE *f; + unsigned long long n; + size_t n_headers; + void (*free)(void *); +}; + +struct http_cfg +{ + int (*read)(void *buf , size_t n, void *user); + int (*write)(const void *buf, size_t n, void *user); + int (*payload)(const struct http_payload *p, struct http_response *r, + void *user); + int (*length)(unsigned long long len, const struct http_cookie *c, + struct http_response *r, void *user); + const char *tmpdir; + void *user; +}; + +struct http_ctx *http_alloc(const struct http_cfg *cfg); +void http_free(struct http_ctx *h); +int http_update(struct http_ctx *h, bool *write, bool *close); +int http_response_add_header(struct http_response *r, const char *header, + const char *value); +char *http_cookie_create(const char *key, const char *value); +char *http_encode_url(const char *url); +char *http_decode_url(const char *url, bool spaces); + +#endif /* HTTP_H */ diff --git a/include/libweb/server.h b/include/libweb/server.h new file mode 100644 index 0000000..74f06ae --- /dev/null +++ b/include/libweb/server.h @@ -0,0 +1,15 @@ +#ifndef SERVER_H +#define SERVER_H + +#include +#include + +struct server *server_init(unsigned short port); +struct server_client *server_poll(struct server *s, bool *io, bool *exit); +int server_read(void *buf, size_t n, struct server_client *c); +int server_write(const void *buf, size_t n, struct server_client *c); +int server_close(struct server *s); +int server_client_close(struct server *s, struct server_client *c); +void server_client_write_pending(struct server_client *c, bool write); + +#endif /* SERVER_H */ diff --git a/include/libweb/wildcard_cmp.h b/include/libweb/wildcard_cmp.h new file mode 100644 index 0000000..fa09913 --- /dev/null +++ b/include/libweb/wildcard_cmp.h @@ -0,0 +1,8 @@ +#ifndef WILDCARD_CMP_H +#define WILDCARD_CMP_H + +#include + +int wildcard_cmp(const char *s, const char *p, bool casecmp); + +#endif /* WILDCARD_CMP_H */ diff --git a/include/slweb/handler.h b/include/slweb/handler.h deleted file mode 100644 index 84a8073..0000000 --- a/include/slweb/handler.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef HANDLER_H -#define HANDLER_H - -#include "slweb/http.h" -#include - -typedef int (*handler_fn)(const struct http_payload *p, - struct http_response *r, void *user); - -struct handler_cfg -{ - const char *tmpdir; - int (*length)(unsigned long long len, const struct http_cookie *c, - struct http_response *r, void *user); - void *user; -}; - -struct handler *handler_alloc(const struct handler_cfg *cfg); -void handler_free(struct handler *h); -int handler_add(struct handler *h, const char *url, enum http_op op, - handler_fn f, void *user); -int handler_listen(struct handler *h, unsigned short port); - -#endif /* HANDLER_H */ diff --git a/include/slweb/html.h b/include/slweb/html.h deleted file mode 100644 index e62575e..0000000 --- a/include/slweb/html.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef HTML_H -#define HTML_H - -#include - -struct html_node *html_node_alloc(const char *element); -void html_node_free(struct html_node *n); -int html_node_set_value(struct html_node *n, const char *val); -int html_node_set_value_unescaped(struct html_node *n, const char *val); -int html_node_add_attr(struct html_node *n, const char *attr, const char *val); -struct html_node *html_node_add_child(struct html_node *n, const char *elem); -void html_node_add_sibling(struct html_node *n, struct html_node *sibling); -int html_serialize(const struct html_node *n, struct dynstr *d); - -#endif /* HTML_H */ diff --git a/include/slweb/http.h b/include/slweb/http.h deleted file mode 100644 index 68ffb9a..0000000 --- a/include/slweb/http.h +++ /dev/null @@ -1,110 +0,0 @@ -#ifndef HTTP_H -#define HTTP_H - -#include -#include -#include - -struct http_payload -{ - enum http_op - { - HTTP_OP_GET, - HTTP_OP_POST, - HTTP_OP_HEAD - } op; - - const char *resource; - - struct http_cookie - { - const char *field, *value; - } cookie; - - union - { - struct http_post - { - bool expect_continue; - const char *data; - size_t nfiles, npairs; - - const struct http_post_pair - { - const char *name, *value; - } *pairs; - - const struct http_post_file - { - const char *name, *tmpname, *filename; - } *files; - } post; - } u; - - const struct http_arg - { - char *key, *value; - } *args; - - size_t n_args; -}; - -#define HTTP_STATUSES \ - X(CONTINUE, "Continue", 100) \ - X(OK, "OK", 200) \ - X(SEE_OTHER, "See other", 303) \ - X(BAD_REQUEST, "Bad Request", 400) \ - X(UNAUTHORIZED, "Unauthorized", 401) \ - X(FORBIDDEN, "Forbidden", 403) \ - X(NOT_FOUND, "Not found", 404) \ - X(PAYLOAD_TOO_LARGE, "Payload too large", 413) \ - X(INTERNAL_ERROR, "Internal Server Error", 500) - -struct http_response -{ - enum http_status - { -#define X(x, y, z) HTTP_STATUS_##x, - HTTP_STATUSES -#undef X - } status; - - struct http_header - { - char *header, *value; - } *headers; - - union - { - const void *ro; - void *rw; - } buf; - - FILE *f; - unsigned long long n; - size_t n_headers; - void (*free)(void *); -}; - -struct http_cfg -{ - int (*read)(void *buf , size_t n, void *user); - int (*write)(const void *buf, size_t n, void *user); - int (*payload)(const struct http_payload *p, struct http_response *r, - void *user); - int (*length)(unsigned long long len, const struct http_cookie *c, - struct http_response *r, void *user); - const char *tmpdir; - void *user; -}; - -struct http_ctx *http_alloc(const struct http_cfg *cfg); -void http_free(struct http_ctx *h); -int http_update(struct http_ctx *h, bool *write, bool *close); -int http_response_add_header(struct http_response *r, const char *header, - const char *value); -char *http_cookie_create(const char *key, const char *value); -char *http_encode_url(const char *url); -char *http_decode_url(const char *url, bool spaces); - -#endif /* HTTP_H */ diff --git a/include/slweb/server.h b/include/slweb/server.h deleted file mode 100644 index 74f06ae..0000000 --- a/include/slweb/server.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef SERVER_H -#define SERVER_H - -#include -#include - -struct server *server_init(unsigned short port); -struct server_client *server_poll(struct server *s, bool *io, bool *exit); -int server_read(void *buf, size_t n, struct server_client *c); -int server_write(const void *buf, size_t n, struct server_client *c); -int server_close(struct server *s); -int server_client_close(struct server *s, struct server_client *c); -void server_client_write_pending(struct server_client *c, bool write); - -#endif /* SERVER_H */ diff --git a/include/slweb/wildcard_cmp.h b/include/slweb/wildcard_cmp.h deleted file mode 100644 index fa09913..0000000 --- a/include/slweb/wildcard_cmp.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef WILDCARD_CMP_H -#define WILDCARD_CMP_H - -#include - -int wildcard_cmp(const char *s, const char *p, bool casecmp); - -#endif /* WILDCARD_CMP_H */ -- cgit v1.2.3