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)
|
||||
NUM_HANDLE should be 3
|
||||
|
||||
To Be Decided
|
||||
=============
|
||||
|
||||
- IPV6 support ?
|
||||
|
||||
|
||||
- A sane way to implement the virtual directory callback initialization and checking
|
||||
against NULL pointers.
|
||||
|
||||
|
||||
|
@ -82,6 +82,7 @@ libupnp_la_SOURCES = \
|
||||
src/inc/util.h \
|
||||
src/inc/utilall.h \
|
||||
src/inc/uuid.h \
|
||||
src/inc/VirtualDir.h \
|
||||
src/inc/webserver.h
|
||||
|
||||
# ssdp
|
||||
|
250
upnp/inc/upnp.h
250
upnp/inc/upnp.h
@ -710,106 +710,6 @@ enum Upnp_DescType_e {
|
||||
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.
|
||||
* Note that any memory passed to the callback function
|
||||
* is valid only during the callback and should be copied if it
|
||||
@ -2528,28 +2428,125 @@ EXPORT_SPEC int UpnpDownloadXmlDoc(
|
||||
*/
|
||||
|
||||
EXPORT_SPEC int UpnpSetWebServerRootDir(
|
||||
IN const char* rootDir /** Path of the root directory of the web
|
||||
server. */
|
||||
);
|
||||
/** Path of the root directory of the web server. */
|
||||
IN const char *rootDir);
|
||||
|
||||
/** {\bf UpnpSetVirtualDirCallbacks} sets the callback function to be used to
|
||||
* access a virtual directory. Refer to the description of
|
||||
* {\bf UpnpVirtualDirCallbacks} for a description of the functions.
|
||||
|
||||
/* The type of handle returned by the web server for open requests. */
|
||||
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:
|
||||
* \begin{itemize}
|
||||
* \item {\tt UPPN_E_SUCCESS}: The operation completed successfully.
|
||||
* \item {\tt UPNP_E_INVALID_ARGUMENT}: {\bf callbacks} is not a valid
|
||||
* pointer.
|
||||
* \item {\tt UPNP_E_INVALID_ARGUMENT}: {\bf callback} is not a valid pointer.
|
||||
* \end{itemize}
|
||||
*/
|
||||
EXPORT_SPEC int UpnpVirtualDir_set_GetInfoCallback(VDCallback_GetInfo callback);
|
||||
|
||||
EXPORT_SPEC int UpnpSetVirtualDirCallbacks(
|
||||
IN struct UpnpVirtualDirCallbacks *callbacks /** Pointer to a structure
|
||||
containing points to the
|
||||
virtual interface
|
||||
functions. */
|
||||
);
|
||||
typedef UpnpWebFileHandle (*VDCallback_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);
|
||||
|
||||
/** {\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
|
||||
* {\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.
|
||||
* \end{itemize}
|
||||
*/
|
||||
|
||||
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
|
||||
* enabled, or {\tt FALSE} if it is not.
|
||||
@ -2574,7 +2570,6 @@ EXPORT_SPEC int UpnpEnableWebserver(
|
||||
* \item {\tt FALSE}: The webserver is not enabled
|
||||
* \end{itemize}
|
||||
*/
|
||||
|
||||
EXPORT_SPEC int UpnpIsWebserverEnabled();
|
||||
|
||||
/** {\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.
|
||||
* \end{itemize}
|
||||
*/
|
||||
|
||||
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 UpnpAddVirtualDir}.
|
||||
@ -2604,23 +2597,20 @@ EXPORT_SPEC int UpnpAddVirtualDir(
|
||||
* \item {\tt UPNP_E_INVALID_ARGUMENT}: {\bf dirName} is not valid.
|
||||
* \end{itemize}
|
||||
*/
|
||||
|
||||
EXPORT_SPEC int UpnpRemoveVirtualDir(
|
||||
IN const char *dirName /** The name of the virtual directory mapping to
|
||||
remove. */
|
||||
);
|
||||
/** The name of the virtual directory mapping to remove. */
|
||||
IN const char *dirName);
|
||||
|
||||
/** {\bf UpnpRemoveAllVirtualDirs} removes all virtual directory mappings.
|
||||
*
|
||||
* @return [void] This function does not return a value.
|
||||
*
|
||||
*/
|
||||
|
||||
EXPORT_SPEC void UpnpRemoveAllVirtualDirs( );
|
||||
EXPORT_SPEC void UpnpRemoveAllVirtualDirs();
|
||||
|
||||
EXPORT_SPEC void UpnpFree(
|
||||
IN void *item /* The item to free. */
|
||||
);
|
||||
/** The item to free. */
|
||||
IN void *item);
|
||||
|
||||
/*! @} */ /* Web Server API */
|
||||
|
||||
|
@ -82,58 +82,61 @@
|
||||
|
||||
|
||||
#ifdef INTERNAL_WEB_SERVER
|
||||
#include "webserver.h"
|
||||
#include "urlconfig.h"
|
||||
#include "VirtualDir.h"
|
||||
#include "webserver.h"
|
||||
#endif // INTERNAL_WEB_SERVER
|
||||
|
||||
|
||||
// This structure is for virtual directory callbacks
|
||||
struct UpnpVirtualDirCallbacks virtualDirCallback;
|
||||
|
||||
//
|
||||
virtualDirList *pVirtualDirList;
|
||||
|
||||
// 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)
|
||||
ithread_rwlock_t GlobalHndRWLock;
|
||||
ithread_rwlock_t GlobalHndRWLock;
|
||||
|
||||
// Mutex to synchronize the uuid creation process
|
||||
ithread_mutex_t gUUIDMutex;
|
||||
ithread_mutex_t gUUIDMutex;
|
||||
|
||||
ithread_mutex_t gSDKInitMutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
ithread_mutex_t gSDKInitMutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
TimerThread gTimerThread;
|
||||
TimerThread gTimerThread;
|
||||
|
||||
ThreadPool gSendThreadPool;
|
||||
ThreadPool gRecvThreadPool;
|
||||
ThreadPool gMiniServerThreadPool;
|
||||
ThreadPool gSendThreadPool;
|
||||
ThreadPool gRecvThreadPool;
|
||||
ThreadPool gMiniServerThreadPool;
|
||||
|
||||
//Flag to indicate the state of web server
|
||||
WebServerState bWebServerState = WEB_SERVER_DISABLED;
|
||||
// Flag to indicate the state of web server
|
||||
WebServerState bWebServerState = WEB_SERVER_DISABLED;
|
||||
|
||||
// Static buffer to contain interface name. (extern'ed in upnp.h)
|
||||
char gIF_NAME[LINE_SIZE] = { '\0' };
|
||||
char gIF_NAME[LINE_SIZE] = { '\0' };
|
||||
|
||||
// Static buffer to contain interface IPv4 address. (extern'ed in upnp.h)
|
||||
char gIF_IPV4[22]/* INET_ADDRSTRLEN*/ = { '\0' };
|
||||
char gIF_IPV4[22]/* INET_ADDRSTRLEN*/ = { '\0' };
|
||||
|
||||
// Static buffer to contain interface IPv6 address. (extern'ed in upnp.h)
|
||||
char gIF_IPV6[65]/* INET6_ADDRSTRLEN*/ = { '\0' };
|
||||
char gIF_IPV6[65]/* INET6_ADDRSTRLEN*/ = { '\0' };
|
||||
|
||||
// Contains interface index. (extern'ed in upnp.h)
|
||||
int gIF_INDEX = -1;
|
||||
int gIF_INDEX = -1;
|
||||
|
||||
// local IPv4 and IPv6 ports for the mini-server
|
||||
unsigned short LOCAL_PORT_V4;
|
||||
unsigned short LOCAL_PORT_V6;
|
||||
unsigned short LOCAL_PORT_V4;
|
||||
unsigned short LOCAL_PORT_V6;
|
||||
|
||||
// UPnP device and control point handle table
|
||||
void *HandleTable[NUM_HANDLE];
|
||||
|
||||
//This structure is for virtual directory callbacks
|
||||
struct UpnpVirtualDirCallbacks virtualDirCallback;
|
||||
void *HandleTable[NUM_HANDLE];
|
||||
|
||||
// a local dir which serves as webserver root
|
||||
extern membuffer gDocumentRootDir;
|
||||
extern membuffer gDocumentRootDir;
|
||||
|
||||
// Maximum content-length that the SDK will process on an incoming packet.
|
||||
// Content-Length exceeding this size will be not processed and error 413
|
||||
@ -142,22 +145,22 @@ size_t g_maxContentLength = DEFAULT_SOAP_CONTENT_LENGTH; // in bytes
|
||||
|
||||
// Global variable to denote the state of Upnp SDK
|
||||
// = 0 if uninitialized, = 1 if initialized.
|
||||
int UpnpSdkInit = 0;
|
||||
int UpnpSdkInit = 0;
|
||||
|
||||
// Global variable to denote the state of Upnp SDK client registration.
|
||||
// = 0 if unregistered, = 1 if registered.
|
||||
int UpnpSdkClientRegistered = 0;
|
||||
int UpnpSdkClientRegistered = 0;
|
||||
|
||||
// Global variable to denote the state of Upnp SDK IPv4 device registration.
|
||||
// = 0 if unregistered, = 1 if registered.
|
||||
int UpnpSdkDeviceRegisteredV4 = 0;
|
||||
int UpnpSdkDeviceRegisteredV4 = 0;
|
||||
|
||||
// Global variable to denote the state of Upnp SDK IPv6 device registration.
|
||||
// = 0 if unregistered, = 1 if registered.
|
||||
int UpnpSdkDeviceregisteredV6 = 0;
|
||||
int UpnpSdkDeviceregisteredV6 = 0;
|
||||
|
||||
// Global variable used in discovery notifications.
|
||||
Upnp_SID gUpnpSdkNLSuuid;
|
||||
Upnp_SID gUpnpSdkNLSuuid;
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
@ -5048,46 +5051,86 @@ UpnpIsWebserverEnabled()
|
||||
return ( bWebServerState == WEB_SERVER_ENABLED );
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
* Function: UpnpSetVirtualDirCallbacks
|
||||
*
|
||||
* 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 )
|
||||
|
||||
int UpnpVirtualDir_set_GetInfoCallback(VDCallback_GetInfo callback)
|
||||
{
|
||||
struct UpnpVirtualDirCallbacks *pCallback;
|
||||
int ret = UPNP_E_SUCCESS;
|
||||
if (!callback) {
|
||||
ret = UPNP_E_INVALID_PARAM;
|
||||
} else {
|
||||
virtualDirCallback.get_info = callback;
|
||||
}
|
||||
|
||||
if( UpnpSdkInit != 1 ) {
|
||||
// SDK is not initialized
|
||||
return UPNP_E_FINISH;
|
||||
}
|
||||
|
||||
pCallback = &virtualDirCallback;
|
||||
|
||||
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;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
|
||||
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
|
||||
*
|
||||
* Parameters:
|
||||
@ -5096,8 +5139,7 @@ UpnpSetVirtualDirCallbacks( IN struct UpnpVirtualDirCallbacks *callbacks )
|
||||
* Description:
|
||||
* This function free the memory allocated by tbe UPnP library
|
||||
*
|
||||
* Return Values: VOID
|
||||
*
|
||||
* Return Values: void
|
||||
***************************************************************************/
|
||||
void
|
||||
UpnpFree( IN void *item )
|
||||
|
@ -58,6 +58,7 @@
|
||||
#include "upnp.h"
|
||||
#include "upnpapi.h"
|
||||
#include "util.h"
|
||||
#include "VirtualDir.h"
|
||||
|
||||
|
||||
#ifndef WIN32
|
||||
@ -520,40 +521,33 @@ web_server_set_alias( IN const char *alias_name,
|
||||
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 web_server_init()
|
||||
{
|
||||
int ret_code;
|
||||
int ret = 0;
|
||||
if (bWebServerState == WEB_SERVER_DISABLED) {
|
||||
// decode media list
|
||||
media_list_init();
|
||||
membuffer_init(&gDocumentRootDir);
|
||||
glob_alias_init();
|
||||
pVirtualDirList = NULL;
|
||||
|
||||
if( bWebServerState == WEB_SERVER_DISABLED ) {
|
||||
media_list_init(); // decode media list
|
||||
membuffer_init( &gDocumentRootDir );
|
||||
glob_alias_init();
|
||||
// Initialize callbacks
|
||||
virtualDirCallback.get_info = NULL;
|
||||
virtualDirCallback.open = NULL;
|
||||
virtualDirCallback.read = NULL;
|
||||
virtualDirCallback.write = NULL;
|
||||
virtualDirCallback.seek = NULL;
|
||||
virtualDirCallback.close = NULL;
|
||||
|
||||
pVirtualDirList = NULL;
|
||||
if (ithread_mutex_init(&gWebMutex, NULL) == -1) {
|
||||
ret = UPNP_E_OUTOF_MEMORY;
|
||||
} else {
|
||||
bWebServerState = WEB_SERVER_ENABLED;
|
||||
}
|
||||
}
|
||||
|
||||
ret_code = ithread_mutex_init( &gWebMutex, NULL );
|
||||
if( ret_code == -1 ) {
|
||||
return UPNP_E_OUTOF_MEMORY;
|
||||
}
|
||||
bWebServerState = WEB_SERVER_ENABLED;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/************************************************************************
|
||||
@ -1213,7 +1207,6 @@ process_request( IN http_message_t * req,
|
||||
int resp_minor;
|
||||
xboolean alias_grabbed;
|
||||
size_t dummy;
|
||||
struct UpnpVirtualDirCallbacks *pVirtualDirCallback;
|
||||
const char *extra_headers;
|
||||
|
||||
print_http_headers( req );
|
||||
@ -1285,8 +1278,7 @@ process_request( IN http_message_t * req,
|
||||
if (using_virtual_dir) {
|
||||
if (req->method != HTTPMETHOD_POST) {
|
||||
// get file info
|
||||
pVirtualDirCallback = &virtualDirCallback;
|
||||
if (pVirtualDirCallback->get_info(filename->buf, finfo) != 0) {
|
||||
if (virtualDirCallback.get_info(filename->buf, finfo) != 0) {
|
||||
err_code = HTTP_NOT_FOUND;
|
||||
goto error_handler;
|
||||
}
|
||||
@ -1301,7 +1293,7 @@ process_request( IN http_message_t * req,
|
||||
goto error_handler;
|
||||
}
|
||||
// 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)) {
|
||||
err_code = HTTP_NOT_FOUND;
|
||||
goto error_handler;
|
||||
@ -1523,8 +1515,8 @@ error_handler:
|
||||
* HTTP_OK
|
||||
************************************************************************/
|
||||
int
|
||||
http_RecvPostMessage( http_parser_t * parser,
|
||||
IN SOCKINFO * info,
|
||||
http_RecvPostMessage( http_parser_t *parser,
|
||||
IN SOCKINFO *info,
|
||||
char *filename,
|
||||
struct SendInstruction *Instr )
|
||||
{
|
||||
@ -1541,12 +1533,10 @@ http_RecvPostMessage( http_parser_t * parser,
|
||||
int ret_code = 0;
|
||||
|
||||
if( Instr && Instr->IsVirtualFile ) {
|
||||
|
||||
Fp = (virtualDirCallback.open)( filename, UPNP_WRITE );
|
||||
if( Fp == NULL ) {
|
||||
return HTTP_INTERNAL_SERVER_ERROR;
|
||||
}
|
||||
|
||||
} else {
|
||||
Fp = fopen( filename, "wb" );
|
||||
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
|
||||
#define UPNPDK_H
|
||||
#ifndef UPNPAPI_H
|
||||
#define UPNPAPI_H
|
||||
|
||||
|
||||
#include "upnp.h"
|
||||
#include "client_table.h"
|
||||
#include "upnp.h"
|
||||
//#include "../ssdp/ssdplib.h"
|
||||
#include "VirtualDir.h" /* for struct UpnpVirtualDirCallbacks */
|
||||
|
||||
|
||||
#define MAX_INTERFACES 256
|
||||
|
||||
@ -197,8 +199,6 @@ int getlocalhostname(char *out, const int out_len);
|
||||
|
||||
extern WebServerState bWebServerState;
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* UPNPAPI_H */
|
||||
|
||||
|
||||
/************************ END OF upnpapi.h **********************/
|
||||
|
@ -43,103 +43,104 @@ extern "C" {
|
||||
|
||||
struct SendInstruction
|
||||
{
|
||||
int IsVirtualFile;
|
||||
int IsChunkActive;
|
||||
int IsRangeActive;
|
||||
int IsTrailers;
|
||||
char RangeHeader[200];
|
||||
off_t RangeOffset;
|
||||
off_t ReadSendSize; // Read from local source and send on the network.
|
||||
long RecvWriteSize; // Recv from the network and write into local file.
|
||||
int IsVirtualFile;
|
||||
int IsChunkActive;
|
||||
int IsRangeActive;
|
||||
int IsTrailers;
|
||||
char RangeHeader[200];
|
||||
off_t RangeOffset;
|
||||
off_t ReadSendSize; // Read from local source and send on the network.
|
||||
long RecvWriteSize; // Recv from the network and write into local file.
|
||||
|
||||
//Later few more member could be added depending on the requirement.
|
||||
//Later few more member could be added depending on the requirement.
|
||||
};
|
||||
|
||||
/************************************************************************
|
||||
* 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 );
|
||||
* 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();
|
||||
|
||||
/************************************************************************
|
||||
* Function: web_server_destroy
|
||||
*
|
||||
* Parameters:
|
||||
* none
|
||||
*
|
||||
* Description: Release memory allocated for the global web server root
|
||||
* directory and the global XML document
|
||||
* Resets the flag bWebServerState to WEB_SERVER_DISABLED
|
||||
*
|
||||
* Returns:
|
||||
* void
|
||||
************************************************************************/
|
||||
void web_server_destroy( void );
|
||||
* Function: web_server_destroy
|
||||
*
|
||||
* Parameters:
|
||||
* none
|
||||
*
|
||||
* Description: Release memory allocated for the global web server root
|
||||
* directory and the global XML document
|
||||
* Resets the flag bWebServerState to WEB_SERVER_DISABLED
|
||||
*
|
||||
* Returns:
|
||||
* void
|
||||
************************************************************************/
|
||||
void web_server_destroy();
|
||||
|
||||
/************************************************************************
|
||||
* Function: web_server_set_alias
|
||||
*
|
||||
* Parameters:
|
||||
* alias_name: webserver name of alias; created by caller and freed by
|
||||
* caller (doesn't even have to be malloc()d .)
|
||||
* alias_content: the xml doc; this is allocated by the caller; and
|
||||
* freed by the web server
|
||||
* alias_content_length: length of alias body in bytes
|
||||
* last_modified: time when the contents of alias were last
|
||||
* changed (local time)
|
||||
*
|
||||
* Description: Replaces current alias with the given alias. To remove
|
||||
* the current alias, set alias_name to NULL.
|
||||
*
|
||||
* Returns:
|
||||
* 0 - OK
|
||||
* UPNP_E_OUTOF_MEMORY: note: alias_content is not freed here
|
||||
************************************************************************/
|
||||
int web_server_set_alias( IN const char* alias_name,
|
||||
IN const char* alias_content, IN size_t alias_content_length,
|
||||
IN time_t last_modified );
|
||||
* Function: web_server_set_alias
|
||||
*
|
||||
* Parameters:
|
||||
* alias_name: webserver name of alias; created by caller and freed by
|
||||
* caller (doesn't even have to be malloc()d .)
|
||||
* alias_content: the xml doc; this is allocated by the caller; and
|
||||
* freed by the web server
|
||||
* alias_content_length: length of alias body in bytes
|
||||
* last_modified: time when the contents of alias were last
|
||||
* changed (local time)
|
||||
*
|
||||
* Description: Replaces current alias with the given alias. To remove
|
||||
* the current alias, set alias_name to NULL.
|
||||
*
|
||||
* Returns:
|
||||
* 0 - OK
|
||||
* UPNP_E_OUTOF_MEMORY: note: alias_content is not freed here
|
||||
************************************************************************/
|
||||
int web_server_set_alias(
|
||||
IN const char* alias_name,
|
||||
IN const char* alias_content, IN size_t alias_content_length,
|
||||
IN time_t last_modified);
|
||||
|
||||
/************************************************************************
|
||||
* Function: web_server_set_root_dir
|
||||
*
|
||||
* Parameters:
|
||||
* IN const char* root_dir ; String having the root directory for the
|
||||
* document
|
||||
*
|
||||
* Description: Assign the path specfied by the IN const char* root_dir
|
||||
* parameter to the global Document root directory. Also check for
|
||||
* path names ending in '/'
|
||||
*
|
||||
* Returns:
|
||||
* int
|
||||
************************************************************************/
|
||||
int web_server_set_root_dir( IN const char* root_dir );
|
||||
* Function: web_server_set_root_dir
|
||||
*
|
||||
* Parameters:
|
||||
* IN const char* root_dir ; String having the root directory for the
|
||||
* document
|
||||
*
|
||||
* Description: Assign the path specfied by the IN const char* root_dir
|
||||
* parameter to the global Document root directory. Also check for
|
||||
* path names ending in '/'
|
||||
*
|
||||
* Returns:
|
||||
* int
|
||||
************************************************************************/
|
||||
int web_server_set_root_dir(IN const char* root_dir);
|
||||
|
||||
/************************************************************************
|
||||
* Function: web_server_callback
|
||||
*
|
||||
* Parameters:
|
||||
* IN http_parser_t *parser,
|
||||
* INOUT http_message_t* req,
|
||||
* IN SOCKINFO *info
|
||||
*
|
||||
* Description: main entry point into web server;
|
||||
* handles HTTP GET and HEAD requests
|
||||
*
|
||||
* Returns:
|
||||
* void
|
||||
************************************************************************/
|
||||
void web_server_callback( IN http_parser_t *parser, IN http_message_t* req, INOUT SOCKINFO *info );
|
||||
* Function: web_server_callback
|
||||
*
|
||||
* Parameters:
|
||||
* IN http_parser_t *parser,
|
||||
* INOUT http_message_t* req,
|
||||
* IN SOCKINFO *info
|
||||
*
|
||||
* Description: main entry point into web server;
|
||||
* handles HTTP GET and HEAD requests
|
||||
*
|
||||
* Returns:
|
||||
* void
|
||||
************************************************************************/
|
||||
void web_server_callback(IN http_parser_t *parser, IN http_message_t *req, INOUT SOCKINFO *info);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
Loading…
Reference in New Issue
Block a user