You are not logged in.

#1 2016-08-31 13:27:09

truewar
Member
From: Czech Republic
Registered: 2016-08-30
Posts: 13
Website

WebStuff - C Library for Web Development

Hello Community!

This is my first post here despite I am Arch User for several years.

I am about to share few workouts with Open Source world.
And first of them is a WebStuff.

You can see it in action on my website lowenware.com.
Whole website is written in C using this library.

Main features are:
- built-in web server that could work as backend
- simple API to access  get/post variables, read/save cookies
- lightweight templating engine
- own API to parse command line arguments
- own Configuration file format ( almost python like) engine

You can install it from AUR. I.E. using yaourt:

yaourt -S webstuff

For testing you can try my tutorial:


hello.c
-----------------------------------------------------------------------------------
#include <ws/webstuff.h>

const char      cHost[] = "0.0.0.0";
const int       cPort   = 8080;
const WsVersion version = {0, 0, 1, 0};

void
handler(WsRequest * wsr)
{
    int      i,c;
    WsPair * p;
    char   * user = ws_request_get_var(wsr, wsGet, "user");

    ws_print(wsr, "<html>"
                    "<head>"
                        "<title>WebStuff HelloWorld tutorial</title>"
                    "</head>"
                    "<body>");

    ws_printf(wsr,    "<h1>Hello, %s!</h1>", (user) ? user : "World");
    ws_print(wsr,     "<ul>");

    c = ws_list_get_count(wsr->environ);
    for (i=0; i<c; i++)
    {
        p = ws_list_get_item(wsr->environ, i);
        ws_printf(wsr, "<li><b>%s</b> = %s;</li>", p->key, 
                                             (p->value) ? p->value : "");
    }

    ws_print(wsr,     "</ul>"
                    "</body>"
                  "</html>");
}

int
main(int argc, char ** argv)
{
    WsModule    * module = ws_module_new("HelloWorld", NULL);
    WsUrl         urls[] = { {"^(.*)$", handler, NULL},
                             {NULL,     NULL,    NULL} };

    ws_module_set_urls   ( module, urls );
    ws_module_set_socket ( module, cHost, cPort );
    ws_module_start(module);

    ws_module_free(module);

    return 0;
}

To compile you can use:

gcc hello.c -lws -o hello_ws

then just launch as

./hello_ws

and navigate your browser to localhost:8080

Last edited by truewar (2016-08-31 13:34:13)

Offline

#2 2016-08-31 13:32:41

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,523
Website

Re: WebStuff - C Library for Web Development

Cool project, thanks for sharing.  But I see you posted an https link, yet your software doesn't seem to handle SSL nor is your server listening on port 443.  Changing the link to http works.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#3 2016-08-31 13:35:37

truewar
Member
From: Czech Republic
Registered: 2016-08-30
Posts: 13
Website

Re: WebStuff - C Library for Web Development

Trilby wrote:

Cool project, thanks for sharing.  But I see you posted an https link, yet your software doesn't seem to handle SSL nor is your server listening on port 443.  Changing the link to http works.

Thank you!

I've just fixed the link. WebStuff has no SSL support at this moment, but it is possible to use it on frontend web server.
Lowenware.com is powered with nginx.

Offline

#4 2016-08-31 14:31:33

doomkin
Member
Registered: 2016-08-31
Posts: 1

Re: WebStuff - C Library for Web Development

It works! Compact, only 8920 bytes.

Offline

#5 2016-08-31 16:19:47

truewar
Member
From: Czech Republic
Registered: 2016-08-30
Posts: 13
Website

Re: WebStuff - C Library for Web Development

doomkin wrote:

It works! Compact, only 8920 bytes.

I try to keep it really lightweight.

Offline

Board footer

Powered by FluxBB