Project Glib: it compiles ... mostly 12

Posted by jan Tue, 19 Feb 2008 17:14:00 GMT

Part of my ongoing, hidden effort to port lighttpd to glib I can now at least say: it compiles.

Well, mostly. The core does compile and mod_staticfile is also mostly done. Mostly, as I don’t have decided on how to handle the config-file handling yet.

So, what has been done so far:

  • buffer.c and buffer.h are gone and are replaced by GString
  • array.c is gone and is replace by GHashTable or GPtrArray
  • array.h will vanish when the data_…c goes away
  • log.c is now a wrapper around g_log_…

As you see this is ripping out the basic data-structures and replaces them by a glib look-alike.

This isn’t just a drop-in replacement as the structures use other field-names and sometimes have a slightly different meaning.

One example is GString vs. buffer:

buffer {
  char *ptr;
  size_t used;
  size_t size;
};

GString {
  char *str;
  size_t len;
  size_t allocated_len;
};

While str and ptr, and allocated_len and size match, used and len differ by one byte (used includes the NUL-byte, len doesn’t).

One side-effect of this boring work is seeing the code-size shrinking, piece by piece.

Seeing old, sometimes dirty code vanish is another nice side-effect. Like the log_error_write() call … man …

Weekends Projects: lua as config-language 16

Posted by jan Sat, 09 Feb 2008 23:09:00 GMT

With the first implementation of mod_cml and later mod_magnet smart users asked why we don’t use lua also as config language for lighttpd.

Up to now I was pushing back and saying that a huge change in the configfile would make upgraders very unhappy as they would have to rewrite the config files. Looking at what we have for 1.5.0 right now, we need tweaks anyway.

This always happens if you rip a thing apart: you see more things that should be cleaned up. My first experiments are a bit done:

server = {
        name = "my.example.org",
        modules = {
                "mod_indexfile" 
        },
        ["errorfile-prefix"] = "foobar",
}

sockets = {
        [":80"] = {
                server = { name = "foo.example.org" },
                HTTP = { url = function(url)
                        if url == "foo" then
                                server.name = "baz.example.org" 
                        end
                end },
        }
}

sockets[":80"].HTTP.url("foo")
print(server.name)

This is a first idea. It shows how the LUA syntax isn’t sooo different from our current config syntax.

  • The global variables, stay global as now.
  • socket conditionals is now a simple array of sockets
  • conditionals are functions, now you can do what you want with it

I hope that I can handle the full config syntax into this structure. For now it is looks more appealing that ripping the old config-parser code apart and turn it into glib-notation. With all the conditionals and types we basicly have implemented our own scripting language.

Let’s see where this leads too.

Weekend Projects: killing buffer.c and array.c 8

Posted by jan Sat, 09 Feb 2008 08:46:00 GMT

As part of a weekend project I’m ripping 1.5 apart a bit. I worked with glib for quite some time now and feel the need to replace the base-structures around “buffer” (strings) and “array” (hash) apart and replace it with the glib counter-parts.

To make this a nice experience and that I don’t harm anyone else I imported trunk into a local bzr tree:

bzr clone svn://svn.lighttpd.net/lighttpd/

to clone the SVN tree.

Let’s see how well that experiment goes.