Monero
Loading...
Searching...
No Matches
minihttptestserver.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <signal.h>
#include <time.h>
#include <errno.h>
Include dependency graph for minihttptestserver.c:

Macros

#define INADDR_LOOPBACK   0x7f000001
#define CRAP_LENGTH   (2048)
#define FAVICON_LENGTH   (6 + 16 + 40 + 8 + 32 * 4)

Enumerations

enum  modes {
  MODE_INVALID , MODE_CHUNKED , MODE_ADDCRAP , MODE_NORMAL ,
  MODE_FAVICON , MODE_MALFORMED
}

Functions

static int server (unsigned short port, const char *expected_file_name, int ipv6)
void handle_signal_chld (int sig)
void handle_signal_int (int sig)
void build_content (char *p, size_t n)
void build_crap (char *p, size_t n)
char * build_chunked_response (size_t content_length, size_t *response_len)
void build_favicon_content (unsigned char *p, size_t n)
void send_response (int c, const char *buffer, size_t len)
void handle_http_connection (int c)
int main (int argc, char **argv)

Variables

volatile sig_atomic_t quit = 0
volatile sig_atomic_t child_to_wait_for = 0
struct { 
   enum modes   mode 
   const char *   text 
modes_array []

Macro Definition Documentation

◆ CRAP_LENGTH

#define CRAP_LENGTH   (2048)

◆ FAVICON_LENGTH

#define FAVICON_LENGTH   (6 + 16 + 40 + 8 + 32 * 4)

◆ INADDR_LOOPBACK

#define INADDR_LOOPBACK   0x7f000001

Enumeration Type Documentation

◆ modes

enum modes
Enumerator
MODE_INVALID 
MODE_CHUNKED 
MODE_ADDCRAP 
MODE_NORMAL 
MODE_FAVICON 
MODE_MALFORMED 

Function Documentation

◆ build_chunked_response()

char * build_chunked_response ( size_t content_length,
size_t * response_len )

build chunked response. return a malloc'ed buffer

◆ build_content()

void build_content ( char * p,
size_t n )

build a text/plain content of the specified length

◆ build_crap()

void build_crap ( char * p,
size_t n )

build crappy content

◆ build_favicon_content()

void build_favicon_content ( unsigned char * p,
size_t n )

◆ handle_http_connection()

void handle_http_connection ( int c)

handle the HTTP connection

◆ handle_signal_chld()

void handle_signal_chld ( int sig)

signal handler for SIGCHLD (child status has changed)

◆ handle_signal_int()

void handle_signal_int ( int sig)

signal handler for SIGINT (CRTL C)

◆ main()

int main ( int argc,
char ** argv )

◆ send_response()

void send_response ( int c,
const char * buffer,
size_t len )

write the response with random behaviour !

◆ server()

int server ( unsigned short port,
const char * expected_file_name,
int ipv6 )
static

Variable Documentation

◆ child_to_wait_for

volatile sig_atomic_t child_to_wait_for = 0

◆ mode

enum modes mode

◆ [struct]

const struct { ... } modes_array[]
Initial value:
= {
{MODE_CHUNKED, "chunked"},
{MODE_ADDCRAP, "addcrap"},
{MODE_NORMAL, "normal"},
{MODE_FAVICON, "favicon.ico"},
{MODE_MALFORMED, "malformed"},
{MODE_INVALID, NULL}
}
@ MODE_ADDCRAP
Definition minihttptestserver.c:264
@ MODE_CHUNKED
Definition minihttptestserver.c:264
@ MODE_MALFORMED
Definition minihttptestserver.c:264
@ MODE_INVALID
Definition minihttptestserver.c:264
@ MODE_FAVICON
Definition minihttptestserver.c:264
@ MODE_NORMAL
Definition minihttptestserver.c:264

◆ quit

volatile sig_atomic_t quit = 0

◆ text

const char* text