WebRequestHandler Class Reference

This class is responsible for processing requests that come to the user interface. More...

#include <web_request_handler.h>

Inheritance diagram for WebRequestHandler:
RequestHandler zmm::Object web::action web::add web::addObject web::auth web::autoscan web::containers web::directories web::edit_load web::edit_save web::files web::items web::remove web::tasks web::voidType

Public Member Functions

 WebRequestHandler ()
 Constructor, currently empty.
virtual void get_info (IN const char *filename, OUT struct File_Info *info)
 Returns information about the requested content.
virtual zmm::Ref< IOHandleropen (IN const char *filename, OUT struct File_Info *info, IN enum UpnpOpenFileMode mode)
 Decodes the parameters from the filename (URL) and calls the internal open() function.
virtual void process ()=0
 This method must be overriden by the subclasses that actually process the given request.
void retain ()
void release ()
int getRefCount ()

Static Public Member Functions

static zmm::String buildScriptPath (zmm::String filename)
 builds full path to a script for the given relative filename
static void split_url (const char *url, char separator, zmm::String &path, zmm::String &parameters)
 Splits the url into a path and parameters string. Only '?' and '/' separators are allowed, otherwise an exception will be thrown.
static void * operator new (size_t size)
static void operator delete (void *ptr)

Protected Member Functions

zmm::String param (zmm::String name)
 Little support function to access stuff from the dictionary in in an easier fashion.
int intParam (zmm::String name, int invalid=0)
bool boolParam (zmm::String name)
void check_request (bool checkLogin=true)
 Checks if the incoming request is valid.
zmm::String renderXMLHeader ()
 Helper function to create a generic XML document header.
zmm::Ref< IOHandleropen (IN enum UpnpOpenFileMode mode)
 Prepares the output buffer and calls the process function.
void addUpdateIDs (zmm::Ref< mxml::Element > root, zmm::Ref< Session > session)
 add the ui update ids from the given session as xml tags to the given root element
void handleUpdateIDs ()
 check if ui update ids should be added to the response and add them in that case. must only be called after check_request
void appendTask (zmm::Ref< mxml::Element > el, zmm::Ref< GenericTask > task)
 add the content manager task to the given xml element as xml elements
bool accountsEnabled ()
 check if accounts are enabled in the config
zmm::String mapAutoscanType (int type)
int remapAutoscanType (zmm::String type)

Protected Attributes

bool checkRequestCalled
zmm::Ref< Dictionaryparams
 Decoded URL parameters are stored as a dictionary.
zmm::String filename
 The original filename from url if anyone needs it.
enum UpnpOpenFileMode mode
 We can also always see what mode was requested.
zmm::Ref< zmm::StringBufferout
 This is filled during request processing and holds the output.
zmm::Ref< mxml::Elementroot
 This is the root xml element to be populated by process() method.
zmm::Ref< Sessionsession
 The current session, used for this request; will be filled by check_request().
mt_atomic_t _ref_count
pthread_mutex_t mutex

Detailed Description

This class is responsible for processing requests that come to the user interface.

Definition at line 56 of file web_request_handler.h.


Constructor & Destructor Documentation

WebRequestHandler::WebRequestHandler (  ) 

Constructor, currently empty.

Definition at line 48 of file web_request_handler.cc.

References checkRequestCalled, and params.


Member Function Documentation

bool WebRequestHandler::accountsEnabled (  )  [inline, protected]

check if accounts are enabled in the config

Returns:
true if accounts are enabled, false if not

Definition at line 126 of file web_request_handler.h.

References CFG_SERVER_UI_ACCOUNTS_ENABLED, and Singleton< ConfigManager >::getInstance().

Referenced by web::auth::process().

void WebRequestHandler::addUpdateIDs ( zmm::Ref< mxml::Element root,
zmm::Ref< Session session 
) [protected]

add the ui update ids from the given session as xml tags to the given root element

Parameters:
root the xml element to add the elements to
session the session from which the ui update ids should be taken

Definition at line 280 of file web_request_handler.cc.

References _, zmm::String::c_str(), log_debug, mxml::mxml_bool_type, and string_ok().

Referenced by handleUpdateIDs().

void WebRequestHandler::appendTask ( zmm::Ref< mxml::Element el,
zmm::Ref< GenericTask task 
) [protected]

add the content manager task to the given xml element as xml elements

Parameters:
el the xml element to add the elements to
task the task to add to the given xml element

Definition at line 292 of file web_request_handler.cc.

References _, mxml::mxml_bool_type, mxml::mxml_int_type, and nil.

Referenced by open(), and web::tasks::process().

bool WebRequestHandler::boolParam ( zmm::String  name  )  [protected]

Definition at line 63 of file web_request_handler.cc.

References param(), and string_ok().

Referenced by web::autoscan::process().

static zmm::String WebRequestHandler::buildScriptPath ( zmm::String  filename  )  [static]

builds full path to a script for the given relative filename

void WebRequestHandler::check_request ( bool  checkLogin = true  )  [protected]

Checks if the incoming request is valid.

Each request going to the ui must at least have a valid session id, and a driver parameter. Also, there can only by a primary or a a decondary driver.

Definition at line 69 of file web_request_handler.cc.

References _, checkRequestCalled, Singleton< SessionManager >::getInstance(), nil, param(), session, and sid.

Referenced by web::voidType::process(), web::autoscan::process(), web::tasks::process(), web::remove::process(), web::items::process(), web::files::process(), web::edit_save::process(), web::edit_load::process(), web::directories::process(), web::containers::process(), web::auth::process(), web::addObject::process(), web::add::process(), and web::action::process().

void WebRequestHandler::get_info ( IN const char *  filename,
OUT struct File_Info info 
) [virtual]

Returns information about the requested content.

Parameters:
filename Requested URL
info File_Info structure, quite similar to statbuf.

We need to override this, because for serving UI pages (mostly generated from dynamic XML) we do not know the size of the data. This is of course different for the FileRequestHandler, where we can check the file and return all information about it.

Implements RequestHandler.

Definition at line 96 of file web_request_handler.cc.

References _, zmm::String::c_str(), DEFAULT_INTERNAL_CHARSET, ixmlCloneDOMString(), MIMETYPE_JSON, MIMETYPE_XML, NULL, param(), and string_ok().

Referenced by open().

int Object::getRefCount (  )  [inherited]

Definition at line 78 of file object.cc.

References zmm::Object::_ref_count, and atomic_get().

void WebRequestHandler::handleUpdateIDs (  )  [protected]

check if ui update ids should be added to the response and add them in that case. must only be called after check_request

Definition at line 260 of file web_request_handler.cc.

References _, addUpdateIDs(), mxml::mxml_bool_type, param(), root, session, and string_ok().

Referenced by open().

int WebRequestHandler::intParam ( zmm::String  name,
int  invalid = 0 
) [protected]
String WebRequestHandler::mapAutoscanType ( int  type  )  [protected]

Definition at line 304 of file web_request_handler.cc.

References _.

Referenced by web::items::process(), and web::containers::process().

Ref< IOHandler > WebRequestHandler::open ( IN const char *  filename,
OUT struct File_Info info,
IN enum UpnpOpenFileMode  mode 
) [virtual]

Decodes the parameters from the filename (URL) and calls the internal open() function.

Parameters:
filename The requested URL
mode either UPNP_READ or UPNP_WRITE
Returns:
the appropriate IOHandler for the request.

Implements RequestHandler.

Definition at line 243 of file web_request_handler.cc.

References get_info(), log_debug, NULL, open(), params, RequestHandler::split_url(), and URL_UI_PARAM_SEPARATOR.

Ref< IOHandler > WebRequestHandler::open ( IN enum UpnpOpenFileMode  mode  )  [protected]
void Object::operator delete ( void *  ptr  )  [static, inherited]

Definition at line 87 of file object.cc.

References FREE.

void * Object::operator new ( size_t  size  )  [static, inherited]

Definition at line 83 of file object.cc.

References MALLOC.

zmm::String WebRequestHandler::param ( zmm::String  name  )  [inline, protected]
virtual void WebRequestHandler::process (  )  [pure virtual]

This method must be overriden by the subclasses that actually process the given request.

Implemented in web::auth, web::containers, web::directories, web::files, web::items, web::add, web::remove, web::edit_load, web::edit_save, web::addObject, web::autoscan, web::voidType, web::tasks, and web::action.

Referenced by open().

void Object::release (  )  [inherited]
int WebRequestHandler::remapAutoscanType ( zmm::String  type  )  [protected]

Definition at line 314 of file web_request_handler.cc.

String WebRequestHandler::renderXMLHeader (  )  [protected]

Helper function to create a generic XML document header.

Parameters:
xsl_link If not nil, also adds header information that is required for the XSL processor.
Returns:
The header as a string... because our parser does not yet understand <? ?> stuff :)

Definition at line 90 of file web_request_handler.cc.

References _, and DEFAULT_INTERNAL_CHARSET.

Referenced by open().

void Object::retain (  )  [inherited]
void RequestHandler::split_url ( const char *  url,
char  separator,
zmm::String path,
zmm::String parameters 
) [static, inherited]

Splits the url into a path and parameters string. Only '?' and '/' separators are allowed, otherwise an exception will be thrown.

Parameters:
url URL that has to be processed
path variable where the path portion will be saved
parameters variable where the parameters portion will be saved

This function splits the url into it's path and parameter components. content/media SEPARATOR object_id=12345&transcode=wav would be transformed to: path = "content/media" parameters = "object_id=12345&transcode=wav"

Definition at line 41 of file request_handler.cc.

References _, _Exception, zmm::String::index(), zmm::String::rindex(), and zmm::String::substring().

Referenced by create_request_handler(), ServeRequestHandler::get_info(), open(), and ServeRequestHandler::open().


Field Documentation

mt_atomic_t zmm::Object::_ref_count [protected, inherited]

Definition at line 59 of file web_request_handler.h.

Referenced by check_request(), open(), and WebRequestHandler().

The original filename from url if anyone needs it.

Definition at line 65 of file web_request_handler.h.

Referenced by web::files::process(), and web::directories::process().

We can also always see what mode was requested.

Definition at line 68 of file web_request_handler.h.

pthread_mutex_t zmm::Object::mutex [protected, inherited]

This is filled during request processing and holds the output.

The XML or HTML that is the result of a request is put in this buffer, this is what is being served to the web browser.

Definition at line 74 of file web_request_handler.h.

Referenced by open().

Decoded URL parameters are stored as a dictionary.

Definition at line 62 of file web_request_handler.h.

Referenced by open(), param(), web::edit_save::process(), and WebRequestHandler().

The current session, used for this request; will be filled by check_request().

Definition at line 81 of file web_request_handler.h.

Referenced by check_request(), handleUpdateIDs(), and web::auth::process().


The documentation for this class was generated from the following files:

Generated on Fri Mar 26 20:16:58 2010 for MediaTomb by  doxygen 1.6.1