apache httpd extension help for special protocol - c++

I want to create a apache extension for my special protocol which listens on the same port as apache but on a specific directory or file like PHP. I need this to power my game with a custom server but not with PHP. I can't listen on a different port or different server.
I don't want to create a PHP file or something similar. I need a complete executable program where I can dynamically allocate memory etc. the program is completely outside of the apache server, but the apache 'passes-through' special requests to this program (for example the .foo files or the /foo/ directory.
I need a tutorial or a help to create a custom extension for apache.
UPDATE:
I want to create a daemon running in the background of my server, and then when apache sends a request, it forwarded this to my daemon, and then the daemon generates the request, and then send an answer. this is important that is not like a php script file or a perl because this is not executed once, the program is running all time, and waiting for the apache to send something. I don't know how to communicate with apache. But I think this is not a CGI, because if I read well, the CGI running is like: apache gets the request, and then START a new process for my php or perl file, sends the data through arguments and stdIN, and then when the process ends, reads the answer form the stdOut and send it back, the process then finished.
But my program still running. I need to run my program in the background all time because I need to store data in the memory which is loaded at startup.
like this.:
http://i53.tinypic.com/v45jzo.jpg

You don't need a special extension, just register a CGI handler that calls your processing code.
Edit
You can setup apache to proxy requests to your daemon.
You will need to return a properly formatted HTTP response or it wont work. You should read up on Apache and web based communications in general to get a better idea what is needed in your daemon.
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass /foo http://foo.example.com/bar
ProxyPassReverse /foo http://foo.example.com/bar
P.S. Writing an Apache extension is much more difficult an not portable.

To answer your second question about what CGI is
CGI stands for common gateway interface.
when you register a handler as Byron pointed out you tell apache to give the 'request' to your application. apache listens to the output stdout of your application and returns the result to the user.
The parameters for the application are all supplied via the environment which you can access from your application.
But if you don't understand this stuff you are going to run into problems. such as you must set certain headers.
DC

Related

Qt+wasm client-server communication

In Qt webassembly documentation there is a mention, than one can use QNetworkAccessManager for HTTP communication with the server that hosts my website. The problem is, that I can't hard-code URL for the server as it should be able to be deployed on any server. Is there a simple way to receive it somehow?
The problem is, that I can't hard-code URL for the server as it should be able to be deployed on any server. Is there a simple way to receive it somehow?
Yes. Your server program runs a QApplication, and the single instance of that class could get that URL.
In other words, you'll document that your C++ program (the executable file obtained by compilation, e.g. with GCC) foo would accept some --server-url argument, and you would start foo --server-url http://example.com/somestrangeurl/
Please notice that WebAssembly is often running inside Web browsers (that is, inside Web or HTTP clients). Most HTTP servers (e.g. lighttpd) are running on Linux OS (and you might use Wt or libonion or some other HTTP server library for them, if you have to code your HTTP server from scratch).

How to host CGI application?

Up to now i have tested hunchentoot-cgi(CL), mighttpd2(Haskell), ocsigen(OCaml), yaws(erlang) to host an old python CGI application. Except hunchentoot-cgi, all work great. I like Lisp-style programming, so i really want to host the application in a Lisp style web server.
In erlang, i just need to config it as below:
>cat ~/yaws.conf
...
<server 192.168.1.2>
port = 8000
listen = 0.0.0.0
docroot = /media/G/www/qachina/
access_log = false
appmods = <cgi-bin, yaws_appmod_cgi>
</server>
...
then the python CGI application can work.
How about Noir/Ring ?
Ring (and, consequently, Noir) is not a web server in the sense you seem to think. It is a framework for creating web applications. It does not provide access to external applications; rather it allows you to write your own dynamic web applications in Clojure. Then these applications can be deployed to standard Java servlet container or run manually using embedded Jetty web server.
It is of course possible to create such web application which would take an output of an external CGI program, process it and feed the results to the client, but you have to write all CGI processing by yourself (e.g. parse HTTP headers and construct standard Ring response map). As far as I know, there are no CGI wrappers for Ring stack.

c++ how to listen HTTP requests

Im new in C++.
I need to listen HTTP requests.
Please advice me some good tutorials or examples
Thanks
update:
Platform: Windows
Language: C++
I will explain more clearly what i need
when user clicks row on this page: http://ucp-anticheat.org/monitor.html applications is automatically starts on client machine.
I want to make same thing.
I think on client side is service which listens http requests and if url starts with steam:// service automatically runs application...
Do i need to listen http requests?
What is best solution for my problem?
You can listen to http requests through a web server like mongoose , which can be easily used in C++ http://code.google.com/p/mongoose/ , and here is a good example of using mongoose web server http://code.google.com/p/mongoose/source/browse/examples/hello.c
I m not sure what you mean 'client side', if you are meaning Browser as your client, you can't control nothing outside your browser. If you want to control a machine, you need your client machine to run your exe, that has the code to act based on your server instructions.
You should create a simple server program, create a SOCKET listening on default http, https etc, ports. Usually we do it inside a loop (at each one you make a read).
Now... would be easer if you specified if you are on Unix like OS or Windows, but from now on you can google it. Like sys/socket.h or try "man 7 socket" on almost all linux (at least the ones I know).
If you want to sniff something you can google some specific apps around web.
If i get your question right, you want to be able to launch an application when someone clicks a link with a custom protocol, like steam:// or telnet://. You are looking for an Protocol Handler.
A simple way to register such an application is using the ftype program, as described here.

How do I copy a file on a http server, from the client?

In the past I used an ftp server, connected via "ftp" from the client and "GET" to copy one file from the remote machine to the local machine.
Is it possible to do the same but with the server only running a http server?
Server: GoAhead Web Server.
Both client and http server on Windows.
The copy can be either initiated from the browser or if need a separate program can be written on the client. (i.e. - any windows api calls to copy a file from http server?)
(Also, the files may not be in the http root web directory but somewhere else on the server....can that happen?)
HTTP servers will only serve up files that are located within the site's document root. If you want to get at files that are outside the document root, you'll have to have a script serve up that file from the server (php, perl, cgi, etc...), or find some way of getting that file "inside" the document root.
To download files within the site's document root, you just hit a url pointing at that file - that's the core point of HTTP - you're just downloading content from the site.
HTTP servers will also not accept uploads without an intermediate script to handle it. If they did, you could upload any file you wanted to any server, anywhere.
What others mentioned about HTTP servers is true, but GoAhead Web Server is not a only a HTTP server. It provides many other features on top of that. And file upload seems possible, with help of a patch. More info:
https://embedthis.com/goahead/
Use WebDav for this purpose.

Is it possible to run Apache and IIS on the same machine with one IP-Address (and different ports ?)

The "main" one should be IIS. Is there an option to address the Apache without typing in the port-number
The reason for this is: I cannot get Django to work on IIS
Any ideas will be appreciated
You could set up Apache on a different port, then use redirects or proxying on IIS to get people to the Apache port without them having to type it.
The only way to avoid typing in the port number is to set up a proxy, which could be either one of the two webservers. That way, the proxy makes the connection on the alternate port and the client doesn't have to know where it is.
I don't know about IIS, but on Apache, you would have to load mod_proxy (and I think, mod_proxy_http) and then do something like this:
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass /foo http://foo.example.com/bar
ProxyPassReverse /foo http://foo.example.com/bar
Also check the docs for mod_proxy online.
You might also want to look at lightweight webservers such as lighttpd, if you're going to have two running. It's a common setup to have a light webserver taking specific tasks away from the main one. (Apache for dynamic and lighttpd for static content is one typical example).
There's also other possibilities, ranging from getting more fancy, such as
Have a third webserver doing only the proxying and the other two on alternate ports
Have them running on the same port but two IPs and hide that fact via your network setup
to attacking the root cause by either
finding somenone who knows how to get Django running on IIS
moving from IIS to another webserver
Of course, I have no clue what might be appropriate for your situation.
If this is a matter of running Django on a server that already needs IIS, you can run django on IIS directly, thanks to efforts like Django-IIS and PyISAPIe. I think it would be preferable to NOT run a second web server when all its going to be doing is proxying requests out to a third server, the Django code.