Hiding UpnpVirtualDirCallbacks and struct virtual_Dir_List.
git-svn-id: https://pupnp.svn.sourceforge.net/svnroot/pupnp/trunk@362 119443c7-1b9e-41f8-b6fc-b9c35fce742c
This commit is contained in:
parent
be2fa49891
commit
7acfd52f6b
8
TODO
8
TODO
@ -23,11 +23,7 @@ http://sourceforge.net/tracker/?group_id=7189&atid=307189
|
|||||||
B) An IPv4 and IPv6 device (2)
|
B) An IPv4 and IPv6 device (2)
|
||||||
NUM_HANDLE should be 3
|
NUM_HANDLE should be 3
|
||||||
|
|
||||||
To Be Decided
|
- A sane way to implement the virtual directory callback initialization and checking
|
||||||
=============
|
against NULL pointers.
|
||||||
|
|
||||||
- IPV6 support ?
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -82,6 +82,7 @@ libupnp_la_SOURCES = \
|
|||||||
src/inc/util.h \
|
src/inc/util.h \
|
||||||
src/inc/utilall.h \
|
src/inc/utilall.h \
|
||||||
src/inc/uuid.h \
|
src/inc/uuid.h \
|
||||||
|
src/inc/VirtualDir.h \
|
||||||
src/inc/webserver.h
|
src/inc/webserver.h
|
||||||
|
|
||||||
# ssdp
|
# ssdp
|
||||||
|
248
upnp/inc/upnp.h
248
upnp/inc/upnp.h
@ -710,106 +710,6 @@ enum Upnp_DescType_e {
|
|||||||
typedef enum Upnp_DescType_e Upnp_DescType;
|
typedef enum Upnp_DescType_e Upnp_DescType;
|
||||||
|
|
||||||
|
|
||||||
/* The type of handle returned by the web server for open requests. */
|
|
||||||
typedef void *UpnpWebFileHandle;
|
|
||||||
|
|
||||||
/** The {\bf UpnpVirtualDirCallbacks} structure contains the pointers to
|
|
||||||
* file-related callback functions a device application can register to
|
|
||||||
* virtualize URLs.
|
|
||||||
*/
|
|
||||||
struct UpnpVirtualDirCallbacks
|
|
||||||
{
|
|
||||||
/** Called by the web server to query information on a file. The callback
|
|
||||||
* should return 0 on success or -1 on an error. */
|
|
||||||
int (*get_info) (
|
|
||||||
/** The name of the file to query. */
|
|
||||||
IN const char *filename,
|
|
||||||
/** Pointer to a structure to store the information on the file. */
|
|
||||||
OUT UpnpFileInfo *info);
|
|
||||||
|
|
||||||
/** Called by the web server to open a file. The callback should return
|
|
||||||
* a valid handle if the file can be opened. Otherwise, it should return
|
|
||||||
* {\tt NULL} to signify an error. */
|
|
||||||
UpnpWebFileHandle (*open)(
|
|
||||||
/** The name of the file to open. */
|
|
||||||
IN const char *filename,
|
|
||||||
/** The mode in which to open the file.
|
|
||||||
* Valid values are {\tt UPNP_READ} or {\tt UPNP_WRITE}. */
|
|
||||||
IN enum UpnpOpenFileMode Mode);
|
|
||||||
|
|
||||||
/** Called by the web server to perform a sequential read from an open
|
|
||||||
* file. The callback should copy {\bf buflen} bytes from the file into
|
|
||||||
* the buffer.
|
|
||||||
* @return [int] An integer representing one of the following:
|
|
||||||
* \begin{itemize}
|
|
||||||
* \item {\tt 0}: The file contains no more data (EOF).
|
|
||||||
* \item {\tt >0}: A successful read of the number of bytes in the
|
|
||||||
* return code.
|
|
||||||
* \item {\tt <0}: An error occurred reading the file.
|
|
||||||
* \end{itemzie}
|
|
||||||
*/
|
|
||||||
int (*read) (
|
|
||||||
/** The handle of the file to read. */
|
|
||||||
IN UpnpWebFileHandle fileHnd,
|
|
||||||
/** The buffer in which to place the data. */
|
|
||||||
OUT char *buf,
|
|
||||||
/** The size of the buffer (i.e. the number of bytes to read). */
|
|
||||||
IN size_t buflen);
|
|
||||||
|
|
||||||
/** Called by the web server to perform a sequential write to an open
|
|
||||||
* file. The callback should write {\bf buflen} bytes into the file from
|
|
||||||
* the buffer. It should return the actual number of bytes written,
|
|
||||||
* which might be less than {\bf buflen} in the case of a write error.
|
|
||||||
*/
|
|
||||||
int (*write) (
|
|
||||||
/** The handle of the file to write. */
|
|
||||||
IN UpnpWebFileHandle fileHnd,
|
|
||||||
/** The buffer with the bytes to write. */
|
|
||||||
IN char *buf,
|
|
||||||
/** The number of bytes to write. */
|
|
||||||
IN size_t buflen);
|
|
||||||
|
|
||||||
/** Called by the web server to move the file pointer, or offset, into
|
|
||||||
* an open file. The {\bf origin} parameter determines where to start
|
|
||||||
* moving the file pointer. A value of {\tt SEEK_CUR} moves the
|
|
||||||
* file pointer relative to where it is. The {\bf offset} parameter can
|
|
||||||
* be either positive (move forward) or negative (move backward).
|
|
||||||
* {\tt SEEK_END} moves relative to the end of the file. A positive
|
|
||||||
* {\bf offset} extends the file. A negative {\bf offset} moves backward
|
|
||||||
* in the file. Finally, {\tt SEEK_SET} moves to an absolute position in
|
|
||||||
* the file. In this case, {\bf offset} must be positive. The callback
|
|
||||||
* should return 0 on a successful seek or a non-zero value on an error.
|
|
||||||
*/
|
|
||||||
int (*seek) (
|
|
||||||
/** The handle of the file to move the file pointer. */
|
|
||||||
IN UpnpWebFileHandle fileHnd,
|
|
||||||
/** The number of bytes to move in the file. Positive values
|
|
||||||
* move foward and negative values move backward. Note that
|
|
||||||
* this must be positive if the {\bf origin} is {\tt SEEK_SET}. */
|
|
||||||
IN off_t offset,
|
|
||||||
/** The position to move relative to. It can be {\tt SEEK_CUR}
|
|
||||||
* to move relative to the current position, {\tt SEEK_END} to
|
|
||||||
* move relative to the end of the file, or {\tt SEEK_SET} to
|
|
||||||
* specify an absolute offset. */
|
|
||||||
IN int origin);
|
|
||||||
|
|
||||||
/** Called by the web server to close a file opened via the {\bf open}
|
|
||||||
* callback. It should return 0 on success, or a non-zero value on an
|
|
||||||
* error.
|
|
||||||
*/
|
|
||||||
int (*close) (
|
|
||||||
/** The handle of the file to close. */
|
|
||||||
IN UpnpWebFileHandle fileHnd);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct virtual_Dir_List
|
|
||||||
{
|
|
||||||
struct virtual_Dir_List *next;
|
|
||||||
char dirName[NAME_SIZE];
|
|
||||||
} virtualDirList;
|
|
||||||
|
|
||||||
|
|
||||||
/** All callback functions share the same prototype, documented below.
|
/** All callback functions share the same prototype, documented below.
|
||||||
* Note that any memory passed to the callback function
|
* Note that any memory passed to the callback function
|
||||||
* is valid only during the callback and should be copied if it
|
* is valid only during the callback and should be copied if it
|
||||||
@ -2528,28 +2428,125 @@ EXPORT_SPEC int UpnpDownloadXmlDoc(
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
EXPORT_SPEC int UpnpSetWebServerRootDir(
|
EXPORT_SPEC int UpnpSetWebServerRootDir(
|
||||||
IN const char* rootDir /** Path of the root directory of the web
|
/** Path of the root directory of the web server. */
|
||||||
server. */
|
IN const char *rootDir);
|
||||||
);
|
|
||||||
|
|
||||||
/** {\bf UpnpSetVirtualDirCallbacks} sets the callback function to be used to
|
|
||||||
* access a virtual directory. Refer to the description of
|
/* The type of handle returned by the web server for open requests. */
|
||||||
* {\bf UpnpVirtualDirCallbacks} for a description of the functions.
|
typedef void *UpnpWebFileHandle;
|
||||||
|
|
||||||
|
|
||||||
|
typedef int (*VDCallback_GetInfo)(
|
||||||
|
/** The name of the file to query. */
|
||||||
|
IN const char *filename,
|
||||||
|
/** Pointer to a structure to store the information on the file. */
|
||||||
|
OUT UpnpFileInfo *info);
|
||||||
|
|
||||||
|
/** {\bf UpnpVirtualDir_set_GetInfoCallback} sets the get_info callback function
|
||||||
|
* to be used to access a virtual directory.
|
||||||
*
|
*
|
||||||
* @return [int] An integer representing one of the following:
|
* @return [int] An integer representing one of the following:
|
||||||
* \begin{itemize}
|
* \begin{itemize}
|
||||||
* \item {\tt UPPN_E_SUCCESS}: The operation completed successfully.
|
* \item {\tt UPPN_E_SUCCESS}: The operation completed successfully.
|
||||||
* \item {\tt UPNP_E_INVALID_ARGUMENT}: {\bf callbacks} is not a valid
|
* \item {\tt UPNP_E_INVALID_ARGUMENT}: {\bf callback} is not a valid pointer.
|
||||||
* pointer.
|
|
||||||
* \end{itemize}
|
* \end{itemize}
|
||||||
*/
|
*/
|
||||||
|
EXPORT_SPEC int UpnpVirtualDir_set_GetInfoCallback(VDCallback_GetInfo callback);
|
||||||
|
|
||||||
EXPORT_SPEC int UpnpSetVirtualDirCallbacks(
|
typedef UpnpWebFileHandle (*VDCallback_Open)(
|
||||||
IN struct UpnpVirtualDirCallbacks *callbacks /** Pointer to a structure
|
/** The name of the file to open. */
|
||||||
containing points to the
|
IN const char *filename,
|
||||||
virtual interface
|
/** The mode in which to open the file.
|
||||||
functions. */
|
* Valid values are {\tt UPNP_READ} or {\tt UPNP_WRITE}. */
|
||||||
);
|
IN enum UpnpOpenFileMode Mode);
|
||||||
|
|
||||||
|
/** {\bf UpnpVirtualDir_set_OpenCallback} sets the open callback function
|
||||||
|
* to be used to access a virtual directory.
|
||||||
|
*
|
||||||
|
* @return [int] An integer representing one of the following:
|
||||||
|
* \begin{itemize}
|
||||||
|
* \item {\tt UPPN_E_SUCCESS}: The operation completed successfully.
|
||||||
|
* \item {\tt UPNP_E_INVALID_ARGUMENT}: {\bf callback} is not a valid pointer.
|
||||||
|
* \end{itemize}
|
||||||
|
*/
|
||||||
|
EXPORT_SPEC int UpnpVirtualDir_set_OpenCallback(VDCallback_Open callback);
|
||||||
|
|
||||||
|
typedef int (*VDCallback_Read) (
|
||||||
|
/** The handle of the file to read. */
|
||||||
|
IN UpnpWebFileHandle fileHnd,
|
||||||
|
/** The buffer in which to place the data. */
|
||||||
|
OUT char *buf,
|
||||||
|
/** The size of the buffer (i.e. the number of bytes to read). */
|
||||||
|
IN size_t buflen);
|
||||||
|
|
||||||
|
/** {\bf UpnpVirtualDir_set_ReadCallback} sets the read callback function
|
||||||
|
* to be used to access a virtual directory.
|
||||||
|
*
|
||||||
|
* @return [int] An integer representing one of the following:
|
||||||
|
* \begin{itemize}
|
||||||
|
* \item {\tt UPPN_E_SUCCESS}: The operation completed successfully.
|
||||||
|
* \item {\tt UPNP_E_INVALID_ARGUMENT}: {\bf callback} is not a valid pointer.
|
||||||
|
* \end{itemize}
|
||||||
|
*/
|
||||||
|
EXPORT_SPEC int UpnpVirtualDir_set_ReadCallback(VDCallback_Read callback);
|
||||||
|
|
||||||
|
typedef int (*VDCallback_Write) (
|
||||||
|
/** The handle of the file to write. */
|
||||||
|
IN UpnpWebFileHandle fileHnd,
|
||||||
|
/** The buffer with the bytes to write. */
|
||||||
|
IN char *buf,
|
||||||
|
/** The number of bytes to write. */
|
||||||
|
IN size_t buflen);
|
||||||
|
|
||||||
|
/** {\bf UpnpVirtualDir_set_WriteCallback} sets the write callback function
|
||||||
|
* to be used to access a virtual directory.
|
||||||
|
*
|
||||||
|
* @return [int] An integer representing one of the following:
|
||||||
|
* \begin{itemize}
|
||||||
|
* \item {\tt UPPN_E_SUCCESS}: The operation completed successfully.
|
||||||
|
* \item {\tt UPNP_E_INVALID_ARGUMENT}: {\bf callback} is not a valid pointer.
|
||||||
|
* \end{itemize}
|
||||||
|
*/
|
||||||
|
EXPORT_SPEC int UpnpVirtualDir_set_WriteCallback(VDCallback_Write callback);
|
||||||
|
|
||||||
|
typedef int (*VDCallback_Seek) (
|
||||||
|
/** The handle of the file to move the file pointer. */
|
||||||
|
IN UpnpWebFileHandle fileHnd,
|
||||||
|
/** The number of bytes to move in the file. Positive values
|
||||||
|
* move foward and negative values move backward. Note that
|
||||||
|
* this must be positive if the {\bf origin} is {\tt SEEK_SET}. */
|
||||||
|
IN off_t offset,
|
||||||
|
/** The position to move relative to. It can be {\tt SEEK_CUR}
|
||||||
|
* to move relative to the current position, {\tt SEEK_END} to
|
||||||
|
* move relative to the end of the file, or {\tt SEEK_SET} to
|
||||||
|
* specify an absolute offset. */
|
||||||
|
IN int origin);
|
||||||
|
|
||||||
|
/** {\bf UpnpVirtualDir_set_SeekCallback} sets the seek callback function
|
||||||
|
* to be used to access a virtual directory.
|
||||||
|
*
|
||||||
|
* @return [int] An integer representing one of the following:
|
||||||
|
* \begin{itemize}
|
||||||
|
* \item {\tt UPPN_E_SUCCESS}: The operation completed successfully.
|
||||||
|
* \item {\tt UPNP_E_INVALID_ARGUMENT}: {\bf callback} is not a valid pointer.
|
||||||
|
* \end{itemize}
|
||||||
|
*/
|
||||||
|
EXPORT_SPEC int UpnpVirtualDir_set_SeekCallback(VDCallback_Seek callback);
|
||||||
|
|
||||||
|
typedef int (*VDCallback_Close) (
|
||||||
|
/** The handle of the file to close. */
|
||||||
|
IN UpnpWebFileHandle fileHnd);
|
||||||
|
|
||||||
|
/** {\bf UpnpVirtualDir_set_CloseCallback} sets the close callback function
|
||||||
|
* to be used to access a virtual directory.
|
||||||
|
*
|
||||||
|
* @return [int] An integer representing one of the following:
|
||||||
|
* \begin{itemize}
|
||||||
|
* \item {\tt UPPN_E_SUCCESS}: The operation completed successfully.
|
||||||
|
* \item {\tt UPNP_E_INVALID_ARGUMENT}: {\bf callback} is not a valid pointer.
|
||||||
|
* \end{itemize}
|
||||||
|
*/
|
||||||
|
EXPORT_SPEC int UpnpVirtualDir_set_CloseCallback(VDCallback_Close callback);
|
||||||
|
|
||||||
/** {\bf UpnpEnableWebServer} enables or disables the webserver. A value of
|
/** {\bf UpnpEnableWebServer} enables or disables the webserver. A value of
|
||||||
* {\tt TRUE} enables the webserver, {\tt FALSE} disables it.
|
* {\tt TRUE} enables the webserver, {\tt FALSE} disables it.
|
||||||
@ -2560,10 +2557,9 @@ EXPORT_SPEC int UpnpSetVirtualDirCallbacks(
|
|||||||
* \item {\tt UPNP_E_INVALID_ARGUMENT}: {\bf enable} is not valid.
|
* \item {\tt UPNP_E_INVALID_ARGUMENT}: {\bf enable} is not valid.
|
||||||
* \end{itemize}
|
* \end{itemize}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
EXPORT_SPEC int UpnpEnableWebserver(
|
EXPORT_SPEC int UpnpEnableWebserver(
|
||||||
IN int enable /** {\tt TRUE} to enable, {\tt FALSE} to disable. */
|
/** {\tt TRUE} to enable, {\tt FALSE} to disable. */
|
||||||
);
|
IN int enable);
|
||||||
|
|
||||||
/** {\bf UpnpIsWebServerEnabled} returns {\tt TRUE} if the webserver is
|
/** {\bf UpnpIsWebServerEnabled} returns {\tt TRUE} if the webserver is
|
||||||
* enabled, or {\tt FALSE} if it is not.
|
* enabled, or {\tt FALSE} if it is not.
|
||||||
@ -2574,7 +2570,6 @@ EXPORT_SPEC int UpnpEnableWebserver(
|
|||||||
* \item {\tt FALSE}: The webserver is not enabled
|
* \item {\tt FALSE}: The webserver is not enabled
|
||||||
* \end{itemize}
|
* \end{itemize}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
EXPORT_SPEC int UpnpIsWebserverEnabled();
|
EXPORT_SPEC int UpnpIsWebserverEnabled();
|
||||||
|
|
||||||
/** {\bf UpnpAddVirtualDir} adds a virtual directory mapping.
|
/** {\bf UpnpAddVirtualDir} adds a virtual directory mapping.
|
||||||
@ -2589,11 +2584,9 @@ EXPORT_SPEC int UpnpIsWebserverEnabled();
|
|||||||
* \item {\tt UPNP_E_INVALID_ARGUMENT}: {\bf dirName} is not valid.
|
* \item {\tt UPNP_E_INVALID_ARGUMENT}: {\bf dirName} is not valid.
|
||||||
* \end{itemize}
|
* \end{itemize}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
EXPORT_SPEC int UpnpAddVirtualDir(
|
EXPORT_SPEC int UpnpAddVirtualDir(
|
||||||
IN const char *dirName /** The name of the new directory mapping to add.
|
/** The name of the new directory mapping to add. */
|
||||||
*/
|
IN const char *dirName);
|
||||||
);
|
|
||||||
|
|
||||||
/** {\bf UpnpRemoveVirtualDir} removes a virtual directory mapping made with
|
/** {\bf UpnpRemoveVirtualDir} removes a virtual directory mapping made with
|
||||||
* {\bf UpnpAddVirtualDir}.
|
* {\bf UpnpAddVirtualDir}.
|
||||||
@ -2604,23 +2597,20 @@ EXPORT_SPEC int UpnpAddVirtualDir(
|
|||||||
* \item {\tt UPNP_E_INVALID_ARGUMENT}: {\bf dirName} is not valid.
|
* \item {\tt UPNP_E_INVALID_ARGUMENT}: {\bf dirName} is not valid.
|
||||||
* \end{itemize}
|
* \end{itemize}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
EXPORT_SPEC int UpnpRemoveVirtualDir(
|
EXPORT_SPEC int UpnpRemoveVirtualDir(
|
||||||
IN const char *dirName /** The name of the virtual directory mapping to
|
/** The name of the virtual directory mapping to remove. */
|
||||||
remove. */
|
IN const char *dirName);
|
||||||
);
|
|
||||||
|
|
||||||
/** {\bf UpnpRemoveAllVirtualDirs} removes all virtual directory mappings.
|
/** {\bf UpnpRemoveAllVirtualDirs} removes all virtual directory mappings.
|
||||||
*
|
*
|
||||||
* @return [void] This function does not return a value.
|
* @return [void] This function does not return a value.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
EXPORT_SPEC void UpnpRemoveAllVirtualDirs();
|
EXPORT_SPEC void UpnpRemoveAllVirtualDirs();
|
||||||
|
|
||||||
EXPORT_SPEC void UpnpFree(
|
EXPORT_SPEC void UpnpFree(
|
||||||
IN void *item /* The item to free. */
|
/** The item to free. */
|
||||||
);
|
IN void *item);
|
||||||
|
|
||||||
/*! @} */ /* Web Server API */
|
/*! @} */ /* Web Server API */
|
||||||
|
|
||||||
|
@ -82,16 +82,22 @@
|
|||||||
|
|
||||||
|
|
||||||
#ifdef INTERNAL_WEB_SERVER
|
#ifdef INTERNAL_WEB_SERVER
|
||||||
#include "webserver.h"
|
|
||||||
#include "urlconfig.h"
|
#include "urlconfig.h"
|
||||||
|
#include "VirtualDir.h"
|
||||||
|
#include "webserver.h"
|
||||||
#endif // INTERNAL_WEB_SERVER
|
#endif // INTERNAL_WEB_SERVER
|
||||||
|
|
||||||
|
|
||||||
|
// This structure is for virtual directory callbacks
|
||||||
|
struct UpnpVirtualDirCallbacks virtualDirCallback;
|
||||||
|
|
||||||
//
|
//
|
||||||
virtualDirList *pVirtualDirList;
|
virtualDirList *pVirtualDirList;
|
||||||
|
|
||||||
// Mutex to synchronize the subscription handling at the client side
|
// Mutex to synchronize the subscription handling at the client side
|
||||||
CLIENTONLY( ithread_mutex_t GlobalClientSubscribeMutex; )
|
#ifdef INCLUDE_CLIENT_APIS
|
||||||
|
ithread_mutex_t GlobalClientSubscribeMutex;
|
||||||
|
#endif /* INCLUDE_CLIENT_APIS */
|
||||||
|
|
||||||
// rwlock to synchronize handles (root device or control point handle)
|
// rwlock to synchronize handles (root device or control point handle)
|
||||||
ithread_rwlock_t GlobalHndRWLock;
|
ithread_rwlock_t GlobalHndRWLock;
|
||||||
@ -129,9 +135,6 @@ CLIENTONLY( ithread_mutex_t GlobalClientSubscribeMutex; )
|
|||||||
// UPnP device and control point handle table
|
// UPnP device and control point handle table
|
||||||
void *HandleTable[NUM_HANDLE];
|
void *HandleTable[NUM_HANDLE];
|
||||||
|
|
||||||
//This structure is for virtual directory callbacks
|
|
||||||
struct UpnpVirtualDirCallbacks virtualDirCallback;
|
|
||||||
|
|
||||||
// a local dir which serves as webserver root
|
// a local dir which serves as webserver root
|
||||||
extern membuffer gDocumentRootDir;
|
extern membuffer gDocumentRootDir;
|
||||||
|
|
||||||
@ -5048,45 +5051,85 @@ UpnpIsWebserverEnabled()
|
|||||||
return ( bWebServerState == WEB_SERVER_ENABLED );
|
return ( bWebServerState == WEB_SERVER_ENABLED );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**************************************************************************
|
|
||||||
* Function: UpnpSetVirtualDirCallbacks
|
int UpnpVirtualDir_set_GetInfoCallback(VDCallback_GetInfo callback)
|
||||||
*
|
|
||||||
* Parameters:
|
|
||||||
* IN struct UpnpVirtualDirCallbacks *callbacks:a structure that
|
|
||||||
* contains the callback functions.
|
|
||||||
*
|
|
||||||
* Description:
|
|
||||||
* This function sets the callback function to be used to
|
|
||||||
* access a virtual directory.
|
|
||||||
*
|
|
||||||
* Return Values: int
|
|
||||||
* UPNP_E_SUCCESS on success, or UPNP_E_INVALID_PARAM
|
|
||||||
***************************************************************************/
|
|
||||||
int
|
|
||||||
UpnpSetVirtualDirCallbacks( IN struct UpnpVirtualDirCallbacks *callbacks )
|
|
||||||
{
|
{
|
||||||
struct UpnpVirtualDirCallbacks *pCallback;
|
int ret = UPNP_E_SUCCESS;
|
||||||
|
if (!callback) {
|
||||||
if( UpnpSdkInit != 1 ) {
|
ret = UPNP_E_INVALID_PARAM;
|
||||||
// SDK is not initialized
|
} else {
|
||||||
return UPNP_E_FINISH;
|
virtualDirCallback.get_info = callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
pCallback = &virtualDirCallback;
|
return ret;
|
||||||
|
|
||||||
if( callbacks == NULL )
|
|
||||||
return UPNP_E_INVALID_PARAM;
|
|
||||||
|
|
||||||
pCallback->get_info = callbacks->get_info;
|
|
||||||
pCallback->open = callbacks->open;
|
|
||||||
pCallback->close = callbacks->close;
|
|
||||||
pCallback->read = callbacks->read;
|
|
||||||
pCallback->write = callbacks->write;
|
|
||||||
pCallback->seek = callbacks->seek;
|
|
||||||
|
|
||||||
return UPNP_E_SUCCESS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int UpnpVirtualDir_set_OpenCallback(VDCallback_Open callback)
|
||||||
|
{
|
||||||
|
int ret = UPNP_E_SUCCESS;
|
||||||
|
if (!callback) {
|
||||||
|
ret = UPNP_E_INVALID_PARAM;
|
||||||
|
} else {
|
||||||
|
virtualDirCallback.open = callback;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int UpnpVirtualDir_set_ReadCallback(VDCallback_Read callback)
|
||||||
|
{
|
||||||
|
int ret = UPNP_E_SUCCESS;
|
||||||
|
if (!callback) {
|
||||||
|
ret = UPNP_E_INVALID_PARAM;
|
||||||
|
} else {
|
||||||
|
virtualDirCallback.read = callback;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int UpnpVirtualDir_set_WriteCallback(VDCallback_Write callback)
|
||||||
|
{
|
||||||
|
int ret = UPNP_E_SUCCESS;
|
||||||
|
if (!callback) {
|
||||||
|
ret = UPNP_E_INVALID_PARAM;
|
||||||
|
} else {
|
||||||
|
virtualDirCallback.write = callback;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int UpnpVirtualDir_set_SeekCallback(VDCallback_Seek callback)
|
||||||
|
{
|
||||||
|
int ret = UPNP_E_SUCCESS;
|
||||||
|
if (!callback) {
|
||||||
|
ret = UPNP_E_INVALID_PARAM;
|
||||||
|
} else {
|
||||||
|
virtualDirCallback.seek = callback;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int UpnpVirtualDir_set_CloseCallback(VDCallback_Close callback)
|
||||||
|
{
|
||||||
|
int ret = UPNP_E_SUCCESS;
|
||||||
|
if (!callback) {
|
||||||
|
ret = UPNP_E_INVALID_PARAM;
|
||||||
|
} else {
|
||||||
|
virtualDirCallback.close = callback;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
* Function: UpnpFree
|
* Function: UpnpFree
|
||||||
*
|
*
|
||||||
@ -5096,8 +5139,7 @@ UpnpSetVirtualDirCallbacks( IN struct UpnpVirtualDirCallbacks *callbacks )
|
|||||||
* Description:
|
* Description:
|
||||||
* This function free the memory allocated by tbe UPnP library
|
* This function free the memory allocated by tbe UPnP library
|
||||||
*
|
*
|
||||||
* Return Values: VOID
|
* Return Values: void
|
||||||
*
|
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
void
|
void
|
||||||
UpnpFree( IN void *item )
|
UpnpFree( IN void *item )
|
||||||
|
@ -58,6 +58,7 @@
|
|||||||
#include "upnp.h"
|
#include "upnp.h"
|
||||||
#include "upnpapi.h"
|
#include "upnpapi.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#include "VirtualDir.h"
|
||||||
|
|
||||||
|
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
@ -520,40 +521,33 @@ web_server_set_alias( IN const char *alias_name,
|
|||||||
return UPNP_E_OUTOF_MEMORY;
|
return UPNP_E_OUTOF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
|
||||||
* Function: web_server_init
|
|
||||||
*
|
|
||||||
* Parameters:
|
|
||||||
* none
|
|
||||||
*
|
|
||||||
* Description: Initilialize the different documents. Initialize the
|
|
||||||
* memory for root directory for web server. Call to initialize global
|
|
||||||
* XML document. Sets bWebServerState to WEB_SERVER_ENABLED
|
|
||||||
*
|
|
||||||
* Returns:
|
|
||||||
* 0 - OK
|
|
||||||
* UPNP_E_OUTOF_MEMORY: note: alias_content is not freed here
|
|
||||||
************************************************************************/
|
|
||||||
int
|
|
||||||
web_server_init( void )
|
|
||||||
{
|
|
||||||
int ret_code;
|
|
||||||
|
|
||||||
|
int web_server_init()
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
if (bWebServerState == WEB_SERVER_DISABLED) {
|
if (bWebServerState == WEB_SERVER_DISABLED) {
|
||||||
media_list_init(); // decode media list
|
// decode media list
|
||||||
|
media_list_init();
|
||||||
membuffer_init(&gDocumentRootDir);
|
membuffer_init(&gDocumentRootDir);
|
||||||
glob_alias_init();
|
glob_alias_init();
|
||||||
|
|
||||||
pVirtualDirList = NULL;
|
pVirtualDirList = NULL;
|
||||||
|
|
||||||
ret_code = ithread_mutex_init( &gWebMutex, NULL );
|
// Initialize callbacks
|
||||||
if( ret_code == -1 ) {
|
virtualDirCallback.get_info = NULL;
|
||||||
return UPNP_E_OUTOF_MEMORY;
|
virtualDirCallback.open = NULL;
|
||||||
}
|
virtualDirCallback.read = NULL;
|
||||||
|
virtualDirCallback.write = NULL;
|
||||||
|
virtualDirCallback.seek = NULL;
|
||||||
|
virtualDirCallback.close = NULL;
|
||||||
|
|
||||||
|
if (ithread_mutex_init(&gWebMutex, NULL) == -1) {
|
||||||
|
ret = UPNP_E_OUTOF_MEMORY;
|
||||||
|
} else {
|
||||||
bWebServerState = WEB_SERVER_ENABLED;
|
bWebServerState = WEB_SERVER_ENABLED;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
@ -1213,7 +1207,6 @@ process_request( IN http_message_t * req,
|
|||||||
int resp_minor;
|
int resp_minor;
|
||||||
xboolean alias_grabbed;
|
xboolean alias_grabbed;
|
||||||
size_t dummy;
|
size_t dummy;
|
||||||
struct UpnpVirtualDirCallbacks *pVirtualDirCallback;
|
|
||||||
const char *extra_headers;
|
const char *extra_headers;
|
||||||
|
|
||||||
print_http_headers( req );
|
print_http_headers( req );
|
||||||
@ -1285,8 +1278,7 @@ process_request( IN http_message_t * req,
|
|||||||
if (using_virtual_dir) {
|
if (using_virtual_dir) {
|
||||||
if (req->method != HTTPMETHOD_POST) {
|
if (req->method != HTTPMETHOD_POST) {
|
||||||
// get file info
|
// get file info
|
||||||
pVirtualDirCallback = &virtualDirCallback;
|
if (virtualDirCallback.get_info(filename->buf, finfo) != 0) {
|
||||||
if (pVirtualDirCallback->get_info(filename->buf, finfo) != 0) {
|
|
||||||
err_code = HTTP_NOT_FOUND;
|
err_code = HTTP_NOT_FOUND;
|
||||||
goto error_handler;
|
goto error_handler;
|
||||||
}
|
}
|
||||||
@ -1301,7 +1293,7 @@ process_request( IN http_message_t * req,
|
|||||||
goto error_handler;
|
goto error_handler;
|
||||||
}
|
}
|
||||||
// get info
|
// get info
|
||||||
if( pVirtualDirCallback->get_info(filename->buf, finfo) != UPNP_E_SUCCESS ||
|
if (virtualDirCallback.get_info(filename->buf, finfo) != UPNP_E_SUCCESS ||
|
||||||
UpnpFileInfo_get_IsDirectory(finfo)) {
|
UpnpFileInfo_get_IsDirectory(finfo)) {
|
||||||
err_code = HTTP_NOT_FOUND;
|
err_code = HTTP_NOT_FOUND;
|
||||||
goto error_handler;
|
goto error_handler;
|
||||||
@ -1541,12 +1533,10 @@ http_RecvPostMessage( http_parser_t * parser,
|
|||||||
int ret_code = 0;
|
int ret_code = 0;
|
||||||
|
|
||||||
if( Instr && Instr->IsVirtualFile ) {
|
if( Instr && Instr->IsVirtualFile ) {
|
||||||
|
|
||||||
Fp = (virtualDirCallback.open)( filename, UPNP_WRITE );
|
Fp = (virtualDirCallback.open)( filename, UPNP_WRITE );
|
||||||
if( Fp == NULL ) {
|
if( Fp == NULL ) {
|
||||||
return HTTP_INTERNAL_SERVER_ERROR;
|
return HTTP_INTERNAL_SERVER_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Fp = fopen( filename, "wb" );
|
Fp = fopen( filename, "wb" );
|
||||||
if( Fp == NULL ) {
|
if( Fp == NULL ) {
|
||||||
|
71
upnp/src/inc/VirtualDir.h
Normal file
71
upnp/src/inc/VirtualDir.h
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
|
||||||
|
|
||||||
|
#ifndef VIRTUALDIR_H
|
||||||
|
#define VIRTUALDIR_H
|
||||||
|
|
||||||
|
|
||||||
|
/** The {\bf UpnpVirtualDirCallbacks} structure contains the pointers to
|
||||||
|
* file-related callback functions a device application can register to
|
||||||
|
* virtualize URLs.
|
||||||
|
*/
|
||||||
|
struct UpnpVirtualDirCallbacks
|
||||||
|
{
|
||||||
|
/** Called by the web server to query information on a file. The callback
|
||||||
|
* should return 0 on success or -1 on an error. */
|
||||||
|
VDCallback_GetInfo get_info;
|
||||||
|
|
||||||
|
/** Called by the web server to open a file. The callback should return
|
||||||
|
* a valid handle if the file can be opened. Otherwise, it should return
|
||||||
|
* {\tt NULL} to signify an error. */
|
||||||
|
VDCallback_Open open;
|
||||||
|
|
||||||
|
/** Called by the web server to perform a sequential read from an open
|
||||||
|
* file. The callback should copy {\bf buflen} bytes from the file into
|
||||||
|
* the buffer.
|
||||||
|
* @return [int] An integer representing one of the following:
|
||||||
|
* \begin{itemize}
|
||||||
|
* \item {\tt 0}: The file contains no more data (EOF).
|
||||||
|
* \item {\tt >0}: A successful read of the number of bytes in the
|
||||||
|
* return code.
|
||||||
|
* \item {\tt <0}: An error occurred reading the file.
|
||||||
|
* \end{itemzie}
|
||||||
|
*/
|
||||||
|
VDCallback_Read read;
|
||||||
|
|
||||||
|
/** Called by the web server to perform a sequential write to an open
|
||||||
|
* file. The callback should write {\bf buflen} bytes into the file from
|
||||||
|
* the buffer. It should return the actual number of bytes written,
|
||||||
|
* which might be less than {\bf buflen} in the case of a write error.
|
||||||
|
*/
|
||||||
|
VDCallback_Write write;
|
||||||
|
|
||||||
|
/** Called by the web server to move the file pointer, or offset, into
|
||||||
|
* an open file. The {\bf origin} parameter determines where to start
|
||||||
|
* moving the file pointer. A value of {\tt SEEK_CUR} moves the
|
||||||
|
* file pointer relative to where it is. The {\bf offset} parameter can
|
||||||
|
* be either positive (move forward) or negative (move backward).
|
||||||
|
* {\tt SEEK_END} moves relative to the end of the file. A positive
|
||||||
|
* {\bf offset} extends the file. A negative {\bf offset} moves backward
|
||||||
|
* in the file. Finally, {\tt SEEK_SET} moves to an absolute position in
|
||||||
|
* the file. In this case, {\bf offset} must be positive. The callback
|
||||||
|
* should return 0 on a successful seek or a non-zero value on an error.
|
||||||
|
*/
|
||||||
|
VDCallback_Seek seek;
|
||||||
|
|
||||||
|
/** Called by the web server to close a file opened via the {\bf open}
|
||||||
|
* callback. It should return 0 on success, or a non-zero value on an
|
||||||
|
* error.
|
||||||
|
*/
|
||||||
|
VDCallback_Close close;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct virtual_Dir_List
|
||||||
|
{
|
||||||
|
struct virtual_Dir_List *next;
|
||||||
|
char dirName[NAME_SIZE];
|
||||||
|
} virtualDirList;
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* VIRTUALDIR_H */
|
||||||
|
|
@ -29,14 +29,16 @@
|
|||||||
//
|
//
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// File : upnpapi.h
|
|
||||||
|
|
||||||
#ifndef UPNPDK_H
|
#ifndef UPNPAPI_H
|
||||||
#define UPNPDK_H
|
#define UPNPAPI_H
|
||||||
|
|
||||||
|
|
||||||
#include "upnp.h"
|
|
||||||
#include "client_table.h"
|
#include "client_table.h"
|
||||||
|
#include "upnp.h"
|
||||||
//#include "../ssdp/ssdplib.h"
|
//#include "../ssdp/ssdplib.h"
|
||||||
|
#include "VirtualDir.h" /* for struct UpnpVirtualDirCallbacks */
|
||||||
|
|
||||||
|
|
||||||
#define MAX_INTERFACES 256
|
#define MAX_INTERFACES 256
|
||||||
|
|
||||||
@ -197,8 +199,6 @@ int getlocalhostname(char *out, const int out_len);
|
|||||||
|
|
||||||
extern WebServerState bWebServerState;
|
extern WebServerState bWebServerState;
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
#endif /* UPNPAPI_H */
|
||||||
|
|
||||||
|
|
||||||
/************************ END OF upnpapi.h **********************/
|
|
||||||
|
@ -69,7 +69,7 @@ struct SendInstruction
|
|||||||
* 0 - OK
|
* 0 - OK
|
||||||
* UPNP_E_OUTOF_MEMORY: note: alias_content is not freed here
|
* UPNP_E_OUTOF_MEMORY: note: alias_content is not freed here
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
int web_server_init( void );
|
int web_server_init();
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function: web_server_destroy
|
* Function: web_server_destroy
|
||||||
@ -84,7 +84,7 @@ int web_server_init( void );
|
|||||||
* Returns:
|
* Returns:
|
||||||
* void
|
* void
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
void web_server_destroy( void );
|
void web_server_destroy();
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* Function: web_server_set_alias
|
* Function: web_server_set_alias
|
||||||
@ -105,7 +105,8 @@ void web_server_destroy( void );
|
|||||||
* 0 - OK
|
* 0 - OK
|
||||||
* UPNP_E_OUTOF_MEMORY: note: alias_content is not freed here
|
* UPNP_E_OUTOF_MEMORY: note: alias_content is not freed here
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
int web_server_set_alias( IN const char* alias_name,
|
int web_server_set_alias(
|
||||||
|
IN const char* alias_name,
|
||||||
IN const char* alias_content, IN size_t alias_content_length,
|
IN const char* alias_content, IN size_t alias_content_length,
|
||||||
IN time_t last_modified);
|
IN time_t last_modified);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user