netwerk/protocol/about/nsAboutProtocolUtils.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 #ifndef nsAboutProtocolUtils_h
michael@0 6 #define nsAboutProtocolUtils_h
michael@0 7
michael@0 8 #include "nsIURI.h"
michael@0 9 #include "nsString.h"
michael@0 10 #include "nsReadableUtils.h"
michael@0 11 #include "nsIAboutModule.h"
michael@0 12 #include "nsServiceManagerUtils.h"
michael@0 13 #include "prtime.h"
michael@0 14
michael@0 15 inline nsresult
michael@0 16 NS_GetAboutModuleName(nsIURI *aAboutURI, nsCString& aModule)
michael@0 17 {
michael@0 18 #ifdef DEBUG
michael@0 19 {
michael@0 20 bool isAbout;
michael@0 21 NS_ASSERTION(NS_SUCCEEDED(aAboutURI->SchemeIs("about", &isAbout)) &&
michael@0 22 isAbout,
michael@0 23 "should be used only on about: URIs");
michael@0 24 }
michael@0 25 #endif
michael@0 26
michael@0 27 nsresult rv = aAboutURI->GetPath(aModule);
michael@0 28 NS_ENSURE_SUCCESS(rv, rv);
michael@0 29
michael@0 30 int32_t f = aModule.FindCharInSet(NS_LITERAL_CSTRING("#?"));
michael@0 31 if (f != kNotFound) {
michael@0 32 aModule.Truncate(f);
michael@0 33 }
michael@0 34
michael@0 35 // convert to lowercase, as all about: modules are lowercase
michael@0 36 ToLowerCase(aModule);
michael@0 37 return NS_OK;
michael@0 38 }
michael@0 39
michael@0 40 inline nsresult
michael@0 41 NS_GetAboutModule(nsIURI *aAboutURI, nsIAboutModule** aModule)
michael@0 42 {
michael@0 43 NS_PRECONDITION(aAboutURI, "Must have URI");
michael@0 44
michael@0 45 nsAutoCString contractID;
michael@0 46 nsresult rv = NS_GetAboutModuleName(aAboutURI, contractID);
michael@0 47 if (NS_FAILED(rv)) return rv;
michael@0 48
michael@0 49 // look up a handler to deal with "what"
michael@0 50 contractID.Insert(NS_LITERAL_CSTRING(NS_ABOUT_MODULE_CONTRACTID_PREFIX), 0);
michael@0 51
michael@0 52 return CallGetService(contractID.get(), aModule);
michael@0 53 }
michael@0 54
michael@0 55 inline PRTime SecondsToPRTime(uint32_t t_sec)
michael@0 56 {
michael@0 57 PRTime t_usec, usec_per_sec;
michael@0 58 t_usec = t_sec;
michael@0 59 usec_per_sec = PR_USEC_PER_SEC;
michael@0 60 return t_usec *= usec_per_sec;
michael@0 61 }
michael@0 62 inline void PrintTimeString(char *buf, uint32_t bufsize, uint32_t t_sec)
michael@0 63 {
michael@0 64 PRExplodedTime et;
michael@0 65 PRTime t_usec = SecondsToPRTime(t_sec);
michael@0 66 PR_ExplodeTime(t_usec, PR_LocalTimeParameters, &et);
michael@0 67 PR_FormatTime(buf, bufsize, "%Y-%m-%d %H:%M:%S", &et);
michael@0 68 }
michael@0 69
michael@0 70
michael@0 71 #endif

mercurial