You are not logged in.

#1 2010-07-30 17:34:28

manzinger
Member
Registered: 2009-11-11
Posts: 26

CMS written in C?

Hi

Is it possible to write a CMS (content management system) in pure C? How would the best way to approach it?
I'm a C beginner and thought this would be a nice project to enhance my C skills.
The CMS should be as simple as possible. My webserver is lighttpd.
Any advice is welcome.

Offline

#2 2010-07-30 17:39:46

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: CMS written in C?

I'm not a dev, but maybe you should start with simpler tasks: a clock, a calculator, calendar - you can combine them into your CMS one day.

Offline

#3 2010-07-30 20:29:30

j.roszk
Member
From: Poznan/Poland
Registered: 2008-05-22
Posts: 29
Website

Re: CMS written in C?

I think you may end up with a realization of Greenspun's Tenth Rule. In this particular case you can replace Common Lisp with PHP smile

But you asked for advice. I would try to implement some kind of static HTML page generator + curses or gui based progam to fill database records with data. If you need anything to be displayed dynamically (e.g. visitor counter) you can generate PHP code and run it every time through the interpreter with lighthttpd. Later on you can replace it with custom CGI script and generate everything on the fly.

If I were you I would use a different tool for the job.

Last edited by j.roszk (2010-07-30 20:36:59)

Offline

#4 2010-07-31 09:02:27

simlan
Member
From: Germany
Registered: 2010-05-30
Posts: 20

Re: CMS written in C?

I would not try that with C. C is ~portable compiler things like webservers are written with it but you would have to implement many old wheels that alredy exists for other languages.

Offline

#5 2010-07-31 12:11:33

manzinger
Member
Registered: 2009-11-11
Posts: 26

Re: CMS written in C?

you're probably right. I just found this: http://sourceforge.net/projects/damn-small-cms/
but it seems to be abandonded for years with the code no longer available.

I also found that this guy obviously has his own C CMS, but it's not open source:  http://blog.fefe.de/faq.html
but he also wrote his own webserver and some custom libs for it, which is way beyond my understandings yet.

Offline

#6 2010-07-31 12:14:40

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: CMS written in C?

manzinger wrote:

you're probably right. I just found this: http://sourceforge.net/projects/damn-small-cms/
but it seems to be abandonded for years with the code no longer available.

I also found that this guy obviously has his own C CMS, but it's not open source:  http://blog.fefe.de/faq.html
but he also wrote his own webserver and some custom libs for it, which is way beyond my understandings yet.

This guy attempted to write a replacement for glibc IIRC so he's not quite a newbie. It should tell you loud and clear that writing a cms in C in not a sport for the meek.

Offline

#7 2010-08-01 13:17:06

tindzk
Member
Registered: 2010-05-10
Posts: 25
Website

Re: CMS written in C?

Interesting topic. I've also been experimenting with web applications in C and it's not as difficult as it might sound. However, all you need is a library which does a great deal of effort to prevent common errors problems like buffer overflows. As soon as more your design gets more and more complex, a template engine becomes indispensable.

But most importantly, you have to ensure that your code is well-structured. For my projects, I am using radical concepts to enforce an object-oriented approach:

1) A .c file always contains a class.
2) Methods must be implemented like this: Class_Method(Class *this, String var1, String var2)
3) Each class must have a constructor, Class_Init(...), and may have a destructor, Class_Destroy().
4) Namespaces must be used for all libraries and may be used for the application itself.

I always separate the web code from the library code. The web interface is where you interact with the user, whereas in the library, you're processing the data. It's important to make this distinction because it makes your code much cleaner and more debuggable (Writing test cases for web interfaces is far more difficult than just calling a function for doing the same.)

Function names can get very long. That's why I don't use namespaces in the applications. But the libraries should have a namespace because most functions in the web interface are actually called after a library function which could lead to conflicts otherwise.

Ok, this sounds very theoretical, so here's a real-life example: I'm currently working on a news crawler completely written in C.

It has a console interface which checks some websites and downloads news to disk which doesn't appear in the index yet.

There's also a web interface which uses the same library as the console interface. Hence, no code duplication. It can query the local archive or just query the websites in real time.

The web interface consists of resources. A resource is defined at the end of a file, e.g.:

ResourceInterface Listing_Methods = {
    .isRequested      = (void *) Listing_IsRequested,
    .new              = (void *) Listing_New,
    .init             = (void *) Listing_Init,
    .destroy          = (void *) Listing_Destroy,
    .onHeader         = NULL,
    .onQueryParameter = (void *) Listing_OnQueryParameter,
    .onBodyParameter  = (void *) Listing_OnBodyParameter,
    .setPath          = (void *) Listing_SetPath,
    .onRequest        = (void *) Listing_OnRequest
};

The isRequested method compares the path and returns true when the resource matches. Each resource can even accept multiple paths, e.g.:

bool Listing_IsRequested(String path) {
    return String_BeginsWith(path, $("/category"))
        || String_BeginsWith(path, $("/archive"))
        || String_BeginsWith(path, $("/list"));
}

A resource may also have a function for extracting parts from the URL. Here's one I'm using:

void Listing_SetPath(Listing *this, String path) {
    StringArray *parts = String_Split(path, '/');

    if (String_Equals(parts->buf[1], $("list"))) {
        this->path.type = Spider_ArticleType_List;

        this->path.u.list = HeapString(0);

        if (parts->len > 2) {
            this->path.u.list = String_Clone(parts->buf[2]);
        }
    } else if (String_Equals(parts->buf[1], $("archive"))) {
        this->path.type = Spider_ArticleType_Archive;

        this->path.u.archive.provider = HeapString(0);
        this->path.u.archive.month    = HeapString(0);

        if (parts->len > 2) {
            this->path.u.archive.provider = String_Clone(parts->buf[2]);

            if (parts->len > 3) {
                this->path.u.archive.month = String_Clone(parts->buf[3]);
            }
        }
    } else if (String_Equals(parts->buf[1], $("category"))) {
        this->path.type = Spider_ArticleType_Category;

        this->path.u.category = Spider_Category_Unset;

        if (parts->len > 2) {
            this->path.u.category = Spider_Category_Resolve(parts->buf[2]);
        }
    }

    Array_Destroy(parts);
}

It might look very lengthy but it's actually covering a lot of cases. I wouldn't even know how to do the same with regular expressions.

This will work for:

/list
/list/To Read
/archive
/archive/Guardian
/archive/Guardian/2010-08
/category
/category/Health

As you can see, it's all actually very readable. Of course, you could also use a router and regular expressions for all these things. It's a matter of taste but I like it better to have everything together. I don't want these things scattered over the whole project while they can be encapsulated.

Screenshot: 201008011541401280x800s.png

tim@tim-laptop /Projects/Spider/Web $ du -h httpd.bin 
1,2M    httpd.bin

The whole application, with HTTP server and all necessary libraries built in weighs only 1.2 MiB! No need for any third-party libraries or runtimes.

I can highly recommend it to anyone. Writing websites in C will be a bit different from what we're used to but it also offers a great flexibility. With the right compiler and some tricks, you can make things nearly as comfortable as in Python or Ruby. What's even more worthwhile is the learning effect: You'll start thinking completely differently about solving problems helping you to write faster and more secure applications.

Last edited by tindzk (2010-08-01 13:50:23)

Offline

#8 2010-08-01 13:29:48

xenobrain
Member
From: Lodi, CA
Registered: 2006-05-31
Posts: 91

Re: CMS written in C?

Wt is a very C++-ey web framework, so it's not quite what you're looking for. 

It sure looks interesting though.

I'm currently looking for a framework to use for a project I'll be starting soon and this looks mighty tempting as by far most comfortable with C++/Qt than any other language or framework.

Offline

#9 2010-08-01 18:44:46

tavianator
Member
From: Waterloo, ON, Canada
Registered: 2007-08-21
Posts: 858
Website

Re: CMS written in C?

tindzk wrote:

Interesting topic. I've also been experimenting with web applications in C and it's not as difficult as it might sound. However, all you need is a library which does a great deal of effort to prevent common errors problems like buffer overflows. As soon as more your design gets more and more complex, a template engine becomes indispensable.

But most importantly, you have to ensure that your code is well-structured. For my projects, I am using radical concepts to enforce an object-oriented approach:

1) A .c file always contains a class.
2) Methods must be implemented like this: Class_Method(Class *this, String var1, String var2)
3) Each class must have a constructor, Class_Init(...), and may have a destructor, Class_Destroy().
4) Namespaces must be used for all libraries and may be used for the application itself.

Um..., any reason not to use C++ if you're this into a strictly object-oriented approach?

Offline

#10 2010-08-01 19:49:55

tindzk
Member
Registered: 2010-05-10
Posts: 25
Website

Re: CMS written in C?

tavianator wrote:

Um..., any reason not to use C++ if you're this into a strictly object-oriented approach?

I've actually tried to learn C++ but it turned out that this language is far too complicated. A glimpse at Boost shows its utter complexity.

Interestingly, I make a lot more mistakes in C++ than in C. Hence, for me it's less productive.

C is WYSIWYG; I have the complete control over what the program does. There are no silly type-dependent ambiguities like the 'equal' operator.

C++ is incompatible to C; I'd have to insert lots of #ifdefs to make my headers C++-compatible. Why? Shouldn't it be the other way round?

Compiling C++ takes much longer than C. I don't know why but it's annoying.

Even people like Torvalds to whom I'd attribute a certain expertise share my opinion about C++. Are they all wrong?

In a Lisp discussion, I can remember someone calling C a 'lingua franca'. I think that's an excellent comparison. Sure, even C++ will be still written in a few years but C is the basis for all major operating systems. It's used almost exclusively in embedded systems.

Why should I be using C++ apart from OO? I want a transparent, fast and simple language. C++, I'm afraid, doesn't comply with my requirements.

Offline

#11 2010-08-01 20:21:54

Pajaro
Member
Registered: 2004-04-21
Posts: 884

Re: CMS written in C?

I would have a look at this:
http://www.boutell.com/cgic/

Offline

#12 2010-08-01 22:23:42

saline
Member
Registered: 2010-02-20
Posts: 86

Re: CMS written in C?

tindzk wrote:
tavianator wrote:

Um..., any reason not to use C++ if you're this into a strictly object-oriented approach?

...snip...

Any reason not to use C while you're using C?  If you're going to use OOP, why not just use that little part of C++?  The #ifdefs are almost nothing.

Offline

#13 2010-08-01 22:28:35

ablepharus
Member
From: Berlin
Registered: 2010-05-23
Posts: 129

Re: CMS written in C?

I can really recommend tntnet (http://tntnet.org) it's a full webserver written in C++  with a very smart usage (php-like) http://tntnet.org/exampleCalc.html

Offline

#14 2010-08-02 12:35:44

tindzk
Member
Registered: 2010-05-10
Posts: 25
Website

Re: CMS written in C?

saline wrote:

Any reason not to use C while you're using C?  If you're going to use OOP, why not just use that little part of C++?  The #ifdefs are almost nothing.

Sure, writing a few #ifdefs is not much effort but why do I have to "fix" my C headers just to make them C++ compatible? It's a tedious task and I wouldn't ever want to do it for a larger code base.

Even though using the OO subset of C++ sounds seductive, there are yet too many differences (cf. http://nothings.org/computer/cpp.html) and incompatibilities between C++ and C to make programming in it a pleasant experience.

Last edited by tindzk (2010-08-02 12:37:39)

Offline

#15 2010-08-02 22:29:34

saline
Member
Registered: 2010-02-20
Posts: 86

Re: CMS written in C?

tindzk wrote:
saline wrote:

Any reason not to use C while you're using C?  If you're going to use OOP, why not just use that little part of C++?  The #ifdefs are almost nothing.

Sure, writing a few #ifdefs is not much effort but why do I have to "fix" my C headers just to make them C++ compatible? It's a tedious task and I wouldn't ever want to do it for a larger code base.

Even though using the OO subset of C++ sounds seductive, there are yet too many differences (cf. http://nothings.org/computer/cpp.html) and incompatibilities between C++ and C to make programming in it a pleasant experience.

Touche.

Offline

#16 2010-08-03 04:32:46

tavianator
Member
From: Waterloo, ON, Canada
Registered: 2007-08-21
Posts: 858
Website

Re: CMS written in C?

tindzk wrote:
saline wrote:

Any reason not to use C while you're using C?  If you're going to use OOP, why not just use that little part of C++?  The #ifdefs are almost nothing.

Sure, writing a few #ifdefs is not much effort but why do I have to "fix" my C headers just to make them C++ compatible? It's a tedious task and I wouldn't ever want to do it for a larger code base.

Even though using the OO subset of C++ sounds seductive, there are yet too many differences (cf. http://nothings.org/computer/cpp.html) and incompatibilities between C++ and C to make programming in it a pleasant experience.

Because C++ isn't strictly backward-compatible with C?  For the record, here's all I had to do for my ~10,000 line raytracer's headers: http://gitorious.org/dimension/dimensio … n.h#line54

Anyway, I was in no way suggesting that C++ is somehow better than C.  All I meant was that forcing the OO paradigm that strictly on your C code makes no sense, as C isn't an OO-paradigm language.

Sorry for getting so off topic, I'll go now wink

Offline

#17 2010-10-17 08:09:34

manzinger
Member
Registered: 2009-11-11
Posts: 26

Re: CMS written in C?

sorry, for bringing this old thread up again, but I now found a project others may also be interested in:

http://cppcms.sourceforge.net/wikipp/en/page/main

a web framework written in c++

they also published a benchmark to compare it to perl/python/PHP CMSs, which is pretty impressive:
http://art-blog.no-ip.info/cppcms/blog/post/67

Offline

#18 2010-10-17 08:33:25

Dieter@be
Forum Fellow
From: Belgium
Registered: 2006-11-05
Posts: 2,001
Website

Re: CMS written in C?

you could also create a basic webpage in php, compile it with hiphop to C++ and go further from that


< Daenyth> and he works prolifically
4 8 15 16 23 42

Offline

#19 2010-10-17 13:35:41

manzinger
Member
Registered: 2009-11-11
Posts: 26

Re: CMS written in C?

Dieter@be wrote:

you could also create a basic webpage in php, compile it with hiphop to C++ and go further from that

thanks I never heard of this before. I didn't know facebook contributed something for the open source community.

Offline

#20 2010-10-17 13:55:29

Dieter@be
Forum Fellow
From: Belgium
Registered: 2006-11-05
Posts: 2,001
Website

Re: CMS written in C?

manzinger wrote:
Dieter@be wrote:

you could also create a basic webpage in php, compile it with hiphop to C++ and go further from that

thanks I never heard of this before. I didn't know facebook contributed something for the open source community.

seriously? they contribute a *lot*


< Daenyth> and he works prolifically
4 8 15 16 23 42

Offline

#21 2010-10-20 12:55:00

gbarnett
Member
Registered: 2010-09-28
Posts: 7

Re: CMS written in C?

C is really not particulalry well matched for a CMS, particularly a web-based CMS. If you are looking to tone your C skills then I suggest you just download the kernel source code and peruse it for a while looking up certain things that confuse you (there will be many) and then possibly hack on it. For web stuff you have a plethora of languages at your disposal: PHP, Ruby (on Rails), Java, etc... However, there is nothing stopping you from writing the high performance bits in C and then interoperating with them via one of the aforementioned languages.

Offline

#22 2010-10-28 15:00:22

kaizoku
Member
Registered: 2009-01-09
Posts: 62

Re: CMS written in C?

You might want to look at fcgi which is about 5 times faster than cgi, you can use existing webserver such as nginx or cherokee.

Offline

#23 2012-01-07 22:37:00

idaunis
Member
Registered: 2012-01-07
Posts: 1

Re: CMS written in C?

BinaryTiers uses a very simple C syntax. It might be used in any scenario where you need Content Management, from basic web applications to complex social networking websites :

http://www.binarytiers.org

Offline

#24 2012-01-08 05:44:04

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 19,797

Re: CMS written in C?

This thread is over a year old.  I am going to close this thread in accordance with our policy

If anyone is experiencing an issue, please feel free to start a new thread and reference this thread.  That way, we can keep old information from muddying the waters of contemporary issues.


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

Board footer

Powered by FluxBB