From af7cf378c38c9bc7f062dea691a2d868affafdb5 Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Tue, 24 Sep 2002 09:15:18 +0000 Subject: #102945# Added convertRelToAbs. --- sal/inc/rtl/uri.h | 60 +++++++++++++++++++++++++++++++++++++++++++++++------ sal/inc/rtl/uri.hxx | 39 +++++++++++++++++++++++++++------- 2 files changed, 86 insertions(+), 13 deletions(-) (limited to 'sal') diff --git a/sal/inc/rtl/uri.h b/sal/inc/rtl/uri.h index fb84257d0216..99e88b4f2ad5 100644 --- a/sal/inc/rtl/uri.h +++ b/sal/inc/rtl/uri.h @@ -2,9 +2,9 @@ * * $RCSfile: uri.h,v $ * - * $Revision: 1.5 $ + * $Revision: 1.6 $ * - * last change: $Author: sb $ $Date: 2001-10-29 11:55:09 $ + * last change: $Author: sb $ $Date: 2002-09-24 10:15:18 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -50,7 +50,7 @@ * * The Initial Developer of the Original Code is: Sun Microsystems, Inc. * - * Copyright: 2000 by Sun Microsystems, Inc. + * Copyright: 2002 by Sun Microsystems, Inc. * * All Rights Reserved. * @@ -63,13 +63,13 @@ #define _RTL_URI_H_ #ifndef _RTL_TEXTENC_H -#include +#include "rtl/textenc.h" #endif #ifndef _RTL_USTRING_H_ -#include +#include "rtl/ustring.h" #endif #ifndef _SAL_TYPES_H_ -#include +#include "sal/types.h" #endif #if defined __cplusplus @@ -309,6 +309,54 @@ void rtl_uriDecode(rtl_uString * pText, rtl_uString ** pResult) SAL_THROW_EXTERN_C(); +/** Convert a relative URI reference into an absolute one. + + A URI reference is a URI plus an optional <"#" fragment> part. + + This function uses the algorithm described in RFC 2396, section 5.2, with + the following clarifications: (1) Backwards-compatible relative URIs + starting with a scheme component (see RFC 2396, section 5.2, step 3) are not + supported. (2) Segments "." and ".." within the path of the base URI are + not considered special, RFC 2396 seems a bit unlcear about that point. + (3) Erroneous excess segments ".." within the path of the relative URI (if + it is indeed relative) are left intact, as the examples in RFC 2396, + section C.2, suggest. (4) If the relative URI is a reference to the + "current document," the "current document" is taken to be the base URI. + + This function signals exceptions by returning false and letting pException + point to a message explaining the exception. + + @param pBaseUriRef + An absolute, hierarchical URI reference that serves as the base URI. If it + has to be inspected (i.e., pRelUriRef is not an absolute URI already), and + if it either is not an absolute URI (i.e., does not begin with a + part) or has a path that is non-empty but does not start + with "/", an exception will be signaled. + + @param pRelUriRef + An URI reference that may be either absolute or relative. If it is + absolute, it will be returned unmodified (and it need not be hierarchical + then). + + @param pResult + Returns an absolute URI reference. Must itself not be null, and must point + to either null or a valid string. If an exception is signalled, it is left + unchanged. + + @param pException + Returns an explanatory message in case an exception is signalled. Must + itself not be null, and must point to either null or a valid string. If no + exception is signalled, it is left unchanged. + + @return + True if no exception is signalled, otherwise false. + */ +sal_Bool rtl_uriConvertRelToAbs(rtl_uString * pBaseUriRef, + rtl_uString * pRelUriRef, + rtl_uString ** pResult, + rtl_uString ** pException) + SAL_THROW_EXTERN_C(); + #if defined __cplusplus } #endif /* __cplusplus */ diff --git a/sal/inc/rtl/uri.hxx b/sal/inc/rtl/uri.hxx index 3d575c1b2bdb..3a8c93caa45e 100644 --- a/sal/inc/rtl/uri.hxx +++ b/sal/inc/rtl/uri.hxx @@ -2,9 +2,9 @@ * * $RCSfile: uri.hxx,v $ * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * - * last change: $Author: sb $ $Date: 2001-10-29 11:55:09 $ + * last change: $Author: sb $ $Date: 2002-09-24 10:15:18 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -50,7 +50,7 @@ * * The Initial Developer of the Original Code is: Sun Microsystems, Inc. * - * Copyright: 2000 by Sun Microsystems, Inc. + * Copyright: 2002 by Sun Microsystems, Inc. * * All Rights Reserved. * @@ -62,17 +62,20 @@ #ifndef _RTL_URI_HXX_ #define _RTL_URI_HXX_ +#ifndef INCLUDED_RTL_MALFORMEDURIEXCEPTION_HXX +#include "rtl/malformeduriexception.hxx" +#endif #ifndef _RTL_URI_H_ -#include +#include "rtl/uri.h" #endif #ifndef _RTL_TEXTENC_H -#include +#include "rtl/textenc.h" #endif #ifndef _RTL_USTRING_HXX_ -#include +#include "rtl/ustring.hxx" #endif #ifndef _SAL_TYPES_H_ -#include +#include "sal/types.h" #endif namespace rtl { @@ -107,6 +110,15 @@ public: rtl_TextEncoding eCharset) SAL_THROW(()); + /** A wrapper around rtl_uriConvertRelToAbs() from (see there). + + @exception MalformedUriException + Thrown in case rtl_uriConvertRelToAbs() signals an exception due to a + malformed base URI. + */ + static inline rtl::OUString convertRelToAbs( + rtl::OUString const & rBaseUriRef, rtl::OUString const & rRelUriRef); + private: /** not implemented @internal */ @@ -168,6 +180,19 @@ inline rtl::OUString Uri::decode(rtl::OUString const & rText, return aResult; } +inline rtl::OUString Uri::convertRelToAbs(rtl::OUString const & rBaseUriRef, + rtl::OUString const & rRelUriRef) +{ + rtl::OUString aResult; + rtl::OUString aException; + if (!rtl_uriConvertRelToAbs( + const_cast< rtl::OUString & >(rBaseUriRef).pData, + const_cast< rtl::OUString & >(rRelUriRef).pData, &aResult.pData, + &aException.pData)) + throw MalformedUriException(aException); + return aResult; +} + } #endif // _RTL_URI_HXX_ -- cgit