web_callbacks.cc File Reference

#include "common.h"
#include "tools.h"
#include "web_callbacks.h"
#include "server.h"
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include "storage.h"
#include "cds_objects.h"
#include "process.h"
#include "update_manager.h"
#include "ixml.h"
#include "io_handler.h"
#include "request_handler.h"
#include "file_request_handler.h"
#include "web_request_handler.h"
#include "serve_request_handler.h"
#include "web/pages.h"
#include "dictionary.h"
#include <sys/types.h>
#include <sys/stat.h>

Go to the source code of this file.

Functions

static Ref< RequestHandlercreate_request_handler (const char *filename)
static int web_get_info (IN const char *filename, OUT struct File_Info *info)
 Query information on a file.
static UpnpWebFileHandle web_open (IN const char *filename, OUT struct File_Info *info, IN enum UpnpOpenFileMode mode)
 Opens a file for the web server.
static int web_read (IN UpnpWebFileHandle f, OUT char *buf, IN size_t length)
 Reads a previously opened file sequentially.
static int web_write (IN UpnpWebFileHandle f, IN char *buf, IN size_t length)
 Writes to a previously opened file sequentially.
static int web_seek (IN UpnpWebFileHandle f, IN off_t offset, IN int whence)
 Performs a seek on an open file.
static int web_close (IN UpnpWebFileHandle f)
 Closes a previously opened file.
int register_web_callbacks ()
 Registers callback functions for the internal web server.

Detailed Description

This handles the VirtualDirCallbacks that come from the web server.

Definition in file web_callbacks.cc.


Function Documentation

static Ref<RequestHandler> create_request_handler ( const char *  filename  )  [static]
int register_web_callbacks (  ) 

Registers callback functions for the internal web server.

This function registers callbacks for the internal web server. The callback functions are: web_get_info Query information on a file. web_open Open a file. web_read Sequentially read from a file. web_write Sequentially write to a file (not supported). web_seek Perform a seek on a file. web_close Close file.

Returns:
UPNP_E_SUCCESS Callbacks registered successfully, else eror code.

Definition at line 327 of file web_callbacks.cc.

References UpnpVirtualDirCallbacks::close, UpnpVirtualDirCallbacks::get_info, UpnpVirtualDirCallbacks::open, UpnpVirtualDirCallbacks::read, UpnpVirtualDirCallbacks::seek, UPNP_E_SUCCESS, UpnpSetVirtualDirCallbacks(), web_close(), web_get_info(), web_open(), web_read(), web_seek(), web_write(), and UpnpVirtualDirCallbacks::write.

Referenced by Server::upnp_init().

static int web_close ( IN UpnpWebFileHandle  f  )  [static]

Closes a previously opened file.

Parameters:
f IOHandler for that file.

Same as fclose()

Returns:
0 On success, non-zero on error.
Parameters:
f Handle of the file.

Same as fclose()

Return values:
0 On success, non-zero on error.

Definition at line 297 of file web_callbacks.cc.

References zmm::String::c_str(), zmm::Exception::getMessage(), log_error, and zmm::Exception::printStackTrace().

Referenced by register_web_callbacks().

static int web_get_info ( IN const char *  filename,
OUT struct File_Info info 
) [static]

Query information on a file.

Parameters:
filename Name of the file to query.
File_Info Pointer to the struction that stores information about the file.

This function corresponds to get_info from the UpnpVirtualDirCallbacks structure. It is called by the web server to query information about a file. To perform the operation an appropriate request handler is created, it then takes care of filling in the data.

Returns:
0 Success.
-1 Error.

Definition at line 153 of file web_callbacks.cc.

References zmm::String::c_str(), create_request_handler(), zmm::Exception::getMessage(), log_error, and log_info.

Referenced by register_web_callbacks().

static UpnpWebFileHandle web_open ( IN const char *  filename,
OUT struct File_Info info,
IN enum UpnpOpenFileMode  mode 
) [static]

Opens a file for the web server.

Parameters:
filename Name of the file to open (or actually the full URL)
mode in which the file will be opened (we only support UPNP_READ)
File_Info Pointer to the struction that stores information about the file.

This function is called by the web server when it needs to open a file. It first calls create_request_handler() which tries to identify the request and returns us the appropriate IOHandler. Note, that we return values here, because the SDK does not work with exceptions.

Returns:
UpnpWebFileHandle A valid file handle.
NULL Error.

Definition at line 192 of file web_callbacks.cc.

References zmm::String::c_str(), create_request_handler(), zmm::Exception::getMessage(), zmm::Ref< T >::getPtr(), log_error, log_info, and NULL.

Referenced by register_web_callbacks().

static int web_read ( IN UpnpWebFileHandle  f,
OUT char *  buf,
IN size_t  length 
) [static]

Reads a previously opened file sequentially.

Parameters:
f IOHandler that takes care of this request.
buf This buffer will be filled by our read functions.
length Number of bytes to read.

This function is called by the web server to perform a sequential read from an open file. It calls the read function of the appropriate IOHandler, which copies length bytes from the file or memory into the output buffer.

Returns:
0 EOF encountered.
-1 Error.
Parameters:
f Handle of the file.
buf This buffer will be filled by fread.
length Number of bytes to read.

This function is called by the web server to perform a sequential read from an open file. It copies length bytes from the file into the buffer.

Return values:
0 EOF encountered.
-1 Error.

Definition at line 231 of file web_callbacks.cc.

References Singleton< Server >::getInstance(), and IOHandler::read().

Referenced by register_web_callbacks().

static int web_seek ( IN UpnpWebFileHandle  f,
IN off_t  offset,
IN int  whence 
) [static]

Performs a seek on an open file.

Parameters:
f Handle of the file.
offset Number of bytes to move in the file. For seeking forwards positive values are used, for seeking backwards - negative. Offset must be positive if origin is set to SEEK_SET
whence The position to move relative to. SEEK_CUR to move relative to current position, SEEK_END to move relative to the end of file, SEEK_SET to specify an absolute offset.

This function is called by the web server to perform seek on an a file. The seek operatoin itself is performed by the responsible IOHandler.

Returns:
0 On success, non-zero value on error.

Definition at line 274 of file web_callbacks.cc.

References zmm::String::c_str(), zmm::Exception::getMessage(), log_error, zmm::Exception::printStackTrace(), and IOHandler::seek().

Referenced by register_web_callbacks().

static int web_write ( IN UpnpWebFileHandle  f,
IN char *  buf,
IN size_t  length 
) [static]

Writes to a previously opened file sequentially.

Parameters:
f Handle of the file.
buf This buffer will be filled by fwrite.
length Number of bytes to fwrite.

This function is called by the web server to perform a sequential write to an open file. It copies length bytes into the file from the buffer. It should return the actual number of bytes written, in case of a write error this might be less than length.

Returns:
Actual number of bytes written.
Warning:
Currently this function is not supported.
Parameters:
f Handle of the file.
buf This buffer will be filled by fwrite.
length Number of bytes to fwrite.

This function is called by the web server to perform a sequential write to an open file. It copies length bytes into the file from the buffer. It should return the actual number of bytes written, in case of a write error this might be less than length.

Return values:
Actual number of bytes written.
Warning:
Currently this function is not supported.

Definition at line 255 of file web_callbacks.cc.

Referenced by register_web_callbacks().


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