2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nspr.h"
|
|
|
|
#include "nscore.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIIOService.h"
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIComponentRegistrar.h"
|
|
|
|
#include "nsIURI.h"
|
|
|
|
|
|
|
|
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
|
|
|
|
|
|
|
nsresult ServiceMakeAbsolute(nsIURI *baseURI, char *relativeInfo, char **_retval) {
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIIOService> serv(do_GetService(kIOServiceCID, &rv));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
return serv->MakeAbsolute(relativeInfo, baseURI, _retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult URLMakeAbsolute(nsIURI *baseURI, char *relativeInfo, char **_retval) {
|
|
|
|
return baseURI->MakeAbsolute(relativeInfo, _retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
if (argc < 4) {
|
|
|
|
printf("usage: %s int (loop count) baseURL relativeSpec\n", argv[0]);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t cycles = atoi(argv[1]);
|
2007-03-22 10:30:00 -07:00
|
|
|
char *base = argv[2];
|
|
|
|
char *rel = argv[3];
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIServiceManager> servMan;
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_InitXPCOM2(getter_AddRefs(servMan), nullptr, nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(servMan);
|
|
|
|
NS_ASSERTION(registrar, "Null nsIComponentRegistrar");
|
|
|
|
if (registrar)
|
2012-07-30 07:20:58 -07:00
|
|
|
registrar->AutoRegister(nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIIOService> serv(do_GetService(kIOServiceCID, &rv));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
2012-07-30 07:20:58 -07:00
|
|
|
rv = serv->NewURI(base, nullptr, getter_AddRefs(uri));
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
char *absURLString;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t i = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
while (i++ < cycles) {
|
|
|
|
rv = ServiceMakeAbsolute(uri, rel, &absURLString);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
nsMemory::Free(absURLString);
|
|
|
|
|
|
|
|
rv = URLMakeAbsolute(uri, rel, &absURLString);
|
|
|
|
nsMemory::Free(absURLString);
|
|
|
|
}
|
|
|
|
} // this scopes the nsCOMPtrs
|
|
|
|
// no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_ShutdownXPCOM(nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
return rv;
|
|
|
|
}
|