Apache mod_c++ wanted? - c++

I want to experiment a bit with C++ as a server side language. I'm not looking for a framework, and simply want to achieve a silly old "Hello World" webapp using C++.
Is there an Apache HTTP server module that I can install?
If i can do the PHP equivalent of :
<?php
$personName = "Peter Pan";
echo "Hello " . $personName;
I'd be most thrilled! Thanks in advance!

cgi would do this. Just have your C++ app spit its output to stdout and your mod_cgi will handle it

You might want to have a look at http://www.webtoolkit.eu/wt or www.tntnet.org instead.

"mod_c++" doesn't make sense; Once you're talking about compiled programs, Apache doesn't care what language the binary comes from. mod_cgi allows Apache to invoke such a binary (regardless of it's source language) in response to HTTP requests. Read more here:
http://library.thinkquest.org/16728/content/cgi/cplusplus.html

Suppose for the moment the OP wanted something that was "like mod_php, mod_perl". Given the right configuration, it would be monumentally easy for the "mod_c++" to look at the source files, and compiled files and decide whether it had to do a "one off" compilation task. In fact this is how make works.
I know the OP probably didn't mean that it had to be "interpreted", but it's certainly not impossible to allow apache to compile cpp files on the fly if needed [this is how jsp works, btw].

I did create a mod_cpp once. It basically was written in c, but loaded a .so which was in turn written in C++.
Its performance was really good, but lacked a lot of things that we take for granted in things like PHP (sessions, HTML un/escaping, etc). It did use a template engine to separate the HTML from the C++.
I tell you, the initial set-up was a lot of work (the mod_cpp part); after that, it was kinda easy to write the .so's. I even tried to create an sf.net project to open-source it, but I never got around to actually porting it :-(
In summary: I did not find anything like that on the net, did it myself and found out to be a lot more work then I anticipated, but the result was very cool! This helped me a lot: Apache Modules

I'm not saying there is no such thing, but if there is it would be monumentally inefficient. C++ is a compiled language, not an interpretive one, so the putative Apache C++ module would have to invoke the C++ compiler to compile the code before executing it. This would be very, very slow, apart from other problems.

Related

C++ Terminal-Output not one after another

I'm sorry if this question sounds a little childish, but I'm very new to C++ and console applications.
I recently wrote a HTTP1.1-Client to down/upload files. Everything works fine. The Problem is that there are quite a lot of logs to be output on the terminal and there is also the content of the remote host that should be print to the terminal. At the end of the application some of the output is not well formed - sometimes the order ist not right and sometimes the messages are just broken apart.
The application does not use multithreading and uses the libraries SPDLOG and FMT::FORMAT to output the data. The code is way to big to be put in here but if you'd anyway like to see it i can as well post it here.
I'd be thankful for every suggestion about what I might have done wrong and what the problem might be. Thanks!

Creating QR Codes with ColdFusion

Is there any way with pure ColdFusion/cfscript to produce a QR code, without relying on external APIs or JavaScript?
No. ColdFusion cannot generate bar codes by itself. You need a separate tool or library. It is easy enough to install a java library, like ZXing. Then generate the images from CF. Alternately, you could do a <cfhttp> call to an external server that generates the bar code image for you, or basically do the same thing with javascript. You would not need to install anything for the latter two (2) options. But they still rely on an external resource.
Bottom line you need something more than just ColdFusion. What is the reason you cannot use either an external API or javascript? Because without either of those, you are probably out of luck.
Edit based on comments:
If the only restriction is the images must generated locally, then you can use ZXing as described in the link above -OR- any of the other components/libraries mentioned in the other responses, like Joe's suggestion which uses iText (though also based on ZXing).
Some other external APIs
http://cfbarbecue.riaforge.org/
http://zanstra.com/my/Barcode.html?barcode=3PTSP8827A231
If you really wanted to, you could look up (perhaps you need to buy?) the encoding standard for QR codes, which I believe is an ISO standard. Then you could write a program which would output a table with the appropriate number of rows and columns, each with either a black or a white background. I wouldn't recommend this form of "rolling your own" though; it's a lot of work to do essentially what's been done before.
Tim Cunningham wrote a library that is hosted on Github that utilizes iText that does just this very thing. https://github.com/boltz/QRToad

Generating a C++ classes from IDL file using MICO (CORBA)

I wan to generate a C++ classes from a IDL file using MICO in the contxet of CORBA. I download the mico-2.3.13.zip but iI don't know how to use it. Please if someone can help me and thanks all.
The answer would probably be longer that would comfortably fit in a short reply, but here are some pages with helpful starter info.
This class webpage has a mini tutorial using mico
http://www.cs.wichita.edu/~chang/lecture/cs843/program/mico-idl.html
Here's another fairly simple tutorial page
http://people.inf.ethz.ch/roemer/micodoc/node16.html
You first need to compile MICO from the sources. Depending on your operating system and environment this will require different steps. In linux/mac os x they are basically calling the ./configure script and then make if it did not fail. Under windows I think that you can call nmake directly (with some options, read the README files).
After compilation completes (this may take a few minutes) and if everything goes fine, you should have the executables and can use them to create your own CORBA interfaces and services.

I want to show off my C++ projects through a website

The problem is that, well, it's C++. The way I've created them makes it such that they've always been run via a terminal/console window and wait for user input or else simply take a sample input and run with that. The output has also always been to the terminal screen or sometimes to a file. I'm not quite sure how I could take all of that and integrate it with a website while leaving the source code as it is, if that's at all possible. I guess what I'm trying to aim for is to have whatever website I use behave like a terminal window that will accept user input and then send it off to run the C++ program in question and return with the output (whatever it may be), all with minimal modification to the source code. Either that or else set up a more automated kind of page where a user can just click 'Go' and the program will run using a sample input.
When it comes to web I consider myself intermediate with HTML, CSS, PHP & MySQL, and a beginner with Javascript, so if this can be accomplished using those languages, that would be fantastic. If not, don't be afraid to show me something new though.
The easiest interaction model to bring to the web is an application that takes its input up front and produces its output on stdout. In this situation, as the unknown poster mentioned, you could use CGI. But due to the nature of CGI, this will only work (in the simplest sense) if all the information is collected from the user in one page, sent to the application and the results returned in one page. This is because each invocation of a page using CGI spawns a new indepdent process to serve the request. (There are other more efficient solutions now, such as FastCGI which keeps a pool of processes around.) If your application is interactive, in that it collects some information, presents some results, prints some options, collects some more user input, then produces more results, it will need to be adapted.
Here is about the simplest possible CGI program in C++:
#include <iostream>
int main(int argc, char* argv[])
{
std::cout << "Content-type: text/plain\n" << std::endl;
std::cout << "Hello, CGI World!" << std::endl;
}
All it does is return the content type followed by a blank line, then the actual content with the usual boring greeting.
To accept user input, you would write a form in HTML, and the POST target would be your application. It will be passed a string containing the parameters of the request, in the usual HTTP style:
foo.cgi?QTY=123&N=41&DESC=Simple+Junk
You would then need to parse the query string (which is passed to the program via the QUERY_STRING environment variable) to gather the input fields from the form to pass to your application. Beware, as parsing parameter strings is the source of a great number of security exploits. It would definitely be worthwhile finding a CGI library for C++ (a Google search reveals many) that does the parsing for you. The query data can be obtained with:
const char* data = getenv("QUERY_STRING");
So at a minimum, you would need to change your application to accept its input from a query string of name=value pairs. You don't even need to generate HTML if you don't want to; simply return the content type as text/plain to begin with. Then you can improve it later with HTML (and change the content type accordingly).
There are other more sophisticated solutions, including entire web frameworks such as Wt. But that would involve considerable changes to your apps, which you said you wished to avoid.
Almost off-topic, but you might want to take a look at Wt.
have you considered using cgi ... its 19th century technology which lets webserver execute programs written in C/C++ to run and generate output
I do not know much about it ... but I used it for some school projects
Show it all off with Screencasts. I use Camtasia Studio, but there are a ton of them out there: http://en.wikipedia.org/wiki/Screencast
Camtasia will even generate all of the HTML and Flash you need to upload to your web server. Buy a nice USB microphone, and write a script of what you're going to say and show.
What is the purpose of showing off your projects? Do you wish to impress your friends or employers?
It doesn't seem feasible to emulate or port your C++ console apps through a web interface.
I suppose you could write a bridge between a server side script and your C++ binary which passes the user input through to your app, then returns the result through the web interface. Bear in mind this would be a huge task for you to undertake.
Ruby have a compiler on their website which demonstrates this can be done.
However no one on the web would expect to run your C++ apps in a web browser. Also I think that anyone who is interested in running a C++ app would be totally comfortable with downloading a C++ binary that you made and running it (apart from the security risk) but when you think about it we download apps and run them all the time, whilst trusting the source.
I have a portfolio website which I created for the purpose of letting employers see my work. Take a look, it will give you an idea of another way you can do things.
Basically I provide the binaries for download, videos, screenshots and links. Things that the user can use to see my work quickly if they don't have time (or an appropriate computer) to run my projects on.
Good luck
I have no experience with this (other than hearing a guy on BART talk about implementing his server-side code all in C), but you might consider taking a look at SWIG (http://www.swig.org/). It allows you to wrap C++ so that you can access C++ code when using languages such as PHP.

What's the fastest way to determine a full URL from a relative URL (given a base URL)

I'm currently using the module URI::URL to generate a full URL from a relative URL; however, it isn't running as fast as I'd like it to be. Does anyone know another way to do this that may be faster?
Just happened across this article which point out shortcomings in Redhat/Centos/Fedora implementations of Perl which affect URI profoundly.
If you are running one of these Linux flavours, you might want to recompile Perl from original source (not RPM source).
I realized that anyone running perl code with the distribution perl interpretter on Redhat 5.2, Centos 5.2 or Fedora 9 is likely a victim. Yes, even if your code doesn’t use the fancy bless/overload idiom, many CPAN modules do! This google search shows 1500+ modules use the bless/overload idiom and they include some really popular ones like URI, JSON. ...
... At this point, I decided to recompile perl from source. The bug was gone. And the difference was appalling. Everything got seriously fast. CPUs were chilling at a loadavg below 0.10 and we were processing data 100x to 1000x faster!
The following code should work.
$uri = URI->new_abs( $str, $base_uri )
You should also take a look at the URI page on search.cpan.org.
Brendan, I should have clarified that I can't guarantee what the relative path is going to look like. It could be pretty tricky (e.g. has a slash at the front, doesn't have a slash, has "../", etc).
Peter, that's what I'm using now. Or is that faster then using the URI::URL->new($path)->abs?
Could depend a bit how you obtain those 2 strings. Probably the secure, fireproof way to do that is what is in URI::URL or similar libraries, where all alternatives, including malicious ones, would be considered. Maybe slower, but in some environments faster will be the speed of a bullet going to your own foot.
But if you expect there something plain and not tricky could see if it starts with /, chains of ../, or any other char. The 1st would put the server name + the url, the 2nd chop paths from the base uri till getting in one of the other 2 alternatives, or just add it to the base url.
Perhaps I got the wrong end of the stick but wouldn't,
$full_url = $base_url . $relative_url
work? IIRC Perl text processing is pretty quick.
#lennysan Ah sure yes of course. Sorry I can't help, my Perl is pretty rusty.