namespace www

Overview

Stuff to bring BioShell online, e.g. embedded web-server. More…

// typedefs

typedef enum ui::www::HttpStatus http_status_t
typedef struct ui::www::http_t http_t

// enums

enum HttpStatus
enum Method

// structs

struct Path
struct Request
struct Route
struct http_t

// classes

class Response
class WebServer

// global functions

std::string decode_url (const std::string& url)
std::string encode_url (const std::string& url)

bool get_query_value (
    Request* req,
    const std::string& query_key,
    std::string& value
    )

std::string get_query_value (
    Request* req,
    const std::string& query_key
    )

http_t* http_get (
    const std::string& url,
    void* memctx
    )

http_t* http_post (
    const std::string& url,
    void const* data,
    std::size_t size,
    void* memctx
    )

HttpStatus http_process (http_t* http)
void http_release (http_t* http)

bool inject_http_option (
    Request* req,
    const std::string& query_key,
    utils::options::Option& option
    )

std::string load_url (const std::string& url)
void log_request (Request* req)
unsigned long resolve_name (const std::string& name)

void show_error (
    Response* res,
    const std::string& msg
    )

void split_url (
    const std::string& url,
    std::string& first,
    std::string& second
    )

Detailed Documentation

Stuff to bring BioShell online, e.g. embedded web-server.

Typedefs

typedef enum ui::www::HttpStatus http_status_t

Defines status of a HTTP call.

typedef struct ui::www::http_t http_t

Data structure for a single HTTP connection.

Global Functions

std::string decode_url (const std::string& url)

Decodes a URL string that has been sent in an encoded form.

Parameters:

url
  • encoded URL

Returns:

decoded URL string

std::string encode_url (const std::string& url)

Encodes a URL string by replacing non-ASCI characters with their codes.

Parameters:

url
  • a URL to be encoded

Returns:

encoded URL string

bool get_query_value (
    Request* req,
    const std::string& query_key,
    std::string& value
    )

Reads a value associated with a given key in a HTTP request.

This method attempts to find a value for a key in a GET or POST request. For example, if a GET request looked like: http://www.site.com?protein_id=2gb1 , then get_query_value(req,"protein_id"); should return 2gb1 string.

Parameters:

req
  • incoming http request
query_key
  • the key
value
  • placeholder to store the value

Returns:

true if the given key was found in the request; false otherwise

std::string get_query_value (
    Request* req,
    const std::string& query_key
    )

Reads a value associated with a given key in a HTTP request.

This method attempts to find a value for a key in a GET or POST request. For example, if a GET request looked like: http://www.site.com?protein_id=2gb1 , then get_query_value(req,"protein_id"); should return 2gb1 string.

Parameters:

req
  • incoming http request
query_key
  • the key

Returns:

value associated with a given key

http_t* http_get (
    const std::string& url,
    void* memctx
    )

Sends a GET request to a server.

Parameters:

url
  • URL to be accessed
memctx
  • buffer for data

Returns:

a structure describing the result

http_t* http_post (
    const std::string& url,
    void const* data,
    std::size_t size,
    void* memctx
    )

Sends a POST request to a server.

Parameters:

url
  • URL to be accessed
memctx
  • buffer for data

Returns:

a structure describing the result

HttpStatus http_process (http_t* http)

Process a HTTP connection.

Parameters:

http
  • HTTP structure
void http_release (http_t* http)

Releases a HTTP connection.

Parameters:

http
  • HTTP structure
bool inject_http_option (
    Request* req,
    const std::string& query_key,
    utils::options::Option& option
    )

Registers an option=value pair in the OptionParser instance as it would be used at command-line.

This method extracts from the given GET/POST query a value associated with the given string key. The value is subsequently assigned to a command-line option.

Parameters:

req
  • incoming http request
query_key
  • GET/POST parameter identifier.
option
  • option to which a given value will be assigned

Returns:

true if the given query_key has been found in the given GET/POST query; false otherwise (which means the option was not placed at the command line)

void log_request (Request* req)

Writes a log message about a given http request to the logger.

void show_error (
    Response* res,
    const std::string& msg
    )

Loads the given error message to a http package body.

Parameters:

res
  • package that will be returned
msg
  • the error message text