petal.c File Reference

HTTP1.1/SSL server. More...

#include "config.h"
#include <openssl/x509.h>
#include <openssl/pem.h>
#include <ctype.h>
#include <signal.h>

Functions

static void usage (void)
 Give petal usage, and exit (1).
 
static void print_exit (const char *str)
 fatal exit
 
static void log_errno (const char *str)
 print errno
 
static int parse_ip_addr (char *str, int port, struct sockaddr_storage *ret, socklen_t *l)
 parse a text IP address into a sockaddr
 
static void fd_close (int fd)
 close the fd
 
static int read_ssl_line (SSL *ssl, char *buf, size_t len)
 Read one line from SSL zero terminates. More...
 
static int process_one_header (char *buf, char *file, size_t flen, char *host, size_t hlen, int *vs)
 process one http header
 
static int read_http_headers (SSL *ssl, char *file, size_t flen, char *host, size_t hlen, int *vs)
 read http headers and process them
 
static SSL_CTX * setup_ctx (char *key, char *cert)
 setup SSL context
 
static int setup_fd (char *addr, int port)
 setup listening TCP
 
static SSL * setup_ssl (int s, SSL_CTX *ctx)
 setup SSL connection to the client
 
static int file_name_is_safe (char *s)
 check a file name for safety
 
static void adjust_host (char *host)
 adjust host
 
static void adjust_file (char *file)
 adjust filename
 
static int host_name_is_safe (char *s)
 check a host name for safety
 
static void provide_file_10 (SSL *ssl, char *fname)
 provide file in whole transfer
 
static void provide_file_chunked (SSL *ssl, char *fname)
 provide file over SSL, chunked encoding
 
static void service_ssl (SSL *ssl, struct sockaddr_storage *from, socklen_t falen)
 provide service to the ssl descriptor
 
static void do_service (char *addr, int port, char *key, char *cert)
 provide ssl service
 
int main (int argc, char *argv[])
 Main routine for petal.
 

Variables

static int verb = 0
 verbosity for this application
 
int optind
 getopt global, in case header files fail to declare it.
 
char * optarg
 getopt global, in case header files fail to declare it.
 

Detailed Description

HTTP1.1/SSL server.

Function Documentation

◆ read_ssl_line()

static int read_ssl_line ( SSL *  ssl,
char *  buf,
size_t  len 
)
static

Read one line from SSL zero terminates.

skips "\r\n" (but not copied to buf).

Parameters
sslthe SSL connection to read from (blocking).
bufbuffer to return line in.
lensize of the buffer.
Returns
0 on error, 1 on success.

References verb.

Referenced by read_http_headers().