michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 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: #include "nspr.h" michael@0: #include "nscore.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsIIOService.h" michael@0: #include "nsIServiceManager.h" michael@0: #include "nsIComponentRegistrar.h" michael@0: #include "nsIURI.h" michael@0: michael@0: static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID); michael@0: michael@0: nsresult ServiceMakeAbsolute(nsIURI *baseURI, char *relativeInfo, char **_retval) { michael@0: nsresult rv; michael@0: nsCOMPtr serv(do_GetService(kIOServiceCID, &rv)); michael@0: if (NS_FAILED(rv)) return rv; michael@0: michael@0: return serv->MakeAbsolute(relativeInfo, baseURI, _retval); michael@0: } michael@0: michael@0: nsresult URLMakeAbsolute(nsIURI *baseURI, char *relativeInfo, char **_retval) { michael@0: return baseURI->MakeAbsolute(relativeInfo, _retval); michael@0: } michael@0: michael@0: int michael@0: main(int argc, char* argv[]) michael@0: { michael@0: nsresult rv = NS_OK; michael@0: if (argc < 4) { michael@0: printf("usage: %s int (loop count) baseURL relativeSpec\n", argv[0]); michael@0: return -1; michael@0: } michael@0: michael@0: uint32_t cycles = atoi(argv[1]); michael@0: char *base = argv[2]; michael@0: char *rel = argv[3]; michael@0: { michael@0: nsCOMPtr servMan; michael@0: NS_InitXPCOM2(getter_AddRefs(servMan), nullptr, nullptr); michael@0: nsCOMPtr registrar = do_QueryInterface(servMan); michael@0: NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); michael@0: if (registrar) michael@0: registrar->AutoRegister(nullptr); michael@0: michael@0: nsCOMPtr serv(do_GetService(kIOServiceCID, &rv)); michael@0: if (NS_FAILED(rv)) return rv; michael@0: michael@0: nsCOMPtr uri; michael@0: rv = serv->NewURI(base, nullptr, getter_AddRefs(uri)); michael@0: if (NS_FAILED(rv)) return rv; michael@0: michael@0: char *absURLString; michael@0: uint32_t i = 0; michael@0: while (i++ < cycles) { michael@0: rv = ServiceMakeAbsolute(uri, rel, &absURLString); michael@0: if (NS_FAILED(rv)) return rv; michael@0: nsMemory::Free(absURLString); michael@0: michael@0: rv = URLMakeAbsolute(uri, rel, &absURLString); michael@0: nsMemory::Free(absURLString); michael@0: } michael@0: } // this scopes the nsCOMPtrs michael@0: // no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM michael@0: NS_ShutdownXPCOM(nullptr); michael@0: return rv; michael@0: }