views:

2129

answers:

13

I've searched the web a bit, but all I found was abandoned projects and only CGI support.

EDIT: C isn't just used for writing drivers or embedded systems. We have mailreaders, newsreaders, editors, etc. all written in C. I've written two BBS in the last century, before the web became popular. The libraries are getting better and you don't have to reinvent the wheel over and over again. Nice data structures and string handling is easily possible in C. But yet, there's not much going on in web development.

I'd like to come back to my roots and try to write web applications in C.

As for bad languages: People use C++, Perl, and PHP for web applications. It doesn't stop them that the common perception of these language isn't very good.

EDIT 2: I've written BBS software in C and nobody thought this was a crazy idea, although others have done it in GfA BASIC back then. I don't understand why today it should be considered a bad idea. Have a look at the software you are using or the most common programming languages in open source software.

A: 

I am not sure of a library, but if you could visit this site vijaymukhi.com you could find some learning projects developed using C.

You can specifically check the "Air Ticket Reservation" and "Ecommerce Modules".

NOTE: This is only a learning projects with c and cgi.

Please check the "Projects(with source)" section on the treemenu.

P.S: I don't recommend this for production/live sites.

rajesh pillai
A: 

Why would you want to do that?

EDIT: The reason for answering a question with another question here is that the OP must either be masochistic or confused about the merits and disadvantages of C or he must have very specific requirements he hasn't told us about. Assuming the latter, this question might help us discover the real problem behind his question (such as "How can I write a web app that will run on my wrist watch?") and give him better advice.

Kim
I didn't downvote, but you should probably have posted your question as a comment in the original question.
RossFabricant
A: 

Unless you have a very specific requirement to use C, you should probably rethink your language choice. Even with a framework (which as you've noticed, are hard to come by these days), a webapp in C is likely to be very error-prone, especially to buffer overlows related to untrusted user input.

If you have some SDK or legacy code in C that you need to access, and no alternative but to use it, you can still get at this in various ways from another language.

For example in Java there is JNI. And you can always wrap the SDK in a CLI program that does what you need, and run it from your webapp (which can then be written in any language). The same caveats about buffer overflows etc will apply, but at least you can program defensively in the CLI program (i.e. don't trust your arguments and sanitize them before using).

Another alternative may be to use IPC to a process which provides access to the 'C' SDK or legacy code functions. Same arguments about defensive programming apply.

frankodwyer
+5  A: 

As others have noted C is not the best language for developing a web application. However, if the application's core is already written in C, AND you are ok with only a single user accessing the application at the time, AND you can trust that user (for instance, because the application will only be made available behind a firewall), then the swill library is an interesting choice. It is an embedded web server, which with a handful of lines can provide a web interface to any C application. I've used it twice, for the CScout refactoring browser and for providing a user interface to legacy production line optimization code, and it worked like a charm.

Diomidis Spinellis
A: 

It is hard to think of any situation where C is the best language to develop a web app. Just as you wouldn't want to write a GUI app in FORTRAN or a device driver in COBOL.

Why not try PHP? The syntax is fairly similar to C.

Andy Brice
To some extend the question always could have been. Why C, to ask this now just neglects the fact that every current OS in wider use was written in C, and every database was written in C. So C still has it's place....
Friedrich
Yes, C has it's place. But not for web apps.
Andy Brice
Well it's your right to decide so but: have you tried C for web apps?Every language was used for web development and so I bet that quite a few older pages have use C-CGI programs, and it probably has worked well for them
Friedrich
A: 

Well, years ago I wrote a "CSP" compiler, a very basic equivalent to JSP, but in C. It generated CGI C code. I guess you could use THAT as a base or for simple experimentation. I never did anything with it so you can have it if you want (and if I can find it)... just drop me a line.

ggambett
+3  A: 

clearsilver should do the job fine http://www.clearsilver.net/docs/

and if you need some GC stuff you always can use the boehm weisser gc.

Regards Friedrich

Friedrich
On the first look clearsilver only offers CGI. But there are flexible hooks and a (broken) example how to use it with FastCGI. Looks usable to me.
stesch
+2  A: 

In addition to Swill, I would look at GNU libmicrohttpd and Hughes libhttpd. Both are intended to embed web servers in programs. I was nearly deciding on Hughes for a web frontend of sorts for Berkeley DB but may go the Python route instead.

Jakob Eriksson
A: 

Why not convert your legacy C code into a php / apache plugin? Then you've got the best of both worlds, modern web based language / server but utilising all the existing code in your legacy application.

Mark Ingram
There is no legacy C code.
stesch
Then my advice is definately not to bother using C/C++ to develop a web app. There are much better languages and frameworks you can use.PHP is a good suggestion as it's syntax is similar to C/C++. However C# / ASP.NET might be better for you.
Mark Ingram
I already used Perl, Java, PHP, Ruby, Python, etc. for web development.
stesch
+1  A: 

I haven't tried it, maybe someone would find it usefull: klone. It is a framework for building standalone web serververs and html templating with embedded C.

+3  A: 

I've used GNU libmicrohttpd and it is excellent: clear API; lightweight; open source and still actively developed; and it embedded nicely into our existing C application. Importantly, it is licensed under the LGPL, but Hughes libhttpd has a dual license, which may be an issue for commercial projects. (Credit to Jakob Eriksson's answer for getting there first.)

Edit: Also mentioned here.

sblair
+1  A: 

You could try libevent. It has a HTTP server.

I read on the HTTP server in libevent, but there doesn't seem an easy (or well documented) to access the fields of a POST request.
stesch
A: 

Ignore the naysayers that say that C is not acceptable or advisable. The assumption that they make is that they are writing your application. This can be a good learning experience for you.

C has some very specific advantages over other modules. You can easily write a framework for it that does a lot of the heavy lifting for your application, without too much effort.

The danger is the safety and sanity of your code. The advice that I have is to try Django or Rails and see how they 'do it', then take the best of their ideas back to C.

Your development time may be "slower", but on the other hand you will have intimate knowledge of your stack and framework.

Wade Mealing