xbmc/xbmc — pull request #706 by Montellese (2012-02-19 11:15:06+00:00)
Title: webserver: decouple different webserver capabilities into handlers

These changes decouple different capabilities we built into our webserver (like HTTP API, JSON-RPC, VFS access etc) which are currently all handled in CWebServer::AnswerToConnection(), into different classes called handlers which all implement the same interface IHTTPRequestHandler. This makes it a lot easier to maintain those different handlers without having to fear that changing something in one of them affects the behaviour of one of the other handlers (which is currently possible). Most webservers (like Apache HTTPd etc) use handlers to allow to extend them without having to mess around with the webserver implementation itself.

The whole handler-system is based on registering the existing handlers (with a priority) in the CWebserver instance. Then everytime a new HTTP request comes through libmicrohttpd the webserver works through the list of the registered handlers and calls IHTTPRequestHandler::CheckHTTPRequest() which will return whether this handler wants/is able to handle the current request. If that's the case a new instance of that specific handler is requested (because HTTP requests are handled in different and possibly concurrent threads) and then the webserver lets the handler do with the request whatever he wants by calling IHTTPRequestHandler::HandleHTTPRequest(). It then waits for that method to finish and then retrieves the HTTP response code and the data of the response from the instance before destroying it and sending the HTTP response to the requester.

IMO this will also make it easier to add new functionality (e.g. the image resizing posted in PR #92). Based on this work I have also started implementing a handler which will be able to execute python scripts through our webserver (which would allow more powerful webinterfaces for XBMC).

I have tested these changes on win32 and linux (ubuntu) but it's not tested on osx and requires changes to osx/ios project files.