💾 Archived View for gemini.thededem.de › lc19 › src › include › srv.h captured on 2024-08-18 at 18:17:37.
⬅️ Previous capture (2021-12-03)
-=-=-=-=-=-=-
/* Copyright 2020, 2021 Lukas Wedeking * * This file is part of LC19. * * LC19 is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * LC19 is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with LC19. If not, see <https://www.gnu.org/licenses/>. */ #ifndef GEMINI_SERVER_SRV_H #define GEMINI_SERVER_SRV_H #include<stddef.h> #include<stdio.h> #include<sys/stat.h> #include "../include/url.h" enum ResponseState { RESPONSESTATE_UNSET = 0, RESPONSESTATE_FLUSHED = 1 << 0, RESPONSESTATE_READY = 1 << 1, RESPONSESTATE_READY_CGI = 1 << 1, }; enum ResourceType { RESOURCETYPE_PLAIN = 0, RESOURCETYPE_CGI = 1 << 0, }; struct Response { enum ResponseState state; int status; char meta[1025]; FILE* data; enum ResourceType type; }; /* * Set the response status code. */ int srv_response_set_status(int status); /* * Set the meta string of the response. * * If something fails, the meta string of the response is in an undefined state. */ int srv_response_set_meta(const char *meta); /* * Set the data of the response. */ void srv_response_set_data(FILE *data, enum ResourceType type); /* * Write the response, ie. its meta string followd by its data, to stdout. */ void srv_response_flush(); /* * Get the path of an auxiliary file. The first parameter is a local path to a * resource. The second parameter is the extension of the auxiliary file. The * auxiliary file has the filename ".resource_filename.extension". */ char* srv_resource_aux_path(const char *path, const char *extension); /* * Get the content of a resource's auxiliary file. path is the local path to the * resource, type defines the auxiliary file and size defines the size of the * buffer that is being returned. Returns NULL if no auxiliary information were * available. */ char* srv_resource_aux_content(const char *path, const char *type, size_t size); /* * Try to determine a resource's mime type via an auxiliary .mime file and the * the response accordingly. Returns 0, if the mime type was not read. */ int srv_resource_mime_from_file(const char *path); /* * Check if a redirect is defined for a resource and set the response * accordingly. Returns 0, if no redirect was specified. */ int srv_response_redirect(const char *path); char* srv_find_file_ext(const char *path); int srv_response_meta_from_mimedb(const char *path, const char *mimedb); int srv_response_meta_from_ext(const char *path); void srv_response_dir_index(const char *path, struct Url *url); int srv_response_url_error(const struct Url *url); int srv_check_resource_path(const char *path); char* srv_resource_path(const char *data_dir, const struct Url *url, enum ResourceType *type, struct stat *st); void srv_resource_append_mime_parameter(const char *param); void srv_resource_update_mime_parameters(const char *path); void srv_response_resource(struct Url *url); #endif