diff --git a/ChangeLog b/ChangeLog index 634ec37..593fa31 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,13 @@ Version 1.6.10 ******************************************************************************* +2010-11-15 Marcelo Roberto Jimenez + + 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 Add GENA_NOTIFICATION_xxx_TIMEOUT variable. diff --git a/upnp/inc/upnptools.h b/upnp/inc/upnptools.h index c28c157..750a100 100644 --- a/upnp/inc/upnptools.h +++ b/upnp/inc/upnptools.h @@ -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 UPNP_E_SUCCESS: The operation completed successfully. + * \li UPNP_E_INVALID_PARAM: \b RelURL is NULL. + * \li UPNP_E_INVALID_URL: The \b BaseURL / \b RelURL + * combination does not form a valid URL. + * \li UPNP_E_OUTOF_MEMORY: 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). diff --git a/upnp/src/api/upnptools.c b/upnp/src/api/upnptools.c index 2becc1b..3bbe9eb 100644 --- a/upnp/src/api/upnptools.c +++ b/upnp/src/api/upnptools.c @@ -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;