Path: blob/main/crypto/openssl/apps/include/http_server.h
34878 views
/*1* Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.2*3* Licensed under the Apache License 2.0 (the "License"). You may not use4* this file except in compliance with the License. You can obtain a copy5* in the file LICENSE in the source distribution or at6* https://www.openssl.org/source/license.html7*/89#ifndef OSSL_HTTP_SERVER_H10# define OSSL_HTTP_SERVER_H1112# include "apps.h"13# include "log.h"1415# ifndef HAVE_FORK16# if defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_WINDOWS)17# define HAVE_FORK 018# else19# define HAVE_FORK 120# endif21# endif2223# if HAVE_FORK24# undef NO_FORK25# else26# define NO_FORK27# endif2829# if !defined(NO_FORK) && !defined(OPENSSL_NO_SOCK) \30&& !defined(OPENSSL_NO_POSIX_IO)31# define HTTP_DAEMON32# include <sys/types.h>33# include <sys/wait.h>34# include <signal.h>35# define MAXERRLEN 1000 /* limit error text sent to syslog to 1000 bytes */36# endif3738# ifndef OPENSSL_NO_SOCK39/*-40* Initialize an HTTP server, setting up its listening BIO41* prog: the name of the current app42* port: the port to listen on43* verbosity: the level of verbosity to use, or -1 for default: LOG_INFO44* returns a BIO for accepting requests, NULL on error45*/46BIO *http_server_init(const char *prog, const char *port, int verbosity);4748/*-49* Accept an ASN.1-formatted HTTP request50* it: the expected request ASN.1 type51* preq: pointer to variable where to place the parsed request52* ppath: pointer to variable where to place the request path, or NULL53* pcbio: pointer to variable where to place the BIO for sending the response to54* acbio: the listening bio (typically as returned by http_server_init_bio())55* found_keep_alive: for returning flag if client requests persistent connection56* prog: the name of the current app, for diagnostics only57* accept_get: whether to accept GET requests (in addition to POST requests)58* timeout: connection timeout (in seconds), or 0 for none/infinite59* returns 0 in case caller should retry, then *preq == *ppath == *pcbio == NULL60* returns -1 on fatal error; also then holds *preq == *ppath == *pcbio == NULL61* returns 1 otherwise. In this case it is guaranteed that *pcbio != NULL while62* *ppath == NULL and *preq == NULL if and only if the request is invalid,63* On return value 1 the caller is responsible for sending an HTTP response,64* using http_server_send_asn1_resp() or http_server_send_status().65* The caller must free any non-NULL *preq, *ppath, and *pcbio pointers.66*/67int http_server_get_asn1_req(const ASN1_ITEM *it, ASN1_VALUE **preq,68char **ppath, BIO **pcbio, BIO *acbio,69int *found_keep_alive,70const char *prog, int accept_get, int timeout);7172/*-73* Send an ASN.1-formatted HTTP response74* prog: the name of the current app, for diagnostics only75* cbio: destination BIO (typically as returned by http_server_get_asn1_req())76* note: cbio should not do an encoding that changes the output length77* keep_alive: grant persistent connection78* content_type: string identifying the type of the response79* it: the response ASN.1 type80* resp: the response to send81* returns 1 on success, 0 on failure82*/83int http_server_send_asn1_resp(const char *prog, BIO *cbio, int keep_alive,84const char *content_type,85const ASN1_ITEM *it, const ASN1_VALUE *resp);8687/*-88* Send a trivial HTTP response, typically to report an error or OK89* prog: the name of the current app, for diagnostics only90* cbio: destination BIO (typically as returned by http_server_get_asn1_req())91* status: the status code to send92* reason: the corresponding human-readable string93* returns 1 on success, 0 on failure94*/95int http_server_send_status(const char *prog, BIO *cbio,96int status, const char *reason);9798# endif99100# ifdef HTTP_DAEMON101extern int n_responders;102extern int acfd;103104void socket_timeout(int signum);105void spawn_loop(const char *prog);106# endif107108#endif109110111