From e0c068602adc5ce82a36a7032b772f280cdaebca Mon Sep 17 00:00:00 2001 From: "mscott%netscape.com" Date: Thu, 25 Mar 1999 04:48:45 +0000 Subject: [PATCH] (not part of build yet) implementation of nntp service. --- mailnews/news/src/nsNntpService.cpp | 101 ++++++++++++++++++++++++++++ mailnews/news/src/nsNntpService.h | 39 +++++++++++ 2 files changed, 140 insertions(+) create mode 100644 mailnews/news/src/nsNntpService.cpp create mode 100644 mailnews/news/src/nsNntpService.h diff --git a/mailnews/news/src/nsNntpService.cpp b/mailnews/news/src/nsNntpService.cpp new file mode 100644 index 00000000000..3e43e5328df --- /dev/null +++ b/mailnews/news/src/nsNntpService.cpp @@ -0,0 +1,101 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#include "msgCore.h" // precompiled header... +#include "nntpCore.h" + +#ifdef XP_PC +#include // for InterlockedIncrement +#endif + + +#include "nsNntpService.h" +#include "nsINetService.h" +#include "nsINntpUrl.h" +#include "nsNntpProtocol.h" + +static NS_DEFINE_CID(kNntpUrlCID, NS_NNTPURL_CID); + +nsNntpService::nsNntpService() +{ + NS_INIT_REFCNT(); +} + +nsNntpService::~nsNntpService() +{} + +NS_IMPL_THREADSAFE_ISUPPORTS(nsNntpService, nsINntpService::GetIID()); + +NS_IMETHODIMP nsNntpService::RunNewsUrl(const nsString& urlString, nsISupports * aConsumer, + nsIUrlListener *aUrlListener, nsIURL ** aUrl) +{ + // for now, assume the url is a news url and load it.... + nsINntpUrl *nntpUrl = nsnull; + nsINetService *pNetService = nsnull; + nsITransport *transport = nsnull; + nsNNTPProtocol *nntpProtocol = nsnull; + nsresult rv = NS_OK; + + // make sure we have a netlib service around... + rv = NS_NewINetService(&pNetService, nsnull); + + if (NS_SUCCEEDED(rv) && pNetService) + { + + rv = nsComponentManager::CreateInstance(kNntpUrlCID, nsnull, nsINntpUrl::GetIID(), (void **) + &nntpUrl); + + if (NS_SUCCEEDED(rv) && nntpUrl) + { + char * urlSpec = urlString.ToNewCString(); + nntpUrl->SetSpec(urlSpec); + if (urlSpec) + delete [] urlSpec; + + const char * host; + PRUint32 port = NEWS_PORT; + + if (aUrlListener) // register listener if there is one... + nntpUrl->RegisterListener(aUrlListener); + + nntpUrl->GetHostPort(&port); + nntpUrl->GetHost(&host); + // okay now create a transport to run the url in... + pNetService->CreateSocketTransport(&transport, port, host); + if (NS_SUCCEEDED(rv) && transport) + { + // almost there...now create a nntp protocol instance to run the url in... + nntpProtocol = new nsNNTPProtocol(nntpUrl, transport); + if (nntpProtocol) + nntpProtocol->LoadURL(nntpUrl, aConsumer); + } + + if (aUrl) + *aUrl = nntpUrl; // transfer ref count + else + NS_RELEASE(nntpUrl); + } // if nntpUrl + + NS_RELEASE(pNetService); + } // if pNetService + + return rv; +} + + + diff --git a/mailnews/news/src/nsNntpService.h b/mailnews/news/src/nsNntpService.h new file mode 100644 index 00000000000..768a6c78a00 --- /dev/null +++ b/mailnews/news/src/nsNntpService.h @@ -0,0 +1,39 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#ifndef nsNntpService_h___ +#define nsNntpService_h___ + +#include "nsINntpService.h" + +class nsIURL; +class nsIUrlListener; + +class nsNntpService : public nsINntpService +{ +public: + NS_DECL_ISUPPORTS + nsNntpService(); + + NS_IMETHOD RunNewsUrl (const nsString& urlString, nsISupports * aConsumer, + nsIUrlListener * aUrlListener, nsIURL ** aURL); +protected: + virtual ~nsNntpService(); +}; + +#endif /* nsNntpService_h___ */ \ No newline at end of file