LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Web lacking C cgi examples/documentation (http://www.linuxquestions.org/questions/programming-9/web-lacking-c-cgi-examples-documentation-4175413528/)

errigour 06-26-2012 04:13 PM

Web lacking C cgi examples/documentation
 
I have searched the web for cgi documentation and examples in c and found very little and I was hoping someone could post some in depth examples on cgi programming or maybe direct me to cgi documentation for C. I can multiply post method get variables and I can Create a page that says hello world.

Nominal Animal 06-26-2012 09:26 PM

The qDecoder library has some useful examples, and it supports just about everything including file uploads. It is also in the public domain, so you can use it in any project you like.

The Common Gateway Interface itself is specified in RFC 3875, I believe, but all implementations (like Apache mod_cgi and mod_cgid) have their differences or extensions, and do behave a bit differently on Windows than on sane OSes, so you'd better rely on that documentation -- and experimentation.

A decade ago the libraries were chock full of fixes for browser bugs. Especially Internet Explorer POST data tended to be all kinds of wonky. I'm not up to date on this, but I'd guess things have stabilized a lot. To really find out, you'd have to dive into e.g. PHP sources, and look at the POST data parsing to see if there are still workarounds applied to browser bugs.

If you are thinking about using C for CGI programming, I'd recommend you pretty quickly move on to FastCGI, perhaps using Apache mod_fcgid. It can provide much higher performance in high-load cases. FastCGI is a separate protocol to CGI, and has some important differences. For example, each process can/should respond to multiple (unrelated) queries, instead of existing only to serve one request. The approach is different.

After a quick search, I only found fastcgi C++ library (download), plus the old devkit at fastcgi.com (but check the license terms first).

Currently, programming languages like Python tend to be fast enough to be used for very high volume sites, especially if using FastCGI, so C/C++ CGI/FastCGI programming is a rare thing. Personally, I've considered writing an efficient image upload tool that would use a dedicated user account and automatically generate thumbnail versions of the image -- but it turns out using Python or even PHP via mod_fcgid+SuEXEC makes more sense in the long term. One must consider the maintenance effort needed, too.

I might re-examine that if I ever work with an embedded device with say Nginx, and need a reliable, small-footprint uploader without a full scripting language installation -- but otherwise I think I'll use Python for something like this.

Hope this helps,

errigour 06-27-2012 07:14 AM

Hey thanks, Anything helps.


All times are GMT -5. The time now is 12:13 AM.