michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsAboutProtocolUtils_h michael@0: #define nsAboutProtocolUtils_h michael@0: michael@0: #include "nsIURI.h" michael@0: #include "nsString.h" michael@0: #include "nsReadableUtils.h" michael@0: #include "nsIAboutModule.h" michael@0: #include "nsServiceManagerUtils.h" michael@0: #include "prtime.h" michael@0: michael@0: inline nsresult michael@0: NS_GetAboutModuleName(nsIURI *aAboutURI, nsCString& aModule) michael@0: { michael@0: #ifdef DEBUG michael@0: { michael@0: bool isAbout; michael@0: NS_ASSERTION(NS_SUCCEEDED(aAboutURI->SchemeIs("about", &isAbout)) && michael@0: isAbout, michael@0: "should be used only on about: URIs"); michael@0: } michael@0: #endif michael@0: michael@0: nsresult rv = aAboutURI->GetPath(aModule); michael@0: NS_ENSURE_SUCCESS(rv, rv); michael@0: michael@0: int32_t f = aModule.FindCharInSet(NS_LITERAL_CSTRING("#?")); michael@0: if (f != kNotFound) { michael@0: aModule.Truncate(f); michael@0: } michael@0: michael@0: // convert to lowercase, as all about: modules are lowercase michael@0: ToLowerCase(aModule); michael@0: return NS_OK; michael@0: } michael@0: michael@0: inline nsresult michael@0: NS_GetAboutModule(nsIURI *aAboutURI, nsIAboutModule** aModule) michael@0: { michael@0: NS_PRECONDITION(aAboutURI, "Must have URI"); michael@0: michael@0: nsAutoCString contractID; michael@0: nsresult rv = NS_GetAboutModuleName(aAboutURI, contractID); michael@0: if (NS_FAILED(rv)) return rv; michael@0: michael@0: // look up a handler to deal with "what" michael@0: contractID.Insert(NS_LITERAL_CSTRING(NS_ABOUT_MODULE_CONTRACTID_PREFIX), 0); michael@0: michael@0: return CallGetService(contractID.get(), aModule); michael@0: } michael@0: michael@0: inline PRTime SecondsToPRTime(uint32_t t_sec) michael@0: { michael@0: PRTime t_usec, usec_per_sec; michael@0: t_usec = t_sec; michael@0: usec_per_sec = PR_USEC_PER_SEC; michael@0: return t_usec *= usec_per_sec; michael@0: } michael@0: inline void PrintTimeString(char *buf, uint32_t bufsize, uint32_t t_sec) michael@0: { michael@0: PRExplodedTime et; michael@0: PRTime t_usec = SecondsToPRTime(t_sec); michael@0: PR_ExplodeTime(t_usec, PR_LocalTimeParameters, &et); michael@0: PR_FormatTime(buf, bufsize, "%Y-%m-%d %H:%M:%S", &et); michael@0: } michael@0: michael@0: michael@0: #endif