1 /* $NetBSD: httpd.h,v 1.1 2024/02/18 20:57:53 christos Exp $ */ 2 3 /* 4 * Copyright (C) Internet Systems Consortium, Inc. ("ISC") 5 * 6 * SPDX-License-Identifier: MPL-2.0 7 * 8 * This Source Code Form is subject to the terms of the Mozilla Public 9 * License, v. 2.0. If a copy of the MPL was not distributed with this 10 * file, you can obtain one at https://mozilla.org/MPL/2.0/. 11 * 12 * See the COPYRIGHT file distributed with this work for additional 13 * information regarding copyright ownership. 14 */ 15 16 #ifndef ISC_HTTPD_H 17 #define ISC_HTTPD_H 1 18 19 /*! \file */ 20 21 #include <stdbool.h> 22 23 #include <isc/event.h> 24 #include <isc/eventclass.h> 25 #include <isc/mutex.h> 26 #include <isc/task.h> 27 #include <isc/time.h> 28 #include <isc/types.h> 29 30 /*% 31 * HTTP urls. These are the URLs we manage, and the function to call to 32 * provide the data for it. We pass in the base url (so the same function 33 * can handle multiple requests), and a structure to fill in to return a 34 * result to the client. We also pass in a pointer to be filled in for 35 * the data cleanup function. 36 */ 37 struct isc_httpdurl { 38 char *url; 39 isc_httpdaction_t *action; 40 void *action_arg; 41 bool isstatic; 42 isc_time_t loadtime; 43 ISC_LINK(isc_httpdurl_t) link; 44 }; 45 46 #define HTTPD_EVENTCLASS ISC_EVENTCLASS(4300) 47 #define HTTPD_SHUTDOWN (HTTPD_EVENTCLASS + 0x0001) 48 49 #define ISC_HTTPDMGR_FLAGSHUTTINGDOWN 0x00000001 50 51 /* 52 * Create a new http daemon which will send, once every time period, 53 * a http-like header followed by HTTP data. 54 */ 55 isc_result_t 56 isc_httpdmgr_create(isc_mem_t *mctx, isc_socket_t *sock, isc_task_t *task, 57 isc_httpdclientok_t *client_ok, 58 isc_httpdondestroy_t *ondestory, void *cb_arg, 59 isc_timermgr_t *tmgr, isc_httpdmgr_t **httpdp); 60 61 void 62 isc_httpdmgr_shutdown(isc_httpdmgr_t **httpdp); 63 64 isc_result_t 65 isc_httpdmgr_addurl(isc_httpdmgr_t *httpdmgr, const char *url, 66 isc_httpdaction_t *func, void *arg); 67 68 isc_result_t 69 isc_httpdmgr_addurl2(isc_httpdmgr_t *httpdmgr, const char *url, bool isstatic, 70 isc_httpdaction_t *func, void *arg); 71 72 isc_result_t 73 isc_httpd_response(isc_httpd_t *httpd); 74 75 isc_result_t 76 isc_httpd_addheader(isc_httpd_t *httpd, const char *name, const char *val); 77 78 isc_result_t 79 isc_httpd_addheaderuint(isc_httpd_t *httpd, const char *name, int val); 80 81 isc_result_t 82 isc_httpd_endheaders(isc_httpd_t *httpd); 83 84 void 85 isc_httpd_setfinishhook(void (*fn)(void)); 86 87 #endif /* ISC_HTTPD_H */ 88