HTTP-2-lib
Static Public Member Functions
h2_utils Class Reference

#include <h2_utils.hpp>

Static Public Member Functions

static int sendConnectionHeader (struct ClientSessionData *clientSessData)
 
static int sessionOnReceived (struct ClientSessionData *clientSessData)
 
static struct ClientSessionDatacreateClientSessionData (struct ApplicationContext *appCtx, int sock, struct sockaddr *clientAddress, int addressLength)
 
static string bytesToString (const unsigned char *data, size_t firstIndex, size_t secondIndex)
 
static ulong hexToUlong (string hexString)
 
static void sendGetResponse (struct ClientSessionData *clientSessData, const unsigned char *data, string path)
 
static string resolvePath (struct ClientSessionData *clientSessData, string path)
 
static void getResponse200 (struct ClientSessionData *clientSessData, const unsigned char *data, string filepath)
 
static void getResponse404 (struct ClientSessionData *clientSessData, const unsigned char *data)
 
static void deleteClientSessionData (struct ClientSessionData *clientSessData)
 

Member Function Documentation

◆ bytesToString()

string h2_utils::bytesToString ( const unsigned char *  data,
size_t  firstIndex,
size_t  secondIndex 
)
static

Converts bytes from unsigned char* to string

Parameters
data- bytes to be converted
firstIndex- Index to start reading from
secondIndex- Index after the last to byte to be read
Returns
string - from bytes

◆ createClientSessionData()

struct ClientSessionData * h2_utils::createClientSessionData ( struct ApplicationContext appCtx,
int  sock,
struct sockaddr *  clientAddress,
int  addressLength 
)
static

Creates a clientSessionData object which keeps all to be used for one single connection.

Parameters
appCtx- Application-wide application_ctx object.
sock- file descriptor for the connection
clientAddress- socket address of the client.
addressLength- length of socket address.
Returns
clientSessData - the newly created

◆ deleteClientSessionData()

void h2_utils::deleteClientSessionData ( struct ClientSessionData clientSessData)
static

Deletes and frees memory hold by the ClientSessionData object.

Parameters
clientSessData- The ClientSessionData object to delete.

◆ getResponse200()

void h2_utils::getResponse200 ( struct ClientSessionData clientSessData,
const unsigned char *  data,
string  filepath 
)
static

Responds to get request with html, js or css file, and status: 200.

Parameters
clientSessData- ClientSessionData, used to respond to correct client
data- pointer to array containing request
filepath- where the requested file is located

◆ getResponse404()

void h2_utils::getResponse404 ( struct ClientSessionData clientSessData,
const unsigned char *  data 
)
static

Sends a status: 404 Not Found response

Parameters
clientSessData- ClientSessionData, used to respond to correct client
data- pointer to array containing request

◆ hexToUlong()

ulong h2_utils::hexToUlong ( string  hexString)
static

Convert hexString to ulong

Parameters
hexString- hexString to be converted
Returns
ulong

◆ resolvePath()

string h2_utils::resolvePath ( struct ClientSessionData clientSessData,
string  path 
)
static

Resolves user-defined routes, and returns the filepath in publicDir

Parameters
clientSessData- ClientSessionData to access list of routes
path- path to resolve
Returns
string - filepath in publicDir

◆ sendConnectionHeader()

int h2_utils::sendConnectionHeader ( struct ClientSessionData clientSessData)
static

Sends server connection header with 'MAXIMUM_CONCURRENT_STREAMS' set to 100.

Parameters
ClientSessData- ClientSessionData object for this particular connection.
Returns
returnValue - 0 if successful, non-zero if failure.

◆ sendGetResponse()

void h2_utils::sendGetResponse ( struct ClientSessionData clientSessData,
const unsigned char *  data,
string  path 
)
static

Send a get response when recieving a request

Parameters
ClientSessData- ClientSessionData
data- pointer to array with the request
path- where to find requested resource

◆ sessionOnReceived()

int h2_utils::sessionOnReceived ( struct ClientSessionData clientSessData)
static

Gets called every time a frame is recieved from a client

Parameters
clientSessData- ClientSessionData
Returns
0 if successful, non-zero if failure

The documentation for this class was generated from the following files: