2001-09-28 20:14:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00: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/. */
|
1999-10-07 21:43:49 +00:00
|
|
|
|
|
|
|
#include "nspr.h"
|
|
|
|
#include "nscore.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIIOService.h"
|
|
|
|
#include "nsIServiceManager.h"
|
2002-01-29 21:22:13 +00:00
|
|
|
#include "nsIComponentRegistrar.h"
|
1999-10-07 21:43:49 +00:00
|
|
|
#include "nsIURI.h"
|
|
|
|
|
|
|
|
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
|
|
|
|
|
|
|
nsresult ServiceMakeAbsolute(nsIURI *baseURI, char *relativeInfo, char **_retval) {
|
|
|
|
nsresult rv;
|
2001-07-25 07:54:28 +00:00
|
|
|
nsCOMPtr<nsIIOService> serv(do_GetService(kIOServiceCID, &rv));
|
1999-10-07 21:43:49 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2002-07-04 14:29:25 +00:00
|
|
|
|
1999-10-07 21:43:49 +00:00
|
|
|
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 15:56:38 +00:00
|
|
|
uint32_t cycles = atoi(argv[1]);
|
1999-10-07 21:43:49 +00:00
|
|
|
char *base = argv[2];
|
|
|
|
char *rel = argv[3];
|
2002-07-04 14:29:25 +00:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIServiceManager> servMan;
|
2012-07-30 14:20:58 +00:00
|
|
|
NS_InitXPCOM2(getter_AddRefs(servMan), nullptr, nullptr);
|
2002-07-04 14:29:25 +00:00
|
|
|
nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(servMan);
|
|
|
|
NS_ASSERTION(registrar, "Null nsIComponentRegistrar");
|
|
|
|
if (registrar)
|
2012-07-30 14:20:58 +00:00
|
|
|
registrar->AutoRegister(nullptr);
|
1999-10-07 21:43:49 +00:00
|
|
|
|
2002-07-04 14:29:25 +00:00
|
|
|
nsCOMPtr<nsIIOService> serv(do_GetService(kIOServiceCID, &rv));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-10-07 21:43:49 +00:00
|
|
|
|
2002-07-04 14:29:25 +00:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
2012-07-30 14:20:58 +00:00
|
|
|
rv = serv->NewURI(base, nullptr, getter_AddRefs(uri));
|
1999-10-07 21:43:49 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2002-07-04 14:29:25 +00:00
|
|
|
char *absURLString;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t i = 0;
|
2002-07-04 14:29:25 +00:00
|
|
|
while (i++ < cycles) {
|
|
|
|
rv = ServiceMakeAbsolute(uri, rel, &absURLString);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
nsMemory::Free(absURLString);
|
1999-10-07 21:43:49 +00:00
|
|
|
|
2002-07-04 14:29:25 +00:00
|
|
|
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 14:20:58 +00:00
|
|
|
NS_ShutdownXPCOM(nullptr);
|
1999-10-07 21:43:49 +00:00
|
|
|
return rv;
|
|
|
|
}
|