sister
Functions
i4httools.h File Reference

Miscellaneous routines for building an HTTP server. More...

#include <stdio.h>

Go to the source code of this file.

Functions

int checkPath (const char path[])
 Checks if a path leaves the webserver's document-root (wwwpath). More...
 
void httpOK (FILE *tx)
 Outputs an "OK" HTTP response to a stream. More...
 
void httpMovedPermanently (FILE *tx, const char newRelPath[])
 Outputs a "moved permanently" HTTP response and error page to a stream. More...
 
void httpBadRequest (FILE *tx)
 Outputs a "bad request" HTTP response and error page to a stream. More...
 
void httpForbidden (FILE *tx, const char relPath[])
 Outputs a "forbidden" HTTP response and error page to a stream. More...
 
void httpNotFound (FILE *tx, const char relPath[])
 Outputs a "not found" HTTP response and error page to a stream. More...
 
void httpInternalServerError (FILE *tx, const char relPath[])
 Outputs an "internal server error" HTTP response and error page to a stream. More...
 

Detailed Description

Miscellaneous routines for building an HTTP server.

This module contains some routines that are useful for implementing a web server.

Function Documentation

◆ checkPath()

int checkPath ( const char  path[])

Checks if a path leaves the webserver's document-root (wwwpath).

This routine checks if the path (as obtained from the HTTP GET request) ascends the VFS beyond the webserver's document-root directory (wwwpath). Such requests should not be served.

Note
This function stops processing as soon as the path ascends beyond the root of the web directory.
Parameters
pathRequested URL.
Returns
Positive depth of the request relative to the web directory, or -1 if the relative URL ascends beyond the web directory.

◆ httpBadRequest()

void httpBadRequest ( FILE *  tx)

Outputs a "bad request" HTTP response and error page to a stream.

This routine generates an "HTTP/1.0 400 Bad Request" status line and a corresponding HTML error page on the given stream, which should normally be the client connection.

Parameters
txThe output stream.

◆ httpForbidden()

void httpForbidden ( FILE *  tx,
const char  relPath[] 
)

Outputs a "forbidden" HTTP response and error page to a stream.

This routine generates an "HTTP/1.0 403 Forbidden" status line and a corresponding HTML error page on the given stream, which should normally be the client connection.

Parameters
txThe output stream.
relPathRequested URL.

◆ httpInternalServerError()

void httpInternalServerError ( FILE *  tx,
const char  relPath[] 
)

Outputs an "internal server error" HTTP response and error page to a stream.

This routine generates an "HTTP/1.0 500 Internal Server Error" status line and a corresponding HTML error page on the given stream, which should normally be the client connection.

Parameters
txThe output stream.
relPathRequested URL. May be NULL if not applicable.

◆ httpMovedPermanently()

void httpMovedPermanently ( FILE *  tx,
const char  newRelPath[] 
)

Outputs a "moved permanently" HTTP response and error page to a stream.

This routine generates a "moved permanently (301)" HTTP response on the given stream, which should normally be the client connection.

Parameters
txThe output stream.
newRelPathPath to which the request is redirected.
Note
This function is not needed for assignment 2 (sister), only for assignment 5 (mother).

◆ httpNotFound()

void httpNotFound ( FILE *  tx,
const char  relPath[] 
)

Outputs a "not found" HTTP response and error page to a stream.

This routine generates an "HTTP/1.0 404 Not Found" status line and a corresponding HTML error page on the given stream, which should normally be the client connection.

Parameters
txThe output stream.
relPathRequested URL.

◆ httpOK()

void httpOK ( FILE *  tx)

Outputs an "OK" HTTP response to a stream.

This routine generates an "OK (200)" status line on the given stream, which should normally be the client connection.

Parameters
txThe output stream.