Example #1
0
int show_about(http_request req, http_response page)
{
    const char* html =
        "<p>So what's a web cache good for anyway? The objective"
        " for this web cache is to offload high traffic web sites"
        " by moving static data to a separate web server and"
        " serve the requests for the static data as fast as possible,"
        " so that the original web server can focus on its main tasks."
        "<p>The Highlander web cache loads data from disk at startup"
        " and never reads from disk again, unless asked to do so."
        " This way the data(images, files, anything static) is always"
        " available in memory and can be sent to the client with"
        " zero disk access and zero system calls except for the network"
        " write() calls."
        "<p>The Highlander web cache is very portable between POSIX"
        " systems, meaning that you can scale both up and down as"
        " your needs changes."
        ;


    (void)req;
    if (!add_page_start(page, PAGE_ABOUT))
		return HTTP_500_INTERNAL_SERVER_ERROR;

    if (!response_add(page, html))
		return HTTP_500_INTERNAL_SERVER_ERROR;

    if (!add_page_end(page, NULL))
		return HTTP_500_INTERNAL_SERVER_ERROR;

    return 0;
}
Example #2
0
int show_cache(http_request req, http_response page)
{
    char msgbuf[100] = { '\0' };

    const char *action;
    if (!add_page_start(page, PAGE_CACHE)
    || !response_href(page, "/cache?a=reload", "reload cache")
    || !response_br(page))
        return HTTP_500_INTERNAL_SERVER_ERROR;

    if ( (action = request_get_parameter_value(req, "a")) == NULL) {
        /* No action */
    }
    else if (strcmp(action, "reload") == 0) {
        size_t files;
        if ( (files = reload_cache()) == 0)
            strcpy(msgbuf, "No files were added to the cache, an error probably occured");
        else {
            sprintf(msgbuf, "Added %zu files to cache", files);
        }
    }

    if (!add_page_end(page, msgbuf))
        return HTTP_500_INTERNAL_SERVER_ERROR;

    return HTTP_200_OK;
}