Added the convenience function UpnpResolveURL2() to upnptools.c.

This function avoids some unecessary memory allocation.
The memory alloc'd by this function must be freed later by the caller.
(cherry picked from commit 8651174861)
This commit is contained in:
Marcelo Roberto Jimenez 2010-11-15 01:01:07 -02:00
parent 5c8d118899
commit dd2624ebfe
3 changed files with 52 additions and 3 deletions

View File

@ -233,6 +233,13 @@ Version 1.8.0
Version 1.6.10
*******************************************************************************
2010-11-15 Marcelo Roberto Jimenez <mroberto(at)users.sourceforge.net>
Added the convenience function UpnpResolveURL2() to upnptools.c.
This function avoids some unecessary memory allocation.
The memory alloc'd by this function must be freed later by the caller.
2010-11-10 Fabrice Fontaine <fabrice.fontaine(at)orange-ftgroup.com>
Add GENA_NOTIFICATION_xxx_TIMEOUT variable.

View File

@ -96,6 +96,30 @@ EXPORT_SPEC int UpnpResolveURL(
char *AbsURL);
/*!
* \brief Combines a base URL and a relative URL into a single absolute URL.
*
* The memory for \b AbsURL becomes owned by the caller and should be freed
* later.
*
* \return An integer representing one of the following:
* \li <tt>UPNP_E_SUCCESS</tt>: The operation completed successfully.
* \li <tt>UPNP_E_INVALID_PARAM</tt>: \b RelURL is <tt>NULL</tt>.
* \li <tt>UPNP_E_INVALID_URL</tt>: The \b BaseURL / \b RelURL
* combination does not form a valid URL.
* \li <tt>UPNP_E_OUTOF_MEMORY</tt>: Insufficient resources exist to
* complete this operation.
*/
EXPORT_SPEC int UpnpResolveURL2(
/*! [in] The base URL to combine. */
const char *BaseURL,
/*! [in] The relative URL to \b BaseURL. */
const char *RelURL,
/*! [out] A pointer to a pointer to a buffer to store the
* absolute URL. Must be freed later by the caller. */
char **AbsURL);
/*!
* \brief Creates an action request packet based on its input parameters
* (status variable name and value pair).

View File

@ -147,18 +147,36 @@ int UpnpResolveURL(
int ret = UPNP_E_SUCCESS;
char *tempRel = NULL;
if (RelURL == NULL) {
if (!RelURL) {
ret = UPNP_E_INVALID_PARAM;
goto ExitFunction;
}
tempRel = resolve_rel_url((char *)BaseURL, (char *)RelURL);
if (tempRel) {
strcpy(AbsURL, tempRel);
free(tempRel);
} else {
} else
ret = UPNP_E_INVALID_URL;
ExitFunction:
return UPNP_E_SUCCESS;
}
int UpnpResolveURL2(
const char *BaseURL,
const char *RelURL,
char **AbsURL)
{
int ret = UPNP_E_SUCCESS;
if (!RelURL) {
ret = UPNP_E_INVALID_PARAM;
goto ExitFunction;
}
*AbsURL = resolve_rel_url((char *)BaseURL, (char *)RelURL);
if (!*AbsURL)
ret = UPNP_E_INVALID_URL;
ExitFunction:
return UPNP_E_SUCCESS;